Merge commit 'johnw/master'
[org-mode.git] / lisp / org-agenda.el
blob5e0f4fd56c49316f4d68df28c765330cc9f09072
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'.")
1316 (defvar org-agenda-menu) ; defined later in this file.
1317 (defvar org-agenda-restrict) ; defined later in this file.
1318 (defvar org-agenda-follow-mode nil)
1319 (defvar org-agenda-entry-text-mode nil)
1320 (defvar org-agenda-clockreport-mode nil)
1321 (defvar org-agenda-show-log nil)
1322 (defvar org-agenda-redo-command nil)
1323 (defvar org-agenda-query-string nil)
1324 (defvar org-agenda-mode-hook nil
1325 "Hook for org-agenda-mode, run after the mode is turned on.")
1326 (defvar org-agenda-type nil)
1327 (defvar org-agenda-force-single-file nil)
1328 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1330 (defun org-agenda-mode ()
1331 "Mode for time-sorted view on action items in Org-mode files.
1333 The following commands are available:
1335 \\{org-agenda-mode-map}"
1336 (interactive)
1337 (kill-all-local-variables)
1338 (setq org-agenda-undo-list nil
1339 org-agenda-pending-undo-list nil
1340 org-agenda-bulk-marked-entries nil)
1341 (setq major-mode 'org-agenda-mode)
1342 ;; Keep global-font-lock-mode from turning on font-lock-mode
1343 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1344 (setq mode-name "Org-Agenda")
1345 (use-local-map org-agenda-mode-map)
1346 (easy-menu-add org-agenda-menu)
1347 (if org-startup-truncated (setq truncate-lines t))
1348 (org-set-local 'line-move-visual nil)
1349 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1350 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1351 ;; Make sure properties are removed when copying text
1352 (when (boundp 'buffer-substring-filters)
1353 (org-set-local 'buffer-substring-filters
1354 (cons (lambda (x)
1355 (set-text-properties 0 (length x) nil x) x)
1356 buffer-substring-filters)))
1357 (unless org-agenda-keep-modes
1358 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1359 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1360 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1361 org-agenda-show-log org-agenda-start-with-log-mode))
1363 (easy-menu-change
1364 '("Agenda") "Agenda Files"
1365 (append
1366 (list
1367 (vector
1368 (if (get 'org-agenda-files 'org-restrict)
1369 "Restricted to single file"
1370 "Edit File List")
1371 '(org-edit-agenda-file-list)
1372 (not (get 'org-agenda-files 'org-restrict)))
1373 "--")
1374 (mapcar 'org-file-menu-entry (org-agenda-files))))
1375 (org-agenda-set-mode-name)
1376 (apply
1377 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1378 (list 'org-agenda-mode-hook)))
1380 (substitute-key-definition 'undo 'org-agenda-undo
1381 org-agenda-mode-map global-map)
1382 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1383 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1384 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1385 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1386 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1387 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1388 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1389 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1390 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1391 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1392 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1393 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1394 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1395 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1396 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1397 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1398 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1399 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1400 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1401 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1402 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1403 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1404 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1405 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1406 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1407 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1408 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1409 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1410 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1411 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1412 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1413 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1414 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1415 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1416 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1417 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1418 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1419 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1420 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1421 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1422 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1423 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1424 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1426 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1427 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1428 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1429 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1430 (while l (org-defkey org-agenda-mode-map
1431 (int-to-string (pop l)) 'digit-argument)))
1433 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1434 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1435 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1436 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1437 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1438 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1439 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1440 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1441 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1442 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1443 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1444 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1445 'org-clock-modify-effort-estimate)
1446 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1447 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1448 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1449 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1450 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1451 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1452 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1453 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1454 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1455 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1456 (substitute-key-definition 'next-line 'org-agenda-next-line
1457 org-agenda-mode-map global-map)
1458 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1459 org-agenda-mode-map global-map)
1460 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1461 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1462 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1463 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1464 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1465 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1466 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1467 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1468 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1469 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1470 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1471 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1472 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1473 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1474 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1475 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1476 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1477 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1478 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1479 (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
1480 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1481 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1482 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1483 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1484 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1485 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1486 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1487 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1488 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1489 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1491 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1492 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1493 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1494 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1495 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1496 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1497 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1498 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1499 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1500 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1502 (defvar org-agenda-keymap (copy-keymap org-agenda-mode-map)
1503 "Local keymap for agenda entries from Org-mode.")
1505 (org-defkey org-agenda-keymap
1506 (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
1507 (org-defkey org-agenda-keymap
1508 (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
1509 (when org-agenda-mouse-1-follows-link
1510 (org-defkey org-agenda-keymap [follow-link] 'mouse-face))
1511 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1512 '("Agenda"
1513 ("Agenda Files")
1514 "--"
1515 ("Agenda Dates"
1516 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1517 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1518 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1519 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1520 "--"
1521 ("View"
1522 ["Day View" org-agenda-day-view
1523 :active (org-agenda-check-type nil 'agenda)
1524 :style radio :selected (equal org-agenda-ndays 1)
1525 :keys "v d (or just d)"]
1526 ["Week View" org-agenda-week-view
1527 :active (org-agenda-check-type nil 'agenda)
1528 :style radio :selected (equal org-agenda-ndays 7)
1529 :keys "v w (or just w)"]
1530 ["Month View" org-agenda-month-view
1531 :active (org-agenda-check-type nil 'agenda)
1532 :style radio :selected (member org-agenda-ndays '(28 29 30 31))
1533 :keys "v m"]
1534 ["Year View" org-agenda-year-view
1535 :active (org-agenda-check-type nil 'agenda)
1536 :style radio :selected (member org-agenda-ndays '(365 366))
1537 :keys "v y"]
1538 "--"
1539 ["Include Diary" org-agenda-toggle-diary
1540 :style toggle :selected org-agenda-include-diary
1541 :active (org-agenda-check-type nil 'agenda)]
1542 ["Use Time Grid" org-agenda-toggle-time-grid
1543 :style toggle :selected org-agenda-use-time-grid
1544 :active (org-agenda-check-type nil 'agenda)]
1545 "--"
1546 ["Show clock report" org-agenda-clockreport-mode
1547 :style toggle :selected org-agenda-clockreport-mode
1548 :active (org-agenda-check-type nil 'agenda)]
1549 ["Show some entry text" org-agenda-entry-text-mode
1550 :style toggle :selected org-agenda-entry-text-mode
1551 :active t]
1552 "--"
1553 ["Show Logbook entries" org-agenda-log-mode
1554 :style toggle :selected org-agenda-show-log
1555 :active (org-agenda-check-type nil 'agenda 'timeline)
1556 :keys "v l (or just l)"]
1557 ["Include archived trees" org-agenda-archives-mode
1558 :style toggle :selected org-agenda-archives-mode :active t
1559 :keys "v a"]
1560 ["Include archive files" (org-agenda-archives-mode t)
1561 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1562 :keys "v A"]
1563 "--"
1564 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1565 ["Write view to file" org-write-agenda t]
1566 ["Rebuild buffer" org-agenda-redo t]
1567 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1568 "--"
1569 ["Show original entry" org-agenda-show t]
1570 ["Go To (other window)" org-agenda-goto t]
1571 ["Go To (this window)" org-agenda-switch-to t]
1572 ["Follow Mode" org-agenda-follow-mode
1573 :style toggle :selected org-agenda-follow-mode :active t]
1574 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1575 "--"
1576 ("TODO"
1577 ["Cycle TODO" org-agenda-todo t]
1578 ["Next TODO set" org-agenda-todo-nextset t]
1579 ["Previous TODO set" org-agenda-todo-previousset t]
1580 ["Add note" org-agenda-add-note t])
1581 ("Archive/Refile/Delete"
1582 ["Archive default" org-agenda-archive-default t]
1583 ["Archive default" org-agenda-archive-default-with-confirmation t]
1584 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1585 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1586 ["Archive subtree" org-agenda-archive t]
1587 "--"
1588 ["Refile" org-agenda-refile t]
1589 "--"
1590 ["Delete subtree" org-agenda-kill t])
1591 ("Bulk action"
1592 ["Mark entry" org-agenda-bulk-mark t]
1593 ["Unmark entry" org-agenda-bulk-unmark t]
1594 ["Act on all marked" org-agenda-bulk-action t]
1595 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1596 "--"
1597 ("Tags and Properties"
1598 ["Show all Tags" org-agenda-show-tags t]
1599 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1600 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1601 "--"
1602 ["Column View" org-columns t])
1603 ("Deadline/Schedule"
1604 ["Schedule" org-agenda-schedule t]
1605 ["Set Deadline" org-agenda-deadline t]
1606 "--"
1607 ["Mark item" org-agenda-action :active t :keys "k m"]
1608 ["Show mark item" org-agenda-action :active t :keys "k v"]
1609 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1610 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1611 "--"
1612 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1613 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1614 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1615 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1616 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1617 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1618 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1619 ("Clock and Effort"
1620 ["Clock in" org-agenda-clock-in t]
1621 ["Clock out" org-agenda-clock-out t]
1622 ["Clock cancel" org-agenda-clock-cancel t]
1623 ["Goto running clock" org-clock-goto t]
1624 "--"
1625 ["Set Effort" org-agenda-set-effort t]
1626 ["Change clocked effort" org-clock-modify-effort-estimate
1627 (org-clock-is-active)])
1628 ("Priority"
1629 ["Set Priority" org-agenda-priority t]
1630 ["Increase Priority" org-agenda-priority-up t]
1631 ["Decrease Priority" org-agenda-priority-down t]
1632 ["Show Priority" org-agenda-show-priority t])
1633 ("Calendar/Diary"
1634 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
1635 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
1636 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
1637 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
1638 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
1639 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
1640 "--"
1641 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
1642 "--"
1643 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
1644 "--"
1645 ("MobileOrg"
1646 ["Push Files and Views" org-mobile-push t]
1647 ["Get Captured and Flagged" org-mobile-pull t]
1648 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
1649 ["Show note / unflag" org-agenda-show-the-flagging-note t]
1650 "--"
1651 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
1652 "--"
1653 ["Quit" org-agenda-quit t]
1654 ["Exit and Release Buffers" org-agenda-exit t]
1657 ;;; Agenda undo
1659 (defvar org-agenda-allow-remote-undo t
1660 "Non-nil means, allow remote undo from the agenda buffer.")
1661 (defvar org-agenda-undo-list nil
1662 "List of undoable operations in the agenda since last refresh.")
1663 (defvar org-agenda-undo-has-started-in nil
1664 "Buffers that have already seen `undo-start' in the current undo sequence.")
1665 (defvar org-agenda-pending-undo-list nil
1666 "In a series of undo commands, this is the list of remaining undo items.")
1669 (defun org-agenda-undo ()
1670 "Undo a remote editing step in the agenda.
1671 This undoes changes both in the agenda buffer and in the remote buffer
1672 that have been changed along."
1673 (interactive)
1674 (or org-agenda-allow-remote-undo
1675 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
1676 (if (not (eq this-command last-command))
1677 (setq org-agenda-undo-has-started-in nil
1678 org-agenda-pending-undo-list org-agenda-undo-list))
1679 (if (not org-agenda-pending-undo-list)
1680 (error "No further undo information"))
1681 (let* ((entry (pop org-agenda-pending-undo-list))
1682 buf line cmd rembuf)
1683 (setq cmd (pop entry) line (pop entry))
1684 (setq rembuf (nth 2 entry))
1685 (org-with-remote-undo rembuf
1686 (while (bufferp (setq buf (pop entry)))
1687 (if (pop entry)
1688 (with-current-buffer buf
1689 (let ((last-undo-buffer buf)
1690 (inhibit-read-only t))
1691 (unless (memq buf org-agenda-undo-has-started-in)
1692 (push buf org-agenda-undo-has-started-in)
1693 (make-local-variable 'pending-undo-list)
1694 (undo-start))
1695 (while (and pending-undo-list
1696 (listp pending-undo-list)
1697 (not (car pending-undo-list)))
1698 (pop pending-undo-list))
1699 (undo-more 1))))))
1700 (org-goto-line line)
1701 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
1703 (defun org-verify-change-for-undo (l1 l2)
1704 "Verify that a real change occurred between the undo lists L1 and L2."
1705 (while (and l1 (listp l1) (null (car l1))) (pop l1))
1706 (while (and l2 (listp l2) (null (car l2))) (pop l2))
1707 (not (eq l1 l2)))
1709 ;;; Agenda dispatch
1711 (defvar org-agenda-restrict nil)
1712 (defvar org-agenda-restrict-begin (make-marker))
1713 (defvar org-agenda-restrict-end (make-marker))
1714 (defvar org-agenda-last-dispatch-buffer nil)
1715 (defvar org-agenda-overriding-restriction nil)
1717 ;;;###autoload
1718 (defun org-agenda (&optional arg keys restriction)
1719 "Dispatch agenda commands to collect entries to the agenda buffer.
1720 Prompts for a command to execute. Any prefix arg will be passed
1721 on to the selected command. The default selections are:
1723 a Call `org-agenda-list' to display the agenda for current day or week.
1724 t Call `org-todo-list' to display the global todo list.
1725 T Call `org-todo-list' to display the global todo list, select only
1726 entries with a specific TODO keyword (the user gets a prompt).
1727 m Call `org-tags-view' to display headlines with tags matching
1728 a condition (the user is prompted for the condition).
1729 M Like `m', but select only TODO entries, no ordinary headlines.
1730 L Create a timeline for the current buffer.
1731 e Export views to associated files.
1732 s Search entries for keywords.
1733 / Multi occur across all agenda files and also files listed
1734 in `org-agenda-text-search-extra-files'.
1735 < Restrict agenda commands to buffer, subtree, or region.
1736 Press several times to get the desired effect.
1737 > Remove a previous restriction.
1738 # List \"stuck\" projects.
1739 ! Configure what \"stuck\" means.
1740 C Configure custom agenda commands.
1742 More commands can be added by configuring the variable
1743 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
1744 searches can be pre-defined in this way.
1746 If the current buffer is in Org-mode and visiting a file, you can also
1747 first press `<' once to indicate that the agenda should be temporarily
1748 \(until the next use of \\[org-agenda]) restricted to the current file.
1749 Pressing `<' twice means to restrict to the current subtree or region
1750 \(if active)."
1751 (interactive "P")
1752 (catch 'exit
1753 (let* ((prefix-descriptions nil)
1754 (org-agenda-window-setup (if (equal (buffer-name)
1755 org-agenda-buffer-name)
1756 'current-window
1757 org-agenda-window-setup))
1758 (org-agenda-custom-commands-orig org-agenda-custom-commands)
1759 (org-agenda-custom-commands
1760 ;; normalize different versions
1761 (delq nil
1762 (mapcar
1763 (lambda (x)
1764 (cond ((stringp (cdr x))
1765 (push x prefix-descriptions)
1766 nil)
1767 ((stringp (nth 1 x)) x)
1768 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1769 (t (cons (car x) (cons "" (cdr x))))))
1770 org-agenda-custom-commands)))
1771 (buf (current-buffer))
1772 (bfn (buffer-file-name (buffer-base-buffer)))
1773 entry key type match lprops ans)
1774 ;; Turn off restriction unless there is an overriding one,
1775 (unless org-agenda-overriding-restriction
1776 (unless (org-bound-and-true-p org-agenda-keep-restriced-file-list)
1777 ;; There is a request to keep the file list in place
1778 (put 'org-agenda-files 'org-restrict nil))
1779 (setq org-agenda-restrict nil)
1780 (move-marker org-agenda-restrict-begin nil)
1781 (move-marker org-agenda-restrict-end nil))
1782 ;; Delete old local properties
1783 (put 'org-agenda-redo-command 'org-lprops nil)
1784 ;; Remember where this call originated
1785 (setq org-agenda-last-dispatch-buffer (current-buffer))
1786 (unless keys
1787 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
1788 keys (car ans)
1789 restriction (cdr ans)))
1790 ;; Estabish the restriction, if any
1791 (when (and (not org-agenda-overriding-restriction) restriction)
1792 (put 'org-agenda-files 'org-restrict (list bfn))
1793 (cond
1794 ((eq restriction 'region)
1795 (setq org-agenda-restrict t)
1796 (move-marker org-agenda-restrict-begin (region-beginning))
1797 (move-marker org-agenda-restrict-end (region-end)))
1798 ((eq restriction 'subtree)
1799 (save-excursion
1800 (setq org-agenda-restrict t)
1801 (org-back-to-heading t)
1802 (move-marker org-agenda-restrict-begin (point))
1803 (move-marker org-agenda-restrict-end
1804 (progn (org-end-of-subtree t)))))))
1806 (require 'calendar) ; FIXME: can we avoid this for some commands?
1807 ;; For example the todo list should not need it (but does...)
1808 (cond
1809 ((setq entry (assoc keys org-agenda-custom-commands))
1810 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
1811 (progn
1812 (setq type (nth 2 entry) match (eval (nth 3 entry))
1813 lprops (nth 4 entry))
1814 (put 'org-agenda-redo-command 'org-lprops lprops)
1815 (cond
1816 ((eq type 'agenda)
1817 (org-let lprops '(org-agenda-list current-prefix-arg)))
1818 ((eq type 'alltodo)
1819 (org-let lprops '(org-todo-list current-prefix-arg)))
1820 ((eq type 'search)
1821 (org-let lprops '(org-search-view current-prefix-arg match nil)))
1822 ((eq type 'stuck)
1823 (org-let lprops '(org-agenda-list-stuck-projects
1824 current-prefix-arg)))
1825 ((eq type 'tags)
1826 (org-let lprops '(org-tags-view current-prefix-arg match)))
1827 ((eq type 'tags-todo)
1828 (org-let lprops '(org-tags-view '(4) match)))
1829 ((eq type 'todo)
1830 (org-let lprops '(org-todo-list match)))
1831 ((eq type 'tags-tree)
1832 (org-check-for-org-mode)
1833 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
1834 ((eq type 'todo-tree)
1835 (org-check-for-org-mode)
1836 (org-let lprops
1837 '(org-occur (concat "^" outline-regexp "[ \t]*"
1838 (regexp-quote match) "\\>"))))
1839 ((eq type 'occur-tree)
1840 (org-check-for-org-mode)
1841 (org-let lprops '(org-occur match)))
1842 ((functionp type)
1843 (org-let lprops '(funcall type match)))
1844 ((fboundp type)
1845 (org-let lprops '(funcall type match)))
1846 (t (error "Invalid custom agenda command type %s" type))))
1847 (org-run-agenda-series (nth 1 entry) (cddr entry))))
1848 ((equal keys "C")
1849 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
1850 (customize-variable 'org-agenda-custom-commands))
1851 ((equal keys "a") (call-interactively 'org-agenda-list))
1852 ((equal keys "s") (call-interactively 'org-search-view))
1853 ((equal keys "t") (call-interactively 'org-todo-list))
1854 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
1855 ((equal keys "m") (call-interactively 'org-tags-view))
1856 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
1857 ((equal keys "e") (call-interactively 'org-store-agenda-views))
1858 ((equal keys "?") (org-tags-view nil "+FLAGGED")
1859 (org-add-hook
1860 'post-command-hook
1861 (lambda ()
1862 (unless (current-message)
1863 (let* ((m (org-agenda-get-any-marker))
1864 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
1865 (when note
1866 (message (concat
1867 "FLAGGING-NOTE ([?] for more info): "
1868 (org-add-props
1869 (replace-regexp-in-string
1870 "\\\\n" "//"
1871 (copy-sequence note))
1872 nil 'face 'org-warning)))))))
1873 t t))
1874 ((equal keys "L")
1875 (unless (org-mode-p)
1876 (error "This is not an Org-mode file"))
1877 (unless restriction
1878 (put 'org-agenda-files 'org-restrict (list bfn))
1879 (org-call-with-arg 'org-timeline arg)))
1880 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
1881 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
1882 ((equal keys "!") (customize-variable 'org-stuck-projects))
1883 (t (error "Invalid agenda key"))))))
1885 (defun org-agenda-normalize-custom-commands (cmds)
1886 (delq nil
1887 (mapcar
1888 (lambda (x)
1889 (cond ((stringp (cdr x)) nil)
1890 ((stringp (nth 1 x)) x)
1891 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
1892 (t (cons (car x) (cons "" (cdr x))))))
1893 cmds)))
1895 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
1896 "The user interface for selecting an agenda command."
1897 (catch 'exit
1898 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
1899 (restrict-ok (and bfn (org-mode-p)))
1900 (region-p (org-region-active-p))
1901 (custom org-agenda-custom-commands)
1902 (selstring "")
1903 restriction second-time
1904 c entry key type match prefixes rmheader header-end custom1 desc)
1905 (save-window-excursion
1906 (delete-other-windows)
1907 (org-switch-to-buffer-other-window " *Agenda Commands*")
1908 (erase-buffer)
1909 (insert (eval-when-compile
1910 (let ((header
1912 Press key for an agenda command: < Buffer, subtree/region restriction
1913 -------------------------------- > Remove restriction
1914 a Agenda for current week or day e Export agenda views
1915 t List of all TODO entries T Entries with special TODO kwd
1916 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
1917 L Timeline for current buffer # List stuck projects (!=configure)
1918 s Search for keywords C Configure custom agenda commands
1919 / Multi-occur ? Find :FLAGGED: entries
1921 (start 0))
1922 (while (string-match
1923 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
1924 header start)
1925 (setq start (match-end 0))
1926 (add-text-properties (match-beginning 2) (match-end 2)
1927 '(face bold) header))
1928 header)))
1929 (setq header-end (move-marker (make-marker) (point)))
1930 (while t
1931 (setq custom1 custom)
1932 (when (eq rmheader t)
1933 (org-goto-line 1)
1934 (re-search-forward ":" nil t)
1935 (delete-region (match-end 0) (point-at-eol))
1936 (forward-char 1)
1937 (looking-at "-+")
1938 (delete-region (match-end 0) (point-at-eol))
1939 (move-marker header-end (match-end 0)))
1940 (goto-char header-end)
1941 (delete-region (point) (point-max))
1942 (while (setq entry (pop custom1))
1943 (setq key (car entry) desc (nth 1 entry)
1944 type (nth 2 entry)
1945 match (nth 3 entry))
1946 (if (> (length key) 1)
1947 (add-to-list 'prefixes (string-to-char key))
1948 (insert
1949 (format
1950 "\n%-4s%-14s: %s"
1951 (org-add-props (copy-sequence key)
1952 '(face bold))
1953 (cond
1954 ((string-match "\\S-" desc) desc)
1955 ((eq type 'agenda) "Agenda for current week or day")
1956 ((eq type 'alltodo) "List of all TODO entries")
1957 ((eq type 'search) "Word search")
1958 ((eq type 'stuck) "List of stuck projects")
1959 ((eq type 'todo) "TODO keyword")
1960 ((eq type 'tags) "Tags query")
1961 ((eq type 'tags-todo) "Tags (TODO)")
1962 ((eq type 'tags-tree) "Tags tree")
1963 ((eq type 'todo-tree) "TODO kwd tree")
1964 ((eq type 'occur-tree) "Occur tree")
1965 ((functionp type) (if (symbolp type)
1966 (symbol-name type)
1967 "Lambda expression"))
1968 (t "???"))
1969 (cond
1970 ((stringp match)
1971 (setq match (copy-sequence match))
1972 (org-add-props match nil 'face 'org-warning))
1973 (match
1974 (format "set of %d commands" (length match)))
1975 (t ""))))))
1976 (when prefixes
1977 (mapc (lambda (x)
1978 (insert
1979 (format "\n%s %s"
1980 (org-add-props (char-to-string x)
1981 nil 'face 'bold)
1982 (or (cdr (assoc (concat selstring (char-to-string x))
1983 prefix-descriptions))
1984 "Prefix key"))))
1985 prefixes))
1986 (goto-char (point-min))
1987 (if second-time
1988 (if (not (pos-visible-in-window-p (point-max)))
1989 (org-fit-window-to-buffer))
1990 (setq second-time t)
1991 (org-fit-window-to-buffer))
1992 (message "Press key for agenda command%s:"
1993 (if (or restrict-ok org-agenda-overriding-restriction)
1994 (if org-agenda-overriding-restriction
1995 " (restriction lock active)"
1996 (if restriction
1997 (format " (restricted to %s)" restriction)
1998 " (unrestricted)"))
1999 ""))
2000 (setq c (read-char-exclusive))
2001 (message "")
2002 (cond
2003 ((assoc (char-to-string c) custom)
2004 (setq selstring (concat selstring (char-to-string c)))
2005 (throw 'exit (cons selstring restriction)))
2006 ((memq c prefixes)
2007 (setq selstring (concat selstring (char-to-string c))
2008 prefixes nil
2009 rmheader (or rmheader t)
2010 custom (delq nil (mapcar
2011 (lambda (x)
2012 (if (or (= (length (car x)) 1)
2013 (/= (string-to-char (car x)) c))
2015 (cons (substring (car x) 1) (cdr x))))
2016 custom))))
2017 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2018 (message "Restriction is only possible in Org-mode buffers")
2019 (ding) (sit-for 1))
2020 ((eq c ?1)
2021 (org-agenda-remove-restriction-lock 'noupdate)
2022 (setq restriction 'buffer))
2023 ((eq c ?0)
2024 (org-agenda-remove-restriction-lock 'noupdate)
2025 (setq restriction (if region-p 'region 'subtree)))
2026 ((eq c ?<)
2027 (org-agenda-remove-restriction-lock 'noupdate)
2028 (setq restriction
2029 (cond
2030 ((eq restriction 'buffer)
2031 (if region-p 'region 'subtree))
2032 ((memq restriction '(subtree region))
2033 nil)
2034 (t 'buffer))))
2035 ((eq c ?>)
2036 (org-agenda-remove-restriction-lock 'noupdate)
2037 (setq restriction nil))
2038 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2039 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2040 ((and (> (length selstring) 0) (eq c ?\d))
2041 (delete-window)
2042 (org-agenda-get-restriction-and-command prefix-descriptions))
2044 ((equal c ?q) (error "Abort"))
2045 (t (error "Invalid key %c" c))))))))
2047 (defun org-run-agenda-series (name series)
2048 (org-let (nth 1 series) '(org-prepare-agenda name))
2049 (let* ((org-agenda-multi t)
2050 (redo (list 'org-run-agenda-series name (list 'quote series)))
2051 (cmds (car series))
2052 (gprops (nth 1 series))
2053 match ;; The byte compiler incorrectly complains about this. Keep it!
2054 cmd type lprops)
2055 (while (setq cmd (pop cmds))
2056 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2057 (cond
2058 ((eq type 'agenda)
2059 (org-let2 gprops lprops
2060 '(call-interactively 'org-agenda-list)))
2061 ((eq type 'alltodo)
2062 (org-let2 gprops lprops
2063 '(call-interactively 'org-todo-list)))
2064 ((eq type 'search)
2065 (org-let2 gprops lprops
2066 '(org-search-view current-prefix-arg match nil)))
2067 ((eq type 'stuck)
2068 (org-let2 gprops lprops
2069 '(call-interactively 'org-agenda-list-stuck-projects)))
2070 ((eq type 'tags)
2071 (org-let2 gprops lprops
2072 '(org-tags-view current-prefix-arg match)))
2073 ((eq type 'tags-todo)
2074 (org-let2 gprops lprops
2075 '(org-tags-view '(4) match)))
2076 ((eq type 'todo)
2077 (org-let2 gprops lprops
2078 '(org-todo-list match)))
2079 ((fboundp type)
2080 (org-let2 gprops lprops
2081 '(funcall type match)))
2082 (t (error "Invalid type in command series"))))
2083 (widen)
2084 (setq org-agenda-redo-command redo)
2085 (goto-char (point-min)))
2086 (org-fit-agenda-window)
2087 (org-let (nth 1 series) '(org-finalize-agenda)))
2089 ;;;###autoload
2090 (defmacro org-batch-agenda (cmd-key &rest parameters)
2091 "Run an agenda command in batch mode and send the result to STDOUT.
2092 If CMD-KEY is a string of length 1, it is used as a key in
2093 `org-agenda-custom-commands' and triggers this command. If it is a
2094 longer string it is used as a tags/todo match string.
2095 Paramters are alternating variable names and values that will be bound
2096 before running the agenda command."
2097 (let (pars)
2098 (while parameters
2099 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2100 (if (> (length cmd-key) 2)
2101 (eval (list 'let (nreverse pars)
2102 (list 'org-tags-view nil cmd-key)))
2103 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2104 (set-buffer org-agenda-buffer-name)
2105 (princ (org-encode-for-stdout (buffer-string)))))
2107 ;(defun org-encode-for-stdout (string)
2108 ; (if (fboundp 'encode-coding-string)
2109 ; (encode-coding-string string buffer-file-coding-system)
2110 ; string))
2112 (defun org-encode-for-stdout (string)
2113 string)
2115 (defvar org-agenda-info nil)
2117 ;;;###autoload
2118 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2119 "Run an agenda command in batch mode and send the result to STDOUT.
2120 If CMD-KEY is a string of length 1, it is used as a key in
2121 `org-agenda-custom-commands' and triggers this command. If it is a
2122 longer string it is used as a tags/todo match string.
2123 Paramters are alternating variable names and values that will be bound
2124 before running the agenda command.
2126 The output gives a line for each selected agenda item. Each
2127 item is a list of comma-separated values, like this:
2129 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2131 category The category of the item
2132 head The headline, without TODO kwd, TAGS and PRIORITY
2133 type The type of the agenda entry, can be
2134 todo selected in TODO match
2135 tagsmatch selected in tags match
2136 diary imported from diary
2137 deadline a deadline on given date
2138 scheduled scheduled on given date
2139 timestamp entry has timestamp on given date
2140 closed entry was closed on given date
2141 upcoming-deadline warning about deadline
2142 past-scheduled forwarded scheduled item
2143 block entry has date block including g. date
2144 todo The todo keyword, if any
2145 tags All tags including inherited ones, separated by colons
2146 date The relevant date, like 2007-2-14
2147 time The time, like 15:00-16:50
2148 extra Sting with extra planning info
2149 priority-l The priority letter if any was given
2150 priority-n The computed numerical priority
2151 agenda-day The day in the agenda where this is listed"
2153 (let (pars)
2154 (while parameters
2155 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2156 (push (list 'org-agenda-remove-tags t) pars)
2157 (if (> (length cmd-key) 2)
2158 (eval (list 'let (nreverse pars)
2159 (list 'org-tags-view nil cmd-key)))
2160 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2161 (set-buffer org-agenda-buffer-name)
2162 (let* ((lines (org-split-string (buffer-string) "\n"))
2163 line)
2164 (while (setq line (pop lines))
2165 (catch 'next
2166 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2167 (setq org-agenda-info
2168 (org-fix-agenda-info (text-properties-at 0 line)))
2169 (princ
2170 (org-encode-for-stdout
2171 (mapconcat 'org-agenda-export-csv-mapper
2172 '(org-category txt type todo tags date time-of-day extra
2173 priority-letter priority agenda-day)
2174 ",")))
2175 (princ "\n"))))))
2177 (defun org-fix-agenda-info (props)
2178 "Make sure all properties on an agenda item have a canonical form,
2179 so the export commands can easily use it."
2180 (let (tmp re)
2181 (when (setq tmp (plist-get props 'tags))
2182 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2183 (when (setq tmp (plist-get props 'date))
2184 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2185 (let ((calendar-date-display-form '(year "-" month "-" day)))
2186 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2188 (setq tmp (calendar-date-string tmp)))
2189 (setq props (plist-put props 'date tmp)))
2190 (when (setq tmp (plist-get props 'day))
2191 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2192 (let ((calendar-date-display-form '(year "-" month "-" day)))
2193 (setq tmp (calendar-date-string tmp)))
2194 (setq props (plist-put props 'day tmp))
2195 (setq props (plist-put props 'agenda-day tmp)))
2196 (when (setq tmp (plist-get props 'txt))
2197 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2198 (plist-put props 'priority-letter (match-string 1 tmp))
2199 (setq tmp (replace-match "" t t tmp)))
2200 (when (and (setq re (plist-get props 'org-todo-regexp))
2201 (setq re (concat "\\`\\.*" re " ?"))
2202 (string-match re tmp))
2203 (plist-put props 'todo (match-string 1 tmp))
2204 (setq tmp (replace-match "" t t tmp)))
2205 (plist-put props 'txt tmp)))
2206 props)
2208 (defun org-agenda-export-csv-mapper (prop)
2209 (let ((res (plist-get org-agenda-info prop)))
2210 (setq res
2211 (cond
2212 ((not res) "")
2213 ((stringp res) res)
2214 (t (prin1-to-string res))))
2215 (while (string-match "," res)
2216 (setq res (replace-match ";" t t res)))
2217 (org-trim res)))
2220 ;;;###autoload
2221 (defun org-store-agenda-views (&rest parameters)
2222 (interactive)
2223 (eval (list 'org-batch-store-agenda-views)))
2225 ;; FIXME, why is this a macro?????
2226 ;;;###autoload
2227 (defmacro org-batch-store-agenda-views (&rest parameters)
2228 "Run all custom agenda commands that have a file argument."
2229 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2230 (pop-up-frames nil)
2231 (dir default-directory)
2232 pars cmd thiscmdkey files opts cmd-or-set)
2233 (while parameters
2234 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2235 (setq pars (reverse pars))
2236 (save-window-excursion
2237 (while cmds
2238 (setq cmd (pop cmds)
2239 thiscmdkey (car cmd)
2240 cmd-or-set (nth 2 cmd)
2241 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2242 files (nth (if (listp cmd-or-set) 4 5) cmd))
2243 (if (stringp files) (setq files (list files)))
2244 (when files
2245 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2246 (list 'org-agenda nil thiscmdkey)))
2247 (set-buffer org-agenda-buffer-name)
2248 (while files
2249 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2250 (list 'org-write-agenda
2251 (expand-file-name (pop files) dir) nil t))))
2252 (and (get-buffer org-agenda-buffer-name)
2253 (kill-buffer org-agenda-buffer-name)))))))
2255 (defun org-agenda-mark-header-line (pos)
2256 "Mark the line at POS as an agenda structure header."
2257 (save-excursion
2258 (goto-char pos)
2259 (put-text-property (point-at-bol) (point-at-eol)
2260 'org-agenda-structural-header t)
2261 (when org-agenda-title-append
2262 (put-text-property (point-at-bol) (point-at-eol)
2263 'org-agenda-title-append org-agenda-title-append))))
2265 (defvar org-mobile-creating-agendas)
2266 (defun org-write-agenda (file &optional open nosettings)
2267 "Write the current buffer (an agenda view) as a file.
2268 Depending on the extension of the file name, plain text (.txt),
2269 HTML (.html or .htm) or Postscript (.ps) is produced.
2270 If the extension is .ics, run icalendar export over all files used
2271 to construct the agenda and limit the export to entries listed in the
2272 agenda now.
2273 With prefic argument OPEN, open the new file immediately.
2274 If NOSETTINGS is given, do not scope the settings of
2275 `org-agenda-exporter-settings' into the export commands. This is used when
2276 the settings have already been scoped and we do not wish to overrule other,
2277 higher priority settings."
2278 (interactive "FWrite agenda to file: \nP")
2279 (if (not (file-writable-p file))
2280 (error "Cannot write agenda to file %s" file))
2281 (cond
2282 ((string-match "\\.html?\\'" file) (require 'htmlize))
2283 ((string-match "\\.ps\\'" file) (require 'ps-print)))
2284 (org-let (if nosettings nil org-agenda-exporter-settings)
2285 '(save-excursion
2286 (save-window-excursion
2287 (org-agenda-mark-filtered-text)
2288 (let ((bs (copy-sequence (buffer-string))) beg)
2289 (org-agenda-unmark-filtered-text)
2290 (with-temp-buffer
2291 (insert bs)
2292 (org-agenda-remove-marked-text 'org-filtered)
2293 (while (setq beg (text-property-any (point-min) (point-max)
2294 'org-filtered t))
2295 (delete-region
2296 beg (or (next-single-property-change beg 'org-filtered)
2297 (point-max))))
2298 (run-hooks 'org-agenda-before-write-hook)
2299 (cond
2300 ((org-bound-and-true-p org-mobile-creating-agendas)
2301 (org-mobile-write-agenda-for-mobile file))
2302 ((string-match "\\.html?\\'" file)
2303 (set-buffer (htmlize-buffer (current-buffer)))
2305 (when (and org-agenda-export-html-style
2306 (string-match "<style>" org-agenda-export-html-style))
2307 ;; replace <style> section with org-agenda-export-html-style
2308 (goto-char (point-min))
2309 (kill-region (- (search-forward "<style") 6)
2310 (search-forward "</style>"))
2311 (insert org-agenda-export-html-style))
2312 (write-file file)
2313 (kill-buffer (current-buffer))
2314 (message "HTML written to %s" file))
2315 ((string-match "\\.ps\\'" file)
2316 (require 'ps-print)
2317 (flet ((ps-get-buffer-name () "Agenda View"))
2318 (ps-print-buffer-with-faces file))
2319 (message "Postscript written to %s" file))
2320 ((string-match "\\.pdf\\'" file)
2321 (require 'ps-print)
2322 (flet ((ps-get-buffer-name () "Agenda View"))
2323 (ps-print-buffer-with-faces
2324 (concat (file-name-sans-extension file) ".ps")))
2325 (call-process "ps2pdf" nil nil nil
2326 (expand-file-name
2327 (concat (file-name-sans-extension file) ".ps"))
2328 (expand-file-name file))
2329 (message "PDF written to %s" file))
2330 ((string-match "\\.ics\\'" file)
2331 (require 'org-icalendar)
2332 (let ((org-agenda-marker-table
2333 (org-create-marker-find-array
2334 (org-agenda-collect-markers)))
2335 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2336 (org-combined-agenda-icalendar-file file))
2337 (apply 'org-export-icalendar 'combine
2338 (org-agenda-files nil 'ifmode))))
2340 (let ((bs (buffer-string)))
2341 (find-file file)
2342 (erase-buffer)
2343 (insert bs)
2344 (save-buffer 0)
2345 (kill-buffer (current-buffer))
2346 (message "Plain text written to %s" file))))))))
2347 (set-buffer org-agenda-buffer-name))
2348 (when open (org-open-file file)))
2350 (defvar org-agenda-filter-overlays nil)
2352 (defun org-agenda-mark-filtered-text ()
2353 "Mark all text hidden by filtering with a text property."
2354 (let ((inhibit-read-only t))
2355 (mapc
2356 (lambda (o)
2357 (when (equal (org-overlay-buffer o) (current-buffer))
2358 (put-text-property
2359 (org-overlay-start o) (org-overlay-end o)
2360 'org-filtered t)))
2361 org-agenda-filter-overlays)))
2363 (defun org-agenda-unmark-filtered-text ()
2364 "Remove the filtering text property."
2365 (let ((inhibit-read-only t))
2366 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2368 (defun org-agenda-remove-marked-text (property &optional value)
2369 "Delete all text marked with VALUE of PROPERTY.
2370 VALUE defaults to t."
2371 (let (beg)
2372 (setq value (or value t))
2373 (while (setq beg (text-property-any (point-min) (point-max)
2374 property value))
2375 (delete-region
2376 beg (or (next-single-property-change beg 'org-filtered)
2377 (point-max))))))
2379 (defun org-agenda-add-entry-text ()
2380 "Add entry text to agenda lines.
2381 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2382 entry text following headings shown in the agenda.
2383 Drawers will be excluded, also the line with scheduling/deadline info."
2384 (when (and (> org-agenda-add-entry-text-maxlines 0)
2385 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2386 (let (m txt)
2387 (goto-char (point-min))
2388 (while (not (eobp))
2389 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2390 (beginning-of-line 2)
2391 (setq txt (org-agenda-get-some-entry-text
2392 m org-agenda-add-entry-text-maxlines " > "))
2393 (end-of-line 1)
2394 (if (string-match "\\S-" txt) (insert "\n" txt)))))))
2396 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2397 &rest keep)
2398 "Extract entry text from MARKER, at most N-LINES lines.
2399 This will ignore drawers etc, just get the text.
2400 If INDENT is given, prefix every line with this string. If KEEP is
2401 given, it is a list of symbols, defining stuff that hould not be
2402 removed from the entry content. Currently only `planning' is allowed here."
2403 (let (txt drawer-re kwd-time-re ind)
2404 (save-excursion
2405 (with-current-buffer (marker-buffer marker)
2406 (if (not (org-mode-p))
2407 (setq txt "")
2408 (save-excursion
2409 (save-restriction
2410 (widen)
2411 (goto-char marker)
2412 (end-of-line 1)
2413 (setq txt (buffer-substring
2414 (min (1+ (point)) (point-max))
2415 (progn (outline-next-heading) (point)))
2416 drawer-re org-drawer-regexp
2417 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2418 ".*\n?"))
2419 (with-temp-buffer
2420 (insert txt)
2421 (when org-agenda-add-entry-text-descriptive-links
2422 (goto-char (point-min))
2423 (while (org-activate-bracket-links (point-max))
2424 (add-text-properties (match-beginning 0) (match-end 0)
2425 '(face org-link))))
2426 (goto-char (point-min))
2427 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2428 (set-text-properties (match-beginning 0) (match-end 0)
2429 nil))
2430 (goto-char (point-min))
2431 (while (re-search-forward drawer-re nil t)
2432 (delete-region
2433 (match-beginning 0)
2434 (progn (re-search-forward
2435 "^[ \t]*:END:.*\n?" nil 'move)
2436 (point))))
2437 (unless (member 'planning keep)
2438 (goto-char (point-min))
2439 (while (re-search-forward kwd-time-re nil t)
2440 (replace-match "")))
2441 (goto-char (point-min))
2442 (when org-agenda-entry-text-exclude-regexps
2443 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2444 (while (setq re (pop re-list))
2445 (goto-char (point-min))
2446 (while (re-search-forward re nil t)
2447 (replace-match "")))))
2448 (goto-char (point-max))
2449 (skip-chars-backward " \t\n")
2450 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2452 ;; find and remove min common indentation
2453 (goto-char (point-min))
2454 (untabify (point-min) (point-max))
2455 (setq ind (org-get-indentation))
2456 (while (not (eobp))
2457 (unless (looking-at "[ \t]*$")
2458 (setq ind (min ind (org-get-indentation))))
2459 (beginning-of-line 2))
2460 (goto-char (point-min))
2461 (while (not (eobp))
2462 (unless (looking-at "[ \t]*$")
2463 (move-to-column ind)
2464 (delete-region (point-at-bol) (point)))
2465 (beginning-of-line 2))
2467 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2469 (goto-char (point-min))
2470 (when indent
2471 (while (and (not (eobp)) (re-search-forward "^" nil t))
2472 (replace-match indent t t)))
2473 (goto-char (point-min))
2474 (while (looking-at "[ \t]*\n") (replace-match ""))
2475 (goto-char (point-max))
2476 (when (> (org-current-line)
2477 n-lines)
2478 (org-goto-line (1+ n-lines))
2479 (backward-char 1))
2480 (setq txt (buffer-substring (point-min) (point)))))))))
2481 txt))
2483 (defun org-agenda-collect-markers ()
2484 "Collect the markers pointing to entries in the agenda buffer."
2485 (let (m markers)
2486 (save-excursion
2487 (goto-char (point-min))
2488 (while (not (eobp))
2489 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2490 (org-get-at-bol 'org-marker)))
2491 (push m markers))
2492 (beginning-of-line 2)))
2493 (nreverse markers)))
2495 (defun org-create-marker-find-array (marker-list)
2496 "Create a alist of files names with all marker positions in that file."
2497 (let (f tbl m a p)
2498 (while (setq m (pop marker-list))
2499 (setq p (marker-position m)
2500 f (buffer-file-name (or (buffer-base-buffer
2501 (marker-buffer m))
2502 (marker-buffer m))))
2503 (if (setq a (assoc f tbl))
2504 (push (marker-position m) (cdr a))
2505 (push (list f p) tbl)))
2506 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2507 tbl)))
2509 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2510 (defun org-check-agenda-marker-table ()
2511 "Check of the current entry is on the marker list."
2512 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2514 (and (setq a (assoc file org-agenda-marker-table))
2515 (save-match-data
2516 (save-excursion
2517 (org-back-to-heading t)
2518 (member (point) (cdr a)))))))
2520 (defun org-check-for-org-mode ()
2521 "Make sure current buffer is in org-mode. Error if not."
2522 (or (org-mode-p)
2523 (error "Cannot execute org-mode agenda command on buffer in %s"
2524 major-mode)))
2526 (defun org-fit-agenda-window ()
2527 "Fit the window to the buffer size."
2528 (and (memq org-agenda-window-setup '(reorganize-frame))
2529 (fboundp 'fit-window-to-buffer)
2530 (org-fit-window-to-buffer
2532 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2533 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2535 ;;; Agenda prepare and finalize
2537 (defvar org-agenda-multi nil) ; dynamically scoped
2538 (defvar org-agenda-buffer-name "*Org Agenda*")
2539 (defvar org-pre-agenda-window-conf nil)
2540 (defvar org-agenda-columns-active nil)
2541 (defvar org-agenda-name nil)
2542 (defvar org-agenda-filter nil)
2543 (defvar org-agenda-filter-preset nil
2544 "A preset of the tags filter used for secondary agenda filtering.
2545 This must be a list of strings, each string must be a single tag preceeded
2546 by \"+\" or \"-\".
2547 This variable should not be set directly, but agenda custom commands can
2548 bind it in the options section.")
2550 (defun org-prepare-agenda (&optional name)
2551 (setq org-todo-keywords-for-agenda nil)
2552 (setq org-done-keywords-for-agenda nil)
2553 (setq org-drawers-for-agenda nil)
2554 (setq org-agenda-filter nil)
2555 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2556 (if org-agenda-multi
2557 (progn
2558 (setq buffer-read-only nil)
2559 (goto-char (point-max))
2560 (unless (or (bobp) org-agenda-compact-blocks)
2561 (insert "\n"
2562 (if (stringp org-agenda-block-separator)
2563 org-agenda-block-separator
2564 (make-string (window-width) org-agenda-block-separator))
2565 "\n"))
2566 (narrow-to-region (point) (point-max)))
2567 (org-agenda-reset-markers)
2568 (setq org-agenda-contributing-files nil)
2569 (setq org-agenda-columns-active nil)
2570 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2571 (setq org-todo-keywords-for-agenda
2572 (org-uniquify org-todo-keywords-for-agenda))
2573 (setq org-done-keywords-for-agenda
2574 (org-uniquify org-done-keywords-for-agenda))
2575 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2576 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2577 (awin (get-buffer-window abuf)))
2578 (cond
2579 ((equal (current-buffer) abuf) nil)
2580 (awin (select-window awin))
2581 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
2582 ((equal org-agenda-window-setup 'current-window)
2583 (switch-to-buffer abuf))
2584 ((equal org-agenda-window-setup 'other-window)
2585 (org-switch-to-buffer-other-window abuf))
2586 ((equal org-agenda-window-setup 'other-frame)
2587 (switch-to-buffer-other-frame abuf))
2588 ((equal org-agenda-window-setup 'reorganize-frame)
2589 (delete-other-windows)
2590 (org-switch-to-buffer-other-window abuf))))
2591 (setq buffer-read-only nil)
2592 (let ((inhibit-read-only t)) (erase-buffer))
2593 (org-agenda-mode)
2594 (and name (not org-agenda-name)
2595 (org-set-local 'org-agenda-name name)))
2596 (setq buffer-read-only nil))
2598 (defun org-finalize-agenda ()
2599 "Finishing touch for the agenda buffer, called just before displaying it."
2600 (unless org-agenda-multi
2601 (save-excursion
2602 (let ((inhibit-read-only t))
2603 (goto-char (point-min))
2604 (while (org-activate-bracket-links (point-max))
2605 (add-text-properties (match-beginning 0) (match-end 0)
2606 '(face org-link)))
2607 (org-agenda-align-tags)
2608 (unless org-agenda-with-colors
2609 (remove-text-properties (point-min) (point-max) '(face nil))))
2610 (if (and (boundp 'org-agenda-overriding-columns-format)
2611 org-agenda-overriding-columns-format)
2612 (org-set-local 'org-agenda-overriding-columns-format
2613 org-agenda-overriding-columns-format))
2614 (if (and (boundp 'org-agenda-view-columns-initially)
2615 org-agenda-view-columns-initially)
2616 (org-agenda-columns))
2617 (when org-agenda-fontify-priorities
2618 (org-agenda-fontify-priorities))
2619 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
2620 (org-agenda-dim-blocked-tasks))
2621 (org-agenda-mark-clocking-task)
2622 (when org-agenda-entry-text-mode
2623 (org-agenda-entry-text-hide)
2624 (org-agenda-entry-text-show))
2625 (if (functionp 'org-habit-insert-consistency-graphs)
2626 (org-habit-insert-consistency-graphs))
2627 (run-hooks 'org-finalize-agenda-hook)
2628 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
2629 (when (get 'org-agenda-filter :preset-filter)
2630 (org-agenda-filter-apply org-agenda-filter))
2633 (defun org-agenda-mark-clocking-task ()
2634 "Mark the current clock entry in the agenda if it is present."
2635 (mapc (lambda (o)
2636 (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
2637 (org-delete-overlay o)))
2638 (org-overlays-in (point-min) (point-max)))
2639 (when (marker-buffer org-clock-hd-marker)
2640 (save-excursion
2641 (goto-char (point-min))
2642 (let (s ov)
2643 (while (setq s (next-single-property-change (point) 'org-hd-marker))
2644 (goto-char s)
2645 (when (equal (org-get-at-bol 'org-hd-marker)
2646 org-clock-hd-marker)
2647 (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
2648 (org-overlay-put ov 'type 'org-agenda-clocking)
2649 (org-overlay-put ov 'face 'org-agenda-clocking)
2650 (org-overlay-put ov 'help-echo
2651 "The clock is running in this item")))))))
2653 (defun org-agenda-fontify-priorities ()
2654 "Make highest priority lines bold, and lowest italic."
2655 (interactive)
2656 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
2657 (org-delete-overlay o)))
2658 (org-overlays-in (point-min) (point-max)))
2659 (save-excursion
2660 (let ((inhibit-read-only t)
2661 b e p ov h l)
2662 (goto-char (point-min))
2663 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
2664 (setq h (or (get-char-property (point) 'org-highest-priority)
2665 org-highest-priority)
2666 l (or (get-char-property (point) 'org-lowest-priority)
2667 org-lowest-priority)
2668 p (string-to-char (match-string 1))
2669 b (match-beginning 0)
2670 e (if (eq org-agenda-fontify-priorities 'cookies)
2671 (match-end 0)
2672 (point-at-eol))
2673 ov (org-make-overlay b e))
2674 (org-overlay-put
2675 ov 'face
2676 (cond ((cdr (assoc p org-priority-faces)))
2677 ((and (listp org-agenda-fontify-priorities)
2678 (cdr (assoc p org-agenda-fontify-priorities))))
2679 ((equal p l) 'italic)
2680 ((equal p h) 'bold)))
2681 (org-overlay-put ov 'org-type 'org-priority)))))
2683 (defun org-agenda-dim-blocked-tasks ()
2684 "Dim currently blocked TODO's in the agenda display."
2685 (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
2686 (org-delete-overlay o)))
2687 (org-overlays-in (point-min) (point-max)))
2688 (save-excursion
2689 (let ((inhibit-read-only t)
2690 (org-depend-tag-blocked nil)
2691 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
2692 org-blocked-by-checkboxes
2693 invis1 b e p ov h l)
2694 (goto-char (point-min))
2695 (while (let ((pos (next-single-property-change (point) 'todo-state)))
2696 (and pos (goto-char (1+ pos))))
2697 (setq org-blocked-by-checkboxes nil invis1 invis)
2698 (let ((marker (org-get-at-bol 'org-hd-marker)))
2699 (when (and marker
2700 (not (with-current-buffer (marker-buffer marker)
2701 (save-excursion
2702 (goto-char marker)
2703 (if (org-entry-get nil "NOBLOCKING")
2704 t ;; Never block this entry
2705 (run-hook-with-args-until-failure
2706 'org-blocker-hook
2707 (list :type 'todo-state-change
2708 :position marker
2709 :from 'todo
2710 :to 'done)))))))
2711 (if org-blocked-by-checkboxes (setq invis1 nil))
2712 (setq b (if invis1
2713 (max (point-min) (1- (point-at-bol)))
2714 (point-at-bol))
2715 e (point-at-eol)
2716 ov (org-make-overlay b e))
2717 (if invis1
2718 (org-overlay-put ov 'invisible t)
2719 (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
2720 (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
2722 (defvar org-agenda-skip-function nil
2723 "Function to be called at each match during agenda construction.
2724 If this function returns nil, the current match should not be skipped.
2725 Otherwise, the function must return a position from where the search
2726 should be continued.
2727 This may also be a Lisp form, it will be evaluated.
2728 Never set this variable using `setq' or so, because then it will apply
2729 to all future agenda commands. Instead, bind it with `let' to scope
2730 it dynamically into the agenda-constructing command. A good way to set
2731 it is through options in org-agenda-custom-commands.")
2733 (defun org-agenda-skip ()
2734 "Throw to `:skip' in places that should be skipped.
2735 Also moves point to the end of the skipped region, so that search can
2736 continue from there."
2737 (let ((p (point-at-bol)) to fp)
2738 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
2739 (get-text-property p :org-archived)
2740 (org-end-of-subtree t)
2741 (throw :skip t))
2742 (and org-agenda-skip-comment-trees
2743 (get-text-property p :org-comment)
2744 (org-end-of-subtree t)
2745 (throw :skip t))
2746 (if (equal (char-after p) ?#) (throw :skip t))
2747 (when (and (or (setq fp (functionp org-agenda-skip-function))
2748 (consp org-agenda-skip-function))
2749 (setq to (save-excursion
2750 (save-match-data
2751 (if fp
2752 (funcall org-agenda-skip-function)
2753 (eval org-agenda-skip-function))))))
2754 (goto-char to)
2755 (throw :skip t))))
2757 (defvar org-agenda-markers nil
2758 "List of all currently active markers created by `org-agenda'.")
2759 (defvar org-agenda-last-marker-time (org-float-time)
2760 "Creation time of the last agenda marker.")
2762 (defun org-agenda-new-marker (&optional pos)
2763 "Return a new agenda marker.
2764 Org-mode keeps a list of these markers and resets them when they are
2765 no longer in use."
2766 (let ((m (copy-marker (or pos (point)))))
2767 (setq org-agenda-last-marker-time (org-float-time))
2768 (push m org-agenda-markers)
2771 (defun org-agenda-reset-markers ()
2772 "Reset markers created by `org-agenda'."
2773 (while org-agenda-markers
2774 (move-marker (pop org-agenda-markers) nil)))
2776 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
2777 "Save relative positions of markers in region."
2778 (mapc (lambda (m) (org-check-and-save-marker m beg end))
2779 org-agenda-markers))
2781 ;;; Entry text mode
2783 (defun org-agenda-entry-text-show-here ()
2784 "Add some text from te entry as context to the current line."
2785 (let (m txt o)
2786 (setq m (org-get-at-bol 'org-hd-marker))
2787 (unless (marker-buffer m)
2788 (error "No marker points to an entry here"))
2789 (setq txt (concat "\n" (org-no-properties
2790 (org-agenda-get-some-entry-text
2791 m org-agenda-entry-text-maxlines " > "))))
2792 (when (string-match "\\S-" txt)
2793 (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
2794 (org-overlay-put o 'evaporate t)
2795 (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
2796 (org-overlay-put o 'after-string txt))))
2798 (defun org-agenda-entry-text-show ()
2799 "Add entry context for all agenda lines."
2800 (interactive)
2801 (save-excursion
2802 (goto-char (point-max))
2803 (beginning-of-line 1)
2804 (while (not (bobp))
2805 (when (org-get-at-bol 'org-hd-marker)
2806 (org-agenda-entry-text-show-here))
2807 (beginning-of-line 0))))
2809 (defun org-agenda-entry-text-hide ()
2810 "Remove any shown entry context."
2811 (delq nil
2812 (mapcar (lambda (o)
2813 (if (eq (org-overlay-get o 'org-overlay-type)
2814 'agenda-entry-content)
2815 (progn (org-delete-overlay o) t)))
2816 (org-overlays-in (point-min) (point-max)))))
2818 ;;; Agenda timeline
2820 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
2822 (defun org-timeline (&optional include-all)
2823 "Show a time-sorted view of the entries in the current org file.
2824 Only entries with a time stamp of today or later will be listed. With
2825 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
2826 under the current date.
2827 If the buffer contains an active region, only check the region for
2828 dates."
2829 (interactive "P")
2830 (require 'calendar)
2831 (org-compile-prefix-format 'timeline)
2832 (org-set-sorting-strategy 'timeline)
2833 (let* ((dopast t)
2834 (dotodo include-all)
2835 (doclosed org-agenda-show-log)
2836 (entry buffer-file-name)
2837 (date (calendar-current-date))
2838 (beg (if (org-region-active-p) (region-beginning) (point-min)))
2839 (end (if (org-region-active-p) (region-end) (point-max)))
2840 (day-numbers (org-get-all-dates beg end 'no-ranges
2841 t doclosed ; always include today
2842 org-timeline-show-empty-dates))
2843 (org-deadline-warning-days 0)
2844 (org-agenda-only-exact-dates t)
2845 (today (time-to-days (current-time)))
2846 (past t)
2847 args
2848 s e rtn d emptyp wd)
2849 (setq org-agenda-redo-command
2850 (list 'progn
2851 (list 'org-switch-to-buffer-other-window (current-buffer))
2852 (list 'org-timeline (list 'quote include-all))))
2853 (if (not dopast)
2854 ;; Remove past dates from the list of dates.
2855 (setq day-numbers (delq nil (mapcar (lambda(x)
2856 (if (>= x today) x nil))
2857 day-numbers))))
2858 (org-prepare-agenda (concat "Timeline "
2859 (file-name-nondirectory buffer-file-name)))
2860 (if doclosed (push :closed args))
2861 (push :timestamp args)
2862 (push :deadline args)
2863 (push :scheduled args)
2864 (push :sexp args)
2865 (if dotodo (push :todo args))
2866 (insert "Timeline of file " entry "\n")
2867 (add-text-properties (point-min) (point)
2868 (list 'face 'org-agenda-structure))
2869 (org-agenda-mark-header-line (point-min))
2870 (while (setq d (pop day-numbers))
2871 (if (and (listp d) (eq (car d) :omitted))
2872 (progn
2873 (setq s (point))
2874 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
2875 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
2876 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
2877 (if (and (>= d today)
2878 dopast
2879 past)
2880 (progn
2881 (setq past nil)
2882 (insert (make-string 79 ?-) "\n")))
2883 (setq date (calendar-gregorian-from-absolute d)
2884 wd (calendar-day-of-week date))
2885 (setq s (point))
2886 (setq rtn (and (not emptyp)
2887 (apply 'org-agenda-get-day-entries entry
2888 date args)))
2889 (if (or rtn (equal d today) org-timeline-show-empty-dates)
2890 (progn
2891 (insert
2892 (if (stringp org-agenda-format-date)
2893 (format-time-string org-agenda-format-date
2894 (org-time-from-absolute date))
2895 (funcall org-agenda-format-date date))
2896 "\n")
2897 (put-text-property s (1- (point)) 'face
2898 (if (member wd org-agenda-weekend-days)
2899 'org-agenda-date-weekend
2900 'org-agenda-date))
2901 (put-text-property s (1- (point)) 'org-date-line t)
2902 (put-text-property s (1- (point)) 'org-agenda-date-header t)
2903 (if (equal d today)
2904 (put-text-property s (1- (point)) 'org-today t))
2905 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
2906 (put-text-property s (1- (point)) 'day d)))))
2907 (goto-char (point-min))
2908 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
2909 (point-min)))
2910 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
2911 (org-finalize-agenda)
2912 (setq buffer-read-only t)))
2914 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
2915 "Return a list of all relevant day numbers from BEG to END buffer positions.
2916 If NO-RANGES is non-nil, include only the start and end dates of a range,
2917 not every single day in the range. If FORCE-TODAY is non-nil, make
2918 sure that TODAY is included in the list. If INACTIVE is non-nil, also
2919 inactive time stamps (those in square brackets) are included.
2920 When EMPTY is non-nil, also include days without any entries."
2921 (let ((re (concat
2922 (if pre-re pre-re "")
2923 (if inactive org-ts-regexp-both org-ts-regexp)))
2924 dates dates1 date day day1 day2 ts1 ts2)
2925 (if force-today
2926 (setq dates (list (time-to-days (current-time)))))
2927 (save-excursion
2928 (goto-char beg)
2929 (while (re-search-forward re end t)
2930 (setq day (time-to-days (org-time-string-to-time
2931 (substring (match-string 1) 0 10))))
2932 (or (memq day dates) (push day dates)))
2933 (unless no-ranges
2934 (goto-char beg)
2935 (while (re-search-forward org-tr-regexp end t)
2936 (setq ts1 (substring (match-string 1) 0 10)
2937 ts2 (substring (match-string 2) 0 10)
2938 day1 (time-to-days (org-time-string-to-time ts1))
2939 day2 (time-to-days (org-time-string-to-time ts2)))
2940 (while (< (setq day1 (1+ day1)) day2)
2941 (or (memq day1 dates) (push day1 dates)))))
2942 (setq dates (sort dates '<))
2943 (when empty
2944 (while (setq day (pop dates))
2945 (setq day2 (car dates))
2946 (push day dates1)
2947 (when (and day2 empty)
2948 (if (or (eq empty t)
2949 (and (numberp empty) (<= (- day2 day) empty)))
2950 (while (< (setq day (1+ day)) day2)
2951 (push (list day) dates1))
2952 (push (cons :omitted (- day2 day)) dates1))))
2953 (setq dates (nreverse dates1)))
2954 dates)))
2956 ;;; Agenda Daily/Weekly
2958 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2959 (defvar org-agenda-start-day nil ; dynamically scoped parameter
2960 "Custom commands can set this variable in the options section.")
2961 (defvar org-agenda-last-arguments nil
2962 "The arguments of the previous call to org-agenda")
2963 (defvar org-starting-day nil) ; local variable in the agenda buffer
2964 (defvar org-agenda-span nil) ; local variable in the agenda buffer
2965 (defvar org-include-all-loc nil) ; local variable
2966 (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
2968 ;;;###autoload
2969 (defun org-agenda-list (&optional include-all start-day ndays)
2970 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
2971 The view will be for the current day or week, but from the overview buffer
2972 you will be able to go to other days/weeks.
2974 With one \\[universal-argument] prefix argument INCLUDE-ALL,
2975 all unfinished TODO items will also be shown, before the agenda.
2976 This feature is considered obsolete, please use the TODO list or a block
2977 agenda instead.
2979 With a numeric prefix argument in an interactive call, the agenda will
2980 span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
2981 the number of days. NDAYS defaults to `org-agenda-ndays'.
2983 START-DAY defaults to TODAY, or to the most recent match for the weekday
2984 given in `org-agenda-start-on-weekday'."
2985 (interactive "P")
2986 (if (and (integerp include-all) (> include-all 0))
2987 (setq ndays include-all include-all nil))
2988 (setq ndays (or ndays org-agenda-ndays)
2989 start-day (or start-day org-agenda-start-day))
2990 (if org-agenda-overriding-arguments
2991 (setq include-all (car org-agenda-overriding-arguments)
2992 start-day (nth 1 org-agenda-overriding-arguments)
2993 ndays (nth 2 org-agenda-overriding-arguments)))
2994 (if (stringp start-day)
2995 ;; Convert to an absolute day number
2996 (setq start-day (time-to-days (org-read-date nil t start-day))))
2997 (setq org-agenda-last-arguments (list include-all start-day ndays))
2998 (org-compile-prefix-format 'agenda)
2999 (org-set-sorting-strategy 'agenda)
3000 (require 'calendar)
3001 (let* ((org-agenda-start-on-weekday
3002 (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
3003 org-agenda-start-on-weekday nil))
3004 (thefiles (org-agenda-files nil 'ifmode))
3005 (files thefiles)
3006 (today (time-to-days
3007 (time-subtract (current-time)
3008 (list 0 (* 3600 org-extend-today-until) 0))))
3009 (sd (or start-day today))
3010 (start (if (or (null org-agenda-start-on-weekday)
3011 (< org-agenda-ndays 7))
3013 (let* ((nt (calendar-day-of-week
3014 (calendar-gregorian-from-absolute sd)))
3015 (n1 org-agenda-start-on-weekday)
3016 (d (- nt n1)))
3017 (- sd (+ (if (< d 0) 7 0) d)))))
3018 (day-numbers (list start))
3019 (day-cnt 0)
3020 (inhibit-redisplay (not debug-on-error))
3021 s e rtn rtnall file date d start-pos end-pos todayp nd wd
3022 clocktable-start clocktable-end)
3023 (setq org-agenda-redo-command
3024 (list 'org-agenda-list (list 'quote include-all) start-day ndays))
3025 ;; Make the list of days
3026 (setq ndays (or ndays org-agenda-ndays)
3027 nd ndays)
3028 (while (> ndays 1)
3029 (push (1+ (car day-numbers)) day-numbers)
3030 (setq ndays (1- ndays)))
3031 (setq day-numbers (nreverse day-numbers))
3032 (setq clocktable-start (car day-numbers)
3033 clocktable-end (1+ (or (org-last day-numbers) 0)))
3034 (org-prepare-agenda "Day/Week")
3035 (org-set-local 'org-starting-day (car day-numbers))
3036 (org-set-local 'org-include-all-loc include-all)
3037 (org-set-local 'org-agenda-span
3038 (org-agenda-ndays-to-span nd))
3039 (when (and (or include-all org-agenda-include-all-todo)
3040 (member today day-numbers))
3041 (setq files thefiles
3042 rtnall nil)
3043 (while (setq file (pop files))
3044 (catch 'nextfile
3045 (org-check-agenda-file file)
3046 (setq date (calendar-gregorian-from-absolute today)
3047 rtn (org-agenda-get-day-entries
3048 file date :todo))
3049 (setq rtnall (append rtnall rtn))))
3050 (when rtnall
3051 (insert "All currently open TODO items:\n")
3052 (add-text-properties (point-min) (1- (point))
3053 (list 'face 'org-agenda-structure
3054 'short-heading "All TODO items"))
3055 (org-agenda-mark-header-line (point-min))
3056 (insert (org-finalize-agenda-entries rtnall) "\n")))
3057 (unless org-agenda-compact-blocks
3058 (let* ((d1 (car day-numbers))
3059 (d2 (org-last day-numbers))
3060 (w1 (org-days-to-iso-week d1))
3061 (w2 (org-days-to-iso-week d2)))
3062 (setq s (point))
3063 (if org-agenda-overriding-header
3064 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3065 nil 'face 'org-agenda-structure) "\n")
3066 (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
3067 "-agenda"
3068 (if (< (- d2 d1) 350)
3069 (if (= w1 w2)
3070 (format " (W%02d)" w1)
3071 (format " (W%02d-W%02d)" w1 w2))
3073 ":\n")))
3074 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3075 'org-date-line t))
3076 (org-agenda-mark-header-line s))
3077 (while (setq d (pop day-numbers))
3078 (setq date (calendar-gregorian-from-absolute d)
3079 wd (calendar-day-of-week date)
3080 s (point))
3081 (if (or (setq todayp (= d today))
3082 (and (not start-pos) (= d sd)))
3083 (setq start-pos (point))
3084 (if (and start-pos (not end-pos))
3085 (setq end-pos (point))))
3086 (setq files thefiles
3087 rtnall nil)
3088 (while (setq file (pop files))
3089 (catch 'nextfile
3090 (org-check-agenda-file file)
3091 (cond
3092 ((eq org-agenda-show-log 'only)
3093 (setq rtn (org-agenda-get-day-entries
3094 file date :closed)))
3095 (org-agenda-show-log
3096 (setq rtn (org-agenda-get-day-entries
3097 file date
3098 :deadline :scheduled :timestamp :sexp :closed)))
3100 (setq rtn (org-agenda-get-day-entries
3101 file date
3102 :deadline :scheduled :sexp :timestamp))))
3103 (setq rtnall (append rtnall rtn))))
3104 (if org-agenda-include-diary
3105 (let ((org-agenda-search-headline-for-time t))
3106 (require 'diary-lib)
3107 (setq rtn (org-get-entries-from-diary date))
3108 (setq rtnall (append rtnall rtn))))
3109 (if (or rtnall org-agenda-show-all-dates)
3110 (progn
3111 (setq day-cnt (1+ day-cnt))
3112 (insert
3113 (if (stringp org-agenda-format-date)
3114 (format-time-string org-agenda-format-date
3115 (org-time-from-absolute date))
3116 (funcall org-agenda-format-date date))
3117 "\n")
3118 (put-text-property s (1- (point)) 'face
3119 (if (member wd org-agenda-weekend-days)
3120 'org-agenda-date-weekend
3121 'org-agenda-date))
3122 (put-text-property s (1- (point)) 'org-date-line t)
3123 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3124 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3125 (when todayp
3126 (put-text-property s (1- (point)) 'org-today t)
3127 (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
3128 (if rtnall (insert
3129 (org-finalize-agenda-entries
3130 (org-agenda-add-time-grid-maybe
3131 rtnall nd todayp))
3132 "\n"))
3133 (put-text-property s (1- (point)) 'day d)
3134 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3135 (when (and org-agenda-clockreport-mode clocktable-start)
3136 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3137 ;; the above line is to ensure the restricted range!
3138 (p org-agenda-clockreport-parameter-plist)
3139 tbl)
3140 (setq p (org-plist-delete p :block))
3141 (setq p (plist-put p :tstart clocktable-start))
3142 (setq p (plist-put p :tend clocktable-end))
3143 (setq p (plist-put p :scope 'agenda))
3144 (setq tbl (apply 'org-get-clocktable p))
3145 (insert tbl)))
3146 (goto-char (point-min))
3147 (or org-agenda-multi (org-fit-agenda-window))
3148 (unless (and (pos-visible-in-window-p (point-min))
3149 (pos-visible-in-window-p (point-max)))
3150 (goto-char (1- (point-max)))
3151 (recenter -1)
3152 (if (not (pos-visible-in-window-p (or start-pos 1)))
3153 (progn
3154 (goto-char (or start-pos 1))
3155 (recenter 1))))
3156 (goto-char (or start-pos 1))
3157 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3158 (org-finalize-agenda)
3159 (setq buffer-read-only t)
3160 (message "")))
3162 (defun org-agenda-ndays-to-span (n)
3163 (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
3165 ;;; Agenda word search
3167 (defvar org-agenda-search-history nil)
3168 (defvar org-todo-only nil)
3170 (defvar org-search-syntax-table nil
3171 "Special syntax table for org-mode search.
3172 In this table, we have single quotes not as word constituents, to
3173 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3175 (defun org-search-syntax-table ()
3176 (unless org-search-syntax-table
3177 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3178 (modify-syntax-entry ?' "." org-search-syntax-table)
3179 (modify-syntax-entry ?` "." org-search-syntax-table))
3180 org-search-syntax-table)
3182 ;;;###autoload
3183 (defun org-search-view (&optional todo-only string edit-at)
3184 "Show all entries that contain words or regular expressions.
3185 If the first character of the search string is an asterisks,
3186 search only the headlines.
3188 With optional prefix argument TODO-ONLY, only consider entries that are
3189 TODO entries. The argument STRING can be used to pass a default search
3190 string into this function. If EDIT-AT is non-nil, it means that the
3191 user should get a chance to edit this string, with cursor at position
3192 EDIT-AT.
3194 The search string is broken into \"words\" by splitting at whitespace.
3195 Depending on the variable `org-agenda-search-view-search-words-only'
3196 and on wether the first character in the search string is \"+\" or \"-\",
3197 The string is then interpreted either as a substrig with variable amounts
3198 of whitespace, or as a list or individual words that should be matched.
3200 The default is a substring match, where each space in the search string
3201 can expand to an arbitrary amount of whitespace, including newlines.
3203 If matching individual words, these words are then interpreted as a
3204 boolean expression with logical AND. Words prefixed with a minus must
3205 not occur in the entry. Words without a prefix or prefixed with a plus
3206 must occur in the entry. Matching is case-insensitive and the words
3207 are enclosed by word delimiters.
3209 Words enclosed by curly braces are interpreted as regular expressions
3210 that must or must not match in the entry.
3212 If the search string starts with an asterisk, search only in headlines.
3213 If (possibly after the leading star) the search string starts with an
3214 exclamation mark, this also means to look at TODO entries only, an effect
3215 that can also be achieved with a prefix argument.
3217 This command searches the agenda files, and in addition the files listed
3218 in `org-agenda-text-search-extra-files'."
3219 (interactive "P")
3220 (org-compile-prefix-format 'search)
3221 (org-set-sorting-strategy 'search)
3222 (org-prepare-agenda "SEARCH")
3223 (let* ((props (list 'face nil
3224 'done-face 'org-agenda-done
3225 'org-not-done-regexp org-not-done-regexp
3226 'org-todo-regexp org-todo-regexp
3227 'org-complex-heading-regexp org-complex-heading-regexp
3228 'mouse-face 'highlight
3229 'keymap org-agenda-keymap
3230 'help-echo (format "mouse-2 or RET jump to location")))
3231 regexp rtn rtnall files file pos
3232 marker category tags c neg re as-words
3233 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3234 (unless (and (not edit-at)
3235 (stringp string)
3236 (string-match "\\S-" string))
3237 (setq string (read-string "[+-]Word/{Regexp} ...: "
3238 (cond
3239 ((integerp edit-at) (cons string edit-at))
3240 (edit-at string))
3241 'org-agenda-search-history)))
3242 (org-set-local 'org-todo-only todo-only)
3243 (setq org-agenda-redo-command
3244 (list 'org-search-view (if todo-only t nil) string
3245 '(if current-prefix-arg 1 nil)))
3246 (setq org-agenda-query-string string)
3248 (if (equal (string-to-char string) ?*)
3249 (setq hdl-only t
3250 words (substring string 1))
3251 (setq words string))
3252 (when (equal (string-to-char words) ?!)
3253 (setq todo-only t
3254 words (substring words 1)))
3255 (if (or org-agenda-search-view-search-words-only
3256 (member (string-to-char string) '(?- ?+)))
3257 (setq as-words t))
3258 (setq words (org-split-string words))
3259 (if as-words
3260 (mapc (lambda (w)
3261 (setq c (string-to-char w))
3262 (if (equal c ?-)
3263 (setq neg t w (substring w 1))
3264 (if (equal c ?+)
3265 (setq neg nil w (substring w 1))
3266 (setq neg nil)))
3267 (if (string-match "\\`{.*}\\'" w)
3268 (setq re (substring w 1 -1))
3269 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
3270 (if neg (push re regexps-) (push re regexps+)))
3271 words)
3272 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3273 regexps+))
3274 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3275 (if (not regexps+)
3276 (setq regexp (concat "^" org-outline-regexp))
3277 (setq regexp (pop regexps+))
3278 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3279 regexp))))
3280 (setq files (org-agenda-files nil 'ifmode))
3281 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3282 (pop org-agenda-text-search-extra-files)
3283 (setq files (org-add-archive-files files)))
3284 (setq files (append files org-agenda-text-search-extra-files)
3285 rtnall nil)
3286 (while (setq file (pop files))
3287 (setq ee nil)
3288 (catch 'nextfile
3289 (org-check-agenda-file file)
3290 (setq buffer (if (file-exists-p file)
3291 (org-get-agenda-file-buffer file)
3292 (error "No such file %s" file)))
3293 (if (not buffer)
3294 ;; If file does not exist, make sure an error message is sent
3295 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3296 file))))
3297 (with-current-buffer buffer
3298 (with-syntax-table (org-search-syntax-table)
3299 (unless (org-mode-p)
3300 (error "Agenda file %s is not in `org-mode'" file))
3301 (let ((case-fold-search t))
3302 (save-excursion
3303 (save-restriction
3304 (if org-agenda-restrict
3305 (narrow-to-region org-agenda-restrict-begin
3306 org-agenda-restrict-end)
3307 (widen))
3308 (goto-char (point-min))
3309 (unless (or (org-on-heading-p)
3310 (outline-next-heading))
3311 (throw 'nextfile t))
3312 (goto-char (max (point-min) (1- (point))))
3313 (while (re-search-forward regexp nil t)
3314 (org-back-to-heading t)
3315 (skip-chars-forward "* ")
3316 (setq beg (point-at-bol)
3317 beg1 (point)
3318 end (progn (outline-next-heading) (point)))
3319 (catch :skip
3320 (goto-char beg)
3321 (org-agenda-skip)
3322 (setq str (buffer-substring-no-properties
3323 (point-at-bol)
3324 (if hdl-only (point-at-eol) end)))
3325 (mapc (lambda (wr) (when (string-match wr str)
3326 (goto-char (1- end))
3327 (throw :skip t)))
3328 regexps-)
3329 (mapc (lambda (wr) (unless (string-match wr str)
3330 (goto-char (1- end))
3331 (throw :skip t)))
3332 (if todo-only
3333 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3334 regexps+)
3335 regexps+))
3336 (goto-char beg)
3337 (setq marker (org-agenda-new-marker (point))
3338 category (org-get-category)
3339 tags (org-get-tags-at (point))
3340 txt (org-format-agenda-item
3342 (buffer-substring-no-properties
3343 beg1 (point-at-eol))
3344 category tags))
3345 (org-add-props txt props
3346 'org-marker marker 'org-hd-marker marker
3347 'org-todo-regexp org-todo-regexp
3348 'org-complex-heading-regexp org-complex-heading-regexp
3349 'priority 1000 'org-category category
3350 'type "search")
3351 (push txt ee)
3352 (goto-char (1- end))))))))))
3353 (setq rtn (nreverse ee))
3354 (setq rtnall (append rtnall rtn)))
3355 (if org-agenda-overriding-header
3356 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3357 nil 'face 'org-agenda-structure) "\n")
3358 (insert "Search words: ")
3359 (add-text-properties (point-min) (1- (point))
3360 (list 'face 'org-agenda-structure))
3361 (setq pos (point))
3362 (insert string "\n")
3363 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3364 (setq pos (point))
3365 (unless org-agenda-multi
3366 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3367 (add-text-properties pos (1- (point))
3368 (list 'face 'org-agenda-structure))))
3369 (org-agenda-mark-header-line (point-min))
3370 (when rtnall
3371 (insert (org-finalize-agenda-entries rtnall) "\n"))
3372 (goto-char (point-min))
3373 (or org-agenda-multi (org-fit-agenda-window))
3374 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3375 (org-finalize-agenda)
3376 (setq buffer-read-only t)))
3378 ;;; Agenda TODO list
3380 (defvar org-select-this-todo-keyword nil)
3381 (defvar org-last-arg nil)
3383 ;;;###autoload
3384 (defun org-todo-list (arg)
3385 "Show all TODO entries from all agenda file in a single list.
3386 The prefix arg can be used to select a specific TODO keyword and limit
3387 the list to these. When using \\[universal-argument], you will be prompted
3388 for a keyword. A numeric prefix directly selects the Nth keyword in
3389 `org-todo-keywords-1'."
3390 (interactive "P")
3391 (require 'calendar)
3392 (org-compile-prefix-format 'todo)
3393 (org-set-sorting-strategy 'todo)
3394 (org-prepare-agenda "TODO")
3395 (let* ((today (time-to-days (current-time)))
3396 (date (calendar-gregorian-from-absolute today))
3397 (kwds org-todo-keywords-for-agenda)
3398 (completion-ignore-case t)
3399 (org-select-this-todo-keyword
3400 (if (stringp arg) arg
3401 (and arg (integerp arg) (> arg 0)
3402 (nth (1- arg) kwds))))
3403 rtn rtnall files file pos)
3404 (when (equal arg '(4))
3405 (setq org-select-this-todo-keyword
3406 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3407 (mapcar 'list kwds) nil nil)))
3408 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3409 (org-set-local 'org-last-arg arg)
3410 (setq org-agenda-redo-command
3411 '(org-todo-list (or current-prefix-arg org-last-arg)))
3412 (setq files (org-agenda-files nil 'ifmode)
3413 rtnall nil)
3414 (while (setq file (pop files))
3415 (catch 'nextfile
3416 (org-check-agenda-file file)
3417 (setq rtn (org-agenda-get-day-entries file date :todo))
3418 (setq rtnall (append rtnall rtn))))
3419 (if org-agenda-overriding-header
3420 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3421 nil 'face 'org-agenda-structure) "\n")
3422 (insert "Global list of TODO items of type: ")
3423 (add-text-properties (point-min) (1- (point))
3424 (list 'face 'org-agenda-structure
3425 'short-heading
3426 (concat "ToDo: "
3427 (or org-select-this-todo-keyword "ALL"))))
3428 (org-agenda-mark-header-line (point-min))
3429 (setq pos (point))
3430 (insert (or org-select-this-todo-keyword "ALL") "\n")
3431 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3432 (setq pos (point))
3433 (unless org-agenda-multi
3434 (insert "Available with `N r': (0)ALL")
3435 (let ((n 0) s)
3436 (mapc (lambda (x)
3437 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3438 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3439 (insert "\n "))
3440 (insert " " s))
3441 kwds))
3442 (insert "\n"))
3443 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3444 (org-agenda-mark-header-line (point-min))
3445 (when rtnall
3446 (insert (org-finalize-agenda-entries rtnall) "\n"))
3447 (goto-char (point-min))
3448 (or org-agenda-multi (org-fit-agenda-window))
3449 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
3450 (org-finalize-agenda)
3451 (setq buffer-read-only t)))
3453 ;;; Agenda tags match
3455 ;;;###autoload
3456 (defun org-tags-view (&optional todo-only match)
3457 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
3458 The prefix arg TODO-ONLY limits the search to TODO entries."
3459 (interactive "P")
3460 (org-compile-prefix-format 'tags)
3461 (org-set-sorting-strategy 'tags)
3462 (let* ((org-tags-match-list-sublevels
3463 ;?????? (if todo-only t org-tags-match-list-sublevels))
3464 org-tags-match-list-sublevels)
3465 (completion-ignore-case t)
3466 rtn rtnall files file pos matcher
3467 buffer)
3468 (setq matcher (org-make-tags-matcher match)
3469 match (car matcher) matcher (cdr matcher))
3470 (org-prepare-agenda (concat "TAGS " match))
3471 (setq org-agenda-query-string match)
3472 (setq org-agenda-redo-command
3473 (list 'org-tags-view (list 'quote todo-only)
3474 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
3475 (setq files (org-agenda-files nil 'ifmode)
3476 rtnall nil)
3477 (while (setq file (pop files))
3478 (catch 'nextfile
3479 (org-check-agenda-file file)
3480 (setq buffer (if (file-exists-p file)
3481 (org-get-agenda-file-buffer file)
3482 (error "No such file %s" file)))
3483 (if (not buffer)
3484 ;; If file does not exist, error message to agenda
3485 (setq rtn (list
3486 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3487 rtnall (append rtnall rtn))
3488 (with-current-buffer buffer
3489 (unless (org-mode-p)
3490 (error "Agenda file %s is not in `org-mode'" file))
3491 (save-excursion
3492 (save-restriction
3493 (if org-agenda-restrict
3494 (narrow-to-region org-agenda-restrict-begin
3495 org-agenda-restrict-end)
3496 (widen))
3497 (setq rtn (org-scan-tags 'agenda matcher todo-only))
3498 (setq rtnall (append rtnall rtn))))))))
3499 (if org-agenda-overriding-header
3500 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3501 nil 'face 'org-agenda-structure) "\n")
3502 (insert "Headlines with TAGS match: ")
3503 (add-text-properties (point-min) (1- (point))
3504 (list 'face 'org-agenda-structure
3505 'short-heading
3506 (concat "Match: " match)))
3507 (setq pos (point))
3508 (insert match "\n")
3509 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3510 (setq pos (point))
3511 (unless org-agenda-multi
3512 (insert "Press `C-u r' to search again with new search string\n"))
3513 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3514 (org-agenda-mark-header-line (point-min))
3515 (when rtnall
3516 (insert (org-finalize-agenda-entries rtnall) "\n"))
3517 (goto-char (point-min))
3518 (or org-agenda-multi (org-fit-agenda-window))
3519 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
3520 (org-finalize-agenda)
3521 (setq buffer-read-only t)))
3523 ;;; Agenda Finding stuck projects
3525 (defvar org-agenda-skip-regexp nil
3526 "Regular expression used in skipping subtrees for the agenda.
3527 This is basically a temporary global variable that can be set and then
3528 used by user-defined selections using `org-agenda-skip-function'.")
3530 (defvar org-agenda-overriding-header nil
3531 "When this is set during todo and tags searches, will replace header.
3532 This variable should not be set directly, but custom commands can bind it
3533 in the options section.")
3535 (defun org-agenda-skip-entry-when-regexp-matches ()
3536 "Checks if the current entry contains match for `org-agenda-skip-regexp'.
3537 If yes, it returns the end position of this entry, causing agenda commands
3538 to skip the entry but continuing the search in the subtree. This is a
3539 function that can be put into `org-agenda-skip-function' for the duration
3540 of a command."
3541 (let ((end (save-excursion (org-end-of-subtree t)))
3542 skip)
3543 (save-excursion
3544 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3545 (and skip end)))
3547 (defun org-agenda-skip-subtree-when-regexp-matches ()
3548 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3549 If yes, it returns the end position of this tree, causing agenda commands
3550 to skip this subtree. This is a function that can be put into
3551 `org-agenda-skip-function' for the duration of a command."
3552 (let ((end (save-excursion (org-end-of-subtree t)))
3553 skip)
3554 (save-excursion
3555 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3556 (and skip end)))
3558 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
3559 "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
3560 If yes, it returns the end position of the current entry (NOT the tree),
3561 causing agenda commands to skip the entry but continuing the search in
3562 the subtree. This is a function that can be put into
3563 `org-agenda-skip-function' for the duration of a command. An important
3564 use of this function is for the stuck project list."
3565 (let ((end (save-excursion (org-end-of-subtree t)))
3566 (entry-end (save-excursion (outline-next-heading) (1- (point))))
3567 skip)
3568 (save-excursion
3569 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
3570 (and skip entry-end)))
3572 (defun org-agenda-skip-entry-if (&rest conditions)
3573 "Skip entry if any of CONDITIONS is true.
3574 See `org-agenda-skip-if' for details."
3575 (org-agenda-skip-if nil conditions))
3577 (defun org-agenda-skip-subtree-if (&rest conditions)
3578 "Skip entry if any of CONDITIONS is true.
3579 See `org-agenda-skip-if' for details."
3580 (org-agenda-skip-if t conditions))
3582 (defun org-agenda-skip-if (subtree conditions)
3583 "Checks current entity for CONDITIONS.
3584 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
3585 the entry, i.e. the text before the next heading is checked.
3587 CONDITIONS is a list of symbols, boolean OR is used to combine the results
3588 from different tests. Valid conditions are:
3590 scheduled Check if there is a scheduled cookie
3591 notscheduled Check if there is no scheduled cookie
3592 deadline Check if there is a deadline
3593 notdeadline Check if there is no deadline
3594 timestamp Check if there is a timestamp (also deadline or scheduled)
3595 nottimestamp Check if there is no timestamp (also deadline or scheduled)
3596 regexp Check if regexp matches
3597 notregexp Check if regexp does not match.
3599 The regexp is taken from the conditions list, it must come right after
3600 the `regexp' or `notregexp' element.
3602 If any of these conditions is met, this function returns the end point of
3603 the entity, causing the search to continue from there. This is a function
3604 that can be put into `org-agenda-skip-function' for the duration of a command."
3605 (let (beg end m)
3606 (org-back-to-heading t)
3607 (setq beg (point)
3608 end (if subtree
3609 (progn (org-end-of-subtree t) (point))
3610 (progn (outline-next-heading) (1- (point)))))
3611 (goto-char beg)
3612 (and
3614 (and (memq 'scheduled conditions)
3615 (re-search-forward org-scheduled-time-regexp end t))
3616 (and (memq 'notscheduled conditions)
3617 (not (re-search-forward org-scheduled-time-regexp end t)))
3618 (and (memq 'deadline conditions)
3619 (re-search-forward org-deadline-time-regexp end t))
3620 (and (memq 'notdeadline conditions)
3621 (not (re-search-forward org-deadline-time-regexp end t)))
3622 (and (memq 'timestamp conditions)
3623 (re-search-forward org-ts-regexp end t))
3624 (and (memq 'nottimestamp conditions)
3625 (not (re-search-forward org-ts-regexp end t)))
3626 (and (setq m (memq 'regexp conditions))
3627 (stringp (nth 1 m))
3628 (re-search-forward (nth 1 m) end t))
3629 (and (setq m (memq 'notregexp conditions))
3630 (stringp (nth 1 m))
3631 (not (re-search-forward (nth 1 m) end t))))
3632 end)))
3634 ;;;###autoload
3635 (defun org-agenda-list-stuck-projects (&rest ignore)
3636 "Create agenda view for projects that are stuck.
3637 Stuck projects are project that have no next actions. For the definitions
3638 of what a project is and how to check if it stuck, customize the variable
3639 `org-stuck-projects'.
3640 MATCH is being ignored."
3641 (interactive)
3642 (let* ((org-agenda-skip-function
3643 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
3644 ;; We could have used org-agenda-skip-if here.
3645 (org-agenda-overriding-header
3646 (or org-agenda-overriding-header "List of stuck projects: "))
3647 (matcher (nth 0 org-stuck-projects))
3648 (todo (nth 1 org-stuck-projects))
3649 (todo-wds (if (member "*" todo)
3650 (progn
3651 (org-prepare-agenda-buffers (org-agenda-files
3652 nil 'ifmode))
3653 (org-delete-all
3654 org-done-keywords-for-agenda
3655 (copy-sequence org-todo-keywords-for-agenda)))
3656 todo))
3657 (todo-re (concat "^\\*+[ \t]+\\("
3658 (mapconcat 'identity todo-wds "\\|")
3659 "\\)\\>"))
3660 (tags (nth 2 org-stuck-projects))
3661 (tags-re (if (member "*" tags)
3662 (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
3663 (if tags
3664 (concat "^\\*+ .*:\\("
3665 (mapconcat 'identity tags "\\|")
3666 (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
3667 (gen-re (nth 3 org-stuck-projects))
3668 (re-list
3669 (delq nil
3670 (list
3671 (if todo todo-re)
3672 (if tags tags-re)
3673 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
3674 gen-re)))))
3675 (setq org-agenda-skip-regexp
3676 (if re-list
3677 (mapconcat 'identity re-list "\\|")
3678 (error "No information how to identify unstuck projects")))
3679 (org-tags-view nil matcher)
3680 (with-current-buffer org-agenda-buffer-name
3681 (setq org-agenda-redo-command
3682 '(org-agenda-list-stuck-projects
3683 (or current-prefix-arg org-last-arg))))))
3685 ;;; Diary integration
3687 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
3688 (defvar list-diary-entries-hook)
3690 (defun org-get-entries-from-diary (date)
3691 "Get the (Emacs Calendar) diary entries for DATE."
3692 (require 'diary-lib)
3693 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
3694 (fancy-diary-buffer diary-fancy-buffer)
3695 (diary-display-hook '(fancy-diary-display))
3696 (diary-display-function 'fancy-diary-display)
3697 (pop-up-frames nil)
3698 (list-diary-entries-hook
3699 (cons 'org-diary-default-entry list-diary-entries-hook))
3700 (diary-file-name-prefix-function nil) ; turn this feature off
3701 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
3702 entries
3703 (org-disable-agenda-to-diary t))
3704 (save-excursion
3705 (save-window-excursion
3706 (funcall (if (fboundp 'diary-list-entries)
3707 'diary-list-entries 'list-diary-entries)
3708 date 1)))
3709 (if (not (get-buffer diary-fancy-buffer))
3710 (setq entries nil)
3711 (with-current-buffer diary-fancy-buffer
3712 (setq buffer-read-only nil)
3713 (if (zerop (buffer-size))
3714 ;; No entries
3715 (setq entries nil)
3716 ;; Omit the date and other unnecessary stuff
3717 (org-agenda-cleanup-fancy-diary)
3718 ;; Add prefix to each line and extend the text properties
3719 (if (zerop (buffer-size))
3720 (setq entries nil)
3721 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
3722 (set-buffer-modified-p nil)
3723 (kill-buffer diary-fancy-buffer)))
3724 (when entries
3725 (setq entries (org-split-string entries "\n"))
3726 (setq entries
3727 (mapcar
3728 (lambda (x)
3729 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
3730 ;; Extend the text properties to the beginning of the line
3731 (org-add-props x (text-properties-at (1- (length x)) x)
3732 'type "diary" 'date date))
3733 entries)))))
3735 (defvar org-agenda-cleanup-fancy-diary-hook nil
3736 "Hook run when the fancy diary buffer is cleaned up.")
3738 (defun org-agenda-cleanup-fancy-diary ()
3739 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
3740 This gets rid of the date, the underline under the date, and
3741 the dummy entry installed by `org-mode' to ensure non-empty diary for each
3742 date. It also removes lines that contain only whitespace."
3743 (goto-char (point-min))
3744 (if (looking-at ".*?:[ \t]*")
3745 (progn
3746 (replace-match "")
3747 (re-search-forward "\n=+$" nil t)
3748 (replace-match "")
3749 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
3750 (re-search-forward "\n=+$" nil t)
3751 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
3752 (goto-char (point-min))
3753 (while (re-search-forward "^ +\n" nil t)
3754 (replace-match ""))
3755 (goto-char (point-min))
3756 (if (re-search-forward "^Org-mode dummy\n?" nil t)
3757 (replace-match ""))
3758 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
3760 ;; Make sure entries from the diary have the right text properties.
3761 (eval-after-load "diary-lib"
3762 '(if (boundp 'diary-modify-entry-list-string-function)
3763 ;; We can rely on the hook, nothing to do
3765 ;; Hook not available, must use advice to make this work
3766 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
3767 "Make the position visible."
3768 (if (and org-disable-agenda-to-diary ;; called from org-agenda
3769 (stringp string)
3770 buffer-file-name)
3771 (setq string (org-modify-diary-entry-string string))))))
3773 (defun org-modify-diary-entry-string (string)
3774 "Add text properties to string, allowing org-mode to act on it."
3775 (org-add-props string nil
3776 'mouse-face 'highlight
3777 'keymap org-agenda-keymap
3778 'help-echo (if buffer-file-name
3779 (format "mouse-2 or RET jump to diary file %s"
3780 (abbreviate-file-name buffer-file-name))
3782 'org-agenda-diary-link t
3783 'org-marker (org-agenda-new-marker (point-at-bol))))
3785 (defun org-diary-default-entry ()
3786 "Add a dummy entry to the diary.
3787 Needed to avoid empty dates which mess up holiday display."
3788 ;; Catch the error if dealing with the new add-to-diary-alist
3789 (when org-disable-agenda-to-diary
3790 (condition-case nil
3791 (org-add-to-diary-list original-date "Org-mode dummy" "")
3792 (error
3793 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
3795 (defun org-add-to-diary-list (&rest args)
3796 (if (fboundp 'diary-add-to-list)
3797 (apply 'diary-add-to-list args)
3798 (apply 'add-to-diary-list args)))
3800 ;;;###autoload
3801 (defun org-diary (&rest args)
3802 "Return diary information from org-files.
3803 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
3804 It accesses org files and extracts information from those files to be
3805 listed in the diary. The function accepts arguments specifying what
3806 items should be listed. The following arguments are allowed:
3808 :timestamp List the headlines of items containing a date stamp or
3809 date range matching the selected date. Deadlines will
3810 also be listed, on the expiration day.
3812 :sexp List entries resulting from diary-like sexps.
3814 :deadline List any deadlines past due, or due within
3815 `org-deadline-warning-days'. The listing occurs only
3816 in the diary for *today*, not at any other date. If
3817 an entry is marked DONE, it is no longer listed.
3819 :scheduled List all items which are scheduled for the given date.
3820 The diary for *today* also contains items which were
3821 scheduled earlier and are not yet marked DONE.
3823 :todo List all TODO items from the org-file. This may be a
3824 long list - so this is not turned on by default.
3825 Like deadlines, these entries only show up in the
3826 diary for *today*, not at any other date.
3828 The call in the diary file should look like this:
3830 &%%(org-diary) ~/path/to/some/orgfile.org
3832 Use a separate line for each org file to check. Or, if you omit the file name,
3833 all files listed in `org-agenda-files' will be checked automatically:
3835 &%%(org-diary)
3837 If you don't give any arguments (as in the example above), the default
3838 arguments (:deadline :scheduled :timestamp :sexp) are used.
3839 So the example above may also be written as
3841 &%%(org-diary :deadline :timestamp :sexp :scheduled)
3843 The function expects the lisp variables `entry' and `date' to be provided
3844 by the caller, because this is how the calendar works. Don't use this
3845 function from a program - use `org-agenda-get-day-entries' instead."
3846 (when (> (- (org-float-time)
3847 org-agenda-last-marker-time)
3849 (org-agenda-reset-markers))
3850 (org-compile-prefix-format 'agenda)
3851 (org-set-sorting-strategy 'agenda)
3852 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3853 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
3854 (list entry)
3855 (org-agenda-files t)))
3856 file rtn results)
3857 (org-prepare-agenda-buffers files)
3858 ;; If this is called during org-agenda, don't return any entries to
3859 ;; the calendar. Org Agenda will list these entries itself.
3860 (if org-disable-agenda-to-diary (setq files nil))
3861 (while (setq file (pop files))
3862 (setq rtn (apply 'org-agenda-get-day-entries file date args))
3863 (setq results (append results rtn)))
3864 (if results
3865 (concat (org-finalize-agenda-entries results) "\n"))))
3867 ;;; Agenda entry finders
3869 (defun org-agenda-get-day-entries (file date &rest args)
3870 "Does the work for `org-diary' and `org-agenda'.
3871 FILE is the path to a file to be checked for entries. DATE is date like
3872 the one returned by `calendar-current-date'. ARGS are symbols indicating
3873 which kind of entries should be extracted. For details about these, see
3874 the documentation of `org-diary'."
3875 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
3876 (let* ((org-startup-folded nil)
3877 (org-startup-align-all-tables nil)
3878 (buffer (if (file-exists-p file)
3879 (org-get-agenda-file-buffer file)
3880 (error "No such file %s" file)))
3881 arg results rtn deadline-results)
3882 (if (not buffer)
3883 ;; If file does not exist, make sure an error message ends up in diary
3884 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
3885 (with-current-buffer buffer
3886 (unless (org-mode-p)
3887 (error "Agenda file %s is not in `org-mode'" file))
3888 (let ((case-fold-search nil))
3889 (save-excursion
3890 (save-restriction
3891 (if org-agenda-restrict
3892 (narrow-to-region org-agenda-restrict-begin
3893 org-agenda-restrict-end)
3894 (widen))
3895 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
3896 (while (setq arg (pop args))
3897 (cond
3898 ((and (eq arg :todo)
3899 (equal date (calendar-current-date)))
3900 (setq rtn (org-agenda-get-todos))
3901 (setq results (append results rtn)))
3902 ((eq arg :timestamp)
3903 (setq rtn (org-agenda-get-blocks))
3904 (setq results (append results rtn))
3905 (setq rtn (org-agenda-get-timestamps))
3906 (setq results (append results rtn)))
3907 ((eq arg :sexp)
3908 (setq rtn (org-agenda-get-sexps))
3909 (setq results (append results rtn)))
3910 ((eq arg :scheduled)
3911 (setq rtn (org-agenda-get-scheduled deadline-results))
3912 (setq results (append results rtn)))
3913 ((eq arg :closed)
3914 (setq rtn (org-agenda-get-progress))
3915 (setq results (append results rtn)))
3916 ((eq arg :deadline)
3917 (setq rtn (org-agenda-get-deadlines))
3918 (setq deadline-results (copy-sequence rtn))
3919 (setq results (append results rtn))))))))
3920 results))))
3922 (defun org-agenda-get-todos ()
3923 "Return the TODO information for agenda display."
3924 (let* ((props (list 'face nil
3925 'done-face 'org-agenda-done
3926 'org-not-done-regexp org-not-done-regexp
3927 'org-todo-regexp org-todo-regexp
3928 'org-complex-heading-regexp org-complex-heading-regexp
3929 'mouse-face 'highlight
3930 'keymap org-agenda-keymap
3931 'help-echo
3932 (format "mouse-2 or RET jump to org file %s"
3933 (abbreviate-file-name buffer-file-name))))
3934 (regexp (concat "^\\*+[ \t]+\\("
3935 (if org-select-this-todo-keyword
3936 (if (equal org-select-this-todo-keyword "*")
3937 org-todo-regexp
3938 (concat "\\<\\("
3939 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
3940 "\\)\\>"))
3941 org-not-done-regexp)
3942 "[^\n\r]*\\)"))
3943 marker priority category tags todo-state
3944 ee txt beg end)
3945 (goto-char (point-min))
3946 (while (re-search-forward regexp nil t)
3947 (catch :skip
3948 (save-match-data
3949 (beginning-of-line)
3950 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
3951 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
3952 (goto-char (1+ beg))
3953 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
3954 (throw :skip nil)))
3955 (goto-char beg)
3956 (org-agenda-skip)
3957 (goto-char (match-beginning 1))
3958 (setq marker (org-agenda-new-marker (match-beginning 0))
3959 category (org-get-category)
3960 txt (match-string 1)
3961 tags (org-get-tags-at (point))
3962 txt (org-format-agenda-item "" txt category tags)
3963 priority (1+ (org-get-priority txt))
3964 todo-state (org-get-todo-state))
3965 (org-add-props txt props
3966 'org-marker marker 'org-hd-marker marker
3967 'priority priority 'org-category category
3968 'type "todo" 'todo-state todo-state)
3969 (push txt ee)
3970 (if org-agenda-todo-list-sublevels
3971 (goto-char (match-end 1))
3972 (org-end-of-subtree 'invisible))))
3973 (nreverse ee)))
3975 ;;;###autoload
3976 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
3977 "Do we have a reason to ignore this todo entry because it has a time stamp?"
3978 (when (or org-agenda-todo-ignore-with-date
3979 org-agenda-todo-ignore-scheduled
3980 org-agenda-todo-ignore-deadlines)
3981 (setq end (or end (save-excursion (outline-next-heading) (point))))
3982 (save-excursion
3983 (or (and org-agenda-todo-ignore-with-date
3984 (re-search-forward org-ts-regexp end t))
3985 (and org-agenda-todo-ignore-scheduled
3986 (re-search-forward org-scheduled-time-regexp end t))
3987 (and org-agenda-todo-ignore-deadlines
3988 (re-search-forward org-deadline-time-regexp end t)
3989 (org-deadline-close (match-string 1)))))))
3991 (defconst org-agenda-no-heading-message
3992 "No heading for this item in buffer or region.")
3994 (defun org-agenda-get-timestamps ()
3995 "Return the date stamp information for agenda display."
3996 (let* ((props (list 'face nil
3997 'org-not-done-regexp org-not-done-regexp
3998 'org-todo-regexp org-todo-regexp
3999 'org-complex-heading-regexp org-complex-heading-regexp
4000 'mouse-face 'highlight
4001 'keymap org-agenda-keymap
4002 'help-echo
4003 (format "mouse-2 or RET jump to org file %s"
4004 (abbreviate-file-name buffer-file-name))))
4005 (d1 (calendar-absolute-from-gregorian date))
4006 (remove-re
4007 (concat
4008 (regexp-quote
4009 (format-time-string
4010 "<%Y-%m-%d"
4011 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4012 ".*?>"))
4013 (regexp
4014 (concat
4015 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4016 (regexp-quote
4017 (substring
4018 (format-time-string
4019 (car org-time-stamp-formats)
4020 (apply 'encode-time ; DATE bound by calendar
4021 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4022 1 11))
4023 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4024 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4025 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4026 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4027 todo-state end-of-match)
4028 (goto-char (point-min))
4029 (while (setq end-of-match (re-search-forward regexp nil t))
4030 (setq b0 (match-beginning 0)
4031 b3 (match-beginning 3) e3 (match-end 3))
4032 (catch :skip
4033 (and (org-at-date-range-p) (throw :skip nil))
4034 (org-agenda-skip)
4035 (if (and (match-end 1)
4036 (not (= d1 (org-time-string-to-absolute
4037 (match-string 1) d1 nil
4038 org-agenda-repeating-timestamp-show-all))))
4039 (throw :skip nil))
4040 (if (and e3
4041 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4042 (throw :skip nil))
4043 (setq tmp (buffer-substring (max (point-min)
4044 (- b0 org-ds-keyword-length))
4046 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4047 inactivep (= (char-after b0) ?\[)
4048 deadlinep (string-match org-deadline-regexp tmp)
4049 scheduledp (string-match org-scheduled-regexp tmp)
4050 closedp (and org-agenda-include-inactive-timestamps
4051 (string-match org-closed-string tmp))
4052 clockp (and org-agenda-include-inactive-timestamps
4053 (or (string-match org-clock-string tmp)
4054 (string-match "]-+\\'" tmp)))
4055 todo-state (org-get-todo-state)
4056 donep (member todo-state org-done-keywords))
4057 (if (or scheduledp deadlinep closedp clockp
4058 (and donep org-agenda-skip-timestamp-if-done))
4059 (throw :skip t))
4060 (if (string-match ">" timestr)
4061 ;; substring should only run to end of time stamp
4062 (setq timestr (substring timestr 0 (match-end 0))))
4063 (setq marker (org-agenda-new-marker b0)
4064 category (org-get-category b0))
4065 (save-excursion
4066 (if (not (re-search-backward "^\\*+ " nil t))
4067 (setq txt org-agenda-no-heading-message)
4068 (goto-char (match-beginning 0))
4069 (setq hdmarker (org-agenda-new-marker)
4070 tags (org-get-tags-at))
4071 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4072 (setq head (match-string 1))
4073 (setq txt (org-format-agenda-item
4074 (if inactivep "[" nil)
4075 head category tags timestr nil
4076 remove-re)))
4077 (setq priority (org-get-priority txt))
4078 (org-add-props txt props
4079 'org-marker marker 'org-hd-marker hdmarker)
4080 (org-add-props txt nil 'priority priority
4081 'org-category category 'date date
4082 'todo-state todo-state
4083 'type "timestamp")
4084 (push txt ee))
4085 (if org-agenda-skip-additional-timestamps-same-entry
4086 (outline-next-heading)
4087 (goto-char end-of-match))))
4088 (nreverse ee)))
4090 (defun org-agenda-get-sexps ()
4091 "Return the sexp information for agenda display."
4092 (require 'diary-lib)
4093 (let* ((props (list 'face nil
4094 'mouse-face 'highlight
4095 'keymap org-agenda-keymap
4096 'help-echo
4097 (format "mouse-2 or RET jump to org file %s"
4098 (abbreviate-file-name buffer-file-name))))
4099 (regexp "^&?%%(")
4100 marker category ee txt tags entry result beg b sexp sexp-entry
4101 todo-state)
4102 (goto-char (point-min))
4103 (while (re-search-forward regexp nil t)
4104 (catch :skip
4105 (org-agenda-skip)
4106 (setq beg (match-beginning 0))
4107 (goto-char (1- (match-end 0)))
4108 (setq b (point))
4109 (forward-sexp 1)
4110 (setq sexp (buffer-substring b (point)))
4111 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4112 (org-trim (match-string 1))
4113 ""))
4114 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4115 (when result
4116 (setq marker (org-agenda-new-marker beg)
4117 category (org-get-category beg)
4118 todo-state (org-get-todo-state))
4120 (if (string-match "\\S-" result)
4121 (setq txt result)
4122 (setq txt "SEXP entry returned empty string"))
4124 (setq txt (org-format-agenda-item
4125 "" txt category tags 'time))
4126 (org-add-props txt props 'org-marker marker)
4127 (org-add-props txt nil
4128 'org-category category 'date date 'todo-state todo-state
4129 'type "sexp")
4130 (push txt ee))))
4131 (nreverse ee)))
4133 (defalias 'org-get-closed 'org-agenda-get-progress)
4134 (defun org-agenda-get-progress ()
4135 "Return the logged TODO entries for agenda display."
4136 (let* ((props (list 'mouse-face 'highlight
4137 'org-not-done-regexp org-not-done-regexp
4138 'org-todo-regexp org-todo-regexp
4139 'org-complex-heading-regexp org-complex-heading-regexp
4140 'keymap org-agenda-keymap
4141 'help-echo
4142 (format "mouse-2 or RET jump to org file %s"
4143 (abbreviate-file-name buffer-file-name))))
4144 (items (if (consp org-agenda-show-log)
4145 org-agenda-show-log
4146 org-agenda-log-mode-items))
4147 (parts
4148 (delq nil
4149 (list
4150 (if (memq 'closed items) (concat "\\<" org-closed-string))
4151 (if (memq 'clock items) (concat "\\<" org-clock-string))
4152 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4153 (parts-re (if parts (mapconcat 'identity parts "\\|")
4154 (error "`org-agenda-log-mode-items' is empty")))
4155 (regexp (concat
4156 "\\(" parts-re "\\)"
4157 " *\\["
4158 (regexp-quote
4159 (substring
4160 (format-time-string
4161 (car org-time-stamp-formats)
4162 (apply 'encode-time ; DATE bound by calendar
4163 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4164 1 11))))
4165 (org-agenda-search-headline-for-time nil)
4166 marker hdmarker priority category tags closedp statep clockp state
4167 ee txt extra timestr rest clocked)
4168 (goto-char (point-min))
4169 (while (re-search-forward regexp nil t)
4170 (catch :skip
4171 (org-agenda-skip)
4172 (setq marker (org-agenda-new-marker (match-beginning 0))
4173 closedp (equal (match-string 1) org-closed-string)
4174 statep (equal (string-to-char (match-string 1)) ?-)
4175 clockp (not (or closedp statep))
4176 state (and statep (match-string 2))
4177 category (org-get-category (match-beginning 0))
4178 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4180 (when (string-match "\\]" timestr)
4181 ;; substring should only run to end of time stamp
4182 (setq rest (substring timestr (match-end 0))
4183 timestr (substring timestr 0 (match-end 0)))
4184 (if (and (not closedp) (not statep)
4185 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4186 (progn (setq timestr (concat (substring timestr 0 -1)
4187 "-" (match-string 1 rest) "]"))
4188 (setq clocked (match-string 2 rest)))
4189 (setq clocked "-")))
4190 (save-excursion
4191 (cond
4192 ((not org-agenda-log-mode-add-notes) (setq extra nil))
4193 (statep
4194 (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4195 (setq extra (match-string 1))))
4196 (clockp
4197 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4198 (setq extra (match-string 1))))
4199 (t (setq extra nil)))
4200 (if (not (re-search-backward "^\\*+ " nil t))
4201 (setq txt org-agenda-no-heading-message)
4202 (goto-char (match-beginning 0))
4203 (setq hdmarker (org-agenda-new-marker)
4204 tags (org-get-tags-at))
4205 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4206 (setq txt (match-string 1))
4207 (when extra
4208 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4209 (setq txt (concat (substring txt 0 (match-beginning 1))
4210 " - " extra " " (match-string 2 txt)))
4211 (setq txt (concat txt " - " extra))))
4212 (setq txt (org-format-agenda-item
4213 (cond
4214 (closedp "Closed: ")
4215 (statep (concat "State: (" state ")"))
4216 (t (concat "Clocked: (" clocked ")")))
4217 txt category tags timestr)))
4218 (setq priority 100000)
4219 (org-add-props txt props
4220 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4221 'priority priority 'org-category category
4222 'type "closed" 'date date
4223 'undone-face 'org-warning 'done-face 'org-agenda-done)
4224 (push txt ee))
4225 (goto-char (point-at-eol))))
4226 (nreverse ee)))
4228 (defun org-agenda-get-deadlines ()
4229 "Return the deadline information for agenda display."
4230 (let* ((props (list 'mouse-face 'highlight
4231 'org-not-done-regexp org-not-done-regexp
4232 'org-todo-regexp org-todo-regexp
4233 'org-complex-heading-regexp org-complex-heading-regexp
4234 'keymap org-agenda-keymap
4235 'help-echo
4236 (format "mouse-2 or RET jump to org file %s"
4237 (abbreviate-file-name buffer-file-name))))
4238 (regexp org-deadline-time-regexp)
4239 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4240 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4241 d2 diff dfrac wdays pos pos1 category tags
4242 ee txt head face s todo-state upcomingp donep timestr)
4243 (goto-char (point-min))
4244 (while (re-search-forward regexp nil t)
4245 (catch :skip
4246 (org-agenda-skip)
4247 (setq s (match-string 1)
4248 txt nil
4249 pos (1- (match-beginning 1))
4250 d2 (org-time-string-to-absolute
4251 (match-string 1) d1 'past
4252 org-agenda-repeating-timestamp-show-all)
4253 diff (- d2 d1)
4254 wdays (org-get-wdays s)
4255 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4256 upcomingp (and todayp (> diff 0)))
4257 ;; When to show a deadline in the calendar:
4258 ;; If the expiration is within wdays warning time.
4259 ;; Past-due deadlines are only shown on the current date
4260 (if (and (or (and (<= diff wdays)
4261 (and todayp (not org-agenda-only-exact-dates)))
4262 (= diff 0)))
4263 (save-excursion
4264 (setq todo-state (org-get-todo-state))
4265 (setq donep (member todo-state org-done-keywords))
4266 (if (and donep
4267 (or org-agenda-skip-deadline-if-done
4268 (not (= diff 0))))
4269 (setq txt nil)
4270 (setq category (org-get-category))
4271 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4272 (setq txt org-agenda-no-heading-message)
4273 (goto-char (match-end 0))
4274 (setq pos1 (match-beginning 0))
4275 (setq tags (org-get-tags-at pos1))
4276 (setq head (buffer-substring-no-properties
4277 (point)
4278 (progn (skip-chars-forward "^\r\n")
4279 (point))))
4280 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4281 (setq timestr
4282 (concat (substring s (match-beginning 1)) " "))
4283 (setq timestr 'time))
4284 (setq txt (org-format-agenda-item
4285 (if (= diff 0)
4286 (car org-agenda-deadline-leaders)
4287 (if (functionp
4288 (nth 1 org-agenda-deadline-leaders))
4289 (funcall
4290 (nth 1 org-agenda-deadline-leaders)
4291 diff date)
4292 (format (nth 1 org-agenda-deadline-leaders)
4293 diff)))
4294 head category tags
4295 (if (not (= diff 0)) nil timestr)))))
4296 (when txt
4297 (setq face (org-agenda-deadline-face dfrac wdays))
4298 (org-add-props txt props
4299 'org-marker (org-agenda-new-marker pos)
4300 'org-hd-marker (org-agenda-new-marker pos1)
4301 'priority (+ (- diff)
4302 (org-get-priority txt))
4303 'org-category category
4304 'todo-state todo-state
4305 'type (if upcomingp "upcoming-deadline" "deadline")
4306 'date (if upcomingp date d2)
4307 'face (if donep 'org-agenda-done face)
4308 'undone-face face 'done-face 'org-agenda-done)
4309 (push txt ee))))))
4310 (nreverse ee)))
4312 (defun org-agenda-deadline-face (fraction &optional wdays)
4313 "Return the face to displaying a deadline item.
4314 FRACTION is what fraction of the head-warning time has passed."
4315 (if (equal wdays 0) (setq fraction 1.))
4316 (let ((faces org-agenda-deadline-faces) f)
4317 (catch 'exit
4318 (while (setq f (pop faces))
4319 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
4321 (defun org-agenda-get-scheduled (&optional deadline-results)
4322 "Return the scheduled information for agenda display."
4323 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
4324 'org-todo-regexp org-todo-regexp
4325 'org-complex-heading-regexp org-complex-heading-regexp
4326 'done-face 'org-agenda-done
4327 'mouse-face 'highlight
4328 'keymap org-agenda-keymap
4329 'help-echo
4330 (format "mouse-2 or RET jump to org file %s"
4331 (abbreviate-file-name buffer-file-name))))
4332 (regexp org-scheduled-time-regexp)
4333 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4334 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4336 (deadline-position-alist
4337 (mapcar (lambda (a) (and (setq mm (get-text-property
4338 0 'org-hd-marker a))
4339 (cons (marker-position mm) a)))
4340 deadline-results))
4341 d2 diff pos pos1 category tags donep
4342 ee txt head pastschedp todo-state face timestr s habitp)
4343 (goto-char (point-min))
4344 (while (re-search-forward regexp nil t)
4345 (catch :skip
4346 (org-agenda-skip)
4347 (setq s (match-string 1)
4348 txt nil
4349 pos (1- (match-beginning 1))
4350 d2 (org-time-string-to-absolute
4351 (match-string 1) d1 'past
4352 org-agenda-repeating-timestamp-show-all)
4353 diff (- d2 d1))
4354 (setq pastschedp (and todayp (< diff 0)))
4355 ;; When to show a scheduled item in the calendar:
4356 ;; If it is on or past the date.
4357 (when (or (and (< diff 0)
4358 (< (abs diff) org-scheduled-past-days)
4359 (and todayp (not org-agenda-only-exact-dates)))
4360 (= diff 0))
4361 (save-excursion
4362 (setq todo-state (org-get-todo-state))
4363 (setq donep (member todo-state org-done-keywords))
4364 (setq habitp (and (functionp 'org-is-habit-p)
4365 (org-is-habit-p)))
4366 (if (and donep
4367 (or habitp org-agenda-skip-scheduled-if-done
4368 (not (= diff 0))))
4369 (setq txt nil)
4370 (setq category (org-get-category))
4371 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4372 (setq txt org-agenda-no-heading-message)
4373 (goto-char (match-end 0))
4374 (setq pos1 (match-beginning 0))
4375 (if habitp
4376 (if (or (not org-habit-show-habits)
4377 (and (not todayp)
4378 org-habit-show-habits-only-for-today))
4379 (throw :skip nil))
4380 (if (and
4381 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
4382 (and org-agenda-skip-scheduled-if-deadline-is-shown
4383 pastschedp))
4384 (setq mm (assoc pos1 deadline-position-alist)))
4385 (throw :skip nil)))
4386 (setq tags (org-get-tags-at))
4387 (setq head (buffer-substring-no-properties
4388 (point)
4389 (progn (skip-chars-forward "^\r\n") (point))))
4390 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4391 (setq timestr
4392 (concat (substring s (match-beginning 1)) " "))
4393 (setq timestr 'time))
4394 (setq txt (org-format-agenda-item
4395 (if (= diff 0)
4396 (car org-agenda-scheduled-leaders)
4397 (format (nth 1 org-agenda-scheduled-leaders)
4398 (- 1 diff)))
4399 head category tags
4400 (if (not (= diff 0)) nil timestr)
4401 nil nil habitp))))
4402 (when txt
4403 (setq face
4404 (cond
4405 ((and (not habitp) pastschedp)
4406 'org-scheduled-previously)
4407 (todayp 'org-scheduled-today)
4408 (t 'org-scheduled))
4409 habitp (and habitp (org-habit-parse-todo)))
4410 (org-add-props txt props
4411 'undone-face face
4412 'face (if donep 'org-agenda-done face)
4413 'org-marker (org-agenda-new-marker pos)
4414 'org-hd-marker (org-agenda-new-marker pos1)
4415 'type (if pastschedp "past-scheduled" "scheduled")
4416 'date (if pastschedp d2 date)
4417 'priority (if habitp
4418 (org-habit-get-priority habitp)
4419 (+ 94 (- 5 diff) (org-get-priority txt)))
4420 'org-category category
4421 'org-habit-p habitp
4422 'todo-state todo-state)
4423 (push txt ee))))))
4424 (nreverse ee)))
4426 (defun org-agenda-get-blocks ()
4427 "Return the date-range information for agenda display."
4428 (let* ((props (list 'face nil
4429 'org-not-done-regexp org-not-done-regexp
4430 'org-todo-regexp org-todo-regexp
4431 'org-complex-heading-regexp org-complex-heading-regexp
4432 'mouse-face 'highlight
4433 'keymap org-agenda-keymap
4434 'help-echo
4435 (format "mouse-2 or RET jump to org file %s"
4436 (abbreviate-file-name buffer-file-name))))
4437 (regexp org-tr-regexp)
4438 (d0 (calendar-absolute-from-gregorian date))
4439 marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
4440 head donep)
4441 (goto-char (point-min))
4442 (while (re-search-forward regexp nil t)
4443 (catch :skip
4444 (org-agenda-skip)
4445 (setq pos (point))
4446 (setq timestr (match-string 0)
4447 s1 (match-string 1)
4448 s2 (match-string 2)
4449 d1 (time-to-days (org-time-string-to-time s1))
4450 d2 (time-to-days (org-time-string-to-time s2)))
4451 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
4452 ;; Only allow days between the limits, because the normal
4453 ;; date stamps will catch the limits.
4454 (save-excursion
4455 (setq todo-state (org-get-todo-state))
4456 (setq donep (member todo-state org-done-keywords))
4457 (if (and donep org-agenda-skip-timestamp-if-done)
4458 (throw :skip t))
4459 (setq marker (org-agenda-new-marker (point)))
4460 (setq category (org-get-category))
4461 (if (not (re-search-backward "^\\*+ " nil t))
4462 (setq txt org-agenda-no-heading-message)
4463 (goto-char (match-beginning 0))
4464 (setq hdmarker (org-agenda-new-marker (point)))
4465 (setq tags (org-get-tags-at))
4466 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4467 (setq head (match-string 1))
4468 (setq txt (org-format-agenda-item
4469 (format
4470 (nth (if (= d1 d2) 0 1)
4471 org-agenda-timerange-leaders)
4472 (1+ (- d0 d1)) (1+ (- d2 d1)))
4473 head category tags
4474 (if (= d0 d1) timestr))))
4475 (org-add-props txt props
4476 'org-marker marker 'org-hd-marker hdmarker
4477 'type "block" 'date date
4478 'todo-state todo-state
4479 'priority (org-get-priority txt) 'org-category category)
4480 (push txt ee)))
4481 (goto-char pos)))
4482 ;; Sort the entries by expiration date.
4483 (nreverse ee)))
4485 ;;; Agenda presentation and sorting
4487 (defvar org-prefix-has-time nil
4488 "A flag, set by `org-compile-prefix-format'.
4489 The flag is set if the currently compiled format contains a `%t'.")
4490 (defvar org-prefix-has-tag nil
4491 "A flag, set by `org-compile-prefix-format'.
4492 The flag is set if the currently compiled format contains a `%T'.")
4493 (defvar org-prefix-has-effort nil
4494 "A flag, set by `org-compile-prefix-format'.
4495 The flag is set if the currently compiled format contains a `%e'.")
4496 (defvar org-prefix-category-length nil
4497 "Used by `org-compile-prefix-format' to remember the category field widh.")
4498 (defvar org-prefix-category-max-length nil
4499 "Used by `org-compile-prefix-format' to remember the category field widh.")
4501 (defun org-format-agenda-item (extra txt &optional category tags dotime
4502 noprefix remove-re habitp)
4503 "Format TXT to be inserted into the agenda buffer.
4504 In particular, it adds the prefix and corresponding text properties. EXTRA
4505 must be a string and replaces the `%s' specifier in the prefix format.
4506 CATEGORY (string, symbol or nil) may be used to overrule the default
4507 category taken from local variable or file name. It will replace the `%c'
4508 specifier in the format. DOTIME, when non-nil, indicates that a
4509 time-of-day should be extracted from TXT for sorting of this entry, and for
4510 the `%t' specifier in the format. When DOTIME is a string, this string is
4511 searched for a time before TXT is. NOPREFIX is a flag and indicates that
4512 only the correctly processes TXT should be returned - this is used by
4513 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
4514 Any match of REMOVE-RE will be removed from TXT."
4515 (save-match-data
4516 ;; Diary entries sometimes have extra whitespace at the beginning
4517 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
4518 (when org-agenda-show-inherited-tags
4519 ;; Fix the tags part in txt
4520 (setq txt (org-agenda-add-inherited-tags txt tags)))
4521 (let* ((category (or category
4522 org-category
4523 (if buffer-file-name
4524 (file-name-sans-extension
4525 (file-name-nondirectory buffer-file-name))
4526 "")))
4527 ;; time, tag, effort are needed for the eval of the prefix format
4528 (tag (if tags (nth (1- (length tags)) tags) ""))
4529 time effort neffort
4530 (ts (if dotime (concat
4531 (if (stringp dotime) dotime "")
4532 (and org-agenda-search-headline-for-time txt))))
4533 (time-of-day (and dotime (org-get-time-of-day ts)))
4534 stamp plain s0 s1 s2 t1 t2 rtn srp l
4535 duration thecategory)
4536 (and (org-mode-p) buffer-file-name
4537 (add-to-list 'org-agenda-contributing-files buffer-file-name))
4538 (when (and dotime time-of-day)
4539 ;; Extract starting and ending time and move them to prefix
4540 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
4541 (setq plain (string-match org-plain-time-of-day-regexp ts)))
4542 (setq s0 (match-string 0 ts)
4543 srp (and stamp (match-end 3))
4544 s1 (match-string (if plain 1 2) ts)
4545 s2 (match-string (if plain 8 (if srp 4 6)) ts))
4547 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
4548 ;; them, we might want to remove them there to avoid duplication.
4549 ;; The user can turn this off with a variable.
4550 (if (and org-prefix-has-time
4551 org-agenda-remove-times-when-in-prefix (or stamp plain)
4552 (string-match (concat (regexp-quote s0) " *") txt)
4553 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
4554 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
4555 (= (match-beginning 0) 0)
4557 (setq txt (replace-match "" nil nil txt))))
4558 ;; Normalize the time(s) to 24 hour
4559 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
4560 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
4561 ;; Compute the duration
4562 (when s1
4563 (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
4564 (string-to-number (substring s1 3)))
4565 t2 (cond
4566 (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
4567 (string-to-number (substring s2 3))))
4568 (org-agenda-default-appointment-duration
4569 (+ t1 org-agenda-default-appointment-duration))
4570 (t nil)))
4571 (setq duration (if t2 (- t2 t1)))))
4573 (when (and s1 (not s2) org-agenda-default-appointment-duration
4574 (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
4575 (let ((m (+ (string-to-number (match-string 2 s1))
4576 (* 60 (string-to-number (match-string 1 s1)))
4577 org-agenda-default-appointment-duration))
4579 (setq h (/ m 60) m (- m (* h 60)))
4580 (setq s2 (format "%02d:%02d" h m))))
4582 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
4583 txt)
4584 ;; Tags are in the string
4585 (if (or (eq org-agenda-remove-tags t)
4586 (and org-agenda-remove-tags
4587 org-prefix-has-tag))
4588 (setq txt (replace-match "" t t txt))
4589 (setq txt (replace-match
4590 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
4591 (match-string 2 txt))
4592 t t txt))))
4593 (when (org-mode-p)
4594 (setq effort
4595 (condition-case nil
4596 (org-get-effort
4597 (or (get-text-property 0 'org-hd-marker txt)
4598 (get-text-property 0 'org-marker txt)))
4599 (error nil)))
4600 (when effort
4601 (setq neffort (org-hh:mm-string-to-minutes effort)
4602 effort (setq effort (concat "[" effort "]" )))))
4604 (when remove-re
4605 (while (string-match remove-re txt)
4606 (setq txt (replace-match "" t t txt))))
4608 ;; Create the final string
4609 (if noprefix
4610 (setq rtn txt)
4611 ;; Prepare the variables needed in the eval of the compiled format
4612 (setq time (cond (s2 (concat s1 "-" s2))
4613 (s1 (concat s1 "......"))
4614 (t ""))
4615 extra (or (and (not habitp) extra) "")
4616 category (if (symbolp category) (symbol-name category) category)
4617 thecategory (copy-sequence category))
4618 (if (string-match org-bracket-link-regexp category)
4619 (progn
4620 (setq l (if (match-end 3)
4621 (- (match-end 3) (match-beginning 3))
4622 (- (match-end 1) (match-beginning 1))))
4623 (when (< l (or org-prefix-category-length 0))
4624 (setq category (copy-sequence category))
4625 (org-add-props category nil
4626 'extra-space (make-string
4627 (- org-prefix-category-length l 1) ?\ ))))
4628 (if (and org-prefix-category-max-length
4629 (>= (length category) org-prefix-category-max-length))
4630 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
4631 ;; Evaluate the compiled format
4632 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
4634 ;; And finally add the text properties
4635 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
4636 (org-add-props rtn nil
4637 'org-category (if thecategory (downcase thecategory) category)
4638 'tags (mapcar 'org-downcase-keep-props tags)
4639 'org-highest-priority org-highest-priority
4640 'org-lowest-priority org-lowest-priority
4641 'prefix-length (- (length rtn) (length txt))
4642 'time-of-day time-of-day
4643 'duration duration
4644 'effort effort
4645 'effort-minutes neffort
4646 'txt txt
4647 'time time
4648 'extra extra
4649 'dotime dotime))))
4651 (defun org-agenda-add-inherited-tags (txt tags)
4652 "Remove tags string from TXT, and add complete list of tags.
4653 The new list includes inherited tags. If any inherited tags are present,
4654 a double colon separates inherited tags from local tags."
4655 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
4656 (setq txt (substring txt 0 (match-beginning 0))))
4657 (when tags
4658 (let ((have-i (get-text-property 0 'inherited (car tags)))
4660 (setq txt (concat txt " :"
4661 (mapconcat
4662 (lambda (x)
4663 (setq i (get-text-property 0 'inherited x))
4664 (if (and have-i (not i))
4665 (progn
4666 (setq have-i nil)
4667 (concat ":" x))
4669 tags ":")
4670 (if have-i "::" ":")))))
4671 txt)
4673 (defun org-downcase-keep-props (s)
4674 (let ((props (text-properties-at 0 s)))
4675 (setq s (downcase s))
4676 (add-text-properties 0 (length s) props s)
4679 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
4680 (defvar org-agenda-sorting-strategy-selected nil)
4682 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
4683 (catch 'exit
4684 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
4685 ((and todayp (member 'today (car org-agenda-time-grid))))
4686 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
4687 ((member 'weekly (car org-agenda-time-grid)))
4688 (t (throw 'exit list)))
4689 (let* ((have (delq nil (mapcar
4690 (lambda (x) (get-text-property 1 'time-of-day x))
4691 list)))
4692 (string (nth 1 org-agenda-time-grid))
4693 (gridtimes (nth 2 org-agenda-time-grid))
4694 (req (car org-agenda-time-grid))
4695 (remove (member 'remove-match req))
4696 new time)
4697 (if (and (member 'require-timed req) (not have))
4698 ;; don't show empty grid
4699 (throw 'exit list))
4700 (while (setq time (pop gridtimes))
4701 (unless (and remove (member time have))
4702 (setq time (int-to-string time))
4703 (push (org-format-agenda-item
4704 nil string "" nil
4705 (concat (substring time 0 -2) ":" (substring time -2)))
4706 new)
4707 (put-text-property
4708 1 (length (car new)) 'face 'org-time-grid (car new))))
4709 (if (member 'time-up org-agenda-sorting-strategy-selected)
4710 (append new list)
4711 (append list new)))))
4713 (defun org-compile-prefix-format (key)
4714 "Compile the prefix format into a Lisp form that can be evaluated.
4715 The resulting form is returned and stored in the variable
4716 `org-prefix-format-compiled'."
4717 (setq org-prefix-has-time nil org-prefix-has-tag nil
4718 org-prefix-category-length nil org-prefix-has-effort nil)
4719 (let ((s (cond
4720 ((stringp org-agenda-prefix-format)
4721 org-agenda-prefix-format)
4722 ((assq key org-agenda-prefix-format)
4723 (cdr (assq key org-agenda-prefix-format)))
4724 (t " %-12:c%?-12t% s")))
4725 (start 0)
4726 varform vars var e c f opt)
4727 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
4728 s start)
4729 (setq var (cdr (assoc (match-string 4 s)
4730 '(("c" . category) ("t" . time) ("s" . extra)
4731 ("T" . tag) ("e" . effort))))
4732 c (or (match-string 3 s) "")
4733 opt (match-beginning 1)
4734 start (1+ (match-beginning 0)))
4735 (if (equal var 'time) (setq org-prefix-has-time t))
4736 (if (equal var 'tag) (setq org-prefix-has-tag t))
4737 (if (equal var 'effort) (setq org-prefix-has-effort t))
4738 (setq f (concat "%" (match-string 2 s) "s"))
4739 (when (equal var 'category)
4740 (setq org-prefix-category-length
4741 (floor (abs (string-to-number (match-string 2 s)))))
4742 (setq org-prefix-category-max-length
4743 (let ((x (match-string 2 s)))
4744 (save-match-data
4745 (if (string-match "\\.[0-9]+" x)
4746 (string-to-number (substring (match-string 0 x) 1)))))))
4747 (if opt
4748 (setq varform
4749 `(if (equal "" ,var)
4751 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
4752 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
4753 (setq s (replace-match "%s" t nil s))
4754 (push varform vars))
4755 (setq vars (nreverse vars))
4756 (setq org-prefix-format-compiled `(format ,s ,@vars))))
4758 (defun org-set-sorting-strategy (key)
4759 (if (symbolp (car org-agenda-sorting-strategy))
4760 ;; the old format
4761 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
4762 (setq org-agenda-sorting-strategy-selected
4763 (or (cdr (assq key org-agenda-sorting-strategy))
4764 (cdr (assq 'agenda org-agenda-sorting-strategy))
4765 '(time-up category-keep priority-down)))))
4767 (defun org-get-time-of-day (s &optional string mod24)
4768 "Check string S for a time of day.
4769 If found, return it as a military time number between 0 and 2400.
4770 If not found, return nil.
4771 The optional STRING argument forces conversion into a 5 character wide string
4772 HH:MM."
4773 (save-match-data
4774 (when
4775 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
4776 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
4777 (let* ((h (string-to-number (match-string 1 s)))
4778 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
4779 (ampm (if (match-end 4) (downcase (match-string 4 s))))
4780 (am-p (equal ampm "am"))
4781 (h1 (cond ((not ampm) h)
4782 ((= h 12) (if am-p 0 12))
4783 (t (+ h (if am-p 0 12)))))
4784 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
4785 (mod h1 24) h1))
4786 (t0 (+ (* 100 h2) m))
4787 (t1 (concat (if (>= h1 24) "+" " ")
4788 (if (< t0 100) "0" "")
4789 (if (< t0 10) "0" "")
4790 (int-to-string t0))))
4791 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
4793 (defun org-finalize-agenda-entries (list &optional nosort)
4794 "Sort and concatenate the agenda items."
4795 (setq list (mapcar 'org-agenda-highlight-todo list))
4796 (if nosort
4797 list
4798 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
4800 (defun org-agenda-highlight-todo (x)
4801 (let ((org-done-keywords org-done-keywords-for-agenda)
4802 re pl)
4803 (if (eq x 'line)
4804 (save-excursion
4805 (beginning-of-line 1)
4806 (setq re (org-get-at-bol 'org-todo-regexp))
4807 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
4808 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
4809 (add-text-properties (match-beginning 0) (match-end 1)
4810 (list 'face (org-get-todo-face 1)))
4811 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
4812 (delete-region (match-beginning 1) (1- (match-end 0)))
4813 (goto-char (match-beginning 1))
4814 (insert (format org-agenda-todo-keyword-format s)))))
4815 (setq re (concat (get-text-property 0 'org-todo-regexp x))
4816 pl (get-text-property 0 'prefix-length x))
4817 (when (and re
4818 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
4819 x (or pl 0)) pl))
4820 (add-text-properties
4821 (or (match-end 1) (match-end 0)) (match-end 0)
4822 (list 'face (org-get-todo-face (match-string 2 x)))
4824 (setq x (concat (substring x 0 (match-end 1))
4825 (format org-agenda-todo-keyword-format
4826 (match-string 2 x))
4827 (org-add-props " " (text-properties-at 0 x))
4828 (substring x (match-end 3)))))
4829 x)))
4831 (defsubst org-cmp-priority (a b)
4832 "Compare the priorities of string A and B."
4833 (let ((pa (or (get-text-property 1 'priority a) 0))
4834 (pb (or (get-text-property 1 'priority b) 0)))
4835 (cond ((> pa pb) +1)
4836 ((< pa pb) -1)
4837 (t nil))))
4839 (defsubst org-cmp-effort (a b)
4840 "Compare the priorities of string A and B."
4841 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
4842 (ea (or (get-text-property 1 'effort-minutes a) def))
4843 (eb (or (get-text-property 1 'effort-minutes b) def)))
4844 (cond ((> ea eb) +1)
4845 ((< ea eb) -1)
4846 (t nil))))
4848 (defsubst org-cmp-category (a b)
4849 "Compare the string values of categories of strings A and B."
4850 (let ((ca (or (get-text-property 1 'org-category a) ""))
4851 (cb (or (get-text-property 1 'org-category b) "")))
4852 (cond ((string-lessp ca cb) -1)
4853 ((string-lessp cb ca) +1)
4854 (t nil))))
4856 (defsubst org-cmp-todo-state (a b)
4857 "Compare the todo states of strings A and B."
4858 (let* ((ma (or (get-text-property 1 'org-marker a)
4859 (get-text-property 1 'org-hd-marker a)))
4860 (mb (or (get-text-property 1 'org-marker b)
4861 (get-text-property 1 'org-hd-marker b)))
4862 (fa (and ma (marker-buffer ma)))
4863 (fb (and mb (marker-buffer mb)))
4864 (todo-kwds
4865 (or (and fa (with-current-buffer fa org-todo-keywords-1))
4866 (and fb (with-current-buffer fb org-todo-keywords-1))))
4867 (ta (or (get-text-property 1 'todo-state a) ""))
4868 (tb (or (get-text-property 1 'todo-state b) ""))
4869 (la (- (length (member ta todo-kwds))))
4870 (lb (- (length (member tb todo-kwds))))
4871 (donepa (member ta org-done-keywords-for-agenda))
4872 (donepb (member tb org-done-keywords-for-agenda)))
4873 (cond ((and donepa (not donepb)) -1)
4874 ((and (not donepa) donepb) +1)
4875 ((< la lb) -1)
4876 ((< lb la) +1)
4877 (t nil))))
4879 (defsubst org-cmp-tag (a b)
4880 "Compare the string values of the first tags of A and B."
4881 (let ((ta (car (last (get-text-property 1 'tags a))))
4882 (tb (car (last (get-text-property 1 'tags b)))))
4883 (cond ((not ta) +1)
4884 ((not tb) -1)
4885 ((string-lessp ta tb) -1)
4886 ((string-lessp tb ta) +1)
4887 (t nil))))
4889 (defsubst org-cmp-time (a b)
4890 "Compare the time-of-day values of strings A and B."
4891 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
4892 (ta (or (get-text-property 1 'time-of-day a) def))
4893 (tb (or (get-text-property 1 'time-of-day b) def)))
4894 (cond ((< ta tb) -1)
4895 ((< tb ta) +1)
4896 (t nil))))
4898 (defsubst org-cmp-habit-p (a b)
4899 "Compare the todo states of strings A and B."
4900 (let ((ha (get-text-property 1 'org-habit-p a))
4901 (hb (get-text-property 1 'org-habit-p b)))
4902 (cond ((and ha (not hb)) -1)
4903 ((and (not ha) hb) +1)
4904 (t nil))))
4906 (defun org-entries-lessp (a b)
4907 "Predicate for sorting agenda entries."
4908 ;; The following variables will be used when the form is evaluated.
4909 ;; So even though the compiler complains, keep them.
4910 (let* ((time-up (org-cmp-time a b))
4911 (time-down (if time-up (- time-up) nil))
4912 (priority-up (org-cmp-priority a b))
4913 (priority-down (if priority-up (- priority-up) nil))
4914 (effort-up (org-cmp-effort a b))
4915 (effort-down (if effort-up (- effort-up) nil))
4916 (category-up (org-cmp-category a b))
4917 (category-down (if category-up (- category-up) nil))
4918 (category-keep (if category-up +1 nil))
4919 (tag-up (org-cmp-tag a b))
4920 (tag-down (if tag-up (- tag-up) nil))
4921 (todo-state-up (org-cmp-todo-state a b))
4922 (todo-state-down (if todo-state-up (- todo-state-up) nil))
4923 (habit-up (org-cmp-habit-p a b))
4924 (habit-down (if habit-up (- habit-up) nil))
4925 user-defined-up user-defined-down)
4926 (if (and org-agenda-cmp-user-defined
4927 (functionp org-agenda-cmp-user-defined))
4928 (setq user-defined-up
4929 (funcall org-agenda-cmp-user-defined a b)
4930 user-defined-down (if user-defined-up (- user-defined-up) nil)))
4931 (cdr (assoc
4932 (eval (cons 'or org-agenda-sorting-strategy-selected))
4933 '((-1 . t) (1 . nil) (nil . nil))))))
4935 ;;; Agenda restriction lock
4937 (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
4938 "Overlay to mark the headline to which arenda commands are restricted.")
4939 (org-overlay-put org-agenda-restriction-lock-overlay
4940 'face 'org-agenda-restriction-lock)
4941 (org-overlay-put org-agenda-restriction-lock-overlay
4942 'help-echo "Agendas are currently limited to this subtree.")
4943 (org-detach-overlay org-agenda-restriction-lock-overlay)
4945 (defun org-agenda-set-restriction-lock (&optional type)
4946 "Set restriction lock for agenda, to current subtree or file.
4947 Restriction will be the file if TYPE is `file', or if type is the
4948 universal prefix '(4), or if the cursor is before the first headline
4949 in the file. Otherwise, restriction will be to the current subtree."
4950 (interactive "P")
4951 (and (equal type '(4)) (setq type 'file))
4952 (setq type (cond
4953 (type type)
4954 ((org-at-heading-p) 'subtree)
4955 ((condition-case nil (org-back-to-heading t) (error nil))
4956 'subtree)
4957 (t 'file)))
4958 (if (eq type 'subtree)
4959 (progn
4960 (setq org-agenda-restrict t)
4961 (setq org-agenda-overriding-restriction 'subtree)
4962 (put 'org-agenda-files 'org-restrict
4963 (list (buffer-file-name (buffer-base-buffer))))
4964 (org-back-to-heading t)
4965 (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
4966 (move-marker org-agenda-restrict-begin (point))
4967 (move-marker org-agenda-restrict-end
4968 (save-excursion (org-end-of-subtree t)))
4969 (message "Locking agenda restriction to subtree"))
4970 (put 'org-agenda-files 'org-restrict
4971 (list (buffer-file-name (buffer-base-buffer))))
4972 (setq org-agenda-restrict nil)
4973 (setq org-agenda-overriding-restriction 'file)
4974 (move-marker org-agenda-restrict-begin nil)
4975 (move-marker org-agenda-restrict-end nil)
4976 (message "Locking agenda restriction to file"))
4977 (setq current-prefix-arg nil)
4978 (org-agenda-maybe-redo))
4980 (defun org-agenda-remove-restriction-lock (&optional noupdate)
4981 "Remove the agenda restriction lock."
4982 (interactive "P")
4983 (org-detach-overlay org-agenda-restriction-lock-overlay)
4984 (org-detach-overlay org-speedbar-restriction-lock-overlay)
4985 (setq org-agenda-overriding-restriction nil)
4986 (setq org-agenda-restrict nil)
4987 (put 'org-agenda-files 'org-restrict nil)
4988 (move-marker org-agenda-restrict-begin nil)
4989 (move-marker org-agenda-restrict-end nil)
4990 (setq current-prefix-arg nil)
4991 (message "Agenda restriction lock removed")
4992 (or noupdate (org-agenda-maybe-redo)))
4994 (defun org-agenda-maybe-redo ()
4995 "If there is any window showing the agenda view, update it."
4996 (let ((w (get-buffer-window org-agenda-buffer-name t))
4997 (w0 (selected-window)))
4998 (when w
4999 (select-window w)
5000 (org-agenda-redo)
5001 (select-window w0)
5002 (if org-agenda-overriding-restriction
5003 (message "Agenda view shifted to new %s restriction"
5004 org-agenda-overriding-restriction)
5005 (message "Agenda restriction lock removed")))))
5007 ;;; Agenda commands
5009 (defun org-agenda-check-type (error &rest types)
5010 "Check if agenda buffer is of allowed type.
5011 If ERROR is non-nil, throw an error, otherwise just return nil."
5012 (if (memq org-agenda-type types)
5014 (if error
5015 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5016 nil)))
5018 (defun org-agenda-quit ()
5019 "Exit agenda by removing the window or the buffer."
5020 (interactive)
5021 (if org-agenda-columns-active
5022 (org-columns-quit)
5023 (let ((buf (current-buffer)))
5024 (if (eq org-agenda-window-setup 'other-frame)
5025 (progn
5026 (kill-buffer buf)
5027 (org-agenda-reset-markers)
5028 (org-columns-remove-overlays)
5029 (setq org-agenda-archives-mode nil)
5030 (delete-frame))
5031 (and (not (eq org-agenda-window-setup 'current-window))
5032 (not (one-window-p))
5033 (delete-window))
5034 (kill-buffer buf)
5035 (org-agenda-reset-markers)
5036 (org-columns-remove-overlays)
5037 (setq org-agenda-archives-mode nil)))
5038 ;; Maybe restore the pre-agenda window configuration.
5039 (and org-agenda-restore-windows-after-quit
5040 (not (eq org-agenda-window-setup 'other-frame))
5041 org-pre-agenda-window-conf
5042 (set-window-configuration org-pre-agenda-window-conf))))
5044 (defun org-agenda-exit ()
5045 "Exit agenda by removing the window or the buffer.
5046 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5047 Org-mode buffers visited directly by the user will not be touched."
5048 (interactive)
5049 (org-release-buffers org-agenda-new-buffers)
5050 (setq org-agenda-new-buffers nil)
5051 (org-agenda-quit))
5053 (defun org-agenda-execute (arg)
5054 "Execute another agenda command, keeping same window.\\<global-map>
5055 So this is just a shortcut for `\\[org-agenda]', available in the agenda."
5056 (interactive "P")
5057 (let ((org-agenda-window-setup 'current-window))
5058 (org-agenda arg)))
5060 (defun org-agenda-redo ()
5061 "Rebuild Agenda.
5062 When this is the global TODO list, a prefix argument will be interpreted."
5063 (interactive)
5064 (let* ((org-agenda-keep-modes t)
5065 (filter org-agenda-filter)
5066 (preset (get 'org-agenda-filter :preset-filter))
5067 (cols org-agenda-columns-active)
5068 (line (org-current-line))
5069 (window-line (- line (org-current-line (window-start))))
5070 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5071 (put 'org-agenda-filter :preset-filter nil)
5072 (and cols (org-columns-quit))
5073 (message "Rebuilding agenda buffer...")
5074 (org-let lprops '(eval org-agenda-redo-command))
5075 (setq org-agenda-undo-list nil
5076 org-agenda-pending-undo-list nil)
5077 (message "Rebuilding agenda buffer...done")
5078 (put 'org-agenda-filter :preset-filter preset)
5079 (and (or filter preset) (org-agenda-filter-apply filter))
5080 (and cols (interactive-p) (org-agenda-columns))
5081 (org-goto-line line)
5082 (recenter window-line)))
5085 (defvar org-global-tags-completion-table nil)
5086 (defvar org-agenda-filter-form nil)
5087 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5088 "Keep only those lines in the agenda buffer that have a specific tag.
5089 The tag is selected with its fast selection letter, as configured.
5090 With prefix argument STRIP, remove all lines that do have the tag.
5091 A lisp caller can specify CHAR. NARROW means that the new tag should be
5092 used to narrow the search - the interactive user can also press `-' or `+'
5093 to switch to narrowing."
5094 (interactive "P")
5095 (let* ((alist org-tag-alist-for-agenda)
5096 (tag-chars (mapconcat
5097 (lambda (x) (if (cdr x) (char-to-string (cdr x)) ""))
5098 alist ""))
5099 (efforts (org-split-string
5100 (or (cdr (assoc (concat org-effort-property "_ALL")
5101 org-global-properties))
5102 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5103 (effort-op org-agenda-filter-effort-default-operator)
5104 (effort-prompt "")
5105 (inhibit-read-only t)
5106 (current org-agenda-filter)
5107 char a n tag)
5108 (unless char
5109 (message
5110 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5111 (if narrow "Narrow" "Filter") tag-chars
5112 (if org-agenda-auto-exclude-function "[RET], " ""))
5113 (setq char (read-char)))
5114 (when (member char '(?+ ?-))
5115 ;; Narrowing down
5116 (cond ((equal char ?-) (setq strip t narrow t))
5117 ((equal char ?+) (setq strip nil narrow t)))
5118 (message
5119 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5120 (setq char (read-char)))
5121 (when (member char '(?< ?> ?= ??))
5122 ;; An effort operator
5123 (setq effort-op (char-to-string char))
5124 (setq alist nil) ; to make sure it will be interpreted as effort.
5125 (unless (equal char ??)
5126 (loop for i from 0 to 9 do
5127 (setq effort-prompt
5128 (concat
5129 effort-prompt " ["
5130 (if (= i 9) "0" (int-to-string (1+ i)))
5131 "]" (nth i efforts))))
5132 (message "Effort%s: %s " effort-op effort-prompt)
5133 (setq char (read-char))
5134 (when (or (< char ?0) (> char ?9))
5135 (error "Need 1-9,0 to select effort" ))))
5136 (when (equal char ?\t)
5137 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5138 (org-set-local 'org-global-tags-completion-table
5139 (org-global-tags-completion-table)))
5140 (let ((completion-ignore-case t))
5141 (setq tag (org-icompleting-read
5142 "Tag: " org-global-tags-completion-table))))
5143 (cond
5144 ((equal char ?\r)
5145 (org-agenda-filter-by-tag-show-all)
5146 (when org-agenda-auto-exclude-function
5147 (setq org-agenda-filter '())
5148 (dolist (tag org-tag-alist-for-agenda)
5149 (let ((modifier (funcall org-agenda-auto-exclude-function
5150 (car tag))))
5151 (if modifier
5152 (push modifier org-agenda-filter))))
5153 (if (not (null org-agenda-filter))
5154 (org-agenda-filter-apply org-agenda-filter))))
5155 ((equal char ?/)
5156 (org-agenda-filter-by-tag-show-all)
5157 (when (get 'org-agenda-filter :preset-filter)
5158 (org-agenda-filter-apply org-agenda-filter)))
5159 ((or (equal char ?\ )
5160 (setq a (rassoc char alist))
5161 (and (>= char ?0) (<= char ?9)
5162 (setq n (if (= char ?0) 9 (- char ?0 1))
5163 tag (concat effort-op (nth n efforts))
5164 a (cons tag nil)))
5165 (and (= char ??)
5166 (setq tag "?eff")
5167 a (cons tag nil))
5168 (and tag (setq a (cons tag nil))))
5169 (org-agenda-filter-by-tag-show-all)
5170 (setq tag (car a))
5171 (setq org-agenda-filter
5172 (cons (concat (if strip "-" "+") tag)
5173 (if narrow current nil)))
5174 (org-agenda-filter-apply org-agenda-filter))
5175 (t (error "Invalid tag selection character %c" char)))))
5177 (defun org-agenda-filter-by-tag-refine (strip &optional char)
5178 "Refine the current filter. See `org-agenda-filter-by-tag."
5179 (interactive "P")
5180 (org-agenda-filter-by-tag strip char 'refine))
5182 (defun org-agenda-filter-make-matcher ()
5183 "Create the form that tests a line for the agenda filter."
5184 (let (f f1)
5185 (dolist (x (append (get 'org-agenda-filter :preset-filter)
5186 org-agenda-filter))
5187 (if (member x '("-" "+"))
5188 (setq f1 (if (equal x "-") 'tags '(not tags)))
5189 (if (string-match "[<=>?]" x)
5190 (setq f1 (org-agenda-filter-effort-form x))
5191 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
5192 (if (equal (string-to-char x) ?-)
5193 (setq f1 (list 'not f1))))
5194 (push f1 f))
5195 (cons 'and (nreverse f))))
5197 (defun org-agenda-filter-effort-form (e)
5198 "Return the form to compare the effort of the current line with what E says.
5199 E looks line \"+<2:25\"."
5200 (let (op)
5201 (setq e (substring e 1))
5202 (setq op (string-to-char e) e (substring e 1))
5203 (setq op (cond ((equal op ?<) '<=)
5204 ((equal op ?>) '>=)
5205 ((equal op ??) op)
5206 (t '=)))
5207 (list 'org-agenda-compare-effort (list 'quote op)
5208 (org-hh:mm-string-to-minutes e))))
5210 (defun org-agenda-compare-effort (op value)
5211 "Compare the effort of the current line with VALUE, using OP.
5212 If the line does not have an effort defined, return nil."
5213 (let ((eff (org-get-at-bol 'effort-minutes)))
5214 (if (equal op ??)
5215 (not eff)
5216 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
5217 value))))
5219 (defun org-agenda-filter-apply (filter)
5220 "Set FILTER as the new agenda filter and apply it."
5221 (let (tags)
5222 (setq org-agenda-filter filter
5223 org-agenda-filter-form (org-agenda-filter-make-matcher))
5224 (org-agenda-set-mode-name)
5225 (save-excursion
5226 (goto-char (point-min))
5227 (while (not (eobp))
5228 (if (org-get-at-bol 'org-marker)
5229 (progn
5230 (setq tags (org-get-at-bol 'tags)) ; used in eval
5231 (if (not (eval org-agenda-filter-form))
5232 (org-agenda-filter-by-tag-hide-line))
5233 (beginning-of-line 2))
5234 (beginning-of-line 2))))))
5236 (defun org-agenda-filter-by-tag-hide-line ()
5237 (let (ov)
5238 (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
5239 (point-at-eol)))
5240 (org-overlay-put ov 'invisible t)
5241 (org-overlay-put ov 'type 'tags-filter)
5242 (push ov org-agenda-filter-overlays)))
5244 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
5245 (setq pos (or pos (point)))
5246 (save-excursion
5247 (dolist (ov (org-overlays-at pos))
5248 (when (and (org-overlay-get ov 'invisible)
5249 (eq (org-overlay-get ov 'type) 'tags-filter))
5250 (goto-char pos)
5251 (if (< (org-overlay-start ov) (point-at-eol))
5252 (org-move-overlay ov (point-at-eol)
5253 (org-overlay-end ov)))))))
5255 (defun org-agenda-filter-by-tag-show-all ()
5256 (mapc 'org-delete-overlay org-agenda-filter-overlays)
5257 (setq org-agenda-filter-overlays nil)
5258 (setq org-agenda-filter nil)
5259 (setq org-agenda-filter-form nil)
5260 (org-agenda-set-mode-name))
5262 (defun org-agenda-manipulate-query-add ()
5263 "Manipulate the query by adding a search term with positive selection.
5264 Positive selection means, the term must be matched for selection of an entry."
5265 (interactive)
5266 (org-agenda-manipulate-query ?\[))
5267 (defun org-agenda-manipulate-query-subtract ()
5268 "Manipulate the query by adding a search term with negative selection.
5269 Negative selection means, term must not be matched for selection of an entry."
5270 (interactive)
5271 (org-agenda-manipulate-query ?\]))
5272 (defun org-agenda-manipulate-query-add-re ()
5273 "Manipulate the query by adding a search regexp with positive selection.
5274 Positive selection means, the regexp must match for selection of an entry."
5275 (interactive)
5276 (org-agenda-manipulate-query ?\{))
5277 (defun org-agenda-manipulate-query-subtract-re ()
5278 "Manipulate the query by adding a search regexp with negative selection.
5279 Negative selection means, regexp must not match for selection of an entry."
5280 (interactive)
5281 (org-agenda-manipulate-query ?\}))
5282 (defun org-agenda-manipulate-query (char)
5283 (cond
5284 ((memq org-agenda-type '(timeline agenda))
5285 (let ((org-agenda-include-inactive-timestamps t))
5286 (org-agenda-redo))
5287 (message "Display now includes inactive timestamps as well"))
5288 ((eq org-agenda-type 'search)
5289 (org-add-to-string
5290 'org-agenda-query-string
5291 (cdr (assoc char '((?\[ . " +") (?\] . " -")
5292 (?\{ . " +{}") (?\} . " -{}")))))
5293 (setq org-agenda-redo-command
5294 (list 'org-search-view
5295 org-todo-only
5296 org-agenda-query-string
5297 (+ (length org-agenda-query-string)
5298 (if (member char '(?\{ ?\})) 0 1))))
5299 (set-register org-agenda-query-register org-agenda-query-string)
5300 (org-agenda-redo))
5301 (t (error "Cannot manipulate query for %s-type agenda buffers"
5302 org-agenda-type))))
5304 (defun org-add-to-string (var string)
5305 (set var (concat (symbol-value var) string)))
5307 (defun org-agenda-goto-date (date)
5308 "Jump to DATE in agenda."
5309 (interactive (list (org-read-date)))
5310 (org-agenda-list nil date))
5312 (defun org-agenda-goto-today ()
5313 "Go to today."
5314 (interactive)
5315 (org-agenda-check-type t 'timeline 'agenda)
5316 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
5317 (cond
5318 (tdpos (goto-char tdpos))
5319 ((eq org-agenda-type 'agenda)
5320 (let* ((sd (time-to-days
5321 (time-subtract (current-time)
5322 (list 0 (* 3600 org-extend-today-until) 0))))
5323 (comp (org-agenda-compute-time-span sd org-agenda-span))
5324 (org-agenda-overriding-arguments org-agenda-last-arguments))
5325 (setf (nth 1 org-agenda-overriding-arguments) (car comp))
5326 (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
5327 (org-agenda-redo)
5328 (org-agenda-find-same-or-today-or-agenda)))
5329 (t (error "Cannot find today")))))
5331 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
5332 (goto-char
5333 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
5334 (text-property-any (point-min) (point-max) 'org-today t)
5335 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
5336 (point-min))))
5338 (defun org-agenda-later (arg)
5339 "Go forward in time by thee current span.
5340 With prefix ARG, go forward that many times the current span."
5341 (interactive "p")
5342 (org-agenda-check-type t 'agenda)
5343 (let* ((span org-agenda-span)
5344 (sd org-starting-day)
5345 (greg (calendar-gregorian-from-absolute sd))
5346 (cnt (org-get-at-bol 'org-day-cnt))
5347 greg2 nd)
5348 (cond
5349 ((eq span 'day)
5350 (setq sd (+ arg sd) nd 1))
5351 ((eq span 'week)
5352 (setq sd (+ (* 7 arg) sd) nd 7))
5353 ((eq span 'month)
5354 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
5355 sd (calendar-absolute-from-gregorian greg2))
5356 (setcar greg2 (1+ (car greg2)))
5357 (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
5358 ((eq span 'year)
5359 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
5360 sd (calendar-absolute-from-gregorian greg2))
5361 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
5362 (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
5363 (let ((org-agenda-overriding-arguments
5364 (list (car org-agenda-last-arguments) sd nd t)))
5365 (org-agenda-redo)
5366 (org-agenda-find-same-or-today-or-agenda cnt))))
5368 (defun org-agenda-earlier (arg)
5369 "Go backward in time by the current span.
5370 With prefix ARG, go backward that many times the current span."
5371 (interactive "p")
5372 (org-agenda-later (- arg)))
5374 (defun org-agenda-view-mode-dispatch ()
5375 "Call one of the view mode commands."
5376 (interactive)
5377 (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
5378 clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
5379 (let ((a (read-char-exclusive)))
5380 (case a
5381 (?d (call-interactively 'org-agenda-day-view))
5382 (?w (call-interactively 'org-agenda-week-view))
5383 (?m (call-interactively 'org-agenda-month-view))
5384 (?y (call-interactively 'org-agenda-year-view))
5385 (?l (call-interactively 'org-agenda-log-mode))
5386 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
5387 (?a (call-interactively 'org-agenda-archives-mode))
5388 (?A (org-agenda-archives-mode 'files))
5389 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
5390 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
5391 (?G (call-interactively 'org-agenda-toggle-time-grid))
5392 (?D (call-interactively 'org-agenda-toggle-diary))
5393 (?\[ (let ((org-agenda-include-inactive-timestamps t))
5394 (org-agenda-check-type t 'timeline 'agenda)
5395 (org-agenda-redo))
5396 (message "Display now includes inactive timestamps as well"))
5397 (?q (message "Abort"))
5398 (otherwise (error "Invalid key" )))))
5400 (defun org-agenda-day-view (&optional day-of-year)
5401 "Switch to daily view for agenda.
5402 With argument DAY-OF-YEAR, switch to that day of the year."
5403 (interactive "P")
5404 (setq org-agenda-ndays 1)
5405 (org-agenda-change-time-span 'day day-of-year))
5406 (defun org-agenda-week-view (&optional iso-week)
5407 "Switch to daily view for agenda.
5408 With argument ISO-WEEK, switch to the corresponding ISO week.
5409 If ISO-WEEK has more then 2 digits, only the last two encode the
5410 week. Any digits before this encode a year. So 200712 means
5411 week 12 of year 2007. Years in the range 1938-2037 can also be
5412 written as 2-digit years."
5413 (interactive "P")
5414 (setq org-agenda-ndays 7)
5415 (org-agenda-change-time-span 'week iso-week))
5416 (defun org-agenda-month-view (&optional month)
5417 "Switch to monthly view for agenda.
5418 With argument MONTH, switch to that month."
5419 (interactive "P")
5420 (org-agenda-change-time-span 'month month))
5421 (defun org-agenda-year-view (&optional year)
5422 "Switch to yearly view for agenda.
5423 With argument YEAR, switch to that year.
5424 If MONTH has more then 2 digits, only the last two encode the
5425 month. Any digits before this encode a year. So 200712 means
5426 December year 2007. Years in the range 1938-2037 can also be
5427 written as 2-digit years."
5428 (interactive "P")
5429 (when year
5430 (setq year (org-small-year-to-year year)))
5431 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
5432 (org-agenda-change-time-span 'year year)
5433 (error "Abort")))
5435 (defun org-agenda-change-time-span (span &optional n)
5436 "Change the agenda view to SPAN.
5437 SPAN may be `day', `week', `month', `year'."
5438 (org-agenda-check-type t 'agenda)
5439 (if (and (not n) (equal org-agenda-span span))
5440 (error "Viewing span is already \"%s\"" span))
5441 (let* ((sd (or (org-get-at-bol 'day)
5442 org-starting-day))
5443 (computed (org-agenda-compute-time-span sd span n))
5444 (org-agenda-overriding-arguments
5445 (list (car org-agenda-last-arguments)
5446 (car computed) (cdr computed) t)))
5447 (org-agenda-redo)
5448 (org-agenda-find-same-or-today-or-agenda))
5449 (org-agenda-set-mode-name)
5450 (message "Switched to %s view" span))
5452 (defun org-agenda-compute-time-span (sd span &optional n)
5453 "Compute starting date and number of days for agenda.
5454 SPAN may be `day', `week', `month', `year'. The return value
5455 is a cons cell with the starting date and the number of days,
5456 so that the date SD will be in that range."
5457 (let* ((greg (calendar-gregorian-from-absolute sd))
5458 (dg (nth 1 greg))
5459 (mg (car greg))
5460 (yg (nth 2 greg))
5461 nd w1 y1 m1 thisweek)
5462 (cond
5463 ((eq span 'day)
5464 (when n
5465 (setq sd (+ (calendar-absolute-from-gregorian
5466 (list mg 1 yg))
5467 n -1)))
5468 (setq nd 1))
5469 ((eq span 'week)
5470 (let* ((nt (calendar-day-of-week
5471 (calendar-gregorian-from-absolute sd)))
5472 (d (if org-agenda-start-on-weekday
5473 (- nt org-agenda-start-on-weekday)
5474 0)))
5475 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
5476 (when n
5477 (require 'cal-iso)
5478 (setq thisweek (car (calendar-iso-from-absolute sd)))
5479 (when (> n 99)
5480 (setq y1 (org-small-year-to-year (/ n 100))
5481 n (mod n 100)))
5482 (setq sd
5483 (calendar-absolute-from-iso
5484 (list n 1
5485 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
5486 (setq nd 7)))
5487 ((eq span 'month)
5488 (when (and n (> n 99))
5489 (setq y1 (org-small-year-to-year (/ n 100))
5490 n (mod n 100)))
5491 (setq sd (calendar-absolute-from-gregorian
5492 (list (or n mg) 1 (or y1 yg)))
5493 nd (- (calendar-absolute-from-gregorian
5494 (list (1+ (or n mg)) 1 (or y1 yg)))
5495 sd)))
5496 ((eq span 'year)
5497 (setq sd (calendar-absolute-from-gregorian
5498 (list 1 1 (or n yg)))
5499 nd (- (calendar-absolute-from-gregorian
5500 (list 1 1 (1+ (or n yg))))
5501 sd))))
5502 (cons sd nd)))
5504 (defun org-agenda-next-date-line (&optional arg)
5505 "Jump to the next line indicating a date in agenda buffer."
5506 (interactive "p")
5507 (org-agenda-check-type t 'agenda 'timeline)
5508 (beginning-of-line 1)
5509 ;; This does not work if user makes date format that starts with a blank
5510 (if (looking-at "^\\S-") (forward-char 1))
5511 (if (not (re-search-forward "^\\S-" nil t arg))
5512 (progn
5513 (backward-char 1)
5514 (error "No next date after this line in this buffer")))
5515 (goto-char (match-beginning 0)))
5517 (defun org-agenda-previous-date-line (&optional arg)
5518 "Jump to the previous line indicating a date in agenda buffer."
5519 (interactive "p")
5520 (org-agenda-check-type t 'agenda 'timeline)
5521 (beginning-of-line 1)
5522 (if (not (re-search-backward "^\\S-" nil t arg))
5523 (error "No previous date before this line in this buffer")))
5525 ;; Initialize the highlight
5526 (defvar org-hl (org-make-overlay 1 1))
5527 (org-overlay-put org-hl 'face 'highlight)
5529 (defun org-highlight (begin end &optional buffer)
5530 "Highlight a region with overlay."
5531 (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
5532 org-hl begin end (or buffer (current-buffer))))
5534 (defun org-unhighlight ()
5535 "Detach overlay INDEX."
5536 (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
5538 ;; FIXME this is currently not used.
5539 (defun org-highlight-until-next-command (beg end &optional buffer)
5540 "Move the highlight overlay to BEG/END, remove it before the next command."
5541 (org-highlight beg end buffer)
5542 (add-hook 'pre-command-hook 'org-unhighlight-once))
5543 (defun org-unhighlight-once ()
5544 "Remove the highlight from its position, and this function from the hook."
5545 (remove-hook 'pre-command-hook 'org-unhighlight-once)
5546 (org-unhighlight))
5548 (defun org-agenda-follow-mode ()
5549 "Toggle follow mode in an agenda buffer."
5550 (interactive)
5551 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
5552 (org-agenda-set-mode-name)
5553 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5554 (org-agenda-show))
5555 (message "Follow mode is %s"
5556 (if org-agenda-follow-mode "on" "off")))
5558 (defun org-agenda-entry-text-mode (&optional arg)
5559 "Toggle entry text mode in an agenda buffer."
5560 (interactive "P")
5561 (if (integerp arg)
5562 (setq org-agenda-entry-text-mode t)
5563 (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
5564 (org-agenda-entry-text-hide)
5565 (and org-agenda-entry-text-mode
5566 (let ((org-agenda-entry-text-maxlines
5567 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5568 (org-agenda-entry-text-show)))
5569 (org-agenda-set-mode-name)
5570 (message "Entry text mode is %s. Maximum number of lines is %d"
5571 (if org-agenda-entry-text-mode "on" "off")
5572 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
5574 (defun org-agenda-clockreport-mode ()
5575 "Toggle clocktable mode in an agenda buffer."
5576 (interactive)
5577 (org-agenda-check-type t 'agenda)
5578 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
5579 (org-agenda-set-mode-name)
5580 (org-agenda-redo)
5581 (message "Clocktable mode is %s"
5582 (if org-agenda-clockreport-mode "on" "off")))
5584 (defun org-agenda-log-mode (&optional special)
5585 "Toggle log mode in an agenda buffer.
5586 With argument SPECIAL, show all possible log items, not only the ones
5587 configured in `org-agenda-log-mode-items'.
5588 With a double `C-u' prefix arg, show *only* log items, nothing else."
5589 (interactive "P")
5590 (org-agenda-check-type t 'agenda 'timeline)
5591 (setq org-agenda-show-log
5592 (if (equal special '(16))
5593 'only
5594 (if special '(closed clock state)
5595 (not org-agenda-show-log))))
5596 (org-agenda-set-mode-name)
5597 (org-agenda-redo)
5598 (message "Log mode is %s"
5599 (if org-agenda-show-log "on" "off")))
5601 (defun org-agenda-archives-mode (&optional with-files)
5602 "Toggle inclusion of items in trees marked with :ARCHIVE:.
5603 When called with a prefix argument, include all archive files as well."
5604 (interactive "P")
5605 (setq org-agenda-archives-mode
5606 (if with-files t (if org-agenda-archives-mode nil 'trees)))
5607 (org-agenda-set-mode-name)
5608 (org-agenda-redo)
5609 (message
5610 "%s"
5611 (cond
5612 ((eq org-agenda-archives-mode nil)
5613 "No archives are included")
5614 ((eq org-agenda-archives-mode 'trees)
5615 (format "Trees with :%s: tag are included" org-archive-tag))
5616 ((eq org-agenda-archives-mode t)
5617 (format "Trees with :%s: tag and all active archive files are included"
5618 org-archive-tag)))))
5620 (defun org-agenda-toggle-diary ()
5621 "Toggle diary inclusion in an agenda buffer."
5622 (interactive)
5623 (org-agenda-check-type t 'agenda)
5624 (setq org-agenda-include-diary (not org-agenda-include-diary))
5625 (org-agenda-redo)
5626 (org-agenda-set-mode-name)
5627 (message "Diary inclusion turned %s"
5628 (if org-agenda-include-diary "on" "off")))
5630 (defun org-agenda-toggle-time-grid ()
5631 "Toggle time grid in an agenda buffer."
5632 (interactive)
5633 (org-agenda-check-type t 'agenda)
5634 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
5635 (org-agenda-redo)
5636 (org-agenda-set-mode-name)
5637 (message "Time-grid turned %s"
5638 (if org-agenda-use-time-grid "on" "off")))
5640 (defun org-agenda-set-mode-name ()
5641 "Set the mode name to indicate all the small mode settings."
5642 (setq mode-name
5643 (concat "Org-Agenda"
5644 (if (equal org-agenda-ndays 1) " Day" "")
5645 (if (equal org-agenda-ndays 7) " Week" "")
5646 (if org-agenda-follow-mode " Follow" "")
5647 (if org-agenda-entry-text-mode " ETxt" "")
5648 (if org-agenda-include-diary " Diary" "")
5649 (if org-agenda-use-time-grid " Grid" "")
5650 (if (and (boundp 'org-habit-show-habits)
5651 org-habit-show-habits) " Habit" "")
5652 (if (consp org-agenda-show-log) " LogAll"
5653 (if org-agenda-show-log " Log" ""))
5654 (if (or org-agenda-filter (get 'org-agenda-filter
5655 :preset-filter))
5656 (concat " {" (mapconcat
5657 'identity
5658 (append (get 'org-agenda-filter
5659 :preset-filter)
5660 org-agenda-filter) "") "}")
5662 (if org-agenda-archives-mode
5663 (if (eq org-agenda-archives-mode t)
5664 " Archives"
5665 (format " :%s:" org-archive-tag))
5667 (if org-agenda-clockreport-mode " Clock" "")))
5668 (force-mode-line-update))
5670 (defun org-agenda-post-command-hook ()
5671 (setq org-agenda-type
5672 (or (get-text-property (point) 'org-agenda-type)
5673 (get-text-property (max (point-min) (1- (point)))
5674 'org-agenda-type))))
5676 (defun org-agenda-next-line ()
5677 "Move cursor to the next line, and show if follow-mode is active."
5678 (interactive)
5679 (call-interactively 'next-line)
5680 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5681 (org-agenda-show)))
5682 (defun org-agenda-previous-line ()
5683 "Move cursor to the previous line, and show if follow-mode is active."
5685 (interactive)
5686 (call-interactively 'previous-line)
5687 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
5688 (org-agenda-show)))
5690 (defun org-agenda-show-priority ()
5691 "Show the priority of the current item.
5692 This priority is composed of the main priority given with the [#A] cookies,
5693 and by additional input from the age of a schedules or deadline entry."
5694 (interactive)
5695 (let* ((pri (org-get-at-bol 'priority)))
5696 (message "Priority is %d" (if pri pri -1000))))
5698 (defun org-agenda-show-tags ()
5699 "Show the tags applicable to the current item."
5700 (interactive)
5701 (let* ((tags (org-get-at-bol 'tags)))
5702 (if tags
5703 (message "Tags are :%s:"
5704 (org-no-properties (mapconcat 'identity tags ":")))
5705 (message "No tags associated with this line"))))
5707 (defun org-agenda-goto (&optional highlight)
5708 "Go to the Org-mode file which contains the item at point."
5709 (interactive)
5710 (let* ((marker (or (org-get-at-bol 'org-marker)
5711 (org-agenda-error)))
5712 (buffer (marker-buffer marker))
5713 (pos (marker-position marker)))
5714 (switch-to-buffer-other-window buffer)
5715 (widen)
5716 (goto-char pos)
5717 (when (org-mode-p)
5718 (org-show-context 'agenda)
5719 (save-excursion
5720 (and (outline-next-heading)
5721 (org-flag-heading nil)))) ; show the next heading
5722 (recenter (/ (window-height) 2))
5723 (run-hooks 'org-agenda-after-show-hook)
5724 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
5726 (defvar org-agenda-after-show-hook nil
5727 "Normal hook run after an item has been shown from the agenda.
5728 Point is in the buffer where the item originated.")
5730 (defun org-agenda-kill ()
5731 "Kill the entry or subtree belonging to the current agenda entry."
5732 (interactive)
5733 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5734 (let* ((marker (or (org-get-at-bol 'org-marker)
5735 (org-agenda-error)))
5736 (buffer (marker-buffer marker))
5737 (pos (marker-position marker))
5738 (type (org-get-at-bol 'type))
5739 dbeg dend (n 0) conf)
5740 (org-with-remote-undo buffer
5741 (with-current-buffer buffer
5742 (save-excursion
5743 (goto-char pos)
5744 (if (and (org-mode-p) (not (member type '("sexp"))))
5745 (setq dbeg (progn (org-back-to-heading t) (point))
5746 dend (org-end-of-subtree t t))
5747 (setq dbeg (point-at-bol)
5748 dend (min (point-max) (1+ (point-at-eol)))))
5749 (goto-char dbeg)
5750 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
5751 (setq conf (or (eq t org-agenda-confirm-kill)
5752 (and (numberp org-agenda-confirm-kill)
5753 (> n org-agenda-confirm-kill))))
5754 (and conf
5755 (not (y-or-n-p
5756 (format "Delete entry with %d lines in buffer \"%s\"? "
5757 n (buffer-name buffer))))
5758 (error "Abort"))
5759 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
5760 (with-current-buffer buffer (delete-region dbeg dend))
5761 (message "Agenda item and source killed"))))
5763 (defun org-agenda-archive-default ()
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))
5769 (defun org-agenda-archive-default-with-confirmation ()
5770 "Archive the entry or subtree belonging to the current agenda entry."
5771 (interactive)
5772 (require 'org-archive)
5773 (org-agenda-archive-with org-archive-default-command 'confirm))
5775 (defun org-agenda-archive ()
5776 "Archive the entry or subtree belonging to the current agenda entry."
5777 (interactive)
5778 (org-agenda-archive-with 'org-archive-subtree))
5780 (defun org-agenda-archive-to-archive-sibling ()
5781 "Move the entry to the archive sibling."
5782 (interactive)
5783 (org-agenda-archive-with 'org-archive-to-archive-sibling))
5785 (defun org-agenda-archive-with (cmd &optional confirm)
5786 "Move the entry to the archive sibling."
5787 (interactive)
5788 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
5789 (let* ((marker (or (org-get-at-bol 'org-marker)
5790 (org-agenda-error)))
5791 (buffer (marker-buffer marker))
5792 (pos (marker-position marker)))
5793 (org-with-remote-undo buffer
5794 (with-current-buffer buffer
5795 (if (org-mode-p)
5796 (if (and confirm
5797 (not (y-or-n-p "Archive this subtree or entry? ")))
5798 (error "Abort")
5799 (save-excursion
5800 (goto-char pos)
5801 (org-remove-subtree-entries-from-agenda)
5802 (org-back-to-heading t)
5803 (funcall cmd)))
5804 (error "Archiving works only in Org-mode files"))))))
5806 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
5807 "Remove all lines in the agenda that correspond to a given subtree.
5808 The subtree is the one in buffer BUF, starting at BEG and ending at END.
5809 If this information is not given, the function uses the tree at point."
5810 (let ((buf (or buf (current-buffer))) m p)
5811 (save-excursion
5812 (unless (and beg end)
5813 (org-back-to-heading t)
5814 (setq beg (point))
5815 (org-end-of-subtree t)
5816 (setq end (point)))
5817 (set-buffer (get-buffer org-agenda-buffer-name))
5818 (save-excursion
5819 (goto-char (point-max))
5820 (beginning-of-line 1)
5821 (while (not (bobp))
5822 (when (and (setq m (org-get-at-bol 'org-marker))
5823 (equal buf (marker-buffer m))
5824 (setq p (marker-position m))
5825 (>= p beg)
5826 (< p end))
5827 (let ((inhibit-read-only t))
5828 (delete-region (point-at-bol) (1+ (point-at-eol)))))
5829 (beginning-of-line 0))))))
5831 (defun org-agenda-refile (&optional goto rfloc)
5832 "Refile the item at point."
5833 (interactive "P")
5834 (if (equal goto '(16))
5835 (org-refile-goto-last-stored)
5836 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5837 (org-agenda-error)))
5838 (buffer (marker-buffer marker))
5839 (pos (marker-position marker))
5840 (rfloc (or rfloc
5841 (org-refile-get-location
5842 (if goto "Goto: " "Refile to: ") buffer
5843 org-refile-allow-creating-parent-nodes))))
5844 (with-current-buffer buffer
5845 (save-excursion
5846 (save-restriction
5847 (widen)
5848 (goto-char marker)
5849 (org-remove-subtree-entries-from-agenda)
5850 (org-refile goto buffer rfloc)))))))
5852 (defun org-agenda-open-link (&optional arg)
5853 "Follow the link in the current line, if any.
5854 This looks for a link in the displayed line in the agenda. It also looks
5855 at the text of the entry itself."
5856 (interactive "P")
5857 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
5858 (org-get-at-bol 'org-marker)))
5859 (buffer (and marker (marker-buffer marker)))
5860 (prefix (buffer-substring
5861 (point-at-bol)
5862 (+ (point-at-bol)
5863 (or (org-get-at-bol 'prefix-length) 0)))))
5864 (cond
5865 (buffer
5866 (with-current-buffer buffer
5867 (save-excursion
5868 (save-restriction
5869 (widen)
5870 (goto-char marker)
5871 (org-offer-links-in-entry arg prefix)))))
5872 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
5873 (save-excursion
5874 (beginning-of-line 1)
5875 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
5876 (org-open-link-from-string (match-string 1)))
5877 (t (error "No link to open here")))))
5879 (defun org-agenda-copy-local-variable (var)
5880 "Get a variable from a referenced buffer and install it here."
5881 (let ((m (org-get-at-bol 'org-marker)))
5882 (when (and m (buffer-live-p (marker-buffer m)))
5883 (org-set-local var (with-current-buffer (marker-buffer m)
5884 (symbol-value var))))))
5886 (defun org-agenda-switch-to (&optional delete-other-windows)
5887 "Go to the Org-mode file which contains the item at point."
5888 (interactive)
5889 (if (and org-return-follows-link
5890 (not (org-get-at-bol 'org-marker))
5891 (org-in-regexp org-bracket-link-regexp))
5892 (org-open-link-from-string (match-string 0))
5893 (let* ((marker (or (org-get-at-bol 'org-marker)
5894 (org-agenda-error)))
5895 (buffer (marker-buffer marker))
5896 (pos (marker-position marker)))
5897 (switch-to-buffer buffer)
5898 (and delete-other-windows (delete-other-windows))
5899 (widen)
5900 (goto-char pos)
5901 (when (org-mode-p)
5902 (org-show-context 'agenda)
5903 (save-excursion
5904 (and (outline-next-heading)
5905 (org-flag-heading nil))))))) ; show the next heading
5907 (defun org-agenda-goto-mouse (ev)
5908 "Go to the Org-mode file which contains the item at the mouse click."
5909 (interactive "e")
5910 (mouse-set-point ev)
5911 (org-agenda-goto))
5913 (defun org-agenda-show (&optional full-entry)
5914 "Display the Org-mode file which contains the item at point.
5915 With prefix argument FULL-ENTRY, make the entire entry visible
5916 if it was hidden in the outline."
5917 (interactive "P")
5918 (let ((win (selected-window)))
5919 (if full-entry
5920 (let ((org-show-entry-below t))
5921 (org-agenda-goto t))
5922 (org-agenda-goto t))
5923 (select-window win)))
5925 (defvar org-agenda-show-window nil)
5926 (defun org-agenda-show-and-scroll-up ()
5927 "Display the Org-mode file which contains the item at point.
5928 When called repeatedly, scroll the window that is displaying the buffer."
5929 (interactive)
5930 (let ((win (selected-window)))
5931 (if (and (window-live-p org-agenda-show-window)
5932 (eq this-command last-command))
5933 (progn
5934 (select-window org-agenda-show-window)
5935 (ignore-errors (scroll-up)))
5936 (org-agenda-goto t)
5937 (show-subtree)
5938 (setq org-agenda-show-window (selected-window)))
5939 (select-window win)))
5941 (defun org-agenda-show-scroll-down ()
5942 "Scroll down the window showing the agenda."
5943 (interactive)
5944 (let ((win (selected-window)))
5945 (when (window-live-p org-agenda-show-window)
5946 (select-window org-agenda-show-window)
5947 (ignore-errors (scroll-down))
5948 (select-window win))))
5950 (defun org-agenda-show-1 (&optional more)
5951 "Display the Org-mode file which contains the item at point.
5952 The prefix arg causes further revieling:
5954 0 hide the subtree
5955 1 just show the entry according to defaults.
5956 2 show the children view
5957 3 show the subtree view
5958 4 show the entire subtree and any LOGBOOK drawers
5959 5 show the entire subtree and any drawers
5960 With prefix argument FULL-ENTRY, make the entire entry visible
5961 if it was hidden in the outline."
5962 (interactive "p")
5963 (let ((win (selected-window)))
5964 (org-agenda-goto t)
5965 (org-recenter-heading 1)
5966 (cond
5967 ((= more 0)
5968 (hide-subtree)
5969 (save-excursion
5970 (org-back-to-heading)
5971 (run-hook-with-args 'org-cycle-hook 'folded))
5972 (message "Remote: FOLDED"))
5973 ((and (interactive-p) (= more 1))
5974 (message "Remote: show with default settings"))
5975 ((= more 2)
5976 (show-entry)
5977 (show-children)
5978 (save-excursion
5979 (org-back-to-heading)
5980 (run-hook-with-args 'org-cycle-hook 'children))
5981 (message "Remote: CHILDREN"))
5982 ((= more 3)
5983 (show-subtree)
5984 (save-excursion
5985 (org-back-to-heading)
5986 (run-hook-with-args 'org-cycle-hook 'subtree))
5987 (message "Remote: SUBTREE"))
5988 ((= more 4)
5989 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
5990 (org-drawer-regexp
5991 (concat "^[ \t]*:\\("
5992 (mapconcat 'regexp-quote org-drawers "\\|")
5993 "\\):[ \t]*$")))
5994 (show-subtree)
5995 (save-excursion
5996 (org-back-to-heading)
5997 (org-cycle-hide-drawers 'subtree)))
5998 (message "Remote: SUBTREE AND LOGBOOK"))
5999 ((> more 4)
6000 (show-subtree)
6001 (message "Remote: SUBTREE AND ALL DRAWERS")))
6002 (select-window win)))
6004 (defun org-recenter-heading (n)
6005 (save-excursion
6006 (org-back-to-heading)
6007 (recenter n)))
6009 (defvar org-agenda-cycle-counter nil)
6010 (defun org-agenda-cycle-show (&optional n)
6011 "Show the current entry in another window, with default settings.
6012 Default settings are taken from `org-show-hierarchy-above' and siblings.
6013 When use repeatedly in immediate succession, the remote entry will cycle
6014 through visibility
6016 children -> subtree -> folded
6018 When called with a numeric prefix arg, that arg will be passed through to
6019 `org-agenda-show-1'. For the interpretation of that argument, see the
6020 docstring of `org-agenda-show-1'."
6021 (interactive "P")
6022 (if (integerp n)
6023 (setq org-agenda-cycle-counter n)
6024 (if (not (eq last-command this-command))
6025 (setq org-agenda-cycle-counter 1)
6026 (if (equal org-agenda-cycle-counter 0)
6027 (setq org-agenda-cycle-counter 2)
6028 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6029 (if (> org-agenda-cycle-counter 3)
6030 (setq org-agenda-cycle-counter 0)))))
6031 (org-agenda-show-1 org-agenda-cycle-counter))
6033 (defun org-agenda-recenter (arg)
6034 "Display the Org-mode file which contains the item at point and recenter."
6035 (interactive "P")
6036 (let ((win (selected-window)))
6037 (org-agenda-goto t)
6038 (recenter arg)
6039 (select-window win)))
6041 (defun org-agenda-show-mouse (ev)
6042 "Display the Org-mode file which contains the item at the mouse click."
6043 (interactive "e")
6044 (mouse-set-point ev)
6045 (org-agenda-show))
6047 (defun org-agenda-check-no-diary ()
6048 "Check if the entry is a diary link and abort if yes."
6049 (if (org-get-at-bol 'org-agenda-diary-link)
6050 (org-agenda-error)))
6052 (defun org-agenda-error ()
6053 (error "Command not allowed in this line"))
6055 (defun org-agenda-tree-to-indirect-buffer ()
6056 "Show the subtree corresponding to the current entry in an indirect buffer.
6057 This calls the command `org-tree-to-indirect-buffer' from the original
6058 Org-mode buffer.
6059 With numerical prefix arg ARG, go up to this level and then take that tree.
6060 With a C-u prefix, make a separate frame for this tree (i.e. don't use the
6061 dedicated frame)."
6062 (interactive)
6063 (org-agenda-check-no-diary)
6064 (let* ((marker (or (org-get-at-bol 'org-marker)
6065 (org-agenda-error)))
6066 (buffer (marker-buffer marker))
6067 (pos (marker-position marker)))
6068 (with-current-buffer buffer
6069 (save-excursion
6070 (goto-char pos)
6071 (call-interactively 'org-tree-to-indirect-buffer)))))
6073 (defvar org-last-heading-marker (make-marker)
6074 "Marker pointing to the headline that last changed its TODO state
6075 by a remote command from the agenda.")
6077 (defun org-agenda-todo-nextset ()
6078 "Switch TODO entry to next sequence."
6079 (interactive)
6080 (org-agenda-todo 'nextset))
6082 (defun org-agenda-todo-previousset ()
6083 "Switch TODO entry to previous sequence."
6084 (interactive)
6085 (org-agenda-todo 'previousset))
6087 (defun org-agenda-todo (&optional arg)
6088 "Cycle TODO state of line at point, also in Org-mode file.
6089 This changes the line at point, all other lines in the agenda referring to
6090 the same tree node, and the headline of the tree node in the Org-mode file."
6091 (interactive "P")
6092 (org-agenda-check-no-diary)
6093 (let* ((col (current-column))
6094 (marker (or (org-get-at-bol 'org-marker)
6095 (org-agenda-error)))
6096 (buffer (marker-buffer marker))
6097 (pos (marker-position marker))
6098 (hdmarker (org-get-at-bol 'org-hd-marker))
6099 (todayp (equal (org-get-at-bol 'day)
6100 (time-to-days (current-time))))
6101 (inhibit-read-only t)
6102 org-agenda-headline-snapshot-before-repeat newhead just-one)
6103 (org-with-remote-undo buffer
6104 (with-current-buffer buffer
6105 (widen)
6106 (goto-char pos)
6107 (org-show-context 'agenda)
6108 (save-excursion
6109 (and (outline-next-heading)
6110 (org-flag-heading nil))) ; show the next heading
6111 (let ((current-prefix-arg arg))
6112 (call-interactively 'org-todo))
6113 (and (bolp) (forward-char 1))
6114 (setq newhead (org-get-heading))
6115 (when (and (org-bound-and-true-p
6116 org-agenda-headline-snapshot-before-repeat)
6117 (not (equal org-agenda-headline-snapshot-before-repeat
6118 newhead))
6119 todayp)
6120 (setq newhead org-agenda-headline-snapshot-before-repeat
6121 just-one t))
6122 (save-excursion
6123 (org-back-to-heading)
6124 (move-marker org-last-heading-marker (point))))
6125 (beginning-of-line 1)
6126 (save-excursion
6127 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6128 (org-move-to-column col))))
6130 (defun org-agenda-add-note (&optional arg)
6131 "Add a time-stamped note to the entry at point."
6132 (interactive "P")
6133 (org-agenda-check-no-diary)
6134 (let* ((marker (or (org-get-at-bol 'org-marker)
6135 (org-agenda-error)))
6136 (buffer (marker-buffer marker))
6137 (pos (marker-position marker))
6138 (hdmarker (org-get-at-bol 'org-hd-marker))
6139 (inhibit-read-only t))
6140 (with-current-buffer buffer
6141 (widen)
6142 (goto-char pos)
6143 (org-show-context 'agenda)
6144 (save-excursion
6145 (and (outline-next-heading)
6146 (org-flag-heading nil))) ; show the next heading
6147 (org-add-note))))
6149 (defun org-agenda-change-all-lines (newhead hdmarker
6150 &optional fixface just-this)
6151 "Change all lines in the agenda buffer which match HDMARKER.
6152 The new content of the line will be NEWHEAD (as modified by
6153 `org-format-agenda-item'). HDMARKER is checked with
6154 `equal' against all `org-hd-marker' text properties in the file.
6155 If FIXFACE is non-nil, the face of each item is modified according to
6156 the new TODO state.
6157 If JUST-THIS is non-nil, change just the current line, not all.
6158 If FORCE-TAGS is non nil, the car of it returns the new tags."
6159 (let* ((inhibit-read-only t)
6160 (line (org-current-line))
6161 (thetags (with-current-buffer (marker-buffer hdmarker)
6162 (save-excursion (save-restriction (widen)
6163 (goto-char hdmarker)
6164 (org-get-tags-at)))))
6165 props m pl undone-face done-face finish new dotime cat tags)
6166 (save-excursion
6167 (goto-char (point-max))
6168 (beginning-of-line 1)
6169 (while (not finish)
6170 (setq finish (bobp))
6171 (when (and (setq m (org-get-at-bol 'org-hd-marker))
6172 (or (not just-this) (= (org-current-line) line))
6173 (equal m hdmarker))
6174 (setq props (text-properties-at (point))
6175 dotime (org-get-at-bol 'dotime)
6176 cat (org-get-at-bol 'org-category)
6177 tags thetags
6178 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
6179 pl (org-get-at-bol 'prefix-length)
6180 undone-face (org-get-at-bol 'undone-face)
6181 done-face (org-get-at-bol 'done-face))
6182 (goto-char (+ (point) pl))
6183 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
6184 (cond
6185 ((equal new "")
6186 (beginning-of-line 1)
6187 (and (looking-at ".*\n?") (replace-match "")))
6188 ((looking-at ".*")
6189 (replace-match new t t)
6190 (beginning-of-line 1)
6191 (add-text-properties (point-at-bol) (point-at-eol) props)
6192 (when fixface
6193 (add-text-properties
6194 (point-at-bol) (point-at-eol)
6195 (list 'face
6196 (if org-last-todo-state-is-todo
6197 undone-face done-face))))
6198 (org-agenda-highlight-todo 'line)
6199 (beginning-of-line 1))
6200 (t (error "Line update did not work"))))
6201 (beginning-of-line 0)))
6202 (org-finalize-agenda)))
6204 (defun org-agenda-align-tags (&optional line)
6205 "Align all tags in agenda items to `org-agenda-tags-column'."
6206 (let ((inhibit-read-only t) l c)
6207 (save-excursion
6208 (goto-char (if line (point-at-bol) (point-min)))
6209 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
6210 (if line (point-at-eol) nil) t)
6211 (add-text-properties
6212 (match-beginning 2) (match-end 2)
6213 (list 'face (delq nil (let ((prop (get-text-property
6214 (match-beginning 2) 'face)))
6215 (or (listp prop) (setq prop (list prop)))
6216 (if (memq 'org-tag prop)
6217 prop
6218 (cons 'org-tag prop))))))
6219 (setq l (- (match-end 2) (match-beginning 2))
6220 c (if (< org-agenda-tags-column 0)
6221 (- (abs org-agenda-tags-column) l)
6222 org-agenda-tags-column))
6223 (delete-region (match-beginning 1) (match-end 1))
6224 (goto-char (match-beginning 1))
6225 (insert (org-add-props
6226 (make-string (max 1 (- c (current-column))) ?\ )
6227 (text-properties-at (point)))))
6228 (goto-char (point-min))
6229 (org-font-lock-add-tag-faces (point-max)))))
6231 (defun org-agenda-priority-up ()
6232 "Increase the priority of line at point, also in Org-mode file."
6233 (interactive)
6234 (org-agenda-priority 'up))
6236 (defun org-agenda-priority-down ()
6237 "Decrease the priority of line at point, also in Org-mode file."
6238 (interactive)
6239 (org-agenda-priority 'down))
6241 (defun org-agenda-priority (&optional force-direction)
6242 "Set the priority of line at point, also in Org-mode file.
6243 This changes the line at point, all other lines in the agenda referring to
6244 the same tree node, and the headline of the tree node in the Org-mode file."
6245 (interactive)
6246 (unless org-enable-priority-commands
6247 (error "Priority commands are disabled"))
6248 (org-agenda-check-no-diary)
6249 (let* ((marker (or (org-get-at-bol 'org-marker)
6250 (org-agenda-error)))
6251 (hdmarker (org-get-at-bol 'org-hd-marker))
6252 (buffer (marker-buffer hdmarker))
6253 (pos (marker-position hdmarker))
6254 (inhibit-read-only t)
6255 newhead)
6256 (org-with-remote-undo buffer
6257 (with-current-buffer buffer
6258 (widen)
6259 (goto-char pos)
6260 (org-show-context 'agenda)
6261 (save-excursion
6262 (and (outline-next-heading)
6263 (org-flag-heading nil))) ; show the next heading
6264 (funcall 'org-priority force-direction)
6265 (end-of-line 1)
6266 (setq newhead (org-get-heading)))
6267 (org-agenda-change-all-lines newhead hdmarker)
6268 (beginning-of-line 1))))
6270 ;; FIXME: should fix the tags property of the agenda line.
6271 (defun org-agenda-set-tags (&optional tag onoff)
6272 "Set tags for the current headline."
6273 (interactive)
6274 (org-agenda-check-no-diary)
6275 (if (and (org-region-active-p) (interactive-p))
6276 (call-interactively 'org-change-tag-in-region)
6277 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6278 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6279 (org-agenda-error)))
6280 (buffer (marker-buffer hdmarker))
6281 (pos (marker-position hdmarker))
6282 (inhibit-read-only t)
6283 newhead)
6284 (org-with-remote-undo buffer
6285 (with-current-buffer buffer
6286 (widen)
6287 (goto-char pos)
6288 (save-excursion
6289 (org-show-context 'agenda))
6290 (save-excursion
6291 (and (outline-next-heading)
6292 (org-flag-heading nil))) ; show the next heading
6293 (goto-char pos)
6294 (if tag
6295 (org-toggle-tag tag onoff)
6296 (call-interactively 'org-set-tags))
6297 (end-of-line 1)
6298 (setq newhead (org-get-heading)))
6299 (org-agenda-change-all-lines newhead hdmarker)
6300 (beginning-of-line 1)))))
6302 (defun org-agenda-set-property ()
6303 "Set a property for the current headline."
6304 (interactive)
6305 (org-agenda-check-no-diary)
6306 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6307 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6308 (org-agenda-error)))
6309 (buffer (marker-buffer hdmarker))
6310 (pos (marker-position hdmarker))
6311 (inhibit-read-only t)
6312 newhead)
6313 (org-with-remote-undo buffer
6314 (with-current-buffer buffer
6315 (widen)
6316 (goto-char pos)
6317 (save-excursion
6318 (org-show-context 'agenda))
6319 (save-excursion
6320 (and (outline-next-heading)
6321 (org-flag-heading nil))) ; show the next heading
6322 (goto-char pos)
6323 (call-interactively 'org-set-property)))))
6325 (defun org-agenda-set-effort ()
6326 "Set the effort property for the current headline."
6327 (interactive)
6328 (org-agenda-check-no-diary)
6329 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6330 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6331 (org-agenda-error)))
6332 (buffer (marker-buffer hdmarker))
6333 (pos (marker-position hdmarker))
6334 (inhibit-read-only t)
6335 newhead)
6336 (org-with-remote-undo buffer
6337 (with-current-buffer buffer
6338 (widen)
6339 (goto-char pos)
6340 (save-excursion
6341 (org-show-context 'agenda))
6342 (save-excursion
6343 (and (outline-next-heading)
6344 (org-flag-heading nil))) ; show the next heading
6345 (goto-char pos)
6346 (call-interactively 'org-set-effort)
6347 (end-of-line 1)))))
6349 (defun org-agenda-toggle-archive-tag ()
6350 "Toggle the archive tag for the current entry."
6351 (interactive)
6352 (org-agenda-check-no-diary)
6353 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
6354 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
6355 (org-agenda-error)))
6356 (buffer (marker-buffer hdmarker))
6357 (pos (marker-position hdmarker))
6358 (inhibit-read-only t)
6359 newhead)
6360 (org-with-remote-undo buffer
6361 (with-current-buffer buffer
6362 (widen)
6363 (goto-char pos)
6364 (org-show-context 'agenda)
6365 (save-excursion
6366 (and (outline-next-heading)
6367 (org-flag-heading nil))) ; show the next heading
6368 (call-interactively 'org-toggle-archive-tag)
6369 (end-of-line 1)
6370 (setq newhead (org-get-heading)))
6371 (org-agenda-change-all-lines newhead hdmarker)
6372 (beginning-of-line 1))))
6374 (defun org-agenda-do-date-later (arg)
6375 (interactive "P")
6376 (cond
6377 ((or (equal arg '(16))
6378 (memq last-command
6379 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6380 (setq this-command 'org-agenda-date-later-minutes)
6381 (org-agenda-date-later-minutes 1))
6382 ((or (equal arg '(4))
6383 (memq last-command
6384 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6385 (setq this-command 'org-agenda-date-later-hours)
6386 (org-agenda-date-later-hours 1))
6388 (org-agenda-date-later (prefix-numeric-value arg)))))
6390 (defun org-agenda-do-date-earlier (arg)
6391 (interactive "P")
6392 (cond
6393 ((or (equal arg '(16))
6394 (memq last-command
6395 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
6396 (setq this-command 'org-agenda-date-earlier-minutes)
6397 (org-agenda-date-earlier-minutes 1))
6398 ((or (equal arg '(4))
6399 (memq last-command
6400 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
6401 (setq this-command 'org-agenda-date-earlier-hours)
6402 (org-agenda-date-earlier-hours 1))
6404 (org-agenda-date-earlier (prefix-numeric-value arg)))))
6406 (defun org-agenda-date-later (arg &optional what)
6407 "Change the date of this item to one day later."
6408 (interactive "p")
6409 (org-agenda-check-type t 'agenda 'timeline)
6410 (org-agenda-check-no-diary)
6411 (let* ((marker (or (org-get-at-bol 'org-marker)
6412 (org-agenda-error)))
6413 (buffer (marker-buffer marker))
6414 (pos (marker-position marker)))
6415 (org-with-remote-undo buffer
6416 (with-current-buffer buffer
6417 (widen)
6418 (goto-char pos)
6419 (if (not (org-at-timestamp-p))
6420 (error "Cannot find time stamp"))
6421 (org-timestamp-change arg (or what 'day)))
6422 (org-agenda-show-new-time marker org-last-changed-timestamp))
6423 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6425 (defun org-agenda-date-earlier (arg &optional what)
6426 "Change the date of this item to one day earlier."
6427 (interactive "p")
6428 (org-agenda-date-later (- arg) what))
6430 (defun org-agenda-date-later-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-later arg 'minute))
6436 (defun org-agenda-date-earlier-minutes (arg)
6437 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
6438 (interactive "p")
6439 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
6440 (org-agenda-date-earlier arg 'minute))
6442 (defun org-agenda-date-later-hours (arg)
6443 "Change the time of this item, in hour steps."
6444 (interactive "p")
6445 (org-agenda-date-later arg 'hour))
6447 (defun org-agenda-date-earlier-hours (arg)
6448 "Change the time of this item, in hour steps."
6449 (interactive "p")
6450 (org-agenda-date-earlier arg 'hour))
6452 (defun org-agenda-show-new-time (marker stamp &optional prefix)
6453 "Show new date stamp via text properties."
6454 ;; We use text properties to make this undoable
6455 (let ((inhibit-read-only t)
6456 (buffer-invisibility-spec))
6457 (setq stamp (concat " " prefix " => " stamp))
6458 (save-excursion
6459 (goto-char (point-max))
6460 (while (not (bobp))
6461 (when (equal marker (org-get-at-bol 'org-marker))
6462 (org-move-to-column (- (window-width) (length stamp)) t)
6463 (org-agenda-fix-tags-filter-overlays-at (point))
6464 (if (featurep 'xemacs)
6465 ;; Use `duplicable' property to trigger undo recording
6466 (let ((ex (make-extent nil nil))
6467 (gl (make-glyph stamp)))
6468 (set-glyph-face gl 'secondary-selection)
6469 (set-extent-properties
6470 ex (list 'invisible t 'end-glyph gl 'duplicable t))
6471 (insert-extent ex (1- (point)) (point-at-eol)))
6472 (add-text-properties
6473 (1- (point)) (point-at-eol)
6474 (list 'display (org-add-props stamp nil
6475 'face 'secondary-selection))))
6476 (beginning-of-line 1))
6477 (beginning-of-line 0)))))
6479 (defun org-agenda-date-prompt (arg)
6480 "Change the date of this item. Date is prompted for, with default today.
6481 The prefix ARG is passed to the `org-time-stamp' command and can therefore
6482 be used to request time specification in the time stamp."
6483 (interactive "P")
6484 (org-agenda-check-type t 'agenda 'timeline)
6485 (org-agenda-check-no-diary)
6486 (let* ((marker (or (org-get-at-bol 'org-marker)
6487 (org-agenda-error)))
6488 (buffer (marker-buffer marker))
6489 (pos (marker-position marker)))
6490 (org-with-remote-undo buffer
6491 (with-current-buffer buffer
6492 (widen)
6493 (goto-char pos)
6494 (if (not (org-at-timestamp-p))
6495 (error "Cannot find time stamp"))
6496 (org-time-stamp arg))
6497 (org-agenda-show-new-time marker org-last-changed-timestamp))
6498 (message "Time stamp changed to %s" org-last-changed-timestamp)))
6500 (defun org-agenda-schedule (arg)
6501 "Schedule the item at point."
6502 (interactive "P")
6503 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6504 (org-agenda-check-no-diary)
6505 (let* ((marker (or (org-get-at-bol 'org-marker)
6506 (org-agenda-error)))
6507 (type (marker-insertion-type marker))
6508 (buffer (marker-buffer marker))
6509 (pos (marker-position marker))
6510 (org-insert-labeled-timestamps-at-point nil)
6512 (set-marker-insertion-type marker t)
6513 (org-with-remote-undo buffer
6514 (with-current-buffer buffer
6515 (widen)
6516 (goto-char pos)
6517 (setq ts (org-schedule arg)))
6518 (org-agenda-show-new-time marker ts "S"))
6519 (message "Item scheduled for %s" ts)))
6521 (defun org-agenda-deadline (arg)
6522 "Schedule the item at point."
6523 (interactive "P")
6524 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
6525 (org-agenda-check-no-diary)
6526 (let* ((marker (or (org-get-at-bol 'org-marker)
6527 (org-agenda-error)))
6528 (buffer (marker-buffer marker))
6529 (pos (marker-position marker))
6530 (org-insert-labeled-timestamps-at-point nil)
6532 (org-with-remote-undo buffer
6533 (with-current-buffer buffer
6534 (widen)
6535 (goto-char pos)
6536 (setq ts (org-deadline arg)))
6537 (org-agenda-show-new-time marker ts "D"))
6538 (message "Deadline for this item set to %s" ts)))
6540 (defun org-agenda-action ()
6541 "Select entry for agenda action, or execute an agenda action.
6542 This command prompts for another letter. Valid inputs are:
6544 m Mark the entry at point for an agenda action
6545 s Schedule the marked entry to the date at the cursor
6546 d Set the deadline of the marked entry to the date at the cursor
6547 r Call `org-remember' with cursor date as the default date
6548 SPC Show marked entry in other window
6549 TAB Visit marked entry in other window
6551 The cursor may be at a date in the calendar, or in the Org agenda."
6552 (interactive)
6553 (let (ans)
6554 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
6555 (setq ans (read-char-exclusive))
6556 (cond
6557 ((equal ans ?m)
6558 ;; Mark this entry
6559 (if (eq major-mode 'org-agenda-mode)
6560 (let ((m (or (org-get-at-bol 'org-hd-marker)
6561 (org-get-at-bol 'org-marker))))
6562 (if m
6563 (progn
6564 (move-marker org-agenda-action-marker
6565 (marker-position m) (marker-buffer m))
6566 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
6567 (error "Don't know which entry to mark")))
6568 (error "This command works only in the agenda")))
6569 ((equal ans ?s)
6570 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
6571 ((equal ans ?d)
6572 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
6573 ((equal ans ?r)
6574 (org-agenda-do-action '(org-remember) t))
6575 ((equal ans ?\ )
6576 (let ((cw (selected-window)))
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 (select-window cw)))
6582 ((equal ans ?\C-i)
6583 (org-switch-to-buffer-other-window
6584 (marker-buffer org-agenda-action-marker))
6585 (goto-char org-agenda-action-marker)
6586 (org-show-context 'agenda))
6587 (t (error "Invalid agenda action %c" ans)))))
6589 (defun org-agenda-do-action (form &optional current-buffer)
6590 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
6591 (let ((org-overriding-default-time (org-get-cursor-date)))
6592 (if current-buffer
6593 (eval form)
6594 (if (not (marker-buffer org-agenda-action-marker))
6595 (error "No entry has been selected for agenda action")
6596 (with-current-buffer (marker-buffer org-agenda-action-marker)
6597 (save-excursion
6598 (save-restriction
6599 (widen)
6600 (goto-char org-agenda-action-marker)
6601 (eval form))))))))
6603 (defun org-agenda-clock-in (&optional arg)
6604 "Start the clock on the currently selected item."
6605 (interactive "P")
6606 (org-agenda-check-no-diary)
6607 (if (equal arg '(4))
6608 (org-clock-in arg)
6609 (let* ((marker (or (org-get-at-bol 'org-marker)
6610 (org-agenda-error)))
6611 (hdmarker (or (org-get-at-bol 'org-hd-marker)
6612 marker))
6613 (pos (marker-position marker))
6614 newhead)
6615 (org-with-remote-undo (marker-buffer marker)
6616 (with-current-buffer (marker-buffer marker)
6617 (widen)
6618 (goto-char pos)
6619 (org-show-context 'agenda)
6620 (org-show-entry)
6621 (org-cycle-hide-drawers 'children)
6622 (org-clock-in arg)
6623 (setq newhead (org-get-heading)))
6624 (org-agenda-change-all-lines newhead hdmarker)))))
6626 (defun org-agenda-clock-out (&optional arg)
6627 "Stop the currently running clock."
6628 (interactive "P")
6629 (unless (marker-buffer org-clock-marker)
6630 (error "No running clock"))
6631 (let ((marker (make-marker)) newhead)
6632 (org-with-remote-undo (marker-buffer org-clock-marker)
6633 (with-current-buffer (marker-buffer org-clock-marker)
6634 (save-excursion
6635 (save-restriction
6636 (widen)
6637 (goto-char org-clock-marker)
6638 (org-back-to-heading t)
6639 (move-marker marker (point))
6640 (org-clock-out)
6641 (setq newhead (org-get-heading))))))
6642 (org-agenda-change-all-lines newhead marker)
6643 (move-marker marker nil)))
6645 (defun org-agenda-clock-cancel (&optional arg)
6646 "Cancel the currently running clock."
6647 (interactive "P")
6648 (unless (marker-buffer org-clock-marker)
6649 (error "No running clock"))
6650 (org-with-remote-undo (marker-buffer org-clock-marker)
6651 (org-clock-cancel)))
6653 (defun org-agenda-diary-entry ()
6654 "Make a diary entry, like the `i' command from the calendar.
6655 All the standard commands work: block, weekly etc."
6656 (interactive)
6657 (org-agenda-check-type t 'agenda 'timeline)
6658 (require 'diary-lib)
6659 (let* ((char (progn
6660 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
6661 (read-char-exclusive)))
6662 (cmd (cdr (assoc char
6663 '((?d . insert-diary-entry)
6664 (?w . insert-weekly-diary-entry)
6665 (?m . insert-monthly-diary-entry)
6666 (?y . insert-yearly-diary-entry)
6667 (?a . insert-anniversary-diary-entry)
6668 (?b . insert-block-diary-entry)
6669 (?c . insert-cyclic-diary-entry)))))
6670 (oldf (symbol-function 'calendar-cursor-to-date))
6671 ; (buf (get-file-buffer (substitute-in-file-name diary-file)))
6672 (point (point))
6673 (mark (or (mark t) (point))))
6674 (unless cmd
6675 (error "No command associated with <%c>" char))
6676 (unless (and (get-text-property point 'day)
6677 (or (not (equal ?b char))
6678 (get-text-property mark 'day)))
6679 (error "Don't know which date to use for diary entry"))
6680 ;; We implement this by hacking the `calendar-cursor-to-date' function
6681 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
6682 (let ((calendar-mark-ring
6683 (list (calendar-gregorian-from-absolute
6684 (or (get-text-property mark 'day)
6685 (get-text-property point 'day))))))
6686 (unwind-protect
6687 (progn
6688 (fset 'calendar-cursor-to-date
6689 (lambda (&optional error dummy)
6690 (calendar-gregorian-from-absolute
6691 (get-text-property point 'day))))
6692 (call-interactively cmd))
6693 (fset 'calendar-cursor-to-date oldf)))))
6695 (defun org-agenda-execute-calendar-command (cmd)
6696 "Execute a calendar command from the agenda, with the date associated to
6697 the cursor position."
6698 (org-agenda-check-type t 'agenda 'timeline)
6699 (require 'diary-lib)
6700 (unless (get-text-property (point) 'day)
6701 (error "Don't know which date to use for calendar command"))
6702 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
6703 (point (point))
6704 (date (calendar-gregorian-from-absolute
6705 (get-text-property point 'day)))
6706 ;; the following 2 vars are needed in the calendar
6707 (displayed-month (car date))
6708 (displayed-year (nth 2 date)))
6709 (unwind-protect
6710 (progn
6711 (fset 'calendar-cursor-to-date
6712 (lambda (&optional error dummy)
6713 (calendar-gregorian-from-absolute
6714 (get-text-property point 'day))))
6715 (call-interactively cmd))
6716 (fset 'calendar-cursor-to-date oldf))))
6718 (defun org-agenda-phases-of-moon ()
6719 "Display the phases of the moon for the 3 months around the cursor date."
6720 (interactive)
6721 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
6723 (defun org-agenda-holidays ()
6724 "Display the holidays for the 3 months around the cursor date."
6725 (interactive)
6726 (org-agenda-execute-calendar-command 'list-calendar-holidays))
6728 (defvar calendar-longitude)
6729 (defvar calendar-latitude)
6730 (defvar calendar-location-name)
6732 (defun org-agenda-sunrise-sunset (arg)
6733 "Display sunrise and sunset for the cursor date.
6734 Latitude and longitude can be specified with the variables
6735 `calendar-latitude' and `calendar-longitude'. When called with prefix
6736 argument, latitude and longitude will be prompted for."
6737 (interactive "P")
6738 (require 'solar)
6739 (let ((calendar-longitude (if arg nil calendar-longitude))
6740 (calendar-latitude (if arg nil calendar-latitude))
6741 (calendar-location-name
6742 (if arg "the given coordinates" calendar-location-name)))
6743 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
6745 (defun org-agenda-goto-calendar ()
6746 "Open the Emacs calendar with the date at the cursor."
6747 (interactive)
6748 (org-agenda-check-type t 'agenda 'timeline)
6749 (let* ((day (or (get-text-property (point) 'day)
6750 (error "Don't know which date to open in calendar")))
6751 (date (calendar-gregorian-from-absolute day))
6752 (calendar-move-hook nil)
6753 (calendar-view-holidays-initially-flag nil)
6754 (calendar-view-diary-initially-flag nil)
6755 (view-calendar-holidays-initially nil)
6756 (view-diary-entries-initially nil))
6757 (calendar)
6758 (calendar-goto-date date)))
6760 ;;;###autoload
6761 (defun org-calendar-goto-agenda ()
6762 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
6763 This is a command that has to be installed in `calendar-mode-map'."
6764 (interactive)
6765 (org-agenda-list nil (calendar-absolute-from-gregorian
6766 (calendar-cursor-to-date))
6767 nil))
6769 (defun org-agenda-convert-date ()
6770 (interactive)
6771 (org-agenda-check-type t 'agenda 'timeline)
6772 (let ((day (get-text-property (point) 'day))
6773 date s)
6774 (unless day
6775 (error "Don't know which date to convert"))
6776 (setq date (calendar-gregorian-from-absolute day))
6777 (setq s (concat
6778 "Gregorian: " (calendar-date-string date) "\n"
6779 "ISO: " (calendar-iso-date-string date) "\n"
6780 "Day of Yr: " (calendar-day-of-year-string date) "\n"
6781 "Julian: " (calendar-julian-date-string date) "\n"
6782 "Astron. JD: " (calendar-astro-date-string date)
6783 " (Julian date number at noon UTC)\n"
6784 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
6785 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
6786 "French: " (calendar-french-date-string date) "\n"
6787 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
6788 "Mayan: " (calendar-mayan-date-string date) "\n"
6789 "Coptic: " (calendar-coptic-date-string date) "\n"
6790 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
6791 "Persian: " (calendar-persian-date-string date) "\n"
6792 "Chinese: " (calendar-chinese-date-string date) "\n"))
6793 (with-output-to-temp-buffer "*Dates*"
6794 (princ s))
6795 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
6797 ;;; Bulk commands
6799 (defvar org-agenda-bulk-marked-entries nil
6800 "List of markers that refer to marked entries in the agenda.")
6802 (defun org-agenda-bulk-marked-p ()
6803 (eq (get-char-property (point-at-bol) 'type)
6804 'org-marked-entry-overlay))
6806 (defun org-agenda-bulk-mark ()
6807 "Mark the entry at point for future bulk action."
6808 (interactive)
6809 (org-agenda-check-no-diary)
6810 (let* ((m (org-get-at-bol 'org-hd-marker))
6812 (unless (org-agenda-bulk-marked-p)
6813 (unless m (error "Nothing to mark at point"))
6814 (push m org-agenda-bulk-marked-entries)
6815 (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
6816 (org-overlay-display ov "> "
6817 (org-get-todo-face "TODO")
6818 'evaporate)
6819 (org-overlay-put ov 'type 'org-marked-entry-overlay))
6820 (beginning-of-line 2)
6821 (message "%d entries marked for bulk action"
6822 (length org-agenda-bulk-marked-entries))))
6824 (defun org-agenda-bulk-unmark ()
6825 "Unmark the entry at point for future bulk action."
6826 (interactive)
6827 (when (org-agenda-bulk-marked-p)
6828 (org-agenda-bulk-remove-overlays
6829 (point-at-bol) (+ 2 (point-at-bol)))
6830 (setq org-agenda-bulk-marked-entries
6831 (delete (org-get-at-bol 'org-hd-marker)
6832 org-agenda-bulk-marked-entries)))
6833 (beginning-of-line 2)
6834 (message "%d entries marked for bulk action"
6835 (length org-agenda-bulk-marked-entries)))
6837 (defun org-agenda-bulk-toggle ()
6838 "Toggle marking the entry at point for bulk action."
6839 (interactive)
6840 (if (org-agenda-bulk-marked-p)
6841 (org-agenda-bulk-unmark)
6842 (org-agenda-bulk-mark)))
6844 (defun org-agenda-bulk-remove-overlays (&optional beg end)
6845 "Remove the mark overlays between BEG and END in the agenda buffer.
6846 BEG and END default to the buffer limits.
6848 This only removes the overlays, it does not remove the markers
6849 from the list in `org-agenda-bulk-marked-entries'."
6850 (interactive)
6851 (mapc (lambda (ov)
6852 (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
6853 (org-delete-overlay ov)))
6854 (org-overlays-in (or beg (point-min)) (or end (point-max)))))
6856 (defun org-agenda-bulk-remove-all-marks ()
6857 "Remove all marks in the agenda buffer.
6858 This will remove the markers, and the overlays."
6859 (interactive)
6860 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
6861 (setq org-agenda-bulk-marked-entries nil)
6862 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
6864 (defun org-agenda-bulk-action ()
6865 "Execute an remote-editing action on all marked entries."
6866 (interactive)
6867 (unless org-agenda-bulk-marked-entries
6868 (error "No entries are marked"))
6869 (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
6870 (let* ((action (read-char-exclusive))
6871 (entries (reverse org-agenda-bulk-marked-entries))
6872 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
6873 (cond
6874 ((equal action ?$)
6875 (setq cmd '(org-agenda-archive)))
6877 ((equal action ?A)
6878 (setq cmd '(org-agenda-archive-to-archive-sibling)))
6880 ((member action '(?r ?w))
6881 (setq rfloc (org-refile-get-location
6882 "Refile to: "
6883 (marker-buffer (car org-agenda-bulk-marked-entries))
6884 org-refile-allow-creating-parent-nodes))
6885 (setcar (nthcdr 3 rfloc)
6886 (move-marker (make-marker) (nth 3 rfloc)
6887 (or (get-file-buffer (nth 1 rfloc))
6888 (find-buffer-visiting (nth 1 rfloc))
6889 (error "This should not happen"))))
6891 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
6893 ((equal action ?t)
6894 (setq state (org-icompleting-read
6895 "Todo state: "
6896 (with-current-buffer (marker-buffer (car entries))
6897 (mapcar 'list org-todo-keywords-1))))
6898 (setq cmd `(let ((org-inhibit-blocking t)
6899 (org-inhibit-logging 'note))
6900 (org-agenda-todo ,state))))
6902 ((memq action '(?- ?+))
6903 (setq tag (org-icompleting-read
6904 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
6905 (with-current-buffer (marker-buffer (car entries))
6906 (delq nil
6907 (mapcar (lambda (x)
6908 (if (stringp (car x)) x)) org-tag-alist)))))
6909 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
6911 ((memq action '(?s ?d))
6912 (let* ((date (org-read-date
6913 nil nil nil
6914 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
6915 (ans org-read-date-final-answer)
6916 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
6917 (setq cmd `(let* ((bound (fboundp 'read-string))
6918 (old (and bound (symbol-function 'read-string))))
6919 (unwind-protect
6920 (progn
6921 (fset 'read-string (lambda (&rest ignore) ,ans))
6922 (call-interactively ',c1))
6923 (if bound
6924 (fset 'read-string old)
6925 (fmakunbound 'read-string)))))))
6926 (t (error "Invalid bulk action")))
6928 ;; Sort the markers, to make sure that parents are handled before children
6929 (setq entries (sort entries
6930 (lambda (a b)
6931 (cond
6932 ((equal (marker-buffer a) (marker-buffer b))
6933 (< (marker-position a) (marker-position b)))
6935 (string< (buffer-name (marker-buffer a))
6936 (buffer-name (marker-buffer b))))))))
6938 ;; Now loop over all markers and apply cmd
6939 (while (setq e (pop entries))
6940 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
6941 (if (not pos)
6942 (progn (message "Skipping removed entry at %s" e)
6943 (setq cntskip (1+ cntskip)))
6944 (goto-char pos)
6945 (eval cmd)
6946 (setq org-agenda-bulk-marked-entries
6947 (delete e org-agenda-bulk-marked-entries))
6948 (setq cnt (1+ cnt))))
6949 (setq org-agenda-bulk-marked-entries nil)
6950 (org-agenda-bulk-remove-all-marks)
6951 (message "Acted on %d entries%s"
6953 (if (= cntskip 0)
6955 (format ", skipped %d (disappeared before their turn)"
6956 cntskip)))))
6958 ;;; Flagging notes
6960 (defun org-agenda-show-the-flagging-note ()
6961 "Display the flagging note in the other window.
6962 When called a second time in direct sequence, offer to remove the FLAGGING
6963 tag and (if present) the flagging note."
6964 (interactive)
6965 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
6966 (win (selected-window))
6967 note heading newhead)
6968 (unless hdmarker
6969 (error "No linked entry at point"))
6970 (if (and (eq this-command last-command)
6971 (y-or-n-p "Unflag and remove any flagging note? "))
6972 (progn
6973 (org-agenda-remove-flag hdmarker)
6974 (let ((win (get-buffer-window "*Flagging Note*")))
6975 (and win (delete-window win)))
6976 (message "Entry unflaged"))
6977 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
6978 (unless note
6979 (error "No flagging note"))
6980 (org-kill-new note)
6981 (org-switch-to-buffer-other-window "*Flagging Note*")
6982 (erase-buffer)
6983 (insert note)
6984 (goto-char (point-min))
6985 (while (re-search-forward "\\\\n" nil t)
6986 (replace-match "\n" t t))
6987 (goto-char (point-min))
6988 (select-window win)
6989 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
6991 (defun org-agenda-remove-flag (marker)
6992 "Remove the FLAGGED tag and any flaging note in the entry."
6993 (let (newhead)
6994 (org-with-point-at marker
6995 (org-toggle-tag "FLAGGED" 'off)
6996 (org-entry-delete nil "THEFLAGGINGNOTE")
6997 (setq newhead (org-get-heading)))
6998 (org-agenda-change-all-lines newhead marker)
6999 (message "Entry unflaged")))
7001 (defun org-agenda-get-any-marker (&optional pos)
7002 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
7003 (get-text-property (or pos (point-at-bol)) 'org-marker)))
7005 ;;; Appointment reminders
7007 (defvar appt-time-msg-list)
7009 ;;;###autoload
7010 (defun org-agenda-to-appt (&optional refresh filter)
7011 "Activate appointments found in `org-agenda-files'.
7012 With a \\[universal-argument] prefix, refresh the list of
7013 appointments.
7015 If FILTER is t, interactively prompt the user for a regular
7016 expression, and filter out entries that don't match it.
7018 If FILTER is a string, use this string as a regular expression
7019 for filtering entries out.
7021 FILTER can also be an alist with the car of each cell being
7022 either 'headline or 'category. For example:
7024 '((headline \"IMPORTANT\")
7025 (category \"Work\"))
7027 will only add headlines containing IMPORTANT or headlines
7028 belonging to the \"Work\" category."
7029 (interactive "P")
7030 (require 'calendar)
7031 (if refresh (setq appt-time-msg-list nil))
7032 (if (eq filter t)
7033 (setq filter (read-from-minibuffer "Regexp filter: ")))
7034 (let* ((cnt 0) ; count added events
7035 (org-agenda-new-buffers nil)
7036 (org-deadline-warning-days 0)
7037 (today (org-date-to-gregorian
7038 (time-to-days (current-time))))
7039 (org-agenda-restrict nil)
7040 (files (org-agenda-files 'unrestricted)) entries file)
7041 ;; Get all entries which may contain an appt
7042 (org-prepare-agenda-buffers files)
7043 (while (setq file (pop files))
7044 (setq entries
7045 (append entries
7046 (org-agenda-get-day-entries
7047 file today :timestamp :scheduled :deadline))))
7048 (setq entries (delq nil entries))
7049 ;; Map thru entries and find if we should filter them out
7050 (mapc
7051 (lambda(x)
7052 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
7053 (cat (get-text-property 1 'org-category x))
7054 (tod (get-text-property 1 'time-of-day x))
7055 (ok (or (null filter)
7056 (and (stringp filter) (string-match filter evt))
7057 (and (listp filter)
7058 (or (string-match
7059 (cadr (assoc 'category filter)) cat)
7060 (string-match
7061 (cadr (assoc 'headline filter)) evt))))))
7062 ;; FIXME: Shall we remove text-properties for the appt text?
7063 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
7064 (when (and ok tod)
7065 (setq tod (concat "00" (number-to-string tod))
7066 tod (when (string-match
7067 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
7068 (concat (match-string 1 tod) ":"
7069 (match-string 2 tod))))
7070 (appt-add tod evt)
7071 (setq cnt (1+ cnt))))) entries)
7072 (org-release-buffers org-agenda-new-buffers)
7073 (if (eq cnt 0)
7074 (message "No event to add")
7075 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
7077 (defun org-agenda-todayp (date)
7078 "Does DATE mean today, when considering `org-extend-today-until'?"
7079 (let (today h)
7080 (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
7081 (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
7082 (setq h (nth 2 (decode-time (current-time))))
7083 (or (and (>= h org-extend-today-until)
7084 (= date today))
7085 (and (< h org-extend-today-until)
7086 (= date (1- today))))))
7088 (provide 'org-agenda)
7090 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
7092 ;;; org-agenda.el ends here