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