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