Add missing colon to #+INCLUDE in structure template
[org-mode.git] / lisp / org-agenda.el
blob00441e5382b008c7462b5120f0c8189d246adf68
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 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))
87 (defvar calendar-mode-map)
88 (defvar org-clock-current-task) ; defined in org-clock.el
89 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
90 (defvar org-habit-show-habits)
91 (defvar org-habit-show-habits-only-for-today)
92 (defvar org-habit-show-all-today nil)
94 ;; Defined somewhere in this file, but used before definition.
95 (defvar org-agenda-buffer-name)
96 (defvar org-agenda-overriding-header)
97 (defvar org-agenda-title-append nil)
98 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
99 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
100 (defvar org-agenda-undo-list)
101 (defvar org-agenda-pending-undo-list)
102 (defvar original-date) ; dynamically scoped, calendar.el does scope this
104 (defcustom org-agenda-confirm-kill 1
105 "When set, remote killing from the agenda buffer needs confirmation.
106 When t, a confirmation is always needed. When a number N, confirmation is
107 only needed when the text to be killed contains more than N non-white lines."
108 :group 'org-agenda
109 :type '(choice
110 (const :tag "Never" nil)
111 (const :tag "Always" t)
112 (integer :tag "When more than N lines")))
114 (defcustom org-agenda-compact-blocks nil
115 "Non-nil means make the block agenda more compact.
116 This is done globally by leaving out lines like the agenda span
117 name and week number or the separator lines."
118 :group 'org-agenda
119 :type 'boolean)
121 (defcustom org-agenda-block-separator ?=
122 "The separator between blocks in the agenda.
123 If this is a string, it will be used as the separator, with a newline added.
124 If it is a character, it will be repeated to fill the window width.
125 If nil the separator is disabled. In `org-agenda-custom-commands' this
126 addresses the separator between the current and the previous block."
127 :group 'org-agenda
128 :type '(choice
129 (const :tag "Disabled" nil)
130 (character)
131 (string)))
133 (defgroup org-agenda-export nil
134 "Options concerning exporting agenda views in Org-mode."
135 :tag "Org Agenda Export"
136 :group 'org-agenda)
138 (defcustom org-agenda-with-colors t
139 "Non-nil means use colors in agenda views."
140 :group 'org-agenda-export
141 :type 'boolean)
143 (defcustom org-agenda-exporter-settings nil
144 "Alist of variable/value pairs that should be active during agenda export.
145 This is a good place to set options for ps-print and for htmlize.
146 Note that the way this is implemented, the values will be evaluated
147 before assigned to the variables. So make sure to quote values you do
148 *not* want evaluated, for example
150 (setq org-agenda-exporter-settings
151 '((ps-print-color-p 'black-white)))"
152 :group 'org-agenda-export
153 :type '(repeat
154 (list
155 (variable)
156 (sexp :tag "Value"))))
158 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
159 "Hook run in temporary buffer before writing it to an export file.
160 A useful function is `org-agenda-add-entry-text'."
161 :group 'org-agenda-export
162 :type 'hook
163 :options '(org-agenda-add-entry-text))
165 (defcustom org-agenda-add-entry-text-maxlines 0
166 "Maximum number of entry text lines to be added to agenda.
167 This is only relevant when `org-agenda-add-entry-text' is part of
168 `org-agenda-before-write-hook', which it is by default.
169 When this is 0, nothing will happen. When it is greater than 0, it
170 specifies the maximum number of lines that will be added for each entry
171 that is listed in the agenda view.
173 Note that this variable is not used during display, only when exporting
174 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
175 and `org-agenda-entry-text-maxlines'."
176 :group 'org-agenda
177 :type 'integer)
179 (defcustom org-agenda-add-entry-text-descriptive-links t
180 "Non-nil means export org-links as descriptive links in agenda added text.
181 This variable applies to the text added to the agenda when
182 `org-agenda-add-entry-text-maxlines' is larger than 0.
183 When this variable nil, the URL will (also) be shown."
184 :group 'org-agenda
185 :type 'boolean)
187 (defcustom org-agenda-export-html-style ""
188 "The style specification for exported HTML Agenda files.
189 If this variable contains a string, it will replace the default <style>
190 section as produced by `htmlize'.
191 Since there are different ways of setting style information, this variable
192 needs to contain the full HTML structure to provide a style, including the
193 surrounding HTML tags. The style specifications should include definitions
194 the fonts used by the agenda, here is an example:
196 <style type=\"text/css\">
197 p { font-weight: normal; color: gray; }
198 .org-agenda-structure {
199 font-size: 110%;
200 color: #003399;
201 font-weight: 600;
203 .org-todo {
204 color: #cc6666;
205 font-weight: bold;
207 .org-agenda-done {
208 color: #339933;
210 .org-done {
211 color: #339933;
213 .title { text-align: center; }
214 .todo, .deadline { color: red; }
215 .done { color: green; }
216 </style>
218 or, if you want to keep the style in a file,
220 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
222 As the value of this option simply gets inserted into the HTML <head> header,
223 you can \"misuse\" it to also add other text to the header. However,
224 <style>...</style> is required, if not present the variable will be ignored."
225 :group 'org-agenda-export
226 :group 'org-export-html
227 :type 'string)
229 (defcustom org-agenda-persistent-filter nil
230 "When set, keep filters from one agenda view to the next."
231 :group 'org-agenda
232 :type 'boolean)
234 (defgroup org-agenda-custom-commands nil
235 "Options concerning agenda views in Org-mode."
236 :tag "Org Agenda Custom Commands"
237 :group 'org-agenda)
239 (defconst org-sorting-choice
240 '(choice
241 (const time-up) (const time-down)
242 (const category-keep) (const category-up) (const category-down)
243 (const tag-down) (const tag-up)
244 (const priority-up) (const priority-down)
245 (const todo-state-up) (const todo-state-down)
246 (const effort-up) (const effort-down)
247 (const habit-up) (const habit-down)
248 (const alpha-up) (const alpha-down)
249 (const user-defined-up) (const user-defined-down))
250 "Sorting choices.")
252 ;; Keep custom values for `org-agenda-filter-preset' compatible with
253 ;; the new variable `org-agenda-tag-filter-preset'.
254 (if (fboundp 'defvaralias)
255 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
256 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
258 (defconst org-agenda-custom-commands-local-options
259 `(repeat :tag "Local settings for this command. Remember to quote values"
260 (choice :tag "Setting"
261 (list :tag "Heading for this block"
262 (const org-agenda-overriding-header)
263 (string :tag "Headline"))
264 (list :tag "Files to be searched"
265 (const org-agenda-files)
266 (list
267 (const :format "" quote)
268 (repeat (file))))
269 (list :tag "Sorting strategy"
270 (const org-agenda-sorting-strategy)
271 (list
272 (const :format "" quote)
273 (repeat
274 ,org-sorting-choice)))
275 (list :tag "Prefix format"
276 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
277 (string))
278 (list :tag "Number of days in agenda"
279 (const org-agenda-span)
280 (choice (const :tag "Day" 'day)
281 (const :tag "Week" 'week)
282 (const :tag "Month" 'month)
283 (const :tag "Year" 'year)
284 (integer :tag "Custom")))
285 (list :tag "Fixed starting date"
286 (const org-agenda-start-day)
287 (string :value "2007-11-01"))
288 (list :tag "Start on day of week"
289 (const org-agenda-start-on-weekday)
290 (choice :value 1
291 (const :tag "Today" nil)
292 (integer :tag "Weekday No.")))
293 (list :tag "Include data from diary"
294 (const org-agenda-include-diary)
295 (boolean))
296 (list :tag "Deadline Warning days"
297 (const org-deadline-warning-days)
298 (integer :value 1))
299 (list :tag "Category filter preset"
300 (const org-agenda-category-filter-preset)
301 (list
302 (const :format "" quote)
303 (repeat
304 (string :tag "+category or -category"))))
305 (list :tag "Tags filter preset"
306 (const org-agenda-tag-filter-preset)
307 (list
308 (const :format "" quote)
309 (repeat
310 (string :tag "+tag or -tag"))))
311 (list :tag "Set daily/weekly entry types"
312 (const org-agenda-entry-types)
313 (list
314 (const :format "" quote)
315 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
316 (const :deadline)
317 (const :scheduled)
318 (const :timestamp)
319 (const :sexp))))
320 (list :tag "Standard skipping condition"
321 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
322 (const org-agenda-skip-function)
323 (list
324 (const :format "" quote)
325 (list
326 (choice
327 :tag "Skipping range"
328 (const :tag "Skip entry" org-agenda-skip-entry-if)
329 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
330 (repeat :inline t :tag "Conditions for skipping"
331 (choice
332 :tag "Condition type"
333 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
334 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
335 (list :tag "TODO state is" :inline t
336 (const 'todo)
337 (choice
338 (const :tag "any not-done state" 'todo)
339 (const :tag "any done state" 'done)
340 (const :tag "any state" 'any)
341 (list :tag "Keyword list"
342 (const :format "" quote)
343 (repeat (string :tag "Keyword")))))
344 (list :tag "TODO state is not" :inline t
345 (const 'nottodo)
346 (choice
347 (const :tag "any not-done state" 'todo)
348 (const :tag "any done state" 'done)
349 (const :tag "any state" 'any)
350 (list :tag "Keyword list"
351 (const :format "" quote)
352 (repeat (string :tag "Keyword")))))
353 (const :tag "scheduled" 'scheduled)
354 (const :tag "not scheduled" 'notscheduled)
355 (const :tag "deadline" 'deadline)
356 (const :tag "no deadline" 'notdeadline)
357 (const :tag "timestamp" 'timestamp)
358 (const :tag "no timestamp" 'nottimestamp))))))
359 (list :tag "Non-standard skipping condition"
360 :value (org-agenda-skip-function)
361 (const org-agenda-skip-function)
362 (sexp :tag "Function or form (quoted!)"))
363 (list :tag "Any variable"
364 (variable :tag "Variable")
365 (sexp :tag "Value (sexp)"))))
366 "Selection of examples for agenda command settings.
367 This will be spliced into the custom type of
368 `org-agenda-custom-commands'.")
371 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
372 ((agenda "") (alltodo))))
373 "Custom commands for the agenda.
374 These commands will be offered on the splash screen displayed by the
375 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
377 (key desc type match settings files)
379 key The key (one or more characters as a string) to be associated
380 with the command.
381 desc A description of the command, when omitted or nil, a default
382 description is built using MATCH.
383 type The command type, any of the following symbols:
384 agenda The daily/weekly agenda.
385 todo Entries with a specific TODO keyword, in all agenda files.
386 search Entries containing search words entry or headline.
387 tags Tags/Property/TODO match in all agenda files.
388 tags-todo Tags/P/T match in all agenda files, TODO entries only.
389 todo-tree Sparse tree of specific TODO keyword in *current* file.
390 tags-tree Sparse tree with all tags matches in *current* file.
391 occur-tree Occur sparse tree for *current* file.
392 ... A user-defined function.
393 match What to search for:
394 - a single keyword for TODO keyword searches
395 - a tags match expression for tags searches
396 - a word search expression for text searches.
397 - a regular expression for occur searches
398 For all other commands, this should be the empty string.
399 settings A list of option settings, similar to that in a let form, so like
400 this: ((opt1 val1) (opt2 val2) ...). The values will be
401 evaluated at the moment of execution, so quote them when needed.
402 files A list of files file to write the produced agenda buffer to
403 with the command `org-store-agenda-views'.
404 If a file name ends in \".html\", an HTML version of the buffer
405 is written out. If it ends in \".ps\", a postscript version is
406 produced. Otherwise, only the plain text is written to the file.
408 You can also define a set of commands, to create a composite agenda buffer.
409 In this case, an entry looks like this:
411 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
413 where
415 desc A description string to be displayed in the dispatcher menu.
416 cmd An agenda command, similar to the above. However, tree commands
417 are not allowed, but instead you can get agenda and global todo list.
418 So valid commands for a set are:
419 (agenda \"\" settings)
420 (alltodo \"\" settings)
421 (stuck \"\" settings)
422 (todo \"match\" settings files)
423 (search \"match\" settings files)
424 (tags \"match\" settings files)
425 (tags-todo \"match\" settings files)
427 Each command can carry a list of options, and another set of options can be
428 given for the whole set of commands. Individual command options take
429 precedence over the general options.
431 When using several characters as key to a command, the first characters
432 are prefix commands. For the dispatcher to display useful information, you
433 should provide a description for the prefix, like
435 (setq org-agenda-custom-commands
436 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
437 (\"hl\" tags \"+HOME+Lisa\")
438 (\"hp\" tags \"+HOME+Peter\")
439 (\"hk\" tags \"+HOME+Kim\")))"
440 :group 'org-agenda-custom-commands
441 :type `(repeat
442 (choice :value ("x" "Describe command here" tags "" nil)
443 (list :tag "Single command"
444 (string :tag "Access Key(s) ")
445 (option (string :tag "Description"))
446 (choice
447 (const :tag "Agenda" agenda)
448 (const :tag "TODO list" alltodo)
449 (const :tag "Search words" search)
450 (const :tag "Stuck projects" stuck)
451 (const :tag "Tags/Property match (all agenda files)" tags)
452 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
453 (const :tag "TODO keyword search (all agenda files)" todo)
454 (const :tag "Tags sparse tree (current buffer)" tags-tree)
455 (const :tag "TODO keyword tree (current buffer)" todo-tree)
456 (const :tag "Occur tree (current buffer)" occur-tree)
457 (sexp :tag "Other, user-defined function"))
458 (string :tag "Match (only for some commands)")
459 ,org-agenda-custom-commands-local-options
460 (option (repeat :tag "Export" (file :tag "Export to"))))
461 (list :tag "Command series, all agenda files"
462 (string :tag "Access Key(s)")
463 (string :tag "Description ")
464 (repeat :tag "Component"
465 (choice
466 (list :tag "Agenda"
467 (const :format "" agenda)
468 (const :tag "" :format "" "")
469 ,org-agenda-custom-commands-local-options)
470 (list :tag "TODO list (all keywords)"
471 (const :format "" alltodo)
472 (const :tag "" :format "" "")
473 ,org-agenda-custom-commands-local-options)
474 (list :tag "Search words"
475 (const :format "" search)
476 (string :tag "Match")
477 ,org-agenda-custom-commands-local-options)
478 (list :tag "Stuck projects"
479 (const :format "" stuck)
480 (const :tag "" :format "" "")
481 ,org-agenda-custom-commands-local-options)
482 (list :tag "Tags search"
483 (const :format "" tags)
484 (string :tag "Match")
485 ,org-agenda-custom-commands-local-options)
486 (list :tag "Tags search, TODO entries only"
487 (const :format "" tags-todo)
488 (string :tag "Match")
489 ,org-agenda-custom-commands-local-options)
490 (list :tag "TODO keyword search"
491 (const :format "" todo)
492 (string :tag "Match")
493 ,org-agenda-custom-commands-local-options)
494 (list :tag "Other, user-defined function"
495 (symbol :tag "function")
496 (string :tag "Match")
497 ,org-agenda-custom-commands-local-options)))
499 (repeat :tag "Settings for entire command set"
500 (list (variable :tag "Any variable")
501 (sexp :tag "Value")))
502 (option (repeat :tag "Export" (file :tag "Export to"))))
503 (cons :tag "Prefix key documentation"
504 (string :tag "Access Key(s)")
505 (string :tag "Description ")))))
507 (defcustom org-agenda-query-register ?o
508 "The register holding the current query string.
509 The purpose of this is that if you construct a query string interactively,
510 you can then use it to define a custom command."
511 :group 'org-agenda-custom-commands
512 :type 'character)
514 (defcustom org-stuck-projects
515 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
516 "How to identify stuck projects.
517 This is a list of four items:
518 1. A tags/todo/property matcher string that is used to identify a project.
519 See the manual for a description of tag and property searches.
520 The entire tree below a headline matched by this is considered one project.
521 2. A list of TODO keywords identifying non-stuck projects.
522 If the project subtree contains any headline with one of these todo
523 keywords, the project is considered to be not stuck. If you specify
524 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
525 3. A list of tags identifying non-stuck projects.
526 If the project subtree contains any headline with one of these tags,
527 the project is considered to be not stuck. If you specify \"*\" as
528 a tag, any tag will mark the project unstuck. Note that this is about
529 the explicit presence of a tag somewhere in the subtree, inherited
530 tags to not count here. If inherited tags make a project not stuck,
531 use \"-TAG\" in the tags part of the matcher under (1.) above.
532 4. An arbitrary regular expression matching non-stuck projects.
534 If the project turns out to be not stuck, search continues also in the
535 subtree to see if any of the subtasks have project status.
537 See also the variable `org-tags-match-list-sublevels' which applies
538 to projects matched by this search as well.
540 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
541 or `C-c a #' to produce the list."
542 :group 'org-agenda-custom-commands
543 :type '(list
544 (string :tag "Tags/TODO match to identify a project")
545 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
546 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
547 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
549 (defcustom org-agenda-filter-effort-default-operator "<"
550 "The default operator for effort estimate filtering.
551 If you select an effort estimate limit without first pressing an operator,
552 this one will be used."
553 :group 'org-agenda-custom-commands
554 :type '(choice (const :tag "less or equal" "<")
555 (const :tag "greater or equal"">")
556 (const :tag "equal" "=")))
558 (defgroup org-agenda-skip nil
559 "Options concerning skipping parts of agenda files."
560 :tag "Org Agenda Skip"
561 :group 'org-agenda)
563 (defcustom org-agenda-skip-function-global nil
564 "Function to be called at each match during agenda construction.
565 If this function returns nil, the current match should not be skipped.
566 If the function decided to skip an agenda match, is must return the
567 buffer position from which the search should be continued.
568 This may also be a Lisp form, which will be evaluated.
570 This variable will be applied to every agenda match, including
571 tags/property searches and TODO lists. So try to make the test function
572 do its checking as efficiently as possible. To implement a skipping
573 condition just for specific agenda commands, use the variable
574 `org-agenda-skip-function' which can be set in the options section
575 of custom agenda commands."
576 :group 'org-agenda-skip
577 :type 'sexp)
579 (defgroup org-agenda-daily/weekly nil
580 "Options concerning the daily/weekly agenda."
581 :tag "Org Agenda Daily/Weekly"
582 :group 'org-agenda)
583 (defgroup org-agenda-todo-list nil
584 "Options concerning the global todo list agenda view."
585 :tag "Org Agenda Todo List"
586 :group 'org-agenda)
587 (defgroup org-agenda-match-view nil
588 "Options concerning the general tags/property/todo match agenda view."
589 :tag "Org Agenda Match View"
590 :group 'org-agenda)
591 (defgroup org-agenda-search-view nil
592 "Options concerning the general tags/property/todo match agenda view."
593 :tag "Org Agenda Match View"
594 :group 'org-agenda)
596 (defvar org-agenda-archives-mode nil
597 "Non-nil means the agenda will include archived items.
598 If this is the symbol `trees', trees in the selected agenda scope
599 that are marked with the ARCHIVE tag will be included anyway. When this is
600 t, also all archive files associated with the current selection of agenda
601 files will be included.")
603 (defcustom org-agenda-skip-comment-trees t
604 "Non-nil means skip trees that start with the COMMENT keyword.
605 When nil, these trees are also scanned by agenda commands."
606 :group 'org-agenda-skip
607 :type 'boolean)
609 (defcustom org-agenda-todo-list-sublevels t
610 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
611 When nil, the sublevels of a TODO entry are not checked, resulting in
612 potentially much shorter TODO lists."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type 'boolean)
617 (defcustom org-agenda-todo-ignore-with-date nil
618 "Non-nil means don't show entries with a date in the global todo list.
619 You can use this if you prefer to mark mere appointments with a TODO keyword,
620 but don't want them to show up in the TODO list.
621 When this is set, it also covers deadlines and scheduled items, the settings
622 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
623 will be ignored.
624 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
625 :group 'org-agenda-skip
626 :group 'org-agenda-todo-list
627 :type 'boolean)
629 (defcustom org-agenda-todo-ignore-timestamp nil
630 "Non-nil means don't show entries with a timestamp.
631 This applies when creating the global todo list.
632 Valid values are:
634 past Don't show entries for today or in the past.
636 future Don't show entries with a timestamp in the future.
637 The idea behind this is that if it has a future
638 timestamp, you don't want to think about it until the
639 date.
641 all Don't show any entries with a timestamp in the global todo list.
642 The idea behind this is that by setting a timestamp, you
643 have already \"taken care\" of this item.
645 This variable can also have an integer as a value. If positive (N),
646 todos with a timestamp N or more days in the future will be ignored. If
647 negative (-N), todos with a timestamp N or more days in the past will be
648 ignored. If 0, todos with a timestamp either today or in the future will
649 be ignored. For example, a value of -1 will exclude todos with a
650 timestamp in the past (yesterday or earlier), while a value of 7 will
651 exclude todos with a timestamp a week or more in the future.
653 See also `org-agenda-todo-ignore-with-date'.
654 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
655 to make his option also apply to the tags-todo list."
656 :group 'org-agenda-skip
657 :group 'org-agenda-todo-list
658 :version "24.1"
659 :type '(choice
660 (const :tag "Ignore future timestamp todos" future)
661 (const :tag "Ignore past or present timestamp todos" past)
662 (const :tag "Ignore all timestamp todos" all)
663 (const :tag "Show timestamp todos" nil)
664 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
666 (defcustom org-agenda-todo-ignore-scheduled nil
667 "Non-nil means, ignore some scheduled TODO items when making TODO list.
668 This applies when creating the global todo list.
669 Valid values are:
671 past Don't show entries scheduled today or in the past.
673 future Don't show entries scheduled in the future.
674 The idea behind this is that by scheduling it, you don't want to
675 think about it until the scheduled date.
677 all Don't show any scheduled entries in the global todo list.
678 The idea behind this is that by scheduling it, you have already
679 \"taken care\" of this item.
681 t Same as `all', for backward compatibility.
683 This variable can also have an integer as a value. See
684 `org-agenda-todo-ignore-timestamp' for more details.
686 See also `org-agenda-todo-ignore-with-date'.
687 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
688 to make his option also apply to the tags-todo list."
689 :group 'org-agenda-skip
690 :group 'org-agenda-todo-list
691 :type '(choice
692 (const :tag "Ignore future-scheduled todos" future)
693 (const :tag "Ignore past- or present-scheduled todos" past)
694 (const :tag "Ignore all scheduled todos" all)
695 (const :tag "Ignore all scheduled todos (compatibility)" t)
696 (const :tag "Show scheduled todos" nil)
697 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
699 (defcustom org-agenda-todo-ignore-deadlines nil
700 "Non-nil means ignore some deadlined TODO items when making TODO list.
701 There are different motivations for using different values, please think
702 carefully when configuring this variable.
704 This applies when creating the global todo list.
705 Valid values are:
707 near Don't show near deadline entries. A deadline is near when it is
708 closer than `org-deadline-warning-days' days. The idea behind this
709 is that such items will appear in the agenda anyway.
711 far Don't show TODO entries where a deadline has been defined, but
712 the deadline is not near. This is useful if you don't want to
713 use the todo list to figure out what to do now.
715 past Don't show entries with a deadline timestamp for today or in the past.
717 future Don't show entries with a deadline timestamp in the future, not even
718 when they become `near' ones. Use it with caution.
720 all Ignore all TODO entries that do have a deadline.
722 t Same as `near', for backward compatibility.
724 This variable can also have an integer as a value. See
725 `org-agenda-todo-ignore-timestamp' for more details.
727 See also `org-agenda-todo-ignore-with-date'.
728 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
729 to make his option also apply to the tags-todo list."
730 :group 'org-agenda-skip
731 :group 'org-agenda-todo-list
732 :type '(choice
733 (const :tag "Ignore near deadlines" near)
734 (const :tag "Ignore near deadlines (compatibility)" t)
735 (const :tag "Ignore far deadlines" far)
736 (const :tag "Ignore all TODOs with a deadlines" all)
737 (const :tag "Show all TODOs, even if they have a deadline" nil)
738 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
740 (defcustom org-agenda-tags-todo-honor-ignore-options nil
741 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
742 The variables
743 `org-agenda-todo-ignore-with-date',
744 `org-agenda-todo-ignore-timestamp',
745 `org-agenda-todo-ignore-scheduled',
746 `org-agenda-todo-ignore-deadlines'
747 make the global TODO list skip entries that have time stamps of certain
748 kinds. If this option is set, the same options will also apply for the
749 tags-todo search, which is the general tags/property matcher
750 restricted to unfinished TODO entries only."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :group 'org-agenda-match-view
754 :type 'boolean)
756 (defcustom org-agenda-skip-scheduled-if-done nil
757 "Non-nil means don't show scheduled items in agenda when they are done.
758 This is relevant for the daily/weekly agenda, not for the TODO list. And
759 it applies only to the actual date of the scheduling. Warnings about
760 an item with a past scheduling dates are always turned off when the item
761 is DONE."
762 :group 'org-agenda-skip
763 :group 'org-agenda-daily/weekly
764 :type 'boolean)
766 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
767 "Non-nil means skip scheduling line if same entry shows because of deadline.
768 In the agenda of today, an entry can show up multiple times because
769 it is both scheduled and has a nearby deadline, and maybe a plain time
770 stamp as well.
771 When this variable is t, then only the deadline is shown and the fact that
772 the entry is scheduled today or was scheduled previously is not shown.
773 When this variable is nil, the entry will be shown several times. When
774 the variable is the symbol `not-today', then skip scheduled previously,
775 but not scheduled today."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type '(choice
779 (const :tag "Never" nil)
780 (const :tag "Always" t)
781 (const :tag "Not when scheduled today" not-today)))
783 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
784 "Non-nil means skip timestamp line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times
786 because it has both a plain timestamp and has a nearby deadline.
787 When this variable is t, then only the deadline is shown and the
788 fact that the entry has a timestamp for or including today is not
789 shown. When this variable is nil, the entry will be shown
790 several times."
791 :group 'org-agenda-skip
792 :group 'org-agenda-daily/weekly
793 :version "24.1"
794 :type '(choice
795 (const :tag "Never" nil)
796 (const :tag "Always" t)))
798 (defcustom org-agenda-skip-deadline-if-done nil
799 "Non-nil means don't show deadlines when the corresponding item is done.
800 When nil, the deadline is still shown and should give you a happy feeling.
801 This is relevant for the daily/weekly agenda. And it applied only to the
802 actually date of the deadline. Warnings about approaching and past-due
803 deadlines are always turned off when the item is DONE."
804 :group 'org-agenda-skip
805 :group 'org-agenda-daily/weekly
806 :type 'boolean)
808 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
809 "Non-nil means skip deadline prewarning when entry is also scheduled.
810 This will apply on all days where a prewarning for the deadline would
811 be shown, but not at the day when the entry is actually due. On that day,
812 the deadline will be shown anyway.
813 This variable may be set to nil, t, or a number which will then give
814 the number of days before the actual deadline when the prewarnings
815 should resume.
816 This can be used in a workflow where the first showing of the deadline will
817 trigger you to schedule it, and then you don't want to be reminded of it
818 because you will take care of it on the day when scheduled."
819 :group 'org-agenda-skip
820 :group 'org-agenda-daily/weekly
821 :version "24.1"
822 :type '(choice
823 (const :tag "Alwas show prewarning" nil)
824 (const :tag "Remove prewarning if entry is scheduled" t)
825 (integer :tag "Restart prewarning N days before deadline")))
827 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
828 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
829 When non-nil, after the search for timestamps has matched once in an
830 entry, the rest of the entry will not be searched."
831 :group 'org-agenda-skip
832 :type 'boolean)
834 (defcustom org-agenda-skip-timestamp-if-done nil
835 "Non-nil means don't select item by timestamp or -range if it is DONE."
836 :group 'org-agenda-skip
837 :group 'org-agenda-daily/weekly
838 :type 'boolean)
840 (defcustom org-agenda-dim-blocked-tasks t
841 "Non-nil means dim blocked tasks in the agenda display.
842 This causes some overhead during agenda construction, but if you
843 have turned on `org-enforce-todo-dependencies',
844 `org-enforce-todo-checkbox-dependencies', or any other blocking
845 mechanism, this will create useful feedback in the agenda.
847 Instead of t, this variable can also have the value `invisible'.
848 Then blocked tasks will be invisible and only become visible when
849 they become unblocked. An exemption to this behavior is when a task is
850 blocked because of unchecked checkboxes below it. Since checkboxes do
851 not show up in the agenda views, making this task invisible you remove any
852 trace from agenda views that there is something to do. Therefore, a task
853 that is blocked because of checkboxes will never be made invisible, it
854 will only be dimmed."
855 :group 'org-agenda-daily/weekly
856 :group 'org-agenda-todo-list
857 :type '(choice
858 (const :tag "Do not dim" nil)
859 (const :tag "Dim to a gray face" t)
860 (const :tag "Make invisible" invisible)))
862 (defcustom org-timeline-show-empty-dates 3
863 "Non-nil means `org-timeline' also shows dates without an entry.
864 When nil, only the days which actually have entries are shown.
865 When t, all days between the first and the last date are shown.
866 When an integer, show also empty dates, but if there is a gap of more than
867 N days, just insert a special line indicating the size of the gap."
868 :group 'org-agenda-skip
869 :type '(choice
870 (const :tag "None" nil)
871 (const :tag "All" t)
872 (integer :tag "at most")))
874 (defgroup org-agenda-startup nil
875 "Options concerning initial settings in the Agenda in Org Mode."
876 :tag "Org Agenda Startup"
877 :group 'org-agenda)
879 (defcustom org-agenda-menu-show-matcher t
880 "Non-nil means show the match string in the agenda dispatcher menu.
881 When nil, the matcher string is not shown, but is put into the help-echo
882 property so than moving the mouse over the command shows it.
883 Setting it to nil is good if matcher strings are very long and/or if
884 you want to use two-columns display (see `org-agenda-menu-two-columns')."
885 :group 'org-agenda
886 :version "24.1"
887 :type 'boolean)
889 (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
891 (defcustom org-agenda-menu-two-columns nil
892 "Non-nil means, use two columns to show custom commands in the dispatcher.
893 If you use this, you probably want to set `org-agenda-menu-show-matcher'
894 to nil."
895 :group 'org-agenda
896 :version "24.1"
897 :type 'boolean)
899 (defcustom org-finalize-agenda-hook nil
900 "Hook run just before displaying an agenda buffer."
901 :group 'org-agenda-startup
902 :type 'hook)
904 (defcustom org-agenda-mouse-1-follows-link nil
905 "Non-nil means mouse-1 on a link will follow the link in the agenda.
906 A longer mouse click will still set point. Does not work on XEmacs.
907 Needs to be set before org.el is loaded."
908 :group 'org-agenda-startup
909 :type 'boolean)
911 (defcustom org-agenda-start-with-follow-mode nil
912 "The initial value of follow mode in a newly created agenda window."
913 :group 'org-agenda-startup
914 :type 'boolean)
916 (defcustom org-agenda-follow-indirect nil
917 "Non-nil means `org-agenda-follow-mode' displays only the
918 current item's tree, in an indirect buffer."
919 :group 'org-agenda
920 :version "24.1"
921 :type 'boolean)
923 (defcustom org-agenda-show-outline-path t
924 "Non-nil means show outline path in echo area after line motion."
925 :group 'org-agenda-startup
926 :type 'boolean)
928 (defcustom org-agenda-start-with-entry-text-mode nil
929 "The initial value of entry-text-mode in a newly created agenda window."
930 :group 'org-agenda-startup
931 :type 'boolean)
933 (defcustom org-agenda-entry-text-maxlines 5
934 "Number of text lines to be added when `E' is pressed in the agenda.
936 Note that this variable only used during agenda display. Add add entry text
937 when exporting the agenda, configure the variable
938 `org-agenda-add-entry-ext-maxlines'."
939 :group 'org-agenda
940 :type 'integer)
942 (defcustom org-agenda-entry-text-exclude-regexps nil
943 "List of regular expressions to clean up entry text.
944 The complete matches of all regular expressions in this list will be
945 removed from entry text before it is shown in the agenda."
946 :group 'org-agenda
947 :type '(repeat (regexp)))
949 (defvar org-agenda-entry-text-cleanup-hook nil
950 "Hook that is run after basic cleanup of entry text to be shown in agenda.
951 This cleanup is done in a temporary buffer, so the function may inspect and
952 change the entire buffer.
953 Some default stuff like drawers and scheduling/deadline dates will already
954 have been removed when this is called, as will any matches for regular
955 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
957 (defvar org-agenda-include-inactive-timestamps nil
958 "Non-nil means include inactive time stamps in agenda and timeline.
959 Dynamically scoped.")
961 (defgroup org-agenda-windows nil
962 "Options concerning the windows used by the Agenda in Org Mode."
963 :tag "Org Agenda Windows"
964 :group 'org-agenda)
966 (defcustom org-agenda-window-setup 'reorganize-frame
967 "How the agenda buffer should be displayed.
968 Possible values for this option are:
970 current-window Show agenda in the current window, keeping all other windows.
971 other-window Use `switch-to-buffer-other-window' to display agenda.
972 reorganize-frame Show only two windows on the current frame, the current
973 window and the agenda.
974 other-frame Use `switch-to-buffer-other-frame' to display agenda.
975 Also, when exiting the agenda, kill that frame.
976 See also the variable `org-agenda-restore-windows-after-quit'."
977 :group 'org-agenda-windows
978 :type '(choice
979 (const current-window)
980 (const other-frame)
981 (const other-window)
982 (const reorganize-frame)))
984 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
985 "The min and max height of the agenda window as a fraction of frame height.
986 The value of the variable is a cons cell with two numbers between 0 and 1.
987 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
988 :group 'org-agenda-windows
989 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
991 (defcustom org-agenda-restore-windows-after-quit nil
992 "Non-nil means restore window configuration upon exiting agenda.
993 Before the window configuration is changed for displaying the agenda,
994 the current status is recorded. When the agenda is exited with
995 `q' or `x' and this option is set, the old state is restored. If
996 `org-agenda-window-setup' is `other-frame', the value of this
997 option will be ignored."
998 :group 'org-agenda-windows
999 :type 'boolean)
1001 (defcustom org-agenda-ndays nil
1002 "Number of days to include in overview display.
1003 Should be 1 or 7.
1004 Obsolete, see `org-agenda-span'."
1005 :group 'org-agenda-daily/weekly
1006 :type 'integer)
1008 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1010 (defcustom org-agenda-span 'week
1011 "Number of days to include in overview display.
1012 Can be day, week, month, year, or any number of days.
1013 Custom commands can set this variable in the options section."
1014 :group 'org-agenda-daily/weekly
1015 :type '(choice (const :tag "Day" day)
1016 (const :tag "Week" week)
1017 (const :tag "Month" month)
1018 (const :tag "Year" year)
1019 (integer :tag "Custom")))
1021 (defcustom org-agenda-start-on-weekday 1
1022 "Non-nil means start the overview always on the specified weekday.
1023 0 denotes Sunday, 1 denotes Monday etc.
1024 When nil, always start on the current day.
1025 Custom commands can set this variable in the options section."
1026 :group 'org-agenda-daily/weekly
1027 :type '(choice (const :tag "Today" nil)
1028 (integer :tag "Weekday No.")))
1030 (defcustom org-agenda-show-all-dates t
1031 "Non-nil means `org-agenda' shows every day in the selected range.
1032 When nil, only the days which actually have entries are shown."
1033 :group 'org-agenda-daily/weekly
1034 :type 'boolean)
1036 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1037 "Format string for displaying dates in the agenda.
1038 Used by the daily/weekly agenda and by the timeline. This should be
1039 a format string understood by `format-time-string', or a function returning
1040 the formatted date as a string. The function must take a single argument,
1041 a calendar-style date list like (month day year)."
1042 :group 'org-agenda-daily/weekly
1043 :type '(choice
1044 (string :tag "Format string")
1045 (function :tag "Function")))
1047 (defun org-agenda-format-date-aligned (date)
1048 "Format a date string for display in the daily/weekly agenda, or timeline.
1049 This function makes sure that dates are aligned for easy reading."
1050 (require 'cal-iso)
1051 (let* ((dayname (calendar-day-name date))
1052 (day (cadr date))
1053 (day-of-week (calendar-day-of-week date))
1054 (month (car date))
1055 (monthname (calendar-month-name month))
1056 (year (nth 2 date))
1057 (iso-week (org-days-to-iso-week
1058 (calendar-absolute-from-gregorian date)))
1059 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1060 (1- year))
1061 ((and (= month 12) (<= iso-week 1))
1062 (1+ year))
1063 (t year)))
1064 (weekstring (if (= day-of-week 1)
1065 (format " W%02d" iso-week)
1066 "")))
1067 (format "%-10s %2d %s %4d%s"
1068 dayname day monthname year weekstring)))
1070 (defcustom org-agenda-time-leading-zero nil
1071 "Non-nil means use leading zero for military times in agenda.
1072 For example, 9:30am would become 09:30 rather than 9:30."
1073 :group 'org-agenda-daily/weekly
1074 :version "24.1"
1075 :type 'boolean)
1077 (defcustom org-agenda-timegrid-use-ampm nil
1078 "When set, show AM/PM style timestamps on the timegrid."
1079 :group 'org-agenda
1080 :version "24.1"
1081 :type 'boolean)
1083 (defun org-agenda-time-of-day-to-ampm (time)
1084 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1085 (let* ((hour-number (string-to-number (substring time 0 -3)))
1086 (minute (substring time -2))
1087 (ampm "am"))
1088 (cond
1089 ((equal hour-number 12)
1090 (setq ampm "pm"))
1091 ((> hour-number 12)
1092 (setq ampm "pm")
1093 (setq hour-number (- hour-number 12))))
1094 (concat
1095 (if org-agenda-time-leading-zero
1096 (format "%02d" hour-number)
1097 (format "%02s" (number-to-string hour-number)))
1098 ":" minute ampm)))
1100 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1101 "Conditionally convert TIME to AM/PM format
1102 based on `org-agenda-timegrid-use-ampm'"
1103 (if org-agenda-timegrid-use-ampm
1104 (org-agenda-time-of-day-to-ampm time)
1105 time))
1107 (defcustom org-agenda-weekend-days '(6 0)
1108 "Which days are weekend?
1109 These days get the special face `org-agenda-date-weekend' in the agenda
1110 and timeline buffers."
1111 :group 'org-agenda-daily/weekly
1112 :type '(set :greedy t
1113 (const :tag "Monday" 1)
1114 (const :tag "Tuesday" 2)
1115 (const :tag "Wednesday" 3)
1116 (const :tag "Thursday" 4)
1117 (const :tag "Friday" 5)
1118 (const :tag "Saturday" 6)
1119 (const :tag "Sunday" 0)))
1121 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1122 "Non-nil means jump to today when moving a past date forward in time.
1123 When using S-right in the agenda to move a a date forward, and the date
1124 stamp currently points to the past, the first key press will move it
1125 to today. WHen nil, just move one day forward even if the date stays
1126 in the past."
1127 :group 'org-agenda-daily/weekly
1128 :version "24.1"
1129 :type 'boolean)
1131 (defcustom org-agenda-include-diary nil
1132 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1133 Custom commands can set this variable in the options section."
1134 :group 'org-agenda-daily/weekly
1135 :type 'boolean)
1137 (defcustom org-agenda-include-deadlines t
1138 "If non-nil, include entries within their deadline warning period.
1139 Custom commands can set this variable in the options section."
1140 :group 'org-agenda-daily/weekly
1141 :version "24.1"
1142 :type 'boolean)
1144 (defcustom org-agenda-repeating-timestamp-show-all t
1145 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1146 When set to a list of strings, only show occurrences of repeating
1147 stamps for these TODO keywords. When nil, only one occurrence is
1148 shown, either today or the nearest into the future."
1149 :group 'org-agenda-daily/weekly
1150 :type '(choice
1151 (const :tag "Show repeating stamps" t)
1152 (repeat :tag "Show repeating stamps for these TODO keywords"
1153 (string :tag "TODO Keyword"))
1154 (const :tag "Don't show repeating stamps" nil)))
1156 (defcustom org-scheduled-past-days 10000
1157 "No. of days to continue listing scheduled items that are not marked DONE.
1158 When an item is scheduled on a date, it shows up in the agenda on this
1159 day and will be listed until it is marked done for the number of days
1160 given here."
1161 :group 'org-agenda-daily/weekly
1162 :type 'integer)
1164 (defcustom org-agenda-log-mode-items '(closed clock)
1165 "List of items that should be shown in agenda log mode.
1166 This list may contain the following symbols:
1168 closed Show entries that have been closed on that day.
1169 clock Show entries that have received clocked time on that day.
1170 state Show all logged state changes.
1171 Note that instead of changing this variable, you can also press `C-u l' in
1172 the agenda to display all available LOG items temporarily."
1173 :group 'org-agenda-daily/weekly
1174 :type '(set :greedy t (const closed) (const clock) (const state)))
1176 (defcustom org-agenda-clock-consistency-checks
1177 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1178 :gap-ok-around ("4:00")
1179 :default-face ((:background "DarkRed") (:foreground "white"))
1180 :overlap-face nil :gap-face nil :no-end-time-face nil
1181 :long-face nil :short-face nil)
1182 "This is a property list, with the following keys:
1184 :max-duration Mark clocking chunks that are longer than this time.
1185 This is a time string like \"HH:MM\", or the number
1186 of minutes as an integer.
1188 :min-duration Mark clocking chunks that are shorter that this.
1189 This is a time string like \"HH:MM\", or the number
1190 of minutes as an integer.
1192 :max-gap Mark gaps between clocking chunks that are longer than
1193 this duration. A number of minutes, or a string
1194 like \"HH:MM\".
1196 :gap-ok-around List of times during the day which are usually not working
1197 times. When a gap is detected, but the gap contains any
1198 of these times, the gap is *not* reported. For example,
1199 if this is (\"4:00\" \"13:00\") then gaps that contain
1200 4:00 in the morning (i.e. the night) and 13:00
1201 (i.e. a typical lunch time) do not cause a warning.
1202 You should have at least one time during the night in this
1203 list, or otherwise the first task each morning will trigger
1204 a warning because it follows a long gap.
1206 Furthermore, the following properties can be used to define faces for
1207 issue display.
1209 :default-face the default face, if the specific face is undefined
1210 :overlap-face face for overlapping clocks
1211 :gap-face face for gaps between clocks
1212 :no-end-time-face face for incomplete clocks
1213 :long-face face for clock intervals that are too long
1214 :short-face face for clock intervals that are too short"
1215 :group 'org-agenda-daily/weekly
1216 :group 'org-clock
1217 :version "24.1"
1218 :type 'plist)
1220 (defcustom org-agenda-log-mode-add-notes t
1221 "Non-nil means add first line of notes to log entries in agenda views.
1222 If a log item like a state change or a clock entry is associated with
1223 notes, the first line of these notes will be added to the entry in the
1224 agenda display."
1225 :group 'org-agenda-daily/weekly
1226 :type 'boolean)
1228 (defcustom org-agenda-start-with-log-mode nil
1229 "The initial value of log-mode in a newly created agenda window.
1230 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1231 explanations on the possible values."
1232 :group 'org-agenda-startup
1233 :group 'org-agenda-daily/weekly
1234 :type '(choice (const :tag "Don't show log items" nil)
1235 (const :tag "Show only log items" 'only)
1236 (const :tag "Show all possible log items" 'clockcheck)
1237 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1238 (choice (const :tag "Show closed log items" 'closed)
1239 (const :tag "Show clocked log items" 'clock)
1240 (const :tag "Show all logged state changes" 'state)))))
1242 (defcustom org-agenda-start-with-clockreport-mode nil
1243 "The initial value of clockreport-mode in a newly created agenda window."
1244 :group 'org-agenda-startup
1245 :group 'org-agenda-daily/weekly
1246 :type 'boolean)
1248 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1249 "Property list with parameters for the clocktable in clockreport mode.
1250 This is the display mode that shows a clock table in the daily/weekly
1251 agenda, the properties for this dynamic block can be set here.
1252 The usual clocktable parameters are allowed here, but you cannot set
1253 the properties :name, :tstart, :tend, :block, and :scope - these will
1254 be overwritten to make sure the content accurately reflects the
1255 current display in the agenda."
1256 :group 'org-agenda-daily/weekly
1257 :type 'plist)
1259 (defcustom org-agenda-search-view-always-boolean nil
1260 "Non-nil means the search string is interpreted as individual parts.
1262 The search string for search view can either be interpreted as a phrase,
1263 or as a list of snippets that define a boolean search for a number of
1264 strings.
1266 When this is non-nil, the string will be split on whitespace, and each
1267 snippet will be searched individually, and all must match in order to
1268 select an entry. A snippet is then a single string of non-white
1269 characters, or a string in double quotes, or a regexp in {} braces.
1270 If a snippet is preceded by \"-\", the snippet must *not* match.
1271 \"+\" is syntactic sugar for positive selection. Each snippet may
1272 be found as a full word or a partial word, but see the variable
1273 `org-agenda-search-view-force-full-words'.
1275 When this is nil, search will look for the entire search phrase as one,
1276 with each space character matching any amount of whitespace, including
1277 line breaks.
1279 Even when this is nil, you can still switch to Boolean search dynamically
1280 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1281 is a regexp marked with braces like \"{abc}\", this will also switch to
1282 boolean search."
1283 :group 'org-agenda-search-view
1284 :version "24.1"
1285 :type 'boolean)
1287 (if (fboundp 'defvaralias)
1288 (defvaralias 'org-agenda-search-view-search-words-only
1289 'org-agenda-search-view-always-boolean))
1291 (defcustom org-agenda-search-view-force-full-words nil
1292 "Non-nil means, search words must be matches as complete words.
1293 When nil, they may also match part of a word."
1294 :group 'org-agenda-search-view
1295 :version "24.1"
1296 :type 'boolean)
1298 (defgroup org-agenda-time-grid nil
1299 "Options concerning the time grid in the Org-mode Agenda."
1300 :tag "Org Agenda Time Grid"
1301 :group 'org-agenda)
1303 (defcustom org-agenda-search-headline-for-time t
1304 "Non-nil means search headline for a time-of-day.
1305 If the headline contains a time-of-day in one format or another, it will
1306 be used to sort the entry into the time sequence of items for a day.
1307 Some people have time stamps in the headline that refer to the creation
1308 time or so, and then this produces an unwanted side effect. If this is
1309 the case for your, use this variable to turn off searching the headline
1310 for a time."
1311 :group 'org-agenda-time-grid
1312 :type 'boolean)
1314 (defcustom org-agenda-use-time-grid t
1315 "Non-nil means show a time grid in the agenda schedule.
1316 A time grid is a set of lines for specific times (like every two hours between
1317 8:00 and 20:00). The items scheduled for a day at specific times are
1318 sorted in between these lines.
1319 For details about when the grid will be shown, and what it will look like, see
1320 the variable `org-agenda-time-grid'."
1321 :group 'org-agenda-time-grid
1322 :type 'boolean)
1324 (defcustom org-agenda-time-grid
1325 '((daily today require-timed)
1326 "----------------"
1327 (800 1000 1200 1400 1600 1800 2000))
1329 "The settings for time grid for agenda display.
1330 This is a list of three items. The first item is again a list. It contains
1331 symbols specifying conditions when the grid should be displayed:
1333 daily if the agenda shows a single day
1334 weekly if the agenda shows an entire week
1335 today show grid on current date, independent of daily/weekly display
1336 require-timed show grid only if at least one item has a time specification
1338 The second item is a string which will be placed behind the grid time.
1340 The third item is a list of integers, indicating the times that should have
1341 a grid line."
1342 :group 'org-agenda-time-grid
1343 :type
1344 '(list
1345 (set :greedy t :tag "Grid Display Options"
1346 (const :tag "Show grid in single day agenda display" daily)
1347 (const :tag "Show grid in weekly agenda display" weekly)
1348 (const :tag "Always show grid for today" today)
1349 (const :tag "Show grid only if any timed entries are present"
1350 require-timed)
1351 (const :tag "Skip grid times already present in an entry"
1352 remove-match))
1353 (string :tag "Grid String")
1354 (repeat :tag "Grid Times" (integer :tag "Time"))))
1356 (defcustom org-agenda-show-current-time-in-grid t
1357 "Non-nil means show the current time in the time grid."
1358 :group 'org-agenda-time-grid
1359 :version "24.1"
1360 :type 'boolean)
1362 (defcustom org-agenda-current-time-string
1363 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1364 "The string for the current time marker in the agenda."
1365 :group 'org-agenda-time-grid
1366 :version "24.1"
1367 :type 'string)
1369 (defgroup org-agenda-sorting nil
1370 "Options concerning sorting in the Org-mode Agenda."
1371 :tag "Org Agenda Sorting"
1372 :group 'org-agenda)
1374 (defcustom org-agenda-sorting-strategy
1375 '((agenda habit-down time-up priority-down category-keep)
1376 (todo priority-down category-keep)
1377 (tags priority-down category-keep)
1378 (search category-keep))
1379 "Sorting structure for the agenda items of a single day.
1380 This is a list of symbols which will be used in sequence to determine
1381 if an entry should be listed before another entry. The following
1382 symbols are recognized:
1384 time-up Put entries with time-of-day indications first, early first
1385 time-down Put entries with time-of-day indications first, late first
1386 category-keep Keep the default order of categories, corresponding to the
1387 sequence in `org-agenda-files'.
1388 category-up Sort alphabetically by category, A-Z.
1389 category-down Sort alphabetically by category, Z-A.
1390 tag-up Sort alphabetically by last tag, A-Z.
1391 tag-down Sort alphabetically by last tag, Z-A.
1392 priority-up Sort numerically by priority, high priority last.
1393 priority-down Sort numerically by priority, high priority first.
1394 todo-state-up Sort by todo state, tasks that are done last.
1395 todo-state-down Sort by todo state, tasks that are done first.
1396 effort-up Sort numerically by estimated effort, high effort last.
1397 effort-down Sort numerically by estimated effort, high effort first.
1398 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1399 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1400 habit-up Put entries that are habits first
1401 habit-down Put entries that are habits last
1402 alpha-up Sort headlines alphabetically
1403 alpha-down Sort headlines alphabetically, reversed
1405 The different possibilities will be tried in sequence, and testing stops
1406 if one comparison returns a \"not-equal\". For example, the default
1407 '(time-up category-keep priority-down)
1408 means: Pull out all entries having a specified time of day and sort them,
1409 in order to make a time schedule for the current day the first thing in the
1410 agenda listing for the day. Of the entries without a time indication, keep
1411 the grouped in categories, don't sort the categories, but keep them in
1412 the sequence given in `org-agenda-files'. Within each category sort by
1413 priority.
1415 Leaving out `category-keep' would mean that items will be sorted across
1416 categories by priority.
1418 Instead of a single list, this can also be a set of list for specific
1419 contents, with a context symbol in the car of the list, any of
1420 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1422 Custom commands can bind this variable in the options section."
1423 :group 'org-agenda-sorting
1424 :type `(choice
1425 (repeat :tag "General" ,org-sorting-choice)
1426 (list :tag "Individually"
1427 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1428 (repeat ,org-sorting-choice))
1429 (cons (const :tag "Strategy for TODO lists" todo)
1430 (repeat ,org-sorting-choice))
1431 (cons (const :tag "Strategy for Tags matches" tags)
1432 (repeat ,org-sorting-choice))
1433 (cons (const :tag "Strategy for search matches" search)
1434 (repeat ,org-sorting-choice)))))
1436 (defcustom org-agenda-cmp-user-defined nil
1437 "A function to define the comparison `user-defined'.
1438 This function must receive two arguments, agenda entry a and b.
1439 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1440 the user comparison, return nil.
1441 When this is defined, you can make `user-defined-up' and `user-defined-down'
1442 part of an agenda sorting strategy."
1443 :group 'org-agenda-sorting
1444 :type 'symbol)
1446 (defcustom org-sort-agenda-notime-is-late t
1447 "Non-nil means items without time are considered late.
1448 This is only relevant for sorting. When t, items which have no explicit
1449 time like 15:30 will be considered as 99:01, i.e. later than any items which
1450 do have a time. When nil, the default time is before 0:00. You can use this
1451 option to decide if the schedule for today should come before or after timeless
1452 agenda entries."
1453 :group 'org-agenda-sorting
1454 :type 'boolean)
1456 (defcustom org-sort-agenda-noeffort-is-high t
1457 "Non-nil means items without effort estimate are sorted as high effort.
1458 This also applies when filtering an agenda view with respect to the
1459 < or > effort operator. Then, tasks with no effort defined will be treated
1460 as tasks with high effort.
1461 When nil, such items are sorted as 0 minutes effort."
1462 :group 'org-agenda-sorting
1463 :type 'boolean)
1465 (defgroup org-agenda-line-format nil
1466 "Options concerning the entry prefix in the Org-mode agenda display."
1467 :tag "Org Agenda Line Format"
1468 :group 'org-agenda)
1470 (defcustom org-agenda-prefix-format
1471 '((agenda . " %i %-12:c%?-12t% s")
1472 (timeline . " % s")
1473 (todo . " %i %-12:c")
1474 (tags . " %i %-12:c")
1475 (search . " %i %-12:c"))
1476 "Format specifications for the prefix of items in the agenda views.
1477 An alist with five entries, each for the different agenda types. The
1478 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1479 The values are format strings.
1481 This format works similar to a printf format, with the following meaning:
1483 %c the category of the item, \"Diary\" for entries from the diary,
1484 or as given by the CATEGORY keyword or derived from the file name
1485 %e the effort required by the item
1486 %i the icon category of the item, see `org-agenda-category-icon-alist'
1487 %T the last tag of the item (ignore inherited tags, which come first)
1488 %t the HH:MM time-of-day specification if one applies to the entry
1489 %s Scheduling/Deadline information, a short string
1490 %(expression) Eval EXPRESSION and replace the control string
1491 by the result
1493 All specifiers work basically like the standard `%s' of printf, but may
1494 contain two additional characters: a question mark just after the `%'
1495 and a whitespace/punctuation character just before the final letter.
1497 If the first character after `%' is a question mark, the entire field
1498 will only be included if the corresponding value applies to the current
1499 entry. This is useful for fields which should have fixed width when
1500 present, but zero width when absent. For example, \"%?-12t\" will
1501 result in a 12 character time field if a time of the day is specified,
1502 but will completely disappear in entries which do not contain a time.
1504 If there is punctuation or whitespace character just before the final
1505 format letter, this character will be appended to the field value if
1506 the value is not empty. For example, the format \"%-12:c\" leads to
1507 \"Diary: \" if the category is \"Diary\". If the category were be
1508 empty, no additional colon would be inserted.
1510 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1511 which means:
1513 - Indent the line with two space characters
1514 - Give the category a 12 chars wide field, padded with whitespace on
1515 the right (because of `-'). Append a colon if there is a category
1516 (because of `:').
1517 - If there is a time-of-day, put it into a 12 chars wide field. If no
1518 time, don't put in an empty field, just skip it (because of '?').
1519 - Finally, put the scheduling information.
1521 See also the variables `org-agenda-remove-times-when-in-prefix' and
1522 `org-agenda-remove-tags'.
1524 Custom commands can set this variable in the options section."
1525 :type '(choice
1526 (string :tag "General format")
1527 (list :greedy t :tag "View dependent"
1528 (cons (const agenda) (string :tag "Format"))
1529 (cons (const timeline) (string :tag "Format"))
1530 (cons (const todo) (string :tag "Format"))
1531 (cons (const tags) (string :tag "Format"))
1532 (cons (const search) (string :tag "Format"))))
1533 :group 'org-agenda-line-format)
1535 (defvar org-prefix-format-compiled nil
1536 "The compiled prefix format and associated variables.
1537 This is a list where first element is a list of variable bindings, and second
1538 element is the compiled format expression. See the variable
1539 `org-agenda-prefix-format'.")
1541 (defcustom org-agenda-todo-keyword-format "%-1s"
1542 "Format for the TODO keyword in agenda lines.
1543 Set this to something like \"%-12s\" if you want all TODO keywords
1544 to occupy a fixed space in the agenda display."
1545 :group 'org-agenda-line-format
1546 :type 'string)
1548 (defcustom org-agenda-diary-sexp-prefix nil
1549 "A regexp that matches part of a diary sexp entry
1550 which should be treated as scheduling/deadline information in
1551 `org-agenda'.
1553 For example, you can use this to extract the `diary-remind-message' from
1554 `diary-remind' entries."
1555 :group 'org-agenda-line-format
1556 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1558 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1559 "Text preceding timerange entries in the agenda view.
1560 This is a list with two strings. The first applies when the range
1561 is entirely on one day. The second applies if the range spans several days.
1562 The strings may have two \"%d\" format specifiers which will be filled
1563 with the sequence number of the days, and the total number of days in the
1564 range, respectively."
1565 :group 'org-agenda-line-format
1566 :type '(list
1567 (string :tag "Deadline today ")
1568 (choice :tag "Deadline relative"
1569 (string :tag "Format string")
1570 (function))))
1572 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1573 "Text preceding scheduled items in the agenda view.
1574 This is a list with two strings. The first applies when the item is
1575 scheduled on the current day. The second applies when it has been scheduled
1576 previously, it may contain a %d indicating that this is the nth time that
1577 this item is scheduled, due to automatic rescheduling of unfinished items
1578 for the following day. So this number is one larger than the number of days
1579 that passed since this item was scheduled first."
1580 :group 'org-agenda-line-format
1581 :type '(list
1582 (string :tag "Scheduled today ")
1583 (string :tag "Scheduled previously")))
1585 (defcustom org-agenda-inactive-leader "["
1586 "Text preceding item pulled into the agenda by inactive time stamps.
1587 These entries are added to the agenda when pressing \"[\"."
1588 :group 'org-agenda-line-format
1589 :version "24.1"
1590 :type '(list
1591 (string :tag "Scheduled today ")
1592 (string :tag "Scheduled previously")))
1594 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1595 "Text preceding deadline items in the agenda view.
1596 This is a list with two strings. The first applies when the item has its
1597 deadline on the current day. The second applies when it is in the past or
1598 in the future, it may contain %d to capture how many days away the deadline
1599 is (was)."
1600 :group 'org-agenda-line-format
1601 :type '(list
1602 (string :tag "Deadline today ")
1603 (choice :tag "Deadline relative"
1604 (string :tag "Format string")
1605 (function))))
1607 (defcustom org-agenda-remove-times-when-in-prefix t
1608 "Non-nil means remove duplicate time specifications in agenda items.
1609 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1610 time-of-day specification in a headline or diary entry is extracted and
1611 placed into the prefix. If this option is non-nil, the original specification
1612 \(a timestamp or -range, or just a plain time(range) specification like
1613 11:30-4pm) will be removed for agenda display. This makes the agenda less
1614 cluttered.
1615 The option can be t or nil. It may also be the symbol `beg', indicating
1616 that the time should only be removed when it is located at the beginning of
1617 the headline/diary entry."
1618 :group 'org-agenda-line-format
1619 :type '(choice
1620 (const :tag "Always" t)
1621 (const :tag "Never" nil)
1622 (const :tag "When at beginning of entry" beg)))
1624 (defcustom org-agenda-remove-timeranges-from-blocks nil
1625 "Non-nil means remove time ranges specifications in agenda
1626 items that span on several days."
1627 :group 'org-agenda-line-format
1628 :version "24.1"
1629 :type 'boolean)
1631 (defcustom org-agenda-default-appointment-duration nil
1632 "Default duration for appointments that only have a starting time.
1633 When nil, no duration is specified in such cases.
1634 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1635 :group 'org-agenda-line-format
1636 :type '(choice
1637 (integer :tag "Minutes")
1638 (const :tag "No default duration")))
1640 (defcustom org-agenda-show-inherited-tags t
1641 "Non-nil means show inherited tags in each agenda line."
1642 :group 'org-agenda-line-format
1643 :type 'boolean)
1645 (defcustom org-agenda-hide-tags-regexp nil
1646 "Regular expression used to filter away specific tags in agenda views.
1647 This means that these tags will be present, but not be shown in the agenda
1648 line. Secondary filtering will still work on the hidden tags.
1649 Nil means don't hide any tags."
1650 :group 'org-agenda-line-format
1651 :type '(choice
1652 (const :tag "Hide none" nil)
1653 (string :tag "Regexp ")))
1655 (defcustom org-agenda-remove-tags nil
1656 "Non-nil means remove the tags from the headline copy in the agenda.
1657 When this is the symbol `prefix', only remove tags when
1658 `org-agenda-prefix-format' contains a `%T' specifier."
1659 :group 'org-agenda-line-format
1660 :type '(choice
1661 (const :tag "Always" t)
1662 (const :tag "Never" nil)
1663 (const :tag "When prefix format contains %T" prefix)))
1665 (if (fboundp 'defvaralias)
1666 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1667 'org-agenda-remove-tags))
1669 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1670 "Shift tags in agenda items to this column.
1671 If this number is positive, it specifies the column. If it is negative,
1672 it means that the tags should be flushright to that column. For example,
1673 -80 works well for a normal 80 character screen."
1674 :group 'org-agenda-line-format
1675 :type 'integer)
1677 (if (fboundp 'defvaralias)
1678 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1680 (defcustom org-agenda-fontify-priorities 'cookies
1681 "Non-nil means highlight low and high priorities in agenda.
1682 When t, the highest priority entries are bold, lowest priority italic.
1683 However, settings in `org-priority-faces' will overrule these faces.
1684 When this variable is the symbol `cookies', only fontify the
1685 cookies, not the entire task.
1686 This may also be an association list of priority faces, whose
1687 keys are the character values of `org-highest-priority',
1688 `org-default-priority', and `org-lowest-priority' (the default values
1689 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1690 color as a string, or a list like `(:background \"Red\")'.
1691 If it is a color, the variable `org-faces-easy-properties'
1692 determines if it is a foreground or a background color."
1693 :group 'org-agenda-line-format
1694 :type '(choice
1695 (const :tag "Never" nil)
1696 (const :tag "Defaults" t)
1697 (const :tag "Cookies only" cookies)
1698 (repeat :tag "Specify"
1699 (list (character :tag "Priority" :value ?A)
1700 (choice :tag "Face "
1701 (string :tag "Color")
1702 (sexp :tag "Face"))))))
1704 (defcustom org-agenda-day-face-function nil
1705 "Function called to determine what face should be used to display a day.
1706 The only argument passed to that function is the day. It should
1707 returns a face, or nil if does not want to specify a face and let
1708 the normal rules apply."
1709 :group 'org-agenda-line-format
1710 :version "24.1"
1711 :type 'function)
1713 (defcustom org-agenda-category-icon-alist nil
1714 "Alist of category icon to be displayed in agenda views.
1716 Each entry should have the following format:
1718 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1720 Where CATEGORY-REGEXP is a regexp matching the categories where
1721 the icon should be displayed.
1722 FILE-OR-DATA either a file path or a string containing image data.
1724 The other fields can be omitted safely if not needed:
1725 TYPE indicates the image type.
1726 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1727 image data.
1728 PROPS are additional image attributes to assign to the image,
1729 like, e.g. `:ascent center'.
1731 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1733 If you want to set the display properties yourself, just put a
1734 list as second element:
1736 (CATEGORY-REGEXP (MY PROPERTY LIST))
1738 For example, to display a 16px horizontal space for Emacs
1739 category, you can use:
1741 (\"Emacs\" '(space . (:width (16))))"
1742 :group 'org-agenda-line-format
1743 :version "24.1"
1744 :type '(alist :key-type (string :tag "Regexp matching category")
1745 :value-type (choice (list :tag "Icon"
1746 (string :tag "File or data")
1747 (symbol :tag "Type")
1748 (boolean :tag "Data?")
1749 (repeat :tag "Extra image properties" :inline t symbol))
1750 (list :tag "Display properties" sexp))))
1752 (defgroup org-agenda-column-view nil
1753 "Options concerning column view in the agenda."
1754 :tag "Org Agenda Column View"
1755 :group 'org-agenda)
1757 (defcustom org-agenda-columns-show-summaries t
1758 "Non-nil means show summaries for columns displayed in the agenda view."
1759 :group 'org-agenda-column-view
1760 :type 'boolean)
1762 (defcustom org-agenda-columns-compute-summary-properties t
1763 "Non-nil means recompute all summary properties before column view.
1764 When column view in the agenda is listing properties that have a summary
1765 operator, it can go to all relevant buffers and recompute the summaries
1766 there. This can mean overhead for the agenda column view, but is necessary
1767 to have thing up to date.
1768 As a special case, a CLOCKSUM property also makes sure that the clock
1769 computations are current."
1770 :group 'org-agenda-column-view
1771 :type 'boolean)
1773 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1774 "Non-nil means the duration of an appointment will add to day effort.
1775 The property to which appointment durations will be added is the one given
1776 in the option `org-effort-property'. If an appointment does not have
1777 an end time, `org-agenda-default-appointment-duration' will be used. If that
1778 is not set, an appointment without end time will not contribute to the time
1779 estimate."
1780 :group 'org-agenda-column-view
1781 :type 'boolean)
1783 (defcustom org-agenda-auto-exclude-function nil
1784 "A function called with a tag to decide if it is filtered on '/ RET'.
1785 The sole argument to the function, which is called once for each
1786 possible tag, is a string giving the name of the tag. The
1787 function should return either nil if the tag should be included
1788 as normal, or \"-<TAG>\" to exclude the tag.
1789 Note that for the purpose of tag filtering, only the lower-case version of
1790 all tags will be considered, so that this function will only ever see
1791 the lower-case version of all tags."
1792 :group 'org-agenda
1793 :type 'function)
1795 (defcustom org-agenda-bulk-custom-functions nil
1796 "Alist of characters and custom functions for bulk actions.
1797 For example, this value makes those two functions available:
1799 '((?R set-category)
1800 (?C bulk-cut))
1802 With selected entries in an agenda buffer, `B R' will call
1803 the custom function `set-category' on the selected entries.
1804 Note that functions in this alist don't need to be quoted."
1805 :type 'alist
1806 :version "24.1"
1807 :group 'org-agenda)
1809 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1810 "Execute BODY with point at location given by `org-hd-marker' property.
1811 If STRING is non-nil, the text property will be fetched from position 0
1812 in that string. If STRING is nil, it will be fetched from the beginning
1813 of the current line."
1814 (org-with-gensyms (marker)
1815 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1816 'org-hd-marker ,string)))
1817 (with-current-buffer (marker-buffer ,marker)
1818 (save-excursion
1819 (goto-char ,marker)
1820 ,@body)))))
1821 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1823 (defun org-add-agenda-custom-command (entry)
1824 "Replace or add a command in `org-agenda-custom-commands'.
1825 This is mostly for hacking and trying a new command - once the command
1826 works you probably want to add it to `org-agenda-custom-commands' for good."
1827 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1828 (if ass
1829 (setcdr ass (cdr entry))
1830 (push entry org-agenda-custom-commands))))
1832 ;;; Define the org-agenda-mode
1834 (defvar org-agenda-mode-map (make-sparse-keymap)
1835 "Keymap for `org-agenda-mode'.")
1836 (if (fboundp 'defvaralias)
1837 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1839 (defvar org-agenda-menu) ; defined later in this file.
1840 (defvar org-agenda-restrict) ; defined later in this file.
1841 (defvar org-agenda-follow-mode nil)
1842 (defvar org-agenda-entry-text-mode nil)
1843 (defvar org-agenda-clockreport-mode nil)
1844 (defvar org-agenda-show-log nil)
1845 (defvar org-agenda-redo-command nil)
1846 (defvar org-agenda-query-string nil)
1847 (defvar org-agenda-mode-hook nil
1848 "Hook for `org-agenda-mode', run after the mode is turned on.")
1849 (defvar org-agenda-type nil)
1850 (defvar org-agenda-force-single-file nil)
1851 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1854 ;;; Multiple agenda buffers support
1856 ;;;###autoload
1857 (defun org-toggle-sticky-agenda (&optional arg)
1858 "Toggle `org-agenda-sticky'."
1859 (interactive "P")
1860 (let ((new-value (if arg
1861 (> (prefix-numeric-value arg) 0)
1862 (not org-agenda-sticky))))
1863 (if (equal new-value org-agenda-sticky)
1864 (and (org-called-interactively-p 'interactive)
1865 (message "Sticky agenda was already %s"
1866 (if org-agenda-sticky "enabled" "disabled")))
1867 (setq org-agenda-sticky new-value)
1868 (org-agenda-kill-all-agenda-buffers)
1869 (and (org-called-interactively-p 'interactive)
1870 (message "Sticky agenda was %s"
1871 (if org-agenda-sticky "enabled" "disabled"))))))
1873 (defcustom org-agenda-sticky nil
1874 "Non-nil means agenda q key will bury agenda buffers.
1875 Agenda commands will then show existing buffer instead of generating new ones.
1876 When nil, `q' will kill the single agenda buffer."
1877 :group 'org-agenda
1878 :type 'boolean
1879 :set (lambda (var val)
1880 (if (boundp var)
1881 (org-toggle-sticky-agenda (if val 1 0))
1882 (set var val))))
1884 (defvar org-agenda-buffer nil
1885 "Agenda buffer currently being generated.")
1887 (defvar org-agenda-last-prefix-arg nil)
1888 (defvar org-agenda-this-buffer-name nil)
1889 (defvar org-agenda-doing-sticky-redo nil)
1890 (defvar org-agenda-this-buffer-is-sticky nil)
1892 (defconst org-agenda-local-vars
1893 '(org-agenda-this-buffer-name
1894 org-agenda-undo-list
1895 org-agenda-pending-undo-list
1896 org-agenda-follow-mode
1897 org-agenda-entry-text-mode
1898 org-agenda-clockreport-mode
1899 org-agenda-show-log
1900 org-agenda-redo-command
1901 org-agenda-query-string
1902 org-agenda-type
1903 org-agenda-bulk-marked-entries
1904 org-agenda-undo-has-started-in
1905 org-agenda-last-arguments
1906 org-agenda-info
1907 org-agenda-tag-filter-overlays
1908 org-agenda-cat-filter-overlays
1909 org-pre-agenda-window-conf
1910 org-agenda-columns-active
1911 org-agenda-tag-filter
1912 org-agenda-category-filter
1913 org-agenda-markers
1914 org-agenda-last-search-view-search-was-boolean
1915 org-agenda-filtered-by-category
1916 org-agenda-filter-form
1917 org-agenda-show-window
1918 org-agenda-cycle-counter
1919 org-agenda-last-prefix-arg)
1920 "Variables that must be local in agenda buffers to allow multiple buffers.")
1922 (defun org-agenda-mode ()
1923 "Mode for time-sorted view on action items in Org-mode files.
1925 The following commands are available:
1927 \\{org-agenda-mode-map}"
1928 (interactive)
1929 (cond (org-agenda-doing-sticky-redo
1930 ;; Refreshing sticky agenda-buffer
1932 ;; Preserve the value of `org-agenda-local-vars' variables,
1933 ;; while letting `kill-all-local-variables' kill the rest
1934 (let ((save (buffer-local-variables)))
1935 (kill-all-local-variables)
1936 (mapc 'make-local-variable org-agenda-local-vars)
1937 (dolist (elem save)
1938 (let ((var (car elem))
1939 (val (cdr elem)))
1940 (when (and val
1941 (member var org-agenda-local-vars))
1942 (set var val)))))
1943 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1944 (org-agenda-sticky
1945 ;; Creating a sticky Agenda buffer for the first time
1946 (kill-all-local-variables)
1947 (mapc 'make-local-variable org-agenda-local-vars)
1948 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1950 ;; Creating a non-sticky agenda buffer
1951 (kill-all-local-variables)
1952 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1953 (setq org-agenda-undo-list nil
1954 org-agenda-pending-undo-list nil
1955 org-agenda-bulk-marked-entries nil)
1956 (setq major-mode 'org-agenda-mode)
1957 ;; Keep global-font-lock-mode from turning on font-lock-mode
1958 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1959 (setq mode-name "Org-Agenda")
1960 (use-local-map org-agenda-mode-map)
1961 (easy-menu-add org-agenda-menu)
1962 (if org-startup-truncated (setq truncate-lines t))
1963 (org-set-local 'line-move-visual nil)
1964 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1965 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1966 ;; Make sure properties are removed when copying text
1967 (make-local-variable 'filter-buffer-substring-functions)
1968 (add-hook 'filter-buffer-substring-functions
1969 (lambda (fun start end delete)
1970 (substring-no-properties (funcall fun start end delete))))
1971 (unless org-agenda-keep-modes
1972 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1973 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1974 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1975 org-agenda-show-log org-agenda-start-with-log-mode))
1977 (easy-menu-change
1978 '("Agenda") "Agenda Files"
1979 (append
1980 (list
1981 (vector
1982 (if (get 'org-agenda-files 'org-restrict)
1983 "Restricted to single file"
1984 "Edit File List")
1985 '(org-edit-agenda-file-list)
1986 (not (get 'org-agenda-files 'org-restrict)))
1987 "--")
1988 (mapcar 'org-file-menu-entry (org-agenda-files))))
1989 (org-agenda-set-mode-name)
1990 (apply
1991 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1992 (list 'org-agenda-mode-hook)))
1994 (substitute-key-definition 'undo 'org-agenda-undo
1995 org-agenda-mode-map global-map)
1996 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1997 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1998 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1999 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2000 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2001 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2002 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2003 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2004 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2005 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2006 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2007 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2008 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2009 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2010 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2011 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2012 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2013 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2014 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2015 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2016 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2017 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2018 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2019 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2020 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2021 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2022 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2023 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2024 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2025 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2026 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2027 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2028 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2029 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2030 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2031 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2032 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2033 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2034 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2035 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2036 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2037 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2038 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2039 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2040 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2041 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2043 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2044 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2045 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2046 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2047 (while l (org-defkey org-agenda-mode-map
2048 (int-to-string (pop l)) 'digit-argument)))
2050 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2051 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2052 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2053 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2054 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2055 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2056 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2057 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2058 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2059 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2060 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2061 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2062 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2063 'org-clock-modify-effort-estimate)
2064 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2065 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2066 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2067 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2068 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2069 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2070 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2071 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2072 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2073 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2074 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2075 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2076 (substitute-key-definition 'next-line 'org-agenda-next-line
2077 org-agenda-mode-map global-map)
2078 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2079 org-agenda-mode-map global-map)
2080 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2081 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2082 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2083 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2084 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2085 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2086 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2087 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2088 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2089 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2090 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2091 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2093 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2094 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2095 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2096 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2097 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2098 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2099 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2100 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2101 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2102 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2103 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2104 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2105 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2106 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2107 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2108 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2109 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2111 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2112 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2113 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2114 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2115 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2116 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2117 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2118 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2119 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2120 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2121 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2124 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2125 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2126 (when org-agenda-mouse-1-follows-link
2127 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2128 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2129 '("Agenda"
2130 ("Agenda Files")
2131 "--"
2132 ("Agenda Dates"
2133 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2134 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2135 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2136 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2137 "--"
2138 ("View"
2139 ["Day View" org-agenda-day-view
2140 :active (org-agenda-check-type nil 'agenda)
2141 :style radio :selected (eq org-agenda-current-span 'day)
2142 :keys "v d (or just d)"]
2143 ["Week View" org-agenda-week-view
2144 :active (org-agenda-check-type nil 'agenda)
2145 :style radio :selected (eq org-agenda-current-span 'week)
2146 :keys "v w (or just w)"]
2147 ["Month View" org-agenda-month-view
2148 :active (org-agenda-check-type nil 'agenda)
2149 :style radio :selected (eq org-agenda-current-span 'month)
2150 :keys "v m"]
2151 ["Year View" org-agenda-year-view
2152 :active (org-agenda-check-type nil 'agenda)
2153 :style radio :selected (eq org-agenda-current-span 'year)
2154 :keys "v y"]
2155 "--"
2156 ["Include Diary" org-agenda-toggle-diary
2157 :style toggle :selected org-agenda-include-diary
2158 :active (org-agenda-check-type nil 'agenda)]
2159 ["Include Deadlines" org-agenda-toggle-deadlines
2160 :style toggle :selected org-agenda-include-deadlines
2161 :active (org-agenda-check-type nil 'agenda)]
2162 ["Use Time Grid" org-agenda-toggle-time-grid
2163 :style toggle :selected org-agenda-use-time-grid
2164 :active (org-agenda-check-type nil 'agenda)]
2165 "--"
2166 ["Show clock report" org-agenda-clockreport-mode
2167 :style toggle :selected org-agenda-clockreport-mode
2168 :active (org-agenda-check-type nil 'agenda)]
2169 ["Show some entry text" org-agenda-entry-text-mode
2170 :style toggle :selected org-agenda-entry-text-mode
2171 :active t]
2172 "--"
2173 ["Show Logbook entries" org-agenda-log-mode
2174 :style toggle :selected org-agenda-show-log
2175 :active (org-agenda-check-type nil 'agenda 'timeline)
2176 :keys "v l (or just l)"]
2177 ["Include archived trees" org-agenda-archives-mode
2178 :style toggle :selected org-agenda-archives-mode :active t
2179 :keys "v a"]
2180 ["Include archive files" (org-agenda-archives-mode t)
2181 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2182 :keys "v A"]
2183 "--"
2184 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2185 ["Write view to file" org-agenda-write t]
2186 ["Rebuild buffer" org-agenda-redo t]
2187 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2188 "--"
2189 ["Show original entry" org-agenda-show t]
2190 ["Go To (other window)" org-agenda-goto t]
2191 ["Go To (this window)" org-agenda-switch-to t]
2192 ["Follow Mode" org-agenda-follow-mode
2193 :style toggle :selected org-agenda-follow-mode :active t]
2194 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2195 "--"
2196 ("TODO"
2197 ["Cycle TODO" org-agenda-todo t]
2198 ["Next TODO set" org-agenda-todo-nextset t]
2199 ["Previous TODO set" org-agenda-todo-previousset t]
2200 ["Add note" org-agenda-add-note t])
2201 ("Archive/Refile/Delete"
2202 ["Archive default" org-agenda-archive-default t]
2203 ["Archive default" org-agenda-archive-default-with-confirmation t]
2204 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2205 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2206 ["Archive subtree" org-agenda-archive t]
2207 "--"
2208 ["Refile" org-agenda-refile t]
2209 "--"
2210 ["Delete subtree" org-agenda-kill t])
2211 ("Bulk action"
2212 ["Mark entry" org-agenda-bulk-mark t]
2213 ["Mark all" org-agenda-bulk-mark-all t]
2214 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2215 ["Unmark entry" org-agenda-bulk-unmark t]
2216 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2217 ["Act on all marked" org-agenda-bulk-action t]
2218 "--"
2219 ("Tags and Properties"
2220 ["Show all Tags" org-agenda-show-tags t]
2221 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2222 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2223 "--"
2224 ["Column View" org-columns t])
2225 ("Deadline/Schedule"
2226 ["Schedule" org-agenda-schedule t]
2227 ["Set Deadline" org-agenda-deadline t]
2228 "--"
2229 ["Mark item" org-agenda-action :active t :keys "k m"]
2230 ["Show mark item" org-agenda-action :active t :keys "k v"]
2231 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2232 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2233 "--"
2234 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2235 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2236 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2237 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2238 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2239 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2240 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2241 ("Clock and Effort"
2242 ["Clock in" org-agenda-clock-in t]
2243 ["Clock out" org-agenda-clock-out t]
2244 ["Clock cancel" org-agenda-clock-cancel t]
2245 ["Goto running clock" org-clock-goto t]
2246 "--"
2247 ["Set Effort" org-agenda-set-effort t]
2248 ["Change clocked effort" org-clock-modify-effort-estimate
2249 (org-clock-is-active)])
2250 ("Priority"
2251 ["Set Priority" org-agenda-priority t]
2252 ["Increase Priority" org-agenda-priority-up t]
2253 ["Decrease Priority" org-agenda-priority-down t]
2254 ["Show Priority" org-agenda-show-priority t])
2255 ("Calendar/Diary"
2256 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2257 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2258 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2259 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2262 "--"
2263 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2264 "--"
2265 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2266 "--"
2267 ("MobileOrg"
2268 ["Push Files and Views" org-mobile-push t]
2269 ["Get Captured and Flagged" org-mobile-pull t]
2270 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2271 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2272 "--"
2273 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2274 "--"
2275 ["Quit" org-agenda-quit t]
2276 ["Exit and Release Buffers" org-agenda-exit t]
2279 ;;; Agenda undo
2281 (defvar org-agenda-allow-remote-undo t
2282 "Non-nil means allow remote undo from the agenda buffer.")
2283 (defvar org-agenda-undo-list nil
2284 "List of undoable operations in the agenda since last refresh.")
2285 (defvar org-agenda-undo-has-started-in nil
2286 "Buffers that have already seen `undo-start' in the current undo sequence.")
2287 (defvar org-agenda-pending-undo-list nil
2288 "In a series of undo commands, this is the list of remaining undo items.")
2290 (defun org-agenda-undo ()
2291 "Undo a remote editing step in the agenda.
2292 This undoes changes both in the agenda buffer and in the remote buffer
2293 that have been changed along."
2294 (interactive)
2295 (or org-agenda-allow-remote-undo
2296 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2297 (if (not (eq this-command last-command))
2298 (setq org-agenda-undo-has-started-in nil
2299 org-agenda-pending-undo-list org-agenda-undo-list))
2300 (if (not org-agenda-pending-undo-list)
2301 (error "No further undo information"))
2302 (let* ((entry (pop org-agenda-pending-undo-list))
2303 buf line cmd rembuf)
2304 (setq cmd (pop entry) line (pop entry))
2305 (setq rembuf (nth 2 entry))
2306 (org-with-remote-undo rembuf
2307 (while (bufferp (setq buf (pop entry)))
2308 (if (pop entry)
2309 (with-current-buffer buf
2310 (let ((last-undo-buffer buf)
2311 (inhibit-read-only t))
2312 (unless (memq buf org-agenda-undo-has-started-in)
2313 (push buf org-agenda-undo-has-started-in)
2314 (make-local-variable 'pending-undo-list)
2315 (undo-start))
2316 (while (and pending-undo-list
2317 (listp pending-undo-list)
2318 (not (car pending-undo-list)))
2319 (pop pending-undo-list))
2320 (undo-more 1))))))
2321 (org-goto-line line)
2322 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2324 (defun org-verify-change-for-undo (l1 l2)
2325 "Verify that a real change occurred between the undo lists L1 and L2."
2326 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2327 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2328 (not (eq l1 l2)))
2330 ;;; Agenda dispatch
2332 (defvar org-agenda-restrict nil)
2333 (defvar org-agenda-restrict-begin (make-marker))
2334 (defvar org-agenda-restrict-end (make-marker))
2335 (defvar org-agenda-last-dispatch-buffer nil)
2336 (defvar org-agenda-overriding-restriction nil)
2338 (defcustom org-agenda-custom-commands-contexts nil
2339 "Alist of custom agenda keys and contextual rules.
2341 For example, if you have a custom agenda command \"p\" and you
2342 want this command to be accessible only from plain text files,
2343 use this:
2345 '((\"p\" (in-file . \"\\.txt\")))
2347 Here are the available contexts definitions:
2349 in-file: command displayed only in matching files
2350 in-mode: command displayed only in matching modes
2351 not-in-file: command not displayed in matching files
2352 not-in-mode: command not displayed in matching modes
2353 [function]: a custom function taking no argument
2355 If you define several checks, the agenda command will be
2356 accessible if there is at least one valid check.
2358 You can also bind a key to another agenda custom command
2359 depending on contextual rules.
2361 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2363 Here it means: in .txt files, use \"p\" as the key for the
2364 agenda command otherwise associated with \"q\". (The command
2365 originally associated with \"q\" is not displayed to avoid
2366 duplicates.)"
2367 ;; :version "24.3"
2368 :group 'org-agenda-custom-commands
2369 :type '(repeat (list :tag "Rule"
2370 (string :tag " Agenda key")
2371 (string :tag "Replace by command")
2372 (repeat :tag "Available when"
2373 (choice
2374 (cons :tag "Condition"
2375 (choice
2376 (const :tag "In file" in-file)
2377 (const :tag "Not in file" not-in-file)
2378 (const :tag "In mode" in-mode)
2379 (const :tag "Not in mode" not-in-mode))
2380 (regexp))
2381 (function :tag "Custom function"))))))
2383 ;;;###autoload
2384 (defun org-agenda (&optional arg keys restriction)
2385 "Dispatch agenda commands to collect entries to the agenda buffer.
2386 Prompts for a command to execute. Any prefix arg will be passed
2387 on to the selected command. The default selections are:
2389 a Call `org-agenda-list' to display the agenda for current day or week.
2390 t Call `org-todo-list' to display the global todo list.
2391 T Call `org-todo-list' to display the global todo list, select only
2392 entries with a specific TODO keyword (the user gets a prompt).
2393 m Call `org-tags-view' to display headlines with tags matching
2394 a condition (the user is prompted for the condition).
2395 M Like `m', but select only TODO entries, no ordinary headlines.
2396 L Create a timeline for the current buffer.
2397 e Export views to associated files.
2398 s Search entries for keywords.
2399 / Multi occur across all agenda files and also files listed
2400 in `org-agenda-text-search-extra-files'.
2401 < Restrict agenda commands to buffer, subtree, or region.
2402 Press several times to get the desired effect.
2403 > Remove a previous restriction.
2404 # List \"stuck\" projects.
2405 ! Configure what \"stuck\" means.
2406 C Configure custom agenda commands.
2408 More commands can be added by configuring the variable
2409 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2410 searches can be pre-defined in this way.
2412 If the current buffer is in Org-mode and visiting a file, you can also
2413 first press `<' once to indicate that the agenda should be temporarily
2414 \(until the next use of \\[org-agenda]) restricted to the current file.
2415 Pressing `<' twice means to restrict to the current subtree or region
2416 \(if active)."
2417 (interactive "P")
2418 (catch 'exit
2419 (let* ((prefix-descriptions nil)
2420 (org-agenda-buffer-name org-agenda-buffer-name)
2421 (org-agenda-window-setup (if (equal (buffer-name)
2422 org-agenda-buffer-name)
2423 'current-window
2424 org-agenda-window-setup))
2425 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2426 (org-agenda-custom-commands
2427 ;; normalize different versions
2428 (delq nil
2429 (mapcar
2430 (lambda (x)
2431 (cond ((stringp (cdr x))
2432 (push x prefix-descriptions)
2433 nil)
2434 ((stringp (nth 1 x)) x)
2435 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2436 (t (cons (car x) (cons "" (cdr x))))))
2437 org-agenda-custom-commands)))
2438 (org-agenda-custom-commands
2439 (org-contextualize-keys
2440 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2441 (buf (current-buffer))
2442 (bfn (buffer-file-name (buffer-base-buffer)))
2443 entry key type match lprops ans)
2444 ;; Turn off restriction unless there is an overriding one,
2445 (unless org-agenda-overriding-restriction
2446 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2447 ;; There is a request to keep the file list in place
2448 (put 'org-agenda-files 'org-restrict nil))
2449 (setq org-agenda-restrict nil)
2450 (move-marker org-agenda-restrict-begin nil)
2451 (move-marker org-agenda-restrict-end nil))
2452 ;; Delete old local properties
2453 (put 'org-agenda-redo-command 'org-lprops nil)
2454 ;; Delete previously set last-arguments
2455 (put 'org-agenda-redo-command 'last-args nil)
2456 ;; Remember where this call originated
2457 (setq org-agenda-last-dispatch-buffer (current-buffer))
2458 (unless keys
2459 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2460 keys (car ans)
2461 restriction (cdr ans)))
2462 ;; If we have sticky agenda buffers, set a name for the buffer,
2463 ;; depending on the invoking keys. The user may still set this
2464 ;; as a command option, which will overwrite what we do here.
2465 (if org-agenda-sticky
2466 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2467 ;; Establish the restriction, if any
2468 (when (and (not org-agenda-overriding-restriction) restriction)
2469 (put 'org-agenda-files 'org-restrict (list bfn))
2470 (cond
2471 ((eq restriction 'region)
2472 (setq org-agenda-restrict t)
2473 (move-marker org-agenda-restrict-begin (region-beginning))
2474 (move-marker org-agenda-restrict-end (region-end)))
2475 ((eq restriction 'subtree)
2476 (save-excursion
2477 (setq org-agenda-restrict t)
2478 (org-back-to-heading t)
2479 (move-marker org-agenda-restrict-begin (point))
2480 (move-marker org-agenda-restrict-end
2481 (progn (org-end-of-subtree t)))))))
2483 ;; For example the todo list should not need it (but does...)
2484 (cond
2485 ((setq entry (assoc keys org-agenda-custom-commands))
2486 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2487 (progn
2488 (setq type (nth 2 entry) match (eval (nth 3 entry))
2489 lprops (nth 4 entry))
2490 (put 'org-agenda-redo-command 'org-lprops lprops)
2491 (cond
2492 ((eq type 'agenda)
2493 (org-let lprops '(org-agenda-list current-prefix-arg)))
2494 ((eq type 'alltodo)
2495 (org-let lprops '(org-todo-list current-prefix-arg)))
2496 ((eq type 'search)
2497 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2498 ((eq type 'stuck)
2499 (org-let lprops '(org-agenda-list-stuck-projects
2500 current-prefix-arg)))
2501 ((eq type 'tags)
2502 (org-let lprops '(org-tags-view current-prefix-arg match)))
2503 ((eq type 'tags-todo)
2504 (org-let lprops '(org-tags-view '(4) match)))
2505 ((eq type 'todo)
2506 (org-let lprops '(org-todo-list match)))
2507 ((eq type 'tags-tree)
2508 (org-check-for-org-mode)
2509 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2510 ((eq type 'todo-tree)
2511 (org-check-for-org-mode)
2512 (org-let lprops
2513 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2514 (regexp-quote match) "\\>"))))
2515 ((eq type 'occur-tree)
2516 (org-check-for-org-mode)
2517 (org-let lprops '(org-occur match)))
2518 ((functionp type)
2519 (org-let lprops '(funcall type match)))
2520 ((fboundp type)
2521 (org-let lprops '(funcall type match)))
2522 (t (error "Invalid custom agenda command type %s" type))))
2523 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2524 ((equal keys "C")
2525 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2526 (customize-variable 'org-agenda-custom-commands))
2527 ((equal keys "a") (call-interactively 'org-agenda-list))
2528 ((equal keys "s") (call-interactively 'org-search-view))
2529 ((equal keys "t") (call-interactively 'org-todo-list))
2530 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2531 ((equal keys "m") (call-interactively 'org-tags-view))
2532 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2533 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2534 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2535 (org-add-hook
2536 'post-command-hook
2537 (lambda ()
2538 (unless (current-message)
2539 (let* ((m (org-agenda-get-any-marker))
2540 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2541 (when note
2542 (message (concat
2543 "FLAGGING-NOTE ([?] for more info): "
2544 (org-add-props
2545 (replace-regexp-in-string
2546 "\\\\n" "//"
2547 (copy-sequence note))
2548 nil 'face 'org-warning)))))))
2549 t t))
2550 ((equal keys "L")
2551 (unless (derived-mode-p 'org-mode)
2552 (error "This is not an Org-mode file"))
2553 (unless restriction
2554 (put 'org-agenda-files 'org-restrict (list bfn))
2555 (org-call-with-arg 'org-timeline arg)))
2556 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2557 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2558 ((equal keys "!") (customize-variable 'org-stuck-projects))
2559 (t (error "Invalid agenda key"))))))
2561 (defun org-agenda-append-agenda ()
2562 "Append another agenda view to the current one.
2563 This function allows interactive building of block agendas.
2564 Agenda views are separated by `org-agenda-block-separator'."
2565 (interactive)
2566 (unless (string= (buffer-name) org-agenda-buffer-name)
2567 (error "Can only append from within agenda buffer"))
2568 (let ((org-agenda-multi t))
2569 (org-agenda)
2570 (widen)))
2572 (defun org-agenda-normalize-custom-commands (cmds)
2573 (delq nil
2574 (mapcar
2575 (lambda (x)
2576 (cond ((stringp (cdr x)) nil)
2577 ((stringp (nth 1 x)) x)
2578 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2579 (t (cons (car x) (cons "" (cdr x))))))
2580 cmds)))
2582 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2583 "The user interface for selecting an agenda command."
2584 (catch 'exit
2585 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2586 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2587 (region-p (org-region-active-p))
2588 (custom org-agenda-custom-commands)
2589 (selstring "")
2590 restriction second-time
2591 c entry key type match prefixes rmheader header-end custom1 desc
2592 line lines left right n n1)
2593 (save-window-excursion
2594 (delete-other-windows)
2595 (org-switch-to-buffer-other-window " *Agenda Commands*")
2596 (erase-buffer)
2597 (insert (eval-when-compile
2598 (let ((header
2599 "Press key for an agenda command: < Buffer, subtree/region restriction
2600 -------------------------------- > Remove restriction
2601 a Agenda for current week or day e Export agenda views
2602 t List of all TODO entries T Entries with special TODO kwd
2603 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2604 L Timeline for current buffer # List stuck projects (!=configure)
2605 s Search for keywords * Toggle sticky agenda views
2606 / Multi-occur ? Find :FLAGGED: entries
2607 C Configure custom agenda commands
2609 (start 0))
2610 (while (string-match
2611 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2612 header start)
2613 (setq start (match-end 0))
2614 (add-text-properties (match-beginning 2) (match-end 2)
2615 '(face bold) header))
2616 header)))
2617 (setq header-end (move-marker (make-marker) (point)))
2618 (while t
2619 (setq custom1 custom)
2620 (when (eq rmheader t)
2621 (org-goto-line 1)
2622 (re-search-forward ":" nil t)
2623 (delete-region (match-end 0) (point-at-eol))
2624 (forward-char 1)
2625 (looking-at "-+")
2626 (delete-region (match-end 0) (point-at-eol))
2627 (move-marker header-end (match-end 0)))
2628 (goto-char header-end)
2629 (delete-region (point) (point-max))
2631 ;; Produce all the lines that describe custom commands and prefixes
2632 (setq lines nil)
2633 (while (setq entry (pop custom1))
2634 (setq key (car entry) desc (nth 1 entry)
2635 type (nth 2 entry)
2636 match (nth 3 entry))
2637 (if (> (length key) 1)
2638 (add-to-list 'prefixes (string-to-char key))
2639 (setq line
2640 (format
2641 "%-4s%-14s"
2642 (org-add-props (copy-sequence key)
2643 '(face bold))
2644 (cond
2645 ((string-match "\\S-" desc) desc)
2646 ((eq type 'agenda) "Agenda for current week or day")
2647 ((eq type 'alltodo) "List of all TODO entries")
2648 ((eq type 'search) "Word search")
2649 ((eq type 'stuck) "List of stuck projects")
2650 ((eq type 'todo) "TODO keyword")
2651 ((eq type 'tags) "Tags query")
2652 ((eq type 'tags-todo) "Tags (TODO)")
2653 ((eq type 'tags-tree) "Tags tree")
2654 ((eq type 'todo-tree) "TODO kwd tree")
2655 ((eq type 'occur-tree) "Occur tree")
2656 ((functionp type) (if (symbolp type)
2657 (symbol-name type)
2658 "Lambda expression"))
2659 (t "???"))))
2660 (if org-agenda-menu-show-matcher
2661 (setq line
2662 (concat line ": "
2663 (cond
2664 ((stringp match)
2665 (setq match (copy-sequence match))
2666 (org-add-props match nil 'face 'org-warning))
2667 (match
2668 (format "set of %d commands" (length match)))
2669 (t ""))))
2670 (if (org-string-nw-p match)
2671 (add-text-properties
2672 0 (length line) (list 'help-echo
2673 (concat "Matcher: "match)) line)))
2674 (push line lines)))
2675 (setq lines (nreverse lines))
2676 (when prefixes
2677 (mapc (lambda (x)
2678 (push
2679 (format "%s %s"
2680 (org-add-props (char-to-string x)
2681 nil 'face 'bold)
2682 (or (cdr (assoc (concat selstring
2683 (char-to-string x))
2684 prefix-descriptions))
2685 "Prefix key"))
2686 lines))
2687 prefixes))
2689 ;; Check if we should display in two columns
2690 (if org-agenda-menu-two-columns
2691 (progn
2692 (setq n (length lines)
2693 n1 (+ (/ n 2) (mod n 2))
2694 right (nthcdr n1 lines)
2695 left (copy-sequence lines))
2696 (setcdr (nthcdr (1- n1) left) nil))
2697 (setq left lines right nil))
2698 (while left
2699 (insert "\n" (pop left))
2700 (when right
2701 (if (< (current-column) 40)
2702 (move-to-column 40 t)
2703 (insert " "))
2704 (insert (pop right))))
2706 ;; Make the window the right size
2707 (goto-char (point-min))
2708 (if second-time
2709 (if (not (pos-visible-in-window-p (point-max)))
2710 (org-fit-window-to-buffer))
2711 (setq second-time t)
2712 (org-fit-window-to-buffer))
2714 ;; Ask for selection
2715 (message "Press key for agenda command%s:"
2716 (if (or restrict-ok org-agenda-overriding-restriction)
2717 (if org-agenda-overriding-restriction
2718 " (restriction lock active)"
2719 (if restriction
2720 (format " (restricted to %s)" restriction)
2721 " (unrestricted)"))
2722 ""))
2723 (setq c (read-char-exclusive))
2724 (message "")
2725 (cond
2726 ((assoc (char-to-string c) custom)
2727 (setq selstring (concat selstring (char-to-string c)))
2728 (throw 'exit (cons selstring restriction)))
2729 ((memq c prefixes)
2730 (setq selstring (concat selstring (char-to-string c))
2731 prefixes nil
2732 rmheader (or rmheader t)
2733 custom (delq nil (mapcar
2734 (lambda (x)
2735 (if (or (= (length (car x)) 1)
2736 (/= (string-to-char (car x)) c))
2738 (cons (substring (car x) 1) (cdr x))))
2739 custom))))
2740 ((eq c ?*)
2741 (call-interactively 'org-toggle-sticky-agenda)
2742 (sit-for 2))
2743 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2744 (message "Restriction is only possible in Org-mode buffers")
2745 (ding) (sit-for 1))
2746 ((eq c ?1)
2747 (org-agenda-remove-restriction-lock 'noupdate)
2748 (setq restriction 'buffer))
2749 ((eq c ?0)
2750 (org-agenda-remove-restriction-lock 'noupdate)
2751 (setq restriction (if region-p 'region 'subtree)))
2752 ((eq c ?<)
2753 (org-agenda-remove-restriction-lock 'noupdate)
2754 (setq restriction
2755 (cond
2756 ((eq restriction 'buffer)
2757 (if region-p 'region 'subtree))
2758 ((memq restriction '(subtree region))
2759 nil)
2760 (t 'buffer))))
2761 ((eq c ?>)
2762 (org-agenda-remove-restriction-lock 'noupdate)
2763 (setq restriction nil))
2764 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2765 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2766 ((and (> (length selstring) 0) (eq c ?\d))
2767 (delete-window)
2768 (org-agenda-get-restriction-and-command prefix-descriptions))
2770 ((equal c ?q) (error "Abort"))
2771 (t (error "Invalid key %c" c))))))))
2773 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2774 (defvar org-agenda-last-arguments nil
2775 "The arguments of the previous call to `org-agenda'.")
2776 (defun org-agenda-run-series (name series)
2777 (org-let (nth 1 series) '(org-prepare-agenda name))
2778 ;; We need to reset agenda markers here, because when constructing a
2779 ;; block agenda, the individual blocks do not do that.
2780 (org-agenda-reset-markers)
2781 (let* ((org-agenda-multi t)
2782 (redo (list 'org-agenda-run-series name (list 'quote series)))
2783 (org-agenda-overriding-arguments
2784 (or org-agenda-overriding-arguments
2785 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2786 (get 'org-agenda-redo-command 'last-args))))
2787 (cmds (car series))
2788 (gprops (nth 1 series))
2789 match ;; The byte compiler incorrectly complains about this. Keep it!
2790 cmd type lprops)
2791 (while (setq cmd (pop cmds))
2792 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2793 (cond
2794 ((eq type 'agenda)
2795 (org-let2 gprops lprops
2796 '(call-interactively 'org-agenda-list)))
2797 ((eq type 'alltodo)
2798 (org-let2 gprops lprops
2799 '(call-interactively 'org-todo-list)))
2800 ((eq type 'search)
2801 (org-let2 gprops lprops
2802 '(org-search-view current-prefix-arg match nil)))
2803 ((eq type 'stuck)
2804 (org-let2 gprops lprops
2805 '(call-interactively 'org-agenda-list-stuck-projects)))
2806 ((eq type 'tags)
2807 (org-let2 gprops lprops
2808 '(org-tags-view current-prefix-arg match)))
2809 ((eq type 'tags-todo)
2810 (org-let2 gprops lprops
2811 '(org-tags-view '(4) match)))
2812 ((eq type 'todo)
2813 (org-let2 gprops lprops
2814 '(org-todo-list match)))
2815 ((fboundp type)
2816 (org-let2 gprops lprops
2817 '(funcall type match)))
2818 (t (error "Invalid type in command series"))))
2819 (widen)
2820 (setq org-agenda-redo-command redo)
2821 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2822 (goto-char (point-min)))
2823 (org-fit-agenda-window)
2824 (org-let (nth 1 series) '(org-finalize-agenda)))
2826 ;;;###autoload
2827 (defmacro org-batch-agenda (cmd-key &rest parameters)
2828 "Run an agenda command in batch mode and send the result to STDOUT.
2829 If CMD-KEY is a string of length 1, it is used as a key in
2830 `org-agenda-custom-commands' and triggers this command. If it is a
2831 longer string it is used as a tags/todo match string.
2832 Parameters are alternating variable names and values that will be bound
2833 before running the agenda command."
2834 (org-eval-in-environment (org-make-parameter-alist parameters)
2835 (if (> (length cmd-key) 2)
2836 (org-tags-view nil cmd-key)
2837 (org-agenda nil cmd-key)))
2838 (set-buffer org-agenda-buffer-name)
2839 (princ (buffer-string)))
2840 (def-edebug-spec org-batch-agenda (form &rest sexp))
2842 (defvar org-agenda-info nil)
2844 ;;;###autoload
2845 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2846 "Run an agenda command in batch mode and send the result to STDOUT.
2847 If CMD-KEY is a string of length 1, it is used as a key in
2848 `org-agenda-custom-commands' and triggers this command. If it is a
2849 longer string it is used as a tags/todo match string.
2850 Parameters are alternating variable names and values that will be bound
2851 before running the agenda command.
2853 The output gives a line for each selected agenda item. Each
2854 item is a list of comma-separated values, like this:
2856 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2858 category The category of the item
2859 head The headline, without TODO kwd, TAGS and PRIORITY
2860 type The type of the agenda entry, can be
2861 todo selected in TODO match
2862 tagsmatch selected in tags match
2863 diary imported from diary
2864 deadline a deadline on given date
2865 scheduled scheduled on given date
2866 timestamp entry has timestamp on given date
2867 closed entry was closed on given date
2868 upcoming-deadline warning about deadline
2869 past-scheduled forwarded scheduled item
2870 block entry has date block including g. date
2871 todo The todo keyword, if any
2872 tags All tags including inherited ones, separated by colons
2873 date The relevant date, like 2007-2-14
2874 time The time, like 15:00-16:50
2875 extra Sting with extra planning info
2876 priority-l The priority letter if any was given
2877 priority-n The computed numerical priority
2878 agenda-day The day in the agenda where this is listed"
2879 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2880 (org-make-parameter-alist parameters))
2881 (if (> (length cmd-key) 2)
2882 (org-tags-view nil cmd-key)
2883 (org-agenda nil cmd-key)))
2884 (set-buffer org-agenda-buffer-name)
2885 (let* ((lines (org-split-string (buffer-string) "\n"))
2886 line)
2887 (while (setq line (pop lines))
2888 (catch 'next
2889 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2890 (setq org-agenda-info
2891 (org-fix-agenda-info (text-properties-at 0 line)))
2892 (princ
2893 (mapconcat 'org-agenda-export-csv-mapper
2894 '(org-category txt type todo tags date time extra
2895 priority-letter priority agenda-day)
2896 ","))
2897 (princ "\n")))))
2898 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2900 (defun org-fix-agenda-info (props)
2901 "Make sure all properties on an agenda item have a canonical form.
2902 This ensures the export commands can easily use it."
2903 (let (tmp re)
2904 (when (setq tmp (plist-get props 'tags))
2905 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2906 (when (setq tmp (plist-get props 'date))
2907 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2908 (let ((calendar-date-display-form '(year "-" month "-" day)))
2909 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2911 (setq tmp (calendar-date-string tmp)))
2912 (setq props (plist-put props 'date tmp)))
2913 (when (setq tmp (plist-get props 'day))
2914 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2915 (let ((calendar-date-display-form '(year "-" month "-" day)))
2916 (setq tmp (calendar-date-string tmp)))
2917 (setq props (plist-put props 'day tmp))
2918 (setq props (plist-put props 'agenda-day tmp)))
2919 (when (setq tmp (plist-get props 'txt))
2920 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2921 (plist-put props 'priority-letter (match-string 1 tmp))
2922 (setq tmp (replace-match "" t t tmp)))
2923 (when (and (setq re (plist-get props 'org-todo-regexp))
2924 (setq re (concat "\\`\\.*" re " ?"))
2925 (string-match re tmp))
2926 (plist-put props 'todo (match-string 1 tmp))
2927 (setq tmp (replace-match "" t t tmp)))
2928 (plist-put props 'txt tmp)))
2929 props)
2931 (defun org-agenda-export-csv-mapper (prop)
2932 (let ((res (plist-get org-agenda-info prop)))
2933 (setq res
2934 (cond
2935 ((not res) "")
2936 ((stringp res) res)
2937 (t (prin1-to-string res))))
2938 (while (string-match "," res)
2939 (setq res (replace-match ";" t t res)))
2940 (org-trim res)))
2942 ;;;###autoload
2943 (defun org-store-agenda-views (&rest parameters)
2944 (interactive)
2945 (eval (list 'org-batch-store-agenda-views)))
2947 ;;;###autoload
2948 (defmacro org-batch-store-agenda-views (&rest parameters)
2949 "Run all custom agenda commands that have a file argument."
2950 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2951 (pop-up-frames nil)
2952 (dir default-directory)
2953 (pars (org-make-parameter-alist parameters))
2954 cmd thiscmdkey files opts cmd-or-set bufname)
2955 (save-window-excursion
2956 (while cmds
2957 (setq cmd (pop cmds)
2958 thiscmdkey (car cmd)
2959 bufname (if org-agenda-sticky (format "*Org Agenda(%s)*" thiscmdkey)
2960 org-agenda-buffer-name)
2961 cmd-or-set (nth 2 cmd)
2962 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2963 files (nth (if (listp cmd-or-set) 4 5) cmd))
2964 (if (stringp files) (setq files (list files)))
2965 (when files
2966 (org-eval-in-environment (append org-agenda-exporter-settings
2967 opts pars)
2968 (org-agenda nil thiscmdkey))
2969 (set-buffer bufname)
2970 (while files
2971 (org-eval-in-environment (append org-agenda-exporter-settings
2972 opts pars)
2973 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2974 (and (get-buffer bufname)
2975 (kill-buffer bufname)))))))
2976 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2978 (defun org-agenda-mark-header-line (pos)
2979 "Mark the line at POS as an agenda structure header."
2980 (save-excursion
2981 (goto-char pos)
2982 (put-text-property (point-at-bol) (point-at-eol)
2983 'org-agenda-structural-header t)
2984 (when org-agenda-title-append
2985 (put-text-property (point-at-bol) (point-at-eol)
2986 'org-agenda-title-append org-agenda-title-append))))
2988 (defvar org-mobile-creating-agendas)
2989 (defvar org-agenda-write-buffer-name "Agenda View")
2990 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
2991 "Write the current buffer (an agenda view) as a file.
2992 Depending on the extension of the file name, plain text (.txt),
2993 HTML (.html or .htm) or Postscript (.ps) is produced.
2994 If the extension is .ics, run icalendar export over all files used
2995 to construct the agenda and limit the export to entries listed in the
2996 agenda now.
2997 With prefix argument OPEN, open the new file immediately.
2998 If NOSETTINGS is given, do not scope the settings of
2999 `org-agenda-exporter-settings' into the export commands. This is used when
3000 the settings have already been scoped and we do not wish to overrule other,
3001 higher priority settings.
3002 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3003 (interactive "FWrite agenda to file: \nP")
3004 (if (not (file-writable-p file))
3005 (error "Cannot write agenda to file %s" file))
3006 (org-let (if nosettings nil org-agenda-exporter-settings)
3007 '(save-excursion
3008 (save-window-excursion
3009 (org-agenda-mark-filtered-text)
3010 (let ((bs (copy-sequence (buffer-string))) beg)
3011 (org-agenda-unmark-filtered-text)
3012 (with-temp-buffer
3013 (rename-buffer org-agenda-write-buffer-name t)
3014 (set-buffer-modified-p nil)
3015 (insert bs)
3016 (org-agenda-remove-marked-text 'org-filtered)
3017 (while (setq beg (text-property-any (point-min) (point-max)
3018 'org-filtered t))
3019 (delete-region
3020 beg (or (next-single-property-change beg 'org-filtered)
3021 (point-max))))
3022 (run-hooks 'org-agenda-before-write-hook)
3023 (cond
3024 ((org-bound-and-true-p org-mobile-creating-agendas)
3025 (org-mobile-write-agenda-for-mobile file))
3026 ((string-match "\\.html?\\'" file)
3027 (require 'htmlize)
3028 (set-buffer (htmlize-buffer (current-buffer)))
3029 (when (and org-agenda-export-html-style
3030 (string-match "<style>" org-agenda-export-html-style))
3031 ;; replace <style> section with org-agenda-export-html-style
3032 (goto-char (point-min))
3033 (kill-region (- (search-forward "<style") 6)
3034 (search-forward "</style>"))
3035 (insert org-agenda-export-html-style))
3036 (write-file file)
3037 (kill-buffer (current-buffer))
3038 (message "HTML written to %s" file))
3039 ((string-match "\\.ps\\'" file)
3040 (require 'ps-print)
3041 (ps-print-buffer-with-faces file)
3042 (message "Postscript written to %s" file))
3043 ((string-match "\\.pdf\\'" file)
3044 (require 'ps-print)
3045 (ps-print-buffer-with-faces
3046 (concat (file-name-sans-extension file) ".ps"))
3047 (call-process "ps2pdf" nil nil nil
3048 (expand-file-name
3049 (concat (file-name-sans-extension file) ".ps"))
3050 (expand-file-name file))
3051 (delete-file (concat (file-name-sans-extension file) ".ps"))
3052 (message "PDF written to %s" file))
3053 ((string-match "\\.ics\\'" file)
3054 (require 'org-icalendar)
3055 (let ((org-agenda-marker-table
3056 (org-create-marker-find-array
3057 (org-agenda-collect-markers)))
3058 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3059 (org-combined-agenda-icalendar-file file))
3060 (apply 'org-export-icalendar 'combine
3061 (org-agenda-files nil 'ifmode))))
3063 (let ((bs (buffer-string)))
3064 (find-file file)
3065 (erase-buffer)
3066 (insert bs)
3067 (save-buffer 0)
3068 (kill-buffer (current-buffer))
3069 (message "Plain text written to %s" file))))))))
3070 (set-buffer (or agenda-bufname
3071 (and (called-interactively-p 'any) (buffer-name))
3072 org-agenda-buffer-name)))
3073 (when open (org-open-file file)))
3075 (defvar org-agenda-tag-filter-overlays nil)
3076 (defvar org-agenda-cat-filter-overlays nil)
3078 (defun org-agenda-mark-filtered-text ()
3079 "Mark all text hidden by filtering with a text property."
3080 (let ((inhibit-read-only t))
3081 (mapc
3082 (lambda (o)
3083 (when (equal (overlay-buffer o) (current-buffer))
3084 (put-text-property
3085 (overlay-start o) (overlay-end o)
3086 'org-filtered t)))
3087 (append org-agenda-tag-filter-overlays
3088 org-agenda-cat-filter-overlays))))
3090 (defun org-agenda-unmark-filtered-text ()
3091 "Remove the filtering text property."
3092 (let ((inhibit-read-only t))
3093 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3095 (defun org-agenda-remove-marked-text (property &optional value)
3096 "Delete all text marked with VALUE of PROPERTY.
3097 VALUE defaults to t."
3098 (let (beg)
3099 (setq value (or value t))
3100 (while (setq beg (text-property-any (point-min) (point-max)
3101 property value))
3102 (delete-region
3103 beg (or (next-single-property-change beg 'org-filtered)
3104 (point-max))))))
3106 (defun org-agenda-add-entry-text ()
3107 "Add entry text to agenda lines.
3108 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3109 entry text following headings shown in the agenda.
3110 Drawers will be excluded, also the line with scheduling/deadline info."
3111 (when (and (> org-agenda-add-entry-text-maxlines 0)
3112 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3113 (let (m txt)
3114 (goto-char (point-min))
3115 (while (not (eobp))
3116 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3117 (beginning-of-line 2)
3118 (setq txt (org-agenda-get-some-entry-text
3119 m org-agenda-add-entry-text-maxlines " > "))
3120 (end-of-line 1)
3121 (if (string-match "\\S-" txt)
3122 (insert "\n" txt)
3123 (or (eobp) (forward-char 1))))))))
3125 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3126 &rest keep)
3127 "Extract entry text from MARKER, at most N-LINES lines.
3128 This will ignore drawers etc, just get the text.
3129 If INDENT is given, prefix every line with this string. If KEEP is
3130 given, it is a list of symbols, defining stuff that should not be
3131 removed from the entry content. Currently only `planning' is allowed here."
3132 (let (txt drawer-re kwd-time-re ind)
3133 (save-excursion
3134 (with-current-buffer (marker-buffer marker)
3135 (if (not (derived-mode-p 'org-mode))
3136 (setq txt "")
3137 (save-excursion
3138 (save-restriction
3139 (widen)
3140 (goto-char marker)
3141 (end-of-line 1)
3142 (setq txt (buffer-substring
3143 (min (1+ (point)) (point-max))
3144 (progn (outline-next-heading) (point)))
3145 drawer-re org-drawer-regexp
3146 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3147 ".*\n?"))
3148 (with-temp-buffer
3149 (insert txt)
3150 (when org-agenda-add-entry-text-descriptive-links
3151 (goto-char (point-min))
3152 (while (org-activate-bracket-links (point-max))
3153 (add-text-properties (match-beginning 0) (match-end 0)
3154 '(face org-link))))
3155 (goto-char (point-min))
3156 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3157 (set-text-properties (match-beginning 0) (match-end 0)
3158 nil))
3159 (goto-char (point-min))
3160 (while (re-search-forward drawer-re nil t)
3161 (delete-region
3162 (match-beginning 0)
3163 (progn (re-search-forward
3164 "^[ \t]*:END:.*\n?" nil 'move)
3165 (point))))
3166 (unless (member 'planning keep)
3167 (goto-char (point-min))
3168 (while (re-search-forward kwd-time-re nil t)
3169 (replace-match "")))
3170 (goto-char (point-min))
3171 (when org-agenda-entry-text-exclude-regexps
3172 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3173 (while (setq re (pop re-list))
3174 (goto-char (point-min))
3175 (while (re-search-forward re nil t)
3176 (replace-match "")))))
3177 (goto-char (point-max))
3178 (skip-chars-backward " \t\n")
3179 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3181 ;; find and remove min common indentation
3182 (goto-char (point-min))
3183 (untabify (point-min) (point-max))
3184 (setq ind (org-get-indentation))
3185 (while (not (eobp))
3186 (unless (looking-at "[ \t]*$")
3187 (setq ind (min ind (org-get-indentation))))
3188 (beginning-of-line 2))
3189 (goto-char (point-min))
3190 (while (not (eobp))
3191 (unless (looking-at "[ \t]*$")
3192 (move-to-column ind)
3193 (delete-region (point-at-bol) (point)))
3194 (beginning-of-line 2))
3196 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3198 (goto-char (point-min))
3199 (when indent
3200 (while (and (not (eobp)) (re-search-forward "^" nil t))
3201 (replace-match indent t t)))
3202 (goto-char (point-min))
3203 (while (looking-at "[ \t]*\n") (replace-match ""))
3204 (goto-char (point-max))
3205 (when (> (org-current-line)
3206 n-lines)
3207 (org-goto-line (1+ n-lines))
3208 (backward-char 1))
3209 (setq txt (buffer-substring (point-min) (point)))))))))
3210 txt))
3212 (defun org-agenda-collect-markers ()
3213 "Collect the markers pointing to entries in the agenda buffer."
3214 (let (m markers)
3215 (save-excursion
3216 (goto-char (point-min))
3217 (while (not (eobp))
3218 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3219 (org-get-at-bol 'org-marker)))
3220 (push m markers))
3221 (beginning-of-line 2)))
3222 (nreverse markers)))
3224 (defun org-create-marker-find-array (marker-list)
3225 "Create a alist of files names with all marker positions in that file."
3226 (let (f tbl m a p)
3227 (while (setq m (pop marker-list))
3228 (setq p (marker-position m)
3229 f (buffer-file-name (or (buffer-base-buffer
3230 (marker-buffer m))
3231 (marker-buffer m))))
3232 (if (setq a (assoc f tbl))
3233 (push (marker-position m) (cdr a))
3234 (push (list f p) tbl)))
3235 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3236 tbl)))
3238 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3239 (defun org-check-agenda-marker-table ()
3240 "Check of the current entry is on the marker list."
3241 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3243 (and (setq a (assoc file org-agenda-marker-table))
3244 (save-match-data
3245 (save-excursion
3246 (org-back-to-heading t)
3247 (member (point) (cdr a)))))))
3249 (defun org-check-for-org-mode ()
3250 "Make sure current buffer is in org-mode. Error if not."
3251 (or (derived-mode-p 'org-mode)
3252 (error "Cannot execute org-mode agenda command on buffer in %s"
3253 major-mode)))
3255 (defun org-fit-agenda-window ()
3256 "Fit the window to the buffer size."
3257 (and (memq org-agenda-window-setup '(reorganize-frame))
3258 (fboundp 'fit-window-to-buffer)
3259 (org-fit-window-to-buffer
3261 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3262 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3264 ;;; Agenda prepare and finalize
3266 (defvar org-agenda-multi nil) ; dynamically scoped
3267 (defvar org-agenda-buffer-name "*Org Agenda*")
3268 (defvar org-pre-agenda-window-conf nil)
3269 (defvar org-agenda-columns-active nil)
3270 (defvar org-agenda-name nil)
3271 (defvar org-agenda-tag-filter nil)
3272 (defvar org-agenda-category-filter nil)
3273 (defvar org-agenda-top-category-filter nil)
3274 (defvar org-agenda-tag-filter-while-redo nil)
3275 (defvar org-agenda-tag-filter-preset nil
3276 "A preset of the tags filter used for secondary agenda filtering.
3277 This must be a list of strings, each string must be a single tag preceded
3278 by \"+\" or \"-\".
3279 This variable should not be set directly, but agenda custom commands can
3280 bind it in the options section. The preset filter is a global property of
3281 the entire agenda view. In a block agenda, it will not work reliably to
3282 define a filter for one of the individual blocks. You need to set it in
3283 the global options and expect it to be applied to the entire view.")
3285 (defvar org-agenda-category-filter-preset nil
3286 "A preset of the category filter used for secondary agenda filtering.
3287 This must be a list of strings, each string must be a single category
3288 preceded by \"+\" or \"-\".
3289 This variable should not be set directly, but agenda custom commands can
3290 bind it in the options section. The preset filter is a global property of
3291 the entire agenda view. In a block agenda, it will not work reliably to
3292 define a filter for one of the individual blocks. You need to set it in
3293 the global options and expect it to be applied to the entire view.")
3296 (defun org-agenda-use-sticky-p ()
3297 "Return non-nil if an agenda buffer named
3298 `org-agenda-buffer-name' exists and should be shown instead of
3299 generating a new one."
3300 (and
3301 ;; turned off by user
3302 org-agenda-sticky
3303 ;; For multi-agenda buffer already exists
3304 (not org-agenda-multi)
3305 ;; buffer found
3306 (get-buffer org-agenda-buffer-name)
3307 ;; C-u parameter is same as last call
3308 (with-current-buffer (get-buffer org-agenda-buffer-name)
3309 (and
3310 (equal current-prefix-arg
3311 org-agenda-last-prefix-arg)
3312 ;; In case user turned stickiness on, while having existing
3313 ;; Agenda buffer active, don't reuse that buffer, because it
3314 ;; does not have org variables local
3315 org-agenda-this-buffer-is-sticky))))
3317 (defun org-prepare-agenda-window (abuf)
3318 "Setup agenda buffer in the window."
3319 (let* ((awin (get-buffer-window abuf))
3320 wconf)
3321 (cond
3322 ((equal (current-buffer) abuf) nil)
3323 (awin (select-window awin))
3324 ((not (setq wconf (current-window-configuration))))
3325 ((equal org-agenda-window-setup 'current-window)
3326 (org-pop-to-buffer-same-window abuf))
3327 ((equal org-agenda-window-setup 'other-window)
3328 (org-switch-to-buffer-other-window abuf))
3329 ((equal org-agenda-window-setup 'other-frame)
3330 (switch-to-buffer-other-frame abuf))
3331 ((equal org-agenda-window-setup 'reorganize-frame)
3332 (delete-other-windows)
3333 (org-switch-to-buffer-other-window abuf)))
3334 ;; additional test in case agenda is invoked from within agenda
3335 ;; buffer via elisp link
3336 (unless (equal (current-buffer) abuf)
3337 (org-pop-to-buffer-same-window abuf))
3338 (setq org-pre-agenda-window-conf
3339 (or org-pre-agenda-window-conf wconf))))
3341 (defun org-prepare-agenda (&optional name)
3342 (if (org-agenda-use-sticky-p)
3343 (progn
3344 ;; Popup existing buffer
3345 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3346 (message "Sticky Agenda buffer, use `r' to refresh")
3347 (throw 'exit nil))
3348 (setq org-todo-keywords-for-agenda nil)
3349 (setq org-drawers-for-agenda nil)
3350 (unless org-agenda-persistent-filter
3351 (setq org-agenda-tag-filter nil
3352 org-agenda-category-filter nil))
3353 (put 'org-agenda-tag-filter :preset-filter
3354 org-agenda-tag-filter-preset)
3355 (put 'org-agenda-category-filter :preset-filter
3356 org-agenda-category-filter-preset)
3357 (if org-agenda-multi
3358 (progn
3359 (setq buffer-read-only nil)
3360 (goto-char (point-max))
3361 (unless (or (bobp) org-agenda-compact-blocks
3362 (not org-agenda-block-separator))
3363 (insert "\n"
3364 (if (stringp org-agenda-block-separator)
3365 org-agenda-block-separator
3366 (make-string (window-width) org-agenda-block-separator))
3367 "\n"))
3368 (narrow-to-region (point) (point-max)))
3369 (setq org-done-keywords-for-agenda nil)
3371 ;; Setting any org variables that are in org-agenda-local-vars
3372 ;; list need to be done after the prepare call
3373 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3374 (setq buffer-read-only nil)
3375 (org-agenda-reset-markers)
3376 (let ((inhibit-read-only t)) (erase-buffer))
3377 (org-agenda-mode)
3378 (setq org-agenda-buffer (current-buffer))
3379 (setq org-agenda-contributing-files nil)
3380 (setq org-agenda-columns-active nil)
3381 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3382 (setq org-todo-keywords-for-agenda
3383 (org-uniquify org-todo-keywords-for-agenda))
3384 (setq org-done-keywords-for-agenda
3385 (org-uniquify org-done-keywords-for-agenda))
3386 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3387 (setq org-agenda-last-prefix-arg current-prefix-arg)
3388 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3389 (and name (not org-agenda-name)
3390 (org-set-local 'org-agenda-name name)))
3391 (setq buffer-read-only nil)))
3393 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3394 (defun org-finalize-agenda ()
3395 "Finishing touch for the agenda buffer, called just before displaying it."
3396 (unless org-agenda-multi
3397 (save-excursion
3398 (let ((inhibit-read-only t))
3399 (goto-char (point-min))
3400 (while (org-activate-bracket-links (point-max))
3401 (add-text-properties (match-beginning 0) (match-end 0)
3402 '(face org-link)))
3403 (org-agenda-align-tags)
3404 (unless org-agenda-with-colors
3405 (remove-text-properties (point-min) (point-max) '(face nil))))
3406 (if (and (boundp 'org-agenda-overriding-columns-format)
3407 org-agenda-overriding-columns-format)
3408 (org-set-local 'org-agenda-overriding-columns-format
3409 org-agenda-overriding-columns-format))
3410 (if (and (boundp 'org-agenda-view-columns-initially)
3411 org-agenda-view-columns-initially)
3412 (org-agenda-columns))
3413 (when org-agenda-fontify-priorities
3414 (org-agenda-fontify-priorities))
3415 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3416 (org-agenda-dim-blocked-tasks))
3417 (org-agenda-mark-clocking-task)
3418 (when org-agenda-entry-text-mode
3419 (org-agenda-entry-text-hide)
3420 (org-agenda-entry-text-show))
3421 (if (functionp 'org-habit-insert-consistency-graphs)
3422 (org-habit-insert-consistency-graphs))
3423 (run-hooks 'org-finalize-agenda-hook)
3424 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3425 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3426 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3427 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3428 (org-agenda-filter-apply org-agenda-category-filter 'category))
3429 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3432 (defun org-agenda-mark-clocking-task ()
3433 "Mark the current clock entry in the agenda if it is present."
3434 (mapc (lambda (o)
3435 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3436 (delete-overlay o)))
3437 (overlays-in (point-min) (point-max)))
3438 (when (marker-buffer org-clock-hd-marker)
3439 (save-excursion
3440 (goto-char (point-min))
3441 (let (s ov)
3442 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3443 (goto-char s)
3444 (when (equal (org-get-at-bol 'org-hd-marker)
3445 org-clock-hd-marker)
3446 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3447 (overlay-put ov 'type 'org-agenda-clocking)
3448 (overlay-put ov 'face 'org-agenda-clocking)
3449 (overlay-put ov 'help-echo
3450 "The clock is running in this item")))))))
3452 (defun org-agenda-fontify-priorities ()
3453 "Make highest priority lines bold, and lowest italic."
3454 (interactive)
3455 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3456 (delete-overlay o)))
3457 (overlays-in (point-min) (point-max)))
3458 (save-excursion
3459 (let ((inhibit-read-only t)
3460 b e p ov h l)
3461 (goto-char (point-min))
3462 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3463 (setq h (or (get-char-property (point) 'org-highest-priority)
3464 org-highest-priority)
3465 l (or (get-char-property (point) 'org-lowest-priority)
3466 org-lowest-priority)
3467 p (string-to-char (match-string 1))
3468 b (match-beginning 0)
3469 e (if (eq org-agenda-fontify-priorities 'cookies)
3470 (match-end 0)
3471 (point-at-eol))
3472 ov (make-overlay b e))
3473 (overlay-put
3474 ov 'face
3475 (cond ((org-face-from-face-or-color
3476 'priority nil
3477 (cdr (assoc p org-priority-faces))))
3478 ((and (listp org-agenda-fontify-priorities)
3479 (org-face-from-face-or-color
3480 'priority nil
3481 (cdr (assoc p org-agenda-fontify-priorities)))))
3482 ((equal p l) 'italic)
3483 ((equal p h) 'bold)))
3484 (overlay-put ov 'org-type 'org-priority)))))
3486 (defun org-agenda-dim-blocked-tasks ()
3487 "Dim currently blocked TODO's in the agenda display."
3488 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3489 (delete-overlay o)))
3490 (overlays-in (point-min) (point-max)))
3491 (save-excursion
3492 (let ((inhibit-read-only t)
3493 (org-depend-tag-blocked nil)
3494 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3495 org-blocked-by-checkboxes
3496 invis1 b e p ov h l)
3497 (goto-char (point-min))
3498 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3499 (and pos (goto-char (1+ pos))))
3500 (setq org-blocked-by-checkboxes nil invis1 invis)
3501 (let ((marker (org-get-at-bol 'org-hd-marker)))
3502 (when (and marker
3503 (with-current-buffer (marker-buffer marker)
3504 (save-excursion (goto-char marker)
3505 (org-entry-blocked-p))))
3506 (if org-blocked-by-checkboxes (setq invis1 nil))
3507 (setq b (if invis1
3508 (max (point-min) (1- (point-at-bol)))
3509 (point-at-bol))
3510 e (point-at-eol)
3511 ov (make-overlay b e))
3512 (if invis1
3513 (overlay-put ov 'invisible t)
3514 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3515 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3517 (defvar org-agenda-skip-function nil
3518 "Function to be called at each match during agenda construction.
3519 If this function returns nil, the current match should not be skipped.
3520 Otherwise, the function must return a position from where the search
3521 should be continued.
3522 This may also be a Lisp form, it will be evaluated.
3523 Never set this variable using `setq' or so, because then it will apply
3524 to all future agenda commands. If you do want a global skipping condition,
3525 use the option `org-agenda-skip-function-global' instead.
3526 The correct usage for `org-agenda-skip-function' is to bind it with
3527 `let' to scope it dynamically into the agenda-constructing command.
3528 A good way to set it is through options in `org-agenda-custom-commands'.")
3530 (defun org-agenda-skip ()
3531 "Throw to `:skip' in places that should be skipped.
3532 Also moves point to the end of the skipped region, so that search can
3533 continue from there."
3534 (let ((p (point-at-bol)) to)
3535 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3536 (get-text-property p :org-archived)
3537 (org-end-of-subtree t)
3538 (throw :skip t))
3539 (and org-agenda-skip-comment-trees
3540 (get-text-property p :org-comment)
3541 (org-end-of-subtree t)
3542 (throw :skip t))
3543 (if (equal (char-after p) ?#) (throw :skip t))
3544 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3545 (org-agenda-skip-eval org-agenda-skip-function)))
3546 (goto-char to)
3547 (throw :skip t))))
3549 (defun org-agenda-skip-eval (form)
3550 "If FORM is a function or a list, call (or eval) is and return result.
3551 `save-excursion' and `save-match-data' are wrapped around the call, so point
3552 and match data are returned to the previous state no matter what these
3553 functions do."
3554 (let (fp)
3555 (and form
3556 (or (setq fp (functionp form))
3557 (consp form))
3558 (save-excursion
3559 (save-match-data
3560 (if fp
3561 (funcall form)
3562 (eval form)))))))
3564 (defvar org-agenda-markers nil
3565 "List of all currently active markers created by `org-agenda'.")
3566 (defvar org-agenda-last-marker-time (org-float-time)
3567 "Creation time of the last agenda marker.")
3569 (defun org-agenda-new-marker (&optional pos)
3570 "Return a new agenda marker.
3571 Org-mode keeps a list of these markers and resets them when they are
3572 no longer in use."
3573 (let ((m (copy-marker (or pos (point)))))
3574 (setq org-agenda-last-marker-time (org-float-time))
3575 (if org-agenda-buffer
3576 (with-current-buffer org-agenda-buffer
3577 (push m org-agenda-markers))
3578 (push m org-agenda-markers))
3581 (defun org-agenda-reset-markers ()
3582 "Reset markers created by `org-agenda'."
3583 (while org-agenda-markers
3584 (move-marker (pop org-agenda-markers) nil)))
3586 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3587 "Save relative positions of markers in region.
3588 This check for agenda markers in all agenda buffers currently active."
3589 (dolist (buf (buffer-list))
3590 (with-current-buffer buf
3591 (when (eq major-mode 'org-agenda-mode)
3592 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3593 org-agenda-markers)))))
3595 ;;; Entry text mode
3597 (defun org-agenda-entry-text-show-here ()
3598 "Add some text from the entry as context to the current line."
3599 (let (m txt o)
3600 (setq m (org-get-at-bol 'org-hd-marker))
3601 (unless (marker-buffer m)
3602 (error "No marker points to an entry here"))
3603 (setq txt (concat "\n" (org-no-properties
3604 (org-agenda-get-some-entry-text
3605 m org-agenda-entry-text-maxlines " > "))))
3606 (when (string-match "\\S-" txt)
3607 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3608 (overlay-put o 'evaporate t)
3609 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3610 (overlay-put o 'after-string txt))))
3612 (defun org-agenda-entry-text-show ()
3613 "Add entry context for all agenda lines."
3614 (interactive)
3615 (save-excursion
3616 (goto-char (point-max))
3617 (beginning-of-line 1)
3618 (while (not (bobp))
3619 (when (org-get-at-bol 'org-hd-marker)
3620 (org-agenda-entry-text-show-here))
3621 (beginning-of-line 0))))
3623 (defun org-agenda-entry-text-hide ()
3624 "Remove any shown entry context."
3625 (delq nil
3626 (mapcar (lambda (o)
3627 (if (eq (overlay-get o 'org-overlay-type)
3628 'agenda-entry-content)
3629 (progn (delete-overlay o) t)))
3630 (overlays-in (point-min) (point-max)))))
3632 (defun org-agenda-get-day-face (date)
3633 "Return the face DATE should be displayed with."
3634 (or (and (functionp org-agenda-day-face-function)
3635 (funcall org-agenda-day-face-function date))
3636 (cond ((org-agenda-todayp date)
3637 'org-agenda-date-today)
3638 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3639 'org-agenda-date-weekend)
3640 (t 'org-agenda-date))))
3642 ;;; Agenda timeline
3644 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3646 (defun org-timeline (&optional dotodo)
3647 "Show a time-sorted view of the entries in the current org file.
3648 Only entries with a time stamp of today or later will be listed. With
3649 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3650 under the current date.
3651 If the buffer contains an active region, only check the region for
3652 dates."
3653 (interactive "P")
3654 (let* ((dopast t)
3655 (org-agenda-show-log-scoped org-agenda-show-log)
3656 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3657 (current-buffer))))
3658 (date (calendar-current-date))
3659 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3660 (end (if (org-region-active-p) (region-end) (point-max)))
3661 (day-numbers (org-get-all-dates
3662 beg end 'no-ranges
3663 t org-agenda-show-log-scoped ; always include today
3664 org-timeline-show-empty-dates))
3665 (org-deadline-warning-days 0)
3666 (org-agenda-only-exact-dates t)
3667 (today (org-today))
3668 (past t)
3669 args
3670 s e rtn d emptyp)
3671 (setq org-agenda-redo-command
3672 (list 'progn
3673 (list 'org-switch-to-buffer-other-window (current-buffer))
3674 (list 'org-timeline (list 'quote dotodo))))
3675 (if (not dopast)
3676 ;; Remove past dates from the list of dates.
3677 (setq day-numbers (delq nil (mapcar (lambda(x)
3678 (if (>= x today) x nil))
3679 day-numbers))))
3680 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3681 (org-compile-prefix-format 'timeline)
3682 (org-set-sorting-strategy 'timeline)
3683 (if org-agenda-show-log-scoped (push :closed args))
3684 (push :timestamp args)
3685 (push :deadline args)
3686 (push :scheduled args)
3687 (push :sexp args)
3688 (if dotodo (push :todo args))
3689 (insert "Timeline of file " entry "\n")
3690 (add-text-properties (point-min) (point)
3691 (list 'face 'org-agenda-structure))
3692 (org-agenda-mark-header-line (point-min))
3693 (while (setq d (pop day-numbers))
3694 (if (and (listp d) (eq (car d) :omitted))
3695 (progn
3696 (setq s (point))
3697 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3698 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3699 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3700 (if (and (>= d today)
3701 dopast
3702 past)
3703 (progn
3704 (setq past nil)
3705 (insert (make-string 79 ?-) "\n")))
3706 (setq date (calendar-gregorian-from-absolute d))
3707 (setq s (point))
3708 (setq rtn (and (not emptyp)
3709 (apply 'org-agenda-get-day-entries entry
3710 date args)))
3711 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3712 (progn
3713 (insert
3714 (if (stringp org-agenda-format-date)
3715 (format-time-string org-agenda-format-date
3716 (org-time-from-absolute date))
3717 (funcall org-agenda-format-date date))
3718 "\n")
3719 (put-text-property s (1- (point)) 'face
3720 (org-agenda-get-day-face date))
3721 (put-text-property s (1- (point)) 'org-date-line t)
3722 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3723 (if (equal d today)
3724 (put-text-property s (1- (point)) 'org-today t))
3725 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3726 (put-text-property s (1- (point)) 'day d)))))
3727 (goto-char (point-min))
3728 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3729 (point-min)))
3730 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3731 (org-finalize-agenda)
3732 (setq buffer-read-only t)))
3734 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3735 "Return a list of all relevant day numbers from BEG to END buffer positions.
3736 If NO-RANGES is non-nil, include only the start and end dates of a range,
3737 not every single day in the range. If FORCE-TODAY is non-nil, make
3738 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3739 inactive time stamps (those in square brackets) are included.
3740 When EMPTY is non-nil, also include days without any entries."
3741 (let ((re (concat
3742 (if pre-re pre-re "")
3743 (if inactive org-ts-regexp-both org-ts-regexp)))
3744 dates dates1 date day day1 day2 ts1 ts2 pos)
3745 (if force-today
3746 (setq dates (list (org-today))))
3747 (save-excursion
3748 (goto-char beg)
3749 (while (re-search-forward re end t)
3750 (setq day (time-to-days (org-time-string-to-time
3751 (substring (match-string 1) 0 10)
3752 (current-buffer) (match-beginning 0))))
3753 (or (memq day dates) (push day dates)))
3754 (unless no-ranges
3755 (goto-char beg)
3756 (while (re-search-forward org-tr-regexp end t)
3757 (setq pos (match-beginning 0))
3758 (setq ts1 (substring (match-string 1) 0 10)
3759 ts2 (substring (match-string 2) 0 10)
3760 day1 (time-to-days (org-time-string-to-time
3761 ts1 (current-buffer) pos))
3762 day2 (time-to-days (org-time-string-to-time
3763 ts2 (current-buffer) pos)))
3764 (while (< (setq day1 (1+ day1)) day2)
3765 (or (memq day1 dates) (push day1 dates)))))
3766 (setq dates (sort dates '<))
3767 (when empty
3768 (while (setq day (pop dates))
3769 (setq day2 (car dates))
3770 (push day dates1)
3771 (when (and day2 empty)
3772 (if (or (eq empty t)
3773 (and (numberp empty) (<= (- day2 day) empty)))
3774 (while (< (setq day (1+ day)) day2)
3775 (push (list day) dates1))
3776 (push (cons :omitted (- day2 day)) dates1))))
3777 (setq dates (nreverse dates1)))
3778 dates)))
3780 ;;; Agenda Daily/Weekly
3782 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3783 "Start day for the agenda view.
3784 Custom commands can set this variable in the options section.")
3785 (defvar org-starting-day nil) ; local variable in the agenda buffer
3786 (defvar org-agenda-current-span nil
3787 "The current span used in the agenda view.") ; local variable in the agenda buffer
3788 (defvar org-arg-loc nil) ; local variable
3790 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3791 "List of types searched for when creating the daily/weekly agenda.
3792 This variable is a list of symbols that controls the types of
3793 items that appear in the daily/weekly agenda. Allowed symbols in this
3794 list are are
3796 :timestamp List items containing a date stamp or date range matching
3797 the selected date. This includes sexp entries in
3798 angular brackets.
3800 :sexp List entries resulting from plain diary-like sexps.
3802 :deadline List deadline due on that date. When the date is today,
3803 also list any deadlines past due, or due within
3804 `org-deadline-warning-days'. `:deadline' must appear before
3805 `:scheduled' if the setting of
3806 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3807 any effect.
3809 :scheduled List all items which are scheduled for the given date.
3810 The diary for *today* also contains items which were
3811 scheduled earlier and are not yet marked DONE.
3813 By default, all four types are turned on.
3815 Never set this variable globally using `setq', because then it
3816 will apply to all future agenda commands. Instead, bind it with
3817 `let' to scope it dynamically into the agenda-constructing
3818 command. A good way to set it is through options in
3819 `org-agenda-custom-commands'. For a more flexible (though
3820 somewhat less efficient) way of determining what is included in
3821 the daily/weekly agenda, see `org-agenda-skip-function'.")
3823 ;;;###autoload
3824 (defun org-agenda-list (&optional arg start-day span)
3825 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3826 The view will be for the current day or week, but from the overview buffer
3827 you will be able to go to other days/weeks.
3829 With a numeric prefix argument in an interactive call, the agenda will
3830 span ARG days. Lisp programs should instead specify SPAN to change
3831 the number of days. SPAN defaults to `org-agenda-span'.
3833 START-DAY defaults to TODAY, or to the most recent match for the weekday
3834 given in `org-agenda-start-on-weekday'."
3835 (interactive "P")
3836 (if (and (integerp arg) (> arg 0))
3837 (setq span arg arg nil))
3838 (org-prepare-agenda "Day/Week")
3839 (setq start-day (or start-day org-agenda-start-day))
3840 (if org-agenda-overriding-arguments
3841 (setq arg (car org-agenda-overriding-arguments)
3842 start-day (nth 1 org-agenda-overriding-arguments)
3843 span (nth 2 org-agenda-overriding-arguments)))
3844 (if (stringp start-day)
3845 ;; Convert to an absolute day number
3846 (setq start-day (time-to-days (org-read-date nil t start-day))))
3847 (setq org-agenda-last-arguments (list arg start-day span))
3848 (org-compile-prefix-format 'agenda)
3849 (org-set-sorting-strategy 'agenda)
3850 (let* ((span (org-agenda-ndays-to-span
3851 (or span org-agenda-ndays org-agenda-span)))
3852 (today (org-today))
3853 (sd (or start-day today))
3854 (ndays (org-agenda-span-to-ndays span sd))
3855 (org-agenda-start-on-weekday
3856 (if (eq ndays 7)
3857 org-agenda-start-on-weekday))
3858 (thefiles (org-agenda-files nil 'ifmode))
3859 (files thefiles)
3860 (start (if (or (null org-agenda-start-on-weekday)
3861 (< ndays 7))
3863 (let* ((nt (calendar-day-of-week
3864 (calendar-gregorian-from-absolute sd)))
3865 (n1 org-agenda-start-on-weekday)
3866 (d (- nt n1)))
3867 (- sd (+ (if (< d 0) 7 0) d)))))
3868 (day-numbers (list start))
3869 (day-cnt 0)
3870 (inhibit-redisplay (not debug-on-error))
3871 (org-agenda-show-log-scoped org-agenda-show-log)
3872 s e rtn rtnall file date d start-pos end-pos todayp
3873 clocktable-start clocktable-end filter)
3874 (setq org-agenda-redo-command
3875 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3876 (dotimes (n (1- ndays))
3877 (push (1+ (car day-numbers)) day-numbers))
3878 (setq day-numbers (nreverse day-numbers))
3879 (setq clocktable-start (car day-numbers)
3880 clocktable-end (1+ (or (org-last day-numbers) 0)))
3881 (org-set-local 'org-starting-day (car day-numbers))
3882 (org-set-local 'org-arg-loc arg)
3883 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3884 (unless org-agenda-compact-blocks
3885 (let* ((d1 (car day-numbers))
3886 (d2 (org-last day-numbers))
3887 (w1 (org-days-to-iso-week d1))
3888 (w2 (org-days-to-iso-week d2)))
3889 (setq s (point))
3890 (if org-agenda-overriding-header
3891 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3892 nil 'face 'org-agenda-structure) "\n")
3893 (insert (org-agenda-span-name span)
3894 "-agenda"
3895 (if (< (- d2 d1) 350)
3896 (if (= w1 w2)
3897 (format " (W%02d)" w1)
3898 (format " (W%02d-W%02d)" w1 w2))
3900 ":\n")))
3901 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3902 'org-date-line t))
3903 (org-agenda-mark-header-line s))
3904 (while (setq d (pop day-numbers))
3905 (setq date (calendar-gregorian-from-absolute d)
3906 s (point))
3907 (if (or (setq todayp (= d today))
3908 (and (not start-pos) (= d sd)))
3909 (setq start-pos (point))
3910 (if (and start-pos (not end-pos))
3911 (setq end-pos (point))))
3912 (setq files thefiles
3913 rtnall nil)
3914 (while (setq file (pop files))
3915 (catch 'nextfile
3916 (org-check-agenda-file file)
3917 (let ((org-agenda-entry-types org-agenda-entry-types))
3918 (unless org-agenda-include-deadlines
3919 (setq org-agenda-entry-types
3920 (delq :deadline org-agenda-entry-types)))
3921 (cond
3922 ((memq org-agenda-show-log-scoped '(only clockcheck))
3923 (setq rtn (org-agenda-get-day-entries
3924 file date :closed)))
3925 (org-agenda-show-log-scoped
3926 (setq rtn (apply 'org-agenda-get-day-entries
3927 file date
3928 (append '(:closed) org-agenda-entry-types))))
3930 (setq rtn (apply 'org-agenda-get-day-entries
3931 file date
3932 org-agenda-entry-types)))))
3933 (setq rtnall (append rtnall rtn)))) ;; all entries
3934 (if org-agenda-include-diary
3935 (let ((org-agenda-search-headline-for-time t))
3936 (require 'diary-lib)
3937 (setq rtn (org-get-entries-from-diary date))
3938 (setq rtnall (append rtnall rtn))))
3939 (if (or rtnall org-agenda-show-all-dates)
3940 (progn
3941 (setq day-cnt (1+ day-cnt))
3942 (insert
3943 (if (stringp org-agenda-format-date)
3944 (format-time-string org-agenda-format-date
3945 (org-time-from-absolute date))
3946 (funcall org-agenda-format-date date))
3947 "\n")
3948 (put-text-property s (1- (point)) 'face
3949 (org-agenda-get-day-face date))
3950 (put-text-property s (1- (point)) 'org-date-line t)
3951 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3952 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3953 (when todayp
3954 (put-text-property s (1- (point)) 'org-today t))
3955 (setq rtnall
3956 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3957 (if rtnall (insert ;; all entries
3958 (org-finalize-agenda-entries rtnall)
3959 "\n"))
3960 (put-text-property s (1- (point)) 'day d)
3961 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3962 (when (and org-agenda-clockreport-mode clocktable-start)
3963 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3964 ;; the above line is to ensure the restricted range!
3965 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3966 tbl)
3967 (setq p (org-plist-delete p :block))
3968 (setq p (plist-put p :tstart clocktable-start))
3969 (setq p (plist-put p :tend clocktable-end))
3970 (setq p (plist-put p :scope 'agenda))
3971 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3972 (setq filter (or org-agenda-tag-filter-while-redo
3973 (get 'org-agenda-tag-filter :preset-filter))))
3974 (setq p (plist-put p :tags (mapconcat (lambda (x)
3975 (if (string-match "[<>=]" x)
3978 filter ""))))
3979 (setq tbl (apply 'org-get-clocktable p))
3980 (insert tbl)))
3981 (goto-char (point-min))
3982 (or org-agenda-multi (org-fit-agenda-window))
3983 (unless (and (pos-visible-in-window-p (point-min))
3984 (pos-visible-in-window-p (point-max)))
3985 (goto-char (1- (point-max)))
3986 (recenter -1)
3987 (if (not (pos-visible-in-window-p (or start-pos 1)))
3988 (progn
3989 (goto-char (or start-pos 1))
3990 (recenter 1))))
3991 (goto-char (or start-pos 1))
3992 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3993 (if (eq org-agenda-show-log-scoped 'clockcheck)
3994 (org-agenda-show-clocking-issues))
3995 (org-finalize-agenda)
3996 (setq buffer-read-only t)
3997 (message "")))
3999 (defun org-agenda-ndays-to-span (n)
4000 "Return a span symbol for a span of N days, or N if none matches."
4001 (cond ((symbolp n) n)
4002 ((= n 1) 'day)
4003 ((= n 7) 'week)
4004 (t n)))
4006 (defun org-agenda-span-to-ndays (span start-day)
4007 "Return ndays from SPAN starting at START-DAY."
4008 (cond ((numberp span) span)
4009 ((eq span 'day) 1)
4010 ((eq span 'week) 7)
4011 ((eq span 'month)
4012 (let ((date (calendar-gregorian-from-absolute start-day)))
4013 (calendar-last-day-of-month (car date) (caddr date))))
4014 ((eq span 'year)
4015 (let ((date (calendar-gregorian-from-absolute start-day)))
4016 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4018 (defun org-agenda-span-name (span)
4019 "Return a SPAN name."
4020 (if (null span)
4022 (if (symbolp span)
4023 (capitalize (symbol-name span))
4024 (format "%d days" span))))
4026 ;;; Agenda word search
4028 (defvar org-agenda-search-history nil)
4029 (defvar org-todo-only nil)
4031 (defvar org-search-syntax-table nil
4032 "Special syntax table for org-mode search.
4033 In this table, we have single quotes not as word constituents, to
4034 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4036 (defvar org-mode-syntax-table) ; From org.el
4037 (defun org-search-syntax-table ()
4038 (unless org-search-syntax-table
4039 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4040 (modify-syntax-entry ?' "." org-search-syntax-table)
4041 (modify-syntax-entry ?` "." org-search-syntax-table))
4042 org-search-syntax-table)
4044 (defvar org-agenda-last-search-view-search-was-boolean nil)
4046 ;;;###autoload
4047 (defun org-search-view (&optional todo-only string edit-at)
4048 "Show all entries that contain a phrase or words or regular expressions.
4050 With optional prefix argument TODO-ONLY, only consider entries that are
4051 TODO entries. The argument STRING can be used to pass a default search
4052 string into this function. If EDIT-AT is non-nil, it means that the
4053 user should get a chance to edit this string, with cursor at position
4054 EDIT-AT.
4056 The search string can be viewed either as a phrase that should be found as
4057 is, or it can be broken into a number of snippets, each of which must match
4058 in a Boolean way to select an entry. The default depends on the variable
4059 `org-agenda-search-view-always-boolean'.
4060 Even if this is turned off (the default) you can always switch to
4061 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4063 The default is a direct search of the whole phrase, where each space in
4064 the search string can expand to an arbitrary amount of whitespace,
4065 including newlines.
4067 If using a Boolean search, the search string is split on whitespace and
4068 each snippet is searched separately, with logical AND to select an entry.
4069 Words prefixed with a minus must *not* occur in the entry. Words without
4070 a prefix or prefixed with a plus must occur in the entry. Matching is
4071 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4072 match whole words, not parts of a word) if
4073 `org-agenda-search-view-force-full-words' is set (default is nil).
4075 Boolean search snippets enclosed by curly braces are interpreted as
4076 regular expressions that must or (when preceded with \"-\") must not
4077 match in the entry. Snippets enclosed into double quotes will be taken
4078 as a whole, to include whitespace.
4080 - If the search string starts with an asterisk, search only in headlines.
4081 - If (possibly after the leading star) the search string starts with an
4082 exclamation mark, this also means to look at TODO entries only, an effect
4083 that can also be achieved with a prefix argument.
4084 - If (possibly after star and exclamation mark) the search string starts
4085 with a colon, this will mean that the (non-regexp) snippets of the
4086 Boolean search must match as full words.
4088 This command searches the agenda files, and in addition the files listed
4089 in `org-agenda-text-search-extra-files'."
4090 (interactive "P")
4091 (org-prepare-agenda "SEARCH")
4092 (org-compile-prefix-format 'search)
4093 (org-set-sorting-strategy 'search)
4094 (let* ((props (list 'face nil
4095 'done-face 'org-agenda-done
4096 'org-not-done-regexp org-not-done-regexp
4097 'org-todo-regexp org-todo-regexp
4098 'org-complex-heading-regexp org-complex-heading-regexp
4099 'mouse-face 'highlight
4100 'help-echo (format "mouse-2 or RET jump to location")))
4101 (full-words org-agenda-search-view-force-full-words)
4102 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4103 regexp rtn rtnall files file pos
4104 marker category category-pos tags c neg re boolean
4105 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4106 (unless (and (not edit-at)
4107 (stringp string)
4108 (string-match "\\S-" string))
4109 (setq string (read-string
4110 (if org-agenda-search-view-always-boolean
4111 "[+-]Word/{Regexp} ...: "
4112 "Phrase, or [+-]Word/{Regexp} ...: ")
4113 (cond
4114 ((integerp edit-at) (cons string edit-at))
4115 (edit-at string))
4116 'org-agenda-search-history)))
4117 (org-set-local 'org-todo-only todo-only)
4118 (setq org-agenda-redo-command
4119 (list 'org-search-view (if todo-only t nil) string
4120 '(if current-prefix-arg 1 nil)))
4121 (setq org-agenda-query-string string)
4123 (if (equal (string-to-char string) ?*)
4124 (setq hdl-only t
4125 words (substring string 1))
4126 (setq words string))
4127 (when (equal (string-to-char words) ?!)
4128 (setq todo-only t
4129 words (substring words 1)))
4130 (when (equal (string-to-char words) ?:)
4131 (setq full-words t
4132 words (substring words 1)))
4133 (if (or org-agenda-search-view-always-boolean
4134 (member (string-to-char words) '(?- ?+ ?\{)))
4135 (setq boolean t))
4136 (setq words (org-split-string words))
4137 (let (www w)
4138 (while (setq w (pop words))
4139 (while (and (string-match "\\\\\\'" w) words)
4140 (setq w (concat (substring w 0 -1) " " (pop words))))
4141 (push w www))
4142 (setq words (nreverse www) www nil)
4143 (while (setq w (pop words))
4144 (when (and (string-match "\\`[-+]?{" w)
4145 (not (string-match "}\\'" w)))
4146 (while (and words (not (string-match "}\\'" (car words))))
4147 (setq w (concat w " " (pop words))))
4148 (setq w (concat w " " (pop words))))
4149 (push w www))
4150 (setq words (nreverse www)))
4151 (setq org-agenda-last-search-view-search-was-boolean boolean)
4152 (when boolean
4153 (let (wds w)
4154 (while (setq w (pop words))
4155 (if (or (equal (substring w 0 1) "\"")
4156 (and (> (length w) 1)
4157 (member (substring w 0 1) '("+" "-"))
4158 (equal (substring w 1 2) "\"")))
4159 (while (and words (not (equal (substring w -1) "\"")))
4160 (setq w (concat w " " (pop words)))))
4161 (and (string-match "\\`\\([-+]?\\)\"" w)
4162 (setq w (replace-match "\\1" nil nil w)))
4163 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4164 (push w wds))
4165 (setq words (nreverse wds))))
4166 (if boolean
4167 (mapc (lambda (w)
4168 (setq c (string-to-char w))
4169 (if (equal c ?-)
4170 (setq neg t w (substring w 1))
4171 (if (equal c ?+)
4172 (setq neg nil w (substring w 1))
4173 (setq neg nil)))
4174 (if (string-match "\\`{.*}\\'" w)
4175 (setq re (substring w 1 -1))
4176 (if full-words
4177 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4178 (setq re (regexp-quote (downcase w)))))
4179 (if neg (push re regexps-) (push re regexps+)))
4180 words)
4181 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4182 regexps+))
4183 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4184 (if (not regexps+)
4185 (setq regexp org-outline-regexp-bol)
4186 (setq regexp (pop regexps+))
4187 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4188 regexp))))
4189 (setq files (org-agenda-files nil 'ifmode))
4190 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4191 (pop org-agenda-text-search-extra-files)
4192 (setq files (org-add-archive-files files)))
4193 (setq files (append files org-agenda-text-search-extra-files)
4194 rtnall nil)
4195 (while (setq file (pop files))
4196 (setq ee nil)
4197 (catch 'nextfile
4198 (org-check-agenda-file file)
4199 (setq buffer (if (file-exists-p file)
4200 (org-get-agenda-file-buffer file)
4201 (error "No such file %s" file)))
4202 (if (not buffer)
4203 ;; If file does not exist, make sure an error message is sent
4204 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4205 file))))
4206 (with-current-buffer buffer
4207 (with-syntax-table (org-search-syntax-table)
4208 (unless (derived-mode-p 'org-mode)
4209 (error "Agenda file %s is not in `org-mode'" file))
4210 (let ((case-fold-search t))
4211 (save-excursion
4212 (save-restriction
4213 (if org-agenda-restrict
4214 (narrow-to-region org-agenda-restrict-begin
4215 org-agenda-restrict-end)
4216 (widen))
4217 (goto-char (point-min))
4218 (unless (or (org-at-heading-p)
4219 (outline-next-heading))
4220 (throw 'nextfile t))
4221 (goto-char (max (point-min) (1- (point))))
4222 (while (re-search-forward regexp nil t)
4223 (org-back-to-heading t)
4224 (skip-chars-forward "* ")
4225 (setq beg (point-at-bol)
4226 beg1 (point)
4227 end (progn (outline-next-heading) (point)))
4228 (catch :skip
4229 (goto-char beg)
4230 (org-agenda-skip)
4231 (setq str (buffer-substring-no-properties
4232 (point-at-bol)
4233 (if hdl-only (point-at-eol) end)))
4234 (mapc (lambda (wr) (when (string-match wr str)
4235 (goto-char (1- end))
4236 (throw :skip t)))
4237 regexps-)
4238 (mapc (lambda (wr) (unless (string-match wr str)
4239 (goto-char (1- end))
4240 (throw :skip t)))
4241 (if todo-only
4242 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4243 regexps+)
4244 regexps+))
4245 (goto-char beg)
4246 (setq marker (org-agenda-new-marker (point))
4247 category (org-get-category)
4248 category-pos (get-text-property (point) 'org-category-position)
4249 tags (org-get-tags-at (point))
4250 txt (org-agenda-format-item
4252 (buffer-substring-no-properties
4253 beg1 (point-at-eol))
4254 category tags))
4255 (org-add-props txt props
4256 'org-marker marker 'org-hd-marker marker
4257 'org-todo-regexp org-todo-regexp
4258 'org-complex-heading-regexp org-complex-heading-regexp
4259 'priority 1000 'org-category category
4260 'org-category-position category-pos
4261 'type "search")
4262 (push txt ee)
4263 (goto-char (1- end))))))))))
4264 (setq rtn (nreverse ee))
4265 (setq rtnall (append rtnall rtn)))
4266 (if org-agenda-overriding-header
4267 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4268 nil 'face 'org-agenda-structure) "\n")
4269 (insert "Search words: ")
4270 (add-text-properties (point-min) (1- (point))
4271 (list 'face 'org-agenda-structure))
4272 (setq pos (point))
4273 (insert string "\n")
4274 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4275 (setq pos (point))
4276 (unless org-agenda-multi
4277 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4278 (add-text-properties pos (1- (point))
4279 (list 'face 'org-agenda-structure))))
4280 (org-agenda-mark-header-line (point-min))
4281 (when rtnall
4282 (insert (org-finalize-agenda-entries rtnall) "\n"))
4283 (goto-char (point-min))
4284 (or org-agenda-multi (org-fit-agenda-window))
4285 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4286 (org-finalize-agenda)
4287 (setq buffer-read-only t)))
4289 ;;; Agenda TODO list
4291 (defvar org-select-this-todo-keyword nil)
4292 (defvar org-last-arg nil)
4294 ;;;###autoload
4295 (defun org-todo-list (arg)
4296 "Show all (not done) TODO entries from all agenda file in a single list.
4297 The prefix arg can be used to select a specific TODO keyword and limit
4298 the list to these. When using \\[universal-argument], you will be prompted
4299 for a keyword. A numeric prefix directly selects the Nth keyword in
4300 `org-todo-keywords-1'."
4301 (interactive "P")
4302 (org-prepare-agenda "TODO")
4303 (org-compile-prefix-format 'todo)
4304 (org-set-sorting-strategy 'todo)
4305 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4306 (let* ((today (org-today))
4307 (date (calendar-gregorian-from-absolute today))
4308 (kwds org-todo-keywords-for-agenda)
4309 (completion-ignore-case t)
4310 (org-select-this-todo-keyword
4311 (if (stringp arg) arg
4312 (and arg (integerp arg) (> arg 0)
4313 (nth (1- arg) kwds))))
4314 rtn rtnall files file pos)
4315 (when (equal arg '(4))
4316 (setq org-select-this-todo-keyword
4317 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4318 (mapcar 'list kwds) nil nil)))
4319 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4320 (org-set-local 'org-last-arg arg)
4321 (setq org-agenda-redo-command
4322 '(org-todo-list (or current-prefix-arg org-last-arg)))
4323 (setq files (org-agenda-files nil 'ifmode)
4324 rtnall nil)
4325 (while (setq file (pop files))
4326 (catch 'nextfile
4327 (org-check-agenda-file file)
4328 (setq rtn (org-agenda-get-day-entries file date :todo))
4329 (setq rtnall (append rtnall rtn))))
4330 (if org-agenda-overriding-header
4331 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4332 nil 'face 'org-agenda-structure) "\n")
4333 (insert "Global list of TODO items of type: ")
4334 (add-text-properties (point-min) (1- (point))
4335 (list 'face 'org-agenda-structure
4336 'short-heading
4337 (concat "ToDo: "
4338 (or org-select-this-todo-keyword "ALL"))))
4339 (org-agenda-mark-header-line (point-min))
4340 (setq pos (point))
4341 (insert (or org-select-this-todo-keyword "ALL") "\n")
4342 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4343 (setq pos (point))
4344 (unless org-agenda-multi
4345 (insert "Available with `N r': (0)ALL")
4346 (let ((n 0) s)
4347 (mapc (lambda (x)
4348 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4349 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4350 (insert "\n "))
4351 (insert " " s))
4352 kwds))
4353 (insert "\n"))
4354 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4355 (org-agenda-mark-header-line (point-min))
4356 (when rtnall
4357 (insert (org-finalize-agenda-entries rtnall) "\n"))
4358 (goto-char (point-min))
4359 (or org-agenda-multi (org-fit-agenda-window))
4360 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4361 (org-finalize-agenda)
4362 (setq buffer-read-only t)))
4364 ;;; Agenda tags match
4366 ;;;###autoload
4367 (defun org-tags-view (&optional todo-only match)
4368 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4369 The prefix arg TODO-ONLY limits the search to TODO entries."
4370 (interactive "P")
4371 (let* ((org-tags-match-list-sublevels
4372 org-tags-match-list-sublevels)
4373 (completion-ignore-case t)
4374 rtn rtnall files file pos matcher
4375 buffer)
4376 (when (and (stringp match) (not (string-match "\\S-" match)))
4377 (setq match nil))
4378 (setq matcher (org-make-tags-matcher match)
4379 match (car matcher) matcher (cdr matcher))
4380 (org-prepare-agenda (concat "TAGS " match))
4381 (org-compile-prefix-format 'tags)
4382 (org-set-sorting-strategy 'tags)
4383 (setq org-agenda-query-string match)
4384 (setq org-agenda-redo-command
4385 (list 'org-tags-view (list 'quote todo-only)
4386 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4387 (setq files (org-agenda-files nil 'ifmode)
4388 rtnall nil)
4389 (while (setq file (pop files))
4390 (catch 'nextfile
4391 (org-check-agenda-file file)
4392 (setq buffer (if (file-exists-p file)
4393 (org-get-agenda-file-buffer file)
4394 (error "No such file %s" file)))
4395 (if (not buffer)
4396 ;; If file does not exist, error message to agenda
4397 (setq rtn (list
4398 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4399 rtnall (append rtnall rtn))
4400 (with-current-buffer buffer
4401 (unless (derived-mode-p 'org-mode)
4402 (error "Agenda file %s is not in `org-mode'" file))
4403 (save-excursion
4404 (save-restriction
4405 (if org-agenda-restrict
4406 (narrow-to-region org-agenda-restrict-begin
4407 org-agenda-restrict-end)
4408 (widen))
4409 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4410 (setq rtnall (append rtnall rtn))))))))
4411 (if org-agenda-overriding-header
4412 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4413 nil 'face 'org-agenda-structure) "\n")
4414 (insert "Headlines with TAGS match: ")
4415 (add-text-properties (point-min) (1- (point))
4416 (list 'face 'org-agenda-structure
4417 'short-heading
4418 (concat "Match: " match)))
4419 (setq pos (point))
4420 (insert match "\n")
4421 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4422 (setq pos (point))
4423 (unless org-agenda-multi
4424 (insert "Press `C-u r' to search again with new search string\n"))
4425 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4426 (org-agenda-mark-header-line (point-min))
4427 (when rtnall
4428 (insert (org-finalize-agenda-entries rtnall) "\n"))
4429 (goto-char (point-min))
4430 (or org-agenda-multi (org-fit-agenda-window))
4431 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4432 (org-finalize-agenda)
4433 (setq buffer-read-only t)))
4435 ;;; Agenda Finding stuck projects
4437 (defvar org-agenda-skip-regexp nil
4438 "Regular expression used in skipping subtrees for the agenda.
4439 This is basically a temporary global variable that can be set and then
4440 used by user-defined selections using `org-agenda-skip-function'.")
4442 (defvar org-agenda-overriding-header nil
4443 "When set during agenda, todo and tags searches it replaces the header.
4444 This variable should not be set directly, but custom commands can bind it
4445 in the options section.")
4447 (defun org-agenda-skip-entry-when-regexp-matches ()
4448 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4449 If yes, it returns the end position of this entry, causing agenda commands
4450 to skip the entry but continuing the search in the subtree. This is a
4451 function that can be put into `org-agenda-skip-function' for the duration
4452 of a command."
4453 (let ((end (save-excursion (org-end-of-subtree t)))
4454 skip)
4455 (save-excursion
4456 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4457 (and skip end)))
4459 (defun org-agenda-skip-subtree-when-regexp-matches ()
4460 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4461 If yes, it returns the end position of this tree, causing agenda commands
4462 to skip this subtree. This is a function that can be put into
4463 `org-agenda-skip-function' for the duration of a command."
4464 (let ((end (save-excursion (org-end-of-subtree t)))
4465 skip)
4466 (save-excursion
4467 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4468 (and skip end)))
4470 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4471 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4472 If yes, it returns the end position of the current entry (NOT the tree),
4473 causing agenda commands to skip the entry but continuing the search in
4474 the subtree. This is a function that can be put into
4475 `org-agenda-skip-function' for the duration of a command. An important
4476 use of this function is for the stuck project list."
4477 (let ((end (save-excursion (org-end-of-subtree t)))
4478 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4479 skip)
4480 (save-excursion
4481 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4482 (and skip entry-end)))
4484 (defun org-agenda-skip-entry-if (&rest conditions)
4485 "Skip entry if any of CONDITIONS is true.
4486 See `org-agenda-skip-if' for details."
4487 (org-agenda-skip-if nil conditions))
4489 (defun org-agenda-skip-subtree-if (&rest conditions)
4490 "Skip entry if any of CONDITIONS is true.
4491 See `org-agenda-skip-if' for details."
4492 (org-agenda-skip-if t conditions))
4494 (defun org-agenda-skip-if (subtree conditions)
4495 "Checks current entity for CONDITIONS.
4496 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4497 the entry (i.e. the text before the next heading) is checked.
4499 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4500 from different tests. Valid conditions are:
4502 scheduled Check if there is a scheduled cookie
4503 notscheduled Check if there is no scheduled cookie
4504 deadline Check if there is a deadline
4505 notdeadline Check if there is no deadline
4506 timestamp Check if there is a timestamp (also deadline or scheduled)
4507 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4508 regexp Check if regexp matches
4509 notregexp Check if regexp does not match.
4510 todo Check if TODO keyword matches
4511 nottodo Check if TODO keyword does not match
4513 The regexp is taken from the conditions list, it must come right after
4514 the `regexp' or `notregexp' element.
4516 `todo' and `nottodo' accept as an argument a list of todo
4517 keywords, which may include \"*\" to match any todo keyword.
4519 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4521 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4523 Instead of a list, a keyword class may be given. For example:
4525 (org-agenda-skip-entry-if 'nottodo 'done)
4527 would skip entries that haven't been marked with any of \"DONE\"
4528 keywords. Possible classes are: `todo', `done', `any'.
4530 If any of these conditions is met, this function returns the end point of
4531 the entity, causing the search to continue from there. This is a function
4532 that can be put into `org-agenda-skip-function' for the duration of a command."
4533 (let (beg end m)
4534 (org-back-to-heading t)
4535 (setq beg (point)
4536 end (if subtree
4537 (progn (org-end-of-subtree t) (point))
4538 (progn (outline-next-heading) (1- (point)))))
4539 (goto-char beg)
4540 (and
4542 (and (memq 'scheduled conditions)
4543 (re-search-forward org-scheduled-time-regexp end t))
4544 (and (memq 'notscheduled conditions)
4545 (not (re-search-forward org-scheduled-time-regexp end t)))
4546 (and (memq 'deadline conditions)
4547 (re-search-forward org-deadline-time-regexp end t))
4548 (and (memq 'notdeadline conditions)
4549 (not (re-search-forward org-deadline-time-regexp end t)))
4550 (and (memq 'timestamp conditions)
4551 (re-search-forward org-ts-regexp end t))
4552 (and (memq 'nottimestamp conditions)
4553 (not (re-search-forward org-ts-regexp end t)))
4554 (and (setq m (memq 'regexp conditions))
4555 (stringp (nth 1 m))
4556 (re-search-forward (nth 1 m) end t))
4557 (and (setq m (memq 'notregexp conditions))
4558 (stringp (nth 1 m))
4559 (not (re-search-forward (nth 1 m) end t)))
4560 (and (or
4561 (setq m (memq 'nottodo conditions))
4562 (setq m (memq 'todo-unblocked conditions))
4563 (setq m (memq 'nottodo-unblocked conditions))
4564 (setq m (memq 'todo conditions)))
4565 (org-agenda-skip-if-todo m end)))
4566 end)))
4568 (defun org-agenda-skip-if-todo (args end)
4569 "Helper function for `org-agenda-skip-if', do not use it directly.
4570 ARGS is a list with first element either `todo', `nottodo',
4571 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4572 a list of TODO keywords, or a state symbol `todo' or `done' or
4573 `any'."
4574 (let ((kw (car args))
4575 (arg (cadr args))
4576 todo-wds todo-re)
4577 (setq todo-wds
4578 (org-uniquify
4579 (cond
4580 ((listp arg) ;; list of keywords
4581 (if (member "*" arg)
4582 (mapcar 'substring-no-properties org-todo-keywords-1)
4583 arg))
4584 ((symbolp arg) ;; keyword class name
4585 (cond
4586 ((eq arg 'todo)
4587 (org-delete-all org-done-keywords
4588 (mapcar 'substring-no-properties
4589 org-todo-keywords-1)))
4590 ((eq arg 'done) org-done-keywords)
4591 ((eq arg 'any)
4592 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4593 (setq todo-re
4594 (concat "^\\*+[ \t]+\\<\\("
4595 (mapconcat 'identity todo-wds "\\|")
4596 "\\)\\>"))
4597 (cond
4598 ((eq kw 'todo) (re-search-forward todo-re end t))
4599 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4600 ((eq kw 'todo-unblocked)
4601 (catch 'unblocked
4602 (while (re-search-forward todo-re end t)
4603 (or (org-entry-blocked-p) (throw 'unblocked t)))
4604 nil))
4605 ((eq kw 'nottodo-unblocked)
4606 (catch 'unblocked
4607 (while (re-search-forward todo-re end t)
4608 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4612 ;;;###autoload
4613 (defun org-agenda-list-stuck-projects (&rest ignore)
4614 "Create agenda view for projects that are stuck.
4615 Stuck projects are project that have no next actions. For the definitions
4616 of what a project is and how to check if it stuck, customize the variable
4617 `org-stuck-projects'."
4618 (interactive)
4619 (let* ((org-agenda-skip-function
4620 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4621 ;; We could have used org-agenda-skip-if here.
4622 (org-agenda-overriding-header
4623 (or org-agenda-overriding-header "List of stuck projects: "))
4624 (matcher (nth 0 org-stuck-projects))
4625 (todo (nth 1 org-stuck-projects))
4626 (todo-wds (if (member "*" todo)
4627 (progn
4628 (org-prepare-agenda-buffers (org-agenda-files
4629 nil 'ifmode))
4630 (org-delete-all
4631 org-done-keywords-for-agenda
4632 (copy-sequence org-todo-keywords-for-agenda)))
4633 todo))
4634 (todo-re (concat "^\\*+[ \t]+\\("
4635 (mapconcat 'identity todo-wds "\\|")
4636 "\\)\\>"))
4637 (tags (nth 2 org-stuck-projects))
4638 (tags-re (if (member "*" tags)
4639 (concat org-outline-regexp-bol
4640 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4641 (if tags
4642 (concat org-outline-regexp-bol
4643 ".*:\\("
4644 (mapconcat 'identity tags "\\|")
4645 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4646 (gen-re (nth 3 org-stuck-projects))
4647 (re-list
4648 (delq nil
4649 (list
4650 (if todo todo-re)
4651 (if tags tags-re)
4652 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4653 gen-re)))))
4654 (setq org-agenda-skip-regexp
4655 (if re-list
4656 (mapconcat 'identity re-list "\\|")
4657 (error "No information how to identify unstuck projects")))
4658 (org-tags-view nil matcher)
4659 (with-current-buffer org-agenda-buffer-name
4660 (setq org-agenda-redo-command
4661 '(org-agenda-list-stuck-projects
4662 (or current-prefix-arg org-last-arg))))))
4664 ;;; Diary integration
4666 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4667 (defvar diary-list-entries-hook)
4668 (defvar diary-time-regexp)
4669 (defun org-get-entries-from-diary (date)
4670 "Get the (Emacs Calendar) diary entries for DATE."
4671 (require 'diary-lib)
4672 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4673 (diary-display-hook '(fancy-diary-display))
4674 (diary-display-function 'fancy-diary-display)
4675 (pop-up-frames nil)
4676 (diary-list-entries-hook
4677 (cons 'org-diary-default-entry diary-list-entries-hook))
4678 (diary-file-name-prefix-function nil) ; turn this feature off
4679 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4680 entries
4681 (org-disable-agenda-to-diary t))
4682 (save-excursion
4683 (save-window-excursion
4684 (funcall (if (fboundp 'diary-list-entries)
4685 'diary-list-entries 'list-diary-entries)
4686 date 1)))
4687 (if (not (get-buffer diary-fancy-buffer))
4688 (setq entries nil)
4689 (with-current-buffer diary-fancy-buffer
4690 (setq buffer-read-only nil)
4691 (if (zerop (buffer-size))
4692 ;; No entries
4693 (setq entries nil)
4694 ;; Omit the date and other unnecessary stuff
4695 (org-agenda-cleanup-fancy-diary)
4696 ;; Add prefix to each line and extend the text properties
4697 (if (zerop (buffer-size))
4698 (setq entries nil)
4699 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4700 (setq entries
4701 (with-temp-buffer
4702 (insert entries) (goto-char (point-min))
4703 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4704 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4705 (replace-match (concat "; " (match-string 1)))))
4706 (buffer-string)))))
4707 (set-buffer-modified-p nil)
4708 (kill-buffer diary-fancy-buffer)))
4709 (when entries
4710 (setq entries (org-split-string entries "\n"))
4711 (setq entries
4712 (mapcar
4713 (lambda (x)
4714 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4715 ;; Extend the text properties to the beginning of the line
4716 (org-add-props x (text-properties-at (1- (length x)) x)
4717 'type "diary" 'date date 'face 'org-agenda-diary))
4718 entries)))))
4720 (defvar org-agenda-cleanup-fancy-diary-hook nil
4721 "Hook run when the fancy diary buffer is cleaned up.")
4723 (defun org-agenda-cleanup-fancy-diary ()
4724 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4725 This gets rid of the date, the underline under the date, and
4726 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4727 date. It also removes lines that contain only whitespace."
4728 (goto-char (point-min))
4729 (if (looking-at ".*?:[ \t]*")
4730 (progn
4731 (replace-match "")
4732 (re-search-forward "\n=+$" nil t)
4733 (replace-match "")
4734 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4735 (re-search-forward "\n=+$" nil t)
4736 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4737 (goto-char (point-min))
4738 (while (re-search-forward "^ +\n" nil t)
4739 (replace-match ""))
4740 (goto-char (point-min))
4741 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4742 (replace-match ""))
4743 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4745 ;; Make sure entries from the diary have the right text properties.
4746 (eval-after-load "diary-lib"
4747 '(if (boundp 'diary-modify-entry-list-string-function)
4748 ;; We can rely on the hook, nothing to do
4750 ;; Hook not available, must use advice to make this work
4751 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4752 "Make the position visible."
4753 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4754 (stringp string)
4755 buffer-file-name)
4756 (setq string (org-modify-diary-entry-string string))))))
4758 (defun org-modify-diary-entry-string (string)
4759 "Add text properties to string, allowing org-mode to act on it."
4760 (org-add-props string nil
4761 'mouse-face 'highlight
4762 'help-echo (if buffer-file-name
4763 (format "mouse-2 or RET jump to diary file %s"
4764 (abbreviate-file-name buffer-file-name))
4766 'org-agenda-diary-link t
4767 'org-marker (org-agenda-new-marker (point-at-bol))))
4769 (defun org-diary-default-entry ()
4770 "Add a dummy entry to the diary.
4771 Needed to avoid empty dates which mess up holiday display."
4772 ;; Catch the error if dealing with the new add-to-diary-alist
4773 (when org-disable-agenda-to-diary
4774 (condition-case nil
4775 (org-add-to-diary-list original-date "Org-mode dummy" "")
4776 (error
4777 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4779 (defun org-add-to-diary-list (&rest args)
4780 (if (fboundp 'diary-add-to-list)
4781 (apply 'diary-add-to-list args)
4782 (apply 'add-to-diary-list args)))
4784 (defvar org-diary-last-run-time nil)
4786 ;;;###autoload
4787 (defun org-diary (&rest args)
4788 "Return diary information from org files.
4789 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4790 It accesses org files and extracts information from those files to be
4791 listed in the diary. The function accepts arguments specifying what
4792 items should be listed. For a list of arguments allowed here, see the
4793 variable `org-agenda-entry-types'.
4795 The call in the diary file should look like this:
4797 &%%(org-diary) ~/path/to/some/orgfile.org
4799 Use a separate line for each org file to check. Or, if you omit the file name,
4800 all files listed in `org-agenda-files' will be checked automatically:
4802 &%%(org-diary)
4804 If you don't give any arguments (as in the example above), the default
4805 arguments (:deadline :scheduled :timestamp :sexp) are used.
4806 So the example above may also be written as
4808 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4810 The function expects the lisp variables `entry' and `date' to be provided
4811 by the caller, because this is how the calendar works. Don't use this
4812 function from a program - use `org-agenda-get-day-entries' instead."
4813 (when (> (- (org-float-time)
4814 org-agenda-last-marker-time)
4816 ;; I am not sure if this works with sticky agendas, because the marker
4817 ;; list is then no longer a global variable.
4818 (org-agenda-reset-markers))
4819 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4820 (when (buffer-live-p org-agenda-buffer)
4821 (org-compile-prefix-format 'agenda))
4822 (org-set-sorting-strategy 'agenda)
4823 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4824 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4825 (list entry)
4826 (org-agenda-files t)))
4827 (time (org-float-time))
4828 file rtn results)
4829 (when (or (not org-diary-last-run-time)
4830 (> (- time
4831 org-diary-last-run-time)
4833 (org-prepare-agenda-buffers files))
4834 (setq org-diary-last-run-time time)
4835 ;; If this is called during org-agenda, don't return any entries to
4836 ;; the calendar. Org Agenda will list these entries itself.
4837 (if org-disable-agenda-to-diary (setq files nil))
4838 (while (setq file (pop files))
4839 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4840 (setq results (append results rtn)))
4841 (if results
4842 (concat (org-finalize-agenda-entries results) "\n"))))
4844 ;;; Agenda entry finders
4846 (defun org-agenda-get-day-entries (file date &rest args)
4847 "Does the work for `org-diary' and `org-agenda'.
4848 FILE is the path to a file to be checked for entries. DATE is date like
4849 the one returned by `calendar-current-date'. ARGS are symbols indicating
4850 which kind of entries should be extracted. For details about these, see
4851 the documentation of `org-diary'."
4852 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4853 (let* ((org-startup-folded nil)
4854 (org-startup-align-all-tables nil)
4855 (buffer (if (file-exists-p file)
4856 (org-get-agenda-file-buffer file)
4857 (error "No such file %s" file)))
4858 arg results rtn deadline-results)
4859 (if (not buffer)
4860 ;; If file does not exist, make sure an error message ends up in diary
4861 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4862 (with-current-buffer buffer
4863 (unless (derived-mode-p 'org-mode)
4864 (error "Agenda file %s is not in `org-mode'" file))
4865 (let ((case-fold-search nil))
4866 (save-excursion
4867 (save-restriction
4868 (if org-agenda-restrict
4869 (narrow-to-region org-agenda-restrict-begin
4870 org-agenda-restrict-end)
4871 (widen))
4872 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4873 (while (setq arg (pop args))
4874 (cond
4875 ((and (eq arg :todo)
4876 (equal date (calendar-gregorian-from-absolute
4877 (org-today))))
4878 (setq rtn (org-agenda-get-todos))
4879 (setq results (append results rtn)))
4880 ((eq arg :timestamp)
4881 (setq rtn (org-agenda-get-blocks))
4882 (setq results (append results rtn))
4883 (setq rtn (org-agenda-get-timestamps deadline-results))
4884 (setq results (append results rtn)))
4885 ((eq arg :sexp)
4886 (setq rtn (org-agenda-get-sexps))
4887 (setq results (append results rtn)))
4888 ((eq arg :scheduled)
4889 (setq rtn (org-agenda-get-scheduled deadline-results))
4890 (setq results (append results rtn)))
4891 ((eq arg :closed)
4892 (setq rtn (org-agenda-get-progress))
4893 (setq results (append results rtn)))
4894 ((eq arg :deadline)
4895 (setq rtn (org-agenda-get-deadlines))
4896 (setq deadline-results (copy-sequence rtn))
4897 (setq results (append results rtn))))))))
4898 results))))
4900 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4901 (defun org-agenda-get-todos ()
4902 "Return the TODO information for agenda display."
4903 (let* ((props (list 'face nil
4904 'done-face 'org-agenda-done
4905 'org-not-done-regexp org-not-done-regexp
4906 'org-todo-regexp org-todo-regexp
4907 'org-complex-heading-regexp org-complex-heading-regexp
4908 'mouse-face 'highlight
4909 'help-echo
4910 (format "mouse-2 or RET jump to org file %s"
4911 (abbreviate-file-name buffer-file-name))))
4912 (regexp (format org-heading-keyword-regexp-format
4913 (cond
4914 ((and org-select-this-todo-keyword
4915 (equal org-select-this-todo-keyword "*"))
4916 org-todo-regexp)
4917 (org-select-this-todo-keyword
4918 (concat "\\("
4919 (mapconcat 'identity
4920 (org-split-string
4921 org-select-this-todo-keyword
4922 "|")
4923 "\\|") "\\)"))
4924 (t org-not-done-regexp))))
4925 marker priority category category-pos tags todo-state
4926 ee txt beg end)
4927 (goto-char (point-min))
4928 (while (re-search-forward regexp nil t)
4929 (catch :skip
4930 (save-match-data
4931 (beginning-of-line)
4932 (org-agenda-skip)
4933 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4934 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4935 (goto-char (1+ beg))
4936 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4937 (throw :skip nil)))
4938 (goto-char (match-beginning 2))
4939 (setq marker (org-agenda-new-marker (match-beginning 0))
4940 category (org-get-category)
4941 category-pos (get-text-property (point) 'org-category-position)
4942 txt (org-trim
4943 (buffer-substring (match-beginning 2) (match-end 0)))
4944 tags (org-get-tags-at (point))
4945 txt (org-agenda-format-item "" txt category tags)
4946 priority (1+ (org-get-priority txt))
4947 todo-state (org-get-todo-state))
4948 (org-add-props txt props
4949 'org-marker marker 'org-hd-marker marker
4950 'priority priority 'org-category category
4951 'org-category-position category-pos
4952 'type "todo" 'todo-state todo-state)
4953 (push txt ee)
4954 (if org-agenda-todo-list-sublevels
4955 (goto-char (match-end 2))
4956 (org-end-of-subtree 'invisible))))
4957 (nreverse ee)))
4959 (defun org-agenda-todo-custom-ignore-p (time n)
4960 "Check whether timestamp is farther away then n number of days.
4961 This function is invoked if `org-agenda-todo-ignore-deadlines',
4962 `org-agenda-todo-ignore-scheduled' or
4963 `org-agenda-todo-ignore-timestamp' is set to an integer."
4964 (let ((days (org-days-to-time time)))
4965 (if (>= n 0)
4966 (>= days n)
4967 (<= days n))))
4969 ;;;###autoload
4970 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4971 (&optional end)
4972 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4973 (when (or org-agenda-todo-ignore-with-date
4974 org-agenda-todo-ignore-scheduled
4975 org-agenda-todo-ignore-deadlines
4976 org-agenda-todo-ignore-timestamp)
4977 (setq end (or end (save-excursion (outline-next-heading) (point))))
4978 (save-excursion
4979 (or (and org-agenda-todo-ignore-with-date
4980 (re-search-forward org-ts-regexp end t))
4981 (and org-agenda-todo-ignore-scheduled
4982 (re-search-forward org-scheduled-time-regexp end t)
4983 (cond
4984 ((eq org-agenda-todo-ignore-scheduled 'future)
4985 (> (org-days-to-time (match-string 1)) 0))
4986 ((eq org-agenda-todo-ignore-scheduled 'past)
4987 (<= (org-days-to-time (match-string 1)) 0))
4988 ((numberp org-agenda-todo-ignore-scheduled)
4989 (org-agenda-todo-custom-ignore-p
4990 (match-string 1) org-agenda-todo-ignore-scheduled))
4991 (t)))
4992 (and org-agenda-todo-ignore-deadlines
4993 (re-search-forward org-deadline-time-regexp end t)
4994 (cond
4995 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4996 ((eq org-agenda-todo-ignore-deadlines 'far)
4997 (not (org-deadline-close (match-string 1))))
4998 ((eq org-agenda-todo-ignore-deadlines 'future)
4999 (> (org-days-to-time (match-string 1)) 0))
5000 ((eq org-agenda-todo-ignore-deadlines 'past)
5001 (<= (org-days-to-time (match-string 1)) 0))
5002 ((numberp org-agenda-todo-ignore-deadlines)
5003 (org-agenda-todo-custom-ignore-p
5004 (match-string 1) org-agenda-todo-ignore-deadlines))
5005 (t (org-deadline-close (match-string 1)))))
5006 (and org-agenda-todo-ignore-timestamp
5007 (let ((buffer (current-buffer))
5008 (regexp
5009 (concat
5010 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5011 (start (point)))
5012 ;; Copy current buffer into a temporary one
5013 (with-temp-buffer
5014 (insert-buffer-substring buffer start end)
5015 (goto-char (point-min))
5016 ;; Delete SCHEDULED and DEADLINE items
5017 (while (re-search-forward regexp end t)
5018 (delete-region (match-beginning 0) (match-end 0)))
5019 (goto-char (point-min))
5020 ;; No search for timestamp left
5021 (when (re-search-forward org-ts-regexp nil t)
5022 (cond
5023 ((eq org-agenda-todo-ignore-timestamp 'future)
5024 (> (org-days-to-time (match-string 1)) 0))
5025 ((eq org-agenda-todo-ignore-timestamp 'past)
5026 (<= (org-days-to-time (match-string 1)) 0))
5027 ((numberp org-agenda-todo-ignore-timestamp)
5028 (org-agenda-todo-custom-ignore-p
5029 (match-string 1) org-agenda-todo-ignore-timestamp))
5030 (t))))))))))
5032 (defconst org-agenda-no-heading-message
5033 "No heading for this item in buffer or region.")
5035 (defun org-agenda-get-timestamps (&optional deadline-results)
5036 "Return the date stamp information for agenda display."
5037 (let* ((props (list 'face 'org-agenda-calendar-event
5038 'org-not-done-regexp org-not-done-regexp
5039 'org-todo-regexp org-todo-regexp
5040 'org-complex-heading-regexp org-complex-heading-regexp
5041 'mouse-face 'highlight
5042 'help-echo
5043 (format "mouse-2 or RET jump to org file %s"
5044 (abbreviate-file-name buffer-file-name))))
5045 (d1 (calendar-absolute-from-gregorian date))
5047 (deadline-position-alist
5048 (mapcar (lambda (a) (and (setq mm (get-text-property
5049 0 'org-hd-marker a))
5050 (cons (marker-position mm) a)))
5051 deadline-results))
5052 (remove-re org-ts-regexp)
5053 (regexp
5054 (concat
5055 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5056 (regexp-quote
5057 (substring
5058 (format-time-string
5059 (car org-time-stamp-formats)
5060 (apply 'encode-time ; DATE bound by calendar
5061 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5062 1 11))
5063 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5064 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5065 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5066 donep tmp priority category category-pos ee txt timestr tags
5067 b0 b3 e3 head todo-state end-of-match show-all warntime)
5068 (goto-char (point-min))
5069 (while (setq end-of-match (re-search-forward regexp nil t))
5070 (setq b0 (match-beginning 0)
5071 b3 (match-beginning 3) e3 (match-end 3)
5072 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5073 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5074 (member todo-state
5075 org-agenda-repeating-timestamp-show-all)))
5076 (catch :skip
5077 (and (org-at-date-range-p) (throw :skip nil))
5078 (org-agenda-skip)
5079 (if (and (match-end 1)
5080 (not (= d1 (org-time-string-to-absolute
5081 (match-string 1) d1 nil show-all
5082 (current-buffer) b0))))
5083 (throw :skip nil))
5084 (if (and e3
5085 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5086 (throw :skip nil))
5087 (setq tmp (buffer-substring (max (point-min)
5088 (- b0 org-ds-keyword-length))
5090 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5091 inactivep (= (char-after b0) ?\[)
5092 deadlinep (string-match org-deadline-regexp tmp)
5093 scheduledp (string-match org-scheduled-regexp tmp)
5094 closedp (and org-agenda-include-inactive-timestamps
5095 (string-match org-closed-string tmp))
5096 clockp (and org-agenda-include-inactive-timestamps
5097 (or (string-match org-clock-string tmp)
5098 (string-match "]-+\\'" tmp)))
5099 warntime (org-entry-get (point) "APPT_WARNTIME")
5100 donep (member todo-state org-done-keywords))
5101 (if (or scheduledp deadlinep closedp clockp
5102 (and donep org-agenda-skip-timestamp-if-done))
5103 (throw :skip t))
5104 (if (string-match ">" timestr)
5105 ;; substring should only run to end of time stamp
5106 (setq timestr (substring timestr 0 (match-end 0))))
5107 (setq marker (org-agenda-new-marker b0)
5108 category (org-get-category b0)
5109 category-pos (get-text-property b0 'org-category-position))
5110 (save-excursion
5111 (if (not (re-search-backward org-outline-regexp-bol nil t))
5112 (setq txt org-agenda-no-heading-message)
5113 (goto-char (match-beginning 0))
5114 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5115 (assoc (point) deadline-position-alist))
5116 (throw :skip nil))
5117 (setq hdmarker (org-agenda-new-marker)
5118 tags (org-get-tags-at))
5119 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5120 (setq head (or (match-string 1) ""))
5121 (setq txt (org-agenda-format-item
5122 (if inactivep org-agenda-inactive-leader nil)
5123 head category tags timestr
5124 remove-re)))
5125 (setq priority (org-get-priority txt))
5126 (org-add-props txt props
5127 'org-marker marker 'org-hd-marker hdmarker)
5128 (org-add-props txt nil 'priority priority
5129 'org-category category 'date date
5130 'org-category-position category-pos
5131 'todo-state todo-state
5132 'warntime warntime
5133 'type "timestamp")
5134 (push txt ee))
5135 (if org-agenda-skip-additional-timestamps-same-entry
5136 (outline-next-heading)
5137 (goto-char end-of-match))))
5138 (nreverse ee)))
5140 (defun org-agenda-get-sexps ()
5141 "Return the sexp information for agenda display."
5142 (require 'diary-lib)
5143 (let* ((props (list 'face 'org-agenda-calendar-sexp
5144 'mouse-face 'highlight
5145 'help-echo
5146 (format "mouse-2 or RET jump to org file %s"
5147 (abbreviate-file-name buffer-file-name))))
5148 (regexp "^&?%%(")
5149 marker category extra category-pos ee txt tags entry
5150 result beg b sexp sexp-entry todo-state warntime)
5151 (goto-char (point-min))
5152 (while (re-search-forward regexp nil t)
5153 (catch :skip
5154 (org-agenda-skip)
5155 (setq beg (match-beginning 0))
5156 (goto-char (1- (match-end 0)))
5157 (setq b (point))
5158 (forward-sexp 1)
5159 (setq sexp (buffer-substring b (point)))
5160 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5161 (org-trim (match-string 1))
5162 ""))
5163 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5164 (when result
5165 (setq marker (org-agenda-new-marker beg)
5166 category (org-get-category beg)
5167 category-pos (get-text-property beg 'org-category-position)
5168 tags (save-excursion (org-backward-heading-same-level 0)
5169 (org-get-tags-at))
5170 todo-state (org-get-todo-state)
5171 warntime (org-entry-get (point) "APPT_WARNTIME"))
5173 (dolist (r (if (stringp result)
5174 (list result)
5175 result)) ;; we expect a list here
5176 (when (and org-agenda-diary-sexp-prefix
5177 (string-match org-agenda-diary-sexp-prefix r))
5178 (setq extra (match-string 0 r)
5179 r (replace-match "" nil nil r)))
5180 (if (string-match "\\S-" r)
5181 (setq txt r)
5182 (setq txt "SEXP entry returned empty string"))
5184 (setq txt (org-agenda-format-item
5185 extra txt category tags 'time))
5186 (org-add-props txt props 'org-marker marker)
5187 (org-add-props txt nil
5188 'org-category category 'date date 'todo-state todo-state
5189 'org-category-position category-pos 'tags tags
5190 'type "sexp" 'warntime warntime)
5191 (push txt ee)))))
5192 (nreverse ee)))
5194 ;; Calendar sanity: define some functions that are independent of
5195 ;; `calendar-date-style'.
5196 ;; Normally I would like to use ISO format when calling the diary functions,
5197 ;; but to make sure we still have Emacs 22 compatibility we bind
5198 ;; also `european-calendar-style' and use european format
5199 (defun org-anniversary (year month day &optional mark)
5200 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5201 (org-no-warnings
5202 (let ((calendar-date-style 'european) (european-calendar-style t))
5203 (diary-anniversary day month year mark))))
5204 (defun org-cyclic (N year month day &optional mark)
5205 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5206 (org-no-warnings
5207 (let ((calendar-date-style 'european) (european-calendar-style t))
5208 (diary-cyclic N day month year mark))))
5209 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5210 "Like `diary-block', but with fixed (ISO) order of arguments."
5211 (org-no-warnings
5212 (let ((calendar-date-style 'european) (european-calendar-style t))
5213 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5214 (defun org-date (year month day &optional mark)
5215 "Like `diary-date', but with fixed (ISO) order of arguments."
5216 (org-no-warnings
5217 (let ((calendar-date-style 'european) (european-calendar-style t))
5218 (diary-date day month year mark))))
5219 (defalias 'org-float 'diary-float)
5221 ;; Define the` org-class' function
5222 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5223 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5224 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5225 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5226 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5227 `holidays', then any date that is known by the Emacs calendar to be a
5228 holiday will also be skipped."
5229 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5230 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5231 (d (calendar-absolute-from-gregorian date)))
5232 (and
5233 (<= date1 d)
5234 (<= d date2)
5235 (= (calendar-day-of-week date) dayname)
5236 (or (not skip-weeks)
5237 (progn
5238 (require 'cal-iso)
5239 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5240 (not (and (memq 'holidays skip-weeks)
5241 (calendar-check-holidays date)))
5242 entry)))
5244 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5245 "Like `org-class', but honor `calendar-date-style'.
5246 The order of the first 2 times 3 arguments depends on the variable
5247 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5248 So for American calendars, give this as MONTH DAY YEAR, for European as
5249 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5250 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5251 is any number of ISO weeks in the block period for which the item should
5252 be skipped.
5254 This function is here only for backward compatibility and it is deprecated,
5255 please use `org-class' instead."
5256 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5257 (date2 (org-order-calendar-date-args m2 d2 y2)))
5258 (org-class
5259 (nth 2 date1) (car date1) (nth 1 date1)
5260 (nth 2 date2) (car date2) (nth 1 date2)
5261 dayname skip-weeks)))
5262 (make-obsolete 'org-diary-class 'org-class "")
5264 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5265 (defalias 'org-get-closed 'org-agenda-get-progress)
5266 (defun org-agenda-get-progress ()
5267 "Return the logged TODO entries for agenda display."
5268 (let* ((props (list 'mouse-face 'highlight
5269 'org-not-done-regexp org-not-done-regexp
5270 'org-todo-regexp org-todo-regexp
5271 'org-complex-heading-regexp org-complex-heading-regexp
5272 'help-echo
5273 (format "mouse-2 or RET jump to org file %s"
5274 (abbreviate-file-name buffer-file-name))))
5275 (items (if (consp org-agenda-show-log-scoped)
5276 org-agenda-show-log-scoped
5277 (if (eq org-agenda-show-log-scoped 'clockcheck)
5278 '(clock)
5279 org-agenda-log-mode-items)))
5280 (parts
5281 (delq nil
5282 (list
5283 (if (memq 'closed items) (concat "\\<" org-closed-string))
5284 (if (memq 'clock items) (concat "\\<" org-clock-string))
5285 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5286 (parts-re (if parts (mapconcat 'identity parts "\\|")
5287 (error "`org-agenda-log-mode-items' is empty")))
5288 (regexp (concat
5289 "\\(" parts-re "\\)"
5290 " *\\["
5291 (regexp-quote
5292 (substring
5293 (format-time-string
5294 (car org-time-stamp-formats)
5295 (apply 'encode-time ; DATE bound by calendar
5296 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5297 1 11))))
5298 (org-agenda-search-headline-for-time nil)
5299 marker hdmarker priority category category-pos tags closedp
5300 statep clockp state ee txt extra timestr rest clocked)
5301 (goto-char (point-min))
5302 (while (re-search-forward regexp nil t)
5303 (catch :skip
5304 (org-agenda-skip)
5305 (setq marker (org-agenda-new-marker (match-beginning 0))
5306 closedp (equal (match-string 1) org-closed-string)
5307 statep (equal (string-to-char (match-string 1)) ?-)
5308 clockp (not (or closedp statep))
5309 state (and statep (match-string 2))
5310 category (org-get-category (match-beginning 0))
5311 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5312 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5313 (when (string-match "\\]" timestr)
5314 ;; substring should only run to end of time stamp
5315 (setq rest (substring timestr (match-end 0))
5316 timestr (substring timestr 0 (match-end 0)))
5317 (if (and (not closedp) (not statep)
5318 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5319 rest))
5320 (progn (setq timestr (concat (substring timestr 0 -1)
5321 "-" (match-string 1 rest) "]"))
5322 (setq clocked (match-string 2 rest)))
5323 (setq clocked "-")))
5324 (save-excursion
5325 (setq extra
5326 (cond
5327 ((not org-agenda-log-mode-add-notes) nil)
5328 (statep
5329 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5330 (match-string 1)))
5331 (clockp
5332 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5333 (match-string 1)))))
5334 (if (not (re-search-backward org-outline-regexp-bol nil t))
5335 (setq txt org-agenda-no-heading-message)
5336 (goto-char (match-beginning 0))
5337 (setq hdmarker (org-agenda-new-marker)
5338 tags (org-get-tags-at))
5339 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5340 (setq txt (match-string 1))
5341 (when extra
5342 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5343 (setq txt (concat (substring txt 0 (match-beginning 1))
5344 " - " extra " " (match-string 2 txt)))
5345 (setq txt (concat txt " - " extra))))
5346 (setq txt (org-agenda-format-item
5347 (cond
5348 (closedp "Closed: ")
5349 (statep (concat "State: (" state ")"))
5350 (t (concat "Clocked: (" clocked ")")))
5351 txt category tags timestr)))
5352 (setq priority 100000)
5353 (org-add-props txt props
5354 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5355 'priority priority 'org-category category
5356 'org-category-position category-pos
5357 'type "closed" 'date date
5358 'undone-face 'org-warning 'done-face 'org-agenda-done)
5359 (push txt ee))
5360 (goto-char (point-at-eol))))
5361 (nreverse ee)))
5363 (defun org-agenda-show-clocking-issues ()
5364 "Add overlays, showing issues with clocking.
5365 See also the user option `org-agenda-clock-consistency-checks'."
5366 (interactive)
5367 (let* ((pl org-agenda-clock-consistency-checks)
5368 (re (concat "^[ \t]*"
5369 org-clock-string
5370 "[ \t]+"
5371 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5372 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5373 (tlstart 0.)
5374 (tlend 0.)
5375 (maxtime (org-hh:mm-string-to-minutes
5376 (or (plist-get pl :max-duration) "24:00")))
5377 (mintime (org-hh:mm-string-to-minutes
5378 (or (plist-get pl :min-duration) 0)))
5379 (maxgap (org-hh:mm-string-to-minutes
5380 ;; default 30:00 means never complain
5381 (or (plist-get pl :max-gap) "30:00")))
5382 (gapok (mapcar 'org-hh:mm-string-to-minutes
5383 (plist-get pl :gap-ok-around)))
5384 (def-face (or (plist-get pl :default-face)
5385 '((:background "DarkRed") (:foreground "white"))))
5386 issue face m te ts dt ov)
5387 (goto-char (point-min))
5388 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5389 (setq issue nil face def-face)
5390 (catch 'next
5391 (setq m (org-get-at-bol 'org-marker)
5392 te nil ts nil)
5393 (unless (and m (markerp m))
5394 (setq issue "No valid clock line") (throw 'next t))
5395 (org-with-point-at m
5396 (save-excursion
5397 (goto-char (point-at-bol))
5398 (unless (looking-at re)
5399 (error "No valid Clock line")
5400 (throw 'next t))
5401 (unless (match-end 3)
5402 (setq issue "No end time"
5403 face (or (plist-get pl :no-end-time-face) face))
5404 (throw 'next t))
5405 (setq ts (match-string 1)
5406 te (match-string 3)
5407 ts (org-float-time
5408 (apply 'encode-time (org-parse-time-string ts)))
5409 te (org-float-time
5410 (apply 'encode-time (org-parse-time-string te)))
5411 dt (- te ts))))
5412 (cond
5413 ((> dt (* 60 maxtime))
5414 ;; a very long clocking chunk
5415 (setq issue (format "Clocking interval is very long: %s"
5416 (org-minutes-to-hh:mm-string
5417 (floor (/ (float dt) 60.))))
5418 face (or (plist-get pl :long-face) face)))
5419 ((< dt (* 60 mintime))
5420 ;; a very short clocking chunk
5421 (setq issue (format "Clocking interval is very short: %s"
5422 (org-minutes-to-hh:mm-string
5423 (floor (/ (float dt) 60.))))
5424 face (or (plist-get pl :short-face) face)))
5425 ((and (> tlend 0) (< ts tlend))
5426 ;; Two clock entries are overlapping
5427 (setq issue (format "Clocking overlap: %d minutes"
5428 (/ (- tlend ts) 60))
5429 face (or (plist-get pl :overlap-face) face)))
5430 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5431 ;; There is a gap, lets see if we need to report it
5432 (unless (org-agenda-check-clock-gap tlend ts gapok)
5433 (setq issue (format "Clocking gap: %d minutes"
5434 (/ (- ts tlend) 60))
5435 face (or (plist-get pl :gap-face) face))))
5436 (t nil)))
5437 (setq tlend (or te tlend) tlstart (or ts tlstart))
5438 (when issue
5439 ;; OK, there was some issue, add an overlay to show the issue
5440 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5441 (overlay-put ov 'before-string
5442 (concat
5443 (org-add-props
5444 (format "%-43s" (concat " " issue))
5446 'face face)
5447 "\n"))
5448 (overlay-put ov 'evaporate t)))))
5450 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5451 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5452 (catch 'exit
5453 (unless ok-list
5454 ;; there are no OK times for gaps...
5455 (throw 'exit nil))
5456 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5457 ;; This is more than 24 hours, so it is OK.
5458 ;; because we have at least one OK time, that must be in the
5459 ;; 24 hour interval.
5460 (throw 'exit t))
5461 ;; We have a shorter gap.
5462 ;; Now we have to get the minute of the day when these times are
5463 (let* ((t1dec (decode-time (seconds-to-time t1)))
5464 (t2dec (decode-time (seconds-to-time t2)))
5465 ;; compute the minute on the day
5466 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5467 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5468 (when (< min2 min1)
5469 ;; if min2 is smaller than min1, this means it is on the next day.
5470 ;; Wrap it to after midnight.
5471 (setq min2 (+ min2 1440)))
5472 ;; Now check if any of the OK times is in the gap
5473 (mapc (lambda (x)
5474 ;; Wrap the time to after midnight if necessary
5475 (if (< x min1) (setq x (+ x 1440)))
5476 ;; Check if in interval
5477 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5478 ok-list)
5479 ;; Nope, this gap is not OK
5480 nil)))
5482 (defun org-agenda-get-deadlines ()
5483 "Return the deadline information for agenda display."
5484 (let* ((props (list 'mouse-face 'highlight
5485 'org-not-done-regexp org-not-done-regexp
5486 'org-todo-regexp org-todo-regexp
5487 'org-complex-heading-regexp org-complex-heading-regexp
5488 'help-echo
5489 (format "mouse-2 or RET jump to org file %s"
5490 (abbreviate-file-name buffer-file-name))))
5491 (regexp org-deadline-time-regexp)
5492 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5493 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5494 d2 diff dfrac wdays pos pos1 category category-pos
5495 tags suppress-prewarning ee txt head face s todo-state
5496 show-all upcomingp donep timestr warntime)
5497 (goto-char (point-min))
5498 (while (re-search-forward regexp nil t)
5499 (setq suppress-prewarning nil)
5500 (catch :skip
5501 (org-agenda-skip)
5502 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5503 (save-match-data
5504 (string-match org-scheduled-time-regexp
5505 (buffer-substring (point-at-bol)
5506 (point-at-eol)))))
5507 (setq suppress-prewarning
5508 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5509 org-agenda-skip-deadline-prewarning-if-scheduled
5510 0)))
5511 (setq s (match-string 1)
5512 txt nil
5513 pos (1- (match-beginning 1))
5514 todo-state (save-match-data (org-get-todo-state))
5515 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5516 (member todo-state
5517 org-agenda-repeating-timestamp-show-all))
5518 d2 (org-time-string-to-absolute
5519 (match-string 1) d1 'past show-all
5520 (current-buffer) pos)
5521 diff (- d2 d1)
5522 wdays (if suppress-prewarning
5523 (let ((org-deadline-warning-days suppress-prewarning))
5524 (org-get-wdays s))
5525 (org-get-wdays s))
5526 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5527 upcomingp (and todayp (> diff 0)))
5528 ;; When to show a deadline in the calendar:
5529 ;; If the expiration is within wdays warning time.
5530 ;; Past-due deadlines are only shown on the current date
5531 (if (and (or (and (<= diff wdays)
5532 (and todayp (not org-agenda-only-exact-dates)))
5533 (= diff 0)))
5534 (save-excursion
5535 ;; (setq todo-state (org-get-todo-state))
5536 (setq donep (member todo-state org-done-keywords))
5537 (if (and donep
5538 (or org-agenda-skip-deadline-if-done
5539 (not (= diff 0))))
5540 (setq txt nil)
5541 (setq category (org-get-category)
5542 warntime (org-entry-get (point) "APPT_WARNTIME")
5543 category-pos (get-text-property (point) 'org-category-position))
5544 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5545 (setq txt org-agenda-no-heading-message)
5546 (goto-char (match-end 0))
5547 (setq pos1 (match-beginning 0))
5548 (setq tags (org-get-tags-at pos1))
5549 (setq head (buffer-substring-no-properties
5550 (point)
5551 (progn (skip-chars-forward "^\r\n")
5552 (point))))
5553 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5554 (setq timestr
5555 (concat (substring s (match-beginning 1)) " "))
5556 (setq timestr 'time))
5557 (setq txt (org-agenda-format-item
5558 (if (= diff 0)
5559 (car org-agenda-deadline-leaders)
5560 (if (functionp
5561 (nth 1 org-agenda-deadline-leaders))
5562 (funcall
5563 (nth 1 org-agenda-deadline-leaders)
5564 diff date)
5565 (format (nth 1 org-agenda-deadline-leaders)
5566 diff)))
5567 head category tags
5568 (if (not (= diff 0)) nil timestr)))))
5569 (when txt
5570 (setq face (org-agenda-deadline-face dfrac))
5571 (org-add-props txt props
5572 'org-marker (org-agenda-new-marker pos)
5573 'warntime warntime
5574 'org-hd-marker (org-agenda-new-marker pos1)
5575 'priority (+ (- diff)
5576 (org-get-priority txt))
5577 'org-category category
5578 'org-category-position category-pos
5579 'todo-state todo-state
5580 'type (if upcomingp "upcoming-deadline" "deadline")
5581 'date (if upcomingp date d2)
5582 'face (if donep 'org-agenda-done face)
5583 'undone-face face 'done-face 'org-agenda-done)
5584 (push txt ee))))))
5585 (nreverse ee)))
5587 (defun org-agenda-deadline-face (fraction)
5588 "Return the face to displaying a deadline item.
5589 FRACTION is what fraction of the head-warning time has passed."
5590 (let ((faces org-agenda-deadline-faces) f)
5591 (catch 'exit
5592 (while (setq f (pop faces))
5593 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5595 (defun org-agenda-get-scheduled (&optional deadline-results)
5596 "Return the scheduled information for agenda display."
5597 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5598 'org-todo-regexp org-todo-regexp
5599 'org-complex-heading-regexp org-complex-heading-regexp
5600 'done-face 'org-agenda-done
5601 'mouse-face 'highlight
5602 'help-echo
5603 (format "mouse-2 or RET jump to org file %s"
5604 (abbreviate-file-name buffer-file-name))))
5605 (regexp org-scheduled-time-regexp)
5606 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5607 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5609 (deadline-position-alist
5610 (mapcar (lambda (a) (and (setq mm (get-text-property
5611 0 'org-hd-marker a))
5612 (cons (marker-position mm) a)))
5613 deadline-results))
5614 d2 diff pos pos1 category category-pos tags donep
5615 ee txt head pastschedp todo-state face timestr s habitp show-all
5616 did-habit-check-p warntime)
5617 (goto-char (point-min))
5618 (while (re-search-forward regexp nil t)
5619 (catch :skip
5620 (org-agenda-skip)
5621 (setq s (match-string 1)
5622 txt nil
5623 pos (1- (match-beginning 1))
5624 todo-state (save-match-data (org-get-todo-state))
5625 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5626 (member todo-state
5627 org-agenda-repeating-timestamp-show-all))
5628 d2 (org-time-string-to-absolute
5629 (match-string 1) d1 'past show-all
5630 (current-buffer) pos)
5631 diff (- d2 d1)
5632 warntime (org-entry-get (point) "APPT_WARNTIME"))
5633 (setq pastschedp (and todayp (< diff 0)))
5634 (setq did-habit-check-p nil)
5635 ;; When to show a scheduled item in the calendar:
5636 ;; If it is on or past the date.
5637 (when (or (and (< diff 0)
5638 (< (abs diff) org-scheduled-past-days)
5639 (and todayp (not org-agenda-only-exact-dates)))
5640 (= diff 0)
5641 ;; org-is-habit-p uses org-entry-get, which is expansive
5642 ;; so we go extra mile to only call it once
5643 (and todayp
5644 org-habit-show-all-today
5645 (setq did-habit-check-p t)
5646 (setq habitp (and (functionp 'org-is-habit-p)
5647 (org-is-habit-p)))))
5648 (save-excursion
5649 (setq donep (member todo-state org-done-keywords))
5650 (if (and donep
5651 (or org-agenda-skip-scheduled-if-done
5652 (not (= diff 0))
5653 (and (functionp 'org-is-habit-p)
5654 (org-is-habit-p))))
5655 (setq txt nil)
5656 (setq habitp (if did-habit-check-p habitp
5657 (and (functionp 'org-is-habit-p)
5658 (org-is-habit-p))))
5659 (setq category (org-get-category)
5660 category-pos (get-text-property (point) 'org-category-position))
5661 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5662 (setq txt org-agenda-no-heading-message)
5663 (goto-char (match-end 0))
5664 (setq pos1 (match-beginning 0))
5665 (if habitp
5666 (if (or (not org-habit-show-habits)
5667 (and (not todayp)
5668 org-habit-show-habits-only-for-today))
5669 (throw :skip nil))
5670 (if (and
5671 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5672 (and org-agenda-skip-scheduled-if-deadline-is-shown
5673 pastschedp))
5674 (setq mm (assoc pos1 deadline-position-alist)))
5675 (throw :skip nil)))
5676 (setq tags (org-get-tags-at))
5677 (setq head (buffer-substring-no-properties
5678 (point)
5679 (progn (skip-chars-forward "^\r\n") (point))))
5680 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5681 (setq timestr
5682 (concat (substring s (match-beginning 1)) " "))
5683 (setq timestr 'time))
5684 (setq txt (org-agenda-format-item
5685 (if (= diff 0)
5686 (car org-agenda-scheduled-leaders)
5687 (format (nth 1 org-agenda-scheduled-leaders)
5688 (- 1 diff)))
5689 head category tags
5690 (if (not (= diff 0)) nil timestr)
5691 nil habitp))))
5692 (when txt
5693 (setq face
5694 (cond
5695 ((and (not habitp) pastschedp)
5696 'org-scheduled-previously)
5697 (todayp 'org-scheduled-today)
5698 (t 'org-scheduled))
5699 habitp (and habitp (org-habit-parse-todo)))
5700 (org-add-props txt props
5701 'undone-face face
5702 'face (if donep 'org-agenda-done face)
5703 'org-marker (org-agenda-new-marker pos)
5704 'org-hd-marker (org-agenda-new-marker pos1)
5705 'type (if pastschedp "past-scheduled" "scheduled")
5706 'date (if pastschedp d2 date)
5707 'warntime warntime
5708 'priority (if habitp
5709 (org-habit-get-priority habitp)
5710 (+ 94 (- 5 diff) (org-get-priority txt)))
5711 'org-category category
5712 'category-position category-pos
5713 'org-habit-p habitp
5714 'todo-state todo-state)
5715 (push txt ee))))))
5716 (nreverse ee)))
5718 (defun org-agenda-get-blocks ()
5719 "Return the date-range information for agenda display."
5720 (let* ((props (list 'face nil
5721 'org-not-done-regexp org-not-done-regexp
5722 'org-todo-regexp org-todo-regexp
5723 'org-complex-heading-regexp org-complex-heading-regexp
5724 'mouse-face 'highlight
5725 'help-echo
5726 (format "mouse-2 or RET jump to org file %s"
5727 (abbreviate-file-name buffer-file-name))))
5728 (regexp org-tr-regexp)
5729 (d0 (calendar-absolute-from-gregorian date))
5730 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5731 todo-state tags pos head donep)
5732 (goto-char (point-min))
5733 (while (re-search-forward regexp nil t)
5734 (catch :skip
5735 (org-agenda-skip)
5736 (setq pos (point))
5737 (let ((start-time (match-string 1))
5738 (end-time (match-string 2)))
5739 (setq s1 (match-string 1)
5740 s2 (match-string 2)
5741 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5742 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5743 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5744 ;; Only allow days between the limits, because the normal
5745 ;; date stamps will catch the limits.
5746 (save-excursion
5747 (setq todo-state (org-get-todo-state))
5748 (setq donep (member todo-state org-done-keywords))
5749 (if (and donep org-agenda-skip-timestamp-if-done)
5750 (throw :skip t))
5751 (setq marker (org-agenda-new-marker (point)))
5752 (setq category (org-get-category)
5753 category-pos (get-text-property (point) 'org-category-position))
5754 (if (not (re-search-backward org-outline-regexp-bol nil t))
5755 (setq txt org-agenda-no-heading-message)
5756 (goto-char (match-beginning 0))
5757 (setq hdmarker (org-agenda-new-marker (point)))
5758 (setq tags (org-get-tags-at))
5759 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5760 (setq head (match-string 1))
5761 (let ((remove-re
5762 (if org-agenda-remove-timeranges-from-blocks
5763 (concat
5764 "<" (regexp-quote s1) ".*?>"
5765 "--"
5766 "<" (regexp-quote s2) ".*?>")
5767 nil)))
5768 (setq txt (org-agenda-format-item
5769 (format
5770 (nth (if (= d1 d2) 0 1)
5771 org-agenda-timerange-leaders)
5772 (1+ (- d0 d1)) (1+ (- d2 d1)))
5773 head category tags
5774 (cond ((and (= d1 d0) (= d2 d0))
5775 (concat "<" start-time ">--<" end-time ">"))
5776 ((= d1 d0)
5777 (concat "<" start-time ">"))
5778 ((= d2 d0)
5779 (concat "<" end-time ">")))
5780 remove-re))))
5781 (org-add-props txt props
5782 'org-marker marker 'org-hd-marker hdmarker
5783 'type "block" 'date date
5784 'todo-state todo-state
5785 'priority (org-get-priority txt) 'org-category category
5786 'org-category-position category-pos)
5787 (push txt ee))))
5788 (goto-char pos)))
5789 ;; Sort the entries by expiration date.
5790 (nreverse ee)))
5792 ;;; Agenda presentation and sorting
5794 (defvar org-prefix-has-time nil
5795 "A flag, set by `org-compile-prefix-format'.
5796 The flag is set if the currently compiled format contains a `%t'.")
5797 (defvar org-prefix-has-tag nil
5798 "A flag, set by `org-compile-prefix-format'.
5799 The flag is set if the currently compiled format contains a `%T'.")
5800 (defvar org-prefix-has-effort nil
5801 "A flag, set by `org-compile-prefix-format'.
5802 The flag is set if the currently compiled format contains a `%e'.")
5803 (defvar org-prefix-category-length nil
5804 "Used by `org-compile-prefix-format' to remember the category field width.")
5805 (defvar org-prefix-category-max-length nil
5806 "Used by `org-compile-prefix-format' to remember the category field width.")
5808 (defun org-agenda-get-category-icon (category)
5809 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5810 (dolist (entry org-agenda-category-icon-alist)
5811 (when (org-string-match-p (car entry) category)
5812 (if (listp (cadr entry))
5813 (return (cadr entry))
5814 (return (apply 'create-image (cdr entry)))))))
5816 (defun org-agenda-format-item (extra txt &optional category tags dotime
5817 remove-re habitp)
5818 "Format TXT to be inserted into the agenda buffer.
5819 In particular, it adds the prefix and corresponding text properties. EXTRA
5820 must be a string and replaces the `%s' specifier in the prefix format.
5821 CATEGORY (string, symbol or nil) may be used to overrule the default
5822 category taken from local variable or file name. It will replace the `%c'
5823 specifier in the format. DOTIME, when non-nil, indicates that a
5824 time-of-day should be extracted from TXT for sorting of this entry, and for
5825 the `%t' specifier in the format. When DOTIME is a string, this string is
5826 searched for a time before TXT is. TAGS can be the tags of the headline.
5827 Any match of REMOVE-RE will be removed from TXT."
5828 ;; We keep the org-prefix-* variable values along with a compiled
5829 ;; formatter, so that multiple agendas existing at the same time, do
5830 ;; not step on each other toes.
5832 ;; It was inconvenient to make these variables buffer local in
5833 ;; Agenda buffers, because this function expects to be called with
5834 ;; the buffer where item comes from being current, and not agenda
5835 ;; buffer
5836 (let* ((bindings (car org-prefix-format-compiled))
5837 (formatter (cadr org-prefix-format-compiled)))
5838 (loop for (var value) in bindings
5839 do (set var value))
5840 (save-match-data
5841 ;; Diary entries sometimes have extra whitespace at the beginning
5842 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5844 ;; Fix the tags part in txt
5845 (setq txt (org-agenda-fix-displayed-tags
5846 txt tags
5847 org-agenda-show-inherited-tags
5848 org-agenda-hide-tags-regexp))
5849 (let* ((category (or category
5850 (if (stringp org-category)
5851 org-category
5852 (and org-category (symbol-name org-category)))
5853 (if buffer-file-name
5854 (file-name-sans-extension
5855 (file-name-nondirectory buffer-file-name))
5856 "")))
5857 (category-icon (org-agenda-get-category-icon category))
5858 (category-icon (if category-icon
5859 (propertize " " 'display category-icon)
5860 ""))
5861 ;; time, tag, effort are needed for the eval of the prefix format
5862 (tag (if tags (nth (1- (length tags)) tags) ""))
5863 time effort neffort
5864 (ts (if dotime (concat
5865 (if (stringp dotime) dotime "")
5866 (and org-agenda-search-headline-for-time txt))))
5867 (time-of-day (and dotime (org-get-time-of-day ts)))
5868 stamp plain s0 s1 s2 rtn srp l
5869 duration thecategory)
5870 (and (derived-mode-p 'org-mode) buffer-file-name
5871 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5872 (when (and dotime time-of-day)
5873 ;; Extract starting and ending time and move them to prefix
5874 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5875 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5876 (setq s0 (match-string 0 ts)
5877 srp (and stamp (match-end 3))
5878 s1 (match-string (if plain 1 2) ts)
5879 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5881 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5882 ;; them, we might want to remove them there to avoid duplication.
5883 ;; The user can turn this off with a variable.
5884 (if (and org-prefix-has-time
5885 org-agenda-remove-times-when-in-prefix (or stamp plain)
5886 (string-match (concat (regexp-quote s0) " *") txt)
5887 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5888 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5889 (= (match-beginning 0) 0)
5891 (setq txt (replace-match "" nil nil txt))))
5892 ;; Normalize the time(s) to 24 hour
5893 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5894 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5896 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5897 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5898 (setq s2
5899 (org-minutes-to-hh:mm-string
5900 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5902 ;; Compute the duration
5903 (when s2
5904 (setq duration (- (org-hh:mm-string-to-minutes s2)
5905 (org-hh:mm-string-to-minutes s1)))))
5907 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5908 txt)
5909 ;; Tags are in the string
5910 (if (or (eq org-agenda-remove-tags t)
5911 (and org-agenda-remove-tags
5912 org-prefix-has-tag))
5913 (setq txt (replace-match "" t t txt))
5914 (setq txt (replace-match
5915 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5916 (match-string 2 txt))
5917 t t txt))))
5918 (when (derived-mode-p 'org-mode)
5919 (setq effort
5920 (condition-case nil
5921 (org-get-effort
5922 (or (get-text-property 0 'org-hd-marker txt)
5923 (get-text-property 0 'org-marker txt)))
5924 (error nil)))
5925 (when effort
5926 (setq neffort (org-duration-string-to-minutes effort)
5927 effort (setq effort (concat "[" effort "]")))))
5928 ;; prevent erroring out with %e format when there is no effort
5929 (or effort (setq effort ""))
5931 (when remove-re
5932 (while (string-match remove-re txt)
5933 (setq txt (replace-match "" t t txt))))
5935 ;; Set org-heading property on `txt' to mark the start of the
5936 ;; heading.
5937 (add-text-properties 0 (length txt) '(org-heading t) txt)
5939 ;; Prepare the variables needed in the eval of the compiled format
5940 (setq time (cond (s2 (concat
5941 (org-agenda-time-of-day-to-ampm-maybe s1)
5942 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5943 (if org-agenda-timegrid-use-ampm " ")))
5944 (s1 (concat
5945 (org-agenda-time-of-day-to-ampm-maybe s1)
5946 (if org-agenda-timegrid-use-ampm
5947 "........ "
5948 "......")))
5949 (t ""))
5950 extra (or (and (not habitp) extra) "")
5951 category (if (symbolp category) (symbol-name category) category)
5952 thecategory (copy-sequence category))
5953 (if (string-match org-bracket-link-regexp category)
5954 (progn
5955 (setq l (if (match-end 3)
5956 (- (match-end 3) (match-beginning 3))
5957 (- (match-end 1) (match-beginning 1))))
5958 (when (< l (or org-prefix-category-length 0))
5959 (setq category (copy-sequence category))
5960 (org-add-props category nil
5961 'extra-space (make-string
5962 (- org-prefix-category-length l 1) ?\ ))))
5963 (if (and org-prefix-category-max-length
5964 (>= (length category) org-prefix-category-max-length))
5965 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5966 ;; Evaluate the compiled format
5967 (setq rtn (concat (eval formatter) txt))
5969 ;; And finally add the text properties
5970 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5971 (org-add-props rtn nil
5972 'org-category (if thecategory (downcase thecategory) category)
5973 'tags (mapcar 'org-downcase-keep-props tags)
5974 'org-highest-priority org-highest-priority
5975 'org-lowest-priority org-lowest-priority
5976 'time-of-day time-of-day
5977 'duration duration
5978 'effort effort
5979 'effort-minutes neffort
5980 'txt txt
5981 'time time
5982 'extra extra
5983 'format org-prefix-format-compiled
5984 'dotime dotime)))))
5986 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5987 "Remove tags string from TXT, and add a modified list of tags.
5988 The modified list may contain inherited tags, and tags matched by
5989 `org-agenda-hide-tags-regexp' will be removed."
5990 (when (or add-inherited hide-re)
5991 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5992 (setq txt (substring txt 0 (match-beginning 0))))
5993 (setq tags
5994 (delq nil
5995 (mapcar (lambda (tg)
5996 (if (or (and hide-re (string-match hide-re tg))
5997 (and (not add-inherited)
5998 (get-text-property 0 'inherited tg)))
6000 tg))
6001 tags)))
6002 (when tags
6003 (let ((have-i (get-text-property 0 'inherited (car tags)))
6005 (setq txt (concat txt " :"
6006 (mapconcat
6007 (lambda (x)
6008 (setq i (get-text-property 0 'inherited x))
6009 (if (and have-i (not i))
6010 (progn
6011 (setq have-i nil)
6012 (concat ":" x))
6014 tags ":")
6015 (if have-i "::" ":"))))))
6016 txt)
6018 (defun org-downcase-keep-props (s)
6019 (let ((props (text-properties-at 0 s)))
6020 (setq s (downcase s))
6021 (add-text-properties 0 (length s) props s)
6024 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6025 (defvar org-agenda-sorting-strategy-selected nil)
6027 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6028 (catch 'exit
6029 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6030 ((and todayp (member 'today (car org-agenda-time-grid))))
6031 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6032 ((member 'weekly (car org-agenda-time-grid)))
6033 (t (throw 'exit list)))
6034 (let* ((have (delq nil (mapcar
6035 (lambda (x) (get-text-property 1 'time-of-day x))
6036 list)))
6037 (string (nth 1 org-agenda-time-grid))
6038 (gridtimes (nth 2 org-agenda-time-grid))
6039 (req (car org-agenda-time-grid))
6040 (remove (member 'remove-match req))
6041 new time)
6042 (if (and (member 'require-timed req) (not have))
6043 ;; don't show empty grid
6044 (throw 'exit list))
6045 (while (setq time (pop gridtimes))
6046 (unless (and remove (member time have))
6047 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6048 (push (org-agenda-format-item
6049 nil string "" nil
6050 (concat (substring time 0 -2) ":" (substring time -2)))
6051 new)
6052 (put-text-property
6053 2 (length (car new)) 'face 'org-time-grid (car new))))
6054 (when (and todayp org-agenda-show-current-time-in-grid)
6055 (push (org-agenda-format-item
6057 org-agenda-current-time-string
6058 "" nil
6059 (format-time-string "%H:%M "))
6060 new)
6061 (put-text-property
6062 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6064 (if (member 'time-up org-agenda-sorting-strategy-selected)
6065 (append new list)
6066 (append list new)))))
6068 (defun org-compile-prefix-format (key)
6069 "Compile the prefix format into a Lisp form that can be evaluated.
6070 The resulting form and associated variable bindings is returned
6071 and stored in the variable `org-prefix-format-compiled'."
6072 (setq org-prefix-has-time nil org-prefix-has-tag nil
6073 org-prefix-category-length nil
6074 org-prefix-has-effort nil)
6075 (let ((s (cond
6076 ((stringp org-agenda-prefix-format)
6077 org-agenda-prefix-format)
6078 ((assq key org-agenda-prefix-format)
6079 (cdr (assq key org-agenda-prefix-format)))
6080 (t " %-12:c%?-12t% s")))
6081 (start 0)
6082 varform vars var e c f opt)
6083 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6084 s start)
6085 (setq var (or (cdr (assoc (match-string 4 s)
6086 '(("c" . category) ("t" . time) ("s" . extra)
6087 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6088 'eval)
6089 c (or (match-string 3 s) "")
6090 opt (match-beginning 1)
6091 start (1+ (match-beginning 0)))
6092 (if (equal var 'time) (setq org-prefix-has-time t))
6093 (if (equal var 'tag) (setq org-prefix-has-tag t))
6094 (if (equal var 'effort) (setq org-prefix-has-effort t))
6095 (setq f (concat "%" (match-string 2 s) "s"))
6096 (when (equal var 'category)
6097 (setq org-prefix-category-length
6098 (floor (abs (string-to-number (match-string 2 s)))))
6099 (setq org-prefix-category-max-length
6100 (let ((x (match-string 2 s)))
6101 (save-match-data
6102 (if (string-match "\\.[0-9]+" x)
6103 (string-to-number (substring (match-string 0 x) 1)))))))
6104 (if (eq var 'eval)
6105 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6106 (if opt
6107 (setq varform
6108 `(if (equal "" ,var)
6110 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6111 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6112 (setq s (replace-match "%s" t nil s))
6113 (push varform vars))
6114 (setq vars (nreverse vars))
6115 (with-current-buffer org-agenda-buffer
6116 (setq org-prefix-format-compiled
6117 (list
6118 `((org-prefix-has-time ,org-prefix-has-time)
6119 (org-prefix-has-tag ,org-prefix-has-tag)
6120 (org-prefix-category-length ,org-prefix-category-length)
6121 (org-prefix-has-effort ,org-prefix-has-effort))
6122 `(format ,s ,@vars))))))
6124 (defun org-set-sorting-strategy (key)
6125 (if (symbolp (car org-agenda-sorting-strategy))
6126 ;; the old format
6127 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6128 (setq org-agenda-sorting-strategy-selected
6129 (or (cdr (assq key org-agenda-sorting-strategy))
6130 (cdr (assq 'agenda org-agenda-sorting-strategy))
6131 '(time-up category-keep priority-down)))))
6133 (defun org-get-time-of-day (s &optional string mod24)
6134 "Check string S for a time of day.
6135 If found, return it as a military time number between 0 and 2400.
6136 If not found, return nil.
6137 The optional STRING argument forces conversion into a 5 character wide string
6138 HH:MM."
6139 (save-match-data
6140 (when
6141 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6142 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6143 (let* ((h (string-to-number (match-string 1 s)))
6144 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6145 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6146 (am-p (equal ampm "am"))
6147 (h1 (cond ((not ampm) h)
6148 ((= h 12) (if am-p 0 12))
6149 (t (+ h (if am-p 0 12)))))
6150 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6151 (mod h1 24) h1))
6152 (t0 (+ (* 100 h2) m))
6153 (t1 (concat (if (>= h1 24) "+" " ")
6154 (if (and org-agenda-time-leading-zero
6155 (< t0 1000)) "0" "")
6156 (if (< t0 100) "0" "")
6157 (if (< t0 10) "0" "")
6158 (int-to-string t0))))
6159 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6161 (defvar org-agenda-before-sorting-filter-function nil
6162 "Function to be applied to agenda items prior to sorting.
6163 Prior to sorting also means just before they are inserted into the agenda.
6165 To aid sorting, you may revisit the original entries and add more text
6166 properties which will later be used by the sorting functions.
6168 The function should take a string argument, an agenda line.
6169 It has access to the text properties in that line, which contain among
6170 other things, the property `org-hd-marker' that points to the entry
6171 where the line comes from. Note that not all lines going into the agenda
6172 have this property, only most.
6174 The function should return the modified string. It is probably best
6175 to ONLY change text properties.
6177 You can also use this function as a filter, by returning nil for lines
6178 you don't want to have in the agenda at all. For this application, you
6179 could bind the variable in the options section of a custom command.")
6181 (defun org-finalize-agenda-entries (list &optional nosort)
6182 "Sort and concatenate the agenda items."
6183 (setq list (mapcar 'org-agenda-highlight-todo list))
6184 (if nosort
6185 list
6186 (when org-agenda-before-sorting-filter-function
6187 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6188 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6190 (defun org-agenda-highlight-todo (x)
6191 (let ((org-done-keywords org-done-keywords-for-agenda)
6192 (case-fold-search nil)
6194 (if (eq x 'line)
6195 (save-excursion
6196 (beginning-of-line 1)
6197 (setq re (org-get-at-bol 'org-todo-regexp))
6198 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6199 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6200 (add-text-properties (match-beginning 0) (match-end 1)
6201 (list 'face (org-get-todo-face 1)))
6202 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6203 (delete-region (match-beginning 1) (1- (match-end 0)))
6204 (goto-char (match-beginning 1))
6205 (insert (format org-agenda-todo-keyword-format s)))))
6206 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6207 (setq re (get-text-property 0 'org-todo-regexp x))
6208 (when (and re
6209 ;; Test `pl' because if there's no heading content,
6210 ;; there's no point matching to highlight. Note
6211 ;; that if we didn't test `pl' first, and there
6212 ;; happened to be no keyword from `org-todo-regexp'
6213 ;; on this heading line, then the `equal' comparison
6214 ;; afterwards would spuriously succeed in the case
6215 ;; where `pl' is nil -- causing an args-out-of-range
6216 ;; error when we try to add text properties to text
6217 ;; that isn't there.
6219 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6220 x pl) pl))
6221 (add-text-properties
6222 (or (match-end 1) (match-end 0)) (match-end 0)
6223 (list 'face (org-get-todo-face (match-string 2 x)))
6225 (when (match-end 1)
6226 (setq x (concat (substring x 0 (match-end 1))
6227 (format org-agenda-todo-keyword-format
6228 (match-string 2 x))
6229 (org-add-props " " (text-properties-at 0 x))
6230 (substring x (match-end 3)))))))
6231 x)))
6233 (defsubst org-cmp-priority (a b)
6234 "Compare the priorities of string A and B."
6235 (let ((pa (or (get-text-property 1 'priority a) 0))
6236 (pb (or (get-text-property 1 'priority b) 0)))
6237 (cond ((> pa pb) +1)
6238 ((< pa pb) -1))))
6240 (defsubst org-cmp-effort (a b)
6241 "Compare the effort values of string A and B."
6242 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6243 (ea (or (get-text-property 1 'effort-minutes a) def))
6244 (eb (or (get-text-property 1 'effort-minutes b) def)))
6245 (cond ((> ea eb) +1)
6246 ((< ea eb) -1))))
6248 (defsubst org-cmp-category (a b)
6249 "Compare the string values of categories of strings A and B."
6250 (let ((ca (or (get-text-property 1 'org-category a) ""))
6251 (cb (or (get-text-property 1 'org-category b) "")))
6252 (cond ((string-lessp ca cb) -1)
6253 ((string-lessp cb ca) +1))))
6255 (defsubst org-cmp-todo-state (a b)
6256 "Compare the todo states of strings A and B."
6257 (let* ((ma (or (get-text-property 1 'org-marker a)
6258 (get-text-property 1 'org-hd-marker a)))
6259 (mb (or (get-text-property 1 'org-marker b)
6260 (get-text-property 1 'org-hd-marker b)))
6261 (fa (and ma (marker-buffer ma)))
6262 (fb (and mb (marker-buffer mb)))
6263 (todo-kwds
6264 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6265 (and fb (with-current-buffer fb org-todo-keywords-1))))
6266 (ta (or (get-text-property 1 'todo-state a) ""))
6267 (tb (or (get-text-property 1 'todo-state b) ""))
6268 (la (- (length (member ta todo-kwds))))
6269 (lb (- (length (member tb todo-kwds))))
6270 (donepa (member ta org-done-keywords-for-agenda))
6271 (donepb (member tb org-done-keywords-for-agenda)))
6272 (cond ((and donepa (not donepb)) -1)
6273 ((and (not donepa) donepb) +1)
6274 ((< la lb) -1)
6275 ((< lb la) +1))))
6277 (defsubst org-cmp-alpha (a b)
6278 "Compare the headlines, alphabetically."
6279 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6280 (plb (text-property-any 0 (length b) 'org-heading t b))
6281 (ta (and pla (substring a pla)))
6282 (tb (and plb (substring b plb))))
6283 (when pla
6284 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6285 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6286 (setq ta (substring ta (match-end 0))))
6287 (setq ta (downcase ta)))
6288 (when plb
6289 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6290 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6291 (setq tb (substring tb (match-end 0))))
6292 (setq tb (downcase tb)))
6293 (cond ((not ta) +1)
6294 ((not tb) -1)
6295 ((string-lessp ta tb) -1)
6296 ((string-lessp tb ta) +1))))
6298 (defsubst org-cmp-tag (a b)
6299 "Compare the string values of the first tags of A and B."
6300 (let ((ta (car (last (get-text-property 1 'tags a))))
6301 (tb (car (last (get-text-property 1 'tags b)))))
6302 (cond ((not ta) +1)
6303 ((not tb) -1)
6304 ((string-lessp ta tb) -1)
6305 ((string-lessp tb ta) +1))))
6307 (defsubst org-cmp-time (a b)
6308 "Compare the time-of-day values of strings A and B."
6309 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6310 (ta (or (get-text-property 1 'time-of-day a) def))
6311 (tb (or (get-text-property 1 'time-of-day b) def)))
6312 (cond ((< ta tb) -1)
6313 ((< tb ta) +1))))
6315 (defsubst org-cmp-habit-p (a b)
6316 "Compare the todo states of strings A and B."
6317 (let ((ha (get-text-property 1 'org-habit-p a))
6318 (hb (get-text-property 1 'org-habit-p b)))
6319 (cond ((and ha (not hb)) -1)
6320 ((and (not ha) hb) +1))))
6322 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6324 (defun org-entries-lessp (a b)
6325 "Predicate for sorting agenda entries."
6326 ;; The following variables will be used when the form is evaluated.
6327 ;; So even though the compiler complains, keep them.
6328 (let* ((ss org-agenda-sorting-strategy-selected)
6329 (time-up (and (org-em 'time-up 'time-down ss)
6330 (org-cmp-time a b)))
6331 (time-down (if time-up (- time-up) nil))
6332 (priority-up (and (org-em 'priority-up 'priority-down ss)
6333 (org-cmp-priority a b)))
6334 (priority-down (if priority-up (- priority-up) nil))
6335 (effort-up (and (org-em 'effort-up 'effort-down ss)
6336 (org-cmp-effort a b)))
6337 (effort-down (if effort-up (- effort-up) nil))
6338 (category-up (and (or (org-em 'category-up 'category-down ss)
6339 (memq 'category-keep ss))
6340 (org-cmp-category a b)))
6341 (category-down (if category-up (- category-up) nil))
6342 (category-keep (if category-up +1 nil))
6343 (tag-up (and (org-em 'tag-up 'tag-down ss)
6344 (org-cmp-tag a b)))
6345 (tag-down (if tag-up (- tag-up) nil))
6346 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6347 (org-cmp-todo-state a b)))
6348 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6349 (habit-up (and (org-em 'habit-up 'habit-down ss)
6350 (org-cmp-habit-p a b)))
6351 (habit-down (if habit-up (- habit-up) nil))
6352 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6353 (org-cmp-alpha a b)))
6354 (alpha-down (if alpha-up (- alpha-up) nil))
6355 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6356 user-defined-up user-defined-down)
6357 (if (and need-user-cmp org-agenda-cmp-user-defined
6358 (functionp org-agenda-cmp-user-defined))
6359 (setq user-defined-up
6360 (funcall org-agenda-cmp-user-defined a b)
6361 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6362 (cdr (assoc
6363 (eval (cons 'or org-agenda-sorting-strategy-selected))
6364 '((-1 . t) (1 . nil) (nil . nil))))))
6366 ;;; Agenda restriction lock
6368 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6369 "Overlay to mark the headline to which agenda commands are restricted.")
6370 (overlay-put org-agenda-restriction-lock-overlay
6371 'face 'org-agenda-restriction-lock)
6372 (overlay-put org-agenda-restriction-lock-overlay
6373 'help-echo "Agendas are currently limited to this subtree.")
6374 (org-detach-overlay org-agenda-restriction-lock-overlay)
6376 (defun org-agenda-set-restriction-lock (&optional type)
6377 "Set restriction lock for agenda, to current subtree or file.
6378 Restriction will be the file if TYPE is `file', or if type is the
6379 universal prefix '(4), or if the cursor is before the first headline
6380 in the file. Otherwise, restriction will be to the current subtree."
6381 (interactive "P")
6382 (and (equal type '(4)) (setq type 'file))
6383 (setq type (cond
6384 (type type)
6385 ((org-at-heading-p) 'subtree)
6386 ((condition-case nil (org-back-to-heading t) (error nil))
6387 'subtree)
6388 (t 'file)))
6389 (if (eq type 'subtree)
6390 (progn
6391 (setq org-agenda-restrict t)
6392 (setq org-agenda-overriding-restriction 'subtree)
6393 (put 'org-agenda-files 'org-restrict
6394 (list (buffer-file-name (buffer-base-buffer))))
6395 (org-back-to-heading t)
6396 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6397 (move-marker org-agenda-restrict-begin (point))
6398 (move-marker org-agenda-restrict-end
6399 (save-excursion (org-end-of-subtree t)))
6400 (message "Locking agenda restriction to subtree"))
6401 (put 'org-agenda-files 'org-restrict
6402 (list (buffer-file-name (buffer-base-buffer))))
6403 (setq org-agenda-restrict nil)
6404 (setq org-agenda-overriding-restriction 'file)
6405 (move-marker org-agenda-restrict-begin nil)
6406 (move-marker org-agenda-restrict-end nil)
6407 (message "Locking agenda restriction to file"))
6408 (setq current-prefix-arg nil)
6409 (org-agenda-maybe-redo))
6411 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6412 "Remove the agenda restriction lock."
6413 (interactive "P")
6414 (org-detach-overlay org-agenda-restriction-lock-overlay)
6415 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6416 (setq org-agenda-overriding-restriction nil)
6417 (setq org-agenda-restrict nil)
6418 (put 'org-agenda-files 'org-restrict nil)
6419 (move-marker org-agenda-restrict-begin nil)
6420 (move-marker org-agenda-restrict-end nil)
6421 (setq current-prefix-arg nil)
6422 (message "Agenda restriction lock removed")
6423 (or noupdate (org-agenda-maybe-redo)))
6425 (defun org-agenda-maybe-redo ()
6426 "If there is any window showing the agenda view, update it."
6427 (let ((w (get-buffer-window org-agenda-buffer-name t))
6428 (w0 (selected-window)))
6429 (when w
6430 (select-window w)
6431 (org-agenda-redo)
6432 (select-window w0)
6433 (if org-agenda-overriding-restriction
6434 (message "Agenda view shifted to new %s restriction"
6435 org-agenda-overriding-restriction)
6436 (message "Agenda restriction lock removed")))))
6438 ;;; Agenda commands
6440 (defun org-agenda-check-type (error &rest types)
6441 "Check if agenda buffer is of allowed type.
6442 If ERROR is non-nil, throw an error, otherwise just return nil."
6443 (if (not org-agenda-type)
6444 (error "No Org agenda currently displayed")
6445 (if (memq org-agenda-type types)
6447 (if error
6448 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6449 nil))))
6451 (defun org-agenda-Quit (&optional arg)
6452 "Exit agenda by removing the window or the buffer."
6453 (interactive)
6454 (if org-agenda-columns-active
6455 (org-columns-quit)
6456 (let ((buf (current-buffer)))
6457 (if (eq org-agenda-window-setup 'other-frame)
6458 (progn
6459 (org-agenda-reset-markers)
6460 (kill-buffer buf)
6461 (org-columns-remove-overlays)
6462 (setq org-agenda-archives-mode nil)
6463 (delete-frame))
6464 (and (not (eq org-agenda-window-setup 'current-window))
6465 (not (one-window-p))
6466 (delete-window))
6467 (org-agenda-reset-markers)
6468 (kill-buffer buf)
6469 (org-columns-remove-overlays)
6470 (setq org-agenda-archives-mode nil)))
6471 ;; Maybe restore the pre-agenda window configuration.
6472 (and org-agenda-restore-windows-after-quit
6473 (not (eq org-agenda-window-setup 'other-frame))
6474 org-pre-agenda-window-conf
6475 (set-window-configuration org-pre-agenda-window-conf)
6476 (setq org-pre-agenda-window-conf nil))))
6478 (defun org-agenda-quit ()
6479 "Exit agenda by killing agenda buffer or burying it when
6480 `org-agenda-sticky' is non-NIL"
6481 (interactive)
6482 (if org-agenda-columns-active
6483 (org-columns-quit)
6484 (if org-agenda-sticky
6485 (let ((buf (current-buffer)))
6486 (if (eq org-agenda-window-setup 'other-frame)
6487 (progn
6488 (delete-frame))
6489 (and (not (eq org-agenda-window-setup 'current-window))
6490 (not (one-window-p))
6491 (delete-window)))
6492 (with-current-buffer buf
6493 (bury-buffer)
6494 ;; Maybe restore the pre-agenda window configuration.
6495 (and org-agenda-restore-windows-after-quit
6496 (not (eq org-agenda-window-setup 'other-frame))
6497 org-pre-agenda-window-conf
6498 (set-window-configuration org-pre-agenda-window-conf)
6499 (setq org-pre-agenda-window-conf nil))))
6500 (org-agenda-Quit))))
6502 (defun org-agenda-exit ()
6503 "Exit agenda by removing the window or the buffer.
6504 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6505 Org-mode buffers visited directly by the user will not be touched."
6506 (interactive)
6507 (org-release-buffers org-agenda-new-buffers)
6508 (setq org-agenda-new-buffers nil)
6509 (org-agenda-Quit))
6511 (defun org-agenda-kill-all-agenda-buffers ()
6512 "Kill all buffers in `org-agena-mode'.
6513 This is used when toggling sticky agendas. You can also explicitly invoke it
6514 with `C-c a C-k'."
6515 (interactive)
6516 (let (blist)
6517 (dolist (buf (buffer-list))
6518 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6519 (push buf blist)))
6520 (mapc 'kill-buffer blist)))
6522 (defun org-agenda-execute (arg)
6523 "Execute another agenda command, keeping same window.
6524 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6525 in the agenda."
6526 (interactive "P")
6527 (let ((org-agenda-window-setup 'current-window))
6528 (org-agenda arg)))
6530 (defun org-agenda-redo ()
6531 "Rebuild Agenda.
6532 When this is the global TODO list, a prefix argument will be interpreted."
6533 (interactive)
6534 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6535 (org-agenda-sticky nil)
6536 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6537 org-agenda-buffer-name))
6538 (org-agenda-keep-modes t)
6539 (tag-filter org-agenda-tag-filter)
6540 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6541 (top-cat-filter org-agenda-top-category-filter)
6542 (cat-filter org-agenda-category-filter)
6543 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6544 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6545 (cols org-agenda-columns-active)
6546 (line (org-current-line))
6547 (window-line (- line (org-current-line (window-start))))
6548 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6549 (put 'org-agenda-tag-filter :preset-filter nil)
6550 (put 'org-agenda-category-filter :preset-filter nil)
6551 (and cols (org-columns-quit))
6552 (message "Rebuilding agenda buffer...")
6553 (org-let lprops '(eval org-agenda-redo-command))
6554 (setq org-agenda-undo-list nil
6555 org-agenda-pending-undo-list nil)
6556 (message "Rebuilding agenda buffer...done")
6557 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6558 (put 'org-agenda-category-filter :preset-filter cat-preset)
6559 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6560 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6561 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6562 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6563 (org-goto-line line)
6564 (recenter window-line)))
6566 (defvar org-global-tags-completion-table nil)
6567 (defvar org-agenda-filter-form nil)
6568 (defvar org-agenda-filtered-by-category nil)
6570 (defun org-agenda-filter-by-category (strip)
6571 "Keep only those lines in the agenda buffer that have a specific category.
6572 The category is that of the current line."
6573 (interactive "P")
6574 (if (and org-agenda-filtered-by-category
6575 org-agenda-category-filter)
6576 (org-agenda-filter-show-all-cat)
6577 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6578 (if cat (org-agenda-filter-apply
6579 (list (concat (if strip "-" "+") cat)) 'category)
6580 (error "No category at point")))))
6582 (defun org-find-top-category (&optional pos)
6583 (save-excursion
6584 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6585 (if pos (goto-char pos))
6586 ;; Skip up to the topmost parent
6587 (while (ignore-errors (outline-up-heading 1) t))
6588 (ignore-errors
6589 (nth 4 (org-heading-components))))))
6591 (defvar org-agenda-filtered-by-top-category nil)
6593 (defun org-agenda-filter-by-top-category (strip)
6594 "Keep only those lines in the agenda buffer that have a specific category.
6595 The category is that of the current line."
6596 (interactive "P")
6597 (if org-agenda-filtered-by-top-category
6598 (progn
6599 (setq org-agenda-filtered-by-top-category nil
6600 org-agenda-top-category-filter nil)
6601 (org-agenda-filter-show-all-cat))
6602 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6603 (if cat (org-agenda-filter-top-category-apply cat strip)
6604 (error "No top-level category at point")))))
6606 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6607 "Keep only those lines in the agenda buffer that have a specific tag.
6608 The tag is selected with its fast selection letter, as configured.
6609 With prefix argument STRIP, remove all lines that do have the tag.
6610 A lisp caller can specify CHAR. NARROW means that the new tag should be
6611 used to narrow the search - the interactive user can also press `-' or `+'
6612 to switch to narrowing."
6613 (interactive "P")
6614 (let* ((alist org-tag-alist-for-agenda)
6615 (tag-chars (mapconcat
6616 (lambda (x) (if (and (not (symbolp (car x)))
6617 (cdr x))
6618 (char-to-string (cdr x))
6619 ""))
6620 alist ""))
6621 (efforts (org-split-string
6622 (or (cdr (assoc (concat org-effort-property "_ALL")
6623 org-global-properties))
6624 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6625 "")))
6626 (effort-op org-agenda-filter-effort-default-operator)
6627 (effort-prompt "")
6628 (inhibit-read-only t)
6629 (current org-agenda-tag-filter)
6630 maybe-refresh a n tag)
6631 (unless char
6632 (message
6633 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6634 (if narrow "Narrow" "Filter") tag-chars
6635 (if org-agenda-auto-exclude-function "[RET], " ""))
6636 (setq char (read-char-exclusive)))
6637 (when (member char '(?+ ?-))
6638 ;; Narrowing down
6639 (cond ((equal char ?-) (setq strip t narrow t))
6640 ((equal char ?+) (setq strip nil narrow t)))
6641 (message
6642 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6643 (setq char (read-char-exclusive)))
6644 (when (member char '(?< ?> ?= ??))
6645 ;; An effort operator
6646 (setq effort-op (char-to-string char))
6647 (setq alist nil) ; to make sure it will be interpreted as effort.
6648 (unless (equal char ??)
6649 (loop for i from 0 to 9 do
6650 (setq effort-prompt
6651 (concat
6652 effort-prompt " ["
6653 (if (= i 9) "0" (int-to-string (1+ i)))
6654 "]" (nth i efforts))))
6655 (message "Effort%s: %s " effort-op effort-prompt)
6656 (setq char (read-char-exclusive))
6657 (when (or (< char ?0) (> char ?9))
6658 (error "Need 1-9,0 to select effort"))))
6659 (when (equal char ?\t)
6660 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6661 (org-set-local 'org-global-tags-completion-table
6662 (org-global-tags-completion-table)))
6663 (let ((completion-ignore-case t))
6664 (setq tag (org-icompleting-read
6665 "Tag: " org-global-tags-completion-table))))
6666 (cond
6667 ((equal char ?\r)
6668 (org-agenda-filter-show-all-tag)
6669 (when org-agenda-auto-exclude-function
6670 (setq org-agenda-tag-filter '())
6671 (dolist (tag (org-agenda-get-represented-tags))
6672 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6673 (if modifier
6674 (push modifier org-agenda-tag-filter))))
6675 (if (not (null org-agenda-tag-filter))
6676 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6677 (setq maybe-refresh t))
6678 ((equal char ?/)
6679 (org-agenda-filter-show-all-tag)
6680 (when (get 'org-agenda-tag-filter :preset-filter)
6681 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6682 (setq maybe-refresh t))
6683 ((equal char ?. )
6684 (setq org-agenda-tag-filter
6685 (mapcar (lambda(tag) (concat "+" tag))
6686 (org-get-at-bol 'tags)))
6687 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6688 (setq maybe-refresh t))
6689 ((or (equal char ?\ )
6690 (setq a (rassoc char alist))
6691 (and (>= char ?0) (<= char ?9)
6692 (setq n (if (= char ?0) 9 (- char ?0 1))
6693 tag (concat effort-op (nth n efforts))
6694 a (cons tag nil)))
6695 (and (= char ??)
6696 (setq tag "?eff")
6697 a (cons tag nil))
6698 (and tag (setq a (cons tag nil))))
6699 (org-agenda-filter-show-all-tag)
6700 (setq tag (car a))
6701 (setq org-agenda-tag-filter
6702 (cons (concat (if strip "-" "+") tag)
6703 (if narrow current nil)))
6704 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6705 (setq maybe-refresh t))
6706 (t (error "Invalid tag selection character %c" char)))
6707 (when (and maybe-refresh
6708 (eq org-agenda-clockreport-mode 'with-filter))
6709 (org-agenda-redo))))
6711 (defun org-agenda-get-represented-tags ()
6712 "Get a list of all tags currently represented in the agenda."
6713 (let (p tags)
6714 (save-excursion
6715 (goto-char (point-min))
6716 (while (setq p (next-single-property-change (point) 'tags))
6717 (goto-char p)
6718 (mapc (lambda (x) (add-to-list 'tags x))
6719 (get-text-property (point) 'tags))))
6720 tags))
6722 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6723 "Refine the current filter. See `org-agenda-filter-by-tag'."
6724 (interactive "P")
6725 (org-agenda-filter-by-tag strip char 'refine))
6727 (defun org-agenda-filter-make-matcher ()
6728 "Create the form that tests a line for agenda filter."
6729 (let (f f1)
6730 ;; first compute the tag-filter matcher
6731 (dolist (x (delete-dups
6732 (append (get 'org-agenda-tag-filter
6733 :preset-filter) org-agenda-tag-filter)))
6734 (if (member x '("-" "+"))
6735 (setq f1 (if (equal x "-") 'tags '(not tags)))
6736 (if (string-match "[<=>?]" x)
6737 (setq f1 (org-agenda-filter-effort-form x))
6738 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6739 (if (equal (string-to-char x) ?-)
6740 (setq f1 (list 'not f1))))
6741 (push f1 f))
6742 ;; then compute the category-filter matcher
6743 (dolist (x (delete-dups
6744 (append (get 'org-agenda-category-filter
6745 :preset-filter) org-agenda-category-filter)))
6746 (if (equal "-" (substring x 0 1))
6747 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6748 (setq f1 (list 'equal (substring x 1) 'cat)))
6749 (push f1 f))
6750 (cons 'and (nreverse f))))
6752 (defun org-agenda-filter-effort-form (e)
6753 "Return the form to compare the effort of the current line with what E says.
6754 E looks like \"+<2:25\"."
6755 (let (op)
6756 (setq e (substring e 1))
6757 (setq op (string-to-char e) e (substring e 1))
6758 (setq op (cond ((equal op ?<) '<=)
6759 ((equal op ?>) '>=)
6760 ((equal op ??) op)
6761 (t '=)))
6762 (list 'org-agenda-compare-effort (list 'quote op)
6763 (org-duration-string-to-minutes e))))
6765 (defun org-agenda-compare-effort (op value)
6766 "Compare the effort of the current line with VALUE, using OP.
6767 If the line does not have an effort defined, return nil."
6768 (let ((eff (org-get-at-bol 'effort-minutes)))
6769 (if (equal op ??)
6770 (not eff)
6771 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6772 value))))
6774 (defun org-agenda-filter-apply (filter type)
6775 "Set FILTER as the new agenda filter and apply it."
6776 (let (tags cat)
6777 (if (eq type 'tag)
6778 (setq org-agenda-tag-filter filter)
6779 (setq org-agenda-category-filter filter))
6780 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6781 (if (and (eq type 'category)
6782 (not (equal (substring (car filter) 0 1) "-")))
6783 ;; Only set `org-agenda-filtered-by-category' to t
6784 ;; when a unique category is used as the filter
6785 (setq org-agenda-filtered-by-category t))
6786 (org-agenda-set-mode-name)
6787 (save-excursion
6788 (goto-char (point-min))
6789 (while (not (eobp))
6790 (if (org-get-at-bol 'org-marker)
6791 (progn
6792 (setq tags (org-get-at-bol 'tags) ; used in eval
6793 cat (get-text-property (point) 'org-category))
6794 (if (not (eval org-agenda-filter-form))
6795 (org-agenda-filter-hide-line type))
6796 (beginning-of-line 2))
6797 (beginning-of-line 2))))
6798 (if (get-char-property (point) 'invisible)
6799 (ignore-errors (org-agenda-previous-line)))))
6801 (defun org-agenda-filter-top-category-apply (category &optional negative)
6802 "Set FILTER as the new agenda filter and apply it."
6803 (org-agenda-set-mode-name)
6804 (save-excursion
6805 (goto-char (point-min))
6806 (while (not (eobp))
6807 (let* ((pos (org-get-at-bol 'org-hd-marker))
6808 (topcat (and pos (org-find-top-category pos))))
6809 (if (and topcat (funcall (if negative 'identity 'not)
6810 (string= category topcat)))
6811 (org-agenda-filter-hide-line 'category)))
6812 (beginning-of-line 2)))
6813 (if (get-char-property (point) 'invisible)
6814 (org-agenda-previous-line))
6815 (setq org-agenda-top-category-filter category
6816 org-agenda-filtered-by-top-category t))
6818 (defun org-agenda-filter-hide-line (type)
6819 (let (ov)
6820 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6821 (point-at-eol)))
6822 (overlay-put ov 'invisible t)
6823 (overlay-put ov 'type type)
6824 (if (eq type 'tag)
6825 (push ov org-agenda-tag-filter-overlays)
6826 (push ov org-agenda-cat-filter-overlays))))
6828 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6829 (setq pos (or pos (point)))
6830 (save-excursion
6831 (dolist (ov (overlays-at pos))
6832 (when (and (overlay-get ov 'invisible)
6833 (eq (overlay-get ov 'type) 'tag))
6834 (goto-char pos)
6835 (if (< (overlay-start ov) (point-at-eol))
6836 (move-overlay ov (point-at-eol)
6837 (overlay-end ov)))))))
6839 (defun org-agenda-filter-show-all-tag nil
6840 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6841 (setq org-agenda-tag-filter-overlays nil
6842 org-agenda-tag-filter nil
6843 org-agenda-filter-form nil)
6844 (org-agenda-set-mode-name))
6846 (defun org-agenda-filter-show-all-cat nil
6847 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6848 (setq org-agenda-cat-filter-overlays nil
6849 org-agenda-filtered-by-category nil
6850 org-agenda-category-filter nil
6851 org-agenda-filter-form nil)
6852 (org-agenda-set-mode-name))
6854 (defun org-agenda-manipulate-query-add ()
6855 "Manipulate the query by adding a search term with positive selection.
6856 Positive selection means the term must be matched for selection of an entry."
6857 (interactive)
6858 (org-agenda-manipulate-query ?\[))
6859 (defun org-agenda-manipulate-query-subtract ()
6860 "Manipulate the query by adding a search term with negative selection.
6861 Negative selection means term must not be matched for selection of an entry."
6862 (interactive)
6863 (org-agenda-manipulate-query ?\]))
6864 (defun org-agenda-manipulate-query-add-re ()
6865 "Manipulate the query by adding a search regexp with positive selection.
6866 Positive selection means the regexp must match for selection of an entry."
6867 (interactive)
6868 (org-agenda-manipulate-query ?\{))
6869 (defun org-agenda-manipulate-query-subtract-re ()
6870 "Manipulate the query by adding a search regexp with negative selection.
6871 Negative selection means regexp must not match for selection of an entry."
6872 (interactive)
6873 (org-agenda-manipulate-query ?\}))
6874 (defun org-agenda-manipulate-query (char)
6875 (cond
6876 ((memq org-agenda-type '(timeline agenda))
6877 (let ((org-agenda-include-inactive-timestamps t))
6878 (org-agenda-redo))
6879 (message "Display now includes inactive timestamps as well"))
6880 ((eq org-agenda-type 'search)
6881 (org-add-to-string
6882 'org-agenda-query-string
6883 (if org-agenda-last-search-view-search-was-boolean
6884 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6885 (?\{ . " +{}") (?\} . " -{}"))))
6886 " "))
6887 (setq org-agenda-redo-command
6888 (list 'org-search-view
6889 org-todo-only
6890 org-agenda-query-string
6891 (+ (length org-agenda-query-string)
6892 (if (member char '(?\{ ?\})) 0 1))))
6893 (set-register org-agenda-query-register org-agenda-query-string)
6894 (org-agenda-redo))
6895 (t (error "Cannot manipulate query for %s-type agenda buffers"
6896 org-agenda-type))))
6898 (defun org-add-to-string (var string)
6899 (set var (concat (symbol-value var) string)))
6901 (defun org-agenda-goto-date (date)
6902 "Jump to DATE in agenda."
6903 (interactive (list (let ((org-read-date-prefer-future
6904 (eval org-agenda-jump-prefer-future)))
6905 (org-read-date))))
6906 (org-agenda-list nil date))
6908 (defun org-agenda-goto-today ()
6909 "Go to today."
6910 (interactive)
6911 (org-agenda-check-type t 'timeline 'agenda)
6912 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6913 (cond
6914 (tdpos (goto-char tdpos))
6915 ((eq org-agenda-type 'agenda)
6916 (let* ((sd (org-agenda-compute-starting-span
6917 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6918 (org-agenda-overriding-arguments org-agenda-last-arguments))
6919 (setf (nth 1 org-agenda-overriding-arguments) sd)
6920 (org-agenda-redo)
6921 (org-agenda-find-same-or-today-or-agenda)))
6922 (t (error "Cannot find today")))))
6924 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6925 (goto-char
6926 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6927 (text-property-any (point-min) (point-max) 'org-today t)
6928 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6929 (point-min))))
6931 (defun org-agenda-later (arg)
6932 "Go forward in time by thee current span.
6933 With prefix ARG, go forward that many times the current span."
6934 (interactive "p")
6935 (org-agenda-check-type t 'agenda)
6936 (let* ((span org-agenda-current-span)
6937 (sd org-starting-day)
6938 (greg (calendar-gregorian-from-absolute sd))
6939 (cnt (org-get-at-bol 'org-day-cnt))
6940 greg2)
6941 (cond
6942 ((eq span 'day)
6943 (setq sd (+ arg sd)))
6944 ((eq span 'week)
6945 (setq sd (+ (* 7 arg) sd)))
6946 ((eq span 'month)
6947 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6948 sd (calendar-absolute-from-gregorian greg2))
6949 (setcar greg2 (1+ (car greg2))))
6950 ((eq span 'year)
6951 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6952 sd (calendar-absolute-from-gregorian greg2))
6953 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6955 (setq sd (+ (* span arg) sd))))
6956 (let ((org-agenda-overriding-arguments
6957 (list (car org-agenda-last-arguments) sd span t)))
6958 (org-agenda-redo)
6959 (org-agenda-find-same-or-today-or-agenda cnt))))
6961 (defun org-agenda-earlier (arg)
6962 "Go backward in time by the current span.
6963 With prefix ARG, go backward that many times the current span."
6964 (interactive "p")
6965 (org-agenda-later (- arg)))
6967 (defun org-agenda-view-mode-dispatch ()
6968 "Call one of the view mode commands."
6969 (interactive)
6970 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6971 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6972 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6973 (let ((a (read-char-exclusive)))
6974 (case a
6975 (?\ (call-interactively 'org-agenda-reset-view))
6976 (?d (call-interactively 'org-agenda-day-view))
6977 (?w (call-interactively 'org-agenda-week-view))
6978 (?m (call-interactively 'org-agenda-month-view))
6979 (?y (call-interactively 'org-agenda-year-view))
6980 (?l (call-interactively 'org-agenda-log-mode))
6981 (?L (org-agenda-log-mode '(4)))
6982 (?c (org-agenda-log-mode 'clockcheck))
6983 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6984 (?a (call-interactively 'org-agenda-archives-mode))
6985 (?A (org-agenda-archives-mode 'files))
6986 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6987 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6988 (?G (call-interactively 'org-agenda-toggle-time-grid))
6989 (?D (call-interactively 'org-agenda-toggle-diary))
6990 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6991 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6992 (org-agenda-check-type t 'timeline 'agenda)
6993 (org-agenda-redo))
6994 (message "Display now includes inactive timestamps as well"))
6995 (?q (message "Abort"))
6996 (otherwise (error "Invalid key" )))))
6998 (defun org-agenda-reset-view ()
6999 "Switch to default view for agenda."
7000 (interactive)
7001 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7002 (defun org-agenda-day-view (&optional day-of-year)
7003 "Switch to daily view for agenda.
7004 With argument DAY-OF-YEAR, switch to that day of the year."
7005 (interactive "P")
7006 (org-agenda-change-time-span 'day day-of-year))
7007 (defun org-agenda-week-view (&optional iso-week)
7008 "Switch to daily view for agenda.
7009 With argument ISO-WEEK, switch to the corresponding ISO week.
7010 If ISO-WEEK has more then 2 digits, only the last two encode the
7011 week. Any digits before this encode a year. So 200712 means
7012 week 12 of year 2007. Years in the range 1938-2037 can also be
7013 written as 2-digit years."
7014 (interactive "P")
7015 (org-agenda-change-time-span 'week iso-week))
7016 (defun org-agenda-month-view (&optional month)
7017 "Switch to monthly view for agenda.
7018 With argument MONTH, switch to that month."
7019 (interactive "P")
7020 (org-agenda-change-time-span 'month month))
7021 (defun org-agenda-year-view (&optional year)
7022 "Switch to yearly view for agenda.
7023 With argument YEAR, switch to that year.
7024 If MONTH has more then 2 digits, only the last two encode the
7025 month. Any digits before this encode a year. So 200712 means
7026 December year 2007. Years in the range 1938-2037 can also be
7027 written as 2-digit years."
7028 (interactive "P")
7029 (when year
7030 (setq year (org-small-year-to-year year)))
7031 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7032 (org-agenda-change-time-span 'year year)
7033 (error "Abort")))
7035 (defun org-agenda-change-time-span (span &optional n)
7036 "Change the agenda view to SPAN.
7037 SPAN may be `day', `week', `month', `year'."
7038 (org-agenda-check-type t 'agenda)
7039 (if (and (not n) (equal org-agenda-current-span span))
7040 (error "Viewing span is already \"%s\"" span))
7041 (let* ((sd (or (org-get-at-bol 'day)
7042 org-starting-day))
7043 (sd (org-agenda-compute-starting-span sd span n))
7044 (org-agenda-overriding-arguments
7045 (or org-agenda-overriding-arguments
7046 (list (car org-agenda-last-arguments) sd span t))))
7047 (org-agenda-redo)
7048 (org-agenda-find-same-or-today-or-agenda))
7049 (org-agenda-set-mode-name)
7050 (message "Switched to %s view" span))
7052 (defun org-agenda-compute-starting-span (sd span &optional n)
7053 "Compute starting date for agenda.
7054 SPAN may be `day', `week', `month', `year'. The return value
7055 is a cons cell with the starting date and the number of days,
7056 so that the date SD will be in that range."
7057 (let* ((greg (calendar-gregorian-from-absolute sd))
7058 (dg (nth 1 greg))
7059 (mg (car greg))
7060 (yg (nth 2 greg)))
7061 (cond
7062 ((eq span 'day)
7063 (when n
7064 (setq sd (+ (calendar-absolute-from-gregorian
7065 (list mg 1 yg))
7066 n -1))))
7067 ((eq span 'week)
7068 (let* ((nt (calendar-day-of-week
7069 (calendar-gregorian-from-absolute sd)))
7070 (d (if org-agenda-start-on-weekday
7071 (- nt org-agenda-start-on-weekday)
7074 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7075 (when n
7076 (require 'cal-iso)
7077 (when (> n 99)
7078 (setq y1 (org-small-year-to-year (/ n 100))
7079 n (mod n 100)))
7080 (setq sd
7081 (calendar-absolute-from-iso
7082 (list n 1
7083 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7084 ((eq span 'month)
7085 (let (y1)
7086 (when (and n (> n 99))
7087 (setq y1 (org-small-year-to-year (/ n 100))
7088 n (mod n 100)))
7089 (setq sd (calendar-absolute-from-gregorian
7090 (list (or n mg) 1 (or y1 yg))))))
7091 ((eq span 'year)
7092 (setq sd (calendar-absolute-from-gregorian
7093 (list 1 1 (or n yg))))))
7094 sd))
7096 (defun org-agenda-next-date-line (&optional arg)
7097 "Jump to the next line indicating a date in agenda buffer."
7098 (interactive "p")
7099 (org-agenda-check-type t 'agenda 'timeline)
7100 (beginning-of-line 1)
7101 ;; This does not work if user makes date format that starts with a blank
7102 (if (looking-at "^\\S-") (forward-char 1))
7103 (if (not (re-search-forward "^\\S-" nil t arg))
7104 (progn
7105 (backward-char 1)
7106 (error "No next date after this line in this buffer")))
7107 (goto-char (match-beginning 0)))
7109 (defun org-agenda-previous-date-line (&optional arg)
7110 "Jump to the previous line indicating a date in agenda buffer."
7111 (interactive "p")
7112 (org-agenda-check-type t 'agenda 'timeline)
7113 (beginning-of-line 1)
7114 (if (not (re-search-backward "^\\S-" nil t arg))
7115 (error "No previous date before this line in this buffer")))
7117 ;; Initialize the highlight
7118 (defvar org-hl (make-overlay 1 1))
7119 (overlay-put org-hl 'face 'highlight)
7121 (defun org-highlight (begin end &optional buffer)
7122 "Highlight a region with overlay."
7123 (move-overlay org-hl begin end (or buffer (current-buffer))))
7125 (defun org-unhighlight ()
7126 "Detach overlay INDEX."
7127 (org-detach-overlay org-hl))
7129 ;; FIXME this is currently not used.
7130 (defun org-highlight-until-next-command (beg end &optional buffer)
7131 "Move the highlight overlay to BEG/END, remove it before the next command."
7132 (org-highlight beg end buffer)
7133 (add-hook 'pre-command-hook 'org-unhighlight-once))
7134 (defun org-unhighlight-once ()
7135 "Remove the highlight from its position, and this function from the hook."
7136 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7137 (org-unhighlight))
7139 (defun org-agenda-follow-mode ()
7140 "Toggle follow mode in an agenda buffer."
7141 (interactive)
7142 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7143 (org-agenda-set-mode-name)
7144 (org-agenda-do-context-action)
7145 (message "Follow mode is %s"
7146 (if org-agenda-follow-mode "on" "off")))
7148 (defun org-agenda-entry-text-mode (&optional arg)
7149 "Toggle entry text mode in an agenda buffer."
7150 (interactive "P")
7151 (setq org-agenda-entry-text-mode (or (integerp arg)
7152 (not org-agenda-entry-text-mode)))
7153 (org-agenda-entry-text-hide)
7154 (and org-agenda-entry-text-mode
7155 (let ((org-agenda-entry-text-maxlines
7156 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7157 (org-agenda-entry-text-show)))
7158 (org-agenda-set-mode-name)
7159 (message "Entry text mode is %s. Maximum number of lines is %d"
7160 (if org-agenda-entry-text-mode "on" "off")
7161 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7163 (defun org-agenda-clockreport-mode (&optional with-filter)
7164 "Toggle clocktable mode in an agenda buffer.
7165 With prefix arg WITH-FILTER, make the clocktable respect the current
7166 agenda filter."
7167 (interactive "P")
7168 (org-agenda-check-type t 'agenda)
7169 (if with-filter
7170 (setq org-agenda-clockreport-mode 'with-filter)
7171 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7172 (org-agenda-set-mode-name)
7173 (org-agenda-redo)
7174 (message "Clocktable mode is %s"
7175 (if org-agenda-clockreport-mode "on" "off")))
7177 (defun org-agenda-log-mode (&optional special)
7178 "Toggle log mode in an agenda buffer.
7179 With argument SPECIAL, show all possible log items, not only the ones
7180 configured in `org-agenda-log-mode-items'.
7181 With a double `C-u' prefix arg, show *only* log items, nothing else."
7182 (interactive "P")
7183 (org-agenda-check-type t 'agenda 'timeline)
7184 (setq org-agenda-show-log
7185 (cond
7186 ((equal special '(16)) 'only)
7187 ((eq special 'clockcheck)
7188 (if (eq org-agenda-show-log 'clockcheck)
7189 nil 'clockcheck))
7190 (special '(closed clock state))
7191 (t (not org-agenda-show-log))))
7192 (org-agenda-set-mode-name)
7193 (org-agenda-redo)
7194 (message "Log mode is %s"
7195 (if org-agenda-show-log "on" "off")))
7197 (defun org-agenda-archives-mode (&optional with-files)
7198 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7199 When called with a prefix argument, include all archive files as well."
7200 (interactive "P")
7201 (setq org-agenda-archives-mode
7202 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7203 (org-agenda-set-mode-name)
7204 (org-agenda-redo)
7205 (message
7206 "%s"
7207 (cond
7208 ((eq org-agenda-archives-mode nil)
7209 "No archives are included")
7210 ((eq org-agenda-archives-mode 'trees)
7211 (format "Trees with :%s: tag are included" org-archive-tag))
7212 ((eq org-agenda-archives-mode t)
7213 (format "Trees with :%s: tag and all active archive files are included"
7214 org-archive-tag)))))
7216 (defun org-agenda-toggle-diary ()
7217 "Toggle diary inclusion in an agenda buffer."
7218 (interactive)
7219 (org-agenda-check-type t 'agenda)
7220 (setq org-agenda-include-diary (not org-agenda-include-diary))
7221 (org-agenda-redo)
7222 (org-agenda-set-mode-name)
7223 (message "Diary inclusion turned %s"
7224 (if org-agenda-include-diary "on" "off")))
7226 (defun org-agenda-toggle-deadlines ()
7227 "Toggle inclusion of entries with a deadline in an agenda buffer."
7228 (interactive)
7229 (org-agenda-check-type t 'agenda)
7230 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7231 (org-agenda-redo)
7232 (org-agenda-set-mode-name)
7233 (message "Deadlines inclusion turned %s"
7234 (if org-agenda-include-deadlines "on" "off")))
7236 (defun org-agenda-toggle-time-grid ()
7237 "Toggle time grid in an agenda buffer."
7238 (interactive)
7239 (org-agenda-check-type t 'agenda)
7240 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7241 (org-agenda-redo)
7242 (org-agenda-set-mode-name)
7243 (message "Time-grid turned %s"
7244 (if org-agenda-use-time-grid "on" "off")))
7246 (defun org-agenda-set-mode-name ()
7247 "Set the mode name to indicate all the small mode settings."
7248 (setq mode-name
7249 (list "Org-Agenda"
7250 (if (get 'org-agenda-files 'org-restrict) " []" "")
7252 '(:eval (org-agenda-span-name org-agenda-current-span))
7253 (if org-agenda-follow-mode " Follow" "")
7254 (if org-agenda-entry-text-mode " ETxt" "")
7255 (if org-agenda-include-diary " Diary" "")
7256 (if org-agenda-include-deadlines " Ddl" "")
7257 (if org-agenda-use-time-grid " Grid" "")
7258 (if (and (boundp 'org-habit-show-habits)
7259 org-habit-show-habits) " Habit" "")
7260 (cond
7261 ((consp org-agenda-show-log) " LogAll")
7262 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7263 (org-agenda-show-log " Log")
7264 (t ""))
7265 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7266 :preset-filter))
7267 '(:eval (org-propertize
7268 (concat " <"
7269 (mapconcat
7270 'identity
7271 (append
7272 (get 'org-agenda-category-filter :preset-filter)
7273 org-agenda-category-filter)
7275 ">")
7276 'face 'org-agenda-filter-category
7277 'help-echo "Category used in filtering"))
7279 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7280 :preset-filter))
7281 '(:eval (org-propertize
7282 (concat " {"
7283 (mapconcat
7284 'identity
7285 (append
7286 (get 'org-agenda-tag-filter :preset-filter)
7287 org-agenda-tag-filter)
7289 "}")
7290 'face 'org-agenda-filter-tags
7291 'help-echo "Tags used in filtering"))
7293 (if org-agenda-archives-mode
7294 (if (eq org-agenda-archives-mode t)
7295 " Archives"
7296 (format " :%s:" org-archive-tag))
7298 (if org-agenda-clockreport-mode
7299 (if (eq org-agenda-clockreport-mode 'with-filter)
7300 " Clock{}" " Clock")
7301 "")))
7302 (force-mode-line-update))
7304 (defun org-agenda-post-command-hook ()
7305 (setq org-agenda-type
7306 (or (get-text-property (point) 'org-agenda-type)
7307 (get-text-property (max (point-min) (1- (point)))
7308 'org-agenda-type))))
7310 (defun org-agenda-next-line ()
7311 "Move cursor to the next line, and show if follow mode is active."
7312 (interactive)
7313 (call-interactively 'next-line)
7314 (org-agenda-do-context-action))
7316 (defun org-agenda-previous-line ()
7317 "Move cursor to the previous line, and show if follow-mode is active."
7318 (interactive)
7319 (call-interactively 'previous-line)
7320 (org-agenda-do-context-action))
7322 (defun org-agenda-next-item (n)
7323 "Move cursor to next agenda item."
7324 (interactive "p")
7325 (let ((col (current-column)))
7326 (dotimes (c n)
7327 (when (next-single-property-change (point-at-eol) 'org-marker)
7328 (move-end-of-line 1)
7329 (goto-char (next-single-property-change (point) 'org-marker))))
7330 (org-move-to-column col))
7331 (org-agenda-do-context-action))
7333 (defun org-agenda-previous-item (n)
7334 "Move cursor to next agenda item."
7335 (interactive "p")
7336 (dotimes (c n)
7337 (let ((col (current-column))
7338 (goto (save-excursion
7339 (move-end-of-line 0)
7340 (previous-single-property-change (point) 'org-marker))))
7341 (if goto (goto-char goto))
7342 (org-move-to-column col)))
7343 (org-agenda-do-context-action))
7345 (defun org-agenda-do-context-action ()
7346 "Show outline path and, maybe, follow mode window."
7347 (let ((m (org-get-at-bol 'org-marker)))
7348 (when (and (markerp m) (marker-buffer m))
7349 (and org-agenda-follow-mode
7350 (if org-agenda-follow-indirect
7351 (org-agenda-tree-to-indirect-buffer)
7352 (org-agenda-show)))
7353 (and org-agenda-show-outline-path
7354 (org-with-point-at m (org-display-outline-path t))))))
7356 (defun org-agenda-show-priority ()
7357 "Show the priority of the current item.
7358 This priority is composed of the main priority given with the [#A] cookies,
7359 and by additional input from the age of a schedules or deadline entry."
7360 (interactive)
7361 (let* ((pri (org-get-at-bol 'priority)))
7362 (message "Priority is %d" (if pri pri -1000))))
7364 (defun org-agenda-show-tags ()
7365 "Show the tags applicable to the current item."
7366 (interactive)
7367 (let* ((tags (org-get-at-bol 'tags)))
7368 (if tags
7369 (message "Tags are :%s:"
7370 (org-no-properties (mapconcat 'identity tags ":")))
7371 (message "No tags associated with this line"))))
7373 (defun org-agenda-goto (&optional highlight)
7374 "Go to the Org-mode file which contains the item at point."
7375 (interactive)
7376 (let* ((marker (or (org-get-at-bol 'org-marker)
7377 (org-agenda-error)))
7378 (buffer (marker-buffer marker))
7379 (pos (marker-position marker)))
7380 (switch-to-buffer-other-window buffer)
7381 (widen)
7382 (push-mark)
7383 (goto-char pos)
7384 (when (derived-mode-p 'org-mode)
7385 (org-show-context 'agenda)
7386 (save-excursion
7387 (and (outline-next-heading)
7388 (org-flag-heading nil)))) ; show the next heading
7389 (when (outline-invisible-p)
7390 (show-entry)) ; display invisible text
7391 (recenter (/ (window-height) 2))
7392 (run-hooks 'org-agenda-after-show-hook)
7393 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7395 (defvar org-agenda-after-show-hook nil
7396 "Normal hook run after an item has been shown from the agenda.
7397 Point is in the buffer where the item originated.")
7399 (defun org-agenda-kill ()
7400 "Kill the entry or subtree belonging to the current agenda entry."
7401 (interactive)
7402 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7403 (let* ((bufname-orig (buffer-name))
7404 (marker (or (org-get-at-bol 'org-marker)
7405 (org-agenda-error)))
7406 (buffer (marker-buffer marker))
7407 (pos (marker-position marker))
7408 (type (org-get-at-bol 'type))
7409 dbeg dend (n 0) conf)
7410 (org-with-remote-undo buffer
7411 (with-current-buffer buffer
7412 (save-excursion
7413 (goto-char pos)
7414 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7415 (setq dbeg (progn (org-back-to-heading t) (point))
7416 dend (org-end-of-subtree t t))
7417 (setq dbeg (point-at-bol)
7418 dend (min (point-max) (1+ (point-at-eol)))))
7419 (goto-char dbeg)
7420 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7421 (setq conf (or (eq t org-agenda-confirm-kill)
7422 (and (numberp org-agenda-confirm-kill)
7423 (> n org-agenda-confirm-kill))))
7424 (and conf
7425 (not (y-or-n-p
7426 (format "Delete entry with %d lines in buffer \"%s\"? "
7427 n (buffer-name buffer))))
7428 (error "Abort"))
7429 (let ((org-agenda-buffer-name bufname-orig))
7430 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7431 (with-current-buffer buffer (delete-region dbeg dend))
7432 (message "Agenda item and source killed"))))
7434 (defvar org-archive-default-command)
7435 (defun org-agenda-archive-default ()
7436 "Archive the entry or subtree belonging to the current agenda entry."
7437 (interactive)
7438 (require 'org-archive)
7439 (org-agenda-archive-with org-archive-default-command))
7441 (defun org-agenda-archive-default-with-confirmation ()
7442 "Archive the entry or subtree belonging to the current agenda entry."
7443 (interactive)
7444 (require 'org-archive)
7445 (org-agenda-archive-with org-archive-default-command 'confirm))
7447 (defun org-agenda-archive ()
7448 "Archive the entry or subtree belonging to the current agenda entry."
7449 (interactive)
7450 (org-agenda-archive-with 'org-archive-subtree))
7452 (defun org-agenda-archive-to-archive-sibling ()
7453 "Move the entry to the archive sibling."
7454 (interactive)
7455 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7457 (defun org-agenda-archive-with (cmd &optional confirm)
7458 "Move the entry to the archive sibling."
7459 (interactive)
7460 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7461 (let* ((bufname-orig (buffer-name))
7462 (marker (or (org-get-at-bol 'org-marker)
7463 (org-agenda-error)))
7464 (buffer (marker-buffer marker))
7465 (pos (marker-position marker)))
7466 (org-with-remote-undo buffer
7467 (with-current-buffer buffer
7468 (if (derived-mode-p 'org-mode)
7469 (if (and confirm
7470 (not (y-or-n-p "Archive this subtree or entry? ")))
7471 (error "Abort")
7472 (save-excursion
7473 (goto-char pos)
7474 (let ((org-agenda-buffer-name bufname-orig))
7475 (org-remove-subtree-entries-from-agenda))
7476 (org-back-to-heading t)
7477 (funcall cmd)))
7478 (error "Archiving works only in Org-mode files"))))))
7480 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7481 "Remove all lines in the agenda that correspond to a given subtree.
7482 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7483 If this information is not given, the function uses the tree at point."
7484 (let ((buf (or buf (current-buffer))) m p)
7485 (save-excursion
7486 (unless (and beg end)
7487 (org-back-to-heading t)
7488 (setq beg (point))
7489 (org-end-of-subtree t)
7490 (setq end (point)))
7491 (set-buffer (get-buffer org-agenda-buffer-name))
7492 (save-excursion
7493 (goto-char (point-max))
7494 (beginning-of-line 1)
7495 (while (not (bobp))
7496 (when (and (setq m (org-get-at-bol 'org-marker))
7497 (equal buf (marker-buffer m))
7498 (setq p (marker-position m))
7499 (>= p beg)
7500 (< p end))
7501 (let ((inhibit-read-only t))
7502 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7503 (beginning-of-line 0))))))
7505 (defun org-agenda-refile (&optional goto rfloc no-update)
7506 "Refile the item at point."
7507 (interactive "P")
7508 (if (equal goto '(16))
7509 (org-refile-goto-last-stored)
7510 (let* ((buffer-orig (buffer-name))
7511 (marker (or (org-get-at-bol 'org-hd-marker)
7512 (org-agenda-error)))
7513 (buffer (marker-buffer marker))
7514 (pos (marker-position marker))
7515 (rfloc (or rfloc
7516 (org-refile-get-location
7517 (if goto "Goto" "Refile to") buffer
7518 org-refile-allow-creating-parent-nodes))))
7519 (with-current-buffer buffer
7520 (save-excursion
7521 (save-restriction
7522 (widen)
7523 (goto-char marker)
7524 (let ((org-agenda-buffer-name buffer-orig))
7525 (org-remove-subtree-entries-from-agenda))
7526 (org-refile goto buffer rfloc)))))
7527 (unless no-update (org-agenda-redo))))
7529 (defun org-agenda-open-link (&optional arg)
7530 "Follow the link in the current line, if any.
7531 This looks for a link in the displayed line in the agenda. It also looks
7532 at the text of the entry itself."
7533 (interactive "P")
7534 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7535 (org-get-at-bol 'org-marker)))
7536 (buffer (and marker (marker-buffer marker)))
7537 (prefix (buffer-substring
7538 (point-at-bol) (point-at-eol))))
7539 (cond
7540 (buffer
7541 (with-current-buffer buffer
7542 (save-excursion
7543 (save-restriction
7544 (widen)
7545 (goto-char marker)
7546 (org-offer-links-in-entry arg prefix)))))
7547 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7548 (save-excursion
7549 (beginning-of-line 1)
7550 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7551 (org-open-link-from-string (match-string 1)))
7552 (t (error "No link to open here")))))
7554 (defun org-agenda-copy-local-variable (var)
7555 "Get a variable from a referenced buffer and install it here."
7556 (let ((m (org-get-at-bol 'org-marker)))
7557 (when (and m (buffer-live-p (marker-buffer m)))
7558 (org-set-local var (with-current-buffer (marker-buffer m)
7559 (symbol-value var))))))
7561 (defun org-agenda-switch-to (&optional delete-other-windows)
7562 "Go to the Org-mode file which contains the item at point."
7563 (interactive)
7564 (if (and org-return-follows-link
7565 (not (org-get-at-bol 'org-marker))
7566 (org-in-regexp org-bracket-link-regexp))
7567 (org-open-link-from-string (match-string 0))
7568 (let* ((marker (or (org-get-at-bol 'org-marker)
7569 (org-agenda-error)))
7570 (buffer (marker-buffer marker))
7571 (pos (marker-position marker)))
7572 (org-pop-to-buffer-same-window buffer)
7573 (and delete-other-windows (delete-other-windows))
7574 (widen)
7575 (goto-char pos)
7576 (when (derived-mode-p 'org-mode)
7577 (org-show-context 'agenda)
7578 (save-excursion
7579 (and (outline-next-heading)
7580 (org-flag-heading nil))) ; show the next heading
7581 (when (outline-invisible-p)
7582 (show-entry)) ; display invisible text
7583 (run-hooks 'org-agenda-after-show-hook)))))
7585 (defun org-agenda-goto-mouse (ev)
7586 "Go to the Org-mode file which contains the item at the mouse click."
7587 (interactive "e")
7588 (mouse-set-point ev)
7589 (org-agenda-goto))
7591 (defun org-agenda-show (&optional full-entry)
7592 "Display the Org-mode file which contains the item at point.
7593 With prefix argument FULL-ENTRY, make the entire entry visible
7594 if it was hidden in the outline."
7595 (interactive "P")
7596 (let ((win (selected-window)))
7597 (if full-entry
7598 (let ((org-show-entry-below t))
7599 (org-agenda-goto t))
7600 (org-agenda-goto t))
7601 (select-window win)))
7603 (defvar org-agenda-show-window nil)
7604 (defun org-agenda-show-and-scroll-up (&optional arg)
7605 "Display the Org-mode file which contains the item at point.
7606 When called repeatedly, scroll the window that is displaying the buffer.
7607 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7608 `show-subtree' to display the item, so that drawers and logbooks stay
7609 folded."
7610 (interactive "P")
7611 (let ((win (selected-window)))
7612 (if (and (window-live-p org-agenda-show-window)
7613 (eq this-command last-command))
7614 (progn
7615 (select-window org-agenda-show-window)
7616 (ignore-errors (scroll-up)))
7617 (org-agenda-goto t)
7618 (if arg (org-show-entry) (show-subtree))
7619 (setq org-agenda-show-window (selected-window)))
7620 (select-window win)))
7622 (defun org-agenda-show-scroll-down ()
7623 "Scroll down the window showing the agenda."
7624 (interactive)
7625 (let ((win (selected-window)))
7626 (when (window-live-p org-agenda-show-window)
7627 (select-window org-agenda-show-window)
7628 (ignore-errors (scroll-down))
7629 (select-window win))))
7631 (defun org-agenda-show-1 (&optional more)
7632 "Display the Org-mode file which contains the item at point.
7633 The prefix arg selects the amount of information to display:
7635 0 hide the subtree
7636 1 just show the entry according to defaults.
7637 2 show the children view
7638 3 show the subtree view
7639 4 show the entire subtree and any LOGBOOK drawers
7640 5 show the entire subtree and any drawers
7641 With prefix argument FULL-ENTRY, make the entire entry visible
7642 if it was hidden in the outline."
7643 (interactive "p")
7644 (let ((win (selected-window)))
7645 (org-agenda-goto t)
7646 (org-recenter-heading 1)
7647 (cond
7648 ((= more 0)
7649 (hide-subtree)
7650 (save-excursion
7651 (org-back-to-heading)
7652 (run-hook-with-args 'org-cycle-hook 'folded))
7653 (message "Remote: FOLDED"))
7654 ((and (org-called-interactively-p 'any) (= more 1))
7655 (message "Remote: show with default settings"))
7656 ((= more 2)
7657 (show-entry)
7658 (show-children)
7659 (save-excursion
7660 (org-back-to-heading)
7661 (run-hook-with-args 'org-cycle-hook 'children))
7662 (message "Remote: CHILDREN"))
7663 ((= more 3)
7664 (show-subtree)
7665 (save-excursion
7666 (org-back-to-heading)
7667 (run-hook-with-args 'org-cycle-hook 'subtree))
7668 (message "Remote: SUBTREE"))
7669 ((= more 4)
7670 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7671 (org-drawer-regexp
7672 (concat "^[ \t]*:\\("
7673 (mapconcat 'regexp-quote org-drawers "\\|")
7674 "\\):[ \t]*$")))
7675 (show-subtree)
7676 (save-excursion
7677 (org-back-to-heading)
7678 (org-cycle-hide-drawers 'subtree)))
7679 (message "Remote: SUBTREE AND LOGBOOK"))
7680 ((> more 4)
7681 (show-subtree)
7682 (message "Remote: SUBTREE AND ALL DRAWERS")))
7683 (select-window win)))
7685 (defun org-recenter-heading (n)
7686 (save-excursion
7687 (org-back-to-heading)
7688 (recenter n)))
7690 (defvar org-agenda-cycle-counter nil)
7691 (defun org-agenda-cycle-show (&optional n)
7692 "Show the current entry in another window, with default settings.
7693 Default settings are taken from `org-show-hierarchy-above' and siblings.
7694 When use repeatedly in immediate succession, the remote entry will cycle
7695 through visibility
7697 children -> subtree -> folded
7699 When called with a numeric prefix arg, that arg will be passed through to
7700 `org-agenda-show-1'. For the interpretation of that argument, see the
7701 docstring of `org-agenda-show-1'."
7702 (interactive "P")
7703 (if (integerp n)
7704 (setq org-agenda-cycle-counter n)
7705 (if (not (eq last-command this-command))
7706 (setq org-agenda-cycle-counter 1)
7707 (if (equal org-agenda-cycle-counter 0)
7708 (setq org-agenda-cycle-counter 2)
7709 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7710 (if (> org-agenda-cycle-counter 3)
7711 (setq org-agenda-cycle-counter 0)))))
7712 (org-agenda-show-1 org-agenda-cycle-counter))
7714 (defun org-agenda-recenter (arg)
7715 "Display the Org-mode file which contains the item at point and recenter."
7716 (interactive "P")
7717 (let ((win (selected-window)))
7718 (org-agenda-goto t)
7719 (recenter arg)
7720 (select-window win)))
7722 (defun org-agenda-show-mouse (ev)
7723 "Display the Org-mode file which contains the item at the mouse click."
7724 (interactive "e")
7725 (mouse-set-point ev)
7726 (org-agenda-show))
7728 (defun org-agenda-check-no-diary ()
7729 "Check if the entry is a diary link and abort if yes."
7730 (if (org-get-at-bol 'org-agenda-diary-link)
7731 (org-agenda-error)))
7733 (defun org-agenda-error ()
7734 (error "Command not allowed in this line"))
7736 (defun org-agenda-tree-to-indirect-buffer ()
7737 "Show the subtree corresponding to the current entry in an indirect buffer.
7738 This calls the command `org-tree-to-indirect-buffer' from the original
7739 Org-mode buffer.
7740 With numerical prefix arg ARG, go up to this level and then take that tree.
7741 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7742 use the dedicated frame)."
7743 (interactive)
7744 (if (and current-prefix-arg (listp current-prefix-arg))
7745 (org-agenda-do-tree-to-indirect-buffer)
7746 (let ((agenda-window (selected-window))
7747 (indirect-window
7748 (and org-last-indirect-buffer
7749 (get-buffer-window org-last-indirect-buffer))))
7750 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7751 (unwind-protect
7752 (progn
7753 (unless (and indirect-window (window-live-p indirect-window))
7754 (setq indirect-window (split-window agenda-window)))
7755 (select-window indirect-window)
7756 (switch-to-buffer org-last-indirect-buffer :norecord)
7757 (fit-window-to-buffer indirect-window))
7758 (select-window (get-buffer-window org-agenda-buffer-name))))))
7760 (defun org-agenda-do-tree-to-indirect-buffer ()
7761 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7762 (org-agenda-check-no-diary)
7763 (let* ((marker (or (org-get-at-bol 'org-marker)
7764 (org-agenda-error)))
7765 (buffer (marker-buffer marker))
7766 (pos (marker-position marker)))
7767 (with-current-buffer buffer
7768 (save-excursion
7769 (goto-char pos)
7770 (call-interactively 'org-tree-to-indirect-buffer)))))
7772 (defvar org-last-heading-marker (make-marker)
7773 "Marker pointing to the headline that last changed its TODO state
7774 by a remote command from the agenda.")
7776 (defun org-agenda-todo-nextset ()
7777 "Switch TODO entry to next sequence."
7778 (interactive)
7779 (org-agenda-todo 'nextset))
7781 (defun org-agenda-todo-previousset ()
7782 "Switch TODO entry to previous sequence."
7783 (interactive)
7784 (org-agenda-todo 'previousset))
7786 (defun org-agenda-todo (&optional arg)
7787 "Cycle TODO state of line at point, also in Org-mode file.
7788 This changes the line at point, all other lines in the agenda referring to
7789 the same tree node, and the headline of the tree node in the Org-mode file."
7790 (interactive "P")
7791 (org-agenda-check-no-diary)
7792 (let* ((col (current-column))
7793 (marker (or (org-get-at-bol 'org-marker)
7794 (org-agenda-error)))
7795 (buffer (marker-buffer marker))
7796 (pos (marker-position marker))
7797 (hdmarker (org-get-at-bol 'org-hd-marker))
7798 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7799 (inhibit-read-only t)
7800 org-agenda-headline-snapshot-before-repeat newhead just-one)
7801 (org-with-remote-undo buffer
7802 (with-current-buffer buffer
7803 (widen)
7804 (goto-char pos)
7805 (org-show-context 'agenda)
7806 (save-excursion
7807 (and (outline-next-heading)
7808 (org-flag-heading nil))) ; show the next heading
7809 (let ((current-prefix-arg arg))
7810 (call-interactively 'org-todo))
7811 (and (bolp) (forward-char 1))
7812 (setq newhead (org-get-heading))
7813 (when (and (org-bound-and-true-p
7814 org-agenda-headline-snapshot-before-repeat)
7815 (not (equal org-agenda-headline-snapshot-before-repeat
7816 newhead))
7817 todayp)
7818 (setq newhead org-agenda-headline-snapshot-before-repeat
7819 just-one t))
7820 (save-excursion
7821 (org-back-to-heading)
7822 (move-marker org-last-heading-marker (point))))
7823 (beginning-of-line 1)
7824 (save-excursion
7825 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7826 (org-move-to-column col))))
7828 (defun org-agenda-add-note (&optional arg)
7829 "Add a time-stamped note to the entry at point."
7830 (interactive "P")
7831 (org-agenda-check-no-diary)
7832 (let* ((marker (or (org-get-at-bol 'org-marker)
7833 (org-agenda-error)))
7834 (buffer (marker-buffer marker))
7835 (pos (marker-position marker))
7836 (hdmarker (org-get-at-bol 'org-hd-marker))
7837 (inhibit-read-only t))
7838 (with-current-buffer buffer
7839 (widen)
7840 (goto-char pos)
7841 (org-show-context 'agenda)
7842 (save-excursion
7843 (and (outline-next-heading)
7844 (org-flag-heading nil))) ; show the next heading
7845 (org-add-note))))
7847 (defun org-agenda-change-all-lines (newhead hdmarker
7848 &optional fixface just-this)
7849 "Change all lines in the agenda buffer which match HDMARKER.
7850 The new content of the line will be NEWHEAD (as modified by
7851 `org-agenda-format-item'). HDMARKER is checked with
7852 `equal' against all `org-hd-marker' text properties in the file.
7853 If FIXFACE is non-nil, the face of each item is modified according to
7854 the new TODO state.
7855 If JUST-THIS is non-nil, change just the current line, not all.
7856 If FORCE-TAGS is non nil, the car of it returns the new tags."
7857 (let* ((inhibit-read-only t)
7858 (line (org-current-line))
7859 (org-agenda-buffer (current-buffer))
7860 (thetags (with-current-buffer (marker-buffer hdmarker)
7861 (save-excursion (save-restriction (widen)
7862 (goto-char hdmarker)
7863 (org-get-tags-at)))))
7864 props m pl undone-face done-face finish new dotime cat tags)
7865 (save-excursion
7866 (goto-char (point-max))
7867 (beginning-of-line 1)
7868 (while (not finish)
7869 (setq finish (bobp))
7870 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7871 (or (not just-this) (= (org-current-line) line))
7872 (equal m hdmarker))
7873 (setq props (text-properties-at (point))
7874 dotime (org-get-at-bol 'dotime)
7875 cat (org-get-at-bol 'org-category)
7876 tags thetags
7878 (let ((org-prefix-format-compiled
7879 (or (get-text-property (point) 'format)
7880 org-prefix-format-compiled))
7881 (extra (org-get-at-bol 'extra)))
7882 (with-current-buffer (marker-buffer hdmarker)
7883 (save-excursion
7884 (save-restriction
7885 (widen)
7886 (org-agenda-format-item extra newhead cat tags dotime)))))
7887 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7888 undone-face (org-get-at-bol 'undone-face)
7889 done-face (org-get-at-bol 'done-face))
7890 (beginning-of-line 1)
7891 (cond
7892 ((equal new "")
7893 (and (looking-at ".*\n?") (replace-match "")))
7894 ((looking-at ".*")
7895 (replace-match new t t)
7896 (beginning-of-line 1)
7897 (add-text-properties (point-at-bol) (point-at-eol) props)
7898 (when fixface
7899 (add-text-properties
7900 (point-at-bol) (point-at-eol)
7901 (list 'face
7902 (if org-last-todo-state-is-todo
7903 undone-face done-face))))
7904 (org-agenda-highlight-todo 'line)
7905 (beginning-of-line 1))
7906 (t (error "Line update did not work"))))
7907 (beginning-of-line 0)))
7908 (org-finalize-agenda)))
7910 (defun org-agenda-align-tags (&optional line)
7911 "Align all tags in agenda items to `org-agenda-tags-column'."
7912 (let ((inhibit-read-only t) l c)
7913 (save-excursion
7914 (goto-char (if line (point-at-bol) (point-min)))
7915 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7916 (if line (point-at-eol) nil) t)
7917 (add-text-properties
7918 (match-beginning 2) (match-end 2)
7919 (list 'face (delq nil (let ((prop (get-text-property
7920 (match-beginning 2) 'face)))
7921 (or (listp prop) (setq prop (list prop)))
7922 (if (memq 'org-tag prop)
7923 prop
7924 (cons 'org-tag prop))))))
7925 (setq l (- (match-end 2) (match-beginning 2))
7926 c (if (< org-agenda-tags-column 0)
7927 (- (abs org-agenda-tags-column) l)
7928 org-agenda-tags-column))
7929 (delete-region (match-beginning 1) (match-end 1))
7930 (goto-char (match-beginning 1))
7931 (insert (org-add-props
7932 (make-string (max 1 (- c (current-column))) ?\ )
7933 (plist-put (copy-sequence (text-properties-at (point)))
7934 'face nil))))
7935 (goto-char (point-min))
7936 (org-font-lock-add-tag-faces (point-max)))))
7938 (defun org-agenda-priority-up ()
7939 "Increase the priority of line at point, also in Org-mode file."
7940 (interactive)
7941 (org-agenda-priority 'up))
7943 (defun org-agenda-priority-down ()
7944 "Decrease the priority of line at point, also in Org-mode file."
7945 (interactive)
7946 (org-agenda-priority 'down))
7948 (defun org-agenda-priority (&optional force-direction)
7949 "Set the priority of line at point, also in Org-mode file.
7950 This changes the line at point, all other lines in the agenda referring to
7951 the same tree node, and the headline of the tree node in the Org-mode file."
7952 (interactive)
7953 (unless org-enable-priority-commands
7954 (error "Priority commands are disabled"))
7955 (org-agenda-check-no-diary)
7956 (let* ((marker (or (org-get-at-bol 'org-marker)
7957 (org-agenda-error)))
7958 (hdmarker (org-get-at-bol 'org-hd-marker))
7959 (buffer (marker-buffer hdmarker))
7960 (pos (marker-position hdmarker))
7961 (inhibit-read-only t)
7962 newhead)
7963 (org-with-remote-undo buffer
7964 (with-current-buffer buffer
7965 (widen)
7966 (goto-char pos)
7967 (org-show-context 'agenda)
7968 (save-excursion
7969 (and (outline-next-heading)
7970 (org-flag-heading nil))) ; show the next heading
7971 (funcall 'org-priority force-direction)
7972 (end-of-line 1)
7973 (setq newhead (org-get-heading)))
7974 (org-agenda-change-all-lines newhead hdmarker)
7975 (beginning-of-line 1))))
7977 ;; FIXME: should fix the tags property of the agenda line.
7978 (defun org-agenda-set-tags (&optional tag onoff)
7979 "Set tags for the current headline."
7980 (interactive)
7981 (org-agenda-check-no-diary)
7982 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7983 (call-interactively 'org-change-tag-in-region)
7984 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7985 (org-agenda-error)))
7986 (buffer (marker-buffer hdmarker))
7987 (pos (marker-position hdmarker))
7988 (inhibit-read-only t)
7989 newhead)
7990 (org-with-remote-undo buffer
7991 (with-current-buffer buffer
7992 (widen)
7993 (goto-char pos)
7994 (save-excursion
7995 (org-show-context 'agenda))
7996 (save-excursion
7997 (and (outline-next-heading)
7998 (org-flag-heading nil))) ; show the next heading
7999 (goto-char pos)
8000 (if tag
8001 (org-toggle-tag tag onoff)
8002 (call-interactively 'org-set-tags))
8003 (end-of-line 1)
8004 (setq newhead (org-get-heading)))
8005 (org-agenda-change-all-lines newhead hdmarker)
8006 (beginning-of-line 1)))))
8008 (defun org-agenda-set-property ()
8009 "Set a property for the current headline."
8010 (interactive)
8011 (org-agenda-check-no-diary)
8012 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8013 (org-agenda-error)))
8014 (buffer (marker-buffer hdmarker))
8015 (pos (marker-position hdmarker))
8016 (inhibit-read-only t)
8017 newhead)
8018 (org-with-remote-undo buffer
8019 (with-current-buffer buffer
8020 (widen)
8021 (goto-char pos)
8022 (save-excursion
8023 (org-show-context 'agenda))
8024 (save-excursion
8025 (and (outline-next-heading)
8026 (org-flag-heading nil))) ; show the next heading
8027 (goto-char pos)
8028 (call-interactively 'org-set-property)))))
8030 (defun org-agenda-set-effort ()
8031 "Set the effort property for the current headline."
8032 (interactive)
8033 (org-agenda-check-no-diary)
8034 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8035 (org-agenda-error)))
8036 (buffer (marker-buffer hdmarker))
8037 (pos (marker-position hdmarker))
8038 (inhibit-read-only t)
8039 newhead)
8040 (org-with-remote-undo buffer
8041 (with-current-buffer buffer
8042 (widen)
8043 (goto-char pos)
8044 (save-excursion
8045 (org-show-context 'agenda))
8046 (save-excursion
8047 (and (outline-next-heading)
8048 (org-flag-heading nil))) ; show the next heading
8049 (goto-char pos)
8050 (call-interactively 'org-set-effort)
8051 (end-of-line 1)
8052 (setq newhead (org-get-heading)))
8053 (org-agenda-change-all-lines newhead hdmarker))))
8055 (defun org-agenda-toggle-archive-tag ()
8056 "Toggle the archive tag for the current entry."
8057 (interactive)
8058 (org-agenda-check-no-diary)
8059 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8060 (org-agenda-error)))
8061 (buffer (marker-buffer hdmarker))
8062 (pos (marker-position hdmarker))
8063 (inhibit-read-only t)
8064 newhead)
8065 (org-with-remote-undo buffer
8066 (with-current-buffer buffer
8067 (widen)
8068 (goto-char pos)
8069 (org-show-context 'agenda)
8070 (save-excursion
8071 (and (outline-next-heading)
8072 (org-flag-heading nil))) ; show the next heading
8073 (call-interactively 'org-toggle-archive-tag)
8074 (end-of-line 1)
8075 (setq newhead (org-get-heading)))
8076 (org-agenda-change-all-lines newhead hdmarker)
8077 (beginning-of-line 1))))
8079 (defun org-agenda-do-date-later (arg)
8080 (interactive "P")
8081 (cond
8082 ((or (equal arg '(16))
8083 (memq last-command
8084 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8085 (setq this-command 'org-agenda-date-later-minutes)
8086 (org-agenda-date-later-minutes 1))
8087 ((or (equal arg '(4))
8088 (memq last-command
8089 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8090 (setq this-command 'org-agenda-date-later-hours)
8091 (org-agenda-date-later-hours 1))
8093 (org-agenda-date-later (prefix-numeric-value arg)))))
8095 (defun org-agenda-do-date-earlier (arg)
8096 (interactive "P")
8097 (cond
8098 ((or (equal arg '(16))
8099 (memq last-command
8100 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8101 (setq this-command 'org-agenda-date-earlier-minutes)
8102 (org-agenda-date-earlier-minutes 1))
8103 ((or (equal arg '(4))
8104 (memq last-command
8105 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8106 (setq this-command 'org-agenda-date-earlier-hours)
8107 (org-agenda-date-earlier-hours 1))
8109 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8111 (defun org-agenda-date-later (arg &optional what)
8112 "Change the date of this item to ARG day(s) later."
8113 (interactive "p")
8114 (org-agenda-check-type t 'agenda 'timeline)
8115 (org-agenda-check-no-diary)
8116 (let* ((marker (or (org-get-at-bol 'org-marker)
8117 (org-agenda-error)))
8118 (buffer (marker-buffer marker))
8119 (pos (marker-position marker))
8120 cdate today)
8121 (org-with-remote-undo buffer
8122 (with-current-buffer buffer
8123 (widen)
8124 (goto-char pos)
8125 (if (not (org-at-timestamp-p))
8126 (error "Cannot find time stamp"))
8127 (when (and org-agenda-move-date-from-past-immediately-to-today
8128 (equal arg 1)
8129 (or (not what) (eq what 'day))
8130 (not (save-match-data (org-at-date-range-p))))
8131 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8132 cdate (calendar-absolute-from-gregorian
8133 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8134 today (org-today))
8135 (if (> today cdate)
8136 ;; immediately shift to today
8137 (setq arg (- today cdate))))
8138 (org-timestamp-change arg (or what 'day))
8139 (when (and (org-at-date-range-p)
8140 (re-search-backward org-tr-regexp-both (point-at-bol)))
8141 (let ((end org-last-changed-timestamp))
8142 (org-timestamp-change arg (or what 'day))
8143 (setq org-last-changed-timestamp
8144 (concat org-last-changed-timestamp "--" end)))))
8145 (org-agenda-show-new-time marker org-last-changed-timestamp))
8146 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8148 (defun org-agenda-date-earlier (arg &optional what)
8149 "Change the date of this item to ARG day(s) earlier."
8150 (interactive "p")
8151 (org-agenda-date-later (- arg) what))
8153 (defun org-agenda-date-later-minutes (arg)
8154 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8155 (interactive "p")
8156 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8157 (org-agenda-date-later arg 'minute))
8159 (defun org-agenda-date-earlier-minutes (arg)
8160 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8161 (interactive "p")
8162 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8163 (org-agenda-date-earlier arg 'minute))
8165 (defun org-agenda-date-later-hours (arg)
8166 "Change the time of this item, in hour steps."
8167 (interactive "p")
8168 (org-agenda-date-later arg 'hour))
8170 (defun org-agenda-date-earlier-hours (arg)
8171 "Change the time of this item, in hour steps."
8172 (interactive "p")
8173 (org-agenda-date-earlier arg 'hour))
8175 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8176 "Show new date stamp via text properties."
8177 ;; We use text properties to make this undoable
8178 (let ((inhibit-read-only t)
8179 (buffer-invisibility-spec))
8180 (setq stamp (concat " " prefix " => " stamp))
8181 (save-excursion
8182 (goto-char (point-max))
8183 (while (not (bobp))
8184 (when (equal marker (org-get-at-bol 'org-marker))
8185 (org-move-to-column (- (window-width) (length stamp)) t)
8186 (org-agenda-fix-tags-filter-overlays-at (point))
8187 (if (featurep 'xemacs)
8188 ;; Use `duplicable' property to trigger undo recording
8189 (let ((ex (make-extent nil nil))
8190 (gl (make-glyph stamp)))
8191 (set-glyph-face gl 'secondary-selection)
8192 (set-extent-properties
8193 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8194 (insert-extent ex (1- (point)) (point-at-eol)))
8195 (add-text-properties
8196 (1- (point)) (point-at-eol)
8197 (list 'display (org-add-props stamp nil
8198 'face 'secondary-selection))))
8199 (beginning-of-line 1))
8200 (beginning-of-line 0)))))
8202 (defun org-agenda-date-prompt (arg)
8203 "Change the date of this item. Date is prompted for, with default today.
8204 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8205 be used to request time specification in the time stamp."
8206 (interactive "P")
8207 (org-agenda-check-type t 'agenda 'timeline)
8208 (org-agenda-check-no-diary)
8209 (let* ((marker (or (org-get-at-bol 'org-marker)
8210 (org-agenda-error)))
8211 (buffer (marker-buffer marker))
8212 (pos (marker-position marker)))
8213 (org-with-remote-undo buffer
8214 (with-current-buffer buffer
8215 (widen)
8216 (goto-char pos)
8217 (if (not (org-at-timestamp-p t))
8218 (error "Cannot find time stamp"))
8219 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8220 (org-agenda-show-new-time marker org-last-changed-timestamp))
8221 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8223 (defun org-agenda-schedule (arg &optional time)
8224 "Schedule the item at point.
8225 ARG is passed through to `org-schedule'."
8226 (interactive "P")
8227 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8228 (org-agenda-check-no-diary)
8229 (let* ((marker (or (org-get-at-bol 'org-marker)
8230 (org-agenda-error)))
8231 (type (marker-insertion-type marker))
8232 (buffer (marker-buffer marker))
8233 (pos (marker-position marker))
8234 (org-insert-labeled-timestamps-at-point nil)
8236 (set-marker-insertion-type marker t)
8237 (org-with-remote-undo buffer
8238 (with-current-buffer buffer
8239 (widen)
8240 (goto-char pos)
8241 (setq ts (org-schedule arg time)))
8242 (org-agenda-show-new-time marker ts "S"))
8243 (message "Item scheduled for %s" ts)))
8245 (defun org-agenda-deadline (arg &optional time)
8246 "Schedule the item at point.
8247 ARG is passed through to `org-deadline'."
8248 (interactive "P")
8249 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8250 (org-agenda-check-no-diary)
8251 (let* ((marker (or (org-get-at-bol 'org-marker)
8252 (org-agenda-error)))
8253 (buffer (marker-buffer marker))
8254 (pos (marker-position marker))
8255 (org-insert-labeled-timestamps-at-point nil)
8257 (org-with-remote-undo buffer
8258 (with-current-buffer buffer
8259 (widen)
8260 (goto-char pos)
8261 (setq ts (org-deadline arg time)))
8262 (org-agenda-show-new-time marker ts "D"))
8263 (message "Deadline for this item set to %s" ts)))
8265 (defun org-agenda-action ()
8266 "Select entry for agenda action, or execute an agenda action.
8267 This command prompts for another letter. Valid inputs are:
8269 m Mark the entry at point for an agenda action
8270 s Schedule the marked entry to the date at the cursor
8271 d Set the deadline of the marked entry to the date at the cursor
8272 r Call `org-remember' with cursor date as the default date
8273 c Call `org-capture' with cursor date as the default date
8274 SPC Show marked entry in other window
8275 TAB Visit marked entry in other window
8277 The cursor may be at a date in the calendar, or in the Org agenda."
8278 (interactive)
8279 (let (ans)
8280 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8281 (setq ans (read-char-exclusive))
8282 (cond
8283 ((equal ans ?m)
8284 ;; Mark this entry
8285 (if (eq major-mode 'org-agenda-mode)
8286 (let ((m (or (org-get-at-bol 'org-hd-marker)
8287 (org-get-at-bol 'org-marker))))
8288 (if m
8289 (progn
8290 (move-marker org-agenda-action-marker
8291 (marker-position m) (marker-buffer m))
8292 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8293 (error "Don't know which entry to mark")))
8294 (error "This command works only in the agenda")))
8295 ((equal ans ?s)
8296 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8297 ((equal ans ?d)
8298 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8299 ((equal ans ?r)
8300 (org-agenda-do-action '(org-remember) t))
8301 ((equal ans ?c)
8302 (org-agenda-do-action '(org-capture) t))
8303 ((equal ans ?\ )
8304 (let ((cw (selected-window)))
8305 (org-switch-to-buffer-other-window
8306 (marker-buffer org-agenda-action-marker))
8307 (goto-char org-agenda-action-marker)
8308 (org-show-context 'agenda)
8309 (select-window cw)))
8310 ((equal ans ?\C-i)
8311 (org-switch-to-buffer-other-window
8312 (marker-buffer org-agenda-action-marker))
8313 (goto-char org-agenda-action-marker)
8314 (org-show-context 'agenda))
8315 (t (error "Invalid agenda action %c" ans)))))
8317 (defun org-agenda-do-action (form &optional current-buffer)
8318 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8319 (let ((org-overriding-default-time (org-get-cursor-date)))
8320 (if current-buffer
8321 (eval form)
8322 (if (not (marker-buffer org-agenda-action-marker))
8323 (error "No entry has been selected for agenda action")
8324 (with-current-buffer (marker-buffer org-agenda-action-marker)
8325 (save-excursion
8326 (save-restriction
8327 (widen)
8328 (goto-char org-agenda-action-marker)
8329 (eval form))))))))
8331 (defun org-agenda-clock-in (&optional arg)
8332 "Start the clock on the currently selected item."
8333 (interactive "P")
8334 (org-agenda-check-no-diary)
8335 (if (equal arg '(4))
8336 (org-clock-in arg)
8337 (let* ((marker (or (org-get-at-bol 'org-marker)
8338 (org-agenda-error)))
8339 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8340 marker))
8341 (pos (marker-position marker))
8342 newhead)
8343 (org-with-remote-undo (marker-buffer marker)
8344 (with-current-buffer (marker-buffer marker)
8345 (widen)
8346 (goto-char pos)
8347 (org-show-context 'agenda)
8348 (org-show-entry)
8349 (org-cycle-hide-drawers 'children)
8350 (org-clock-in arg)
8351 (setq newhead (org-get-heading)))
8352 (org-agenda-change-all-lines newhead hdmarker)))))
8354 (defun org-agenda-clock-out ()
8355 "Stop the currently running clock."
8356 (interactive)
8357 (unless (marker-buffer org-clock-marker)
8358 (error "No running clock"))
8359 (let ((marker (make-marker)) newhead)
8360 (org-with-remote-undo (marker-buffer org-clock-marker)
8361 (with-current-buffer (marker-buffer org-clock-marker)
8362 (save-excursion
8363 (save-restriction
8364 (widen)
8365 (goto-char org-clock-marker)
8366 (org-back-to-heading t)
8367 (move-marker marker (point))
8368 (org-clock-out)
8369 (setq newhead (org-get-heading))))))
8370 (org-agenda-change-all-lines newhead marker)
8371 (move-marker marker nil)))
8373 (defun org-agenda-clock-cancel (&optional arg)
8374 "Cancel the currently running clock."
8375 (interactive "P")
8376 (unless (marker-buffer org-clock-marker)
8377 (error "No running clock"))
8378 (org-with-remote-undo (marker-buffer org-clock-marker)
8379 (org-clock-cancel)))
8381 (defun org-agenda-clock-goto ()
8382 "Jump to the currently clocked in task within the agenda.
8383 If the currently clocked in task is not listed in the agenda
8384 buffer, display it in another window."
8385 (interactive)
8386 (let (pos)
8387 (mapc (lambda (o)
8388 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8389 (setq pos (overlay-start o))))
8390 (overlays-in (point-min) (point-max)))
8391 (cond (pos (goto-char pos))
8392 ;; If the currently clocked entry is not in the agenda
8393 ;; buffer, we visit it in another window:
8394 (org-clock-current-task
8395 (org-switch-to-buffer-other-window (org-clock-goto)))
8396 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8398 (defun org-agenda-diary-entry-in-org-file ()
8399 "Make a diary entry in the file `org-agenda-diary-file'."
8400 (let (d1 d2 char (text "") dp1 dp2)
8401 (if (equal (buffer-name) "*Calendar*")
8402 (setq d1 (calendar-cursor-to-date t)
8403 d2 (car calendar-mark-ring))
8404 (setq dp1 (get-text-property (point-at-bol) 'day))
8405 (unless dp1 (error "No date defined in current line"))
8406 (setq d1 (calendar-gregorian-from-absolute dp1)
8407 d2 (and (ignore-errors (mark))
8408 (save-excursion
8409 (goto-char (mark))
8410 (setq dp2 (get-text-property (point-at-bol) 'day)))
8411 (calendar-gregorian-from-absolute dp2))))
8412 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8413 (setq char (read-char-exclusive))
8414 (cond
8415 ((equal char ?d)
8416 (setq text (read-string "Day entry: "))
8417 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8418 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8419 ((equal char ?a)
8420 (setq d1 (list (car d1) (nth 1 d1)
8421 (read-number (format "Reference year [%d]: " (nth 2 d1))
8422 (nth 2 d1))))
8423 (setq text (read-string "Anniversary (use %d to show years): "))
8424 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8425 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8426 ((equal char ?b)
8427 (setq text (read-string "Block entry: "))
8428 (unless (and d1 d2 (not (equal d1 d2)))
8429 (error "No block of days selected"))
8430 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8431 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8432 ((equal char ?j)
8433 (org-switch-to-buffer-other-window
8434 (find-file-noselect org-agenda-diary-file))
8435 (require 'org-datetree)
8436 (org-datetree-find-date-create d1)
8437 (org-reveal t))
8438 (t (error "Invalid selection character `%c'" char)))))
8440 (defcustom org-agenda-insert-diary-strategy 'date-tree
8441 "Where in `org-agenda-diary-file' should new entries be added?
8442 Valid values:
8444 date-tree in the date tree, as child of the date
8445 top-level as top-level entries at the end of the file."
8446 :group 'org-agenda
8447 :type '(choice
8448 (const :tag "in a date tree" date-tree)
8449 (const :tag "as top level at end of file" top-level)))
8451 (defcustom org-agenda-insert-diary-extract-time nil
8452 "Non-nil means extract any time specification from the diary entry."
8453 :group 'org-agenda
8454 :version "24.1"
8455 :type 'boolean)
8457 (defcustom org-agenda-bulk-mark-char ">"
8458 "A single-character string to be used as the bulk mark."
8459 :group 'org-agenda
8460 :version "24.1"
8461 :type 'string)
8463 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8464 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8465 If TEXT is not empty, it will become the headline of the new entry, and
8466 the resulting entry will not be shown. When TEXT is empty, switch to
8467 `org-agenda-diary-file' and let the user finish the entry there."
8468 (let ((cw (current-window-configuration)))
8469 (org-switch-to-buffer-other-window
8470 (find-file-noselect org-agenda-diary-file))
8471 (widen)
8472 (goto-char (point-min))
8473 (cond
8474 ((eq type 'anniversary)
8475 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8476 (progn
8477 (or (org-at-heading-p t)
8478 (progn
8479 (outline-next-heading)
8480 (insert "* Anniversaries\n\n")
8481 (beginning-of-line -1)))))
8482 (outline-next-heading)
8483 (org-back-over-empty-lines)
8484 (backward-char 1)
8485 (insert "\n")
8486 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8487 (nth 2 d1) (car d1) (nth 1 d1) text)))
8488 ((eq type 'day)
8489 (let ((org-prefix-has-time t)
8490 (org-agenda-time-leading-zero t)
8491 fmt time time2)
8492 (if org-agenda-insert-diary-extract-time
8493 ;; Use org-agenda-format-item to parse text for a time-range and
8494 ;; remove it. FIXME: This is a hack, we should refactor
8495 ;; that function to make time extraction available separately
8496 (setq fmt (org-agenda-format-item nil text nil nil t)
8497 time (get-text-property 0 'time fmt)
8498 time2 (if (> (length time) 0)
8499 ;; split-string removes trailing ...... if
8500 ;; no end time given. First space
8501 ;; separates time from date.
8502 (concat " " (car (split-string time "\\.")))
8503 nil)
8504 text (get-text-property 0 'txt fmt)))
8505 (if (eq org-agenda-insert-diary-strategy 'top-level)
8506 (org-agenda-insert-diary-as-top-level text)
8507 (require 'org-datetree)
8508 (org-datetree-find-date-create d1)
8509 (org-agenda-insert-diary-make-new-entry text))
8510 (org-insert-time-stamp (org-time-from-absolute
8511 (calendar-absolute-from-gregorian d1))
8512 nil nil nil nil time2))
8513 (end-of-line 0))
8514 ((eq type 'block)
8515 (if (> (calendar-absolute-from-gregorian d1)
8516 (calendar-absolute-from-gregorian d2))
8517 (setq d1 (prog1 d2 (setq d2 d1))))
8518 (if (eq org-agenda-insert-diary-strategy 'top-level)
8519 (org-agenda-insert-diary-as-top-level text)
8520 (require 'org-datetree)
8521 (org-datetree-find-date-create d1)
8522 (org-agenda-insert-diary-make-new-entry text))
8523 (org-insert-time-stamp (org-time-from-absolute
8524 (calendar-absolute-from-gregorian d1)))
8525 (insert "--")
8526 (org-insert-time-stamp (org-time-from-absolute
8527 (calendar-absolute-from-gregorian d2)))
8528 (end-of-line 0)))
8529 (if (string-match "\\S-" text)
8530 (progn
8531 (set-window-configuration cw)
8532 (message "%s entry added to %s"
8533 (capitalize (symbol-name type))
8534 (abbreviate-file-name org-agenda-diary-file)))
8535 (org-reveal t)
8536 (message "Please finish entry here"))))
8538 (defun org-agenda-insert-diary-as-top-level (text)
8539 "Make new entry as a top-level entry at the end of the file.
8540 Add TEXT as headline, and position the cursor in the second line so that
8541 a timestamp can be added there."
8542 (widen)
8543 (goto-char (point-max))
8544 (or (bolp) (insert "\n"))
8545 (insert "* " text "\n")
8546 (if org-adapt-indentation (org-indent-to-column 2)))
8548 (defun org-agenda-insert-diary-make-new-entry (text)
8549 "Make new entry as last child of current entry.
8550 Add TEXT as headline, and position the cursor in the second line so that
8551 a timestamp can be added there."
8552 (let ((org-show-following-heading t)
8553 (org-show-siblings t)
8554 (org-show-hierarchy-above t)
8555 (org-show-entry-below t)
8556 col)
8557 (outline-next-heading)
8558 (org-back-over-empty-lines)
8559 (or (looking-at "[ \t]*$")
8560 (progn (insert "\n") (backward-char 1)))
8561 (org-insert-heading nil t)
8562 (org-do-demote)
8563 (setq col (current-column))
8564 (insert text "\n")
8565 (if org-adapt-indentation (org-indent-to-column col))
8566 (let ((org-show-following-heading t)
8567 (org-show-siblings t)
8568 (org-show-hierarchy-above t)
8569 (org-show-entry-below t))
8570 (org-show-context))))
8572 (defun org-agenda-diary-entry ()
8573 "Make a diary entry, like the `i' command from the calendar.
8574 All the standard commands work: block, weekly etc.
8575 When `org-agenda-diary-file' points to a file,
8576 `org-agenda-diary-entry-in-org-file' is called instead to create
8577 entries in that Org-mode file."
8578 (interactive)
8579 (org-agenda-check-type t 'agenda 'timeline)
8580 (if (not (eq org-agenda-diary-file 'diary-file))
8581 (org-agenda-diary-entry-in-org-file)
8582 (require 'diary-lib)
8583 (let* ((char (progn
8584 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8585 (read-char-exclusive)))
8586 (cmd (cdr (assoc char
8587 '((?d . insert-diary-entry)
8588 (?w . insert-weekly-diary-entry)
8589 (?m . insert-monthly-diary-entry)
8590 (?y . insert-yearly-diary-entry)
8591 (?a . insert-anniversary-diary-entry)
8592 (?b . insert-block-diary-entry)
8593 (?c . insert-cyclic-diary-entry)))))
8594 (oldf (symbol-function 'calendar-cursor-to-date))
8595 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8596 (point (point))
8597 (mark (or (mark t) (point))))
8598 (unless cmd
8599 (error "No command associated with <%c>" char))
8600 (unless (and (get-text-property point 'day)
8601 (or (not (equal ?b char))
8602 (get-text-property mark 'day)))
8603 (error "Don't know which date to use for diary entry"))
8604 ;; We implement this by hacking the `calendar-cursor-to-date' function
8605 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8606 (let ((calendar-mark-ring
8607 (list (calendar-gregorian-from-absolute
8608 (or (get-text-property mark 'day)
8609 (get-text-property point 'day))))))
8610 (unwind-protect
8611 (progn
8612 (fset 'calendar-cursor-to-date
8613 (lambda (&optional error dummy)
8614 (calendar-gregorian-from-absolute
8615 (get-text-property point 'day))))
8616 (call-interactively cmd))
8617 (fset 'calendar-cursor-to-date oldf))))))
8619 (defun org-agenda-execute-calendar-command (cmd)
8620 "Execute a calendar command from the agenda, with the date associated to
8621 the cursor position."
8622 (org-agenda-check-type t 'agenda 'timeline)
8623 (require 'diary-lib)
8624 (unless (get-text-property (point) 'day)
8625 (error "Don't know which date to use for calendar command"))
8626 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8627 (point (point))
8628 (date (calendar-gregorian-from-absolute
8629 (get-text-property point 'day)))
8630 ;; the following 2 vars are needed in the calendar
8631 (displayed-month (car date))
8632 (displayed-year (nth 2 date)))
8633 (unwind-protect
8634 (progn
8635 (fset 'calendar-cursor-to-date
8636 (lambda (&optional error dummy)
8637 (calendar-gregorian-from-absolute
8638 (get-text-property point 'day))))
8639 (call-interactively cmd))
8640 (fset 'calendar-cursor-to-date oldf))))
8642 (defun org-agenda-phases-of-moon ()
8643 "Display the phases of the moon for the 3 months around the cursor date."
8644 (interactive)
8645 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8647 (defun org-agenda-holidays ()
8648 "Display the holidays for the 3 months around the cursor date."
8649 (interactive)
8650 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8652 (defvar calendar-longitude)
8653 (defvar calendar-latitude)
8654 (defvar calendar-location-name)
8656 (defun org-agenda-sunrise-sunset (arg)
8657 "Display sunrise and sunset for the cursor date.
8658 Latitude and longitude can be specified with the variables
8659 `calendar-latitude' and `calendar-longitude'. When called with prefix
8660 argument, latitude and longitude will be prompted for."
8661 (interactive "P")
8662 (require 'solar)
8663 (let ((calendar-longitude (if arg nil calendar-longitude))
8664 (calendar-latitude (if arg nil calendar-latitude))
8665 (calendar-location-name
8666 (if arg "the given coordinates" calendar-location-name)))
8667 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8669 (defun org-agenda-goto-calendar ()
8670 "Open the Emacs calendar with the date at the cursor."
8671 (interactive)
8672 (org-agenda-check-type t 'agenda 'timeline)
8673 (let* ((day (or (get-text-property (point) 'day)
8674 (error "Don't know which date to open in calendar")))
8675 (date (calendar-gregorian-from-absolute day))
8676 (calendar-move-hook nil)
8677 (calendar-view-holidays-initially-flag nil)
8678 (calendar-view-diary-initially-flag nil))
8679 (calendar)
8680 (calendar-goto-date date)))
8682 ;;;###autoload
8683 (defun org-calendar-goto-agenda ()
8684 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8685 This is a command that has to be installed in `calendar-mode-map'."
8686 (interactive)
8687 (org-agenda-list nil (calendar-absolute-from-gregorian
8688 (calendar-cursor-to-date))
8689 nil))
8691 (defun org-agenda-convert-date ()
8692 (interactive)
8693 (org-agenda-check-type t 'agenda 'timeline)
8694 (let ((day (get-text-property (point) 'day))
8695 date s)
8696 (unless day
8697 (error "Don't know which date to convert"))
8698 (setq date (calendar-gregorian-from-absolute day))
8699 (setq s (concat
8700 "Gregorian: " (calendar-date-string date) "\n"
8701 "ISO: " (calendar-iso-date-string date) "\n"
8702 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8703 "Julian: " (calendar-julian-date-string date) "\n"
8704 "Astron. JD: " (calendar-astro-date-string date)
8705 " (Julian date number at noon UTC)\n"
8706 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8707 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8708 "French: " (calendar-french-date-string date) "\n"
8709 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8710 "Mayan: " (calendar-mayan-date-string date) "\n"
8711 "Coptic: " (calendar-coptic-date-string date) "\n"
8712 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8713 "Persian: " (calendar-persian-date-string date) "\n"
8714 "Chinese: " (calendar-chinese-date-string date) "\n"))
8715 (with-output-to-temp-buffer "*Dates*"
8716 (princ s))
8717 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8719 ;;; Bulk commands
8721 (defvar org-agenda-bulk-marked-entries nil
8722 "List of markers that refer to marked entries in the agenda.")
8724 (defun org-agenda-bulk-marked-p ()
8725 (eq (get-char-property (point-at-bol) 'type)
8726 'org-marked-entry-overlay))
8728 (defun org-agenda-bulk-mark (&optional arg)
8729 "Mark the entry at point for future bulk action."
8730 (interactive "p")
8731 (dotimes (i (or arg 1))
8732 (unless (org-get-at-bol 'org-agenda-diary-link)
8733 (let* ((m (org-get-at-bol 'org-hd-marker))
8735 (unless (org-agenda-bulk-marked-p)
8736 (unless m (error "Nothing to mark at point"))
8737 (push m org-agenda-bulk-marked-entries)
8738 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8739 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8740 (org-get-todo-face "TODO")
8741 'evaporate)
8742 (overlay-put ov 'type 'org-marked-entry-overlay))
8743 (beginning-of-line 2)
8744 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8745 (beginning-of-line 2))
8746 (message "%d entries marked for bulk action"
8747 (length org-agenda-bulk-marked-entries))))))
8749 (defun org-agenda-bulk-mark-all ()
8750 "Mark all entries for future agenda bulk action."
8751 (interactive)
8752 (org-agenda-bulk-mark-regexp "."))
8754 (defun org-agenda-bulk-mark-regexp (regexp)
8755 "Mark entries matching REGEXP for future agenda bulk action."
8756 (interactive "sMark entries matching regexp: ")
8757 (let ((entries-marked 0))
8758 (save-excursion
8759 (goto-char (point-min))
8760 (goto-char (next-single-property-change (point) 'txt))
8761 (while (re-search-forward regexp nil t)
8762 (when (string-match regexp (get-text-property (point) 'txt))
8763 (setq entries-marked (1+ entries-marked))
8764 (call-interactively 'org-agenda-bulk-mark))))
8765 (if (not entries-marked)
8766 (message "No entry matching this regexp."))))
8768 (defun org-agenda-bulk-unmark (&optional arg)
8769 "Unmark the entry at point for future bulk action."
8770 (interactive "P")
8771 (if arg
8772 (org-agenda-bulk-unmark-all)
8773 (cond ((org-agenda-bulk-marked-p)
8774 (org-agenda-bulk-remove-overlays
8775 (point-at-bol) (+ 2 (point-at-bol)))
8776 (setq org-agenda-bulk-marked-entries
8777 (delete (org-get-at-bol 'org-hd-marker)
8778 org-agenda-bulk-marked-entries))
8779 (beginning-of-line 2)
8780 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8781 (beginning-of-line 2))
8782 (message "%d entries left marked for bulk action"
8783 (length org-agenda-bulk-marked-entries)))
8784 (t (message "No entry to unmark here")))))
8786 (defun org-agenda-bulk-toggle ()
8787 "Toggle marking the entry at point for bulk action."
8788 (interactive)
8789 (if (org-agenda-bulk-marked-p)
8790 (org-agenda-bulk-unmark)
8791 (org-agenda-bulk-mark)))
8793 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8794 "Remove the mark overlays between BEG and END in the agenda buffer.
8795 BEG and END default to the buffer limits.
8797 This only removes the overlays, it does not remove the markers
8798 from the list in `org-agenda-bulk-marked-entries'."
8799 (interactive)
8800 (mapc (lambda (ov)
8801 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8802 (delete-overlay ov)))
8803 (overlays-in (or beg (point-min)) (or end (point-max)))))
8805 (defun org-agenda-bulk-unmark-all ()
8806 "Remove all marks in the agenda buffer.
8807 This will remove the markers and the overlays."
8808 (interactive)
8809 (if (null org-agenda-bulk-marked-entries)
8810 (message "No entry to unmark")
8811 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8812 (setq org-agenda-bulk-marked-entries nil)
8813 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8815 (defcustom org-agenda-persistent-marks nil
8816 "Non-nil means marked items will stay marked after a bulk action.
8817 You can toggle this interactively by typing `p' when prompted for a
8818 bulk action."
8819 :group 'org-agenda
8820 :version "24.1"
8821 :type 'boolean)
8823 (defun org-agenda-bulk-action (&optional arg)
8824 "Execute an remote-editing action on all marked entries.
8825 The prefix arg is passed through to the command if possible."
8826 (interactive "P")
8827 ;; Make sure we have markers, and only valid ones
8828 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8829 (mapc
8830 (lambda (m)
8831 (unless (and (markerp m)
8832 (marker-buffer m)
8833 (buffer-live-p (marker-buffer m))
8834 (marker-position m))
8835 (error "Marker %s for bulk command is invalid" m)))
8836 org-agenda-bulk-marked-entries)
8838 ;; Prompt for the bulk command
8839 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8840 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8841 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8842 (when org-agenda-bulk-custom-functions
8843 (concat " Custom: ["
8844 (mapconcat (lambda(f) (char-to-string (car f)))
8845 org-agenda-bulk-custom-functions "")
8846 "]"))))
8847 (catch 'exit
8848 (let* ((action (read-char-exclusive))
8849 (org-log-refile (if org-log-refile 'time nil))
8850 (entries (reverse org-agenda-bulk-marked-entries))
8851 redo-at-end
8852 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8853 (cond
8854 ((equal action ?p)
8855 (let ((org-agenda-persistent-marks
8856 (not org-agenda-persistent-marks)))
8857 (org-agenda-bulk-action)
8858 (throw 'exit nil)))
8860 ((equal action ?$)
8861 (setq cmd '(org-agenda-archive)))
8863 ((equal action ?A)
8864 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8866 ((member action '(?r ?w))
8867 (setq rfloc (org-refile-get-location
8868 "Refile to"
8869 (marker-buffer (car org-agenda-bulk-marked-entries))
8870 org-refile-allow-creating-parent-nodes))
8871 (if (nth 3 rfloc)
8872 (setcar (nthcdr 3 rfloc)
8873 (move-marker (make-marker) (nth 3 rfloc)
8874 (or (get-file-buffer (nth 1 rfloc))
8875 (find-buffer-visiting (nth 1 rfloc))
8876 (error "This should not happen")))))
8878 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8879 redo-at-end t))
8881 ((equal action ?t)
8882 (setq state (org-icompleting-read
8883 "Todo state: "
8884 (with-current-buffer (marker-buffer (car entries))
8885 (mapcar 'list org-todo-keywords-1))))
8886 (setq cmd `(let ((org-inhibit-blocking t)
8887 (org-inhibit-logging 'note))
8888 (org-agenda-todo ,state))))
8890 ((memq action '(?- ?+))
8891 (setq tag (org-icompleting-read
8892 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8893 (with-current-buffer (marker-buffer (car entries))
8894 (delq nil
8895 (mapcar (lambda (x)
8896 (if (stringp (car x)) x)) org-tag-alist)))))
8897 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8899 ((memq action '(?s ?d))
8900 (let* ((date (unless arg
8901 (org-read-date
8902 nil nil nil
8903 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8904 (ans (if arg nil org-read-date-final-answer))
8905 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8906 (setq cmd `(let* ((bound (fboundp 'read-string))
8907 (old (and bound (symbol-function 'read-string))))
8908 (unwind-protect
8909 (progn
8910 (fset 'read-string (lambda (&rest ignore) ,ans))
8911 (eval '(,c1 arg)))
8912 (if bound
8913 (fset 'read-string old)
8914 (fmakunbound 'read-string)))))))
8916 ((equal action ?S)
8917 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8918 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8919 (let ((days (read-number
8920 (format "Scatter tasks across how many %sdays: "
8921 (if arg "week" "")) 7)))
8922 (setq cmd
8923 `(let ((distance (1+ (random ,days))))
8924 (if arg
8925 (let ((dist distance)
8926 (day-of-week
8927 (calendar-day-of-week
8928 (calendar-gregorian-from-absolute (org-today)))))
8929 (dotimes (i (1+ dist))
8930 (while (member day-of-week org-agenda-weekend-days)
8931 (incf distance)
8932 (incf day-of-week)
8933 (if (= day-of-week 7)
8934 (setq day-of-week 0)))
8935 (incf day-of-week)
8936 (if (= day-of-week 7)
8937 (setq day-of-week 0)))))
8938 ;; silently fail when try to replan a sexp entry
8939 (condition-case nil
8940 (let* ((date (calendar-gregorian-from-absolute
8941 (+ (org-today) distance)))
8942 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8943 (nth 2 date))))
8944 (org-agenda-schedule nil time))
8945 (error nil)))))))
8947 ((assoc action org-agenda-bulk-custom-functions)
8948 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8949 redo-at-end t))
8951 ((equal action ?f)
8952 (setq cmd (list (intern
8953 (org-icompleting-read "Function: "
8954 obarray 'fboundp t nil nil)))))
8956 (t (error "Invalid bulk action")))
8958 ;; Sort the markers, to make sure that parents are handled before children
8959 (setq entries (sort entries
8960 (lambda (a b)
8961 (cond
8962 ((equal (marker-buffer a) (marker-buffer b))
8963 (< (marker-position a) (marker-position b)))
8965 (string< (buffer-name (marker-buffer a))
8966 (buffer-name (marker-buffer b))))))))
8968 ;; Now loop over all markers and apply cmd
8969 (while (setq e (pop entries))
8970 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8971 (if (not pos)
8972 (progn (message "Skipping removed entry at %s" e)
8973 (setq cntskip (1+ cntskip)))
8974 (goto-char pos)
8975 (let (org-loop-over-headlines-in-active-region)
8976 (eval cmd))
8977 (when (not org-agenda-persistent-marks)
8978 (setq org-agenda-bulk-marked-entries
8979 (delete e org-agenda-bulk-marked-entries)))
8980 (setq cnt (1+ cnt))))
8981 (when (not org-agenda-persistent-marks)
8982 (org-agenda-bulk-unmark-all))
8983 (when redo-at-end (org-agenda-redo))
8984 (message "Acted on %d entries%s%s"
8986 (if (= cntskip 0)
8988 (format ", skipped %d (disappeared before their turn)"
8989 cntskip))
8990 (if (not org-agenda-persistent-marks)
8991 "" " (kept marked)"))))))
8993 ;;; Flagging notes
8995 (defun org-agenda-show-the-flagging-note ()
8996 "Display the flagging note in the other window.
8997 When called a second time in direct sequence, offer to remove the FLAGGING
8998 tag and (if present) the flagging note."
8999 (interactive)
9000 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9001 (win (selected-window))
9002 note heading newhead)
9003 (unless hdmarker
9004 (error "No linked entry at point"))
9005 (if (and (eq this-command last-command)
9006 (y-or-n-p "Unflag and remove any flagging note? "))
9007 (progn
9008 (org-agenda-remove-flag hdmarker)
9009 (let ((win (get-buffer-window "*Flagging Note*")))
9010 (and win (delete-window win)))
9011 (message "Entry unflagged"))
9012 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9013 (unless note
9014 (error "No flagging note"))
9015 (org-kill-new note)
9016 (org-switch-to-buffer-other-window "*Flagging Note*")
9017 (erase-buffer)
9018 (insert note)
9019 (goto-char (point-min))
9020 (while (re-search-forward "\\\\n" nil t)
9021 (replace-match "\n" t t))
9022 (goto-char (point-min))
9023 (select-window win)
9024 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9026 (defun org-agenda-remove-flag (marker)
9027 "Remove the FLAGGED tag and any flagging note in the entry."
9028 (let (newhead)
9029 (org-with-point-at marker
9030 (org-toggle-tag "FLAGGED" 'off)
9031 (org-entry-delete nil "THEFLAGGINGNOTE")
9032 (setq newhead (org-get-heading)))
9033 (org-agenda-change-all-lines newhead marker)
9034 (message "Entry unflagged")))
9036 (defun org-agenda-get-any-marker (&optional pos)
9037 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9038 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9040 ;;; Appointment reminders
9042 (defvar appt-time-msg-list)
9044 ;;;###autoload
9045 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9046 "Activate appointments found in `org-agenda-files'.
9047 With a \\[universal-argument] prefix, refresh the list of
9048 appointments.
9050 If FILTER is t, interactively prompt the user for a regular
9051 expression, and filter out entries that don't match it.
9053 If FILTER is a string, use this string as a regular expression
9054 for filtering entries out.
9056 If FILTER is a function, filter out entries against which
9057 calling the function returns nil. This function takes one
9058 argument: an entry from `org-agenda-get-day-entries'.
9060 FILTER can also be an alist with the car of each cell being
9061 either 'headline or 'category. For example:
9063 '((headline \"IMPORTANT\")
9064 (category \"Work\"))
9066 will only add headlines containing IMPORTANT or headlines
9067 belonging to the \"Work\" category.
9069 ARGS are symbols indicating what kind of entries to consider.
9070 By default `org-agenda-to-appt' will use :deadline, :scheduled
9071 and :timestamp entries. See the docstring of `org-diary' for
9072 details and examples.
9074 If an entry as a APPT_WARNTIME property, its value will be used
9075 to override `appt-message-warning-time'."
9076 (interactive "P")
9077 (if refresh (setq appt-time-msg-list nil))
9078 (if (eq filter t)
9079 (setq filter (read-from-minibuffer "Regexp filter: ")))
9080 (let* ((cnt 0) ; count added events
9081 (scope (or args '(:deadline :scheduled :timestamp)))
9082 (org-agenda-new-buffers nil)
9083 (org-deadline-warning-days 0)
9084 ;; Do not use `org-today' here because appt only takes
9085 ;; time and without date as argument, so it may pass wrong
9086 ;; information otherwise
9087 (today (org-date-to-gregorian
9088 (time-to-days (current-time))))
9089 (org-agenda-restrict nil)
9090 (files (org-agenda-files 'unrestricted)) entries file
9091 (org-agenda-buffer nil))
9092 ;; Get all entries which may contain an appt
9093 (org-prepare-agenda-buffers files)
9094 (while (setq file (pop files))
9095 (setq entries
9096 (delq nil
9097 (append entries
9098 (apply 'org-agenda-get-day-entries
9099 file today scope)))))
9100 ;; Map thru entries and find if we should filter them out
9101 (mapc
9102 (lambda(x)
9103 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9104 (cat (get-text-property 1 'org-category x))
9105 (tod (get-text-property 1 'time-of-day x))
9106 (ok (or (null filter)
9107 (and (stringp filter) (string-match filter evt))
9108 (and (functionp filter) (funcall filter x))
9109 (and (listp filter)
9110 (let ((cat-filter (cadr (assoc 'category filter)))
9111 (evt-filter (cadr (assoc 'headline filter))))
9112 (or (and (stringp cat-filter)
9113 (string-match cat-filter cat))
9114 (and (stringp evt-filter)
9115 (string-match evt-filter evt)))))))
9116 (wrn (get-text-property 1 'warntime x)))
9117 ;; FIXME: Shall we remove text-properties for the appt text?
9118 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9119 (when (and ok tod)
9120 (setq tod (concat "00" (number-to-string tod))
9121 tod (when (string-match
9122 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9123 (concat (match-string 1 tod) ":"
9124 (match-string 2 tod))))
9125 (if (version< emacs-version "23.3")
9126 (appt-add tod evt)
9127 (appt-add tod evt wrn))
9128 (setq cnt (1+ cnt))))) entries)
9129 (org-release-buffers org-agenda-new-buffers)
9130 (if (eq cnt 0)
9131 (message "No event to add")
9132 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9134 (defun org-agenda-todayp (date)
9135 "Does DATE mean today, when considering `org-extend-today-until'?"
9136 (let ((today (org-today))
9137 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9138 date)))
9139 (eq date today)))
9141 (defun org-agenda-todo-yesterday (&optional arg)
9142 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9143 (interactive "P")
9144 (let* ((hour (third (decode-time
9145 (org-current-time))))
9146 (org-extend-today-until (1+ hour)))
9147 (org-agenda-todo arg)))
9149 (provide 'org-agenda)
9151 ;;; org-agenda.el ends here