org-babel: store noweb-expanded code body in 'info' data structure
[rgr-org-mode.git] / lisp / org-agenda.el
blob5f193c622a68a04ccf53b77981b1dfc12f999a2c
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 6.32trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl)
36 (require 'calendar))
38 (declare-function diary-add-to-list "diary-lib"
39 (date string specifier &optional marker globcolor literal))
40 (declare-function calendar-absolute-from-iso "cal-iso" (date))
41 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
42 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
43 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
44 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
46 (declare-function calendar-french-date-string "cal-french" (&optional date))
47 (declare-function calendar-goto-date "cal-move" (date))
48 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
49 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
50 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
51 (declare-function calendar-iso-from-absolute "cal-iso" (date))
52 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
53 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
54 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
55 (declare-function org-columns-quit "org-colview" ())
56 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
57 (declare-function org-habit-insert-consistency-graphs
58 "org-habit" (&optional line))
59 (declare-function org-is-habit-p "org-habit" (&optional pom))
60 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
61 (declare-function org-habit-get-priority "org-habit" (habit))
62 (defvar calendar-mode-map)
63 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
64 (defvar org-habit-show-habits)
65 (defvar org-habit-show-habits-only-for-today)
67 ;; Defined somewhere in this file, but used before definition.
68 (defvar org-agenda-buffer-name)
69 (defvar org-agenda-overriding-header)
70 (defvar org-agenda-title-append nil)
71 (defvar entry)
72 (defvar date)
73 (defvar org-agenda-undo-list)
74 (defvar org-agenda-pending-undo-list)
75 (defvar original-date) ; dynamically scoped, calendar.el does scope this
77 (defcustom org-agenda-confirm-kill 1
78 "When set, remote killing from the agenda buffer needs confirmation.
79 When t, a confirmation is always needed. When a number N, confirmation is
80 only needed when the text to be killed contains more than N non-white lines."
81 :group 'org-agenda
82 :type '(choice
83 (const :tag "Never" nil)
84 (const :tag "Always" t)
85 (integer :tag "When more than N lines")))
87 (defcustom org-agenda-compact-blocks nil
88 "Non-nil means, make the block agenda more compact.
89 This is done by leaving out unnecessary lines."
90 :group 'org-agenda
91 :type 'boolean)
93 (defcustom org-agenda-block-separator ?=
94 "The separator between blocks in the agenda.
95 If this is a string, it will be used as the separator, with a newline added.
96 If it is a character, it will be repeated to fill the window width."
97 :group 'org-agenda
98 :type '(choice
99 (character)
100 (string)))
102 (defgroup org-agenda-export nil
103 "Options concerning exporting agenda views in Org-mode."
104 :tag "Org Agenda Export"
105 :group 'org-agenda)
107 (defcustom org-agenda-with-colors t
108 "Non-nil means, use colors in agenda views."
109 :group 'org-agenda-export
110 :type 'boolean)
112 (defcustom org-agenda-exporter-settings nil
113 "Alist of variable/value pairs that should be active during agenda export.
114 This is a good place to set options for ps-print and for htmlize.
115 Note that the way this is implemented, the values will be evaluated
116 before assigned to the variables. So make sure to quote values you do
117 *not* want evaluated, for example
119 (setq org-agenda-exporter-settings
120 '((ps-print-color-p 'black-white)))"
121 :group 'org-agenda-export
122 :type '(repeat
123 (list
124 (variable)
125 (sexp :tag "Value"))))
127 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
128 "Hook run in temporary buffer before writing it to an export file.
129 A useful function is `org-agenda-add-entry-text'."
130 :group 'org-agenda-export
131 :type 'hook
132 :options '(org-agenda-add-entry-text))
134 (defcustom org-agenda-add-entry-text-maxlines 0
135 "Maximum number of entry text lines to be added to agenda.
136 This is only relevant when `org-agenda-add-entry-text' is part of
137 `org-agenda-before-write-hook', which it is by default.
138 When this is 0, nothing will happen. When it is greater than 0, it
139 specifies the maximum number of lines that will be added for each entry
140 that is listed in the agenda view.
142 Note that this variable is not used during display, only when exporting
143 the agenda. For agenda display, see org-agenda-entry-text-mode and the
144 variable `org-agenda-entry-text-maxlines'."
145 :group 'org-agenda
146 :type 'integer)
148 (defcustom org-agenda-add-entry-text-descriptive-links t
149 "Non-nil means, export org-links as descriptive links in agenda added text.
150 This variable applies to the text added to the agenda when
151 `org-agenda-add-entry-text-maxlines' is larger than 0.
152 When this variable nil, the URL will (also) be shown."
153 :group 'org-agenda
154 :type 'boolean)
156 (defcustom org-agenda-export-html-style ""
157 "The style specification for exported HTML Agenda files.
158 If this variable contains a string, it will replace the default <style>
159 section as produced by `htmlize'.
160 Since there are different ways of setting style information, this variable
161 needs to contain the full HTML structure to provide a style, including the
162 surrounding HTML tags. The style specifications should include definitions
163 the fonts used by the agenda, here is an example:
165 <style type=\"text/css\">
166 p { font-weight: normal; color: gray; }
167 .org-agenda-structure {
168 font-size: 110%;
169 color: #003399;
170 font-weight: 600;
172 .org-todo {
173 color: #cc6666;
174 font-weight: bold;
176 .org-agenda-done {
177 color: #339933;
179 .org-done {
180 color: #339933;
182 .title { text-align: center; }
183 .todo, .deadline { color: red; }
184 .done { color: green; }
185 </style>
187 or, if you want to keep the style in a file,
189 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
191 As the value of this option simply gets inserted into the HTML <head> header,
192 you can \"misuse\" it to also add other text to the header. However,
193 <style>...</style> is required, if not present the variable will be ignored."
194 :group 'org-agenda-export
195 :group 'org-export-html
196 :type 'string)
198 (defgroup org-agenda-custom-commands nil
199 "Options concerning agenda views in Org-mode."
200 :tag "Org Agenda Custom Commands"
201 :group 'org-agenda)
203 (defconst org-sorting-choice
204 '(choice
205 (const time-up) (const time-down)
206 (const category-keep) (const category-up) (const category-down)
207 (const tag-down) (const tag-up)
208 (const priority-up) (const priority-down)
209 (const todo-state-up) (const todo-state-down)
210 (const effort-up) (const effort-down)
211 (const habit-up) (const habit-down)
212 (const user-defined-up) (const user-defined-down))
213 "Sorting choices.")
215 (defconst org-agenda-custom-commands-local-options
216 `(repeat :tag "Local settings for this command. Remember to quote values"
217 (choice :tag "Setting"
218 (list :tag "Heading for this block"
219 (const org-agenda-overriding-header)
220 (string :tag "Headline"))
221 (list :tag "Files to be searched"
222 (const org-agenda-files)
223 (list
224 (const :format "" quote)
225 (repeat (file))))
226 (list :tag "Sorting strategy"
227 (const org-agenda-sorting-strategy)
228 (list
229 (const :format "" quote)
230 (repeat
231 ,org-sorting-choice)))
232 (list :tag "Prefix format"
233 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
234 (string))
235 (list :tag "Number of days in agenda"
236 (const org-agenda-ndays)
237 (integer :value 1))
238 (list :tag "Fixed starting date"
239 (const org-agenda-start-day)
240 (string :value "2007-11-01"))
241 (list :tag "Start on day of week"
242 (const org-agenda-start-on-weekday)
243 (choice :value 1
244 (const :tag "Today" nil)
245 (integer :tag "Weekday No.")))
246 (list :tag "Include data from diary"
247 (const org-agenda-include-diary)
248 (boolean))
249 (list :tag "Deadline Warning days"
250 (const org-deadline-warning-days)
251 (integer :value 1))
252 (list :tag "Tags filter preset"
253 (const org-agenda-filter-preset)
254 (list
255 (const :format "" quote)
256 (repeat
257 (string :tag "+tag or -tag"))))
258 (list :tag "Standard skipping condition"
259 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
260 (const org-agenda-skip-function)
261 (list
262 (const :format "" quote)
263 (list
264 (choice
265 :tag "Skipping range"
266 (const :tag "Skip entry" org-agenda-skip-entry-if)
267 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
268 (repeat :inline t :tag "Conditions for skipping"
269 (choice
270 :tag "Condition type"
271 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
272 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
273 (const :tag "scheduled" 'scheduled)
274 (const :tag "not scheduled" 'notscheduled)
275 (const :tag "deadline" 'deadline)
276 (const :tag "no deadline" 'notdeadline)
277 (const :tag "timestamp" 'timestamp)
278 (const :tag "no timestamp" 'nottimestamp))))))
279 (list :tag "Non-standard skipping condition"
280 :value (org-agenda-skip-function)
281 (const org-agenda-skip-function)
282 (sexp :tag "Function or form (quoted!)"))
283 (list :tag "Any variable"
284 (variable :tag "Variable")
285 (sexp :tag "Value (sexp)"))))
286 "Selection of examples for agenda command settings.
287 This will be spliced into the custom type of
288 `org-agenda-custom-commands'.")
291 (defcustom org-agenda-custom-commands nil
292 "Custom commands for the agenda.
293 These commands will be offered on the splash screen displayed by the
294 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
296 (key desc type match settings files)
298 key The key (one or more characters as a string) to be associated
299 with the command.
300 desc A description of the command, when omitted or nil, a default
301 description is built using MATCH.
302 type The command type, any of the following symbols:
303 agenda The daily/weekly agenda.
304 todo Entries with a specific TODO keyword, in all agenda files.
305 search Entries containing search words entry or headline.
306 tags Tags/Property/TODO match in all agenda files.
307 tags-todo Tags/P/T match in all agenda files, TODO entries only.
308 todo-tree Sparse tree of specific TODO keyword in *current* file.
309 tags-tree Sparse tree with all tags matches in *current* file.
310 occur-tree Occur sparse tree for *current* file.
311 ... A user-defined function.
312 match What to search for:
313 - a single keyword for TODO keyword searches
314 - a tags match expression for tags searches
315 - a word search expression for text searches.
316 - a regular expression for occur searches
317 For all other commands, this should be the empty string.
318 settings A list of option settings, similar to that in a let form, so like
319 this: ((opt1 val1) (opt2 val2) ...). The values will be
320 evaluated at the moment of execution, so quote them when needed.
321 files A list of files file to write the produced agenda buffer to
322 with the command `org-store-agenda-views'.
323 If a file name ends in \".html\", an HTML version of the buffer
324 is written out. If it ends in \".ps\", a postscript version is
325 produced. Otherwise, only the plain text is written to the file.
327 You can also define a set of commands, to create a composite agenda buffer.
328 In this case, an entry looks like this:
330 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
332 where
334 desc A description string to be displayed in the dispatcher menu.
335 cmd An agenda command, similar to the above. However, tree commands
336 are no allowed, but instead you can get agenda and global todo list.
337 So valid commands for a set are:
338 (agenda \"\" settings)
339 (alltodo \"\" settings)
340 (stuck \"\" settings)
341 (todo \"match\" settings files)
342 (search \"match\" settings files)
343 (tags \"match\" settings files)
344 (tags-todo \"match\" settings files)
346 Each command can carry a list of options, and another set of options can be
347 given for the whole set of commands. Individual command options take
348 precedence over the general options.
350 When using several characters as key to a command, the first characters
351 are prefix commands. For the dispatcher to display useful information, you
352 should provide a description for the prefix, like
354 (setq org-agenda-custom-commands
355 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
356 (\"hl\" tags \"+HOME+Lisa\")
357 (\"hp\" tags \"+HOME+Peter\")
358 (\"hk\" tags \"+HOME+Kim\")))"
359 :group 'org-agenda-custom-commands
360 :type `(repeat
361 (choice :value ("x" "Describe command here" tags "" nil)
362 (list :tag "Single command"
363 (string :tag "Access Key(s) ")
364 (option (string :tag "Description"))
365 (choice
366 (const :tag "Agenda" agenda)
367 (const :tag "TODO list" alltodo)
368 (const :tag "Search words" search)
369 (const :tag "Stuck projects" stuck)
370 (const :tag "Tags/Property match (all agenda files)" tags)
371 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
372 (const :tag "TODO keyword search (all agenda files)" todo)
373 (const :tag "Tags sparse tree (current buffer)" tags-tree)
374 (const :tag "TODO keyword tree (current buffer)" todo-tree)
375 (const :tag "Occur tree (current buffer)" occur-tree)
376 (sexp :tag "Other, user-defined function"))
377 (string :tag "Match (only for some commands)")
378 ,org-agenda-custom-commands-local-options
379 (option (repeat :tag "Export" (file :tag "Export to"))))
380 (list :tag "Command series, all agenda files"
381 (string :tag "Access Key(s)")
382 (string :tag "Description ")
383 (repeat :tag "Component"
384 (choice
385 (list :tag "Agenda"
386 (const :format "" agenda)
387 (const :tag "" :format "" "")
388 ,org-agenda-custom-commands-local-options)
389 (list :tag "TODO list (all keywords)"
390 (const :format "" alltodo)
391 (const :tag "" :format "" "")
392 ,org-agenda-custom-commands-local-options)
393 (list :tag "Search words"
394 (const :format "" search)
395 (string :tag "Match")
396 ,org-agenda-custom-commands-local-options)
397 (list :tag "Stuck projects"
398 (const :format "" stuck)
399 (const :tag "" :format "" "")
400 ,org-agenda-custom-commands-local-options)
401 (list :tag "Tags search"
402 (const :format "" tags)
403 (string :tag "Match")
404 ,org-agenda-custom-commands-local-options)
405 (list :tag "Tags search, TODO entries only"
406 (const :format "" tags-todo)
407 (string :tag "Match")
408 ,org-agenda-custom-commands-local-options)
409 (list :tag "TODO keyword search"
410 (const :format "" todo)
411 (string :tag "Match")
412 ,org-agenda-custom-commands-local-options)
413 (list :tag "Other, user-defined function"
414 (symbol :tag "function")
415 (string :tag "Match")
416 ,org-agenda-custom-commands-local-options)))
418 (repeat :tag "Settings for entire command set"
419 (list (variable :tag "Any variable")
420 (sexp :tag "Value")))
421 (option (repeat :tag "Export" (file :tag "Export to"))))
422 (cons :tag "Prefix key documentation"
423 (string :tag "Access Key(s)")
424 (string :tag "Description ")))))
426 (defcustom org-agenda-query-register ?o
427 "The register holding the current query string.
428 The purpose of this is that if you construct a query string interactively,
429 you can then use it to define a custom command."
430 :group 'org-agenda-custom-commands
431 :type 'character)
433 (defcustom org-stuck-projects
434 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
435 "How to identify stuck projects.
436 This is a list of four items:
437 1. A tags/todo/property matcher string that is used to identify a project.
438 See the manual for a description of tag and property searches.
439 The entire tree below a headline matched by this is considered one project.
440 2. A list of TODO keywords identifying non-stuck projects.
441 If the project subtree contains any headline with one of these todo
442 keywords, the project is considered to be not stuck. If you specify
443 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
444 3. A list of tags identifying non-stuck projects.
445 If the project subtree contains any headline with one of these tags,
446 the project is considered to be not stuck. If you specify \"*\" as
447 a tag, any tag will mark the project unstuck. Note that this is about
448 the explicit presence of a tag somewhere in the subtree, inherited
449 tags to not count here. If inherited tags make a project not stuck,
450 use \"-TAG\" in the tags part of the matcher under (1.) above.
451 4. An arbitrary regular expression matching non-stuck projects.
453 If the project turns out to be not stuck, search continues also in the
454 subtree to see if any of the subtasks have project status.
456 See also the variable `org-tags-match-list-sublevels' which applies
457 to projects matched by this search as well.
459 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
460 or `C-c a #' to produce the list."
461 :group 'org-agenda-custom-commands
462 :type '(list
463 (string :tag "Tags/TODO match to identify a project")
464 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
465 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
466 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
468 (defcustom org-agenda-filter-effort-default-operator "<"
469 "The default operator for effort estimate filtering.
470 If you select an effort estimate limit without first pressing an operator,
471 this one will be used."
472 :group 'org-agenda-custom-commands
473 :type '(choice (const :tag "less or equal" "<")
474 (const :tag "greater or equal"">")
475 (const :tag "equal" "=")))
477 (defgroup org-agenda-skip nil
478 "Options concerning skipping parts of agenda files."
479 :tag "Org Agenda Skip"
480 :group 'org-agenda)
481 (defgroup org-agenda-daily/weekly nil
482 "Options concerning the daily/weekly agenda."
483 :tag "Org Agenda Daily/Weekly"
484 :group 'org-agenda)
485 (defgroup org-agenda-todo-list nil
486 "Options concerning the global todo list agenda view."
487 :tag "Org Agenda Todo List"
488 :group 'org-agenda)
489 (defgroup org-agenda-match-view nil
490 "Options concerning the general tags/property/todo match agenda view."
491 :tag "Org Agenda Match View"
492 :group 'org-agenda)
493 (defgroup org-agenda-search-view nil
494 "Options concerning the general tags/property/todo match agenda view."
495 :tag "Org Agenda Match View"
496 :group 'org-agenda)
498 (defvar org-agenda-archives-mode nil
499 "Non-nil means, the agenda will include archived items.
500 If this is the symbol `trees', trees in the selected agenda scope
501 that are marked with the ARCHIVE tag will be included anyway. When this is
502 t, also all archive files associated with the current selection of agenda
503 files will be included.")
505 (defcustom org-agenda-skip-comment-trees t
506 "Non-nil means, skip trees that start with the COMMENT keyword.
507 When nil, these trees are also scanned by agenda commands."
508 :group 'org-agenda-skip
509 :type 'boolean)
511 (defcustom org-agenda-todo-list-sublevels t
512 "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
513 When nil, the sublevels of a TODO entry are not checked, resulting in
514 potentially much shorter TODO lists."
515 :group 'org-agenda-skip
516 :group 'org-agenda-todo-list
517 :type 'boolean)
519 (defcustom org-agenda-todo-ignore-with-date nil
520 "Non-nil means, don't show entries with a date in the global todo list.
521 You can use this if you prefer to mark mere appointments with a TODO keyword,
522 but don't want them to show up in the TODO list.
523 When this is set, it also covers deadlines and scheduled items, the settings
524 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
525 will be ignored.
526 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
527 :group 'org-agenda-skip
528 :group 'org-agenda-todo-list
529 :type 'boolean)
531 (defcustom org-agenda-todo-ignore-scheduled nil
532 "Non-nil means, don't show scheduled entries in the global todo list.
533 The idea behind this is that by scheduling it, you have already taken care
534 of this item.
535 See also `org-agenda-todo-ignore-with-date'.
536 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
537 :group 'org-agenda-skip
538 :group 'org-agenda-todo-list
539 :type 'boolean)
541 (defcustom org-agenda-todo-ignore-deadlines nil
542 "Non-nil means, don't show near deadline entries in the global todo list.
543 Near means closer than `org-deadline-warning-days' days.
544 The idea behind this is that such items will appear in the agenda anyway.
545 See also `org-agenda-todo-ignore-with-date'.
546 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
547 :group 'org-agenda-skip
548 :group 'org-agenda-todo-list
549 :type 'boolean)
551 (defcustom org-agenda-tags-todo-honor-ignore-options nil
552 "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
553 The variables
554 `org-agenda-todo-ignore-with-date',
555 `org-agenda-todo-ignore-scheduled'
556 `org-agenda-todo-ignore-deadlines'
557 make the global TODO list skip entries that have time stamps of certain
558 kinds. If this option is set, the same options will also apply for the
559 tags-todo search, which is the general tags/property matcher
560 restricted to unfinished TODO entries only."
561 :group 'org-agenda-skip
562 :group 'org-agenda-todo-list
563 :group 'org-agenda-match-view
564 :type 'boolean)
566 (defcustom org-agenda-skip-scheduled-if-done nil
567 "Non-nil means don't show scheduled items in agenda when they are done.
568 This is relevant for the daily/weekly agenda, not for the TODO list. And
569 it applies only to the actual date of the scheduling. Warnings about
570 an item with a past scheduling dates are always turned off when the item
571 is DONE."
572 :group 'org-agenda-skip
573 :group 'org-agenda-daily/weekly
574 :type 'boolean)
576 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
577 "Non-nil means skip scheduling line if same entry shows because of deadline.
578 In the agenda of today, an entry can show up multiple times because
579 it is both scheduled and has a nearby deadline, and maybe a plain time
580 stamp as well.
581 When this variable is t, then only the deadline is shown and the fact that
582 the entry is scheduled today or was scheduled previously is not shown.
583 When this variable is nil, the entry will be shown several times. When
584 the variable is the symbol `not-today', then skip scheduled previously,
585 but not scheduled today."
586 :group 'org-agenda-skip
587 :group 'org-agenda-daily/weekly
588 :type '(choice
589 (const :tag "Never" nil)
590 (const :tag "Always" t)
591 (const :tag "Not when scheduled today" not-today)))
593 (defcustom org-agenda-skip-deadline-if-done nil
594 "Non-nil means don't show deadlines when the corresponding item is done.
595 When nil, the deadline is still shown and should give you a happy feeling.
596 This is relevant for the daily/weekly agenda. And it applied only to the
597 actually date of the deadline. Warnings about approaching and past-due
598 deadlines are always turned off when the item is DONE."
599 :group 'org-agenda-skip
600 :group 'org-agenda-daily/weekly
601 :type 'boolean)
603 (defcustom org-agenda-skip-additional-timestamps-same-entry t
604 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
605 When non-nil, after the search for timestamps has matched once in an
606 entry, the rest of the entry will not be searched."
607 :group 'org-agenda-skip
608 :type 'boolean)
610 (defcustom org-agenda-skip-timestamp-if-done nil
611 "Non-nil means don't select item by timestamp or -range if it is DONE."
612 :group 'org-agenda-skip
613 :group 'org-agenda-daily/weekly
614 :type 'boolean)
616 (defcustom org-agenda-dim-blocked-tasks t
617 "Non-nil means, dim blocked tasks in the agenda display.
618 This causes some overhead during agenda construction, but if you
619 have turned on `org-enforce-todo-dependencies',
620 `org-enforce-todo-checkbox-dependencies', or any other blocking
621 mechanism, this will create useful feedback in the agenda.
623 Instead ot t, this variable can also have the value `invisible'.
624 Then blocked tasks will be invisible and only become visible when
625 they become unblocked. An exemption to this behavior is when a task is
626 blocked because of unchecked checkboxes below it. Since checkboxes do
627 not show up in the agenda views, making this task invisible you remove any
628 trace from agenda views that there is something to do. Therefore, a task
629 that is blocked because of checkboxes will never be made invisible, it
630 will only be dimmed."
631 :group 'org-agenda-daily/weekly
632 :group 'org-agenda-todo-list
633 :type '(choice
634 (const :tag "Do not dim" nil)
635 (const :tag "Dim to a grey face" t)
636 (const :tag "Make invisibe" invisible)))
638 (defcustom org-timeline-show-empty-dates 3
639 "Non-nil means, `org-timeline' also shows dates without an entry.
640 When nil, only the days which actually have entries are shown.
641 When t, all days between the first and the last date are shown.
642 When an integer, show also empty dates, but if there is a gap of more than
643 N days, just insert a special line indicating the size of the gap."
644 :group 'org-agenda-skip
645 :type '(choice
646 (const :tag "None" nil)
647 (const :tag "All" t)
648 (integer :tag "at most")))
650 (defgroup org-agenda-startup nil
651 "Options concerning initial settings in the Agenda in Org Mode."
652 :tag "Org Agenda Startup"
653 :group 'org-agenda)
655 (defcustom org-finalize-agenda-hook nil
656 "Hook run just before displaying an agenda buffer."
657 :group 'org-agenda-startup
658 :type 'hook)
660 (defcustom org-agenda-mouse-1-follows-link nil
661 "Non-nil means, mouse-1 on a link will follow the link in the agenda.
662 A longer mouse click will still set point. Does not work on XEmacs.
663 Needs to be set before org.el is loaded."
664 :group 'org-agenda-startup
665 :type 'boolean)
667 (defcustom org-agenda-start-with-follow-mode nil
668 "The initial value of follow-mode in a newly created agenda window."
669 :group 'org-agenda-startup
670 :type 'boolean)
672 (defcustom org-agenda-start-with-entry-text-mode nil
673 "The initial value of entry-text-mode in a newly created agenda window."
674 :group 'org-agenda-startup
675 :type 'boolean)
677 (defcustom org-agenda-entry-text-maxlines 5
678 "Number of text lines to be added when `E' is presed in the agenda.
680 Note that this variable only used during agenda display. Add add entry text
681 when exporting the agenda, configure the variable
682 `org-agenda-add-entry-ext-maxlines'."
683 :group 'org-agenda
684 :type 'integer)
686 (defcustom org-agenda-entry-text-exclude-regexps nil
687 "List of regular expressions to clean up entry text.
688 The complete matches of all regular expressions in this list will be
689 removed from entry text before it is shown in the agenda."
690 :group 'org-agenda
691 :type '(repeat (regexp)))
693 (defvar org-agenda-entry-text-cleanup-hook nil
694 "Hook that is run after basic cleanup of entry text to be shown in agenda.
695 This cleanup is done in a temporary buffer, so the function may inspect and
696 change the entire buffer.
697 Some default stuff like drawers and scheduling/deadline dates will already
698 have been removed when this is called, as will any matches for regular
699 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
701 (defvar org-agenda-include-inactive-timestamps nil
702 "Non-nil means, include inactive time stamps in agenda and timeline.")
704 (defgroup org-agenda-windows nil
705 "Options concerning the windows used by the Agenda in Org Mode."
706 :tag "Org Agenda Windows"
707 :group 'org-agenda)
709 (defcustom org-agenda-window-setup 'reorganize-frame
710 "How the agenda buffer should be displayed.
711 Possible values for this option are:
713 current-window Show agenda in the current window, keeping all other windows.
714 other-window Use `switch-to-buffer-other-window' to display agenda.
715 reorganize-frame Show only two windows on the current frame, the current
716 window and the agenda.
717 other-frame Use `switch-to-buffer-other-frame' to display agenda.
718 Also, when exiting the agenda, kill that frame.
719 See also the variable `org-agenda-restore-windows-after-quit'."
720 :group 'org-agenda-windows
721 :type '(choice
722 (const current-window)
723 (const other-frame)
724 (const other-window)
725 (const reorganize-frame)))
727 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
728 "The min and max height of the agenda window as a fraction of frame height.
729 The value of the variable is a cons cell with two numbers between 0 and 1.
730 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
731 :group 'org-agenda-windows
732 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
734 (defcustom org-agenda-restore-windows-after-quit nil
735 "Non-nil means, restore window configuration open exiting agenda.
736 Before the window configuration is changed for displaying the agenda,
737 the current status is recorded. When the agenda is exited with
738 `q' or `x' and this option is set, the old state is restored. If
739 `org-agenda-window-setup' is `other-frame', the value of this
740 option will be ignored."
741 :group 'org-agenda-windows
742 :type 'boolean)
744 (defcustom org-agenda-ndays 7
745 "Number of days to include in overview display.
746 Should be 1 or 7.
747 Custom commands can set this variable in the options section."
748 :group 'org-agenda-daily/weekly
749 :type 'integer)
751 (defcustom org-agenda-start-on-weekday 1
752 "Non-nil means, start the overview always on the specified weekday.
753 0 denotes Sunday, 1 denotes Monday etc.
754 When nil, always start on the current day.
755 Custom commands can set this variable in the options section."
756 :group 'org-agenda-daily/weekly
757 :type '(choice (const :tag "Today" nil)
758 (integer :tag "Weekday No.")))
760 (defcustom org-agenda-show-all-dates t
761 "Non-nil means, `org-agenda' shows every day in the selected range.
762 When nil, only the days which actually have entries are shown."
763 :group 'org-agenda-daily/weekly
764 :type 'boolean)
766 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
767 "Format string for displaying dates in the agenda.
768 Used by the daily/weekly agenda and by the timeline. This should be
769 a format string understood by `format-time-string', or a function returning
770 the formatted date as a string. The function must take a single argument,
771 a calendar-style date list like (month day year)."
772 :group 'org-agenda-daily/weekly
773 :type '(choice
774 (string :tag "Format string")
775 (function :tag "Function")))
777 (defun org-agenda-format-date-aligned (date)
778 "Format a date string for display in the daily/weekly agenda, or timeline.
779 This function makes sure that dates are aligned for easy reading."
780 (require 'cal-iso)
781 (let* ((dayname (calendar-day-name date))
782 (day (cadr date))
783 (day-of-week (calendar-day-of-week date))
784 (month (car date))
785 (monthname (calendar-month-name month))
786 (year (nth 2 date))
787 (iso-week (org-days-to-iso-week
788 (calendar-absolute-from-gregorian date)))
789 (weekyear (cond ((and (= month 1) (>= iso-week 52))
790 (1- year))
791 ((and (= month 12) (<= iso-week 1))
792 (1+ year))
793 (t year)))
794 (weekstring (if (= day-of-week 1)
795 (format " W%02d" iso-week)
796 "")))
797 (format "%-10s %2d %s %4d%s"
798 dayname day monthname year weekstring)))
800 (defcustom org-agenda-weekend-days '(6 0)
801 "Which days are weekend?
802 These days get the special face `org-agenda-date-weekend' in the agenda
803 and timeline buffers."
804 :group 'org-agenda-daily/weekly
805 :type '(set :greedy t
806 (const :tag "Monday" 1)
807 (const :tag "Tuesday" 2)
808 (const :tag "Wednesday" 3)
809 (const :tag "Thursday" 4)
810 (const :tag "Friday" 5)
811 (const :tag "Saturday" 6)
812 (const :tag "Sunday" 0)))
814 (defcustom org-agenda-include-diary nil
815 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
816 Custom commands can set this variable in the options section."
817 :group 'org-agenda-daily/weekly
818 :type 'boolean)
820 (defcustom org-agenda-include-all-todo nil
821 "Set means weekly/daily agenda will always contain all TODO entries.
822 The TODO entries will be listed at the top of the agenda, before
823 the entries for specific days.
824 This option is deprecated, it is better to define a block agenda instead."
825 :group 'org-agenda-daily/weekly
826 :type 'boolean)
828 (defcustom org-agenda-repeating-timestamp-show-all t
829 "Non-nil means, show all occurrences of a repeating stamp in the agenda.
830 When nil, only one occurrence is shown, either today or the
831 nearest into the future."
832 :group 'org-agenda-daily/weekly
833 :type 'boolean)
835 (defcustom org-scheduled-past-days 10000
836 "No. of days to continue listing scheduled items that are not marked DONE.
837 When an item is scheduled on a date, it shows up in the agenda on this
838 day and will be listed until it is marked done for the number of days
839 given here."
840 :group 'org-agenda-daily/weekly
841 :type 'integer)
843 (defcustom org-agenda-log-mode-items '(closed clock)
844 "List of items that should be shown in agenda log mode.
845 This list may contain the following symbols:
847 closed Show entries that have been closed on that day.
848 clock Show entries that have received clocked time on that day.
849 state Show all logged state changes.
850 Note that instead of changing this variable, you can also press `C-u l' in
851 the agenda to display all available LOG items temporarily."
852 :group 'org-agenda-daily/weekly
853 :type '(set :greedy t (const closed) (const clock) (const state)))
855 (defcustom org-agenda-log-mode-add-notes t
856 "Non-nil means, add first line of notes to log entries in agenda views.
857 If a log item like a state change or a clock entry is associated with
858 notes, the first line of these notes will be added to the entry in the
859 agenda display."
860 :group 'org-agenda-daily/weekly
861 :type 'boolean)
863 (defcustom org-agenda-start-with-log-mode nil
864 "The initial value of log-mode in a newly created agenda window."
865 :group 'org-agenda-startup
866 :group 'org-agenda-daily/weekly
867 :type 'boolean)
869 (defcustom org-agenda-start-with-clockreport-mode nil
870 "The initial value of clockreport-mode in a newly created agenda window."
871 :group 'org-agenda-startup
872 :group 'org-agenda-daily/weekly
873 :type 'boolean)
875 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
876 "Property list with parameters for the clocktable in clockreport mode.
877 This is the display mode that shows a clock table in the daily/weekly
878 agenda, the properties for this dynamic block can be set here.
879 The usual clocktable parameters are allowed here, but you cannot set
880 the properties :name, :tstart, :tend, :block, and :scope - these will
881 be overwritten to make sure the content accurately reflects the
882 current display in the agenda."
883 :group 'org-agenda-daily/weekly
884 :type 'plist)
886 (defcustom org-agenda-search-view-search-words-only nil
887 "Non-nil means, the search string is interpreted as individual words
888 The search then looks for each word separately in each entry and
889 selects entries that have matches for all words.
890 When nil, matching as loose words will only take place if the first
891 word is preceded by + or -. If that is not the case, the search
892 string will just be matched as a substring in the entry, but with
893 each space character allowing for any whitespace, including newlines."
894 :group 'org-agenda-search-view
895 :type 'boolean)
897 (defgroup org-agenda-time-grid nil
898 "Options concerning the time grid in the Org-mode Agenda."
899 :tag "Org Agenda Time Grid"
900 :group 'org-agenda)
902 (defcustom org-agenda-search-headline-for-time t
903 "Non-nil means, search headline for a time-of-day.
904 If the headline contains a time-of-day in one format or another, it will
905 be used to sort the entry into the time sequence of items for a day.
906 Some people have time stamps in the headline that refer to the creation
907 time or so, and then this produces an unwanted side effect. If this is
908 the case for your, use this variable to turn off searching the headline
909 for a time."
910 :group 'org-agenda-time-grid
911 :type 'boolean)
913 (defcustom org-agenda-use-time-grid t
914 "Non-nil means, show a time grid in the agenda schedule.
915 A time grid is a set of lines for specific times (like every two hours between
916 8:00 and 20:00). The items scheduled for a day at specific times are
917 sorted in between these lines.
918 For details about when the grid will be shown, and what it will look like, see
919 the variable `org-agenda-time-grid'."
920 :group 'org-agenda-time-grid
921 :type 'boolean)
923 (defcustom org-agenda-time-grid
924 '((daily today require-timed)
925 "----------------"
926 (800 1000 1200 1400 1600 1800 2000))
928 "The settings for time grid for agenda display.
929 This is a list of three items. The first item is again a list. It contains
930 symbols specifying conditions when the grid should be displayed:
932 daily if the agenda shows a single day
933 weekly if the agenda shows an entire week
934 today show grid on current date, independent of daily/weekly display
935 require-timed show grid only if at least one item has a time specification
937 The second item is a string which will be placed behind the grid time.
939 The third item is a list of integers, indicating the times that should have
940 a grid line."
941 :group 'org-agenda-time-grid
942 :type
943 '(list
944 (set :greedy t :tag "Grid Display Options"
945 (const :tag "Show grid in single day agenda display" daily)
946 (const :tag "Show grid in weekly agenda display" weekly)
947 (const :tag "Always show grid for today" today)
948 (const :tag "Show grid only if any timed entries are present"
949 require-timed)
950 (const :tag "Skip grid times already present in an entry"
951 remove-match))
952 (string :tag "Grid String")
953 (repeat :tag "Grid Times" (integer :tag "Time"))))
955 (defgroup org-agenda-sorting nil
956 "Options concerning sorting in the Org-mode Agenda."
957 :tag "Org Agenda Sorting"
958 :group 'org-agenda)
960 (defcustom org-agenda-sorting-strategy
961 '((agenda habit-down time-up priority-down category-keep)
962 (todo priority-down category-keep)
963 (tags priority-down category-keep)
964 (search category-keep))
965 "Sorting structure for the agenda items of a single day.
966 This is a list of symbols which will be used in sequence to determine
967 if an entry should be listed before another entry. The following
968 symbols are recognized:
970 time-up Put entries with time-of-day indications first, early first
971 time-down Put entries with time-of-day indications first, late first
972 category-keep Keep the default order of categories, corresponding to the
973 sequence in `org-agenda-files'.
974 category-up Sort alphabetically by category, A-Z.
975 category-down Sort alphabetically by category, Z-A.
976 tag-up Sort alphabetically by last tag, A-Z.
977 tag-down Sort alphabetically by last tag, Z-A.
978 priority-up Sort numerically by priority, high priority last.
979 priority-down Sort numerically by priority, high priority first.
980 todo-state-up Sort by todo state, tasks that are done last.
981 todo-state-down Sort by todo state, tasks that are done first.
982 effort-up Sort numerically by estimated effort, high effort last.
983 effort-down Sort numerically by estimated effort, high effort first.
984 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
985 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
986 habit-up Put entries that are habits first
987 habit-down Put entries that are habits last
989 The different possibilities will be tried in sequence, and testing stops
990 if one comparison returns a \"not-equal\". For example, the default
991 '(time-up category-keep priority-down)
992 means: Pull out all entries having a specified time of day and sort them,
993 in order to make a time schedule for the current day the first thing in the
994 agenda listing for the day. Of the entries without a time indication, keep
995 the grouped in categories, don't sort the categories, but keep them in
996 the sequence given in `org-agenda-files'. Within each category sort by
997 priority.
999 Leaving out `category-keep' would mean that items will be sorted across
1000 categories by priority.
1002 Instead of a single list, this can also be a set of list for specific
1003 contents, with a context symbol in the car of the list, any of
1004 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1006 Custom commands can bind this variable in the options section."
1007 :group 'org-agenda-sorting
1008 :type `(choice
1009 (repeat :tag "General" ,org-sorting-choice)
1010 (list :tag "Individually"
1011 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1012 (repeat ,org-sorting-choice))
1013 (cons (const :tag "Strategy for TODO lists" todo)
1014 (repeat ,org-sorting-choice))
1015 (cons (const :tag "Strategy for Tags matches" tags)
1016 (repeat ,org-sorting-choice))
1017 (cons (const :tag "Strategy for search matches" search)
1018 (repeat ,org-sorting-choice)))))
1020 (defcustom org-agenda-cmp-user-defined nil
1021 "A function to define the comparison `user-defined'.
1022 This function must receive two arguments, agenda entry a and b.
1023 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1024 the user comparison, return nil.
1025 When this is defined, you can make `user-defined-up' and `user-defined-down'
1026 part of an agenda sorting strategy."
1027 :group 'org-agenda-sorting
1028 :type 'symbol)
1030 (defcustom org-sort-agenda-notime-is-late t
1031 "Non-nil means, items without time are considered late.
1032 This is only relevant for sorting. When t, items which have no explicit
1033 time like 15:30 will be considered as 99:01, i.e. later than any items which
1034 do have a time. When nil, the default time is before 0:00. You can use this
1035 option to decide if the schedule for today should come before or after timeless
1036 agenda entries."
1037 :group 'org-agenda-sorting
1038 :type 'boolean)
1040 (defcustom org-sort-agenda-noeffort-is-high t
1041 "Non-nil means, items without effort estimate are sorted as high effort.
1042 This also applies when filtering an agenda view with respect to the
1043 < or > effort operator. Then, tasks with no effort defined will be treated
1044 as tasks with high effort.
1045 When nil, such items are sorted as 0 minutes effort."
1046 :group 'org-agenda-sorting
1047 :type 'boolean)
1049 (defgroup org-agenda-line-format nil
1050 "Options concerning the entry prefix in the Org-mode agenda display."
1051 :tag "Org Agenda Line Format"
1052 :group 'org-agenda)
1054 (defcustom org-agenda-prefix-format
1055 '((agenda . " %-12:c%?-12t% s")
1056 (timeline . " % s")
1057 (todo . " %-12:c")
1058 (tags . " %-12:c")
1059 (search . " %-12:c"))
1060 "Format specifications for the prefix of items in the agenda views.
1061 An alist with four entries, for the different agenda types. The keys to the
1062 sublists are `agenda', `timeline', `todo', and `tags'. The values
1063 are format strings.
1064 This format works similar to a printf format, with the following meaning:
1066 %c the category of the item, \"Diary\" for entries from the diary, or
1067 as given by the CATEGORY keyword or derived from the file name.
1068 %T the *last* tag of the item. Last because inherited tags come
1069 first in the list.
1070 %t the time-of-day specification if one applies to the entry, in the
1071 format HH:MM
1072 %s Scheduling/Deadline information, a short string
1074 All specifiers work basically like the standard `%s' of printf, but may
1075 contain two additional characters: A question mark just after the `%' and
1076 a whitespace/punctuation character just before the final letter.
1078 If the first character after `%' is a question mark, the entire field
1079 will only be included if the corresponding value applies to the
1080 current entry. This is useful for fields which should have fixed
1081 width when present, but zero width when absent. For example,
1082 \"%?-12t\" will result in a 12 character time field if a time of the
1083 day is specified, but will completely disappear in entries which do
1084 not contain a time.
1086 If there is punctuation or whitespace character just before the final
1087 format letter, this character will be appended to the field value if
1088 the value is not empty. For example, the format \"%-12:c\" leads to
1089 \"Diary: \" if the category is \"Diary\". If the category were be
1090 empty, no additional colon would be interted.
1092 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1093 - Indent the line with two space characters
1094 - Give the category in a 12 chars wide field, padded with whitespace on
1095 the right (because of `-'). Append a colon if there is a category
1096 (because of `:').
1097 - If there is a time-of-day, put it into a 12 chars wide field. If no
1098 time, don't put in an empty field, just skip it (because of '?').
1099 - Finally, put the scheduling information and append a whitespace.
1101 As another example, if you don't want the time-of-day of entries in
1102 the prefix, you could use:
1104 (setq org-agenda-prefix-format \" %-11:c% s\")
1106 See also the variables `org-agenda-remove-times-when-in-prefix' and
1107 `org-agenda-remove-tags'.
1109 Custom commands can set this variable in the options section."
1110 :type '(choice
1111 (string :tag "General format")
1112 (list :greedy t :tag "View dependent"
1113 (cons (const agenda) (string :tag "Format"))
1114 (cons (const timeline) (string :tag "Format"))
1115 (cons (const todo) (string :tag "Format"))
1116 (cons (const tags) (string :tag "Format"))
1117 (cons (const search) (string :tag "Format"))))
1118 :group 'org-agenda-line-format)
1120 (defvar org-prefix-format-compiled nil
1121 "The compiled version of the most recently used prefix format.
1122 See the variable `org-agenda-prefix-format'.")
1124 (defcustom org-agenda-todo-keyword-format "%-1s"
1125 "Format for the TODO keyword in agenda lines.
1126 Set this to something like \"%-12s\" if you want all TODO keywords
1127 to occupy a fixed space in the agenda display."
1128 :group 'org-agenda-line-format
1129 :type 'string)
1131 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1132 "Text preceding timerange entries in the agenda view.
1133 This is a list with two strings. The first applies when the range
1134 is entirely on one day. The second applies if the range spans several days.
1135 The strings may have two \"%d\" format specifiers which will be filled
1136 with the sequence number of the days, and the total number of days in the
1137 range, respectively."
1138 :group 'org-agenda-line-format
1139 :type '(list
1140 (string :tag "Deadline today ")
1141 (choice :tag "Deadline relative"
1142 (string :tag "Format string")
1143 (function))))
1145 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1146 "Text preceeding scheduled items in the agenda view.
1147 This is a list with two strings. The first applies when the item is
1148 scheduled on the current day. The second applies when it has been scheduled
1149 previously, it may contain a %d indicating that this is the nth time that
1150 this item is scheduled, due to automatic rescheduling of unfinished items
1151 for the following day. So this number is one larger than the number of days
1152 that passed since this item was scheduled first."
1153 :group 'org-agenda-line-format
1154 :type '(list
1155 (string :tag "Scheduled today ")
1156 (string :tag "Scheduled previously")))
1158 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1159 "Text preceeding deadline items in the agenda view.
1160 This is a list with two strings. The first applies when the item has its
1161 deadline on the current day. The second applies when it is in the past or
1162 in the future, it may contain %d to capture how many days away the deadline
1163 is (was)."
1164 :group 'org-agenda-line-format
1165 :type '(list
1166 (string :tag "Deadline today ")
1167 (choice :tag "Deadline relative"
1168 (string :tag "Format string")
1169 (function))))
1171 (defcustom org-agenda-remove-times-when-in-prefix t
1172 "Non-nil means, remove duplicate time specifications in agenda items.
1173 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1174 time-of-day specification in a headline or diary entry is extracted and
1175 placed into the prefix. If this option is non-nil, the original specification
1176 \(a timestamp or -range, or just a plain time(range) specification like
1177 11:30-4pm) will be removed for agenda display. This makes the agenda less
1178 cluttered.
1179 The option can be t or nil. It may also be the symbol `beg', indicating
1180 that the time should only be removed what it is located at the beginning of
1181 the headline/diary entry."
1182 :group 'org-agenda-line-format
1183 :type '(choice
1184 (const :tag "Always" t)
1185 (const :tag "Never" nil)
1186 (const :tag "When at beginning of entry" beg)))
1189 (defcustom org-agenda-default-appointment-duration nil
1190 "Default duration for appointments that only have a starting time.
1191 When nil, no duration is specified in such cases.
1192 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1193 :group 'org-agenda-line-format
1194 :type '(choice
1195 (integer :tag "Minutes")
1196 (const :tag "No default duration")))
1198 (defcustom org-agenda-show-inherited-tags t
1199 "Non-nil means, show inherited tags in each agenda line."
1200 :group 'org-agenda-line-format
1201 :type 'boolean)
1203 (defcustom org-agenda-remove-tags nil
1204 "Non-nil means, remove the tags from the headline copy in the agenda.
1205 When this is the symbol `prefix', only remove tags when
1206 `org-agenda-prefix-format' contains a `%T' specifier."
1207 :group 'org-agenda-line-format
1208 :type '(choice
1209 (const :tag "Always" t)
1210 (const :tag "Never" nil)
1211 (const :tag "When prefix format contains %T" prefix)))
1213 (if (fboundp 'defvaralias)
1214 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1215 'org-agenda-remove-tags))
1217 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1218 "Shift tags in agenda items to this column.
1219 If this number is positive, it specifies the column. If it is negative,
1220 it means that the tags should be flushright to that column. For example,
1221 -80 works well for a normal 80 character screen."
1222 :group 'org-agenda-line-format
1223 :type 'integer)
1225 (if (fboundp 'defvaralias)
1226 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1228 (defcustom org-agenda-fontify-priorities 'cookies
1229 "Non-nil means, highlight low and high priorities in agenda.
1230 When t, the highest priority entries are bold, lowest priority italic.
1231 However, settings in org-priority-faces will overrule these faces.
1232 When this variable is the symbol `cookies', only fontify the
1233 cookies, not the entire task.
1234 This may also be an association list of priority faces, whose
1235 keys are the character values of `org-highest-priority',
1236 `org-default-priority', and `org-lowest-priority' (the default values
1237 are ?A, ?B, and ?C, respectively). The face may be a named face,
1238 or a list like `(:background \"Red\")'."
1239 :group 'org-agenda-line-format
1240 :type '(choice
1241 (const :tag "Never" nil)
1242 (const :tag "Defaults" t)
1243 (const :tag "Cookies only" cookies)
1244 (repeat :tag "Specify"
1245 (list (character :tag "Priority" :value ?A)
1246 (sexp :tag "face")))))
1248 (defgroup org-agenda-column-view nil
1249 "Options concerning column view in the agenda."
1250 :tag "Org Agenda Column View"
1251 :group 'org-agenda)
1253 (defcustom org-agenda-columns-show-summaries t
1254 "Non-nil means, show summaries for columns displayed in the agenda view."
1255 :group 'org-agenda-column-view
1256 :type 'boolean)
1258 (defcustom org-agenda-columns-remove-prefix-from-item t
1259 "Non-nil means, remove the prefix from a headline for agenda column view.
1260 The special ITEM field in the columns format contains the current line, with
1261 all information shown in other columns (like the TODO state or a tag).
1262 When this variable is non-nil, also the agenda prefix will be removed from
1263 the content of the ITEM field, to make sure as much as possible of the
1264 headline can be shown in the limited width of the field."
1265 :group 'org-agenda
1266 :type 'boolean)
1268 (defcustom org-agenda-columns-compute-summary-properties t
1269 "Non-nil means, recompute all summary properties before column view.
1270 When column view in the agenda is listing properties that have a summary
1271 operator, it can go to all relevant buffers and recompute the summaries
1272 there. This can mean overhead for the agenda column view, but is necessary
1273 to have thing up to date.
1274 As a special case, a CLOCKSUM property also makes sure that the clock
1275 computations are current."
1276 :group 'org-agenda-column-view
1277 :type 'boolean)
1279 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1280 "Non-nil means, the duration of an appointment will add to day effort.
1281 The property to which appointment durations will be added is the one given
1282 in the option `org-effort-property'. If an appointment does not have
1283 an end time, `org-agenda-default-appointment-duration' will be used. If that
1284 is not set, an appointment without end time will not contribute to the time
1285 estimate."
1286 :group 'org-agenda-column-view
1287 :type 'boolean)
1289 (defcustom org-agenda-auto-exclude-function nil
1290 "A function called with a tag to decide if it is filtered on '/ RET'.
1291 The sole argument to the function, which is called once for each
1292 possible tag, is a string giving the name of the tag. The
1293 function should return either nil if the tag should be included
1294 as normal, or \"-<TAG>\" to exclude the tag."
1295 :group 'org-agenda
1296 :type 'function)
1298 (eval-when-compile
1299 (require 'cl))
1300 (require 'org)
1302 (defun org-add-agenda-custom-command (entry)
1303 "Replace or add a command in `org-agenda-custom-commands'.
1304 This is mostly for hacking and trying a new command - once the command
1305 works you probably want to add it to `org-agenda-custom-commands' for good."
1306 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1307 (if ass
1308 (setcdr ass (cdr entry))
1309 (push entry org-agenda-custom-commands))))
1311 ;;; Define the Org-agenda-mode
1313 (defvar org-agenda-mode-map (make-sparse-keymap)
1314 "Keymap for `org-agenda-mode'.")
1315 (if (fboundp 'defvaralias)
1316 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1318 (defvar org-agenda-menu) ; defined later in this file.
1319 (defvar org-agenda-restrict) ; defined later in this file.
1320 (defvar org-agenda-follow-mode nil)
1321 (defvar org-agenda-entry-text-mode nil)
1322 (defvar org-agenda-clockreport-mode nil)
1323 (defvar org-agenda-show-log nil)
1324 (defvar org-agenda-redo-command nil)
1325 (defvar org-agenda-query-string nil)
1326 (defvar org-agenda-mode-hook nil
1327 "Hook for org-agenda-mode, run after the mode is turned on.")
1328 (defvar org-agenda-type nil)
1329 (defvar org-agenda-force-single-file nil)
1330 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1332 (defun org-agenda-mode ()
1333 "Mode for time-sorted view on action items in Org-mode files.
1335 The following commands are available:
1337 \\{org-agenda-mode-map}"
1338 (interactive)
1339 (kill-all-local-variables)
1340 (setq org-agenda-undo-list nil
1341 org-agenda-pending-undo-list nil
1342 org-agenda-bulk-marked-entries nil)
1343 (setq major-mode 'org-agenda-mode)
1344 ;; Keep global-font-lock-mode from turning on font-lock-mode
1345 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1346 (setq mode-name "Org-Agenda")
1347 (use-local-map org-agenda-mode-map)
1348 (easy-menu-add org-agenda-menu)
1349 (if org-startup-truncated (setq truncate-lines t))
1350 (org-set-local 'line-move-visual nil)
1351 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1352 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1353 ;; Make sure properties are removed when copying text
1354 (when (boundp 'buffer-substring-filters)
1355 (org-set-local 'buffer-substring-filters
1356 (cons (lambda (x)
1357 (set-text-properties 0 (length x) nil x) x)
1358 buffer-substring-filters)))
1359 (unless org-agenda-keep-modes
1360 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1361 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1362 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1363 org-agenda-show-log org-agenda-start-with-log-mode))
1365 (easy-menu-change
1366 '("Agenda") "Agenda Files"
1367 (append
1368 (list
1369 (vector
1370 (if (get 'org-agenda-files 'org-restrict)
1371 "Restricted to single file"
1372 "Edit File List")
1373 '(org-edit-agenda-file-list)
1374 (not (get 'org-agenda-files 'org-restrict)))
1375 "--")
1376 (mapcar 'org-file-menu-entry (org-agenda-files))))
1377 (org-agenda-set-mode-name)
1378 (apply
1379 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1380 (list 'org-agenda-mode-hook)))
1382 (substitute-key-definition 'undo 'org-agenda-undo
1383 org-agenda-mode-map global-map)
1384 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1385 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1386 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1387 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1388 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1389 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1390 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1391 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1392 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1393 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1394 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1395 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1396 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1397 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1398 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1399 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1400 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1401 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1402 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1403 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1404 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1405 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1406 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1407 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1408 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1409 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1410 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1411 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1412 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1413 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1414 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1415 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1416 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1417 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1418 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1419 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1420 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1421 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1422 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1423 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1424 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1425 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1426 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1428 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1429 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1430 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1431 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1432 (while l (org-defkey org-agenda-mode-map
1433 (int-to-string (pop l)) 'digit-argument)))
1435 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1436 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1437 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1438 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1439 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1440 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1441 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1442 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1443 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1444 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1445 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1446 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1447 'org-clock-modify-effort-estimate)
1448 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1449 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1450 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1451 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1452 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1453 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1454 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1455 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1456 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1457 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1458 (substitute-key-definition 'next-line 'org-agenda-next-line
1459 org-agenda-mode-map global-map)
1460 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1461 org-agenda-mode-map global-map)
1462 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1463 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1464 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1465 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1466 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1467 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1468 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1469 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1470 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1471 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1472 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1473 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1474 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1475 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1476 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1477 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1478 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1479 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1480 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1481 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1482 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1483 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1484 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1485 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1486 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1487 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1488 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1489 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1490 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1491 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1493 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1494 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1495 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1496 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1497 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1498 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1499 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1500 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1501 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1502 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1504 (org-defkey org-agenda-mode-map
1505 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1506 (org-defkey org-agenda-mode-map
1507 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1508 (when org-agenda-mouse-1-follows-link
1509 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1510 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1511 '("Agenda"
1512 ("Agenda Files")
1513 "--"
1514 ("Agenda Dates"
1515 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1516 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1517 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1518 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1519 "--"
1520 ("View"
1521 ["Day View" org-agenda-day-view
1522 :active (org-agenda-check-type nil 'agenda)
1523 :style radio :selected (equal org-agenda-ndays 1)
1524 :keys "v d (or just d)"]
1525 ["Week View" org-agenda-week-view
1526 :active (org-agenda-check-type nil 'agenda)
1527 :style radio :selected (equal org-agenda-ndays 7)
1528 :keys "v w (or just w)"]
1529 ["Month View" org-agenda-month-view
1530 :active (org-agenda-check-type nil 'agenda)
1531 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1532 :keys "v m"]
1533 ["Year View" org-agenda-year-view
1534 :active (org-agenda-check-type nil 'agenda)
1535 :style radio :selected (member org-agenda-ndays '(365 366))
1536 :keys "v y"]
1537 "--"
1538 ["Include Diary" org-agenda-toggle-diary
1539 :style toggle :selected org-agenda-include-diary
1540 :active (org-agenda-check-type nil 'agenda)]
1541 ["Use Time Grid" org-agenda-toggle-time-grid
1542 :style toggle :selected org-agenda-use-time-grid
1543 :active (org-agenda-check-type nil 'agenda)]
1544 "--"
1545 ["Show clock report" org-agenda-clockreport-mode
1546 :style toggle :selected org-agenda-clockreport-mode
1547 :active (org-agenda-check-type nil 'agenda)]
1548 ["Show some entry text" org-agenda-entry-text-mode
1549 :style toggle :selected org-agenda-entry-text-mode
1550 :active t]
1551 "--"
1552 ["Show Logbook entries" org-agenda-log-mode
1553 :style toggle :selected org-agenda-show-log
1554 :active (org-agenda-check-type nil 'agenda 'timeline)
1555 :keys "v l (or just l)"]
1556 ["Include archived trees" org-agenda-archives-mode
1557 :style toggle :selected org-agenda-archives-mode :active t
1558 :keys "v a"]
1559 ["Include archive files" (org-agenda-archives-mode t)
1560 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1561 :keys "v A"]
1562 "--"
1563 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1564 ["Write view to file" org-write-agenda t]
1565 ["Rebuild buffer" org-agenda-redo t]
1566 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1567 "--"
1568 ["Show original entry" org-agenda-show t]
1569 ["Go To (other window)" org-agenda-goto t]
1570 ["Go To (this window)" org-agenda-switch-to t]
1571 ["Follow Mode" org-agenda-follow-mode
1572 :style toggle :selected org-agenda-follow-mode :active t]
1573 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1574 "--"
1575 ("TODO"
1576 ["Cycle TODO" org-agenda-todo t]
1577 ["Next TODO set" org-agenda-todo-nextset t]
1578 ["Previous TODO set" org-agenda-todo-previousset t]
1579 ["Add note" org-agenda-add-note t])
1580 ("Archive/Refile/Delete"
1581 ["Archive default" org-agenda-archive-default t]
1582 ["Archive default" org-agenda-archive-default-with-confirmation t]
1583 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1584 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1585 ["Archive subtree" org-agenda-archive t]
1586 "--"
1587 ["Refile" org-agenda-refile t]
1588 "--"
1589 ["Delete subtree" org-agenda-kill t])
1590 ("Bulk action"
1591 ["Mark entry" org-agenda-bulk-mark t]
1592 ["Unmark entry" org-agenda-bulk-unmark t]
1593 ["Act on all marked" org-agenda-bulk-action t]
1594 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1595 "--"
1596 ("Tags and Properties"
1597 ["Show all Tags" org-agenda-show-tags t]
1598 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1599 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1600 "--"
1601 ["Column View" org-columns t])
1602 ("Deadline/Schedule"
1603 ["Schedule" org-agenda-schedule t]
1604 ["Set Deadline" org-agenda-deadline t]
1605 "--"
1606 ["Mark item" org-agenda-action :active t :keys "k m"]
1607 ["Show mark item" org-agenda-action :active t :keys "k v"]
1608 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1609 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1610 "--"
1611 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1612 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1613 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1614 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1615 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1616 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1617 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1618 ("Clock and Effort"
1619 ["Clock in" org-agenda-clock-in t]
1620 ["Clock out" org-agenda-clock-out t]
1621 ["Clock cancel" org-agenda-clock-cancel t]
1622 ["Goto running clock" org-clock-goto t]
1623 "--"
1624 ["Set Effort" org-agenda-set-effort t]
1625 ["Change clocked effort" org-clock-modify-effort-estimate
1626 (org-clock-is-active)])
1627 ("Priority"
1628 ["Set Priority" org-agenda-priority t]
1629 ["Increase Priority" org-agenda-priority-up t]
1630 ["Decrease Priority" org-agenda-priority-down t]
1631 ["Show Priority" org-agenda-show-priority t])
1632 ("Calendar/Diary"
1633 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1634 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1635 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1636 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1637 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1638 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1639 "--"
1640 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1641 "--"
1642 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1643 "--"
1644 ("MobileOrg"
1645 ["Push Files and Views" org-mobile-push t]
1646 ["Get Captured and Flagged" org-mobile-pull t]
1647 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1648 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1649 "--"
1650 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1651 "--"
1652 ["Quit" org-agenda-quit t]
1653 ["Exit and Release Buffers" org-agenda-exit t]
1656 ;;; Agenda undo
1658 (defvar org-agenda-allow-remote-undo t
1659 "Non-nil means, allow remote undo from the agenda buffer.")
1660 (defvar org-agenda-undo-list nil
1661 "List of undoable operations in the agenda since last refresh.")
1662 (defvar org-agenda-undo-has-started-in nil
1663 "Buffers that have already seen `undo-start' in the current undo sequence.")
1664 (defvar org-agenda-pending-undo-list nil
1665 "In a series of undo commands, this is the list of remaining undo items.")
1668 (defun org-agenda-undo ()
1669 "Undo a remote editing step in the agenda.
1670 This undoes changes both in the agenda buffer and in the remote buffer
1671 that have been changed along."
1672 (interactive)
1673 (or org-agenda-allow-remote-undo
1674 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1675 (if (not (eq this-command last-command))
1676 (setq org-agenda-undo-has-started-in nil
1677 org-agenda-pending-undo-list org-agenda-undo-list))
1678 (if (not org-agenda-pending-undo-list)
1679 (error "No further undo information"))
1680 (let* ((entry (pop org-agenda-pending-undo-list))
1681 buf line cmd rembuf)
1682 (setq cmd (pop entry) line (pop entry))
1683 (setq rembuf (nth 2 entry))
1684 (org-with-remote-undo rembuf
1685 (while (bufferp (setq buf (pop entry)))
1686 (if (pop entry)
1687 (with-current-buffer buf
1688 (let ((last-undo-buffer buf)
1689 (inhibit-read-only t))
1690 (unless (memq buf org-agenda-undo-has-started-in)
1691 (push buf org-agenda-undo-has-started-in)
1692 (make-local-variable 'pending-undo-list)
1693 (undo-start))
1694 (while (and pending-undo-list
1695 (listp pending-undo-list)
1696 (not (car pending-undo-list)))
1697 (pop pending-undo-list))
1698 (undo-more 1))))))
1699 (org-goto-line line)
1700 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1702 (defun org-verify-change-for-undo (l1 l2)
1703 "Verify that a real change occurred between the undo lists L1 and L2."
1704 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1705 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1706 (not (eq l1 l2)))
1708 ;;; Agenda dispatch
1710 (defvar org-agenda-restrict nil)
1711 (defvar org-agenda-restrict-begin (make-marker))
1712 (defvar org-agenda-restrict-end (make-marker))
1713 (defvar org-agenda-last-dispatch-buffer nil)
1714 (defvar org-agenda-overriding-restriction nil)
1716 ;;;###autoload
1717 (defun org-agenda (&optional arg keys restriction)
1718 "Dispatch agenda commands to collect entries to the agenda buffer.
1719 Prompts for a command to execute. Any prefix arg will be passed
1720 on to the selected command. The default selections are:
1722 a Call `org-agenda-list' to display the agenda for current day or week.
1723 t Call `org-todo-list' to display the global todo list.
1724 T Call `org-todo-list' to display the global todo list, select only
1725 entries with a specific TODO keyword (the user gets a prompt).
1726 m Call `org-tags-view' to display headlines with tags matching
1727 a condition (the user is prompted for the condition).
1728 M Like `m', but select only TODO entries, no ordinary headlines.
1729 L Create a timeline for the current buffer.
1730 e Export views to associated files.
1731 s Search entries for keywords.
1732 / Multi occur across all agenda files and also files listed
1733 in `org-agenda-text-search-extra-files'.
1734 < Restrict agenda commands to buffer, subtree, or region.
1735 Press several times to get the desired effect.
1736 > Remove a previous restriction.
1737 # List \"stuck\" projects.
1738 ! Configure what \"stuck\" means.
1739 C Configure custom agenda commands.
1741 More commands can be added by configuring the variable
1742 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1743 searches can be pre-defined in this way.
1745 If the current buffer is in Org-mode and visiting a file, you can also
1746 first press `<' once to indicate that the agenda should be temporarily
1747 \(until the next use of \\[org-agenda]) restricted to the current file.
1748 Pressing `<' twice means to restrict to the current subtree or region
1749 \(if active)."
1750 (interactive "P")
1751 (catch 'exit
1752 (let* ((prefix-descriptions nil)
1753 (org-agenda-window-setup (if (equal (buffer-name)
1754 org-agenda-buffer-name)
1755 'current-window
1756 org-agenda-window-setup))
1757 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1758 (org-agenda-custom-commands
1759 ;; normalize different versions
1760 (delq nil
1761 (mapcar
1762 (lambda (x)
1763 (cond ((stringp (cdr x))
1764 (push x prefix-descriptions)
1765 nil)
1766 ((stringp (nth 1 x)) x)
1767 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1768 (t (cons (car x) (cons "" (cdr x))))))
1769 org-agenda-custom-commands)))
1770 (buf (current-buffer))
1771 (bfn (buffer-file-name (buffer-base-buffer)))
1772 entry key type match lprops ans)
1773 ;; Turn off restriction unless there is an overriding one,
1774 (unless org-agenda-overriding-restriction
1775 (unless (org-bound-and-true-p org-agenda-keep-restriced-file-list)
1776 ;; There is a request to keep the file list in place
1777 (put 'org-agenda-files 'org-restrict nil))
1778 (setq org-agenda-restrict nil)
1779 (move-marker org-agenda-restrict-begin nil)
1780 (move-marker org-agenda-restrict-end nil))
1781 ;; Delete old local properties
1782 (put 'org-agenda-redo-command 'org-lprops nil)
1783 ;; Remember where this call originated
1784 (setq org-agenda-last-dispatch-buffer (current-buffer))
1785 (unless keys
1786 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1787 keys (car ans)
1788 restriction (cdr ans)))
1789 ;; Estabish the restriction, if any
1790 (when (and (not org-agenda-overriding-restriction) restriction)
1791 (put 'org-agenda-files 'org-restrict (list bfn))
1792 (cond
1793 ((eq restriction 'region)
1794 (setq org-agenda-restrict t)
1795 (move-marker org-agenda-restrict-begin (region-beginning))
1796 (move-marker org-agenda-restrict-end (region-end)))
1797 ((eq restriction 'subtree)
1798 (save-excursion
1799 (setq org-agenda-restrict t)
1800 (org-back-to-heading t)
1801 (move-marker org-agenda-restrict-begin (point))
1802 (move-marker org-agenda-restrict-end
1803 (progn (org-end-of-subtree t)))))))
1805 (require 'calendar) ; FIXME: can we avoid this for some commands?
1806 ;; For example the todo list should not need it (but does...)
1807 (cond
1808 ((setq entry (assoc keys org-agenda-custom-commands))
1809 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1810 (progn
1811 (setq type (nth 2 entry) match (eval (nth 3 entry))
1812 lprops (nth 4 entry))
1813 (put 'org-agenda-redo-command 'org-lprops lprops)
1814 (cond
1815 ((eq type 'agenda)
1816 (org-let lprops '(org-agenda-list current-prefix-arg)))
1817 ((eq type 'alltodo)
1818 (org-let lprops '(org-todo-list current-prefix-arg)))
1819 ((eq type 'search)
1820 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1821 ((eq type 'stuck)
1822 (org-let lprops '(org-agenda-list-stuck-projects
1823 current-prefix-arg)))
1824 ((eq type 'tags)
1825 (org-let lprops '(org-tags-view current-prefix-arg match)))
1826 ((eq type 'tags-todo)
1827 (org-let lprops '(org-tags-view '(4) match)))
1828 ((eq type 'todo)
1829 (org-let lprops '(org-todo-list match)))
1830 ((eq type 'tags-tree)
1831 (org-check-for-org-mode)
1832 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1833 ((eq type 'todo-tree)
1834 (org-check-for-org-mode)
1835 (org-let lprops
1836 '(org-occur (concat "^" outline-regexp "[ \t]*"
1837 (regexp-quote match) "\\>"))))
1838 ((eq type 'occur-tree)
1839 (org-check-for-org-mode)
1840 (org-let lprops '(org-occur match)))
1841 ((functionp type)
1842 (org-let lprops '(funcall type match)))
1843 ((fboundp type)
1844 (org-let lprops '(funcall type match)))
1845 (t (error "Invalid custom agenda command type %s" type))))
1846 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1847 ((equal keys "C")
1848 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1849 (customize-variable 'org-agenda-custom-commands))
1850 ((equal keys "a") (call-interactively 'org-agenda-list))
1851 ((equal keys "s") (call-interactively 'org-search-view))
1852 ((equal keys "t") (call-interactively 'org-todo-list))
1853 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1854 ((equal keys "m") (call-interactively 'org-tags-view))
1855 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1856 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1857 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1858 (org-add-hook
1859 'post-command-hook
1860 (lambda ()
1861 (unless (current-message)
1862 (let* ((m (org-agenda-get-any-marker))
1863 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1864 (when note
1865 (message (concat
1866 "FLAGGING-NOTE ([?] for more info): "
1867 (org-add-props
1868 (replace-regexp-in-string
1869 "\\\\n" "//"
1870 (copy-sequence note))
1871 nil 'face 'org-warning)))))))
1872 t t))
1873 ((equal keys "L")
1874 (unless (org-mode-p)
1875 (error "This is not an Org-mode file"))
1876 (unless restriction
1877 (put 'org-agenda-files 'org-restrict (list bfn))
1878 (org-call-with-arg 'org-timeline arg)))
1879 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1880 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1881 ((equal keys "!") (customize-variable 'org-stuck-projects))
1882 (t (error "Invalid agenda key"))))))
1884 (defun org-agenda-normalize-custom-commands (cmds)
1885 (delq nil
1886 (mapcar
1887 (lambda (x)
1888 (cond ((stringp (cdr x)) nil)
1889 ((stringp (nth 1 x)) x)
1890 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1891 (t (cons (car x) (cons "" (cdr x))))))
1892 cmds)))
1894 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1895 "The user interface for selecting an agenda command."
1896 (catch 'exit
1897 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1898 (restrict-ok (and bfn (org-mode-p)))
1899 (region-p (org-region-active-p))
1900 (custom org-agenda-custom-commands)
1901 (selstring "")
1902 restriction second-time
1903 c entry key type match prefixes rmheader header-end custom1 desc)
1904 (save-window-excursion
1905 (delete-other-windows)
1906 (org-switch-to-buffer-other-window " *Agenda Commands*")
1907 (erase-buffer)
1908 (insert (eval-when-compile
1909 (let ((header
1911 Press key for an agenda command: < Buffer, subtree/region restriction
1912 -------------------------------- > Remove restriction
1913 a Agenda for current week or day e Export agenda views
1914 t List of all TODO entries T Entries with special TODO kwd
1915 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1916 L Timeline for current buffer # List stuck projects (!=configure)
1917 s Search for keywords C Configure custom agenda commands
1918 / Multi-occur ? Find :FLAGGED: entries
1920 (start 0))
1921 (while (string-match
1922 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1923 header start)
1924 (setq start (match-end 0))
1925 (add-text-properties (match-beginning 2) (match-end 2)
1926 '(face bold) header))
1927 header)))
1928 (setq header-end (move-marker (make-marker) (point)))
1929 (while t
1930 (setq custom1 custom)
1931 (when (eq rmheader t)
1932 (org-goto-line 1)
1933 (re-search-forward ":" nil t)
1934 (delete-region (match-end 0) (point-at-eol))
1935 (forward-char 1)
1936 (looking-at "-+")
1937 (delete-region (match-end 0) (point-at-eol))
1938 (move-marker header-end (match-end 0)))
1939 (goto-char header-end)
1940 (delete-region (point) (point-max))
1941 (while (setq entry (pop custom1))
1942 (setq key (car entry) desc (nth 1 entry)
1943 type (nth 2 entry)
1944 match (nth 3 entry))
1945 (if (> (length key) 1)
1946 (add-to-list 'prefixes (string-to-char key))
1947 (insert
1948 (format
1949 "\n%-4s%-14s: %s"
1950 (org-add-props (copy-sequence key)
1951 '(face bold))
1952 (cond
1953 ((string-match "\\S-" desc) desc)
1954 ((eq type 'agenda) "Agenda for current week or day")
1955 ((eq type 'alltodo) "List of all TODO entries")
1956 ((eq type 'search) "Word search")
1957 ((eq type 'stuck) "List of stuck projects")
1958 ((eq type 'todo) "TODO keyword")
1959 ((eq type 'tags) "Tags query")
1960 ((eq type 'tags-todo) "Tags (TODO)")
1961 ((eq type 'tags-tree) "Tags tree")
1962 ((eq type 'todo-tree) "TODO kwd tree")
1963 ((eq type 'occur-tree) "Occur tree")
1964 ((functionp type) (if (symbolp type)
1965 (symbol-name type)
1966 "Lambda expression"))
1967 (t "???"))
1968 (cond
1969 ((stringp match)
1970 (setq match (copy-sequence match))
1971 (org-add-props match nil 'face 'org-warning))
1972 (match
1973 (format "set of %d commands" (length match)))
1974 (t ""))))))
1975 (when prefixes
1976 (mapc (lambda (x)
1977 (insert
1978 (format "\n%s %s"
1979 (org-add-props (char-to-string x)
1980 nil 'face 'bold)
1981 (or (cdr (assoc (concat selstring (char-to-string x))
1982 prefix-descriptions))
1983 "Prefix key"))))
1984 prefixes))
1985 (goto-char (point-min))
1986 (if second-time
1987 (if (not (pos-visible-in-window-p (point-max)))
1988 (org-fit-window-to-buffer))
1989 (setq second-time t)
1990 (org-fit-window-to-buffer))
1991 (message "Press key for agenda command%s:"
1992 (if (or restrict-ok org-agenda-overriding-restriction)
1993 (if org-agenda-overriding-restriction
1994 " (restriction lock active)"
1995 (if restriction
1996 (format " (restricted to %s)" restriction)
1997 " (unrestricted)"))
1998 ""))
1999 (setq c (read-char-exclusive))
2000 (message "")
2001 (cond
2002 ((assoc (char-to-string c) custom)
2003 (setq selstring (concat selstring (char-to-string c)))
2004 (throw 'exit (cons selstring restriction)))
2005 ((memq c prefixes)
2006 (setq selstring (concat selstring (char-to-string c))
2007 prefixes nil
2008 rmheader (or rmheader t)
2009 custom (delq nil (mapcar
2010 (lambda (x)
2011 (if (or (= (length (car x)) 1)
2012 (/= (string-to-char (car x)) c))
2014 (cons (substring (car x) 1) (cdr x))))
2015 custom))))
2016 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2017 (message "Restriction is only possible in Org-mode buffers")
2018 (ding) (sit-for 1))
2019 ((eq c ?1)
2020 (org-agenda-remove-restriction-lock 'noupdate)
2021 (setq restriction 'buffer))
2022 ((eq c ?0)
2023 (org-agenda-remove-restriction-lock 'noupdate)
2024 (setq restriction (if region-p 'region 'subtree)))
2025 ((eq c ?<)
2026 (org-agenda-remove-restriction-lock 'noupdate)
2027 (setq restriction
2028 (cond
2029 ((eq restriction 'buffer)
2030 (if region-p 'region 'subtree))
2031 ((memq restriction '(subtree region))
2032 nil)
2033 (t 'buffer))))
2034 ((eq c ?>)
2035 (org-agenda-remove-restriction-lock 'noupdate)
2036 (setq restriction nil))
2037 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2038 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2039 ((and (> (length selstring) 0) (eq c ?\d))
2040 (delete-window)
2041 (org-agenda-get-restriction-and-command prefix-descriptions))
2043 ((equal c ?q) (error "Abort"))
2044 (t (error "Invalid key %c" c))))))))
2046 (defun org-run-agenda-series (name series)
2047 (org-let (nth 1 series) '(org-prepare-agenda name))
2048 (let* ((org-agenda-multi t)
2049 (redo (list 'org-run-agenda-series name (list 'quote series)))
2050 (cmds (car series))
2051 (gprops (nth 1 series))
2052 match ;; The byte compiler incorrectly complains about this. Keep it!
2053 cmd type lprops)
2054 (while (setq cmd (pop cmds))
2055 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2056 (cond
2057 ((eq type 'agenda)
2058 (org-let2 gprops lprops
2059 '(call-interactively 'org-agenda-list)))
2060 ((eq type 'alltodo)
2061 (org-let2 gprops lprops
2062 '(call-interactively 'org-todo-list)))
2063 ((eq type 'search)
2064 (org-let2 gprops lprops
2065 '(org-search-view current-prefix-arg match nil)))
2066 ((eq type 'stuck)
2067 (org-let2 gprops lprops
2068 '(call-interactively 'org-agenda-list-stuck-projects)))
2069 ((eq type 'tags)
2070 (org-let2 gprops lprops
2071 '(org-tags-view current-prefix-arg match)))
2072 ((eq type 'tags-todo)
2073 (org-let2 gprops lprops
2074 '(org-tags-view '(4) match)))
2075 ((eq type 'todo)
2076 (org-let2 gprops lprops
2077 '(org-todo-list match)))
2078 ((fboundp type)
2079 (org-let2 gprops lprops
2080 '(funcall type match)))
2081 (t (error "Invalid type in command series"))))
2082 (widen)
2083 (setq org-agenda-redo-command redo)
2084 (goto-char (point-min)))
2085 (org-fit-agenda-window)
2086 (org-let (nth 1 series) '(org-finalize-agenda)))
2088 ;;;###autoload
2089 (defmacro org-batch-agenda (cmd-key &rest parameters)
2090 "Run an agenda command in batch mode and send the result to STDOUT.
2091 If CMD-KEY is a string of length 1, it is used as a key in
2092 `org-agenda-custom-commands' and triggers this command. If it is a
2093 longer string it is used as a tags/todo match string.
2094 Paramters are alternating variable names and values that will be bound
2095 before running the agenda command."
2096 (let (pars)
2097 (while parameters
2098 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2099 (if (> (length cmd-key) 2)
2100 (eval (list 'let (nreverse pars)
2101 (list 'org-tags-view nil cmd-key)))
2102 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2103 (set-buffer org-agenda-buffer-name)
2104 (princ (org-encode-for-stdout (buffer-string)))))
2106 ;(defun org-encode-for-stdout (string)
2107 ; (if (fboundp 'encode-coding-string)
2108 ; (encode-coding-string string buffer-file-coding-system)
2109 ; string))
2111 (defun org-encode-for-stdout (string)
2112 string)
2114 (defvar org-agenda-info nil)
2116 ;;;###autoload
2117 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2118 "Run an agenda command in batch mode and send the result to STDOUT.
2119 If CMD-KEY is a string of length 1, it is used as a key in
2120 `org-agenda-custom-commands' and triggers this command. If it is a
2121 longer string it is used as a tags/todo match string.
2122 Paramters are alternating variable names and values that will be bound
2123 before running the agenda command.
2125 The output gives a line for each selected agenda item. Each
2126 item is a list of comma-separated values, like this:
2128 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2130 category The category of the item
2131 head The headline, without TODO kwd, TAGS and PRIORITY
2132 type The type of the agenda entry, can be
2133 todo selected in TODO match
2134 tagsmatch selected in tags match
2135 diary imported from diary
2136 deadline a deadline on given date
2137 scheduled scheduled on given date
2138 timestamp entry has timestamp on given date
2139 closed entry was closed on given date
2140 upcoming-deadline warning about deadline
2141 past-scheduled forwarded scheduled item
2142 block entry has date block including g. date
2143 todo The todo keyword, if any
2144 tags All tags including inherited ones, separated by colons
2145 date The relevant date, like 2007-2-14
2146 time The time, like 15:00-16:50
2147 extra Sting with extra planning info
2148 priority-l The priority letter if any was given
2149 priority-n The computed numerical priority
2150 agenda-day The day in the agenda where this is listed"
2152 (let (pars)
2153 (while parameters
2154 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2155 (push (list 'org-agenda-remove-tags t) pars)
2156 (if (> (length cmd-key) 2)
2157 (eval (list 'let (nreverse pars)
2158 (list 'org-tags-view nil cmd-key)))
2159 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2160 (set-buffer org-agenda-buffer-name)
2161 (let* ((lines (org-split-string (buffer-string) "\n"))
2162 line)
2163 (while (setq line (pop lines))
2164 (catch 'next
2165 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2166 (setq org-agenda-info
2167 (org-fix-agenda-info (text-properties-at 0 line)))
2168 (princ
2169 (org-encode-for-stdout
2170 (mapconcat 'org-agenda-export-csv-mapper
2171 '(org-category txt type todo tags date time-of-day extra
2172 priority-letter priority agenda-day)
2173 ",")))
2174 (princ "\n"))))))
2176 (defun org-fix-agenda-info (props)
2177 "Make sure all properties on an agenda item have a canonical form,
2178 so the export commands can easily use it."
2179 (let (tmp re)
2180 (when (setq tmp (plist-get props 'tags))
2181 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2182 (when (setq tmp (plist-get props 'date))
2183 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2184 (let ((calendar-date-display-form '(year "-" month "-" day)))
2185 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2187 (setq tmp (calendar-date-string tmp)))
2188 (setq props (plist-put props 'date tmp)))
2189 (when (setq tmp (plist-get props 'day))
2190 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2191 (let ((calendar-date-display-form '(year "-" month "-" day)))
2192 (setq tmp (calendar-date-string tmp)))
2193 (setq props (plist-put props 'day tmp))
2194 (setq props (plist-put props 'agenda-day tmp)))
2195 (when (setq tmp (plist-get props 'txt))
2196 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2197 (plist-put props 'priority-letter (match-string 1 tmp))
2198 (setq tmp (replace-match "" t t tmp)))
2199 (when (and (setq re (plist-get props 'org-todo-regexp))
2200 (setq re (concat "\\`\\.*" re " ?"))
2201 (string-match re tmp))
2202 (plist-put props 'todo (match-string 1 tmp))
2203 (setq tmp (replace-match "" t t tmp)))
2204 (plist-put props 'txt tmp)))
2205 props)
2207 (defun org-agenda-export-csv-mapper (prop)
2208 (let ((res (plist-get org-agenda-info prop)))
2209 (setq res
2210 (cond
2211 ((not res) "")
2212 ((stringp res) res)
2213 (t (prin1-to-string res))))
2214 (while (string-match "," res)
2215 (setq res (replace-match ";" t t res)))
2216 (org-trim res)))
2219 ;;;###autoload
2220 (defun org-store-agenda-views (&rest parameters)
2221 (interactive)
2222 (eval (list 'org-batch-store-agenda-views)))
2224 ;; FIXME, why is this a macro?????
2225 ;;;###autoload
2226 (defmacro org-batch-store-agenda-views (&rest parameters)
2227 "Run all custom agenda commands that have a file argument."
2228 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2229 (pop-up-frames nil)
2230 (dir default-directory)
2231 pars cmd thiscmdkey files opts cmd-or-set)
2232 (while parameters
2233 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2234 (setq pars (reverse pars))
2235 (save-window-excursion
2236 (while cmds
2237 (setq cmd (pop cmds)
2238 thiscmdkey (car cmd)
2239 cmd-or-set (nth 2 cmd)
2240 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2241 files (nth (if (listp cmd-or-set) 4 5) cmd))
2242 (if (stringp files) (setq files (list files)))
2243 (when files
2244 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2245 (list 'org-agenda nil thiscmdkey)))
2246 (set-buffer org-agenda-buffer-name)
2247 (while files
2248 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2249 (list 'org-write-agenda
2250 (expand-file-name (pop files) dir) nil t))))
2251 (and (get-buffer org-agenda-buffer-name)
2252 (kill-buffer org-agenda-buffer-name)))))))
2254 (defun org-agenda-mark-header-line (pos)
2255 "Mark the line at POS as an agenda structure header."
2256 (save-excursion
2257 (goto-char pos)
2258 (put-text-property (point-at-bol) (point-at-eol)
2259 'org-agenda-structural-header t)
2260 (when org-agenda-title-append
2261 (put-text-property (point-at-bol) (point-at-eol)
2262 'org-agenda-title-append org-agenda-title-append))))
2264 (defvar org-mobile-creating-agendas)
2265 (defun org-write-agenda (file &optional open nosettings)
2266 "Write the current buffer (an agenda view) as a file.
2267 Depending on the extension of the file name, plain text (.txt),
2268 HTML (.html or .htm) or Postscript (.ps) is produced.
2269 If the extension is .ics, run icalendar export over all files used
2270 to construct the agenda and limit the export to entries listed in the
2271 agenda now.
2272 With prefic argument OPEN, open the new file immediately.
2273 If NOSETTINGS is given, do not scope the settings of
2274 `org-agenda-exporter-settings' into the export commands. This is used when
2275 the settings have already been scoped and we do not wish to overrule other,
2276 higher priority settings."
2277 (interactive "FWrite agenda to file: \nP")
2278 (if (not (file-writable-p file))
2279 (error "Cannot write agenda to file %s" file))
2280 (cond
2281 ((string-match "\\.html?\\'" file) (require 'htmlize))
2282 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2283 (org-let (if nosettings nil org-agenda-exporter-settings)
2284 '(save-excursion
2285 (save-window-excursion
2286 (org-agenda-mark-filtered-text)
2287 (let ((bs (copy-sequence (buffer-string))) beg)
2288 (org-agenda-unmark-filtered-text)
2289 (with-temp-buffer
2290 (insert bs)
2291 (org-agenda-remove-marked-text 'org-filtered)
2292 (while (setq beg (text-property-any (point-min) (point-max)
2293 'org-filtered t))
2294 (delete-region
2295 beg (or (next-single-property-change beg 'org-filtered)
2296 (point-max))))
2297 (run-hooks 'org-agenda-before-write-hook)
2298 (cond
2299 ((org-bound-and-true-p org-mobile-creating-agendas)
2300 (org-mobile-write-agenda-for-mobile file))
2301 ((string-match "\\.html?\\'" file)
2302 (set-buffer (htmlize-buffer (current-buffer)))
2304 (when (and org-agenda-export-html-style
2305 (string-match "<style>" org-agenda-export-html-style))
2306 ;; replace <style> section with org-agenda-export-html-style
2307 (goto-char (point-min))
2308 (kill-region (- (search-forward "<style") 6)
2309 (search-forward "</style>"))
2310 (insert org-agenda-export-html-style))
2311 (write-file file)
2312 (kill-buffer (current-buffer))
2313 (message "HTML written to %s" file))
2314 ((string-match "\\.ps\\'" file)
2315 (require 'ps-print)
2316 (flet ((ps-get-buffer-name () "Agenda View"))
2317 (ps-print-buffer-with-faces file))
2318 (message "Postscript written to %s" file))
2319 ((string-match "\\.pdf\\'" file)
2320 (require 'ps-print)
2321 (flet ((ps-get-buffer-name () "Agenda View"))
2322 (ps-print-buffer-with-faces
2323 (concat (file-name-sans-extension file) ".ps")))
2324 (call-process "ps2pdf" nil nil nil
2325 (expand-file-name
2326 (concat (file-name-sans-extension file) ".ps"))
2327 (expand-file-name file))
2328 (message "PDF written to %s" file))
2329 ((string-match "\\.ics\\'" file)
2330 (require 'org-icalendar)
2331 (let ((org-agenda-marker-table
2332 (org-create-marker-find-array
2333 (org-agenda-collect-markers)))
2334 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2335 (org-combined-agenda-icalendar-file file))
2336 (apply 'org-export-icalendar 'combine
2337 (org-agenda-files nil 'ifmode))))
2339 (let ((bs (buffer-string)))
2340 (find-file file)
2341 (erase-buffer)
2342 (insert bs)
2343 (save-buffer 0)
2344 (kill-buffer (current-buffer))
2345 (message "Plain text written to %s" file))))))))
2346 (set-buffer org-agenda-buffer-name))
2347 (when open (org-open-file file)))
2349 (defvar org-agenda-filter-overlays nil)
2351 (defun org-agenda-mark-filtered-text ()
2352 "Mark all text hidden by filtering with a text property."
2353 (let ((inhibit-read-only t))
2354 (mapc
2355 (lambda (o)
2356 (when (equal (org-overlay-buffer o) (current-buffer))
2357 (put-text-property
2358 (org-overlay-start o) (org-overlay-end o)
2359 'org-filtered t)))
2360 org-agenda-filter-overlays)))
2362 (defun org-agenda-unmark-filtered-text ()
2363 "Remove the filtering text property."
2364 (let ((inhibit-read-only t))
2365 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2367 (defun org-agenda-remove-marked-text (property &optional value)
2368 "Delete all text marked with VALUE of PROPERTY.
2369 VALUE defaults to t."
2370 (let (beg)
2371 (setq value (or value t))
2372 (while (setq beg (text-property-any (point-min) (point-max)
2373 property value))
2374 (delete-region
2375 beg (or (next-single-property-change beg 'org-filtered)
2376 (point-max))))))
2378 (defun org-agenda-add-entry-text ()
2379 "Add entry text to agenda lines.
2380 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2381 entry text following headings shown in the agenda.
2382 Drawers will be excluded, also the line with scheduling/deadline info."
2383 (when (and (> org-agenda-add-entry-text-maxlines 0)
2384 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2385 (let (m txt)
2386 (goto-char (point-min))
2387 (while (not (eobp))
2388 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2389 (beginning-of-line 2)
2390 (setq txt (org-agenda-get-some-entry-text
2391 m org-agenda-add-entry-text-maxlines " > "))
2392 (end-of-line 1)
2393 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2395 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2396 &rest keep)
2397 "Extract entry text from MARKER, at most N-LINES lines.
2398 This will ignore drawers etc, just get the text.
2399 If INDENT is given, prefix every line with this string. If KEEP is
2400 given, it is a list of symbols, defining stuff that hould not be
2401 removed from the entry content. Currently only `planning' is allowed here."
2402 (let (txt drawer-re kwd-time-re ind)
2403 (save-excursion
2404 (with-current-buffer (marker-buffer marker)
2405 (if (not (org-mode-p))
2406 (setq txt "")
2407 (save-excursion
2408 (save-restriction
2409 (widen)
2410 (goto-char marker)
2411 (end-of-line 1)
2412 (setq txt (buffer-substring
2413 (min (1+ (point)) (point-max))
2414 (progn (outline-next-heading) (point)))
2415 drawer-re org-drawer-regexp
2416 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2417 ".*\n?"))
2418 (with-temp-buffer
2419 (insert txt)
2420 (when org-agenda-add-entry-text-descriptive-links
2421 (goto-char (point-min))
2422 (while (org-activate-bracket-links (point-max))
2423 (add-text-properties (match-beginning 0) (match-end 0)
2424 '(face org-link))))
2425 (goto-char (point-min))
2426 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2427 (set-text-properties (match-beginning 0) (match-end 0)
2428 nil))
2429 (goto-char (point-min))
2430 (while (re-search-forward drawer-re nil t)
2431 (delete-region
2432 (match-beginning 0)
2433 (progn (re-search-forward
2434 "^[ \t]*:END:.*\n?" nil 'move)
2435 (point))))
2436 (unless (member 'planning keep)
2437 (goto-char (point-min))
2438 (while (re-search-forward kwd-time-re nil t)
2439 (replace-match "")))
2440 (goto-char (point-min))
2441 (when org-agenda-entry-text-exclude-regexps
2442 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2443 (while (setq re (pop re-list))
2444 (goto-char (point-min))
2445 (while (re-search-forward re nil t)
2446 (replace-match "")))))
2447 (goto-char (point-max))
2448 (skip-chars-backward " \t\n")
2449 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2451 ;; find and remove min common indentation
2452 (goto-char (point-min))
2453 (untabify (point-min) (point-max))
2454 (setq ind (org-get-indentation))
2455 (while (not (eobp))
2456 (unless (looking-at "[ \t]*$")
2457 (setq ind (min ind (org-get-indentation))))
2458 (beginning-of-line 2))
2459 (goto-char (point-min))
2460 (while (not (eobp))
2461 (unless (looking-at "[ \t]*$")
2462 (move-to-column ind)
2463 (delete-region (point-at-bol) (point)))
2464 (beginning-of-line 2))
2466 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2468 (goto-char (point-min))
2469 (when indent
2470 (while (and (not (eobp)) (re-search-forward "^" nil t))
2471 (replace-match indent t t)))
2472 (goto-char (point-min))
2473 (while (looking-at "[ \t]*\n") (replace-match ""))
2474 (goto-char (point-max))
2475 (when (> (org-current-line)
2476 n-lines)
2477 (org-goto-line (1+ n-lines))
2478 (backward-char 1))
2479 (setq txt (buffer-substring (point-min) (point)))))))))
2480 txt))
2482 (defun org-agenda-collect-markers ()
2483 "Collect the markers pointing to entries in the agenda buffer."
2484 (let (m markers)
2485 (save-excursion
2486 (goto-char (point-min))
2487 (while (not (eobp))
2488 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2489 (org-get-at-bol 'org-marker)))
2490 (push m markers))
2491 (beginning-of-line 2)))
2492 (nreverse markers)))
2494 (defun org-create-marker-find-array (marker-list)
2495 "Create a alist of files names with all marker positions in that file."
2496 (let (f tbl m a p)
2497 (while (setq m (pop marker-list))
2498 (setq p (marker-position m)
2499 f (buffer-file-name (or (buffer-base-buffer
2500 (marker-buffer m))
2501 (marker-buffer m))))
2502 (if (setq a (assoc f tbl))
2503 (push (marker-position m) (cdr a))
2504 (push (list f p) tbl)))
2505 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2506 tbl)))
2508 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2509 (defun org-check-agenda-marker-table ()
2510 "Check of the current entry is on the marker list."
2511 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2513 (and (setq a (assoc file org-agenda-marker-table))
2514 (save-match-data
2515 (save-excursion
2516 (org-back-to-heading t)
2517 (member (point) (cdr a)))))))
2519 (defun org-check-for-org-mode ()
2520 "Make sure current buffer is in org-mode. Error if not."
2521 (or (org-mode-p)
2522 (error "Cannot execute org-mode agenda command on buffer in %s"
2523 major-mode)))
2525 (defun org-fit-agenda-window ()
2526 "Fit the window to the buffer size."
2527 (and (memq org-agenda-window-setup '(reorganize-frame))
2528 (fboundp 'fit-window-to-buffer)
2529 (org-fit-window-to-buffer
2531 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2532 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2534 ;;; Agenda prepare and finalize
2536 (defvar org-agenda-multi nil) ; dynamically scoped
2537 (defvar org-agenda-buffer-name "*Org Agenda*")
2538 (defvar org-pre-agenda-window-conf nil)
2539 (defvar org-agenda-columns-active nil)
2540 (defvar org-agenda-name nil)
2541 (defvar org-agenda-filter nil)
2542 (defvar org-agenda-filter-preset nil
2543 "A preset of the tags filter used for secondary agenda filtering.
2544 This must be a list of strings, each string must be a single tag preceeded
2545 by \"+\" or \"-\".
2546 This variable should not be set directly, but agenda custom commands can
2547 bind it in the options section.")
2549 (defun org-prepare-agenda (&optional name)
2550 (setq org-todo-keywords-for-agenda nil)
2551 (setq org-done-keywords-for-agenda nil)
2552 (setq org-drawers-for-agenda nil)
2553 (setq org-agenda-filter nil)
2554 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2555 (if org-agenda-multi
2556 (progn
2557 (setq buffer-read-only nil)
2558 (goto-char (point-max))
2559 (unless (or (bobp) org-agenda-compact-blocks)
2560 (insert "\n"
2561 (if (stringp org-agenda-block-separator)
2562 org-agenda-block-separator
2563 (make-string (window-width) org-agenda-block-separator))
2564 "\n"))
2565 (narrow-to-region (point) (point-max)))
2566 (org-agenda-reset-markers)
2567 (setq org-agenda-contributing-files nil)
2568 (setq org-agenda-columns-active nil)
2569 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2570 (setq org-todo-keywords-for-agenda
2571 (org-uniquify org-todo-keywords-for-agenda))
2572 (setq org-done-keywords-for-agenda
2573 (org-uniquify org-done-keywords-for-agenda))
2574 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2575 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2576 (awin (get-buffer-window abuf)))
2577 (cond
2578 ((equal (current-buffer) abuf) nil)
2579 (awin (select-window awin))
2580 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2581 ((equal org-agenda-window-setup 'current-window)
2582 (switch-to-buffer abuf))
2583 ((equal org-agenda-window-setup 'other-window)
2584 (org-switch-to-buffer-other-window abuf))
2585 ((equal org-agenda-window-setup 'other-frame)
2586 (switch-to-buffer-other-frame abuf))
2587 ((equal org-agenda-window-setup 'reorganize-frame)
2588 (delete-other-windows)
2589 (org-switch-to-buffer-other-window abuf))))
2590 (setq buffer-read-only nil)
2591 (let ((inhibit-read-only t)) (erase-buffer))
2592 (org-agenda-mode)
2593 (and name (not org-agenda-name)
2594 (org-set-local 'org-agenda-name name)))
2595 (setq buffer-read-only nil))
2597 (defun org-finalize-agenda ()
2598 "Finishing touch for the agenda buffer, called just before displaying it."
2599 (unless org-agenda-multi
2600 (save-excursion
2601 (let ((inhibit-read-only t))
2602 (goto-char (point-min))
2603 (while (org-activate-bracket-links (point-max))
2604 (add-text-properties (match-beginning 0) (match-end 0)
2605 '(face org-link)))
2606 (org-agenda-align-tags)
2607 (unless org-agenda-with-colors
2608 (remove-text-properties (point-min) (point-max) '(face nil))))
2609 (if (and (boundp 'org-agenda-overriding-columns-format)
2610 org-agenda-overriding-columns-format)
2611 (org-set-local 'org-agenda-overriding-columns-format
2612 org-agenda-overriding-columns-format))
2613 (if (and (boundp 'org-agenda-view-columns-initially)
2614 org-agenda-view-columns-initially)
2615 (org-agenda-columns))
2616 (when org-agenda-fontify-priorities
2617 (org-agenda-fontify-priorities))
2618 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2619 (org-agenda-dim-blocked-tasks))
2620 (org-agenda-mark-clocking-task)
2621 (when org-agenda-entry-text-mode
2622 (org-agenda-entry-text-hide)
2623 (org-agenda-entry-text-show))
2624 (if (functionp 'org-habit-insert-consistency-graphs)
2625 (org-habit-insert-consistency-graphs))
2626 (run-hooks 'org-finalize-agenda-hook)
2627 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2628 (when (get 'org-agenda-filter :preset-filter)
2629 (org-agenda-filter-apply org-agenda-filter))
2632 (defun org-agenda-mark-clocking-task ()
2633 "Mark the current clock entry in the agenda if it is present."
2634 (mapc (lambda (o)
2635 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2636 (org-delete-overlay o)))
2637 (org-overlays-in (point-min) (point-max)))
2638 (when (marker-buffer org-clock-hd-marker)
2639 (save-excursion
2640 (goto-char (point-min))
2641 (let (s ov)
2642 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2643 (goto-char s)
2644 (when (equal (org-get-at-bol 'org-hd-marker)
2645 org-clock-hd-marker)
2646 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2647 (org-overlay-put ov 'type 'org-agenda-clocking)
2648 (org-overlay-put ov 'face 'org-agenda-clocking)
2649 (org-overlay-put ov 'help-echo
2650 "The clock is running in this item")))))))
2652 (defun org-agenda-fontify-priorities ()
2653 "Make highest priority lines bold, and lowest italic."
2654 (interactive)
2655 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2656 (org-delete-overlay o)))
2657 (org-overlays-in (point-min) (point-max)))
2658 (save-excursion
2659 (let ((inhibit-read-only t)
2660 b e p ov h l)
2661 (goto-char (point-min))
2662 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2663 (setq h (or (get-char-property (point) 'org-highest-priority)
2664 org-highest-priority)
2665 l (or (get-char-property (point) 'org-lowest-priority)
2666 org-lowest-priority)
2667 p (string-to-char (match-string 1))
2668 b (match-beginning 0)
2669 e (if (eq org-agenda-fontify-priorities 'cookies)
2670 (match-end 0)
2671 (point-at-eol))
2672 ov (org-make-overlay b e))
2673 (org-overlay-put
2674 ov 'face
2675 (cond ((cdr (assoc p org-priority-faces)))
2676 ((and (listp org-agenda-fontify-priorities)
2677 (cdr (assoc p org-agenda-fontify-priorities))))
2678 ((equal p l) 'italic)
2679 ((equal p h) 'bold)))
2680 (org-overlay-put ov 'org-type 'org-priority)))))
2682 (defun org-agenda-dim-blocked-tasks ()
2683 "Dim currently blocked TODO's in the agenda display."
2684 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2685 (org-delete-overlay o)))
2686 (org-overlays-in (point-min) (point-max)))
2687 (save-excursion
2688 (let ((inhibit-read-only t)
2689 (org-depend-tag-blocked nil)
2690 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2691 org-blocked-by-checkboxes
2692 invis1 b e p ov h l)
2693 (goto-char (point-min))
2694 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2695 (and pos (goto-char (1+ pos))))
2696 (setq org-blocked-by-checkboxes nil invis1 invis)
2697 (let ((marker (org-get-at-bol 'org-hd-marker)))
2698 (when (and marker
2699 (not (with-current-buffer (marker-buffer marker)
2700 (save-excursion
2701 (goto-char marker)
2702 (if (org-entry-get nil "NOBLOCKING")
2703 t ;; Never block this entry
2704 (run-hook-with-args-until-failure
2705 'org-blocker-hook
2706 (list :type 'todo-state-change
2707 :position marker
2708 :from 'todo
2709 :to 'done)))))))
2710 (if org-blocked-by-checkboxes (setq invis1 nil))
2711 (setq b (if invis1
2712 (max (point-min) (1- (point-at-bol)))
2713 (point-at-bol))
2714 e (point-at-eol)
2715 ov (org-make-overlay b e))
2716 (if invis1
2717 (org-overlay-put ov 'invisible t)
2718 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2719 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2721 (defvar org-agenda-skip-function nil
2722 "Function to be called at each match during agenda construction.
2723 If this function returns nil, the current match should not be skipped.
2724 Otherwise, the function must return a position from where the search
2725 should be continued.
2726 This may also be a Lisp form, it will be evaluated.
2727 Never set this variable using `setq' or so, because then it will apply
2728 to all future agenda commands. Instead, bind it with `let' to scope
2729 it dynamically into the agenda-constructing command. A good way to set
2730 it is through options in org-agenda-custom-commands.")
2732 (defun org-agenda-skip ()
2733 "Throw to `:skip' in places that should be skipped.
2734 Also moves point to the end of the skipped region, so that search can
2735 continue from there."
2736 (let ((p (point-at-bol)) to fp)
2737 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2738 (get-text-property p :org-archived)
2739 (org-end-of-subtree t)
2740 (throw :skip t))
2741 (and org-agenda-skip-comment-trees
2742 (get-text-property p :org-comment)
2743 (org-end-of-subtree t)
2744 (throw :skip t))
2745 (if (equal (char-after p) ?#) (throw :skip t))
2746 (when (and (or (setq fp (functionp org-agenda-skip-function))
2747 (consp org-agenda-skip-function))
2748 (setq to (save-excursion
2749 (save-match-data
2750 (if fp
2751 (funcall org-agenda-skip-function)
2752 (eval org-agenda-skip-function))))))
2753 (goto-char to)
2754 (throw :skip t))))
2756 (defvar org-agenda-markers nil
2757 "List of all currently active markers created by `org-agenda'.")
2758 (defvar org-agenda-last-marker-time (org-float-time)
2759 "Creation time of the last agenda marker.")
2761 (defun org-agenda-new-marker (&optional pos)
2762 "Return a new agenda marker.
2763 Org-mode keeps a list of these markers and resets them when they are
2764 no longer in use."
2765 (let ((m (copy-marker (or pos (point)))))
2766 (setq org-agenda-last-marker-time (org-float-time))
2767 (push m org-agenda-markers)
2770 (defun org-agenda-reset-markers ()
2771 "Reset markers created by `org-agenda'."
2772 (while org-agenda-markers
2773 (move-marker (pop org-agenda-markers) nil)))
2775 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2776 "Save relative positions of markers in region."
2777 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2778 org-agenda-markers))
2780 ;;; Entry text mode
2782 (defun org-agenda-entry-text-show-here ()
2783 "Add some text from te entry as context to the current line."
2784 (let (m txt o)
2785 (setq m (org-get-at-bol 'org-hd-marker))
2786 (unless (marker-buffer m)
2787 (error "No marker points to an entry here"))
2788 (setq txt (concat "\n" (org-no-properties
2789 (org-agenda-get-some-entry-text
2790 m org-agenda-entry-text-maxlines " > "))))
2791 (when (string-match "\\S-" txt)
2792 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2793 (org-overlay-put o 'evaporate t)
2794 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2795 (org-overlay-put o 'after-string txt))))
2797 (defun org-agenda-entry-text-show ()
2798 "Add entry context for all agenda lines."
2799 (interactive)
2800 (save-excursion
2801 (goto-char (point-max))
2802 (beginning-of-line 1)
2803 (while (not (bobp))
2804 (when (org-get-at-bol 'org-hd-marker)
2805 (org-agenda-entry-text-show-here))
2806 (beginning-of-line 0))))
2808 (defun org-agenda-entry-text-hide ()
2809 "Remove any shown entry context."
2810 (delq nil
2811 (mapcar (lambda (o)
2812 (if (eq (org-overlay-get o 'org-overlay-type)
2813 'agenda-entry-content)
2814 (progn (org-delete-overlay o) t)))
2815 (org-overlays-in (point-min) (point-max)))))
2817 ;;; Agenda timeline
2819 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2821 (defun org-timeline (&optional include-all)
2822 "Show a time-sorted view of the entries in the current org file.
2823 Only entries with a time stamp of today or later will be listed. With
2824 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2825 under the current date.
2826 If the buffer contains an active region, only check the region for
2827 dates."
2828 (interactive "P")
2829 (require 'calendar)
2830 (org-compile-prefix-format 'timeline)
2831 (org-set-sorting-strategy 'timeline)
2832 (let* ((dopast t)
2833 (dotodo include-all)
2834 (doclosed org-agenda-show-log)
2835 (entry buffer-file-name)
2836 (date (calendar-current-date))
2837 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2838 (end (if (org-region-active-p) (region-end) (point-max)))
2839 (day-numbers (org-get-all-dates beg end 'no-ranges
2840 t doclosed ; always include today
2841 org-timeline-show-empty-dates))
2842 (org-deadline-warning-days 0)
2843 (org-agenda-only-exact-dates t)
2844 (today (time-to-days (current-time)))
2845 (past t)
2846 args
2847 s e rtn d emptyp wd)
2848 (setq org-agenda-redo-command
2849 (list 'progn
2850 (list 'org-switch-to-buffer-other-window (current-buffer))
2851 (list 'org-timeline (list 'quote include-all))))
2852 (if (not dopast)
2853 ;; Remove past dates from the list of dates.
2854 (setq day-numbers (delq nil (mapcar (lambda(x)
2855 (if (>= x today) x nil))
2856 day-numbers))))
2857 (org-prepare-agenda (concat "Timeline "
2858 (file-name-nondirectory buffer-file-name)))
2859 (if doclosed (push :closed args))
2860 (push :timestamp args)
2861 (push :deadline args)
2862 (push :scheduled args)
2863 (push :sexp args)
2864 (if dotodo (push :todo args))
2865 (insert "Timeline of file " entry "\n")
2866 (add-text-properties (point-min) (point)
2867 (list 'face 'org-agenda-structure))
2868 (org-agenda-mark-header-line (point-min))
2869 (while (setq d (pop day-numbers))
2870 (if (and (listp d) (eq (car d) :omitted))
2871 (progn
2872 (setq s (point))
2873 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2874 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2875 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2876 (if (and (>= d today)
2877 dopast
2878 past)
2879 (progn
2880 (setq past nil)
2881 (insert (make-string 79 ?-) "\n")))
2882 (setq date (calendar-gregorian-from-absolute d)
2883 wd (calendar-day-of-week date))
2884 (setq s (point))
2885 (setq rtn (and (not emptyp)
2886 (apply 'org-agenda-get-day-entries entry
2887 date args)))
2888 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2889 (progn
2890 (insert
2891 (if (stringp org-agenda-format-date)
2892 (format-time-string org-agenda-format-date
2893 (org-time-from-absolute date))
2894 (funcall org-agenda-format-date date))
2895 "\n")
2896 (put-text-property s (1- (point)) 'face
2897 (if (member wd org-agenda-weekend-days)
2898 'org-agenda-date-weekend
2899 'org-agenda-date))
2900 (put-text-property s (1- (point)) 'org-date-line t)
2901 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2902 (if (equal d today)
2903 (put-text-property s (1- (point)) 'org-today t))
2904 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2905 (put-text-property s (1- (point)) 'day d)))))
2906 (goto-char (point-min))
2907 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2908 (point-min)))
2909 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2910 (org-finalize-agenda)
2911 (setq buffer-read-only t)))
2913 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2914 "Return a list of all relevant day numbers from BEG to END buffer positions.
2915 If NO-RANGES is non-nil, include only the start and end dates of a range,
2916 not every single day in the range. If FORCE-TODAY is non-nil, make
2917 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2918 inactive time stamps (those in square brackets) are included.
2919 When EMPTY is non-nil, also include days without any entries."
2920 (let ((re (concat
2921 (if pre-re pre-re "")
2922 (if inactive org-ts-regexp-both org-ts-regexp)))
2923 dates dates1 date day day1 day2 ts1 ts2)
2924 (if force-today
2925 (setq dates (list (time-to-days (current-time)))))
2926 (save-excursion
2927 (goto-char beg)
2928 (while (re-search-forward re end t)
2929 (setq day (time-to-days (org-time-string-to-time
2930 (substring (match-string 1) 0 10))))
2931 (or (memq day dates) (push day dates)))
2932 (unless no-ranges
2933 (goto-char beg)
2934 (while (re-search-forward org-tr-regexp end t)
2935 (setq ts1 (substring (match-string 1) 0 10)
2936 ts2 (substring (match-string 2) 0 10)
2937 day1 (time-to-days (org-time-string-to-time ts1))
2938 day2 (time-to-days (org-time-string-to-time ts2)))
2939 (while (< (setq day1 (1+ day1)) day2)
2940 (or (memq day1 dates) (push day1 dates)))))
2941 (setq dates (sort dates '<))
2942 (when empty
2943 (while (setq day (pop dates))
2944 (setq day2 (car dates))
2945 (push day dates1)
2946 (when (and day2 empty)
2947 (if (or (eq empty t)
2948 (and (numberp empty) (<= (- day2 day) empty)))
2949 (while (< (setq day (1+ day)) day2)
2950 (push (list day) dates1))
2951 (push (cons :omitted (- day2 day)) dates1))))
2952 (setq dates (nreverse dates1)))
2953 dates)))
2955 ;;; Agenda Daily/Weekly
2957 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2958 (defvar org-agenda-start-day nil ; dynamically scoped parameter
2959 "Custom commands can set this variable in the options section.")
2960 (defvar org-agenda-last-arguments nil
2961 "The arguments of the previous call to org-agenda")
2962 (defvar org-starting-day nil) ; local variable in the agenda buffer
2963 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2964 (defvar org-include-all-loc nil) ; local variable
2965 (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
2967 ;;;###autoload
2968 (defun org-agenda-list (&optional include-all start-day ndays)
2969 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2970 The view will be for the current day or week, but from the overview buffer
2971 you will be able to go to other days/weeks.
2973 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2974 all unfinished TODO items will also be shown, before the agenda.
2975 This feature is considered obsolete, please use the TODO list or a block
2976 agenda instead.
2978 With a numeric prefix argument in an interactive call, the agenda will
2979 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2980 the number of days. NDAYS defaults to `org-agenda-ndays'.
2982 START-DAY defaults to TODAY, or to the most recent match for the weekday
2983 given in `org-agenda-start-on-weekday'."
2984 (interactive "P")
2985 (if (and (integerp include-all) (> include-all 0))
2986 (setq ndays include-all include-all nil))
2987 (setq ndays (or ndays org-agenda-ndays)
2988 start-day (or start-day org-agenda-start-day))
2989 (if org-agenda-overriding-arguments
2990 (setq include-all (car org-agenda-overriding-arguments)
2991 start-day (nth 1 org-agenda-overriding-arguments)
2992 ndays (nth 2 org-agenda-overriding-arguments)))
2993 (if (stringp start-day)
2994 ;; Convert to an absolute day number
2995 (setq start-day (time-to-days (org-read-date nil t start-day))))
2996 (setq org-agenda-last-arguments (list include-all start-day ndays))
2997 (org-compile-prefix-format 'agenda)
2998 (org-set-sorting-strategy 'agenda)
2999 (require 'calendar)
3000 (let* ((org-agenda-start-on-weekday
3001 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3002 org-agenda-start-on-weekday nil))
3003 (thefiles (org-agenda-files nil 'ifmode))
3004 (files thefiles)
3005 (today (time-to-days
3006 (time-subtract (current-time)
3007 (list 0 (* 3600 org-extend-today-until) 0))))
3008 (sd (or start-day today))
3009 (start (if (or (null org-agenda-start-on-weekday)
3010 (< org-agenda-ndays 7))
3012 (let* ((nt (calendar-day-of-week
3013 (calendar-gregorian-from-absolute sd)))
3014 (n1 org-agenda-start-on-weekday)
3015 (d (- nt n1)))
3016 (- sd (+ (if (< d 0) 7 0) d)))))
3017 (day-numbers (list start))
3018 (day-cnt 0)
3019 (inhibit-redisplay (not debug-on-error))
3020 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3021 clocktable-start clocktable-end)
3022 (setq org-agenda-redo-command
3023 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3024 ;; Make the list of days
3025 (setq ndays (or ndays org-agenda-ndays)
3026 nd ndays)
3027 (while (> ndays 1)
3028 (push (1+ (car day-numbers)) day-numbers)
3029 (setq ndays (1- ndays)))
3030 (setq day-numbers (nreverse day-numbers))
3031 (setq clocktable-start (car day-numbers)
3032 clocktable-end (1+ (or (org-last day-numbers) 0)))
3033 (org-prepare-agenda "Day/Week")
3034 (org-set-local 'org-starting-day (car day-numbers))
3035 (org-set-local 'org-include-all-loc include-all)
3036 (org-set-local 'org-agenda-span
3037 (org-agenda-ndays-to-span nd))
3038 (when (and (or include-all org-agenda-include-all-todo)
3039 (member today day-numbers))
3040 (setq files thefiles
3041 rtnall nil)
3042 (while (setq file (pop files))
3043 (catch 'nextfile
3044 (org-check-agenda-file file)
3045 (setq date (calendar-gregorian-from-absolute today)
3046 rtn (org-agenda-get-day-entries
3047 file date :todo))
3048 (setq rtnall (append rtnall rtn))))
3049 (when rtnall
3050 (insert "All currently open TODO items:\n")
3051 (add-text-properties (point-min) (1- (point))
3052 (list 'face 'org-agenda-structure
3053 'short-heading "All TODO items"))
3054 (org-agenda-mark-header-line (point-min))
3055 (insert (org-finalize-agenda-entries rtnall) "\n")))
3056 (unless org-agenda-compact-blocks
3057 (let* ((d1 (car day-numbers))
3058 (d2 (org-last day-numbers))
3059 (w1 (org-days-to-iso-week d1))
3060 (w2 (org-days-to-iso-week d2)))
3061 (setq s (point))
3062 (if org-agenda-overriding-header
3063 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3064 nil 'face 'org-agenda-structure) "\n")
3065 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3066 "-agenda"
3067 (if (< (- d2 d1) 350)
3068 (if (= w1 w2)
3069 (format " (W%02d)" w1)
3070 (format " (W%02d-W%02d)" w1 w2))
3072 ":\n")))
3073 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3074 'org-date-line t))
3075 (org-agenda-mark-header-line s))
3076 (while (setq d (pop day-numbers))
3077 (setq date (calendar-gregorian-from-absolute d)
3078 wd (calendar-day-of-week date)
3079 s (point))
3080 (if (or (setq todayp (= d today))
3081 (and (not start-pos) (= d sd)))
3082 (setq start-pos (point))
3083 (if (and start-pos (not end-pos))
3084 (setq end-pos (point))))
3085 (setq files thefiles
3086 rtnall nil)
3087 (while (setq file (pop files))
3088 (catch 'nextfile
3089 (org-check-agenda-file file)
3090 (cond
3091 ((eq org-agenda-show-log 'only)
3092 (setq rtn (org-agenda-get-day-entries
3093 file date :closed)))
3094 (org-agenda-show-log
3095 (setq rtn (org-agenda-get-day-entries
3096 file date
3097 :deadline :scheduled :timestamp :sexp :closed)))
3099 (setq rtn (org-agenda-get-day-entries
3100 file date
3101 :deadline :scheduled :sexp :timestamp))))
3102 (setq rtnall (append rtnall rtn))))
3103 (if org-agenda-include-diary
3104 (let ((org-agenda-search-headline-for-time t))
3105 (require 'diary-lib)
3106 (setq rtn (org-get-entries-from-diary date))
3107 (setq rtnall (append rtnall rtn))))
3108 (if (or rtnall org-agenda-show-all-dates)
3109 (progn
3110 (setq day-cnt (1+ day-cnt))
3111 (insert
3112 (if (stringp org-agenda-format-date)
3113 (format-time-string org-agenda-format-date
3114 (org-time-from-absolute date))
3115 (funcall org-agenda-format-date date))
3116 "\n")
3117 (put-text-property s (1- (point)) 'face
3118 (if (member wd org-agenda-weekend-days)
3119 'org-agenda-date-weekend
3120 'org-agenda-date))
3121 (put-text-property s (1- (point)) 'org-date-line t)
3122 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3123 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3124 (when todayp
3125 (put-text-property s (1- (point)) 'org-today t)
3126 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3127 (if rtnall (insert
3128 (org-finalize-agenda-entries
3129 (org-agenda-add-time-grid-maybe
3130 rtnall nd todayp))
3131 "\n"))
3132 (put-text-property s (1- (point)) 'day d)
3133 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3134 (when (and org-agenda-clockreport-mode clocktable-start)
3135 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3136 ;; the above line is to ensure the restricted range!
3137 (p org-agenda-clockreport-parameter-plist)
3138 tbl)
3139 (setq p (org-plist-delete p :block))
3140 (setq p (plist-put p :tstart clocktable-start))
3141 (setq p (plist-put p :tend clocktable-end))
3142 (setq p (plist-put p :scope 'agenda))
3143 (setq tbl (apply 'org-get-clocktable p))
3144 (insert tbl)))
3145 (goto-char (point-min))
3146 (or org-agenda-multi (org-fit-agenda-window))
3147 (unless (and (pos-visible-in-window-p (point-min))
3148 (pos-visible-in-window-p (point-max)))
3149 (goto-char (1- (point-max)))
3150 (recenter -1)
3151 (if (not (pos-visible-in-window-p (or start-pos 1)))
3152 (progn
3153 (goto-char (or start-pos 1))
3154 (recenter 1))))
3155 (goto-char (or start-pos 1))
3156 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3157 (org-finalize-agenda)
3158 (setq buffer-read-only t)
3159 (message "")))
3161 (defun org-agenda-ndays-to-span (n)
3162 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3164 ;;; Agenda word search
3166 (defvar org-agenda-search-history nil)
3167 (defvar org-todo-only nil)
3169 (defvar org-search-syntax-table nil
3170 "Special syntax table for org-mode search.
3171 In this table, we have single quotes not as word constituents, to
3172 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3174 (defun org-search-syntax-table ()
3175 (unless org-search-syntax-table
3176 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3177 (modify-syntax-entry ?' "." org-search-syntax-table)
3178 (modify-syntax-entry ?` "." org-search-syntax-table))
3179 org-search-syntax-table)
3181 ;;;###autoload
3182 (defun org-search-view (&optional todo-only string edit-at)
3183 "Show all entries that contain words or regular expressions.
3184 If the first character of the search string is an asterisks,
3185 search only the headlines.
3187 With optional prefix argument TODO-ONLY, only consider entries that are
3188 TODO entries. The argument STRING can be used to pass a default search
3189 string into this function. If EDIT-AT is non-nil, it means that the
3190 user should get a chance to edit this string, with cursor at position
3191 EDIT-AT.
3193 The search string is broken into \"words\" by splitting at whitespace.
3194 Depending on the variable `org-agenda-search-view-search-words-only'
3195 and on wether the first character in the search string is \"+\" or \"-\",
3196 The string is then interpreted either as a substrig with variable amounts
3197 of whitespace, or as a list or individual words that should be matched.
3199 The default is a substring match, where each space in the search string
3200 can expand to an arbitrary amount of whitespace, including newlines.
3202 If matching individual words, these words are then interpreted as a
3203 boolean expression with logical AND. Words prefixed with a minus must
3204 not occur in the entry. Words without a prefix or prefixed with a plus
3205 must occur in the entry. Matching is case-insensitive and the words
3206 are enclosed by word delimiters.
3208 Words enclosed by curly braces are interpreted as regular expressions
3209 that must or must not match in the entry.
3211 If the search string starts with an asterisk, search only in headlines.
3212 If (possibly after the leading star) the search string starts with an
3213 exclamation mark, this also means to look at TODO entries only, an effect
3214 that can also be achieved with a prefix argument.
3216 This command searches the agenda files, and in addition the files listed
3217 in `org-agenda-text-search-extra-files'."
3218 (interactive "P")
3219 (org-compile-prefix-format 'search)
3220 (org-set-sorting-strategy 'search)
3221 (org-prepare-agenda "SEARCH")
3222 (let* ((props (list 'face nil
3223 'done-face 'org-agenda-done
3224 'org-not-done-regexp org-not-done-regexp
3225 'org-todo-regexp org-todo-regexp
3226 'org-complex-heading-regexp org-complex-heading-regexp
3227 'mouse-face 'highlight
3228 'help-echo (format "mouse-2 or RET jump to location")))
3229 regexp rtn rtnall files file pos
3230 marker category tags c neg re as-words
3231 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3232 (unless (and (not edit-at)
3233 (stringp string)
3234 (string-match "\\S-" string))
3235 (setq string (read-string "[+-]Word/{Regexp} ...: "
3236 (cond
3237 ((integerp edit-at) (cons string edit-at))
3238 (edit-at string))
3239 'org-agenda-search-history)))
3240 (org-set-local 'org-todo-only todo-only)
3241 (setq org-agenda-redo-command
3242 (list 'org-search-view (if todo-only t nil) string
3243 '(if current-prefix-arg 1 nil)))
3244 (setq org-agenda-query-string string)
3246 (if (equal (string-to-char string) ?*)
3247 (setq hdl-only t
3248 words (substring string 1))
3249 (setq words string))
3250 (when (equal (string-to-char words) ?!)
3251 (setq todo-only t
3252 words (substring words 1)))
3253 (if (or org-agenda-search-view-search-words-only
3254 (member (string-to-char string) '(?- ?+)))
3255 (setq as-words t))
3256 (setq words (org-split-string words))
3257 (if as-words
3258 (mapc (lambda (w)
3259 (setq c (string-to-char w))
3260 (if (equal c ?-)
3261 (setq neg t w (substring w 1))
3262 (if (equal c ?+)
3263 (setq neg nil w (substring w 1))
3264 (setq neg nil)))
3265 (if (string-match "\\`{.*}\\'" w)
3266 (setq re (substring w 1 -1))
3267 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
3268 (if neg (push re regexps-) (push re regexps+)))
3269 words)
3270 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3271 regexps+))
3272 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3273 (if (not regexps+)
3274 (setq regexp (concat "^" org-outline-regexp))
3275 (setq regexp (pop regexps+))
3276 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3277 regexp))))
3278 (setq files (org-agenda-files nil 'ifmode))
3279 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3280 (pop org-agenda-text-search-extra-files)
3281 (setq files (org-add-archive-files files)))
3282 (setq files (append files org-agenda-text-search-extra-files)
3283 rtnall nil)
3284 (while (setq file (pop files))
3285 (setq ee nil)
3286 (catch 'nextfile
3287 (org-check-agenda-file file)
3288 (setq buffer (if (file-exists-p file)
3289 (org-get-agenda-file-buffer file)
3290 (error "No such file %s" file)))
3291 (if (not buffer)
3292 ;; If file does not exist, make sure an error message is sent
3293 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3294 file))))
3295 (with-current-buffer buffer
3296 (with-syntax-table (org-search-syntax-table)
3297 (unless (org-mode-p)
3298 (error "Agenda file %s is not in `org-mode'" file))
3299 (let ((case-fold-search t))
3300 (save-excursion
3301 (save-restriction
3302 (if org-agenda-restrict
3303 (narrow-to-region org-agenda-restrict-begin
3304 org-agenda-restrict-end)
3305 (widen))
3306 (goto-char (point-min))
3307 (unless (or (org-on-heading-p)
3308 (outline-next-heading))
3309 (throw 'nextfile t))
3310 (goto-char (max (point-min) (1- (point))))
3311 (while (re-search-forward regexp nil t)
3312 (org-back-to-heading t)
3313 (skip-chars-forward "* ")
3314 (setq beg (point-at-bol)
3315 beg1 (point)
3316 end (progn (outline-next-heading) (point)))
3317 (catch :skip
3318 (goto-char beg)
3319 (org-agenda-skip)
3320 (setq str (buffer-substring-no-properties
3321 (point-at-bol)
3322 (if hdl-only (point-at-eol) end)))
3323 (mapc (lambda (wr) (when (string-match wr str)
3324 (goto-char (1- end))
3325 (throw :skip t)))
3326 regexps-)
3327 (mapc (lambda (wr) (unless (string-match wr str)
3328 (goto-char (1- end))
3329 (throw :skip t)))
3330 (if todo-only
3331 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3332 regexps+)
3333 regexps+))
3334 (goto-char beg)
3335 (setq marker (org-agenda-new-marker (point))
3336 category (org-get-category)
3337 tags (org-get-tags-at (point))
3338 txt (org-format-agenda-item
3340 (buffer-substring-no-properties
3341 beg1 (point-at-eol))
3342 category tags))
3343 (org-add-props txt props
3344 'org-marker marker 'org-hd-marker marker
3345 'org-todo-regexp org-todo-regexp
3346 'org-complex-heading-regexp org-complex-heading-regexp
3347 'priority 1000 'org-category category
3348 'type "search")
3349 (push txt ee)
3350 (goto-char (1- end))))))))))
3351 (setq rtn (nreverse ee))
3352 (setq rtnall (append rtnall rtn)))
3353 (if org-agenda-overriding-header
3354 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3355 nil 'face 'org-agenda-structure) "\n")
3356 (insert "Search words: ")
3357 (add-text-properties (point-min) (1- (point))
3358 (list 'face 'org-agenda-structure))
3359 (setq pos (point))
3360 (insert string "\n")
3361 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3362 (setq pos (point))
3363 (unless org-agenda-multi
3364 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3365 (add-text-properties pos (1- (point))
3366 (list 'face 'org-agenda-structure))))
3367 (org-agenda-mark-header-line (point-min))
3368 (when rtnall
3369 (insert (org-finalize-agenda-entries rtnall) "\n"))
3370 (goto-char (point-min))
3371 (or org-agenda-multi (org-fit-agenda-window))
3372 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3373 (org-finalize-agenda)
3374 (setq buffer-read-only t)))
3376 ;;; Agenda TODO list
3378 (defvar org-select-this-todo-keyword nil)
3379 (defvar org-last-arg nil)
3381 ;;;###autoload
3382 (defun org-todo-list (arg)
3383 "Show all TODO entries from all agenda file in a single list.
3384 The prefix arg can be used to select a specific TODO keyword and limit
3385 the list to these. When using \\[universal-argument], you will be prompted
3386 for a keyword. A numeric prefix directly selects the Nth keyword in
3387 `org-todo-keywords-1'."
3388 (interactive "P")
3389 (require 'calendar)
3390 (org-compile-prefix-format 'todo)
3391 (org-set-sorting-strategy 'todo)
3392 (org-prepare-agenda "TODO")
3393 (let* ((today (time-to-days (current-time)))
3394 (date (calendar-gregorian-from-absolute today))
3395 (kwds org-todo-keywords-for-agenda)
3396 (completion-ignore-case t)
3397 (org-select-this-todo-keyword
3398 (if (stringp arg) arg
3399 (and arg (integerp arg) (> arg 0)
3400 (nth (1- arg) kwds))))
3401 rtn rtnall files file pos)
3402 (when (equal arg '(4))
3403 (setq org-select-this-todo-keyword
3404 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3405 (mapcar 'list kwds) nil nil)))
3406 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3407 (org-set-local 'org-last-arg arg)
3408 (setq org-agenda-redo-command
3409 '(org-todo-list (or current-prefix-arg org-last-arg)))
3410 (setq files (org-agenda-files nil 'ifmode)
3411 rtnall nil)
3412 (while (setq file (pop files))
3413 (catch 'nextfile
3414 (org-check-agenda-file file)
3415 (setq rtn (org-agenda-get-day-entries file date :todo))
3416 (setq rtnall (append rtnall rtn))))
3417 (if org-agenda-overriding-header
3418 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3419 nil 'face 'org-agenda-structure) "\n")
3420 (insert "Global list of TODO items of type: ")
3421 (add-text-properties (point-min) (1- (point))
3422 (list 'face 'org-agenda-structure
3423 'short-heading
3424 (concat "ToDo: "
3425 (or org-select-this-todo-keyword "ALL"))))
3426 (org-agenda-mark-header-line (point-min))
3427 (setq pos (point))
3428 (insert (or org-select-this-todo-keyword "ALL") "\n")
3429 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3430 (setq pos (point))
3431 (unless org-agenda-multi
3432 (insert "Available with `N r': (0)ALL")
3433 (let ((n 0) s)
3434 (mapc (lambda (x)
3435 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3436 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3437 (insert "\n "))
3438 (insert " " s))
3439 kwds))
3440 (insert "\n"))
3441 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3442 (org-agenda-mark-header-line (point-min))
3443 (when rtnall
3444 (insert (org-finalize-agenda-entries rtnall) "\n"))
3445 (goto-char (point-min))
3446 (or org-agenda-multi (org-fit-agenda-window))
3447 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3448 (org-finalize-agenda)
3449 (setq buffer-read-only t)))
3451 ;;; Agenda tags match
3453 ;;;###autoload
3454 (defun org-tags-view (&optional todo-only match)
3455 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3456 The prefix arg TODO-ONLY limits the search to TODO entries."
3457 (interactive "P")
3458 (org-compile-prefix-format 'tags)
3459 (org-set-sorting-strategy 'tags)
3460 (let* ((org-tags-match-list-sublevels
3461 ;?????? (if todo-only t org-tags-match-list-sublevels))
3462 org-tags-match-list-sublevels)
3463 (completion-ignore-case t)
3464 rtn rtnall files file pos matcher
3465 buffer)
3466 (setq matcher (org-make-tags-matcher match)
3467 match (car matcher) matcher (cdr matcher))
3468 (org-prepare-agenda (concat "TAGS " match))
3469 (setq org-agenda-query-string match)
3470 (setq org-agenda-redo-command
3471 (list 'org-tags-view (list 'quote todo-only)
3472 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3473 (setq files (org-agenda-files nil 'ifmode)
3474 rtnall nil)
3475 (while (setq file (pop files))
3476 (catch 'nextfile
3477 (org-check-agenda-file file)
3478 (setq buffer (if (file-exists-p file)
3479 (org-get-agenda-file-buffer file)
3480 (error "No such file %s" file)))
3481 (if (not buffer)
3482 ;; If file does not exist, error message to agenda
3483 (setq rtn (list
3484 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3485 rtnall (append rtnall rtn))
3486 (with-current-buffer buffer
3487 (unless (org-mode-p)
3488 (error "Agenda file %s is not in `org-mode'" file))
3489 (save-excursion
3490 (save-restriction
3491 (if org-agenda-restrict
3492 (narrow-to-region org-agenda-restrict-begin
3493 org-agenda-restrict-end)
3494 (widen))
3495 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3496 (setq rtnall (append rtnall rtn))))))))
3497 (if org-agenda-overriding-header
3498 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3499 nil 'face 'org-agenda-structure) "\n")
3500 (insert "Headlines with TAGS match: ")
3501 (add-text-properties (point-min) (1- (point))
3502 (list 'face 'org-agenda-structure
3503 'short-heading
3504 (concat "Match: " match)))
3505 (setq pos (point))
3506 (insert match "\n")
3507 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3508 (setq pos (point))
3509 (unless org-agenda-multi
3510 (insert "Press `C-u r' to search again with new search string\n"))
3511 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3512 (org-agenda-mark-header-line (point-min))
3513 (when rtnall
3514 (insert (org-finalize-agenda-entries rtnall) "\n"))
3515 (goto-char (point-min))
3516 (or org-agenda-multi (org-fit-agenda-window))
3517 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3518 (org-finalize-agenda)
3519 (setq buffer-read-only t)))
3521 ;;; Agenda Finding stuck projects
3523 (defvar org-agenda-skip-regexp nil
3524 "Regular expression used in skipping subtrees for the agenda.
3525 This is basically a temporary global variable that can be set and then
3526 used by user-defined selections using `org-agenda-skip-function'.")
3528 (defvar org-agenda-overriding-header nil
3529 "When this is set during todo and tags searches, will replace header.
3530 This variable should not be set directly, but custom commands can bind it
3531 in the options section.")
3533 (defun org-agenda-skip-entry-when-regexp-matches ()
3534 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3535 If yes, it returns the end position of this entry, causing agenda commands
3536 to skip the entry but continuing the search in the subtree. This is a
3537 function that can be put into `org-agenda-skip-function' for the duration
3538 of a command."
3539 (let ((end (save-excursion (org-end-of-subtree t)))
3540 skip)
3541 (save-excursion
3542 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3543 (and skip end)))
3545 (defun org-agenda-skip-subtree-when-regexp-matches ()
3546 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3547 If yes, it returns the end position of this tree, causing agenda commands
3548 to skip this subtree. This is a function that can be put into
3549 `org-agenda-skip-function' for the duration of a command."
3550 (let ((end (save-excursion (org-end-of-subtree t)))
3551 skip)
3552 (save-excursion
3553 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3554 (and skip end)))
3556 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3557 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3558 If yes, it returns the end position of the current entry (NOT the tree),
3559 causing agenda commands to skip the entry but continuing the search in
3560 the subtree. This is a function that can be put into
3561 `org-agenda-skip-function' for the duration of a command. An important
3562 use of this function is for the stuck project list."
3563 (let ((end (save-excursion (org-end-of-subtree t)))
3564 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3565 skip)
3566 (save-excursion
3567 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3568 (and skip entry-end)))
3570 (defun org-agenda-skip-entry-if (&rest conditions)
3571 "Skip entry if any of CONDITIONS is true.
3572 See `org-agenda-skip-if' for details."
3573 (org-agenda-skip-if nil conditions))
3575 (defun org-agenda-skip-subtree-if (&rest conditions)
3576 "Skip entry if any of CONDITIONS is true.
3577 See `org-agenda-skip-if' for details."
3578 (org-agenda-skip-if t conditions))
3580 (defun org-agenda-skip-if (subtree conditions)
3581 "Checks current entity for CONDITIONS.
3582 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3583 the entry, i.e. the text before the next heading is checked.
3585 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3586 from different tests. Valid conditions are:
3588 scheduled Check if there is a scheduled cookie
3589 notscheduled Check if there is no scheduled cookie
3590 deadline Check if there is a deadline
3591 notdeadline Check if there is no deadline
3592 timestamp Check if there is a timestamp (also deadline or scheduled)
3593 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3594 regexp Check if regexp matches
3595 notregexp Check if regexp does not match.
3597 The regexp is taken from the conditions list, it must come right after
3598 the `regexp' or `notregexp' element.
3600 If any of these conditions is met, this function returns the end point of
3601 the entity, causing the search to continue from there. This is a function
3602 that can be put into `org-agenda-skip-function' for the duration of a command."
3603 (let (beg end m)
3604 (org-back-to-heading t)
3605 (setq beg (point)
3606 end (if subtree
3607 (progn (org-end-of-subtree t) (point))
3608 (progn (outline-next-heading) (1- (point)))))
3609 (goto-char beg)
3610 (and
3612 (and (memq 'scheduled conditions)
3613 (re-search-forward org-scheduled-time-regexp end t))
3614 (and (memq 'notscheduled conditions)
3615 (not (re-search-forward org-scheduled-time-regexp end t)))
3616 (and (memq 'deadline conditions)
3617 (re-search-forward org-deadline-time-regexp end t))
3618 (and (memq 'notdeadline conditions)
3619 (not (re-search-forward org-deadline-time-regexp end t)))
3620 (and (memq 'timestamp conditions)
3621 (re-search-forward org-ts-regexp end t))
3622 (and (memq 'nottimestamp conditions)
3623 (not (re-search-forward org-ts-regexp end t)))
3624 (and (setq m (memq 'regexp conditions))
3625 (stringp (nth 1 m))
3626 (re-search-forward (nth 1 m) end t))
3627 (and (setq m (memq 'notregexp conditions))
3628 (stringp (nth 1 m))
3629 (not (re-search-forward (nth 1 m) end t))))
3630 end)))
3632 ;;;###autoload
3633 (defun org-agenda-list-stuck-projects (&rest ignore)
3634 "Create agenda view for projects that are stuck.
3635 Stuck projects are project that have no next actions. For the definitions
3636 of what a project is and how to check if it stuck, customize the variable
3637 `org-stuck-projects'.
3638 MATCH is being ignored."
3639 (interactive)
3640 (let* ((org-agenda-skip-function
3641 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3642 ;; We could have used org-agenda-skip-if here.
3643 (org-agenda-overriding-header
3644 (or org-agenda-overriding-header "List of stuck projects: "))
3645 (matcher (nth 0 org-stuck-projects))
3646 (todo (nth 1 org-stuck-projects))
3647 (todo-wds (if (member "*" todo)
3648 (progn
3649 (org-prepare-agenda-buffers (org-agenda-files
3650 nil 'ifmode))
3651 (org-delete-all
3652 org-done-keywords-for-agenda
3653 (copy-sequence org-todo-keywords-for-agenda)))
3654 todo))
3655 (todo-re (concat "^\\*+[ \t]+\\("
3656 (mapconcat 'identity todo-wds "\\|")
3657 "\\)\\>"))
3658 (tags (nth 2 org-stuck-projects))
3659 (tags-re (if (member "*" tags)
3660 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3661 (if tags
3662 (concat "^\\*+ .*:\\("
3663 (mapconcat 'identity tags "\\|")
3664 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3665 (gen-re (nth 3 org-stuck-projects))
3666 (re-list
3667 (delq nil
3668 (list
3669 (if todo todo-re)
3670 (if tags tags-re)
3671 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3672 gen-re)))))
3673 (setq org-agenda-skip-regexp
3674 (if re-list
3675 (mapconcat 'identity re-list "\\|")
3676 (error "No information how to identify unstuck projects")))
3677 (org-tags-view nil matcher)
3678 (with-current-buffer org-agenda-buffer-name
3679 (setq org-agenda-redo-command
3680 '(org-agenda-list-stuck-projects
3681 (or current-prefix-arg org-last-arg))))))
3683 ;;; Diary integration
3685 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3686 (defvar list-diary-entries-hook)
3688 (defun org-get-entries-from-diary (date)
3689 "Get the (Emacs Calendar) diary entries for DATE."
3690 (require 'diary-lib)
3691 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3692 (fancy-diary-buffer diary-fancy-buffer)
3693 (diary-display-hook '(fancy-diary-display))
3694 (diary-display-function 'fancy-diary-display)
3695 (pop-up-frames nil)
3696 (list-diary-entries-hook
3697 (cons 'org-diary-default-entry list-diary-entries-hook))
3698 (diary-file-name-prefix-function nil) ; turn this feature off
3699 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3700 entries
3701 (org-disable-agenda-to-diary t))
3702 (save-excursion
3703 (save-window-excursion
3704 (funcall (if (fboundp 'diary-list-entries)
3705 'diary-list-entries 'list-diary-entries)
3706 date 1)))
3707 (if (not (get-buffer diary-fancy-buffer))
3708 (setq entries nil)
3709 (with-current-buffer diary-fancy-buffer
3710 (setq buffer-read-only nil)
3711 (if (zerop (buffer-size))
3712 ;; No entries
3713 (setq entries nil)
3714 ;; Omit the date and other unnecessary stuff
3715 (org-agenda-cleanup-fancy-diary)
3716 ;; Add prefix to each line and extend the text properties
3717 (if (zerop (buffer-size))
3718 (setq entries nil)
3719 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3720 (set-buffer-modified-p nil)
3721 (kill-buffer diary-fancy-buffer)))
3722 (when entries
3723 (setq entries (org-split-string entries "\n"))
3724 (setq entries
3725 (mapcar
3726 (lambda (x)
3727 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3728 ;; Extend the text properties to the beginning of the line
3729 (org-add-props x (text-properties-at (1- (length x)) x)
3730 'type "diary" 'date date))
3731 entries)))))
3733 (defvar org-agenda-cleanup-fancy-diary-hook nil
3734 "Hook run when the fancy diary buffer is cleaned up.")
3736 (defun org-agenda-cleanup-fancy-diary ()
3737 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3738 This gets rid of the date, the underline under the date, and
3739 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3740 date. It also removes lines that contain only whitespace."
3741 (goto-char (point-min))
3742 (if (looking-at ".*?:[ \t]*")
3743 (progn
3744 (replace-match "")
3745 (re-search-forward "\n=+$" nil t)
3746 (replace-match "")
3747 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3748 (re-search-forward "\n=+$" nil t)
3749 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3750 (goto-char (point-min))
3751 (while (re-search-forward "^ +\n" nil t)
3752 (replace-match ""))
3753 (goto-char (point-min))
3754 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3755 (replace-match ""))
3756 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3758 ;; Make sure entries from the diary have the right text properties.
3759 (eval-after-load "diary-lib"
3760 '(if (boundp 'diary-modify-entry-list-string-function)
3761 ;; We can rely on the hook, nothing to do
3763 ;; Hook not available, must use advice to make this work
3764 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3765 "Make the position visible."
3766 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3767 (stringp string)
3768 buffer-file-name)
3769 (setq string (org-modify-diary-entry-string string))))))
3771 (defun org-modify-diary-entry-string (string)
3772 "Add text properties to string, allowing org-mode to act on it."
3773 (org-add-props string nil
3774 'mouse-face 'highlight
3775 'help-echo (if buffer-file-name
3776 (format "mouse-2 or RET jump to diary file %s"
3777 (abbreviate-file-name buffer-file-name))
3779 'org-agenda-diary-link t
3780 'org-marker (org-agenda-new-marker (point-at-bol))))
3782 (defun org-diary-default-entry ()
3783 "Add a dummy entry to the diary.
3784 Needed to avoid empty dates which mess up holiday display."
3785 ;; Catch the error if dealing with the new add-to-diary-alist
3786 (when org-disable-agenda-to-diary
3787 (condition-case nil
3788 (org-add-to-diary-list original-date "Org-mode dummy" "")
3789 (error
3790 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3792 (defun org-add-to-diary-list (&rest args)
3793 (if (fboundp 'diary-add-to-list)
3794 (apply 'diary-add-to-list args)
3795 (apply 'add-to-diary-list args)))
3797 ;;;###autoload
3798 (defun org-diary (&rest args)
3799 "Return diary information from org-files.
3800 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3801 It accesses org files and extracts information from those files to be
3802 listed in the diary. The function accepts arguments specifying what
3803 items should be listed. The following arguments are allowed:
3805 :timestamp List the headlines of items containing a date stamp or
3806 date range matching the selected date. Deadlines will
3807 also be listed, on the expiration day.
3809 :sexp List entries resulting from diary-like sexps.
3811 :deadline List any deadlines past due, or due within
3812 `org-deadline-warning-days'. The listing occurs only
3813 in the diary for *today*, not at any other date. If
3814 an entry is marked DONE, it is no longer listed.
3816 :scheduled List all items which are scheduled for the given date.
3817 The diary for *today* also contains items which were
3818 scheduled earlier and are not yet marked DONE.
3820 :todo List all TODO items from the org-file. This may be a
3821 long list - so this is not turned on by default.
3822 Like deadlines, these entries only show up in the
3823 diary for *today*, not at any other date.
3825 The call in the diary file should look like this:
3827 &%%(org-diary) ~/path/to/some/orgfile.org
3829 Use a separate line for each org file to check. Or, if you omit the file name,
3830 all files listed in `org-agenda-files' will be checked automatically:
3832 &%%(org-diary)
3834 If you don't give any arguments (as in the example above), the default
3835 arguments (:deadline :scheduled :timestamp :sexp) are used.
3836 So the example above may also be written as
3838 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3840 The function expects the lisp variables `entry' and `date' to be provided
3841 by the caller, because this is how the calendar works. Don't use this
3842 function from a program - use `org-agenda-get-day-entries' instead."
3843 (when (> (- (org-float-time)
3844 org-agenda-last-marker-time)
3846 (org-agenda-reset-markers))
3847 (org-compile-prefix-format 'agenda)
3848 (org-set-sorting-strategy 'agenda)
3849 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3850 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3851 (list entry)
3852 (org-agenda-files t)))
3853 file rtn results)
3854 (org-prepare-agenda-buffers files)
3855 ;; If this is called during org-agenda, don't return any entries to
3856 ;; the calendar. Org Agenda will list these entries itself.
3857 (if org-disable-agenda-to-diary (setq files nil))
3858 (while (setq file (pop files))
3859 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3860 (setq results (append results rtn)))
3861 (if results
3862 (concat (org-finalize-agenda-entries results) "\n"))))
3864 ;;; Agenda entry finders
3866 (defun org-agenda-get-day-entries (file date &rest args)
3867 "Does the work for `org-diary' and `org-agenda'.
3868 FILE is the path to a file to be checked for entries. DATE is date like
3869 the one returned by `calendar-current-date'. ARGS are symbols indicating
3870 which kind of entries should be extracted. For details about these, see
3871 the documentation of `org-diary'."
3872 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3873 (let* ((org-startup-folded nil)
3874 (org-startup-align-all-tables nil)
3875 (buffer (if (file-exists-p file)
3876 (org-get-agenda-file-buffer file)
3877 (error "No such file %s" file)))
3878 arg results rtn deadline-results)
3879 (if (not buffer)
3880 ;; If file does not exist, make sure an error message ends up in diary
3881 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3882 (with-current-buffer buffer
3883 (unless (org-mode-p)
3884 (error "Agenda file %s is not in `org-mode'" file))
3885 (let ((case-fold-search nil))
3886 (save-excursion
3887 (save-restriction
3888 (if org-agenda-restrict
3889 (narrow-to-region org-agenda-restrict-begin
3890 org-agenda-restrict-end)
3891 (widen))
3892 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3893 (while (setq arg (pop args))
3894 (cond
3895 ((and (eq arg :todo)
3896 (equal date (calendar-current-date)))
3897 (setq rtn (org-agenda-get-todos))
3898 (setq results (append results rtn)))
3899 ((eq arg :timestamp)
3900 (setq rtn (org-agenda-get-blocks))
3901 (setq results (append results rtn))
3902 (setq rtn (org-agenda-get-timestamps))
3903 (setq results (append results rtn)))
3904 ((eq arg :sexp)
3905 (setq rtn (org-agenda-get-sexps))
3906 (setq results (append results rtn)))
3907 ((eq arg :scheduled)
3908 (setq rtn (org-agenda-get-scheduled deadline-results))
3909 (setq results (append results rtn)))
3910 ((eq arg :closed)
3911 (setq rtn (org-agenda-get-progress))
3912 (setq results (append results rtn)))
3913 ((eq arg :deadline)
3914 (setq rtn (org-agenda-get-deadlines))
3915 (setq deadline-results (copy-sequence rtn))
3916 (setq results (append results rtn))))))))
3917 results))))
3919 (defun org-agenda-get-todos ()
3920 "Return the TODO information for agenda display."
3921 (let* ((props (list 'face nil
3922 'done-face 'org-agenda-done
3923 'org-not-done-regexp org-not-done-regexp
3924 'org-todo-regexp org-todo-regexp
3925 'org-complex-heading-regexp org-complex-heading-regexp
3926 'mouse-face 'highlight
3927 'help-echo
3928 (format "mouse-2 or RET jump to org file %s"
3929 (abbreviate-file-name buffer-file-name))))
3930 (regexp (concat "^\\*+[ \t]+\\("
3931 (if org-select-this-todo-keyword
3932 (if (equal org-select-this-todo-keyword "*")
3933 org-todo-regexp
3934 (concat "\\<\\("
3935 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3936 "\\)\\>"))
3937 org-not-done-regexp)
3938 "[^\n\r]*\\)"))
3939 marker priority category tags todo-state
3940 ee txt beg end)
3941 (goto-char (point-min))
3942 (while (re-search-forward regexp nil t)
3943 (catch :skip
3944 (save-match-data
3945 (beginning-of-line)
3946 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
3947 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
3948 (goto-char (1+ beg))
3949 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3950 (throw :skip nil)))
3951 (goto-char beg)
3952 (org-agenda-skip)
3953 (goto-char (match-beginning 1))
3954 (setq marker (org-agenda-new-marker (match-beginning 0))
3955 category (org-get-category)
3956 txt (match-string 1)
3957 tags (org-get-tags-at (point))
3958 txt (org-format-agenda-item "" txt category tags)
3959 priority (1+ (org-get-priority txt))
3960 todo-state (org-get-todo-state))
3961 (org-add-props txt props
3962 'org-marker marker 'org-hd-marker marker
3963 'priority priority 'org-category category
3964 'type "todo" 'todo-state todo-state)
3965 (push txt ee)
3966 (if org-agenda-todo-list-sublevels
3967 (goto-char (match-end 1))
3968 (org-end-of-subtree 'invisible))))
3969 (nreverse ee)))
3971 ;;;###autoload
3972 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
3973 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3974 (when (or org-agenda-todo-ignore-with-date
3975 org-agenda-todo-ignore-scheduled
3976 org-agenda-todo-ignore-deadlines)
3977 (setq end (or end (save-excursion (outline-next-heading) (point))))
3978 (save-excursion
3979 (or (and org-agenda-todo-ignore-with-date
3980 (re-search-forward org-ts-regexp end t))
3981 (and org-agenda-todo-ignore-scheduled
3982 (re-search-forward org-scheduled-time-regexp end t))
3983 (and org-agenda-todo-ignore-deadlines
3984 (re-search-forward org-deadline-time-regexp end t)
3985 (org-deadline-close (match-string 1)))))))
3987 (defconst org-agenda-no-heading-message
3988 "No heading for this item in buffer or region.")
3990 (defun org-agenda-get-timestamps ()
3991 "Return the date stamp information for agenda display."
3992 (let* ((props (list 'face nil
3993 'org-not-done-regexp org-not-done-regexp
3994 'org-todo-regexp org-todo-regexp
3995 'org-complex-heading-regexp org-complex-heading-regexp
3996 'mouse-face 'highlight
3997 'help-echo
3998 (format "mouse-2 or RET jump to org file %s"
3999 (abbreviate-file-name buffer-file-name))))
4000 (d1 (calendar-absolute-from-gregorian date))
4001 (remove-re
4002 (concat
4003 (regexp-quote
4004 (format-time-string
4005 "<%Y-%m-%d"
4006 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4007 ".*?>"))
4008 (regexp
4009 (concat
4010 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4011 (regexp-quote
4012 (substring
4013 (format-time-string
4014 (car org-time-stamp-formats)
4015 (apply 'encode-time ; DATE bound by calendar
4016 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4017 1 11))
4018 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4019 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4020 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4021 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4022 todo-state end-of-match)
4023 (goto-char (point-min))
4024 (while (setq end-of-match (re-search-forward regexp nil t))
4025 (setq b0 (match-beginning 0)
4026 b3 (match-beginning 3) e3 (match-end 3))
4027 (catch :skip
4028 (and (org-at-date-range-p) (throw :skip nil))
4029 (org-agenda-skip)
4030 (if (and (match-end 1)
4031 (not (= d1 (org-time-string-to-absolute
4032 (match-string 1) d1 nil
4033 org-agenda-repeating-timestamp-show-all))))
4034 (throw :skip nil))
4035 (if (and e3
4036 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4037 (throw :skip nil))
4038 (setq tmp (buffer-substring (max (point-min)
4039 (- b0 org-ds-keyword-length))
4041 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4042 inactivep (= (char-after b0) ?\[)
4043 deadlinep (string-match org-deadline-regexp tmp)
4044 scheduledp (string-match org-scheduled-regexp tmp)
4045 closedp (and org-agenda-include-inactive-timestamps
4046 (string-match org-closed-string tmp))
4047 clockp (and org-agenda-include-inactive-timestamps
4048 (or (string-match org-clock-string tmp)
4049 (string-match "]-+\\'" tmp)))
4050 todo-state (org-get-todo-state)
4051 donep (member todo-state org-done-keywords))
4052 (if (or scheduledp deadlinep closedp clockp
4053 (and donep org-agenda-skip-timestamp-if-done))
4054 (throw :skip t))
4055 (if (string-match ">" timestr)
4056 ;; substring should only run to end of time stamp
4057 (setq timestr (substring timestr 0 (match-end 0))))
4058 (setq marker (org-agenda-new-marker b0)
4059 category (org-get-category b0))
4060 (save-excursion
4061 (if (not (re-search-backward "^\\*+ " nil t))
4062 (setq txt org-agenda-no-heading-message)
4063 (goto-char (match-beginning 0))
4064 (setq hdmarker (org-agenda-new-marker)
4065 tags (org-get-tags-at))
4066 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4067 (setq head (match-string 1))
4068 (setq txt (org-format-agenda-item
4069 (if inactivep "[" nil)
4070 head category tags timestr nil
4071 remove-re)))
4072 (setq priority (org-get-priority txt))
4073 (org-add-props txt props
4074 'org-marker marker 'org-hd-marker hdmarker)
4075 (org-add-props txt nil 'priority priority
4076 'org-category category 'date date
4077 'todo-state todo-state
4078 'type "timestamp")
4079 (push txt ee))
4080 (if org-agenda-skip-additional-timestamps-same-entry
4081 (outline-next-heading)
4082 (goto-char end-of-match))))
4083 (nreverse ee)))
4085 (defun org-agenda-get-sexps ()
4086 "Return the sexp information for agenda display."
4087 (require 'diary-lib)
4088 (let* ((props (list 'face nil
4089 'mouse-face 'highlight
4090 'help-echo
4091 (format "mouse-2 or RET jump to org file %s"
4092 (abbreviate-file-name buffer-file-name))))
4093 (regexp "^&?%%(")
4094 marker category ee txt tags entry result beg b sexp sexp-entry
4095 todo-state)
4096 (goto-char (point-min))
4097 (while (re-search-forward regexp nil t)
4098 (catch :skip
4099 (org-agenda-skip)
4100 (setq beg (match-beginning 0))
4101 (goto-char (1- (match-end 0)))
4102 (setq b (point))
4103 (forward-sexp 1)
4104 (setq sexp (buffer-substring b (point)))
4105 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4106 (org-trim (match-string 1))
4107 ""))
4108 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4109 (when result
4110 (setq marker (org-agenda-new-marker beg)
4111 category (org-get-category beg)
4112 todo-state (org-get-todo-state))
4114 (if (string-match "\\S-" result)
4115 (setq txt result)
4116 (setq txt "SEXP entry returned empty string"))
4118 (setq txt (org-format-agenda-item
4119 "" txt category tags 'time))
4120 (org-add-props txt props 'org-marker marker)
4121 (org-add-props txt nil
4122 'org-category category 'date date 'todo-state todo-state
4123 'type "sexp")
4124 (push txt ee))))
4125 (nreverse ee)))
4127 (defalias 'org-get-closed 'org-agenda-get-progress)
4128 (defun org-agenda-get-progress ()
4129 "Return the logged TODO entries for agenda display."
4130 (let* ((props (list 'mouse-face 'highlight
4131 'org-not-done-regexp org-not-done-regexp
4132 'org-todo-regexp org-todo-regexp
4133 'org-complex-heading-regexp org-complex-heading-regexp
4134 'help-echo
4135 (format "mouse-2 or RET jump to org file %s"
4136 (abbreviate-file-name buffer-file-name))))
4137 (items (if (consp org-agenda-show-log)
4138 org-agenda-show-log
4139 org-agenda-log-mode-items))
4140 (parts
4141 (delq nil
4142 (list
4143 (if (memq 'closed items) (concat "\\<" org-closed-string))
4144 (if (memq 'clock items) (concat "\\<" org-clock-string))
4145 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4146 (parts-re (if parts (mapconcat 'identity parts "\\|")
4147 (error "`org-agenda-log-mode-items' is empty")))
4148 (regexp (concat
4149 "\\(" parts-re "\\)"
4150 " *\\["
4151 (regexp-quote
4152 (substring
4153 (format-time-string
4154 (car org-time-stamp-formats)
4155 (apply 'encode-time ; DATE bound by calendar
4156 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4157 1 11))))
4158 (org-agenda-search-headline-for-time nil)
4159 marker hdmarker priority category tags closedp statep clockp state
4160 ee txt extra timestr rest clocked)
4161 (goto-char (point-min))
4162 (while (re-search-forward regexp nil t)
4163 (catch :skip
4164 (org-agenda-skip)
4165 (setq marker (org-agenda-new-marker (match-beginning 0))
4166 closedp (equal (match-string 1) org-closed-string)
4167 statep (equal (string-to-char (match-string 1)) ?-)
4168 clockp (not (or closedp statep))
4169 state (and statep (match-string 2))
4170 category (org-get-category (match-beginning 0))
4171 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4173 (when (string-match "\\]" timestr)
4174 ;; substring should only run to end of time stamp
4175 (setq rest (substring timestr (match-end 0))
4176 timestr (substring timestr 0 (match-end 0)))
4177 (if (and (not closedp) (not statep)
4178 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4179 (progn (setq timestr (concat (substring timestr 0 -1)
4180 "-" (match-string 1 rest) "]"))
4181 (setq clocked (match-string 2 rest)))
4182 (setq clocked "-")))
4183 (save-excursion
4184 (cond
4185 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4186 (statep
4187 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4188 (setq extra (match-string 1))))
4189 (clockp
4190 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4191 (setq extra (match-string 1))))
4192 (t (setq extra nil)))
4193 (if (not (re-search-backward "^\\*+ " nil t))
4194 (setq txt org-agenda-no-heading-message)
4195 (goto-char (match-beginning 0))
4196 (setq hdmarker (org-agenda-new-marker)
4197 tags (org-get-tags-at))
4198 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4199 (setq txt (match-string 1))
4200 (when extra
4201 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4202 (setq txt (concat (substring txt 0 (match-beginning 1))
4203 " - " extra " " (match-string 2 txt)))
4204 (setq txt (concat txt " - " extra))))
4205 (setq txt (org-format-agenda-item
4206 (cond
4207 (closedp "Closed: ")
4208 (statep (concat "State: (" state ")"))
4209 (t (concat "Clocked: (" clocked ")")))
4210 txt category tags timestr)))
4211 (setq priority 100000)
4212 (org-add-props txt props
4213 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4214 'priority priority 'org-category category
4215 'type "closed" 'date date
4216 'undone-face 'org-warning 'done-face 'org-agenda-done)
4217 (push txt ee))
4218 (goto-char (point-at-eol))))
4219 (nreverse ee)))
4221 (defun org-agenda-get-deadlines ()
4222 "Return the deadline information for agenda display."
4223 (let* ((props (list 'mouse-face 'highlight
4224 'org-not-done-regexp org-not-done-regexp
4225 'org-todo-regexp org-todo-regexp
4226 'org-complex-heading-regexp org-complex-heading-regexp
4227 'help-echo
4228 (format "mouse-2 or RET jump to org file %s"
4229 (abbreviate-file-name buffer-file-name))))
4230 (regexp org-deadline-time-regexp)
4231 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4232 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4233 d2 diff dfrac wdays pos pos1 category tags
4234 ee txt head face s todo-state upcomingp donep timestr)
4235 (goto-char (point-min))
4236 (while (re-search-forward regexp nil t)
4237 (catch :skip
4238 (org-agenda-skip)
4239 (setq s (match-string 1)
4240 txt nil
4241 pos (1- (match-beginning 1))
4242 d2 (org-time-string-to-absolute
4243 (match-string 1) d1 'past
4244 org-agenda-repeating-timestamp-show-all)
4245 diff (- d2 d1)
4246 wdays (org-get-wdays s)
4247 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4248 upcomingp (and todayp (> diff 0)))
4249 ;; When to show a deadline in the calendar:
4250 ;; If the expiration is within wdays warning time.
4251 ;; Past-due deadlines are only shown on the current date
4252 (if (and (or (and (<= diff wdays)
4253 (and todayp (not org-agenda-only-exact-dates)))
4254 (= diff 0)))
4255 (save-excursion
4256 (setq todo-state (org-get-todo-state))
4257 (setq donep (member todo-state org-done-keywords))
4258 (if (and donep
4259 (or org-agenda-skip-deadline-if-done
4260 (not (= diff 0))))
4261 (setq txt nil)
4262 (setq category (org-get-category))
4263 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4264 (setq txt org-agenda-no-heading-message)
4265 (goto-char (match-end 0))
4266 (setq pos1 (match-beginning 0))
4267 (setq tags (org-get-tags-at pos1))
4268 (setq head (buffer-substring-no-properties
4269 (point)
4270 (progn (skip-chars-forward "^\r\n")
4271 (point))))
4272 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4273 (setq timestr
4274 (concat (substring s (match-beginning 1)) " "))
4275 (setq timestr 'time))
4276 (setq txt (org-format-agenda-item
4277 (if (= diff 0)
4278 (car org-agenda-deadline-leaders)
4279 (if (functionp
4280 (nth 1 org-agenda-deadline-leaders))
4281 (funcall
4282 (nth 1 org-agenda-deadline-leaders)
4283 diff date)
4284 (format (nth 1 org-agenda-deadline-leaders)
4285 diff)))
4286 head category tags
4287 (if (not (= diff 0)) nil timestr)))))
4288 (when txt
4289 (setq face (org-agenda-deadline-face dfrac wdays))
4290 (org-add-props txt props
4291 'org-marker (org-agenda-new-marker pos)
4292 'org-hd-marker (org-agenda-new-marker pos1)
4293 'priority (+ (- diff)
4294 (org-get-priority txt))
4295 'org-category category
4296 'todo-state todo-state
4297 'type (if upcomingp "upcoming-deadline" "deadline")
4298 'date (if upcomingp date d2)
4299 'face (if donep 'org-agenda-done face)
4300 'undone-face face 'done-face 'org-agenda-done)
4301 (push txt ee))))))
4302 (nreverse ee)))
4304 (defun org-agenda-deadline-face (fraction &optional wdays)
4305 "Return the face to displaying a deadline item.
4306 FRACTION is what fraction of the head-warning time has passed."
4307 (if (equal wdays 0) (setq fraction 1.))
4308 (let ((faces org-agenda-deadline-faces) f)
4309 (catch 'exit
4310 (while (setq f (pop faces))
4311 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4313 (defun org-agenda-get-scheduled (&optional deadline-results)
4314 "Return the scheduled information for agenda display."
4315 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4316 'org-todo-regexp org-todo-regexp
4317 'org-complex-heading-regexp org-complex-heading-regexp
4318 'done-face 'org-agenda-done
4319 'mouse-face 'highlight
4320 'help-echo
4321 (format "mouse-2 or RET jump to org file %s"
4322 (abbreviate-file-name buffer-file-name))))
4323 (regexp org-scheduled-time-regexp)
4324 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4325 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4327 (deadline-position-alist
4328 (mapcar (lambda (a) (and (setq mm (get-text-property
4329 0 'org-hd-marker a))
4330 (cons (marker-position mm) a)))
4331 deadline-results))
4332 d2 diff pos pos1 category tags donep
4333 ee txt head pastschedp todo-state face timestr s habitp)
4334 (goto-char (point-min))
4335 (while (re-search-forward regexp nil t)
4336 (catch :skip
4337 (org-agenda-skip)
4338 (setq s (match-string 1)
4339 txt nil
4340 pos (1- (match-beginning 1))
4341 d2 (org-time-string-to-absolute
4342 (match-string 1) d1 'past
4343 org-agenda-repeating-timestamp-show-all)
4344 diff (- d2 d1))
4345 (setq pastschedp (and todayp (< diff 0)))
4346 ;; When to show a scheduled item in the calendar:
4347 ;; If it is on or past the date.
4348 (when (or (and (< diff 0)
4349 (< (abs diff) org-scheduled-past-days)
4350 (and todayp (not org-agenda-only-exact-dates)))
4351 (= diff 0))
4352 (save-excursion
4353 (setq todo-state (org-get-todo-state))
4354 (setq donep (member todo-state org-done-keywords))
4355 (setq habitp (and (functionp 'org-is-habit-p)
4356 (org-is-habit-p)))
4357 (if (and donep
4358 (or habitp org-agenda-skip-scheduled-if-done
4359 (not (= diff 0))))
4360 (setq txt nil)
4361 (setq category (org-get-category))
4362 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4363 (setq txt org-agenda-no-heading-message)
4364 (goto-char (match-end 0))
4365 (setq pos1 (match-beginning 0))
4366 (if habitp
4367 (if (or (not org-habit-show-habits)
4368 (and (not todayp)
4369 org-habit-show-habits-only-for-today))
4370 (throw :skip nil))
4371 (if (and
4372 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4373 (and org-agenda-skip-scheduled-if-deadline-is-shown
4374 pastschedp))
4375 (setq mm (assoc pos1 deadline-position-alist)))
4376 (throw :skip nil)))
4377 (setq tags (org-get-tags-at))
4378 (setq head (buffer-substring-no-properties
4379 (point)
4380 (progn (skip-chars-forward "^\r\n") (point))))
4381 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4382 (setq timestr
4383 (concat (substring s (match-beginning 1)) " "))
4384 (setq timestr 'time))
4385 (setq txt (org-format-agenda-item
4386 (if (= diff 0)
4387 (car org-agenda-scheduled-leaders)
4388 (format (nth 1 org-agenda-scheduled-leaders)
4389 (- 1 diff)))
4390 head category tags
4391 (if (not (= diff 0)) nil timestr)
4392 nil nil habitp))))
4393 (when txt
4394 (setq face
4395 (cond
4396 ((and (not habitp) pastschedp)
4397 'org-scheduled-previously)
4398 (todayp 'org-scheduled-today)
4399 (t 'org-scheduled))
4400 habitp (and habitp (org-habit-parse-todo)))
4401 (org-add-props txt props
4402 'undone-face face
4403 'face (if donep 'org-agenda-done face)
4404 'org-marker (org-agenda-new-marker pos)
4405 'org-hd-marker (org-agenda-new-marker pos1)
4406 'type (if pastschedp "past-scheduled" "scheduled")
4407 'date (if pastschedp d2 date)
4408 'priority (if habitp
4409 (org-habit-get-priority habitp)
4410 (+ 94 (- 5 diff) (org-get-priority txt)))
4411 'org-category category
4412 'org-habit-p habitp
4413 'todo-state todo-state)
4414 (push txt ee))))))
4415 (nreverse ee)))
4417 (defun org-agenda-get-blocks ()
4418 "Return the date-range information for agenda display."
4419 (let* ((props (list 'face nil
4420 'org-not-done-regexp org-not-done-regexp
4421 'org-todo-regexp org-todo-regexp
4422 'org-complex-heading-regexp org-complex-heading-regexp
4423 'mouse-face 'highlight
4424 'help-echo
4425 (format "mouse-2 or RET jump to org file %s"
4426 (abbreviate-file-name buffer-file-name))))
4427 (regexp org-tr-regexp)
4428 (d0 (calendar-absolute-from-gregorian date))
4429 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4430 head donep)
4431 (goto-char (point-min))
4432 (while (re-search-forward regexp nil t)
4433 (catch :skip
4434 (org-agenda-skip)
4435 (setq pos (point))
4436 (setq timestr (match-string 0)
4437 s1 (match-string 1)
4438 s2 (match-string 2)
4439 d1 (time-to-days (org-time-string-to-time s1))
4440 d2 (time-to-days (org-time-string-to-time s2)))
4441 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4442 ;; Only allow days between the limits, because the normal
4443 ;; date stamps will catch the limits.
4444 (save-excursion
4445 (setq todo-state (org-get-todo-state))
4446 (setq donep (member todo-state org-done-keywords))
4447 (if (and donep org-agenda-skip-timestamp-if-done)
4448 (throw :skip t))
4449 (setq marker (org-agenda-new-marker (point)))
4450 (setq category (org-get-category))
4451 (if (not (re-search-backward "^\\*+ " nil t))
4452 (setq txt org-agenda-no-heading-message)
4453 (goto-char (match-beginning 0))
4454 (setq hdmarker (org-agenda-new-marker (point)))
4455 (setq tags (org-get-tags-at))
4456 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4457 (setq head (match-string 1))
4458 (setq txt (org-format-agenda-item
4459 (format
4460 (nth (if (= d1 d2) 0 1)
4461 org-agenda-timerange-leaders)
4462 (1+ (- d0 d1)) (1+ (- d2 d1)))
4463 head category tags
4464 (if (= d0 d1) timestr))))
4465 (org-add-props txt props
4466 'org-marker marker 'org-hd-marker hdmarker
4467 'type "block" 'date date
4468 'todo-state todo-state
4469 'priority (org-get-priority txt) 'org-category category)
4470 (push txt ee)))
4471 (goto-char pos)))
4472 ;; Sort the entries by expiration date.
4473 (nreverse ee)))
4475 ;;; Agenda presentation and sorting
4477 (defvar org-prefix-has-time nil
4478 "A flag, set by `org-compile-prefix-format'.
4479 The flag is set if the currently compiled format contains a `%t'.")
4480 (defvar org-prefix-has-tag nil
4481 "A flag, set by `org-compile-prefix-format'.
4482 The flag is set if the currently compiled format contains a `%T'.")
4483 (defvar org-prefix-has-effort nil
4484 "A flag, set by `org-compile-prefix-format'.
4485 The flag is set if the currently compiled format contains a `%e'.")
4486 (defvar org-prefix-category-length nil
4487 "Used by `org-compile-prefix-format' to remember the category field widh.")
4488 (defvar org-prefix-category-max-length nil
4489 "Used by `org-compile-prefix-format' to remember the category field widh.")
4491 (defun org-format-agenda-item (extra txt &optional category tags dotime
4492 noprefix remove-re habitp)
4493 "Format TXT to be inserted into the agenda buffer.
4494 In particular, it adds the prefix and corresponding text properties. EXTRA
4495 must be a string and replaces the `%s' specifier in the prefix format.
4496 CATEGORY (string, symbol or nil) may be used to overrule the default
4497 category taken from local variable or file name. It will replace the `%c'
4498 specifier in the format. DOTIME, when non-nil, indicates that a
4499 time-of-day should be extracted from TXT for sorting of this entry, and for
4500 the `%t' specifier in the format. When DOTIME is a string, this string is
4501 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4502 only the correctly processes TXT should be returned - this is used by
4503 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4504 Any match of REMOVE-RE will be removed from TXT."
4505 (save-match-data
4506 ;; Diary entries sometimes have extra whitespace at the beginning
4507 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4508 (when org-agenda-show-inherited-tags
4509 ;; Fix the tags part in txt
4510 (setq txt (org-agenda-add-inherited-tags txt tags)))
4511 (let* ((category (or category
4512 org-category
4513 (if buffer-file-name
4514 (file-name-sans-extension
4515 (file-name-nondirectory buffer-file-name))
4516 "")))
4517 ;; time, tag, effort are needed for the eval of the prefix format
4518 (tag (if tags (nth (1- (length tags)) tags) ""))
4519 time effort neffort
4520 (ts (if dotime (concat
4521 (if (stringp dotime) dotime "")
4522 (and org-agenda-search-headline-for-time txt))))
4523 (time-of-day (and dotime (org-get-time-of-day ts)))
4524 stamp plain s0 s1 s2 t1 t2 rtn srp l
4525 duration thecategory)
4526 (and (org-mode-p) buffer-file-name
4527 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4528 (when (and dotime time-of-day)
4529 ;; Extract starting and ending time and move them to prefix
4530 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4531 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4532 (setq s0 (match-string 0 ts)
4533 srp (and stamp (match-end 3))
4534 s1 (match-string (if plain 1 2) ts)
4535 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4537 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4538 ;; them, we might want to remove them there to avoid duplication.
4539 ;; The user can turn this off with a variable.
4540 (if (and org-prefix-has-time
4541 org-agenda-remove-times-when-in-prefix (or stamp plain)
4542 (string-match (concat (regexp-quote s0) " *") txt)
4543 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4544 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4545 (= (match-beginning 0) 0)
4547 (setq txt (replace-match "" nil nil txt))))
4548 ;; Normalize the time(s) to 24 hour
4549 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4550 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4551 ;; Compute the duration
4552 (when s1
4553 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4554 (string-to-number (substring s1 3)))
4555 t2 (cond
4556 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4557 (string-to-number (substring s2 3))))
4558 (org-agenda-default-appointment-duration
4559 (+ t1 org-agenda-default-appointment-duration))
4560 (t nil)))
4561 (setq duration (if t2 (- t2 t1)))))
4563 (when (and s1 (not s2) org-agenda-default-appointment-duration
4564 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4565 (let ((m (+ (string-to-number (match-string 2 s1))
4566 (* 60 (string-to-number (match-string 1 s1)))
4567 org-agenda-default-appointment-duration))
4569 (setq h (/ m 60) m (- m (* h 60)))
4570 (setq s2 (format "%02d:%02d" h m))))
4572 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4573 txt)
4574 ;; Tags are in the string
4575 (if (or (eq org-agenda-remove-tags t)
4576 (and org-agenda-remove-tags
4577 org-prefix-has-tag))
4578 (setq txt (replace-match "" t t txt))
4579 (setq txt (replace-match
4580 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4581 (match-string 2 txt))
4582 t t txt))))
4583 (when (org-mode-p)
4584 (setq effort
4585 (condition-case nil
4586 (org-get-effort
4587 (or (get-text-property 0 'org-hd-marker txt)
4588 (get-text-property 0 'org-marker txt)))
4589 (error nil)))
4590 (when effort
4591 (setq neffort (org-hh:mm-string-to-minutes effort)
4592 effort (setq effort (concat "[" effort "]" )))))
4594 (when remove-re
4595 (while (string-match remove-re txt)
4596 (setq txt (replace-match "" t t txt))))
4598 ;; Create the final string
4599 (if noprefix
4600 (setq rtn txt)
4601 ;; Prepare the variables needed in the eval of the compiled format
4602 (setq time (cond (s2 (concat s1 "-" s2))
4603 (s1 (concat s1 "......"))
4604 (t ""))
4605 extra (or (and (not habitp) extra) "")
4606 category (if (symbolp category) (symbol-name category) category)
4607 thecategory (copy-sequence category))
4608 (if (string-match org-bracket-link-regexp category)
4609 (progn
4610 (setq l (if (match-end 3)
4611 (- (match-end 3) (match-beginning 3))
4612 (- (match-end 1) (match-beginning 1))))
4613 (when (< l (or org-prefix-category-length 0))
4614 (setq category (copy-sequence category))
4615 (org-add-props category nil
4616 'extra-space (make-string
4617 (- org-prefix-category-length l 1) ?\ ))))
4618 (if (and org-prefix-category-max-length
4619 (>= (length category) org-prefix-category-max-length))
4620 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4621 ;; Evaluate the compiled format
4622 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4624 ;; And finally add the text properties
4625 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4626 (org-add-props rtn nil
4627 'org-category (if thecategory (downcase thecategory) category)
4628 'tags (mapcar 'org-downcase-keep-props tags)
4629 'org-highest-priority org-highest-priority
4630 'org-lowest-priority org-lowest-priority
4631 'prefix-length (- (length rtn) (length txt))
4632 'time-of-day time-of-day
4633 'duration duration
4634 'effort effort
4635 'effort-minutes neffort
4636 'txt txt
4637 'time time
4638 'extra extra
4639 'dotime dotime))))
4641 (defun org-agenda-add-inherited-tags (txt tags)
4642 "Remove tags string from TXT, and add complete list of tags.
4643 The new list includes inherited tags. If any inherited tags are present,
4644 a double colon separates inherited tags from local tags."
4645 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4646 (setq txt (substring txt 0 (match-beginning 0))))
4647 (when tags
4648 (let ((have-i (get-text-property 0 'inherited (car tags)))
4650 (setq txt (concat txt " :"
4651 (mapconcat
4652 (lambda (x)
4653 (setq i (get-text-property 0 'inherited x))
4654 (if (and have-i (not i))
4655 (progn
4656 (setq have-i nil)
4657 (concat ":" x))
4659 tags ":")
4660 (if have-i "::" ":")))))
4661 txt)
4663 (defun org-downcase-keep-props (s)
4664 (let ((props (text-properties-at 0 s)))
4665 (setq s (downcase s))
4666 (add-text-properties 0 (length s) props s)
4669 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4670 (defvar org-agenda-sorting-strategy-selected nil)
4672 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4673 (catch 'exit
4674 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4675 ((and todayp (member 'today (car org-agenda-time-grid))))
4676 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4677 ((member 'weekly (car org-agenda-time-grid)))
4678 (t (throw 'exit list)))
4679 (let* ((have (delq nil (mapcar
4680 (lambda (x) (get-text-property 1 'time-of-day x))
4681 list)))
4682 (string (nth 1 org-agenda-time-grid))
4683 (gridtimes (nth 2 org-agenda-time-grid))
4684 (req (car org-agenda-time-grid))
4685 (remove (member 'remove-match req))
4686 new time)
4687 (if (and (member 'require-timed req) (not have))
4688 ;; don't show empty grid
4689 (throw 'exit list))
4690 (while (setq time (pop gridtimes))
4691 (unless (and remove (member time have))
4692 (setq time (int-to-string time))
4693 (push (org-format-agenda-item
4694 nil string "" nil
4695 (concat (substring time 0 -2) ":" (substring time -2)))
4696 new)
4697 (put-text-property
4698 1 (length (car new)) 'face 'org-time-grid (car new))))
4699 (if (member 'time-up org-agenda-sorting-strategy-selected)
4700 (append new list)
4701 (append list new)))))
4703 (defun org-compile-prefix-format (key)
4704 "Compile the prefix format into a Lisp form that can be evaluated.
4705 The resulting form is returned and stored in the variable
4706 `org-prefix-format-compiled'."
4707 (setq org-prefix-has-time nil org-prefix-has-tag nil
4708 org-prefix-category-length nil org-prefix-has-effort nil)
4709 (let ((s (cond
4710 ((stringp org-agenda-prefix-format)
4711 org-agenda-prefix-format)
4712 ((assq key org-agenda-prefix-format)
4713 (cdr (assq key org-agenda-prefix-format)))
4714 (t " %-12:c%?-12t% s")))
4715 (start 0)
4716 varform vars var e c f opt)
4717 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4718 s start)
4719 (setq var (cdr (assoc (match-string 4 s)
4720 '(("c" . category) ("t" . time) ("s" . extra)
4721 ("T" . tag) ("e" . effort))))
4722 c (or (match-string 3 s) "")
4723 opt (match-beginning 1)
4724 start (1+ (match-beginning 0)))
4725 (if (equal var 'time) (setq org-prefix-has-time t))
4726 (if (equal var 'tag) (setq org-prefix-has-tag t))
4727 (if (equal var 'effort) (setq org-prefix-has-effort t))
4728 (setq f (concat "%" (match-string 2 s) "s"))
4729 (when (equal var 'category)
4730 (setq org-prefix-category-length
4731 (floor (abs (string-to-number (match-string 2 s)))))
4732 (setq org-prefix-category-max-length
4733 (let ((x (match-string 2 s)))
4734 (save-match-data
4735 (if (string-match "\\.[0-9]+" x)
4736 (string-to-number (substring (match-string 0 x) 1)))))))
4737 (if opt
4738 (setq varform
4739 `(if (equal "" ,var)
4741 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4742 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4743 (setq s (replace-match "%s" t nil s))
4744 (push varform vars))
4745 (setq vars (nreverse vars))
4746 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4748 (defun org-set-sorting-strategy (key)
4749 (if (symbolp (car org-agenda-sorting-strategy))
4750 ;; the old format
4751 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4752 (setq org-agenda-sorting-strategy-selected
4753 (or (cdr (assq key org-agenda-sorting-strategy))
4754 (cdr (assq 'agenda org-agenda-sorting-strategy))
4755 '(time-up category-keep priority-down)))))
4757 (defun org-get-time-of-day (s &optional string mod24)
4758 "Check string S for a time of day.
4759 If found, return it as a military time number between 0 and 2400.
4760 If not found, return nil.
4761 The optional STRING argument forces conversion into a 5 character wide string
4762 HH:MM."
4763 (save-match-data
4764 (when
4765 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4766 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4767 (let* ((h (string-to-number (match-string 1 s)))
4768 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4769 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4770 (am-p (equal ampm "am"))
4771 (h1 (cond ((not ampm) h)
4772 ((= h 12) (if am-p 0 12))
4773 (t (+ h (if am-p 0 12)))))
4774 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4775 (mod h1 24) h1))
4776 (t0 (+ (* 100 h2) m))
4777 (t1 (concat (if (>= h1 24) "+" " ")
4778 (if (< t0 100) "0" "")
4779 (if (< t0 10) "0" "")
4780 (int-to-string t0))))
4781 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4783 (defun org-finalize-agenda-entries (list &optional nosort)
4784 "Sort and concatenate the agenda items."
4785 (setq list (mapcar 'org-agenda-highlight-todo list))
4786 (if nosort
4787 list
4788 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4790 (defun org-agenda-highlight-todo (x)
4791 (let ((org-done-keywords org-done-keywords-for-agenda)
4792 re pl)
4793 (if (eq x 'line)
4794 (save-excursion
4795 (beginning-of-line 1)
4796 (setq re (org-get-at-bol 'org-todo-regexp))
4797 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4798 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4799 (add-text-properties (match-beginning 0) (match-end 1)
4800 (list 'face (org-get-todo-face 1)))
4801 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4802 (delete-region (match-beginning 1) (1- (match-end 0)))
4803 (goto-char (match-beginning 1))
4804 (insert (format org-agenda-todo-keyword-format s)))))
4805 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4806 pl (get-text-property 0 'prefix-length x))
4807 (when (and re
4808 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4809 x (or pl 0)) pl))
4810 (add-text-properties
4811 (or (match-end 1) (match-end 0)) (match-end 0)
4812 (list 'face (org-get-todo-face (match-string 2 x)))
4814 (setq x (concat (substring x 0 (match-end 1))
4815 (format org-agenda-todo-keyword-format
4816 (match-string 2 x))
4817 (org-add-props " " (text-properties-at 0 x))
4818 (substring x (match-end 3)))))
4819 x)))
4821 (defsubst org-cmp-priority (a b)
4822 "Compare the priorities of string A and B."
4823 (let ((pa (or (get-text-property 1 'priority a) 0))
4824 (pb (or (get-text-property 1 'priority b) 0)))
4825 (cond ((> pa pb) +1)
4826 ((< pa pb) -1)
4827 (t nil))))
4829 (defsubst org-cmp-effort (a b)
4830 "Compare the priorities of string A and B."
4831 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4832 (ea (or (get-text-property 1 'effort-minutes a) def))
4833 (eb (or (get-text-property 1 'effort-minutes b) def)))
4834 (cond ((> ea eb) +1)
4835 ((< ea eb) -1)
4836 (t nil))))
4838 (defsubst org-cmp-category (a b)
4839 "Compare the string values of categories of strings A and B."
4840 (let ((ca (or (get-text-property 1 'org-category a) ""))
4841 (cb (or (get-text-property 1 'org-category b) "")))
4842 (cond ((string-lessp ca cb) -1)
4843 ((string-lessp cb ca) +1)
4844 (t nil))))
4846 (defsubst org-cmp-todo-state (a b)
4847 "Compare the todo states of strings A and B."
4848 (let* ((ma (or (get-text-property 1 'org-marker a)
4849 (get-text-property 1 'org-hd-marker a)))
4850 (mb (or (get-text-property 1 'org-marker b)
4851 (get-text-property 1 'org-hd-marker b)))
4852 (fa (and ma (marker-buffer ma)))
4853 (fb (and mb (marker-buffer mb)))
4854 (todo-kwds
4855 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4856 (and fb (with-current-buffer fb org-todo-keywords-1))))
4857 (ta (or (get-text-property 1 'todo-state a) ""))
4858 (tb (or (get-text-property 1 'todo-state b) ""))
4859 (la (- (length (member ta todo-kwds))))
4860 (lb (- (length (member tb todo-kwds))))
4861 (donepa (member ta org-done-keywords-for-agenda))
4862 (donepb (member tb org-done-keywords-for-agenda)))
4863 (cond ((and donepa (not donepb)) -1)
4864 ((and (not donepa) donepb) +1)
4865 ((< la lb) -1)
4866 ((< lb la) +1)
4867 (t nil))))
4869 (defsubst org-cmp-tag (a b)
4870 "Compare the string values of the first tags of A and B."
4871 (let ((ta (car (last (get-text-property 1 'tags a))))
4872 (tb (car (last (get-text-property 1 'tags b)))))
4873 (cond ((not ta) +1)
4874 ((not tb) -1)
4875 ((string-lessp ta tb) -1)
4876 ((string-lessp tb ta) +1)
4877 (t nil))))
4879 (defsubst org-cmp-time (a b)
4880 "Compare the time-of-day values of strings A and B."
4881 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
4882 (ta (or (get-text-property 1 'time-of-day a) def))
4883 (tb (or (get-text-property 1 'time-of-day b) def)))
4884 (cond ((< ta tb) -1)
4885 ((< tb ta) +1)
4886 (t nil))))
4888 (defsubst org-cmp-habit-p (a b)
4889 "Compare the todo states of strings A and B."
4890 (let ((ha (get-text-property 1 'org-habit-p a))
4891 (hb (get-text-property 1 'org-habit-p b)))
4892 (cond ((and ha (not hb)) -1)
4893 ((and (not ha) hb) +1)
4894 (t nil))))
4896 (defun org-entries-lessp (a b)
4897 "Predicate for sorting agenda entries."
4898 ;; The following variables will be used when the form is evaluated.
4899 ;; So even though the compiler complains, keep them.
4900 (let* ((time-up (org-cmp-time a b))
4901 (time-down (if time-up (- time-up) nil))
4902 (priority-up (org-cmp-priority a b))
4903 (priority-down (if priority-up (- priority-up) nil))
4904 (effort-up (org-cmp-effort a b))
4905 (effort-down (if effort-up (- effort-up) nil))
4906 (category-up (org-cmp-category a b))
4907 (category-down (if category-up (- category-up) nil))
4908 (category-keep (if category-up +1 nil))
4909 (tag-up (org-cmp-tag a b))
4910 (tag-down (if tag-up (- tag-up) nil))
4911 (todo-state-up (org-cmp-todo-state a b))
4912 (todo-state-down (if todo-state-up (- todo-state-up) nil))
4913 (habit-up (org-cmp-habit-p a b))
4914 (habit-down (if habit-up (- habit-up) nil))
4915 user-defined-up user-defined-down)
4916 (if (and org-agenda-cmp-user-defined
4917 (functionp org-agenda-cmp-user-defined))
4918 (setq user-defined-up
4919 (funcall org-agenda-cmp-user-defined a b)
4920 user-defined-down (if user-defined-up (- user-defined-up) nil)))
4921 (cdr (assoc
4922 (eval (cons 'or org-agenda-sorting-strategy-selected))
4923 '((-1 . t) (1 . nil) (nil . nil))))))
4925 ;;; Agenda restriction lock
4927 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
4928 "Overlay to mark the headline to which arenda commands are restricted.")
4929 (org-overlay-put org-agenda-restriction-lock-overlay
4930 'face 'org-agenda-restriction-lock)
4931 (org-overlay-put org-agenda-restriction-lock-overlay
4932 'help-echo "Agendas are currently limited to this subtree.")
4933 (org-detach-overlay org-agenda-restriction-lock-overlay)
4935 (defun org-agenda-set-restriction-lock (&optional type)
4936 "Set restriction lock for agenda, to current subtree or file.
4937 Restriction will be the file if TYPE is `file', or if type is the
4938 universal prefix '(4), or if the cursor is before the first headline
4939 in the file. Otherwise, restriction will be to the current subtree."
4940 (interactive "P")
4941 (and (equal type '(4)) (setq type 'file))
4942 (setq type (cond
4943 (type type)
4944 ((org-at-heading-p) 'subtree)
4945 ((condition-case nil (org-back-to-heading t) (error nil))
4946 'subtree)
4947 (t 'file)))
4948 (if (eq type 'subtree)
4949 (progn
4950 (setq org-agenda-restrict t)
4951 (setq org-agenda-overriding-restriction 'subtree)
4952 (put 'org-agenda-files 'org-restrict
4953 (list (buffer-file-name (buffer-base-buffer))))
4954 (org-back-to-heading t)
4955 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
4956 (move-marker org-agenda-restrict-begin (point))
4957 (move-marker org-agenda-restrict-end
4958 (save-excursion (org-end-of-subtree t)))
4959 (message "Locking agenda restriction to subtree"))
4960 (put 'org-agenda-files 'org-restrict
4961 (list (buffer-file-name (buffer-base-buffer))))
4962 (setq org-agenda-restrict nil)
4963 (setq org-agenda-overriding-restriction 'file)
4964 (move-marker org-agenda-restrict-begin nil)
4965 (move-marker org-agenda-restrict-end nil)
4966 (message "Locking agenda restriction to file"))
4967 (setq current-prefix-arg nil)
4968 (org-agenda-maybe-redo))
4970 (defun org-agenda-remove-restriction-lock (&optional noupdate)
4971 "Remove the agenda restriction lock."
4972 (interactive "P")
4973 (org-detach-overlay org-agenda-restriction-lock-overlay)
4974 (org-detach-overlay org-speedbar-restriction-lock-overlay)
4975 (setq org-agenda-overriding-restriction nil)
4976 (setq org-agenda-restrict nil)
4977 (put 'org-agenda-files 'org-restrict nil)
4978 (move-marker org-agenda-restrict-begin nil)
4979 (move-marker org-agenda-restrict-end nil)
4980 (setq current-prefix-arg nil)
4981 (message "Agenda restriction lock removed")
4982 (or noupdate (org-agenda-maybe-redo)))
4984 (defun org-agenda-maybe-redo ()
4985 "If there is any window showing the agenda view, update it."
4986 (let ((w (get-buffer-window org-agenda-buffer-name t))
4987 (w0 (selected-window)))
4988 (when w
4989 (select-window w)
4990 (org-agenda-redo)
4991 (select-window w0)
4992 (if org-agenda-overriding-restriction
4993 (message "Agenda view shifted to new %s restriction"
4994 org-agenda-overriding-restriction)
4995 (message "Agenda restriction lock removed")))))
4997 ;;; Agenda commands
4999 (defun org-agenda-check-type (error &rest types)
5000 "Check if agenda buffer is of allowed type.
5001 If ERROR is non-nil, throw an error, otherwise just return nil."
5002 (if (memq org-agenda-type types)
5004 (if error
5005 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5006 nil)))
5008 (defun org-agenda-quit ()
5009 "Exit agenda by removing the window or the buffer."
5010 (interactive)
5011 (if org-agenda-columns-active
5012 (org-columns-quit)
5013 (let ((buf (current-buffer)))
5014 (if (eq org-agenda-window-setup 'other-frame)
5015 (progn
5016 (kill-buffer buf)
5017 (org-agenda-reset-markers)
5018 (org-columns-remove-overlays)
5019 (setq org-agenda-archives-mode nil)
5020 (delete-frame))
5021 (and (not (eq org-agenda-window-setup 'current-window))
5022 (not (one-window-p))
5023 (delete-window))
5024 (kill-buffer buf)
5025 (org-agenda-reset-markers)
5026 (org-columns-remove-overlays)
5027 (setq org-agenda-archives-mode nil)))
5028 ;; Maybe restore the pre-agenda window configuration.
5029 (and org-agenda-restore-windows-after-quit
5030 (not (eq org-agenda-window-setup 'other-frame))
5031 org-pre-agenda-window-conf
5032 (set-window-configuration org-pre-agenda-window-conf))))
5034 (defun org-agenda-exit ()
5035 "Exit agenda by removing the window or the buffer.
5036 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5037 Org-mode buffers visited directly by the user will not be touched."
5038 (interactive)
5039 (org-release-buffers org-agenda-new-buffers)
5040 (setq org-agenda-new-buffers nil)
5041 (org-agenda-quit))
5043 (defun org-agenda-execute (arg)
5044 "Execute another agenda command, keeping same window.\\<global-map>
5045 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5046 (interactive "P")
5047 (let ((org-agenda-window-setup 'current-window))
5048 (org-agenda arg)))
5050 (defun org-agenda-redo ()
5051 "Rebuild Agenda.
5052 When this is the global TODO list, a prefix argument will be interpreted."
5053 (interactive)
5054 (let* ((org-agenda-keep-modes t)
5055 (filter org-agenda-filter)
5056 (preset (get 'org-agenda-filter :preset-filter))
5057 (cols org-agenda-columns-active)
5058 (line (org-current-line))
5059 (window-line (- line (org-current-line (window-start))))
5060 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5061 (put 'org-agenda-filter :preset-filter nil)
5062 (and cols (org-columns-quit))
5063 (message "Rebuilding agenda buffer...")
5064 (org-let lprops '(eval org-agenda-redo-command))
5065 (setq org-agenda-undo-list nil
5066 org-agenda-pending-undo-list nil)
5067 (message "Rebuilding agenda buffer...done")
5068 (put 'org-agenda-filter :preset-filter preset)
5069 (and (or filter preset) (org-agenda-filter-apply filter))
5070 (and cols (interactive-p) (org-agenda-columns))
5071 (org-goto-line line)
5072 (recenter window-line)))
5075 (defvar org-global-tags-completion-table nil)
5076 (defvar org-agenda-filter-form nil)
5077 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5078 "Keep only those lines in the agenda buffer that have a specific tag.
5079 The tag is selected with its fast selection letter, as configured.
5080 With prefix argument STRIP, remove all lines that do have the tag.
5081 A lisp caller can specify CHAR. NARROW means that the new tag should be
5082 used to narrow the search - the interactive user can also press `-' or `+'
5083 to switch to narrowing."
5084 (interactive "P")
5085 (let* ((alist org-tag-alist-for-agenda)
5086 (tag-chars (mapconcat
5087 (lambda (x) (if (and (not (symbolp (car x)))
5088 (cdr x))
5089 (char-to-string (cdr x))
5090 ""))
5091 alist ""))
5092 (efforts (org-split-string
5093 (or (cdr (assoc (concat org-effort-property "_ALL")
5094 org-global-properties))
5095 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5096 (effort-op org-agenda-filter-effort-default-operator)
5097 (effort-prompt "")
5098 (inhibit-read-only t)
5099 (current org-agenda-filter)
5100 char a n tag)
5101 (unless char
5102 (message
5103 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5104 (if narrow "Narrow" "Filter") tag-chars
5105 (if org-agenda-auto-exclude-function "[RET], " ""))
5106 (setq char (read-char)))
5107 (when (member char '(?+ ?-))
5108 ;; Narrowing down
5109 (cond ((equal char ?-) (setq strip t narrow t))
5110 ((equal char ?+) (setq strip nil narrow t)))
5111 (message
5112 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5113 (setq char (read-char)))
5114 (when (member char '(?< ?> ?= ??))
5115 ;; An effort operator
5116 (setq effort-op (char-to-string char))
5117 (setq alist nil) ; to make sure it will be interpreted as effort.
5118 (unless (equal char ??)
5119 (loop for i from 0 to 9 do
5120 (setq effort-prompt
5121 (concat
5122 effort-prompt " ["
5123 (if (= i 9) "0" (int-to-string (1+ i)))
5124 "]" (nth i efforts))))
5125 (message "Effort%s: %s " effort-op effort-prompt)
5126 (setq char (read-char))
5127 (when (or (< char ?0) (> char ?9))
5128 (error "Need 1-9,0 to select effort" ))))
5129 (when (equal char ?\t)
5130 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5131 (org-set-local 'org-global-tags-completion-table
5132 (org-global-tags-completion-table)))
5133 (let ((completion-ignore-case t))
5134 (setq tag (org-icompleting-read
5135 "Tag: " org-global-tags-completion-table))))
5136 (cond
5137 ((equal char ?\r)
5138 (org-agenda-filter-by-tag-show-all)
5139 (when org-agenda-auto-exclude-function
5140 (setq org-agenda-filter '())
5141 (dolist (tag org-tag-alist-for-agenda)
5142 (let ((modifier (funcall org-agenda-auto-exclude-function
5143 (car tag))))
5144 (if modifier
5145 (push modifier org-agenda-filter))))
5146 (if (not (null org-agenda-filter))
5147 (org-agenda-filter-apply org-agenda-filter))))
5148 ((equal char ?/)
5149 (org-agenda-filter-by-tag-show-all)
5150 (when (get 'org-agenda-filter :preset-filter)
5151 (org-agenda-filter-apply org-agenda-filter)))
5152 ((or (equal char ?\ )
5153 (setq a (rassoc char alist))
5154 (and (>= char ?0) (<= char ?9)
5155 (setq n (if (= char ?0) 9 (- char ?0 1))
5156 tag (concat effort-op (nth n efforts))
5157 a (cons tag nil)))
5158 (and (= char ??)
5159 (setq tag "?eff")
5160 a (cons tag nil))
5161 (and tag (setq a (cons tag nil))))
5162 (org-agenda-filter-by-tag-show-all)
5163 (setq tag (car a))
5164 (setq org-agenda-filter
5165 (cons (concat (if strip "-" "+") tag)
5166 (if narrow current nil)))
5167 (org-agenda-filter-apply org-agenda-filter))
5168 (t (error "Invalid tag selection character %c" char)))))
5170 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5171 "Refine the current filter. See `org-agenda-filter-by-tag."
5172 (interactive "P")
5173 (org-agenda-filter-by-tag strip char 'refine))
5175 (defun org-agenda-filter-make-matcher ()
5176 "Create the form that tests a line for the agenda filter."
5177 (let (f f1)
5178 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5179 org-agenda-filter))
5180 (if (member x '("-" "+"))
5181 (setq f1 (if (equal x "-") 'tags '(not tags)))
5182 (if (string-match "[<=>?]" x)
5183 (setq f1 (org-agenda-filter-effort-form x))
5184 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5185 (if (equal (string-to-char x) ?-)
5186 (setq f1 (list 'not f1))))
5187 (push f1 f))
5188 (cons 'and (nreverse f))))
5190 (defun org-agenda-filter-effort-form (e)
5191 "Return the form to compare the effort of the current line with what E says.
5192 E looks line \"+<2:25\"."
5193 (let (op)
5194 (setq e (substring e 1))
5195 (setq op (string-to-char e) e (substring e 1))
5196 (setq op (cond ((equal op ?<) '<=)
5197 ((equal op ?>) '>=)
5198 ((equal op ??) op)
5199 (t '=)))
5200 (list 'org-agenda-compare-effort (list 'quote op)
5201 (org-hh:mm-string-to-minutes e))))
5203 (defun org-agenda-compare-effort (op value)
5204 "Compare the effort of the current line with VALUE, using OP.
5205 If the line does not have an effort defined, return nil."
5206 (let ((eff (org-get-at-bol 'effort-minutes)))
5207 (if (equal op ??)
5208 (not eff)
5209 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5210 value))))
5212 (defun org-agenda-filter-apply (filter)
5213 "Set FILTER as the new agenda filter and apply it."
5214 (let (tags)
5215 (setq org-agenda-filter filter
5216 org-agenda-filter-form (org-agenda-filter-make-matcher))
5217 (org-agenda-set-mode-name)
5218 (save-excursion
5219 (goto-char (point-min))
5220 (while (not (eobp))
5221 (if (org-get-at-bol 'org-marker)
5222 (progn
5223 (setq tags (org-get-at-bol 'tags)) ; used in eval
5224 (if (not (eval org-agenda-filter-form))
5225 (org-agenda-filter-by-tag-hide-line))
5226 (beginning-of-line 2))
5227 (beginning-of-line 2))))))
5229 (defun org-agenda-filter-by-tag-hide-line ()
5230 (let (ov)
5231 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5232 (point-at-eol)))
5233 (org-overlay-put ov 'invisible t)
5234 (org-overlay-put ov 'type 'tags-filter)
5235 (push ov org-agenda-filter-overlays)))
5237 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5238 (setq pos (or pos (point)))
5239 (save-excursion
5240 (dolist (ov (org-overlays-at pos))
5241 (when (and (org-overlay-get ov 'invisible)
5242 (eq (org-overlay-get ov 'type) 'tags-filter))
5243 (goto-char pos)
5244 (if (< (org-overlay-start ov) (point-at-eol))
5245 (org-move-overlay ov (point-at-eol)
5246 (org-overlay-end ov)))))))
5248 (defun org-agenda-filter-by-tag-show-all ()
5249 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5250 (setq org-agenda-filter-overlays nil)
5251 (setq org-agenda-filter nil)
5252 (setq org-agenda-filter-form nil)
5253 (org-agenda-set-mode-name))
5255 (defun org-agenda-manipulate-query-add ()
5256 "Manipulate the query by adding a search term with positive selection.
5257 Positive selection means, the term must be matched for selection of an entry."
5258 (interactive)
5259 (org-agenda-manipulate-query ?\[))
5260 (defun org-agenda-manipulate-query-subtract ()
5261 "Manipulate the query by adding a search term with negative selection.
5262 Negative selection means, term must not be matched for selection of an entry."
5263 (interactive)
5264 (org-agenda-manipulate-query ?\]))
5265 (defun org-agenda-manipulate-query-add-re ()
5266 "Manipulate the query by adding a search regexp with positive selection.
5267 Positive selection means, the regexp must match for selection of an entry."
5268 (interactive)
5269 (org-agenda-manipulate-query ?\{))
5270 (defun org-agenda-manipulate-query-subtract-re ()
5271 "Manipulate the query by adding a search regexp with negative selection.
5272 Negative selection means, regexp must not match for selection of an entry."
5273 (interactive)
5274 (org-agenda-manipulate-query ?\}))
5275 (defun org-agenda-manipulate-query (char)
5276 (cond
5277 ((memq org-agenda-type '(timeline agenda))
5278 (let ((org-agenda-include-inactive-timestamps t))
5279 (org-agenda-redo))
5280 (message "Display now includes inactive timestamps as well"))
5281 ((eq org-agenda-type 'search)
5282 (org-add-to-string
5283 'org-agenda-query-string
5284 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5285 (?\{ . " +{}") (?\} . " -{}")))))
5286 (setq org-agenda-redo-command
5287 (list 'org-search-view
5288 org-todo-only
5289 org-agenda-query-string
5290 (+ (length org-agenda-query-string)
5291 (if (member char '(?\{ ?\})) 0 1))))
5292 (set-register org-agenda-query-register org-agenda-query-string)
5293 (org-agenda-redo))
5294 (t (error "Cannot manipulate query for %s-type agenda buffers"
5295 org-agenda-type))))
5297 (defun org-add-to-string (var string)
5298 (set var (concat (symbol-value var) string)))
5300 (defun org-agenda-goto-date (date)
5301 "Jump to DATE in agenda."
5302 (interactive (list (org-read-date)))
5303 (org-agenda-list nil date))
5305 (defun org-agenda-goto-today ()
5306 "Go to today."
5307 (interactive)
5308 (org-agenda-check-type t 'timeline 'agenda)
5309 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5310 (cond
5311 (tdpos (goto-char tdpos))
5312 ((eq org-agenda-type 'agenda)
5313 (let* ((sd (time-to-days
5314 (time-subtract (current-time)
5315 (list 0 (* 3600 org-extend-today-until) 0))))
5316 (comp (org-agenda-compute-time-span sd org-agenda-span))
5317 (org-agenda-overriding-arguments org-agenda-last-arguments))
5318 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5319 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5320 (org-agenda-redo)
5321 (org-agenda-find-same-or-today-or-agenda)))
5322 (t (error "Cannot find today")))))
5324 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5325 (goto-char
5326 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5327 (text-property-any (point-min) (point-max) 'org-today t)
5328 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5329 (point-min))))
5331 (defun org-agenda-later (arg)
5332 "Go forward in time by thee current span.
5333 With prefix ARG, go forward that many times the current span."
5334 (interactive "p")
5335 (org-agenda-check-type t 'agenda)
5336 (let* ((span org-agenda-span)
5337 (sd org-starting-day)
5338 (greg (calendar-gregorian-from-absolute sd))
5339 (cnt (org-get-at-bol 'org-day-cnt))
5340 greg2 nd)
5341 (cond
5342 ((eq span 'day)
5343 (setq sd (+ arg sd) nd 1))
5344 ((eq span 'week)
5345 (setq sd (+ (* 7 arg) sd) nd 7))
5346 ((eq span 'month)
5347 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5348 sd (calendar-absolute-from-gregorian greg2))
5349 (setcar greg2 (1+ (car greg2)))
5350 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5351 ((eq span 'year)
5352 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5353 sd (calendar-absolute-from-gregorian greg2))
5354 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5355 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5356 (let ((org-agenda-overriding-arguments
5357 (list (car org-agenda-last-arguments) sd nd t)))
5358 (org-agenda-redo)
5359 (org-agenda-find-same-or-today-or-agenda cnt))))
5361 (defun org-agenda-earlier (arg)
5362 "Go backward in time by the current span.
5363 With prefix ARG, go backward that many times the current span."
5364 (interactive "p")
5365 (org-agenda-later (- arg)))
5367 (defun org-agenda-view-mode-dispatch ()
5368 "Call one of the view mode commands."
5369 (interactive)
5370 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5371 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5372 (let ((a (read-char-exclusive)))
5373 (case a
5374 (?d (call-interactively 'org-agenda-day-view))
5375 (?w (call-interactively 'org-agenda-week-view))
5376 (?m (call-interactively 'org-agenda-month-view))
5377 (?y (call-interactively 'org-agenda-year-view))
5378 (?l (call-interactively 'org-agenda-log-mode))
5379 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5380 (?a (call-interactively 'org-agenda-archives-mode))
5381 (?A (org-agenda-archives-mode 'files))
5382 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5383 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5384 (?G (call-interactively 'org-agenda-toggle-time-grid))
5385 (?D (call-interactively 'org-agenda-toggle-diary))
5386 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5387 (org-agenda-check-type t 'timeline 'agenda)
5388 (org-agenda-redo))
5389 (message "Display now includes inactive timestamps as well"))
5390 (?q (message "Abort"))
5391 (otherwise (error "Invalid key" )))))
5393 (defun org-agenda-day-view (&optional day-of-year)
5394 "Switch to daily view for agenda.
5395 With argument DAY-OF-YEAR, switch to that day of the year."
5396 (interactive "P")
5397 (setq org-agenda-ndays 1)
5398 (org-agenda-change-time-span 'day day-of-year))
5399 (defun org-agenda-week-view (&optional iso-week)
5400 "Switch to daily view for agenda.
5401 With argument ISO-WEEK, switch to the corresponding ISO week.
5402 If ISO-WEEK has more then 2 digits, only the last two encode the
5403 week. Any digits before this encode a year. So 200712 means
5404 week 12 of year 2007. Years in the range 1938-2037 can also be
5405 written as 2-digit years."
5406 (interactive "P")
5407 (setq org-agenda-ndays 7)
5408 (org-agenda-change-time-span 'week iso-week))
5409 (defun org-agenda-month-view (&optional month)
5410 "Switch to monthly view for agenda.
5411 With argument MONTH, switch to that month."
5412 (interactive "P")
5413 (org-agenda-change-time-span 'month month))
5414 (defun org-agenda-year-view (&optional year)
5415 "Switch to yearly view for agenda.
5416 With argument YEAR, switch to that year.
5417 If MONTH has more then 2 digits, only the last two encode the
5418 month. Any digits before this encode a year. So 200712 means
5419 December year 2007. Years in the range 1938-2037 can also be
5420 written as 2-digit years."
5421 (interactive "P")
5422 (when year
5423 (setq year (org-small-year-to-year year)))
5424 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5425 (org-agenda-change-time-span 'year year)
5426 (error "Abort")))
5428 (defun org-agenda-change-time-span (span &optional n)
5429 "Change the agenda view to SPAN.
5430 SPAN may be `day', `week', `month', `year'."
5431 (org-agenda-check-type t 'agenda)
5432 (if (and (not n) (equal org-agenda-span span))
5433 (error "Viewing span is already \"%s\"" span))
5434 (let* ((sd (or (org-get-at-bol 'day)
5435 org-starting-day))
5436 (computed (org-agenda-compute-time-span sd span n))
5437 (org-agenda-overriding-arguments
5438 (list (car org-agenda-last-arguments)
5439 (car computed) (cdr computed) t)))
5440 (org-agenda-redo)
5441 (org-agenda-find-same-or-today-or-agenda))
5442 (org-agenda-set-mode-name)
5443 (message "Switched to %s view" span))
5445 (defun org-agenda-compute-time-span (sd span &optional n)
5446 "Compute starting date and number of days for agenda.
5447 SPAN may be `day', `week', `month', `year'. The return value
5448 is a cons cell with the starting date and the number of days,
5449 so that the date SD will be in that range."
5450 (let* ((greg (calendar-gregorian-from-absolute sd))
5451 (dg (nth 1 greg))
5452 (mg (car greg))
5453 (yg (nth 2 greg))
5454 nd w1 y1 m1 thisweek)
5455 (cond
5456 ((eq span 'day)
5457 (when n
5458 (setq sd (+ (calendar-absolute-from-gregorian
5459 (list mg 1 yg))
5460 n -1)))
5461 (setq nd 1))
5462 ((eq span 'week)
5463 (let* ((nt (calendar-day-of-week
5464 (calendar-gregorian-from-absolute sd)))
5465 (d (if org-agenda-start-on-weekday
5466 (- nt org-agenda-start-on-weekday)
5467 0)))
5468 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5469 (when n
5470 (require 'cal-iso)
5471 (setq thisweek (car (calendar-iso-from-absolute sd)))
5472 (when (> n 99)
5473 (setq y1 (org-small-year-to-year (/ n 100))
5474 n (mod n 100)))
5475 (setq sd
5476 (calendar-absolute-from-iso
5477 (list n 1
5478 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5479 (setq nd 7)))
5480 ((eq span 'month)
5481 (when (and n (> n 99))
5482 (setq y1 (org-small-year-to-year (/ n 100))
5483 n (mod n 100)))
5484 (setq sd (calendar-absolute-from-gregorian
5485 (list (or n mg) 1 (or y1 yg)))
5486 nd (- (calendar-absolute-from-gregorian
5487 (list (1+ (or n mg)) 1 (or y1 yg)))
5488 sd)))
5489 ((eq span 'year)
5490 (setq sd (calendar-absolute-from-gregorian
5491 (list 1 1 (or n yg)))
5492 nd (- (calendar-absolute-from-gregorian
5493 (list 1 1 (1+ (or n yg))))
5494 sd))))
5495 (cons sd nd)))
5497 (defun org-agenda-next-date-line (&optional arg)
5498 "Jump to the next line indicating a date in agenda buffer."
5499 (interactive "p")
5500 (org-agenda-check-type t 'agenda 'timeline)
5501 (beginning-of-line 1)
5502 ;; This does not work if user makes date format that starts with a blank
5503 (if (looking-at "^\\S-") (forward-char 1))
5504 (if (not (re-search-forward "^\\S-" nil t arg))
5505 (progn
5506 (backward-char 1)
5507 (error "No next date after this line in this buffer")))
5508 (goto-char (match-beginning 0)))
5510 (defun org-agenda-previous-date-line (&optional arg)
5511 "Jump to the previous line indicating a date in agenda buffer."
5512 (interactive "p")
5513 (org-agenda-check-type t 'agenda 'timeline)
5514 (beginning-of-line 1)
5515 (if (not (re-search-backward "^\\S-" nil t arg))
5516 (error "No previous date before this line in this buffer")))
5518 ;; Initialize the highlight
5519 (defvar org-hl (org-make-overlay 1 1))
5520 (org-overlay-put org-hl 'face 'highlight)
5522 (defun org-highlight (begin end &optional buffer)
5523 "Highlight a region with overlay."
5524 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5525 org-hl begin end (or buffer (current-buffer))))
5527 (defun org-unhighlight ()
5528 "Detach overlay INDEX."
5529 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5531 ;; FIXME this is currently not used.
5532 (defun org-highlight-until-next-command (beg end &optional buffer)
5533 "Move the highlight overlay to BEG/END, remove it before the next command."
5534 (org-highlight beg end buffer)
5535 (add-hook 'pre-command-hook 'org-unhighlight-once))
5536 (defun org-unhighlight-once ()
5537 "Remove the highlight from its position, and this function from the hook."
5538 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5539 (org-unhighlight))
5541 (defun org-agenda-follow-mode ()
5542 "Toggle follow mode in an agenda buffer."
5543 (interactive)
5544 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5545 (org-agenda-set-mode-name)
5546 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5547 (org-agenda-show))
5548 (message "Follow mode is %s"
5549 (if org-agenda-follow-mode "on" "off")))
5551 (defun org-agenda-entry-text-mode (&optional arg)
5552 "Toggle entry text mode in an agenda buffer."
5553 (interactive "P")
5554 (if (integerp arg)
5555 (setq org-agenda-entry-text-mode t)
5556 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5557 (org-agenda-entry-text-hide)
5558 (and org-agenda-entry-text-mode
5559 (let ((org-agenda-entry-text-maxlines
5560 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5561 (org-agenda-entry-text-show)))
5562 (org-agenda-set-mode-name)
5563 (message "Entry text mode is %s. Maximum number of lines is %d"
5564 (if org-agenda-entry-text-mode "on" "off")
5565 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5567 (defun org-agenda-clockreport-mode ()
5568 "Toggle clocktable mode in an agenda buffer."
5569 (interactive)
5570 (org-agenda-check-type t 'agenda)
5571 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5572 (org-agenda-set-mode-name)
5573 (org-agenda-redo)
5574 (message "Clocktable mode is %s"
5575 (if org-agenda-clockreport-mode "on" "off")))
5577 (defun org-agenda-log-mode (&optional special)
5578 "Toggle log mode in an agenda buffer.
5579 With argument SPECIAL, show all possible log items, not only the ones
5580 configured in `org-agenda-log-mode-items'.
5581 With a double `C-u' prefix arg, show *only* log items, nothing else."
5582 (interactive "P")
5583 (org-agenda-check-type t 'agenda 'timeline)
5584 (setq org-agenda-show-log
5585 (if (equal special '(16))
5586 'only
5587 (if special '(closed clock state)
5588 (not org-agenda-show-log))))
5589 (org-agenda-set-mode-name)
5590 (org-agenda-redo)
5591 (message "Log mode is %s"
5592 (if org-agenda-show-log "on" "off")))
5594 (defun org-agenda-archives-mode (&optional with-files)
5595 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5596 When called with a prefix argument, include all archive files as well."
5597 (interactive "P")
5598 (setq org-agenda-archives-mode
5599 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5600 (org-agenda-set-mode-name)
5601 (org-agenda-redo)
5602 (message
5603 "%s"
5604 (cond
5605 ((eq org-agenda-archives-mode nil)
5606 "No archives are included")
5607 ((eq org-agenda-archives-mode 'trees)
5608 (format "Trees with :%s: tag are included" org-archive-tag))
5609 ((eq org-agenda-archives-mode t)
5610 (format "Trees with :%s: tag and all active archive files are included"
5611 org-archive-tag)))))
5613 (defun org-agenda-toggle-diary ()
5614 "Toggle diary inclusion in an agenda buffer."
5615 (interactive)
5616 (org-agenda-check-type t 'agenda)
5617 (setq org-agenda-include-diary (not org-agenda-include-diary))
5618 (org-agenda-redo)
5619 (org-agenda-set-mode-name)
5620 (message "Diary inclusion turned %s"
5621 (if org-agenda-include-diary "on" "off")))
5623 (defun org-agenda-toggle-time-grid ()
5624 "Toggle time grid in an agenda buffer."
5625 (interactive)
5626 (org-agenda-check-type t 'agenda)
5627 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5628 (org-agenda-redo)
5629 (org-agenda-set-mode-name)
5630 (message "Time-grid turned %s"
5631 (if org-agenda-use-time-grid "on" "off")))
5633 (defun org-agenda-set-mode-name ()
5634 "Set the mode name to indicate all the small mode settings."
5635 (setq mode-name
5636 (concat "Org-Agenda"
5637 (if (equal org-agenda-ndays 1) " Day" "")
5638 (if (equal org-agenda-ndays 7) " Week" "")
5639 (if org-agenda-follow-mode " Follow" "")
5640 (if org-agenda-entry-text-mode " ETxt" "")
5641 (if org-agenda-include-diary " Diary" "")
5642 (if org-agenda-use-time-grid " Grid" "")
5643 (if (and (boundp 'org-habit-show-habits)
5644 org-habit-show-habits) " Habit" "")
5645 (if (consp org-agenda-show-log) " LogAll"
5646 (if org-agenda-show-log " Log" ""))
5647 (if (or org-agenda-filter (get 'org-agenda-filter
5648 :preset-filter))
5649 (concat " {" (mapconcat
5650 'identity
5651 (append (get 'org-agenda-filter
5652 :preset-filter)
5653 org-agenda-filter) "") "}")
5655 (if org-agenda-archives-mode
5656 (if (eq org-agenda-archives-mode t)
5657 " Archives"
5658 (format " :%s:" org-archive-tag))
5660 (if org-agenda-clockreport-mode " Clock" "")))
5661 (force-mode-line-update))
5663 (defun org-agenda-post-command-hook ()
5664 (setq org-agenda-type
5665 (or (get-text-property (point) 'org-agenda-type)
5666 (get-text-property (max (point-min) (1- (point)))
5667 'org-agenda-type))))
5669 (defun org-agenda-next-line ()
5670 "Move cursor to the next line, and show if follow-mode is active."
5671 (interactive)
5672 (call-interactively 'next-line)
5673 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5674 (org-agenda-show)))
5675 (defun org-agenda-previous-line ()
5676 "Move cursor to the previous line, and show if follow-mode is active."
5678 (interactive)
5679 (call-interactively 'previous-line)
5680 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5681 (org-agenda-show)))
5683 (defun org-agenda-show-priority ()
5684 "Show the priority of the current item.
5685 This priority is composed of the main priority given with the [#A] cookies,
5686 and by additional input from the age of a schedules or deadline entry."
5687 (interactive)
5688 (let* ((pri (org-get-at-bol 'priority)))
5689 (message "Priority is %d" (if pri pri -1000))))
5691 (defun org-agenda-show-tags ()
5692 "Show the tags applicable to the current item."
5693 (interactive)
5694 (let* ((tags (org-get-at-bol 'tags)))
5695 (if tags
5696 (message "Tags are :%s:"
5697 (org-no-properties (mapconcat 'identity tags ":")))
5698 (message "No tags associated with this line"))))
5700 (defun org-agenda-goto (&optional highlight)
5701 "Go to the Org-mode file which contains the item at point."
5702 (interactive)
5703 (let* ((marker (or (org-get-at-bol 'org-marker)
5704 (org-agenda-error)))
5705 (buffer (marker-buffer marker))
5706 (pos (marker-position marker)))
5707 (switch-to-buffer-other-window buffer)
5708 (widen)
5709 (goto-char pos)
5710 (when (org-mode-p)
5711 (org-show-context 'agenda)
5712 (save-excursion
5713 (and (outline-next-heading)
5714 (org-flag-heading nil)))) ; show the next heading
5715 (recenter (/ (window-height) 2))
5716 (run-hooks 'org-agenda-after-show-hook)
5717 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5719 (defvar org-agenda-after-show-hook nil
5720 "Normal hook run after an item has been shown from the agenda.
5721 Point is in the buffer where the item originated.")
5723 (defun org-agenda-kill ()
5724 "Kill the entry or subtree belonging to the current agenda entry."
5725 (interactive)
5726 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5727 (let* ((marker (or (org-get-at-bol 'org-marker)
5728 (org-agenda-error)))
5729 (buffer (marker-buffer marker))
5730 (pos (marker-position marker))
5731 (type (org-get-at-bol 'type))
5732 dbeg dend (n 0) conf)
5733 (org-with-remote-undo buffer
5734 (with-current-buffer buffer
5735 (save-excursion
5736 (goto-char pos)
5737 (if (and (org-mode-p) (not (member type '("sexp"))))
5738 (setq dbeg (progn (org-back-to-heading t) (point))
5739 dend (org-end-of-subtree t t))
5740 (setq dbeg (point-at-bol)
5741 dend (min (point-max) (1+ (point-at-eol)))))
5742 (goto-char dbeg)
5743 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5744 (setq conf (or (eq t org-agenda-confirm-kill)
5745 (and (numberp org-agenda-confirm-kill)
5746 (> n org-agenda-confirm-kill))))
5747 (and conf
5748 (not (y-or-n-p
5749 (format "Delete entry with %d lines in buffer \"%s\"? "
5750 n (buffer-name buffer))))
5751 (error "Abort"))
5752 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5753 (with-current-buffer buffer (delete-region dbeg dend))
5754 (message "Agenda item and source killed"))))
5756 (defvar org-archive-default-command)
5757 (defun org-agenda-archive-default ()
5758 "Archive the entry or subtree belonging to the current agenda entry."
5759 (interactive)
5760 (require 'org-archive)
5761 (org-agenda-archive-with org-archive-default-command))
5763 (defun org-agenda-archive-default-with-confirmation ()
5764 "Archive the entry or subtree belonging to the current agenda entry."
5765 (interactive)
5766 (require 'org-archive)
5767 (org-agenda-archive-with org-archive-default-command 'confirm))
5769 (defun org-agenda-archive ()
5770 "Archive the entry or subtree belonging to the current agenda entry."
5771 (interactive)
5772 (org-agenda-archive-with 'org-archive-subtree))
5774 (defun org-agenda-archive-to-archive-sibling ()
5775 "Move the entry to the archive sibling."
5776 (interactive)
5777 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5779 (defun org-agenda-archive-with (cmd &optional confirm)
5780 "Move the entry to the archive sibling."
5781 (interactive)
5782 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5783 (let* ((marker (or (org-get-at-bol 'org-marker)
5784 (org-agenda-error)))
5785 (buffer (marker-buffer marker))
5786 (pos (marker-position marker)))
5787 (org-with-remote-undo buffer
5788 (with-current-buffer buffer
5789 (if (org-mode-p)
5790 (if (and confirm
5791 (not (y-or-n-p "Archive this subtree or entry? ")))
5792 (error "Abort")
5793 (save-excursion
5794 (goto-char pos)
5795 (org-remove-subtree-entries-from-agenda)
5796 (org-back-to-heading t)
5797 (funcall cmd)))
5798 (error "Archiving works only in Org-mode files"))))))
5800 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5801 "Remove all lines in the agenda that correspond to a given subtree.
5802 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5803 If this information is not given, the function uses the tree at point."
5804 (let ((buf (or buf (current-buffer))) m p)
5805 (save-excursion
5806 (unless (and beg end)
5807 (org-back-to-heading t)
5808 (setq beg (point))
5809 (org-end-of-subtree t)
5810 (setq end (point)))
5811 (set-buffer (get-buffer org-agenda-buffer-name))
5812 (save-excursion
5813 (goto-char (point-max))
5814 (beginning-of-line 1)
5815 (while (not (bobp))
5816 (when (and (setq m (org-get-at-bol 'org-marker))
5817 (equal buf (marker-buffer m))
5818 (setq p (marker-position m))
5819 (>= p beg)
5820 (< p end))
5821 (let ((inhibit-read-only t))
5822 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5823 (beginning-of-line 0))))))
5825 (defun org-agenda-refile (&optional goto rfloc)
5826 "Refile the item at point."
5827 (interactive "P")
5828 (if (equal goto '(16))
5829 (org-refile-goto-last-stored)
5830 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5831 (org-agenda-error)))
5832 (buffer (marker-buffer marker))
5833 (pos (marker-position marker))
5834 (rfloc (or rfloc
5835 (org-refile-get-location
5836 (if goto "Goto: " "Refile to: ") buffer
5837 org-refile-allow-creating-parent-nodes))))
5838 (with-current-buffer buffer
5839 (save-excursion
5840 (save-restriction
5841 (widen)
5842 (goto-char marker)
5843 (org-remove-subtree-entries-from-agenda)
5844 (org-refile goto buffer rfloc)))))))
5846 (defun org-agenda-open-link (&optional arg)
5847 "Follow the link in the current line, if any.
5848 This looks for a link in the displayed line in the agenda. It also looks
5849 at the text of the entry itself."
5850 (interactive "P")
5851 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5852 (org-get-at-bol 'org-marker)))
5853 (buffer (and marker (marker-buffer marker)))
5854 (prefix (buffer-substring
5855 (point-at-bol)
5856 (+ (point-at-bol)
5857 (or (org-get-at-bol 'prefix-length) 0)))))
5858 (cond
5859 (buffer
5860 (with-current-buffer buffer
5861 (save-excursion
5862 (save-restriction
5863 (widen)
5864 (goto-char marker)
5865 (org-offer-links-in-entry arg prefix)))))
5866 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
5867 (save-excursion
5868 (beginning-of-line 1)
5869 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
5870 (org-open-link-from-string (match-string 1)))
5871 (t (error "No link to open here")))))
5873 (defun org-agenda-copy-local-variable (var)
5874 "Get a variable from a referenced buffer and install it here."
5875 (let ((m (org-get-at-bol 'org-marker)))
5876 (when (and m (buffer-live-p (marker-buffer m)))
5877 (org-set-local var (with-current-buffer (marker-buffer m)
5878 (symbol-value var))))))
5880 (defun org-agenda-switch-to (&optional delete-other-windows)
5881 "Go to the Org-mode file which contains the item at point."
5882 (interactive)
5883 (if (and org-return-follows-link
5884 (not (org-get-at-bol 'org-marker))
5885 (org-in-regexp org-bracket-link-regexp))
5886 (org-open-link-from-string (match-string 0))
5887 (let* ((marker (or (org-get-at-bol 'org-marker)
5888 (org-agenda-error)))
5889 (buffer (marker-buffer marker))
5890 (pos (marker-position marker)))
5891 (switch-to-buffer buffer)
5892 (and delete-other-windows (delete-other-windows))
5893 (widen)
5894 (goto-char pos)
5895 (when (org-mode-p)
5896 (org-show-context 'agenda)
5897 (save-excursion
5898 (and (outline-next-heading)
5899 (org-flag-heading nil))))))) ; show the next heading
5901 (defun org-agenda-goto-mouse (ev)
5902 "Go to the Org-mode file which contains the item at the mouse click."
5903 (interactive "e")
5904 (mouse-set-point ev)
5905 (org-agenda-goto))
5907 (defun org-agenda-show (&optional full-entry)
5908 "Display the Org-mode file which contains the item at point.
5909 With prefix argument FULL-ENTRY, make the entire entry visible
5910 if it was hidden in the outline."
5911 (interactive "P")
5912 (let ((win (selected-window)))
5913 (if full-entry
5914 (let ((org-show-entry-below t))
5915 (org-agenda-goto t))
5916 (org-agenda-goto t))
5917 (select-window win)))
5919 (defvar org-agenda-show-window nil)
5920 (defun org-agenda-show-and-scroll-up ()
5921 "Display the Org-mode file which contains the item at point.
5922 When called repeatedly, scroll the window that is displaying the buffer."
5923 (interactive)
5924 (let ((win (selected-window)))
5925 (if (and (window-live-p org-agenda-show-window)
5926 (eq this-command last-command))
5927 (progn
5928 (select-window org-agenda-show-window)
5929 (ignore-errors (scroll-up)))
5930 (org-agenda-goto t)
5931 (show-subtree)
5932 (setq org-agenda-show-window (selected-window)))
5933 (select-window win)))
5935 (defun org-agenda-show-scroll-down ()
5936 "Scroll down the window showing the agenda."
5937 (interactive)
5938 (let ((win (selected-window)))
5939 (when (window-live-p org-agenda-show-window)
5940 (select-window org-agenda-show-window)
5941 (ignore-errors (scroll-down))
5942 (select-window win))))
5944 (defun org-agenda-show-1 (&optional more)
5945 "Display the Org-mode file which contains the item at point.
5946 The prefix arg causes further revieling:
5948 0 hide the subtree
5949 1 just show the entry according to defaults.
5950 2 show the children view
5951 3 show the subtree view
5952 4 show the entire subtree and any LOGBOOK drawers
5953 5 show the entire subtree and any drawers
5954 With prefix argument FULL-ENTRY, make the entire entry visible
5955 if it was hidden in the outline."
5956 (interactive "p")
5957 (let ((win (selected-window)))
5958 (org-agenda-goto t)
5959 (org-recenter-heading 1)
5960 (cond
5961 ((= more 0)
5962 (hide-subtree)
5963 (save-excursion
5964 (org-back-to-heading)
5965 (run-hook-with-args 'org-cycle-hook 'folded))
5966 (message "Remote: FOLDED"))
5967 ((and (interactive-p) (= more 1))
5968 (message "Remote: show with default settings"))
5969 ((= more 2)
5970 (show-entry)
5971 (show-children)
5972 (save-excursion
5973 (org-back-to-heading)
5974 (run-hook-with-args 'org-cycle-hook 'children))
5975 (message "Remote: CHILDREN"))
5976 ((= more 3)
5977 (show-subtree)
5978 (save-excursion
5979 (org-back-to-heading)
5980 (run-hook-with-args 'org-cycle-hook 'subtree))
5981 (message "Remote: SUBTREE"))
5982 ((= more 4)
5983 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
5984 (org-drawer-regexp
5985 (concat "^[ \t]*:\\("
5986 (mapconcat 'regexp-quote org-drawers "\\|")
5987 "\\):[ \t]*$")))
5988 (show-subtree)
5989 (save-excursion
5990 (org-back-to-heading)
5991 (org-cycle-hide-drawers 'subtree)))
5992 (message "Remote: SUBTREE AND LOGBOOK"))
5993 ((> more 4)
5994 (show-subtree)
5995 (message "Remote: SUBTREE AND ALL DRAWERS")))
5996 (select-window win)))
5998 (defun org-recenter-heading (n)
5999 (save-excursion
6000 (org-back-to-heading)
6001 (recenter n)))
6003 (defvar org-agenda-cycle-counter nil)
6004 (defun org-agenda-cycle-show (&optional n)
6005 "Show the current entry in another window, with default settings.
6006 Default settings are taken from `org-show-hierarchy-above' and siblings.
6007 When use repeatedly in immediate succession, the remote entry will cycle
6008 through visibility
6010 children -> subtree -> folded
6012 When called with a numeric prefix arg, that arg will be passed through to
6013 `org-agenda-show-1'. For the interpretation of that argument, see the
6014 docstring of `org-agenda-show-1'."
6015 (interactive "P")
6016 (if (integerp n)
6017 (setq org-agenda-cycle-counter n)
6018 (if (not (eq last-command this-command))
6019 (setq org-agenda-cycle-counter 1)
6020 (if (equal org-agenda-cycle-counter 0)
6021 (setq org-agenda-cycle-counter 2)
6022 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6023 (if (> org-agenda-cycle-counter 3)
6024 (setq org-agenda-cycle-counter 0)))))
6025 (org-agenda-show-1 org-agenda-cycle-counter))
6027 (defun org-agenda-recenter (arg)
6028 "Display the Org-mode file which contains the item at point and recenter."
6029 (interactive "P")
6030 (let ((win (selected-window)))
6031 (org-agenda-goto t)
6032 (recenter arg)
6033 (select-window win)))
6035 (defun org-agenda-show-mouse (ev)
6036 "Display the Org-mode file which contains the item at the mouse click."
6037 (interactive "e")
6038 (mouse-set-point ev)
6039 (org-agenda-show))
6041 (defun org-agenda-check-no-diary ()
6042 "Check if the entry is a diary link and abort if yes."
6043 (if (org-get-at-bol 'org-agenda-diary-link)
6044 (org-agenda-error)))
6046 (defun org-agenda-error ()
6047 (error "Command not allowed in this line"))
6049 (defun org-agenda-tree-to-indirect-buffer ()
6050 "Show the subtree corresponding to the current entry in an indirect buffer.
6051 This calls the command `org-tree-to-indirect-buffer' from the original
6052 Org-mode buffer.
6053 With numerical prefix arg ARG, go up to this level and then take that tree.
6054 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6055 dedicated frame)."
6056 (interactive)
6057 (org-agenda-check-no-diary)
6058 (let* ((marker (or (org-get-at-bol 'org-marker)
6059 (org-agenda-error)))
6060 (buffer (marker-buffer marker))
6061 (pos (marker-position marker)))
6062 (with-current-buffer buffer
6063 (save-excursion
6064 (goto-char pos)
6065 (call-interactively 'org-tree-to-indirect-buffer)))))
6067 (defvar org-last-heading-marker (make-marker)
6068 "Marker pointing to the headline that last changed its TODO state
6069 by a remote command from the agenda.")
6071 (defun org-agenda-todo-nextset ()
6072 "Switch TODO entry to next sequence."
6073 (interactive)
6074 (org-agenda-todo 'nextset))
6076 (defun org-agenda-todo-previousset ()
6077 "Switch TODO entry to previous sequence."
6078 (interactive)
6079 (org-agenda-todo 'previousset))
6081 (defun org-agenda-todo (&optional arg)
6082 "Cycle TODO state of line at point, also in Org-mode file.
6083 This changes the line at point, all other lines in the agenda referring to
6084 the same tree node, and the headline of the tree node in the Org-mode file."
6085 (interactive "P")
6086 (org-agenda-check-no-diary)
6087 (let* ((col (current-column))
6088 (marker (or (org-get-at-bol 'org-marker)
6089 (org-agenda-error)))
6090 (buffer (marker-buffer marker))
6091 (pos (marker-position marker))
6092 (hdmarker (org-get-at-bol 'org-hd-marker))
6093 (todayp (equal (org-get-at-bol 'day)
6094 (time-to-days (current-time))))
6095 (inhibit-read-only t)
6096 org-agenda-headline-snapshot-before-repeat newhead just-one)
6097 (org-with-remote-undo buffer
6098 (with-current-buffer buffer
6099 (widen)
6100 (goto-char pos)
6101 (org-show-context 'agenda)
6102 (save-excursion
6103 (and (outline-next-heading)
6104 (org-flag-heading nil))) ; show the next heading
6105 (let ((current-prefix-arg arg))
6106 (call-interactively 'org-todo))
6107 (and (bolp) (forward-char 1))
6108 (setq newhead (org-get-heading))
6109 (when (and (org-bound-and-true-p
6110 org-agenda-headline-snapshot-before-repeat)
6111 (not (equal org-agenda-headline-snapshot-before-repeat
6112 newhead))
6113 todayp)
6114 (setq newhead org-agenda-headline-snapshot-before-repeat
6115 just-one t))
6116 (save-excursion
6117 (org-back-to-heading)
6118 (move-marker org-last-heading-marker (point))))
6119 (beginning-of-line 1)
6120 (save-excursion
6121 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6122 (org-move-to-column col))))
6124 (defun org-agenda-add-note (&optional arg)
6125 "Add a time-stamped note to the entry at point."
6126 (interactive "P")
6127 (org-agenda-check-no-diary)
6128 (let* ((marker (or (org-get-at-bol 'org-marker)
6129 (org-agenda-error)))
6130 (buffer (marker-buffer marker))
6131 (pos (marker-position marker))
6132 (hdmarker (org-get-at-bol 'org-hd-marker))
6133 (inhibit-read-only t))
6134 (with-current-buffer buffer
6135 (widen)
6136 (goto-char pos)
6137 (org-show-context 'agenda)
6138 (save-excursion
6139 (and (outline-next-heading)
6140 (org-flag-heading nil))) ; show the next heading
6141 (org-add-note))))
6143 (defun org-agenda-change-all-lines (newhead hdmarker
6144 &optional fixface just-this)
6145 "Change all lines in the agenda buffer which match HDMARKER.
6146 The new content of the line will be NEWHEAD (as modified by
6147 `org-format-agenda-item'). HDMARKER is checked with
6148 `equal' against all `org-hd-marker' text properties in the file.
6149 If FIXFACE is non-nil, the face of each item is modified according to
6150 the new TODO state.
6151 If JUST-THIS is non-nil, change just the current line, not all.
6152 If FORCE-TAGS is non nil, the car of it returns the new tags."
6153 (let* ((inhibit-read-only t)
6154 (line (org-current-line))
6155 (thetags (with-current-buffer (marker-buffer hdmarker)
6156 (save-excursion (save-restriction (widen)
6157 (goto-char hdmarker)
6158 (org-get-tags-at)))))
6159 props m pl undone-face done-face finish new dotime cat tags)
6160 (save-excursion
6161 (goto-char (point-max))
6162 (beginning-of-line 1)
6163 (while (not finish)
6164 (setq finish (bobp))
6165 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6166 (or (not just-this) (= (org-current-line) line))
6167 (equal m hdmarker))
6168 (setq props (text-properties-at (point))
6169 dotime (org-get-at-bol 'dotime)
6170 cat (org-get-at-bol 'org-category)
6171 tags thetags
6172 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6173 pl (org-get-at-bol 'prefix-length)
6174 undone-face (org-get-at-bol 'undone-face)
6175 done-face (org-get-at-bol 'done-face))
6176 (goto-char (+ (point) pl))
6177 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6178 (cond
6179 ((equal new "")
6180 (beginning-of-line 1)
6181 (and (looking-at ".*\n?") (replace-match "")))
6182 ((looking-at ".*")
6183 (replace-match new t t)
6184 (beginning-of-line 1)
6185 (add-text-properties (point-at-bol) (point-at-eol) props)
6186 (when fixface
6187 (add-text-properties
6188 (point-at-bol) (point-at-eol)
6189 (list 'face
6190 (if org-last-todo-state-is-todo
6191 undone-face done-face))))
6192 (org-agenda-highlight-todo 'line)
6193 (beginning-of-line 1))
6194 (t (error "Line update did not work"))))
6195 (beginning-of-line 0)))
6196 (org-finalize-agenda)))
6198 (defun org-agenda-align-tags (&optional line)
6199 "Align all tags in agenda items to `org-agenda-tags-column'."
6200 (let ((inhibit-read-only t) l c)
6201 (save-excursion
6202 (goto-char (if line (point-at-bol) (point-min)))
6203 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6204 (if line (point-at-eol) nil) t)
6205 (add-text-properties
6206 (match-beginning 2) (match-end 2)
6207 (list 'face (delq nil (let ((prop (get-text-property
6208 (match-beginning 2) 'face)))
6209 (or (listp prop) (setq prop (list prop)))
6210 (if (memq 'org-tag prop)
6211 prop
6212 (cons 'org-tag prop))))))
6213 (setq l (- (match-end 2) (match-beginning 2))
6214 c (if (< org-agenda-tags-column 0)
6215 (- (abs org-agenda-tags-column) l)
6216 org-agenda-tags-column))
6217 (delete-region (match-beginning 1) (match-end 1))
6218 (goto-char (match-beginning 1))
6219 (insert (org-add-props
6220 (make-string (max 1 (- c (current-column))) ?\ )
6221 (text-properties-at (point)))))
6222 (goto-char (point-min))
6223 (org-font-lock-add-tag-faces (point-max)))))
6225 (defun org-agenda-priority-up ()
6226 "Increase the priority of line at point, also in Org-mode file."
6227 (interactive)
6228 (org-agenda-priority 'up))
6230 (defun org-agenda-priority-down ()
6231 "Decrease the priority of line at point, also in Org-mode file."
6232 (interactive)
6233 (org-agenda-priority 'down))
6235 (defun org-agenda-priority (&optional force-direction)
6236 "Set the priority of line at point, also in Org-mode file.
6237 This changes the line at point, all other lines in the agenda referring to
6238 the same tree node, and the headline of the tree node in the Org-mode file."
6239 (interactive)
6240 (unless org-enable-priority-commands
6241 (error "Priority commands are disabled"))
6242 (org-agenda-check-no-diary)
6243 (let* ((marker (or (org-get-at-bol 'org-marker)
6244 (org-agenda-error)))
6245 (hdmarker (org-get-at-bol 'org-hd-marker))
6246 (buffer (marker-buffer hdmarker))
6247 (pos (marker-position hdmarker))
6248 (inhibit-read-only t)
6249 newhead)
6250 (org-with-remote-undo buffer
6251 (with-current-buffer buffer
6252 (widen)
6253 (goto-char pos)
6254 (org-show-context 'agenda)
6255 (save-excursion
6256 (and (outline-next-heading)
6257 (org-flag-heading nil))) ; show the next heading
6258 (funcall 'org-priority force-direction)
6259 (end-of-line 1)
6260 (setq newhead (org-get-heading)))
6261 (org-agenda-change-all-lines newhead hdmarker)
6262 (beginning-of-line 1))))
6264 ;; FIXME: should fix the tags property of the agenda line.
6265 (defun org-agenda-set-tags (&optional tag onoff)
6266 "Set tags for the current headline."
6267 (interactive)
6268 (org-agenda-check-no-diary)
6269 (if (and (org-region-active-p) (interactive-p))
6270 (call-interactively 'org-change-tag-in-region)
6271 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6272 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6273 (org-agenda-error)))
6274 (buffer (marker-buffer hdmarker))
6275 (pos (marker-position hdmarker))
6276 (inhibit-read-only t)
6277 newhead)
6278 (org-with-remote-undo buffer
6279 (with-current-buffer buffer
6280 (widen)
6281 (goto-char pos)
6282 (save-excursion
6283 (org-show-context 'agenda))
6284 (save-excursion
6285 (and (outline-next-heading)
6286 (org-flag-heading nil))) ; show the next heading
6287 (goto-char pos)
6288 (if tag
6289 (org-toggle-tag tag onoff)
6290 (call-interactively 'org-set-tags))
6291 (end-of-line 1)
6292 (setq newhead (org-get-heading)))
6293 (org-agenda-change-all-lines newhead hdmarker)
6294 (beginning-of-line 1)))))
6296 (defun org-agenda-set-property ()
6297 "Set a property for the current headline."
6298 (interactive)
6299 (org-agenda-check-no-diary)
6300 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6301 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6302 (org-agenda-error)))
6303 (buffer (marker-buffer hdmarker))
6304 (pos (marker-position hdmarker))
6305 (inhibit-read-only t)
6306 newhead)
6307 (org-with-remote-undo buffer
6308 (with-current-buffer buffer
6309 (widen)
6310 (goto-char pos)
6311 (save-excursion
6312 (org-show-context 'agenda))
6313 (save-excursion
6314 (and (outline-next-heading)
6315 (org-flag-heading nil))) ; show the next heading
6316 (goto-char pos)
6317 (call-interactively 'org-set-property)))))
6319 (defun org-agenda-set-effort ()
6320 "Set the effort property for the current headline."
6321 (interactive)
6322 (org-agenda-check-no-diary)
6323 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6324 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6325 (org-agenda-error)))
6326 (buffer (marker-buffer hdmarker))
6327 (pos (marker-position hdmarker))
6328 (inhibit-read-only t)
6329 newhead)
6330 (org-with-remote-undo buffer
6331 (with-current-buffer buffer
6332 (widen)
6333 (goto-char pos)
6334 (save-excursion
6335 (org-show-context 'agenda))
6336 (save-excursion
6337 (and (outline-next-heading)
6338 (org-flag-heading nil))) ; show the next heading
6339 (goto-char pos)
6340 (call-interactively 'org-set-effort)
6341 (end-of-line 1)))))
6343 (defun org-agenda-toggle-archive-tag ()
6344 "Toggle the archive tag for the current entry."
6345 (interactive)
6346 (org-agenda-check-no-diary)
6347 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6348 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6349 (org-agenda-error)))
6350 (buffer (marker-buffer hdmarker))
6351 (pos (marker-position hdmarker))
6352 (inhibit-read-only t)
6353 newhead)
6354 (org-with-remote-undo buffer
6355 (with-current-buffer buffer
6356 (widen)
6357 (goto-char pos)
6358 (org-show-context 'agenda)
6359 (save-excursion
6360 (and (outline-next-heading)
6361 (org-flag-heading nil))) ; show the next heading
6362 (call-interactively 'org-toggle-archive-tag)
6363 (end-of-line 1)
6364 (setq newhead (org-get-heading)))
6365 (org-agenda-change-all-lines newhead hdmarker)
6366 (beginning-of-line 1))))
6368 (defun org-agenda-do-date-later (arg)
6369 (interactive "P")
6370 (cond
6371 ((or (equal arg '(16))
6372 (memq last-command
6373 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6374 (setq this-command 'org-agenda-date-later-minutes)
6375 (org-agenda-date-later-minutes 1))
6376 ((or (equal arg '(4))
6377 (memq last-command
6378 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6379 (setq this-command 'org-agenda-date-later-hours)
6380 (org-agenda-date-later-hours 1))
6382 (org-agenda-date-later (prefix-numeric-value arg)))))
6384 (defun org-agenda-do-date-earlier (arg)
6385 (interactive "P")
6386 (cond
6387 ((or (equal arg '(16))
6388 (memq last-command
6389 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6390 (setq this-command 'org-agenda-date-earlier-minutes)
6391 (org-agenda-date-earlier-minutes 1))
6392 ((or (equal arg '(4))
6393 (memq last-command
6394 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6395 (setq this-command 'org-agenda-date-earlier-hours)
6396 (org-agenda-date-earlier-hours 1))
6398 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6400 (defun org-agenda-date-later (arg &optional what)
6401 "Change the date of this item to one day later."
6402 (interactive "p")
6403 (org-agenda-check-type t 'agenda 'timeline)
6404 (org-agenda-check-no-diary)
6405 (let* ((marker (or (org-get-at-bol 'org-marker)
6406 (org-agenda-error)))
6407 (buffer (marker-buffer marker))
6408 (pos (marker-position marker)))
6409 (org-with-remote-undo buffer
6410 (with-current-buffer buffer
6411 (widen)
6412 (goto-char pos)
6413 (if (not (org-at-timestamp-p))
6414 (error "Cannot find time stamp"))
6415 (org-timestamp-change arg (or what 'day)))
6416 (org-agenda-show-new-time marker org-last-changed-timestamp))
6417 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6419 (defun org-agenda-date-earlier (arg &optional what)
6420 "Change the date of this item to one day earlier."
6421 (interactive "p")
6422 (org-agenda-date-later (- arg) what))
6424 (defun org-agenda-date-later-minutes (arg)
6425 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6426 (interactive "p")
6427 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6428 (org-agenda-date-later arg 'minute))
6430 (defun org-agenda-date-earlier-minutes (arg)
6431 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6432 (interactive "p")
6433 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6434 (org-agenda-date-earlier arg 'minute))
6436 (defun org-agenda-date-later-hours (arg)
6437 "Change the time of this item, in hour steps."
6438 (interactive "p")
6439 (org-agenda-date-later arg 'hour))
6441 (defun org-agenda-date-earlier-hours (arg)
6442 "Change the time of this item, in hour steps."
6443 (interactive "p")
6444 (org-agenda-date-earlier arg 'hour))
6446 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6447 "Show new date stamp via text properties."
6448 ;; We use text properties to make this undoable
6449 (let ((inhibit-read-only t)
6450 (buffer-invisibility-spec))
6451 (setq stamp (concat " " prefix " => " stamp))
6452 (save-excursion
6453 (goto-char (point-max))
6454 (while (not (bobp))
6455 (when (equal marker (org-get-at-bol 'org-marker))
6456 (org-move-to-column (- (window-width) (length stamp)) t)
6457 (org-agenda-fix-tags-filter-overlays-at (point))
6458 (if (featurep 'xemacs)
6459 ;; Use `duplicable' property to trigger undo recording
6460 (let ((ex (make-extent nil nil))
6461 (gl (make-glyph stamp)))
6462 (set-glyph-face gl 'secondary-selection)
6463 (set-extent-properties
6464 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6465 (insert-extent ex (1- (point)) (point-at-eol)))
6466 (add-text-properties
6467 (1- (point)) (point-at-eol)
6468 (list 'display (org-add-props stamp nil
6469 'face 'secondary-selection))))
6470 (beginning-of-line 1))
6471 (beginning-of-line 0)))))
6473 (defun org-agenda-date-prompt (arg)
6474 "Change the date of this item. Date is prompted for, with default today.
6475 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6476 be used to request time specification in the time stamp."
6477 (interactive "P")
6478 (org-agenda-check-type t 'agenda 'timeline)
6479 (org-agenda-check-no-diary)
6480 (let* ((marker (or (org-get-at-bol 'org-marker)
6481 (org-agenda-error)))
6482 (buffer (marker-buffer marker))
6483 (pos (marker-position marker)))
6484 (org-with-remote-undo buffer
6485 (with-current-buffer buffer
6486 (widen)
6487 (goto-char pos)
6488 (if (not (org-at-timestamp-p))
6489 (error "Cannot find time stamp"))
6490 (org-time-stamp arg))
6491 (org-agenda-show-new-time marker org-last-changed-timestamp))
6492 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6494 (defun org-agenda-schedule (arg)
6495 "Schedule the item at point."
6496 (interactive "P")
6497 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6498 (org-agenda-check-no-diary)
6499 (let* ((marker (or (org-get-at-bol 'org-marker)
6500 (org-agenda-error)))
6501 (type (marker-insertion-type marker))
6502 (buffer (marker-buffer marker))
6503 (pos (marker-position marker))
6504 (org-insert-labeled-timestamps-at-point nil)
6506 (set-marker-insertion-type marker t)
6507 (org-with-remote-undo buffer
6508 (with-current-buffer buffer
6509 (widen)
6510 (goto-char pos)
6511 (setq ts (org-schedule arg)))
6512 (org-agenda-show-new-time marker ts "S"))
6513 (message "Item scheduled for %s" ts)))
6515 (defun org-agenda-deadline (arg)
6516 "Schedule the item at point."
6517 (interactive "P")
6518 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6519 (org-agenda-check-no-diary)
6520 (let* ((marker (or (org-get-at-bol 'org-marker)
6521 (org-agenda-error)))
6522 (buffer (marker-buffer marker))
6523 (pos (marker-position marker))
6524 (org-insert-labeled-timestamps-at-point nil)
6526 (org-with-remote-undo buffer
6527 (with-current-buffer buffer
6528 (widen)
6529 (goto-char pos)
6530 (setq ts (org-deadline arg)))
6531 (org-agenda-show-new-time marker ts "D"))
6532 (message "Deadline for this item set to %s" ts)))
6534 (defun org-agenda-action ()
6535 "Select entry for agenda action, or execute an agenda action.
6536 This command prompts for another letter. Valid inputs are:
6538 m Mark the entry at point for an agenda action
6539 s Schedule the marked entry to the date at the cursor
6540 d Set the deadline of the marked entry to the date at the cursor
6541 r Call `org-remember' with cursor date as the default date
6542 SPC Show marked entry in other window
6543 TAB Visit marked entry in other window
6545 The cursor may be at a date in the calendar, or in the Org agenda."
6546 (interactive)
6547 (let (ans)
6548 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6549 (setq ans (read-char-exclusive))
6550 (cond
6551 ((equal ans ?m)
6552 ;; Mark this entry
6553 (if (eq major-mode 'org-agenda-mode)
6554 (let ((m (or (org-get-at-bol 'org-hd-marker)
6555 (org-get-at-bol 'org-marker))))
6556 (if m
6557 (progn
6558 (move-marker org-agenda-action-marker
6559 (marker-position m) (marker-buffer m))
6560 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6561 (error "Don't know which entry to mark")))
6562 (error "This command works only in the agenda")))
6563 ((equal ans ?s)
6564 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6565 ((equal ans ?d)
6566 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6567 ((equal ans ?r)
6568 (org-agenda-do-action '(org-remember) t))
6569 ((equal ans ?\ )
6570 (let ((cw (selected-window)))
6571 (org-switch-to-buffer-other-window
6572 (marker-buffer org-agenda-action-marker))
6573 (goto-char org-agenda-action-marker)
6574 (org-show-context 'agenda)
6575 (select-window cw)))
6576 ((equal ans ?\C-i)
6577 (org-switch-to-buffer-other-window
6578 (marker-buffer org-agenda-action-marker))
6579 (goto-char org-agenda-action-marker)
6580 (org-show-context 'agenda))
6581 (t (error "Invalid agenda action %c" ans)))))
6583 (defun org-agenda-do-action (form &optional current-buffer)
6584 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6585 (let ((org-overriding-default-time (org-get-cursor-date)))
6586 (if current-buffer
6587 (eval form)
6588 (if (not (marker-buffer org-agenda-action-marker))
6589 (error "No entry has been selected for agenda action")
6590 (with-current-buffer (marker-buffer org-agenda-action-marker)
6591 (save-excursion
6592 (save-restriction
6593 (widen)
6594 (goto-char org-agenda-action-marker)
6595 (eval form))))))))
6597 (defun org-agenda-clock-in (&optional arg)
6598 "Start the clock on the currently selected item."
6599 (interactive "P")
6600 (org-agenda-check-no-diary)
6601 (if (equal arg '(4))
6602 (org-clock-in arg)
6603 (let* ((marker (or (org-get-at-bol 'org-marker)
6604 (org-agenda-error)))
6605 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6606 marker))
6607 (pos (marker-position marker))
6608 newhead)
6609 (org-with-remote-undo (marker-buffer marker)
6610 (with-current-buffer (marker-buffer marker)
6611 (widen)
6612 (goto-char pos)
6613 (org-show-context 'agenda)
6614 (org-show-entry)
6615 (org-cycle-hide-drawers 'children)
6616 (org-clock-in arg)
6617 (setq newhead (org-get-heading)))
6618 (org-agenda-change-all-lines newhead hdmarker)))))
6620 (defun org-agenda-clock-out (&optional arg)
6621 "Stop the currently running clock."
6622 (interactive "P")
6623 (unless (marker-buffer org-clock-marker)
6624 (error "No running clock"))
6625 (let ((marker (make-marker)) newhead)
6626 (org-with-remote-undo (marker-buffer org-clock-marker)
6627 (with-current-buffer (marker-buffer org-clock-marker)
6628 (save-excursion
6629 (save-restriction
6630 (widen)
6631 (goto-char org-clock-marker)
6632 (org-back-to-heading t)
6633 (move-marker marker (point))
6634 (org-clock-out)
6635 (setq newhead (org-get-heading))))))
6636 (org-agenda-change-all-lines newhead marker)
6637 (move-marker marker nil)))
6639 (defun org-agenda-clock-cancel (&optional arg)
6640 "Cancel the currently running clock."
6641 (interactive "P")
6642 (unless (marker-buffer org-clock-marker)
6643 (error "No running clock"))
6644 (org-with-remote-undo (marker-buffer org-clock-marker)
6645 (org-clock-cancel)))
6647 (defun org-agenda-diary-entry ()
6648 "Make a diary entry, like the `i' command from the calendar.
6649 All the standard commands work: block, weekly etc."
6650 (interactive)
6651 (org-agenda-check-type t 'agenda 'timeline)
6652 (require 'diary-lib)
6653 (let* ((char (progn
6654 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6655 (read-char-exclusive)))
6656 (cmd (cdr (assoc char
6657 '((?d . insert-diary-entry)
6658 (?w . insert-weekly-diary-entry)
6659 (?m . insert-monthly-diary-entry)
6660 (?y . insert-yearly-diary-entry)
6661 (?a . insert-anniversary-diary-entry)
6662 (?b . insert-block-diary-entry)
6663 (?c . insert-cyclic-diary-entry)))))
6664 (oldf (symbol-function 'calendar-cursor-to-date))
6665 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6666 (point (point))
6667 (mark (or (mark t) (point))))
6668 (unless cmd
6669 (error "No command associated with <%c>" char))
6670 (unless (and (get-text-property point 'day)
6671 (or (not (equal ?b char))
6672 (get-text-property mark 'day)))
6673 (error "Don't know which date to use for diary entry"))
6674 ;; We implement this by hacking the `calendar-cursor-to-date' function
6675 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6676 (let ((calendar-mark-ring
6677 (list (calendar-gregorian-from-absolute
6678 (or (get-text-property mark 'day)
6679 (get-text-property point 'day))))))
6680 (unwind-protect
6681 (progn
6682 (fset 'calendar-cursor-to-date
6683 (lambda (&optional error dummy)
6684 (calendar-gregorian-from-absolute
6685 (get-text-property point 'day))))
6686 (call-interactively cmd))
6687 (fset 'calendar-cursor-to-date oldf)))))
6689 (defun org-agenda-execute-calendar-command (cmd)
6690 "Execute a calendar command from the agenda, with the date associated to
6691 the cursor position."
6692 (org-agenda-check-type t 'agenda 'timeline)
6693 (require 'diary-lib)
6694 (unless (get-text-property (point) 'day)
6695 (error "Don't know which date to use for calendar command"))
6696 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
6697 (point (point))
6698 (date (calendar-gregorian-from-absolute
6699 (get-text-property point 'day)))
6700 ;; the following 2 vars are needed in the calendar
6701 (displayed-month (car date))
6702 (displayed-year (nth 2 date)))
6703 (unwind-protect
6704 (progn
6705 (fset 'calendar-cursor-to-date
6706 (lambda (&optional error dummy)
6707 (calendar-gregorian-from-absolute
6708 (get-text-property point 'day))))
6709 (call-interactively cmd))
6710 (fset 'calendar-cursor-to-date oldf))))
6712 (defun org-agenda-phases-of-moon ()
6713 "Display the phases of the moon for the 3 months around the cursor date."
6714 (interactive)
6715 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
6717 (defun org-agenda-holidays ()
6718 "Display the holidays for the 3 months around the cursor date."
6719 (interactive)
6720 (org-agenda-execute-calendar-command 'list-calendar-holidays))
6722 (defvar calendar-longitude)
6723 (defvar calendar-latitude)
6724 (defvar calendar-location-name)
6726 (defun org-agenda-sunrise-sunset (arg)
6727 "Display sunrise and sunset for the cursor date.
6728 Latitude and longitude can be specified with the variables
6729 `calendar-latitude' and `calendar-longitude'. When called with prefix
6730 argument, latitude and longitude will be prompted for."
6731 (interactive "P")
6732 (require 'solar)
6733 (let ((calendar-longitude (if arg nil calendar-longitude))
6734 (calendar-latitude (if arg nil calendar-latitude))
6735 (calendar-location-name
6736 (if arg "the given coordinates" calendar-location-name)))
6737 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
6739 (defun org-agenda-goto-calendar ()
6740 "Open the Emacs calendar with the date at the cursor."
6741 (interactive)
6742 (org-agenda-check-type t 'agenda 'timeline)
6743 (let* ((day (or (get-text-property (point) 'day)
6744 (error "Don't know which date to open in calendar")))
6745 (date (calendar-gregorian-from-absolute day))
6746 (calendar-move-hook nil)
6747 (calendar-view-holidays-initially-flag nil)
6748 (calendar-view-diary-initially-flag nil)
6749 (view-calendar-holidays-initially nil)
6750 (view-diary-entries-initially nil))
6751 (calendar)
6752 (calendar-goto-date date)))
6754 ;;;###autoload
6755 (defun org-calendar-goto-agenda ()
6756 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6757 This is a command that has to be installed in `calendar-mode-map'."
6758 (interactive)
6759 (org-agenda-list nil (calendar-absolute-from-gregorian
6760 (calendar-cursor-to-date))
6761 nil))
6763 (defun org-agenda-convert-date ()
6764 (interactive)
6765 (org-agenda-check-type t 'agenda 'timeline)
6766 (let ((day (get-text-property (point) 'day))
6767 date s)
6768 (unless day
6769 (error "Don't know which date to convert"))
6770 (setq date (calendar-gregorian-from-absolute day))
6771 (setq s (concat
6772 "Gregorian: " (calendar-date-string date) "\n"
6773 "ISO: " (calendar-iso-date-string date) "\n"
6774 "Day of Yr: " (calendar-day-of-year-string date) "\n"
6775 "Julian: " (calendar-julian-date-string date) "\n"
6776 "Astron. JD: " (calendar-astro-date-string date)
6777 " (Julian date number at noon UTC)\n"
6778 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
6779 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
6780 "French: " (calendar-french-date-string date) "\n"
6781 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
6782 "Mayan: " (calendar-mayan-date-string date) "\n"
6783 "Coptic: " (calendar-coptic-date-string date) "\n"
6784 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
6785 "Persian: " (calendar-persian-date-string date) "\n"
6786 "Chinese: " (calendar-chinese-date-string date) "\n"))
6787 (with-output-to-temp-buffer "*Dates*"
6788 (princ s))
6789 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6791 ;;; Bulk commands
6793 (defvar org-agenda-bulk-marked-entries nil
6794 "List of markers that refer to marked entries in the agenda.")
6796 (defun org-agenda-bulk-marked-p ()
6797 (eq (get-char-property (point-at-bol) 'type)
6798 'org-marked-entry-overlay))
6800 (defun org-agenda-bulk-mark ()
6801 "Mark the entry at point for future bulk action."
6802 (interactive)
6803 (org-agenda-check-no-diary)
6804 (let* ((m (org-get-at-bol 'org-hd-marker))
6806 (unless (org-agenda-bulk-marked-p)
6807 (unless m (error "Nothing to mark at point"))
6808 (push m org-agenda-bulk-marked-entries)
6809 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
6810 (org-overlay-display ov "> "
6811 (org-get-todo-face "TODO")
6812 'evaporate)
6813 (org-overlay-put ov 'type 'org-marked-entry-overlay))
6814 (beginning-of-line 2)
6815 (message "%d entries marked for bulk action"
6816 (length org-agenda-bulk-marked-entries))))
6818 (defun org-agenda-bulk-unmark ()
6819 "Unmark the entry at point for future bulk action."
6820 (interactive)
6821 (when (org-agenda-bulk-marked-p)
6822 (org-agenda-bulk-remove-overlays
6823 (point-at-bol) (+ 2 (point-at-bol)))
6824 (setq org-agenda-bulk-marked-entries
6825 (delete (org-get-at-bol 'org-hd-marker)
6826 org-agenda-bulk-marked-entries)))
6827 (beginning-of-line 2)
6828 (message "%d entries marked for bulk action"
6829 (length org-agenda-bulk-marked-entries)))
6831 (defun org-agenda-bulk-toggle ()
6832 "Toggle marking the entry at point for bulk action."
6833 (interactive)
6834 (if (org-agenda-bulk-marked-p)
6835 (org-agenda-bulk-unmark)
6836 (org-agenda-bulk-mark)))
6838 (defun org-agenda-bulk-remove-overlays (&optional beg end)
6839 "Remove the mark overlays between BEG and END in the agenda buffer.
6840 BEG and END default to the buffer limits.
6842 This only removes the overlays, it does not remove the markers
6843 from the list in `org-agenda-bulk-marked-entries'."
6844 (interactive)
6845 (mapc (lambda (ov)
6846 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
6847 (org-delete-overlay ov)))
6848 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
6850 (defun org-agenda-bulk-remove-all-marks ()
6851 "Remove all marks in the agenda buffer.
6852 This will remove the markers, and the overlays."
6853 (interactive)
6854 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
6855 (setq org-agenda-bulk-marked-entries nil)
6856 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
6858 (defun org-agenda-bulk-action ()
6859 "Execute an remote-editing action on all marked entries."
6860 (interactive)
6861 (unless org-agenda-bulk-marked-entries
6862 (error "No entries are marked"))
6863 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
6864 (let* ((action (read-char-exclusive))
6865 (entries (reverse org-agenda-bulk-marked-entries))
6866 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
6867 (cond
6868 ((equal action ?$)
6869 (setq cmd '(org-agenda-archive)))
6871 ((equal action ?A)
6872 (setq cmd '(org-agenda-archive-to-archive-sibling)))
6874 ((member action '(?r ?w))
6875 (setq rfloc (org-refile-get-location
6876 "Refile to: "
6877 (marker-buffer (car org-agenda-bulk-marked-entries))
6878 org-refile-allow-creating-parent-nodes))
6879 (setcar (nthcdr 3 rfloc)
6880 (move-marker (make-marker) (nth 3 rfloc)
6881 (or (get-file-buffer (nth 1 rfloc))
6882 (find-buffer-visiting (nth 1 rfloc))
6883 (error "This should not happen"))))
6885 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
6887 ((equal action ?t)
6888 (setq state (org-icompleting-read
6889 "Todo state: "
6890 (with-current-buffer (marker-buffer (car entries))
6891 (mapcar 'list org-todo-keywords-1))))
6892 (setq cmd `(let ((org-inhibit-blocking t)
6893 (org-inhibit-logging 'note))
6894 (org-agenda-todo ,state))))
6896 ((memq action '(?- ?+))
6897 (setq tag (org-icompleting-read
6898 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
6899 (with-current-buffer (marker-buffer (car entries))
6900 (delq nil
6901 (mapcar (lambda (x)
6902 (if (stringp (car x)) x)) org-tag-alist)))))
6903 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
6905 ((memq action '(?s ?d))
6906 (let* ((date (org-read-date
6907 nil nil nil
6908 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
6909 (ans org-read-date-final-answer)
6910 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
6911 (setq cmd `(let* ((bound (fboundp 'read-string))
6912 (old (and bound (symbol-function 'read-string))))
6913 (unwind-protect
6914 (progn
6915 (fset 'read-string (lambda (&rest ignore) ,ans))
6916 (call-interactively ',c1))
6917 (if bound
6918 (fset 'read-string old)
6919 (fmakunbound 'read-string)))))))
6920 (t (error "Invalid bulk action")))
6922 ;; Sort the markers, to make sure that parents are handled before children
6923 (setq entries (sort entries
6924 (lambda (a b)
6925 (cond
6926 ((equal (marker-buffer a) (marker-buffer b))
6927 (< (marker-position a) (marker-position b)))
6929 (string< (buffer-name (marker-buffer a))
6930 (buffer-name (marker-buffer b))))))))
6932 ;; Now loop over all markers and apply cmd
6933 (while (setq e (pop entries))
6934 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
6935 (if (not pos)
6936 (progn (message "Skipping removed entry at %s" e)
6937 (setq cntskip (1+ cntskip)))
6938 (goto-char pos)
6939 (eval cmd)
6940 (setq org-agenda-bulk-marked-entries
6941 (delete e org-agenda-bulk-marked-entries))
6942 (setq cnt (1+ cnt))))
6943 (setq org-agenda-bulk-marked-entries nil)
6944 (org-agenda-bulk-remove-all-marks)
6945 (message "Acted on %d entries%s"
6947 (if (= cntskip 0)
6949 (format ", skipped %d (disappeared before their turn)"
6950 cntskip)))))
6952 ;;; Flagging notes
6954 (defun org-agenda-show-the-flagging-note ()
6955 "Display the flagging note in the other window.
6956 When called a second time in direct sequence, offer to remove the FLAGGING
6957 tag and (if present) the flagging note."
6958 (interactive)
6959 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
6960 (win (selected-window))
6961 note heading newhead)
6962 (unless hdmarker
6963 (error "No linked entry at point"))
6964 (if (and (eq this-command last-command)
6965 (y-or-n-p "Unflag and remove any flagging note? "))
6966 (progn
6967 (org-agenda-remove-flag hdmarker)
6968 (let ((win (get-buffer-window "*Flagging Note*")))
6969 (and win (delete-window win)))
6970 (message "Entry unflaged"))
6971 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
6972 (unless note
6973 (error "No flagging note"))
6974 (org-kill-new note)
6975 (org-switch-to-buffer-other-window "*Flagging Note*")
6976 (erase-buffer)
6977 (insert note)
6978 (goto-char (point-min))
6979 (while (re-search-forward "\\\\n" nil t)
6980 (replace-match "\n" t t))
6981 (goto-char (point-min))
6982 (select-window win)
6983 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
6985 (defun org-agenda-remove-flag (marker)
6986 "Remove the FLAGGED tag and any flaging note in the entry."
6987 (let (newhead)
6988 (org-with-point-at marker
6989 (org-toggle-tag "FLAGGED" 'off)
6990 (org-entry-delete nil "THEFLAGGINGNOTE")
6991 (setq newhead (org-get-heading)))
6992 (org-agenda-change-all-lines newhead marker)
6993 (message "Entry unflaged")))
6995 (defun org-agenda-get-any-marker (&optional pos)
6996 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
6997 (get-text-property (or pos (point-at-bol)) 'org-marker)))
6999 ;;; Appointment reminders
7001 (defvar appt-time-msg-list)
7003 ;;;###autoload
7004 (defun org-agenda-to-appt (&optional refresh filter)
7005 "Activate appointments found in `org-agenda-files'.
7006 With a \\[universal-argument] prefix, refresh the list of
7007 appointments.
7009 If FILTER is t, interactively prompt the user for a regular
7010 expression, and filter out entries that don't match it.
7012 If FILTER is a string, use this string as a regular expression
7013 for filtering entries out.
7015 FILTER can also be an alist with the car of each cell being
7016 either 'headline or 'category. For example:
7018 '((headline \"IMPORTANT\")
7019 (category \"Work\"))
7021 will only add headlines containing IMPORTANT or headlines
7022 belonging to the \"Work\" category."
7023 (interactive "P")
7024 (require 'calendar)
7025 (if refresh (setq appt-time-msg-list nil))
7026 (if (eq filter t)
7027 (setq filter (read-from-minibuffer "Regexp filter: ")))
7028 (let* ((cnt 0) ; count added events
7029 (org-agenda-new-buffers nil)
7030 (org-deadline-warning-days 0)
7031 (today (org-date-to-gregorian
7032 (time-to-days (current-time))))
7033 (org-agenda-restrict nil)
7034 (files (org-agenda-files 'unrestricted)) entries file)
7035 ;; Get all entries which may contain an appt
7036 (org-prepare-agenda-buffers files)
7037 (while (setq file (pop files))
7038 (setq entries
7039 (append entries
7040 (org-agenda-get-day-entries
7041 file today :timestamp :scheduled :deadline))))
7042 (setq entries (delq nil entries))
7043 ;; Map thru entries and find if we should filter them out
7044 (mapc
7045 (lambda(x)
7046 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7047 (cat (get-text-property 1 'org-category x))
7048 (tod (get-text-property 1 'time-of-day x))
7049 (ok (or (null filter)
7050 (and (stringp filter) (string-match filter evt))
7051 (and (listp filter)
7052 (or (string-match
7053 (cadr (assoc 'category filter)) cat)
7054 (string-match
7055 (cadr (assoc 'headline filter)) evt))))))
7056 ;; FIXME: Shall we remove text-properties for the appt text?
7057 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7058 (when (and ok tod)
7059 (setq tod (concat "00" (number-to-string tod))
7060 tod (when (string-match
7061 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7062 (concat (match-string 1 tod) ":"
7063 (match-string 2 tod))))
7064 (appt-add tod evt)
7065 (setq cnt (1+ cnt))))) entries)
7066 (org-release-buffers org-agenda-new-buffers)
7067 (if (eq cnt 0)
7068 (message "No event to add")
7069 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7071 (defun org-agenda-todayp (date)
7072 "Does DATE mean today, when considering `org-extend-today-until'?"
7073 (let (today h)
7074 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7075 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7076 (setq h (nth 2 (decode-time (current-time))))
7077 (or (and (>= h org-extend-today-until)
7078 (= date today))
7079 (and (< h org-extend-today-until)
7080 (= date (1- today))))))
7082 (provide 'org-agenda)
7084 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7086 ;;; org-agenda.el ends here