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