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