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