ox-publish: Small refactoring
[org-mode.git] / lisp / org-agenda.el
blob00594a04b8690faeb626fa73442b36900572264c
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
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.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags do not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
847 "Non-nil means skip scheduled delay when entry also has a deadline.
848 This variable may be set to nil, t, the symbol `post-deadline',
849 or a number which will then give the number of days after the actual
850 scheduled date when the delay should expire. The symbol `post-deadline'
851 eliminates the schedule delay when the date is posterior to the deadline."
852 :group 'org-agenda-skip
853 :group 'org-agenda-daily/weekly
854 :version "24.3"
855 :type '(choice
856 (const :tag "Always honor delay" nil)
857 (const :tag "Ignore delay if posterior to the deadline" post-deadline)
858 (const :tag "Ignore delay if entry has a deadline" t)
859 (integer :tag "Honor delay up until N days after the scheduled date")))
861 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
862 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
863 When non-nil, after the search for timestamps has matched once in an
864 entry, the rest of the entry will not be searched."
865 :group 'org-agenda-skip
866 :type 'boolean)
868 (defcustom org-agenda-skip-timestamp-if-done nil
869 "Non-nil means don't select item by timestamp or -range if it is DONE."
870 :group 'org-agenda-skip
871 :group 'org-agenda-daily/weekly
872 :type 'boolean)
874 (defcustom org-agenda-dim-blocked-tasks nil
875 "Non-nil means dim blocked tasks in the agenda display.
876 This causes some overhead during agenda construction, but if you
877 have turned on `org-enforce-todo-dependencies',
878 `org-enforce-todo-checkbox-dependencies', or any other blocking
879 mechanism, this will create useful feedback in the agenda.
881 Instead of t, this variable can also have the value `invisible'.
882 Then blocked tasks will be invisible and only become visible when
883 they become unblocked. An exemption to this behavior is when a task is
884 blocked because of unchecked checkboxes below it. Since checkboxes do
885 not show up in the agenda views, making this task invisible you remove any
886 trace from agenda views that there is something to do. Therefore, a task
887 that is blocked because of checkboxes will never be made invisible, it
888 will only be dimmed."
889 :group 'org-agenda-daily/weekly
890 :group 'org-agenda-todo-list
891 :version "24.3"
892 :type '(choice
893 (const :tag "Do not dim" nil)
894 (const :tag "Dim to a gray face" t)
895 (const :tag "Make invisible" invisible)))
897 (defcustom org-timeline-show-empty-dates 3
898 "Non-nil means `org-timeline' also shows dates without an entry.
899 When nil, only the days which actually have entries are shown.
900 When t, all days between the first and the last date are shown.
901 When an integer, show also empty dates, but if there is a gap of more than
902 N days, just insert a special line indicating the size of the gap."
903 :group 'org-agenda-skip
904 :type '(choice
905 (const :tag "None" nil)
906 (const :tag "All" t)
907 (integer :tag "at most")))
909 (defgroup org-agenda-startup nil
910 "Options concerning initial settings in the Agenda in Org Mode."
911 :tag "Org Agenda Startup"
912 :group 'org-agenda)
914 (defcustom org-agenda-menu-show-matcher t
915 "Non-nil means show the match string in the agenda dispatcher menu.
916 When nil, the matcher string is not shown, but is put into the help-echo
917 property so than moving the mouse over the command shows it.
918 Setting it to nil is good if matcher strings are very long and/or if
919 you want to use two-columns display (see `org-agenda-menu-two-columns')."
920 :group 'org-agenda
921 :version "24.1"
922 :type 'boolean)
924 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
926 (defcustom org-agenda-menu-two-columns nil
927 "Non-nil means, use two columns to show custom commands in the dispatcher.
928 If you use this, you probably want to set `org-agenda-menu-show-matcher'
929 to nil."
930 :group 'org-agenda
931 :version "24.1"
932 :type 'boolean)
934 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
935 (defcustom org-agenda-finalize-hook nil
936 "Hook run just before displaying an agenda buffer.
937 The buffer is still writable when the hook is called.
939 You can modify some of the buffer substrings but you should be
940 extra careful not to modify the text properties of the agenda
941 headlines as the agenda display heavily relies on them."
942 :group 'org-agenda-startup
943 :type 'hook)
945 (defcustom org-agenda-mouse-1-follows-link nil
946 "Non-nil means mouse-1 on a link will follow the link in the agenda.
947 A longer mouse click will still set point. Does not work on XEmacs.
948 Needs to be set before org.el is loaded."
949 :group 'org-agenda-startup
950 :type 'boolean)
952 (defcustom org-agenda-start-with-follow-mode nil
953 "The initial value of follow mode in a newly created agenda window."
954 :group 'org-agenda-startup
955 :type 'boolean)
957 (defcustom org-agenda-follow-indirect nil
958 "Non-nil means `org-agenda-follow-mode' displays only the
959 current item's tree, in an indirect buffer."
960 :group 'org-agenda
961 :version "24.1"
962 :type 'boolean)
964 (defcustom org-agenda-show-outline-path t
965 "Non-nil means show outline path in echo area after line motion."
966 :group 'org-agenda-startup
967 :type 'boolean)
969 (defcustom org-agenda-start-with-entry-text-mode nil
970 "The initial value of entry-text-mode in a newly created agenda window."
971 :group 'org-agenda-startup
972 :type 'boolean)
974 (defcustom org-agenda-entry-text-maxlines 5
975 "Number of text lines to be added when `E' is pressed in the agenda.
977 Note that this variable only used during agenda display. Add add entry text
978 when exporting the agenda, configure the variable
979 `org-agenda-add-entry-ext-maxlines'."
980 :group 'org-agenda
981 :type 'integer)
983 (defcustom org-agenda-entry-text-exclude-regexps nil
984 "List of regular expressions to clean up entry text.
985 The complete matches of all regular expressions in this list will be
986 removed from entry text before it is shown in the agenda."
987 :group 'org-agenda
988 :type '(repeat (regexp)))
990 (defvar org-agenda-entry-text-cleanup-hook nil
991 "Hook that is run after basic cleanup of entry text to be shown in agenda.
992 This cleanup is done in a temporary buffer, so the function may inspect and
993 change the entire buffer.
994 Some default stuff like drawers and scheduling/deadline dates will already
995 have been removed when this is called, as will any matches for regular
996 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
998 (defvar org-agenda-include-inactive-timestamps nil
999 "Non-nil means include inactive time stamps in agenda and timeline.
1000 Dynamically scoped.")
1002 (defgroup org-agenda-windows nil
1003 "Options concerning the windows used by the Agenda in Org Mode."
1004 :tag "Org Agenda Windows"
1005 :group 'org-agenda)
1007 (defcustom org-agenda-window-setup 'reorganize-frame
1008 "How the agenda buffer should be displayed.
1009 Possible values for this option are:
1011 current-window Show agenda in the current window, keeping all other windows.
1012 other-window Use `switch-to-buffer-other-window' to display agenda.
1013 reorganize-frame Show only two windows on the current frame, the current
1014 window and the agenda.
1015 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1016 Also, when exiting the agenda, kill that frame.
1017 See also the variable `org-agenda-restore-windows-after-quit'."
1018 :group 'org-agenda-windows
1019 :type '(choice
1020 (const current-window)
1021 (const other-frame)
1022 (const other-window)
1023 (const reorganize-frame)))
1025 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1026 "The min and max height of the agenda window as a fraction of frame height.
1027 The value of the variable is a cons cell with two numbers between 0 and 1.
1028 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1029 :group 'org-agenda-windows
1030 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1032 (defcustom org-agenda-restore-windows-after-quit nil
1033 "Non-nil means restore window configuration upon exiting agenda.
1034 Before the window configuration is changed for displaying the agenda,
1035 the current status is recorded. When the agenda is exited with
1036 `q' or `x' and this option is set, the old state is restored. If
1037 `org-agenda-window-setup' is `other-frame', the value of this
1038 option will be ignored."
1039 :group 'org-agenda-windows
1040 :type 'boolean)
1042 (defcustom org-agenda-ndays nil
1043 "Number of days to include in overview display.
1044 Should be 1 or 7.
1045 Obsolete, see `org-agenda-span'."
1046 :group 'org-agenda-daily/weekly
1047 :type 'integer)
1049 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1051 (defcustom org-agenda-span 'week
1052 "Number of days to include in overview display.
1053 Can be day, week, month, year, or any number of days.
1054 Custom commands can set this variable in the options section."
1055 :group 'org-agenda-daily/weekly
1056 :type '(choice (const :tag "Day" day)
1057 (const :tag "Week" week)
1058 (const :tag "Month" month)
1059 (const :tag "Year" year)
1060 (integer :tag "Custom")))
1062 (defcustom org-agenda-start-on-weekday 1
1063 "Non-nil means start the overview always on the specified weekday.
1064 0 denotes Sunday, 1 denotes Monday etc.
1065 When nil, always start on the current day.
1066 Custom commands can set this variable in the options section."
1067 :group 'org-agenda-daily/weekly
1068 :type '(choice (const :tag "Today" nil)
1069 (integer :tag "Weekday No.")))
1071 (defcustom org-agenda-show-all-dates t
1072 "Non-nil means `org-agenda' shows every day in the selected range.
1073 When nil, only the days which actually have entries are shown."
1074 :group 'org-agenda-daily/weekly
1075 :type 'boolean)
1077 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1078 "Format string for displaying dates in the agenda.
1079 Used by the daily/weekly agenda and by the timeline. This should be
1080 a format string understood by `format-time-string', or a function returning
1081 the formatted date as a string. The function must take a single argument,
1082 a calendar-style date list like (month day year)."
1083 :group 'org-agenda-daily/weekly
1084 :type '(choice
1085 (string :tag "Format string")
1086 (function :tag "Function")))
1088 (defun org-agenda-format-date-aligned (date)
1089 "Format a date string for display in the daily/weekly agenda, or timeline.
1090 This function makes sure that dates are aligned for easy reading."
1091 (require 'cal-iso)
1092 (let* ((dayname (calendar-day-name date))
1093 (day (cadr date))
1094 (day-of-week (calendar-day-of-week date))
1095 (month (car date))
1096 (monthname (calendar-month-name month))
1097 (year (nth 2 date))
1098 (iso-week (org-days-to-iso-week
1099 (calendar-absolute-from-gregorian date)))
1100 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1101 (1- year))
1102 ((and (= month 12) (<= iso-week 1))
1103 (1+ year))
1104 (t year)))
1105 (weekstring (if (= day-of-week 1)
1106 (format " W%02d" iso-week)
1107 "")))
1108 (format "%-10s %2d %s %4d%s"
1109 dayname day monthname year weekstring)))
1111 (defcustom org-agenda-time-leading-zero nil
1112 "Non-nil means use leading zero for military times in agenda.
1113 For example, 9:30am would become 09:30 rather than 9:30."
1114 :group 'org-agenda-daily/weekly
1115 :version "24.1"
1116 :type 'boolean)
1118 (defcustom org-agenda-timegrid-use-ampm nil
1119 "When set, show AM/PM style timestamps on the timegrid."
1120 :group 'org-agenda
1121 :version "24.1"
1122 :type 'boolean)
1124 (defun org-agenda-time-of-day-to-ampm (time)
1125 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1126 (let* ((hour-number (string-to-number (substring time 0 -3)))
1127 (minute (substring time -2))
1128 (ampm "am"))
1129 (cond
1130 ((equal hour-number 12)
1131 (setq ampm "pm"))
1132 ((> hour-number 12)
1133 (setq ampm "pm")
1134 (setq hour-number (- hour-number 12))))
1135 (concat
1136 (if org-agenda-time-leading-zero
1137 (format "%02d" hour-number)
1138 (format "%02s" (number-to-string hour-number)))
1139 ":" minute ampm)))
1141 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1142 "Conditionally convert TIME to AM/PM format
1143 based on `org-agenda-timegrid-use-ampm'"
1144 (if org-agenda-timegrid-use-ampm
1145 (org-agenda-time-of-day-to-ampm time)
1146 time))
1148 (defcustom org-agenda-weekend-days '(6 0)
1149 "Which days are weekend?
1150 These days get the special face `org-agenda-date-weekend' in the agenda
1151 and timeline buffers."
1152 :group 'org-agenda-daily/weekly
1153 :type '(set :greedy t
1154 (const :tag "Monday" 1)
1155 (const :tag "Tuesday" 2)
1156 (const :tag "Wednesday" 3)
1157 (const :tag "Thursday" 4)
1158 (const :tag "Friday" 5)
1159 (const :tag "Saturday" 6)
1160 (const :tag "Sunday" 0)))
1162 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1163 "Non-nil means jump to today when moving a past date forward in time.
1164 When using S-right in the agenda to move a a date forward, and the date
1165 stamp currently points to the past, the first key press will move it
1166 to today. WHen nil, just move one day forward even if the date stays
1167 in the past."
1168 :group 'org-agenda-daily/weekly
1169 :version "24.1"
1170 :type 'boolean)
1172 (defcustom org-agenda-include-diary nil
1173 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1174 Custom commands can set this variable in the options section."
1175 :group 'org-agenda-daily/weekly
1176 :type 'boolean)
1178 (defcustom org-agenda-include-deadlines t
1179 "If non-nil, include entries within their deadline warning period.
1180 Custom commands can set this variable in the options section."
1181 :group 'org-agenda-daily/weekly
1182 :version "24.1"
1183 :type 'boolean)
1185 (defcustom org-agenda-repeating-timestamp-show-all t
1186 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1187 When set to a list of strings, only show occurrences of repeating
1188 stamps for these TODO keywords. When nil, only one occurrence is
1189 shown, either today or the nearest into the future."
1190 :group 'org-agenda-daily/weekly
1191 :type '(choice
1192 (const :tag "Show repeating stamps" t)
1193 (repeat :tag "Show repeating stamps for these TODO keywords"
1194 (string :tag "TODO Keyword"))
1195 (const :tag "Don't show repeating stamps" nil)))
1197 (defcustom org-scheduled-past-days 10000
1198 "No. of days to continue listing scheduled items that are not marked DONE.
1199 When an item is scheduled on a date, it shows up in the agenda on this
1200 day and will be listed until it is marked done for the number of days
1201 given here."
1202 :group 'org-agenda-daily/weekly
1203 :type 'integer)
1205 (defcustom org-agenda-log-mode-items '(closed clock)
1206 "List of items that should be shown in agenda log mode.
1207 This list may contain the following symbols:
1209 closed Show entries that have been closed on that day.
1210 clock Show entries that have received clocked time on that day.
1211 state Show all logged state changes.
1212 Note that instead of changing this variable, you can also press `C-u l' in
1213 the agenda to display all available LOG items temporarily."
1214 :group 'org-agenda-daily/weekly
1215 :type '(set :greedy t (const closed) (const clock) (const state)))
1217 (defcustom org-agenda-clock-consistency-checks
1218 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1219 :gap-ok-around ("4:00")
1220 :default-face ((:background "DarkRed") (:foreground "white"))
1221 :overlap-face nil :gap-face nil :no-end-time-face nil
1222 :long-face nil :short-face nil)
1223 "This is a property list, with the following keys:
1225 :max-duration Mark clocking chunks that are longer than this time.
1226 This is a time string like \"HH:MM\", or the number
1227 of minutes as an integer.
1229 :min-duration Mark clocking chunks that are shorter that this.
1230 This is a time string like \"HH:MM\", or the number
1231 of minutes as an integer.
1233 :max-gap Mark gaps between clocking chunks that are longer than
1234 this duration. A number of minutes, or a string
1235 like \"HH:MM\".
1237 :gap-ok-around List of times during the day which are usually not working
1238 times. When a gap is detected, but the gap contains any
1239 of these times, the gap is *not* reported. For example,
1240 if this is (\"4:00\" \"13:00\") then gaps that contain
1241 4:00 in the morning (i.e. the night) and 13:00
1242 (i.e. a typical lunch time) do not cause a warning.
1243 You should have at least one time during the night in this
1244 list, or otherwise the first task each morning will trigger
1245 a warning because it follows a long gap.
1247 Furthermore, the following properties can be used to define faces for
1248 issue display.
1250 :default-face the default face, if the specific face is undefined
1251 :overlap-face face for overlapping clocks
1252 :gap-face face for gaps between clocks
1253 :no-end-time-face face for incomplete clocks
1254 :long-face face for clock intervals that are too long
1255 :short-face face for clock intervals that are too short"
1256 :group 'org-agenda-daily/weekly
1257 :group 'org-clock
1258 :version "24.1"
1259 :type 'plist)
1261 (defcustom org-agenda-log-mode-add-notes t
1262 "Non-nil means add first line of notes to log entries in agenda views.
1263 If a log item like a state change or a clock entry is associated with
1264 notes, the first line of these notes will be added to the entry in the
1265 agenda display."
1266 :group 'org-agenda-daily/weekly
1267 :type 'boolean)
1269 (defcustom org-agenda-start-with-log-mode nil
1270 "The initial value of log-mode in a newly created agenda window.
1271 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1272 explanations on the possible values."
1273 :group 'org-agenda-startup
1274 :group 'org-agenda-daily/weekly
1275 :type '(choice (const :tag "Don't show log items" nil)
1276 (const :tag "Show only log items" 'only)
1277 (const :tag "Show all possible log items" 'clockcheck)
1278 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1279 (choice (const :tag "Show closed log items" 'closed)
1280 (const :tag "Show clocked log items" 'clock)
1281 (const :tag "Show all logged state changes" 'state)))))
1283 (defcustom org-agenda-start-with-clockreport-mode nil
1284 "The initial value of clockreport-mode in a newly created agenda window."
1285 :group 'org-agenda-startup
1286 :group 'org-agenda-daily/weekly
1287 :type 'boolean)
1289 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1290 "Property list with parameters for the clocktable in clockreport mode.
1291 This is the display mode that shows a clock table in the daily/weekly
1292 agenda, the properties for this dynamic block can be set here.
1293 The usual clocktable parameters are allowed here, but you cannot set
1294 the properties :name, :tstart, :tend, :block, and :scope - these will
1295 be overwritten to make sure the content accurately reflects the
1296 current display in the agenda."
1297 :group 'org-agenda-daily/weekly
1298 :type 'plist)
1300 (defcustom org-agenda-search-view-always-boolean nil
1301 "Non-nil means the search string is interpreted as individual parts.
1303 The search string for search view can either be interpreted as a phrase,
1304 or as a list of snippets that define a boolean search for a number of
1305 strings.
1307 When this is non-nil, the string will be split on whitespace, and each
1308 snippet will be searched individually, and all must match in order to
1309 select an entry. A snippet is then a single string of non-white
1310 characters, or a string in double quotes, or a regexp in {} braces.
1311 If a snippet is preceded by \"-\", the snippet must *not* match.
1312 \"+\" is syntactic sugar for positive selection. Each snippet may
1313 be found as a full word or a partial word, but see the variable
1314 `org-agenda-search-view-force-full-words'.
1316 When this is nil, search will look for the entire search phrase as one,
1317 with each space character matching any amount of whitespace, including
1318 line breaks.
1320 Even when this is nil, you can still switch to Boolean search dynamically
1321 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1322 is a regexp marked with braces like \"{abc}\", this will also switch to
1323 boolean search."
1324 :group 'org-agenda-search-view
1325 :version "24.1"
1326 :type 'boolean)
1328 (if (fboundp 'defvaralias)
1329 (defvaralias 'org-agenda-search-view-search-words-only
1330 'org-agenda-search-view-always-boolean))
1332 (defcustom org-agenda-search-view-force-full-words nil
1333 "Non-nil means, search words must be matches as complete words.
1334 When nil, they may also match part of a word."
1335 :group 'org-agenda-search-view
1336 :version "24.1"
1337 :type 'boolean)
1339 (defcustom org-agenda-search-view-max-outline-level nil
1340 "Maximum outline level to display in search view.
1341 E.g. when this is set to 1, the search view will only
1342 show headlines of level 1."
1343 :group 'org-agenda-search-view
1344 :version "24.3"
1345 :type 'integer)
1347 (defgroup org-agenda-time-grid nil
1348 "Options concerning the time grid in the Org-mode Agenda."
1349 :tag "Org Agenda Time Grid"
1350 :group 'org-agenda)
1352 (defcustom org-agenda-search-headline-for-time t
1353 "Non-nil means search headline for a time-of-day.
1354 If the headline contains a time-of-day in one format or another, it will
1355 be used to sort the entry into the time sequence of items for a day.
1356 Some people have time stamps in the headline that refer to the creation
1357 time or so, and then this produces an unwanted side effect. If this is
1358 the case for your, use this variable to turn off searching the headline
1359 for a time."
1360 :group 'org-agenda-time-grid
1361 :type 'boolean)
1363 (defcustom org-agenda-use-time-grid t
1364 "Non-nil means show a time grid in the agenda schedule.
1365 A time grid is a set of lines for specific times (like every two hours between
1366 8:00 and 20:00). The items scheduled for a day at specific times are
1367 sorted in between these lines.
1368 For details about when the grid will be shown, and what it will look like, see
1369 the variable `org-agenda-time-grid'."
1370 :group 'org-agenda-time-grid
1371 :type 'boolean)
1373 (defcustom org-agenda-time-grid
1374 '((daily today require-timed)
1375 "----------------"
1376 (800 1000 1200 1400 1600 1800 2000))
1378 "The settings for time grid for agenda display.
1379 This is a list of three items. The first item is again a list. It contains
1380 symbols specifying conditions when the grid should be displayed:
1382 daily if the agenda shows a single day
1383 weekly if the agenda shows an entire week
1384 today show grid on current date, independent of daily/weekly display
1385 require-timed show grid only if at least one item has a time specification
1387 The second item is a string which will be placed behind the grid time.
1389 The third item is a list of integers, indicating the times that should have
1390 a grid line."
1391 :group 'org-agenda-time-grid
1392 :type
1393 '(list
1394 (set :greedy t :tag "Grid Display Options"
1395 (const :tag "Show grid in single day agenda display" daily)
1396 (const :tag "Show grid in weekly agenda display" weekly)
1397 (const :tag "Always show grid for today" today)
1398 (const :tag "Show grid only if any timed entries are present"
1399 require-timed)
1400 (const :tag "Skip grid times already present in an entry"
1401 remove-match))
1402 (string :tag "Grid String")
1403 (repeat :tag "Grid Times" (integer :tag "Time"))))
1405 (defcustom org-agenda-show-current-time-in-grid t
1406 "Non-nil means show the current time in the time grid."
1407 :group 'org-agenda-time-grid
1408 :version "24.1"
1409 :type 'boolean)
1411 (defcustom org-agenda-current-time-string
1412 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1413 "The string for the current time marker in the agenda."
1414 :group 'org-agenda-time-grid
1415 :version "24.1"
1416 :type 'string)
1418 (defgroup org-agenda-sorting nil
1419 "Options concerning sorting in the Org-mode Agenda."
1420 :tag "Org Agenda Sorting"
1421 :group 'org-agenda)
1423 (defcustom org-agenda-sorting-strategy
1424 '((agenda habit-down time-up priority-down category-keep)
1425 (todo priority-down category-keep)
1426 (tags priority-down category-keep)
1427 (search category-keep))
1428 "Sorting structure for the agenda items of a single day.
1429 This is a list of symbols which will be used in sequence to determine
1430 if an entry should be listed before another entry. The following
1431 symbols are recognized:
1433 time-up Put entries with time-of-day indications first, early first
1434 time-down Put entries with time-of-day indications first, late first
1435 timestamp-up Sort by any timestamp, early first
1436 timestamp-down Sort by any timestamp, late first
1437 scheduled-up Sort by scheduled timestamp, early first
1438 scheduled-down Sort by scheduled timestamp, late first
1439 deadline-up Sort by deadline timestamp, early first
1440 deadline-down Sort by deadline timestamp, late first
1441 ts-up Sort by active timestamp, early first
1442 ts-down Sort by active timestamp, late first
1443 tsia-up Sort by inactive timestamp, early first
1444 tsia-down Sort by inactive timestamp, late first
1445 category-keep Keep the default order of categories, corresponding to the
1446 sequence in `org-agenda-files'.
1447 category-up Sort alphabetically by category, A-Z.
1448 category-down Sort alphabetically by category, Z-A.
1449 tag-up Sort alphabetically by last tag, A-Z.
1450 tag-down Sort alphabetically by last tag, Z-A.
1451 priority-up Sort numerically by priority, high priority last.
1452 priority-down Sort numerically by priority, high priority first.
1453 todo-state-up Sort by todo state, tasks that are done last.
1454 todo-state-down Sort by todo state, tasks that are done first.
1455 effort-up Sort numerically by estimated effort, high effort last.
1456 effort-down Sort numerically by estimated effort, high effort first.
1457 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1458 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1459 habit-up Put entries that are habits first
1460 habit-down Put entries that are habits last
1461 alpha-up Sort headlines alphabetically
1462 alpha-down Sort headlines alphabetically, reversed
1464 The different possibilities will be tried in sequence, and testing stops
1465 if one comparison returns a \"not-equal\". For example, the default
1466 '(time-up category-keep priority-down)
1467 means: Pull out all entries having a specified time of day and sort them,
1468 in order to make a time schedule for the current day the first thing in the
1469 agenda listing for the day. Of the entries without a time indication, keep
1470 the grouped in categories, don't sort the categories, but keep them in
1471 the sequence given in `org-agenda-files'. Within each category sort by
1472 priority.
1474 Leaving out `category-keep' would mean that items will be sorted across
1475 categories by priority.
1477 Instead of a single list, this can also be a set of list for specific
1478 contents, with a context symbol in the car of the list, any of
1479 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1481 Custom commands can bind this variable in the options section."
1482 :group 'org-agenda-sorting
1483 :type `(choice
1484 (repeat :tag "General" ,org-sorting-choice)
1485 (list :tag "Individually"
1486 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1487 (repeat ,org-sorting-choice))
1488 (cons (const :tag "Strategy for TODO lists" todo)
1489 (repeat ,org-sorting-choice))
1490 (cons (const :tag "Strategy for Tags matches" tags)
1491 (repeat ,org-sorting-choice))
1492 (cons (const :tag "Strategy for search matches" search)
1493 (repeat ,org-sorting-choice)))))
1495 (defcustom org-agenda-cmp-user-defined nil
1496 "A function to define the comparison `user-defined'.
1497 This function must receive two arguments, agenda entry a and b.
1498 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1499 the user comparison, return nil.
1500 When this is defined, you can make `user-defined-up' and `user-defined-down'
1501 part of an agenda sorting strategy."
1502 :group 'org-agenda-sorting
1503 :type 'symbol)
1505 (defcustom org-sort-agenda-notime-is-late t
1506 "Non-nil means items without time are considered late.
1507 This is only relevant for sorting. When t, items which have no explicit
1508 time like 15:30 will be considered as 99:01, i.e. later than any items which
1509 do have a time. When nil, the default time is before 0:00. You can use this
1510 option to decide if the schedule for today should come before or after timeless
1511 agenda entries."
1512 :group 'org-agenda-sorting
1513 :type 'boolean)
1515 (defcustom org-sort-agenda-noeffort-is-high t
1516 "Non-nil means items without effort estimate are sorted as high effort.
1517 This also applies when filtering an agenda view with respect to the
1518 < or > effort operator. Then, tasks with no effort defined will be treated
1519 as tasks with high effort.
1520 When nil, such items are sorted as 0 minutes effort."
1521 :group 'org-agenda-sorting
1522 :type 'boolean)
1524 (defgroup org-agenda-line-format nil
1525 "Options concerning the entry prefix in the Org-mode agenda display."
1526 :tag "Org Agenda Line Format"
1527 :group 'org-agenda)
1529 (defcustom org-agenda-prefix-format
1530 '((agenda . " %i %-12:c%?-12t% s")
1531 (timeline . " % s")
1532 (todo . " %i %-12:c")
1533 (tags . " %i %-12:c")
1534 (search . " %i %-12:c"))
1535 "Format specifications for the prefix of items in the agenda views.
1536 An alist with five entries, each for the different agenda types. The
1537 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1538 The values are format strings.
1540 This format works similar to a printf format, with the following meaning:
1542 %c the category of the item, \"Diary\" for entries from the diary,
1543 or as given by the CATEGORY keyword or derived from the file name
1544 %e the effort required by the item
1545 %l the level of the item (insert X space(s) if item is of level X)
1546 %i the icon category of the item, see `org-agenda-category-icon-alist'
1547 %T the last tag of the item (ignore inherited tags, which come first)
1548 %t the HH:MM time-of-day specification if one applies to the entry
1549 %s Scheduling/Deadline information, a short string
1550 %b show breadcrumbs, i.e., the names of the higher levels
1551 %(expression) Eval EXPRESSION and replace the control string
1552 by the result
1554 All specifiers work basically like the standard `%s' of printf, but may
1555 contain two additional characters: a question mark just after the `%'
1556 and a whitespace/punctuation character just before the final letter.
1558 If the first character after `%' is a question mark, the entire field
1559 will only be included if the corresponding value applies to the current
1560 entry. This is useful for fields which should have fixed width when
1561 present, but zero width when absent. For example, \"%?-12t\" will
1562 result in a 12 character time field if a time of the day is specified,
1563 but will completely disappear in entries which do not contain a time.
1565 If there is punctuation or whitespace character just before the final
1566 format letter, this character will be appended to the field value if
1567 the value is not empty. For example, the format \"%-12:c\" leads to
1568 \"Diary: \" if the category is \"Diary\". If the category were be
1569 empty, no additional colon would be inserted.
1571 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1572 which means:
1574 - Indent the line with two space characters
1575 - Give the category a 12 chars wide field, padded with whitespace on
1576 the right (because of `-'). Append a colon if there is a category
1577 (because of `:').
1578 - If there is a time-of-day, put it into a 12 chars wide field. If no
1579 time, don't put in an empty field, just skip it (because of '?').
1580 - Finally, put the scheduling information.
1582 See also the variables `org-agenda-remove-times-when-in-prefix' and
1583 `org-agenda-remove-tags'.
1585 Custom commands can set this variable in the options section."
1586 :type '(choice
1587 (string :tag "General format")
1588 (list :greedy t :tag "View dependent"
1589 (cons (const agenda) (string :tag "Format"))
1590 (cons (const timeline) (string :tag "Format"))
1591 (cons (const todo) (string :tag "Format"))
1592 (cons (const tags) (string :tag "Format"))
1593 (cons (const search) (string :tag "Format"))))
1594 :group 'org-agenda-line-format)
1596 (defvar org-prefix-format-compiled nil
1597 "The compiled prefix format and associated variables.
1598 This is a list where first element is a list of variable bindings, and second
1599 element is the compiled format expression. See the variable
1600 `org-agenda-prefix-format'.")
1602 (defcustom org-agenda-todo-keyword-format "%-1s"
1603 "Format for the TODO keyword in agenda lines.
1604 Set this to something like \"%-12s\" if you want all TODO keywords
1605 to occupy a fixed space in the agenda display."
1606 :group 'org-agenda-line-format
1607 :type 'string)
1609 (defcustom org-agenda-diary-sexp-prefix nil
1610 "A regexp that matches part of a diary sexp entry
1611 which should be treated as scheduling/deadline information in
1612 `org-agenda'.
1614 For example, you can use this to extract the `diary-remind-message' from
1615 `diary-remind' entries."
1616 :group 'org-agenda-line-format
1617 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1619 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1620 "Text preceding timerange entries in the agenda view.
1621 This is a list with two strings. The first applies when the range
1622 is entirely on one day. The second applies if the range spans several days.
1623 The strings may have two \"%d\" format specifiers which will be filled
1624 with the sequence number of the days, and the total number of days in the
1625 range, respectively."
1626 :group 'org-agenda-line-format
1627 :type '(list
1628 (string :tag "Deadline today ")
1629 (choice :tag "Deadline relative"
1630 (string :tag "Format string")
1631 (function))))
1633 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1634 "Text preceding scheduled items in the agenda view.
1635 This is a list with two strings. The first applies when the item is
1636 scheduled on the current day. The second applies when it has been scheduled
1637 previously, it may contain a %d indicating that this is the nth time that
1638 this item is scheduled, due to automatic rescheduling of unfinished items
1639 for the following day. So this number is one larger than the number of days
1640 that passed since this item was scheduled first."
1641 :group 'org-agenda-line-format
1642 :type '(list
1643 (string :tag "Scheduled today ")
1644 (string :tag "Scheduled previously")))
1646 (defcustom org-agenda-inactive-leader "["
1647 "Text preceding item pulled into the agenda by inactive time stamps.
1648 These entries are added to the agenda when pressing \"[\"."
1649 :group 'org-agenda-line-format
1650 :version "24.1"
1651 :type '(list
1652 (string :tag "Scheduled today ")
1653 (string :tag "Scheduled previously")))
1655 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1656 "Text preceding deadline items in the agenda view.
1657 This is a list with two strings. The first applies when the item has its
1658 deadline on the current day. The second applies when it is in the past or
1659 in the future, it may contain %d to capture how many days away the deadline
1660 is (was)."
1661 :group 'org-agenda-line-format
1662 :type '(list
1663 (string :tag "Deadline today ")
1664 (choice :tag "Deadline relative"
1665 (string :tag "Format string")
1666 (function))))
1668 (defcustom org-agenda-remove-times-when-in-prefix t
1669 "Non-nil means remove duplicate time specifications in agenda items.
1670 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1671 time-of-day specification in a headline or diary entry is extracted and
1672 placed into the prefix. If this option is non-nil, the original specification
1673 \(a timestamp or -range, or just a plain time(range) specification like
1674 11:30-4pm) will be removed for agenda display. This makes the agenda less
1675 cluttered.
1676 The option can be t or nil. It may also be the symbol `beg', indicating
1677 that the time should only be removed when it is located at the beginning of
1678 the headline/diary entry."
1679 :group 'org-agenda-line-format
1680 :type '(choice
1681 (const :tag "Always" t)
1682 (const :tag "Never" nil)
1683 (const :tag "When at beginning of entry" beg)))
1685 (defcustom org-agenda-remove-timeranges-from-blocks nil
1686 "Non-nil means remove time ranges specifications in agenda
1687 items that span on several days."
1688 :group 'org-agenda-line-format
1689 :version "24.1"
1690 :type 'boolean)
1692 (defcustom org-agenda-default-appointment-duration nil
1693 "Default duration for appointments that only have a starting time.
1694 When nil, no duration is specified in such cases.
1695 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1696 :group 'org-agenda-line-format
1697 :type '(choice
1698 (integer :tag "Minutes")
1699 (const :tag "No default duration")))
1701 (defcustom org-agenda-show-inherited-tags t
1702 "Non-nil means show inherited tags in each agenda line.
1704 When this option is set to 'always, it take precedences over
1705 `org-agenda-use-tag-inheritance' and inherited tags are shown
1706 in every agenda.
1708 When this option is set to t (the default), inherited tags are
1709 shown when they are available, i.e. when the value of
1710 `org-agenda-use-tag-inheritance' has been taken into account.
1712 This can be set to a list of agenda types in which the agenda
1713 must display the inherited tags. Available types are 'todo,
1714 'agenda, 'search and 'timeline.
1716 When set to nil, never show inherited tags in agenda lines."
1717 :group 'org-agenda-line-format
1718 :group 'org-agenda
1719 :version "24.3"
1720 :type '(choice
1721 (const :tag "Show inherited tags when available" t)
1722 (const :tag "Always show inherited tags" 'always)
1723 (repeat :tag "Show inherited tags only in selected agenda types"
1724 (symbol :tag "Agenda type"))))
1726 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1727 "List of agenda view types where to use tag inheritance.
1729 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1730 controlled by `org-use-tag-inheritance'. In other agenda types,
1731 `org-use-tag-inheritance' is not used for the selection of the
1732 agenda entries. Still, you may want the agenda to be aware of
1733 the inherited tags anyway, e.g. for later tag filtering.
1735 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1737 This variable has no effect if `org-agenda-show-inherited-tags'
1738 is set to 'always. In that case, the agenda is aware of those
1739 tags.
1741 The default value sets tags in every agenda type. Setting this
1742 option to nil will speed up non-tags agenda view a lot."
1743 :group 'org-agenda
1744 :version "24.3"
1745 :type '(choice
1746 (const :tag "Use tag inheritance in all agenda types" t)
1747 (repeat :tag "Use tag inheritance in selected agenda types"
1748 (symbol :tag "Agenda type"))))
1750 (defcustom org-agenda-hide-tags-regexp nil
1751 "Regular expression used to filter away specific tags in agenda views.
1752 This means that these tags will be present, but not be shown in the agenda
1753 line. Secondary filtering will still work on the hidden tags.
1754 Nil means don't hide any tags."
1755 :group 'org-agenda-line-format
1756 :type '(choice
1757 (const :tag "Hide none" nil)
1758 (string :tag "Regexp ")))
1760 (defcustom org-agenda-remove-tags nil
1761 "Non-nil means remove the tags from the headline copy in the agenda.
1762 When this is the symbol `prefix', only remove tags when
1763 `org-agenda-prefix-format' contains a `%T' specifier."
1764 :group 'org-agenda-line-format
1765 :type '(choice
1766 (const :tag "Always" t)
1767 (const :tag "Never" nil)
1768 (const :tag "When prefix format contains %T" prefix)))
1770 (if (fboundp 'defvaralias)
1771 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1772 'org-agenda-remove-tags))
1774 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1775 "Shift tags in agenda items to this column.
1776 If this number is positive, it specifies the column. If it is negative,
1777 it means that the tags should be flushright to that column. For example,
1778 -80 works well for a normal 80 character screen."
1779 :group 'org-agenda-line-format
1780 :type 'integer)
1782 (if (fboundp 'defvaralias)
1783 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1785 (defcustom org-agenda-fontify-priorities 'cookies
1786 "Non-nil means highlight low and high priorities in agenda.
1787 When t, the highest priority entries are bold, lowest priority italic.
1788 However, settings in `org-priority-faces' will overrule these faces.
1789 When this variable is the symbol `cookies', only fontify the
1790 cookies, not the entire task.
1791 This may also be an association list of priority faces, whose
1792 keys are the character values of `org-highest-priority',
1793 `org-default-priority', and `org-lowest-priority' (the default values
1794 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1795 color as a string, or a list like `(:background \"Red\")'.
1796 If it is a color, the variable `org-faces-easy-properties'
1797 determines if it is a foreground or a background color."
1798 :group 'org-agenda-line-format
1799 :type '(choice
1800 (const :tag "Never" nil)
1801 (const :tag "Defaults" t)
1802 (const :tag "Cookies only" cookies)
1803 (repeat :tag "Specify"
1804 (list (character :tag "Priority" :value ?A)
1805 (choice :tag "Face "
1806 (string :tag "Color")
1807 (sexp :tag "Face"))))))
1809 (defcustom org-agenda-day-face-function nil
1810 "Function called to determine what face should be used to display a day.
1811 The only argument passed to that function is the day. It should
1812 returns a face, or nil if does not want to specify a face and let
1813 the normal rules apply."
1814 :group 'org-agenda-line-format
1815 :version "24.1"
1816 :type 'function)
1818 (defcustom org-agenda-category-icon-alist nil
1819 "Alist of category icon to be displayed in agenda views.
1821 Each entry should have the following format:
1823 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1825 Where CATEGORY-REGEXP is a regexp matching the categories where
1826 the icon should be displayed.
1827 FILE-OR-DATA either a file path or a string containing image data.
1829 The other fields can be omitted safely if not needed:
1830 TYPE indicates the image type.
1831 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1832 image data.
1833 PROPS are additional image attributes to assign to the image,
1834 like, e.g. `:ascent center'.
1836 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1838 If you want to set the display properties yourself, just put a
1839 list as second element:
1841 (CATEGORY-REGEXP (MY PROPERTY LIST))
1843 For example, to display a 16px horizontal space for Emacs
1844 category, you can use:
1846 (\"Emacs\" '(space . (:width (16))))"
1847 :group 'org-agenda-line-format
1848 :version "24.1"
1849 :type '(alist :key-type (string :tag "Regexp matching category")
1850 :value-type (choice (list :tag "Icon"
1851 (string :tag "File or data")
1852 (symbol :tag "Type")
1853 (boolean :tag "Data?")
1854 (repeat :tag "Extra image properties" :inline t symbol))
1855 (list :tag "Display properties" sexp))))
1857 (defgroup org-agenda-column-view nil
1858 "Options concerning column view in the agenda."
1859 :tag "Org Agenda Column View"
1860 :group 'org-agenda)
1862 (defcustom org-agenda-columns-show-summaries t
1863 "Non-nil means show summaries for columns displayed in the agenda view."
1864 :group 'org-agenda-column-view
1865 :type 'boolean)
1867 (defcustom org-agenda-columns-compute-summary-properties t
1868 "Non-nil means recompute all summary properties before column view.
1869 When column view in the agenda is listing properties that have a summary
1870 operator, it can go to all relevant buffers and recompute the summaries
1871 there. This can mean overhead for the agenda column view, but is necessary
1872 to have thing up to date.
1873 As a special case, a CLOCKSUM property also makes sure that the clock
1874 computations are current."
1875 :group 'org-agenda-column-view
1876 :type 'boolean)
1878 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1879 "Non-nil means the duration of an appointment will add to day effort.
1880 The property to which appointment durations will be added is the one given
1881 in the option `org-effort-property'. If an appointment does not have
1882 an end time, `org-agenda-default-appointment-duration' will be used. If that
1883 is not set, an appointment without end time will not contribute to the time
1884 estimate."
1885 :group 'org-agenda-column-view
1886 :type 'boolean)
1888 (defcustom org-agenda-auto-exclude-function nil
1889 "A function called with a tag to decide if it is filtered on '/ RET'.
1890 The sole argument to the function, which is called once for each
1891 possible tag, is a string giving the name of the tag. The
1892 function should return either nil if the tag should be included
1893 as normal, or \"-<TAG>\" to exclude the tag.
1894 Note that for the purpose of tag filtering, only the lower-case version of
1895 all tags will be considered, so that this function will only ever see
1896 the lower-case version of all tags."
1897 :group 'org-agenda
1898 :type 'function)
1900 (defcustom org-agenda-bulk-custom-functions nil
1901 "Alist of characters and custom functions for bulk actions.
1902 For example, this value makes those two functions available:
1904 '((?R set-category)
1905 (?C bulk-cut))
1907 With selected entries in an agenda buffer, `B R' will call
1908 the custom function `set-category' on the selected entries.
1909 Note that functions in this alist don't need to be quoted."
1910 :type 'alist
1911 :version "24.1"
1912 :group 'org-agenda)
1914 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1915 "Execute BODY with point at location given by `org-hd-marker' property.
1916 If STRING is non-nil, the text property will be fetched from position 0
1917 in that string. If STRING is nil, it will be fetched from the beginning
1918 of the current line."
1919 (org-with-gensyms (marker)
1920 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1921 'org-hd-marker ,string)))
1922 (with-current-buffer (marker-buffer ,marker)
1923 (save-excursion
1924 (goto-char ,marker)
1925 ,@body)))))
1926 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1928 (defun org-add-agenda-custom-command (entry)
1929 "Replace or add a command in `org-agenda-custom-commands'.
1930 This is mostly for hacking and trying a new command - once the command
1931 works you probably want to add it to `org-agenda-custom-commands' for good."
1932 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1933 (if ass
1934 (setcdr ass (cdr entry))
1935 (push entry org-agenda-custom-commands))))
1937 ;;; Define the org-agenda-mode
1939 (defvar org-agenda-mode-map (make-sparse-keymap)
1940 "Keymap for `org-agenda-mode'.")
1941 (if (fboundp 'defvaralias)
1942 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1944 (defvar org-agenda-menu) ; defined later in this file.
1945 (defvar org-agenda-restrict nil) ; defined later in this file.
1946 (defvar org-agenda-follow-mode nil)
1947 (defvar org-agenda-entry-text-mode nil)
1948 (defvar org-agenda-clockreport-mode nil)
1949 (defvar org-agenda-show-log nil)
1950 (defvar org-agenda-redo-command nil)
1951 (defvar org-agenda-query-string nil)
1952 (defvar org-agenda-mode-hook nil
1953 "Hook run after `org-agenda-mode' is turned on.
1954 The buffer is still writable when this hook is called.")
1955 (defvar org-agenda-type nil)
1956 (defvar org-agenda-force-single-file nil)
1957 (defvar org-agenda-bulk-marked-entries nil
1958 "List of markers that refer to marked entries in the agenda.")
1960 ;;; Multiple agenda buffers support
1962 (defcustom org-agenda-sticky nil
1963 "Non-nil means agenda q key will bury agenda buffers.
1964 Agenda commands will then show existing buffer instead of generating new ones.
1965 When nil, `q' will kill the single agenda buffer."
1966 :group 'org-agenda
1967 :version "24.3"
1968 :type 'boolean)
1971 ;;;###autoload
1972 (defun org-toggle-sticky-agenda (&optional arg)
1973 "Toggle `org-agenda-sticky'."
1974 (interactive "P")
1975 (let ((new-value (if arg
1976 (> (prefix-numeric-value arg) 0)
1977 (not org-agenda-sticky))))
1978 (if (equal new-value org-agenda-sticky)
1979 (and (org-called-interactively-p 'interactive)
1980 (message "Sticky agenda was already %s"
1981 (if org-agenda-sticky "enabled" "disabled")))
1982 (setq org-agenda-sticky new-value)
1983 (org-agenda-kill-all-agenda-buffers)
1984 (and (org-called-interactively-p 'interactive)
1985 (message "Sticky agenda was %s"
1986 (if org-agenda-sticky "enabled" "disabled"))))))
1988 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1989 Toggle `org-agenda-sticky'.
1991 \(fn &optional ARG)" t nil)
1993 (defvar org-agenda-buffer nil
1994 "Agenda buffer currently being generated.")
1996 (defvar org-agenda-last-prefix-arg nil)
1997 (defvar org-agenda-this-buffer-name nil)
1998 (defvar org-agenda-doing-sticky-redo nil)
1999 (defvar org-agenda-this-buffer-is-sticky nil)
2001 (defconst org-agenda-local-vars
2002 '(org-agenda-this-buffer-name
2003 org-agenda-undo-list
2004 org-agenda-pending-undo-list
2005 org-agenda-follow-mode
2006 org-agenda-entry-text-mode
2007 org-agenda-clockreport-mode
2008 org-agenda-show-log
2009 org-agenda-redo-command
2010 org-agenda-query-string
2011 org-agenda-type
2012 org-agenda-bulk-marked-entries
2013 org-agenda-undo-has-started-in
2014 org-agenda-info
2015 org-agenda-tag-filter-overlays
2016 org-agenda-cat-filter-overlays
2017 org-agenda-pre-window-conf
2018 org-agenda-columns-active
2019 org-agenda-tag-filter
2020 org-agenda-category-filter
2021 org-agenda-markers
2022 org-agenda-last-search-view-search-was-boolean
2023 org-agenda-filtered-by-category
2024 org-agenda-filter-form
2025 org-agenda-show-window
2026 org-agenda-cycle-counter
2027 org-agenda-last-prefix-arg)
2028 "Variables that must be local in agenda buffers to allow multiple buffers.")
2030 (defun org-agenda-mode ()
2031 "Mode for time-sorted view on action items in Org-mode files.
2033 The following commands are available:
2035 \\{org-agenda-mode-map}"
2036 (interactive)
2037 (cond (org-agenda-doing-sticky-redo
2038 ;; Refreshing sticky agenda-buffer
2040 ;; Preserve the value of `org-agenda-local-vars' variables,
2041 ;; while letting `kill-all-local-variables' kill the rest
2042 (let ((save (buffer-local-variables)))
2043 (kill-all-local-variables)
2044 (mapc 'make-local-variable org-agenda-local-vars)
2045 (dolist (elem save)
2046 (let ((var (car elem))
2047 (val (cdr elem)))
2048 (when (and val
2049 (member var org-agenda-local-vars))
2050 (set var val)))))
2051 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2052 (org-agenda-sticky
2053 ;; Creating a sticky Agenda buffer for the first time
2054 (kill-all-local-variables)
2055 (mapc 'make-local-variable org-agenda-local-vars)
2056 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2058 ;; Creating a non-sticky agenda buffer
2059 (kill-all-local-variables)
2060 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2061 (setq org-agenda-undo-list nil
2062 org-agenda-pending-undo-list nil
2063 org-agenda-bulk-marked-entries nil)
2064 (setq major-mode 'org-agenda-mode)
2065 ;; Keep global-font-lock-mode from turning on font-lock-mode
2066 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2067 (setq mode-name "Org-Agenda")
2068 (use-local-map org-agenda-mode-map)
2069 (easy-menu-add org-agenda-menu)
2070 (if org-startup-truncated (setq truncate-lines t))
2071 (org-set-local 'line-move-visual nil)
2072 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2073 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2074 ;; Make sure properties are removed when copying text
2075 (make-local-variable 'filter-buffer-substring-functions)
2076 (add-hook 'filter-buffer-substring-functions
2077 (lambda (fun start end delete)
2078 (substring-no-properties (funcall fun start end delete))))
2079 (unless org-agenda-keep-modes
2080 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2081 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2082 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2083 org-agenda-show-log org-agenda-start-with-log-mode))
2085 (easy-menu-change
2086 '("Agenda") "Agenda Files"
2087 (append
2088 (list
2089 (vector
2090 (if (get 'org-agenda-files 'org-restrict)
2091 "Restricted to single file"
2092 "Edit File List")
2093 '(org-edit-agenda-file-list)
2094 (not (get 'org-agenda-files 'org-restrict)))
2095 "--")
2096 (mapcar 'org-file-menu-entry (org-agenda-files))))
2097 (org-agenda-set-mode-name)
2098 (apply
2099 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2100 (list 'org-agenda-mode-hook)))
2102 (substitute-key-definition 'undo 'org-agenda-undo
2103 org-agenda-mode-map global-map)
2104 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2105 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2106 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2107 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2108 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2109 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2110 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2111 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2112 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2113 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2114 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2115 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2116 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2117 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2120 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2121 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2123 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2124 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2125 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2126 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2127 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2128 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2129 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2130 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2131 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2132 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2133 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2134 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2135 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2136 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2137 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2138 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2139 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2140 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2141 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2142 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2143 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2144 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2145 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2146 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2147 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2148 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2149 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2151 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2152 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2153 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2154 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2155 (while l (org-defkey org-agenda-mode-map
2156 (int-to-string (pop l)) 'digit-argument)))
2158 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2159 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2160 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2161 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2162 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2163 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2164 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2165 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2166 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2167 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2168 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2169 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2170 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2171 'org-clock-modify-effort-estimate)
2172 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2173 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2174 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2175 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2176 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2177 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2178 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2179 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2180 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2181 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2182 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2183 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2184 (substitute-key-definition 'next-line 'org-agenda-next-line
2185 org-agenda-mode-map global-map)
2186 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2187 org-agenda-mode-map global-map)
2188 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2189 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2190 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2191 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2192 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2193 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2194 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2195 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2196 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2197 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2198 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2199 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2200 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2201 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2202 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2203 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2204 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2205 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2206 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2207 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2208 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2209 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2210 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2211 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2212 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2213 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2214 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2215 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2216 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2217 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2219 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2220 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2221 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2222 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2223 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2224 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2225 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2226 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2227 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2228 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2229 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2230 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2232 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2233 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2234 (when org-agenda-mouse-1-follows-link
2235 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2236 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2237 '("Agenda"
2238 ("Agenda Files")
2239 "--"
2240 ("Agenda Dates"
2241 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2242 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2243 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2244 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2245 "--"
2246 ("View"
2247 ["Day View" org-agenda-day-view
2248 :active (org-agenda-check-type nil 'agenda)
2249 :style radio :selected (eq org-agenda-current-span 'day)
2250 :keys "v d (or just d)"]
2251 ["Week View" org-agenda-week-view
2252 :active (org-agenda-check-type nil 'agenda)
2253 :style radio :selected (eq org-agenda-current-span 'week)
2254 :keys "v w (or just w)"]
2255 ["Month View" org-agenda-month-view
2256 :active (org-agenda-check-type nil 'agenda)
2257 :style radio :selected (eq org-agenda-current-span 'month)
2258 :keys "v m"]
2259 ["Year View" org-agenda-year-view
2260 :active (org-agenda-check-type nil 'agenda)
2261 :style radio :selected (eq org-agenda-current-span 'year)
2262 :keys "v y"]
2263 "--"
2264 ["Include Diary" org-agenda-toggle-diary
2265 :style toggle :selected org-agenda-include-diary
2266 :active (org-agenda-check-type nil 'agenda)]
2267 ["Include Deadlines" org-agenda-toggle-deadlines
2268 :style toggle :selected org-agenda-include-deadlines
2269 :active (org-agenda-check-type nil 'agenda)]
2270 ["Use Time Grid" org-agenda-toggle-time-grid
2271 :style toggle :selected org-agenda-use-time-grid
2272 :active (org-agenda-check-type nil 'agenda)]
2273 "--"
2274 ["Show clock report" org-agenda-clockreport-mode
2275 :style toggle :selected org-agenda-clockreport-mode
2276 :active (org-agenda-check-type nil 'agenda)]
2277 ["Show some entry text" org-agenda-entry-text-mode
2278 :style toggle :selected org-agenda-entry-text-mode
2279 :active t]
2280 "--"
2281 ["Show Logbook entries" org-agenda-log-mode
2282 :style toggle :selected org-agenda-show-log
2283 :active (org-agenda-check-type nil 'agenda 'timeline)
2284 :keys "v l (or just l)"]
2285 ["Include archived trees" org-agenda-archives-mode
2286 :style toggle :selected org-agenda-archives-mode :active t
2287 :keys "v a"]
2288 ["Include archive files" (org-agenda-archives-mode t)
2289 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2290 :keys "v A"]
2291 "--"
2292 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2293 ["Write view to file" org-agenda-write t]
2294 ["Rebuild buffer" org-agenda-redo t]
2295 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2296 "--"
2297 ["Show original entry" org-agenda-show t]
2298 ["Go To (other window)" org-agenda-goto t]
2299 ["Go To (this window)" org-agenda-switch-to t]
2300 ["Capture with cursor date" org-agenda-capture t]
2301 ["Follow Mode" org-agenda-follow-mode
2302 :style toggle :selected org-agenda-follow-mode :active t]
2303 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2304 "--"
2305 ("TODO"
2306 ["Cycle TODO" org-agenda-todo t]
2307 ["Next TODO set" org-agenda-todo-nextset t]
2308 ["Previous TODO set" org-agenda-todo-previousset t]
2309 ["Add note" org-agenda-add-note t])
2310 ("Archive/Refile/Delete"
2311 ["Archive default" org-agenda-archive-default t]
2312 ["Archive default" org-agenda-archive-default-with-confirmation t]
2313 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2314 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2315 ["Archive subtree" org-agenda-archive t]
2316 "--"
2317 ["Refile" org-agenda-refile t]
2318 "--"
2319 ["Delete subtree" org-agenda-kill t])
2320 ("Bulk action"
2321 ["Mark entry" org-agenda-bulk-mark t]
2322 ["Mark all" org-agenda-bulk-mark-all t]
2323 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2324 ["Unmark entry" org-agenda-bulk-unmark t]
2325 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2326 ["Act on all marked" org-agenda-bulk-action t]
2327 "--"
2328 ("Tags and Properties"
2329 ["Show all Tags" org-agenda-show-tags t]
2330 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2331 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2332 "--"
2333 ["Column View" org-columns t])
2334 ("Deadline/Schedule"
2335 ["Schedule" org-agenda-schedule t]
2336 ["Set Deadline" org-agenda-deadline t]
2337 "--"
2338 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2339 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2340 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2341 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2342 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2343 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2344 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2345 ("Clock and Effort"
2346 ["Clock in" org-agenda-clock-in t]
2347 ["Clock out" org-agenda-clock-out t]
2348 ["Clock cancel" org-agenda-clock-cancel t]
2349 ["Goto running clock" org-clock-goto t]
2350 "--"
2351 ["Set Effort" org-agenda-set-effort t]
2352 ["Change clocked effort" org-clock-modify-effort-estimate
2353 (org-clock-is-active)])
2354 ("Priority"
2355 ["Set Priority" org-agenda-priority t]
2356 ["Increase Priority" org-agenda-priority-up t]
2357 ["Decrease Priority" org-agenda-priority-down t]
2358 ["Show Priority" org-show-priority t])
2359 ("Calendar/Diary"
2360 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2361 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2362 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2363 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2364 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2365 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2366 "--"
2367 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2368 "--"
2369 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2370 "--"
2371 ("MobileOrg"
2372 ["Push Files and Views" org-mobile-push t]
2373 ["Get Captured and Flagged" org-mobile-pull t]
2374 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2375 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2376 "--"
2377 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2378 "--"
2379 ["Quit" org-agenda-quit t]
2380 ["Exit and Release Buffers" org-agenda-exit t]
2383 ;;; Agenda undo
2385 (defvar org-agenda-allow-remote-undo t
2386 "Non-nil means allow remote undo from the agenda buffer.")
2387 (defvar org-agenda-undo-has-started-in nil
2388 "Buffers that have already seen `undo-start' in the current undo sequence.")
2390 (defun org-agenda-undo ()
2391 "Undo a remote editing step in the agenda.
2392 This undoes changes both in the agenda buffer and in the remote buffer
2393 that have been changed along."
2394 (interactive)
2395 (or org-agenda-allow-remote-undo
2396 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2397 (if (not (eq this-command last-command))
2398 (setq org-agenda-undo-has-started-in nil
2399 org-agenda-pending-undo-list org-agenda-undo-list))
2400 (if (not org-agenda-pending-undo-list)
2401 (error "No further undo information"))
2402 (let* ((entry (pop org-agenda-pending-undo-list))
2403 buf line cmd rembuf)
2404 (setq cmd (pop entry) line (pop entry))
2405 (setq rembuf (nth 2 entry))
2406 (org-with-remote-undo rembuf
2407 (while (bufferp (setq buf (pop entry)))
2408 (if (pop entry)
2409 (with-current-buffer buf
2410 (let ((last-undo-buffer buf)
2411 (inhibit-read-only t))
2412 (unless (memq buf org-agenda-undo-has-started-in)
2413 (push buf org-agenda-undo-has-started-in)
2414 (make-local-variable 'pending-undo-list)
2415 (undo-start))
2416 (while (and pending-undo-list
2417 (listp pending-undo-list)
2418 (not (car pending-undo-list)))
2419 (pop pending-undo-list))
2420 (undo-more 1))))))
2421 (org-goto-line line)
2422 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2424 (defun org-verify-change-for-undo (l1 l2)
2425 "Verify that a real change occurred between the undo lists L1 and L2."
2426 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2427 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2428 (not (eq l1 l2)))
2430 ;;; Agenda dispatch
2432 (defvar org-agenda-restrict-begin (make-marker))
2433 (defvar org-agenda-restrict-end (make-marker))
2434 (defvar org-agenda-last-dispatch-buffer nil)
2435 (defvar org-agenda-overriding-restriction nil)
2437 (defcustom org-agenda-custom-commands-contexts nil
2438 "Alist of custom agenda keys and contextual rules.
2440 For example, if you have a custom agenda command \"p\" and you
2441 want this command to be accessible only from plain text files,
2442 use this:
2444 '((\"p\" ((in-file . \"\\.txt\"))))
2446 Here are the available contexts definitions:
2448 in-file: command displayed only in matching files
2449 in-mode: command displayed only in matching modes
2450 not-in-file: command not displayed in matching files
2451 not-in-mode: command not displayed in matching modes
2452 in-buffer: command displayed only in matching buffers
2453 not-in-buffer: command not displayed in matching buffers
2454 [function]: a custom function taking no argument
2456 If you define several checks, the agenda command will be
2457 accessible if there is at least one valid check.
2459 You can also bind a key to another agenda custom command
2460 depending on contextual rules.
2462 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2464 Here it means: in .txt files, use \"p\" as the key for the
2465 agenda command otherwise associated with \"q\". (The command
2466 originally associated with \"q\" is not displayed to avoid
2467 duplicates.)"
2468 :version "24.3"
2469 :group 'org-agenda-custom-commands
2470 :type '(repeat (list :tag "Rule"
2471 (string :tag " Agenda key")
2472 (string :tag "Replace by command")
2473 (repeat :tag "Available when"
2474 (choice
2475 (cons :tag "Condition"
2476 (choice
2477 (const :tag "In file" in-file)
2478 (const :tag "Not in file" not-in-file)
2479 (const :tag "In buffer" in-buffer)
2480 (const :tag "Not in buffer" not-in-buffer)
2481 (const :tag "In mode" in-mode)
2482 (const :tag "Not in mode" not-in-mode))
2483 (regexp))
2484 (function :tag "Custom function"))))))
2486 (defcustom org-agenda-max-entries nil
2487 "Maximum number of entries to display in an agenda.
2488 This can be nil (no limit) or an integer or an alist of agenda
2489 types with an associated number of entries to display in this
2490 type."
2491 :version "24.3"
2492 :group 'org-agenda-custom-commands
2493 :type '(choice (symbol :tag "No limit" nil)
2494 (integer :tag "Max number of entries")
2495 (repeat
2496 (cons (choice :tag "Agenda type"
2497 (const agenda)
2498 (const todo)
2499 (const tags)
2500 (const search)
2501 (const timeline))
2502 (integer :tag "Max number of entries")))))
2504 (defcustom org-agenda-max-todos nil
2505 "Maximum number of TODOs to display in an agenda.
2506 This can be nil (no limit) or an integer or an alist of agenda
2507 types with an associated number of entries to display in this
2508 type."
2509 :version "24.3"
2510 :group 'org-agenda-custom-commands
2511 :type '(choice (symbol :tag "No limit" nil)
2512 (integer :tag "Max number of entries")
2513 (repeat
2514 (cons (choice :tag "Agenda type"
2515 (const agenda)
2516 (const todo)
2517 (const tags)
2518 (const search)
2519 (const timeline))
2520 (integer :tag "Max number of entries")))))
2522 (defcustom org-agenda-max-tags nil
2523 "Maximum number of tagged entries to display in an agenda.
2524 This can be nil (no limit) or an integer or an alist of agenda
2525 types with an associated number of entries to display in this
2526 type."
2527 :version "24.3"
2528 :group 'org-agenda-custom-commands
2529 :type '(choice (symbol :tag "No limit" nil)
2530 (integer :tag "Max number of entries")
2531 (repeat
2532 (cons (choice :tag "Agenda type"
2533 (const agenda)
2534 (const todo)
2535 (const tags)
2536 (const search)
2537 (const timeline))
2538 (integer :tag "Max number of entries")))))
2540 (defcustom org-agenda-max-effort nil
2541 "Maximum cumulated effort duration for the agenda.
2542 This can be nil (no limit) or a number of minutes (as an integer)
2543 or an alist of agenda types with an associated number of minutes
2544 to limit entries to in this type."
2545 :version "24.3"
2546 :group 'org-agenda-custom-commands
2547 :type '(choice (symbol :tag "No limit" nil)
2548 (integer :tag "Max number of entries")
2549 (repeat
2550 (cons (choice :tag "Agenda type"
2551 (const agenda)
2552 (const todo)
2553 (const tags)
2554 (const search)
2555 (const timeline))
2556 (integer :tag "Max number of entries")))))
2558 (defvar org-keys nil)
2559 (defvar org-match nil)
2560 ;;;###autoload
2561 (defun org-agenda (&optional arg org-keys restriction)
2562 "Dispatch agenda commands to collect entries to the agenda buffer.
2563 Prompts for a command to execute. Any prefix arg will be passed
2564 on to the selected command. The default selections are:
2566 a Call `org-agenda-list' to display the agenda for current day or week.
2567 t Call `org-todo-list' to display the global todo list.
2568 T Call `org-todo-list' to display the global todo list, select only
2569 entries with a specific TODO keyword (the user gets a prompt).
2570 m Call `org-tags-view' to display headlines with tags matching
2571 a condition (the user is prompted for the condition).
2572 M Like `m', but select only TODO entries, no ordinary headlines.
2573 L Create a timeline for the current buffer.
2574 e Export views to associated files.
2575 s Search entries for keywords.
2576 S Search entries for keywords, only with TODO keywords.
2577 / Multi occur across all agenda files and also files listed
2578 in `org-agenda-text-search-extra-files'.
2579 < Restrict agenda commands to buffer, subtree, or region.
2580 Press several times to get the desired effect.
2581 > Remove a previous restriction.
2582 # List \"stuck\" projects.
2583 ! Configure what \"stuck\" means.
2584 C Configure custom agenda commands.
2586 More commands can be added by configuring the variable
2587 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2588 searches can be pre-defined in this way.
2590 If the current buffer is in Org-mode and visiting a file, you can also
2591 first press `<' once to indicate that the agenda should be temporarily
2592 \(until the next use of \\[org-agenda]) restricted to the current file.
2593 Pressing `<' twice means to restrict to the current subtree or region
2594 \(if active)."
2595 (interactive "P")
2596 (catch 'exit
2597 (let* ((prefix-descriptions nil)
2598 (org-agenda-buffer-name org-agenda-buffer-name)
2599 (org-agenda-window-setup (if (equal (buffer-name)
2600 org-agenda-buffer-name)
2601 'current-window
2602 org-agenda-window-setup))
2603 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2604 (org-agenda-custom-commands
2605 ;; normalize different versions
2606 (delq nil
2607 (mapcar
2608 (lambda (x)
2609 (cond ((stringp (cdr x))
2610 (push x prefix-descriptions)
2611 nil)
2612 ((stringp (nth 1 x)) x)
2613 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2614 (t (cons (car x) (cons "" (cdr x))))))
2615 org-agenda-custom-commands)))
2616 (org-agenda-custom-commands
2617 (org-contextualize-keys
2618 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2619 (buf (current-buffer))
2620 (bfn (buffer-file-name (buffer-base-buffer)))
2621 entry key type org-match lprops ans)
2622 ;; Turn off restriction unless there is an overriding one,
2623 (unless org-agenda-overriding-restriction
2624 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2625 ;; There is a request to keep the file list in place
2626 (put 'org-agenda-files 'org-restrict nil))
2627 (setq org-agenda-restrict nil)
2628 (move-marker org-agenda-restrict-begin nil)
2629 (move-marker org-agenda-restrict-end nil))
2630 ;; Delete old local properties
2631 (put 'org-agenda-redo-command 'org-lprops nil)
2632 ;; Delete previously set last-arguments
2633 (put 'org-agenda-redo-command 'last-args nil)
2634 ;; Remember where this call originated
2635 (setq org-agenda-last-dispatch-buffer (current-buffer))
2636 (unless org-keys
2637 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2638 org-keys (car ans)
2639 restriction (cdr ans)))
2640 ;; If we have sticky agenda buffers, set a name for the buffer,
2641 ;; depending on the invoking keys. The user may still set this
2642 ;; as a command option, which will overwrite what we do here.
2643 (if org-agenda-sticky
2644 (setq org-agenda-buffer-name
2645 (format "*Org Agenda(%s)*" org-keys)))
2646 ;; Establish the restriction, if any
2647 (when (and (not org-agenda-overriding-restriction) restriction)
2648 (put 'org-agenda-files 'org-restrict (list bfn))
2649 (cond
2650 ((eq restriction 'region)
2651 (setq org-agenda-restrict t)
2652 (move-marker org-agenda-restrict-begin (region-beginning))
2653 (move-marker org-agenda-restrict-end (region-end)))
2654 ((eq restriction 'subtree)
2655 (save-excursion
2656 (setq org-agenda-restrict t)
2657 (org-back-to-heading t)
2658 (move-marker org-agenda-restrict-begin (point))
2659 (move-marker org-agenda-restrict-end
2660 (progn (org-end-of-subtree t)))))))
2662 ;; For example the todo list should not need it (but does...)
2663 (cond
2664 ((setq entry (assoc org-keys org-agenda-custom-commands))
2665 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2666 (progn
2667 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2668 lprops (nth 4 entry))
2669 (if org-agenda-sticky
2670 (setq org-agenda-buffer-name
2671 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2672 (format "*Org Agenda(%s)*" org-keys))))
2673 (put 'org-agenda-redo-command 'org-lprops lprops)
2674 (cond
2675 ((eq type 'agenda)
2676 (org-let lprops '(org-agenda-list current-prefix-arg)))
2677 ((eq type 'alltodo)
2678 (org-let lprops '(org-todo-list current-prefix-arg)))
2679 ((eq type 'search)
2680 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2681 ((eq type 'stuck)
2682 (org-let lprops '(org-agenda-list-stuck-projects
2683 current-prefix-arg)))
2684 ((eq type 'tags)
2685 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2686 ((eq type 'tags-todo)
2687 (org-let lprops '(org-tags-view '(4) org-match)))
2688 ((eq type 'todo)
2689 (org-let lprops '(org-todo-list org-match)))
2690 ((eq type 'tags-tree)
2691 (org-check-for-org-mode)
2692 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2693 ((eq type 'todo-tree)
2694 (org-check-for-org-mode)
2695 (org-let lprops
2696 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2697 (regexp-quote org-match) "\\>"))))
2698 ((eq type 'occur-tree)
2699 (org-check-for-org-mode)
2700 (org-let lprops '(org-occur org-match)))
2701 ((functionp type)
2702 (org-let lprops '(funcall type org-match)))
2703 ((fboundp type)
2704 (org-let lprops '(funcall type org-match)))
2705 (t (error "Invalid custom agenda command type %s" type))))
2706 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2707 ((equal org-keys "C")
2708 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2709 (customize-variable 'org-agenda-custom-commands))
2710 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2711 ((equal org-keys "s") (call-interactively 'org-search-view))
2712 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2713 ((equal org-keys "t") (call-interactively 'org-todo-list))
2714 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2715 ((equal org-keys "m") (call-interactively 'org-tags-view))
2716 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2717 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2718 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2719 (org-add-hook
2720 'post-command-hook
2721 (lambda ()
2722 (unless (current-message)
2723 (let* ((m (org-agenda-get-any-marker))
2724 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2725 (when note
2726 (message (concat
2727 "FLAGGING-NOTE ([?] for more info): "
2728 (org-add-props
2729 (replace-regexp-in-string
2730 "\\\\n" "//"
2731 (copy-sequence note))
2732 nil 'face 'org-warning)))))))
2733 t t))
2734 ((equal org-keys "L")
2735 (unless (derived-mode-p 'org-mode)
2736 (error "This is not an Org-mode file"))
2737 (unless restriction
2738 (put 'org-agenda-files 'org-restrict (list bfn))
2739 (org-call-with-arg 'org-timeline arg)))
2740 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2741 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2742 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2743 (t (error "Invalid agenda key"))))))
2745 (autoload 'org-agenda "org-agenda" "\
2746 Dispatch agenda commands to collect entries to the agenda buffer.
2747 Prompts for a command to execute. Any prefix arg will be passed
2748 on to the selected command. The default selections are:
2750 a Call `org-agenda-list' to display the agenda for current day or week.
2751 t Call `org-todo-list' to display the global todo list.
2752 T Call `org-todo-list' to display the global todo list, select only
2753 entries with a specific TODO keyword (the user gets a prompt).
2754 m Call `org-tags-view' to display headlines with tags matching
2755 a condition (the user is prompted for the condition).
2756 M Like `m', but select only TODO entries, no ordinary headlines.
2757 L Create a timeline for the current buffer.
2758 e Export views to associated files.
2759 s Search entries for keywords.
2760 S Search entries for keywords, only with TODO keywords.
2761 / Multi occur across all agenda files and also files listed
2762 in `org-agenda-text-search-extra-files'.
2763 < Restrict agenda commands to buffer, subtree, or region.
2764 Press several times to get the desired effect.
2765 > Remove a previous restriction.
2766 # List \"stuck\" projects.
2767 ! Configure what \"stuck\" means.
2768 C Configure custom agenda commands.
2770 More commands can be added by configuring the variable
2771 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2772 searches can be pre-defined in this way.
2774 If the current buffer is in Org-mode and visiting a file, you can also
2775 first press `<' once to indicate that the agenda should be temporarily
2776 \(until the next use of \\[org-agenda]) restricted to the current file.
2777 Pressing `<' twice means to restrict to the current subtree or region
2778 \(if active).
2780 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2782 (defun org-agenda-append-agenda ()
2783 "Append another agenda view to the current one.
2784 This function allows interactive building of block agendas.
2785 Agenda views are separated by `org-agenda-block-separator'."
2786 (interactive)
2787 (unless (derived-mode-p 'org-agenda-mode)
2788 (error "Can only append from within agenda buffer"))
2789 (let ((org-agenda-multi t))
2790 (org-agenda)
2791 (widen)
2792 (org-agenda-finalize)
2793 (org-agenda-fit-window-to-buffer)))
2795 (defun org-agenda-normalize-custom-commands (cmds)
2796 (delq nil
2797 (mapcar
2798 (lambda (x)
2799 (cond ((stringp (cdr x)) nil)
2800 ((stringp (nth 1 x)) x)
2801 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2802 (t (cons (car x) (cons "" (cdr x))))))
2803 cmds)))
2805 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2806 "The user interface for selecting an agenda command."
2807 (catch 'exit
2808 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2809 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2810 (region-p (org-region-active-p))
2811 (custom org-agenda-custom-commands)
2812 (selstring "")
2813 restriction second-time
2814 c entry key type match prefixes rmheader header-end custom1 desc
2815 line lines left right n n1)
2816 (save-window-excursion
2817 (delete-other-windows)
2818 (org-switch-to-buffer-other-window " *Agenda Commands*")
2819 (erase-buffer)
2820 (insert (eval-when-compile
2821 (let ((header
2822 "Press key for an agenda command: < Buffer, subtree/region restriction
2823 -------------------------------- > Remove restriction
2824 a Agenda for current week or day e Export agenda views
2825 t List of all TODO entries T Entries with special TODO kwd
2826 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2827 s Search for keywords S Like s, but only TODO entries
2828 L Timeline for current buffer # List stuck projects (!=configure)
2829 / Multi-occur C Configure custom agenda commands
2830 ? Find :FLAGGED: entries * Toggle sticky agenda views
2832 (start 0))
2833 (while (string-match
2834 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2835 header start)
2836 (setq start (match-end 0))
2837 (add-text-properties (match-beginning 2) (match-end 2)
2838 '(face bold) header))
2839 header)))
2840 (setq header-end (point-marker))
2841 (while t
2842 (setq custom1 custom)
2843 (when (eq rmheader t)
2844 (org-goto-line 1)
2845 (re-search-forward ":" nil t)
2846 (delete-region (match-end 0) (point-at-eol))
2847 (forward-char 1)
2848 (looking-at "-+")
2849 (delete-region (match-end 0) (point-at-eol))
2850 (move-marker header-end (match-end 0)))
2851 (goto-char header-end)
2852 (delete-region (point) (point-max))
2854 ;; Produce all the lines that describe custom commands and prefixes
2855 (setq lines nil)
2856 (while (setq entry (pop custom1))
2857 (setq key (car entry) desc (nth 1 entry)
2858 type (nth 2 entry)
2859 match (nth 3 entry))
2860 (if (> (length key) 1)
2861 (add-to-list 'prefixes (string-to-char key))
2862 (setq line
2863 (format
2864 "%-4s%-14s"
2865 (org-add-props (copy-sequence key)
2866 '(face bold))
2867 (cond
2868 ((string-match "\\S-" desc) desc)
2869 ((eq type 'agenda) "Agenda for current week or day")
2870 ((eq type 'alltodo) "List of all TODO entries")
2871 ((eq type 'search) "Word search")
2872 ((eq type 'stuck) "List of stuck projects")
2873 ((eq type 'todo) "TODO keyword")
2874 ((eq type 'tags) "Tags query")
2875 ((eq type 'tags-todo) "Tags (TODO)")
2876 ((eq type 'tags-tree) "Tags tree")
2877 ((eq type 'todo-tree) "TODO kwd tree")
2878 ((eq type 'occur-tree) "Occur tree")
2879 ((functionp type) (if (symbolp type)
2880 (symbol-name type)
2881 "Lambda expression"))
2882 (t "???"))))
2883 (if org-agenda-menu-show-matcher
2884 (setq line
2885 (concat line ": "
2886 (cond
2887 ((stringp match)
2888 (setq match (copy-sequence match))
2889 (org-add-props match nil 'face 'org-warning))
2890 ((listp type)
2891 (format "set of %d commands" (length type))))))
2892 (if (org-string-nw-p match)
2893 (add-text-properties
2894 0 (length line) (list 'help-echo
2895 (concat "Matcher: " match)) line)))
2896 (push line lines)))
2897 (setq lines (nreverse lines))
2898 (when prefixes
2899 (mapc (lambda (x)
2900 (push
2901 (format "%s %s"
2902 (org-add-props (char-to-string x)
2903 nil 'face 'bold)
2904 (or (cdr (assoc (concat selstring
2905 (char-to-string x))
2906 prefix-descriptions))
2907 "Prefix key"))
2908 lines))
2909 prefixes))
2911 ;; Check if we should display in two columns
2912 (if org-agenda-menu-two-columns
2913 (progn
2914 (setq n (length lines)
2915 n1 (+ (/ n 2) (mod n 2))
2916 right (nthcdr n1 lines)
2917 left (copy-sequence lines))
2918 (setcdr (nthcdr (1- n1) left) nil))
2919 (setq left lines right nil))
2920 (while left
2921 (insert "\n" (pop left))
2922 (when right
2923 (if (< (current-column) 40)
2924 (move-to-column 40 t)
2925 (insert " "))
2926 (insert (pop right))))
2928 ;; Make the window the right size
2929 (goto-char (point-min))
2930 (if second-time
2931 (if (not (pos-visible-in-window-p (point-max)))
2932 (org-fit-window-to-buffer))
2933 (setq second-time t)
2934 (org-fit-window-to-buffer))
2936 ;; Ask for selection
2937 (message "Press key for agenda command%s:"
2938 (if (or restrict-ok org-agenda-overriding-restriction)
2939 (if org-agenda-overriding-restriction
2940 " (restriction lock active)"
2941 (if restriction
2942 (format " (restricted to %s)" restriction)
2943 " (unrestricted)"))
2944 ""))
2945 (setq c (read-char-exclusive))
2946 (message "")
2947 (cond
2948 ((assoc (char-to-string c) custom)
2949 (setq selstring (concat selstring (char-to-string c)))
2950 (throw 'exit (cons selstring restriction)))
2951 ((memq c prefixes)
2952 (setq selstring (concat selstring (char-to-string c))
2953 prefixes nil
2954 rmheader (or rmheader t)
2955 custom (delq nil (mapcar
2956 (lambda (x)
2957 (if (or (= (length (car x)) 1)
2958 (/= (string-to-char (car x)) c))
2960 (cons (substring (car x) 1) (cdr x))))
2961 custom))))
2962 ((eq c ?*)
2963 (call-interactively 'org-toggle-sticky-agenda)
2964 (sit-for 2))
2965 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2966 (message "Restriction is only possible in Org-mode buffers")
2967 (ding) (sit-for 1))
2968 ((eq c ?1)
2969 (org-agenda-remove-restriction-lock 'noupdate)
2970 (setq restriction 'buffer))
2971 ((eq c ?0)
2972 (org-agenda-remove-restriction-lock 'noupdate)
2973 (setq restriction (if region-p 'region 'subtree)))
2974 ((eq c ?<)
2975 (org-agenda-remove-restriction-lock 'noupdate)
2976 (setq restriction
2977 (cond
2978 ((eq restriction 'buffer)
2979 (if region-p 'region 'subtree))
2980 ((memq restriction '(subtree region))
2981 nil)
2982 (t 'buffer))))
2983 ((eq c ?>)
2984 (org-agenda-remove-restriction-lock 'noupdate)
2985 (setq restriction nil))
2986 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2987 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2988 ((and (> (length selstring) 0) (eq c ?\d))
2989 (delete-window)
2990 (org-agenda-get-restriction-and-command prefix-descriptions))
2992 ((equal c ?q) (error "Abort"))
2993 (t (error "Invalid key %c" c))))))))
2995 (defun org-agenda-fit-window-to-buffer ()
2996 "Fit the window to the buffer size."
2997 (and (memq org-agenda-window-setup '(reorganize-frame))
2998 (fboundp 'fit-window-to-buffer)
2999 (org-fit-window-to-buffer
3001 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3002 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3004 (defvar org-cmd nil)
3005 (defvar org-agenda-overriding-cmd nil)
3006 (defvar org-agenda-overriding-arguments nil)
3007 (defvar org-agenda-overriding-cmd-arguments nil)
3008 (defun org-agenda-run-series (name series)
3009 (org-let (nth 1 series) '(org-agenda-prepare name))
3010 ;; We need to reset agenda markers here, because when constructing a
3011 ;; block agenda, the individual blocks do not do that.
3012 (org-agenda-reset-markers)
3013 (let* ((org-agenda-multi t)
3014 (redo (list 'org-agenda-run-series name (list 'quote series)))
3015 (cmds (car series))
3016 (gprops (nth 1 series))
3017 match ;; The byte compiler incorrectly complains about this. Keep it!
3018 org-cmd type lprops)
3019 (while (setq org-cmd (pop cmds))
3020 (setq type (car org-cmd)
3021 match (eval (nth 1 org-cmd))
3022 lprops (nth 2 org-cmd))
3023 (let ((org-agenda-overriding-arguments
3024 (if (eq org-agenda-overriding-cmd org-cmd)
3025 (or org-agenda-overriding-arguments
3026 org-agenda-overriding-cmd-arguments))))
3027 (cond
3028 ((eq type 'agenda)
3029 (org-let2 gprops lprops
3030 '(call-interactively 'org-agenda-list)))
3031 ((eq type 'alltodo)
3032 (org-let2 gprops lprops
3033 '(call-interactively 'org-todo-list)))
3034 ((eq type 'search)
3035 (org-let2 gprops lprops
3036 '(org-search-view current-prefix-arg match nil)))
3037 ((eq type 'stuck)
3038 (org-let2 gprops lprops
3039 '(call-interactively 'org-agenda-list-stuck-projects)))
3040 ((eq type 'tags)
3041 (org-let2 gprops lprops
3042 '(org-tags-view current-prefix-arg match)))
3043 ((eq type 'tags-todo)
3044 (org-let2 gprops lprops
3045 '(org-tags-view '(4) match)))
3046 ((eq type 'todo)
3047 (org-let2 gprops lprops
3048 '(org-todo-list match)))
3049 ((fboundp type)
3050 (org-let2 gprops lprops
3051 '(funcall type match)))
3052 (t (error "Invalid type in command series")))))
3053 (widen)
3054 (let ((inhibit-read-only t))
3055 (add-text-properties (point-min) (point-max)
3056 `(org-series t org-series-redo-cmd ,redo)))
3057 (setq org-agenda-redo-command redo)
3058 (goto-char (point-min)))
3059 (org-agenda-fit-window-to-buffer)
3060 (org-let (nth 1 series) '(org-agenda-finalize)))
3062 ;;;###autoload
3063 (defmacro org-batch-agenda (cmd-key &rest parameters)
3064 "Run an agenda command in batch mode and send the result to STDOUT.
3065 If CMD-KEY is a string of length 1, it is used as a key in
3066 `org-agenda-custom-commands' and triggers this command. If it is a
3067 longer string it is used as a tags/todo match string.
3068 Parameters are alternating variable names and values that will be bound
3069 before running the agenda command."
3070 (org-eval-in-environment (org-make-parameter-alist parameters)
3071 (if (> (length cmd-key) 2)
3072 (org-tags-view nil cmd-key)
3073 (org-agenda nil cmd-key)))
3074 (set-buffer org-agenda-buffer-name)
3075 (princ (buffer-string)))
3077 (autoload 'org-batch-agenda "org-agenda" "\
3078 Run an agenda command in batch mode and send the result to STDOUT.
3079 If CMD-KEY is a string of length 1, it is used as a key in
3080 `org-agenda-custom-commands' and triggers this command. If it is a
3081 longer string it is used as a tags/todo match string.
3082 Parameters are alternating variable names and values that will be bound
3083 before running the agenda command.
3085 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3086 (def-edebug-spec org-batch-agenda (form &rest sexp))
3088 (defvar org-agenda-info nil)
3090 ;;;###autoload
3091 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3092 "Run an agenda command in batch mode and send the result to STDOUT.
3093 If CMD-KEY is a string of length 1, it is used as a key in
3094 `org-agenda-custom-commands' and triggers this command. If it is a
3095 longer string it is used as a tags/todo match string.
3096 Parameters are alternating variable names and values that will be bound
3097 before running the agenda command.
3099 The output gives a line for each selected agenda item. Each
3100 item is a list of comma-separated values, like this:
3102 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3104 category The category of the item
3105 head The headline, without TODO kwd, TAGS and PRIORITY
3106 type The type of the agenda entry, can be
3107 todo selected in TODO match
3108 tagsmatch selected in tags match
3109 diary imported from diary
3110 deadline a deadline on given date
3111 scheduled scheduled on given date
3112 timestamp entry has timestamp on given date
3113 closed entry was closed on given date
3114 upcoming-deadline warning about deadline
3115 past-scheduled forwarded scheduled item
3116 block entry has date block including g. date
3117 todo The todo keyword, if any
3118 tags All tags including inherited ones, separated by colons
3119 date The relevant date, like 2007-2-14
3120 time The time, like 15:00-16:50
3121 extra Sting with extra planning info
3122 priority-l The priority letter if any was given
3123 priority-n The computed numerical priority
3124 agenda-day The day in the agenda where this is listed"
3125 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3126 (org-make-parameter-alist parameters))
3127 (if (> (length cmd-key) 2)
3128 (org-tags-view nil cmd-key)
3129 (org-agenda nil cmd-key)))
3130 (set-buffer org-agenda-buffer-name)
3131 (let* ((lines (org-split-string (buffer-string) "\n"))
3132 line)
3133 (while (setq line (pop lines))
3134 (catch 'next
3135 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3136 (setq org-agenda-info
3137 (org-fix-agenda-info (text-properties-at 0 line)))
3138 (princ
3139 (mapconcat 'org-agenda-export-csv-mapper
3140 '(org-category txt type todo tags date time extra
3141 priority-letter priority agenda-day)
3142 ","))
3143 (princ "\n")))))
3145 (autoload 'org-batch-agenda-csv "org-agenda" "\
3146 Run an agenda command in batch mode and send the result to STDOUT.
3147 If CMD-KEY is a string of length 1, it is used as a key in
3148 `org-agenda-custom-commands' and triggers this command. If it is a
3149 longer string it is used as a tags/todo match string.
3150 Parameters are alternating variable names and values that will be bound
3151 before running the agenda command.
3153 The output gives a line for each selected agenda item. Each
3154 item is a list of comma-separated values, like this:
3156 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3158 category The category of the item
3159 head The headline, without TODO kwd, TAGS and PRIORITY
3160 type The type of the agenda entry, can be
3161 todo selected in TODO match
3162 tagsmatch selected in tags match
3163 diary imported from diary
3164 deadline a deadline on given date
3165 scheduled scheduled on given date
3166 timestamp entry has timestamp on given date
3167 closed entry was closed on given date
3168 upcoming-deadline warning about deadline
3169 past-scheduled forwarded scheduled item
3170 block entry has date block including g. date
3171 todo The todo keyword, if any
3172 tags All tags including inherited ones, separated by colons
3173 date The relevant date, like 2007-2-14
3174 time The time, like 15:00-16:50
3175 extra Sting with extra planning info
3176 priority-l The priority letter if any was given
3177 priority-n The computed numerical priority
3178 agenda-day The day in the agenda where this is listed
3180 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3181 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3183 (defun org-fix-agenda-info (props)
3184 "Make sure all properties on an agenda item have a canonical form.
3185 This ensures the export commands can easily use it."
3186 (let (tmp re)
3187 (when (setq tmp (plist-get props 'tags))
3188 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3189 (when (setq tmp (plist-get props 'date))
3190 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3191 (let ((calendar-date-display-form '(year "-" month "-" day)))
3192 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3194 (setq tmp (calendar-date-string tmp)))
3195 (setq props (plist-put props 'date tmp)))
3196 (when (setq tmp (plist-get props 'day))
3197 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3198 (let ((calendar-date-display-form '(year "-" month "-" day)))
3199 (setq tmp (calendar-date-string tmp)))
3200 (setq props (plist-put props 'day tmp))
3201 (setq props (plist-put props 'agenda-day tmp)))
3202 (when (setq tmp (plist-get props 'txt))
3203 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3204 (plist-put props 'priority-letter (match-string 1 tmp))
3205 (setq tmp (replace-match "" t t tmp)))
3206 (when (and (setq re (plist-get props 'org-todo-regexp))
3207 (setq re (concat "\\`\\.*" re " ?"))
3208 (string-match re tmp))
3209 (plist-put props 'todo (match-string 1 tmp))
3210 (setq tmp (replace-match "" t t tmp)))
3211 (plist-put props 'txt tmp)))
3212 props)
3214 (defun org-agenda-export-csv-mapper (prop)
3215 (let ((res (plist-get org-agenda-info prop)))
3216 (setq res
3217 (cond
3218 ((not res) "")
3219 ((stringp res) res)
3220 (t (prin1-to-string res))))
3221 (while (string-match "," res)
3222 (setq res (replace-match ";" t t res)))
3223 (org-trim res)))
3225 ;;;###autoload
3226 (defun org-store-agenda-views (&rest parameters)
3227 (interactive)
3228 (eval (list 'org-batch-store-agenda-views)))
3230 (autoload 'org-store-agenda-views "org-agenda" "\
3233 \(fn &rest PARAMETERS)" t nil)
3235 ;;;###autoload
3236 (defmacro org-batch-store-agenda-views (&rest parameters)
3237 "Run all custom agenda commands that have a file argument."
3238 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3239 (pop-up-frames nil)
3240 (dir default-directory)
3241 (pars (org-make-parameter-alist parameters))
3242 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3243 (save-window-excursion
3244 (while cmds
3245 (setq cmd (pop cmds)
3246 thiscmdkey (car cmd)
3247 thiscmdcmd (cdr cmd)
3248 match (nth 2 thiscmdcmd)
3249 bufname (if org-agenda-sticky
3250 (or (and (stringp match)
3251 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3252 (format "*Org Agenda(%s)*" thiscmdkey))
3253 org-agenda-buffer-name)
3254 cmd-or-set (nth 2 cmd)
3255 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3256 files (nth (if (listp cmd-or-set) 4 5) cmd))
3257 (if (stringp files) (setq files (list files)))
3258 (when files
3259 (org-eval-in-environment (append org-agenda-exporter-settings
3260 opts pars)
3261 (org-agenda nil thiscmdkey))
3262 (set-buffer bufname)
3263 (while files
3264 (org-eval-in-environment (append org-agenda-exporter-settings
3265 opts pars)
3266 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3267 (and (get-buffer bufname)
3268 (kill-buffer bufname)))))))
3270 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3271 Run all custom agenda commands that have a file argument.
3273 \(fn &rest PARAMETERS)" nil t)
3274 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3276 (defvar org-agenda-current-span nil
3277 "The current span used in the agenda view.") ; local variable in the agenda buffer
3278 (defun org-agenda-mark-header-line (pos)
3279 "Mark the line at POS as an agenda structure header."
3280 (save-excursion
3281 (goto-char pos)
3282 (put-text-property (point-at-bol) (point-at-eol)
3283 'org-agenda-structural-header t)
3284 (when org-agenda-title-append
3285 (put-text-property (point-at-bol) (point-at-eol)
3286 'org-agenda-title-append org-agenda-title-append))))
3288 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3289 (defvar org-agenda-write-buffer-name "Agenda View")
3290 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3291 "Write the current buffer (an agenda view) as a file.
3292 Depending on the extension of the file name, plain text (.txt),
3293 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3294 If the extension is .ics, run icalendar export over all files used
3295 to construct the agenda and limit the export to entries listed in the
3296 agenda now.
3297 If the extension is .org, collect all subtrees corresponding to the
3298 agenda entries and add them in an .org file.
3299 With prefix argument OPEN, open the new file immediately.
3300 If NOSETTINGS is given, do not scope the settings of
3301 `org-agenda-exporter-settings' into the export commands. This is used when
3302 the settings have already been scoped and we do not wish to overrule other,
3303 higher priority settings.
3304 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3305 (interactive "FWrite agenda to file: \nP")
3306 (if (not (file-writable-p file))
3307 (error "Cannot write agenda to file %s" file))
3308 (org-let (if nosettings nil org-agenda-exporter-settings)
3309 '(save-excursion
3310 (save-window-excursion
3311 (org-agenda-mark-filtered-text)
3312 (let ((bs (copy-sequence (buffer-string))) beg content)
3313 (org-agenda-unmark-filtered-text)
3314 (with-temp-buffer
3315 (rename-buffer org-agenda-write-buffer-name t)
3316 (set-buffer-modified-p nil)
3317 (insert bs)
3318 (org-agenda-remove-marked-text 'org-filtered)
3319 (while (setq beg (text-property-any (point-min) (point-max)
3320 'org-filtered t))
3321 (delete-region
3322 beg (or (next-single-property-change beg 'org-filtered)
3323 (point-max))))
3324 (run-hooks 'org-agenda-before-write-hook)
3325 (cond
3326 ((org-bound-and-true-p org-mobile-creating-agendas)
3327 (org-mobile-write-agenda-for-mobile file))
3328 ((string-match "\\.org\\'" file)
3329 (let (content p m message-log-max)
3330 (goto-char (point-min))
3331 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3332 (goto-char p)
3333 (setq m (get-text-property (point) 'org-hd-marker))
3334 (when m
3335 (push (save-excursion
3336 (set-buffer (marker-buffer m))
3337 (goto-char m)
3338 (org-copy-subtree 1 nil t t)
3339 org-subtree-clip)
3340 content)))
3341 (find-file file)
3342 (erase-buffer)
3343 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3344 (write-file file)
3345 (kill-buffer (current-buffer))
3346 (message "Org file written to %s" file)))
3347 ((string-match "\\.html?\\'" file)
3348 (require 'htmlize)
3349 (set-buffer (htmlize-buffer (current-buffer)))
3350 (when org-agenda-export-html-style
3351 ;; replace <style> section with org-agenda-export-html-style
3352 (goto-char (point-min))
3353 (kill-region (- (search-forward "<style") 6)
3354 (search-forward "</style>"))
3355 (insert org-agenda-export-html-style))
3356 (write-file file)
3357 (kill-buffer (current-buffer))
3358 (message "HTML written to %s" file))
3359 ((string-match "\\.ps\\'" file)
3360 (require 'ps-print)
3361 (ps-print-buffer-with-faces file)
3362 (message "Postscript written to %s" file))
3363 ((string-match "\\.pdf\\'" file)
3364 (require 'ps-print)
3365 (ps-print-buffer-with-faces
3366 (concat (file-name-sans-extension file) ".ps"))
3367 (call-process "ps2pdf" nil nil nil
3368 (expand-file-name
3369 (concat (file-name-sans-extension file) ".ps"))
3370 (expand-file-name file))
3371 (delete-file (concat (file-name-sans-extension file) ".ps"))
3372 (message "PDF written to %s" file))
3373 ((string-match "\\.ics\\'" file)
3374 (require 'ox-icalendar)
3375 (org-icalendar-export-current-agenda (expand-file-name file)))
3377 (let ((bs (buffer-string)))
3378 (find-file file)
3379 (erase-buffer)
3380 (insert bs)
3381 (save-buffer 0)
3382 (kill-buffer (current-buffer))
3383 (message "Plain text written to %s" file))))))))
3384 (set-buffer (or agenda-bufname
3385 (and (org-called-interactively-p 'any) (buffer-name))
3386 org-agenda-buffer-name)))
3387 (when open (org-open-file file)))
3389 (defvar org-agenda-tag-filter-overlays nil)
3390 (defvar org-agenda-cat-filter-overlays nil)
3392 (defun org-agenda-mark-filtered-text ()
3393 "Mark all text hidden by filtering with a text property."
3394 (let ((inhibit-read-only t))
3395 (mapc
3396 (lambda (o)
3397 (when (equal (overlay-buffer o) (current-buffer))
3398 (put-text-property
3399 (overlay-start o) (overlay-end o)
3400 'org-filtered t)))
3401 (append org-agenda-tag-filter-overlays
3402 org-agenda-cat-filter-overlays))))
3404 (defun org-agenda-unmark-filtered-text ()
3405 "Remove the filtering text property."
3406 (let ((inhibit-read-only t))
3407 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3409 (defun org-agenda-remove-marked-text (property &optional value)
3410 "Delete all text marked with VALUE of PROPERTY.
3411 VALUE defaults to t."
3412 (let (beg)
3413 (setq value (or value t))
3414 (while (setq beg (text-property-any (point-min) (point-max)
3415 property value))
3416 (delete-region
3417 beg (or (next-single-property-change beg 'org-filtered)
3418 (point-max))))))
3420 (defun org-agenda-add-entry-text ()
3421 "Add entry text to agenda lines.
3422 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3423 entry text following headings shown in the agenda.
3424 Drawers will be excluded, also the line with scheduling/deadline info."
3425 (when (and (> org-agenda-add-entry-text-maxlines 0)
3426 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3427 (let (m txt)
3428 (goto-char (point-min))
3429 (while (not (eobp))
3430 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3431 (beginning-of-line 2)
3432 (setq txt (org-agenda-get-some-entry-text
3433 m org-agenda-add-entry-text-maxlines " > "))
3434 (end-of-line 1)
3435 (if (string-match "\\S-" txt)
3436 (insert "\n" txt)
3437 (or (eobp) (forward-char 1))))))))
3439 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3440 &rest keep)
3441 "Extract entry text from MARKER, at most N-LINES lines.
3442 This will ignore drawers etc, just get the text.
3443 If INDENT is given, prefix every line with this string. If KEEP is
3444 given, it is a list of symbols, defining stuff that should not be
3445 removed from the entry content. Currently only `planning' is allowed here."
3446 (let (txt drawer-re kwd-time-re ind)
3447 (save-excursion
3448 (with-current-buffer (marker-buffer marker)
3449 (if (not (derived-mode-p 'org-mode))
3450 (setq txt "")
3451 (save-excursion
3452 (save-restriction
3453 (widen)
3454 (goto-char marker)
3455 (end-of-line 1)
3456 (setq txt (buffer-substring
3457 (min (1+ (point)) (point-max))
3458 (progn (outline-next-heading) (point)))
3459 drawer-re org-drawer-regexp
3460 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3461 ".*\n?"))
3462 (with-temp-buffer
3463 (insert txt)
3464 (when org-agenda-add-entry-text-descriptive-links
3465 (goto-char (point-min))
3466 (while (org-activate-bracket-links (point-max))
3467 (add-text-properties (match-beginning 0) (match-end 0)
3468 '(face org-link))))
3469 (goto-char (point-min))
3470 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3471 (set-text-properties (match-beginning 0) (match-end 0)
3472 nil))
3473 (goto-char (point-min))
3474 (while (re-search-forward drawer-re nil t)
3475 (delete-region
3476 (match-beginning 0)
3477 (progn (re-search-forward
3478 "^[ \t]*:END:.*\n?" nil 'move)
3479 (point))))
3480 (unless (member 'planning keep)
3481 (goto-char (point-min))
3482 (while (re-search-forward kwd-time-re nil t)
3483 (replace-match "")))
3484 (goto-char (point-min))
3485 (when org-agenda-entry-text-exclude-regexps
3486 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3487 (while (setq re (pop re-list))
3488 (goto-char (point-min))
3489 (while (re-search-forward re nil t)
3490 (replace-match "")))))
3491 (goto-char (point-max))
3492 (skip-chars-backward " \t\n")
3493 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3495 ;; find and remove min common indentation
3496 (goto-char (point-min))
3497 (untabify (point-min) (point-max))
3498 (setq ind (org-get-indentation))
3499 (while (not (eobp))
3500 (unless (looking-at "[ \t]*$")
3501 (setq ind (min ind (org-get-indentation))))
3502 (beginning-of-line 2))
3503 (goto-char (point-min))
3504 (while (not (eobp))
3505 (unless (looking-at "[ \t]*$")
3506 (move-to-column ind)
3507 (delete-region (point-at-bol) (point)))
3508 (beginning-of-line 2))
3510 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3512 (goto-char (point-min))
3513 (when indent
3514 (while (and (not (eobp)) (re-search-forward "^" nil t))
3515 (replace-match indent t t)))
3516 (goto-char (point-min))
3517 (while (looking-at "[ \t]*\n") (replace-match ""))
3518 (goto-char (point-max))
3519 (when (> (org-current-line)
3520 n-lines)
3521 (org-goto-line (1+ n-lines))
3522 (backward-char 1))
3523 (setq txt (buffer-substring (point-min) (point)))))))))
3524 txt))
3526 (defun org-agenda-collect-markers ()
3527 "Collect the markers pointing to entries in the agenda buffer."
3528 (let (m markers)
3529 (save-excursion
3530 (goto-char (point-min))
3531 (while (not (eobp))
3532 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3533 (org-get-at-bol 'org-marker)))
3534 (push m markers))
3535 (beginning-of-line 2)))
3536 (nreverse markers)))
3538 (defun org-create-marker-find-array (marker-list)
3539 "Create a alist of files names with all marker positions in that file."
3540 (let (f tbl m a p)
3541 (while (setq m (pop marker-list))
3542 (setq p (marker-position m)
3543 f (buffer-file-name (or (buffer-base-buffer
3544 (marker-buffer m))
3545 (marker-buffer m))))
3546 (if (setq a (assoc f tbl))
3547 (push (marker-position m) (cdr a))
3548 (push (list f p) tbl)))
3549 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3550 tbl)))
3552 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3553 (defun org-check-agenda-marker-table ()
3554 "Check of the current entry is on the marker list."
3555 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3557 (and (setq a (assoc file org-agenda-marker-table))
3558 (save-match-data
3559 (save-excursion
3560 (org-back-to-heading t)
3561 (member (point) (cdr a)))))))
3563 (defun org-check-for-org-mode ()
3564 "Make sure current buffer is in org-mode. Error if not."
3565 (or (derived-mode-p 'org-mode)
3566 (error "Cannot execute org-mode agenda command on buffer in %s"
3567 major-mode)))
3569 ;;; Agenda prepare and finalize
3571 (defvar org-agenda-multi nil) ; dynamically scoped
3572 (defvar org-agenda-pre-window-conf nil)
3573 (defvar org-agenda-columns-active nil)
3574 (defvar org-agenda-name nil)
3575 (defvar org-agenda-tag-filter nil)
3576 (defvar org-agenda-category-filter nil)
3577 (defvar org-agenda-top-category-filter nil)
3578 (defvar org-agenda-tag-filter-while-redo nil)
3579 (defvar org-agenda-tag-filter-preset nil
3580 "A preset of the tags filter used for secondary agenda filtering.
3581 This must be a list of strings, each string must be a single tag preceded
3582 by \"+\" or \"-\".
3583 This variable should not be set directly, but agenda custom commands can
3584 bind it in the options section. The preset filter is a global property of
3585 the entire agenda view. In a block agenda, it will not work reliably to
3586 define a filter for one of the individual blocks. You need to set it in
3587 the global options and expect it to be applied to the entire view.")
3589 (defvar org-agenda-category-filter-preset nil
3590 "A preset of the category filter used for secondary agenda filtering.
3591 This must be a list of strings, each string must be a single category
3592 preceded by \"+\" or \"-\".
3593 This variable should not be set directly, but agenda custom commands can
3594 bind it in the options section. The preset filter is a global property of
3595 the entire agenda view. In a block agenda, it will not work reliably to
3596 define a filter for one of the individual blocks. You need to set it in
3597 the global options and expect it to be applied to the entire view.")
3600 (defun org-agenda-use-sticky-p ()
3601 "Return non-nil if an agenda buffer named
3602 `org-agenda-buffer-name' exists and should be shown instead of
3603 generating a new one."
3604 (and
3605 ;; turned off by user
3606 org-agenda-sticky
3607 ;; For multi-agenda buffer already exists
3608 (not org-agenda-multi)
3609 ;; buffer found
3610 (get-buffer org-agenda-buffer-name)
3611 ;; C-u parameter is same as last call
3612 (with-current-buffer (get-buffer org-agenda-buffer-name)
3613 (and
3614 (equal current-prefix-arg
3615 org-agenda-last-prefix-arg)
3616 ;; In case user turned stickiness on, while having existing
3617 ;; Agenda buffer active, don't reuse that buffer, because it
3618 ;; does not have org variables local
3619 org-agenda-this-buffer-is-sticky))))
3621 (defun org-agenda-prepare-window (abuf)
3622 "Setup agenda buffer in the window."
3623 (let* ((awin (get-buffer-window abuf))
3624 wconf)
3625 (cond
3626 ((equal (current-buffer) abuf) nil)
3627 (awin (select-window awin))
3628 ((not (setq wconf (current-window-configuration))))
3629 ((equal org-agenda-window-setup 'current-window)
3630 (org-pop-to-buffer-same-window abuf))
3631 ((equal org-agenda-window-setup 'other-window)
3632 (org-switch-to-buffer-other-window abuf))
3633 ((equal org-agenda-window-setup 'other-frame)
3634 (switch-to-buffer-other-frame abuf))
3635 ((equal org-agenda-window-setup 'reorganize-frame)
3636 (delete-other-windows)
3637 (org-switch-to-buffer-other-window abuf)))
3638 ;; additional test in case agenda is invoked from within agenda
3639 ;; buffer via elisp link
3640 (unless (equal (current-buffer) abuf)
3641 (org-pop-to-buffer-same-window abuf))
3642 (setq org-agenda-pre-window-conf
3643 (or org-agenda-pre-window-conf wconf))))
3645 (defun org-agenda-prepare (&optional name)
3646 (if (org-agenda-use-sticky-p)
3647 (progn
3648 ;; Popup existing buffer
3649 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3650 (message "Sticky Agenda buffer, use `r' to refresh")
3651 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3652 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3653 (setq org-todo-keywords-for-agenda nil)
3654 (setq org-drawers-for-agenda nil)
3655 (unless org-agenda-persistent-filter
3656 (setq org-agenda-tag-filter nil
3657 org-agenda-category-filter nil))
3658 (put 'org-agenda-tag-filter :preset-filter
3659 org-agenda-tag-filter-preset)
3660 (put 'org-agenda-category-filter :preset-filter
3661 org-agenda-category-filter-preset)
3662 (if org-agenda-multi
3663 (progn
3664 (setq buffer-read-only nil)
3665 (goto-char (point-max))
3666 (unless (or (bobp) org-agenda-compact-blocks
3667 (not org-agenda-block-separator))
3668 (insert "\n"
3669 (if (stringp org-agenda-block-separator)
3670 org-agenda-block-separator
3671 (make-string (window-width) org-agenda-block-separator))
3672 "\n"))
3673 (narrow-to-region (point) (point-max)))
3674 (setq org-done-keywords-for-agenda nil)
3676 ;; Setting any org variables that are in org-agenda-local-vars
3677 ;; list need to be done after the prepare call
3678 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3679 (setq buffer-read-only nil)
3680 (org-agenda-reset-markers)
3681 (let ((inhibit-read-only t)) (erase-buffer))
3682 (org-agenda-mode)
3683 (setq org-agenda-buffer (current-buffer))
3684 (setq org-agenda-contributing-files nil)
3685 (setq org-agenda-columns-active nil)
3686 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3687 (setq org-todo-keywords-for-agenda
3688 (org-uniquify org-todo-keywords-for-agenda))
3689 (setq org-done-keywords-for-agenda
3690 (org-uniquify org-done-keywords-for-agenda))
3691 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3692 (setq org-agenda-last-prefix-arg current-prefix-arg)
3693 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3694 (and name (not org-agenda-name)
3695 (org-set-local 'org-agenda-name name)))
3696 (setq buffer-read-only nil)))
3698 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3699 (defun org-agenda-finalize ()
3700 "Finishing touch for the agenda buffer, called just before displaying it."
3701 (unless org-agenda-multi
3702 (save-excursion
3703 (let ((inhibit-read-only t))
3704 (goto-char (point-min))
3705 (save-excursion
3706 (while (org-activate-bracket-links (point-max))
3707 (add-text-properties (match-beginning 0) (match-end 0)
3708 '(face org-link))))
3709 (save-excursion
3710 (while (org-activate-plain-links (point-max))
3711 (add-text-properties (match-beginning 0) (match-end 0)
3712 '(face org-link))))
3713 (unless (eq org-agenda-remove-tags t)
3714 (org-agenda-align-tags))
3715 (unless org-agenda-with-colors
3716 (remove-text-properties (point-min) (point-max) '(face nil)))
3717 (if (and (boundp 'org-agenda-overriding-columns-format)
3718 org-agenda-overriding-columns-format)
3719 (org-set-local 'org-agenda-overriding-columns-format
3720 org-agenda-overriding-columns-format))
3721 (if (and (boundp 'org-agenda-view-columns-initially)
3722 org-agenda-view-columns-initially)
3723 (org-agenda-columns))
3724 (when org-agenda-fontify-priorities
3725 (org-agenda-fontify-priorities))
3726 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3727 (org-agenda-dim-blocked-tasks))
3728 ;; We need to widen when `org-agenda-finalize' is called from
3729 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3730 (when org-clock-current-task
3731 (save-restriction
3732 (widen)
3733 (org-agenda-mark-clocking-task)))
3734 (when org-agenda-entry-text-mode
3735 (org-agenda-entry-text-hide)
3736 (org-agenda-entry-text-show))
3737 (if (and (functionp 'org-habit-insert-consistency-graphs)
3738 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3739 (org-habit-insert-consistency-graphs))
3740 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3741 (unless (or (eq org-agenda-show-inherited-tags 'always)
3742 (and (listp org-agenda-show-inherited-tags)
3743 (memq org-agenda-type org-agenda-show-inherited-tags))
3744 (and (eq org-agenda-show-inherited-tags t)
3745 (or (eq org-agenda-use-tag-inheritance t)
3746 (and (listp org-agenda-use-tag-inheritance)
3747 (not (memq org-agenda-type
3748 org-agenda-use-tag-inheritance))))))
3749 (let (mrk)
3750 (save-excursion
3751 (goto-char (point-min))
3752 (while (equal (forward-line) 0)
3753 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3754 (get-text-property (point) 'org-hd-marker)))
3755 (put-text-property (point-at-bol) (point-at-eol)
3756 'tags (org-with-point-at mrk
3757 (delete-dups
3758 (mapcar 'downcase (org-get-tags-at))))))))))
3759 (run-hooks 'org-agenda-finalize-hook)
3760 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3761 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3762 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3763 (org-agenda-filter-apply org-agenda-category-filter 'category))
3764 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3766 (defun org-agenda-mark-clocking-task ()
3767 "Mark the current clock entry in the agenda if it is present."
3768 (mapc (lambda (o)
3769 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3770 (delete-overlay o)))
3771 (overlays-in (point-min) (point-max)))
3772 (when (marker-buffer org-clock-hd-marker)
3773 (save-excursion
3774 (goto-char (point-min))
3775 (let (s ov)
3776 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3777 (goto-char s)
3778 (when (equal (org-get-at-bol 'org-hd-marker)
3779 org-clock-hd-marker)
3780 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3781 (overlay-put ov 'type 'org-agenda-clocking)
3782 (overlay-put ov 'face 'org-agenda-clocking)
3783 (overlay-put ov 'help-echo
3784 "The clock is running in this item")))))))
3786 (defun org-agenda-fontify-priorities ()
3787 "Make highest priority lines bold, and lowest italic."
3788 (interactive)
3789 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3790 (delete-overlay o)))
3791 (overlays-in (point-min) (point-max)))
3792 (save-excursion
3793 (let (b e p ov h l)
3794 (goto-char (point-min))
3795 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3796 (setq h (or (get-char-property (point) 'org-highest-priority)
3797 org-highest-priority)
3798 l (or (get-char-property (point) 'org-lowest-priority)
3799 org-lowest-priority)
3800 p (string-to-char (match-string 1))
3801 b (match-beginning 0)
3802 e (if (eq org-agenda-fontify-priorities 'cookies)
3803 (match-end 0)
3804 (point-at-eol))
3805 ov (make-overlay b e))
3806 (overlay-put
3807 ov 'face
3808 (cons (cond ((org-face-from-face-or-color
3809 'priority nil
3810 (cdr (assoc p org-priority-faces))))
3811 ((and (listp org-agenda-fontify-priorities)
3812 (org-face-from-face-or-color
3813 'priority nil
3814 (cdr (assoc p org-agenda-fontify-priorities)))))
3815 ((equal p l) 'italic)
3816 ((equal p h) 'bold))
3817 'org-priority))
3818 (overlay-put ov 'org-type 'org-priority)))))
3820 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3821 (interactive "P")
3822 "Dim currently blocked TODO's in the agenda display."
3823 (message "Dim or hide blocked tasks...")
3824 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3825 (delete-overlay o)))
3826 (overlays-in (point-min) (point-max)))
3827 (save-excursion
3828 (let ((inhibit-read-only t)
3829 (org-depend-tag-blocked nil)
3830 (invis (or (not (null invisible))
3831 (eq org-agenda-dim-blocked-tasks 'invisible)))
3832 org-blocked-by-checkboxes
3833 invis1 b e p ov h l)
3834 (goto-char (point-min))
3835 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3836 (and pos (goto-char (1+ pos))))
3837 (setq org-blocked-by-checkboxes nil invis1 invis)
3838 (let ((marker (org-get-at-bol 'org-hd-marker)))
3839 (when (and marker
3840 (with-current-buffer (marker-buffer marker)
3841 (save-excursion (goto-char marker)
3842 (org-entry-blocked-p))))
3843 (if org-blocked-by-checkboxes (setq invis1 nil))
3844 (setq b (if invis1
3845 (max (point-min) (1- (point-at-bol)))
3846 (point-at-bol))
3847 e (point-at-eol)
3848 ov (make-overlay b e))
3849 (if invis1
3850 (overlay-put ov 'invisible t)
3851 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3852 (overlay-put ov 'org-type 'org-blocked-todo))))))
3853 (message "Dim or hide blocked tasks...done"))
3855 (defvar org-agenda-skip-function nil
3856 "Function to be called at each match during agenda construction.
3857 If this function returns nil, the current match should not be skipped.
3858 Otherwise, the function must return a position from where the search
3859 should be continued.
3860 This may also be a Lisp form, it will be evaluated.
3861 Never set this variable using `setq' or so, because then it will apply
3862 to all future agenda commands. If you do want a global skipping condition,
3863 use the option `org-agenda-skip-function-global' instead.
3864 The correct usage for `org-agenda-skip-function' is to bind it with
3865 `let' to scope it dynamically into the agenda-constructing command.
3866 A good way to set it is through options in `org-agenda-custom-commands'.")
3868 (defun org-agenda-skip ()
3869 "Throw to `:skip' in places that should be skipped.
3870 Also moves point to the end of the skipped region, so that search can
3871 continue from there."
3872 (let ((p (point-at-bol)) to)
3873 (when (or
3874 (save-excursion (goto-char p) (looking-at comment-start-skip))
3875 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3876 (get-text-property p :org-archived)
3877 (org-end-of-subtree t))
3878 (and org-agenda-skip-comment-trees
3879 (get-text-property p :org-comment)
3880 (org-end-of-subtree t))
3881 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3882 (org-agenda-skip-eval org-agenda-skip-function)))
3883 (goto-char to))
3884 (org-in-src-block-p t))
3885 (throw :skip t))))
3887 (defun org-agenda-skip-eval (form)
3888 "If FORM is a function or a list, call (or eval) is and return result.
3889 `save-excursion' and `save-match-data' are wrapped around the call, so point
3890 and match data are returned to the previous state no matter what these
3891 functions do."
3892 (let (fp)
3893 (and form
3894 (or (setq fp (functionp form))
3895 (consp form))
3896 (save-excursion
3897 (save-match-data
3898 (if fp
3899 (funcall form)
3900 (eval form)))))))
3902 (defvar org-agenda-markers nil
3903 "List of all currently active markers created by `org-agenda'.")
3904 (defvar org-agenda-last-marker-time (org-float-time)
3905 "Creation time of the last agenda marker.")
3907 (defun org-agenda-new-marker (&optional pos)
3908 "Return a new agenda marker.
3909 Org-mode keeps a list of these markers and resets them when they are
3910 no longer in use."
3911 (let ((m (copy-marker (or pos (point)))))
3912 (setq org-agenda-last-marker-time (org-float-time))
3913 (if org-agenda-buffer
3914 (with-current-buffer org-agenda-buffer
3915 (push m org-agenda-markers))
3916 (push m org-agenda-markers))
3919 (defun org-agenda-reset-markers ()
3920 "Reset markers created by `org-agenda'."
3921 (while org-agenda-markers
3922 (move-marker (pop org-agenda-markers) nil)))
3924 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3925 "Save relative positions of markers in region.
3926 This check for agenda markers in all agenda buffers currently active."
3927 (dolist (buf (buffer-list))
3928 (with-current-buffer buf
3929 (when (eq major-mode 'org-agenda-mode)
3930 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3931 org-agenda-markers)))))
3933 ;;; Entry text mode
3935 (defun org-agenda-entry-text-show-here ()
3936 "Add some text from the entry as context to the current line."
3937 (let (m txt o)
3938 (setq m (org-get-at-bol 'org-hd-marker))
3939 (unless (marker-buffer m)
3940 (error "No marker points to an entry here"))
3941 (setq txt (concat "\n" (org-no-properties
3942 (org-agenda-get-some-entry-text
3943 m org-agenda-entry-text-maxlines " > "))))
3944 (when (string-match "\\S-" txt)
3945 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3946 (overlay-put o 'evaporate t)
3947 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3948 (overlay-put o 'after-string txt))))
3950 (defun org-agenda-entry-text-show ()
3951 "Add entry context for all agenda lines."
3952 (interactive)
3953 (save-excursion
3954 (goto-char (point-max))
3955 (beginning-of-line 1)
3956 (while (not (bobp))
3957 (when (org-get-at-bol 'org-hd-marker)
3958 (org-agenda-entry-text-show-here))
3959 (beginning-of-line 0))))
3961 (defun org-agenda-entry-text-hide ()
3962 "Remove any shown entry context."
3963 (delq nil
3964 (mapcar (lambda (o)
3965 (if (eq (overlay-get o 'org-overlay-type)
3966 'agenda-entry-content)
3967 (progn (delete-overlay o) t)))
3968 (overlays-in (point-min) (point-max)))))
3970 (defun org-agenda-get-day-face (date)
3971 "Return the face DATE should be displayed with."
3972 (or (and (functionp org-agenda-day-face-function)
3973 (funcall org-agenda-day-face-function date))
3974 (cond ((org-agenda-todayp date)
3975 'org-agenda-date-today)
3976 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3977 'org-agenda-date-weekend)
3978 (t 'org-agenda-date))))
3980 ;;; Agenda timeline
3982 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3984 (defun org-timeline (&optional dotodo)
3985 "Show a time-sorted view of the entries in the current org file.
3986 Only entries with a time stamp of today or later will be listed. With
3987 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3988 under the current date.
3989 If the buffer contains an active region, only check the region for
3990 dates."
3991 (interactive "P")
3992 (let* ((dopast t)
3993 (org-agenda-show-log-scoped org-agenda-show-log)
3994 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3995 (current-buffer))))
3996 (date (calendar-current-date))
3997 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3998 (end (if (org-region-active-p) (region-end) (point-max)))
3999 (day-numbers (org-get-all-dates
4000 beg end 'no-ranges
4001 t org-agenda-show-log-scoped ; always include today
4002 org-timeline-show-empty-dates))
4003 (org-deadline-warning-days 0)
4004 (org-agenda-only-exact-dates t)
4005 (today (org-today))
4006 (past t)
4007 args
4008 s e rtn d emptyp)
4009 (setq org-agenda-redo-command
4010 (list 'progn
4011 (list 'org-switch-to-buffer-other-window (current-buffer))
4012 (list 'org-timeline (list 'quote dotodo))))
4013 (if (not dopast)
4014 ;; Remove past dates from the list of dates.
4015 (setq day-numbers (delq nil (mapcar (lambda(x)
4016 (if (>= x today) x nil))
4017 day-numbers))))
4018 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4019 (org-compile-prefix-format 'timeline)
4020 (org-set-sorting-strategy 'timeline)
4021 (if org-agenda-show-log-scoped (push :closed args))
4022 (push :timestamp args)
4023 (push :deadline args)
4024 (push :scheduled args)
4025 (push :sexp args)
4026 (if dotodo (push :todo args))
4027 (insert "Timeline of file " entry "\n")
4028 (add-text-properties (point-min) (point)
4029 (list 'face 'org-agenda-structure))
4030 (org-agenda-mark-header-line (point-min))
4031 (while (setq d (pop day-numbers))
4032 (if (and (listp d) (eq (car d) :omitted))
4033 (progn
4034 (setq s (point))
4035 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4036 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4037 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4038 (if (and (>= d today)
4039 dopast
4040 past)
4041 (progn
4042 (setq past nil)
4043 (insert (make-string 79 ?-) "\n")))
4044 (setq date (calendar-gregorian-from-absolute d))
4045 (setq s (point))
4046 (setq rtn (and (not emptyp)
4047 (apply 'org-agenda-get-day-entries entry
4048 date args)))
4049 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4050 (progn
4051 (insert
4052 (if (stringp org-agenda-format-date)
4053 (format-time-string org-agenda-format-date
4054 (org-time-from-absolute date))
4055 (funcall org-agenda-format-date date))
4056 "\n")
4057 (put-text-property s (1- (point)) 'face
4058 (org-agenda-get-day-face date))
4059 (put-text-property s (1- (point)) 'org-date-line t)
4060 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4061 (if (equal d today)
4062 (put-text-property s (1- (point)) 'org-today t))
4063 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4064 (put-text-property s (1- (point)) 'day d)))))
4065 (goto-char (point-min))
4066 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4067 (point-min)))
4068 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
4069 (org-agenda-finalize)
4070 (setq buffer-read-only t)))
4072 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4073 "Return a list of all relevant day numbers from BEG to END buffer positions.
4074 If NO-RANGES is non-nil, include only the start and end dates of a range,
4075 not every single day in the range. If FORCE-TODAY is non-nil, make
4076 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4077 inactive time stamps (those in square brackets) are included.
4078 When EMPTY is non-nil, also include days without any entries."
4079 (let ((re (concat
4080 (if pre-re pre-re "")
4081 (if inactive org-ts-regexp-both org-ts-regexp)))
4082 dates dates1 date day day1 day2 ts1 ts2 pos)
4083 (if force-today
4084 (setq dates (list (org-today))))
4085 (save-excursion
4086 (goto-char beg)
4087 (while (re-search-forward re end t)
4088 (setq day (time-to-days (org-time-string-to-time
4089 (substring (match-string 1) 0 10)
4090 (current-buffer) (match-beginning 0))))
4091 (or (memq day dates) (push day dates)))
4092 (unless no-ranges
4093 (goto-char beg)
4094 (while (re-search-forward org-tr-regexp end t)
4095 (setq pos (match-beginning 0))
4096 (setq ts1 (substring (match-string 1) 0 10)
4097 ts2 (substring (match-string 2) 0 10)
4098 day1 (time-to-days (org-time-string-to-time
4099 ts1 (current-buffer) pos))
4100 day2 (time-to-days (org-time-string-to-time
4101 ts2 (current-buffer) pos)))
4102 (while (< (setq day1 (1+ day1)) day2)
4103 (or (memq day1 dates) (push day1 dates)))))
4104 (setq dates (sort dates '<))
4105 (when empty
4106 (while (setq day (pop dates))
4107 (setq day2 (car dates))
4108 (push day dates1)
4109 (when (and day2 empty)
4110 (if (or (eq empty t)
4111 (and (numberp empty) (<= (- day2 day) empty)))
4112 (while (< (setq day (1+ day)) day2)
4113 (push (list day) dates1))
4114 (push (cons :omitted (- day2 day)) dates1))))
4115 (setq dates (nreverse dates1)))
4116 dates)))
4118 ;;; Agenda Daily/Weekly
4120 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4121 "Start day for the agenda view.
4122 Custom commands can set this variable in the options section.")
4123 (defvar org-starting-day nil) ; local variable in the agenda buffer
4124 (defvar org-arg-loc nil) ; local variable
4126 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4127 "List of types searched for when creating the daily/weekly agenda.
4128 This variable is a list of symbols that controls the types of
4129 items that appear in the daily/weekly agenda. Allowed symbols in this
4130 list are are
4132 :timestamp List items containing a date stamp or date range matching
4133 the selected date. This includes sexp entries in
4134 angular brackets.
4136 :sexp List entries resulting from plain diary-like sexps.
4138 :deadline List deadline due on that date. When the date is today,
4139 also list any deadlines past due, or due within
4140 `org-deadline-warning-days'. `:deadline' must appear before
4141 `:scheduled' if the setting of
4142 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4143 any effect.
4145 :scheduled List all items which are scheduled for the given date.
4146 The diary for *today* also contains items which were
4147 scheduled earlier and are not yet marked DONE.
4149 By default, all four types are turned on.
4151 Never set this variable globally using `setq', because then it
4152 will apply to all future agenda commands. Instead, bind it with
4153 `let' to scope it dynamically into the agenda-constructing
4154 command. A good way to set it is through options in
4155 `org-agenda-custom-commands'. For a more flexible (though
4156 somewhat less efficient) way of determining what is included in
4157 the daily/weekly agenda, see `org-agenda-skip-function'.")
4159 (defvar org-agenda-buffer-tmp-name nil)
4160 ;;;###autoload
4161 (defun org-agenda-list (&optional arg start-day span)
4162 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4163 The view will be for the current day or week, but from the overview buffer
4164 you will be able to go to other days/weeks.
4166 With a numeric prefix argument in an interactive call, the agenda will
4167 span ARG days. Lisp programs should instead specify SPAN to change
4168 the number of days. SPAN defaults to `org-agenda-span'.
4170 START-DAY defaults to TODAY, or to the most recent match for the weekday
4171 given in `org-agenda-start-on-weekday'."
4172 (interactive "P")
4173 (if org-agenda-overriding-arguments
4174 (setq arg (car org-agenda-overriding-arguments)
4175 start-day (nth 1 org-agenda-overriding-arguments)
4176 span (nth 2 org-agenda-overriding-arguments)))
4177 (if (and (integerp arg) (> arg 0))
4178 (setq span arg arg nil))
4179 (catch 'exit
4180 (setq org-agenda-buffer-name
4181 (or org-agenda-buffer-tmp-name
4182 (if org-agenda-sticky
4183 (cond ((and org-keys (stringp org-match))
4184 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4185 (org-keys
4186 (format "*Org Agenda(%s)*" org-keys))
4187 (t "*Org Agenda(a)*")))
4188 org-agenda-buffer-name))
4189 (org-agenda-prepare "Day/Week")
4190 (setq start-day (or start-day org-agenda-start-day))
4191 (if (stringp start-day)
4192 ;; Convert to an absolute day number
4193 (setq start-day (time-to-days (org-read-date nil t start-day))))
4194 (org-compile-prefix-format 'agenda)
4195 (org-set-sorting-strategy 'agenda)
4196 (let* ((span (org-agenda-ndays-to-span
4197 (or span org-agenda-ndays org-agenda-span)))
4198 (today (org-today))
4199 (sd (or start-day today))
4200 (ndays (org-agenda-span-to-ndays span sd))
4201 (org-agenda-start-on-weekday
4202 (if (eq ndays 7)
4203 org-agenda-start-on-weekday))
4204 (thefiles (org-agenda-files nil 'ifmode))
4205 (files thefiles)
4206 (start (if (or (null org-agenda-start-on-weekday)
4207 (< ndays 7))
4209 (let* ((nt (calendar-day-of-week
4210 (calendar-gregorian-from-absolute sd)))
4211 (n1 org-agenda-start-on-weekday)
4212 (d (- nt n1)))
4213 (- sd (+ (if (< d 0) 7 0) d)))))
4214 (day-numbers (list start))
4215 (day-cnt 0)
4216 (inhibit-redisplay (not debug-on-error))
4217 (org-agenda-show-log-scoped org-agenda-show-log)
4218 s e rtn rtnall file date d start-pos end-pos todayp
4219 clocktable-start clocktable-end filter)
4220 (setq org-agenda-redo-command
4221 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4222 (dotimes (n (1- ndays))
4223 (push (1+ (car day-numbers)) day-numbers))
4224 (setq day-numbers (nreverse day-numbers))
4225 (setq clocktable-start (car day-numbers)
4226 clocktable-end (1+ (or (org-last day-numbers) 0)))
4227 (org-set-local 'org-starting-day (car day-numbers))
4228 (org-set-local 'org-arg-loc arg)
4229 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4230 (unless org-agenda-compact-blocks
4231 (let* ((d1 (car day-numbers))
4232 (d2 (org-last day-numbers))
4233 (w1 (org-days-to-iso-week d1))
4234 (w2 (org-days-to-iso-week d2)))
4235 (setq s (point))
4236 (if org-agenda-overriding-header
4237 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4238 nil 'face 'org-agenda-structure) "\n")
4239 (insert (org-agenda-span-name span)
4240 "-agenda"
4241 (if (< (- d2 d1) 350)
4242 (if (= w1 w2)
4243 (format " (W%02d)" w1)
4244 (format " (W%02d-W%02d)" w1 w2))
4246 ":\n")))
4247 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4248 'org-date-line t))
4249 (org-agenda-mark-header-line s))
4250 (while (setq d (pop day-numbers))
4251 (setq date (calendar-gregorian-from-absolute d)
4252 s (point))
4253 (if (or (setq todayp (= d today))
4254 (and (not start-pos) (= d sd)))
4255 (setq start-pos (point))
4256 (if (and start-pos (not end-pos))
4257 (setq end-pos (point))))
4258 (setq files thefiles
4259 rtnall nil)
4260 (while (setq file (pop files))
4261 (catch 'nextfile
4262 (org-check-agenda-file file)
4263 (let ((org-agenda-entry-types org-agenda-entry-types))
4264 (unless org-agenda-include-deadlines
4265 (setq org-agenda-entry-types
4266 (delq :deadline org-agenda-entry-types)))
4267 (cond
4268 ((memq org-agenda-show-log-scoped '(only clockcheck))
4269 (setq rtn (org-agenda-get-day-entries
4270 file date :closed)))
4271 (org-agenda-show-log-scoped
4272 (setq rtn (apply 'org-agenda-get-day-entries
4273 file date
4274 (append '(:closed) org-agenda-entry-types))))
4276 (setq rtn (apply 'org-agenda-get-day-entries
4277 file date
4278 org-agenda-entry-types)))))
4279 (setq rtnall (append rtnall rtn)))) ;; all entries
4280 (if org-agenda-include-diary
4281 (let ((org-agenda-search-headline-for-time t))
4282 (require 'diary-lib)
4283 (setq rtn (org-get-entries-from-diary date))
4284 (setq rtnall (append rtnall rtn))))
4285 (if (or rtnall org-agenda-show-all-dates)
4286 (progn
4287 (setq day-cnt (1+ day-cnt))
4288 (insert
4289 (if (stringp org-agenda-format-date)
4290 (format-time-string org-agenda-format-date
4291 (org-time-from-absolute date))
4292 (funcall org-agenda-format-date date))
4293 "\n")
4294 (put-text-property s (1- (point)) 'face
4295 (org-agenda-get-day-face date))
4296 (put-text-property s (1- (point)) 'org-date-line t)
4297 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4298 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4299 (when todayp
4300 (put-text-property s (1- (point)) 'org-today t))
4301 (setq rtnall
4302 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4303 (if rtnall (insert ;; all entries
4304 (org-agenda-finalize-entries rtnall 'agenda)
4305 "\n"))
4306 (put-text-property s (1- (point)) 'day d)
4307 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4308 (when (and org-agenda-clockreport-mode clocktable-start)
4309 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4310 ;; the above line is to ensure the restricted range!
4311 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4312 tbl)
4313 (setq p (org-plist-delete p :block))
4314 (setq p (plist-put p :tstart clocktable-start))
4315 (setq p (plist-put p :tend clocktable-end))
4316 (setq p (plist-put p :scope 'agenda))
4317 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4318 (setq filter (or org-agenda-tag-filter-while-redo
4319 (get 'org-agenda-tag-filter :preset-filter))))
4320 (setq p (plist-put p :tags (mapconcat (lambda (x)
4321 (if (string-match "[<>=]" x)
4324 filter ""))))
4325 (setq tbl (apply 'org-clock-get-clocktable p))
4326 (insert tbl)))
4327 (goto-char (point-min))
4328 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4329 (unless (and (pos-visible-in-window-p (point-min))
4330 (pos-visible-in-window-p (point-max)))
4331 (goto-char (1- (point-max)))
4332 (recenter -1)
4333 (if (not (pos-visible-in-window-p (or start-pos 1)))
4334 (progn
4335 (goto-char (or start-pos 1))
4336 (recenter 1))))
4337 (goto-char (or start-pos 1))
4338 (add-text-properties (point-min) (point-max)
4339 `(org-agenda-type agenda
4340 org-last-args (,arg ,start-day ,span)
4341 org-redo-cmd ,org-agenda-redo-command
4342 org-series-cmd ,org-cmd))
4343 (if (eq org-agenda-show-log-scoped 'clockcheck)
4344 (org-agenda-show-clocking-issues))
4345 (org-agenda-finalize)
4346 (setq buffer-read-only t)
4347 (message ""))))
4349 (autoload 'org-agenda-list "org-agenda" "\
4350 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4351 The view will be for the current day or week, but from the overview buffer
4352 you will be able to go to other days/weeks.
4354 With a numeric prefix argument in an interactive call, the agenda will
4355 span ARG days. Lisp programs should instead specify SPAN to change
4356 the number of days. SPAN defaults to `org-agenda-span'.
4358 START-DAY defaults to TODAY, or to the most recent match for the weekday
4359 given in `org-agenda-start-on-weekday'.
4361 \(fn &optional ARG START-DAY SPAN)" t nil)
4363 (defun org-agenda-ndays-to-span (n)
4364 "Return a span symbol for a span of N days, or N if none matches."
4365 (cond ((symbolp n) n)
4366 ((= n 1) 'day)
4367 ((= n 7) 'week)
4368 (t n)))
4370 (defun org-agenda-span-to-ndays (span &optional start-day)
4371 "Return ndays from SPAN, possibly starting at START-DAY."
4372 (cond ((numberp span) span)
4373 ((eq span 'day) 1)
4374 ((eq span 'week) 7)
4375 ((eq span 'month)
4376 (let ((date (calendar-gregorian-from-absolute start-day)))
4377 (calendar-last-day-of-month (car date) (caddr date))))
4378 ((eq span 'year)
4379 (let ((date (calendar-gregorian-from-absolute start-day)))
4380 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4382 (defun org-agenda-span-name (span)
4383 "Return a SPAN name."
4384 (if (null span)
4386 (if (symbolp span)
4387 (capitalize (symbol-name span))
4388 (format "%d days" span))))
4390 ;;; Agenda word search
4392 (defvar org-agenda-search-history nil)
4394 (defvar org-search-syntax-table nil
4395 "Special syntax table for org-mode search.
4396 In this table, we have single quotes not as word constituents, to
4397 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4399 (defvar org-mode-syntax-table) ; From org.el
4400 (defun org-search-syntax-table ()
4401 (unless org-search-syntax-table
4402 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4403 (modify-syntax-entry ?' "." org-search-syntax-table)
4404 (modify-syntax-entry ?` "." org-search-syntax-table))
4405 org-search-syntax-table)
4407 (defvar org-agenda-last-search-view-search-was-boolean nil)
4409 ;;;###autoload
4410 (defun org-search-view (&optional todo-only string edit-at)
4411 "Show all entries that contain a phrase or words or regular expressions.
4413 With optional prefix argument TODO-ONLY, only consider entries that are
4414 TODO entries. The argument STRING can be used to pass a default search
4415 string into this function. If EDIT-AT is non-nil, it means that the
4416 user should get a chance to edit this string, with cursor at position
4417 EDIT-AT.
4419 The search string can be viewed either as a phrase that should be found as
4420 is, or it can be broken into a number of snippets, each of which must match
4421 in a Boolean way to select an entry. The default depends on the variable
4422 `org-agenda-search-view-always-boolean'.
4423 Even if this is turned off (the default) you can always switch to
4424 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4426 The default is a direct search of the whole phrase, where each space in
4427 the search string can expand to an arbitrary amount of whitespace,
4428 including newlines.
4430 If using a Boolean search, the search string is split on whitespace and
4431 each snippet is searched separately, with logical AND to select an entry.
4432 Words prefixed with a minus must *not* occur in the entry. Words without
4433 a prefix or prefixed with a plus must occur in the entry. Matching is
4434 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4435 match whole words, not parts of a word) if
4436 `org-agenda-search-view-force-full-words' is set (default is nil).
4438 Boolean search snippets enclosed by curly braces are interpreted as
4439 regular expressions that must or (when preceded with \"-\") must not
4440 match in the entry. Snippets enclosed into double quotes will be taken
4441 as a whole, to include whitespace.
4443 - If the search string starts with an asterisk, search only in headlines.
4444 - If (possibly after the leading star) the search string starts with an
4445 exclamation mark, this also means to look at TODO entries only, an effect
4446 that can also be achieved with a prefix argument.
4447 - If (possibly after star and exclamation mark) the search string starts
4448 with a colon, this will mean that the (non-regexp) snippets of the
4449 Boolean search must match as full words.
4451 This command searches the agenda files, and in addition the files listed
4452 in `org-agenda-text-search-extra-files'."
4453 (interactive "P")
4454 (if org-agenda-overriding-arguments
4455 (setq todo-only (car org-agenda-overriding-arguments)
4456 string (nth 1 org-agenda-overriding-arguments)
4457 edit-at (nth 2 org-agenda-overriding-arguments)))
4458 (let* ((props (list 'face nil
4459 'done-face 'org-agenda-done
4460 'org-not-done-regexp org-not-done-regexp
4461 'org-todo-regexp org-todo-regexp
4462 'org-complex-heading-regexp org-complex-heading-regexp
4463 'mouse-face 'highlight
4464 'help-echo (format "mouse-2 or RET jump to location")))
4465 (full-words org-agenda-search-view-force-full-words)
4466 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4467 regexp rtn rtnall files file pos inherited-tags
4468 marker category category-pos level tags c neg re boolean
4469 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4470 (unless (and (not edit-at)
4471 (stringp string)
4472 (string-match "\\S-" string))
4473 (setq string (read-string
4474 (if org-agenda-search-view-always-boolean
4475 "[+-]Word/{Regexp} ...: "
4476 "Phrase or [+-]Word/{Regexp} ...: ")
4477 (cond
4478 ((integerp edit-at) (cons string edit-at))
4479 (edit-at string))
4480 'org-agenda-search-history)))
4481 (catch 'exit
4482 (if org-agenda-sticky
4483 (setq org-agenda-buffer-name
4484 (if (stringp string)
4485 (format "*Org Agenda(%s:%s)*"
4486 (or org-keys (or (and todo-only "S") "s")) string)
4487 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4488 (org-agenda-prepare "SEARCH")
4489 (org-compile-prefix-format 'search)
4490 (org-set-sorting-strategy 'search)
4491 (setq org-agenda-redo-command
4492 (list 'org-search-view (if todo-only t nil)
4493 (list 'if 'current-prefix-arg nil string)))
4494 (setq org-agenda-query-string string)
4495 (if (equal (string-to-char string) ?*)
4496 (setq hdl-only t
4497 words (substring string 1))
4498 (setq words string))
4499 (when (equal (string-to-char words) ?!)
4500 (setq todo-only t
4501 words (substring words 1)))
4502 (when (equal (string-to-char words) ?:)
4503 (setq full-words t
4504 words (substring words 1)))
4505 (if (or org-agenda-search-view-always-boolean
4506 (member (string-to-char words) '(?- ?+ ?\{)))
4507 (setq boolean t))
4508 (setq words (org-split-string words))
4509 (let (www w)
4510 (while (setq w (pop words))
4511 (while (and (string-match "\\\\\\'" w) words)
4512 (setq w (concat (substring w 0 -1) " " (pop words))))
4513 (push w www))
4514 (setq words (nreverse www) www nil)
4515 (while (setq w (pop words))
4516 (when (and (string-match "\\`[-+]?{" w)
4517 (not (string-match "}\\'" w)))
4518 (while (and words (not (string-match "}\\'" (car words))))
4519 (setq w (concat w " " (pop words))))
4520 (setq w (concat w " " (pop words))))
4521 (push w www))
4522 (setq words (nreverse www)))
4523 (setq org-agenda-last-search-view-search-was-boolean boolean)
4524 (when boolean
4525 (let (wds w)
4526 (while (setq w (pop words))
4527 (if (or (equal (substring w 0 1) "\"")
4528 (and (> (length w) 1)
4529 (member (substring w 0 1) '("+" "-"))
4530 (equal (substring w 1 2) "\"")))
4531 (while (and words (not (equal (substring w -1) "\"")))
4532 (setq w (concat w " " (pop words)))))
4533 (and (string-match "\\`\\([-+]?\\)\"" w)
4534 (setq w (replace-match "\\1" nil nil w)))
4535 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4536 (push w wds))
4537 (setq words (nreverse wds))))
4538 (if boolean
4539 (mapc (lambda (w)
4540 (setq c (string-to-char w))
4541 (if (equal c ?-)
4542 (setq neg t w (substring w 1))
4543 (if (equal c ?+)
4544 (setq neg nil w (substring w 1))
4545 (setq neg nil)))
4546 (if (string-match "\\`{.*}\\'" w)
4547 (setq re (substring w 1 -1))
4548 (if full-words
4549 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4550 (setq re (regexp-quote (downcase w)))))
4551 (if neg (push re regexps-) (push re regexps+)))
4552 words)
4553 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4554 regexps+))
4555 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4556 (if (not regexps+)
4557 (setq regexp org-outline-regexp-bol)
4558 (setq regexp (pop regexps+))
4559 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4560 regexp))))
4561 (setq files (org-agenda-files nil 'ifmode))
4562 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4563 (pop org-agenda-text-search-extra-files)
4564 (setq files (org-add-archive-files files)))
4565 (setq files (append files org-agenda-text-search-extra-files)
4566 rtnall nil)
4567 (while (setq file (pop files))
4568 (setq ee nil)
4569 (catch 'nextfile
4570 (org-check-agenda-file file)
4571 (setq buffer (if (file-exists-p file)
4572 (org-get-agenda-file-buffer file)
4573 (error "No such file %s" file)))
4574 (if (not buffer)
4575 ;; If file does not exist, make sure an error message is sent
4576 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4577 file))))
4578 (with-current-buffer buffer
4579 (with-syntax-table (org-search-syntax-table)
4580 (unless (derived-mode-p 'org-mode)
4581 (error "Agenda file %s is not in `org-mode'" file))
4582 (let ((case-fold-search t))
4583 (save-excursion
4584 (save-restriction
4585 (if org-agenda-restrict
4586 (narrow-to-region org-agenda-restrict-begin
4587 org-agenda-restrict-end)
4588 (widen))
4589 (goto-char (point-min))
4590 (unless (or (org-at-heading-p)
4591 (outline-next-heading))
4592 (throw 'nextfile t))
4593 (goto-char (max (point-min) (1- (point))))
4594 (while (re-search-forward regexp nil t)
4595 (org-back-to-heading t)
4596 (while (and org-agenda-search-view-max-outline-level
4597 (> (org-reduced-level (org-outline-level))
4598 org-agenda-search-view-max-outline-level)
4599 (forward-line -1)
4600 (outline-back-to-heading t)))
4601 (skip-chars-forward "* ")
4602 (setq beg (point-at-bol)
4603 beg1 (point)
4604 end (progn
4605 (outline-next-heading)
4606 (while (and org-agenda-search-view-max-outline-level
4607 (> (org-reduced-level (org-outline-level))
4608 org-agenda-search-view-max-outline-level)
4609 (forward-line 1)
4610 (outline-next-heading)))
4611 (point)))
4613 (catch :skip
4614 (goto-char beg)
4615 (org-agenda-skip)
4616 (setq str (buffer-substring-no-properties
4617 (point-at-bol)
4618 (if hdl-only (point-at-eol) end)))
4619 (mapc (lambda (wr) (when (string-match wr str)
4620 (goto-char (1- end))
4621 (throw :skip t)))
4622 regexps-)
4623 (mapc (lambda (wr) (unless (string-match wr str)
4624 (goto-char (1- end))
4625 (throw :skip t)))
4626 (if todo-only
4627 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4628 regexps+)
4629 regexps+))
4630 (goto-char beg)
4631 (setq marker (org-agenda-new-marker (point))
4632 category (org-get-category)
4633 level (make-string (org-reduced-level (org-outline-level)) ? )
4634 category-pos (get-text-property (point) 'org-category-position)
4635 inherited-tags
4636 (or (eq org-agenda-show-inherited-tags 'always)
4637 (and (listp org-agenda-show-inherited-tags)
4638 (memq 'todo org-agenda-show-inherited-tags))
4639 (and (eq org-agenda-show-inherited-tags t)
4640 (or (eq org-agenda-use-tag-inheritance t)
4641 (memq 'todo org-agenda-use-tag-inheritance))))
4642 tags (org-get-tags-at nil (not inherited-tags))
4643 txt (org-agenda-format-item
4645 (buffer-substring-no-properties
4646 beg1 (point-at-eol))
4647 level category tags t))
4648 (org-add-props txt props
4649 'org-marker marker 'org-hd-marker marker
4650 'org-todo-regexp org-todo-regexp
4651 'level level
4652 'org-complex-heading-regexp org-complex-heading-regexp
4653 'priority 1000 'org-category category
4654 'org-category-position category-pos
4655 'type "search")
4656 (push txt ee)
4657 (goto-char (1- end))))))))))
4658 (setq rtn (nreverse ee))
4659 (setq rtnall (append rtnall rtn)))
4660 (if org-agenda-overriding-header
4661 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4662 nil 'face 'org-agenda-structure) "\n")
4663 (insert "Search words: ")
4664 (add-text-properties (point-min) (1- (point))
4665 (list 'face 'org-agenda-structure))
4666 (setq pos (point))
4667 (insert string "\n")
4668 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4669 (setq pos (point))
4670 (unless org-agenda-multi
4671 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4672 (add-text-properties pos (1- (point))
4673 (list 'face 'org-agenda-structure))))
4674 (org-agenda-mark-header-line (point-min))
4675 (when rtnall
4676 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4677 (goto-char (point-min))
4678 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4679 (add-text-properties (point-min) (point-max)
4680 `(org-agenda-type search
4681 org-last-args (,todo-only ,string ,edit-at)
4682 org-redo-cmd ,org-agenda-redo-command
4683 org-series-cmd ,org-cmd))
4684 (org-agenda-finalize)
4685 (setq buffer-read-only t))))
4687 (autoload 'org-search-view "org-agenda" "\
4688 Show all entries that contain a phrase or words or regular expressions.
4690 With optional prefix argument TODO-ONLY, only consider entries that are
4691 TODO entries. The argument STRING can be used to pass a default search
4692 string into this function. If EDIT-AT is non-nil, it means that the
4693 user should get a chance to edit this string, with cursor at position
4694 EDIT-AT.
4696 The search string can be viewed either as a phrase that should be found as
4697 is, or it can be broken into a number of snippets, each of which must match
4698 in a Boolean way to select an entry. The default depends on the variable
4699 `org-agenda-search-view-always-boolean'.
4700 Even if this is turned off (the default) you can always switch to
4701 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4703 The default is a direct search of the whole phrase, where each space in
4704 the search string can expand to an arbitrary amount of whitespace,
4705 including newlines.
4707 If using a Boolean search, the search string is split on whitespace and
4708 each snippet is searched separately, with logical AND to select an entry.
4709 Words prefixed with a minus must *not* occur in the entry. Words without
4710 a prefix or prefixed with a plus must occur in the entry. Matching is
4711 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4712 match whole words, not parts of a word) if
4713 `org-agenda-search-view-force-full-words' is set (default is nil).
4715 Boolean search snippets enclosed by curly braces are interpreted as
4716 regular expressions that must or (when preceded with \"-\") must not
4717 match in the entry. Snippets enclosed into double quotes will be taken
4718 as a whole, to include whitespace.
4720 - If the search string starts with an asterisk, search only in headlines.
4721 - If (possibly after the leading star) the search string starts with an
4722 exclamation mark, this also means to look at TODO entries only, an effect
4723 that can also be achieved with a prefix argument.
4724 - If (possibly after star and exclamation mark) the search string starts
4725 with a colon, this will mean that the (non-regexp) snippets of the
4726 Boolean search must match as full words.
4728 This command searches the agenda files, and in addition the files listed
4729 in `org-agenda-text-search-extra-files'.
4731 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4733 ;;; Agenda TODO list
4735 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4736 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4737 (concat
4738 (if (or (equal keywords "ALL") (not keywords))
4739 (propertize "ALL" 'face 'warning)
4740 (mapconcat
4741 (lambda (kw)
4742 (propertize kw 'face (org-get-todo-face kw)))
4743 (org-split-string keywords "|")
4744 "|"))
4745 "\n"))
4747 (defvar org-select-this-todo-keyword nil)
4748 (defvar org-last-arg nil)
4750 ;;;###autoload
4751 (defun org-todo-list (&optional arg)
4752 "Show all (not done) TODO entries from all agenda file in a single list.
4753 The prefix arg can be used to select a specific TODO keyword and limit
4754 the list to these. When using \\[universal-argument], you will be prompted
4755 for a keyword. A numeric prefix directly selects the Nth keyword in
4756 `org-todo-keywords-1'."
4757 (interactive "P")
4758 (if org-agenda-overriding-arguments
4759 (setq arg org-agenda-overriding-arguments))
4760 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4761 (let* ((today (org-today))
4762 (date (calendar-gregorian-from-absolute today))
4763 (kwds org-todo-keywords-for-agenda)
4764 (completion-ignore-case t)
4765 (org-select-this-todo-keyword
4766 (if (stringp arg) arg
4767 (and arg (integerp arg) (> arg 0)
4768 (nth (1- arg) kwds))))
4769 rtn rtnall files file pos)
4770 (when (equal arg '(4))
4771 (setq org-select-this-todo-keyword
4772 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4773 (mapcar 'list kwds) nil nil)))
4774 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4775 (catch 'exit
4776 (if org-agenda-sticky
4777 (setq org-agenda-buffer-name
4778 (if (stringp org-select-this-todo-keyword)
4779 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4780 org-select-this-todo-keyword)
4781 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4782 (org-agenda-prepare "TODO")
4783 (org-compile-prefix-format 'todo)
4784 (org-set-sorting-strategy 'todo)
4785 (setq org-agenda-redo-command
4786 `(org-todo-list (or (and (numberp current-prefix-arg)
4787 current-prefix-arg)
4788 ,org-select-this-todo-keyword
4789 current-prefix-arg ,arg)))
4790 (setq files (org-agenda-files nil 'ifmode)
4791 rtnall nil)
4792 (while (setq file (pop files))
4793 (catch 'nextfile
4794 (org-check-agenda-file file)
4795 (setq rtn (org-agenda-get-day-entries file date :todo))
4796 (setq rtnall (append rtnall rtn))))
4797 (if org-agenda-overriding-header
4798 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4799 nil 'face 'org-agenda-structure) "\n")
4800 (insert "Global list of TODO items of type: ")
4801 (add-text-properties (point-min) (1- (point))
4802 (list 'face 'org-agenda-structure
4803 'short-heading
4804 (concat "ToDo: "
4805 (or org-select-this-todo-keyword "ALL"))))
4806 (org-agenda-mark-header-line (point-min))
4807 (insert (org-agenda-propertize-selected-todo-keywords
4808 org-select-this-todo-keyword))
4809 (setq pos (point))
4810 (unless org-agenda-multi
4811 (insert "Available with `N r': (0)[ALL]")
4812 (let ((n 0) s)
4813 (mapc (lambda (x)
4814 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4815 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4816 (insert "\n "))
4817 (insert " " s))
4818 kwds))
4819 (insert "\n"))
4820 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4821 (org-agenda-mark-header-line (point-min))
4822 (when rtnall
4823 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4824 (goto-char (point-min))
4825 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4826 (add-text-properties (point-min) (point-max)
4827 `(org-agenda-type todo
4828 org-last-args ,arg
4829 org-redo-cmd ,org-agenda-redo-command
4830 org-series-cmd ,org-cmd))
4831 (org-agenda-finalize)
4832 (setq buffer-read-only t))))
4834 (autoload 'org-todo-list "org-agenda" "\
4835 Show all (not done) TODO entries from all agenda file in a single list.
4836 The prefix arg can be used to select a specific TODO keyword and limit
4837 the list to these. When using \\[universal-argument], you will be prompted
4838 for a keyword. A numeric prefix directly selects the Nth keyword in
4839 `org-todo-keywords-1'.
4841 \(fn &optional ARG)" t nil)
4843 ;;; Agenda tags match
4845 ;;;###autoload
4846 (defun org-tags-view (&optional todo-only match)
4847 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4848 The prefix arg TODO-ONLY limits the search to TODO entries."
4849 (interactive "P")
4850 (if org-agenda-overriding-arguments
4851 (setq todo-only (car org-agenda-overriding-arguments)
4852 match (nth 1 org-agenda-overriding-arguments)))
4853 (let* ((org-tags-match-list-sublevels
4854 org-tags-match-list-sublevels)
4855 (completion-ignore-case t)
4856 rtn rtnall files file pos matcher
4857 buffer)
4858 (when (and (stringp match) (not (string-match "\\S-" match)))
4859 (setq match nil))
4860 (setq matcher (org-make-tags-matcher match)
4861 match (car matcher) matcher (cdr matcher))
4862 (catch 'exit
4863 (if org-agenda-sticky
4864 (setq org-agenda-buffer-name
4865 (if (stringp match)
4866 (format "*Org Agenda(%s:%s)*"
4867 (or org-keys (or (and todo-only "M") "m")) match)
4868 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4869 (org-agenda-prepare (concat "TAGS " match))
4870 (org-compile-prefix-format 'tags)
4871 (org-set-sorting-strategy 'tags)
4872 (setq org-agenda-query-string match)
4873 (setq org-agenda-redo-command
4874 (list 'org-tags-view `(quote ,todo-only)
4875 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4876 (setq files (org-agenda-files nil 'ifmode)
4877 rtnall nil)
4878 (while (setq file (pop files))
4879 (catch 'nextfile
4880 (org-check-agenda-file file)
4881 (setq buffer (if (file-exists-p file)
4882 (org-get-agenda-file-buffer file)
4883 (error "No such file %s" file)))
4884 (if (not buffer)
4885 ;; If file does not exist, error message to agenda
4886 (setq rtn (list
4887 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4888 rtnall (append rtnall rtn))
4889 (with-current-buffer buffer
4890 (unless (derived-mode-p 'org-mode)
4891 (error "Agenda file %s is not in `org-mode'" file))
4892 (save-excursion
4893 (save-restriction
4894 (if org-agenda-restrict
4895 (narrow-to-region org-agenda-restrict-begin
4896 org-agenda-restrict-end)
4897 (widen))
4898 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4899 (setq rtnall (append rtnall rtn))))))))
4900 (if org-agenda-overriding-header
4901 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4902 nil 'face 'org-agenda-structure) "\n")
4903 (insert "Headlines with TAGS match: ")
4904 (add-text-properties (point-min) (1- (point))
4905 (list 'face 'org-agenda-structure
4906 'short-heading
4907 (concat "Match: " match)))
4908 (setq pos (point))
4909 (insert match "\n")
4910 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4911 (setq pos (point))
4912 (unless org-agenda-multi
4913 (insert "Press `C-u r' to search again with new search string\n"))
4914 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4915 (org-agenda-mark-header-line (point-min))
4916 (when rtnall
4917 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4918 (goto-char (point-min))
4919 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4920 (add-text-properties (point-min) (point-max)
4921 `(org-agenda-type tags
4922 org-last-args (,todo-only ,match)
4923 org-redo-cmd ,org-agenda-redo-command
4924 org-series-cmd ,org-cmd))
4925 (org-agenda-finalize)
4926 (setq buffer-read-only t))))
4928 (autoload 'org-tags-view "org-agenda" "\
4929 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4930 The prefix arg TODO-ONLY limits the search to TODO entries.
4932 \(fn &optional TODO-ONLY MATCH)" t nil)
4934 ;;; Agenda Finding stuck projects
4936 (defvar org-agenda-skip-regexp nil
4937 "Regular expression used in skipping subtrees for the agenda.
4938 This is basically a temporary global variable that can be set and then
4939 used by user-defined selections using `org-agenda-skip-function'.")
4941 (defvar org-agenda-overriding-header nil
4942 "When set during agenda, todo and tags searches it replaces the header.
4943 This variable should not be set directly, but custom commands can bind it
4944 in the options section.")
4946 (defun org-agenda-skip-entry-when-regexp-matches ()
4947 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4948 If yes, it returns the end position of this entry, causing agenda commands
4949 to skip the entry but continuing the search in the subtree. This is a
4950 function that can be put into `org-agenda-skip-function' for the duration
4951 of a command."
4952 (let ((end (save-excursion (org-end-of-subtree t)))
4953 skip)
4954 (save-excursion
4955 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4956 (and skip end)))
4958 (defun org-agenda-skip-subtree-when-regexp-matches ()
4959 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4960 If yes, it returns the end position of this tree, causing agenda commands
4961 to skip this subtree. This is a function that can be put into
4962 `org-agenda-skip-function' for the duration of a command."
4963 (let ((end (save-excursion (org-end-of-subtree t)))
4964 skip)
4965 (save-excursion
4966 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4967 (and skip end)))
4969 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4970 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4971 If yes, it returns the end position of the current entry (NOT the tree),
4972 causing agenda commands to skip the entry but continuing the search in
4973 the subtree. This is a function that can be put into
4974 `org-agenda-skip-function' for the duration of a command. An important
4975 use of this function is for the stuck project list."
4976 (let ((end (save-excursion (org-end-of-subtree t)))
4977 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4978 skip)
4979 (save-excursion
4980 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4981 (and skip entry-end)))
4983 (defun org-agenda-skip-entry-if (&rest conditions)
4984 "Skip entry if any of CONDITIONS is true.
4985 See `org-agenda-skip-if' for details."
4986 (org-agenda-skip-if nil conditions))
4988 (defun org-agenda-skip-subtree-if (&rest conditions)
4989 "Skip entry if any of CONDITIONS is true.
4990 See `org-agenda-skip-if' for details."
4991 (org-agenda-skip-if t conditions))
4993 (defun org-agenda-skip-if (subtree conditions)
4994 "Checks current entity for CONDITIONS.
4995 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4996 the entry (i.e. the text before the next heading) is checked.
4998 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4999 from different tests. Valid conditions are:
5001 scheduled Check if there is a scheduled cookie
5002 notscheduled Check if there is no scheduled cookie
5003 deadline Check if there is a deadline
5004 notdeadline Check if there is no deadline
5005 timestamp Check if there is a timestamp (also deadline or scheduled)
5006 nottimestamp Check if there is no timestamp (also deadline or scheduled)
5007 regexp Check if regexp matches
5008 notregexp Check if regexp does not match.
5009 todo Check if TODO keyword matches
5010 nottodo Check if TODO keyword does not match
5012 The regexp is taken from the conditions list, it must come right after
5013 the `regexp' or `notregexp' element.
5015 `todo' and `nottodo' accept as an argument a list of todo
5016 keywords, which may include \"*\" to match any todo keyword.
5018 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
5020 would skip all entries with \"TODO\" or \"WAITING\" keywords.
5022 Instead of a list, a keyword class may be given. For example:
5024 (org-agenda-skip-entry-if 'nottodo 'done)
5026 would skip entries that haven't been marked with any of \"DONE\"
5027 keywords. Possible classes are: `todo', `done', `any'.
5029 If any of these conditions is met, this function returns the end point of
5030 the entity, causing the search to continue from there. This is a function
5031 that can be put into `org-agenda-skip-function' for the duration of a command."
5032 (let (beg end m)
5033 (org-back-to-heading t)
5034 (setq beg (point)
5035 end (if subtree
5036 (progn (org-end-of-subtree t) (point))
5037 (progn (outline-next-heading) (1- (point)))))
5038 (goto-char beg)
5039 (and
5041 (and (memq 'scheduled conditions)
5042 (re-search-forward org-scheduled-time-regexp end t))
5043 (and (memq 'notscheduled conditions)
5044 (not (re-search-forward org-scheduled-time-regexp end t)))
5045 (and (memq 'deadline conditions)
5046 (re-search-forward org-deadline-time-regexp end t))
5047 (and (memq 'notdeadline conditions)
5048 (not (re-search-forward org-deadline-time-regexp end t)))
5049 (and (memq 'timestamp conditions)
5050 (re-search-forward org-ts-regexp end t))
5051 (and (memq 'nottimestamp conditions)
5052 (not (re-search-forward org-ts-regexp end t)))
5053 (and (setq m (memq 'regexp conditions))
5054 (stringp (nth 1 m))
5055 (re-search-forward (nth 1 m) end t))
5056 (and (setq m (memq 'notregexp conditions))
5057 (stringp (nth 1 m))
5058 (not (re-search-forward (nth 1 m) end t)))
5059 (and (or
5060 (setq m (memq 'nottodo conditions))
5061 (setq m (memq 'todo-unblocked conditions))
5062 (setq m (memq 'nottodo-unblocked conditions))
5063 (setq m (memq 'todo conditions)))
5064 (org-agenda-skip-if-todo m end)))
5065 end)))
5067 (defun org-agenda-skip-if-todo (args end)
5068 "Helper function for `org-agenda-skip-if', do not use it directly.
5069 ARGS is a list with first element either `todo', `nottodo',
5070 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
5071 a list of TODO keywords, or a state symbol `todo' or `done' or
5072 `any'."
5073 (let ((kw (car args))
5074 (arg (cadr args))
5075 todo-wds todo-re)
5076 (setq todo-wds
5077 (org-uniquify
5078 (cond
5079 ((listp arg) ;; list of keywords
5080 (if (member "*" arg)
5081 (mapcar 'substring-no-properties org-todo-keywords-1)
5082 arg))
5083 ((symbolp arg) ;; keyword class name
5084 (cond
5085 ((eq arg 'todo)
5086 (org-delete-all org-done-keywords
5087 (mapcar 'substring-no-properties
5088 org-todo-keywords-1)))
5089 ((eq arg 'done) org-done-keywords)
5090 ((eq arg 'any)
5091 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5092 (setq todo-re
5093 (concat "^\\*+[ \t]+\\<\\("
5094 (mapconcat 'identity todo-wds "\\|")
5095 "\\)\\>"))
5096 (cond
5097 ((eq kw 'todo) (re-search-forward todo-re end t))
5098 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5099 ((eq kw 'todo-unblocked)
5100 (catch 'unblocked
5101 (while (re-search-forward todo-re end t)
5102 (or (org-entry-blocked-p) (throw 'unblocked t)))
5103 nil))
5104 ((eq kw 'nottodo-unblocked)
5105 (catch 'unblocked
5106 (while (re-search-forward todo-re end t)
5107 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5111 ;;;###autoload
5112 (defun org-agenda-list-stuck-projects (&rest ignore)
5113 "Create agenda view for projects that are stuck.
5114 Stuck projects are project that have no next actions. For the definitions
5115 of what a project is and how to check if it stuck, customize the variable
5116 `org-stuck-projects'."
5117 (interactive)
5118 (let* ((org-agenda-skip-function
5119 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5120 ;; We could have used org-agenda-skip-if here.
5121 (org-agenda-overriding-header
5122 (or org-agenda-overriding-header "List of stuck projects: "))
5123 (matcher (nth 0 org-stuck-projects))
5124 (todo (nth 1 org-stuck-projects))
5125 (todo-wds (if (member "*" todo)
5126 (progn
5127 (org-agenda-prepare-buffers (org-agenda-files
5128 nil 'ifmode))
5129 (org-delete-all
5130 org-done-keywords-for-agenda
5131 (copy-sequence org-todo-keywords-for-agenda)))
5132 todo))
5133 (todo-re (concat "^\\*+[ \t]+\\("
5134 (mapconcat 'identity todo-wds "\\|")
5135 "\\)\\>"))
5136 (tags (nth 2 org-stuck-projects))
5137 (tags-re (if (member "*" tags)
5138 (concat org-outline-regexp-bol
5139 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5140 (if tags
5141 (concat org-outline-regexp-bol
5142 ".*:\\("
5143 (mapconcat 'identity tags "\\|")
5144 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5145 (gen-re (nth 3 org-stuck-projects))
5146 (re-list
5147 (delq nil
5148 (list
5149 (if todo todo-re)
5150 (if tags tags-re)
5151 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5152 gen-re)))))
5153 (setq org-agenda-skip-regexp
5154 (if re-list
5155 (mapconcat 'identity re-list "\\|")
5156 (error "No information how to identify unstuck projects")))
5157 (org-tags-view nil matcher)
5158 (with-current-buffer org-agenda-buffer-name
5159 (setq org-agenda-redo-command
5160 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5162 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
5163 Create agenda view for projects that are stuck.
5164 Stuck projects are project that have no next actions. For the definitions
5165 of what a project is and how to check if it stuck, customize the variable
5166 `org-stuck-projects'.
5168 \(fn &rest IGNORE)" t nil)
5170 ;;; Diary integration
5172 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5173 (defvar diary-list-entries-hook)
5174 (defvar diary-time-regexp)
5175 (defun org-get-entries-from-diary (date)
5176 "Get the (Emacs Calendar) diary entries for DATE."
5177 (require 'diary-lib)
5178 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5179 (diary-display-hook '(fancy-diary-display))
5180 (diary-display-function 'fancy-diary-display)
5181 (pop-up-frames nil)
5182 (diary-list-entries-hook
5183 (cons 'org-diary-default-entry diary-list-entries-hook))
5184 (diary-file-name-prefix nil) ; turn this feature off
5185 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5186 entries
5187 (org-disable-agenda-to-diary t))
5188 (save-excursion
5189 (save-window-excursion
5190 (funcall (if (fboundp 'diary-list-entries)
5191 'diary-list-entries 'list-diary-entries)
5192 date 1)))
5193 (if (not (get-buffer diary-fancy-buffer))
5194 (setq entries nil)
5195 (with-current-buffer diary-fancy-buffer
5196 (setq buffer-read-only nil)
5197 (if (zerop (buffer-size))
5198 ;; No entries
5199 (setq entries nil)
5200 ;; Omit the date and other unnecessary stuff
5201 (org-agenda-cleanup-fancy-diary)
5202 ;; Add prefix to each line and extend the text properties
5203 (if (zerop (buffer-size))
5204 (setq entries nil)
5205 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5206 (setq entries
5207 (with-temp-buffer
5208 (insert entries) (goto-char (point-min))
5209 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5210 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5211 (replace-match (concat "; " (match-string 1)))))
5212 (buffer-string)))))
5213 (set-buffer-modified-p nil)
5214 (kill-buffer diary-fancy-buffer)))
5215 (when entries
5216 (setq entries (org-split-string entries "\n"))
5217 (setq entries
5218 (mapcar
5219 (lambda (x)
5220 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5221 ;; Extend the text properties to the beginning of the line
5222 (org-add-props x (text-properties-at (1- (length x)) x)
5223 'type "diary" 'date date 'face 'org-agenda-diary))
5224 entries)))))
5226 (defvar org-agenda-cleanup-fancy-diary-hook nil
5227 "Hook run when the fancy diary buffer is cleaned up.")
5229 (defun org-agenda-cleanup-fancy-diary ()
5230 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5231 This gets rid of the date, the underline under the date, and
5232 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5233 date. It also removes lines that contain only whitespace."
5234 (goto-char (point-min))
5235 (if (looking-at ".*?:[ \t]*")
5236 (progn
5237 (replace-match "")
5238 (re-search-forward "\n=+$" nil t)
5239 (replace-match "")
5240 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5241 (re-search-forward "\n=+$" nil t)
5242 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5243 (goto-char (point-min))
5244 (while (re-search-forward "^ +\n" nil t)
5245 (replace-match ""))
5246 (goto-char (point-min))
5247 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5248 (replace-match ""))
5249 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5251 ;; Make sure entries from the diary have the right text properties.
5252 (eval-after-load "diary-lib"
5253 '(if (boundp 'diary-modify-entry-list-string-function)
5254 ;; We can rely on the hook, nothing to do
5256 ;; Hook not available, must use advice to make this work
5257 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5258 "Make the position visible."
5259 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5260 (stringp string)
5261 buffer-file-name)
5262 (setq string (org-modify-diary-entry-string string))))))
5264 (defun org-modify-diary-entry-string (string)
5265 "Add text properties to string, allowing org-mode to act on it."
5266 (org-add-props string nil
5267 'mouse-face 'highlight
5268 'help-echo (if buffer-file-name
5269 (format "mouse-2 or RET jump to diary file %s"
5270 (abbreviate-file-name buffer-file-name))
5272 'org-agenda-diary-link t
5273 'org-marker (org-agenda-new-marker (point-at-bol))))
5275 (defun org-diary-default-entry ()
5276 "Add a dummy entry to the diary.
5277 Needed to avoid empty dates which mess up holiday display."
5278 ;; Catch the error if dealing with the new add-to-diary-alist
5279 (when org-disable-agenda-to-diary
5280 (condition-case nil
5281 (org-add-to-diary-list original-date "Org-mode dummy" "")
5282 (error
5283 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5285 (defun org-add-to-diary-list (&rest args)
5286 (if (fboundp 'diary-add-to-list)
5287 (apply 'diary-add-to-list args)
5288 (apply 'add-to-diary-list args)))
5290 (defvar org-diary-last-run-time nil)
5292 ;;;###autoload
5293 (defun org-diary (&rest args)
5294 "Return diary information from org files.
5295 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5296 It accesses org files and extracts information from those files to be
5297 listed in the diary. The function accepts arguments specifying what
5298 items should be listed. For a list of arguments allowed here, see the
5299 variable `org-agenda-entry-types'.
5301 The call in the diary file should look like this:
5303 &%%(org-diary) ~/path/to/some/orgfile.org
5305 Use a separate line for each org file to check. Or, if you omit the file name,
5306 all files listed in `org-agenda-files' will be checked automatically:
5308 &%%(org-diary)
5310 If you don't give any arguments (as in the example above), the default
5311 arguments (:deadline :scheduled :timestamp :sexp) are used.
5312 So the example above may also be written as
5314 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5316 The function expects the lisp variables `entry' and `date' to be provided
5317 by the caller, because this is how the calendar works. Don't use this
5318 function from a program - use `org-agenda-get-day-entries' instead."
5319 (when (> (- (org-float-time)
5320 org-agenda-last-marker-time)
5322 ;; I am not sure if this works with sticky agendas, because the marker
5323 ;; list is then no longer a global variable.
5324 (org-agenda-reset-markers))
5325 (org-compile-prefix-format 'agenda)
5326 (org-set-sorting-strategy 'agenda)
5327 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5328 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5329 (list entry)
5330 (org-agenda-files t)))
5331 (time (org-float-time))
5332 file rtn results)
5333 (when (or (not org-diary-last-run-time)
5334 (> (- time
5335 org-diary-last-run-time)
5337 (org-agenda-prepare-buffers files))
5338 (setq org-diary-last-run-time time)
5339 ;; If this is called during org-agenda, don't return any entries to
5340 ;; the calendar. Org Agenda will list these entries itself.
5341 (if org-disable-agenda-to-diary (setq files nil))
5342 (while (setq file (pop files))
5343 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5344 (setq results (append results rtn)))
5345 (when results
5346 (setq results
5347 (mapcar (lambda (i) (replace-regexp-in-string
5348 org-bracket-link-regexp "\\3" i)) results))
5349 (concat (org-agenda-finalize-entries results) "\n"))))
5351 (autoload 'org-diary "org-agenda" "\
5352 Return diary information from org files.
5353 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5354 It accesses org files and extracts information from those files to be
5355 listed in the diary. The function accepts arguments specifying what
5356 items should be listed. For a list of arguments allowed here, see the
5357 variable `org-agenda-entry-types'.
5359 The call in the diary file should look like this:
5361 &%%(org-diary) ~/path/to/some/orgfile.org
5363 Use a separate line for each org file to check. Or, if you omit the file name,
5364 all files listed in `org-agenda-files' will be checked automatically:
5366 &%%(org-diary)
5368 If you don't give any arguments (as in the example above), the default
5369 arguments (:deadline :scheduled :timestamp :sexp) are used.
5370 So the example above may also be written as
5372 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5374 The function expects the lisp variables `entry' and `date' to be provided
5375 by the caller, because this is how the calendar works. Don't use this
5376 function from a program - use `org-agenda-get-day-entries' instead.
5378 \(fn &rest ARGS)" nil nil)
5380 ;;; Agenda entry finders
5382 (defun org-agenda-get-day-entries (file date &rest args)
5383 "Does the work for `org-diary' and `org-agenda'.
5384 FILE is the path to a file to be checked for entries. DATE is date like
5385 the one returned by `calendar-current-date'. ARGS are symbols indicating
5386 which kind of entries should be extracted. For details about these, see
5387 the documentation of `org-diary'."
5388 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5389 (let* ((org-startup-folded nil)
5390 (org-startup-align-all-tables nil)
5391 (buffer (if (file-exists-p file)
5392 (org-get-agenda-file-buffer file)
5393 (error "No such file %s" file)))
5394 arg results rtn deadline-results)
5395 (if (not buffer)
5396 ;; If file does not exist, make sure an error message ends up in diary
5397 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5398 (with-current-buffer buffer
5399 (unless (derived-mode-p 'org-mode)
5400 (error "Agenda file %s is not in `org-mode'" file))
5401 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5402 (let ((case-fold-search nil))
5403 (save-excursion
5404 (save-restriction
5405 (if org-agenda-restrict
5406 (narrow-to-region org-agenda-restrict-begin
5407 org-agenda-restrict-end)
5408 (widen))
5409 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5410 (while (setq arg (pop args))
5411 (cond
5412 ((and (eq arg :todo)
5413 (equal date (calendar-gregorian-from-absolute
5414 (org-today))))
5415 (setq rtn (org-agenda-get-todos))
5416 (setq results (append results rtn)))
5417 ((eq arg :timestamp)
5418 (setq rtn (org-agenda-get-blocks))
5419 (setq results (append results rtn))
5420 (setq rtn (org-agenda-get-timestamps deadline-results))
5421 (setq results (append results rtn)))
5422 ((eq arg :sexp)
5423 (setq rtn (org-agenda-get-sexps))
5424 (setq results (append results rtn)))
5425 ((eq arg :scheduled)
5426 (setq rtn (org-agenda-get-scheduled deadline-results))
5427 (setq results (append results rtn)))
5428 ((eq arg :closed)
5429 (setq rtn (org-agenda-get-progress))
5430 (setq results (append results rtn)))
5431 ((eq arg :deadline)
5432 (setq rtn (org-agenda-get-deadlines))
5433 (setq deadline-results (copy-sequence rtn))
5434 (setq results (append results rtn))))))))
5435 results))))
5437 (defsubst org-em (x y list)
5438 "Is X or Y a member of LIST?"
5439 (or (memq x list) (memq y list)))
5441 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5442 (defvar org-agenda-sorting-strategy-selected nil)
5444 (defun org-agenda-get-todos ()
5445 "Return the TODO information for agenda display."
5446 (let* ((props (list 'face nil
5447 'done-face 'org-agenda-done
5448 'org-not-done-regexp org-not-done-regexp
5449 'org-todo-regexp org-todo-regexp
5450 'org-complex-heading-regexp org-complex-heading-regexp
5451 'mouse-face 'highlight
5452 'help-echo
5453 (format "mouse-2 or RET jump to org file %s"
5454 (abbreviate-file-name buffer-file-name))))
5455 (regexp (format org-heading-keyword-regexp-format
5456 (cond
5457 ((and org-select-this-todo-keyword
5458 (equal org-select-this-todo-keyword "*"))
5459 org-todo-regexp)
5460 (org-select-this-todo-keyword
5461 (concat "\\("
5462 (mapconcat 'identity
5463 (org-split-string
5464 org-select-this-todo-keyword
5465 "|")
5466 "\\|") "\\)"))
5467 (t org-not-done-regexp))))
5468 marker priority category category-pos level tags todo-state ts-date ts-date-type
5469 ee txt beg end inherited-tags)
5470 (goto-char (point-min))
5471 (while (re-search-forward regexp nil t)
5472 (catch :skip
5473 (save-match-data
5474 (beginning-of-line)
5475 (org-agenda-skip)
5476 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
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))
5480 (throw :skip nil)))
5481 (goto-char (match-beginning 2))
5482 (setq marker (org-agenda-new-marker (match-beginning 0))
5483 category (org-get-category)
5484 ts-date (let (ts)
5485 (save-match-data
5486 (cond ((org-em 'scheduled-up 'scheduled-down
5487 org-agenda-sorting-strategy-selected)
5488 (setq ts (org-entry-get (point) "SCHEDULED")
5489 ts-date-type " scheduled"))
5490 ((org-em 'deadline-up 'deadline-down
5491 org-agenda-sorting-strategy-selected)
5492 (setq ts (org-entry-get (point) "DEADLINE")
5493 ts-date-type " deadline"))
5494 ((org-em 'ts-up 'ts-down
5495 org-agenda-sorting-strategy-selected)
5496 (setq ts (org-entry-get (point) "TIMESTAMP")
5497 ts-date-type " timestamp"))
5498 ((org-em 'tsia-up 'tsia-down
5499 org-agenda-sorting-strategy-selected)
5500 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5501 ts-date-type " timestamp_ia"))
5502 ((org-em 'timestamp-up 'timestamp-down
5503 org-agenda-sorting-strategy-selected)
5504 (setq ts (or (org-entry-get (point) "SCHEDULED")
5505 (org-entry-get (point) "DEADLINE")
5506 (org-entry-get (point) "TIMESTAMP")
5507 (org-entry-get (point) "TIMESTAMP_IA"))
5508 ts-date-type ""))
5509 (t (setq ts-date-type "")))
5510 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5511 category-pos (get-text-property (point) 'org-category-position)
5512 txt (org-trim
5513 (buffer-substring (match-beginning 2) (match-end 0)))
5514 inherited-tags
5515 (or (eq org-agenda-show-inherited-tags 'always)
5516 (and (listp org-agenda-show-inherited-tags)
5517 (memq 'todo org-agenda-show-inherited-tags))
5518 (and (eq org-agenda-show-inherited-tags t)
5519 (or (eq org-agenda-use-tag-inheritance t)
5520 (memq 'todo org-agenda-use-tag-inheritance))))
5521 tags (org-get-tags-at nil (not inherited-tags))
5522 level (make-string (org-reduced-level (org-outline-level)) ? )
5523 txt (org-agenda-format-item "" txt level category tags t)
5524 priority (1+ (org-get-priority txt))
5525 todo-state (org-get-todo-state))
5526 (org-add-props txt props
5527 'org-marker marker 'org-hd-marker marker
5528 'priority priority 'org-category category
5529 'level level
5530 'ts-date ts-date
5531 'org-category-position category-pos
5532 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5533 (push txt ee)
5534 (if org-agenda-todo-list-sublevels
5535 (goto-char (match-end 2))
5536 (org-end-of-subtree 'invisible))))
5537 (nreverse ee)))
5539 (defun org-agenda-todo-custom-ignore-p (time n)
5540 "Check whether timestamp is farther away than n number of days.
5541 This function is invoked if `org-agenda-todo-ignore-deadlines',
5542 `org-agenda-todo-ignore-scheduled' or
5543 `org-agenda-todo-ignore-timestamp' is set to an integer."
5544 (let ((days (org-time-stamp-to-now
5545 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5546 (if (>= n 0)
5547 (>= days n)
5548 (<= days n))))
5550 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5551 (&optional end)
5552 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5553 (when (or org-agenda-todo-ignore-with-date
5554 org-agenda-todo-ignore-scheduled
5555 org-agenda-todo-ignore-deadlines
5556 org-agenda-todo-ignore-timestamp)
5557 (setq end (or end (save-excursion (outline-next-heading) (point))))
5558 (save-excursion
5559 (or (and org-agenda-todo-ignore-with-date
5560 (re-search-forward org-ts-regexp end t))
5561 (and org-agenda-todo-ignore-scheduled
5562 (re-search-forward org-scheduled-time-regexp end t)
5563 (cond
5564 ((eq org-agenda-todo-ignore-scheduled 'future)
5565 (> (org-time-stamp-to-now
5566 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5567 ((eq org-agenda-todo-ignore-scheduled 'past)
5568 (<= (org-time-stamp-to-now
5569 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5570 ((numberp org-agenda-todo-ignore-scheduled)
5571 (org-agenda-todo-custom-ignore-p
5572 (match-string 1) org-agenda-todo-ignore-scheduled))
5573 (t)))
5574 (and org-agenda-todo-ignore-deadlines
5575 (re-search-forward org-deadline-time-regexp end t)
5576 (cond
5577 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5578 ((eq org-agenda-todo-ignore-deadlines 'far)
5579 (not (org-deadline-close (match-string 1))))
5580 ((eq org-agenda-todo-ignore-deadlines '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-deadlines '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-deadlines)
5587 (org-agenda-todo-custom-ignore-p
5588 (match-string 1) org-agenda-todo-ignore-deadlines))
5589 (t (org-deadline-close (match-string 1)))))
5590 (and org-agenda-todo-ignore-timestamp
5591 (let ((buffer (current-buffer))
5592 (regexp
5593 (concat
5594 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5595 (start (point)))
5596 ;; Copy current buffer into a temporary one
5597 (with-temp-buffer
5598 (insert-buffer-substring buffer start end)
5599 (goto-char (point-min))
5600 ;; Delete SCHEDULED and DEADLINE items
5601 (while (re-search-forward regexp end t)
5602 (delete-region (match-beginning 0) (match-end 0)))
5603 (goto-char (point-min))
5604 ;; No search for timestamp left
5605 (when (re-search-forward org-ts-regexp nil t)
5606 (cond
5607 ((eq org-agenda-todo-ignore-timestamp 'future)
5608 (> (org-time-stamp-to-now
5609 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5610 ((eq org-agenda-todo-ignore-timestamp 'past)
5611 (<= (org-time-stamp-to-now
5612 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5613 ((numberp org-agenda-todo-ignore-timestamp)
5614 (org-agenda-todo-custom-ignore-p
5615 (match-string 1) org-agenda-todo-ignore-timestamp))
5616 (t))))))))))
5618 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5619 Do we have a reason to ignore this TODO entry because it has a time stamp?
5621 \(fn &optional END)" nil nil)
5623 (defun org-agenda-get-timestamps (&optional deadline-results)
5624 "Return the date stamp information for agenda display."
5625 (let* ((props (list 'face 'org-agenda-calendar-event
5626 'org-not-done-regexp org-not-done-regexp
5627 'org-todo-regexp org-todo-regexp
5628 'org-complex-heading-regexp org-complex-heading-regexp
5629 'mouse-face 'highlight
5630 'help-echo
5631 (format "mouse-2 or RET jump to org file %s"
5632 (abbreviate-file-name buffer-file-name))))
5633 (d1 (calendar-absolute-from-gregorian date))
5635 (deadline-position-alist
5636 (mapcar (lambda (a) (and (setq mm (get-text-property
5637 0 'org-hd-marker a))
5638 (cons (marker-position mm) a)))
5639 deadline-results))
5640 (remove-re org-ts-regexp)
5641 (regexp
5642 (concat
5643 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5644 (regexp-quote
5645 (substring
5646 (format-time-string
5647 (car org-time-stamp-formats)
5648 (apply 'encode-time ; DATE bound by calendar
5649 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5650 1 11))
5651 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5652 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5653 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5654 donep tmp priority category category-pos level ee txt timestr tags
5655 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5656 inherited-tags ts-date)
5657 (goto-char (point-min))
5658 (while (setq end-of-match (re-search-forward regexp nil t))
5659 (setq b0 (match-beginning 0)
5660 b3 (match-beginning 3) e3 (match-end 3)
5661 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5662 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5663 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5664 (member todo-state
5665 org-agenda-repeating-timestamp-show-all)))
5666 (catch :skip
5667 (and (org-at-date-range-p) (throw :skip nil))
5668 (org-agenda-skip)
5669 (if (and (match-end 1)
5670 (not (= d1 (org-time-string-to-absolute
5671 (match-string 1) d1 nil show-all
5672 (current-buffer) b0))))
5673 (throw :skip nil))
5674 (if (and e3
5675 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5676 (throw :skip nil))
5677 (setq tmp (buffer-substring (max (point-min)
5678 (- b0 org-ds-keyword-length))
5680 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5681 inactivep (= (char-after b0) ?\[)
5682 deadlinep (string-match org-deadline-regexp tmp)
5683 scheduledp (string-match org-scheduled-regexp tmp)
5684 closedp (and org-agenda-include-inactive-timestamps
5685 (string-match org-closed-string tmp))
5686 clockp (and org-agenda-include-inactive-timestamps
5687 (or (string-match org-clock-string tmp)
5688 (string-match "]-+\\'" tmp)))
5689 warntime (get-text-property (point) 'org-appt-warntime)
5690 donep (member todo-state org-done-keywords))
5691 (if (or scheduledp deadlinep closedp clockp
5692 (and donep org-agenda-skip-timestamp-if-done))
5693 (throw :skip t))
5694 (if (string-match ">" timestr)
5695 ;; substring should only run to end of time stamp
5696 (setq timestr (substring timestr 0 (match-end 0))))
5697 (setq marker (org-agenda-new-marker b0)
5698 category (org-get-category b0)
5699 category-pos (get-text-property b0 'org-category-position))
5700 (save-excursion
5701 (if (not (re-search-backward org-outline-regexp-bol nil t))
5702 (throw :skip nil)
5703 (goto-char (match-beginning 0))
5704 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5705 (assoc (point) deadline-position-alist))
5706 (throw :skip nil))
5707 (setq hdmarker (org-agenda-new-marker)
5708 inherited-tags
5709 (or (eq org-agenda-show-inherited-tags 'always)
5710 (and (listp org-agenda-show-inherited-tags)
5711 (memq 'agenda org-agenda-show-inherited-tags))
5712 (and (eq org-agenda-show-inherited-tags t)
5713 (or (eq org-agenda-use-tag-inheritance t)
5714 (memq 'agenda org-agenda-use-tag-inheritance))))
5715 tags (org-get-tags-at nil (not inherited-tags))
5716 level (make-string (org-reduced-level (org-outline-level)) ? ))
5717 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5718 (setq head (or (match-string 1) ""))
5719 (setq txt (org-agenda-format-item
5720 (if inactivep org-agenda-inactive-leader nil)
5721 head level category tags timestr
5722 remove-re habitp)))
5723 (setq priority (org-get-priority txt))
5724 (org-add-props txt props 'priority priority
5725 'org-marker marker 'org-hd-marker hdmarker
5726 'org-category category 'date date
5727 'level level
5728 'ts-date
5729 (ignore-errors (org-time-string-to-absolute timestr))
5730 'org-category-position category-pos
5731 'todo-state todo-state
5732 'warntime warntime
5733 'type "timestamp")
5734 (push txt ee))
5735 (if org-agenda-skip-additional-timestamps-same-entry
5736 (outline-next-heading)
5737 (goto-char end-of-match))))
5738 (nreverse ee)))
5740 (defun org-agenda-get-sexps ()
5741 "Return the sexp information for agenda display."
5742 (require 'diary-lib)
5743 (let* ((props (list 'face 'org-agenda-calendar-sexp
5744 'mouse-face 'highlight
5745 'help-echo
5746 (format "mouse-2 or RET jump to org file %s"
5747 (abbreviate-file-name buffer-file-name))))
5748 (regexp "^&?%%(")
5749 marker category extra category-pos level ee txt tags entry
5750 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5751 (goto-char (point-min))
5752 (while (re-search-forward regexp nil t)
5753 (catch :skip
5754 (org-agenda-skip)
5755 (setq beg (match-beginning 0))
5756 (goto-char (1- (match-end 0)))
5757 (setq b (point))
5758 (forward-sexp 1)
5759 (setq sexp (buffer-substring b (point)))
5760 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5761 (org-trim (match-string 1))
5762 ""))
5763 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5764 (when result
5765 (setq marker (org-agenda-new-marker beg)
5766 level (make-string (org-reduced-level (org-outline-level)) ? )
5767 category (org-get-category beg)
5768 category-pos (get-text-property beg 'org-category-position)
5769 inherited-tags
5770 (or (eq org-agenda-show-inherited-tags 'always)
5771 (and (listp org-agenda-show-inherited-tags)
5772 (memq 'agenda org-agenda-show-inherited-tags))
5773 (and (eq org-agenda-show-inherited-tags t)
5774 (or (eq org-agenda-use-tag-inheritance t)
5775 (memq 'agenda org-agenda-use-tag-inheritance))))
5776 tags (org-get-tags-at nil (not inherited-tags))
5777 todo-state (org-get-todo-state)
5778 warntime (get-text-property (point) 'org-appt-warntime)
5779 extra nil)
5781 (dolist (r (if (stringp result)
5782 (list result)
5783 result)) ;; we expect a list here
5784 (when (and org-agenda-diary-sexp-prefix
5785 (string-match org-agenda-diary-sexp-prefix r))
5786 (setq extra (match-string 0 r)
5787 r (replace-match "" nil nil r)))
5788 (if (string-match "\\S-" r)
5789 (setq txt r)
5790 (setq txt "SEXP entry returned empty string"))
5791 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5792 (org-add-props txt props 'org-marker marker
5793 'org-category category 'date date 'todo-state todo-state
5794 'org-category-position category-pos 'tags tags
5795 'level level
5796 'type "sexp" 'warntime warntime)
5797 (push txt ee)))))
5798 (nreverse ee)))
5800 ;; Calendar sanity: define some functions that are independent of
5801 ;; `calendar-date-style'.
5802 ;; Normally I would like to use ISO format when calling the diary functions,
5803 ;; but to make sure we still have Emacs 22 compatibility we bind
5804 ;; also `european-calendar-style' and use european format
5805 (defun org-anniversary (year month day &optional mark)
5806 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5807 (org-no-warnings
5808 (let ((calendar-date-style 'european) (european-calendar-style t))
5809 (diary-anniversary day month year mark))))
5810 (defun org-cyclic (N year month day &optional mark)
5811 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5812 (org-no-warnings
5813 (let ((calendar-date-style 'european) (european-calendar-style t))
5814 (diary-cyclic N day month year mark))))
5815 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5816 "Like `diary-block', but with fixed (ISO) order of arguments."
5817 (org-no-warnings
5818 (let ((calendar-date-style 'european) (european-calendar-style t))
5819 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5820 (defun org-date (year month day &optional mark)
5821 "Like `diary-date', but with fixed (ISO) order of arguments."
5822 (org-no-warnings
5823 (let ((calendar-date-style 'european) (european-calendar-style t))
5824 (diary-date day month year mark))))
5826 ;; Define the` org-class' function
5827 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5828 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5829 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5830 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5831 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5832 `holidays', then any date that is known by the Emacs calendar to be a
5833 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5834 then those holidays will be skipped."
5835 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5836 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5837 (d (calendar-absolute-from-gregorian date))
5838 (h (when skip-weeks (calendar-check-holidays date))))
5839 (and
5840 (<= date1 d)
5841 (<= d date2)
5842 (= (calendar-day-of-week date) dayname)
5843 (or (not skip-weeks)
5844 (progn
5845 (require 'cal-iso)
5846 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5847 (not (or (and h (memq 'holidays skip-weeks))
5848 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5849 entry)))
5851 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5852 "Like `org-class', but honor `calendar-date-style'.
5853 The order of the first 2 times 3 arguments depends on the variable
5854 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5855 So for American calendars, give this as MONTH DAY YEAR, for European as
5856 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5857 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5858 is any number of ISO weeks in the block period for which the item should
5859 be skipped.
5861 This function is here only for backward compatibility and it is deprecated,
5862 please use `org-class' instead."
5863 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5864 (date2 (org-order-calendar-date-args m2 d2 y2)))
5865 (org-class
5866 (nth 2 date1) (car date1) (nth 1 date1)
5867 (nth 2 date2) (car date2) (nth 1 date2)
5868 dayname skip-weeks)))
5869 (make-obsolete 'org-diary-class 'org-class "")
5871 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5872 (defalias 'org-get-closed 'org-agenda-get-progress)
5873 (defun org-agenda-get-progress ()
5874 "Return the logged TODO entries for agenda display."
5875 (let* ((props (list 'mouse-face 'highlight
5876 'org-not-done-regexp org-not-done-regexp
5877 'org-todo-regexp org-todo-regexp
5878 'org-complex-heading-regexp org-complex-heading-regexp
5879 'help-echo
5880 (format "mouse-2 or RET jump to org file %s"
5881 (abbreviate-file-name buffer-file-name))))
5882 (items (if (consp org-agenda-show-log-scoped)
5883 org-agenda-show-log-scoped
5884 (if (eq org-agenda-show-log-scoped 'clockcheck)
5885 '(clock)
5886 org-agenda-log-mode-items)))
5887 (parts
5888 (delq nil
5889 (list
5890 (if (memq 'closed items) (concat "\\<" org-closed-string))
5891 (if (memq 'clock items) (concat "\\<" org-clock-string))
5892 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5893 (parts-re (if parts (mapconcat 'identity parts "\\|")
5894 (error "`org-agenda-log-mode-items' is empty")))
5895 (regexp (concat
5896 "\\(" parts-re "\\)"
5897 " *\\["
5898 (regexp-quote
5899 (substring
5900 (format-time-string
5901 (car org-time-stamp-formats)
5902 (apply 'encode-time ; DATE bound by calendar
5903 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5904 1 11))))
5905 (org-agenda-search-headline-for-time nil)
5906 marker hdmarker priority category category-pos level tags closedp
5907 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5908 (goto-char (point-min))
5909 (while (re-search-forward regexp nil t)
5910 (catch :skip
5911 (org-agenda-skip)
5912 (setq marker (org-agenda-new-marker (match-beginning 0))
5913 closedp (equal (match-string 1) org-closed-string)
5914 statep (equal (string-to-char (match-string 1)) ?-)
5915 clockp (not (or closedp statep))
5916 state (and statep (match-string 2))
5917 category (org-get-category (match-beginning 0))
5918 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5919 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5920 (when (string-match "\\]" timestr)
5921 ;; substring should only run to end of time stamp
5922 (setq rest (substring timestr (match-end 0))
5923 timestr (substring timestr 0 (match-end 0)))
5924 (if (and (not closedp) (not statep)
5925 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5926 rest))
5927 (progn (setq timestr (concat (substring timestr 0 -1)
5928 "-" (match-string 1 rest) "]"))
5929 (setq clocked (match-string 2 rest)))
5930 (setq clocked "-")))
5931 (save-excursion
5932 (setq extra
5933 (cond
5934 ((not org-agenda-log-mode-add-notes) nil)
5935 (statep
5936 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5937 (match-string 1)))
5938 (clockp
5939 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5940 (match-string 1)))))
5941 (if (not (re-search-backward org-outline-regexp-bol nil t))
5942 (throw :skip nil)
5943 (goto-char (match-beginning 0))
5944 (setq hdmarker (org-agenda-new-marker)
5945 inherited-tags
5946 (or (eq org-agenda-show-inherited-tags 'always)
5947 (and (listp org-agenda-show-inherited-tags)
5948 (memq 'todo org-agenda-show-inherited-tags))
5949 (and (eq org-agenda-show-inherited-tags t)
5950 (or (eq org-agenda-use-tag-inheritance t)
5951 (memq 'todo org-agenda-use-tag-inheritance))))
5952 tags (org-get-tags-at nil (not inherited-tags))
5953 level (make-string (org-reduced-level (org-outline-level)) ? ))
5954 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5955 (setq txt (match-string 1))
5956 (when extra
5957 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5958 (setq txt (concat (substring txt 0 (match-beginning 1))
5959 " - " extra " " (match-string 2 txt)))
5960 (setq txt (concat txt " - " extra))))
5961 (setq txt (org-agenda-format-item
5962 (cond
5963 (closedp "Closed: ")
5964 (statep (concat "State: (" state ")"))
5965 (t (concat "Clocked: (" clocked ")")))
5966 txt level category tags timestr)))
5967 (setq priority 100000)
5968 (org-add-props txt props
5969 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5970 'priority priority 'org-category category
5971 'org-category-position category-pos
5972 'level level
5973 'type "closed" 'date date
5974 'undone-face 'org-warning 'done-face 'org-agenda-done)
5975 (push txt ee))
5976 (goto-char (point-at-eol))))
5977 (nreverse ee)))
5979 (defun org-agenda-show-clocking-issues ()
5980 "Add overlays, showing issues with clocking.
5981 See also the user option `org-agenda-clock-consistency-checks'."
5982 (interactive)
5983 (let* ((org-time-clocksum-use-effort-durations nil)
5984 (pl org-agenda-clock-consistency-checks)
5985 (re (concat "^[ \t]*"
5986 org-clock-string
5987 "[ \t]+"
5988 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5989 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5990 (tlstart 0.)
5991 (tlend 0.)
5992 (maxtime (org-hh:mm-string-to-minutes
5993 (or (plist-get pl :max-duration) "24:00")))
5994 (mintime (org-hh:mm-string-to-minutes
5995 (or (plist-get pl :min-duration) 0)))
5996 (maxgap (org-hh:mm-string-to-minutes
5997 ;; default 30:00 means never complain
5998 (or (plist-get pl :max-gap) "30:00")))
5999 (gapok (mapcar 'org-hh:mm-string-to-minutes
6000 (plist-get pl :gap-ok-around)))
6001 (def-face (or (plist-get pl :default-face)
6002 '((:background "DarkRed") (:foreground "white"))))
6003 issue face m te ts dt ov)
6004 (goto-char (point-min))
6005 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
6006 (setq issue nil face def-face)
6007 (catch 'next
6008 (setq m (org-get-at-bol 'org-marker)
6009 te nil ts nil)
6010 (unless (and m (markerp m))
6011 (setq issue "No valid clock line") (throw 'next t))
6012 (org-with-point-at m
6013 (save-excursion
6014 (goto-char (point-at-bol))
6015 (unless (looking-at re)
6016 (error "No valid Clock line")
6017 (throw 'next t))
6018 (unless (match-end 3)
6019 (setq issue "No end time"
6020 face (or (plist-get pl :no-end-time-face) face))
6021 (throw 'next t))
6022 (setq ts (match-string 1)
6023 te (match-string 3)
6024 ts (org-float-time
6025 (apply 'encode-time (org-parse-time-string ts)))
6026 te (org-float-time
6027 (apply 'encode-time (org-parse-time-string te)))
6028 dt (- te ts))))
6029 (cond
6030 ((> dt (* 60 maxtime))
6031 ;; a very long clocking chunk
6032 (setq issue (format "Clocking interval is very long: %s"
6033 (org-minutes-to-clocksum-string
6034 (floor (/ (float dt) 60.))))
6035 face (or (plist-get pl :long-face) face)))
6036 ((< dt (* 60 mintime))
6037 ;; a very short clocking chunk
6038 (setq issue (format "Clocking interval is very short: %s"
6039 (org-minutes-to-clocksum-string
6040 (floor (/ (float dt) 60.))))
6041 face (or (plist-get pl :short-face) face)))
6042 ((and (> tlend 0) (< ts tlend))
6043 ;; Two clock entries are overlapping
6044 (setq issue (format "Clocking overlap: %d minutes"
6045 (/ (- tlend ts) 60))
6046 face (or (plist-get pl :overlap-face) face)))
6047 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
6048 ;; There is a gap, lets see if we need to report it
6049 (unless (org-agenda-check-clock-gap tlend ts gapok)
6050 (setq issue (format "Clocking gap: %d minutes"
6051 (/ (- ts tlend) 60))
6052 face (or (plist-get pl :gap-face) face))))
6053 (t nil)))
6054 (setq tlend (or te tlend) tlstart (or ts tlstart))
6055 (when issue
6056 ;; OK, there was some issue, add an overlay to show the issue
6057 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
6058 (overlay-put ov 'before-string
6059 (concat
6060 (org-add-props
6061 (format "%-43s" (concat " " issue))
6063 'face face)
6064 "\n"))
6065 (overlay-put ov 'evaporate t)))))
6067 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
6068 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
6069 (catch 'exit
6070 (unless ok-list
6071 ;; there are no OK times for gaps...
6072 (throw 'exit nil))
6073 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
6074 ;; This is more than 24 hours, so it is OK.
6075 ;; because we have at least one OK time, that must be in the
6076 ;; 24 hour interval.
6077 (throw 'exit t))
6078 ;; We have a shorter gap.
6079 ;; Now we have to get the minute of the day when these times are
6080 (let* ((t1dec (decode-time (seconds-to-time t1)))
6081 (t2dec (decode-time (seconds-to-time t2)))
6082 ;; compute the minute on the day
6083 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
6084 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
6085 (when (< min2 min1)
6086 ;; if min2 is smaller than min1, this means it is on the next day.
6087 ;; Wrap it to after midnight.
6088 (setq min2 (+ min2 1440)))
6089 ;; Now check if any of the OK times is in the gap
6090 (mapc (lambda (x)
6091 ;; Wrap the time to after midnight if necessary
6092 (if (< x min1) (setq x (+ x 1440)))
6093 ;; Check if in interval
6094 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
6095 ok-list)
6096 ;; Nope, this gap is not OK
6097 nil)))
6099 (defun org-agenda-get-deadlines ()
6100 "Return the deadline information for agenda display."
6101 (let* ((props (list 'mouse-face 'highlight
6102 'org-not-done-regexp org-not-done-regexp
6103 'org-todo-regexp org-todo-regexp
6104 'org-complex-heading-regexp org-complex-heading-regexp
6105 'help-echo
6106 (format "mouse-2 or RET jump to org file %s"
6107 (abbreviate-file-name buffer-file-name))))
6108 (regexp org-deadline-time-regexp)
6109 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6110 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6111 d2 diff dfrac wdays pos pos1 category category-pos level
6112 tags suppress-prewarning ee txt head face s todo-state
6113 show-all upcomingp donep timestr warntime inherited-tags ts-date)
6114 (goto-char (point-min))
6115 (while (re-search-forward regexp nil t)
6116 (catch :skip
6117 (org-agenda-skip)
6118 (setq s (match-string 1)
6119 txt nil
6120 pos (1- (match-beginning 1))
6121 todo-state (save-match-data (org-get-todo-state))
6122 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6123 (member todo-state
6124 org-agenda-repeating-timestamp-show-all))
6125 d2 (org-time-string-to-absolute
6126 s d1 'past show-all (current-buffer) pos)
6127 diff (- d2 d1))
6128 (setq suppress-prewarning
6129 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
6130 (let ((item (buffer-substring (point-at-bol)
6131 (point-at-eol))))
6132 (save-match-data
6133 (and (string-match
6134 org-scheduled-time-regexp item)
6135 (match-string 1 item)))))))
6136 (cond
6137 ((not ds) nil)
6138 ;; The current item has a scheduled date (in ds), so
6139 ;; evaluate its prewarning lead time.
6140 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6141 ;; Use global prewarning-restart lead time.
6142 org-agenda-skip-deadline-prewarning-if-scheduled)
6143 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6144 'pre-scheduled)
6145 ;; Set prewarning to no earlier than scheduled.
6146 (min (- d2 (org-time-string-to-absolute
6147 ds d1 'past show-all (current-buffer) pos))
6148 org-deadline-warning-days))
6149 ;; Set prewarning to deadline.
6150 (t 0))))
6151 (setq wdays (if suppress-prewarning
6152 (let ((org-deadline-warning-days suppress-prewarning))
6153 (org-get-wdays s))
6154 (org-get-wdays s))
6155 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6156 upcomingp (and todayp (> diff 0)))
6157 ;; When to show a deadline in the calendar:
6158 ;; If the expiration is within wdays warning time.
6159 ;; Past-due deadlines are only shown on the current date
6160 (if (and (or (and (<= diff wdays)
6161 (and todayp (not org-agenda-only-exact-dates)))
6162 (= diff 0)))
6163 (save-excursion
6164 ;; (setq todo-state (org-get-todo-state))
6165 (setq donep (member todo-state org-done-keywords))
6166 (if (and donep
6167 (or org-agenda-skip-deadline-if-done
6168 (not (= diff 0))))
6169 (setq txt nil)
6170 (setq category (org-get-category)
6171 warntime (get-text-property (point) 'org-appt-warntime)
6172 category-pos (get-text-property (point) 'org-category-position))
6173 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6174 (throw :skip nil)
6175 (goto-char (match-end 0))
6176 (setq pos1 (match-beginning 0))
6177 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6178 (setq inherited-tags
6179 (or (eq org-agenda-show-inherited-tags 'always)
6180 (and (listp org-agenda-show-inherited-tags)
6181 (memq 'agenda org-agenda-show-inherited-tags))
6182 (and (eq org-agenda-show-inherited-tags t)
6183 (or (eq org-agenda-use-tag-inheritance t)
6184 (memq 'agenda org-agenda-use-tag-inheritance))))
6185 tags (org-get-tags-at pos1 (not inherited-tags)))
6186 (setq head (buffer-substring
6187 (point)
6188 (progn (skip-chars-forward "^\r\n")
6189 (point))))
6190 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6191 (setq timestr
6192 (concat (substring s (match-beginning 1)) " "))
6193 (setq timestr 'time))
6194 (setq txt (org-agenda-format-item
6195 (if (= diff 0)
6196 (car org-agenda-deadline-leaders)
6197 (if (functionp
6198 (nth 1 org-agenda-deadline-leaders))
6199 (funcall
6200 (nth 1 org-agenda-deadline-leaders)
6201 diff date)
6202 (format (nth 1 org-agenda-deadline-leaders)
6203 diff)))
6204 head level category tags
6205 (if (not (= diff 0)) nil timestr)))))
6206 (when txt
6207 (setq face (org-agenda-deadline-face dfrac))
6208 (org-add-props txt props
6209 'org-marker (org-agenda-new-marker pos)
6210 'warntime warntime
6211 'level level
6212 'ts-date d2
6213 'org-hd-marker (org-agenda-new-marker pos1)
6214 'priority (+ (- diff)
6215 (org-get-priority txt))
6216 'org-category category
6217 'org-category-position category-pos
6218 'todo-state todo-state
6219 'type (if upcomingp "upcoming-deadline" "deadline")
6220 'date (if upcomingp date d2)
6221 'face (if donep 'org-agenda-done face)
6222 'undone-face face 'done-face 'org-agenda-done)
6223 (push txt ee))))))
6224 (nreverse ee)))
6226 (defun org-agenda-deadline-face (fraction)
6227 "Return the face to displaying a deadline item.
6228 FRACTION is what fraction of the head-warning time has passed."
6229 (let ((faces org-agenda-deadline-faces) f)
6230 (catch 'exit
6231 (while (setq f (pop faces))
6232 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6234 (defun org-agenda-get-scheduled (&optional deadline-results)
6235 "Return the scheduled information for agenda display."
6236 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6237 'org-todo-regexp org-todo-regexp
6238 'org-complex-heading-regexp org-complex-heading-regexp
6239 'done-face 'org-agenda-done
6240 'mouse-face 'highlight
6241 'help-echo
6242 (format "mouse-2 or RET jump to org file %s"
6243 (abbreviate-file-name buffer-file-name))))
6244 (regexp org-scheduled-time-regexp)
6245 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6246 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6248 (deadline-position-alist
6249 (mapcar (lambda (a) (and (setq mm (get-text-property
6250 0 'org-hd-marker a))
6251 (cons (marker-position mm) a)))
6252 deadline-results))
6253 d2 diff pos pos1 category category-pos level tags donep
6254 ee txt head pastschedp todo-state face timestr s habitp show-all
6255 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6256 ddays)
6257 (goto-char (point-min))
6258 (while (re-search-forward regexp nil t)
6259 (catch :skip
6260 (org-agenda-skip)
6261 (setq s (match-string 1)
6262 txt nil
6263 pos (1- (match-beginning 1))
6264 todo-state (save-match-data (org-get-todo-state))
6265 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6266 (member todo-state
6267 org-agenda-repeating-timestamp-show-all))
6268 d2 (org-time-string-to-absolute
6269 s d1 'past show-all (current-buffer) pos)
6270 diff (- d2 d1)
6271 warntime (get-text-property (point) 'org-appt-warntime))
6272 (setq pastschedp (and todayp (< diff 0)))
6273 (setq did-habit-check-p nil)
6274 (setq suppress-delay
6275 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6276 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6277 (save-match-data
6278 (and (string-match
6279 org-deadline-time-regexp item)
6280 (match-string 1 item)))))))
6281 (cond
6282 ((not ds) nil)
6283 ;; The current item has a deadline date (in ds), so
6284 ;; evaluate its delay time.
6285 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6286 ;; Use global delay time.
6287 (- org-agenda-skip-scheduled-delay-if-deadline))
6288 ((eq org-agenda-skip-scheduled-delay-if-deadline
6289 'post-deadline)
6290 ;; Set delay to no later than deadline.
6291 (min (- d2 (org-time-string-to-absolute
6292 ds d1 'past show-all (current-buffer) pos))
6293 org-scheduled-delay-days))
6294 (t 0))))
6295 (setq ddays (if suppress-delay
6296 (let ((org-scheduled-delay-days suppress-delay))
6297 (org-get-wdays s t t))
6298 (org-get-wdays s t)))
6299 ;; Use a delay of 0 when there is a repeater and the delay is
6300 ;; of the form --3d
6301 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6302 (< (org-time-string-to-absolute s)
6303 (org-time-string-to-absolute
6304 s d2 'past nil (current-buffer) pos)))
6305 (setq ddays 0))
6306 ;; When to show a scheduled item in the calendar:
6307 ;; If it is on or past the date.
6308 (when (or (and (> ddays 0) (= diff (- ddays)))
6309 (and (zerop ddays) (= diff 0))
6310 (and (< (+ diff ddays) 0)
6311 (< (abs diff) org-scheduled-past-days)
6312 (and todayp (not org-agenda-only-exact-dates)))
6313 ;; org-is-habit-p uses org-entry-get, which is expansive
6314 ;; so we go extra mile to only call it once
6315 (and todayp
6316 (boundp 'org-habit-show-all-today)
6317 org-habit-show-all-today
6318 (setq did-habit-check-p t)
6319 (setq habitp (and (functionp 'org-is-habit-p)
6320 (org-is-habit-p)))))
6321 (save-excursion
6322 (setq donep (member todo-state org-done-keywords))
6323 (if (and donep
6324 (or org-agenda-skip-scheduled-if-done
6325 (not (= diff 0))
6326 (and (functionp 'org-is-habit-p)
6327 (org-is-habit-p))))
6328 (setq txt nil)
6329 (setq habitp (if did-habit-check-p habitp
6330 (and (functionp 'org-is-habit-p)
6331 (org-is-habit-p))))
6332 (setq category (org-get-category)
6333 category-pos (get-text-property (point) 'org-category-position))
6334 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6335 (throw :skip nil)
6336 (goto-char (match-end 0))
6337 (setq pos1 (match-beginning 0))
6338 (if habitp
6339 (if (or (not org-habit-show-habits)
6340 (and (not todayp)
6341 (boundp 'org-habit-show-habits-only-for-today)
6342 org-habit-show-habits-only-for-today))
6343 (throw :skip nil))
6344 (if (and
6345 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6346 (and org-agenda-skip-scheduled-if-deadline-is-shown
6347 pastschedp))
6348 (setq mm (assoc pos1 deadline-position-alist)))
6349 (throw :skip nil)))
6350 (setq inherited-tags
6351 (or (eq org-agenda-show-inherited-tags 'always)
6352 (and (listp org-agenda-show-inherited-tags)
6353 (memq 'agenda org-agenda-show-inherited-tags))
6354 (and (eq org-agenda-show-inherited-tags t)
6355 (or (eq org-agenda-use-tag-inheritance t)
6356 (memq 'agenda org-agenda-use-tag-inheritance))))
6358 tags (org-get-tags-at nil (not inherited-tags)))
6359 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6360 (setq head (buffer-substring
6361 (point)
6362 (progn (skip-chars-forward "^\r\n") (point))))
6363 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6364 (setq timestr
6365 (concat (substring s (match-beginning 1)) " "))
6366 (setq timestr 'time))
6367 (setq txt (org-agenda-format-item
6368 (if (= diff 0)
6369 (car org-agenda-scheduled-leaders)
6370 (format (nth 1 org-agenda-scheduled-leaders)
6371 (- 1 diff)))
6372 head level category tags
6373 (if (not (= diff 0)) nil timestr)
6374 nil habitp))))
6375 (when txt
6376 (setq face
6377 (cond
6378 ((and (not habitp) pastschedp)
6379 'org-scheduled-previously)
6380 (todayp 'org-scheduled-today)
6381 (t 'org-scheduled))
6382 habitp (and habitp (org-habit-parse-todo)))
6383 (org-add-props txt props
6384 'undone-face face
6385 'face (if donep 'org-agenda-done face)
6386 'org-marker (org-agenda-new-marker pos)
6387 'org-hd-marker (org-agenda-new-marker pos1)
6388 'type (if pastschedp "past-scheduled" "scheduled")
6389 'date (if pastschedp d2 date)
6390 'ts-date d2
6391 'warntime warntime
6392 'level level
6393 'priority (if habitp
6394 (org-habit-get-priority habitp)
6395 (+ 94 (- 5 diff) (org-get-priority txt)))
6396 'org-category category
6397 'category-position category-pos
6398 'org-habit-p habitp
6399 'todo-state todo-state)
6400 (push txt ee))))))
6401 (nreverse ee)))
6403 (defun org-agenda-get-blocks ()
6404 "Return the date-range information for agenda display."
6405 (let* ((props (list 'face nil
6406 'org-not-done-regexp org-not-done-regexp
6407 'org-todo-regexp org-todo-regexp
6408 'org-complex-heading-regexp org-complex-heading-regexp
6409 'mouse-face 'highlight
6410 'help-echo
6411 (format "mouse-2 or RET jump to org file %s"
6412 (abbreviate-file-name buffer-file-name))))
6413 (regexp org-tr-regexp)
6414 (d0 (calendar-absolute-from-gregorian date))
6415 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6416 level todo-state tags pos head donep inherited-tags)
6417 (goto-char (point-min))
6418 (while (re-search-forward regexp nil t)
6419 (catch :skip
6420 (org-agenda-skip)
6421 (setq pos (point))
6422 (let ((start-time (match-string 1))
6423 (end-time (match-string 2)))
6424 (setq s1 (match-string 1)
6425 s2 (match-string 2)
6426 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6427 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6428 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6429 ;; Only allow days between the limits, because the normal
6430 ;; date stamps will catch the limits.
6431 (save-excursion
6432 (setq todo-state (org-get-todo-state))
6433 (setq donep (member todo-state org-done-keywords))
6434 (if (and donep org-agenda-skip-timestamp-if-done)
6435 (throw :skip t))
6436 (setq marker (org-agenda-new-marker (point)))
6437 (setq category (org-get-category)
6438 category-pos (get-text-property (point) 'org-category-position))
6439 (if (not (re-search-backward org-outline-regexp-bol nil t))
6440 (throw :skip nil)
6441 (goto-char (match-beginning 0))
6442 (setq hdmarker (org-agenda-new-marker (point))
6443 inherited-tags
6444 (or (eq org-agenda-show-inherited-tags 'always)
6445 (and (listp org-agenda-show-inherited-tags)
6446 (memq 'agenda org-agenda-show-inherited-tags))
6447 (and (eq org-agenda-show-inherited-tags t)
6448 (or (eq org-agenda-use-tag-inheritance t)
6449 (memq 'agenda org-agenda-use-tag-inheritance))))
6451 tags (org-get-tags-at nil (not inherited-tags)))
6452 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6453 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6454 (setq head (match-string 1))
6455 (let ((remove-re
6456 (if org-agenda-remove-timeranges-from-blocks
6457 (concat
6458 "<" (regexp-quote s1) ".*?>"
6459 "--"
6460 "<" (regexp-quote s2) ".*?>")
6461 nil)))
6462 (setq txt (org-agenda-format-item
6463 (format
6464 (nth (if (= d1 d2) 0 1)
6465 org-agenda-timerange-leaders)
6466 (1+ (- d0 d1)) (1+ (- d2 d1)))
6467 head level category tags
6468 (cond ((and (= d1 d0) (= d2 d0))
6469 (concat "<" start-time ">--<" end-time ">"))
6470 ((= d1 d0)
6471 (concat "<" start-time ">"))
6472 ((= d2 d0)
6473 (concat "<" end-time ">")))
6474 remove-re))))
6475 (org-add-props txt props
6476 'org-marker marker 'org-hd-marker hdmarker
6477 'type "block" 'date date
6478 'level level
6479 'todo-state todo-state
6480 'priority (org-get-priority txt) 'org-category category
6481 'org-category-position category-pos)
6482 (push txt ee))))
6483 (goto-char pos)))
6484 ;; Sort the entries by expiration date.
6485 (nreverse ee)))
6487 ;;; Agenda presentation and sorting
6489 (defvar org-prefix-has-time nil
6490 "A flag, set by `org-compile-prefix-format'.
6491 The flag is set if the currently compiled format contains a `%t'.")
6492 (defvar org-prefix-has-tag nil
6493 "A flag, set by `org-compile-prefix-format'.
6494 The flag is set if the currently compiled format contains a `%T'.")
6495 (defvar org-prefix-has-effort nil
6496 "A flag, set by `org-compile-prefix-format'.
6497 The flag is set if the currently compiled format contains a `%e'.")
6498 (defvar org-prefix-has-breadcrumbs nil
6499 "A flag, set by `org-compile-prefix-format'.
6500 The flag is set if the currently compiled format contains a `%b'.")
6501 (defvar org-prefix-category-length nil
6502 "Used by `org-compile-prefix-format' to remember the category field width.")
6503 (defvar org-prefix-category-max-length nil
6504 "Used by `org-compile-prefix-format' to remember the category field width.")
6506 (defun org-agenda-get-category-icon (category)
6507 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6508 (dolist (entry org-agenda-category-icon-alist)
6509 (when (org-string-match-p (car entry) category)
6510 (if (listp (cadr entry))
6511 (return (cadr entry))
6512 (return (apply 'create-image (cdr entry)))))))
6514 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6515 remove-re habitp)
6516 "Format TXT to be inserted into the agenda buffer.
6517 In particular, add the prefix and corresponding text properties.
6519 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6520 LEVEL may be a string to replace the `%l' specifier.
6521 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6522 category taken from local variable or file name. It will replace the `%c'
6523 specifier in the format.
6524 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6525 TXT for sorting of this entry, and for the `%t' specifier in the format.
6526 When DOTIME is a string, this string is searched for a time before TXT is.
6527 TAGS can be the tags of the headline.
6528 Any match of REMOVE-RE will be removed from TXT."
6529 ;; We keep the org-prefix-* variable values along with a compiled
6530 ;; formatter, so that multiple agendas existing at the same time do
6531 ;; not step on each other toes.
6533 ;; It was inconvenient to make these variables buffer local in
6534 ;; Agenda buffers, because this function expects to be called with
6535 ;; the buffer where item comes from being current, and not agenda
6536 ;; buffer
6537 (let* ((bindings (car org-prefix-format-compiled))
6538 (formatter (cadr org-prefix-format-compiled)))
6539 (loop for (var value) in bindings
6540 do (set var value))
6541 (save-match-data
6542 ;; Diary entries sometimes have extra whitespace at the beginning
6543 (setq txt (org-trim txt))
6545 ;; Fix the tags part in txt
6546 (setq txt (org-agenda-fix-displayed-tags
6547 txt tags
6548 org-agenda-show-inherited-tags
6549 org-agenda-hide-tags-regexp))
6551 (let* ((category (or category
6552 (if (stringp org-category)
6553 org-category
6554 (and org-category (symbol-name org-category)))
6555 (if buffer-file-name
6556 (file-name-sans-extension
6557 (file-name-nondirectory buffer-file-name))
6558 "")))
6559 (category-icon (org-agenda-get-category-icon category))
6560 (category-icon (if category-icon
6561 (propertize " " 'display category-icon)
6562 ""))
6563 ;; time, tag, effort are needed for the eval of the prefix format
6564 (tag (if tags (nth (1- (length tags)) tags) ""))
6565 time effort neffort
6566 (ts (if dotime (concat
6567 (if (stringp dotime) dotime "")
6568 (and org-agenda-search-headline-for-time txt))))
6569 (time-of-day (and dotime (org-get-time-of-day ts)))
6570 stamp plain s0 s1 s2 rtn srp l
6571 duration thecategory breadcrumbs)
6572 (and (derived-mode-p 'org-mode) buffer-file-name
6573 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6574 (when (and dotime time-of-day)
6575 ;; Extract starting and ending time and move them to prefix
6576 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6577 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6578 (setq s0 (match-string 0 ts)
6579 srp (and stamp (match-end 3))
6580 s1 (match-string (if plain 1 2) ts)
6581 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6583 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6584 ;; them, we might want to remove them there to avoid duplication.
6585 ;; The user can turn this off with a variable.
6586 (if (and org-prefix-has-time
6587 org-agenda-remove-times-when-in-prefix (or stamp plain)
6588 (string-match (concat (regexp-quote s0) " *") txt)
6589 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6590 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6591 (= (match-beginning 0) 0)
6593 (setq txt (replace-match "" nil nil txt))))
6594 ;; Normalize the time(s) to 24 hour
6595 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6596 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6598 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6599 (let (org-time-clocksum-use-effort-durations)
6600 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6601 (setq s2
6602 (org-minutes-to-clocksum-string
6603 (+ (org-hh:mm-string-to-minutes s1)
6604 org-agenda-default-appointment-duration)))))
6606 ;; Compute the duration
6607 (when s2
6608 (setq duration (- (org-hh:mm-string-to-minutes s2)
6609 (org-hh:mm-string-to-minutes s1)))))
6611 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6612 txt)
6613 ;; Tags are in the string
6614 (if (or (eq org-agenda-remove-tags t)
6615 (and org-agenda-remove-tags
6616 org-prefix-has-tag))
6617 (setq txt (replace-match "" t t txt))
6618 (setq txt (replace-match
6619 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6620 (match-string 2 txt))
6621 t t txt))))
6622 (when (derived-mode-p 'org-mode)
6623 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6624 (if effort
6625 (setq neffort (org-duration-string-to-minutes effort)
6626 effort (setq effort (concat "[" effort "]")))
6627 ;; prevent erroring out with %e format when there is no effort
6628 (setq effort "")))
6630 (when remove-re
6631 (while (string-match remove-re txt)
6632 (setq txt (replace-match "" t t txt))))
6634 ;; Set org-heading property on `txt' to mark the start of the
6635 ;; heading.
6636 (add-text-properties 0 (length txt) '(org-heading t) txt)
6638 ;; Prepare the variables needed in the eval of the compiled format
6639 (setq time (cond (s2 (concat
6640 (org-agenda-time-of-day-to-ampm-maybe s1)
6641 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6642 (if org-agenda-timegrid-use-ampm " ")))
6643 (s1 (concat
6644 (org-agenda-time-of-day-to-ampm-maybe s1)
6645 (if org-agenda-timegrid-use-ampm
6646 "........ "
6647 "......")))
6648 (t ""))
6649 extra (or (and (not habitp) extra) "")
6650 breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6651 (let ((s (org-display-outline-path nil nil "->" t)))
6652 (if (eq "" s) "" (concat s "->"))))
6653 category (if (symbolp category) (symbol-name category) category)
6654 thecategory (copy-sequence category)
6655 level (or level ""))
6656 (if (string-match org-bracket-link-regexp category)
6657 (progn
6658 (setq l (if (match-end 3)
6659 (- (match-end 3) (match-beginning 3))
6660 (- (match-end 1) (match-beginning 1))))
6661 (when (< l (or org-prefix-category-length 0))
6662 (setq category (copy-sequence category))
6663 (org-add-props category nil
6664 'extra-space (make-string
6665 (- org-prefix-category-length l 1) ?\ ))))
6666 (if (and org-prefix-category-max-length
6667 (>= (length category) org-prefix-category-max-length))
6668 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6669 ;; Evaluate the compiled format
6670 (setq rtn (concat (eval formatter) txt))
6672 ;; And finally add the text properties
6673 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6674 (org-add-props rtn nil
6675 'org-category (if thecategory (downcase thecategory) category)
6676 'tags (mapcar 'org-downcase-keep-props tags)
6677 'org-highest-priority org-highest-priority
6678 'org-lowest-priority org-lowest-priority
6679 'time-of-day time-of-day
6680 'duration duration
6681 'effort effort
6682 'effort-minutes neffort
6683 'breadcrumbs breadcrumbs
6684 'txt txt
6685 'level level
6686 'time time
6687 'extra extra
6688 'format org-prefix-format-compiled
6689 'dotime dotime)))))
6691 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6692 "Remove tags string from TXT, and add a modified list of tags.
6693 The modified list may contain inherited tags, and tags matched by
6694 `org-agenda-hide-tags-regexp' will be removed."
6695 (when (or add-inherited hide-re)
6696 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6697 (setq txt (substring txt 0 (match-beginning 0))))
6698 (setq tags
6699 (delq nil
6700 (mapcar (lambda (tg)
6701 (if (or (and hide-re (string-match hide-re tg))
6702 (and (not add-inherited)
6703 (get-text-property 0 'inherited tg)))
6705 tg))
6706 tags)))
6707 (when tags
6708 (let ((have-i (get-text-property 0 'inherited (car tags)))
6710 (setq txt (concat txt " :"
6711 (mapconcat
6712 (lambda (x)
6713 (setq i (get-text-property 0 'inherited x))
6714 (if (and have-i (not i))
6715 (progn
6716 (setq have-i nil)
6717 (concat ":" x))
6719 tags ":")
6720 (if have-i "::" ":"))))))
6721 txt)
6723 (defun org-downcase-keep-props (s)
6724 (let ((props (text-properties-at 0 s)))
6725 (setq s (downcase s))
6726 (add-text-properties 0 (length s) props s)
6729 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6731 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6732 "Add a time-grid for agenda items which need it.
6734 LIST is the list of agenda items formatted by `org-agenda-list'.
6735 NDAYS is the span of the current agenda view.
6736 TODAYP is `t' when the current agenda view is on today."
6737 (catch 'exit
6738 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6739 ((and todayp (member 'today (car org-agenda-time-grid))))
6740 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6741 ((member 'weekly (car org-agenda-time-grid)))
6742 (t (throw 'exit list)))
6743 (let* ((have (delq nil (mapcar
6744 (lambda (x) (get-text-property 1 'time-of-day x))
6745 list)))
6746 (string (nth 1 org-agenda-time-grid))
6747 (gridtimes (nth 2 org-agenda-time-grid))
6748 (req (car org-agenda-time-grid))
6749 (remove (member 'remove-match req))
6750 new time)
6751 (if (and (member 'require-timed req) (not have))
6752 ;; don't show empty grid
6753 (throw 'exit list))
6754 (while (setq time (pop gridtimes))
6755 (unless (and remove (member time have))
6756 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6757 (push (org-agenda-format-item
6758 nil string nil "" nil
6759 (concat (substring time 0 -2) ":" (substring time -2)))
6760 new)
6761 (put-text-property
6762 2 (length (car new)) 'face 'org-time-grid (car new))))
6763 (when (and todayp org-agenda-show-current-time-in-grid)
6764 (push (org-agenda-format-item
6765 nil org-agenda-current-time-string nil "" nil
6766 (format-time-string "%H:%M "))
6767 new)
6768 (put-text-property
6769 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6771 (if (member 'time-up org-agenda-sorting-strategy-selected)
6772 (append new list)
6773 (append list new)))))
6775 (defun org-compile-prefix-format (key)
6776 "Compile the prefix format into a Lisp form that can be evaluated.
6777 The resulting form and associated variable bindings is returned
6778 and stored in the variable `org-prefix-format-compiled'."
6779 (setq org-prefix-has-time nil
6780 org-prefix-has-tag nil
6781 org-prefix-category-length nil
6782 org-prefix-has-effort nil
6783 org-prefix-has-breadcrumbs nil)
6784 (let ((s (cond
6785 ((stringp org-agenda-prefix-format)
6786 org-agenda-prefix-format)
6787 ((assq key org-agenda-prefix-format)
6788 (cdr (assq key org-agenda-prefix-format)))
6789 (t " %-12:c%?-12t% s")))
6790 (start 0)
6791 varform vars var e c f opt)
6792 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6793 s start)
6794 (setq var (or (cdr (assoc (match-string 4 s)
6795 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6796 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6797 'eval)
6798 c (or (match-string 3 s) "")
6799 opt (match-beginning 1)
6800 start (1+ (match-beginning 0)))
6801 (if (equal var 'time) (setq org-prefix-has-time t))
6802 (if (equal var 'tag) (setq org-prefix-has-tag t))
6803 (if (equal var 'effort) (setq org-prefix-has-effort t))
6804 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6805 (setq f (concat "%" (match-string 2 s) "s"))
6806 (when (equal var 'category)
6807 (setq org-prefix-category-length
6808 (floor (abs (string-to-number (match-string 2 s)))))
6809 (setq org-prefix-category-max-length
6810 (let ((x (match-string 2 s)))
6811 (save-match-data
6812 (if (string-match "\\.[0-9]+" x)
6813 (string-to-number (substring (match-string 0 x) 1)))))))
6814 (if (eq var 'eval)
6815 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6816 (if opt
6817 (setq varform
6818 `(if (equal "" ,var)
6820 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6821 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6822 (setq s (replace-match "%s" t nil s))
6823 (push varform vars))
6824 (setq vars (nreverse vars))
6825 (with-current-buffer (or org-agenda-buffer (current-buffer))
6826 (setq org-prefix-format-compiled
6827 (list
6828 `((org-prefix-has-time ,org-prefix-has-time)
6829 (org-prefix-has-tag ,org-prefix-has-tag)
6830 (org-prefix-category-length ,org-prefix-category-length)
6831 (org-prefix-has-effort ,org-prefix-has-effort)
6832 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6833 `(format ,s ,@vars))))))
6835 (defun org-set-sorting-strategy (key)
6836 (if (symbolp (car org-agenda-sorting-strategy))
6837 ;; the old format
6838 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6839 (setq org-agenda-sorting-strategy-selected
6840 (or (cdr (assq key org-agenda-sorting-strategy))
6841 (cdr (assq 'agenda org-agenda-sorting-strategy))
6842 '(time-up category-keep priority-down)))))
6844 (defun org-get-time-of-day (s &optional string mod24)
6845 "Check string S for a time of day.
6846 If found, return it as a military time number between 0 and 2400.
6847 If not found, return nil.
6848 The optional STRING argument forces conversion into a 5 character wide string
6849 HH:MM."
6850 (save-match-data
6851 (when
6852 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6853 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6854 (let* ((h (string-to-number (match-string 1 s)))
6855 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6856 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6857 (am-p (equal ampm "am"))
6858 (h1 (cond ((not ampm) h)
6859 ((= h 12) (if am-p 0 12))
6860 (t (+ h (if am-p 0 12)))))
6861 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6862 (mod h1 24) h1))
6863 (t0 (+ (* 100 h2) m))
6864 (t1 (concat (if (>= h1 24) "+" " ")
6865 (if (and org-agenda-time-leading-zero
6866 (< t0 1000)) "0" "")
6867 (if (< t0 100) "0" "")
6868 (if (< t0 10) "0" "")
6869 (int-to-string t0))))
6870 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6872 (defvar org-agenda-before-sorting-filter-function nil
6873 "Function to be applied to agenda items prior to sorting.
6874 Prior to sorting also means just before they are inserted into the agenda.
6876 To aid sorting, you may revisit the original entries and add more text
6877 properties which will later be used by the sorting functions.
6879 The function should take a string argument, an agenda line.
6880 It has access to the text properties in that line, which contain among
6881 other things, the property `org-hd-marker' that points to the entry
6882 where the line comes from. Note that not all lines going into the agenda
6883 have this property, only most.
6885 The function should return the modified string. It is probably best
6886 to ONLY change text properties.
6888 You can also use this function as a filter, by returning nil for lines
6889 you don't want to have in the agenda at all. For this application, you
6890 could bind the variable in the options section of a custom command.")
6892 (defun org-agenda-finalize-entries (list &optional type)
6893 "Sort, limit and concatenate the LIST of agenda items.
6894 The optional argument TYPE tells the agenda type."
6895 (let ((max-effort (cond ((listp org-agenda-max-effort)
6896 (cdr (assoc type org-agenda-max-effort)))
6897 (t org-agenda-max-effort)))
6898 (max-todo (cond ((listp org-agenda-max-todos)
6899 (cdr (assoc type org-agenda-max-todos)))
6900 (t org-agenda-max-todos)))
6901 (max-tags (cond ((listp org-agenda-max-tags)
6902 (cdr (assoc type org-agenda-max-tags)))
6903 (t org-agenda-max-tags)))
6904 (max-entries (cond ((listp org-agenda-max-entries)
6905 (cdr (assoc type org-agenda-max-entries)))
6906 (t org-agenda-max-entries))) l)
6907 (when org-agenda-before-sorting-filter-function
6908 (setq list
6909 (delq nil
6910 (mapcar
6911 org-agenda-before-sorting-filter-function list))))
6912 (setq list (mapcar 'org-agenda-highlight-todo list)
6913 list (mapcar 'identity (sort list 'org-entries-lessp))
6914 list (org-agenda-limit-entries
6915 list 'effort-minutes max-effort 'identity)
6916 list (org-agenda-limit-entries list 'todo-state max-todo)
6917 list (org-agenda-limit-entries list 'tags max-tags)
6918 list (org-agenda-limit-entries list 'org-hd-marker max-entries)
6919 list (mapconcat 'identity list "\n"))))
6921 (defun org-agenda-limit-entries (list prop limit &optional fn)
6922 "Limit the number of agenda entries."
6923 (if limit
6924 (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
6925 (delq nil
6926 (mapcar
6927 (lambda (e)
6928 (let ((pval (funcall f (get-text-property 1 prop e))))
6929 (if pval (setq lim (+ lim pval)))
6930 (if (or (not pval) (<= lim limit)) e)))
6931 list)))
6932 list))
6934 (defun org-agenda-highlight-todo (x)
6935 (let ((org-done-keywords org-done-keywords-for-agenda)
6936 (case-fold-search nil)
6938 (if (eq x 'line)
6939 (save-excursion
6940 (beginning-of-line 1)
6941 (setq re (org-get-at-bol 'org-todo-regexp))
6942 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6943 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6944 (add-text-properties (match-beginning 0) (match-end 1)
6945 (list 'face (org-get-todo-face 1)))
6946 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6947 (delete-region (match-beginning 1) (1- (match-end 0)))
6948 (goto-char (match-beginning 1))
6949 (insert (format org-agenda-todo-keyword-format s)))))
6950 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6951 (setq re (get-text-property 0 'org-todo-regexp x))
6952 (when (and re
6953 ;; Test `pl' because if there's no heading content,
6954 ;; there's no point matching to highlight. Note
6955 ;; that if we didn't test `pl' first, and there
6956 ;; happened to be no keyword from `org-todo-regexp'
6957 ;; on this heading line, then the `equal' comparison
6958 ;; afterwards would spuriously succeed in the case
6959 ;; where `pl' is nil -- causing an args-out-of-range
6960 ;; error when we try to add text properties to text
6961 ;; that isn't there.
6963 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6964 x pl) pl))
6965 (add-text-properties
6966 (or (match-end 1) (match-end 0)) (match-end 0)
6967 (list 'face (org-get-todo-face (match-string 2 x)))
6969 (when (match-end 1)
6970 (setq x (concat (substring x 0 (match-end 1))
6971 (format org-agenda-todo-keyword-format
6972 (match-string 2 x))
6973 (org-add-props " " (text-properties-at 0 x))
6974 (substring x (match-end 3)))))))
6975 x)))
6977 (defsubst org-cmp-priority (a b)
6978 "Compare the priorities of string A and B."
6979 (let ((pa (or (get-text-property 1 'priority a) 0))
6980 (pb (or (get-text-property 1 'priority b) 0)))
6981 (cond ((> pa pb) +1)
6982 ((< pa pb) -1))))
6984 (defsubst org-cmp-effort (a b)
6985 "Compare the effort values of string A and B."
6986 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6987 (ea (or (get-text-property 1 'effort-minutes a) def))
6988 (eb (or (get-text-property 1 'effort-minutes b) def)))
6989 (cond ((> ea eb) +1)
6990 ((< ea eb) -1))))
6992 (defsubst org-cmp-category (a b)
6993 "Compare the string values of categories of strings A and B."
6994 (let ((ca (or (get-text-property 1 'org-category a) ""))
6995 (cb (or (get-text-property 1 'org-category b) "")))
6996 (cond ((string-lessp ca cb) -1)
6997 ((string-lessp cb ca) +1))))
6999 (defsubst org-cmp-todo-state (a b)
7000 "Compare the todo states of strings A and B."
7001 (let* ((ma (or (get-text-property 1 'org-marker a)
7002 (get-text-property 1 'org-hd-marker a)))
7003 (mb (or (get-text-property 1 'org-marker b)
7004 (get-text-property 1 'org-hd-marker b)))
7005 (fa (and ma (marker-buffer ma)))
7006 (fb (and mb (marker-buffer mb)))
7007 (todo-kwds
7008 (or (and fa (with-current-buffer fa org-todo-keywords-1))
7009 (and fb (with-current-buffer fb org-todo-keywords-1))))
7010 (ta (or (get-text-property 1 'todo-state a) ""))
7011 (tb (or (get-text-property 1 'todo-state b) ""))
7012 (la (- (length (member ta todo-kwds))))
7013 (lb (- (length (member tb todo-kwds))))
7014 (donepa (member ta org-done-keywords-for-agenda))
7015 (donepb (member tb org-done-keywords-for-agenda)))
7016 (cond ((and donepa (not donepb)) -1)
7017 ((and (not donepa) donepb) +1)
7018 ((< la lb) -1)
7019 ((< lb la) +1))))
7021 (defsubst org-cmp-alpha (a b)
7022 "Compare the headlines, alphabetically."
7023 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
7024 (plb (text-property-any 0 (length b) 'org-heading t b))
7025 (ta (and pla (substring a pla)))
7026 (tb (and plb (substring b plb))))
7027 (when pla
7028 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
7029 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
7030 (setq ta (substring ta (match-end 0))))
7031 (setq ta (downcase ta)))
7032 (when plb
7033 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
7034 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
7035 (setq tb (substring tb (match-end 0))))
7036 (setq tb (downcase tb)))
7037 (cond ((not ta) +1)
7038 ((not tb) -1)
7039 ((string-lessp ta tb) -1)
7040 ((string-lessp tb ta) +1))))
7042 (defsubst org-cmp-tag (a b)
7043 "Compare the string values of the first tags of A and B."
7044 (let ((ta (car (last (get-text-property 1 'tags a))))
7045 (tb (car (last (get-text-property 1 'tags b)))))
7046 (cond ((not ta) +1)
7047 ((not tb) -1)
7048 ((string-lessp ta tb) -1)
7049 ((string-lessp tb ta) +1))))
7051 (defsubst org-cmp-time (a b)
7052 "Compare the time-of-day values of strings A and B."
7053 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7054 (ta (or (get-text-property 1 'time-of-day a) def))
7055 (tb (or (get-text-property 1 'time-of-day b) def)))
7056 (cond ((< ta tb) -1)
7057 ((< tb ta) +1))))
7059 (defsubst org-cmp-ts (a b &optional type)
7060 "Compare the timestamps values of entries A and B.
7061 When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
7062 or \"timestamp_ia\", compare within each of these type.
7063 When TYPE is the empty string, compare all timestamps
7064 without respect of their type."
7065 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7066 (ta (or (and (string-match type (get-text-property 1 'type a))
7067 (get-text-property 1 'ts-date a)) def))
7068 (tb (or (and (string-match type (get-text-property 1 'type b))
7069 (get-text-property 1 'ts-date b)) def)))
7070 (cond ((< ta tb) -1)
7071 ((< tb ta) +1))))
7073 (defsubst org-cmp-habit-p (a b)
7074 "Compare the todo states of strings A and B."
7075 (let ((ha (get-text-property 1 'org-habit-p a))
7076 (hb (get-text-property 1 'org-habit-p b)))
7077 (cond ((and ha (not hb)) -1)
7078 ((and (not ha) hb) +1))))
7080 (defun org-entries-lessp (a b)
7081 "Predicate for sorting agenda entries."
7082 ;; The following variables will be used when the form is evaluated.
7083 ;; So even though the compiler complains, keep them.
7084 (let* ((ss org-agenda-sorting-strategy-selected)
7085 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7086 (org-cmp-ts a b "")))
7087 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7088 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7089 (org-cmp-ts a b "scheduled")))
7090 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7091 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7092 (org-cmp-ts a b "deadline")))
7093 (deadline-down (if deadline-up (- deadline-up) nil))
7094 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7095 (org-cmp-ts a b "iatimestamp_ia")))
7096 (tsia-down (if tsia-up (- tsia-up) nil))
7097 (ts-up (and (org-em 'ts-up 'ts-down ss)
7098 (org-cmp-ts a b "timestamp")))
7099 (ts-down (if ts-up (- ts-up) nil))
7100 (time-up (and (org-em 'time-up 'time-down ss)
7101 (org-cmp-time a b)))
7102 (time-down (if time-up (- time-up) nil))
7103 (priority-up (and (org-em 'priority-up 'priority-down ss)
7104 (org-cmp-priority a b)))
7105 (priority-down (if priority-up (- priority-up) nil))
7106 (effort-up (and (org-em 'effort-up 'effort-down ss)
7107 (org-cmp-effort a b)))
7108 (effort-down (if effort-up (- effort-up) nil))
7109 (category-up (and (or (org-em 'category-up 'category-down ss)
7110 (memq 'category-keep ss))
7111 (org-cmp-category a b)))
7112 (category-down (if category-up (- category-up) nil))
7113 (category-keep (if category-up +1 nil))
7114 (tag-up (and (org-em 'tag-up 'tag-down ss)
7115 (org-cmp-tag a b)))
7116 (tag-down (if tag-up (- tag-up) nil))
7117 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7118 (org-cmp-todo-state a b)))
7119 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7120 (habit-up (and (org-em 'habit-up 'habit-down ss)
7121 (org-cmp-habit-p a b)))
7122 (habit-down (if habit-up (- habit-up) nil))
7123 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7124 (org-cmp-alpha a b)))
7125 (alpha-down (if alpha-up (- alpha-up) nil))
7126 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7127 user-defined-up user-defined-down)
7128 (if (and need-user-cmp org-agenda-cmp-user-defined
7129 (functionp org-agenda-cmp-user-defined))
7130 (setq user-defined-up
7131 (funcall org-agenda-cmp-user-defined a b)
7132 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7133 (cdr (assoc
7134 (eval (cons 'or org-agenda-sorting-strategy-selected))
7135 '((-1 . t) (1 . nil) (nil . nil))))))
7137 ;;; Agenda restriction lock
7139 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7140 "Overlay to mark the headline to which agenda commands are restricted.")
7141 (overlay-put org-agenda-restriction-lock-overlay
7142 'face 'org-agenda-restriction-lock)
7143 (overlay-put org-agenda-restriction-lock-overlay
7144 'help-echo "Agendas are currently limited to this subtree.")
7145 (org-detach-overlay org-agenda-restriction-lock-overlay)
7147 (defun org-agenda-set-restriction-lock (&optional type)
7148 "Set restriction lock for agenda, to current subtree or file.
7149 Restriction will be the file if TYPE is `file', or if type is the
7150 universal prefix '(4), or if the cursor is before the first headline
7151 in the file. Otherwise, restriction will be to the current subtree."
7152 (interactive "P")
7153 (and (equal type '(4)) (setq type 'file))
7154 (setq type (cond
7155 (type type)
7156 ((org-at-heading-p) 'subtree)
7157 ((condition-case nil (org-back-to-heading t) (error nil))
7158 'subtree)
7159 (t 'file)))
7160 (if (eq type 'subtree)
7161 (progn
7162 (setq org-agenda-restrict t)
7163 (setq org-agenda-overriding-restriction 'subtree)
7164 (put 'org-agenda-files 'org-restrict
7165 (list (buffer-file-name (buffer-base-buffer))))
7166 (org-back-to-heading t)
7167 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
7168 (move-marker org-agenda-restrict-begin (point))
7169 (move-marker org-agenda-restrict-end
7170 (save-excursion (org-end-of-subtree t)))
7171 (message "Locking agenda restriction to subtree"))
7172 (put 'org-agenda-files 'org-restrict
7173 (list (buffer-file-name (buffer-base-buffer))))
7174 (setq org-agenda-restrict nil)
7175 (setq org-agenda-overriding-restriction 'file)
7176 (move-marker org-agenda-restrict-begin nil)
7177 (move-marker org-agenda-restrict-end nil)
7178 (message "Locking agenda restriction to file"))
7179 (setq current-prefix-arg nil)
7180 (org-agenda-maybe-redo))
7182 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7183 "Remove the agenda restriction lock."
7184 (interactive "P")
7185 (org-detach-overlay org-agenda-restriction-lock-overlay)
7186 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7187 (setq org-agenda-overriding-restriction nil)
7188 (setq org-agenda-restrict nil)
7189 (put 'org-agenda-files 'org-restrict nil)
7190 (move-marker org-agenda-restrict-begin nil)
7191 (move-marker org-agenda-restrict-end nil)
7192 (setq current-prefix-arg nil)
7193 (message "Agenda restriction lock removed")
7194 (or noupdate (org-agenda-maybe-redo)))
7196 (defun org-agenda-maybe-redo ()
7197 "If there is any window showing the agenda view, update it."
7198 (let ((w (get-buffer-window org-agenda-buffer-name t))
7199 (w0 (selected-window)))
7200 (when w
7201 (select-window w)
7202 (org-agenda-redo)
7203 (select-window w0)
7204 (if org-agenda-overriding-restriction
7205 (message "Agenda view shifted to new %s restriction"
7206 org-agenda-overriding-restriction)
7207 (message "Agenda restriction lock removed")))))
7209 ;;; Agenda commands
7211 (defun org-agenda-check-type (error &rest types)
7212 "Check if agenda buffer is of allowed type.
7213 If ERROR is non-nil, throw an error, otherwise just return nil.
7214 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
7215 (if (not org-agenda-type)
7216 (error "No Org agenda currently displayed")
7217 (if (memq org-agenda-type types)
7219 (if error
7220 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7221 nil))))
7223 (defun org-agenda-Quit ()
7224 "Exit the agenda and kill buffers loaded by `org-agenda'.
7225 Also restore the window configuration."
7226 (interactive)
7227 (if org-agenda-columns-active
7228 (org-columns-quit)
7229 (let ((buf (current-buffer)))
7230 (if (eq org-agenda-window-setup 'other-frame)
7231 (progn
7232 (org-agenda-reset-markers)
7233 (kill-buffer buf)
7234 (org-columns-remove-overlays)
7235 (setq org-agenda-archives-mode nil)
7236 (delete-frame))
7237 (and (not (eq org-agenda-window-setup 'current-window))
7238 (not (one-window-p))
7239 (delete-window))
7240 (org-agenda-reset-markers)
7241 (kill-buffer buf)
7242 (org-columns-remove-overlays)
7243 (setq org-agenda-archives-mode nil)))
7244 ;; Maybe restore the pre-agenda window configuration.
7245 (and org-agenda-restore-windows-after-quit
7246 (not (eq org-agenda-window-setup 'other-frame))
7247 org-agenda-pre-window-conf
7248 (set-window-configuration org-agenda-pre-window-conf)
7249 (setq org-agenda-pre-window-conf nil))))
7251 (defun org-agenda-quit ()
7252 "Exit the agenda and restore the window configuration.
7253 When `org-agenda-sticky' is non-nil, only bury the agenda."
7254 (interactive)
7255 (if (and (eq org-indirect-buffer-display 'other-window)
7256 org-last-indirect-buffer)
7257 (let ((org-last-indirect-window
7258 (get-buffer-window org-last-indirect-buffer)))
7259 (if org-last-indirect-window
7260 (delete-window org-last-indirect-window))))
7261 (if org-agenda-columns-active
7262 (org-columns-quit)
7263 (if org-agenda-sticky
7264 (let ((buf (current-buffer)))
7265 (if (eq org-agenda-window-setup 'other-frame)
7266 (progn
7267 (delete-frame))
7268 (and (not (eq org-agenda-window-setup 'current-window))
7269 (not (one-window-p))
7270 (delete-window)))
7271 (with-current-buffer buf
7272 (bury-buffer)
7273 ;; Maybe restore the pre-agenda window configuration.
7274 (and org-agenda-restore-windows-after-quit
7275 (not (eq org-agenda-window-setup 'other-frame))
7276 org-agenda-pre-window-conf
7277 (set-window-configuration org-agenda-pre-window-conf)
7278 (setq org-agenda-pre-window-conf nil))))
7279 (org-agenda-Quit))))
7281 (defun org-agenda-exit ()
7282 "Exit the agenda and restore the window configuration.
7283 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7284 buffers visited directly by the user will not be touched."
7285 (interactive)
7286 (org-release-buffers org-agenda-new-buffers)
7287 (setq org-agenda-new-buffers nil)
7288 (org-agenda-Quit))
7290 (defun org-agenda-kill-all-agenda-buffers ()
7291 "Kill all buffers in `org-agenda-mode'.
7292 This is used when toggling sticky agendas.
7293 You can also explicitly invoke it with `C-c a C-k'."
7294 (interactive)
7295 (let (blist)
7296 (dolist (buf (buffer-list))
7297 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7298 (push buf blist)))
7299 (mapc 'kill-buffer blist)))
7301 (defun org-agenda-execute (arg)
7302 "Execute another agenda command, keeping same window.
7303 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7304 in the agenda."
7305 (interactive "P")
7306 (let ((org-agenda-window-setup 'current-window))
7307 (org-agenda arg)))
7309 (defun org-agenda-redo (&optional all)
7310 "Rebuild possibly ALL agenda view(s) in the current buffer."
7311 (interactive "P")
7312 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7313 (cpa (unless (eq all t) current-prefix-arg))
7314 (org-agenda-doing-sticky-redo org-agenda-sticky)
7315 (org-agenda-sticky nil)
7316 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7317 org-agenda-buffer-name))
7318 (org-agenda-keep-modes t)
7319 (tag-filter org-agenda-tag-filter)
7320 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7321 (top-cat-filter org-agenda-top-category-filter)
7322 (cat-filter org-agenda-category-filter)
7323 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7324 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7325 (cols org-agenda-columns-active)
7326 (line (org-current-line))
7327 (window-line (- line (org-current-line (window-start))))
7328 (lprops (get 'org-agenda-redo-command 'org-lprops))
7329 (redo-cmd (get-text-property p 'org-redo-cmd))
7330 (last-args (get-text-property p 'org-last-args))
7331 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7332 (org-agenda-overriding-cmd-arguments
7333 (unless (eq all t)
7334 (cond ((listp last-args)
7335 (cons (or cpa (car last-args)) (cdr last-args)))
7336 ((stringp last-args)
7337 last-args))))
7338 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7339 (put 'org-agenda-tag-filter :preset-filter nil)
7340 (put 'org-agenda-category-filter :preset-filter nil)
7341 (and cols (org-columns-quit))
7342 (message "Rebuilding agenda buffer...")
7343 (if series-redo-cmd
7344 (eval series-redo-cmd)
7345 (org-let lprops '(eval redo-cmd)))
7346 (setq org-agenda-undo-list nil
7347 org-agenda-pending-undo-list nil)
7348 (message "Rebuilding agenda buffer...done")
7349 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7350 (put 'org-agenda-category-filter :preset-filter cat-preset)
7351 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7352 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7353 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7354 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7355 (org-goto-line line)
7356 (recenter window-line)))
7358 (defvar org-global-tags-completion-table nil)
7359 (defvar org-agenda-filter-form nil)
7360 (defvar org-agenda-filtered-by-category nil)
7362 (defun org-agenda-filter-by-category (strip)
7363 "Keep only those lines in the agenda buffer that have a specific category.
7364 The category is that of the current line."
7365 (interactive "P")
7366 (if (and org-agenda-filtered-by-category
7367 org-agenda-category-filter)
7368 (org-agenda-filter-show-all-cat)
7369 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7370 (if cat (org-agenda-filter-apply
7371 (list (concat (if strip "-" "+") cat)) 'category)
7372 (error "No category at point")))))
7374 (defun org-find-top-category (&optional pos)
7375 (save-excursion
7376 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7377 (if pos (goto-char pos))
7378 ;; Skip up to the topmost parent
7379 (while (ignore-errors (outline-up-heading 1) t))
7380 (ignore-errors
7381 (nth 4 (org-heading-components))))))
7383 (defvar org-agenda-filtered-by-top-category nil)
7385 (defun org-agenda-filter-by-top-category (strip)
7386 "Keep only those lines in the agenda buffer that have a specific category.
7387 The category is that of the current line."
7388 (interactive "P")
7389 (if org-agenda-filtered-by-top-category
7390 (progn
7391 (setq org-agenda-filtered-by-top-category nil
7392 org-agenda-top-category-filter nil)
7393 (org-agenda-filter-show-all-cat))
7394 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7395 (if cat (org-agenda-filter-top-category-apply cat strip)
7396 (error "No top-level category at point")))))
7398 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7399 "Keep only those lines in the agenda buffer that have a specific tag.
7400 The tag is selected with its fast selection letter, as configured.
7401 With prefix argument STRIP, remove all lines that do have the tag.
7402 A lisp caller can specify CHAR. NARROW means that the new tag should be
7403 used to narrow the search - the interactive user can also press `-' or `+'
7404 to switch to narrowing."
7405 (interactive "P")
7406 (let* ((alist org-tag-alist-for-agenda)
7407 (tag-chars (mapconcat
7408 (lambda (x) (if (and (not (symbolp (car x)))
7409 (cdr x))
7410 (char-to-string (cdr x))
7411 ""))
7412 alist ""))
7413 (efforts (org-split-string
7414 (or (cdr (assoc (concat org-effort-property "_ALL")
7415 org-global-properties))
7416 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7417 "")))
7418 (effort-op org-agenda-filter-effort-default-operator)
7419 (effort-prompt "")
7420 (inhibit-read-only t)
7421 (current org-agenda-tag-filter)
7422 maybe-refresh a n tag)
7423 (unless char
7424 (message
7425 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7426 (if narrow "Narrow" "Filter") tag-chars
7427 (if org-agenda-auto-exclude-function "[RET], " ""))
7428 (setq char (read-char-exclusive)))
7429 (when (member char '(?+ ?-))
7430 ;; Narrowing down
7431 (cond ((equal char ?-) (setq strip t narrow t))
7432 ((equal char ?+) (setq strip nil narrow t)))
7433 (message
7434 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7435 (setq char (read-char-exclusive)))
7436 (when (member char '(?< ?> ?= ??))
7437 ;; An effort operator
7438 (setq effort-op (char-to-string char))
7439 (setq alist nil) ; to make sure it will be interpreted as effort.
7440 (unless (equal char ??)
7441 (loop for i from 0 to 9 do
7442 (setq effort-prompt
7443 (concat
7444 effort-prompt " ["
7445 (if (= i 9) "0" (int-to-string (1+ i)))
7446 "]" (nth i efforts))))
7447 (message "Effort%s: %s " effort-op effort-prompt)
7448 (setq char (read-char-exclusive))
7449 (when (or (< char ?0) (> char ?9))
7450 (error "Need 1-9,0 to select effort"))))
7451 (when (equal char ?\t)
7452 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7453 (org-set-local 'org-global-tags-completion-table
7454 (org-global-tags-completion-table)))
7455 (let ((completion-ignore-case t))
7456 (setq tag (org-icompleting-read
7457 "Tag: " org-global-tags-completion-table))))
7458 (cond
7459 ((equal char ?\r)
7460 (org-agenda-filter-show-all-tag)
7461 (when org-agenda-auto-exclude-function
7462 (setq org-agenda-tag-filter '())
7463 (dolist (tag (org-agenda-get-represented-tags))
7464 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7465 (if modifier
7466 (push modifier org-agenda-tag-filter))))
7467 (if (not (null org-agenda-tag-filter))
7468 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7469 (setq maybe-refresh t))
7470 ((equal char ?/)
7471 (org-agenda-filter-show-all-tag)
7472 (when (get 'org-agenda-tag-filter :preset-filter)
7473 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7474 (setq maybe-refresh t))
7475 ((equal char ?. )
7476 (setq org-agenda-tag-filter
7477 (mapcar (lambda(tag) (concat "+" tag))
7478 (org-get-at-bol 'tags)))
7479 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7480 (setq maybe-refresh t))
7481 ((or (equal char ?\ )
7482 (setq a (rassoc char alist))
7483 (and (>= char ?0) (<= char ?9)
7484 (setq n (if (= char ?0) 9 (- char ?0 1))
7485 tag (concat effort-op (nth n efforts))
7486 a (cons tag nil)))
7487 (and (= char ??)
7488 (setq tag "?eff")
7489 a (cons tag nil))
7490 (and tag (setq a (cons tag nil))))
7491 (org-agenda-filter-show-all-tag)
7492 (setq tag (car a))
7493 (setq org-agenda-tag-filter
7494 (cons (concat (if strip "-" "+") tag)
7495 (if narrow current nil)))
7496 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7497 (setq maybe-refresh t))
7498 (t (error "Invalid tag selection character %c" char)))
7499 (when (and maybe-refresh
7500 (eq org-agenda-clockreport-mode 'with-filter))
7501 (org-agenda-redo))))
7503 (defun org-agenda-get-represented-tags ()
7504 "Get a list of all tags currently represented in the agenda."
7505 (let (p tags)
7506 (save-excursion
7507 (goto-char (point-min))
7508 (while (setq p (next-single-property-change (point) 'tags))
7509 (goto-char p)
7510 (mapc (lambda (x) (add-to-list 'tags x))
7511 (get-text-property (point) 'tags))))
7512 tags))
7514 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7515 "Refine the current filter. See `org-agenda-filter-by-tag'."
7516 (interactive "P")
7517 (org-agenda-filter-by-tag strip char 'refine))
7519 (defun org-agenda-filter-make-matcher ()
7520 "Create the form that tests a line for agenda filter."
7521 (let (f f1)
7522 ;; first compute the tag-filter matcher
7523 (dolist (x (delete-dups
7524 (append (get 'org-agenda-tag-filter
7525 :preset-filter) org-agenda-tag-filter)))
7526 (if (member x '("-" "+"))
7527 (setq f1 (if (equal x "-") 'tags '(not tags)))
7528 (if (string-match "[<=>?]" x)
7529 (setq f1 (org-agenda-filter-effort-form x))
7530 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7531 (if (equal (string-to-char x) ?-)
7532 (setq f1 (list 'not f1))))
7533 (push f1 f))
7534 ;; then compute the category-filter matcher
7535 (dolist (x (delete-dups
7536 (append (get 'org-agenda-category-filter
7537 :preset-filter) org-agenda-category-filter)))
7538 (if (equal "-" (substring x 0 1))
7539 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7540 (setq f1 (list 'equal (substring x 1) 'cat)))
7541 (push f1 f))
7542 (cons 'and (nreverse f))))
7544 (defun org-agenda-filter-effort-form (e)
7545 "Return the form to compare the effort of the current line with what E says.
7546 E looks like \"+<2:25\"."
7547 (let (op)
7548 (setq e (substring e 1))
7549 (setq op (string-to-char e) e (substring e 1))
7550 (setq op (cond ((equal op ?<) '<=)
7551 ((equal op ?>) '>=)
7552 ((equal op ??) op)
7553 (t '=)))
7554 (list 'org-agenda-compare-effort (list 'quote op)
7555 (org-duration-string-to-minutes e))))
7557 (defun org-agenda-compare-effort (op value)
7558 "Compare the effort of the current line with VALUE, using OP.
7559 If the line does not have an effort defined, return nil."
7560 (let ((eff (org-get-at-bol 'effort-minutes)))
7561 (if (equal op ??)
7562 (not eff)
7563 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7564 value))))
7566 (defun org-agenda-filter-apply (filter type)
7567 "Set FILTER as the new agenda filter and apply it."
7568 (let (tags cat)
7569 (if (eq type 'tag)
7570 (setq org-agenda-tag-filter filter)
7571 (setq org-agenda-category-filter filter))
7572 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7573 (if (and (eq type 'category)
7574 (not (equal (substring (car filter) 0 1) "-")))
7575 ;; Only set `org-agenda-filtered-by-category' to t
7576 ;; when a unique category is used as the filter
7577 (setq org-agenda-filtered-by-category t))
7578 (org-agenda-set-mode-name)
7579 (save-excursion
7580 (goto-char (point-min))
7581 (while (not (eobp))
7582 (if (org-get-at-bol 'org-marker)
7583 (progn
7584 (setq tags (org-get-at-bol 'tags) ; used in eval
7585 cat (get-text-property (point) 'org-category))
7586 (if (not (eval org-agenda-filter-form))
7587 (org-agenda-filter-hide-line type))
7588 (beginning-of-line 2))
7589 (beginning-of-line 2))))
7590 (if (get-char-property (point) 'invisible)
7591 (ignore-errors (org-agenda-previous-line)))))
7593 (defun org-agenda-filter-top-category-apply (category &optional negative)
7594 "Set FILTER as the new agenda filter and apply it."
7595 (org-agenda-set-mode-name)
7596 (save-excursion
7597 (goto-char (point-min))
7598 (while (not (eobp))
7599 (let* ((pos (org-get-at-bol 'org-hd-marker))
7600 (topcat (and pos (org-find-top-category pos))))
7601 (if (and topcat (funcall (if negative 'identity 'not)
7602 (string= category topcat)))
7603 (org-agenda-filter-hide-line 'category)))
7604 (beginning-of-line 2)))
7605 (if (get-char-property (point) 'invisible)
7606 (org-agenda-previous-line))
7607 (setq org-agenda-top-category-filter category
7608 org-agenda-filtered-by-top-category t))
7610 (defun org-agenda-filter-hide-line (type)
7611 (let (ov)
7612 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7613 (point-at-eol)))
7614 (overlay-put ov 'invisible t)
7615 (overlay-put ov 'type type)
7616 (if (eq type 'tag)
7617 (push ov org-agenda-tag-filter-overlays)
7618 (push ov org-agenda-cat-filter-overlays))))
7620 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7621 (setq pos (or pos (point)))
7622 (save-excursion
7623 (dolist (ov (overlays-at pos))
7624 (when (and (overlay-get ov 'invisible)
7625 (eq (overlay-get ov 'type) 'tag))
7626 (goto-char pos)
7627 (if (< (overlay-start ov) (point-at-eol))
7628 (move-overlay ov (point-at-eol)
7629 (overlay-end ov)))))))
7631 (defun org-agenda-filter-show-all-tag nil
7632 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7633 (setq org-agenda-tag-filter-overlays nil
7634 org-agenda-tag-filter nil
7635 org-agenda-filter-form nil)
7636 (org-agenda-set-mode-name))
7638 (defun org-agenda-filter-show-all-cat nil
7639 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7640 (setq org-agenda-cat-filter-overlays nil
7641 org-agenda-filtered-by-category nil
7642 org-agenda-category-filter nil
7643 org-agenda-filter-form nil)
7644 (org-agenda-set-mode-name))
7646 (defun org-agenda-manipulate-query-add ()
7647 "Manipulate the query by adding a search term with positive selection.
7648 Positive selection means the term must be matched for selection of an entry."
7649 (interactive)
7650 (org-agenda-manipulate-query ?\[))
7651 (defun org-agenda-manipulate-query-subtract ()
7652 "Manipulate the query by adding a search term with negative selection.
7653 Negative selection means term must not be matched for selection of an entry."
7654 (interactive)
7655 (org-agenda-manipulate-query ?\]))
7656 (defun org-agenda-manipulate-query-add-re ()
7657 "Manipulate the query by adding a search regexp with positive selection.
7658 Positive selection means the regexp must match for selection of an entry."
7659 (interactive)
7660 (org-agenda-manipulate-query ?\{))
7661 (defun org-agenda-manipulate-query-subtract-re ()
7662 "Manipulate the query by adding a search regexp with negative selection.
7663 Negative selection means regexp must not match for selection of an entry."
7664 (interactive)
7665 (org-agenda-manipulate-query ?\}))
7666 (defun org-agenda-manipulate-query (char)
7667 (cond
7668 ((memq org-agenda-type '(timeline agenda))
7669 (let ((org-agenda-include-inactive-timestamps t))
7670 (org-agenda-redo))
7671 (message "Display now includes inactive timestamps as well"))
7672 ((eq org-agenda-type 'search)
7673 (org-add-to-string
7674 'org-agenda-query-string
7675 (if org-agenda-last-search-view-search-was-boolean
7676 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7677 (?\{ . " +{}") (?\} . " -{}"))))
7678 " "))
7679 (setq org-agenda-redo-command
7680 (list 'org-search-view
7681 (car (get-text-property (min (1- (point-max)) (point))
7682 'org-last-args))
7683 org-agenda-query-string
7684 (+ (length org-agenda-query-string)
7685 (if (member char '(?\{ ?\})) 0 1))))
7686 (set-register org-agenda-query-register org-agenda-query-string)
7687 (let ((org-agenda-overriding-arguments
7688 (cdr org-agenda-redo-command)))
7689 (org-agenda-redo)))
7690 (t (error "Cannot manipulate query for %s-type agenda buffers"
7691 org-agenda-type))))
7693 (defun org-add-to-string (var string)
7694 (set var (concat (symbol-value var) string)))
7696 (defun org-agenda-goto-date (span)
7697 "Jump to DATE in agenda."
7698 (interactive "P")
7699 (let* ((org-read-date-prefer-future
7700 (eval org-agenda-jump-prefer-future))
7701 (date (org-read-date))
7702 (org-agenda-sticky-orig org-agenda-sticky)
7703 (org-agenda-buffer-tmp-name (buffer-name))
7704 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7705 (0-arg (or current-prefix-arg (car args)))
7706 (2-arg (nth 2 args))
7707 (newcmd (list 'org-agenda-list 0-arg date
7708 (org-agenda-span-to-ndays 2-arg)))
7709 (newargs (cdr newcmd))
7710 (inhibit-read-only t)
7711 org-agenda-sticky)
7712 (if (not (org-agenda-check-type t 'agenda))
7713 (error "Not available in non-agenda blocks")
7714 (add-text-properties (point-min) (point-max)
7715 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7716 (org-agenda-redo)
7717 (setq org-agenda-sticky org-agenda-sticky-orig
7718 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7720 (defun org-agenda-goto-today ()
7721 "Go to today."
7722 (interactive)
7723 (org-agenda-check-type t 'timeline 'agenda)
7724 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7725 (curspan (nth 2 args))
7726 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7727 (cond
7728 (tdpos (goto-char tdpos))
7729 ((eq org-agenda-type 'agenda)
7730 (let* ((sd (org-agenda-compute-starting-span
7731 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7732 (org-agenda-overriding-arguments args))
7733 (setf (nth 1 org-agenda-overriding-arguments) sd)
7734 (org-agenda-redo)
7735 (org-agenda-find-same-or-today-or-agenda)))
7736 (t (error "Cannot find today")))))
7738 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7739 (goto-char
7740 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7741 (text-property-any (point-min) (point-max) 'org-today t)
7742 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7743 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7744 (org-agenda-goto-block-beginning))
7745 (point-min))))
7747 (defun org-agenda-goto-block-beginning ()
7748 "Go the agenda block beginning."
7749 (interactive)
7750 (if (not (derived-mode-p 'org-agenda-mode))
7751 (error "Cannot execute this command outside of org-agenda-mode buffers")
7752 (let (dest)
7753 (save-excursion
7754 (unless (looking-at "\\'")
7755 (forward-char))
7756 (let* ((prop 'org-agenda-structural-header)
7757 (p (previous-single-property-change (point) prop))
7758 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7759 (1- (point))) prop)))
7760 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7761 (if (not dest)
7762 (error "Cannot find the beginning of the blog")
7763 (goto-char dest)
7764 (move-beginning-of-line 1)))))
7766 (defun org-agenda-later (arg)
7767 "Go forward in time by the current span.
7768 With prefix ARG, go forward that many times the current span."
7769 (interactive "p")
7770 (org-agenda-check-type t 'agenda)
7771 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7772 (span (or (nth 2 args) org-agenda-current-span))
7773 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7774 (greg (calendar-gregorian-from-absolute sd))
7775 (cnt (org-get-at-bol 'org-day-cnt))
7776 greg2)
7777 (cond
7778 ((numberp span)
7779 (setq sd (+ (* span arg) sd)))
7780 ((eq span 'day)
7781 (setq sd (+ arg sd)))
7782 ((eq span 'week)
7783 (setq sd (+ (* 7 arg) sd)))
7784 ((eq span 'month)
7785 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7786 sd (calendar-absolute-from-gregorian greg2))
7787 (setcar greg2 (1+ (car greg2))))
7788 ((eq span 'year)
7789 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7790 sd (calendar-absolute-from-gregorian greg2))
7791 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7793 (setq sd (+ (* span arg) sd))))
7794 (let ((org-agenda-overriding-cmd
7795 ;; `cmd' may have been set by `org-agenda-run-series' which
7796 ;; uses `org-agenda-overriding-cmd' to decide whether
7797 ;; overriding is allowed for `cmd'
7798 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7799 (org-agenda-overriding-arguments
7800 (list (car args) sd span)))
7801 (org-agenda-redo)
7802 (org-agenda-find-same-or-today-or-agenda cnt))))
7804 (defun org-agenda-earlier (arg)
7805 "Go backward in time by the current span.
7806 With prefix ARG, go backward that many times the current span."
7807 (interactive "p")
7808 (org-agenda-later (- arg)))
7810 (defun org-agenda-view-mode-dispatch ()
7811 "Call one of the view mode commands."
7812 (interactive)
7813 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7814 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7815 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7816 (let ((a (read-char-exclusive)))
7817 (case a
7818 (?\ (call-interactively 'org-agenda-reset-view))
7819 (?d (call-interactively 'org-agenda-day-view))
7820 (?w (call-interactively 'org-agenda-week-view))
7821 (?m (call-interactively 'org-agenda-month-view))
7822 (?y (call-interactively 'org-agenda-year-view))
7823 (?l (call-interactively 'org-agenda-log-mode))
7824 (?L (org-agenda-log-mode '(4)))
7825 (?c (org-agenda-log-mode 'clockcheck))
7826 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7827 (?a (call-interactively 'org-agenda-archives-mode))
7828 (?A (org-agenda-archives-mode 'files))
7829 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7830 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7831 (?G (call-interactively 'org-agenda-toggle-time-grid))
7832 (?D (call-interactively 'org-agenda-toggle-diary))
7833 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7834 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7835 (org-agenda-check-type t 'timeline 'agenda)
7836 (org-agenda-redo))
7837 (message "Display now includes inactive timestamps as well"))
7838 (?q (message "Abort"))
7839 (otherwise (error "Invalid key" )))))
7841 (defun org-agenda-reset-view ()
7842 "Switch to default view for agenda."
7843 (interactive)
7844 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7845 (defun org-agenda-day-view (&optional day-of-year)
7846 "Switch to daily view for agenda.
7847 With argument DAY-OF-YEAR, switch to that day of the year."
7848 (interactive "P")
7849 (org-agenda-change-time-span 'day day-of-year))
7850 (defun org-agenda-week-view (&optional iso-week)
7851 "Switch to daily view for agenda.
7852 With argument ISO-WEEK, switch to the corresponding ISO week.
7853 If ISO-WEEK has more then 2 digits, only the last two encode the
7854 week. Any digits before this encode a year. So 200712 means
7855 week 12 of year 2007. Years in the range 1938-2037 can also be
7856 written as 2-digit years."
7857 (interactive "P")
7858 (org-agenda-change-time-span 'week iso-week))
7859 (defun org-agenda-month-view (&optional month)
7860 "Switch to monthly view for agenda.
7861 With argument MONTH, switch to that month."
7862 (interactive "P")
7863 (org-agenda-change-time-span 'month month))
7864 (defun org-agenda-year-view (&optional year)
7865 "Switch to yearly view for agenda.
7866 With argument YEAR, switch to that year.
7867 If MONTH has more then 2 digits, only the last two encode the
7868 month. Any digits before this encode a year. So 200712 means
7869 December year 2007. Years in the range 1938-2037 can also be
7870 written as 2-digit years."
7871 (interactive "P")
7872 (when year
7873 (setq year (org-small-year-to-year year)))
7874 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7875 (org-agenda-change-time-span 'year year)
7876 (error "Abort")))
7878 (defun org-agenda-change-time-span (span &optional n)
7879 "Change the agenda view to SPAN.
7880 SPAN may be `day', `week', `month', `year'."
7881 (org-agenda-check-type t 'agenda)
7882 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7883 (curspan (nth 2 args)))
7884 (if (and (not n) (equal curspan span))
7885 (error "Viewing span is already \"%s\"" span))
7886 (let* ((sd (or (org-get-at-bol 'day)
7887 (nth 1 args)
7888 org-starting-day))
7889 (sd (org-agenda-compute-starting-span sd span n))
7890 (org-agenda-overriding-cmd
7891 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7892 (org-agenda-overriding-arguments
7893 (list (car args) sd span)))
7894 (org-agenda-redo)
7895 (org-agenda-find-same-or-today-or-agenda))
7896 (org-agenda-set-mode-name)
7897 (message "Switched to %s view" span)))
7899 (defun org-agenda-compute-starting-span (sd span &optional n)
7900 "Compute starting date for agenda.
7901 SPAN may be `day', `week', `month', `year'. The return value
7902 is a cons cell with the starting date and the number of days,
7903 so that the date SD will be in that range."
7904 (let* ((greg (calendar-gregorian-from-absolute sd))
7905 (dg (nth 1 greg))
7906 (mg (car greg))
7907 (yg (nth 2 greg)))
7908 (cond
7909 ((eq span 'day)
7910 (when n
7911 (setq sd (+ (calendar-absolute-from-gregorian
7912 (list mg 1 yg))
7913 n -1))))
7914 ((eq span 'week)
7915 (let* ((nt (calendar-day-of-week
7916 (calendar-gregorian-from-absolute sd)))
7917 (d (if org-agenda-start-on-weekday
7918 (- nt org-agenda-start-on-weekday)
7921 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7922 (when n
7923 (require 'cal-iso)
7924 (when (> n 99)
7925 (setq y1 (org-small-year-to-year (/ n 100))
7926 n (mod n 100)))
7927 (setq sd
7928 (calendar-absolute-from-iso
7929 (list n 1
7930 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7931 ((eq span 'month)
7932 (let (y1)
7933 (when (and n (> n 99))
7934 (setq y1 (org-small-year-to-year (/ n 100))
7935 n (mod n 100)))
7936 (setq sd (calendar-absolute-from-gregorian
7937 (list (or n mg) 1 (or y1 yg))))))
7938 ((eq span 'year)
7939 (setq sd (calendar-absolute-from-gregorian
7940 (list 1 1 (or n yg))))))
7941 sd))
7943 (defun org-agenda-next-date-line (&optional arg)
7944 "Jump to the next line indicating a date in agenda buffer."
7945 (interactive "p")
7946 (org-agenda-check-type t 'agenda 'timeline)
7947 (beginning-of-line 1)
7948 ;; This does not work if user makes date format that starts with a blank
7949 (if (looking-at "^\\S-") (forward-char 1))
7950 (if (not (re-search-forward "^\\S-" nil t arg))
7951 (progn
7952 (backward-char 1)
7953 (error "No next date after this line in this buffer")))
7954 (goto-char (match-beginning 0)))
7956 (defun org-agenda-previous-date-line (&optional arg)
7957 "Jump to the previous line indicating a date in agenda buffer."
7958 (interactive "p")
7959 (org-agenda-check-type t 'agenda 'timeline)
7960 (beginning-of-line 1)
7961 (if (not (re-search-backward "^\\S-" nil t arg))
7962 (error "No previous date before this line in this buffer")))
7964 ;; Initialize the highlight
7965 (defvar org-hl (make-overlay 1 1))
7966 (overlay-put org-hl 'face 'highlight)
7968 (defun org-highlight (begin end &optional buffer)
7969 "Highlight a region with overlay."
7970 (move-overlay org-hl begin end (or buffer (current-buffer))))
7972 (defun org-unhighlight ()
7973 "Detach overlay INDEX."
7974 (org-detach-overlay org-hl))
7976 (defun org-unhighlight-once ()
7977 "Remove the highlight from its position, and this function from the hook."
7978 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7979 (org-unhighlight))
7981 (defvar org-agenda-pre-follow-window-conf nil)
7982 (defun org-agenda-follow-mode ()
7983 "Toggle follow mode in an agenda buffer."
7984 (interactive)
7985 (unless org-agenda-follow-mode
7986 (setq org-agenda-pre-follow-window-conf
7987 (current-window-configuration)))
7988 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7989 (unless org-agenda-follow-mode
7990 (set-window-configuration org-agenda-pre-follow-window-conf))
7991 (org-agenda-set-mode-name)
7992 (org-agenda-do-context-action)
7993 (message "Follow mode is %s"
7994 (if org-agenda-follow-mode "on" "off")))
7996 (defun org-agenda-entry-text-mode (&optional arg)
7997 "Toggle entry text mode in an agenda buffer."
7998 (interactive "P")
7999 (setq org-agenda-entry-text-mode (or (integerp arg)
8000 (not org-agenda-entry-text-mode)))
8001 (org-agenda-entry-text-hide)
8002 (and org-agenda-entry-text-mode
8003 (let ((org-agenda-entry-text-maxlines
8004 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8005 (org-agenda-entry-text-show)))
8006 (org-agenda-set-mode-name)
8007 (message "Entry text mode is %s. Maximum number of lines is %d"
8008 (if org-agenda-entry-text-mode "on" "off")
8009 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8011 (defun org-agenda-clockreport-mode (&optional with-filter)
8012 "Toggle clocktable mode in an agenda buffer.
8013 With prefix arg WITH-FILTER, make the clocktable respect the current
8014 agenda filter."
8015 (interactive "P")
8016 (org-agenda-check-type t 'agenda)
8017 (if with-filter
8018 (setq org-agenda-clockreport-mode 'with-filter)
8019 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
8020 (org-agenda-set-mode-name)
8021 (org-agenda-redo)
8022 (message "Clocktable mode is %s"
8023 (if org-agenda-clockreport-mode "on" "off")))
8025 (defun org-agenda-log-mode (&optional special)
8026 "Toggle log mode in an agenda buffer.
8027 With argument SPECIAL, show all possible log items, not only the ones
8028 configured in `org-agenda-log-mode-items'.
8029 With a double `C-u' prefix arg, show *only* log items, nothing else."
8030 (interactive "P")
8031 (org-agenda-check-type t 'agenda 'timeline)
8032 (setq org-agenda-show-log
8033 (cond
8034 ((equal special '(16)) 'only)
8035 ((eq special 'clockcheck)
8036 (if (eq org-agenda-show-log 'clockcheck)
8037 nil 'clockcheck))
8038 (special '(closed clock state))
8039 (t (not org-agenda-show-log))))
8040 (org-agenda-set-mode-name)
8041 (org-agenda-redo)
8042 (message "Log mode is %s"
8043 (if org-agenda-show-log "on" "off")))
8045 (defun org-agenda-archives-mode (&optional with-files)
8046 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8047 When called with a prefix argument, include all archive files as well."
8048 (interactive "P")
8049 (setq org-agenda-archives-mode
8050 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8051 (org-agenda-set-mode-name)
8052 (org-agenda-redo)
8053 (message
8054 "%s"
8055 (cond
8056 ((eq org-agenda-archives-mode nil)
8057 "No archives are included")
8058 ((eq org-agenda-archives-mode 'trees)
8059 (format "Trees with :%s: tag are included" org-archive-tag))
8060 ((eq org-agenda-archives-mode t)
8061 (format "Trees with :%s: tag and all active archive files are included"
8062 org-archive-tag)))))
8064 (defun org-agenda-toggle-diary ()
8065 "Toggle diary inclusion in an agenda buffer."
8066 (interactive)
8067 (org-agenda-check-type t 'agenda)
8068 (setq org-agenda-include-diary (not org-agenda-include-diary))
8069 (org-agenda-redo)
8070 (org-agenda-set-mode-name)
8071 (message "Diary inclusion turned %s"
8072 (if org-agenda-include-diary "on" "off")))
8074 (defun org-agenda-toggle-deadlines ()
8075 "Toggle inclusion of entries with a deadline in an agenda buffer."
8076 (interactive)
8077 (org-agenda-check-type t 'agenda)
8078 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8079 (org-agenda-redo)
8080 (org-agenda-set-mode-name)
8081 (message "Deadlines inclusion turned %s"
8082 (if org-agenda-include-deadlines "on" "off")))
8084 (defun org-agenda-toggle-time-grid ()
8085 "Toggle time grid in an agenda buffer."
8086 (interactive)
8087 (org-agenda-check-type t 'agenda)
8088 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8089 (org-agenda-redo)
8090 (org-agenda-set-mode-name)
8091 (message "Time-grid turned %s"
8092 (if org-agenda-use-time-grid "on" "off")))
8094 (defun org-agenda-set-mode-name ()
8095 "Set the mode name to indicate all the small mode settings."
8096 (setq mode-name
8097 (list "Org-Agenda"
8098 (if (get 'org-agenda-files 'org-restrict) " []" "")
8100 '(:eval (org-agenda-span-name org-agenda-current-span))
8101 (if org-agenda-follow-mode " Follow" "")
8102 (if org-agenda-entry-text-mode " ETxt" "")
8103 (if org-agenda-include-diary " Diary" "")
8104 (if org-agenda-include-deadlines " Ddl" "")
8105 (if org-agenda-use-time-grid " Grid" "")
8106 (if (and (boundp 'org-habit-show-habits)
8107 org-habit-show-habits) " Habit" "")
8108 (cond
8109 ((consp org-agenda-show-log) " LogAll")
8110 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8111 (org-agenda-show-log " Log")
8112 (t ""))
8113 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
8114 :preset-filter))
8115 '(:eval (org-propertize
8116 (concat " <"
8117 (mapconcat
8118 'identity
8119 (append
8120 (get 'org-agenda-category-filter :preset-filter)
8121 org-agenda-category-filter)
8123 ">")
8124 'face 'org-agenda-filter-category
8125 'help-echo "Category used in filtering"))
8127 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
8128 :preset-filter))
8129 '(:eval (org-propertize
8130 (concat " {"
8131 (mapconcat
8132 'identity
8133 (append
8134 (get 'org-agenda-tag-filter :preset-filter)
8135 org-agenda-tag-filter)
8137 "}")
8138 'face 'org-agenda-filter-tags
8139 'help-echo "Tags used in filtering"))
8141 (if org-agenda-archives-mode
8142 (if (eq org-agenda-archives-mode t)
8143 " Archives"
8144 (format " :%s:" org-archive-tag))
8146 (if org-agenda-clockreport-mode
8147 (if (eq org-agenda-clockreport-mode 'with-filter)
8148 " Clock{}" " Clock")
8149 "")))
8150 (force-mode-line-update))
8152 (define-obsolete-function-alias
8153 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8155 (defun org-agenda-update-agenda-type ()
8156 "Update the agenda type after each command."
8157 (setq org-agenda-type
8158 (or (get-text-property (point) 'org-agenda-type)
8159 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8161 (defun org-agenda-next-line ()
8162 "Move cursor to the next line, and show if follow mode is active."
8163 (interactive)
8164 (call-interactively 'next-line)
8165 (org-agenda-do-context-action))
8167 (defun org-agenda-previous-line ()
8168 "Move cursor to the previous line, and show if follow-mode is active."
8169 (interactive)
8170 (call-interactively 'previous-line)
8171 (org-agenda-do-context-action))
8173 (defun org-agenda-next-item (n)
8174 "Move cursor to next agenda item."
8175 (interactive "p")
8176 (let ((col (current-column)))
8177 (dotimes (c n)
8178 (when (next-single-property-change (point-at-eol) 'org-marker)
8179 (move-end-of-line 1)
8180 (goto-char (next-single-property-change (point) 'org-marker))))
8181 (org-move-to-column col))
8182 (org-agenda-do-context-action))
8184 (defun org-agenda-previous-item (n)
8185 "Move cursor to next agenda item."
8186 (interactive "p")
8187 (dotimes (c n)
8188 (let ((col (current-column))
8189 (goto (save-excursion
8190 (move-end-of-line 0)
8191 (previous-single-property-change (point) 'org-marker))))
8192 (if goto (goto-char goto))
8193 (org-move-to-column col)))
8194 (org-agenda-do-context-action))
8196 (defun org-agenda-do-context-action ()
8197 "Show outline path and, maybe, follow mode window."
8198 (let ((m (org-get-at-bol 'org-marker)))
8199 (when (and (markerp m) (marker-buffer m))
8200 (and org-agenda-follow-mode
8201 (if org-agenda-follow-indirect
8202 (org-agenda-tree-to-indirect-buffer nil)
8203 (org-agenda-show)))
8204 (and org-agenda-show-outline-path
8205 (org-with-point-at m (org-display-outline-path t))))))
8207 (defun org-agenda-show-tags ()
8208 "Show the tags applicable to the current item."
8209 (interactive)
8210 (let* ((tags (org-get-at-bol 'tags)))
8211 (if tags
8212 (message "Tags are :%s:"
8213 (org-no-properties (mapconcat 'identity tags ":")))
8214 (message "No tags associated with this line"))))
8216 (defun org-agenda-goto (&optional highlight)
8217 "Go to the Org-mode file which contains the item at point."
8218 (interactive)
8219 (let* ((marker (or (org-get-at-bol 'org-marker)
8220 (org-agenda-error)))
8221 (buffer (marker-buffer marker))
8222 (pos (marker-position marker)))
8223 (switch-to-buffer-other-window buffer)
8224 (widen)
8225 (push-mark)
8226 (goto-char pos)
8227 (when (derived-mode-p 'org-mode)
8228 (org-show-context 'agenda)
8229 (save-excursion
8230 (and (outline-next-heading)
8231 (org-flag-heading nil)))) ; show the next heading
8232 (when (outline-invisible-p)
8233 (show-entry)) ; display invisible text
8234 (recenter (/ (window-height) 2))
8235 (run-hooks 'org-agenda-after-show-hook)
8236 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8238 (defvar org-agenda-after-show-hook nil
8239 "Normal hook run after an item has been shown from the agenda.
8240 Point is in the buffer where the item originated.")
8242 (defun org-agenda-kill ()
8243 "Kill the entry or subtree belonging to the current agenda entry."
8244 (interactive)
8245 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8246 (let* ((bufname-orig (buffer-name))
8247 (marker (or (org-get-at-bol 'org-marker)
8248 (org-agenda-error)))
8249 (buffer (marker-buffer marker))
8250 (pos (marker-position marker))
8251 (type (org-get-at-bol 'type))
8252 dbeg dend (n 0) conf)
8253 (org-with-remote-undo buffer
8254 (with-current-buffer buffer
8255 (save-excursion
8256 (goto-char pos)
8257 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8258 (setq dbeg (progn (org-back-to-heading t) (point))
8259 dend (org-end-of-subtree t t))
8260 (setq dbeg (point-at-bol)
8261 dend (min (point-max) (1+ (point-at-eol)))))
8262 (goto-char dbeg)
8263 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8264 (setq conf (or (eq t org-agenda-confirm-kill)
8265 (and (numberp org-agenda-confirm-kill)
8266 (> n org-agenda-confirm-kill))))
8267 (and conf
8268 (not (y-or-n-p
8269 (format "Delete entry with %d lines in buffer \"%s\"? "
8270 n (buffer-name buffer))))
8271 (error "Abort"))
8272 (let ((org-agenda-buffer-name bufname-orig))
8273 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8274 (with-current-buffer buffer (delete-region dbeg dend))
8275 (message "Agenda item and source killed"))))
8277 (defvar org-archive-default-command) ; defined in org-archive.el
8278 (defun org-agenda-archive-default ()
8279 "Archive the entry or subtree belonging to the current agenda entry."
8280 (interactive)
8281 (require 'org-archive)
8282 (org-agenda-archive-with org-archive-default-command))
8284 (defun org-agenda-archive-default-with-confirmation ()
8285 "Archive the entry or subtree belonging to the current agenda entry."
8286 (interactive)
8287 (require 'org-archive)
8288 (org-agenda-archive-with org-archive-default-command 'confirm))
8290 (defun org-agenda-archive ()
8291 "Archive the entry or subtree belonging to the current agenda entry."
8292 (interactive)
8293 (org-agenda-archive-with 'org-archive-subtree))
8295 (defun org-agenda-archive-to-archive-sibling ()
8296 "Move the entry to the archive sibling."
8297 (interactive)
8298 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8300 (defun org-agenda-archive-with (cmd &optional confirm)
8301 "Move the entry to the archive sibling."
8302 (interactive)
8303 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8304 (let* ((bufname-orig (buffer-name))
8305 (marker (or (org-get-at-bol 'org-marker)
8306 (org-agenda-error)))
8307 (buffer (marker-buffer marker))
8308 (pos (marker-position marker)))
8309 (org-with-remote-undo buffer
8310 (with-current-buffer buffer
8311 (if (derived-mode-p 'org-mode)
8312 (if (and confirm
8313 (not (y-or-n-p "Archive this subtree or entry? ")))
8314 (error "Abort")
8315 (save-excursion
8316 (goto-char pos)
8317 (let ((org-agenda-buffer-name bufname-orig))
8318 (org-remove-subtree-entries-from-agenda))
8319 (org-back-to-heading t)
8320 (funcall cmd)))
8321 (error "Archiving works only in Org-mode files"))))))
8323 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8324 "Remove all lines in the agenda that correspond to a given subtree.
8325 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8326 If this information is not given, the function uses the tree at point."
8327 (let ((buf (or buf (current-buffer))) m p)
8328 (save-excursion
8329 (unless (and beg end)
8330 (org-back-to-heading t)
8331 (setq beg (point))
8332 (org-end-of-subtree t)
8333 (setq end (point)))
8334 (set-buffer (get-buffer org-agenda-buffer-name))
8335 (save-excursion
8336 (goto-char (point-max))
8337 (beginning-of-line 1)
8338 (while (not (bobp))
8339 (when (and (setq m (org-get-at-bol 'org-marker))
8340 (equal buf (marker-buffer m))
8341 (setq p (marker-position m))
8342 (>= p beg)
8343 (< p end))
8344 (let ((inhibit-read-only t))
8345 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8346 (beginning-of-line 0))))))
8348 (defun org-agenda-refile (&optional goto rfloc no-update)
8349 "Refile the item at point."
8350 (interactive "P")
8351 (if (equal goto '(16))
8352 (org-refile-goto-last-stored)
8353 (let* ((buffer-orig (buffer-name))
8354 (marker (or (org-get-at-bol 'org-hd-marker)
8355 (org-agenda-error)))
8356 (buffer (marker-buffer marker))
8357 (pos (marker-position marker))
8358 (rfloc (or rfloc
8359 (org-refile-get-location
8360 (if goto "Goto" "Refile to") buffer
8361 org-refile-allow-creating-parent-nodes))))
8362 (with-current-buffer buffer
8363 (save-excursion
8364 (save-restriction
8365 (widen)
8366 (goto-char marker)
8367 (let ((org-agenda-buffer-name buffer-orig))
8368 (org-remove-subtree-entries-from-agenda))
8369 (org-refile goto buffer rfloc)))))
8370 (unless no-update (org-agenda-redo))))
8372 (defun org-agenda-open-link (&optional arg)
8373 "Open the link(s) in the current entry, if any.
8374 This looks for a link in the displayed line in the agenda.
8375 It also looks at the text of the entry itself."
8376 (interactive "P")
8377 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8378 (org-get-at-bol 'org-marker)))
8379 (buffer (and marker (marker-buffer marker)))
8380 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8381 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8382 (lk0 (car lkall))
8383 (lk (if (stringp lk0) (list lk0) lk0))
8384 (lkend (cdr lkall))
8385 trg)
8386 (cond
8387 ((and buffer lk)
8388 (mapcar (lambda(l)
8389 (with-current-buffer buffer
8390 (setq trg (and (string-match org-bracket-link-regexp l)
8391 (match-string 1 l)))
8392 (if (or (not trg) (string-match org-any-link-re trg))
8393 (save-excursion
8394 (save-restriction
8395 (widen)
8396 (goto-char marker)
8397 (when (search-forward l nil lkend)
8398 (goto-char (match-beginning 0))
8399 (org-open-at-point))))
8400 ;; This is an internal link, widen the buffer
8401 (switch-to-buffer-other-window buffer)
8402 (widen)
8403 (goto-char marker)
8404 (when (search-forward l nil lkend)
8405 (goto-char (match-beginning 0))
8406 (org-open-at-point)))))
8407 lk))
8408 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8409 (save-excursion
8410 (beginning-of-line 1)
8411 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8412 (org-open-link-from-string (match-string 1)))
8413 (t (message "No link to open here")))))
8415 (defun org-agenda-copy-local-variable (var)
8416 "Get a variable from a referenced buffer and install it here."
8417 (let ((m (org-get-at-bol 'org-marker)))
8418 (when (and m (buffer-live-p (marker-buffer m)))
8419 (org-set-local var (with-current-buffer (marker-buffer m)
8420 (symbol-value var))))))
8422 (defun org-agenda-switch-to (&optional delete-other-windows)
8423 "Go to the Org-mode file which contains the item at point."
8424 (interactive)
8425 (if (and org-return-follows-link
8426 (not (org-get-at-bol 'org-marker))
8427 (org-in-regexp org-bracket-link-regexp))
8428 (org-open-link-from-string (match-string 0))
8429 (let* ((marker (or (org-get-at-bol 'org-marker)
8430 (org-agenda-error)))
8431 (buffer (marker-buffer marker))
8432 (pos (marker-position marker)))
8433 (org-pop-to-buffer-same-window buffer)
8434 (and delete-other-windows (delete-other-windows))
8435 (widen)
8436 (goto-char pos)
8437 (when (derived-mode-p 'org-mode)
8438 (org-show-context 'agenda)
8439 (save-excursion
8440 (and (outline-next-heading)
8441 (org-flag-heading nil))) ; show the next heading
8442 (when (outline-invisible-p)
8443 (show-entry)) ; display invisible text
8444 (run-hooks 'org-agenda-after-show-hook)))))
8446 (defun org-agenda-goto-mouse (ev)
8447 "Go to the Org-mode file which contains the item at the mouse click."
8448 (interactive "e")
8449 (mouse-set-point ev)
8450 (org-agenda-goto))
8452 (defun org-agenda-show (&optional full-entry)
8453 "Display the Org-mode file which contains the item at point.
8454 With prefix argument FULL-ENTRY, make the entire entry visible
8455 if it was hidden in the outline."
8456 (interactive "P")
8457 (let ((win (selected-window)))
8458 (if full-entry
8459 (let ((org-show-entry-below t))
8460 (org-agenda-goto t))
8461 (org-agenda-goto t))
8462 (select-window win)))
8464 (defvar org-agenda-show-window nil)
8465 (defun org-agenda-show-and-scroll-up (&optional arg)
8466 "Display the Org-mode file which contains the item at point.
8467 When called repeatedly, scroll the window that is displaying the buffer.
8468 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8469 `show-subtree' to display the item, so that drawers and logbooks stay
8470 folded."
8471 (interactive "P")
8472 (let ((win (selected-window)))
8473 (if (and (window-live-p org-agenda-show-window)
8474 (eq this-command last-command))
8475 (progn
8476 (select-window org-agenda-show-window)
8477 (ignore-errors (scroll-up)))
8478 (org-agenda-goto t)
8479 (if arg (org-show-entry) (show-subtree))
8480 (setq org-agenda-show-window (selected-window)))
8481 (select-window win)))
8483 (defun org-agenda-show-scroll-down ()
8484 "Scroll down the window showing the agenda."
8485 (interactive)
8486 (let ((win (selected-window)))
8487 (when (window-live-p org-agenda-show-window)
8488 (select-window org-agenda-show-window)
8489 (ignore-errors (scroll-down))
8490 (select-window win))))
8492 (defun org-agenda-show-1 (&optional more)
8493 "Display the Org-mode file which contains the item at point.
8494 The prefix arg selects the amount of information to display:
8496 0 hide the subtree
8497 1 just show the entry according to defaults.
8498 2 show the children view
8499 3 show the subtree view
8500 4 show the entire subtree and any LOGBOOK drawers
8501 5 show the entire subtree and any drawers
8502 With prefix argument FULL-ENTRY, make the entire entry visible
8503 if it was hidden in the outline."
8504 (interactive "p")
8505 (let ((win (selected-window)))
8506 (org-agenda-goto t)
8507 (org-recenter-heading 1)
8508 (cond
8509 ((= more 0)
8510 (hide-subtree)
8511 (save-excursion
8512 (org-back-to-heading)
8513 (run-hook-with-args 'org-cycle-hook 'folded))
8514 (message "Remote: FOLDED"))
8515 ((and (org-called-interactively-p 'any) (= more 1))
8516 (message "Remote: show with default settings"))
8517 ((= more 2)
8518 (show-entry)
8519 (show-children)
8520 (save-excursion
8521 (org-back-to-heading)
8522 (run-hook-with-args 'org-cycle-hook 'children))
8523 (message "Remote: CHILDREN"))
8524 ((= more 3)
8525 (show-subtree)
8526 (save-excursion
8527 (org-back-to-heading)
8528 (run-hook-with-args 'org-cycle-hook 'subtree))
8529 (message "Remote: SUBTREE"))
8530 ((= more 4)
8531 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8532 (org-drawer-regexp
8533 (concat "^[ \t]*:\\("
8534 (mapconcat 'regexp-quote org-drawers "\\|")
8535 "\\):[ \t]*$")))
8536 (show-subtree)
8537 (save-excursion
8538 (org-back-to-heading)
8539 (org-cycle-hide-drawers 'subtree)))
8540 (message "Remote: SUBTREE AND LOGBOOK"))
8541 ((> more 4)
8542 (show-subtree)
8543 (message "Remote: SUBTREE AND ALL DRAWERS")))
8544 (select-window win)))
8546 (defun org-recenter-heading (n)
8547 (save-excursion
8548 (org-back-to-heading)
8549 (recenter n)))
8551 (defvar org-agenda-cycle-counter nil)
8552 (defun org-agenda-cycle-show (&optional n)
8553 "Show the current entry in another window, with default settings.
8554 Default settings are taken from `org-show-hierarchy-above' and siblings.
8555 When use repeatedly in immediate succession, the remote entry will cycle
8556 through visibility
8558 children -> subtree -> folded
8560 When called with a numeric prefix arg, that arg will be passed through to
8561 `org-agenda-show-1'. For the interpretation of that argument, see the
8562 docstring of `org-agenda-show-1'."
8563 (interactive "P")
8564 (if (integerp n)
8565 (setq org-agenda-cycle-counter n)
8566 (if (not (eq last-command this-command))
8567 (setq org-agenda-cycle-counter 1)
8568 (if (equal org-agenda-cycle-counter 0)
8569 (setq org-agenda-cycle-counter 2)
8570 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8571 (if (> org-agenda-cycle-counter 3)
8572 (setq org-agenda-cycle-counter 0)))))
8573 (org-agenda-show-1 org-agenda-cycle-counter))
8575 (defun org-agenda-recenter (arg)
8576 "Display the Org-mode file which contains the item at point and recenter."
8577 (interactive "P")
8578 (let ((win (selected-window)))
8579 (org-agenda-goto t)
8580 (recenter arg)
8581 (select-window win)))
8583 (defun org-agenda-show-mouse (ev)
8584 "Display the Org-mode file which contains the item at the mouse click."
8585 (interactive "e")
8586 (mouse-set-point ev)
8587 (org-agenda-show))
8589 (defun org-agenda-check-no-diary ()
8590 "Check if the entry is a diary link and abort if yes."
8591 (if (org-get-at-bol 'org-agenda-diary-link)
8592 (org-agenda-error)))
8594 (defun org-agenda-error ()
8595 (error "Command not allowed in this line"))
8597 (defun org-agenda-tree-to-indirect-buffer (arg)
8598 "Show the subtree corresponding to the current entry in an indirect buffer.
8599 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8601 With a numerical prefix ARG, go up to this level and then take that tree.
8602 With a negative numeric ARG, go up by this number of levels.
8603 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8604 use the dedicated frame)."
8605 (interactive "P")
8606 (if current-prefix-arg
8607 (org-agenda-do-tree-to-indirect-buffer arg)
8608 (let ((agenda-buffer (buffer-name))
8609 (agenda-window (selected-window))
8610 (indirect-window
8611 (and org-last-indirect-buffer
8612 (get-buffer-window org-last-indirect-buffer))))
8613 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8614 (unless (or (eq org-indirect-buffer-display 'new-frame)
8615 (eq org-indirect-buffer-display 'dedicated-frame))
8616 (unwind-protect
8617 (unless (and indirect-window (window-live-p indirect-window))
8618 (setq indirect-window (split-window agenda-window)))
8619 (and indirect-window (select-window indirect-window))
8620 (switch-to-buffer org-last-indirect-buffer :norecord)
8621 (fit-window-to-buffer indirect-window)))
8622 (select-window (get-buffer-window agenda-buffer)))))
8624 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8625 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8626 (org-agenda-check-no-diary)
8627 (let* ((marker (or (org-get-at-bol 'org-marker)
8628 (org-agenda-error)))
8629 (buffer (marker-buffer marker))
8630 (pos (marker-position marker)))
8631 (with-current-buffer buffer
8632 (save-excursion
8633 (goto-char pos)
8634 (funcall 'org-tree-to-indirect-buffer arg)))))
8636 (defvar org-last-heading-marker (make-marker)
8637 "Marker pointing to the headline that last changed its TODO state
8638 by a remote command from the agenda.")
8640 (defun org-agenda-todo-nextset ()
8641 "Switch TODO entry to next sequence."
8642 (interactive)
8643 (org-agenda-todo 'nextset))
8645 (defun org-agenda-todo-previousset ()
8646 "Switch TODO entry to previous sequence."
8647 (interactive)
8648 (org-agenda-todo 'previousset))
8650 (defun org-agenda-todo (&optional arg)
8651 "Cycle TODO state of line at point, also in Org-mode file.
8652 This changes the line at point, all other lines in the agenda referring to
8653 the same tree node, and the headline of the tree node in the Org-mode file."
8654 (interactive "P")
8655 (org-agenda-check-no-diary)
8656 (let* ((col (current-column))
8657 (marker (or (org-get-at-bol 'org-marker)
8658 (org-agenda-error)))
8659 (buffer (marker-buffer marker))
8660 (pos (marker-position marker))
8661 (hdmarker (org-get-at-bol 'org-hd-marker))
8662 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8663 (inhibit-read-only t)
8664 org-agenda-headline-snapshot-before-repeat newhead just-one)
8665 (org-with-remote-undo buffer
8666 (with-current-buffer buffer
8667 (widen)
8668 (goto-char pos)
8669 (org-show-context 'agenda)
8670 (save-excursion
8671 (and (outline-next-heading)
8672 (org-flag-heading nil))) ; show the next heading
8673 (let ((current-prefix-arg arg))
8674 (call-interactively 'org-todo))
8675 (and (bolp) (forward-char 1))
8676 (setq newhead (org-get-heading))
8677 (when (and (org-bound-and-true-p
8678 org-agenda-headline-snapshot-before-repeat)
8679 (not (equal org-agenda-headline-snapshot-before-repeat
8680 newhead))
8681 todayp)
8682 (setq newhead org-agenda-headline-snapshot-before-repeat
8683 just-one t))
8684 (save-excursion
8685 (org-back-to-heading)
8686 (move-marker org-last-heading-marker (point))))
8687 (beginning-of-line 1)
8688 (save-excursion
8689 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8690 (org-move-to-column col))))
8692 (defun org-agenda-add-note (&optional arg)
8693 "Add a time-stamped note to the entry at point."
8694 (interactive "P")
8695 (org-agenda-check-no-diary)
8696 (let* ((marker (or (org-get-at-bol 'org-marker)
8697 (org-agenda-error)))
8698 (buffer (marker-buffer marker))
8699 (pos (marker-position marker))
8700 (hdmarker (org-get-at-bol 'org-hd-marker))
8701 (inhibit-read-only t))
8702 (with-current-buffer buffer
8703 (widen)
8704 (goto-char pos)
8705 (org-show-context 'agenda)
8706 (save-excursion
8707 (and (outline-next-heading)
8708 (org-flag-heading nil))) ; show the next heading
8709 (org-add-note))))
8711 (defun org-agenda-change-all-lines (newhead hdmarker
8712 &optional fixface just-this)
8713 "Change all lines in the agenda buffer which match HDMARKER.
8714 The new content of the line will be NEWHEAD (as modified by
8715 `org-agenda-format-item'). HDMARKER is checked with
8716 `equal' against all `org-hd-marker' text properties in the file.
8717 If FIXFACE is non-nil, the face of each item is modified according to
8718 the new TODO state.
8719 If JUST-THIS is non-nil, change just the current line, not all.
8720 If FORCE-TAGS is non nil, the car of it returns the new tags."
8721 (let* ((inhibit-read-only t)
8722 (line (org-current-line))
8723 (org-agenda-buffer (current-buffer))
8724 (thetags (with-current-buffer (marker-buffer hdmarker)
8725 (save-excursion (save-restriction (widen)
8726 (goto-char hdmarker)
8727 (org-get-tags-at)))))
8728 props m pl undone-face done-face finish new dotime level cat tags)
8729 (save-excursion
8730 (goto-char (point-max))
8731 (beginning-of-line 1)
8732 (while (not finish)
8733 (setq finish (bobp))
8734 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8735 (or (not just-this) (= (org-current-line) line))
8736 (equal m hdmarker))
8737 (setq props (text-properties-at (point))
8738 dotime (org-get-at-bol 'dotime)
8739 cat (org-get-at-bol 'org-category)
8740 level (org-get-at-bol 'level)
8741 tags thetags
8743 (let ((org-prefix-format-compiled
8744 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8745 org-prefix-format-compiled))
8746 (extra (org-get-at-bol 'extra)))
8747 (with-current-buffer (marker-buffer hdmarker)
8748 (save-excursion
8749 (save-restriction
8750 (widen)
8751 (org-agenda-format-item extra newhead level cat tags dotime)))))
8752 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8753 undone-face (org-get-at-bol 'undone-face)
8754 done-face (org-get-at-bol 'done-face))
8755 (beginning-of-line 1)
8756 (cond
8757 ((equal new "")
8758 (and (looking-at ".*\n?") (replace-match "")))
8759 ((looking-at ".*")
8760 (replace-match new t t)
8761 (beginning-of-line 1)
8762 (add-text-properties (point-at-bol) (point-at-eol) props)
8763 (when fixface
8764 (add-text-properties
8765 (point-at-bol) (point-at-eol)
8766 (list 'face
8767 (if org-last-todo-state-is-todo
8768 undone-face done-face))))
8769 (org-agenda-highlight-todo 'line)
8770 (beginning-of-line 1))
8771 (t (error "Line update did not work")))
8772 (save-restriction
8773 (narrow-to-region (point-at-bol) (point-at-eol))
8774 (org-agenda-finalize)))
8775 (beginning-of-line 0)))))
8777 (defun org-agenda-align-tags (&optional line)
8778 "Align all tags in agenda items to `org-agenda-tags-column'."
8779 (let ((inhibit-read-only t) l c)
8780 (save-excursion
8781 (goto-char (if line (point-at-bol) (point-min)))
8782 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8783 (if line (point-at-eol) nil) t)
8784 (add-text-properties
8785 (match-beginning 2) (match-end 2)
8786 (list 'face (delq nil (let ((prop (get-text-property
8787 (match-beginning 2) 'face)))
8788 (or (listp prop) (setq prop (list prop)))
8789 (if (memq 'org-tag prop)
8790 prop
8791 (cons 'org-tag prop))))))
8792 (setq l (- (match-end 2) (match-beginning 2))
8793 c (if (< org-agenda-tags-column 0)
8794 (- (abs org-agenda-tags-column) l)
8795 org-agenda-tags-column))
8796 (delete-region (match-beginning 1) (match-end 1))
8797 (goto-char (match-beginning 1))
8798 (insert (org-add-props
8799 (make-string (max 1 (- c (current-column))) ?\ )
8800 (plist-put (copy-sequence (text-properties-at (point)))
8801 'face nil))))
8802 (goto-char (point-min))
8803 (org-font-lock-add-tag-faces (point-max)))))
8805 (defun org-agenda-priority-up ()
8806 "Increase the priority of line at point, also in Org-mode file."
8807 (interactive)
8808 (org-agenda-priority 'up))
8810 (defun org-agenda-priority-down ()
8811 "Decrease the priority of line at point, also in Org-mode file."
8812 (interactive)
8813 (org-agenda-priority 'down))
8815 (defun org-agenda-priority (&optional force-direction)
8816 "Set the priority of line at point, also in Org-mode file.
8817 This changes the line at point, all other lines in the agenda referring to
8818 the same tree node, and the headline of the tree node in the Org-mode file.
8819 Called with a universal prefix arg, show the priority instead of setting it."
8820 (interactive "P")
8821 (if (equal force-direction '(4))
8822 (org-show-priority)
8823 (unless org-enable-priority-commands
8824 (error "Priority commands are disabled"))
8825 (org-agenda-check-no-diary)
8826 (let* ((marker (or (org-get-at-bol 'org-marker)
8827 (org-agenda-error)))
8828 (hdmarker (org-get-at-bol 'org-hd-marker))
8829 (buffer (marker-buffer hdmarker))
8830 (pos (marker-position hdmarker))
8831 (inhibit-read-only t)
8832 newhead)
8833 (org-with-remote-undo buffer
8834 (with-current-buffer buffer
8835 (widen)
8836 (goto-char pos)
8837 (org-show-context 'agenda)
8838 (save-excursion
8839 (and (outline-next-heading)
8840 (org-flag-heading nil))) ; show the next heading
8841 (funcall 'org-priority force-direction)
8842 (end-of-line 1)
8843 (setq newhead (org-get-heading)))
8844 (org-agenda-change-all-lines newhead hdmarker)
8845 (beginning-of-line 1)))))
8847 ;; FIXME: should fix the tags property of the agenda line.
8848 (defun org-agenda-set-tags (&optional tag onoff)
8849 "Set tags for the current headline."
8850 (interactive)
8851 (org-agenda-check-no-diary)
8852 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8853 (call-interactively 'org-change-tag-in-region)
8854 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8855 (org-agenda-error)))
8856 (buffer (marker-buffer hdmarker))
8857 (pos (marker-position hdmarker))
8858 (inhibit-read-only t)
8859 newhead)
8860 (org-with-remote-undo buffer
8861 (with-current-buffer buffer
8862 (widen)
8863 (goto-char pos)
8864 (save-excursion
8865 (org-show-context 'agenda))
8866 (save-excursion
8867 (and (outline-next-heading)
8868 (org-flag-heading nil))) ; show the next heading
8869 (goto-char pos)
8870 (if tag
8871 (org-toggle-tag tag onoff)
8872 (call-interactively 'org-set-tags))
8873 (end-of-line 1)
8874 (setq newhead (org-get-heading)))
8875 (org-agenda-change-all-lines newhead hdmarker)
8876 (beginning-of-line 1)))))
8878 (defun org-agenda-set-property ()
8879 "Set a property for the current headline."
8880 (interactive)
8881 (org-agenda-check-no-diary)
8882 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8883 (org-agenda-error)))
8884 (buffer (marker-buffer hdmarker))
8885 (pos (marker-position hdmarker))
8886 (inhibit-read-only t)
8887 newhead)
8888 (org-with-remote-undo buffer
8889 (with-current-buffer buffer
8890 (widen)
8891 (goto-char pos)
8892 (save-excursion
8893 (org-show-context 'agenda))
8894 (save-excursion
8895 (and (outline-next-heading)
8896 (org-flag-heading nil))) ; show the next heading
8897 (goto-char pos)
8898 (call-interactively 'org-set-property)))))
8900 (defun org-agenda-set-effort ()
8901 "Set the effort property for the current headline."
8902 (interactive)
8903 (org-agenda-check-no-diary)
8904 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8905 (org-agenda-error)))
8906 (buffer (marker-buffer hdmarker))
8907 (pos (marker-position hdmarker))
8908 (inhibit-read-only t)
8909 newhead)
8910 (org-with-remote-undo buffer
8911 (with-current-buffer buffer
8912 (widen)
8913 (goto-char pos)
8914 (save-excursion
8915 (org-show-context 'agenda))
8916 (save-excursion
8917 (and (outline-next-heading)
8918 (org-flag-heading nil))) ; show the next heading
8919 (goto-char pos)
8920 (call-interactively 'org-set-effort)
8921 (end-of-line 1)
8922 (setq newhead (org-get-heading)))
8923 (org-agenda-change-all-lines newhead hdmarker))))
8925 (defun org-agenda-toggle-archive-tag ()
8926 "Toggle the archive tag for the current entry."
8927 (interactive)
8928 (org-agenda-check-no-diary)
8929 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8930 (org-agenda-error)))
8931 (buffer (marker-buffer hdmarker))
8932 (pos (marker-position hdmarker))
8933 (inhibit-read-only t)
8934 newhead)
8935 (org-with-remote-undo buffer
8936 (with-current-buffer buffer
8937 (widen)
8938 (goto-char pos)
8939 (org-show-context 'agenda)
8940 (save-excursion
8941 (and (outline-next-heading)
8942 (org-flag-heading nil))) ; show the next heading
8943 (call-interactively 'org-toggle-archive-tag)
8944 (end-of-line 1)
8945 (setq newhead (org-get-heading)))
8946 (org-agenda-change-all-lines newhead hdmarker)
8947 (beginning-of-line 1))))
8949 (defun org-agenda-do-date-later (arg)
8950 (interactive "P")
8951 (cond
8952 ((or (equal arg '(16))
8953 (memq last-command
8954 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8955 (setq this-command 'org-agenda-date-later-minutes)
8956 (org-agenda-date-later-minutes 1))
8957 ((or (equal arg '(4))
8958 (memq last-command
8959 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8960 (setq this-command 'org-agenda-date-later-hours)
8961 (org-agenda-date-later-hours 1))
8963 (org-agenda-date-later (prefix-numeric-value arg)))))
8965 (defun org-agenda-do-date-earlier (arg)
8966 (interactive "P")
8967 (cond
8968 ((or (equal arg '(16))
8969 (memq last-command
8970 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8971 (setq this-command 'org-agenda-date-earlier-minutes)
8972 (org-agenda-date-earlier-minutes 1))
8973 ((or (equal arg '(4))
8974 (memq last-command
8975 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8976 (setq this-command 'org-agenda-date-earlier-hours)
8977 (org-agenda-date-earlier-hours 1))
8979 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8981 (defun org-agenda-date-later (arg &optional what)
8982 "Change the date of this item to ARG day(s) later."
8983 (interactive "p")
8984 (org-agenda-check-type t 'agenda 'timeline)
8985 (org-agenda-check-no-diary)
8986 (let* ((marker (or (org-get-at-bol 'org-marker)
8987 (org-agenda-error)))
8988 (buffer (marker-buffer marker))
8989 (pos (marker-position marker))
8990 cdate today)
8991 (org-with-remote-undo buffer
8992 (with-current-buffer buffer
8993 (widen)
8994 (goto-char pos)
8995 (if (not (org-at-timestamp-p))
8996 (error "Cannot find time stamp"))
8997 (when (and org-agenda-move-date-from-past-immediately-to-today
8998 (equal arg 1)
8999 (or (not what) (eq what 'day))
9000 (not (save-match-data (org-at-date-range-p))))
9001 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9002 cdate (calendar-absolute-from-gregorian
9003 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9004 today (org-today))
9005 (if (> today cdate)
9006 ;; immediately shift to today
9007 (setq arg (- today cdate))))
9008 (org-timestamp-change arg (or what 'day))
9009 (when (and (org-at-date-range-p)
9010 (re-search-backward org-tr-regexp-both (point-at-bol)))
9011 (let ((end org-last-changed-timestamp))
9012 (org-timestamp-change arg (or what 'day))
9013 (setq org-last-changed-timestamp
9014 (concat org-last-changed-timestamp "--" end)))))
9015 (org-agenda-show-new-time marker org-last-changed-timestamp))
9016 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9018 (defun org-agenda-date-earlier (arg &optional what)
9019 "Change the date of this item to ARG day(s) earlier."
9020 (interactive "p")
9021 (org-agenda-date-later (- arg) what))
9023 (defun org-agenda-date-later-minutes (arg)
9024 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9025 (interactive "p")
9026 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9027 (org-agenda-date-later arg 'minute))
9029 (defun org-agenda-date-earlier-minutes (arg)
9030 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9031 (interactive "p")
9032 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9033 (org-agenda-date-earlier arg 'minute))
9035 (defun org-agenda-date-later-hours (arg)
9036 "Change the time of this item, in hour steps."
9037 (interactive "p")
9038 (org-agenda-date-later arg 'hour))
9040 (defun org-agenda-date-earlier-hours (arg)
9041 "Change the time of this item, in hour steps."
9042 (interactive "p")
9043 (org-agenda-date-earlier arg 'hour))
9045 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9046 "Show new date stamp via text properties."
9047 ;; We use text properties to make this undoable
9048 (let ((inhibit-read-only t))
9049 (setq stamp (concat prefix " => " stamp " "))
9050 (save-excursion
9051 (goto-char (point-max))
9052 (while (not (bobp))
9053 (when (equal marker (org-get-at-bol 'org-marker))
9054 (org-move-to-column (- (window-width) (length stamp)) t)
9055 (org-agenda-fix-tags-filter-overlays-at (point))
9056 (if (featurep 'xemacs)
9057 ;; Use `duplicable' property to trigger undo recording
9058 (let ((ex (make-extent nil nil))
9059 (gl (make-glyph stamp)))
9060 (set-glyph-face gl 'secondary-selection)
9061 (set-extent-properties
9062 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9063 (insert-extent ex (1- (point)) (point-at-eol)))
9064 (add-text-properties
9065 (1- (point)) (point-at-eol)
9066 (list 'display (org-add-props stamp nil
9067 'face 'secondary-selection))))
9068 (beginning-of-line 1))
9069 (beginning-of-line 0)))))
9071 (defun org-agenda-date-prompt (arg)
9072 "Change the date of this item. Date is prompted for, with default today.
9073 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9074 be used to request time specification in the time stamp."
9075 (interactive "P")
9076 (org-agenda-check-type t 'agenda 'timeline)
9077 (org-agenda-check-no-diary)
9078 (let* ((marker (or (org-get-at-bol 'org-marker)
9079 (org-agenda-error)))
9080 (buffer (marker-buffer marker))
9081 (pos (marker-position marker)))
9082 (org-with-remote-undo buffer
9083 (with-current-buffer buffer
9084 (widen)
9085 (goto-char pos)
9086 (if (not (org-at-timestamp-p t))
9087 (error "Cannot find time stamp"))
9088 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9089 (org-agenda-show-new-time marker org-last-changed-timestamp))
9090 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9092 (defun org-agenda-schedule (arg &optional time)
9093 "Schedule the item at point.
9094 ARG is passed through to `org-schedule'."
9095 (interactive "P")
9096 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9097 (org-agenda-check-no-diary)
9098 (let* ((marker (or (org-get-at-bol 'org-marker)
9099 (org-agenda-error)))
9100 (type (marker-insertion-type marker))
9101 (buffer (marker-buffer marker))
9102 (pos (marker-position marker))
9103 (org-insert-labeled-timestamps-at-point nil)
9105 (set-marker-insertion-type marker t)
9106 (org-with-remote-undo buffer
9107 (with-current-buffer buffer
9108 (widen)
9109 (goto-char pos)
9110 (setq ts (org-schedule arg time)))
9111 (org-agenda-show-new-time marker ts " S"))
9112 (message "%s" ts)))
9114 (defun org-agenda-deadline (arg &optional time)
9115 "Schedule the item at point.
9116 ARG is passed through to `org-deadline'."
9117 (interactive "P")
9118 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9119 (org-agenda-check-no-diary)
9120 (let* ((marker (or (org-get-at-bol 'org-marker)
9121 (org-agenda-error)))
9122 (buffer (marker-buffer marker))
9123 (pos (marker-position marker))
9124 (org-insert-labeled-timestamps-at-point nil)
9126 (org-with-remote-undo buffer
9127 (with-current-buffer buffer
9128 (widen)
9129 (goto-char pos)
9130 (setq ts (org-deadline arg time)))
9131 (org-agenda-show-new-time marker ts " D"))
9132 (message "%s" ts)))
9134 (defun org-agenda-clock-in (&optional arg)
9135 "Start the clock on the currently selected item."
9136 (interactive "P")
9137 (org-agenda-check-no-diary)
9138 (if (equal arg '(4))
9139 (org-clock-in arg)
9140 (let* ((marker (or (org-get-at-bol 'org-marker)
9141 (org-agenda-error)))
9142 (hdmarker (or (org-get-at-bol 'org-hd-marker)
9143 marker))
9144 (pos (marker-position marker))
9145 newhead)
9146 (org-with-remote-undo (marker-buffer marker)
9147 (with-current-buffer (marker-buffer marker)
9148 (widen)
9149 (goto-char pos)
9150 (org-show-context 'agenda)
9151 (org-show-entry)
9152 (org-cycle-hide-drawers 'children)
9153 (org-clock-in arg)
9154 (setq newhead (org-get-heading)))
9155 (org-agenda-change-all-lines newhead hdmarker)))))
9157 (defun org-agenda-clock-out ()
9158 "Stop the currently running clock."
9159 (interactive)
9160 (unless (marker-buffer org-clock-marker)
9161 (error "No running clock"))
9162 (let ((marker (make-marker)) newhead)
9163 (org-with-remote-undo (marker-buffer org-clock-marker)
9164 (with-current-buffer (marker-buffer org-clock-marker)
9165 (save-excursion
9166 (save-restriction
9167 (widen)
9168 (goto-char org-clock-marker)
9169 (org-back-to-heading t)
9170 (move-marker marker (point))
9171 (org-clock-out)
9172 (setq newhead (org-get-heading))))))
9173 (org-agenda-change-all-lines newhead marker)
9174 (move-marker marker nil)))
9176 (defun org-agenda-clock-cancel (&optional arg)
9177 "Cancel the currently running clock."
9178 (interactive "P")
9179 (unless (marker-buffer org-clock-marker)
9180 (error "No running clock"))
9181 (org-with-remote-undo (marker-buffer org-clock-marker)
9182 (org-clock-cancel)))
9184 (defun org-agenda-clock-goto ()
9185 "Jump to the currently clocked in task within the agenda.
9186 If the currently clocked in task is not listed in the agenda
9187 buffer, display it in another window."
9188 (interactive)
9189 (let (pos)
9190 (mapc (lambda (o)
9191 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9192 (setq pos (overlay-start o))))
9193 (overlays-in (point-min) (point-max)))
9194 (cond (pos (goto-char pos))
9195 ;; If the currently clocked entry is not in the agenda
9196 ;; buffer, we visit it in another window:
9197 (org-clock-current-task
9198 (org-switch-to-buffer-other-window (org-clock-goto)))
9199 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9201 (defun org-agenda-diary-entry-in-org-file ()
9202 "Make a diary entry in the file `org-agenda-diary-file'."
9203 (let (d1 d2 char (text "") dp1 dp2)
9204 (if (equal (buffer-name) "*Calendar*")
9205 (setq d1 (calendar-cursor-to-date t)
9206 d2 (car calendar-mark-ring))
9207 (setq dp1 (get-text-property (point-at-bol) 'day))
9208 (unless dp1 (error "No date defined in current line"))
9209 (setq d1 (calendar-gregorian-from-absolute dp1)
9210 d2 (and (ignore-errors (mark))
9211 (save-excursion
9212 (goto-char (mark))
9213 (setq dp2 (get-text-property (point-at-bol) 'day)))
9214 (calendar-gregorian-from-absolute dp2))))
9215 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9216 (setq char (read-char-exclusive))
9217 (cond
9218 ((equal char ?d)
9219 (setq text (read-string "Day entry: "))
9220 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9221 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9222 ((equal char ?a)
9223 (setq d1 (list (car d1) (nth 1 d1)
9224 (read-number (format "Reference year [%d]: " (nth 2 d1))
9225 (nth 2 d1))))
9226 (setq text (read-string "Anniversary (use %d to show years): "))
9227 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9228 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9229 ((equal char ?b)
9230 (setq text (read-string "Block entry: "))
9231 (unless (and d1 d2 (not (equal d1 d2)))
9232 (error "No block of days selected"))
9233 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9234 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9235 ((equal char ?j)
9236 (org-switch-to-buffer-other-window
9237 (find-file-noselect org-agenda-diary-file))
9238 (require 'org-datetree)
9239 (org-datetree-find-date-create d1)
9240 (org-reveal t))
9241 (t (error "Invalid selection character `%c'" char)))))
9243 (defcustom org-agenda-insert-diary-strategy 'date-tree
9244 "Where in `org-agenda-diary-file' should new entries be added?
9245 Valid values:
9247 date-tree in the date tree, as child of the date
9248 top-level as top-level entries at the end of the file."
9249 :group 'org-agenda
9250 :type '(choice
9251 (const :tag "in a date tree" date-tree)
9252 (const :tag "as top level at end of file" top-level)))
9254 (defcustom org-agenda-insert-diary-extract-time nil
9255 "Non-nil means extract any time specification from the diary entry."
9256 :group 'org-agenda
9257 :version "24.1"
9258 :type 'boolean)
9260 (defcustom org-agenda-bulk-mark-char ">"
9261 "A single-character string to be used as the bulk mark."
9262 :group 'org-agenda
9263 :version "24.1"
9264 :type 'string)
9266 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9267 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9268 If TEXT is not empty, it will become the headline of the new entry, and
9269 the resulting entry will not be shown. When TEXT is empty, switch to
9270 `org-agenda-diary-file' and let the user finish the entry there."
9271 (let ((cw (current-window-configuration)))
9272 (org-switch-to-buffer-other-window
9273 (find-file-noselect org-agenda-diary-file))
9274 (widen)
9275 (goto-char (point-min))
9276 (cond
9277 ((eq type 'anniversary)
9278 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9279 (progn
9280 (or (org-at-heading-p t)
9281 (progn
9282 (outline-next-heading)
9283 (insert "* Anniversaries\n\n")
9284 (beginning-of-line -1)))))
9285 (outline-next-heading)
9286 (org-back-over-empty-lines)
9287 (backward-char 1)
9288 (insert "\n")
9289 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9290 (nth 2 d1) (car d1) (nth 1 d1) text)))
9291 ((eq type 'day)
9292 (let ((org-prefix-has-time t)
9293 (org-agenda-time-leading-zero t)
9294 fmt time time2)
9295 (if org-agenda-insert-diary-extract-time
9296 ;; Use org-agenda-format-item to parse text for a time-range and
9297 ;; remove it. FIXME: This is a hack, we should refactor
9298 ;; that function to make time extraction available separately
9299 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9300 time (get-text-property 0 'time fmt)
9301 time2 (if (> (length time) 0)
9302 ;; split-string removes trailing ...... if
9303 ;; no end time given. First space
9304 ;; separates time from date.
9305 (concat " " (car (split-string time "\\.")))
9306 nil)
9307 text (get-text-property 0 'txt fmt)))
9308 (if (eq org-agenda-insert-diary-strategy 'top-level)
9309 (org-agenda-insert-diary-as-top-level text)
9310 (require 'org-datetree)
9311 (org-datetree-find-date-create d1)
9312 (org-agenda-insert-diary-make-new-entry text))
9313 (org-insert-time-stamp (org-time-from-absolute
9314 (calendar-absolute-from-gregorian d1))
9315 nil nil nil nil time2))
9316 (end-of-line 0))
9317 ((eq type 'block)
9318 (if (> (calendar-absolute-from-gregorian d1)
9319 (calendar-absolute-from-gregorian d2))
9320 (setq d1 (prog1 d2 (setq d2 d1))))
9321 (if (eq org-agenda-insert-diary-strategy 'top-level)
9322 (org-agenda-insert-diary-as-top-level text)
9323 (require 'org-datetree)
9324 (org-datetree-find-date-create d1)
9325 (org-agenda-insert-diary-make-new-entry text))
9326 (org-insert-time-stamp (org-time-from-absolute
9327 (calendar-absolute-from-gregorian d1)))
9328 (insert "--")
9329 (org-insert-time-stamp (org-time-from-absolute
9330 (calendar-absolute-from-gregorian d2)))
9331 (end-of-line 0)))
9332 (if (string-match "\\S-" text)
9333 (progn
9334 (set-window-configuration cw)
9335 (message "%s entry added to %s"
9336 (capitalize (symbol-name type))
9337 (abbreviate-file-name org-agenda-diary-file)))
9338 (org-reveal t)
9339 (message "Please finish entry here"))))
9341 (defun org-agenda-insert-diary-as-top-level (text)
9342 "Make new entry as a top-level entry at the end of the file.
9343 Add TEXT as headline, and position the cursor in the second line so that
9344 a timestamp can be added there."
9345 (widen)
9346 (goto-char (point-max))
9347 (or (bolp) (insert "\n"))
9348 (insert "* " text "\n")
9349 (if org-adapt-indentation (org-indent-to-column 2)))
9351 (defun org-agenda-insert-diary-make-new-entry (text)
9352 "Make new entry as last child of current entry.
9353 Add TEXT as headline, and position the cursor in the second line so that
9354 a timestamp can be added there."
9355 (let ((org-show-following-heading t)
9356 (org-show-siblings t)
9357 (org-show-hierarchy-above t)
9358 (org-show-entry-below t)
9359 col)
9360 (outline-next-heading)
9361 (org-back-over-empty-lines)
9362 (or (looking-at "[ \t]*$")
9363 (progn (insert "\n") (backward-char 1)))
9364 (org-insert-heading nil t)
9365 (org-do-demote)
9366 (setq col (current-column))
9367 (insert text "\n")
9368 (if org-adapt-indentation (org-indent-to-column col))
9369 (let ((org-show-following-heading t)
9370 (org-show-siblings t)
9371 (org-show-hierarchy-above t)
9372 (org-show-entry-below t))
9373 (org-show-context))))
9375 (defun org-agenda-diary-entry ()
9376 "Make a diary entry, like the `i' command from the calendar.
9377 All the standard commands work: block, weekly etc.
9378 When `org-agenda-diary-file' points to a file,
9379 `org-agenda-diary-entry-in-org-file' is called instead to create
9380 entries in that Org-mode file."
9381 (interactive)
9382 (if (not (eq org-agenda-diary-file 'diary-file))
9383 (org-agenda-diary-entry-in-org-file)
9384 (require 'diary-lib)
9385 (let* ((char (progn
9386 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9387 (read-char-exclusive)))
9388 (cmd (cdr (assoc char
9389 '((?d . insert-diary-entry)
9390 (?w . insert-weekly-diary-entry)
9391 (?m . insert-monthly-diary-entry)
9392 (?y . insert-yearly-diary-entry)
9393 (?a . insert-anniversary-diary-entry)
9394 (?b . insert-block-diary-entry)
9395 (?c . insert-cyclic-diary-entry)))))
9396 (oldf (symbol-function 'calendar-cursor-to-date))
9397 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9398 (point (point))
9399 (mark (or (mark t) (point))))
9400 (unless cmd
9401 (error "No command associated with <%c>" char))
9402 (unless (and (get-text-property point 'day)
9403 (or (not (equal ?b char))
9404 (get-text-property mark 'day)))
9405 (error "Don't know which date to use for diary entry"))
9406 ;; We implement this by hacking the `calendar-cursor-to-date' function
9407 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9408 (let ((calendar-mark-ring
9409 (list (calendar-gregorian-from-absolute
9410 (or (get-text-property mark 'day)
9411 (get-text-property point 'day))))))
9412 (unwind-protect
9413 (progn
9414 (fset 'calendar-cursor-to-date
9415 (lambda (&optional error dummy)
9416 (calendar-gregorian-from-absolute
9417 (get-text-property point 'day))))
9418 (call-interactively cmd))
9419 (fset 'calendar-cursor-to-date oldf))))))
9421 (defun org-agenda-execute-calendar-command (cmd)
9422 "Execute a calendar command from the agenda with date from cursor."
9423 (org-agenda-check-type t 'agenda 'timeline)
9424 (require 'diary-lib)
9425 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9426 (error "Don't know which date to use for the calendar command"))
9427 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9428 (point (point))
9429 (date (calendar-gregorian-from-absolute
9430 (get-text-property point 'day)))
9431 ;; the following 2 vars are needed in the calendar
9432 (displayed-month (car date))
9433 (displayed-year (nth 2 date)))
9434 (unwind-protect
9435 (progn
9436 (fset 'calendar-cursor-to-date
9437 (lambda (&optional error dummy)
9438 (calendar-gregorian-from-absolute
9439 (get-text-property point 'day))))
9440 (call-interactively cmd))
9441 (fset 'calendar-cursor-to-date oldf))))
9443 (defun org-agenda-phases-of-moon ()
9444 "Display the phases of the moon for the 3 months around the cursor date."
9445 (interactive)
9446 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9448 (defun org-agenda-holidays ()
9449 "Display the holidays for the 3 months around the cursor date."
9450 (interactive)
9451 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9453 (defvar calendar-longitude) ; defined in calendar.el
9454 (defvar calendar-latitude) ; defined in calendar.el
9455 (defvar calendar-location-name) ; defined in calendar.el
9457 (defun org-agenda-sunrise-sunset (arg)
9458 "Display sunrise and sunset for the cursor date.
9459 Latitude and longitude can be specified with the variables
9460 `calendar-latitude' and `calendar-longitude'. When called with prefix
9461 argument, latitude and longitude will be prompted for."
9462 (interactive "P")
9463 (require 'solar)
9464 (let ((calendar-longitude (if arg nil calendar-longitude))
9465 (calendar-latitude (if arg nil calendar-latitude))
9466 (calendar-location-name
9467 (if arg "the given coordinates" calendar-location-name)))
9468 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9470 (defun org-agenda-goto-calendar ()
9471 "Open the Emacs calendar with the date at the cursor."
9472 (interactive)
9473 (org-agenda-check-type t 'agenda 'timeline)
9474 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9475 (error "Don't know which date to open in calendar")))
9476 (date (calendar-gregorian-from-absolute day))
9477 (calendar-move-hook nil)
9478 (calendar-view-holidays-initially-flag nil)
9479 (calendar-view-diary-initially-flag nil))
9480 (calendar)
9481 (calendar-goto-date date)))
9483 ;;;###autoload
9484 (defun org-calendar-goto-agenda ()
9485 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9486 This is a command that has to be installed in `calendar-mode-map'."
9487 (interactive)
9488 (org-agenda-list nil (calendar-absolute-from-gregorian
9489 (calendar-cursor-to-date))
9490 nil))
9492 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9493 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9494 This is a command that has to be installed in `calendar-mode-map'.
9496 \(fn)" t nil)
9498 (defun org-agenda-convert-date ()
9499 (interactive)
9500 (org-agenda-check-type t 'agenda 'timeline)
9501 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9502 date s)
9503 (unless day
9504 (error "Don't know which date to convert"))
9505 (setq date (calendar-gregorian-from-absolute day))
9506 (setq s (concat
9507 "Gregorian: " (calendar-date-string date) "\n"
9508 "ISO: " (calendar-iso-date-string date) "\n"
9509 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9510 "Julian: " (calendar-julian-date-string date) "\n"
9511 "Astron. JD: " (calendar-astro-date-string date)
9512 " (Julian date number at noon UTC)\n"
9513 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9514 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9515 "French: " (calendar-french-date-string date) "\n"
9516 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9517 "Mayan: " (calendar-mayan-date-string date) "\n"
9518 "Coptic: " (calendar-coptic-date-string date) "\n"
9519 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9520 "Persian: " (calendar-persian-date-string date) "\n"
9521 "Chinese: " (calendar-chinese-date-string date) "\n"))
9522 (with-output-to-temp-buffer "*Dates*"
9523 (princ s))
9524 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9526 ;;; Bulk commands
9528 (defun org-agenda-bulk-marked-p ()
9529 (eq (get-char-property (point-at-bol) 'type)
9530 'org-marked-entry-overlay))
9532 (defun org-agenda-bulk-mark (&optional arg)
9533 "Mark the entry at point for future bulk action."
9534 (interactive "p")
9535 (dotimes (i (or arg 1))
9536 (unless (org-get-at-bol 'org-agenda-diary-link)
9537 (let* ((m (org-get-at-bol 'org-hd-marker))
9539 (unless (org-agenda-bulk-marked-p)
9540 (unless m (error "Nothing to mark at point"))
9541 (push m org-agenda-bulk-marked-entries)
9542 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9543 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9544 (org-get-todo-face "TODO")
9545 'evaporate)
9546 (overlay-put ov 'type 'org-marked-entry-overlay))
9547 (beginning-of-line 2)
9548 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9549 (beginning-of-line 2))
9550 (message "%d entries marked for bulk action"
9551 (length org-agenda-bulk-marked-entries))))))
9553 (defun org-agenda-bulk-mark-all ()
9554 "Mark all entries for future agenda bulk action."
9555 (interactive)
9556 (org-agenda-bulk-mark-regexp "."))
9558 (defun org-agenda-bulk-mark-regexp (regexp)
9559 "Mark entries matching REGEXP for future agenda bulk action."
9560 (interactive "sMark entries matching regexp: ")
9561 (let ((entries-marked 0))
9562 (save-excursion
9563 (goto-char (point-min))
9564 (goto-char (next-single-property-change (point) 'txt))
9565 (while (re-search-forward regexp nil t)
9566 (when (string-match regexp (get-text-property (point) 'txt))
9567 (setq entries-marked (1+ entries-marked))
9568 (call-interactively 'org-agenda-bulk-mark))))
9569 (if (not entries-marked)
9570 (message "No entry matching this regexp."))))
9572 (defun org-agenda-bulk-unmark (&optional arg)
9573 "Unmark the entry at point for future bulk action."
9574 (interactive "P")
9575 (if arg
9576 (org-agenda-bulk-unmark-all)
9577 (cond ((org-agenda-bulk-marked-p)
9578 (org-agenda-bulk-remove-overlays
9579 (point-at-bol) (+ 2 (point-at-bol)))
9580 (setq org-agenda-bulk-marked-entries
9581 (delete (org-get-at-bol 'org-hd-marker)
9582 org-agenda-bulk-marked-entries))
9583 (beginning-of-line 2)
9584 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9585 (beginning-of-line 2))
9586 (message "%d entries left marked for bulk action"
9587 (length org-agenda-bulk-marked-entries)))
9588 (t (message "No entry to unmark here")))))
9590 (defun org-agenda-bulk-toggle ()
9591 "Toggle marking the entry at point for bulk action."
9592 (interactive)
9593 (if (org-agenda-bulk-marked-p)
9594 (org-agenda-bulk-unmark)
9595 (org-agenda-bulk-mark)))
9597 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9598 "Remove the mark overlays between BEG and END in the agenda buffer.
9599 BEG and END default to the buffer limits.
9601 This only removes the overlays, it does not remove the markers
9602 from the list in `org-agenda-bulk-marked-entries'."
9603 (interactive)
9604 (mapc (lambda (ov)
9605 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9606 (delete-overlay ov)))
9607 (overlays-in (or beg (point-min)) (or end (point-max)))))
9609 (defun org-agenda-bulk-unmark-all ()
9610 "Remove all marks in the agenda buffer.
9611 This will remove the markers and the overlays."
9612 (interactive)
9613 (if (null org-agenda-bulk-marked-entries)
9614 (message "No entry to unmark")
9615 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9616 (setq org-agenda-bulk-marked-entries nil)
9617 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9619 (defcustom org-agenda-persistent-marks nil
9620 "Non-nil means marked items will stay marked after a bulk action.
9621 You can toggle this interactively by typing `p' when prompted for a
9622 bulk action."
9623 :group 'org-agenda
9624 :version "24.1"
9625 :type 'boolean)
9627 (defun org-agenda-bulk-action (&optional arg)
9628 "Execute an remote-editing action on all marked entries.
9629 The prefix arg is passed through to the command if possible."
9630 (interactive "P")
9631 ;; Make sure we have markers, and only valid ones
9632 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9633 (mapc
9634 (lambda (m)
9635 (unless (and (markerp m)
9636 (marker-buffer m)
9637 (buffer-live-p (marker-buffer m))
9638 (marker-position m))
9639 (error "Marker %s for bulk command is invalid" m)))
9640 org-agenda-bulk-marked-entries)
9642 ;; Prompt for the bulk command
9643 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9644 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9645 "[S]catter [f]unction "
9646 (when org-agenda-bulk-custom-functions
9647 (concat " Custom: ["
9648 (mapconcat (lambda(f) (char-to-string (car f)))
9649 org-agenda-bulk-custom-functions "")
9650 "]"))))
9651 (catch 'exit
9652 (let* ((action (read-char-exclusive))
9653 (org-log-refile (if org-log-refile 'time nil))
9654 (entries (reverse org-agenda-bulk-marked-entries))
9655 (org-overriding-default-time
9656 (if (get-text-property (point) 'org-agenda-date-header)
9657 (org-get-cursor-date)))
9658 redo-at-end
9659 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9660 (cond
9661 ((equal action ?p)
9662 (let ((org-agenda-persistent-marks
9663 (not org-agenda-persistent-marks)))
9664 (org-agenda-bulk-action)
9665 (throw 'exit nil)))
9667 ((equal action ?$)
9668 (setq cmd '(org-agenda-archive)))
9670 ((equal action ?A)
9671 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9673 ((member action '(?r ?w))
9674 (setq rfloc (org-refile-get-location
9675 "Refile to"
9676 (marker-buffer (car entries))
9677 org-refile-allow-creating-parent-nodes))
9678 (if (nth 3 rfloc)
9679 (setcar (nthcdr 3 rfloc)
9680 (move-marker (make-marker) (nth 3 rfloc)
9681 (or (get-file-buffer (nth 1 rfloc))
9682 (find-buffer-visiting (nth 1 rfloc))
9683 (error "This should not happen")))))
9685 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9686 redo-at-end t))
9688 ((equal action ?t)
9689 (setq state (org-icompleting-read
9690 "Todo state: "
9691 (with-current-buffer (marker-buffer (car entries))
9692 (mapcar 'list org-todo-keywords-1))))
9693 (setq cmd `(let ((org-inhibit-blocking t)
9694 (org-inhibit-logging 'note))
9695 (org-agenda-todo ,state))))
9697 ((memq action '(?- ?+))
9698 (setq tag (org-icompleting-read
9699 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9700 (with-current-buffer (marker-buffer (car entries))
9701 (delq nil
9702 (mapcar (lambda (x)
9703 (if (stringp (car x)) x)) org-tag-alist)))))
9704 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9706 ((memq action '(?s ?d))
9707 (let* ((time
9708 (unless arg
9709 (org-read-date
9710 nil nil nil
9711 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9712 org-overriding-default-time)))
9713 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9714 (setq cmd `(eval '(,c1 arg ,time)))))
9716 ((equal action ?S)
9717 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9718 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9719 (let ((days (read-number
9720 (format "Scatter tasks across how many %sdays: "
9721 (if arg "week" "")) 7)))
9722 (setq cmd
9723 `(let ((distance (1+ (random ,days))))
9724 (if arg
9725 (let ((dist distance)
9726 (day-of-week
9727 (calendar-day-of-week
9728 (calendar-gregorian-from-absolute (org-today)))))
9729 (dotimes (i (1+ dist))
9730 (while (member day-of-week org-agenda-weekend-days)
9731 (incf distance)
9732 (incf day-of-week)
9733 (if (= day-of-week 7)
9734 (setq day-of-week 0)))
9735 (incf day-of-week)
9736 (if (= day-of-week 7)
9737 (setq day-of-week 0)))))
9738 ;; silently fail when try to replan a sexp entry
9739 (condition-case nil
9740 (let* ((date (calendar-gregorian-from-absolute
9741 (+ (org-today) distance)))
9742 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9743 (nth 2 date))))
9744 (org-agenda-schedule nil time))
9745 (error nil)))))))
9747 ((assoc action org-agenda-bulk-custom-functions)
9748 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9749 redo-at-end t))
9751 ((equal action ?f)
9752 (setq cmd (list (intern
9753 (org-icompleting-read "Function: "
9754 obarray 'fboundp t nil nil)))))
9756 (t (error "Invalid bulk action")))
9758 ;; Sort the markers, to make sure that parents are handled before children
9759 (setq entries (sort entries
9760 (lambda (a b)
9761 (cond
9762 ((equal (marker-buffer a) (marker-buffer b))
9763 (< (marker-position a) (marker-position b)))
9765 (string< (buffer-name (marker-buffer a))
9766 (buffer-name (marker-buffer b))))))))
9768 ;; Now loop over all markers and apply cmd
9769 (while (setq e (pop entries))
9770 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9771 (if (not pos)
9772 (progn (message "Skipping removed entry at %s" e)
9773 (setq cntskip (1+ cntskip)))
9774 (goto-char pos)
9775 (let (org-loop-over-headlines-in-active-region)
9776 (eval cmd))
9777 (setq cnt (1+ cnt))))
9778 (when redo-at-end (org-agenda-redo))
9779 (unless org-agenda-persistent-marks
9780 (org-agenda-bulk-unmark-all))
9781 (message "Acted on %d entries%s%s"
9783 (if (= cntskip 0)
9785 (format ", skipped %d (disappeared before their turn)"
9786 cntskip))
9787 (if (not org-agenda-persistent-marks)
9788 "" " (kept marked)"))))))
9790 (defun org-agenda-capture (&optional with-time)
9791 "Call `org-capture' with the date at point.
9792 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9793 current HH:MM time."
9794 (interactive "P")
9795 (if (not (eq major-mode 'org-agenda-mode))
9796 (user-error "You cannot do this outside of agenda buffers")
9797 (let ((org-overriding-default-time
9798 (org-get-cursor-date (equal with-time 1))))
9799 (call-interactively 'org-capture))))
9801 ;;; Flagging notes
9803 (defun org-agenda-show-the-flagging-note ()
9804 "Display the flagging note in the other window.
9805 When called a second time in direct sequence, offer to remove the FLAGGING
9806 tag and (if present) the flagging note."
9807 (interactive)
9808 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9809 (win (selected-window))
9810 note heading newhead)
9811 (unless hdmarker
9812 (error "No linked entry at point"))
9813 (if (and (eq this-command last-command)
9814 (y-or-n-p "Unflag and remove any flagging note? "))
9815 (progn
9816 (org-agenda-remove-flag hdmarker)
9817 (let ((win (get-buffer-window "*Flagging Note*")))
9818 (and win (delete-window win)))
9819 (message "Entry unflagged"))
9820 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9821 (unless note
9822 (error "No flagging note"))
9823 (org-kill-new note)
9824 (org-switch-to-buffer-other-window "*Flagging Note*")
9825 (erase-buffer)
9826 (insert note)
9827 (goto-char (point-min))
9828 (while (re-search-forward "\\\\n" nil t)
9829 (replace-match "\n" t t))
9830 (goto-char (point-min))
9831 (select-window win)
9832 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9834 (defun org-agenda-remove-flag (marker)
9835 "Remove the FLAGGED tag and any flagging note in the entry."
9836 (let (newhead)
9837 (org-with-point-at marker
9838 (org-toggle-tag "FLAGGED" 'off)
9839 (org-entry-delete nil "THEFLAGGINGNOTE")
9840 (setq newhead (org-get-heading)))
9841 (org-agenda-change-all-lines newhead marker)
9842 (message "Entry unflagged")))
9844 (defun org-agenda-get-any-marker (&optional pos)
9845 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9846 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9848 ;;; Appointment reminders
9850 (defvar appt-time-msg-list) ; defined in appt.el
9852 ;;;###autoload
9853 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9854 "Activate appointments found in `org-agenda-files'.
9855 With a \\[universal-argument] prefix, refresh the list of
9856 appointments.
9858 If FILTER is t, interactively prompt the user for a regular
9859 expression, and filter out entries that don't match it.
9861 If FILTER is a string, use this string as a regular expression
9862 for filtering entries out.
9864 If FILTER is a function, filter out entries against which
9865 calling the function returns nil. This function takes one
9866 argument: an entry from `org-agenda-get-day-entries'.
9868 FILTER can also be an alist with the car of each cell being
9869 either 'headline or 'category. For example:
9871 '((headline \"IMPORTANT\")
9872 (category \"Work\"))
9874 will only add headlines containing IMPORTANT or headlines
9875 belonging to the \"Work\" category.
9877 ARGS are symbols indicating what kind of entries to consider.
9878 By default `org-agenda-to-appt' will use :deadline, :scheduled
9879 and :timestamp entries. See the docstring of `org-diary' for
9880 details and examples.
9882 If an entry as a APPT_WARNTIME property, its value will be used
9883 to override `appt-message-warning-time'."
9884 (interactive "P")
9885 (if refresh (setq appt-time-msg-list nil))
9886 (if (eq filter t)
9887 (setq filter (read-from-minibuffer "Regexp filter: ")))
9888 (let* ((cnt 0) ; count added events
9889 (scope (or args '(:deadline :scheduled :timestamp)))
9890 (org-agenda-new-buffers nil)
9891 (org-deadline-warning-days 0)
9892 ;; Do not use `org-today' here because appt only takes
9893 ;; time and without date as argument, so it may pass wrong
9894 ;; information otherwise
9895 (today (org-date-to-gregorian
9896 (time-to-days (current-time))))
9897 (org-agenda-restrict nil)
9898 (files (org-agenda-files 'unrestricted)) entries file
9899 (org-agenda-buffer nil))
9900 ;; Get all entries which may contain an appt
9901 (org-agenda-prepare-buffers files)
9902 (while (setq file (pop files))
9903 (setq entries
9904 (delq nil
9905 (append entries
9906 (apply 'org-agenda-get-day-entries
9907 file today scope)))))
9908 ;; Map thru entries and find if we should filter them out
9909 (mapc
9910 (lambda(x)
9911 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9912 (cat (get-text-property 1 'org-category x))
9913 (tod (get-text-property 1 'time-of-day x))
9914 (ok (or (null filter)
9915 (and (stringp filter) (string-match filter evt))
9916 (and (functionp filter) (funcall filter x))
9917 (and (listp filter)
9918 (let ((cat-filter (cadr (assoc 'category filter)))
9919 (evt-filter (cadr (assoc 'headline filter))))
9920 (or (and (stringp cat-filter)
9921 (string-match cat-filter cat))
9922 (and (stringp evt-filter)
9923 (string-match evt-filter evt)))))))
9924 (wrn (get-text-property 1 'warntime x)))
9925 ;; FIXME: Shall we remove text-properties for the appt text?
9926 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9927 (when (and ok tod)
9928 (setq tod (concat "00" (number-to-string tod))
9929 tod (when (string-match
9930 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9931 (concat (match-string 1 tod) ":"
9932 (match-string 2 tod))))
9933 (if (version< emacs-version "23.3")
9934 (appt-add tod evt)
9935 (appt-add tod evt wrn))
9936 (setq cnt (1+ cnt))))) entries)
9937 (org-release-buffers org-agenda-new-buffers)
9938 (if (eq cnt 0)
9939 (message "No event to add")
9940 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9942 (autoload 'org-agenda-to-appt "org-agenda" "\
9943 Activate appointments found in `org-agenda-files'.
9944 With a \\[universal-argument] prefix, refresh the list of
9945 appointments.
9947 If FILTER is t, interactively prompt the user for a regular
9948 expression, and filter out entries that don't match it.
9950 If FILTER is a string, use this string as a regular expression
9951 for filtering entries out.
9953 If FILTER is a function, filter out entries against which
9954 calling the function returns nil. This function takes one
9955 argument: an entry from `org-agenda-get-day-entries'.
9957 FILTER can also be an alist with the car of each cell being
9958 either 'headline or 'category. For example:
9960 '((headline \"IMPORTANT\")
9961 (category \"Work\"))
9963 will only add headlines containing IMPORTANT or headlines
9964 belonging to the \"Work\" category.
9966 ARGS are symbols indicating what kind of entries to consider.
9967 By default `org-agenda-to-appt' will use :deadline, :scheduled
9968 and :timestamp entries. See the docstring of `org-diary' for
9969 details and examples.
9971 If an entry as a APPT_WARNTIME property, its value will be used
9972 to override `appt-message-warning-time'.
9974 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9976 (defun org-agenda-todayp (date)
9977 "Does DATE mean today, when considering `org-extend-today-until'?"
9978 (let ((today (org-today))
9979 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9980 date)))
9981 (eq date today)))
9983 (defun org-agenda-todo-yesterday (&optional arg)
9984 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9985 (interactive "P")
9986 (let* ((hour (third (decode-time
9987 (org-current-time))))
9988 (org-extend-today-until (1+ hour)))
9989 (org-agenda-todo arg)))
9991 (provide 'org-agenda)
9993 ;;; org-agenda.el ends here