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