org-clock.el: localize the "Clock summary at" string.
[org-mode/org-jambu.git] / lisp / org-agenda.el
blob61de6a41a1a14cc5318875275c188970056245ba
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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: 7.5
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))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
93 :group 'org-agenda
94 :type 'boolean)
96 (defcustom org-agenda-block-separator ?=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group 'org-agenda-export
125 :type '(repeat
126 (list
127 (variable)
128 (sexp :tag "Value"))))
130 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group 'org-agenda-export
134 :type 'hook
135 :options '(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines 0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
148 :group 'org-agenda
149 :type 'integer)
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
156 :group 'org-agenda
157 :type 'boolean)
159 (defcustom org-agenda-export-html-style ""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group 'org-agenda-export
198 :group 'org-export-html
199 :type 'string)
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-span)
246 (choice (const :tag "Day" 'day)
247 (const :tag "Week" 'week)
248 (const :tag "Month" 'month)
249 (const :tag "Year" 'year)
250 (integer :tag "Custom")))
251 (list :tag "Fixed starting date"
252 (const org-agenda-start-day)
253 (string :value "2007-11-01"))
254 (list :tag "Start on day of week"
255 (const org-agenda-start-on-weekday)
256 (choice :value 1
257 (const :tag "Today" nil)
258 (integer :tag "Weekday No.")))
259 (list :tag "Include data from diary"
260 (const org-agenda-include-diary)
261 (boolean))
262 (list :tag "Deadline Warning days"
263 (const org-deadline-warning-days)
264 (integer :value 1))
265 (list :tag "Tags filter preset"
266 (const org-agenda-filter-preset)
267 (list
268 (const :format "" quote)
269 (repeat
270 (string :tag "+tag or -tag"))))
271 (list :tag "Set daily/weekly entry types"
272 (const org-agenda-entry-types)
273 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
274 (const :deadline)
275 (const :scheduled)
276 (const :timestamp)
277 (const :sexp)))
278 (list :tag "Standard skipping condition"
279 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
280 (const org-agenda-skip-function)
281 (list
282 (const :format "" quote)
283 (list
284 (choice
285 :tag "Skipping range"
286 (const :tag "Skip entry" org-agenda-skip-entry-if)
287 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
288 (repeat :inline t :tag "Conditions for skipping"
289 (choice
290 :tag "Condition type"
291 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
292 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
293 (list :tag "TODO state is" :inline t
294 (const 'todo)
295 (choice
296 (const :tag "any not-done state" 'todo)
297 (const :tag "any done state" 'done)
298 (const :tag "any state" 'any)
299 (list :tag "Keyword list"
300 (const :format "" quote)
301 (repeat (string :tag "Keyword")))))
302 (list :tag "TODO state is not" :inline t
303 (const 'nottodo)
304 (choice
305 (const :tag "any not-done state" 'todo)
306 (const :tag "any done state" 'done)
307 (const :tag "any state" 'any)
308 (list :tag "Keyword list"
309 (const :format "" quote)
310 (repeat (string :tag "Keyword")))))
311 (const :tag "scheduled" 'scheduled)
312 (const :tag "not scheduled" 'notscheduled)
313 (const :tag "deadline" 'deadline)
314 (const :tag "no deadline" 'notdeadline)
315 (const :tag "timestamp" 'timestamp)
316 (const :tag "no timestamp" 'nottimestamp))))))
317 (list :tag "Non-standard skipping condition"
318 :value (org-agenda-skip-function)
319 (const org-agenda-skip-function)
320 (sexp :tag "Function or form (quoted!)"))
321 (list :tag "Any variable"
322 (variable :tag "Variable")
323 (sexp :tag "Value (sexp)"))))
324 "Selection of examples for agenda command settings.
325 This will be spliced into the custom type of
326 `org-agenda-custom-commands'.")
329 (defcustom org-agenda-custom-commands nil
330 "Custom commands for the agenda.
331 These commands will be offered on the splash screen displayed by the
332 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
334 (key desc type match settings files)
336 key The key (one or more characters as a string) to be associated
337 with the command.
338 desc A description of the command, when omitted or nil, a default
339 description is built using MATCH.
340 type The command type, any of the following symbols:
341 agenda The daily/weekly agenda.
342 todo Entries with a specific TODO keyword, in all agenda files.
343 search Entries containing search words entry or headline.
344 tags Tags/Property/TODO match in all agenda files.
345 tags-todo Tags/P/T match in all agenda files, TODO entries only.
346 todo-tree Sparse tree of specific TODO keyword in *current* file.
347 tags-tree Sparse tree with all tags matches in *current* file.
348 occur-tree Occur sparse tree for *current* file.
349 ... A user-defined function.
350 match What to search for:
351 - a single keyword for TODO keyword searches
352 - a tags match expression for tags searches
353 - a word search expression for text searches.
354 - a regular expression for occur searches
355 For all other commands, this should be the empty string.
356 settings A list of option settings, similar to that in a let form, so like
357 this: ((opt1 val1) (opt2 val2) ...). The values will be
358 evaluated at the moment of execution, so quote them when needed.
359 files A list of files file to write the produced agenda buffer to
360 with the command `org-store-agenda-views'.
361 If a file name ends in \".html\", an HTML version of the buffer
362 is written out. If it ends in \".ps\", a postscript version is
363 produced. Otherwise, only the plain text is written to the file.
365 You can also define a set of commands, to create a composite agenda buffer.
366 In this case, an entry looks like this:
368 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
370 where
372 desc A description string to be displayed in the dispatcher menu.
373 cmd An agenda command, similar to the above. However, tree commands
374 are no allowed, but instead you can get agenda and global todo list.
375 So valid commands for a set are:
376 (agenda \"\" settings)
377 (alltodo \"\" settings)
378 (stuck \"\" settings)
379 (todo \"match\" settings files)
380 (search \"match\" settings files)
381 (tags \"match\" settings files)
382 (tags-todo \"match\" settings files)
384 Each command can carry a list of options, and another set of options can be
385 given for the whole set of commands. Individual command options take
386 precedence over the general options.
388 When using several characters as key to a command, the first characters
389 are prefix commands. For the dispatcher to display useful information, you
390 should provide a description for the prefix, like
392 (setq org-agenda-custom-commands
393 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
394 (\"hl\" tags \"+HOME+Lisa\")
395 (\"hp\" tags \"+HOME+Peter\")
396 (\"hk\" tags \"+HOME+Kim\")))"
397 :group 'org-agenda-custom-commands
398 :type `(repeat
399 (choice :value ("x" "Describe command here" tags "" nil)
400 (list :tag "Single command"
401 (string :tag "Access Key(s) ")
402 (option (string :tag "Description"))
403 (choice
404 (const :tag "Agenda" agenda)
405 (const :tag "TODO list" alltodo)
406 (const :tag "Search words" search)
407 (const :tag "Stuck projects" stuck)
408 (const :tag "Tags/Property match (all agenda files)" tags)
409 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
410 (const :tag "TODO keyword search (all agenda files)" todo)
411 (const :tag "Tags sparse tree (current buffer)" tags-tree)
412 (const :tag "TODO keyword tree (current buffer)" todo-tree)
413 (const :tag "Occur tree (current buffer)" occur-tree)
414 (sexp :tag "Other, user-defined function"))
415 (string :tag "Match (only for some commands)")
416 ,org-agenda-custom-commands-local-options
417 (option (repeat :tag "Export" (file :tag "Export to"))))
418 (list :tag "Command series, all agenda files"
419 (string :tag "Access Key(s)")
420 (string :tag "Description ")
421 (repeat :tag "Component"
422 (choice
423 (list :tag "Agenda"
424 (const :format "" agenda)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "TODO list (all keywords)"
428 (const :format "" alltodo)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Search words"
432 (const :format "" search)
433 (string :tag "Match")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Stuck projects"
436 (const :format "" stuck)
437 (const :tag "" :format "" "")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search"
440 (const :format "" tags)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search, TODO entries only"
444 (const :format "" tags-todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "TODO keyword search"
448 (const :format "" todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "Other, user-defined function"
452 (symbol :tag "function")
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)))
456 (repeat :tag "Settings for entire command set"
457 (list (variable :tag "Any variable")
458 (sexp :tag "Value")))
459 (option (repeat :tag "Export" (file :tag "Export to"))))
460 (cons :tag "Prefix key documentation"
461 (string :tag "Access Key(s)")
462 (string :tag "Description ")))))
464 (defcustom org-agenda-query-register ?o
465 "The register holding the current query string.
466 The purpose of this is that if you construct a query string interactively,
467 you can then use it to define a custom command."
468 :group 'org-agenda-custom-commands
469 :type 'character)
471 (defcustom org-stuck-projects
472 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
473 "How to identify stuck projects.
474 This is a list of four items:
475 1. A tags/todo/property matcher string that is used to identify a project.
476 See the manual for a description of tag and property searches.
477 The entire tree below a headline matched by this is considered one project.
478 2. A list of TODO keywords identifying non-stuck projects.
479 If the project subtree contains any headline with one of these todo
480 keywords, the project is considered to be not stuck. If you specify
481 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
482 3. A list of tags identifying non-stuck projects.
483 If the project subtree contains any headline with one of these tags,
484 the project is considered to be not stuck. If you specify \"*\" as
485 a tag, any tag will mark the project unstuck. Note that this is about
486 the explicit presence of a tag somewhere in the subtree, inherited
487 tags to not count here. If inherited tags make a project not stuck,
488 use \"-TAG\" in the tags part of the matcher under (1.) above.
489 4. An arbitrary regular expression matching non-stuck projects.
491 If the project turns out to be not stuck, search continues also in the
492 subtree to see if any of the subtasks have project status.
494 See also the variable `org-tags-match-list-sublevels' which applies
495 to projects matched by this search as well.
497 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
498 or `C-c a #' to produce the list."
499 :group 'org-agenda-custom-commands
500 :type '(list
501 (string :tag "Tags/TODO match to identify a project")
502 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
503 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
504 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
506 (defcustom org-agenda-filter-effort-default-operator "<"
507 "The default operator for effort estimate filtering.
508 If you select an effort estimate limit without first pressing an operator,
509 this one will be used."
510 :group 'org-agenda-custom-commands
511 :type '(choice (const :tag "less or equal" "<")
512 (const :tag "greater or equal"">")
513 (const :tag "equal" "=")))
515 (defgroup org-agenda-skip nil
516 "Options concerning skipping parts of agenda files."
517 :tag "Org Agenda Skip"
518 :group 'org-agenda)
520 (defcustom org-agenda-skip-function-global nil
521 "Function to be called at each match during agenda construction.
522 If this function returns nil, the current match should not be skipped.
523 If the function decided to skip an agenda match, is must return the
524 buffer position from which the search should be continued.
525 This may also be a Lisp form, which will be evaluated.
527 This variable will be applied to every agenda match, including
528 tags/property searches and TODO lists. So try to make the test function
529 do its checking as efficiently as possible. To implement a skipping
530 condition just for specific agenda commands, use the variable
531 `org-agenda-skip-function' which can be set in the options section
532 of custom agenda commands."
533 :group 'org-agenda-skip
534 :type 'sexp)
536 (defgroup org-agenda-daily/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag "Org Agenda Daily/Weekly"
539 :group 'org-agenda)
540 (defgroup org-agenda-todo-list nil
541 "Options concerning the global todo list agenda view."
542 :tag "Org Agenda Todo List"
543 :group 'org-agenda)
544 (defgroup org-agenda-match-view nil
545 "Options concerning the general tags/property/todo match agenda view."
546 :tag "Org Agenda Match View"
547 :group 'org-agenda)
548 (defgroup org-agenda-search-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
553 (defvar org-agenda-archives-mode nil
554 "Non-nil means the agenda will include archived items.
555 If this is the symbol `trees', trees in the selected agenda scope
556 that are marked with the ARCHIVE tag will be included anyway. When this is
557 t, also all archive files associated with the current selection of agenda
558 files will be included.")
560 (defcustom org-agenda-skip-comment-trees t
561 "Non-nil means skip trees that start with the COMMENT keyword.
562 When nil, these trees are also scanned by agenda commands."
563 :group 'org-agenda-skip
564 :type 'boolean)
566 (defcustom org-agenda-todo-list-sublevels t
567 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
568 When nil, the sublevels of a TODO entry are not checked, resulting in
569 potentially much shorter TODO lists."
570 :group 'org-agenda-skip
571 :group 'org-agenda-todo-list
572 :type 'boolean)
574 (defcustom org-agenda-todo-ignore-with-date nil
575 "Non-nil means don't show entries with a date in the global todo list.
576 You can use this if you prefer to mark mere appointments with a TODO keyword,
577 but don't want them to show up in the TODO list.
578 When this is set, it also covers deadlines and scheduled items, the settings
579 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
580 will be ignored.
581 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
582 :group 'org-agenda-skip
583 :group 'org-agenda-todo-list
584 :type 'boolean)
586 (defcustom org-agenda-todo-ignore-timestamp nil
587 "Non-nil means don't show entries with a timestamp.
588 This applies when creating the global todo list.
589 Valid values are:
591 past Don't show entries for today or in the past.
593 future Don't show entries with a timestamp in the future.
594 The idea behind this is that if it has a future
595 timestamp, you don't want to think about it until the
596 date.
598 all Don't show any entries with a timestamp in the global todo list.
599 The idea behind this is that by setting a timestamp, you
600 have already \"taken care\" of this item.
602 This variable can also have an integer as a value. If positive (N),
603 todos with a timestamp N or more days in the future will be ignored. If
604 negative (-N), todos with a timestamp N or more days in the past will be
605 ignored. If 0, todos with a timestamp either today or in the future will
606 be ignored. For example, a value of -1 will exclude todos with a
607 timestamp in the past (yesterday or earlier), while a value of 7 will
608 exclude todos with a timestamp a week or more in the future.
610 See also `org-agenda-todo-ignore-with-date'.
611 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
612 to make his option also apply to the tags-todo list."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type '(choice
616 (const :tag "Ignore future timestamp todos" future)
617 (const :tag "Ignore past or present timestamp todos" past)
618 (const :tag "Ignore all timestamp todos" all)
619 (const :tag "Show timestamp todos" nil)
620 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
622 (defcustom org-agenda-todo-ignore-scheduled nil
623 "Non-nil means, ignore some scheduled TODO items when making TODO list.
624 This applies when creating the global todo list.
625 Valid values are:
627 past Don't show entries scheduled today or in the past.
629 future Don't show entries scheduled in the future.
630 The idea behind this is that by scheduling it, you don't want to
631 think about it until the scheduled date.
633 all Don't show any scheduled entries in the global todo list.
634 The idea behind this is that by scheduling it, you have already
635 \"taken care\" of this item.
637 t Same as `all', for backward compatibility.
639 This variable can also have an integer as a value. See
640 `org-agenda-todo-ignore-timestamp' for more details.
642 See also `org-agenda-todo-ignore-with-date'.
643 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
644 to make his option also apply to the tags-todo list."
645 :group 'org-agenda-skip
646 :group 'org-agenda-todo-list
647 :type '(choice
648 (const :tag "Ignore future-scheduled todos" future)
649 (const :tag "Ignore past- or present-scheduled todos" past)
650 (const :tag "Ignore all scheduled todos" all)
651 (const :tag "Ignore all scheduled todos (compatibility)" t)
652 (const :tag "Show scheduled todos" nil)
653 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
655 (defcustom org-agenda-todo-ignore-deadlines nil
656 "Non-nil means ignore some deadlined TODO items when making TODO list.
657 There are different motivations for using different values, please think
658 carefully when configuring this variable.
660 This applies when creating the global todo list.
661 Valid values are:
663 near Don't show near deadline entries. A deadline is near when it is
664 closer than `org-deadline-warning-days' days. The idea behind this
665 is that such items will appear in the agenda anyway.
667 far Don't show TODO entries where a deadline has been defined, but
668 the deadline is not near. This is useful if you don't want to
669 use the todo list to figure out what to do now.
671 past Don't show entries with a deadline timestamp for today or in the past.
673 future Don't show entries with a deadline timestamp in the future, not even
674 when they become `near' ones. Use it with caution.
676 all Ignore all TODO entries that do have a deadline.
678 t Same as `near', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore near deadlines" near)
690 (const :tag "Ignore near deadlines (compatibility)" t)
691 (const :tag "Ignore far deadlines" far)
692 (const :tag "Ignore all TODOs with a deadlines" all)
693 (const :tag "Show all TODOs, even if they have a deadline" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-tags-todo-honor-ignore-options nil
697 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
698 The variables
699 `org-agenda-todo-ignore-with-date',
700 `org-agenda-todo-ignore-timestamp',
701 `org-agenda-todo-ignore-scheduled',
702 `org-agenda-todo-ignore-deadlines'
703 make the global TODO list skip entries that have time stamps of certain
704 kinds. If this option is set, the same options will also apply for the
705 tags-todo search, which is the general tags/property matcher
706 restricted to unfinished TODO entries only."
707 :group 'org-agenda-skip
708 :group 'org-agenda-todo-list
709 :group 'org-agenda-match-view
710 :type 'boolean)
712 (defcustom org-agenda-skip-scheduled-if-done nil
713 "Non-nil means don't show scheduled items in agenda when they are done.
714 This is relevant for the daily/weekly agenda, not for the TODO list. And
715 it applies only to the actual date of the scheduling. Warnings about
716 an item with a past scheduling dates are always turned off when the item
717 is DONE."
718 :group 'org-agenda-skip
719 :group 'org-agenda-daily/weekly
720 :type 'boolean)
722 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
723 "Non-nil means skip scheduling line if same entry shows because of deadline.
724 In the agenda of today, an entry can show up multiple times because
725 it is both scheduled and has a nearby deadline, and maybe a plain time
726 stamp as well.
727 When this variable is t, then only the deadline is shown and the fact that
728 the entry is scheduled today or was scheduled previously is not shown.
729 When this variable is nil, the entry will be shown several times. When
730 the variable is the symbol `not-today', then skip scheduled previously,
731 but not scheduled today."
732 :group 'org-agenda-skip
733 :group 'org-agenda-daily/weekly
734 :type '(choice
735 (const :tag "Never" nil)
736 (const :tag "Always" t)
737 (const :tag "Not when scheduled today" not-today)))
739 (defcustom org-agenda-skip-deadline-if-done nil
740 "Non-nil means don't show deadlines when the corresponding item is done.
741 When nil, the deadline is still shown and should give you a happy feeling.
742 This is relevant for the daily/weekly agenda. And it applied only to the
743 actually date of the deadline. Warnings about approaching and past-due
744 deadlines are always turned off when the item is DONE."
745 :group 'org-agenda-skip
746 :group 'org-agenda-daily/weekly
747 :type 'boolean)
749 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
750 "Non-nil means skip deadline prewarning when entry is also scheduled.
751 This will apply on all days where a prewarning for the deadline would
752 be shown, but not at the day when the entry is actually due. On that day,
753 the deadline will be shown anyway.
754 This variable may be set to nil, t, or a number which will then give
755 the number of days before the actual deadline when the prewarnings
756 should resume.
757 This can be used in a workflow where the first showing of the deadline will
758 trigger you to schedule it, and then you don't want to be reminded of it
759 because you will take care of it on the day when scheduled."
760 :group 'org-agenda-skip
761 :group 'org-agenda-daily/weekly
762 :type '(choice
763 (const :tag "Alwas show prewarning" nil)
764 (const :tag "Remove prewarning if entry is scheduled" t)
765 (integer :tag "Restart prewarning N days before deadline")))
767 (defcustom org-agenda-skip-additional-timestamps-same-entry t
768 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
769 When non-nil, after the search for timestamps has matched once in an
770 entry, the rest of the entry will not be searched."
771 :group 'org-agenda-skip
772 :type 'boolean)
774 (defcustom org-agenda-skip-timestamp-if-done nil
775 "Non-nil means don't select item by timestamp or -range if it is DONE."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type 'boolean)
780 (defcustom org-agenda-dim-blocked-tasks t
781 "Non-nil means dim blocked tasks in the agenda display.
782 This causes some overhead during agenda construction, but if you
783 have turned on `org-enforce-todo-dependencies',
784 `org-enforce-todo-checkbox-dependencies', or any other blocking
785 mechanism, this will create useful feedback in the agenda.
787 Instead of t, this variable can also have the value `invisible'.
788 Then blocked tasks will be invisible and only become visible when
789 they become unblocked. An exemption to this behavior is when a task is
790 blocked because of unchecked checkboxes below it. Since checkboxes do
791 not show up in the agenda views, making this task invisible you remove any
792 trace from agenda views that there is something to do. Therefore, a task
793 that is blocked because of checkboxes will never be made invisible, it
794 will only be dimmed."
795 :group 'org-agenda-daily/weekly
796 :group 'org-agenda-todo-list
797 :type '(choice
798 (const :tag "Do not dim" nil)
799 (const :tag "Dim to a grey face" t)
800 (const :tag "Make invisible" invisible)))
802 (defcustom org-timeline-show-empty-dates 3
803 "Non-nil means `org-timeline' also shows dates without an entry.
804 When nil, only the days which actually have entries are shown.
805 When t, all days between the first and the last date are shown.
806 When an integer, show also empty dates, but if there is a gap of more than
807 N days, just insert a special line indicating the size of the gap."
808 :group 'org-agenda-skip
809 :type '(choice
810 (const :tag "None" nil)
811 (const :tag "All" t)
812 (integer :tag "at most")))
814 (defgroup org-agenda-startup nil
815 "Options concerning initial settings in the Agenda in Org Mode."
816 :tag "Org Agenda Startup"
817 :group 'org-agenda)
819 (defcustom org-agenda-menu-show-matcher t
820 "Non-nil means show the match string in the agenda dispatcher menu.
821 When nil, the matcher string is not shown, but is put into the help-echo
822 property so than moving the mouse over the command shows it.
823 Setting it to nil is good if matcher strings are very long and/or if
824 you want to use two-column display (see `org-agenda-menu-two-column')."
825 :group 'org-agenda
826 :type 'boolean)
828 (defcustom org-agenda-menu-two-column nil
829 "Non-nil means, use two columns to show custom commands in the dispatcher.
830 If you use this, you probably want to set `org-agenda-menu-show-matcher'
831 to nil."
832 :group 'org-agenda
833 :type 'boolean)
835 (defcustom org-finalize-agenda-hook nil
836 "Hook run just before displaying an agenda buffer."
837 :group 'org-agenda-startup
838 :type 'hook)
840 (defcustom org-agenda-mouse-1-follows-link nil
841 "Non-nil means mouse-1 on a link will follow the link in the agenda.
842 A longer mouse click will still set point. Does not work on XEmacs.
843 Needs to be set before org.el is loaded."
844 :group 'org-agenda-startup
845 :type 'boolean)
847 (defcustom org-agenda-start-with-follow-mode nil
848 "The initial value of follow mode in a newly created agenda window."
849 :group 'org-agenda-startup
850 :type 'boolean)
852 (defcustom org-agenda-show-outline-path t
853 "Non-nil means show outline path in echo area after line motion."
854 :group 'org-agenda-startup
855 :type 'boolean)
857 (defcustom org-agenda-start-with-entry-text-mode nil
858 "The initial value of entry-text-mode in a newly created agenda window."
859 :group 'org-agenda-startup
860 :type 'boolean)
862 (defcustom org-agenda-entry-text-maxlines 5
863 "Number of text lines to be added when `E' is pressed in the agenda.
865 Note that this variable only used during agenda display. Add add entry text
866 when exporting the agenda, configure the variable
867 `org-agenda-add-entry-ext-maxlines'."
868 :group 'org-agenda
869 :type 'integer)
871 (defcustom org-agenda-entry-text-exclude-regexps nil
872 "List of regular expressions to clean up entry text.
873 The complete matches of all regular expressions in this list will be
874 removed from entry text before it is shown in the agenda."
875 :group 'org-agenda
876 :type '(repeat (regexp)))
878 (defvar org-agenda-entry-text-cleanup-hook nil
879 "Hook that is run after basic cleanup of entry text to be shown in agenda.
880 This cleanup is done in a temporary buffer, so the function may inspect and
881 change the entire buffer.
882 Some default stuff like drawers and scheduling/deadline dates will already
883 have been removed when this is called, as will any matches for regular
884 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
886 (defvar org-agenda-include-inactive-timestamps nil
887 "Non-nil means include inactive time stamps in agenda and timeline.")
889 (defgroup org-agenda-windows nil
890 "Options concerning the windows used by the Agenda in Org Mode."
891 :tag "Org Agenda Windows"
892 :group 'org-agenda)
894 (defcustom org-agenda-window-setup 'reorganize-frame
895 "How the agenda buffer should be displayed.
896 Possible values for this option are:
898 current-window Show agenda in the current window, keeping all other windows.
899 other-window Use `switch-to-buffer-other-window' to display agenda.
900 reorganize-frame Show only two windows on the current frame, the current
901 window and the agenda.
902 other-frame Use `switch-to-buffer-other-frame' to display agenda.
903 Also, when exiting the agenda, kill that frame.
904 See also the variable `org-agenda-restore-windows-after-quit'."
905 :group 'org-agenda-windows
906 :type '(choice
907 (const current-window)
908 (const other-frame)
909 (const other-window)
910 (const reorganize-frame)))
912 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
913 "The min and max height of the agenda window as a fraction of frame height.
914 The value of the variable is a cons cell with two numbers between 0 and 1.
915 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
916 :group 'org-agenda-windows
917 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
919 (defcustom org-agenda-restore-windows-after-quit nil
920 "Non-nil means restore window configuration upon exiting agenda.
921 Before the window configuration is changed for displaying the agenda,
922 the current status is recorded. When the agenda is exited with
923 `q' or `x' and this option is set, the old state is restored. If
924 `org-agenda-window-setup' is `other-frame', the value of this
925 option will be ignored."
926 :group 'org-agenda-windows
927 :type 'boolean)
929 (defcustom org-agenda-ndays nil
930 "Number of days to include in overview display.
931 Should be 1 or 7.
932 Obsolete, see `org-agenda-span'."
933 :group 'org-agenda-daily/weekly
934 :type 'integer)
936 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
938 (defcustom org-agenda-span 'week
939 "Number of days to include in overview display.
940 Can be day, week, month, year, or any number of days.
941 Custom commands can set this variable in the options section."
942 :group 'org-agenda-daily/weekly
943 :type '(choice (const :tag "Day" day)
944 (const :tag "Week" week)
945 (const :tag "Month" month)
946 (const :tag "Year" year)
947 (integer :tag "Custom")))
949 (defcustom org-agenda-start-on-weekday 1
950 "Non-nil means start the overview always on the specified weekday.
951 0 denotes Sunday, 1 denotes Monday etc.
952 When nil, always start on the current day.
953 Custom commands can set this variable in the options section."
954 :group 'org-agenda-daily/weekly
955 :type '(choice (const :tag "Today" nil)
956 (integer :tag "Weekday No.")))
958 (defcustom org-agenda-show-all-dates t
959 "Non-nil means `org-agenda' shows every day in the selected range.
960 When nil, only the days which actually have entries are shown."
961 :group 'org-agenda-daily/weekly
962 :type 'boolean)
964 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
965 "Format string for displaying dates in the agenda.
966 Used by the daily/weekly agenda and by the timeline. This should be
967 a format string understood by `format-time-string', or a function returning
968 the formatted date as a string. The function must take a single argument,
969 a calendar-style date list like (month day year)."
970 :group 'org-agenda-daily/weekly
971 :type '(choice
972 (string :tag "Format string")
973 (function :tag "Function")))
975 (defun org-agenda-format-date-aligned (date)
976 "Format a date string for display in the daily/weekly agenda, or timeline.
977 This function makes sure that dates are aligned for easy reading."
978 (require 'cal-iso)
979 (let* ((dayname (calendar-day-name date))
980 (day (cadr date))
981 (day-of-week (calendar-day-of-week date))
982 (month (car date))
983 (monthname (calendar-month-name month))
984 (year (nth 2 date))
985 (iso-week (org-days-to-iso-week
986 (calendar-absolute-from-gregorian date)))
987 (weekyear (cond ((and (= month 1) (>= iso-week 52))
988 (1- year))
989 ((and (= month 12) (<= iso-week 1))
990 (1+ year))
991 (t year)))
992 (weekstring (if (= day-of-week 1)
993 (format " W%02d" iso-week)
994 "")))
995 (format "%-10s %2d %s %4d%s"
996 dayname day monthname year weekstring)))
998 (defcustom org-agenda-time-leading-zero nil
999 "Non-nil means use leading zero for military times in agenda.
1000 For example, 9:30am would become 09:30 rather than 9:30."
1001 :group 'org-agenda-daily/weekly
1002 :type 'boolean)
1004 (defcustom org-agenda-timegrid-use-ampm nil
1005 "When set, show AM/PM style timestamps on the timegrid."
1006 :group 'org-agenda
1007 :type 'boolean)
1009 (defun org-agenda-time-of-day-to-ampm (time)
1010 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1011 (let* ((hour-number (string-to-number (substring time 0 -3)))
1012 (minute (substring time -2))
1013 (ampm "am"))
1014 (cond
1015 ((equal hour-number 12)
1016 (setq ampm "pm"))
1017 ((> hour-number 12)
1018 (setq ampm "pm")
1019 (setq hour-number (- hour-number 12))))
1020 (concat
1021 (if org-agenda-time-leading-zero
1022 (format "%02d" hour-number)
1023 (format "%02s" (number-to-string hour-number)))
1024 ":" minute ampm)))
1026 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1027 "Conditionally convert TIME to AM/PM format
1028 based on `org-agenda-timegrid-use-ampm'"
1029 (if org-agenda-timegrid-use-ampm
1030 (org-agenda-time-of-day-to-ampm time)
1031 time))
1033 (defcustom org-agenda-weekend-days '(6 0)
1034 "Which days are weekend?
1035 These days get the special face `org-agenda-date-weekend' in the agenda
1036 and timeline buffers."
1037 :group 'org-agenda-daily/weekly
1038 :type '(set :greedy t
1039 (const :tag "Monday" 1)
1040 (const :tag "Tuesday" 2)
1041 (const :tag "Wednesday" 3)
1042 (const :tag "Thursday" 4)
1043 (const :tag "Friday" 5)
1044 (const :tag "Saturday" 6)
1045 (const :tag "Sunday" 0)))
1047 (defcustom org-agenda-include-diary nil
1048 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1049 Custom commands can set this variable in the options section."
1050 :group 'org-agenda-daily/weekly
1051 :type 'boolean)
1053 (defcustom org-agenda-include-deadlines t
1054 "If non-nil, include entries within their deadline warning period.
1055 Custom commands can set this variable in the options section."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-include-all-todo nil
1060 "Set means weekly/daily agenda will always contain all TODO entries.
1061 The TODO entries will be listed at the top of the agenda, before
1062 the entries for specific days.
1063 This option is deprecated, it is better to define a block agenda instead."
1064 :group 'org-agenda-daily/weekly
1065 :type 'boolean)
1067 (defcustom org-agenda-repeating-timestamp-show-all t
1068 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1069 When set to a list of strings, only show occurrences of repeating
1070 stamps for these TODO keywords. When nil, only one occurrence is
1071 shown, either today or the nearest into the future."
1072 :group 'org-agenda-daily/weekly
1073 :type '(choice
1074 (const :tag "Show repeating stamps" t)
1075 (repeat :tag "Show repeating stamps for these TODO keywords"
1076 (string :tag "TODO Keyword"))
1077 (const :tag "Don't show repeating stamps" nil)))
1079 (defcustom org-scheduled-past-days 10000
1080 "No. of days to continue listing scheduled items that are not marked DONE.
1081 When an item is scheduled on a date, it shows up in the agenda on this
1082 day and will be listed until it is marked done for the number of days
1083 given here."
1084 :group 'org-agenda-daily/weekly
1085 :type 'integer)
1087 (defcustom org-agenda-log-mode-items '(closed clock)
1088 "List of items that should be shown in agenda log mode.
1089 This list may contain the following symbols:
1091 closed Show entries that have been closed on that day.
1092 clock Show entries that have received clocked time on that day.
1093 state Show all logged state changes.
1094 Note that instead of changing this variable, you can also press `C-u l' in
1095 the agenda to display all available LOG items temporarily."
1096 :group 'org-agenda-daily/weekly
1097 :type '(set :greedy t (const closed) (const clock) (const state)))
1099 (defcustom org-agenda-log-mode-add-notes t
1100 "Non-nil means add first line of notes to log entries in agenda views.
1101 If a log item like a state change or a clock entry is associated with
1102 notes, the first line of these notes will be added to the entry in the
1103 agenda display."
1104 :group 'org-agenda-daily/weekly
1105 :type 'boolean)
1107 (defcustom org-agenda-start-with-log-mode nil
1108 "The initial value of log-mode in a newly created agenda window."
1109 :group 'org-agenda-startup
1110 :group 'org-agenda-daily/weekly
1111 :type 'boolean)
1113 (defcustom org-agenda-start-with-clockreport-mode nil
1114 "The initial value of clockreport-mode in a newly created agenda window."
1115 :group 'org-agenda-startup
1116 :group 'org-agenda-daily/weekly
1117 :type 'boolean)
1119 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1120 "Property list with parameters for the clocktable in clockreport mode.
1121 This is the display mode that shows a clock table in the daily/weekly
1122 agenda, the properties for this dynamic block can be set here.
1123 The usual clocktable parameters are allowed here, but you cannot set
1124 the properties :name, :tstart, :tend, :block, and :scope - these will
1125 be overwritten to make sure the content accurately reflects the
1126 current display in the agenda."
1127 :group 'org-agenda-daily/weekly
1128 :type 'plist)
1130 (defcustom org-agenda-search-view-always-boolean nil
1131 "Non-nil means the search string is interpreted as individual parts.
1133 The search string for search view can either be interpreted as a phrase,
1134 or as a list of snippets that define a boolean search for a number of
1135 strings.
1137 When this is non-nil, the string will be split on whitespace, and each
1138 snippet will be searched individually, and all must match in order to
1139 select an entry. A snippet is then a single string of non-white
1140 characters, or a string in double quotes, or a regexp in {} braces.
1141 If a snippet is preceded by \"-\", the snippet must *not* match.
1142 \"+\" is syntactic sugar for positive selection. Each snippet may
1143 be found as a full word or a partial word, but see the variable
1144 `org-agenda-search-view-force-full-words'.
1146 When this is nil, search will look for the entire search phrase as one,
1147 with each space character matching any amount of whitespace, including
1148 line breaks.
1150 Even when this is nil, you can still switch to Boolean search dynamically
1151 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1152 is a regexp marked with braces like \"{abc}\", this will also switch to
1153 boolean search."
1154 :group 'org-agenda-search-view
1155 :type 'boolean)
1157 (if (fboundp 'defvaralias)
1158 (defvaralias 'org-agenda-search-view-search-words-only
1159 'org-agenda-search-view-always-boolean))
1161 (defcustom org-agenda-search-view-force-full-words nil
1162 "Non-nil means, search words must be matches as complete words.
1163 When nil, they may also match part of a word."
1164 :group 'org-agenda-search-view
1165 :type 'boolean)
1167 (defgroup org-agenda-time-grid nil
1168 "Options concerning the time grid in the Org-mode Agenda."
1169 :tag "Org Agenda Time Grid"
1170 :group 'org-agenda)
1172 (defcustom org-agenda-search-headline-for-time t
1173 "Non-nil means search headline for a time-of-day.
1174 If the headline contains a time-of-day in one format or another, it will
1175 be used to sort the entry into the time sequence of items for a day.
1176 Some people have time stamps in the headline that refer to the creation
1177 time or so, and then this produces an unwanted side effect. If this is
1178 the case for your, use this variable to turn off searching the headline
1179 for a time."
1180 :group 'org-agenda-time-grid
1181 :type 'boolean)
1183 (defcustom org-agenda-use-time-grid t
1184 "Non-nil means show a time grid in the agenda schedule.
1185 A time grid is a set of lines for specific times (like every two hours between
1186 8:00 and 20:00). The items scheduled for a day at specific times are
1187 sorted in between these lines.
1188 For details about when the grid will be shown, and what it will look like, see
1189 the variable `org-agenda-time-grid'."
1190 :group 'org-agenda-time-grid
1191 :type 'boolean)
1193 (defcustom org-agenda-time-grid
1194 '((daily today require-timed)
1195 "----------------"
1196 (800 1000 1200 1400 1600 1800 2000))
1198 "The settings for time grid for agenda display.
1199 This is a list of three items. The first item is again a list. It contains
1200 symbols specifying conditions when the grid should be displayed:
1202 daily if the agenda shows a single day
1203 weekly if the agenda shows an entire week
1204 today show grid on current date, independent of daily/weekly display
1205 require-timed show grid only if at least one item has a time specification
1207 The second item is a string which will be placed behind the grid time.
1209 The third item is a list of integers, indicating the times that should have
1210 a grid line."
1211 :group 'org-agenda-time-grid
1212 :type
1213 '(list
1214 (set :greedy t :tag "Grid Display Options"
1215 (const :tag "Show grid in single day agenda display" daily)
1216 (const :tag "Show grid in weekly agenda display" weekly)
1217 (const :tag "Always show grid for today" today)
1218 (const :tag "Show grid only if any timed entries are present"
1219 require-timed)
1220 (const :tag "Skip grid times already present in an entry"
1221 remove-match))
1222 (string :tag "Grid String")
1223 (repeat :tag "Grid Times" (integer :tag "Time"))))
1225 (defcustom org-agenda-show-current-time-in-grid t
1226 "Non-nil means show the current time in the time grid."
1227 :group 'org-agenda-time-grid
1228 :type 'boolean)
1230 (defcustom org-agenda-current-time-string
1231 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1232 "The string for the current time marker in the agenda."
1233 :group 'org-agenda-time-grid
1234 :type 'string)
1236 (defgroup org-agenda-sorting nil
1237 "Options concerning sorting in the Org-mode Agenda."
1238 :tag "Org Agenda Sorting"
1239 :group 'org-agenda)
1241 (defcustom org-agenda-sorting-strategy
1242 '((agenda habit-down time-up priority-down category-keep)
1243 (todo priority-down category-keep)
1244 (tags priority-down category-keep)
1245 (search category-keep))
1246 "Sorting structure for the agenda items of a single day.
1247 This is a list of symbols which will be used in sequence to determine
1248 if an entry should be listed before another entry. The following
1249 symbols are recognized:
1251 time-up Put entries with time-of-day indications first, early first
1252 time-down Put entries with time-of-day indications first, late first
1253 category-keep Keep the default order of categories, corresponding to the
1254 sequence in `org-agenda-files'.
1255 category-up Sort alphabetically by category, A-Z.
1256 category-down Sort alphabetically by category, Z-A.
1257 tag-up Sort alphabetically by last tag, A-Z.
1258 tag-down Sort alphabetically by last tag, Z-A.
1259 priority-up Sort numerically by priority, high priority last.
1260 priority-down Sort numerically by priority, high priority first.
1261 todo-state-up Sort by todo state, tasks that are done last.
1262 todo-state-down Sort by todo state, tasks that are done first.
1263 effort-up Sort numerically by estimated effort, high effort last.
1264 effort-down Sort numerically by estimated effort, high effort first.
1265 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1266 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1267 habit-up Put entries that are habits first
1268 habit-down Put entries that are habits last
1269 alpha-up Sort headlines alphabetically
1270 alpha-down Sort headlines alphabetically, reversed
1272 The different possibilities will be tried in sequence, and testing stops
1273 if one comparison returns a \"not-equal\". For example, the default
1274 '(time-up category-keep priority-down)
1275 means: Pull out all entries having a specified time of day and sort them,
1276 in order to make a time schedule for the current day the first thing in the
1277 agenda listing for the day. Of the entries without a time indication, keep
1278 the grouped in categories, don't sort the categories, but keep them in
1279 the sequence given in `org-agenda-files'. Within each category sort by
1280 priority.
1282 Leaving out `category-keep' would mean that items will be sorted across
1283 categories by priority.
1285 Instead of a single list, this can also be a set of list for specific
1286 contents, with a context symbol in the car of the list, any of
1287 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1289 Custom commands can bind this variable in the options section."
1290 :group 'org-agenda-sorting
1291 :type `(choice
1292 (repeat :tag "General" ,org-sorting-choice)
1293 (list :tag "Individually"
1294 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1295 (repeat ,org-sorting-choice))
1296 (cons (const :tag "Strategy for TODO lists" todo)
1297 (repeat ,org-sorting-choice))
1298 (cons (const :tag "Strategy for Tags matches" tags)
1299 (repeat ,org-sorting-choice))
1300 (cons (const :tag "Strategy for search matches" search)
1301 (repeat ,org-sorting-choice)))))
1303 (defcustom org-agenda-cmp-user-defined nil
1304 "A function to define the comparison `user-defined'.
1305 This function must receive two arguments, agenda entry a and b.
1306 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1307 the user comparison, return nil.
1308 When this is defined, you can make `user-defined-up' and `user-defined-down'
1309 part of an agenda sorting strategy."
1310 :group 'org-agenda-sorting
1311 :type 'symbol)
1313 (defcustom org-sort-agenda-notime-is-late t
1314 "Non-nil means items without time are considered late.
1315 This is only relevant for sorting. When t, items which have no explicit
1316 time like 15:30 will be considered as 99:01, i.e. later than any items which
1317 do have a time. When nil, the default time is before 0:00. You can use this
1318 option to decide if the schedule for today should come before or after timeless
1319 agenda entries."
1320 :group 'org-agenda-sorting
1321 :type 'boolean)
1323 (defcustom org-sort-agenda-noeffort-is-high t
1324 "Non-nil means items without effort estimate are sorted as high effort.
1325 This also applies when filtering an agenda view with respect to the
1326 < or > effort operator. Then, tasks with no effort defined will be treated
1327 as tasks with high effort.
1328 When nil, such items are sorted as 0 minutes effort."
1329 :group 'org-agenda-sorting
1330 :type 'boolean)
1332 (defgroup org-agenda-line-format nil
1333 "Options concerning the entry prefix in the Org-mode agenda display."
1334 :tag "Org Agenda Line Format"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-prefix-format
1338 '((agenda . " %i %-12:c%?-12t% s")
1339 (timeline . " % s")
1340 (todo . " %i %-12:c")
1341 (tags . " %i %-12:c")
1342 (search . " %i %-12:c"))
1343 "Format specifications for the prefix of items in the agenda views.
1344 An alist with four entries, for the different agenda types. The keys to the
1345 sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
1346 are format strings.
1347 This format works similar to a printf format, with the following meaning:
1349 %c the category of the item, \"Diary\" for entries from the diary, or
1350 as given by the CATEGORY keyword or derived from the file name.
1351 %i the icon category of the item, as give in
1352 `org-agenda-category-icon-alist'.
1353 %T the *last* tag of the item. Last because inherited tags come
1354 first in the list.
1355 %t the time-of-day specification if one applies to the entry, in the
1356 format HH:MM
1357 %s Scheduling/Deadline information, a short string
1358 %(expression) Eval EXPRESSION and replace the control string
1359 by the result
1361 All specifiers work basically like the standard `%s' of printf, but may
1362 contain two additional characters: A question mark just after the `%' and
1363 a whitespace/punctuation character just before the final letter.
1365 If the first character after `%' is a question mark, the entire field
1366 will only be included if the corresponding value applies to the
1367 current entry. This is useful for fields which should have fixed
1368 width when present, but zero width when absent. For example,
1369 \"%?-12t\" will result in a 12 character time field if a time of the
1370 day is specified, but will completely disappear in entries which do
1371 not contain a time.
1373 If there is punctuation or whitespace character just before the final
1374 format letter, this character will be appended to the field value if
1375 the value is not empty. For example, the format \"%-12:c\" leads to
1376 \"Diary: \" if the category is \"Diary\". If the category were be
1377 empty, no additional colon would be inserted.
1379 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1380 - Indent the line with two space characters
1381 - Give the category in a 12 chars wide field, padded with whitespace on
1382 the right (because of `-'). Append a colon if there is a category
1383 (because of `:').
1384 - If there is a time-of-day, put it into a 12 chars wide field. If no
1385 time, don't put in an empty field, just skip it (because of '?').
1386 - Finally, put the scheduling information and append a whitespace.
1388 As another example, if you don't want the time-of-day of entries in
1389 the prefix, you could use:
1391 (setq org-agenda-prefix-format \" %-11:c% s\")
1393 See also the variables `org-agenda-remove-times-when-in-prefix' and
1394 `org-agenda-remove-tags'.
1396 Custom commands can set this variable in the options section."
1397 :type '(choice
1398 (string :tag "General format")
1399 (list :greedy t :tag "View dependent"
1400 (cons (const agenda) (string :tag "Format"))
1401 (cons (const timeline) (string :tag "Format"))
1402 (cons (const todo) (string :tag "Format"))
1403 (cons (const tags) (string :tag "Format"))
1404 (cons (const search) (string :tag "Format"))))
1405 :group 'org-agenda-line-format)
1407 (defvar org-prefix-format-compiled nil
1408 "The compiled version of the most recently used prefix format.
1409 See the variable `org-agenda-prefix-format'.")
1411 (defcustom org-agenda-todo-keyword-format "%-1s"
1412 "Format for the TODO keyword in agenda lines.
1413 Set this to something like \"%-12s\" if you want all TODO keywords
1414 to occupy a fixed space in the agenda display."
1415 :group 'org-agenda-line-format
1416 :type 'string)
1418 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1419 "Text preceding timerange entries in the agenda view.
1420 This is a list with two strings. The first applies when the range
1421 is entirely on one day. The second applies if the range spans several days.
1422 The strings may have two \"%d\" format specifiers which will be filled
1423 with the sequence number of the days, and the total number of days in the
1424 range, respectively."
1425 :group 'org-agenda-line-format
1426 :type '(list
1427 (string :tag "Deadline today ")
1428 (choice :tag "Deadline relative"
1429 (string :tag "Format string")
1430 (function))))
1432 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1433 "Text preceding scheduled items in the agenda view.
1434 This is a list with two strings. The first applies when the item is
1435 scheduled on the current day. The second applies when it has been scheduled
1436 previously, it may contain a %d indicating that this is the nth time that
1437 this item is scheduled, due to automatic rescheduling of unfinished items
1438 for the following day. So this number is one larger than the number of days
1439 that passed since this item was scheduled first."
1440 :group 'org-agenda-line-format
1441 :type '(list
1442 (string :tag "Scheduled today ")
1443 (string :tag "Scheduled previously")))
1445 (defcustom org-agenda-inactive-leader "["
1446 "Text preceding item pulled into the agenda by inactive time stamps.
1447 These entries are added to the agenda when pressing \"[\"."
1448 :group 'org-agenda-line-format
1449 :type '(list
1450 (string :tag "Scheduled today ")
1451 (string :tag "Scheduled previously")))
1453 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1454 "Text preceding deadline items in the agenda view.
1455 This is a list with two strings. The first applies when the item has its
1456 deadline on the current day. The second applies when it is in the past or
1457 in the future, it may contain %d to capture how many days away the deadline
1458 is (was)."
1459 :group 'org-agenda-line-format
1460 :type '(list
1461 (string :tag "Deadline today ")
1462 (choice :tag "Deadline relative"
1463 (string :tag "Format string")
1464 (function))))
1466 (defcustom org-agenda-remove-times-when-in-prefix t
1467 "Non-nil means remove duplicate time specifications in agenda items.
1468 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1469 time-of-day specification in a headline or diary entry is extracted and
1470 placed into the prefix. If this option is non-nil, the original specification
1471 \(a timestamp or -range, or just a plain time(range) specification like
1472 11:30-4pm) will be removed for agenda display. This makes the agenda less
1473 cluttered.
1474 The option can be t or nil. It may also be the symbol `beg', indicating
1475 that the time should only be removed when it is located at the beginning of
1476 the headline/diary entry."
1477 :group 'org-agenda-line-format
1478 :type '(choice
1479 (const :tag "Always" t)
1480 (const :tag "Never" nil)
1481 (const :tag "When at beginning of entry" beg)))
1483 (defcustom org-agenda-remove-timeranges-from-blocks nil
1484 "Non-nil means remove time ranges specifications in agenda
1485 items that span on several days."
1486 :group 'org-agenda-line-format
1487 :type 'boolean)
1489 (defcustom org-agenda-default-appointment-duration nil
1490 "Default duration for appointments that only have a starting time.
1491 When nil, no duration is specified in such cases.
1492 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1493 :group 'org-agenda-line-format
1494 :type '(choice
1495 (integer :tag "Minutes")
1496 (const :tag "No default duration")))
1498 (defcustom org-agenda-show-inherited-tags t
1499 "Non-nil means show inherited tags in each agenda line."
1500 :group 'org-agenda-line-format
1501 :type 'boolean)
1503 (defcustom org-agenda-hide-tags-regexp nil
1504 "Regular expression used to filter away specific tags in agenda views.
1505 This means that these tags will be present, but not be shown in the agenda
1506 line. Secondary filtering will still work on the hidden tags.
1507 Nil means don't hide any tags."
1508 :group 'org-agenda-line-format
1509 :type '(choice
1510 (const :tag "Hide none" nil)
1511 (string :tag "Regexp ")))
1513 (defcustom org-agenda-remove-tags nil
1514 "Non-nil means remove the tags from the headline copy in the agenda.
1515 When this is the symbol `prefix', only remove tags when
1516 `org-agenda-prefix-format' contains a `%T' specifier."
1517 :group 'org-agenda-line-format
1518 :type '(choice
1519 (const :tag "Always" t)
1520 (const :tag "Never" nil)
1521 (const :tag "When prefix format contains %T" prefix)))
1523 (if (fboundp 'defvaralias)
1524 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1525 'org-agenda-remove-tags))
1527 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1528 "Shift tags in agenda items to this column.
1529 If this number is positive, it specifies the column. If it is negative,
1530 it means that the tags should be flushright to that column. For example,
1531 -80 works well for a normal 80 character screen."
1532 :group 'org-agenda-line-format
1533 :type 'integer)
1535 (if (fboundp 'defvaralias)
1536 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1538 (defcustom org-agenda-fontify-priorities 'cookies
1539 "Non-nil means highlight low and high priorities in agenda.
1540 When t, the highest priority entries are bold, lowest priority italic.
1541 However, settings in `org-priority-faces' will overrule these faces.
1542 When this variable is the symbol `cookies', only fontify the
1543 cookies, not the entire task.
1544 This may also be an association list of priority faces, whose
1545 keys are the character values of `org-highest-priority',
1546 `org-default-priority', and `org-lowest-priority' (the default values
1547 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1548 color as a string, or a list like `(:background \"Red\")'.
1549 If it is a color, the variable `org-faces-easy-properties'
1550 determines if it is a foreground or a background color."
1551 :group 'org-agenda-line-format
1552 :type '(choice
1553 (const :tag "Never" nil)
1554 (const :tag "Defaults" t)
1555 (const :tag "Cookies only" cookies)
1556 (repeat :tag "Specify"
1557 (list (character :tag "Priority" :value ?A)
1558 (choice :tag "Face "
1559 (string :tag "Color")
1560 (sexp :tag "Face"))))))
1562 (defcustom org-agenda-day-face-function nil
1563 "Function called to determine what face should be used to display a day.
1564 The only argument passed to that function is the day. It should
1565 returns a face, or nil if does not want to specify a face and let
1566 the normal rules apply."
1567 :group 'org-agenda-line-format
1568 :type 'function)
1570 (defcustom org-agenda-category-icon-alist nil
1571 "Alist of category icon to be displayed in agenda views.
1573 Each entry should have the following format:
1575 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1577 Where CATEGORY-REGEXP is a regexp matching the categories where
1578 the icon should be displayed.
1579 FILE-OR-DATA either a file path or a string containing image data.
1581 The other fields can be omited safely if not needed:
1582 TYPE indicates the image type.
1583 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1584 image data.
1585 PROPS are additional image attributes to assign to the image,
1586 like, e.g. `:ascent center'.
1588 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1590 If you want to set the display properties yourself, just put a
1591 list as second element:
1593 (CATEGORY-REGEXP (MY PROPERTY LIST))
1595 For example, to display a 16px horizontal space for Emacs
1596 category, you can use:
1598 (\"Emacs\" '(space . (:width (16))))"
1599 :group 'org-agenda-line-format
1600 :type '(alist :key-type (string :tag "Regexp matching category")
1601 :value-type (choice (list :tag "Icon"
1602 (string :tag "File or data")
1603 (symbol :tag "Type")
1604 (boolean :tag "Data?")
1605 (repeat :tag "Extra image properties" :inline t symbol))
1606 (list :tag "Display properties" sexp))))
1608 (defgroup org-agenda-column-view nil
1609 "Options concerning column view in the agenda."
1610 :tag "Org Agenda Column View"
1611 :group 'org-agenda)
1613 (defcustom org-agenda-columns-show-summaries t
1614 "Non-nil means show summaries for columns displayed in the agenda view."
1615 :group 'org-agenda-column-view
1616 :type 'boolean)
1618 (defcustom org-agenda-columns-compute-summary-properties t
1619 "Non-nil means recompute all summary properties before column view.
1620 When column view in the agenda is listing properties that have a summary
1621 operator, it can go to all relevant buffers and recompute the summaries
1622 there. This can mean overhead for the agenda column view, but is necessary
1623 to have thing up to date.
1624 As a special case, a CLOCKSUM property also makes sure that the clock
1625 computations are current."
1626 :group 'org-agenda-column-view
1627 :type 'boolean)
1629 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1630 "Non-nil means the duration of an appointment will add to day effort.
1631 The property to which appointment durations will be added is the one given
1632 in the option `org-effort-property'. If an appointment does not have
1633 an end time, `org-agenda-default-appointment-duration' will be used. If that
1634 is not set, an appointment without end time will not contribute to the time
1635 estimate."
1636 :group 'org-agenda-column-view
1637 :type 'boolean)
1639 (defcustom org-agenda-auto-exclude-function nil
1640 "A function called with a tag to decide if it is filtered on '/ RET'.
1641 The sole argument to the function, which is called once for each
1642 possible tag, is a string giving the name of the tag. The
1643 function should return either nil if the tag should be included
1644 as normal, or \"-<TAG>\" to exclude the tag.
1645 Note that for the purpose of tag filtering, only the lower-case version of
1646 all tags will be considered, so that this function will only ever see
1647 the lower-case version of all tags."
1648 :group 'org-agenda
1649 :type 'function)
1651 (eval-when-compile
1652 (require 'cl))
1653 (require 'org)
1655 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1656 "Execute BODY with point at location given by `org-hd-marker' property.
1657 If STRING is non-nil, the text property will be fetched from position 0
1658 in that string. If STRING is nil, it will be fetched from the beginning
1659 of the current line."
1660 `(let ((marker (get-text-property (if string 0 (point-at-bol))
1661 'org-hd-marker string)))
1662 (with-current-buffer (marker-buffer marker)
1663 (save-excursion
1664 (goto-char marker)
1665 ,@body))))
1667 (defun org-add-agenda-custom-command (entry)
1668 "Replace or add a command in `org-agenda-custom-commands'.
1669 This is mostly for hacking and trying a new command - once the command
1670 works you probably want to add it to `org-agenda-custom-commands' for good."
1671 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1672 (if ass
1673 (setcdr ass (cdr entry))
1674 (push entry org-agenda-custom-commands))))
1676 ;;; Define the Org-agenda-mode
1678 (defvar org-agenda-mode-map (make-sparse-keymap)
1679 "Keymap for `org-agenda-mode'.")
1680 (if (fboundp 'defvaralias)
1681 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1683 (defvar org-agenda-menu) ; defined later in this file.
1684 (defvar org-agenda-restrict) ; defined later in this file.
1685 (defvar org-agenda-follow-mode nil)
1686 (defvar org-agenda-entry-text-mode nil)
1687 (defvar org-agenda-clockreport-mode nil)
1688 (defvar org-agenda-show-log nil)
1689 (defvar org-agenda-redo-command nil)
1690 (defvar org-agenda-query-string nil)
1691 (defvar org-agenda-mode-hook nil
1692 "Hook for `org-agenda-mode', run after the mode is turned on.")
1693 (defvar org-agenda-type nil)
1694 (defvar org-agenda-force-single-file nil)
1695 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1697 (defun org-agenda-mode ()
1698 "Mode for time-sorted view on action items in Org-mode files.
1700 The following commands are available:
1702 \\{org-agenda-mode-map}"
1703 (interactive)
1704 (kill-all-local-variables)
1705 (setq org-agenda-undo-list nil
1706 org-agenda-pending-undo-list nil
1707 org-agenda-bulk-marked-entries nil)
1708 (setq major-mode 'org-agenda-mode)
1709 ;; Keep global-font-lock-mode from turning on font-lock-mode
1710 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1711 (setq mode-name "Org-Agenda")
1712 (use-local-map org-agenda-mode-map)
1713 (easy-menu-add org-agenda-menu)
1714 (if org-startup-truncated (setq truncate-lines t))
1715 (org-set-local 'line-move-visual nil)
1716 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1717 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1718 ;; Make sure properties are removed when copying text
1719 (when (boundp 'buffer-substring-filters)
1720 (org-set-local 'buffer-substring-filters
1721 (cons (lambda (x)
1722 (set-text-properties 0 (length x) nil x) x)
1723 buffer-substring-filters)))
1724 (unless org-agenda-keep-modes
1725 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1726 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1727 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1728 org-agenda-show-log org-agenda-start-with-log-mode))
1730 (easy-menu-change
1731 '("Agenda") "Agenda Files"
1732 (append
1733 (list
1734 (vector
1735 (if (get 'org-agenda-files 'org-restrict)
1736 "Restricted to single file"
1737 "Edit File List")
1738 '(org-edit-agenda-file-list)
1739 (not (get 'org-agenda-files 'org-restrict)))
1740 "--")
1741 (mapcar 'org-file-menu-entry (org-agenda-files))))
1742 (org-agenda-set-mode-name)
1743 (apply
1744 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1745 (list 'org-agenda-mode-hook)))
1747 (substitute-key-definition 'undo 'org-agenda-undo
1748 org-agenda-mode-map global-map)
1749 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1750 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1751 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1752 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1753 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1754 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1755 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1756 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1757 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1758 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
1759 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1760 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1761 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1762 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1763 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1764 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1765 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1766 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1767 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1768 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1769 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1770 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1771 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1772 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1773 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1774 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1775 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1776 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1777 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1778 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1779 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1780 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1781 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1782 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1783 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1784 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1785 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1786 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1787 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1788 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1789 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1790 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1791 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1792 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1793 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1795 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1796 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1797 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1798 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1799 (while l (org-defkey org-agenda-mode-map
1800 (int-to-string (pop l)) 'digit-argument)))
1802 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1803 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1804 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1805 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1806 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1807 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1808 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1809 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1810 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1811 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1812 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1813 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1814 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1815 'org-clock-modify-effort-estimate)
1816 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1817 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1818 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1819 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1820 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1821 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1822 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1823 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1824 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1825 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1826 (substitute-key-definition 'next-line 'org-agenda-next-line
1827 org-agenda-mode-map global-map)
1828 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1829 org-agenda-mode-map global-map)
1830 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1831 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1832 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1833 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1834 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1835 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1836 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1837 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1838 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1839 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1840 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1841 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1842 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1843 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1844 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1845 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1846 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1847 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1848 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1849 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1850 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1851 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1852 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1853 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1854 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1855 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1856 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1857 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1858 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1859 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1861 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1862 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1863 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1864 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1865 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1866 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1867 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1868 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1869 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1870 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1872 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1873 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1874 (when org-agenda-mouse-1-follows-link
1875 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1876 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1877 '("Agenda"
1878 ("Agenda Files")
1879 "--"
1880 ("Agenda Dates"
1881 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1882 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1883 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1884 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1885 "--"
1886 ("View"
1887 ["Day View" org-agenda-day-view
1888 :active (org-agenda-check-type nil 'agenda)
1889 :style radio :selected (eq org-agenda-current-span 'day)
1890 :keys "v d (or just d)"]
1891 ["Week View" org-agenda-week-view
1892 :active (org-agenda-check-type nil 'agenda)
1893 :style radio :selected (eq org-agenda-current-span 'week)
1894 :keys "v w (or just w)"]
1895 ["Month View" org-agenda-month-view
1896 :active (org-agenda-check-type nil 'agenda)
1897 :style radio :selected (eq org-agenda-current-span 'month)
1898 :keys "v m"]
1899 ["Year View" org-agenda-year-view
1900 :active (org-agenda-check-type nil 'agenda)
1901 :style radio :selected (eq org-agenda-current-span 'year)
1902 :keys "v y"]
1903 "--"
1904 ["Include Diary" org-agenda-toggle-diary
1905 :style toggle :selected org-agenda-include-diary
1906 :active (org-agenda-check-type nil 'agenda)]
1907 ["Include Deadlines" org-agenda-toggle-deadlines
1908 :style toggle :selected org-agenda-include-deadlines
1909 :active (org-agenda-check-type nil 'agenda)]
1910 ["Use Time Grid" org-agenda-toggle-time-grid
1911 :style toggle :selected org-agenda-use-time-grid
1912 :active (org-agenda-check-type nil 'agenda)]
1913 "--"
1914 ["Show clock report" org-agenda-clockreport-mode
1915 :style toggle :selected org-agenda-clockreport-mode
1916 :active (org-agenda-check-type nil 'agenda)]
1917 ["Show some entry text" org-agenda-entry-text-mode
1918 :style toggle :selected org-agenda-entry-text-mode
1919 :active t]
1920 "--"
1921 ["Show Logbook entries" org-agenda-log-mode
1922 :style toggle :selected org-agenda-show-log
1923 :active (org-agenda-check-type nil 'agenda 'timeline)
1924 :keys "v l (or just l)"]
1925 ["Include archived trees" org-agenda-archives-mode
1926 :style toggle :selected org-agenda-archives-mode :active t
1927 :keys "v a"]
1928 ["Include archive files" (org-agenda-archives-mode t)
1929 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1930 :keys "v A"]
1931 "--"
1932 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1933 ["Write view to file" org-write-agenda t]
1934 ["Rebuild buffer" org-agenda-redo t]
1935 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1936 "--"
1937 ["Show original entry" org-agenda-show t]
1938 ["Go To (other window)" org-agenda-goto t]
1939 ["Go To (this window)" org-agenda-switch-to t]
1940 ["Follow Mode" org-agenda-follow-mode
1941 :style toggle :selected org-agenda-follow-mode :active t]
1942 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1943 "--"
1944 ("TODO"
1945 ["Cycle TODO" org-agenda-todo t]
1946 ["Next TODO set" org-agenda-todo-nextset t]
1947 ["Previous TODO set" org-agenda-todo-previousset t]
1948 ["Add note" org-agenda-add-note t])
1949 ("Archive/Refile/Delete"
1950 ["Archive default" org-agenda-archive-default t]
1951 ["Archive default" org-agenda-archive-default-with-confirmation t]
1952 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1953 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1954 ["Archive subtree" org-agenda-archive t]
1955 "--"
1956 ["Refile" org-agenda-refile t]
1957 "--"
1958 ["Delete subtree" org-agenda-kill t])
1959 ("Bulk action"
1960 ["Mark entry" org-agenda-bulk-mark t]
1961 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
1962 ["Unmark entry" org-agenda-bulk-unmark t]
1963 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1964 ["Act on all marked" org-agenda-bulk-action t]
1965 "--"
1966 ("Tags and Properties"
1967 ["Show all Tags" org-agenda-show-tags t]
1968 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1969 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1970 "--"
1971 ["Column View" org-columns t])
1972 ("Deadline/Schedule"
1973 ["Schedule" org-agenda-schedule t]
1974 ["Set Deadline" org-agenda-deadline t]
1975 "--"
1976 ["Mark item" org-agenda-action :active t :keys "k m"]
1977 ["Show mark item" org-agenda-action :active t :keys "k v"]
1978 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1979 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1980 "--"
1981 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1982 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1983 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1984 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1985 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1986 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1987 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1988 ("Clock and Effort"
1989 ["Clock in" org-agenda-clock-in t]
1990 ["Clock out" org-agenda-clock-out t]
1991 ["Clock cancel" org-agenda-clock-cancel t]
1992 ["Goto running clock" org-clock-goto t]
1993 "--"
1994 ["Set Effort" org-agenda-set-effort t]
1995 ["Change clocked effort" org-clock-modify-effort-estimate
1996 (org-clock-is-active)])
1997 ("Priority"
1998 ["Set Priority" org-agenda-priority t]
1999 ["Increase Priority" org-agenda-priority-up t]
2000 ["Decrease Priority" org-agenda-priority-down t]
2001 ["Show Priority" org-agenda-show-priority t])
2002 ("Calendar/Diary"
2003 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2004 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2005 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2006 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2007 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2008 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2009 "--"
2010 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2011 "--"
2012 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2013 "--"
2014 ("MobileOrg"
2015 ["Push Files and Views" org-mobile-push t]
2016 ["Get Captured and Flagged" org-mobile-pull t]
2017 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2018 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2019 "--"
2020 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2021 "--"
2022 ["Quit" org-agenda-quit t]
2023 ["Exit and Release Buffers" org-agenda-exit t]
2026 ;;; Agenda undo
2028 (defvar org-agenda-allow-remote-undo t
2029 "Non-nil means allow remote undo from the agenda buffer.")
2030 (defvar org-agenda-undo-list nil
2031 "List of undoable operations in the agenda since last refresh.")
2032 (defvar org-agenda-undo-has-started-in nil
2033 "Buffers that have already seen `undo-start' in the current undo sequence.")
2034 (defvar org-agenda-pending-undo-list nil
2035 "In a series of undo commands, this is the list of remaining undo items.")
2037 (defun org-agenda-undo ()
2038 "Undo a remote editing step in the agenda.
2039 This undoes changes both in the agenda buffer and in the remote buffer
2040 that have been changed along."
2041 (interactive)
2042 (or org-agenda-allow-remote-undo
2043 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2044 (if (not (eq this-command last-command))
2045 (setq org-agenda-undo-has-started-in nil
2046 org-agenda-pending-undo-list org-agenda-undo-list))
2047 (if (not org-agenda-pending-undo-list)
2048 (error "No further undo information"))
2049 (let* ((entry (pop org-agenda-pending-undo-list))
2050 buf line cmd rembuf)
2051 (setq cmd (pop entry) line (pop entry))
2052 (setq rembuf (nth 2 entry))
2053 (org-with-remote-undo rembuf
2054 (while (bufferp (setq buf (pop entry)))
2055 (if (pop entry)
2056 (with-current-buffer buf
2057 (let ((last-undo-buffer buf)
2058 (inhibit-read-only t))
2059 (unless (memq buf org-agenda-undo-has-started-in)
2060 (push buf org-agenda-undo-has-started-in)
2061 (make-local-variable 'pending-undo-list)
2062 (undo-start))
2063 (while (and pending-undo-list
2064 (listp pending-undo-list)
2065 (not (car pending-undo-list)))
2066 (pop pending-undo-list))
2067 (undo-more 1))))))
2068 (org-goto-line line)
2069 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2071 (defun org-verify-change-for-undo (l1 l2)
2072 "Verify that a real change occurred between the undo lists L1 and L2."
2073 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2074 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2075 (not (eq l1 l2)))
2077 ;;; Agenda dispatch
2079 (defvar org-agenda-restrict nil)
2080 (defvar org-agenda-restrict-begin (make-marker))
2081 (defvar org-agenda-restrict-end (make-marker))
2082 (defvar org-agenda-last-dispatch-buffer nil)
2083 (defvar org-agenda-overriding-restriction nil)
2085 ;;;###autoload
2086 (defun org-agenda (&optional arg keys restriction)
2087 "Dispatch agenda commands to collect entries to the agenda buffer.
2088 Prompts for a command to execute. Any prefix arg will be passed
2089 on to the selected command. The default selections are:
2091 a Call `org-agenda-list' to display the agenda for current day or week.
2092 t Call `org-todo-list' to display the global todo list.
2093 T Call `org-todo-list' to display the global todo list, select only
2094 entries with a specific TODO keyword (the user gets a prompt).
2095 m Call `org-tags-view' to display headlines with tags matching
2096 a condition (the user is prompted for the condition).
2097 M Like `m', but select only TODO entries, no ordinary headlines.
2098 L Create a timeline for the current buffer.
2099 e Export views to associated files.
2100 s Search entries for keywords.
2101 / Multi occur across all agenda files and also files listed
2102 in `org-agenda-text-search-extra-files'.
2103 < Restrict agenda commands to buffer, subtree, or region.
2104 Press several times to get the desired effect.
2105 > Remove a previous restriction.
2106 # List \"stuck\" projects.
2107 ! Configure what \"stuck\" means.
2108 C Configure custom agenda commands.
2110 More commands can be added by configuring the variable
2111 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2112 searches can be pre-defined in this way.
2114 If the current buffer is in Org-mode and visiting a file, you can also
2115 first press `<' once to indicate that the agenda should be temporarily
2116 \(until the next use of \\[org-agenda]) restricted to the current file.
2117 Pressing `<' twice means to restrict to the current subtree or region
2118 \(if active)."
2119 (interactive "P")
2120 (catch 'exit
2121 (let* ((prefix-descriptions nil)
2122 (org-agenda-window-setup (if (equal (buffer-name)
2123 org-agenda-buffer-name)
2124 'current-window
2125 org-agenda-window-setup))
2126 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2127 (org-agenda-custom-commands
2128 ;; normalize different versions
2129 (delq nil
2130 (mapcar
2131 (lambda (x)
2132 (cond ((stringp (cdr x))
2133 (push x prefix-descriptions)
2134 nil)
2135 ((stringp (nth 1 x)) x)
2136 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2137 (t (cons (car x) (cons "" (cdr x))))))
2138 org-agenda-custom-commands)))
2139 (buf (current-buffer))
2140 (bfn (buffer-file-name (buffer-base-buffer)))
2141 entry key type match lprops ans)
2142 ;; Turn off restriction unless there is an overriding one,
2143 (unless org-agenda-overriding-restriction
2144 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2145 ;; There is a request to keep the file list in place
2146 (put 'org-agenda-files 'org-restrict nil))
2147 (setq org-agenda-restrict nil)
2148 (move-marker org-agenda-restrict-begin nil)
2149 (move-marker org-agenda-restrict-end nil))
2150 ;; Delete old local properties
2151 (put 'org-agenda-redo-command 'org-lprops nil)
2152 ;; Delete previously set last-arguments
2153 (put 'org-agenda-redo-command 'last-args nil)
2154 ;; Remember where this call originated
2155 (setq org-agenda-last-dispatch-buffer (current-buffer))
2156 (unless keys
2157 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2158 keys (car ans)
2159 restriction (cdr ans)))
2160 ;; Establish the restriction, if any
2161 (when (and (not org-agenda-overriding-restriction) restriction)
2162 (put 'org-agenda-files 'org-restrict (list bfn))
2163 (cond
2164 ((eq restriction 'region)
2165 (setq org-agenda-restrict t)
2166 (move-marker org-agenda-restrict-begin (region-beginning))
2167 (move-marker org-agenda-restrict-end (region-end)))
2168 ((eq restriction 'subtree)
2169 (save-excursion
2170 (setq org-agenda-restrict t)
2171 (org-back-to-heading t)
2172 (move-marker org-agenda-restrict-begin (point))
2173 (move-marker org-agenda-restrict-end
2174 (progn (org-end-of-subtree t)))))))
2176 ;; For example the todo list should not need it (but does...)
2177 (cond
2178 ((setq entry (assoc keys org-agenda-custom-commands))
2179 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2180 (progn
2181 (setq type (nth 2 entry) match (eval (nth 3 entry))
2182 lprops (nth 4 entry))
2183 (put 'org-agenda-redo-command 'org-lprops lprops)
2184 (cond
2185 ((eq type 'agenda)
2186 (org-let lprops '(org-agenda-list current-prefix-arg)))
2187 ((eq type 'alltodo)
2188 (org-let lprops '(org-todo-list current-prefix-arg)))
2189 ((eq type 'search)
2190 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2191 ((eq type 'stuck)
2192 (org-let lprops '(org-agenda-list-stuck-projects
2193 current-prefix-arg)))
2194 ((eq type 'tags)
2195 (org-let lprops '(org-tags-view current-prefix-arg match)))
2196 ((eq type 'tags-todo)
2197 (org-let lprops '(org-tags-view '(4) match)))
2198 ((eq type 'todo)
2199 (org-let lprops '(org-todo-list match)))
2200 ((eq type 'tags-tree)
2201 (org-check-for-org-mode)
2202 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2203 ((eq type 'todo-tree)
2204 (org-check-for-org-mode)
2205 (org-let lprops
2206 '(org-occur (concat "^" outline-regexp "[ \t]*"
2207 (regexp-quote match) "\\>"))))
2208 ((eq type 'occur-tree)
2209 (org-check-for-org-mode)
2210 (org-let lprops '(org-occur match)))
2211 ((functionp type)
2212 (org-let lprops '(funcall type match)))
2213 ((fboundp type)
2214 (org-let lprops '(funcall type match)))
2215 (t (error "Invalid custom agenda command type %s" type))))
2216 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2217 ((equal keys "C")
2218 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2219 (customize-variable 'org-agenda-custom-commands))
2220 ((equal keys "a") (call-interactively 'org-agenda-list))
2221 ((equal keys "s") (call-interactively 'org-search-view))
2222 ((equal keys "t") (call-interactively 'org-todo-list))
2223 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2224 ((equal keys "m") (call-interactively 'org-tags-view))
2225 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2226 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2227 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2228 (org-add-hook
2229 'post-command-hook
2230 (lambda ()
2231 (unless (current-message)
2232 (let* ((m (org-agenda-get-any-marker))
2233 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2234 (when note
2235 (message (concat
2236 "FLAGGING-NOTE ([?] for more info): "
2237 (org-add-props
2238 (replace-regexp-in-string
2239 "\\\\n" "//"
2240 (copy-sequence note))
2241 nil 'face 'org-warning)))))))
2242 t t))
2243 ((equal keys "L")
2244 (unless (org-mode-p)
2245 (error "This is not an Org-mode file"))
2246 (unless restriction
2247 (put 'org-agenda-files 'org-restrict (list bfn))
2248 (org-call-with-arg 'org-timeline arg)))
2249 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2250 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2251 ((equal keys "!") (customize-variable 'org-stuck-projects))
2252 (t (error "Invalid agenda key"))))))
2254 (defun org-agenda-append-agenda ()
2255 "Append another agenda view to the current one.
2256 This function allows interactive building of block agendas.
2257 Agenda views are separated by `org-agenda-block-separator'."
2258 (interactive)
2259 (unless (string= (buffer-name) org-agenda-buffer-name)
2260 (error "Can only append from within agenda buffer"))
2261 (let ((org-agenda-multi t))
2262 (org-agenda)
2263 (widen)))
2265 (defun org-agenda-normalize-custom-commands (cmds)
2266 (delq nil
2267 (mapcar
2268 (lambda (x)
2269 (cond ((stringp (cdr x)) nil)
2270 ((stringp (nth 1 x)) x)
2271 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2272 (t (cons (car x) (cons "" (cdr x))))))
2273 cmds)))
2275 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2276 "The user interface for selecting an agenda command."
2277 (catch 'exit
2278 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2279 (restrict-ok (and bfn (org-mode-p)))
2280 (region-p (org-region-active-p))
2281 (custom org-agenda-custom-commands)
2282 (selstring "")
2283 restriction second-time
2284 c entry key type match prefixes rmheader header-end custom1 desc
2285 line lines left right n n1)
2286 (save-window-excursion
2287 (delete-other-windows)
2288 (org-switch-to-buffer-other-window " *Agenda Commands*")
2289 (erase-buffer)
2290 (insert (eval-when-compile
2291 (let ((header
2293 Press key for an agenda command: < Buffer, subtree/region restriction
2294 -------------------------------- > Remove restriction
2295 a Agenda for current week or day e Export agenda views
2296 t List of all TODO entries T Entries with special TODO kwd
2297 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2298 L Timeline for current buffer # List stuck projects (!=configure)
2299 s Search for keywords C Configure custom agenda commands
2300 / Multi-occur ? Find :FLAGGED: entries
2302 (start 0))
2303 (while (string-match
2304 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2305 header start)
2306 (setq start (match-end 0))
2307 (add-text-properties (match-beginning 2) (match-end 2)
2308 '(face bold) header))
2309 header)))
2310 (setq header-end (move-marker (make-marker) (point)))
2311 (while t
2312 (setq custom1 custom)
2313 (when (eq rmheader t)
2314 (org-goto-line 1)
2315 (re-search-forward ":" nil t)
2316 (delete-region (match-end 0) (point-at-eol))
2317 (forward-char 1)
2318 (looking-at "-+")
2319 (delete-region (match-end 0) (point-at-eol))
2320 (move-marker header-end (match-end 0)))
2321 (goto-char header-end)
2322 (delete-region (point) (point-max))
2324 ;; Produce all the lines that describe custom commands and prefixes
2325 (setq lines nil)
2326 (while (setq entry (pop custom1))
2327 (setq key (car entry) desc (nth 1 entry)
2328 type (nth 2 entry)
2329 match (nth 3 entry))
2330 (if (> (length key) 1)
2331 (add-to-list 'prefixes (string-to-char key))
2332 (setq line
2333 (format
2334 "%-4s%-14s"
2335 (org-add-props (copy-sequence key)
2336 '(face bold))
2337 (cond
2338 ((string-match "\\S-" desc) desc)
2339 ((eq type 'agenda) "Agenda for current week or day")
2340 ((eq type 'alltodo) "List of all TODO entries")
2341 ((eq type 'search) "Word search")
2342 ((eq type 'stuck) "List of stuck projects")
2343 ((eq type 'todo) "TODO keyword")
2344 ((eq type 'tags) "Tags query")
2345 ((eq type 'tags-todo) "Tags (TODO)")
2346 ((eq type 'tags-tree) "Tags tree")
2347 ((eq type 'todo-tree) "TODO kwd tree")
2348 ((eq type 'occur-tree) "Occur tree")
2349 ((functionp type) (if (symbolp type)
2350 (symbol-name type)
2351 "Lambda expression"))
2352 (t "???"))))
2353 (if org-agenda-menu-show-matcher
2354 (setq line
2355 (concat line ": "
2356 (cond
2357 ((stringp match)
2358 (setq match (copy-sequence match))
2359 (org-add-props match nil 'face 'org-warning))
2360 (match
2361 (format "set of %d commands" (length match)))
2362 (t ""))))
2363 (if (org-string-nw-p match)
2364 (add-text-properties
2365 0 (length line) (list 'help-echo
2366 (concat "Matcher: "match)) line)))
2367 (push line lines)))
2368 (setq lines (nreverse lines))
2369 (when prefixes
2370 (mapc (lambda (x)
2371 (push
2372 (format "%s %s"
2373 (org-add-props (char-to-string x)
2374 nil 'face 'bold)
2375 (or (cdr (assoc (concat selstring
2376 (char-to-string x))
2377 prefix-descriptions))
2378 "Prefix key"))
2379 lines))
2380 prefixes))
2382 ;; Check if we should display in two columns
2383 (if org-agenda-menu-two-column
2384 (progn
2385 (setq n (length lines)
2386 n1 (+ (/ n 2) (mod n 2))
2387 right (nthcdr n1 lines)
2388 left (copy-sequence lines))
2389 (setcdr (nthcdr (1- n1) left) nil))
2390 (setq left lines right nil))
2391 (while left
2392 (insert "\n" (pop left))
2393 (when right
2394 (if (< (current-column) 40)
2395 (move-to-column 40 t)
2396 (insert " "))
2397 (insert (pop right))))
2399 ;; Make the window the right size
2400 (goto-char (point-min))
2401 (if second-time
2402 (if (not (pos-visible-in-window-p (point-max)))
2403 (org-fit-window-to-buffer))
2404 (setq second-time t)
2405 (org-fit-window-to-buffer))
2407 ;; Ask for selection
2408 (message "Press key for agenda command%s:"
2409 (if (or restrict-ok org-agenda-overriding-restriction)
2410 (if org-agenda-overriding-restriction
2411 " (restriction lock active)"
2412 (if restriction
2413 (format " (restricted to %s)" restriction)
2414 " (unrestricted)"))
2415 ""))
2416 (setq c (read-char-exclusive))
2417 (message "")
2418 (cond
2419 ((assoc (char-to-string c) custom)
2420 (setq selstring (concat selstring (char-to-string c)))
2421 (throw 'exit (cons selstring restriction)))
2422 ((memq c prefixes)
2423 (setq selstring (concat selstring (char-to-string c))
2424 prefixes nil
2425 rmheader (or rmheader t)
2426 custom (delq nil (mapcar
2427 (lambda (x)
2428 (if (or (= (length (car x)) 1)
2429 (/= (string-to-char (car x)) c))
2431 (cons (substring (car x) 1) (cdr x))))
2432 custom))))
2433 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2434 (message "Restriction is only possible in Org-mode buffers")
2435 (ding) (sit-for 1))
2436 ((eq c ?1)
2437 (org-agenda-remove-restriction-lock 'noupdate)
2438 (setq restriction 'buffer))
2439 ((eq c ?0)
2440 (org-agenda-remove-restriction-lock 'noupdate)
2441 (setq restriction (if region-p 'region 'subtree)))
2442 ((eq c ?<)
2443 (org-agenda-remove-restriction-lock 'noupdate)
2444 (setq restriction
2445 (cond
2446 ((eq restriction 'buffer)
2447 (if region-p 'region 'subtree))
2448 ((memq restriction '(subtree region))
2449 nil)
2450 (t 'buffer))))
2451 ((eq c ?>)
2452 (org-agenda-remove-restriction-lock 'noupdate)
2453 (setq restriction nil))
2454 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2455 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2456 ((and (> (length selstring) 0) (eq c ?\d))
2457 (delete-window)
2458 (org-agenda-get-restriction-and-command prefix-descriptions))
2460 ((equal c ?q) (error "Abort"))
2461 (t (error "Invalid key %c" c))))))))
2463 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2464 (defvar org-agenda-last-arguments nil
2465 "The arguments of the previous call to `org-agenda'.")
2466 (defun org-agenda-run-series (name series)
2467 (org-let (nth 1 series) '(org-prepare-agenda name))
2468 (let* ((org-agenda-multi t)
2469 (redo (list 'org-agenda-run-series name (list 'quote series)))
2470 (org-agenda-overriding-arguments
2471 (or org-agenda-overriding-arguments
2472 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2473 (get 'org-agenda-redo-command 'last-args))))
2474 (cmds (car series))
2475 (gprops (nth 1 series))
2476 match ;; The byte compiler incorrectly complains about this. Keep it!
2477 cmd type lprops)
2478 (while (setq cmd (pop cmds))
2479 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2480 (cond
2481 ((eq type 'agenda)
2482 (org-let2 gprops lprops
2483 '(call-interactively 'org-agenda-list)))
2484 ((eq type 'alltodo)
2485 (org-let2 gprops lprops
2486 '(call-interactively 'org-todo-list)))
2487 ((eq type 'search)
2488 (org-let2 gprops lprops
2489 '(org-search-view current-prefix-arg match nil)))
2490 ((eq type 'stuck)
2491 (org-let2 gprops lprops
2492 '(call-interactively 'org-agenda-list-stuck-projects)))
2493 ((eq type 'tags)
2494 (org-let2 gprops lprops
2495 '(org-tags-view current-prefix-arg match)))
2496 ((eq type 'tags-todo)
2497 (org-let2 gprops lprops
2498 '(org-tags-view '(4) match)))
2499 ((eq type 'todo)
2500 (org-let2 gprops lprops
2501 '(org-todo-list match)))
2502 ((fboundp type)
2503 (org-let2 gprops lprops
2504 '(funcall type match)))
2505 (t (error "Invalid type in command series"))))
2506 (widen)
2507 (setq org-agenda-redo-command redo)
2508 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2509 (goto-char (point-min)))
2510 (org-fit-agenda-window)
2511 (org-let (nth 1 series) '(org-finalize-agenda)))
2513 ;;;###autoload
2514 (defmacro org-batch-agenda (cmd-key &rest parameters)
2515 "Run an agenda command in batch mode and send the result to STDOUT.
2516 If CMD-KEY is a string of length 1, it is used as a key in
2517 `org-agenda-custom-commands' and triggers this command. If it is a
2518 longer string it is used as a tags/todo match string.
2519 Parameters are alternating variable names and values that will be bound
2520 before running the agenda command."
2521 (let (pars)
2522 (while parameters
2523 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2524 (if (> (length cmd-key) 2)
2525 (eval (list 'let (nreverse pars)
2526 (list 'org-tags-view nil cmd-key)))
2527 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2528 (set-buffer org-agenda-buffer-name)
2529 (princ (org-encode-for-stdout (buffer-string)))))
2531 ;(defun org-encode-for-stdout (string)
2532 ; (if (fboundp 'encode-coding-string)
2533 ; (encode-coding-string string buffer-file-coding-system)
2534 ; string))
2536 (defun org-encode-for-stdout (string)
2537 string)
2539 (defvar org-agenda-info nil)
2541 ;;;###autoload
2542 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2543 "Run an agenda command in batch mode and send the result to STDOUT.
2544 If CMD-KEY is a string of length 1, it is used as a key in
2545 `org-agenda-custom-commands' and triggers this command. If it is a
2546 longer string it is used as a tags/todo match string.
2547 Parameters are alternating variable names and values that will be bound
2548 before running the agenda command.
2550 The output gives a line for each selected agenda item. Each
2551 item is a list of comma-separated values, like this:
2553 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2555 category The category of the item
2556 head The headline, without TODO kwd, TAGS and PRIORITY
2557 type The type of the agenda entry, can be
2558 todo selected in TODO match
2559 tagsmatch selected in tags match
2560 diary imported from diary
2561 deadline a deadline on given date
2562 scheduled scheduled on given date
2563 timestamp entry has timestamp on given date
2564 closed entry was closed on given date
2565 upcoming-deadline warning about deadline
2566 past-scheduled forwarded scheduled item
2567 block entry has date block including g. date
2568 todo The todo keyword, if any
2569 tags All tags including inherited ones, separated by colons
2570 date The relevant date, like 2007-2-14
2571 time The time, like 15:00-16:50
2572 extra Sting with extra planning info
2573 priority-l The priority letter if any was given
2574 priority-n The computed numerical priority
2575 agenda-day The day in the agenda where this is listed"
2577 (let (pars)
2578 (while parameters
2579 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2580 (push (list 'org-agenda-remove-tags t) pars)
2581 (if (> (length cmd-key) 2)
2582 (eval (list 'let (nreverse pars)
2583 (list 'org-tags-view nil cmd-key)))
2584 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2585 (set-buffer org-agenda-buffer-name)
2586 (let* ((lines (org-split-string (buffer-string) "\n"))
2587 line)
2588 (while (setq line (pop lines))
2589 (catch 'next
2590 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2591 (setq org-agenda-info
2592 (org-fix-agenda-info (text-properties-at 0 line)))
2593 (princ
2594 (org-encode-for-stdout
2595 (mapconcat 'org-agenda-export-csv-mapper
2596 '(org-category txt type todo tags date time extra
2597 priority-letter priority agenda-day)
2598 ",")))
2599 (princ "\n"))))))
2601 (defun org-fix-agenda-info (props)
2602 "Make sure all properties on an agenda item have a canonical form.
2603 This ensures the export commands can easily use it."
2604 (let (tmp re)
2605 (when (setq tmp (plist-get props 'tags))
2606 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2607 (when (setq tmp (plist-get props 'date))
2608 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2609 (let ((calendar-date-display-form '(year "-" month "-" day)))
2610 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2612 (setq tmp (calendar-date-string tmp)))
2613 (setq props (plist-put props 'date tmp)))
2614 (when (setq tmp (plist-get props 'day))
2615 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2616 (let ((calendar-date-display-form '(year "-" month "-" day)))
2617 (setq tmp (calendar-date-string tmp)))
2618 (setq props (plist-put props 'day tmp))
2619 (setq props (plist-put props 'agenda-day tmp)))
2620 (when (setq tmp (plist-get props 'txt))
2621 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2622 (plist-put props 'priority-letter (match-string 1 tmp))
2623 (setq tmp (replace-match "" t t tmp)))
2624 (when (and (setq re (plist-get props 'org-todo-regexp))
2625 (setq re (concat "\\`\\.*" re " ?"))
2626 (string-match re tmp))
2627 (plist-put props 'todo (match-string 1 tmp))
2628 (setq tmp (replace-match "" t t tmp)))
2629 (plist-put props 'txt tmp)))
2630 props)
2632 (defun org-agenda-export-csv-mapper (prop)
2633 (let ((res (plist-get org-agenda-info prop)))
2634 (setq res
2635 (cond
2636 ((not res) "")
2637 ((stringp res) res)
2638 (t (prin1-to-string res))))
2639 (while (string-match "," res)
2640 (setq res (replace-match ";" t t res)))
2641 (org-trim res)))
2644 ;;;###autoload
2645 (defun org-store-agenda-views (&rest parameters)
2646 (interactive)
2647 (eval (list 'org-batch-store-agenda-views)))
2649 ;; FIXME, why is this a macro?????
2650 ;;;###autoload
2651 (defmacro org-batch-store-agenda-views (&rest parameters)
2652 "Run all custom agenda commands that have a file argument."
2653 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2654 (pop-up-frames nil)
2655 (dir default-directory)
2656 pars cmd thiscmdkey files opts cmd-or-set)
2657 (while parameters
2658 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2659 (setq pars (reverse pars))
2660 (save-window-excursion
2661 (while cmds
2662 (setq cmd (pop cmds)
2663 thiscmdkey (car cmd)
2664 cmd-or-set (nth 2 cmd)
2665 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2666 files (nth (if (listp cmd-or-set) 4 5) cmd))
2667 (if (stringp files) (setq files (list files)))
2668 (when files
2669 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2670 (list 'org-agenda nil thiscmdkey)))
2671 (set-buffer org-agenda-buffer-name)
2672 (while files
2673 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2674 (list 'org-write-agenda
2675 (expand-file-name (pop files) dir) nil t))))
2676 (and (get-buffer org-agenda-buffer-name)
2677 (kill-buffer org-agenda-buffer-name)))))))
2679 (defun org-agenda-mark-header-line (pos)
2680 "Mark the line at POS as an agenda structure header."
2681 (save-excursion
2682 (goto-char pos)
2683 (put-text-property (point-at-bol) (point-at-eol)
2684 'org-agenda-structural-header t)
2685 (when org-agenda-title-append
2686 (put-text-property (point-at-bol) (point-at-eol)
2687 'org-agenda-title-append org-agenda-title-append))))
2689 (defvar org-mobile-creating-agendas)
2690 (defun org-write-agenda (file &optional open nosettings)
2691 "Write the current buffer (an agenda view) as a file.
2692 Depending on the extension of the file name, plain text (.txt),
2693 HTML (.html or .htm) or Postscript (.ps) is produced.
2694 If the extension is .ics, run icalendar export over all files used
2695 to construct the agenda and limit the export to entries listed in the
2696 agenda now.
2697 With prefix argument OPEN, open the new file immediately.
2698 If NOSETTINGS is given, do not scope the settings of
2699 `org-agenda-exporter-settings' into the export commands. This is used when
2700 the settings have already been scoped and we do not wish to overrule other,
2701 higher priority settings."
2702 (interactive "FWrite agenda to file: \nP")
2703 (if (not (file-writable-p file))
2704 (error "Cannot write agenda to file %s" file))
2705 (org-let (if nosettings nil org-agenda-exporter-settings)
2706 '(save-excursion
2707 (save-window-excursion
2708 (org-agenda-mark-filtered-text)
2709 (let ((bs (copy-sequence (buffer-string))) beg)
2710 (org-agenda-unmark-filtered-text)
2711 (with-temp-buffer
2712 (rename-buffer "Agenda View" t)
2713 (set-buffer-modified-p nil)
2714 (insert bs)
2715 (org-agenda-remove-marked-text 'org-filtered)
2716 (while (setq beg (text-property-any (point-min) (point-max)
2717 'org-filtered t))
2718 (delete-region
2719 beg (or (next-single-property-change beg 'org-filtered)
2720 (point-max))))
2721 (run-hooks 'org-agenda-before-write-hook)
2722 (cond
2723 ((org-bound-and-true-p org-mobile-creating-agendas)
2724 (org-mobile-write-agenda-for-mobile file))
2725 ((string-match "\\.html?\\'" file)
2726 (require 'htmlize)
2727 (set-buffer (htmlize-buffer (current-buffer)))
2729 (when (and org-agenda-export-html-style
2730 (string-match "<style>" org-agenda-export-html-style))
2731 ;; replace <style> section with org-agenda-export-html-style
2732 (goto-char (point-min))
2733 (kill-region (- (search-forward "<style") 6)
2734 (search-forward "</style>"))
2735 (insert org-agenda-export-html-style))
2736 (write-file file)
2737 (kill-buffer (current-buffer))
2738 (message "HTML written to %s" file))
2739 ((string-match "\\.ps\\'" file)
2740 (require 'ps-print)
2741 (ps-print-buffer-with-faces file)
2742 (message "Postscript written to %s" file))
2743 ((string-match "\\.pdf\\'" file)
2744 (require 'ps-print)
2745 (ps-print-buffer-with-faces
2746 (concat (file-name-sans-extension file) ".ps"))
2747 (call-process "ps2pdf" nil nil nil
2748 (expand-file-name
2749 (concat (file-name-sans-extension file) ".ps"))
2750 (expand-file-name file))
2751 (delete-file (concat (file-name-sans-extension file) ".ps"))
2752 (message "PDF written to %s" file))
2753 ((string-match "\\.ics\\'" file)
2754 (require 'org-icalendar)
2755 (let ((org-agenda-marker-table
2756 (org-create-marker-find-array
2757 (org-agenda-collect-markers)))
2758 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2759 (org-combined-agenda-icalendar-file file))
2760 (apply 'org-export-icalendar 'combine
2761 (org-agenda-files nil 'ifmode))))
2763 (let ((bs (buffer-string)))
2764 (find-file file)
2765 (erase-buffer)
2766 (insert bs)
2767 (save-buffer 0)
2768 (kill-buffer (current-buffer))
2769 (message "Plain text written to %s" file))))))))
2770 (set-buffer org-agenda-buffer-name))
2771 (when open (org-open-file file)))
2773 (defvar org-agenda-filter-overlays nil)
2775 (defun org-agenda-mark-filtered-text ()
2776 "Mark all text hidden by filtering with a text property."
2777 (let ((inhibit-read-only t))
2778 (mapc
2779 (lambda (o)
2780 (when (equal (overlay-buffer o) (current-buffer))
2781 (put-text-property
2782 (overlay-start o) (overlay-end o)
2783 'org-filtered t)))
2784 org-agenda-filter-overlays)))
2786 (defun org-agenda-unmark-filtered-text ()
2787 "Remove the filtering text property."
2788 (let ((inhibit-read-only t))
2789 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2791 (defun org-agenda-remove-marked-text (property &optional value)
2792 "Delete all text marked with VALUE of PROPERTY.
2793 VALUE defaults to t."
2794 (let (beg)
2795 (setq value (or value t))
2796 (while (setq beg (text-property-any (point-min) (point-max)
2797 property value))
2798 (delete-region
2799 beg (or (next-single-property-change beg 'org-filtered)
2800 (point-max))))))
2802 (defun org-agenda-add-entry-text ()
2803 "Add entry text to agenda lines.
2804 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2805 entry text following headings shown in the agenda.
2806 Drawers will be excluded, also the line with scheduling/deadline info."
2807 (when (and (> org-agenda-add-entry-text-maxlines 0)
2808 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2809 (let (m txt)
2810 (goto-char (point-min))
2811 (while (not (eobp))
2812 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2813 (beginning-of-line 2)
2814 (setq txt (org-agenda-get-some-entry-text
2815 m org-agenda-add-entry-text-maxlines " > "))
2816 (end-of-line 1)
2817 (if (string-match "\\S-" txt)
2818 (insert "\n" txt)
2819 (or (eobp) (forward-char 1))))))))
2821 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2822 &rest keep)
2823 "Extract entry text from MARKER, at most N-LINES lines.
2824 This will ignore drawers etc, just get the text.
2825 If INDENT is given, prefix every line with this string. If KEEP is
2826 given, it is a list of symbols, defining stuff that should not be
2827 removed from the entry content. Currently only `planning' is allowed here."
2828 (let (txt drawer-re kwd-time-re ind)
2829 (save-excursion
2830 (with-current-buffer (marker-buffer marker)
2831 (if (not (org-mode-p))
2832 (setq txt "")
2833 (save-excursion
2834 (save-restriction
2835 (widen)
2836 (goto-char marker)
2837 (end-of-line 1)
2838 (setq txt (buffer-substring
2839 (min (1+ (point)) (point-max))
2840 (progn (outline-next-heading) (point)))
2841 drawer-re org-drawer-regexp
2842 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2843 ".*\n?"))
2844 (with-temp-buffer
2845 (insert txt)
2846 (when org-agenda-add-entry-text-descriptive-links
2847 (goto-char (point-min))
2848 (while (org-activate-bracket-links (point-max))
2849 (add-text-properties (match-beginning 0) (match-end 0)
2850 '(face org-link))))
2851 (goto-char (point-min))
2852 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2853 (set-text-properties (match-beginning 0) (match-end 0)
2854 nil))
2855 (goto-char (point-min))
2856 (while (re-search-forward drawer-re nil t)
2857 (delete-region
2858 (match-beginning 0)
2859 (progn (re-search-forward
2860 "^[ \t]*:END:.*\n?" nil 'move)
2861 (point))))
2862 (unless (member 'planning keep)
2863 (goto-char (point-min))
2864 (while (re-search-forward kwd-time-re nil t)
2865 (replace-match "")))
2866 (goto-char (point-min))
2867 (when org-agenda-entry-text-exclude-regexps
2868 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2869 (while (setq re (pop re-list))
2870 (goto-char (point-min))
2871 (while (re-search-forward re nil t)
2872 (replace-match "")))))
2873 (goto-char (point-max))
2874 (skip-chars-backward " \t\n")
2875 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2877 ;; find and remove min common indentation
2878 (goto-char (point-min))
2879 (untabify (point-min) (point-max))
2880 (setq ind (org-get-indentation))
2881 (while (not (eobp))
2882 (unless (looking-at "[ \t]*$")
2883 (setq ind (min ind (org-get-indentation))))
2884 (beginning-of-line 2))
2885 (goto-char (point-min))
2886 (while (not (eobp))
2887 (unless (looking-at "[ \t]*$")
2888 (move-to-column ind)
2889 (delete-region (point-at-bol) (point)))
2890 (beginning-of-line 2))
2892 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2894 (goto-char (point-min))
2895 (when indent
2896 (while (and (not (eobp)) (re-search-forward "^" nil t))
2897 (replace-match indent t t)))
2898 (goto-char (point-min))
2899 (while (looking-at "[ \t]*\n") (replace-match ""))
2900 (goto-char (point-max))
2901 (when (> (org-current-line)
2902 n-lines)
2903 (org-goto-line (1+ n-lines))
2904 (backward-char 1))
2905 (setq txt (buffer-substring (point-min) (point)))))))))
2906 txt))
2908 (defun org-agenda-collect-markers ()
2909 "Collect the markers pointing to entries in the agenda buffer."
2910 (let (m markers)
2911 (save-excursion
2912 (goto-char (point-min))
2913 (while (not (eobp))
2914 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2915 (org-get-at-bol 'org-marker)))
2916 (push m markers))
2917 (beginning-of-line 2)))
2918 (nreverse markers)))
2920 (defun org-create-marker-find-array (marker-list)
2921 "Create a alist of files names with all marker positions in that file."
2922 (let (f tbl m a p)
2923 (while (setq m (pop marker-list))
2924 (setq p (marker-position m)
2925 f (buffer-file-name (or (buffer-base-buffer
2926 (marker-buffer m))
2927 (marker-buffer m))))
2928 (if (setq a (assoc f tbl))
2929 (push (marker-position m) (cdr a))
2930 (push (list f p) tbl)))
2931 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2932 tbl)))
2934 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2935 (defun org-check-agenda-marker-table ()
2936 "Check of the current entry is on the marker list."
2937 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2939 (and (setq a (assoc file org-agenda-marker-table))
2940 (save-match-data
2941 (save-excursion
2942 (org-back-to-heading t)
2943 (member (point) (cdr a)))))))
2945 (defun org-check-for-org-mode ()
2946 "Make sure current buffer is in org-mode. Error if not."
2947 (or (org-mode-p)
2948 (error "Cannot execute org-mode agenda command on buffer in %s"
2949 major-mode)))
2951 (defun org-fit-agenda-window ()
2952 "Fit the window to the buffer size."
2953 (and (memq org-agenda-window-setup '(reorganize-frame))
2954 (fboundp 'fit-window-to-buffer)
2955 (org-fit-window-to-buffer
2957 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2958 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2960 ;;; Agenda prepare and finalize
2962 (defvar org-agenda-multi nil) ; dynamically scoped
2963 (defvar org-agenda-buffer-name "*Org Agenda*")
2964 (defvar org-pre-agenda-window-conf nil)
2965 (defvar org-agenda-columns-active nil)
2966 (defvar org-agenda-name nil)
2967 (defvar org-agenda-filter nil)
2968 (defvar org-agenda-filter-while-redo nil)
2969 (defvar org-agenda-filter-preset nil
2970 "A preset of the tags filter used for secondary agenda filtering.
2971 This must be a list of strings, each string must be a single tag preceded
2972 by \"+\" or \"-\".
2973 This variable should not be set directly, but agenda custom commands can
2974 bind it in the options section. The preset filter is a global property of
2975 the entire agenda view. In a block agenda, it will not work reliably to
2976 define a filter for one of the individual blocks. You need to set it in
2977 the global options and expect it to be applied to the entire view.")
2979 (defun org-prepare-agenda (&optional name)
2980 (setq org-todo-keywords-for-agenda nil)
2981 (setq org-done-keywords-for-agenda nil)
2982 (setq org-drawers-for-agenda nil)
2983 (unless org-agenda-persistent-filter
2984 (setq org-agenda-filter nil))
2985 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2986 (if org-agenda-multi
2987 (progn
2988 (setq buffer-read-only nil)
2989 (goto-char (point-max))
2990 (unless (or (bobp) org-agenda-compact-blocks)
2991 (insert "\n"
2992 (if (stringp org-agenda-block-separator)
2993 org-agenda-block-separator
2994 (make-string (window-width) org-agenda-block-separator))
2995 "\n"))
2996 (narrow-to-region (point) (point-max)))
2997 (org-agenda-reset-markers)
2998 (setq org-agenda-contributing-files nil)
2999 (setq org-agenda-columns-active nil)
3000 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3001 (setq org-todo-keywords-for-agenda
3002 (org-uniquify org-todo-keywords-for-agenda))
3003 (setq org-done-keywords-for-agenda
3004 (org-uniquify org-done-keywords-for-agenda))
3005 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3006 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3007 (awin (get-buffer-window abuf)))
3008 (cond
3009 ((equal (current-buffer) abuf) nil)
3010 (awin (select-window awin))
3011 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3012 ((equal org-agenda-window-setup 'current-window)
3013 (switch-to-buffer abuf))
3014 ((equal org-agenda-window-setup 'other-window)
3015 (org-switch-to-buffer-other-window abuf))
3016 ((equal org-agenda-window-setup 'other-frame)
3017 (switch-to-buffer-other-frame abuf))
3018 ((equal org-agenda-window-setup 'reorganize-frame)
3019 (delete-other-windows)
3020 (org-switch-to-buffer-other-window abuf)))
3021 ;; additional test in case agenda is invoked from within agenda
3022 ;; buffer via elisp link
3023 (unless (equal (current-buffer) abuf)
3024 (switch-to-buffer abuf)))
3025 (setq buffer-read-only nil)
3026 (let ((inhibit-read-only t)) (erase-buffer))
3027 (org-agenda-mode)
3028 (and name (not org-agenda-name)
3029 (org-set-local 'org-agenda-name name)))
3030 (setq buffer-read-only nil))
3032 (defun org-finalize-agenda ()
3033 "Finishing touch for the agenda buffer, called just before displaying it."
3034 (unless org-agenda-multi
3035 (save-excursion
3036 (let ((inhibit-read-only t))
3037 (goto-char (point-min))
3038 (while (org-activate-bracket-links (point-max))
3039 (add-text-properties (match-beginning 0) (match-end 0)
3040 '(face org-link)))
3041 (org-agenda-align-tags)
3042 (unless org-agenda-with-colors
3043 (remove-text-properties (point-min) (point-max) '(face nil))))
3044 (if (and (boundp 'org-agenda-overriding-columns-format)
3045 org-agenda-overriding-columns-format)
3046 (org-set-local 'org-agenda-overriding-columns-format
3047 org-agenda-overriding-columns-format))
3048 (if (and (boundp 'org-agenda-view-columns-initially)
3049 org-agenda-view-columns-initially)
3050 (org-agenda-columns))
3051 (when org-agenda-fontify-priorities
3052 (org-agenda-fontify-priorities))
3053 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3054 (org-agenda-dim-blocked-tasks))
3055 (org-agenda-mark-clocking-task)
3056 (when org-agenda-entry-text-mode
3057 (org-agenda-entry-text-hide)
3058 (org-agenda-entry-text-show))
3059 (if (functionp 'org-habit-insert-consistency-graphs)
3060 (org-habit-insert-consistency-graphs))
3061 (run-hooks 'org-finalize-agenda-hook)
3062 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3063 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3064 (org-agenda-filter-apply org-agenda-filter))
3067 (defun org-agenda-mark-clocking-task ()
3068 "Mark the current clock entry in the agenda if it is present."
3069 (mapc (lambda (o)
3070 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3071 (delete-overlay o)))
3072 (overlays-in (point-min) (point-max)))
3073 (when (marker-buffer org-clock-hd-marker)
3074 (save-excursion
3075 (goto-char (point-min))
3076 (let (s ov)
3077 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3078 (goto-char s)
3079 (when (equal (org-get-at-bol 'org-hd-marker)
3080 org-clock-hd-marker)
3081 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3082 (overlay-put ov 'type 'org-agenda-clocking)
3083 (overlay-put ov 'face 'org-agenda-clocking)
3084 (overlay-put ov 'help-echo
3085 "The clock is running in this item")))))))
3087 (defun org-agenda-fontify-priorities ()
3088 "Make highest priority lines bold, and lowest italic."
3089 (interactive)
3090 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3091 (delete-overlay o)))
3092 (overlays-in (point-min) (point-max)))
3093 (save-excursion
3094 (let ((inhibit-read-only t)
3095 b e p ov h l)
3096 (goto-char (point-min))
3097 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3098 (setq h (or (get-char-property (point) 'org-highest-priority)
3099 org-highest-priority)
3100 l (or (get-char-property (point) 'org-lowest-priority)
3101 org-lowest-priority)
3102 p (string-to-char (match-string 1))
3103 b (match-beginning 0)
3104 e (if (eq org-agenda-fontify-priorities 'cookies)
3105 (match-end 0)
3106 (point-at-eol))
3107 ov (make-overlay b e))
3108 (overlay-put
3109 ov 'face
3110 (cond ((org-face-from-face-or-color
3111 'priority nil
3112 (cdr (assoc p org-priority-faces))))
3113 ((and (listp org-agenda-fontify-priorities)
3114 (org-face-from-face-or-color
3115 'priority nil
3116 (cdr (assoc p org-agenda-fontify-priorities)))))
3117 ((equal p l) 'italic)
3118 ((equal p h) 'bold)))
3119 (overlay-put ov 'org-type 'org-priority)))))
3121 (defun org-agenda-dim-blocked-tasks ()
3122 "Dim currently blocked TODO's in the agenda display."
3123 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3124 (delete-overlay o)))
3125 (overlays-in (point-min) (point-max)))
3126 (save-excursion
3127 (let ((inhibit-read-only t)
3128 (org-depend-tag-blocked nil)
3129 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3130 org-blocked-by-checkboxes
3131 invis1 b e p ov h l)
3132 (goto-char (point-min))
3133 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3134 (and pos (goto-char (1+ pos))))
3135 (setq org-blocked-by-checkboxes nil invis1 invis)
3136 (let ((marker (org-get-at-bol 'org-hd-marker)))
3137 (when (and marker
3138 (not (with-current-buffer (marker-buffer marker)
3139 (save-excursion
3140 (goto-char marker)
3141 (if (org-entry-get nil "NOBLOCKING")
3142 t ;; Never block this entry
3143 (run-hook-with-args-until-failure
3144 'org-blocker-hook
3145 (list :type 'todo-state-change
3146 :position marker
3147 :from 'todo
3148 :to 'done)))))))
3149 (if org-blocked-by-checkboxes (setq invis1 nil))
3150 (setq b (if invis1
3151 (max (point-min) (1- (point-at-bol)))
3152 (point-at-bol))
3153 e (point-at-eol)
3154 ov (make-overlay b e))
3155 (if invis1
3156 (overlay-put ov 'invisible t)
3157 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3158 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3160 (defvar org-agenda-skip-function nil
3161 "Function to be called at each match during agenda construction.
3162 If this function returns nil, the current match should not be skipped.
3163 Otherwise, the function must return a position from where the search
3164 should be continued.
3165 This may also be a Lisp form, it will be evaluated.
3166 Never set this variable using `setq' or so, because then it will apply
3167 to all future agenda commands. If you do want a global skipping condition,
3168 use the option `org-agenda-skip-function-global' instead.
3169 The correct usage for `org-agenda-skip-function' is to bind it with
3170 `let' to scope it dynamically into the agenda-constructing command.
3171 A good way to set it is through options in `org-agenda-custom-commands'.")
3173 (defun org-agenda-skip ()
3174 "Throw to `:skip' in places that should be skipped.
3175 Also moves point to the end of the skipped region, so that search can
3176 continue from there."
3177 (let ((p (point-at-bol)) to)
3178 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3179 (get-text-property p :org-archived)
3180 (org-end-of-subtree t)
3181 (throw :skip t))
3182 (and org-agenda-skip-comment-trees
3183 (get-text-property p :org-comment)
3184 (org-end-of-subtree t)
3185 (throw :skip t))
3186 (if (equal (char-after p) ?#) (throw :skip t))
3187 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3188 (org-agenda-skip-eval org-agenda-skip-function)))
3189 (goto-char to)
3190 (throw :skip t))))
3192 (defun org-agenda-skip-eval (form)
3193 "If FORM is a function or a list, call (or eval) is and return result.
3194 `save-excursion' and `save-match-data' are wrapped around the call, so point
3195 and match data are returned to the previous state no matter what these
3196 functions do."
3197 (let (fp)
3198 (and form
3199 (or (setq fp (functionp form))
3200 (consp form))
3201 (save-excursion
3202 (save-match-data
3203 (if fp
3204 (funcall form)
3205 (eval form)))))))
3207 (defvar org-agenda-markers nil
3208 "List of all currently active markers created by `org-agenda'.")
3209 (defvar org-agenda-last-marker-time (org-float-time)
3210 "Creation time of the last agenda marker.")
3212 (defun org-agenda-new-marker (&optional pos)
3213 "Return a new agenda marker.
3214 Org-mode keeps a list of these markers and resets them when they are
3215 no longer in use."
3216 (let ((m (copy-marker (or pos (point)))))
3217 (setq org-agenda-last-marker-time (org-float-time))
3218 (push m org-agenda-markers)
3221 (defun org-agenda-reset-markers ()
3222 "Reset markers created by `org-agenda'."
3223 (while org-agenda-markers
3224 (move-marker (pop org-agenda-markers) nil)))
3226 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3227 "Save relative positions of markers in region."
3228 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3229 org-agenda-markers))
3231 ;;; Entry text mode
3233 (defun org-agenda-entry-text-show-here ()
3234 "Add some text from the entry as context to the current line."
3235 (let (m txt o)
3236 (setq m (org-get-at-bol 'org-hd-marker))
3237 (unless (marker-buffer m)
3238 (error "No marker points to an entry here"))
3239 (setq txt (concat "\n" (org-no-properties
3240 (org-agenda-get-some-entry-text
3241 m org-agenda-entry-text-maxlines " > "))))
3242 (when (string-match "\\S-" txt)
3243 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3244 (overlay-put o 'evaporate t)
3245 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3246 (overlay-put o 'after-string txt))))
3248 (defun org-agenda-entry-text-show ()
3249 "Add entry context for all agenda lines."
3250 (interactive)
3251 (save-excursion
3252 (goto-char (point-max))
3253 (beginning-of-line 1)
3254 (while (not (bobp))
3255 (when (org-get-at-bol 'org-hd-marker)
3256 (org-agenda-entry-text-show-here))
3257 (beginning-of-line 0))))
3259 (defun org-agenda-entry-text-hide ()
3260 "Remove any shown entry context."
3261 (delq nil
3262 (mapcar (lambda (o)
3263 (if (eq (overlay-get o 'org-overlay-type)
3264 'agenda-entry-content)
3265 (progn (delete-overlay o) t)))
3266 (overlays-in (point-min) (point-max)))))
3268 (defun org-agenda-get-day-face (date)
3269 "Return the face DATE should be displayed with."
3270 (or (and (functionp org-agenda-day-face-function)
3271 (funcall org-agenda-day-face-function date))
3272 (cond ((org-agenda-todayp date)
3273 'org-agenda-date-today)
3274 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3275 'org-agenda-date-weekend)
3276 (t 'org-agenda-date))))
3278 ;;; Agenda timeline
3280 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3282 (defun org-timeline (&optional include-all)
3283 "Show a time-sorted view of the entries in the current org file.
3284 Only entries with a time stamp of today or later will be listed. With
3285 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3286 under the current date.
3287 If the buffer contains an active region, only check the region for
3288 dates."
3289 (interactive "P")
3290 (org-compile-prefix-format 'timeline)
3291 (org-set-sorting-strategy 'timeline)
3292 (let* ((dopast t)
3293 (dotodo include-all)
3294 (doclosed org-agenda-show-log)
3295 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3296 (current-buffer))))
3297 (date (calendar-current-date))
3298 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3299 (end (if (org-region-active-p) (region-end) (point-max)))
3300 (day-numbers (org-get-all-dates beg end 'no-ranges
3301 t doclosed ; always include today
3302 org-timeline-show-empty-dates))
3303 (org-deadline-warning-days 0)
3304 (org-agenda-only-exact-dates t)
3305 (today (org-today))
3306 (past t)
3307 args
3308 s e rtn d emptyp)
3309 (setq org-agenda-redo-command
3310 (list 'progn
3311 (list 'org-switch-to-buffer-other-window (current-buffer))
3312 (list 'org-timeline (list 'quote include-all))))
3313 (if (not dopast)
3314 ;; Remove past dates from the list of dates.
3315 (setq day-numbers (delq nil (mapcar (lambda(x)
3316 (if (>= x today) x nil))
3317 day-numbers))))
3318 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3319 (if doclosed (push :closed args))
3320 (push :timestamp args)
3321 (push :deadline args)
3322 (push :scheduled args)
3323 (push :sexp args)
3324 (if dotodo (push :todo args))
3325 (insert "Timeline of file " entry "\n")
3326 (add-text-properties (point-min) (point)
3327 (list 'face 'org-agenda-structure))
3328 (org-agenda-mark-header-line (point-min))
3329 (while (setq d (pop day-numbers))
3330 (if (and (listp d) (eq (car d) :omitted))
3331 (progn
3332 (setq s (point))
3333 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3334 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3335 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3336 (if (and (>= d today)
3337 dopast
3338 past)
3339 (progn
3340 (setq past nil)
3341 (insert (make-string 79 ?-) "\n")))
3342 (setq date (calendar-gregorian-from-absolute d))
3343 (setq s (point))
3344 (setq rtn (and (not emptyp)
3345 (apply 'org-agenda-get-day-entries entry
3346 date args)))
3347 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3348 (progn
3349 (insert
3350 (if (stringp org-agenda-format-date)
3351 (format-time-string org-agenda-format-date
3352 (org-time-from-absolute date))
3353 (funcall org-agenda-format-date date))
3354 "\n")
3355 (put-text-property s (1- (point)) 'face
3356 (org-agenda-get-day-face date))
3357 (put-text-property s (1- (point)) 'org-date-line t)
3358 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3359 (if (equal d today)
3360 (put-text-property s (1- (point)) 'org-today t))
3361 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3362 (put-text-property s (1- (point)) 'day d)))))
3363 (goto-char (point-min))
3364 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3365 (point-min)))
3366 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3367 (org-finalize-agenda)
3368 (setq buffer-read-only t)))
3370 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3371 "Return a list of all relevant day numbers from BEG to END buffer positions.
3372 If NO-RANGES is non-nil, include only the start and end dates of a range,
3373 not every single day in the range. If FORCE-TODAY is non-nil, make
3374 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3375 inactive time stamps (those in square brackets) are included.
3376 When EMPTY is non-nil, also include days without any entries."
3377 (let ((re (concat
3378 (if pre-re pre-re "")
3379 (if inactive org-ts-regexp-both org-ts-regexp)))
3380 dates dates1 date day day1 day2 ts1 ts2)
3381 (if force-today
3382 (setq dates (list (org-today))))
3383 (save-excursion
3384 (goto-char beg)
3385 (while (re-search-forward re end t)
3386 (setq day (time-to-days (org-time-string-to-time
3387 (substring (match-string 1) 0 10))))
3388 (or (memq day dates) (push day dates)))
3389 (unless no-ranges
3390 (goto-char beg)
3391 (while (re-search-forward org-tr-regexp end t)
3392 (setq ts1 (substring (match-string 1) 0 10)
3393 ts2 (substring (match-string 2) 0 10)
3394 day1 (time-to-days (org-time-string-to-time ts1))
3395 day2 (time-to-days (org-time-string-to-time ts2)))
3396 (while (< (setq day1 (1+ day1)) day2)
3397 (or (memq day1 dates) (push day1 dates)))))
3398 (setq dates (sort dates '<))
3399 (when empty
3400 (while (setq day (pop dates))
3401 (setq day2 (car dates))
3402 (push day dates1)
3403 (when (and day2 empty)
3404 (if (or (eq empty t)
3405 (and (numberp empty) (<= (- day2 day) empty)))
3406 (while (< (setq day (1+ day)) day2)
3407 (push (list day) dates1))
3408 (push (cons :omitted (- day2 day)) dates1))))
3409 (setq dates (nreverse dates1)))
3410 dates)))
3412 ;;; Agenda Daily/Weekly
3414 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3415 "Custom commands can set this variable in the options section.")
3416 (defvar org-starting-day nil) ; local variable in the agenda buffer
3417 (defvar org-agenda-current-span nil
3418 "The current span used in the agenda view.") ; local variable in the agenda buffer
3419 (defvar org-include-all-loc nil) ; local variable
3421 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3422 "List of types searched for when creating the daily/weekly agenda.
3423 This variable is a list of symbols that controls the types of
3424 items that appear in the daily/weekly agenda. Allowed symbols in this
3425 list are are
3427 :timestamp List items containing a date stamp or date range matching
3428 the selected date. This includes sexp entries in
3429 angular brackets.
3431 :sexp List entries resulting from plain diary-like sexps.
3433 :deadline List deadline due on that date. When the date is today,
3434 also list any deadlines past due, or due within
3435 `org-deadline-warning-days'. `:deadline' must appear before
3436 `:scheduled' if the setting of
3437 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3438 any effect.
3440 :scheduled List all items which are scheduled for the given date.
3441 The diary for *today* also contains items which were
3442 scheduled earlier and are not yet marked DONE.
3444 By default, all four types are turned on.
3446 Never set this variable globally using `setq', because then it
3447 will apply to all future agenda commands. Instead, bind it with
3448 `let' to scope it dynamically into the the agenda-constructing
3449 command. A good way to set it is through options in
3450 `org-agenda-custom-commands'. For a more flexible (though
3451 somewhat less efficient) way of determining what is included in
3452 the daily/weekly agenda, see `org-agenda-skip-function'.")
3454 ;;;###autoload
3455 (defun org-agenda-list (&optional include-all start-day span)
3456 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3457 The view will be for the current day or week, but from the overview buffer
3458 you will be able to go to other days/weeks.
3460 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3461 all unfinished TODO items will also be shown, before the agenda.
3462 This feature is considered obsolete, please use the TODO list or a block
3463 agenda instead.
3465 With a numeric prefix argument in an interactive call, the agenda will
3466 span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
3467 the number of days. SPAN defaults to `org-agenda-span'.
3469 START-DAY defaults to TODAY, or to the most recent match for the weekday
3470 given in `org-agenda-start-on-weekday'."
3471 (interactive "P")
3472 (if (and (integerp include-all) (> include-all 0))
3473 (setq span include-all include-all nil))
3474 (setq start-day (or start-day org-agenda-start-day))
3475 (if org-agenda-overriding-arguments
3476 (setq include-all (car org-agenda-overriding-arguments)
3477 start-day (nth 1 org-agenda-overriding-arguments)
3478 span (nth 2 org-agenda-overriding-arguments)))
3479 (if (stringp start-day)
3480 ;; Convert to an absolute day number
3481 (setq start-day (time-to-days (org-read-date nil t start-day))))
3482 (setq org-agenda-last-arguments (list include-all start-day span))
3483 (org-compile-prefix-format 'agenda)
3484 (org-set-sorting-strategy 'agenda)
3485 (let* ((span (org-agenda-ndays-to-span
3486 (or span org-agenda-ndays org-agenda-span)))
3487 (today (org-today))
3488 (sd (or start-day today))
3489 (ndays (org-agenda-span-to-ndays span sd))
3490 (org-agenda-start-on-weekday
3491 (if (eq ndays 7)
3492 org-agenda-start-on-weekday))
3493 (thefiles (org-agenda-files nil 'ifmode))
3494 (files thefiles)
3495 (start (if (or (null org-agenda-start-on-weekday)
3496 (< ndays 7))
3498 (let* ((nt (calendar-day-of-week
3499 (calendar-gregorian-from-absolute sd)))
3500 (n1 org-agenda-start-on-weekday)
3501 (d (- nt n1)))
3502 (- sd (+ (if (< d 0) 7 0) d)))))
3503 (day-numbers (list start))
3504 (day-cnt 0)
3505 (inhibit-redisplay (not debug-on-error))
3506 s e rtn rtnall file date d start-pos end-pos todayp
3507 clocktable-start clocktable-end filter)
3508 (setq org-agenda-redo-command
3509 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3510 (dotimes (n (1- ndays))
3511 (push (1+ (car day-numbers)) day-numbers))
3512 (setq day-numbers (nreverse day-numbers))
3513 (setq clocktable-start (car day-numbers)
3514 clocktable-end (1+ (or (org-last day-numbers) 0)))
3515 (org-prepare-agenda "Day/Week")
3516 (org-set-local 'org-starting-day (car day-numbers))
3517 (org-set-local 'org-include-all-loc include-all)
3518 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3519 (when (and (or include-all org-agenda-include-all-todo)
3520 (member today day-numbers))
3521 (setq files thefiles
3522 rtnall nil)
3523 (while (setq file (pop files))
3524 (catch 'nextfile
3525 (org-check-agenda-file file)
3526 (setq date (calendar-gregorian-from-absolute today)
3527 rtn (org-agenda-get-day-entries
3528 file date :todo))
3529 (setq rtnall (append rtnall rtn))))
3530 (when rtnall
3531 (insert "All currently open TODO items:\n")
3532 (add-text-properties (point-min) (1- (point))
3533 (list 'face 'org-agenda-structure
3534 'short-heading "All TODO items"))
3535 (org-agenda-mark-header-line (point-min))
3536 (insert (org-finalize-agenda-entries rtnall) "\n")))
3537 (unless org-agenda-compact-blocks
3538 (let* ((d1 (car day-numbers))
3539 (d2 (org-last day-numbers))
3540 (w1 (org-days-to-iso-week d1))
3541 (w2 (org-days-to-iso-week d2)))
3542 (setq s (point))
3543 (if org-agenda-overriding-header
3544 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3545 nil 'face 'org-agenda-structure) "\n")
3546 (insert (org-agenda-span-name span)
3547 "-agenda"
3548 (if (< (- d2 d1) 350)
3549 (if (= w1 w2)
3550 (format " (W%02d)" w1)
3551 (format " (W%02d-W%02d)" w1 w2))
3553 ":\n")))
3554 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3555 'org-date-line t))
3556 (org-agenda-mark-header-line s))
3557 (while (setq d (pop day-numbers))
3558 (setq date (calendar-gregorian-from-absolute d)
3559 s (point))
3560 (if (or (setq todayp (= d today))
3561 (and (not start-pos) (= d sd)))
3562 (setq start-pos (point))
3563 (if (and start-pos (not end-pos))
3564 (setq end-pos (point))))
3565 (setq files thefiles
3566 rtnall nil)
3567 (while (setq file (pop files))
3568 (catch 'nextfile
3569 (org-check-agenda-file file)
3570 (let ((org-agenda-entry-types org-agenda-entry-types))
3571 (unless org-agenda-include-deadlines
3572 (setq org-agenda-entry-types
3573 (delq :deadline org-agenda-entry-types)))
3574 (cond
3575 ((eq org-agenda-show-log 'only)
3576 (setq rtn (org-agenda-get-day-entries
3577 file date :closed)))
3578 (org-agenda-show-log
3579 (setq rtn (apply 'org-agenda-get-day-entries
3580 file date
3581 (append '(:closed) org-agenda-entry-types))))
3583 (setq rtn (apply 'org-agenda-get-day-entries
3584 file date
3585 org-agenda-entry-types)))))
3586 (setq rtnall (append rtnall rtn))))
3587 (if org-agenda-include-diary
3588 (let ((org-agenda-search-headline-for-time t))
3589 (require 'diary-lib)
3590 (setq rtn (org-get-entries-from-diary date))
3591 (setq rtnall (append rtnall rtn))))
3592 (if (or rtnall org-agenda-show-all-dates)
3593 (progn
3594 (setq day-cnt (1+ day-cnt))
3595 (insert
3596 (if (stringp org-agenda-format-date)
3597 (format-time-string org-agenda-format-date
3598 (org-time-from-absolute date))
3599 (funcall org-agenda-format-date date))
3600 "\n")
3601 (put-text-property s (1- (point)) 'face
3602 (org-agenda-get-day-face date))
3603 (put-text-property s (1- (point)) 'org-date-line t)
3604 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3605 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3606 (when todayp
3607 (put-text-property s (1- (point)) 'org-today t))
3608 (if rtnall (insert
3609 (org-finalize-agenda-entries
3610 (org-agenda-add-time-grid-maybe
3611 rtnall ndays todayp))
3612 "\n"))
3613 (put-text-property s (1- (point)) 'day d)
3614 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3615 (when (and org-agenda-clockreport-mode clocktable-start)
3616 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3617 ;; the above line is to ensure the restricted range!
3618 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3619 tbl)
3620 (setq p (org-plist-delete p :block))
3621 (setq p (plist-put p :tstart clocktable-start))
3622 (setq p (plist-put p :tend clocktable-end))
3623 (setq p (plist-put p :scope 'agenda))
3624 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3625 (setq filter (or org-agenda-filter-while-redo
3626 (get 'org-agenda-filter :preset-filter))))
3627 (setq p (plist-put p :tags (mapconcat (lambda (x)
3628 (if (string-match "[<>=]" x)
3631 filter ""))))
3632 (setq tbl (apply 'org-get-clocktable p))
3633 (insert tbl)))
3634 (goto-char (point-min))
3635 (or org-agenda-multi (org-fit-agenda-window))
3636 (unless (and (pos-visible-in-window-p (point-min))
3637 (pos-visible-in-window-p (point-max)))
3638 (goto-char (1- (point-max)))
3639 (recenter -1)
3640 (if (not (pos-visible-in-window-p (or start-pos 1)))
3641 (progn
3642 (goto-char (or start-pos 1))
3643 (recenter 1))))
3644 (goto-char (or start-pos 1))
3645 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3646 (org-finalize-agenda)
3647 (setq buffer-read-only t)
3648 (message "")))
3650 (defun org-agenda-ndays-to-span (n)
3651 "Return a span symbol for a span of N days, or N if none matches."
3652 (cond ((symbolp n) n)
3653 ((= n 1) 'day)
3654 ((= n 7) 'week)
3655 (t n)))
3657 (defun org-agenda-span-to-ndays (span start-day)
3658 "Return ndays from SPAN starting at START-DAY."
3659 (cond ((numberp span) span)
3660 ((eq span 'day) 1)
3661 ((eq span 'week) 7)
3662 ((eq span 'month)
3663 (let ((date (calendar-gregorian-from-absolute start-day)))
3664 (calendar-last-day-of-month (car date) (caddr date))))
3665 ((eq span 'year)
3666 (let ((date (calendar-gregorian-from-absolute start-day)))
3667 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3669 (defun org-agenda-span-name (span)
3670 "Return a SPAN name."
3671 (if (null span)
3673 (if (symbolp span)
3674 (capitalize (symbol-name span))
3675 (format "%d days" span))))
3677 ;;; Agenda word search
3679 (defvar org-agenda-search-history nil)
3680 (defvar org-todo-only nil)
3682 (defvar org-search-syntax-table nil
3683 "Special syntax table for org-mode search.
3684 In this table, we have single quotes not as word constituents, to
3685 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3687 (defun org-search-syntax-table ()
3688 (unless org-search-syntax-table
3689 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3690 (modify-syntax-entry ?' "." org-search-syntax-table)
3691 (modify-syntax-entry ?` "." org-search-syntax-table))
3692 org-search-syntax-table)
3694 (defvar org-agenda-last-search-view-search-was-boolean nil)
3696 ;;;###autoload
3697 (defun org-search-view (&optional todo-only string edit-at)
3698 "Show all entries that contain a phrase or words or regular expressions.
3700 With optional prefix argument TODO-ONLY, only consider entries that are
3701 TODO entries. The argument STRING can be used to pass a default search
3702 string into this function. If EDIT-AT is non-nil, it means that the
3703 user should get a chance to edit this string, with cursor at position
3704 EDIT-AT.
3706 The search string can be viewed either as a phrase that should be found as
3707 is, or it can be broken into a number of snippets, each of which must match
3708 in a Boolean way to select an entry. The default depends on the variable
3709 `org-agenda-search-view-always-boolean'.
3710 Even if this is turned off (the default) you can always switch to
3711 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3713 The default is a direct search of the whole phrase, where each space in
3714 the search string can expand to an arbitrary amount of whitespace,
3715 including newlines.
3717 If using a Boolean search, the search string is split on whitespace and
3718 each snippet is searched separately, with logical AND to select an entry.
3719 Words prefixed with a minus must *not* occur in the entry. Words without
3720 a prefix or prefixed with a plus must occur in the entry. Matching is
3721 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3722 match whole words, not parts of a word) if
3723 `org-agenda-search-view-force-full-words' is set (default is nil).
3725 Boolean search snippets enclosed by curly braces are interpreted as
3726 regular expressions that must or (when preceded with \"-\") must not
3727 match in the entry. Snippets enclosed into double quotes will be taken
3728 as a whole, to include whitespace.
3730 - If the search string starts with an asterisk, search only in headlines.
3731 - If (possibly after the leading star) the search string starts with an
3732 exclamation mark, this also means to look at TODO entries only, an effect
3733 that can also be achieved with a prefix argument.
3734 - If (possibly after star and exclamation mark) the search string starts
3735 with a colon, this will mean that the (non-regexp) snippets of the
3736 Boolean search must match as full words.
3738 This command searches the agenda files, and in addition the files listed
3739 in `org-agenda-text-search-extra-files'."
3740 (interactive "P")
3741 (org-compile-prefix-format 'search)
3742 (org-set-sorting-strategy 'search)
3743 (org-prepare-agenda "SEARCH")
3744 (let* ((props (list 'face nil
3745 'done-face 'org-agenda-done
3746 'org-not-done-regexp org-not-done-regexp
3747 'org-todo-regexp org-todo-regexp
3748 'org-complex-heading-regexp org-complex-heading-regexp
3749 'mouse-face 'highlight
3750 'help-echo (format "mouse-2 or RET jump to location")))
3751 (full-words org-agenda-search-view-force-full-words)
3752 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3753 regexp rtn rtnall files file pos
3754 marker category tags c neg re boolean
3755 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3756 (unless (and (not edit-at)
3757 (stringp string)
3758 (string-match "\\S-" string))
3759 (setq string (read-string
3760 (if org-agenda-search-view-always-boolean
3761 "[+-]Word/{Regexp} ...: "
3762 "Phrase, or [+-]Word/{Regexp} ...: ")
3763 (cond
3764 ((integerp edit-at) (cons string edit-at))
3765 (edit-at string))
3766 'org-agenda-search-history)))
3767 (org-set-local 'org-todo-only todo-only)
3768 (setq org-agenda-redo-command
3769 (list 'org-search-view (if todo-only t nil) string
3770 '(if current-prefix-arg 1 nil)))
3771 (setq org-agenda-query-string string)
3773 (if (equal (string-to-char string) ?*)
3774 (setq hdl-only t
3775 words (substring string 1))
3776 (setq words string))
3777 (when (equal (string-to-char words) ?!)
3778 (setq todo-only t
3779 words (substring words 1)))
3780 (when (equal (string-to-char words) ?:)
3781 (setq full-words t
3782 words (substring words 1)))
3783 (if (or org-agenda-search-view-always-boolean
3784 (member (string-to-char words) '(?- ?+ ?\{)))
3785 (setq boolean t))
3786 (setq words (org-split-string words))
3787 (let (www w)
3788 (while (setq w (pop words))
3789 (while (and (string-match "\\\\\\'" w) words)
3790 (setq w (concat (substring w 0 -1) " " (pop words))))
3791 (push w www))
3792 (setq words (nreverse www) www nil)
3793 (while (setq w (pop words))
3794 (when (and (string-match "\\`[-+]?{" w)
3795 (not (string-match "}\\'" w)))
3796 (while (and words (not (string-match "}\\'" (car words))))
3797 (setq w (concat w " " (pop words))))
3798 (setq w (concat w " " (pop words))))
3799 (push w www))
3800 (setq words (nreverse www)))
3801 (setq org-agenda-last-search-view-search-was-boolean boolean)
3802 (when boolean
3803 (let (wds w)
3804 (while (setq w (pop words))
3805 (if (or (equal (substring w 0 1) "\"")
3806 (and (> (length w) 1)
3807 (member (substring w 0 1) '("+" "-"))
3808 (equal (substring w 1 2) "\"")))
3809 (while (and words (not (equal (substring w -1) "\"")))
3810 (setq w (concat w " " (pop words)))))
3811 (and (string-match "\\`\\([-+]?\\)\"" w)
3812 (setq w (replace-match "\\1" nil nil w)))
3813 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3814 (push w wds))
3815 (setq words (nreverse wds))))
3816 (if boolean
3817 (mapc (lambda (w)
3818 (setq c (string-to-char w))
3819 (if (equal c ?-)
3820 (setq neg t w (substring w 1))
3821 (if (equal c ?+)
3822 (setq neg nil w (substring w 1))
3823 (setq neg nil)))
3824 (if (string-match "\\`{.*}\\'" w)
3825 (setq re (substring w 1 -1))
3826 (if full-words
3827 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3828 (setq re (regexp-quote (downcase w)))))
3829 (if neg (push re regexps-) (push re regexps+)))
3830 words)
3831 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3832 regexps+))
3833 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3834 (if (not regexps+)
3835 (setq regexp (concat "^" org-outline-regexp))
3836 (setq regexp (pop regexps+))
3837 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3838 regexp))))
3839 (setq files (org-agenda-files nil 'ifmode))
3840 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3841 (pop org-agenda-text-search-extra-files)
3842 (setq files (org-add-archive-files files)))
3843 (setq files (append files org-agenda-text-search-extra-files)
3844 rtnall nil)
3845 (while (setq file (pop files))
3846 (setq ee nil)
3847 (catch 'nextfile
3848 (org-check-agenda-file file)
3849 (setq buffer (if (file-exists-p file)
3850 (org-get-agenda-file-buffer file)
3851 (error "No such file %s" file)))
3852 (if (not buffer)
3853 ;; If file does not exist, make sure an error message is sent
3854 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3855 file))))
3856 (with-current-buffer buffer
3857 (with-syntax-table (org-search-syntax-table)
3858 (unless (org-mode-p)
3859 (error "Agenda file %s is not in `org-mode'" file))
3860 (let ((case-fold-search t))
3861 (save-excursion
3862 (save-restriction
3863 (if org-agenda-restrict
3864 (narrow-to-region org-agenda-restrict-begin
3865 org-agenda-restrict-end)
3866 (widen))
3867 (goto-char (point-min))
3868 (unless (or (org-on-heading-p)
3869 (outline-next-heading))
3870 (throw 'nextfile t))
3871 (goto-char (max (point-min) (1- (point))))
3872 (while (re-search-forward regexp nil t)
3873 (org-back-to-heading t)
3874 (skip-chars-forward "* ")
3875 (setq beg (point-at-bol)
3876 beg1 (point)
3877 end (progn (outline-next-heading) (point)))
3878 (catch :skip
3879 (goto-char beg)
3880 (org-agenda-skip)
3881 (setq str (buffer-substring-no-properties
3882 (point-at-bol)
3883 (if hdl-only (point-at-eol) end)))
3884 (mapc (lambda (wr) (when (string-match wr str)
3885 (goto-char (1- end))
3886 (throw :skip t)))
3887 regexps-)
3888 (mapc (lambda (wr) (unless (string-match wr str)
3889 (goto-char (1- end))
3890 (throw :skip t)))
3891 (if todo-only
3892 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3893 regexps+)
3894 regexps+))
3895 (goto-char beg)
3896 (setq marker (org-agenda-new-marker (point))
3897 category (org-get-category)
3898 tags (org-get-tags-at (point))
3899 txt (org-format-agenda-item
3901 (buffer-substring-no-properties
3902 beg1 (point-at-eol))
3903 category tags))
3904 (org-add-props txt props
3905 'org-marker marker 'org-hd-marker marker
3906 'org-todo-regexp org-todo-regexp
3907 'org-complex-heading-regexp org-complex-heading-regexp
3908 'priority 1000 'org-category category
3909 'type "search")
3910 (push txt ee)
3911 (goto-char (1- end))))))))))
3912 (setq rtn (nreverse ee))
3913 (setq rtnall (append rtnall rtn)))
3914 (if org-agenda-overriding-header
3915 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3916 nil 'face 'org-agenda-structure) "\n")
3917 (insert "Search words: ")
3918 (add-text-properties (point-min) (1- (point))
3919 (list 'face 'org-agenda-structure))
3920 (setq pos (point))
3921 (insert string "\n")
3922 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3923 (setq pos (point))
3924 (unless org-agenda-multi
3925 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3926 (add-text-properties pos (1- (point))
3927 (list 'face 'org-agenda-structure))))
3928 (org-agenda-mark-header-line (point-min))
3929 (when rtnall
3930 (insert (org-finalize-agenda-entries rtnall) "\n"))
3931 (goto-char (point-min))
3932 (or org-agenda-multi (org-fit-agenda-window))
3933 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3934 (org-finalize-agenda)
3935 (setq buffer-read-only t)))
3937 ;;; Agenda TODO list
3939 (defvar org-select-this-todo-keyword nil)
3940 (defvar org-last-arg nil)
3942 ;;;###autoload
3943 (defun org-todo-list (arg)
3944 "Show all (not done) TODO entries from all agenda file in a single list.
3945 The prefix arg can be used to select a specific TODO keyword and limit
3946 the list to these. When using \\[universal-argument], you will be prompted
3947 for a keyword. A numeric prefix directly selects the Nth keyword in
3948 `org-todo-keywords-1'."
3949 (interactive "P")
3950 (org-compile-prefix-format 'todo)
3951 (org-set-sorting-strategy 'todo)
3952 (org-prepare-agenda "TODO")
3953 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3954 (let* ((today (org-today))
3955 (date (calendar-gregorian-from-absolute today))
3956 (kwds org-todo-keywords-for-agenda)
3957 (completion-ignore-case t)
3958 (org-select-this-todo-keyword
3959 (if (stringp arg) arg
3960 (and arg (integerp arg) (> arg 0)
3961 (nth (1- arg) kwds))))
3962 rtn rtnall files file pos)
3963 (when (equal arg '(4))
3964 (setq org-select-this-todo-keyword
3965 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3966 (mapcar 'list kwds) nil nil)))
3967 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3968 (org-set-local 'org-last-arg arg)
3969 (setq org-agenda-redo-command
3970 '(org-todo-list (or current-prefix-arg org-last-arg)))
3971 (setq files (org-agenda-files nil 'ifmode)
3972 rtnall nil)
3973 (while (setq file (pop files))
3974 (catch 'nextfile
3975 (org-check-agenda-file file)
3976 (setq rtn (org-agenda-get-day-entries file date :todo))
3977 (setq rtnall (append rtnall rtn))))
3978 (if org-agenda-overriding-header
3979 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3980 nil 'face 'org-agenda-structure) "\n")
3981 (insert "Global list of TODO items of type: ")
3982 (add-text-properties (point-min) (1- (point))
3983 (list 'face 'org-agenda-structure
3984 'short-heading
3985 (concat "ToDo: "
3986 (or org-select-this-todo-keyword "ALL"))))
3987 (org-agenda-mark-header-line (point-min))
3988 (setq pos (point))
3989 (insert (or org-select-this-todo-keyword "ALL") "\n")
3990 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3991 (setq pos (point))
3992 (unless org-agenda-multi
3993 (insert "Available with `N r': (0)ALL")
3994 (let ((n 0) s)
3995 (mapc (lambda (x)
3996 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3997 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3998 (insert "\n "))
3999 (insert " " s))
4000 kwds))
4001 (insert "\n"))
4002 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4003 (org-agenda-mark-header-line (point-min))
4004 (when rtnall
4005 (insert (org-finalize-agenda-entries rtnall) "\n"))
4006 (goto-char (point-min))
4007 (or org-agenda-multi (org-fit-agenda-window))
4008 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4009 (org-finalize-agenda)
4010 (setq buffer-read-only t)))
4012 ;;; Agenda tags match
4014 ;;;###autoload
4015 (defun org-tags-view (&optional todo-only match)
4016 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4017 The prefix arg TODO-ONLY limits the search to TODO entries."
4018 (interactive "P")
4019 (org-compile-prefix-format 'tags)
4020 (org-set-sorting-strategy 'tags)
4021 (let* ((org-tags-match-list-sublevels
4022 org-tags-match-list-sublevels)
4023 (completion-ignore-case t)
4024 rtn rtnall files file pos matcher
4025 buffer)
4026 (when (and (stringp match) (not (string-match "\\S-" match)))
4027 (setq match nil))
4028 (setq matcher (org-make-tags-matcher match)
4029 match (car matcher) matcher (cdr matcher))
4030 (org-prepare-agenda (concat "TAGS " match))
4031 (setq org-agenda-query-string match)
4032 (setq org-agenda-redo-command
4033 (list 'org-tags-view (list 'quote todo-only)
4034 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4035 (setq files (org-agenda-files nil 'ifmode)
4036 rtnall nil)
4037 (while (setq file (pop files))
4038 (catch 'nextfile
4039 (org-check-agenda-file file)
4040 (setq buffer (if (file-exists-p file)
4041 (org-get-agenda-file-buffer file)
4042 (error "No such file %s" file)))
4043 (if (not buffer)
4044 ;; If file does not exist, error message to agenda
4045 (setq rtn (list
4046 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4047 rtnall (append rtnall rtn))
4048 (with-current-buffer buffer
4049 (unless (org-mode-p)
4050 (error "Agenda file %s is not in `org-mode'" file))
4051 (save-excursion
4052 (save-restriction
4053 (if org-agenda-restrict
4054 (narrow-to-region org-agenda-restrict-begin
4055 org-agenda-restrict-end)
4056 (widen))
4057 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4058 (setq rtnall (append rtnall rtn))))))))
4059 (if org-agenda-overriding-header
4060 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4061 nil 'face 'org-agenda-structure) "\n")
4062 (insert "Headlines with TAGS match: ")
4063 (add-text-properties (point-min) (1- (point))
4064 (list 'face 'org-agenda-structure
4065 'short-heading
4066 (concat "Match: " match)))
4067 (setq pos (point))
4068 (insert match "\n")
4069 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4070 (setq pos (point))
4071 (unless org-agenda-multi
4072 (insert "Press `C-u r' to search again with new search string\n"))
4073 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4074 (org-agenda-mark-header-line (point-min))
4075 (when rtnall
4076 (insert (org-finalize-agenda-entries rtnall) "\n"))
4077 (goto-char (point-min))
4078 (or org-agenda-multi (org-fit-agenda-window))
4079 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4080 (org-finalize-agenda)
4081 (setq buffer-read-only t)))
4083 ;;; Agenda Finding stuck projects
4085 (defvar org-agenda-skip-regexp nil
4086 "Regular expression used in skipping subtrees for the agenda.
4087 This is basically a temporary global variable that can be set and then
4088 used by user-defined selections using `org-agenda-skip-function'.")
4090 (defvar org-agenda-overriding-header nil
4091 "When this is set during todo and tags searches, will replace header.
4092 This variable should not be set directly, but custom commands can bind it
4093 in the options section.")
4095 (defun org-agenda-skip-entry-when-regexp-matches ()
4096 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4097 If yes, it returns the end position of this entry, causing agenda commands
4098 to skip the entry but continuing the search in the subtree. This is a
4099 function that can be put into `org-agenda-skip-function' for the duration
4100 of a command."
4101 (let ((end (save-excursion (org-end-of-subtree t)))
4102 skip)
4103 (save-excursion
4104 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4105 (and skip end)))
4107 (defun org-agenda-skip-subtree-when-regexp-matches ()
4108 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4109 If yes, it returns the end position of this tree, causing agenda commands
4110 to skip this subtree. This is a function that can be put into
4111 `org-agenda-skip-function' for the duration of a command."
4112 (let ((end (save-excursion (org-end-of-subtree t)))
4113 skip)
4114 (save-excursion
4115 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4116 (and skip end)))
4118 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4119 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4120 If yes, it returns the end position of the current entry (NOT the tree),
4121 causing agenda commands to skip the entry but continuing the search in
4122 the subtree. This is a function that can be put into
4123 `org-agenda-skip-function' for the duration of a command. An important
4124 use of this function is for the stuck project list."
4125 (let ((end (save-excursion (org-end-of-subtree t)))
4126 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4127 skip)
4128 (save-excursion
4129 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4130 (and skip entry-end)))
4132 (defun org-agenda-skip-entry-if (&rest conditions)
4133 "Skip entry if any of CONDITIONS is true.
4134 See `org-agenda-skip-if' for details."
4135 (org-agenda-skip-if nil conditions))
4137 (defun org-agenda-skip-subtree-if (&rest conditions)
4138 "Skip entry if any of CONDITIONS is true.
4139 See `org-agenda-skip-if' for details."
4140 (org-agenda-skip-if t conditions))
4142 (defun org-agenda-skip-if (subtree conditions)
4143 "Checks current entity for CONDITIONS.
4144 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4145 the entry, i.e. the text before the next heading is checked.
4147 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4148 from different tests. Valid conditions are:
4150 scheduled Check if there is a scheduled cookie
4151 notscheduled Check if there is no scheduled cookie
4152 deadline Check if there is a deadline
4153 notdeadline Check if there is no deadline
4154 timestamp Check if there is a timestamp (also deadline or scheduled)
4155 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4156 regexp Check if regexp matches
4157 notregexp Check if regexp does not match.
4158 todo Check if TODO keyword matches
4159 nottodo Check if TODO keyword does not match
4161 The regexp is taken from the conditions list, it must come right after
4162 the `regexp' or `notregexp' element.
4164 `todo' and `nottodo' accept as an argument a list of todo
4165 keywords, which may include \"*\" to match any todo keyword.
4167 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4169 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4171 Instead of a list a keyword class may be given
4173 (org-agenda-skip-entry-if 'nottodo 'done)
4175 would skip entries that haven't been marked with any of \"DONE\"
4176 keywords. Possible classes are: `todo', `done', `any'.
4178 If any of these conditions is met, this function returns the end point of
4179 the entity, causing the search to continue from there. This is a function
4180 that can be put into `org-agenda-skip-function' for the duration of a command."
4181 (let (beg end m)
4182 (org-back-to-heading t)
4183 (setq beg (point)
4184 end (if subtree
4185 (progn (org-end-of-subtree t) (point))
4186 (progn (outline-next-heading) (1- (point)))))
4187 (goto-char beg)
4188 (and
4190 (and (memq 'scheduled conditions)
4191 (re-search-forward org-scheduled-time-regexp end t))
4192 (and (memq 'notscheduled conditions)
4193 (not (re-search-forward org-scheduled-time-regexp end t)))
4194 (and (memq 'deadline conditions)
4195 (re-search-forward org-deadline-time-regexp end t))
4196 (and (memq 'notdeadline conditions)
4197 (not (re-search-forward org-deadline-time-regexp end t)))
4198 (and (memq 'timestamp conditions)
4199 (re-search-forward org-ts-regexp end t))
4200 (and (memq 'nottimestamp conditions)
4201 (not (re-search-forward org-ts-regexp end t)))
4202 (and (setq m (memq 'regexp conditions))
4203 (stringp (nth 1 m))
4204 (re-search-forward (nth 1 m) end t))
4205 (and (setq m (memq 'notregexp conditions))
4206 (stringp (nth 1 m))
4207 (not (re-search-forward (nth 1 m) end t)))
4208 (and (or
4209 (setq m (memq 'todo conditions))
4210 (setq m (memq 'nottodo conditions)))
4211 (org-agenda-skip-if-todo m end)))
4212 end)))
4214 (defun org-agenda-skip-if-todo (args end)
4215 "Helper function for `org-agenda-skip-if', do not use it directly.
4216 ARGS is a list with first element either `todo' or `nottodo'.
4217 The remainder is either a list of TODO keywords, or a state symbol
4218 `todo' or `done' or `any'."
4219 (let ((kw (car args))
4220 (arg (cadr args))
4221 todo-wds todo-re)
4222 (setq todo-wds
4223 (org-uniquify
4224 (cond
4225 ((listp arg) ;; list of keywords
4226 (if (member "*" arg)
4227 (mapcar 'substring-no-properties org-todo-keywords-1)
4228 arg))
4229 ((symbolp arg) ;; keyword class name
4230 (cond
4231 ((eq arg 'todo)
4232 (org-delete-all org-done-keywords
4233 (mapcar 'substring-no-properties
4234 org-todo-keywords-1)))
4235 ((eq arg 'done) org-done-keywords)
4236 ((eq arg 'any)
4237 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4238 (setq todo-re
4239 (concat "^\\*+[ \t]+\\<\\("
4240 (mapconcat 'identity todo-wds "\\|")
4241 "\\)\\>"))
4242 (if (eq kw 'todo)
4243 (re-search-forward todo-re end t)
4244 (not (re-search-forward todo-re end t)))))
4246 ;;;###autoload
4247 (defun org-agenda-list-stuck-projects (&rest ignore)
4248 "Create agenda view for projects that are stuck.
4249 Stuck projects are project that have no next actions. For the definitions
4250 of what a project is and how to check if it stuck, customize the variable
4251 `org-stuck-projects'."
4252 (interactive)
4253 (let* ((org-agenda-skip-function
4254 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4255 ;; We could have used org-agenda-skip-if here.
4256 (org-agenda-overriding-header
4257 (or org-agenda-overriding-header "List of stuck projects: "))
4258 (matcher (nth 0 org-stuck-projects))
4259 (todo (nth 1 org-stuck-projects))
4260 (todo-wds (if (member "*" todo)
4261 (progn
4262 (org-prepare-agenda-buffers (org-agenda-files
4263 nil 'ifmode))
4264 (org-delete-all
4265 org-done-keywords-for-agenda
4266 (copy-sequence org-todo-keywords-for-agenda)))
4267 todo))
4268 (todo-re (concat "^\\*+[ \t]+\\("
4269 (mapconcat 'identity todo-wds "\\|")
4270 "\\)\\>"))
4271 (tags (nth 2 org-stuck-projects))
4272 (tags-re (if (member "*" tags)
4273 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4274 (if tags
4275 (concat "^\\*+ .*:\\("
4276 (mapconcat 'identity tags "\\|")
4277 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4278 (gen-re (nth 3 org-stuck-projects))
4279 (re-list
4280 (delq nil
4281 (list
4282 (if todo todo-re)
4283 (if tags tags-re)
4284 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4285 gen-re)))))
4286 (setq org-agenda-skip-regexp
4287 (if re-list
4288 (mapconcat 'identity re-list "\\|")
4289 (error "No information how to identify unstuck projects")))
4290 (org-tags-view nil matcher)
4291 (with-current-buffer org-agenda-buffer-name
4292 (setq org-agenda-redo-command
4293 '(org-agenda-list-stuck-projects
4294 (or current-prefix-arg org-last-arg))))))
4296 ;;; Diary integration
4298 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4299 (defvar list-diary-entries-hook)
4300 (defvar diary-time-regexp)
4301 (defun org-get-entries-from-diary (date)
4302 "Get the (Emacs Calendar) diary entries for DATE."
4303 (require 'diary-lib)
4304 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4305 (diary-display-hook '(fancy-diary-display))
4306 (diary-display-function 'fancy-diary-display)
4307 (pop-up-frames nil)
4308 (list-diary-entries-hook
4309 (cons 'org-diary-default-entry list-diary-entries-hook))
4310 (diary-file-name-prefix-function nil) ; turn this feature off
4311 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4312 entries
4313 (org-disable-agenda-to-diary t))
4314 (save-excursion
4315 (save-window-excursion
4316 (funcall (if (fboundp 'diary-list-entries)
4317 'diary-list-entries 'list-diary-entries)
4318 date 1)))
4319 (if (not (get-buffer diary-fancy-buffer))
4320 (setq entries nil)
4321 (with-current-buffer diary-fancy-buffer
4322 (setq buffer-read-only nil)
4323 (if (zerop (buffer-size))
4324 ;; No entries
4325 (setq entries nil)
4326 ;; Omit the date and other unnecessary stuff
4327 (org-agenda-cleanup-fancy-diary)
4328 ;; Add prefix to each line and extend the text properties
4329 (if (zerop (buffer-size))
4330 (setq entries nil)
4331 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4332 (setq entries
4333 (with-temp-buffer
4334 (insert entries) (goto-char (point-min))
4335 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4336 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4337 (replace-match (concat "; " (match-string 1)))))
4338 (buffer-string)))))
4339 (set-buffer-modified-p nil)
4340 (kill-buffer diary-fancy-buffer)))
4341 (when entries
4342 (setq entries (org-split-string entries "\n"))
4343 (setq entries
4344 (mapcar
4345 (lambda (x)
4346 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4347 ;; Extend the text properties to the beginning of the line
4348 (org-add-props x (text-properties-at (1- (length x)) x)
4349 'type "diary" 'date date 'face 'org-agenda-diary))
4350 entries)))))
4352 (defvar org-agenda-cleanup-fancy-diary-hook nil
4353 "Hook run when the fancy diary buffer is cleaned up.")
4355 (defun org-agenda-cleanup-fancy-diary ()
4356 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4357 This gets rid of the date, the underline under the date, and
4358 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4359 date. It also removes lines that contain only whitespace."
4360 (goto-char (point-min))
4361 (if (looking-at ".*?:[ \t]*")
4362 (progn
4363 (replace-match "")
4364 (re-search-forward "\n=+$" nil t)
4365 (replace-match "")
4366 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4367 (re-search-forward "\n=+$" nil t)
4368 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4369 (goto-char (point-min))
4370 (while (re-search-forward "^ +\n" nil t)
4371 (replace-match ""))
4372 (goto-char (point-min))
4373 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4374 (replace-match ""))
4375 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4377 ;; Make sure entries from the diary have the right text properties.
4378 (eval-after-load "diary-lib"
4379 '(if (boundp 'diary-modify-entry-list-string-function)
4380 ;; We can rely on the hook, nothing to do
4382 ;; Hook not available, must use advice to make this work
4383 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4384 "Make the position visible."
4385 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4386 (stringp string)
4387 buffer-file-name)
4388 (setq string (org-modify-diary-entry-string string))))))
4390 (defun org-modify-diary-entry-string (string)
4391 "Add text properties to string, allowing org-mode to act on it."
4392 (org-add-props string nil
4393 'mouse-face 'highlight
4394 'help-echo (if buffer-file-name
4395 (format "mouse-2 or RET jump to diary file %s"
4396 (abbreviate-file-name buffer-file-name))
4398 'org-agenda-diary-link t
4399 'org-marker (org-agenda-new-marker (point-at-bol))))
4401 (defun org-diary-default-entry ()
4402 "Add a dummy entry to the diary.
4403 Needed to avoid empty dates which mess up holiday display."
4404 ;; Catch the error if dealing with the new add-to-diary-alist
4405 (when org-disable-agenda-to-diary
4406 (condition-case nil
4407 (org-add-to-diary-list original-date "Org-mode dummy" "")
4408 (error
4409 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4411 (defun org-add-to-diary-list (&rest args)
4412 (if (fboundp 'diary-add-to-list)
4413 (apply 'diary-add-to-list args)
4414 (apply 'add-to-diary-list args)))
4416 (defvar org-diary-last-run-time nil)
4418 ;;;###autoload
4419 (defun org-diary (&rest args)
4420 "Return diary information from org-files.
4421 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4422 It accesses org files and extracts information from those files to be
4423 listed in the diary. The function accepts arguments specifying what
4424 items should be listed. For a list of arguments allowed here, see the
4425 variable `org-agenda-entry-types'.
4427 The call in the diary file should look like this:
4429 &%%(org-diary) ~/path/to/some/orgfile.org
4431 Use a separate line for each org file to check. Or, if you omit the file name,
4432 all files listed in `org-agenda-files' will be checked automatically:
4434 &%%(org-diary)
4436 If you don't give any arguments (as in the example above), the default
4437 arguments (:deadline :scheduled :timestamp :sexp) are used.
4438 So the example above may also be written as
4440 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4442 The function expects the lisp variables `entry' and `date' to be provided
4443 by the caller, because this is how the calendar works. Don't use this
4444 function from a program - use `org-agenda-get-day-entries' instead."
4445 (when (> (- (org-float-time)
4446 org-agenda-last-marker-time)
4448 (org-agenda-reset-markers))
4449 (org-compile-prefix-format 'agenda)
4450 (org-set-sorting-strategy 'agenda)
4451 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4452 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4453 (list entry)
4454 (org-agenda-files t)))
4455 (time (org-float-time))
4456 file rtn results)
4457 (when (or (not org-diary-last-run-time)
4458 (> (- time
4459 org-diary-last-run-time)
4461 (org-prepare-agenda-buffers files))
4462 (setq org-diary-last-run-time time)
4463 ;; If this is called during org-agenda, don't return any entries to
4464 ;; the calendar. Org Agenda will list these entries itself.
4465 (if org-disable-agenda-to-diary (setq files nil))
4466 (while (setq file (pop files))
4467 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4468 (setq results (append results rtn)))
4469 (if results
4470 (concat (org-finalize-agenda-entries results) "\n"))))
4472 ;;; Agenda entry finders
4474 (defun org-agenda-get-day-entries (file date &rest args)
4475 "Does the work for `org-diary' and `org-agenda'.
4476 FILE is the path to a file to be checked for entries. DATE is date like
4477 the one returned by `calendar-current-date'. ARGS are symbols indicating
4478 which kind of entries should be extracted. For details about these, see
4479 the documentation of `org-diary'."
4480 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4481 (let* ((org-startup-folded nil)
4482 (org-startup-align-all-tables nil)
4483 (buffer (if (file-exists-p file)
4484 (org-get-agenda-file-buffer file)
4485 (error "No such file %s" file)))
4486 arg results rtn deadline-results)
4487 (if (not buffer)
4488 ;; If file does not exist, make sure an error message ends up in diary
4489 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4490 (with-current-buffer buffer
4491 (unless (org-mode-p)
4492 (error "Agenda file %s is not in `org-mode'" file))
4493 (let ((case-fold-search nil))
4494 (save-excursion
4495 (save-restriction
4496 (if org-agenda-restrict
4497 (narrow-to-region org-agenda-restrict-begin
4498 org-agenda-restrict-end)
4499 (widen))
4500 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4501 (while (setq arg (pop args))
4502 (cond
4503 ((and (eq arg :todo)
4504 (equal date (calendar-gregorian-from-absolute
4505 (org-today))))
4506 (setq rtn (org-agenda-get-todos))
4507 (setq results (append results rtn)))
4508 ((eq arg :timestamp)
4509 (setq rtn (org-agenda-get-blocks))
4510 (setq results (append results rtn))
4511 (setq rtn (org-agenda-get-timestamps))
4512 (setq results (append results rtn)))
4513 ((eq arg :sexp)
4514 (setq rtn (org-agenda-get-sexps))
4515 (setq results (append results rtn)))
4516 ((eq arg :scheduled)
4517 (setq rtn (org-agenda-get-scheduled deadline-results))
4518 (setq results (append results rtn)))
4519 ((eq arg :closed)
4520 (setq rtn (org-agenda-get-progress))
4521 (setq results (append results rtn)))
4522 ((eq arg :deadline)
4523 (setq rtn (org-agenda-get-deadlines))
4524 (setq deadline-results (copy-sequence rtn))
4525 (setq results (append results rtn))))))))
4526 results))))
4528 (defun org-agenda-get-todos ()
4529 "Return the TODO information for agenda display."
4530 (let* ((props (list 'face nil
4531 'done-face 'org-agenda-done
4532 'org-not-done-regexp org-not-done-regexp
4533 'org-todo-regexp org-todo-regexp
4534 'org-complex-heading-regexp org-complex-heading-regexp
4535 'mouse-face 'highlight
4536 'help-echo
4537 (format "mouse-2 or RET jump to org file %s"
4538 (abbreviate-file-name buffer-file-name))))
4539 (regexp (concat "^\\*+[ \t]+\\("
4540 (if org-select-this-todo-keyword
4541 (if (equal org-select-this-todo-keyword "*")
4542 org-todo-regexp
4543 (concat "\\<\\("
4544 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4545 "\\)\\>"))
4546 org-not-done-regexp)
4547 "[^\n\r]*\\)"))
4548 marker priority category tags todo-state
4549 ee txt beg end)
4550 (goto-char (point-min))
4551 (while (re-search-forward regexp nil t)
4552 (catch :skip
4553 (save-match-data
4554 (beginning-of-line)
4555 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4556 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4557 (goto-char (1+ beg))
4558 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4559 (throw :skip nil)))
4560 (goto-char beg)
4561 (org-agenda-skip)
4562 (goto-char (match-beginning 1))
4563 (setq marker (org-agenda-new-marker (match-beginning 0))
4564 category (org-get-category)
4565 txt (match-string 1)
4566 tags (org-get-tags-at (point))
4567 txt (org-format-agenda-item "" txt category tags)
4568 priority (1+ (org-get-priority txt))
4569 todo-state (org-get-todo-state))
4570 (org-add-props txt props
4571 'org-marker marker 'org-hd-marker marker
4572 'priority priority 'org-category category
4573 'type "todo" 'todo-state todo-state)
4574 (push txt ee)
4575 (if org-agenda-todo-list-sublevels
4576 (goto-char (match-end 1))
4577 (org-end-of-subtree 'invisible))))
4578 (nreverse ee)))
4580 (defun org-agenda-todo-custom-ignore-p (time n)
4581 "Check whether timestamp is farther away then n number of days.
4582 This function is invoked if `org-agenda-todo-ignore-deadlines',
4583 `org-agenda-todo-ignore-scheduled' or
4584 `org-agenda-todo-ignore-timestamp' is set to an integer."
4585 (let ((days (org-days-to-time time)))
4586 (if (>= n 0)
4587 (>= days n)
4588 (<= days n))))
4590 ;;;###autoload
4591 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4592 (&optional end)
4593 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4594 (when (or org-agenda-todo-ignore-with-date
4595 org-agenda-todo-ignore-scheduled
4596 org-agenda-todo-ignore-deadlines
4597 org-agenda-todo-ignore-timestamp)
4598 (setq end (or end (save-excursion (outline-next-heading) (point))))
4599 (save-excursion
4600 (or (and org-agenda-todo-ignore-with-date
4601 (re-search-forward org-ts-regexp end t))
4602 (and org-agenda-todo-ignore-scheduled
4603 (re-search-forward org-scheduled-time-regexp end t)
4604 (cond
4605 ((eq org-agenda-todo-ignore-scheduled 'future)
4606 (> (org-days-to-time (match-string 1)) 0))
4607 ((eq org-agenda-todo-ignore-scheduled 'past)
4608 (<= (org-days-to-time (match-string 1)) 0))
4609 ((numberp org-agenda-todo-ignore-scheduled)
4610 (org-agenda-todo-custom-ignore-p
4611 (match-string 1) org-agenda-todo-ignore-scheduled))
4612 (t)))
4613 (and org-agenda-todo-ignore-deadlines
4614 (re-search-forward org-deadline-time-regexp end t)
4615 (cond
4616 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4617 ((eq org-agenda-todo-ignore-deadlines 'far)
4618 (not (org-deadline-close (match-string 1))))
4619 ((eq org-agenda-todo-ignore-deadlines 'future)
4620 (> (org-days-to-time (match-string 1)) 0))
4621 ((eq org-agenda-todo-ignore-deadlines 'past)
4622 (<= (org-days-to-time (match-string 1)) 0))
4623 ((numberp org-agenda-todo-ignore-deadlines)
4624 (org-agenda-todo-custom-ignore-p
4625 (match-string 1) org-agenda-todo-ignore-deadlines))
4626 (t (org-deadline-close (match-string 1)))))
4627 (and org-agenda-todo-ignore-timestamp
4628 (let ((buffer (current-buffer))
4629 (regexp
4630 (concat
4631 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4632 (start (point)))
4633 ;; Copy current buffer into a temporary one
4634 (with-temp-buffer
4635 (insert-buffer-substring buffer start end)
4636 (goto-char (point-min))
4637 ;; Delete SCHEDULED and DEADLINE items
4638 (while (re-search-forward regexp end t)
4639 (delete-region (match-beginning 0) (match-end 0)))
4640 (goto-char (point-min))
4641 ;; No search for timestamp left
4642 (when (re-search-forward org-ts-regexp nil t)
4643 (cond
4644 ((eq org-agenda-todo-ignore-timestamp 'future)
4645 (> (org-days-to-time (match-string 1)) 0))
4646 ((eq org-agenda-todo-ignore-timestamp 'past)
4647 (<= (org-days-to-time (match-string 1)) 0))
4648 ((numberp org-agenda-todo-ignore-timestamp)
4649 (org-agenda-todo-custom-ignore-p
4650 (match-string 1) org-agenda-todo-ignore-timestamp))
4651 (t))))))))))
4653 (defconst org-agenda-no-heading-message
4654 "No heading for this item in buffer or region.")
4656 (defun org-agenda-get-timestamps ()
4657 "Return the date stamp information for agenda display."
4658 (let* ((props (list 'face nil
4659 'org-not-done-regexp org-not-done-regexp
4660 'org-todo-regexp org-todo-regexp
4661 'org-complex-heading-regexp org-complex-heading-regexp
4662 'mouse-face 'highlight
4663 'help-echo
4664 (format "mouse-2 or RET jump to org file %s"
4665 (abbreviate-file-name buffer-file-name))))
4666 (d1 (calendar-absolute-from-gregorian date))
4667 (remove-re
4668 (concat
4669 (regexp-quote
4670 (format-time-string
4671 "<%Y-%m-%d"
4672 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4673 ".*?>"))
4674 (regexp
4675 (concat
4676 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4677 (regexp-quote
4678 (substring
4679 (format-time-string
4680 (car org-time-stamp-formats)
4681 (apply 'encode-time ; DATE bound by calendar
4682 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4683 1 11))
4684 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4685 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4686 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4687 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4688 todo-state end-of-match show-all)
4689 (goto-char (point-min))
4690 (while (setq end-of-match (re-search-forward regexp nil t))
4691 (setq b0 (match-beginning 0)
4692 b3 (match-beginning 3) e3 (match-end 3)
4693 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4694 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4695 (member todo-state
4696 org-agenda-repeating-timestamp-show-all)))
4697 (catch :skip
4698 (and (org-at-date-range-p) (throw :skip nil))
4699 (org-agenda-skip)
4700 (if (and (match-end 1)
4701 (not (= d1 (org-time-string-to-absolute
4702 (match-string 1) d1 nil show-all))))
4703 (throw :skip nil))
4704 (if (and e3
4705 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4706 (throw :skip nil))
4707 (setq tmp (buffer-substring (max (point-min)
4708 (- b0 org-ds-keyword-length))
4710 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4711 inactivep (= (char-after b0) ?\[)
4712 deadlinep (string-match org-deadline-regexp tmp)
4713 scheduledp (string-match org-scheduled-regexp tmp)
4714 closedp (and org-agenda-include-inactive-timestamps
4715 (string-match org-closed-string tmp))
4716 clockp (and org-agenda-include-inactive-timestamps
4717 (or (string-match org-clock-string tmp)
4718 (string-match "]-+\\'" tmp)))
4719 donep (member todo-state org-done-keywords))
4720 (if (or scheduledp deadlinep closedp clockp
4721 (and donep org-agenda-skip-timestamp-if-done))
4722 (throw :skip t))
4723 (if (string-match ">" timestr)
4724 ;; substring should only run to end of time stamp
4725 (setq timestr (substring timestr 0 (match-end 0))))
4726 (setq marker (org-agenda-new-marker b0)
4727 category (org-get-category b0))
4728 (save-excursion
4729 (if (not (re-search-backward "^\\*+ " nil t))
4730 (setq txt org-agenda-no-heading-message)
4731 (goto-char (match-beginning 0))
4732 (setq hdmarker (org-agenda-new-marker)
4733 tags (org-get-tags-at))
4734 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4735 (setq head (match-string 1))
4736 (setq txt (org-format-agenda-item
4737 (if inactivep org-agenda-inactive-leader nil)
4738 head category tags timestr
4739 remove-re)))
4740 (setq priority (org-get-priority txt))
4741 (org-add-props txt props
4742 'org-marker marker 'org-hd-marker hdmarker)
4743 (org-add-props txt nil 'priority priority
4744 'org-category category 'date date
4745 'todo-state todo-state
4746 'type "timestamp")
4747 (push txt ee))
4748 (if org-agenda-skip-additional-timestamps-same-entry
4749 (outline-next-heading)
4750 (goto-char end-of-match))))
4751 (nreverse ee)))
4753 (defun org-agenda-get-sexps ()
4754 "Return the sexp information for agenda display."
4755 (require 'diary-lib)
4756 (let* ((props (list 'mouse-face 'highlight
4757 'help-echo
4758 (format "mouse-2 or RET jump to org file %s"
4759 (abbreviate-file-name buffer-file-name))))
4760 (regexp "^&?%%(")
4761 marker category ee txt tags entry result beg b sexp sexp-entry
4762 todo-state)
4763 (goto-char (point-min))
4764 (while (re-search-forward regexp nil t)
4765 (catch :skip
4766 (org-agenda-skip)
4767 (setq beg (match-beginning 0))
4768 (goto-char (1- (match-end 0)))
4769 (setq b (point))
4770 (forward-sexp 1)
4771 (setq sexp (buffer-substring b (point)))
4772 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4773 (org-trim (match-string 1))
4774 ""))
4775 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4776 (when result
4777 (setq marker (org-agenda-new-marker beg)
4778 category (org-get-category beg)
4779 todo-state (org-get-todo-state))
4781 (dolist (r (if (stringp result)
4782 (list result)
4783 result)) ;; we expect a list here
4784 (if (string-match "\\S-" r)
4785 (setq txt r)
4786 (setq txt "SEXP entry returned empty string"))
4788 (setq txt (org-format-agenda-item
4789 "" txt category tags 'time))
4790 (org-add-props txt props 'org-marker marker)
4791 (org-add-props txt nil
4792 'org-category category 'date date 'todo-state todo-state
4793 'type "sexp")
4794 (push txt ee)))))
4795 (nreverse ee)))
4797 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4798 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4799 The order of the first 2 times 3 arguments depends on the variable
4800 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4801 So for American calendars, give this as MONTH DAY YEAR, for European as
4802 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4803 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4804 is any number of ISO weeks in the block period for which the item should
4805 be skipped."
4806 (let* ((date1 (calendar-absolute-from-gregorian
4807 (org-order-calendar-date-args m1 d1 y1)))
4808 (date2 (calendar-absolute-from-gregorian
4809 (org-order-calendar-date-args m2 d2 y2)))
4810 (d (calendar-absolute-from-gregorian date)))
4811 (and
4812 (<= date1 d)
4813 (<= d date2)
4814 (= (calendar-day-of-week date) dayname)
4815 (or (not skip-weeks)
4816 (progn
4817 (require 'cal-iso)
4818 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4819 entry)))
4821 (defalias 'org-get-closed 'org-agenda-get-progress)
4822 (defun org-agenda-get-progress ()
4823 "Return the logged TODO entries for agenda display."
4824 (let* ((props (list 'mouse-face 'highlight
4825 'org-not-done-regexp org-not-done-regexp
4826 'org-todo-regexp org-todo-regexp
4827 'org-complex-heading-regexp org-complex-heading-regexp
4828 'help-echo
4829 (format "mouse-2 or RET jump to org file %s"
4830 (abbreviate-file-name buffer-file-name))))
4831 (items (if (consp org-agenda-show-log)
4832 org-agenda-show-log
4833 org-agenda-log-mode-items))
4834 (parts
4835 (delq nil
4836 (list
4837 (if (memq 'closed items) (concat "\\<" org-closed-string))
4838 (if (memq 'clock items) (concat "\\<" org-clock-string))
4839 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4840 (parts-re (if parts (mapconcat 'identity parts "\\|")
4841 (error "`org-agenda-log-mode-items' is empty")))
4842 (regexp (concat
4843 "\\(" parts-re "\\)"
4844 " *\\["
4845 (regexp-quote
4846 (substring
4847 (format-time-string
4848 (car org-time-stamp-formats)
4849 (apply 'encode-time ; DATE bound by calendar
4850 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4851 1 11))))
4852 (org-agenda-search-headline-for-time nil)
4853 marker hdmarker priority category tags closedp statep clockp state
4854 ee txt extra timestr rest clocked)
4855 (goto-char (point-min))
4856 (while (re-search-forward regexp nil t)
4857 (catch :skip
4858 (org-agenda-skip)
4859 (setq marker (org-agenda-new-marker (match-beginning 0))
4860 closedp (equal (match-string 1) org-closed-string)
4861 statep (equal (string-to-char (match-string 1)) ?-)
4862 clockp (not (or closedp statep))
4863 state (and statep (match-string 2))
4864 category (org-get-category (match-beginning 0))
4865 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4867 (when (string-match "\\]" timestr)
4868 ;; substring should only run to end of time stamp
4869 (setq rest (substring timestr (match-end 0))
4870 timestr (substring timestr 0 (match-end 0)))
4871 (if (and (not closedp) (not statep)
4872 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4873 (progn (setq timestr (concat (substring timestr 0 -1)
4874 "-" (match-string 1 rest) "]"))
4875 (setq clocked (match-string 2 rest)))
4876 (setq clocked "-")))
4877 (save-excursion
4878 (setq extra
4879 (cond
4880 ((not org-agenda-log-mode-add-notes) nil)
4881 (statep
4882 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4883 (match-string 1)))
4884 (clockp
4885 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4886 (match-string 1)))))
4887 (if (not (re-search-backward "^\\*+ " nil t))
4888 (setq txt org-agenda-no-heading-message)
4889 (goto-char (match-beginning 0))
4890 (setq hdmarker (org-agenda-new-marker)
4891 tags (org-get-tags-at))
4892 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4893 (setq txt (match-string 1))
4894 (when extra
4895 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4896 (setq txt (concat (substring txt 0 (match-beginning 1))
4897 " - " extra " " (match-string 2 txt)))
4898 (setq txt (concat txt " - " extra))))
4899 (setq txt (org-format-agenda-item
4900 (cond
4901 (closedp "Closed: ")
4902 (statep (concat "State: (" state ")"))
4903 (t (concat "Clocked: (" clocked ")")))
4904 txt category tags timestr)))
4905 (setq priority 100000)
4906 (org-add-props txt props
4907 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4908 'priority priority 'org-category category
4909 'type "closed" 'date date
4910 'undone-face 'org-warning 'done-face 'org-agenda-done)
4911 (push txt ee))
4912 (goto-char (point-at-eol))))
4913 (nreverse ee)))
4915 (defun org-agenda-get-deadlines ()
4916 "Return the deadline information for agenda display."
4917 (let* ((props (list 'mouse-face 'highlight
4918 'org-not-done-regexp org-not-done-regexp
4919 'org-todo-regexp org-todo-regexp
4920 'org-complex-heading-regexp org-complex-heading-regexp
4921 'help-echo
4922 (format "mouse-2 or RET jump to org file %s"
4923 (abbreviate-file-name buffer-file-name))))
4924 (regexp org-deadline-time-regexp)
4925 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4926 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4927 d2 diff dfrac wdays pos pos1 category tags
4928 suppress-prewarning
4929 ee txt head face s todo-state show-all upcomingp donep timestr)
4930 (goto-char (point-min))
4931 (while (re-search-forward regexp nil t)
4932 (setq suppress-prewarning nil)
4933 (catch :skip
4934 (org-agenda-skip)
4935 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4936 (save-match-data
4937 (string-match org-scheduled-time-regexp
4938 (buffer-substring (point-at-bol)
4939 (point-at-eol)))))
4940 (setq suppress-prewarning
4941 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4942 org-agenda-skip-deadline-prewarning-if-scheduled
4943 0)))
4944 (setq s (match-string 1)
4945 txt nil
4946 pos (1- (match-beginning 1))
4947 todo-state (save-match-data (org-get-todo-state))
4948 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4949 (member todo-state
4950 org-agenda-repeating-timestamp-show-all))
4951 d2 (org-time-string-to-absolute
4952 (match-string 1) d1 'past show-all)
4953 diff (- d2 d1)
4954 wdays (if suppress-prewarning
4955 (let ((org-deadline-warning-days suppress-prewarning))
4956 (org-get-wdays s))
4957 (org-get-wdays s))
4958 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4959 upcomingp (and todayp (> diff 0)))
4960 ;; When to show a deadline in the calendar:
4961 ;; If the expiration is within wdays warning time.
4962 ;; Past-due deadlines are only shown on the current date
4963 (if (and (or (and (<= diff wdays)
4964 (and todayp (not org-agenda-only-exact-dates)))
4965 (= diff 0)))
4966 (save-excursion
4967 ;; (setq todo-state (org-get-todo-state))
4968 (setq donep (member todo-state org-done-keywords))
4969 (if (and donep
4970 (or org-agenda-skip-deadline-if-done
4971 (not (= diff 0))))
4972 (setq txt nil)
4973 (setq category (org-get-category))
4974 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4975 (setq txt org-agenda-no-heading-message)
4976 (goto-char (match-end 0))
4977 (setq pos1 (match-beginning 0))
4978 (setq tags (org-get-tags-at pos1))
4979 (setq head (buffer-substring-no-properties
4980 (point)
4981 (progn (skip-chars-forward "^\r\n")
4982 (point))))
4983 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4984 (setq timestr
4985 (concat (substring s (match-beginning 1)) " "))
4986 (setq timestr 'time))
4987 (setq txt (org-format-agenda-item
4988 (if (= diff 0)
4989 (car org-agenda-deadline-leaders)
4990 (if (functionp
4991 (nth 1 org-agenda-deadline-leaders))
4992 (funcall
4993 (nth 1 org-agenda-deadline-leaders)
4994 diff date)
4995 (format (nth 1 org-agenda-deadline-leaders)
4996 diff)))
4997 head category tags
4998 (if (not (= diff 0)) nil timestr)))))
4999 (when txt
5000 (setq face (org-agenda-deadline-face dfrac wdays))
5001 (org-add-props txt props
5002 'org-marker (org-agenda-new-marker pos)
5003 'org-hd-marker (org-agenda-new-marker pos1)
5004 'priority (+ (- diff)
5005 (org-get-priority txt))
5006 'org-category category
5007 'todo-state todo-state
5008 'type (if upcomingp "upcoming-deadline" "deadline")
5009 'date (if upcomingp date d2)
5010 'face (if donep 'org-agenda-done face)
5011 'undone-face face 'done-face 'org-agenda-done)
5012 (push txt ee))))))
5013 (nreverse ee)))
5015 (defun org-agenda-deadline-face (fraction &optional wdays)
5016 "Return the face to displaying a deadline item.
5017 FRACTION is what fraction of the head-warning time has passed."
5018 (if (equal wdays 0) (setq fraction 1.))
5019 (let ((faces org-agenda-deadline-faces) f)
5020 (catch 'exit
5021 (while (setq f (pop faces))
5022 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5024 (defun org-agenda-get-scheduled (&optional deadline-results)
5025 "Return the scheduled information for agenda display."
5026 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5027 'org-todo-regexp org-todo-regexp
5028 'org-complex-heading-regexp org-complex-heading-regexp
5029 'done-face 'org-agenda-done
5030 'mouse-face 'highlight
5031 'help-echo
5032 (format "mouse-2 or RET jump to org file %s"
5033 (abbreviate-file-name buffer-file-name))))
5034 (regexp org-scheduled-time-regexp)
5035 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5036 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5038 (deadline-position-alist
5039 (mapcar (lambda (a) (and (setq mm (get-text-property
5040 0 'org-hd-marker a))
5041 (cons (marker-position mm) a)))
5042 deadline-results))
5043 d2 diff pos pos1 category tags donep
5044 ee txt head pastschedp todo-state face timestr s habitp show-all)
5045 (goto-char (point-min))
5046 (while (re-search-forward regexp nil t)
5047 (catch :skip
5048 (org-agenda-skip)
5049 (setq s (match-string 1)
5050 txt nil
5051 pos (1- (match-beginning 1))
5052 todo-state (save-match-data (org-get-todo-state))
5053 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5054 (member todo-state
5055 org-agenda-repeating-timestamp-show-all))
5056 d2 (org-time-string-to-absolute
5057 (match-string 1) d1 'past show-all)
5058 diff (- d2 d1))
5059 (setq pastschedp (and todayp (< diff 0)))
5060 ;; When to show a scheduled item in the calendar:
5061 ;; If it is on or past the date.
5062 (when (or (and (< diff 0)
5063 (< (abs diff) org-scheduled-past-days)
5064 (and todayp (not org-agenda-only-exact-dates)))
5065 (= diff 0))
5066 (save-excursion
5067 (setq donep (member todo-state org-done-keywords))
5068 (if (and donep
5069 (or org-agenda-skip-scheduled-if-done
5070 (not (= diff 0))
5071 (and (functionp 'org-is-habit-p)
5072 (org-is-habit-p))))
5073 (setq txt nil)
5074 (setq habitp (and (functionp 'org-is-habit-p)
5075 (org-is-habit-p)))
5076 (setq category (org-get-category))
5077 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5078 (setq txt org-agenda-no-heading-message)
5079 (goto-char (match-end 0))
5080 (setq pos1 (match-beginning 0))
5081 (if habitp
5082 (if (or (not org-habit-show-habits)
5083 (and (not todayp)
5084 org-habit-show-habits-only-for-today))
5085 (throw :skip nil))
5086 (if (and
5087 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5088 (and org-agenda-skip-scheduled-if-deadline-is-shown
5089 pastschedp))
5090 (setq mm (assoc pos1 deadline-position-alist)))
5091 (throw :skip nil)))
5092 (setq tags (org-get-tags-at))
5093 (setq head (buffer-substring-no-properties
5094 (point)
5095 (progn (skip-chars-forward "^\r\n") (point))))
5096 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5097 (setq timestr
5098 (concat (substring s (match-beginning 1)) " "))
5099 (setq timestr 'time))
5100 (setq txt (org-format-agenda-item
5101 (if (= diff 0)
5102 (car org-agenda-scheduled-leaders)
5103 (format (nth 1 org-agenda-scheduled-leaders)
5104 (- 1 diff)))
5105 head category tags
5106 (if (not (= diff 0)) nil timestr)
5107 nil habitp))))
5108 (when txt
5109 (setq face
5110 (cond
5111 ((and (not habitp) pastschedp)
5112 'org-scheduled-previously)
5113 (todayp 'org-scheduled-today)
5114 (t 'org-scheduled))
5115 habitp (and habitp (org-habit-parse-todo)))
5116 (org-add-props txt props
5117 'undone-face face
5118 'face (if donep 'org-agenda-done face)
5119 'org-marker (org-agenda-new-marker pos)
5120 'org-hd-marker (org-agenda-new-marker pos1)
5121 'type (if pastschedp "past-scheduled" "scheduled")
5122 'date (if pastschedp d2 date)
5123 'priority (if habitp
5124 (org-habit-get-priority habitp)
5125 (+ 94 (- 5 diff) (org-get-priority txt)))
5126 'org-category category
5127 'org-habit-p habitp
5128 'todo-state todo-state)
5129 (push txt ee))))))
5130 (nreverse ee)))
5132 (defun org-agenda-get-blocks ()
5133 "Return the date-range information for agenda display."
5134 (let* ((props (list 'face nil
5135 'org-not-done-regexp org-not-done-regexp
5136 'org-todo-regexp org-todo-regexp
5137 'org-complex-heading-regexp org-complex-heading-regexp
5138 'mouse-face 'highlight
5139 'help-echo
5140 (format "mouse-2 or RET jump to org file %s"
5141 (abbreviate-file-name buffer-file-name))))
5142 (regexp org-tr-regexp)
5143 (d0 (calendar-absolute-from-gregorian date))
5144 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5145 head donep)
5146 (goto-char (point-min))
5147 (while (re-search-forward regexp nil t)
5148 (catch :skip
5149 (org-agenda-skip)
5150 (setq pos (point))
5151 (let ((start-time (match-string 1))
5152 (end-time (match-string 2)))
5153 (setq s1 (match-string 1)
5154 s2 (match-string 2)
5155 d1 (time-to-days (org-time-string-to-time s1))
5156 d2 (time-to-days (org-time-string-to-time s2)))
5157 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5158 ;; Only allow days between the limits, because the normal
5159 ;; date stamps will catch the limits.
5160 (save-excursion
5161 (setq todo-state (org-get-todo-state))
5162 (setq donep (member todo-state org-done-keywords))
5163 (if (and donep org-agenda-skip-timestamp-if-done)
5164 (throw :skip t))
5165 (setq marker (org-agenda-new-marker (point)))
5166 (setq category (org-get-category))
5167 (if (not (re-search-backward "^\\*+ " nil t))
5168 (setq txt org-agenda-no-heading-message)
5169 (goto-char (match-beginning 0))
5170 (setq hdmarker (org-agenda-new-marker (point)))
5171 (setq tags (org-get-tags-at))
5172 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5173 (setq head (match-string 1))
5174 (let ((remove-re
5175 (if org-agenda-remove-timeranges-from-blocks
5176 (concat
5177 "<" (regexp-quote s1) ".*?>"
5178 "--"
5179 "<" (regexp-quote s2) ".*?>")
5180 nil)))
5181 (setq txt (org-format-agenda-item
5182 (format
5183 (nth (if (= d1 d2) 0 1)
5184 org-agenda-timerange-leaders)
5185 (1+ (- d0 d1)) (1+ (- d2 d1)))
5186 head category tags
5187 (cond ((= d1 d0)
5188 (concat "<" start-time ">"))
5189 ((= d2 d0)
5190 (concat "<" end-time ">"))
5191 (t nil))
5192 remove-re))))
5193 (org-add-props txt props
5194 'org-marker marker 'org-hd-marker hdmarker
5195 'type "block" 'date date
5196 'todo-state todo-state
5197 'priority (org-get-priority txt) 'org-category category)
5198 (push txt ee))))
5199 (goto-char pos)))
5200 ;; Sort the entries by expiration date.
5201 (nreverse ee)))
5203 ;;; Agenda presentation and sorting
5205 (defvar org-prefix-has-time nil
5206 "A flag, set by `org-compile-prefix-format'.
5207 The flag is set if the currently compiled format contains a `%t'.")
5208 (defvar org-prefix-has-tag nil
5209 "A flag, set by `org-compile-prefix-format'.
5210 The flag is set if the currently compiled format contains a `%T'.")
5211 (defvar org-prefix-has-effort nil
5212 "A flag, set by `org-compile-prefix-format'.
5213 The flag is set if the currently compiled format contains a `%e'.")
5214 (defvar org-prefix-category-length nil
5215 "Used by `org-compile-prefix-format' to remember the category field width.")
5216 (defvar org-prefix-category-max-length nil
5217 "Used by `org-compile-prefix-format' to remember the category field width.")
5219 (defun org-agenda-get-category-icon (category)
5220 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5221 (dolist (entry org-agenda-category-icon-alist)
5222 (when (org-string-match-p (car entry) category)
5223 (if (listp (cadr entry))
5224 (return (cadr entry))
5225 (return (apply 'create-image (cdr entry)))))))
5227 (defun org-format-agenda-item (extra txt &optional category tags dotime
5228 remove-re habitp)
5229 "Format TXT to be inserted into the agenda buffer.
5230 In particular, it adds the prefix and corresponding text properties. EXTRA
5231 must be a string and replaces the `%s' specifier in the prefix format.
5232 CATEGORY (string, symbol or nil) may be used to overrule the default
5233 category taken from local variable or file name. It will replace the `%c'
5234 specifier in the format. DOTIME, when non-nil, indicates that a
5235 time-of-day should be extracted from TXT for sorting of this entry, and for
5236 the `%t' specifier in the format. When DOTIME is a string, this string is
5237 searched for a time before TXT is. TAGS can be the tags of the headline.
5238 Any match of REMOVE-RE will be removed from TXT."
5239 (save-match-data
5240 ;; Diary entries sometimes have extra whitespace at the beginning
5241 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5243 ;; Fix the tags part in txt
5244 (setq txt (org-agenda-fix-displayed-tags
5245 txt tags
5246 org-agenda-show-inherited-tags
5247 org-agenda-hide-tags-regexp))
5248 (let* ((category (or category
5249 (if (stringp org-category)
5250 org-category
5251 (and org-category (symbol-name org-category)))
5252 (if buffer-file-name
5253 (file-name-sans-extension
5254 (file-name-nondirectory buffer-file-name))
5255 "")))
5256 (category-icon (org-agenda-get-category-icon category))
5257 (category-icon (if category-icon
5258 (propertize " " 'display category-icon)
5259 ""))
5260 ;; time, tag, effort are needed for the eval of the prefix format
5261 (tag (if tags (nth (1- (length tags)) tags) ""))
5262 time effort neffort
5263 (ts (if dotime (concat
5264 (if (stringp dotime) dotime "")
5265 (and org-agenda-search-headline-for-time txt))))
5266 (time-of-day (and dotime (org-get-time-of-day ts)))
5267 stamp plain s0 s1 s2 rtn srp l
5268 duration thecategory)
5269 (and (org-mode-p) buffer-file-name
5270 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5271 (when (and dotime time-of-day)
5272 ;; Extract starting and ending time and move them to prefix
5273 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5274 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5275 (setq s0 (match-string 0 ts)
5276 srp (and stamp (match-end 3))
5277 s1 (match-string (if plain 1 2) ts)
5278 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5280 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5281 ;; them, we might want to remove them there to avoid duplication.
5282 ;; The user can turn this off with a variable.
5283 (if (and org-prefix-has-time
5284 org-agenda-remove-times-when-in-prefix (or stamp plain)
5285 (string-match (concat (regexp-quote s0) " *") txt)
5286 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5287 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5288 (= (match-beginning 0) 0)
5290 (setq txt (replace-match "" nil nil txt))))
5291 ;; Normalize the time(s) to 24 hour
5292 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5293 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5295 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5296 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5297 (setq s2
5298 (org-minutes-to-hh:mm-string
5299 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5301 ;; Compute the duration
5302 (when s2
5303 (setq duration (- (org-hh:mm-string-to-minutes s2)
5304 (org-hh:mm-string-to-minutes s1)))))
5306 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5307 txt)
5308 ;; Tags are in the string
5309 (if (or (eq org-agenda-remove-tags t)
5310 (and org-agenda-remove-tags
5311 org-prefix-has-tag))
5312 (setq txt (replace-match "" t t txt))
5313 (setq txt (replace-match
5314 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5315 (match-string 2 txt))
5316 t t txt))))
5317 (when (org-mode-p)
5318 (setq effort
5319 (condition-case nil
5320 (org-get-effort
5321 (or (get-text-property 0 'org-hd-marker txt)
5322 (get-text-property 0 'org-marker txt)))
5323 (error nil)))
5324 (when effort
5325 (setq neffort (org-duration-string-to-minutes effort)
5326 effort (setq effort (concat "[" effort "]" )))))
5328 (when remove-re
5329 (while (string-match remove-re txt)
5330 (setq txt (replace-match "" t t txt))))
5332 ;; Set org-heading property on `rtn' to mark the start of the
5333 ;; heading.
5334 (setq txt (propertize txt 'org-heading t))
5336 ;; Prepare the variables needed in the eval of the compiled format
5337 (setq time (cond (s2 (concat
5338 (org-agenda-time-of-day-to-ampm-maybe s1)
5339 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5340 (if org-agenda-timegrid-use-ampm " ")))
5341 (s1 (concat
5342 (org-agenda-time-of-day-to-ampm-maybe s1)
5343 (if org-agenda-timegrid-use-ampm
5344 "........ "
5345 "......")))
5346 (t ""))
5347 extra (or (and (not habitp) extra) "")
5348 category (if (symbolp category) (symbol-name category) category)
5349 thecategory (copy-sequence category))
5350 (if (string-match org-bracket-link-regexp category)
5351 (progn
5352 (setq l (if (match-end 3)
5353 (- (match-end 3) (match-beginning 3))
5354 (- (match-end 1) (match-beginning 1))))
5355 (when (< l (or org-prefix-category-length 0))
5356 (setq category (copy-sequence category))
5357 (org-add-props category nil
5358 'extra-space (make-string
5359 (- org-prefix-category-length l 1) ?\ ))))
5360 (if (and org-prefix-category-max-length
5361 (>= (length category) org-prefix-category-max-length))
5362 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5363 ;; Evaluate the compiled format
5364 (setq rtn (concat (eval org-prefix-format-compiled) txt))
5366 ;; And finally add the text properties
5367 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5368 (org-add-props rtn nil
5369 'org-category (if thecategory (downcase thecategory) category)
5370 'tags (mapcar 'org-downcase-keep-props tags)
5371 'org-highest-priority org-highest-priority
5372 'org-lowest-priority org-lowest-priority
5373 'time-of-day time-of-day
5374 'duration duration
5375 'effort effort
5376 'effort-minutes neffort
5377 'txt txt
5378 'time time
5379 'extra extra
5380 'dotime dotime))))
5382 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5383 "Remove tags string from TXT, and add a modified list of tags.
5384 The modified list may contain inherited tags, and tags matched by
5385 `org-agenda-hide-tags-regexp' will be removed."
5386 (when (or add-inherited hide-re)
5387 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5388 (setq txt (substring txt 0 (match-beginning 0))))
5389 (setq tags
5390 (delq nil
5391 (mapcar (lambda (tg)
5392 (if (or (and hide-re (string-match hide-re tg))
5393 (and (not add-inherited)
5394 (get-text-property 0 'inherited tg)))
5396 tg))
5397 tags)))
5398 (when tags
5399 (let ((have-i (get-text-property 0 'inherited (car tags)))
5401 (setq txt (concat txt " :"
5402 (mapconcat
5403 (lambda (x)
5404 (setq i (get-text-property 0 'inherited x))
5405 (if (and have-i (not i))
5406 (progn
5407 (setq have-i nil)
5408 (concat ":" x))
5410 tags ":")
5411 (if have-i "::" ":"))))))
5412 txt)
5414 (defun org-downcase-keep-props (s)
5415 (let ((props (text-properties-at 0 s)))
5416 (setq s (downcase s))
5417 (add-text-properties 0 (length s) props s)
5420 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5421 (defvar org-agenda-sorting-strategy-selected nil)
5423 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5424 (catch 'exit
5425 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5426 ((and todayp (member 'today (car org-agenda-time-grid))))
5427 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5428 ((member 'weekly (car org-agenda-time-grid)))
5429 (t (throw 'exit list)))
5430 (let* ((have (delq nil (mapcar
5431 (lambda (x) (get-text-property 1 'time-of-day x))
5432 list)))
5433 (string (nth 1 org-agenda-time-grid))
5434 (gridtimes (nth 2 org-agenda-time-grid))
5435 (req (car org-agenda-time-grid))
5436 (remove (member 'remove-match req))
5437 new time)
5438 (if (and (member 'require-timed req) (not have))
5439 ;; don't show empty grid
5440 (throw 'exit list))
5441 (while (setq time (pop gridtimes))
5442 (unless (and remove (member time have))
5443 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5444 (push (org-format-agenda-item
5445 nil string "" nil
5446 (concat (substring time 0 -2) ":" (substring time -2)))
5447 new)
5448 (put-text-property
5449 2 (length (car new)) 'face 'org-time-grid (car new))))
5450 (when (and todayp org-agenda-show-current-time-in-grid)
5451 (push (org-format-agenda-item
5453 org-agenda-current-time-string
5454 "" nil
5455 (format-time-string "%H:%M "))
5456 new)
5457 (put-text-property
5458 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5460 (if (member 'time-up org-agenda-sorting-strategy-selected)
5461 (append new list)
5462 (append list new)))))
5464 (defun org-compile-prefix-format (key)
5465 "Compile the prefix format into a Lisp form that can be evaluated.
5466 The resulting form is returned and stored in the variable
5467 `org-prefix-format-compiled'."
5468 (setq org-prefix-has-time nil org-prefix-has-tag nil
5469 org-prefix-category-length nil org-prefix-has-effort nil)
5470 (let ((s (cond
5471 ((stringp org-agenda-prefix-format)
5472 org-agenda-prefix-format)
5473 ((assq key org-agenda-prefix-format)
5474 (cdr (assq key org-agenda-prefix-format)))
5475 (t " %-12:c%?-12t% s")))
5476 (start 0)
5477 varform vars var e c f opt)
5478 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5479 s start)
5480 (setq var (or (cdr (assoc (match-string 4 s)
5481 '(("c" . category) ("t" . time) ("s" . extra)
5482 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5483 'eval)
5484 c (or (match-string 3 s) "")
5485 opt (match-beginning 1)
5486 start (1+ (match-beginning 0)))
5487 (if (equal var 'time) (setq org-prefix-has-time t))
5488 (if (equal var 'tag) (setq org-prefix-has-tag t))
5489 (if (equal var 'effort) (setq org-prefix-has-effort t))
5490 (setq f (concat "%" (match-string 2 s) "s"))
5491 (when (equal var 'category)
5492 (setq org-prefix-category-length
5493 (floor (abs (string-to-number (match-string 2 s)))))
5494 (setq org-prefix-category-max-length
5495 (let ((x (match-string 2 s)))
5496 (save-match-data
5497 (if (string-match "\\.[0-9]+" x)
5498 (string-to-number (substring (match-string 0 x) 1)))))))
5499 (if (eq var 'eval)
5500 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5501 (if opt
5502 (setq varform
5503 `(if (equal "" ,var)
5505 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5506 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5507 (setq s (replace-match "%s" t nil s))
5508 (push varform vars))
5509 (setq vars (nreverse vars))
5510 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5512 (defun org-set-sorting-strategy (key)
5513 (if (symbolp (car org-agenda-sorting-strategy))
5514 ;; the old format
5515 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5516 (setq org-agenda-sorting-strategy-selected
5517 (or (cdr (assq key org-agenda-sorting-strategy))
5518 (cdr (assq 'agenda org-agenda-sorting-strategy))
5519 '(time-up category-keep priority-down)))))
5521 (defun org-get-time-of-day (s &optional string mod24)
5522 "Check string S for a time of day.
5523 If found, return it as a military time number between 0 and 2400.
5524 If not found, return nil.
5525 The optional STRING argument forces conversion into a 5 character wide string
5526 HH:MM."
5527 (save-match-data
5528 (when
5529 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5530 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5531 (let* ((h (string-to-number (match-string 1 s)))
5532 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5533 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5534 (am-p (equal ampm "am"))
5535 (h1 (cond ((not ampm) h)
5536 ((= h 12) (if am-p 0 12))
5537 (t (+ h (if am-p 0 12)))))
5538 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5539 (mod h1 24) h1))
5540 (t0 (+ (* 100 h2) m))
5541 (t1 (concat (if (>= h1 24) "+" " ")
5542 (if (and org-agenda-time-leading-zero
5543 (< t0 1000)) "0" "")
5544 (if (< t0 100) "0" "")
5545 (if (< t0 10) "0" "")
5546 (int-to-string t0))))
5547 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5549 (defvar org-agenda-before-sorting-filter-function nil
5550 "Function to be applied to agenda items prior to sorting.
5551 Prior to sorting also means just before they are inserted into the agenda.
5553 To aid sorting, you may revisit the original entries and add more text
5554 properties which will later be used by the sorting functions.
5556 The function should take a string argument, an agenda line.
5557 It has access to the text properties in that line, which contain among
5558 other things, the property `org-hd-marker' that points to the entry
5559 where the line comes from. Note that not all lines going into the agenda
5560 have this property, only most.
5562 The function should return the modified string. It is probably best
5563 to ONLY change text properties.
5565 You can also use this function as a filter, by returning nil for lines
5566 you don't want to have in the agenda at all. For this application, you
5567 could bind the variable in the options section of a custom command.")
5569 (defun org-finalize-agenda-entries (list &optional nosort)
5570 "Sort and concatenate the agenda items."
5571 (setq list (mapcar 'org-agenda-highlight-todo list))
5572 (if nosort
5573 list
5574 (when org-agenda-before-sorting-filter-function
5575 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5576 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5578 (defun org-agenda-highlight-todo (x)
5579 (let ((org-done-keywords org-done-keywords-for-agenda)
5580 (case-fold-search nil)
5582 (if (eq x 'line)
5583 (save-excursion
5584 (beginning-of-line 1)
5585 (setq re (org-get-at-bol 'org-todo-regexp))
5586 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
5587 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5588 (add-text-properties (match-beginning 0) (match-end 1)
5589 (list 'face (org-get-todo-face 1)))
5590 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5591 (delete-region (match-beginning 1) (1- (match-end 0)))
5592 (goto-char (match-beginning 1))
5593 (insert (format org-agenda-todo-keyword-format s)))))
5594 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
5595 (setq re (concat (get-text-property 0 'org-todo-regexp x)))
5596 (when (and re
5597 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5598 x (or pl 0)) pl))
5599 (add-text-properties
5600 (or (match-end 1) (match-end 0)) (match-end 0)
5601 (list 'face (org-get-todo-face (match-string 2 x)))
5603 (when (match-end 1)
5604 (setq x (concat (substring x 0 (match-end 1))
5605 (format org-agenda-todo-keyword-format
5606 (match-string 2 x))
5607 (org-add-props " " (text-properties-at 0 x))
5608 (substring x (match-end 3)))))))
5609 x)))
5611 (defsubst org-cmp-priority (a b)
5612 "Compare the priorities of string A and B."
5613 (let ((pa (or (get-text-property 1 'priority a) 0))
5614 (pb (or (get-text-property 1 'priority b) 0)))
5615 (cond ((> pa pb) +1)
5616 ((< pa pb) -1)
5617 (t nil))))
5619 (defsubst org-cmp-effort (a b)
5620 "Compare the priorities of string A and B."
5621 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5622 (ea (or (get-text-property 1 'effort-minutes a) def))
5623 (eb (or (get-text-property 1 'effort-minutes b) def)))
5624 (cond ((> ea eb) +1)
5625 ((< ea eb) -1)
5626 (t nil))))
5628 (defsubst org-cmp-category (a b)
5629 "Compare the string values of categories of strings A and B."
5630 (let ((ca (or (get-text-property 1 'org-category a) ""))
5631 (cb (or (get-text-property 1 'org-category b) "")))
5632 (cond ((string-lessp ca cb) -1)
5633 ((string-lessp cb ca) +1)
5634 (t nil))))
5636 (defsubst org-cmp-todo-state (a b)
5637 "Compare the todo states of strings A and B."
5638 (let* ((ma (or (get-text-property 1 'org-marker a)
5639 (get-text-property 1 'org-hd-marker a)))
5640 (mb (or (get-text-property 1 'org-marker b)
5641 (get-text-property 1 'org-hd-marker b)))
5642 (fa (and ma (marker-buffer ma)))
5643 (fb (and mb (marker-buffer mb)))
5644 (todo-kwds
5645 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5646 (and fb (with-current-buffer fb org-todo-keywords-1))))
5647 (ta (or (get-text-property 1 'todo-state a) ""))
5648 (tb (or (get-text-property 1 'todo-state b) ""))
5649 (la (- (length (member ta todo-kwds))))
5650 (lb (- (length (member tb todo-kwds))))
5651 (donepa (member ta org-done-keywords-for-agenda))
5652 (donepb (member tb org-done-keywords-for-agenda)))
5653 (cond ((and donepa (not donepb)) -1)
5654 ((and (not donepa) donepb) +1)
5655 ((< la lb) -1)
5656 ((< lb la) +1)
5657 (t nil))))
5659 (defsubst org-cmp-alpha (a b)
5660 "Compare the headlines, alphabetically."
5661 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
5662 (plb (text-property-any 0 (length b) 'org-heading t b))
5663 (ta (and pla (substring a pla)))
5664 (tb (and plb (substring b plb))))
5665 (when pla
5666 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5667 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5668 (setq ta (substring ta (match-end 0))))
5669 (setq ta (downcase ta)))
5670 (when plb
5671 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5672 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5673 (setq tb (substring tb (match-end 0))))
5674 (setq tb (downcase tb)))
5675 (cond ((not ta) +1)
5676 ((not tb) -1)
5677 ((string-lessp ta tb) -1)
5678 ((string-lessp tb ta) +1)
5679 (t nil))))
5681 (defsubst org-cmp-tag (a b)
5682 "Compare the string values of the first tags of A and B."
5683 (let ((ta (car (last (get-text-property 1 'tags a))))
5684 (tb (car (last (get-text-property 1 'tags b)))))
5685 (cond ((not ta) +1)
5686 ((not tb) -1)
5687 ((string-lessp ta tb) -1)
5688 ((string-lessp tb ta) +1)
5689 (t nil))))
5691 (defsubst org-cmp-time (a b)
5692 "Compare the time-of-day values of strings A and B."
5693 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5694 (ta (or (get-text-property 1 'time-of-day a) def))
5695 (tb (or (get-text-property 1 'time-of-day b) def)))
5696 (cond ((< ta tb) -1)
5697 ((< tb ta) +1)
5698 (t nil))))
5700 (defsubst org-cmp-habit-p (a b)
5701 "Compare the todo states of strings A and B."
5702 (let ((ha (get-text-property 1 'org-habit-p a))
5703 (hb (get-text-property 1 'org-habit-p b)))
5704 (cond ((and ha (not hb)) -1)
5705 ((and (not ha) hb) +1)
5706 (t nil))))
5708 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5710 (defun org-entries-lessp (a b)
5711 "Predicate for sorting agenda entries."
5712 ;; The following variables will be used when the form is evaluated.
5713 ;; So even though the compiler complains, keep them.
5714 (let* ((ss org-agenda-sorting-strategy-selected)
5715 (time-up (and (org-em 'time-up 'time-down ss)
5716 (org-cmp-time a b)))
5717 (time-down (if time-up (- time-up) nil))
5718 (priority-up (and (org-em 'priority-up 'priority-down ss)
5719 (org-cmp-priority a b)))
5720 (priority-down (if priority-up (- priority-up) nil))
5721 (effort-up (and (org-em 'effort-up 'effort-down ss)
5722 (org-cmp-effort a b)))
5723 (effort-down (if effort-up (- effort-up) nil))
5724 (category-up (and (or (org-em 'category-up 'category-down ss)
5725 (memq 'category-keep ss))
5726 (org-cmp-category a b)))
5727 (category-down (if category-up (- category-up) nil))
5728 (category-keep (if category-up +1 nil))
5729 (tag-up (and (org-em 'tag-up 'tag-down ss)
5730 (org-cmp-tag a b)))
5731 (tag-down (if tag-up (- tag-up) nil))
5732 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5733 (org-cmp-todo-state a b)))
5734 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5735 (habit-up (and (org-em 'habit-up 'habit-down ss)
5736 (org-cmp-habit-p a b)))
5737 (habit-down (if habit-up (- habit-up) nil))
5738 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5739 (org-cmp-alpha a b)))
5740 (alpha-down (if alpha-up (- alpha-up) nil))
5741 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5742 user-defined-up user-defined-down)
5743 (if (and need-user-cmp org-agenda-cmp-user-defined
5744 (functionp org-agenda-cmp-user-defined))
5745 (setq user-defined-up
5746 (funcall org-agenda-cmp-user-defined a b)
5747 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5748 (cdr (assoc
5749 (eval (cons 'or org-agenda-sorting-strategy-selected))
5750 '((-1 . t) (1 . nil) (nil . nil))))))
5752 ;;; Agenda restriction lock
5754 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5755 "Overlay to mark the headline to which agenda commands are restricted.")
5756 (overlay-put org-agenda-restriction-lock-overlay
5757 'face 'org-agenda-restriction-lock)
5758 (overlay-put org-agenda-restriction-lock-overlay
5759 'help-echo "Agendas are currently limited to this subtree.")
5760 (org-detach-overlay org-agenda-restriction-lock-overlay)
5762 (defun org-agenda-set-restriction-lock (&optional type)
5763 "Set restriction lock for agenda, to current subtree or file.
5764 Restriction will be the file if TYPE is `file', or if type is the
5765 universal prefix '(4), or if the cursor is before the first headline
5766 in the file. Otherwise, restriction will be to the current subtree."
5767 (interactive "P")
5768 (and (equal type '(4)) (setq type 'file))
5769 (setq type (cond
5770 (type type)
5771 ((org-at-heading-p) 'subtree)
5772 ((condition-case nil (org-back-to-heading t) (error nil))
5773 'subtree)
5774 (t 'file)))
5775 (if (eq type 'subtree)
5776 (progn
5777 (setq org-agenda-restrict t)
5778 (setq org-agenda-overriding-restriction 'subtree)
5779 (put 'org-agenda-files 'org-restrict
5780 (list (buffer-file-name (buffer-base-buffer))))
5781 (org-back-to-heading t)
5782 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5783 (move-marker org-agenda-restrict-begin (point))
5784 (move-marker org-agenda-restrict-end
5785 (save-excursion (org-end-of-subtree t)))
5786 (message "Locking agenda restriction to subtree"))
5787 (put 'org-agenda-files 'org-restrict
5788 (list (buffer-file-name (buffer-base-buffer))))
5789 (setq org-agenda-restrict nil)
5790 (setq org-agenda-overriding-restriction 'file)
5791 (move-marker org-agenda-restrict-begin nil)
5792 (move-marker org-agenda-restrict-end nil)
5793 (message "Locking agenda restriction to file"))
5794 (setq current-prefix-arg nil)
5795 (org-agenda-maybe-redo))
5797 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5798 "Remove the agenda restriction lock."
5799 (interactive "P")
5800 (org-detach-overlay org-agenda-restriction-lock-overlay)
5801 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5802 (setq org-agenda-overriding-restriction nil)
5803 (setq org-agenda-restrict nil)
5804 (put 'org-agenda-files 'org-restrict nil)
5805 (move-marker org-agenda-restrict-begin nil)
5806 (move-marker org-agenda-restrict-end nil)
5807 (setq current-prefix-arg nil)
5808 (message "Agenda restriction lock removed")
5809 (or noupdate (org-agenda-maybe-redo)))
5811 (defun org-agenda-maybe-redo ()
5812 "If there is any window showing the agenda view, update it."
5813 (let ((w (get-buffer-window org-agenda-buffer-name t))
5814 (w0 (selected-window)))
5815 (when w
5816 (select-window w)
5817 (org-agenda-redo)
5818 (select-window w0)
5819 (if org-agenda-overriding-restriction
5820 (message "Agenda view shifted to new %s restriction"
5821 org-agenda-overriding-restriction)
5822 (message "Agenda restriction lock removed")))))
5824 ;;; Agenda commands
5826 (defun org-agenda-check-type (error &rest types)
5827 "Check if agenda buffer is of allowed type.
5828 If ERROR is non-nil, throw an error, otherwise just return nil."
5829 (if (memq org-agenda-type types)
5831 (if error
5832 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5833 nil)))
5835 (defun org-agenda-quit ()
5836 "Exit agenda by removing the window or the buffer."
5837 (interactive)
5838 (if org-agenda-columns-active
5839 (org-columns-quit)
5840 (let ((buf (current-buffer)))
5841 (if (eq org-agenda-window-setup 'other-frame)
5842 (progn
5843 (kill-buffer buf)
5844 (org-agenda-reset-markers)
5845 (org-columns-remove-overlays)
5846 (setq org-agenda-archives-mode nil)
5847 (delete-frame))
5848 (and (not (eq org-agenda-window-setup 'current-window))
5849 (not (one-window-p))
5850 (delete-window))
5851 (kill-buffer buf)
5852 (org-agenda-reset-markers)
5853 (org-columns-remove-overlays)
5854 (setq org-agenda-archives-mode nil)))
5855 ;; Maybe restore the pre-agenda window configuration.
5856 (and org-agenda-restore-windows-after-quit
5857 (not (eq org-agenda-window-setup 'other-frame))
5858 org-pre-agenda-window-conf
5859 (set-window-configuration org-pre-agenda-window-conf))))
5861 (defun org-agenda-exit ()
5862 "Exit agenda by removing the window or the buffer.
5863 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5864 Org-mode buffers visited directly by the user will not be touched."
5865 (interactive)
5866 (org-release-buffers org-agenda-new-buffers)
5867 (setq org-agenda-new-buffers nil)
5868 (org-agenda-quit))
5870 (defun org-agenda-execute (arg)
5871 "Execute another agenda command, keeping same window.
5872 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5873 in the agenda."
5874 (interactive "P")
5875 (let ((org-agenda-window-setup 'current-window))
5876 (org-agenda arg)))
5878 (defun org-agenda-redo ()
5879 "Rebuild Agenda.
5880 When this is the global TODO list, a prefix argument will be interpreted."
5881 (interactive)
5882 (let* ((org-agenda-keep-modes t)
5883 (filter org-agenda-filter)
5884 (preset (get 'org-agenda-filter :preset-filter))
5885 (org-agenda-filter-while-redo (or filter preset))
5886 (cols org-agenda-columns-active)
5887 (line (org-current-line))
5888 (window-line (- line (org-current-line (window-start))))
5889 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5890 (put 'org-agenda-filter :preset-filter nil)
5891 (and cols (org-columns-quit))
5892 (message "Rebuilding agenda buffer...")
5893 (org-let lprops '(eval org-agenda-redo-command))
5894 (setq org-agenda-undo-list nil
5895 org-agenda-pending-undo-list nil)
5896 (message "Rebuilding agenda buffer...done")
5897 (put 'org-agenda-filter :preset-filter preset)
5898 (and (or filter preset) (org-agenda-filter-apply filter))
5899 (and cols (interactive-p) (org-agenda-columns))
5900 (org-goto-line line)
5901 (recenter window-line)))
5904 (defvar org-global-tags-completion-table nil)
5905 (defvar org-agenda-filter-form nil)
5906 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5907 "Keep only those lines in the agenda buffer that have a specific tag.
5908 The tag is selected with its fast selection letter, as configured.
5909 With prefix argument STRIP, remove all lines that do have the tag.
5910 A lisp caller can specify CHAR. NARROW means that the new tag should be
5911 used to narrow the search - the interactive user can also press `-' or `+'
5912 to switch to narrowing."
5913 (interactive "P")
5914 (let* ((alist org-tag-alist-for-agenda)
5915 (tag-chars (mapconcat
5916 (lambda (x) (if (and (not (symbolp (car x)))
5917 (cdr x))
5918 (char-to-string (cdr x))
5919 ""))
5920 alist ""))
5921 (efforts (org-split-string
5922 (or (cdr (assoc (concat org-effort-property "_ALL")
5923 org-global-properties))
5924 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5925 (effort-op org-agenda-filter-effort-default-operator)
5926 (effort-prompt "")
5927 (inhibit-read-only t)
5928 (current org-agenda-filter)
5929 maybe-reftresh a n tag)
5930 (unless char
5931 (message
5932 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5933 (if narrow "Narrow" "Filter") tag-chars
5934 (if org-agenda-auto-exclude-function "[RET], " ""))
5935 (setq char (read-char)))
5936 (when (member char '(?+ ?-))
5937 ;; Narrowing down
5938 (cond ((equal char ?-) (setq strip t narrow t))
5939 ((equal char ?+) (setq strip nil narrow t)))
5940 (message
5941 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5942 (setq char (read-char)))
5943 (when (member char '(?< ?> ?= ??))
5944 ;; An effort operator
5945 (setq effort-op (char-to-string char))
5946 (setq alist nil) ; to make sure it will be interpreted as effort.
5947 (unless (equal char ??)
5948 (loop for i from 0 to 9 do
5949 (setq effort-prompt
5950 (concat
5951 effort-prompt " ["
5952 (if (= i 9) "0" (int-to-string (1+ i)))
5953 "]" (nth i efforts))))
5954 (message "Effort%s: %s " effort-op effort-prompt)
5955 (setq char (read-char))
5956 (when (or (< char ?0) (> char ?9))
5957 (error "Need 1-9,0 to select effort" ))))
5958 (when (equal char ?\t)
5959 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5960 (org-set-local 'org-global-tags-completion-table
5961 (org-global-tags-completion-table)))
5962 (let ((completion-ignore-case t))
5963 (setq tag (org-icompleting-read
5964 "Tag: " org-global-tags-completion-table))))
5965 (cond
5966 ((equal char ?\r)
5967 (org-agenda-filter-by-tag-show-all)
5968 (when org-agenda-auto-exclude-function
5969 (setq org-agenda-filter '())
5970 (dolist (tag (org-agenda-get-represented-tags))
5971 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5972 (if modifier
5973 (push modifier org-agenda-filter))))
5974 (if (not (null org-agenda-filter))
5975 (org-agenda-filter-apply org-agenda-filter)))
5976 (setq maybe-reftresh t))
5977 ((equal char ?/)
5978 (org-agenda-filter-by-tag-show-all)
5979 (when (get 'org-agenda-filter :preset-filter)
5980 (org-agenda-filter-apply org-agenda-filter))
5981 (setq maybe-reftresh t))
5982 ((or (equal char ?\ )
5983 (setq a (rassoc char alist))
5984 (and (>= char ?0) (<= char ?9)
5985 (setq n (if (= char ?0) 9 (- char ?0 1))
5986 tag (concat effort-op (nth n efforts))
5987 a (cons tag nil)))
5988 (and (= char ??)
5989 (setq tag "?eff")
5990 a (cons tag nil))
5991 (and tag (setq a (cons tag nil))))
5992 (org-agenda-filter-by-tag-show-all)
5993 (setq tag (car a))
5994 (setq org-agenda-filter
5995 (cons (concat (if strip "-" "+") tag)
5996 (if narrow current nil)))
5997 (org-agenda-filter-apply org-agenda-filter)
5998 (setq maybe-reftresh t))
5999 (t (error "Invalid tag selection character %c" char)))
6000 (when (and maybe-reftresh
6001 (eq org-agenda-clockreport-mode 'with-filter))
6002 (org-agenda-redo))))
6004 (defun org-agenda-get-represented-tags ()
6005 "Get a list of all tags currently represented in the agenda."
6006 (let (p tags)
6007 (save-excursion
6008 (goto-char (point-min))
6009 (while (setq p (next-single-property-change (point) 'tags))
6010 (goto-char p)
6011 (mapc (lambda (x) (add-to-list 'tags x))
6012 (get-text-property (point) 'tags))))
6013 tags))
6015 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6016 "Refine the current filter. See `org-agenda-filter-by-tag."
6017 (interactive "P")
6018 (org-agenda-filter-by-tag strip char 'refine))
6020 (defun org-agenda-filter-make-matcher ()
6021 "Create the form that tests a line for the agenda filter."
6022 (let (f f1)
6023 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6024 org-agenda-filter))
6025 (if (member x '("-" "+"))
6026 (setq f1 (if (equal x "-") 'tags '(not tags)))
6027 (if (string-match "[<=>?]" x)
6028 (setq f1 (org-agenda-filter-effort-form x))
6029 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6030 (if (equal (string-to-char x) ?-)
6031 (setq f1 (list 'not f1))))
6032 (push f1 f))
6033 (cons 'and (nreverse f))))
6035 (defun org-agenda-filter-effort-form (e)
6036 "Return the form to compare the effort of the current line with what E says.
6037 E looks like \"+<2:25\"."
6038 (let (op)
6039 (setq e (substring e 1))
6040 (setq op (string-to-char e) e (substring e 1))
6041 (setq op (cond ((equal op ?<) '<=)
6042 ((equal op ?>) '>=)
6043 ((equal op ??) op)
6044 (t '=)))
6045 (list 'org-agenda-compare-effort (list 'quote op)
6046 (org-duration-string-to-minutes e))))
6048 (defun org-agenda-compare-effort (op value)
6049 "Compare the effort of the current line with VALUE, using OP.
6050 If the line does not have an effort defined, return nil."
6051 (let ((eff (org-get-at-bol 'effort-minutes)))
6052 (if (equal op ??)
6053 (not eff)
6054 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6055 value))))
6057 (defun org-agenda-filter-apply (filter)
6058 "Set FILTER as the new agenda filter and apply it."
6059 (let (tags)
6060 (setq org-agenda-filter filter
6061 org-agenda-filter-form (org-agenda-filter-make-matcher))
6062 (org-agenda-set-mode-name)
6063 (save-excursion
6064 (goto-char (point-min))
6065 (while (not (eobp))
6066 (if (org-get-at-bol 'org-marker)
6067 (progn
6068 (setq tags (org-get-at-bol 'tags)) ; used in eval
6069 (if (not (eval org-agenda-filter-form))
6070 (org-agenda-filter-by-tag-hide-line))
6071 (beginning-of-line 2))
6072 (beginning-of-line 2))))
6073 (if (get-char-property (point) 'invisible)
6074 (org-agenda-previous-line))))
6076 (defun org-agenda-filter-by-tag-hide-line ()
6077 (let (ov)
6078 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6079 (point-at-eol)))
6080 (overlay-put ov 'invisible t)
6081 (overlay-put ov 'type 'tags-filter)
6082 (push ov org-agenda-filter-overlays)))
6084 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6085 (setq pos (or pos (point)))
6086 (save-excursion
6087 (dolist (ov (overlays-at pos))
6088 (when (and (overlay-get ov 'invisible)
6089 (eq (overlay-get ov 'type) 'tags-filter))
6090 (goto-char pos)
6091 (if (< (overlay-start ov) (point-at-eol))
6092 (move-overlay ov (point-at-eol)
6093 (overlay-end ov)))))))
6095 (defun org-agenda-filter-by-tag-show-all ()
6096 (mapc 'delete-overlay org-agenda-filter-overlays)
6097 (setq org-agenda-filter-overlays nil)
6098 (setq org-agenda-filter nil)
6099 (setq org-agenda-filter-form nil)
6100 (org-agenda-set-mode-name))
6102 (defun org-agenda-manipulate-query-add ()
6103 "Manipulate the query by adding a search term with positive selection.
6104 Positive selection means the term must be matched for selection of an entry."
6105 (interactive)
6106 (org-agenda-manipulate-query ?\[))
6107 (defun org-agenda-manipulate-query-subtract ()
6108 "Manipulate the query by adding a search term with negative selection.
6109 Negative selection means term must not be matched for selection of an entry."
6110 (interactive)
6111 (org-agenda-manipulate-query ?\]))
6112 (defun org-agenda-manipulate-query-add-re ()
6113 "Manipulate the query by adding a search regexp with positive selection.
6114 Positive selection means the regexp must match for selection of an entry."
6115 (interactive)
6116 (org-agenda-manipulate-query ?\{))
6117 (defun org-agenda-manipulate-query-subtract-re ()
6118 "Manipulate the query by adding a search regexp with negative selection.
6119 Negative selection means regexp must not match for selection of an entry."
6120 (interactive)
6121 (org-agenda-manipulate-query ?\}))
6122 (defun org-agenda-manipulate-query (char)
6123 (cond
6124 ((memq org-agenda-type '(timeline agenda))
6125 (let ((org-agenda-include-inactive-timestamps t))
6126 (org-agenda-redo))
6127 (message "Display now includes inactive timestamps as well"))
6128 ((eq org-agenda-type 'search)
6129 (org-add-to-string
6130 'org-agenda-query-string
6131 (if org-agenda-last-search-view-search-was-boolean
6132 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6133 (?\{ . " +{}") (?\} . " -{}"))))
6134 " "))
6135 (setq org-agenda-redo-command
6136 (list 'org-search-view
6137 org-todo-only
6138 org-agenda-query-string
6139 (+ (length org-agenda-query-string)
6140 (if (member char '(?\{ ?\})) 0 1))))
6141 (set-register org-agenda-query-register org-agenda-query-string)
6142 (org-agenda-redo))
6143 (t (error "Cannot manipulate query for %s-type agenda buffers"
6144 org-agenda-type))))
6146 (defun org-add-to-string (var string)
6147 (set var (concat (symbol-value var) string)))
6149 (defun org-agenda-goto-date (date)
6150 "Jump to DATE in agenda."
6151 (interactive (list (let ((org-read-date-prefer-future
6152 (eval org-agenda-jump-prefer-future)))
6153 (org-read-date))))
6154 (org-agenda-list nil date))
6156 (defun org-agenda-goto-today ()
6157 "Go to today."
6158 (interactive)
6159 (org-agenda-check-type t 'timeline 'agenda)
6160 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6161 (cond
6162 (tdpos (goto-char tdpos))
6163 ((eq org-agenda-type 'agenda)
6164 (let* ((sd (org-agenda-compute-starting-span
6165 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6166 (org-agenda-overriding-arguments org-agenda-last-arguments))
6167 (setf (nth 1 org-agenda-overriding-arguments) sd)
6168 (org-agenda-redo)
6169 (org-agenda-find-same-or-today-or-agenda)))
6170 (t (error "Cannot find today")))))
6172 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6173 (goto-char
6174 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6175 (text-property-any (point-min) (point-max) 'org-today t)
6176 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6177 (point-min))))
6179 (defun org-agenda-later (arg)
6180 "Go forward in time by thee current span.
6181 With prefix ARG, go forward that many times the current span."
6182 (interactive "p")
6183 (org-agenda-check-type t 'agenda)
6184 (let* ((span org-agenda-current-span)
6185 (sd org-starting-day)
6186 (greg (calendar-gregorian-from-absolute sd))
6187 (cnt (org-get-at-bol 'org-day-cnt))
6188 greg2)
6189 (cond
6190 ((eq span 'day)
6191 (setq sd (+ arg sd)))
6192 ((eq span 'week)
6193 (setq sd (+ (* 7 arg) sd)))
6194 ((eq span 'month)
6195 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6196 sd (calendar-absolute-from-gregorian greg2))
6197 (setcar greg2 (1+ (car greg2))))
6198 ((eq span 'year)
6199 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6200 sd (calendar-absolute-from-gregorian greg2))
6201 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6203 (setq sd (+ (* span arg) sd))))
6204 (let ((org-agenda-overriding-arguments
6205 (list (car org-agenda-last-arguments) sd span t)))
6206 (org-agenda-redo)
6207 (org-agenda-find-same-or-today-or-agenda cnt))))
6209 (defun org-agenda-earlier (arg)
6210 "Go backward in time by the current span.
6211 With prefix ARG, go backward that many times the current span."
6212 (interactive "p")
6213 (org-agenda-later (- arg)))
6215 (defun org-agenda-view-mode-dispatch ()
6216 "Call one of the view mode commands."
6217 (interactive)
6218 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6219 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6220 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6221 (let ((a (read-char-exclusive)))
6222 (case a
6223 (?\ (call-interactively 'org-agenda-reset-view))
6224 (?d (call-interactively 'org-agenda-day-view))
6225 (?w (call-interactively 'org-agenda-week-view))
6226 (?m (call-interactively 'org-agenda-month-view))
6227 (?y (call-interactively 'org-agenda-year-view))
6228 (?l (call-interactively 'org-agenda-log-mode))
6229 (?L (org-agenda-log-mode '(4)))
6230 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6231 (?a (call-interactively 'org-agenda-archives-mode))
6232 (?A (org-agenda-archives-mode 'files))
6233 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6234 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6235 (?G (call-interactively 'org-agenda-toggle-time-grid))
6236 (?D (call-interactively 'org-agenda-toggle-diary))
6237 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6238 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6239 (org-agenda-check-type t 'timeline 'agenda)
6240 (org-agenda-redo))
6241 (message "Display now includes inactive timestamps as well"))
6242 (?q (message "Abort"))
6243 (otherwise (error "Invalid key" )))))
6245 (defun org-agenda-reset-view ()
6246 "Switch to default view for agenda."
6247 (interactive)
6248 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6249 (defun org-agenda-day-view (&optional day-of-year)
6250 "Switch to daily view for agenda.
6251 With argument DAY-OF-YEAR, switch to that day of the year."
6252 (interactive "P")
6253 (org-agenda-change-time-span 'day day-of-year))
6254 (defun org-agenda-week-view (&optional iso-week)
6255 "Switch to daily view for agenda.
6256 With argument ISO-WEEK, switch to the corresponding ISO week.
6257 If ISO-WEEK has more then 2 digits, only the last two encode the
6258 week. Any digits before this encode a year. So 200712 means
6259 week 12 of year 2007. Years in the range 1938-2037 can also be
6260 written as 2-digit years."
6261 (interactive "P")
6262 (org-agenda-change-time-span 'week iso-week))
6263 (defun org-agenda-month-view (&optional month)
6264 "Switch to monthly view for agenda.
6265 With argument MONTH, switch to that month."
6266 (interactive "P")
6267 (org-agenda-change-time-span 'month month))
6268 (defun org-agenda-year-view (&optional year)
6269 "Switch to yearly view for agenda.
6270 With argument YEAR, switch to that year.
6271 If MONTH has more then 2 digits, only the last two encode the
6272 month. Any digits before this encode a year. So 200712 means
6273 December year 2007. Years in the range 1938-2037 can also be
6274 written as 2-digit years."
6275 (interactive "P")
6276 (when year
6277 (setq year (org-small-year-to-year year)))
6278 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6279 (org-agenda-change-time-span 'year year)
6280 (error "Abort")))
6282 (defun org-agenda-change-time-span (span &optional n)
6283 "Change the agenda view to SPAN.
6284 SPAN may be `day', `week', `month', `year'."
6285 (org-agenda-check-type t 'agenda)
6286 (if (and (not n) (equal org-agenda-current-span span))
6287 (error "Viewing span is already \"%s\"" span))
6288 (let* ((sd (or (org-get-at-bol 'day)
6289 org-starting-day))
6290 (sd (org-agenda-compute-starting-span sd span n))
6291 (org-agenda-overriding-arguments
6292 (or org-agenda-overriding-arguments
6293 (list (car org-agenda-last-arguments) sd span t))))
6294 (org-agenda-redo)
6295 (org-agenda-find-same-or-today-or-agenda))
6296 (org-agenda-set-mode-name)
6297 (message "Switched to %s view" span))
6299 (defun org-agenda-compute-starting-span (sd span &optional n)
6300 "Compute starting date for agenda.
6301 SPAN may be `day', `week', `month', `year'. The return value
6302 is a cons cell with the starting date and the number of days,
6303 so that the date SD will be in that range."
6304 (let* ((greg (calendar-gregorian-from-absolute sd))
6305 (dg (nth 1 greg))
6306 (mg (car greg))
6307 (yg (nth 2 greg)))
6308 (cond
6309 ((eq span 'day)
6310 (when n
6311 (setq sd (+ (calendar-absolute-from-gregorian
6312 (list mg 1 yg))
6313 n -1))))
6314 ((eq span 'week)
6315 (let* ((nt (calendar-day-of-week
6316 (calendar-gregorian-from-absolute sd)))
6317 (d (if org-agenda-start-on-weekday
6318 (- nt org-agenda-start-on-weekday)
6321 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6322 (when n
6323 (require 'cal-iso)
6324 (when (> n 99)
6325 (setq y1 (org-small-year-to-year (/ n 100))
6326 n (mod n 100)))
6327 (setq sd
6328 (calendar-absolute-from-iso
6329 (list n 1
6330 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6331 ((eq span 'month)
6332 (let (y1)
6333 (when (and n (> n 99))
6334 (setq y1 (org-small-year-to-year (/ n 100))
6335 n (mod n 100)))
6336 (setq sd (calendar-absolute-from-gregorian
6337 (list (or n mg) 1 (or y1 yg))))))
6338 ((eq span 'year)
6339 (setq sd (calendar-absolute-from-gregorian
6340 (list 1 1 (or n yg))))))
6341 sd))
6343 (defun org-agenda-next-date-line (&optional arg)
6344 "Jump to the next line indicating a date in agenda buffer."
6345 (interactive "p")
6346 (org-agenda-check-type t 'agenda 'timeline)
6347 (beginning-of-line 1)
6348 ;; This does not work if user makes date format that starts with a blank
6349 (if (looking-at "^\\S-") (forward-char 1))
6350 (if (not (re-search-forward "^\\S-" nil t arg))
6351 (progn
6352 (backward-char 1)
6353 (error "No next date after this line in this buffer")))
6354 (goto-char (match-beginning 0)))
6356 (defun org-agenda-previous-date-line (&optional arg)
6357 "Jump to the previous line indicating a date in agenda buffer."
6358 (interactive "p")
6359 (org-agenda-check-type t 'agenda 'timeline)
6360 (beginning-of-line 1)
6361 (if (not (re-search-backward "^\\S-" nil t arg))
6362 (error "No previous date before this line in this buffer")))
6364 ;; Initialize the highlight
6365 (defvar org-hl (make-overlay 1 1))
6366 (overlay-put org-hl 'face 'highlight)
6368 (defun org-highlight (begin end &optional buffer)
6369 "Highlight a region with overlay."
6370 (move-overlay org-hl begin end (or buffer (current-buffer))))
6372 (defun org-unhighlight ()
6373 "Detach overlay INDEX."
6374 (org-detach-overlay org-hl))
6376 ;; FIXME this is currently not used.
6377 (defun org-highlight-until-next-command (beg end &optional buffer)
6378 "Move the highlight overlay to BEG/END, remove it before the next command."
6379 (org-highlight beg end buffer)
6380 (add-hook 'pre-command-hook 'org-unhighlight-once))
6381 (defun org-unhighlight-once ()
6382 "Remove the highlight from its position, and this function from the hook."
6383 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6384 (org-unhighlight))
6386 (defun org-agenda-follow-mode ()
6387 "Toggle follow mode in an agenda buffer."
6388 (interactive)
6389 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6390 (org-agenda-set-mode-name)
6391 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6392 (org-agenda-show))
6393 (message "Follow mode is %s"
6394 (if org-agenda-follow-mode "on" "off")))
6396 (defun org-agenda-entry-text-mode (&optional arg)
6397 "Toggle entry text mode in an agenda buffer."
6398 (interactive "P")
6399 (setq org-agenda-entry-text-mode (or (integerp arg)
6400 (not org-agenda-entry-text-mode)))
6401 (org-agenda-entry-text-hide)
6402 (and org-agenda-entry-text-mode
6403 (let ((org-agenda-entry-text-maxlines
6404 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6405 (org-agenda-entry-text-show)))
6406 (org-agenda-set-mode-name)
6407 (message "Entry text mode is %s. Maximum number of lines is %d"
6408 (if org-agenda-entry-text-mode "on" "off")
6409 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6411 (defun org-agenda-clockreport-mode (&optional with-filter)
6412 "Toggle clocktable mode in an agenda buffer.
6413 With prefix arg WITH-FILTER, make the clocktable respect the current
6414 agenda filter."
6415 (interactive "P")
6416 (org-agenda-check-type t 'agenda)
6417 (if with-filter
6418 (setq org-agenda-clockreport-mode 'with-filter)
6419 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6420 (org-agenda-set-mode-name)
6421 (org-agenda-redo)
6422 (message "Clocktable mode is %s"
6423 (if org-agenda-clockreport-mode "on" "off")))
6425 (defun org-agenda-log-mode (&optional special)
6426 "Toggle log mode in an agenda buffer.
6427 With argument SPECIAL, show all possible log items, not only the ones
6428 configured in `org-agenda-log-mode-items'.
6429 With a double `C-u' prefix arg, show *only* log items, nothing else."
6430 (interactive "P")
6431 (org-agenda-check-type t 'agenda 'timeline)
6432 (setq org-agenda-show-log
6433 (if (equal special '(16))
6434 'only
6435 (if special '(closed clock state)
6436 (not org-agenda-show-log))))
6437 (org-agenda-set-mode-name)
6438 (org-agenda-redo)
6439 (message "Log mode is %s"
6440 (if org-agenda-show-log "on" "off")))
6442 (defun org-agenda-archives-mode (&optional with-files)
6443 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6444 When called with a prefix argument, include all archive files as well."
6445 (interactive "P")
6446 (setq org-agenda-archives-mode
6447 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6448 (org-agenda-set-mode-name)
6449 (org-agenda-redo)
6450 (message
6451 "%s"
6452 (cond
6453 ((eq org-agenda-archives-mode nil)
6454 "No archives are included")
6455 ((eq org-agenda-archives-mode 'trees)
6456 (format "Trees with :%s: tag are included" org-archive-tag))
6457 ((eq org-agenda-archives-mode t)
6458 (format "Trees with :%s: tag and all active archive files are included"
6459 org-archive-tag)))))
6461 (defun org-agenda-toggle-diary ()
6462 "Toggle diary inclusion in an agenda buffer."
6463 (interactive)
6464 (org-agenda-check-type t 'agenda)
6465 (setq org-agenda-include-diary (not org-agenda-include-diary))
6466 (org-agenda-redo)
6467 (org-agenda-set-mode-name)
6468 (message "Diary inclusion turned %s"
6469 (if org-agenda-include-diary "on" "off")))
6471 (defun org-agenda-toggle-deadlines ()
6472 "Toggle inclusion of entries with a deadline in an agenda buffer."
6473 (interactive)
6474 (org-agenda-check-type t 'agenda)
6475 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6476 (org-agenda-redo)
6477 (org-agenda-set-mode-name)
6478 (message "Deadlines inclusion turned %s"
6479 (if org-agenda-include-deadlines "on" "off")))
6481 (defun org-agenda-toggle-time-grid ()
6482 "Toggle time grid in an agenda buffer."
6483 (interactive)
6484 (org-agenda-check-type t 'agenda)
6485 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6486 (org-agenda-redo)
6487 (org-agenda-set-mode-name)
6488 (message "Time-grid turned %s"
6489 (if org-agenda-use-time-grid "on" "off")))
6491 (defun org-agenda-set-mode-name ()
6492 "Set the mode name to indicate all the small mode settings."
6493 (setq mode-name
6494 (list "Org-Agenda"
6495 (if (get 'org-agenda-files 'org-restrict) " []" "")
6497 '(:eval (org-agenda-span-name org-agenda-current-span))
6498 (if org-agenda-follow-mode " Follow" "")
6499 (if org-agenda-entry-text-mode " ETxt" "")
6500 (if org-agenda-include-diary " Diary" "")
6501 (if org-agenda-include-deadlines " Ddl" "")
6502 (if org-agenda-use-time-grid " Grid" "")
6503 (if (and (boundp 'org-habit-show-habits)
6504 org-habit-show-habits) " Habit" "")
6505 (if (consp org-agenda-show-log) " LogAll"
6506 (if org-agenda-show-log " Log" ""))
6507 (if (or org-agenda-filter (get 'org-agenda-filter
6508 :preset-filter))
6509 (concat " {" (mapconcat
6510 'identity
6511 (append (get 'org-agenda-filter
6512 :preset-filter)
6513 org-agenda-filter) "") "}")
6515 (if org-agenda-archives-mode
6516 (if (eq org-agenda-archives-mode t)
6517 " Archives"
6518 (format " :%s:" org-archive-tag))
6520 (if org-agenda-clockreport-mode
6521 (if (eq org-agenda-clockreport-mode 'with-filter)
6522 " Clock{}" " Clock")
6523 "")))
6524 (force-mode-line-update))
6526 (defun org-agenda-post-command-hook ()
6527 (setq org-agenda-type
6528 (or (get-text-property (point) 'org-agenda-type)
6529 (get-text-property (max (point-min) (1- (point)))
6530 'org-agenda-type))))
6532 (defun org-agenda-next-line ()
6533 "Move cursor to the next line, and show if follow mode is active."
6534 (interactive)
6535 (call-interactively 'next-line)
6536 (org-agenda-do-context-action))
6538 (defun org-agenda-previous-line ()
6539 "Move cursor to the previous line, and show if follow-mode is active."
6540 (interactive)
6541 (call-interactively 'previous-line)
6542 (org-agenda-do-context-action))
6544 (defun org-agenda-do-context-action ()
6545 "Show outline path and, maybe, follow mode window."
6546 (let ((m (org-get-at-bol 'org-marker)))
6547 (if (and org-agenda-follow-mode m)
6548 (org-agenda-show))
6549 (if (and m org-agenda-show-outline-path)
6550 (org-with-point-at m
6551 (org-display-outline-path t)))))
6553 (defun org-agenda-show-priority ()
6554 "Show the priority of the current item.
6555 This priority is composed of the main priority given with the [#A] cookies,
6556 and by additional input from the age of a schedules or deadline entry."
6557 (interactive)
6558 (let* ((pri (org-get-at-bol 'priority)))
6559 (message "Priority is %d" (if pri pri -1000))))
6561 (defun org-agenda-show-tags ()
6562 "Show the tags applicable to the current item."
6563 (interactive)
6564 (let* ((tags (org-get-at-bol 'tags)))
6565 (if tags
6566 (message "Tags are :%s:"
6567 (org-no-properties (mapconcat 'identity tags ":")))
6568 (message "No tags associated with this line"))))
6570 (defun org-agenda-goto (&optional highlight)
6571 "Go to the Org-mode file which contains the item at point."
6572 (interactive)
6573 (let* ((marker (or (org-get-at-bol 'org-marker)
6574 (org-agenda-error)))
6575 (buffer (marker-buffer marker))
6576 (pos (marker-position marker)))
6577 (switch-to-buffer-other-window buffer)
6578 (widen)
6579 (push-mark)
6580 (goto-char pos)
6581 (when (org-mode-p)
6582 (org-show-context 'agenda)
6583 (save-excursion
6584 (and (outline-next-heading)
6585 (org-flag-heading nil)))) ; show the next heading
6586 (when (outline-invisible-p)
6587 (show-entry)) ; display invisible text
6588 (recenter (/ (window-height) 2))
6589 (run-hooks 'org-agenda-after-show-hook)
6590 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6592 (defvar org-agenda-after-show-hook nil
6593 "Normal hook run after an item has been shown from the agenda.
6594 Point is in the buffer where the item originated.")
6596 (defun org-agenda-kill ()
6597 "Kill the entry or subtree belonging to the current agenda entry."
6598 (interactive)
6599 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6600 (let* ((marker (or (org-get-at-bol 'org-marker)
6601 (org-agenda-error)))
6602 (buffer (marker-buffer marker))
6603 (pos (marker-position marker))
6604 (type (org-get-at-bol 'type))
6605 dbeg dend (n 0) conf)
6606 (org-with-remote-undo buffer
6607 (with-current-buffer buffer
6608 (save-excursion
6609 (goto-char pos)
6610 (if (and (org-mode-p) (not (member type '("sexp"))))
6611 (setq dbeg (progn (org-back-to-heading t) (point))
6612 dend (org-end-of-subtree t t))
6613 (setq dbeg (point-at-bol)
6614 dend (min (point-max) (1+ (point-at-eol)))))
6615 (goto-char dbeg)
6616 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6617 (setq conf (or (eq t org-agenda-confirm-kill)
6618 (and (numberp org-agenda-confirm-kill)
6619 (> n org-agenda-confirm-kill))))
6620 (and conf
6621 (not (y-or-n-p
6622 (format "Delete entry with %d lines in buffer \"%s\"? "
6623 n (buffer-name buffer))))
6624 (error "Abort"))
6625 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6626 (with-current-buffer buffer (delete-region dbeg dend))
6627 (message "Agenda item and source killed"))))
6629 (defvar org-archive-default-command)
6630 (defun org-agenda-archive-default ()
6631 "Archive the entry or subtree belonging to the current agenda entry."
6632 (interactive)
6633 (require 'org-archive)
6634 (org-agenda-archive-with org-archive-default-command))
6636 (defun org-agenda-archive-default-with-confirmation ()
6637 "Archive the entry or subtree belonging to the current agenda entry."
6638 (interactive)
6639 (require 'org-archive)
6640 (org-agenda-archive-with org-archive-default-command 'confirm))
6642 (defun org-agenda-archive ()
6643 "Archive the entry or subtree belonging to the current agenda entry."
6644 (interactive)
6645 (org-agenda-archive-with 'org-archive-subtree))
6647 (defun org-agenda-archive-to-archive-sibling ()
6648 "Move the entry to the archive sibling."
6649 (interactive)
6650 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6652 (defun org-agenda-archive-with (cmd &optional confirm)
6653 "Move the entry to the archive sibling."
6654 (interactive)
6655 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6656 (let* ((marker (or (org-get-at-bol 'org-marker)
6657 (org-agenda-error)))
6658 (buffer (marker-buffer marker))
6659 (pos (marker-position marker)))
6660 (org-with-remote-undo buffer
6661 (with-current-buffer buffer
6662 (if (org-mode-p)
6663 (if (and confirm
6664 (not (y-or-n-p "Archive this subtree or entry? ")))
6665 (error "Abort")
6666 (save-excursion
6667 (goto-char pos)
6668 (org-remove-subtree-entries-from-agenda)
6669 (org-back-to-heading t)
6670 (funcall cmd)))
6671 (error "Archiving works only in Org-mode files"))))))
6673 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6674 "Remove all lines in the agenda that correspond to a given subtree.
6675 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6676 If this information is not given, the function uses the tree at point."
6677 (let ((buf (or buf (current-buffer))) m p)
6678 (save-excursion
6679 (unless (and beg end)
6680 (org-back-to-heading t)
6681 (setq beg (point))
6682 (org-end-of-subtree t)
6683 (setq end (point)))
6684 (set-buffer (get-buffer org-agenda-buffer-name))
6685 (save-excursion
6686 (goto-char (point-max))
6687 (beginning-of-line 1)
6688 (while (not (bobp))
6689 (when (and (setq m (org-get-at-bol 'org-marker))
6690 (equal buf (marker-buffer m))
6691 (setq p (marker-position m))
6692 (>= p beg)
6693 (< p end))
6694 (let ((inhibit-read-only t))
6695 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6696 (beginning-of-line 0))))))
6698 (defun org-agenda-refile (&optional goto rfloc no-update)
6699 "Refile the item at point."
6700 (interactive "P")
6701 (if (equal goto '(16))
6702 (org-refile-goto-last-stored)
6703 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6704 (org-agenda-error)))
6705 (buffer (marker-buffer marker))
6706 (pos (marker-position marker))
6707 (rfloc (or rfloc
6708 (org-refile-get-location
6709 (if goto "Goto" "Refile to") buffer
6710 org-refile-allow-creating-parent-nodes))))
6711 (with-current-buffer buffer
6712 (save-excursion
6713 (save-restriction
6714 (widen)
6715 (goto-char marker)
6716 (org-remove-subtree-entries-from-agenda)
6717 (org-refile goto buffer rfloc)))))
6718 (unless no-update (org-agenda-redo))))
6720 (defun org-agenda-open-link (&optional arg)
6721 "Follow the link in the current line, if any.
6722 This looks for a link in the displayed line in the agenda. It also looks
6723 at the text of the entry itself."
6724 (interactive "P")
6725 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6726 (org-get-at-bol 'org-marker)))
6727 (buffer (and marker (marker-buffer marker)))
6728 (prefix (buffer-substring
6729 (point-at-bol)
6730 (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
6731 (point-at-bol)))))
6732 (cond
6733 (buffer
6734 (with-current-buffer buffer
6735 (save-excursion
6736 (save-restriction
6737 (widen)
6738 (goto-char marker)
6739 (org-offer-links-in-entry arg prefix)))))
6740 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6741 (save-excursion
6742 (beginning-of-line 1)
6743 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6744 (org-open-link-from-string (match-string 1)))
6745 (t (error "No link to open here")))))
6747 (defun org-agenda-copy-local-variable (var)
6748 "Get a variable from a referenced buffer and install it here."
6749 (let ((m (org-get-at-bol 'org-marker)))
6750 (when (and m (buffer-live-p (marker-buffer m)))
6751 (org-set-local var (with-current-buffer (marker-buffer m)
6752 (symbol-value var))))))
6754 (defun org-agenda-switch-to (&optional delete-other-windows)
6755 "Go to the Org-mode file which contains the item at point."
6756 (interactive)
6757 (if (and org-return-follows-link
6758 (not (org-get-at-bol 'org-marker))
6759 (org-in-regexp org-bracket-link-regexp))
6760 (org-open-link-from-string (match-string 0))
6761 (let* ((marker (or (org-get-at-bol 'org-marker)
6762 (org-agenda-error)))
6763 (buffer (marker-buffer marker))
6764 (pos (marker-position marker)))
6765 (switch-to-buffer buffer)
6766 (and delete-other-windows (delete-other-windows))
6767 (widen)
6768 (goto-char pos)
6769 (when (org-mode-p)
6770 (org-show-context 'agenda)
6771 (save-excursion
6772 (and (outline-next-heading)
6773 (org-flag-heading nil))) ; show the next heading
6774 (when (outline-invisible-p)
6775 (show-entry)))))) ; display invisible text
6777 (defun org-agenda-goto-mouse (ev)
6778 "Go to the Org-mode file which contains the item at the mouse click."
6779 (interactive "e")
6780 (mouse-set-point ev)
6781 (org-agenda-goto))
6783 (defun org-agenda-show (&optional full-entry)
6784 "Display the Org-mode file which contains the item at point.
6785 With prefix argument FULL-ENTRY, make the entire entry visible
6786 if it was hidden in the outline."
6787 (interactive "P")
6788 (let ((win (selected-window)))
6789 (if full-entry
6790 (let ((org-show-entry-below t))
6791 (org-agenda-goto t))
6792 (org-agenda-goto t))
6793 (select-window win)))
6795 (defvar org-agenda-show-window nil)
6796 (defun org-agenda-show-and-scroll-up ()
6797 "Display the Org-mode file which contains the item at point.
6798 When called repeatedly, scroll the window that is displaying the buffer."
6799 (interactive)
6800 (let ((win (selected-window)))
6801 (if (and (window-live-p org-agenda-show-window)
6802 (eq this-command last-command))
6803 (progn
6804 (select-window org-agenda-show-window)
6805 (ignore-errors (scroll-up)))
6806 (org-agenda-goto t)
6807 (show-subtree)
6808 (setq org-agenda-show-window (selected-window)))
6809 (select-window win)))
6811 (defun org-agenda-show-scroll-down ()
6812 "Scroll down the window showing the agenda."
6813 (interactive)
6814 (let ((win (selected-window)))
6815 (when (window-live-p org-agenda-show-window)
6816 (select-window org-agenda-show-window)
6817 (ignore-errors (scroll-down))
6818 (select-window win))))
6820 (defun org-agenda-show-1 (&optional more)
6821 "Display the Org-mode file which contains the item at point.
6822 The prefix arg selects the amount of information to display:
6824 0 hide the subtree
6825 1 just show the entry according to defaults.
6826 2 show the children view
6827 3 show the subtree view
6828 4 show the entire subtree and any LOGBOOK drawers
6829 5 show the entire subtree and any drawers
6830 With prefix argument FULL-ENTRY, make the entire entry visible
6831 if it was hidden in the outline."
6832 (interactive "p")
6833 (let ((win (selected-window)))
6834 (org-agenda-goto t)
6835 (org-recenter-heading 1)
6836 (cond
6837 ((= more 0)
6838 (hide-subtree)
6839 (save-excursion
6840 (org-back-to-heading)
6841 (run-hook-with-args 'org-cycle-hook 'folded))
6842 (message "Remote: FOLDED"))
6843 ((and (interactive-p) (= more 1))
6844 (message "Remote: show with default settings"))
6845 ((= more 2)
6846 (show-entry)
6847 (show-children)
6848 (save-excursion
6849 (org-back-to-heading)
6850 (run-hook-with-args 'org-cycle-hook 'children))
6851 (message "Remote: CHILDREN"))
6852 ((= more 3)
6853 (show-subtree)
6854 (save-excursion
6855 (org-back-to-heading)
6856 (run-hook-with-args 'org-cycle-hook 'subtree))
6857 (message "Remote: SUBTREE"))
6858 ((= more 4)
6859 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6860 (org-drawer-regexp
6861 (concat "^[ \t]*:\\("
6862 (mapconcat 'regexp-quote org-drawers "\\|")
6863 "\\):[ \t]*$")))
6864 (show-subtree)
6865 (save-excursion
6866 (org-back-to-heading)
6867 (org-cycle-hide-drawers 'subtree)))
6868 (message "Remote: SUBTREE AND LOGBOOK"))
6869 ((> more 4)
6870 (show-subtree)
6871 (message "Remote: SUBTREE AND ALL DRAWERS")))
6872 (select-window win)))
6874 (defun org-recenter-heading (n)
6875 (save-excursion
6876 (org-back-to-heading)
6877 (recenter n)))
6879 (defvar org-agenda-cycle-counter nil)
6880 (defun org-agenda-cycle-show (&optional n)
6881 "Show the current entry in another window, with default settings.
6882 Default settings are taken from `org-show-hierarchy-above' and siblings.
6883 When use repeatedly in immediate succession, the remote entry will cycle
6884 through visibility
6886 children -> subtree -> folded
6888 When called with a numeric prefix arg, that arg will be passed through to
6889 `org-agenda-show-1'. For the interpretation of that argument, see the
6890 docstring of `org-agenda-show-1'."
6891 (interactive "P")
6892 (if (integerp n)
6893 (setq org-agenda-cycle-counter n)
6894 (if (not (eq last-command this-command))
6895 (setq org-agenda-cycle-counter 1)
6896 (if (equal org-agenda-cycle-counter 0)
6897 (setq org-agenda-cycle-counter 2)
6898 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6899 (if (> org-agenda-cycle-counter 3)
6900 (setq org-agenda-cycle-counter 0)))))
6901 (org-agenda-show-1 org-agenda-cycle-counter))
6903 (defun org-agenda-recenter (arg)
6904 "Display the Org-mode file which contains the item at point and recenter."
6905 (interactive "P")
6906 (let ((win (selected-window)))
6907 (org-agenda-goto t)
6908 (recenter arg)
6909 (select-window win)))
6911 (defun org-agenda-show-mouse (ev)
6912 "Display the Org-mode file which contains the item at the mouse click."
6913 (interactive "e")
6914 (mouse-set-point ev)
6915 (org-agenda-show))
6917 (defun org-agenda-check-no-diary ()
6918 "Check if the entry is a diary link and abort if yes."
6919 (if (org-get-at-bol 'org-agenda-diary-link)
6920 (org-agenda-error)))
6922 (defun org-agenda-error ()
6923 (error "Command not allowed in this line"))
6925 (defun org-agenda-tree-to-indirect-buffer ()
6926 "Show the subtree corresponding to the current entry in an indirect buffer.
6927 This calls the command `org-tree-to-indirect-buffer' from the original
6928 Org-mode buffer.
6929 With numerical prefix arg ARG, go up to this level and then take that tree.
6930 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6931 use the dedicated frame)."
6932 (interactive)
6933 (org-agenda-check-no-diary)
6934 (let* ((marker (or (org-get-at-bol 'org-marker)
6935 (org-agenda-error)))
6936 (buffer (marker-buffer marker))
6937 (pos (marker-position marker)))
6938 (with-current-buffer buffer
6939 (save-excursion
6940 (goto-char pos)
6941 (call-interactively 'org-tree-to-indirect-buffer)))))
6943 (defvar org-last-heading-marker (make-marker)
6944 "Marker pointing to the headline that last changed its TODO state
6945 by a remote command from the agenda.")
6947 (defun org-agenda-todo-nextset ()
6948 "Switch TODO entry to next sequence."
6949 (interactive)
6950 (org-agenda-todo 'nextset))
6952 (defun org-agenda-todo-previousset ()
6953 "Switch TODO entry to previous sequence."
6954 (interactive)
6955 (org-agenda-todo 'previousset))
6957 (defun org-agenda-todo (&optional arg)
6958 "Cycle TODO state of line at point, also in Org-mode file.
6959 This changes the line at point, all other lines in the agenda referring to
6960 the same tree node, and the headline of the tree node in the Org-mode file."
6961 (interactive "P")
6962 (org-agenda-check-no-diary)
6963 (let* ((col (current-column))
6964 (marker (or (org-get-at-bol 'org-marker)
6965 (org-agenda-error)))
6966 (buffer (marker-buffer marker))
6967 (pos (marker-position marker))
6968 (hdmarker (org-get-at-bol 'org-hd-marker))
6969 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6970 (inhibit-read-only t)
6971 org-agenda-headline-snapshot-before-repeat newhead just-one)
6972 (org-with-remote-undo buffer
6973 (with-current-buffer buffer
6974 (widen)
6975 (goto-char pos)
6976 (org-show-context 'agenda)
6977 (save-excursion
6978 (and (outline-next-heading)
6979 (org-flag-heading nil))) ; show the next heading
6980 (let ((current-prefix-arg arg))
6981 (call-interactively 'org-todo))
6982 (and (bolp) (forward-char 1))
6983 (setq newhead (org-get-heading))
6984 (when (and (org-bound-and-true-p
6985 org-agenda-headline-snapshot-before-repeat)
6986 (not (equal org-agenda-headline-snapshot-before-repeat
6987 newhead))
6988 todayp)
6989 (setq newhead org-agenda-headline-snapshot-before-repeat
6990 just-one t))
6991 (save-excursion
6992 (org-back-to-heading)
6993 (move-marker org-last-heading-marker (point))))
6994 (beginning-of-line 1)
6995 (save-excursion
6996 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6997 (org-move-to-column col))))
6999 (defun org-agenda-add-note (&optional arg)
7000 "Add a time-stamped note to the entry at point."
7001 (interactive "P")
7002 (org-agenda-check-no-diary)
7003 (let* ((marker (or (org-get-at-bol 'org-marker)
7004 (org-agenda-error)))
7005 (buffer (marker-buffer marker))
7006 (pos (marker-position marker))
7007 (hdmarker (org-get-at-bol 'org-hd-marker))
7008 (inhibit-read-only t))
7009 (with-current-buffer buffer
7010 (widen)
7011 (goto-char pos)
7012 (org-show-context 'agenda)
7013 (save-excursion
7014 (and (outline-next-heading)
7015 (org-flag-heading nil))) ; show the next heading
7016 (org-add-note))))
7018 (defun org-agenda-change-all-lines (newhead hdmarker
7019 &optional fixface just-this)
7020 "Change all lines in the agenda buffer which match HDMARKER.
7021 The new content of the line will be NEWHEAD (as modified by
7022 `org-format-agenda-item'). HDMARKER is checked with
7023 `equal' against all `org-hd-marker' text properties in the file.
7024 If FIXFACE is non-nil, the face of each item is modified according to
7025 the new TODO state.
7026 If JUST-THIS is non-nil, change just the current line, not all.
7027 If FORCE-TAGS is non nil, the car of it returns the new tags."
7028 (let* ((inhibit-read-only t)
7029 (line (org-current-line))
7030 (thetags (with-current-buffer (marker-buffer hdmarker)
7031 (save-excursion (save-restriction (widen)
7032 (goto-char hdmarker)
7033 (org-get-tags-at)))))
7034 props m pl undone-face done-face finish new dotime cat tags)
7035 (save-excursion
7036 (goto-char (point-max))
7037 (beginning-of-line 1)
7038 (while (not finish)
7039 (setq finish (bobp))
7040 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7041 (or (not just-this) (= (org-current-line) line))
7042 (equal m hdmarker))
7043 (setq props (text-properties-at (point))
7044 dotime (org-get-at-bol 'dotime)
7045 cat (org-get-at-bol 'org-category)
7046 tags thetags
7047 new (org-format-agenda-item (org-get-at-bol 'extra)
7048 newhead cat tags dotime)
7049 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7050 undone-face (org-get-at-bol 'undone-face)
7051 done-face (org-get-at-bol 'done-face))
7052 (beginning-of-line 1)
7053 (cond
7054 ((equal new "")
7055 (and (looking-at ".*\n?") (replace-match "")))
7056 ((looking-at ".*")
7057 (replace-match new t t)
7058 (beginning-of-line 1)
7059 (add-text-properties (point-at-bol) (point-at-eol) props)
7060 (when fixface
7061 (add-text-properties
7062 (point-at-bol) (point-at-eol)
7063 (list 'face
7064 (if org-last-todo-state-is-todo
7065 undone-face done-face))))
7066 (org-agenda-highlight-todo 'line)
7067 (beginning-of-line 1))
7068 (t (error "Line update did not work"))))
7069 (beginning-of-line 0)))
7070 (org-finalize-agenda)))
7072 (defun org-agenda-align-tags (&optional line)
7073 "Align all tags in agenda items to `org-agenda-tags-column'."
7074 (let ((inhibit-read-only t) l c)
7075 (save-excursion
7076 (goto-char (if line (point-at-bol) (point-min)))
7077 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7078 (if line (point-at-eol) nil) t)
7079 (add-text-properties
7080 (match-beginning 2) (match-end 2)
7081 (list 'face (delq nil (let ((prop (get-text-property
7082 (match-beginning 2) 'face)))
7083 (or (listp prop) (setq prop (list prop)))
7084 (if (memq 'org-tag prop)
7085 prop
7086 (cons 'org-tag prop))))))
7087 (setq l (- (match-end 2) (match-beginning 2))
7088 c (if (< org-agenda-tags-column 0)
7089 (- (abs org-agenda-tags-column) l)
7090 org-agenda-tags-column))
7091 (delete-region (match-beginning 1) (match-end 1))
7092 (goto-char (match-beginning 1))
7093 (insert (org-add-props
7094 (make-string (max 1 (- c (current-column))) ?\ )
7095 (plist-put (copy-sequence (text-properties-at (point)))
7096 'face nil))))
7097 (goto-char (point-min))
7098 (org-font-lock-add-tag-faces (point-max)))))
7100 (defun org-agenda-priority-up ()
7101 "Increase the priority of line at point, also in Org-mode file."
7102 (interactive)
7103 (org-agenda-priority 'up))
7105 (defun org-agenda-priority-down ()
7106 "Decrease the priority of line at point, also in Org-mode file."
7107 (interactive)
7108 (org-agenda-priority 'down))
7110 (defun org-agenda-priority (&optional force-direction)
7111 "Set the priority of line at point, also in Org-mode file.
7112 This changes the line at point, all other lines in the agenda referring to
7113 the same tree node, and the headline of the tree node in the Org-mode file."
7114 (interactive)
7115 (unless org-enable-priority-commands
7116 (error "Priority commands are disabled"))
7117 (org-agenda-check-no-diary)
7118 (let* ((marker (or (org-get-at-bol 'org-marker)
7119 (org-agenda-error)))
7120 (hdmarker (org-get-at-bol 'org-hd-marker))
7121 (buffer (marker-buffer hdmarker))
7122 (pos (marker-position hdmarker))
7123 (inhibit-read-only t)
7124 newhead)
7125 (org-with-remote-undo buffer
7126 (with-current-buffer buffer
7127 (widen)
7128 (goto-char pos)
7129 (org-show-context 'agenda)
7130 (save-excursion
7131 (and (outline-next-heading)
7132 (org-flag-heading nil))) ; show the next heading
7133 (funcall 'org-priority force-direction)
7134 (end-of-line 1)
7135 (setq newhead (org-get-heading)))
7136 (org-agenda-change-all-lines newhead hdmarker)
7137 (beginning-of-line 1))))
7139 ;; FIXME: should fix the tags property of the agenda line.
7140 (defun org-agenda-set-tags (&optional tag onoff)
7141 "Set tags for the current headline."
7142 (interactive)
7143 (org-agenda-check-no-diary)
7144 (if (and (org-region-active-p) (interactive-p))
7145 (call-interactively 'org-change-tag-in-region)
7146 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7147 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7148 (org-agenda-error)))
7149 (buffer (marker-buffer hdmarker))
7150 (pos (marker-position hdmarker))
7151 (inhibit-read-only t)
7152 newhead)
7153 (org-with-remote-undo buffer
7154 (with-current-buffer buffer
7155 (widen)
7156 (goto-char pos)
7157 (save-excursion
7158 (org-show-context 'agenda))
7159 (save-excursion
7160 (and (outline-next-heading)
7161 (org-flag-heading nil))) ; show the next heading
7162 (goto-char pos)
7163 (if tag
7164 (org-toggle-tag tag onoff)
7165 (call-interactively 'org-set-tags))
7166 (end-of-line 1)
7167 (setq newhead (org-get-heading)))
7168 (org-agenda-change-all-lines newhead hdmarker)
7169 (beginning-of-line 1)))))
7171 (defun org-agenda-set-property ()
7172 "Set a property for the current headline."
7173 (interactive)
7174 (org-agenda-check-no-diary)
7175 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7176 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7177 (org-agenda-error)))
7178 (buffer (marker-buffer hdmarker))
7179 (pos (marker-position hdmarker))
7180 (inhibit-read-only t)
7181 newhead)
7182 (org-with-remote-undo buffer
7183 (with-current-buffer buffer
7184 (widen)
7185 (goto-char pos)
7186 (save-excursion
7187 (org-show-context 'agenda))
7188 (save-excursion
7189 (and (outline-next-heading)
7190 (org-flag-heading nil))) ; show the next heading
7191 (goto-char pos)
7192 (call-interactively 'org-set-property)))))
7194 (defun org-agenda-set-effort ()
7195 "Set the effort property for the current headline."
7196 (interactive)
7197 (org-agenda-check-no-diary)
7198 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7199 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7200 (org-agenda-error)))
7201 (buffer (marker-buffer hdmarker))
7202 (pos (marker-position hdmarker))
7203 (inhibit-read-only t)
7204 newhead)
7205 (org-with-remote-undo buffer
7206 (with-current-buffer buffer
7207 (widen)
7208 (goto-char pos)
7209 (save-excursion
7210 (org-show-context 'agenda))
7211 (save-excursion
7212 (and (outline-next-heading)
7213 (org-flag-heading nil))) ; show the next heading
7214 (goto-char pos)
7215 (call-interactively 'org-set-effort)
7216 (end-of-line 1)))))
7218 (defun org-agenda-toggle-archive-tag ()
7219 "Toggle the archive tag for the current entry."
7220 (interactive)
7221 (org-agenda-check-no-diary)
7222 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7223 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7224 (org-agenda-error)))
7225 (buffer (marker-buffer hdmarker))
7226 (pos (marker-position hdmarker))
7227 (inhibit-read-only t)
7228 newhead)
7229 (org-with-remote-undo buffer
7230 (with-current-buffer buffer
7231 (widen)
7232 (goto-char pos)
7233 (org-show-context 'agenda)
7234 (save-excursion
7235 (and (outline-next-heading)
7236 (org-flag-heading nil))) ; show the next heading
7237 (call-interactively 'org-toggle-archive-tag)
7238 (end-of-line 1)
7239 (setq newhead (org-get-heading)))
7240 (org-agenda-change-all-lines newhead hdmarker)
7241 (beginning-of-line 1))))
7243 (defun org-agenda-do-date-later (arg)
7244 (interactive "P")
7245 (cond
7246 ((or (equal arg '(16))
7247 (memq last-command
7248 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7249 (setq this-command 'org-agenda-date-later-minutes)
7250 (org-agenda-date-later-minutes 1))
7251 ((or (equal arg '(4))
7252 (memq last-command
7253 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7254 (setq this-command 'org-agenda-date-later-hours)
7255 (org-agenda-date-later-hours 1))
7257 (org-agenda-date-later (prefix-numeric-value arg)))))
7259 (defun org-agenda-do-date-earlier (arg)
7260 (interactive "P")
7261 (cond
7262 ((or (equal arg '(16))
7263 (memq last-command
7264 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7265 (setq this-command 'org-agenda-date-earlier-minutes)
7266 (org-agenda-date-earlier-minutes 1))
7267 ((or (equal arg '(4))
7268 (memq last-command
7269 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7270 (setq this-command 'org-agenda-date-earlier-hours)
7271 (org-agenda-date-earlier-hours 1))
7273 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7275 (defun org-agenda-date-later (arg &optional what)
7276 "Change the date of this item to ARG day(s) later."
7277 (interactive "p")
7278 (org-agenda-check-type t 'agenda 'timeline)
7279 (org-agenda-check-no-diary)
7280 (let* ((marker (or (org-get-at-bol 'org-marker)
7281 (org-agenda-error)))
7282 (buffer (marker-buffer marker))
7283 (pos (marker-position marker)))
7284 (org-with-remote-undo buffer
7285 (with-current-buffer buffer
7286 (widen)
7287 (goto-char pos)
7288 (if (not (org-at-timestamp-p))
7289 (error "Cannot find time stamp"))
7290 (org-timestamp-change arg (or what 'day)))
7291 (org-agenda-show-new-time marker org-last-changed-timestamp))
7292 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7294 (defun org-agenda-date-earlier (arg &optional what)
7295 "Change the date of this item to ARG day(s) earlier."
7296 (interactive "p")
7297 (org-agenda-date-later (- arg) what))
7299 (defun org-agenda-date-later-minutes (arg)
7300 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7301 (interactive "p")
7302 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7303 (org-agenda-date-later arg 'minute))
7305 (defun org-agenda-date-earlier-minutes (arg)
7306 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7307 (interactive "p")
7308 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7309 (org-agenda-date-earlier arg 'minute))
7311 (defun org-agenda-date-later-hours (arg)
7312 "Change the time of this item, in hour steps."
7313 (interactive "p")
7314 (org-agenda-date-later arg 'hour))
7316 (defun org-agenda-date-earlier-hours (arg)
7317 "Change the time of this item, in hour steps."
7318 (interactive "p")
7319 (org-agenda-date-earlier arg 'hour))
7321 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7322 "Show new date stamp via text properties."
7323 ;; We use text properties to make this undoable
7324 (let ((inhibit-read-only t)
7325 (buffer-invisibility-spec))
7326 (setq stamp (concat " " prefix " => " stamp))
7327 (save-excursion
7328 (goto-char (point-max))
7329 (while (not (bobp))
7330 (when (equal marker (org-get-at-bol 'org-marker))
7331 (org-move-to-column (- (window-width) (length stamp)) t)
7332 (org-agenda-fix-tags-filter-overlays-at (point))
7333 (if (featurep 'xemacs)
7334 ;; Use `duplicable' property to trigger undo recording
7335 (let ((ex (make-extent nil nil))
7336 (gl (make-glyph stamp)))
7337 (set-glyph-face gl 'secondary-selection)
7338 (set-extent-properties
7339 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7340 (insert-extent ex (1- (point)) (point-at-eol)))
7341 (add-text-properties
7342 (1- (point)) (point-at-eol)
7343 (list 'display (org-add-props stamp nil
7344 'face 'secondary-selection))))
7345 (beginning-of-line 1))
7346 (beginning-of-line 0)))))
7348 (defun org-agenda-date-prompt (arg)
7349 "Change the date of this item. Date is prompted for, with default today.
7350 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7351 be used to request time specification in the time stamp."
7352 (interactive "P")
7353 (org-agenda-check-type t 'agenda 'timeline)
7354 (org-agenda-check-no-diary)
7355 (let* ((marker (or (org-get-at-bol 'org-marker)
7356 (org-agenda-error)))
7357 (buffer (marker-buffer marker))
7358 (pos (marker-position marker)))
7359 (org-with-remote-undo buffer
7360 (with-current-buffer buffer
7361 (widen)
7362 (goto-char pos)
7363 (if (not (org-at-timestamp-p t))
7364 (error "Cannot find time stamp"))
7365 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7366 (org-agenda-show-new-time marker org-last-changed-timestamp))
7367 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7369 (defun org-agenda-schedule (arg &optional time)
7370 "Schedule the item at point.
7371 Arg is passed through to `org-schedule'."
7372 (interactive "P")
7373 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7374 (org-agenda-check-no-diary)
7375 (let* ((marker (or (org-get-at-bol 'org-marker)
7376 (org-agenda-error)))
7377 (type (marker-insertion-type marker))
7378 (buffer (marker-buffer marker))
7379 (pos (marker-position marker))
7380 (org-insert-labeled-timestamps-at-point nil)
7382 (set-marker-insertion-type marker t)
7383 (org-with-remote-undo buffer
7384 (with-current-buffer buffer
7385 (widen)
7386 (goto-char pos)
7387 (setq ts (org-schedule arg time)))
7388 (org-agenda-show-new-time marker ts "S"))
7389 (message "Item scheduled for %s" ts)))
7391 (defun org-agenda-deadline (arg &optional time)
7392 "Schedule the item at point.
7393 Arg is passed through to `org-deadline'."
7394 (interactive "P")
7395 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7396 (org-agenda-check-no-diary)
7397 (let* ((marker (or (org-get-at-bol 'org-marker)
7398 (org-agenda-error)))
7399 (buffer (marker-buffer marker))
7400 (pos (marker-position marker))
7401 (org-insert-labeled-timestamps-at-point nil)
7403 (org-with-remote-undo buffer
7404 (with-current-buffer buffer
7405 (widen)
7406 (goto-char pos)
7407 (setq ts (org-deadline arg time)))
7408 (org-agenda-show-new-time marker ts "D"))
7409 (message "Deadline for this item set to %s" ts)))
7411 (defun org-agenda-action ()
7412 "Select entry for agenda action, or execute an agenda action.
7413 This command prompts for another letter. Valid inputs are:
7415 m Mark the entry at point for an agenda action
7416 s Schedule the marked entry to the date at the cursor
7417 d Set the deadline of the marked entry to the date at the cursor
7418 r Call `org-remember' with cursor date as the default date
7419 c Call `org-capture' with cursor date as the default date
7420 SPC Show marked entry in other window
7421 TAB Visit marked entry in other window
7423 The cursor may be at a date in the calendar, or in the Org agenda."
7424 (interactive)
7425 (let (ans)
7426 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7427 (setq ans (read-char-exclusive))
7428 (cond
7429 ((equal ans ?m)
7430 ;; Mark this entry
7431 (if (eq major-mode 'org-agenda-mode)
7432 (let ((m (or (org-get-at-bol 'org-hd-marker)
7433 (org-get-at-bol 'org-marker))))
7434 (if m
7435 (progn
7436 (move-marker org-agenda-action-marker
7437 (marker-position m) (marker-buffer m))
7438 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7439 (error "Don't know which entry to mark")))
7440 (error "This command works only in the agenda")))
7441 ((equal ans ?s)
7442 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7443 ((equal ans ?d)
7444 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7445 ((equal ans ?r)
7446 (org-agenda-do-action '(org-remember) t))
7447 ((equal ans ?c)
7448 (org-agenda-do-action '(org-capture) t))
7449 ((equal ans ?\ )
7450 (let ((cw (selected-window)))
7451 (org-switch-to-buffer-other-window
7452 (marker-buffer org-agenda-action-marker))
7453 (goto-char org-agenda-action-marker)
7454 (org-show-context 'agenda)
7455 (select-window cw)))
7456 ((equal ans ?\C-i)
7457 (org-switch-to-buffer-other-window
7458 (marker-buffer org-agenda-action-marker))
7459 (goto-char org-agenda-action-marker)
7460 (org-show-context 'agenda))
7461 (t (error "Invalid agenda action %c" ans)))))
7463 (defun org-agenda-do-action (form &optional current-buffer)
7464 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7465 (let ((org-overriding-default-time (org-get-cursor-date)))
7466 (if current-buffer
7467 (eval form)
7468 (if (not (marker-buffer org-agenda-action-marker))
7469 (error "No entry has been selected for agenda action")
7470 (with-current-buffer (marker-buffer org-agenda-action-marker)
7471 (save-excursion
7472 (save-restriction
7473 (widen)
7474 (goto-char org-agenda-action-marker)
7475 (eval form))))))))
7477 (defun org-agenda-clock-in (&optional arg)
7478 "Start the clock on the currently selected item."
7479 (interactive "P")
7480 (org-agenda-check-no-diary)
7481 (if (equal arg '(4))
7482 (org-clock-in arg)
7483 (let* ((marker (or (org-get-at-bol 'org-marker)
7484 (org-agenda-error)))
7485 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7486 marker))
7487 (pos (marker-position marker))
7488 newhead)
7489 (org-with-remote-undo (marker-buffer marker)
7490 (with-current-buffer (marker-buffer marker)
7491 (widen)
7492 (goto-char pos)
7493 (org-show-context 'agenda)
7494 (org-show-entry)
7495 (org-cycle-hide-drawers 'children)
7496 (org-clock-in arg)
7497 (setq newhead (org-get-heading)))
7498 (org-agenda-change-all-lines newhead hdmarker)))))
7500 (defun org-agenda-clock-out ()
7501 "Stop the currently running clock."
7502 (interactive)
7503 (unless (marker-buffer org-clock-marker)
7504 (error "No running clock"))
7505 (let ((marker (make-marker)) newhead)
7506 (org-with-remote-undo (marker-buffer org-clock-marker)
7507 (with-current-buffer (marker-buffer org-clock-marker)
7508 (save-excursion
7509 (save-restriction
7510 (widen)
7511 (goto-char org-clock-marker)
7512 (org-back-to-heading t)
7513 (move-marker marker (point))
7514 (org-clock-out)
7515 (setq newhead (org-get-heading))))))
7516 (org-agenda-change-all-lines newhead marker)
7517 (move-marker marker nil)))
7519 (defun org-agenda-clock-cancel (&optional arg)
7520 "Cancel the currently running clock."
7521 (interactive "P")
7522 (unless (marker-buffer org-clock-marker)
7523 (error "No running clock"))
7524 (org-with-remote-undo (marker-buffer org-clock-marker)
7525 (org-clock-cancel)))
7527 (defun org-agenda-clock-goto ()
7528 "Jump to the currently clocked in task within the agenda.
7529 If the currently clocked in task is not listed in the agenda
7530 buffer, display it in another window."
7531 (interactive)
7532 (let (pos)
7533 (mapc (lambda (o)
7534 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7535 (setq pos (overlay-start o))))
7536 (overlays-in (point-min) (point-max)))
7537 (cond (pos (goto-char pos))
7538 ;; If the currently clocked entry is not in the agenda
7539 ;; buffer, we visit it in another window:
7540 (org-clock-current-task
7541 (org-switch-to-buffer-other-window (org-clock-goto)))
7542 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7544 (defun org-agenda-diary-entry-in-org-file ()
7545 "Make a diary entry in the file `org-agenda-diary-file'."
7546 (let (d1 d2 char (text "") dp1 dp2)
7547 (if (equal (buffer-name) "*Calendar*")
7548 (setq d1 (calendar-cursor-to-date t)
7549 d2 (car calendar-mark-ring))
7550 (setq dp1 (get-text-property (point-at-bol) 'day))
7551 (unless dp1 (error "No date defined in current line"))
7552 (setq d1 (calendar-gregorian-from-absolute dp1)
7553 d2 (and (ignore-errors (mark))
7554 (save-excursion
7555 (goto-char (mark))
7556 (setq dp2 (get-text-property (point-at-bol) 'day)))
7557 (calendar-gregorian-from-absolute dp2))))
7558 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7559 (setq char (read-char-exclusive))
7560 (cond
7561 ((equal char ?d)
7562 (setq text (read-string "Day entry: "))
7563 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7564 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7565 ((equal char ?a)
7566 (setq d1 (list (car d1) (nth 1 d1)
7567 (read-number (format "Reference year [%d]: " (nth 2 d1))
7568 (nth 2 d1))))
7569 (setq text (read-string "Anniversary (use %d to show years): "))
7570 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7571 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7572 ((equal char ?b)
7573 (setq text (read-string "Block entry: "))
7574 (unless (and d1 d2 (not (equal d1 d2)))
7575 (error "No block of days selected"))
7576 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7577 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7578 ((equal char ?j)
7579 (org-switch-to-buffer-other-window
7580 (find-file-noselect org-agenda-diary-file))
7581 (require 'org-datetree)
7582 (org-datetree-find-date-create d1)
7583 (org-reveal t))
7584 (t (error "Invalid selection character `%c'" char)))))
7586 (defcustom org-agenda-insert-diary-strategy 'date-tree
7587 "Where in `org-agenda-diary-file' should new entries be added?
7588 Valid values:
7590 date-tree in the date tree, as child of the date
7591 top-level as top-level entries at the end of the file."
7592 :group 'org-agenda
7593 :type '(choice
7594 (const :tag "in a date tree" date-tree)
7595 (const :tag "as top level at end of file" top-level)))
7597 (defcustom org-agenda-insert-diary-extract-time nil
7598 "Non-nil means extract any time specification from the diary entry."
7599 :group 'org-agenda
7600 :type 'boolean)
7602 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7603 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7604 If TEXT is not empty, it will become the headline of the new entry, and
7605 the resulting entry will not be shown. When TEXT is empty, switch to
7606 `org-agenda-diary-file' and let the user finish the entry there."
7607 (let ((cw (current-window-configuration)))
7608 (org-switch-to-buffer-other-window
7609 (find-file-noselect org-agenda-diary-file))
7610 (widen)
7611 (goto-char (point-min))
7612 (cond
7613 ((eq type 'anniversary)
7614 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7615 (progn
7616 (or (org-on-heading-p t)
7617 (progn
7618 (outline-next-heading)
7619 (insert "* Anniversaries\n\n")
7620 (beginning-of-line -1)))))
7621 (outline-next-heading)
7622 (org-back-over-empty-lines)
7623 (backward-char 1)
7624 (insert "\n")
7625 (require 'diary-lib)
7626 (let ((calendar-date-display-form
7627 (if (if (boundp 'calendar-date-style)
7628 (eq calendar-date-style 'european)
7629 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7630 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7631 '(day " " month " " year)
7632 '(month " " day " " year))))
7634 (insert (format "%%%%(diary-anniversary %s) %s"
7635 (calendar-date-string d1 nil t) text))))
7636 ((eq type 'day)
7637 (let ((org-prefix-has-time t)
7638 (org-agenda-time-leading-zero t)
7639 fmt time time2)
7640 (if org-agenda-insert-diary-extract-time
7641 ;; Use org-format-agenda-item to parse text for a time-range and
7642 ;; remove it. FIXME: This is a hack, we should refactor
7643 ;; that function to make time extraction available separately
7644 (setq fmt (org-format-agenda-item nil text nil nil t)
7645 time (get-text-property 0 'time fmt)
7646 time2 (if (> (length time) 0)
7647 ;; split-string removes trailing ...... if
7648 ;; no end time given. First space
7649 ;; separates time from date.
7650 (concat " " (car (split-string time "\\.")))
7651 nil)
7652 text (get-text-property 0 'txt fmt)))
7653 (if (eq org-agenda-insert-diary-strategy 'top-level)
7654 (org-agenda-insert-diary-as-top-level text)
7655 (require 'org-datetree)
7656 (org-datetree-find-date-create d1)
7657 (org-agenda-insert-diary-make-new-entry text))
7658 (org-insert-time-stamp (org-time-from-absolute
7659 (calendar-absolute-from-gregorian d1))
7660 nil nil nil nil time2))
7661 (end-of-line 0))
7662 ((eq type 'block)
7663 (if (> (calendar-absolute-from-gregorian d1)
7664 (calendar-absolute-from-gregorian d2))
7665 (setq d1 (prog1 d2 (setq d2 d1))))
7666 (if (eq org-agenda-insert-diary-strategy 'top-level)
7667 (org-agenda-insert-diary-as-top-level text)
7668 (require 'org-datetree)
7669 (org-datetree-find-date-create d1)
7670 (org-agenda-insert-diary-make-new-entry text))
7671 (org-insert-time-stamp (org-time-from-absolute
7672 (calendar-absolute-from-gregorian d1)))
7673 (insert "--")
7674 (org-insert-time-stamp (org-time-from-absolute
7675 (calendar-absolute-from-gregorian d2)))
7676 (end-of-line 0)))
7677 (if (string-match "\\S-" text)
7678 (progn
7679 (set-window-configuration cw)
7680 (message "%s entry added to %s"
7681 (capitalize (symbol-name type))
7682 (abbreviate-file-name org-agenda-diary-file)))
7683 (org-reveal t)
7684 (message "Please finish entry here"))))
7686 (defun org-agenda-insert-diary-as-top-level (text)
7687 "Make new entry as a top-level entry at the end of the file.
7688 Add TEXT as headline, and position the cursor in the second line so that
7689 a timestamp can be added there."
7690 (widen)
7691 (goto-char (point-max))
7692 (or (bolp) (insert "\n"))
7693 (insert "* " text "\n")
7694 (if org-adapt-indentation (org-indent-to-column 2)))
7696 (defun org-agenda-insert-diary-make-new-entry (text)
7697 "Make new entry as last child of current entry.
7698 Add TEXT as headline, and position the cursor in the second line so that
7699 a timestamp can be added there."
7700 (let ((org-show-following-heading t)
7701 (org-show-siblings t)
7702 (org-show-hierarchy-above t)
7703 (org-show-entry-below t)
7704 col)
7705 (outline-next-heading)
7706 (org-back-over-empty-lines)
7707 (or (looking-at "[ \t]*$")
7708 (progn (insert "\n") (backward-char 1)))
7709 (org-insert-heading nil t)
7710 (org-do-demote)
7711 (setq col (current-column))
7712 (insert text "\n")
7713 (if org-adapt-indentation (org-indent-to-column col))
7714 (let ((org-show-following-heading t)
7715 (org-show-siblings t)
7716 (org-show-hierarchy-above t)
7717 (org-show-entry-below t))
7718 (org-show-context))))
7720 (defun org-agenda-diary-entry ()
7721 "Make a diary entry, like the `i' command from the calendar.
7722 All the standard commands work: block, weekly etc.
7723 When `org-agenda-diary-file' points to a file,
7724 `org-agenda-diary-entry-in-org-file' is called instead to create
7725 entries in that Org-mode file."
7726 (interactive)
7727 (org-agenda-check-type t 'agenda 'timeline)
7728 (if (not (eq org-agenda-diary-file 'diary-file))
7729 (org-agenda-diary-entry-in-org-file)
7730 (require 'diary-lib)
7731 (let* ((char (progn
7732 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7733 (read-char-exclusive)))
7734 (cmd (cdr (assoc char
7735 '((?d . insert-diary-entry)
7736 (?w . insert-weekly-diary-entry)
7737 (?m . insert-monthly-diary-entry)
7738 (?y . insert-yearly-diary-entry)
7739 (?a . insert-anniversary-diary-entry)
7740 (?b . insert-block-diary-entry)
7741 (?c . insert-cyclic-diary-entry)))))
7742 (oldf (symbol-function 'calendar-cursor-to-date))
7743 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7744 (point (point))
7745 (mark (or (mark t) (point))))
7746 (unless cmd
7747 (error "No command associated with <%c>" char))
7748 (unless (and (get-text-property point 'day)
7749 (or (not (equal ?b char))
7750 (get-text-property mark 'day)))
7751 (error "Don't know which date to use for diary entry"))
7752 ;; We implement this by hacking the `calendar-cursor-to-date' function
7753 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7754 (let ((calendar-mark-ring
7755 (list (calendar-gregorian-from-absolute
7756 (or (get-text-property mark 'day)
7757 (get-text-property point 'day))))))
7758 (unwind-protect
7759 (progn
7760 (fset 'calendar-cursor-to-date
7761 (lambda (&optional error dummy)
7762 (calendar-gregorian-from-absolute
7763 (get-text-property point 'day))))
7764 (call-interactively cmd))
7765 (fset 'calendar-cursor-to-date oldf))))))
7767 (defun org-agenda-execute-calendar-command (cmd)
7768 "Execute a calendar command from the agenda, with the date associated to
7769 the cursor position."
7770 (org-agenda-check-type t 'agenda 'timeline)
7771 (require 'diary-lib)
7772 (unless (get-text-property (point) 'day)
7773 (error "Don't know which date to use for calendar command"))
7774 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7775 (point (point))
7776 (date (calendar-gregorian-from-absolute
7777 (get-text-property point 'day)))
7778 ;; the following 2 vars are needed in the calendar
7779 (displayed-month (car date))
7780 (displayed-year (nth 2 date)))
7781 (unwind-protect
7782 (progn
7783 (fset 'calendar-cursor-to-date
7784 (lambda (&optional error dummy)
7785 (calendar-gregorian-from-absolute
7786 (get-text-property point 'day))))
7787 (call-interactively cmd))
7788 (fset 'calendar-cursor-to-date oldf))))
7790 (defun org-agenda-phases-of-moon ()
7791 "Display the phases of the moon for the 3 months around the cursor date."
7792 (interactive)
7793 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7795 (defun org-agenda-holidays ()
7796 "Display the holidays for the 3 months around the cursor date."
7797 (interactive)
7798 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7800 (defvar calendar-longitude)
7801 (defvar calendar-latitude)
7802 (defvar calendar-location-name)
7804 (defun org-agenda-sunrise-sunset (arg)
7805 "Display sunrise and sunset for the cursor date.
7806 Latitude and longitude can be specified with the variables
7807 `calendar-latitude' and `calendar-longitude'. When called with prefix
7808 argument, latitude and longitude will be prompted for."
7809 (interactive "P")
7810 (require 'solar)
7811 (let ((calendar-longitude (if arg nil calendar-longitude))
7812 (calendar-latitude (if arg nil calendar-latitude))
7813 (calendar-location-name
7814 (if arg "the given coordinates" calendar-location-name)))
7815 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7817 (defun org-agenda-goto-calendar ()
7818 "Open the Emacs calendar with the date at the cursor."
7819 (interactive)
7820 (org-agenda-check-type t 'agenda 'timeline)
7821 (let* ((day (or (get-text-property (point) 'day)
7822 (error "Don't know which date to open in calendar")))
7823 (date (calendar-gregorian-from-absolute day))
7824 (calendar-move-hook nil)
7825 (calendar-view-holidays-initially-flag nil)
7826 (calendar-view-diary-initially-flag nil))
7827 (calendar)
7828 (calendar-goto-date date)))
7830 ;;;###autoload
7831 (defun org-calendar-goto-agenda ()
7832 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7833 This is a command that has to be installed in `calendar-mode-map'."
7834 (interactive)
7835 (org-agenda-list nil (calendar-absolute-from-gregorian
7836 (calendar-cursor-to-date))
7837 nil))
7839 (defun org-agenda-convert-date ()
7840 (interactive)
7841 (org-agenda-check-type t 'agenda 'timeline)
7842 (let ((day (get-text-property (point) 'day))
7843 date s)
7844 (unless day
7845 (error "Don't know which date to convert"))
7846 (setq date (calendar-gregorian-from-absolute day))
7847 (setq s (concat
7848 "Gregorian: " (calendar-date-string date) "\n"
7849 "ISO: " (calendar-iso-date-string date) "\n"
7850 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7851 "Julian: " (calendar-julian-date-string date) "\n"
7852 "Astron. JD: " (calendar-astro-date-string date)
7853 " (Julian date number at noon UTC)\n"
7854 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7855 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7856 "French: " (calendar-french-date-string date) "\n"
7857 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7858 "Mayan: " (calendar-mayan-date-string date) "\n"
7859 "Coptic: " (calendar-coptic-date-string date) "\n"
7860 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7861 "Persian: " (calendar-persian-date-string date) "\n"
7862 "Chinese: " (calendar-chinese-date-string date) "\n"))
7863 (with-output-to-temp-buffer "*Dates*"
7864 (princ s))
7865 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7867 ;;; Bulk commands
7869 (defvar org-agenda-bulk-marked-entries nil
7870 "List of markers that refer to marked entries in the agenda.")
7872 (defun org-agenda-bulk-marked-p ()
7873 (eq (get-char-property (point-at-bol) 'type)
7874 'org-marked-entry-overlay))
7876 (defun org-agenda-bulk-mark (&optional arg)
7877 "Mark the entry at point for future bulk action."
7878 (interactive "p")
7879 (dotimes (i (max arg 1))
7880 (unless (org-get-at-bol 'org-agenda-diary-link)
7881 (let* ((m (org-get-at-bol 'org-hd-marker))
7883 (unless (org-agenda-bulk-marked-p)
7884 (unless m (error "Nothing to mark at point"))
7885 (push m org-agenda-bulk-marked-entries)
7886 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7887 (org-overlay-display ov "> "
7888 (org-get-todo-face "TODO")
7889 'evaporate)
7890 (overlay-put ov 'type 'org-marked-entry-overlay))
7891 (beginning-of-line 2)
7892 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7893 (beginning-of-line 2))
7894 (message "%d entries marked for bulk action"
7895 (length org-agenda-bulk-marked-entries))))))
7897 (defun org-agenda-bulk-mark-regexp (regexp)
7898 "Mark entries match REGEXP."
7899 (interactive "sMark entries matching regexp: ")
7900 (let (entries-marked)
7901 (save-excursion
7902 (goto-char (point-min))
7903 (goto-char (next-single-property-change (point) 'txt))
7904 (while (re-search-forward regexp nil t)
7905 (when (string-match regexp (get-text-property (point) 'txt))
7906 (setq entries-marked (+ entries-marked 1))
7907 (call-interactively 'org-agenda-bulk-mark))))
7908 (if (not entries-marked)
7909 (message "No entry matching this regexp."))))
7911 (defun org-agenda-bulk-unmark ()
7912 "Unmark the entry at point for future bulk action."
7913 (interactive)
7914 (when (org-agenda-bulk-marked-p)
7915 (org-agenda-bulk-remove-overlays
7916 (point-at-bol) (+ 2 (point-at-bol)))
7917 (setq org-agenda-bulk-marked-entries
7918 (delete (org-get-at-bol 'org-hd-marker)
7919 org-agenda-bulk-marked-entries)))
7920 (beginning-of-line 2)
7921 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7922 (beginning-of-line 2))
7923 (message "%d entries marked for bulk action"
7924 (length org-agenda-bulk-marked-entries)))
7926 (defun org-agenda-bulk-toggle ()
7927 "Toggle marking the entry at point for bulk action."
7928 (interactive)
7929 (if (org-agenda-bulk-marked-p)
7930 (org-agenda-bulk-unmark)
7931 (org-agenda-bulk-mark)))
7933 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7934 "Remove the mark overlays between BEG and END in the agenda buffer.
7935 BEG and END default to the buffer limits.
7937 This only removes the overlays, it does not remove the markers
7938 from the list in `org-agenda-bulk-marked-entries'."
7939 (interactive)
7940 (mapc (lambda (ov)
7941 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7942 (delete-overlay ov)))
7943 (overlays-in (or beg (point-min)) (or end (point-max)))))
7945 (defun org-agenda-bulk-remove-all-marks ()
7946 "Remove all marks in the agenda buffer.
7947 This will remove the markers, and the overlays."
7948 (interactive)
7949 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7950 (setq org-agenda-bulk-marked-entries nil)
7951 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7953 (defun org-agenda-bulk-action (&optional arg)
7954 "Execute an remote-editing action on all marked entries.
7955 The prefix arg is passed through to the command if possible."
7956 (interactive "P")
7957 (unless org-agenda-bulk-marked-entries
7958 (error "No entries are marked"))
7959 (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline [f]unction")
7960 (let* ((action (read-char-exclusive))
7961 (org-log-refile (if org-log-refile 'time nil))
7962 (entries (reverse org-agenda-bulk-marked-entries))
7963 redo-at-end
7964 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7965 (cond
7966 ((equal action ?$)
7967 (setq cmd '(org-agenda-archive)))
7969 ((equal action ?A)
7970 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7972 ((member action '(?r ?w))
7973 (setq rfloc (org-refile-get-location
7974 "Refile to"
7975 (marker-buffer (car org-agenda-bulk-marked-entries))
7976 org-refile-allow-creating-parent-nodes))
7977 (if (nth 3 rfloc)
7978 (setcar (nthcdr 3 rfloc)
7979 (move-marker (make-marker) (nth 3 rfloc)
7980 (or (get-file-buffer (nth 1 rfloc))
7981 (find-buffer-visiting (nth 1 rfloc))
7982 (error "This should not happen")))))
7984 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7985 redo-at-end t))
7987 ((equal action ?t)
7988 (setq state (org-icompleting-read
7989 "Todo state: "
7990 (with-current-buffer (marker-buffer (car entries))
7991 (mapcar 'list org-todo-keywords-1))))
7992 (setq cmd `(let ((org-inhibit-blocking t)
7993 (org-inhibit-logging 'note))
7994 (org-agenda-todo ,state))))
7996 ((memq action '(?- ?+))
7997 (setq tag (org-icompleting-read
7998 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7999 (with-current-buffer (marker-buffer (car entries))
8000 (delq nil
8001 (mapcar (lambda (x)
8002 (if (stringp (car x)) x)) org-tag-alist)))))
8003 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8005 ((memq action '(?s ?d))
8006 (let* ((date (unless arg
8007 (org-read-date
8008 nil nil nil
8009 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8010 (ans (if arg nil org-read-date-final-answer))
8011 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8012 (setq cmd `(let* ((bound (fboundp 'read-string))
8013 (old (and bound (symbol-function 'read-string))))
8014 (unwind-protect
8015 (progn
8016 (fset 'read-string (lambda (&rest ignore) ,ans))
8017 (eval '(,c1 arg)))
8018 (if bound
8019 (fset 'read-string old)
8020 (fmakunbound 'read-string)))))))
8022 ((equal action ?S)
8023 (if (not (org-agenda-check-type nil 'agenda 'timeline))
8024 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8025 (let ((days (read-number
8026 (format "Scatter tasks across how many %sdays: "
8027 (if arg "week" "")) 7)))
8028 (setq cmd
8029 `(let ((distance (1+ (random ,days))))
8030 (if arg
8031 (let ((dist distance)
8032 (day-of-week
8033 (calendar-day-of-week
8034 (calendar-gregorian-from-absolute (org-today)))))
8035 (dotimes (i (1+ dist))
8036 (while (member day-of-week org-agenda-weekend-days)
8037 (incf distance)
8038 (incf day-of-week)
8039 (if (= day-of-week 7)
8040 (setq day-of-week 0)))
8041 (incf day-of-week)
8042 (if (= day-of-week 7)
8043 (setq day-of-week 0)))))
8044 ;; silently fail when try to replan a sexp entry
8045 (condition-case nil
8046 (org-agenda-date-later distance)
8047 (error nil)))))))
8049 ((equal action ?f)
8050 (setq cmd (list (intern
8051 (org-icompleting-read "Function: "
8052 obarray 'fboundp t nil nil)))))
8054 (t (error "Invalid bulk action")))
8056 ;; Sort the markers, to make sure that parents are handled before children
8057 (setq entries (sort entries
8058 (lambda (a b)
8059 (cond
8060 ((equal (marker-buffer a) (marker-buffer b))
8061 (< (marker-position a) (marker-position b)))
8063 (string< (buffer-name (marker-buffer a))
8064 (buffer-name (marker-buffer b))))))))
8066 ;; Now loop over all markers and apply cmd
8067 (while (setq e (pop entries))
8068 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8069 (if (not pos)
8070 (progn (message "Skipping removed entry at %s" e)
8071 (setq cntskip (1+ cntskip)))
8072 (goto-char pos)
8073 (eval cmd)
8074 (setq org-agenda-bulk-marked-entries
8075 (delete e org-agenda-bulk-marked-entries))
8076 (setq cnt (1+ cnt))))
8077 (setq org-agenda-bulk-marked-entries nil)
8078 (org-agenda-bulk-remove-all-marks)
8079 (when redo-at-end (org-agenda-redo))
8080 (message "Acted on %d entries%s"
8082 (if (= cntskip 0)
8084 (format ", skipped %d (disappeared before their turn)"
8085 cntskip)))))
8087 ;;; Flagging notes
8089 (defun org-agenda-show-the-flagging-note ()
8090 "Display the flagging note in the other window.
8091 When called a second time in direct sequence, offer to remove the FLAGGING
8092 tag and (if present) the flagging note."
8093 (interactive)
8094 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8095 (win (selected-window))
8096 note heading newhead)
8097 (unless hdmarker
8098 (error "No linked entry at point"))
8099 (if (and (eq this-command last-command)
8100 (y-or-n-p "Unflag and remove any flagging note? "))
8101 (progn
8102 (org-agenda-remove-flag hdmarker)
8103 (let ((win (get-buffer-window "*Flagging Note*")))
8104 (and win (delete-window win)))
8105 (message "Entry unflaged"))
8106 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8107 (unless note
8108 (error "No flagging note"))
8109 (org-kill-new note)
8110 (org-switch-to-buffer-other-window "*Flagging Note*")
8111 (erase-buffer)
8112 (insert note)
8113 (goto-char (point-min))
8114 (while (re-search-forward "\\\\n" nil t)
8115 (replace-match "\n" t t))
8116 (goto-char (point-min))
8117 (select-window win)
8118 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8120 (defun org-agenda-remove-flag (marker)
8121 "Remove the FLAGGED tag and any flagging note in the entry."
8122 (let (newhead)
8123 (org-with-point-at marker
8124 (org-toggle-tag "FLAGGED" 'off)
8125 (org-entry-delete nil "THEFLAGGINGNOTE")
8126 (setq newhead (org-get-heading)))
8127 (org-agenda-change-all-lines newhead marker)
8128 (message "Entry unflaged")))
8130 (defun org-agenda-get-any-marker (&optional pos)
8131 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8132 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8134 ;;; Appointment reminders
8136 (defvar appt-time-msg-list)
8138 ;;;###autoload
8139 (defun org-agenda-to-appt (&optional refresh filter)
8140 "Activate appointments found in `org-agenda-files'.
8141 With a \\[universal-argument] prefix, refresh the list of
8142 appointments.
8144 If FILTER is t, interactively prompt the user for a regular
8145 expression, and filter out entries that don't match it.
8147 If FILTER is a string, use this string as a regular expression
8148 for filtering entries out.
8150 FILTER can also be an alist with the car of each cell being
8151 either 'headline or 'category. For example:
8153 '((headline \"IMPORTANT\")
8154 (category \"Work\"))
8156 will only add headlines containing IMPORTANT or headlines
8157 belonging to the \"Work\" category."
8158 (interactive "P")
8159 (if refresh (setq appt-time-msg-list nil))
8160 (if (eq filter t)
8161 (setq filter (read-from-minibuffer "Regexp filter: ")))
8162 (let* ((cnt 0) ; count added events
8163 (org-agenda-new-buffers nil)
8164 (org-deadline-warning-days 0)
8165 ;; Do not use `org-today' here because appt only takes
8166 ;; time and without date as argument, so it may pass wrong
8167 ;; information otherwise
8168 (today (org-date-to-gregorian
8169 (time-to-days (current-time))))
8170 (org-agenda-restrict nil)
8171 (files (org-agenda-files 'unrestricted)) entries file)
8172 ;; Get all entries which may contain an appt
8173 (org-prepare-agenda-buffers files)
8174 (while (setq file (pop files))
8175 (setq entries
8176 (append entries
8177 (org-agenda-get-day-entries
8178 file today :timestamp :scheduled :deadline))))
8179 (setq entries (delq nil entries))
8180 ;; Map thru entries and find if we should filter them out
8181 (mapc
8182 (lambda(x)
8183 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8184 (cat (get-text-property 1 'org-category x))
8185 (tod (get-text-property 1 'time-of-day x))
8186 (ok (or (null filter)
8187 (and (stringp filter) (string-match filter evt))
8188 (and (listp filter)
8189 (or (string-match
8190 (cadr (assoc 'category filter)) cat)
8191 (string-match
8192 (cadr (assoc 'headline filter)) evt))))))
8193 ;; FIXME: Shall we remove text-properties for the appt text?
8194 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8195 (when (and ok tod)
8196 (setq tod (concat "00" (number-to-string tod))
8197 tod (when (string-match
8198 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8199 (concat (match-string 1 tod) ":"
8200 (match-string 2 tod))))
8201 (appt-add tod evt)
8202 (setq cnt (1+ cnt))))) entries)
8203 (org-release-buffers org-agenda-new-buffers)
8204 (if (eq cnt 0)
8205 (message "No event to add")
8206 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8208 (defun org-agenda-todayp (date)
8209 "Does DATE mean today, when considering `org-extend-today-until'?"
8210 (let ((today (org-today))
8211 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8212 date)))
8213 (eq date today)))
8215 (provide 'org-agenda)
8217 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8219 ;;; org-agenda.el ends here