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