51ffbebca0cd7bcf9b59c40cb755e947f36d1b98
[org-mode/org-jambu.git] / lisp / org-agenda.el
blob51ffbebca0cd7bcf9b59c40cb755e947f36d1b98
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.4
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
93 :group 'org-agenda
94 :type 'boolean)
96 (defcustom org-agenda-block-separator ?=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group 'org-agenda-export
125 :type '(repeat
126 (list
127 (variable)
128 (sexp :tag "Value"))))
130 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group 'org-agenda-export
134 :type 'hook
135 :options '(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines 0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
148 :group 'org-agenda
149 :type 'integer)
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
156 :group 'org-agenda
157 :type 'boolean)
159 (defcustom org-agenda-export-html-style ""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group 'org-agenda-export
198 :group 'org-export-html
199 :type 'string)
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-span)
246 (choice (const :tag "Day" 'day)
247 (const :tag "Week" 'week)
248 (const :tag "Month" 'month)
249 (const :tag "Year" 'year)
250 (integer :tag "Custom")))
251 (list :tag "Fixed starting date"
252 (const org-agenda-start-day)
253 (string :value "2007-11-01"))
254 (list :tag "Start on day of week"
255 (const org-agenda-start-on-weekday)
256 (choice :value 1
257 (const :tag "Today" nil)
258 (integer :tag "Weekday No.")))
259 (list :tag "Include data from diary"
260 (const org-agenda-include-diary)
261 (boolean))
262 (list :tag "Deadline Warning days"
263 (const org-deadline-warning-days)
264 (integer :value 1))
265 (list :tag "Tags filter preset"
266 (const org-agenda-filter-preset)
267 (list
268 (const :format "" quote)
269 (repeat
270 (string :tag "+tag or -tag"))))
271 (list :tag "Set daily/weekly entry types"
272 (const org-agenda-entry-types)
273 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
274 (const :deadline)
275 (const :scheduled)
276 (const :timestamp)
277 (const :sexp)))
278 (list :tag "Standard skipping condition"
279 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
280 (const org-agenda-skip-function)
281 (list
282 (const :format "" quote)
283 (list
284 (choice
285 :tag "Skipping range"
286 (const :tag "Skip entry" org-agenda-skip-entry-if)
287 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
288 (repeat :inline t :tag "Conditions for skipping"
289 (choice
290 :tag "Condition type"
291 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
292 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
293 (list :tag "TODO state is" :inline t
294 (const 'todo)
295 (choice
296 (const :tag "any not-done state" 'todo)
297 (const :tag "any done state" 'done)
298 (const :tag "any state" 'any)
299 (list :tag "Keyword list"
300 (const :format "" quote)
301 (repeat (string :tag "Keyword")))))
302 (list :tag "TODO state is not" :inline t
303 (const 'nottodo)
304 (choice
305 (const :tag "any not-done state" 'todo)
306 (const :tag "any done state" 'done)
307 (const :tag "any state" 'any)
308 (list :tag "Keyword list"
309 (const :format "" quote)
310 (repeat (string :tag "Keyword")))))
311 (const :tag "scheduled" 'scheduled)
312 (const :tag "not scheduled" 'notscheduled)
313 (const :tag "deadline" 'deadline)
314 (const :tag "no deadline" 'notdeadline)
315 (const :tag "timestamp" 'timestamp)
316 (const :tag "no timestamp" 'nottimestamp))))))
317 (list :tag "Non-standard skipping condition"
318 :value (org-agenda-skip-function)
319 (const org-agenda-skip-function)
320 (sexp :tag "Function or form (quoted!)"))
321 (list :tag "Any variable"
322 (variable :tag "Variable")
323 (sexp :tag "Value (sexp)"))))
324 "Selection of examples for agenda command settings.
325 This will be spliced into the custom type of
326 `org-agenda-custom-commands'.")
329 (defcustom org-agenda-custom-commands nil
330 "Custom commands for the agenda.
331 These commands will be offered on the splash screen displayed by the
332 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
334 (key desc type match settings files)
336 key The key (one or more characters as a string) to be associated
337 with the command.
338 desc A description of the command, when omitted or nil, a default
339 description is built using MATCH.
340 type The command type, any of the following symbols:
341 agenda The daily/weekly agenda.
342 todo Entries with a specific TODO keyword, in all agenda files.
343 search Entries containing search words entry or headline.
344 tags Tags/Property/TODO match in all agenda files.
345 tags-todo Tags/P/T match in all agenda files, TODO entries only.
346 todo-tree Sparse tree of specific TODO keyword in *current* file.
347 tags-tree Sparse tree with all tags matches in *current* file.
348 occur-tree Occur sparse tree for *current* file.
349 ... A user-defined function.
350 match What to search for:
351 - a single keyword for TODO keyword searches
352 - a tags match expression for tags searches
353 - a word search expression for text searches.
354 - a regular expression for occur searches
355 For all other commands, this should be the empty string.
356 settings A list of option settings, similar to that in a let form, so like
357 this: ((opt1 val1) (opt2 val2) ...). The values will be
358 evaluated at the moment of execution, so quote them when needed.
359 files A list of files file to write the produced agenda buffer to
360 with the command `org-store-agenda-views'.
361 If a file name ends in \".html\", an HTML version of the buffer
362 is written out. If it ends in \".ps\", a postscript version is
363 produced. Otherwise, only the plain text is written to the file.
365 You can also define a set of commands, to create a composite agenda buffer.
366 In this case, an entry looks like this:
368 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
370 where
372 desc A description string to be displayed in the dispatcher menu.
373 cmd An agenda command, similar to the above. However, tree commands
374 are no allowed, but instead you can get agenda and global todo list.
375 So valid commands for a set are:
376 (agenda \"\" settings)
377 (alltodo \"\" settings)
378 (stuck \"\" settings)
379 (todo \"match\" settings files)
380 (search \"match\" settings files)
381 (tags \"match\" settings files)
382 (tags-todo \"match\" settings files)
384 Each command can carry a list of options, and another set of options can be
385 given for the whole set of commands. Individual command options take
386 precedence over the general options.
388 When using several characters as key to a command, the first characters
389 are prefix commands. For the dispatcher to display useful information, you
390 should provide a description for the prefix, like
392 (setq org-agenda-custom-commands
393 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
394 (\"hl\" tags \"+HOME+Lisa\")
395 (\"hp\" tags \"+HOME+Peter\")
396 (\"hk\" tags \"+HOME+Kim\")))"
397 :group 'org-agenda-custom-commands
398 :type `(repeat
399 (choice :value ("x" "Describe command here" tags "" nil)
400 (list :tag "Single command"
401 (string :tag "Access Key(s) ")
402 (option (string :tag "Description"))
403 (choice
404 (const :tag "Agenda" agenda)
405 (const :tag "TODO list" alltodo)
406 (const :tag "Search words" search)
407 (const :tag "Stuck projects" stuck)
408 (const :tag "Tags/Property match (all agenda files)" tags)
409 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
410 (const :tag "TODO keyword search (all agenda files)" todo)
411 (const :tag "Tags sparse tree (current buffer)" tags-tree)
412 (const :tag "TODO keyword tree (current buffer)" todo-tree)
413 (const :tag "Occur tree (current buffer)" occur-tree)
414 (sexp :tag "Other, user-defined function"))
415 (string :tag "Match (only for some commands)")
416 ,org-agenda-custom-commands-local-options
417 (option (repeat :tag "Export" (file :tag "Export to"))))
418 (list :tag "Command series, all agenda files"
419 (string :tag "Access Key(s)")
420 (string :tag "Description ")
421 (repeat :tag "Component"
422 (choice
423 (list :tag "Agenda"
424 (const :format "" agenda)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "TODO list (all keywords)"
428 (const :format "" alltodo)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Search words"
432 (const :format "" search)
433 (string :tag "Match")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Stuck projects"
436 (const :format "" stuck)
437 (const :tag "" :format "" "")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search"
440 (const :format "" tags)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search, TODO entries only"
444 (const :format "" tags-todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "TODO keyword search"
448 (const :format "" todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "Other, user-defined function"
452 (symbol :tag "function")
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)))
456 (repeat :tag "Settings for entire command set"
457 (list (variable :tag "Any variable")
458 (sexp :tag "Value")))
459 (option (repeat :tag "Export" (file :tag "Export to"))))
460 (cons :tag "Prefix key documentation"
461 (string :tag "Access Key(s)")
462 (string :tag "Description ")))))
464 (defcustom org-agenda-query-register ?o
465 "The register holding the current query string.
466 The purpose of this is that if you construct a query string interactively,
467 you can then use it to define a custom command."
468 :group 'org-agenda-custom-commands
469 :type 'character)
471 (defcustom org-stuck-projects
472 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
473 "How to identify stuck projects.
474 This is a list of four items:
475 1. A tags/todo/property matcher string that is used to identify a project.
476 See the manual for a description of tag and property searches.
477 The entire tree below a headline matched by this is considered one project.
478 2. A list of TODO keywords identifying non-stuck projects.
479 If the project subtree contains any headline with one of these todo
480 keywords, the project is considered to be not stuck. If you specify
481 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
482 3. A list of tags identifying non-stuck projects.
483 If the project subtree contains any headline with one of these tags,
484 the project is considered to be not stuck. If you specify \"*\" as
485 a tag, any tag will mark the project unstuck. Note that this is about
486 the explicit presence of a tag somewhere in the subtree, inherited
487 tags to not count here. If inherited tags make a project not stuck,
488 use \"-TAG\" in the tags part of the matcher under (1.) above.
489 4. An arbitrary regular expression matching non-stuck projects.
491 If the project turns out to be not stuck, search continues also in the
492 subtree to see if any of the subtasks have project status.
494 See also the variable `org-tags-match-list-sublevels' which applies
495 to projects matched by this search as well.
497 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
498 or `C-c a #' to produce the list."
499 :group 'org-agenda-custom-commands
500 :type '(list
501 (string :tag "Tags/TODO match to identify a project")
502 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
503 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
504 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
506 (defcustom org-agenda-filter-effort-default-operator "<"
507 "The default operator for effort estimate filtering.
508 If you select an effort estimate limit without first pressing an operator,
509 this one will be used."
510 :group 'org-agenda-custom-commands
511 :type '(choice (const :tag "less or equal" "<")
512 (const :tag "greater or equal"">")
513 (const :tag "equal" "=")))
515 (defgroup org-agenda-skip nil
516 "Options concerning skipping parts of agenda files."
517 :tag "Org Agenda Skip"
518 :group 'org-agenda)
520 (defcustom org-agenda-skip-function-global nil
521 "Function to be called at each match during agenda construction.
522 If this function returns nil, the current match should not be skipped.
523 If the function decided to skip an agenda match, is must return the
524 buffer position from which the search should be continued.
525 This may also be a Lisp form, which will be evaluated.
527 This variable will be applied to every agenda match, including
528 tags/property searches and TODO lists. So try to make the test function
529 do its checking as efficiently as possible. To implement a skipping
530 condition just for specific agenda commands, use the variable
531 `org-agenda-skip-function' which can be set in the options section
532 of custom agenda commands."
533 :group 'org-agenda-skip
534 :type 'sexp)
536 (defgroup org-agenda-daily/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag "Org Agenda Daily/Weekly"
539 :group 'org-agenda)
540 (defgroup org-agenda-todo-list nil
541 "Options concerning the global todo list agenda view."
542 :tag "Org Agenda Todo List"
543 :group 'org-agenda)
544 (defgroup org-agenda-match-view nil
545 "Options concerning the general tags/property/todo match agenda view."
546 :tag "Org Agenda Match View"
547 :group 'org-agenda)
548 (defgroup org-agenda-search-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
553 (defvar org-agenda-archives-mode nil
554 "Non-nil means the agenda will include archived items.
555 If this is the symbol `trees', trees in the selected agenda scope
556 that are marked with the ARCHIVE tag will be included anyway. When this is
557 t, also all archive files associated with the current selection of agenda
558 files will be included.")
560 (defcustom org-agenda-skip-comment-trees t
561 "Non-nil means skip trees that start with the COMMENT keyword.
562 When nil, these trees are also scanned by agenda commands."
563 :group 'org-agenda-skip
564 :type 'boolean)
566 (defcustom org-agenda-todo-list-sublevels t
567 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
568 When nil, the sublevels of a TODO entry are not checked, resulting in
569 potentially much shorter TODO lists."
570 :group 'org-agenda-skip
571 :group 'org-agenda-todo-list
572 :type 'boolean)
574 (defcustom org-agenda-todo-ignore-with-date nil
575 "Non-nil means don't show entries with a date in the global todo list.
576 You can use this if you prefer to mark mere appointments with a TODO keyword,
577 but don't want them to show up in the TODO list.
578 When this is set, it also covers deadlines and scheduled items, the settings
579 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
580 will be ignored.
581 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
582 :group 'org-agenda-skip
583 :group 'org-agenda-todo-list
584 :type 'boolean)
586 (defcustom org-agenda-todo-ignore-timestamp nil
587 "Non-nil means don't show entries with a timestamp.
588 This applies when creating the global todo list.
589 Valid values are:
591 past Don't show entries for today or in the past.
593 future Don't show entries with a timestamp in the future.
594 The idea behind this is that if it has a future
595 timestamp, you don't want to think about it until the
596 date.
598 all Don't show any entries with a timestamp in the global todo list.
599 The idea behind this is that by setting a timestamp, you
600 have already \"taken care\" of this item.
602 This variable can also have an integer as a value. If positive (N),
603 todos with a timestamp N or more days in the future will be ignored. If
604 negative (-N), todos with a timestamp N or more days in the past will be
605 ignored. If 0, todos with a timestamp either today or in the future will
606 be ignored. For example, a value of -1 will exclude todos with a
607 timestamp in the past (yesterday or earlier), while a value of 7 will
608 exclude todos with a timestamp a week or more in the future.
610 See also `org-agenda-todo-ignore-with-date'.
611 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
612 to make his option also apply to the tags-todo list."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type '(choice
616 (const :tag "Ignore future timestamp todos" future)
617 (const :tag "Ignore past or present timestamp todos" past)
618 (const :tag "Ignore all timestamp todos" all)
619 (const :tag "Show timestamp todos" nil)
620 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
622 (defcustom org-agenda-todo-ignore-scheduled nil
623 "Non-nil means, ignore some scheduled TODO items when making TODO list.
624 This applies when creating the global todo list.
625 Valid values are:
627 past Don't show entries scheduled today or in the past.
629 future Don't show entries scheduled in the future.
630 The idea behind this is that by scheduling it, you don't want to
631 think about it until the scheduled date.
633 all Don't show any scheduled entries in the global todo list.
634 The idea behind this is that by scheduling it, you have already
635 \"taken care\" of this item.
637 t Same as `all', for backward compatibility.
639 This variable can also have an integer as a value. See
640 `org-agenda-todo-ignore-timestamp' for more details.
642 See also `org-agenda-todo-ignore-with-date'.
643 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
644 to make his option also apply to the tags-todo list."
645 :group 'org-agenda-skip
646 :group 'org-agenda-todo-list
647 :type '(choice
648 (const :tag "Ignore future-scheduled todos" future)
649 (const :tag "Ignore past- or present-scheduled todos" past)
650 (const :tag "Ignore all scheduled todos" all)
651 (const :tag "Ignore all scheduled todos (compatibility)" t)
652 (const :tag "Show scheduled todos" nil)
653 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
655 (defcustom org-agenda-todo-ignore-deadlines nil
656 "Non-nil means ignore some deadlined TODO items when making TODO list.
657 There are different motivations for using different values, please think
658 carefully when configuring this variable.
660 This applies when creating the global todo list.
661 Valid values are:
663 near Don't show near deadline entries. A deadline is near when it is
664 closer than `org-deadline-warning-days' days. The idea behind this
665 is that such items will appear in the agenda anyway.
667 far Don't show TODO entries where a deadline has been defined, but
668 the deadline is not near. This is useful if you don't want to
669 use the todo list to figure out what to do now.
671 past Don't show entries with a deadline timestamp for today or in the past.
673 future Don't show entries with a deadline timestamp in the future, not even
674 when they become `near' ones. Use it with caution.
676 all Ignore all TODO entries that do have a deadline.
678 t Same as `near', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore near deadlines" near)
690 (const :tag "Ignore near deadlines (compatibility)" t)
691 (const :tag "Ignore far deadlines" far)
692 (const :tag "Ignore all TODOs with a deadlines" all)
693 (const :tag "Show all TODOs, even if they have a deadline" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-tags-todo-honor-ignore-options nil
697 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
698 The variables
699 `org-agenda-todo-ignore-with-date',
700 `org-agenda-todo-ignore-timestamp',
701 `org-agenda-todo-ignore-scheduled',
702 `org-agenda-todo-ignore-deadlines'
703 make the global TODO list skip entries that have time stamps of certain
704 kinds. If this option is set, the same options will also apply for the
705 tags-todo search, which is the general tags/property matcher
706 restricted to unfinished TODO entries only."
707 :group 'org-agenda-skip
708 :group 'org-agenda-todo-list
709 :group 'org-agenda-match-view
710 :type 'boolean)
712 (defcustom org-agenda-skip-scheduled-if-done nil
713 "Non-nil means don't show scheduled items in agenda when they are done.
714 This is relevant for the daily/weekly agenda, not for the TODO list. And
715 it applies only to the actual date of the scheduling. Warnings about
716 an item with a past scheduling dates are always turned off when the item
717 is DONE."
718 :group 'org-agenda-skip
719 :group 'org-agenda-daily/weekly
720 :type 'boolean)
722 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
723 "Non-nil means skip scheduling line if same entry shows because of deadline.
724 In the agenda of today, an entry can show up multiple times because
725 it is both scheduled and has a nearby deadline, and maybe a plain time
726 stamp as well.
727 When this variable is t, then only the deadline is shown and the fact that
728 the entry is scheduled today or was scheduled previously is not shown.
729 When this variable is nil, the entry will be shown several times. When
730 the variable is the symbol `not-today', then skip scheduled previously,
731 but not scheduled today."
732 :group 'org-agenda-skip
733 :group 'org-agenda-daily/weekly
734 :type '(choice
735 (const :tag "Never" nil)
736 (const :tag "Always" t)
737 (const :tag "Not when scheduled today" not-today)))
739 (defcustom org-agenda-skip-deadline-if-done nil
740 "Non-nil means don't show deadlines when the corresponding item is done.
741 When nil, the deadline is still shown and should give you a happy feeling.
742 This is relevant for the daily/weekly agenda. And it applied only to the
743 actually date of the deadline. Warnings about approaching and past-due
744 deadlines are always turned off when the item is DONE."
745 :group 'org-agenda-skip
746 :group 'org-agenda-daily/weekly
747 :type 'boolean)
749 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
750 "Non-nil means skip deadline prewarning when entry is also scheduled.
751 This will apply on all days where a prewarning for the deadline would
752 be shown, but not at the day when the entry is actually due. On that day,
753 the deadline will be shown anyway.
754 This variable may be set to nil, t, or a number which will then give
755 the number of days before the actual deadline when the prewarnings
756 should resume.
757 This can be used in a workflow where the first showing of the deadline will
758 trigger you to schedule it, and then you don't want to be reminded of it
759 because you will take care of it on the day when scheduled."
760 :group 'org-agenda-skip
761 :group 'org-agenda-daily/weekly
762 :type '(choice
763 (const :tag "Alwas show prewarning" nil)
764 (const :tag "Remove prewarning if entry is scheduled" t)
765 (integer :tag "Restart prewarning N days before deadline")))
767 (defcustom org-agenda-skip-additional-timestamps-same-entry t
768 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
769 When non-nil, after the search for timestamps has matched once in an
770 entry, the rest of the entry will not be searched."
771 :group 'org-agenda-skip
772 :type 'boolean)
774 (defcustom org-agenda-skip-timestamp-if-done nil
775 "Non-nil means don't select item by timestamp or -range if it is DONE."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type 'boolean)
780 (defcustom org-agenda-dim-blocked-tasks t
781 "Non-nil means dim blocked tasks in the agenda display.
782 This causes some overhead during agenda construction, but if you
783 have turned on `org-enforce-todo-dependencies',
784 `org-enforce-todo-checkbox-dependencies', or any other blocking
785 mechanism, this will create useful feedback in the agenda.
787 Instead of t, this variable can also have the value `invisible'.
788 Then blocked tasks will be invisible and only become visible when
789 they become unblocked. An exemption to this behavior is when a task is
790 blocked because of unchecked checkboxes below it. Since checkboxes do
791 not show up in the agenda views, making this task invisible you remove any
792 trace from agenda views that there is something to do. Therefore, a task
793 that is blocked because of checkboxes will never be made invisible, it
794 will only be dimmed."
795 :group 'org-agenda-daily/weekly
796 :group 'org-agenda-todo-list
797 :type '(choice
798 (const :tag "Do not dim" nil)
799 (const :tag "Dim to a grey face" t)
800 (const :tag "Make invisible" invisible)))
802 (defcustom org-timeline-show-empty-dates 3
803 "Non-nil means `org-timeline' also shows dates without an entry.
804 When nil, only the days which actually have entries are shown.
805 When t, all days between the first and the last date are shown.
806 When an integer, show also empty dates, but if there is a gap of more than
807 N days, just insert a special line indicating the size of the gap."
808 :group 'org-agenda-skip
809 :type '(choice
810 (const :tag "None" nil)
811 (const :tag "All" t)
812 (integer :tag "at most")))
814 (defgroup org-agenda-startup nil
815 "Options concerning initial settings in the Agenda in Org Mode."
816 :tag "Org Agenda Startup"
817 :group 'org-agenda)
819 (defcustom org-agenda-menu-show-matcher t
820 "Non-nil means show the match string in the agenda dispatcher menu.
821 When nil, the matcher string is not shown, but is put into the help-echo
822 property so than moving the mouse over the command shows it.
823 Setting it to nil is good if matcher strings are very long and/or if
824 you want to use two-column display (see `org-agenda-menu-two-column')."
825 :group 'org-agenda
826 :type 'boolean)
828 (defcustom org-agenda-menu-two-column nil
829 "Non-nil means, use two columns to show custom commands in the dispatcher.
830 If you use this, you probably want to set `org-agenda-menu-show-matcher'
831 to nil."
832 :group 'org-agenda
833 :type 'boolean)
835 (defcustom org-finalize-agenda-hook nil
836 "Hook run just before displaying an agenda buffer."
837 :group 'org-agenda-startup
838 :type 'hook)
840 (defcustom org-agenda-mouse-1-follows-link nil
841 "Non-nil means mouse-1 on a link will follow the link in the agenda.
842 A longer mouse click will still set point. Does not work on XEmacs.
843 Needs to be set before org.el is loaded."
844 :group 'org-agenda-startup
845 :type 'boolean)
847 (defcustom org-agenda-start-with-follow-mode nil
848 "The initial value of follow mode in a newly created agenda window."
849 :group 'org-agenda-startup
850 :type 'boolean)
852 (defcustom org-agenda-show-outline-path t
853 "Non-nil means show outline path in echo area after line motion."
854 :group 'org-agenda-startup
855 :type 'boolean)
857 (defcustom org-agenda-start-with-entry-text-mode nil
858 "The initial value of entry-text-mode in a newly created agenda window."
859 :group 'org-agenda-startup
860 :type 'boolean)
862 (defcustom org-agenda-entry-text-maxlines 5
863 "Number of text lines to be added when `E' is pressed in the agenda.
865 Note that this variable only used during agenda display. Add add entry text
866 when exporting the agenda, configure the variable
867 `org-agenda-add-entry-ext-maxlines'."
868 :group 'org-agenda
869 :type 'integer)
871 (defcustom org-agenda-entry-text-exclude-regexps nil
872 "List of regular expressions to clean up entry text.
873 The complete matches of all regular expressions in this list will be
874 removed from entry text before it is shown in the agenda."
875 :group 'org-agenda
876 :type '(repeat (regexp)))
878 (defvar org-agenda-entry-text-cleanup-hook nil
879 "Hook that is run after basic cleanup of entry text to be shown in agenda.
880 This cleanup is done in a temporary buffer, so the function may inspect and
881 change the entire buffer.
882 Some default stuff like drawers and scheduling/deadline dates will already
883 have been removed when this is called, as will any matches for regular
884 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
886 (defvar org-agenda-include-inactive-timestamps nil
887 "Non-nil means include inactive time stamps in agenda and timeline.")
889 (defgroup org-agenda-windows nil
890 "Options concerning the windows used by the Agenda in Org Mode."
891 :tag "Org Agenda Windows"
892 :group 'org-agenda)
894 (defcustom org-agenda-window-setup 'reorganize-frame
895 "How the agenda buffer should be displayed.
896 Possible values for this option are:
898 current-window Show agenda in the current window, keeping all other windows.
899 other-window Use `switch-to-buffer-other-window' to display agenda.
900 reorganize-frame Show only two windows on the current frame, the current
901 window and the agenda.
902 other-frame Use `switch-to-buffer-other-frame' to display agenda.
903 Also, when exiting the agenda, kill that frame.
904 See also the variable `org-agenda-restore-windows-after-quit'."
905 :group 'org-agenda-windows
906 :type '(choice
907 (const current-window)
908 (const other-frame)
909 (const other-window)
910 (const reorganize-frame)))
912 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
913 "The min and max height of the agenda window as a fraction of frame height.
914 The value of the variable is a cons cell with two numbers between 0 and 1.
915 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
916 :group 'org-agenda-windows
917 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
919 (defcustom org-agenda-restore-windows-after-quit nil
920 "Non-nil means restore window configuration upon exiting agenda.
921 Before the window configuration is changed for displaying the agenda,
922 the current status is recorded. When the agenda is exited with
923 `q' or `x' and this option is set, the old state is restored. If
924 `org-agenda-window-setup' is `other-frame', the value of this
925 option will be ignored."
926 :group 'org-agenda-windows
927 :type 'boolean)
929 (defcustom org-agenda-ndays nil
930 "Number of days to include in overview display.
931 Should be 1 or 7.
932 Obsolete, see `org-agenda-span'."
933 :group 'org-agenda-daily/weekly
934 :type 'integer)
936 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
938 (defcustom org-agenda-span 'week
939 "Number of days to include in overview display.
940 Can be day, week, month, year, or any number of days.
941 Custom commands can set this variable in the options section."
942 :group 'org-agenda-daily/weekly
943 :type '(choice (const :tag "Day" day)
944 (const :tag "Week" week)
945 (const :tag "Month" month)
946 (const :tag "Year" year)
947 (integer :tag "Custom")))
949 (defcustom org-agenda-start-on-weekday 1
950 "Non-nil means start the overview always on the specified weekday.
951 0 denotes Sunday, 1 denotes Monday etc.
952 When nil, always start on the current day.
953 Custom commands can set this variable in the options section."
954 :group 'org-agenda-daily/weekly
955 :type '(choice (const :tag "Today" nil)
956 (integer :tag "Weekday No.")))
958 (defcustom org-agenda-show-all-dates t
959 "Non-nil means `org-agenda' shows every day in the selected range.
960 When nil, only the days which actually have entries are shown."
961 :group 'org-agenda-daily/weekly
962 :type 'boolean)
964 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
965 "Format string for displaying dates in the agenda.
966 Used by the daily/weekly agenda and by the timeline. This should be
967 a format string understood by `format-time-string', or a function returning
968 the formatted date as a string. The function must take a single argument,
969 a calendar-style date list like (month day year)."
970 :group 'org-agenda-daily/weekly
971 :type '(choice
972 (string :tag "Format string")
973 (function :tag "Function")))
975 (defun org-agenda-format-date-aligned (date)
976 "Format a date string for display in the daily/weekly agenda, or timeline.
977 This function makes sure that dates are aligned for easy reading."
978 (require 'cal-iso)
979 (let* ((dayname (calendar-day-name date))
980 (day (cadr date))
981 (day-of-week (calendar-day-of-week date))
982 (month (car date))
983 (monthname (calendar-month-name month))
984 (year (nth 2 date))
985 (iso-week (org-days-to-iso-week
986 (calendar-absolute-from-gregorian date)))
987 (weekyear (cond ((and (= month 1) (>= iso-week 52))
988 (1- year))
989 ((and (= month 12) (<= iso-week 1))
990 (1+ year))
991 (t year)))
992 (weekstring (if (= day-of-week 1)
993 (format " W%02d" iso-week)
994 "")))
995 (format "%-10s %2d %s %4d%s"
996 dayname day monthname year weekstring)))
998 (defcustom org-agenda-time-leading-zero nil
999 "Non-nil means use leading zero for military times in agenda.
1000 For example, 9:30am would become 09:30 rather than 9:30."
1001 :group 'org-agenda-daily/weekly
1002 :type 'boolean)
1004 (defcustom org-agenda-timegrid-use-ampm nil
1005 "When set, show AM/PM style timestamps on the timegrid."
1006 :group 'org-agenda
1007 :type 'boolean)
1009 (defun org-agenda-time-of-day-to-ampm (time)
1010 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1011 (let* ((hour-number (string-to-number (substring time 0 -3)))
1012 (minute (substring time -2))
1013 (ampm "am"))
1014 (cond
1015 ((equal hour-number 12)
1016 (setq ampm "pm"))
1017 ((> hour-number 12)
1018 (setq ampm "pm")
1019 (setq hour-number (- hour-number 12))))
1020 (concat
1021 (if org-agenda-time-leading-zero
1022 (format "%02d" hour-number)
1023 (format "%02s" (number-to-string hour-number)))
1024 ":" minute ampm)))
1026 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1027 "Conditionally convert TIME to AM/PM format
1028 based on `org-agenda-timegrid-use-ampm'"
1029 (if org-agenda-timegrid-use-ampm
1030 (org-agenda-time-of-day-to-ampm time)
1031 time))
1033 (defcustom org-agenda-weekend-days '(6 0)
1034 "Which days are weekend?
1035 These days get the special face `org-agenda-date-weekend' in the agenda
1036 and timeline buffers."
1037 :group 'org-agenda-daily/weekly
1038 :type '(set :greedy t
1039 (const :tag "Monday" 1)
1040 (const :tag "Tuesday" 2)
1041 (const :tag "Wednesday" 3)
1042 (const :tag "Thursday" 4)
1043 (const :tag "Friday" 5)
1044 (const :tag "Saturday" 6)
1045 (const :tag "Sunday" 0)))
1047 (defcustom org-agenda-include-diary nil
1048 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1049 Custom commands can set this variable in the options section."
1050 :group 'org-agenda-daily/weekly
1051 :type 'boolean)
1053 (defcustom org-agenda-include-deadlines t
1054 "If non-nil, include entries within their deadline warning period.
1055 Custom commands can set this variable in the options section."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-include-all-todo nil
1060 "Set means weekly/daily agenda will always contain all TODO entries.
1061 The TODO entries will be listed at the top of the agenda, before
1062 the entries for specific days.
1063 This option is deprecated, it is better to define a block agenda instead."
1064 :group 'org-agenda-daily/weekly
1065 :type 'boolean)
1067 (defcustom org-agenda-repeating-timestamp-show-all t
1068 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1069 When set to a list of strings, only show occurrences of repeating
1070 stamps for these TODO keywords. When nil, only one occurrence is
1071 shown, either today or the nearest into the future."
1072 :group 'org-agenda-daily/weekly
1073 :type '(choice
1074 (const :tag "Show repeating stamps" t)
1075 (repeat :tag "Show repeating stamps for these TODO keywords"
1076 (string :tag "TODO Keyword"))
1077 (const :tag "Don't show repeating stamps" nil)))
1079 (defcustom org-scheduled-past-days 10000
1080 "No. of days to continue listing scheduled items that are not marked DONE.
1081 When an item is scheduled on a date, it shows up in the agenda on this
1082 day and will be listed until it is marked done for the number of days
1083 given here."
1084 :group 'org-agenda-daily/weekly
1085 :type 'integer)
1087 (defcustom org-agenda-log-mode-items '(closed clock)
1088 "List of items that should be shown in agenda log mode.
1089 This list may contain the following symbols:
1091 closed Show entries that have been closed on that day.
1092 clock Show entries that have received clocked time on that day.
1093 state Show all logged state changes.
1094 Note that instead of changing this variable, you can also press `C-u l' in
1095 the agenda to display all available LOG items temporarily."
1096 :group 'org-agenda-daily/weekly
1097 :type '(set :greedy t (const closed) (const clock) (const state)))
1099 (defcustom org-agenda-log-mode-add-notes t
1100 "Non-nil means add first line of notes to log entries in agenda views.
1101 If a log item like a state change or a clock entry is associated with
1102 notes, the first line of these notes will be added to the entry in the
1103 agenda display."
1104 :group 'org-agenda-daily/weekly
1105 :type 'boolean)
1107 (defcustom org-agenda-start-with-log-mode nil
1108 "The initial value of log-mode in a newly created agenda window."
1109 :group 'org-agenda-startup
1110 :group 'org-agenda-daily/weekly
1111 :type 'boolean)
1113 (defcustom org-agenda-start-with-clockreport-mode nil
1114 "The initial value of clockreport-mode in a newly created agenda window."
1115 :group 'org-agenda-startup
1116 :group 'org-agenda-daily/weekly
1117 :type 'boolean)
1119 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1120 "Property list with parameters for the clocktable in clockreport mode.
1121 This is the display mode that shows a clock table in the daily/weekly
1122 agenda, the properties for this dynamic block can be set here.
1123 The usual clocktable parameters are allowed here, but you cannot set
1124 the properties :name, :tstart, :tend, :block, and :scope - these will
1125 be overwritten to make sure the content accurately reflects the
1126 current display in the agenda."
1127 :group 'org-agenda-daily/weekly
1128 :type 'plist)
1130 (defcustom org-agenda-search-view-always-boolean nil
1131 "Non-nil means the search string is interpreted as individual parts.
1133 The search string for search view can either be interpreted as a phrase,
1134 or as a list of snippets that define a boolean search for a number of
1135 strings.
1137 When this is non-nil, the string will be split on whitespace, and each
1138 snippet will be searched individually, and all must match in order to
1139 select an entry. A snippet is then a single string of non-white
1140 characters, or a string in double quotes, or a regexp in {} braces.
1141 If a snippet is preceded by \"-\", the snippet must *not* match.
1142 \"+\" is syntactic sugar for positive selection. Each snippet may
1143 be found as a full word or a partial word, but see the variable
1144 `org-agenda-search-view-force-full-words'.
1146 When this is nil, search will look for the entire search phrase as one,
1147 with each space character matching any amount of whitespace, including
1148 line breaks.
1150 Even when this is nil, you can still switch to Boolean search dynamically
1151 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1152 is a regexp marked with braces like \"{abc}\", this will also switch to
1153 boolean search."
1154 :group 'org-agenda-search-view
1155 :type 'boolean)
1157 (if (fboundp 'defvaralias)
1158 (defvaralias 'org-agenda-search-view-search-words-only
1159 'org-agenda-search-view-always-boolean))
1161 (defcustom org-agenda-search-view-force-full-words nil
1162 "Non-nil means, search words must be matches as complete words.
1163 When nil, they may also match part of a word."
1164 :group 'org-agenda-search-view
1165 :type 'boolean)
1167 (defgroup org-agenda-time-grid nil
1168 "Options concerning the time grid in the Org-mode Agenda."
1169 :tag "Org Agenda Time Grid"
1170 :group 'org-agenda)
1172 (defcustom org-agenda-search-headline-for-time t
1173 "Non-nil means search headline for a time-of-day.
1174 If the headline contains a time-of-day in one format or another, it will
1175 be used to sort the entry into the time sequence of items for a day.
1176 Some people have time stamps in the headline that refer to the creation
1177 time or so, and then this produces an unwanted side effect. If this is
1178 the case for your, use this variable to turn off searching the headline
1179 for a time."
1180 :group 'org-agenda-time-grid
1181 :type 'boolean)
1183 (defcustom org-agenda-use-time-grid t
1184 "Non-nil means show a time grid in the agenda schedule.
1185 A time grid is a set of lines for specific times (like every two hours between
1186 8:00 and 20:00). The items scheduled for a day at specific times are
1187 sorted in between these lines.
1188 For details about when the grid will be shown, and what it will look like, see
1189 the variable `org-agenda-time-grid'."
1190 :group 'org-agenda-time-grid
1191 :type 'boolean)
1193 (defcustom org-agenda-time-grid
1194 '((daily today require-timed)
1195 "----------------"
1196 (800 1000 1200 1400 1600 1800 2000))
1198 "The settings for time grid for agenda display.
1199 This is a list of three items. The first item is again a list. It contains
1200 symbols specifying conditions when the grid should be displayed:
1202 daily if the agenda shows a single day
1203 weekly if the agenda shows an entire week
1204 today show grid on current date, independent of daily/weekly display
1205 require-timed show grid only if at least one item has a time specification
1207 The second item is a string which will be placed behind the grid time.
1209 The third item is a list of integers, indicating the times that should have
1210 a grid line."
1211 :group 'org-agenda-time-grid
1212 :type
1213 '(list
1214 (set :greedy t :tag "Grid Display Options"
1215 (const :tag "Show grid in single day agenda display" daily)
1216 (const :tag "Show grid in weekly agenda display" weekly)
1217 (const :tag "Always show grid for today" today)
1218 (const :tag "Show grid only if any timed entries are present"
1219 require-timed)
1220 (const :tag "Skip grid times already present in an entry"
1221 remove-match))
1222 (string :tag "Grid String")
1223 (repeat :tag "Grid Times" (integer :tag "Time"))))
1225 (defcustom org-agenda-show-current-time-in-grid t
1226 "Non-nil means show the current time in the time grid."
1227 :group 'org-agenda-time-grid
1228 :type 'boolean)
1230 (defcustom org-agenda-current-time-string
1231 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1232 "The string for the current time marker in the agenda."
1233 :group 'org-agenda-time-grid
1234 :type 'string)
1236 (defgroup org-agenda-sorting nil
1237 "Options concerning sorting in the Org-mode Agenda."
1238 :tag "Org Agenda Sorting"
1239 :group 'org-agenda)
1241 (defcustom org-agenda-sorting-strategy
1242 '((agenda habit-down time-up priority-down category-keep)
1243 (todo priority-down category-keep)
1244 (tags priority-down category-keep)
1245 (search category-keep))
1246 "Sorting structure for the agenda items of a single day.
1247 This is a list of symbols which will be used in sequence to determine
1248 if an entry should be listed before another entry. The following
1249 symbols are recognized:
1251 time-up Put entries with time-of-day indications first, early first
1252 time-down Put entries with time-of-day indications first, late first
1253 category-keep Keep the default order of categories, corresponding to the
1254 sequence in `org-agenda-files'.
1255 category-up Sort alphabetically by category, A-Z.
1256 category-down Sort alphabetically by category, Z-A.
1257 tag-up Sort alphabetically by last tag, A-Z.
1258 tag-down Sort alphabetically by last tag, Z-A.
1259 priority-up Sort numerically by priority, high priority last.
1260 priority-down Sort numerically by priority, high priority first.
1261 todo-state-up Sort by todo state, tasks that are done last.
1262 todo-state-down Sort by todo state, tasks that are done first.
1263 effort-up Sort numerically by estimated effort, high effort last.
1264 effort-down Sort numerically by estimated effort, high effort first.
1265 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1266 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1267 habit-up Put entries that are habits first
1268 habit-down Put entries that are habits last
1269 alpha-up Sort headlines alphabetically
1270 alpha-down Sort headlines alphabetically, reversed
1272 The different possibilities will be tried in sequence, and testing stops
1273 if one comparison returns a \"not-equal\". For example, the default
1274 '(time-up category-keep priority-down)
1275 means: Pull out all entries having a specified time of day and sort them,
1276 in order to make a time schedule for the current day the first thing in the
1277 agenda listing for the day. Of the entries without a time indication, keep
1278 the grouped in categories, don't sort the categories, but keep them in
1279 the sequence given in `org-agenda-files'. Within each category sort by
1280 priority.
1282 Leaving out `category-keep' would mean that items will be sorted across
1283 categories by priority.
1285 Instead of a single list, this can also be a set of list for specific
1286 contents, with a context symbol in the car of the list, any of
1287 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1289 Custom commands can bind this variable in the options section."
1290 :group 'org-agenda-sorting
1291 :type `(choice
1292 (repeat :tag "General" ,org-sorting-choice)
1293 (list :tag "Individually"
1294 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1295 (repeat ,org-sorting-choice))
1296 (cons (const :tag "Strategy for TODO lists" todo)
1297 (repeat ,org-sorting-choice))
1298 (cons (const :tag "Strategy for Tags matches" tags)
1299 (repeat ,org-sorting-choice))
1300 (cons (const :tag "Strategy for search matches" search)
1301 (repeat ,org-sorting-choice)))))
1303 (defcustom org-agenda-cmp-user-defined nil
1304 "A function to define the comparison `user-defined'.
1305 This function must receive two arguments, agenda entry a and b.
1306 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1307 the user comparison, return nil.
1308 When this is defined, you can make `user-defined-up' and `user-defined-down'
1309 part of an agenda sorting strategy."
1310 :group 'org-agenda-sorting
1311 :type 'symbol)
1313 (defcustom org-sort-agenda-notime-is-late t
1314 "Non-nil means items without time are considered late.
1315 This is only relevant for sorting. When t, items which have no explicit
1316 time like 15:30 will be considered as 99:01, i.e. later than any items which
1317 do have a time. When nil, the default time is before 0:00. You can use this
1318 option to decide if the schedule for today should come before or after timeless
1319 agenda entries."
1320 :group 'org-agenda-sorting
1321 :type 'boolean)
1323 (defcustom org-sort-agenda-noeffort-is-high t
1324 "Non-nil means items without effort estimate are sorted as high effort.
1325 This also applies when filtering an agenda view with respect to the
1326 < or > effort operator. Then, tasks with no effort defined will be treated
1327 as tasks with high effort.
1328 When nil, such items are sorted as 0 minutes effort."
1329 :group 'org-agenda-sorting
1330 :type 'boolean)
1332 (defgroup org-agenda-line-format nil
1333 "Options concerning the entry prefix in the Org-mode agenda display."
1334 :tag "Org Agenda Line Format"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-prefix-format
1338 '((agenda . " %i %-12:c%?-12t% s")
1339 (timeline . " % s")
1340 (todo . " %i %-12:c")
1341 (tags . " %i %-12:c")
1342 (search . " %i %-12:c"))
1343 "Format specifications for the prefix of items in the agenda views.
1344 An alist with four entries, for the different agenda types. The keys to the
1345 sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
1346 are format strings.
1347 This format works similar to a printf format, with the following meaning:
1349 %c the category of the item, \"Diary\" for entries from the diary, or
1350 as given by the CATEGORY keyword or derived from the file name.
1351 %i the icon category of the item, as give in
1352 `org-agenda-category-icon-alist'.
1353 %T the *last* tag of the item. Last because inherited tags come
1354 first in the list.
1355 %t the time-of-day specification if one applies to the entry, in the
1356 format HH:MM
1357 %s Scheduling/Deadline information, a short string
1358 %(expression) Eval EXPRESSION and replace the control string
1359 by the result
1361 All specifiers work basically like the standard `%s' of printf, but may
1362 contain two additional characters: A question mark just after the `%' and
1363 a whitespace/punctuation character just before the final letter.
1365 If the first character after `%' is a question mark, the entire field
1366 will only be included if the corresponding value applies to the
1367 current entry. This is useful for fields which should have fixed
1368 width when present, but zero width when absent. For example,
1369 \"%?-12t\" will result in a 12 character time field if a time of the
1370 day is specified, but will completely disappear in entries which do
1371 not contain a time.
1373 If there is punctuation or whitespace character just before the final
1374 format letter, this character will be appended to the field value if
1375 the value is not empty. For example, the format \"%-12:c\" leads to
1376 \"Diary: \" if the category is \"Diary\". If the category were be
1377 empty, no additional colon would be inserted.
1379 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1380 - Indent the line with two space characters
1381 - Give the category in a 12 chars wide field, padded with whitespace on
1382 the right (because of `-'). Append a colon if there is a category
1383 (because of `:').
1384 - If there is a time-of-day, put it into a 12 chars wide field. If no
1385 time, don't put in an empty field, just skip it (because of '?').
1386 - Finally, put the scheduling information and append a whitespace.
1388 As another example, if you don't want the time-of-day of entries in
1389 the prefix, you could use:
1391 (setq org-agenda-prefix-format \" %-11:c% s\")
1393 See also the variables `org-agenda-remove-times-when-in-prefix' and
1394 `org-agenda-remove-tags'.
1396 Custom commands can set this variable in the options section."
1397 :type '(choice
1398 (string :tag "General format")
1399 (list :greedy t :tag "View dependent"
1400 (cons (const agenda) (string :tag "Format"))
1401 (cons (const timeline) (string :tag "Format"))
1402 (cons (const todo) (string :tag "Format"))
1403 (cons (const tags) (string :tag "Format"))
1404 (cons (const search) (string :tag "Format"))))
1405 :group 'org-agenda-line-format)
1407 (defvar org-prefix-format-compiled nil
1408 "The compiled version of the most recently used prefix format.
1409 See the variable `org-agenda-prefix-format'.")
1411 (defcustom org-agenda-todo-keyword-format "%-1s"
1412 "Format for the TODO keyword in agenda lines.
1413 Set this to something like \"%-12s\" if you want all TODO keywords
1414 to occupy a fixed space in the agenda display."
1415 :group 'org-agenda-line-format
1416 :type 'string)
1418 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1419 "Text preceding timerange entries in the agenda view.
1420 This is a list with two strings. The first applies when the range
1421 is entirely on one day. The second applies if the range spans several days.
1422 The strings may have two \"%d\" format specifiers which will be filled
1423 with the sequence number of the days, and the total number of days in the
1424 range, respectively."
1425 :group 'org-agenda-line-format
1426 :type '(list
1427 (string :tag "Deadline today ")
1428 (choice :tag "Deadline relative"
1429 (string :tag "Format string")
1430 (function))))
1432 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1433 "Text preceding scheduled items in the agenda view.
1434 This is a list with two strings. The first applies when the item is
1435 scheduled on the current day. The second applies when it has been scheduled
1436 previously, it may contain a %d indicating that this is the nth time that
1437 this item is scheduled, due to automatic rescheduling of unfinished items
1438 for the following day. So this number is one larger than the number of days
1439 that passed since this item was scheduled first."
1440 :group 'org-agenda-line-format
1441 :type '(list
1442 (string :tag "Scheduled today ")
1443 (string :tag "Scheduled previously")))
1445 (defcustom org-agenda-inactive-leader "["
1446 "Text preceding item pulled into the agenda by inactive time stamps.
1447 These entries are added to the agenda when pressing \"[\"."
1448 :group 'org-agenda-line-format
1449 :type '(list
1450 (string :tag "Scheduled today ")
1451 (string :tag "Scheduled previously")))
1453 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1454 "Text preceding deadline items in the agenda view.
1455 This is a list with two strings. The first applies when the item has its
1456 deadline on the current day. The second applies when it is in the past or
1457 in the future, it may contain %d to capture how many days away the deadline
1458 is (was)."
1459 :group 'org-agenda-line-format
1460 :type '(list
1461 (string :tag "Deadline today ")
1462 (choice :tag "Deadline relative"
1463 (string :tag "Format string")
1464 (function))))
1466 (defcustom org-agenda-remove-times-when-in-prefix t
1467 "Non-nil means remove duplicate time specifications in agenda items.
1468 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1469 time-of-day specification in a headline or diary entry is extracted and
1470 placed into the prefix. If this option is non-nil, the original specification
1471 \(a timestamp or -range, or just a plain time(range) specification like
1472 11:30-4pm) will be removed for agenda display. This makes the agenda less
1473 cluttered.
1474 The option can be t or nil. It may also be the symbol `beg', indicating
1475 that the time should only be removed when it is located at the beginning of
1476 the headline/diary entry."
1477 :group 'org-agenda-line-format
1478 :type '(choice
1479 (const :tag "Always" t)
1480 (const :tag "Never" nil)
1481 (const :tag "When at beginning of entry" beg)))
1483 (defcustom org-agenda-remove-timeranges-from-blocks nil
1484 "Non-nil means remove time ranges specifications in agenda
1485 items that span on several days."
1486 :group 'org-agenda-line-format
1487 :type 'boolean)
1489 (defcustom org-agenda-default-appointment-duration nil
1490 "Default duration for appointments that only have a starting time.
1491 When nil, no duration is specified in such cases.
1492 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1493 :group 'org-agenda-line-format
1494 :type '(choice
1495 (integer :tag "Minutes")
1496 (const :tag "No default duration")))
1498 (defcustom org-agenda-show-inherited-tags t
1499 "Non-nil means show inherited tags in each agenda line."
1500 :group 'org-agenda-line-format
1501 :type 'boolean)
1503 (defcustom org-agenda-hide-tags-regexp nil
1504 "Regular expression used to filter away specific tags in agenda views.
1505 This means that these tags will be present, but not be shown in the agenda
1506 line. Secondary filtering will still work on the hidden tags.
1507 Nil means don't hide any tags."
1508 :group 'org-agenda-line-format
1509 :type '(choice
1510 (const :tag "Hide none" nil)
1511 (string :tag "Regexp ")))
1513 (defcustom org-agenda-remove-tags nil
1514 "Non-nil means remove the tags from the headline copy in the agenda.
1515 When this is the symbol `prefix', only remove tags when
1516 `org-agenda-prefix-format' contains a `%T' specifier."
1517 :group 'org-agenda-line-format
1518 :type '(choice
1519 (const :tag "Always" t)
1520 (const :tag "Never" nil)
1521 (const :tag "When prefix format contains %T" prefix)))
1523 (if (fboundp 'defvaralias)
1524 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1525 'org-agenda-remove-tags))
1527 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1528 "Shift tags in agenda items to this column.
1529 If this number is positive, it specifies the column. If it is negative,
1530 it means that the tags should be flushright to that column. For example,
1531 -80 works well for a normal 80 character screen."
1532 :group 'org-agenda-line-format
1533 :type 'integer)
1535 (if (fboundp 'defvaralias)
1536 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1538 (defcustom org-agenda-fontify-priorities 'cookies
1539 "Non-nil means highlight low and high priorities in agenda.
1540 When t, the highest priority entries are bold, lowest priority italic.
1541 However, settings in `org-priority-faces' will overrule these faces.
1542 When this variable is the symbol `cookies', only fontify the
1543 cookies, not the entire task.
1544 This may also be an association list of priority faces, whose
1545 keys are the character values of `org-highest-priority',
1546 `org-default-priority', and `org-lowest-priority' (the default values
1547 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1548 color as a string, or a list like `(:background \"Red\")'.
1549 If it is a color, the variable `org-faces-easy-properties'
1550 determines if it is a foreground or a background color."
1551 :group 'org-agenda-line-format
1552 :type '(choice
1553 (const :tag "Never" nil)
1554 (const :tag "Defaults" t)
1555 (const :tag "Cookies only" cookies)
1556 (repeat :tag "Specify"
1557 (list (character :tag "Priority" :value ?A)
1558 (choice :tag "Face "
1559 (string :tag "Color")
1560 (sexp :tag "Face"))))))
1562 (defcustom org-agenda-day-face-function nil
1563 "Function called to determine what face should be used to display a day.
1564 The only argument passed to that function is the day. It should
1565 returns a face, or nil if does not want to specify a face and let
1566 the normal rules apply."
1567 :group 'org-agenda-line-format
1568 :type 'function)
1570 (defcustom org-agenda-category-icon-alist nil
1571 "Alist of category icon to be displayed in agenda views.
1573 Each entry should have the following format:
1575 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1577 Where CATEGORY-REGEXP is a regexp matching the categories where
1578 the icon should be displayed.
1579 FILE-OR-DATA either a file path or a string containing image data.
1581 The other fields can be omited safely if not needed:
1582 TYPE indicates the image type.
1583 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1584 image data.
1585 PROPS are additional image attributes to assign to the image,
1586 like, e.g. `:ascent center'.
1588 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1590 If you want to set the display properties yourself, just put a
1591 list as second element:
1593 (CATEGORY-REGEXP (MY PROPERTY LIST))
1595 For example, to display a 16px horizontal space for Emacs
1596 category, you can use:
1598 (\"Emacs\" '(space . (:width (16))))"
1599 :group 'org-agenda-line-format
1600 :type '(alist :key-type (string :tag "Regexp matching category")
1601 :value-type (choice (list :tag "Icon"
1602 (string :tag "File or data")
1603 (symbol :tag "Type")
1604 (boolean :tag "Data?")
1605 (repeat :tag "Extra image properties" :inline t symbol))
1606 (list :tag "Display properties" sexp))))
1608 (defgroup org-agenda-column-view nil
1609 "Options concerning column view in the agenda."
1610 :tag "Org Agenda Column View"
1611 :group 'org-agenda)
1613 (defcustom org-agenda-columns-show-summaries t
1614 "Non-nil means show summaries for columns displayed in the agenda view."
1615 :group 'org-agenda-column-view
1616 :type 'boolean)
1618 (defcustom org-agenda-columns-remove-prefix-from-item t
1619 "Non-nil means remove the prefix from a headline for agenda column view.
1620 The special ITEM field in the columns format contains the current line, with
1621 all information shown in other columns (like the TODO state or a tag).
1622 When this variable is non-nil, also the agenda prefix will be removed from
1623 the content of the ITEM field, to make sure as much as possible of the
1624 headline can be shown in the limited width of the field."
1625 :group 'org-agenda
1626 :type 'boolean)
1628 (defcustom org-agenda-columns-compute-summary-properties t
1629 "Non-nil means recompute all summary properties before column view.
1630 When column view in the agenda is listing properties that have a summary
1631 operator, it can go to all relevant buffers and recompute the summaries
1632 there. This can mean overhead for the agenda column view, but is necessary
1633 to have thing up to date.
1634 As a special case, a CLOCKSUM property also makes sure that the clock
1635 computations are current."
1636 :group 'org-agenda-column-view
1637 :type 'boolean)
1639 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1640 "Non-nil means the duration of an appointment will add to day effort.
1641 The property to which appointment durations will be added is the one given
1642 in the option `org-effort-property'. If an appointment does not have
1643 an end time, `org-agenda-default-appointment-duration' will be used. If that
1644 is not set, an appointment without end time will not contribute to the time
1645 estimate."
1646 :group 'org-agenda-column-view
1647 :type 'boolean)
1649 (defcustom org-agenda-auto-exclude-function nil
1650 "A function called with a tag to decide if it is filtered on '/ RET'.
1651 The sole argument to the function, which is called once for each
1652 possible tag, is a string giving the name of the tag. The
1653 function should return either nil if the tag should be included
1654 as normal, or \"-<TAG>\" to exclude the tag.
1655 Note that for the purpose of tag filtering, only the lower-case version of
1656 all tags will be considered, so that this function will only ever see
1657 the lower-case version of all tags."
1658 :group 'org-agenda
1659 :type 'function)
1661 (eval-when-compile
1662 (require 'cl))
1663 (require 'org)
1665 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1666 "Execute BODY with point at location given by `org-hd-marker' property.
1667 If STRING is non-nil, the text property will be fetched from position 0
1668 in that string. If STRING is nil, it will be fetched from the beginning
1669 of the current line."
1670 `(let ((marker (get-text-property (if string 0 (point-at-bol))
1671 'org-hd-marker string)))
1672 (with-current-buffer (marker-buffer marker)
1673 (save-excursion
1674 (goto-char marker)
1675 ,@body))))
1677 (defun org-add-agenda-custom-command (entry)
1678 "Replace or add a command in `org-agenda-custom-commands'.
1679 This is mostly for hacking and trying a new command - once the command
1680 works you probably want to add it to `org-agenda-custom-commands' for good."
1681 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1682 (if ass
1683 (setcdr ass (cdr entry))
1684 (push entry org-agenda-custom-commands))))
1686 ;;; Define the Org-agenda-mode
1688 (defvar org-agenda-mode-map (make-sparse-keymap)
1689 "Keymap for `org-agenda-mode'.")
1690 (if (fboundp 'defvaralias)
1691 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1693 (defvar org-agenda-menu) ; defined later in this file.
1694 (defvar org-agenda-restrict) ; defined later in this file.
1695 (defvar org-agenda-follow-mode nil)
1696 (defvar org-agenda-entry-text-mode nil)
1697 (defvar org-agenda-clockreport-mode nil)
1698 (defvar org-agenda-show-log nil)
1699 (defvar org-agenda-redo-command nil)
1700 (defvar org-agenda-query-string nil)
1701 (defvar org-agenda-mode-hook nil
1702 "Hook for `org-agenda-mode', run after the mode is turned on.")
1703 (defvar org-agenda-type nil)
1704 (defvar org-agenda-force-single-file nil)
1705 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1707 (defun org-agenda-mode ()
1708 "Mode for time-sorted view on action items in Org-mode files.
1710 The following commands are available:
1712 \\{org-agenda-mode-map}"
1713 (interactive)
1714 (kill-all-local-variables)
1715 (setq org-agenda-undo-list nil
1716 org-agenda-pending-undo-list nil
1717 org-agenda-bulk-marked-entries nil)
1718 (setq major-mode 'org-agenda-mode)
1719 ;; Keep global-font-lock-mode from turning on font-lock-mode
1720 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1721 (setq mode-name "Org-Agenda")
1722 (use-local-map org-agenda-mode-map)
1723 (easy-menu-add org-agenda-menu)
1724 (if org-startup-truncated (setq truncate-lines t))
1725 (org-set-local 'line-move-visual nil)
1726 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1727 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1728 ;; Make sure properties are removed when copying text
1729 (when (boundp 'buffer-substring-filters)
1730 (org-set-local 'buffer-substring-filters
1731 (cons (lambda (x)
1732 (set-text-properties 0 (length x) nil x) x)
1733 buffer-substring-filters)))
1734 (unless org-agenda-keep-modes
1735 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1736 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1737 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1738 org-agenda-show-log org-agenda-start-with-log-mode))
1740 (easy-menu-change
1741 '("Agenda") "Agenda Files"
1742 (append
1743 (list
1744 (vector
1745 (if (get 'org-agenda-files 'org-restrict)
1746 "Restricted to single file"
1747 "Edit File List")
1748 '(org-edit-agenda-file-list)
1749 (not (get 'org-agenda-files 'org-restrict)))
1750 "--")
1751 (mapcar 'org-file-menu-entry (org-agenda-files))))
1752 (org-agenda-set-mode-name)
1753 (apply
1754 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1755 (list 'org-agenda-mode-hook)))
1757 (substitute-key-definition 'undo 'org-agenda-undo
1758 org-agenda-mode-map global-map)
1759 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1760 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1761 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1762 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1763 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1764 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1765 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1766 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1767 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1768 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
1769 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1770 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1771 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1772 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1773 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1774 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1775 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1776 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1777 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1778 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1779 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1780 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1781 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1782 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1783 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1784 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1785 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1786 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1787 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1788 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1789 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1790 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1791 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1792 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1793 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1794 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1795 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1796 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1797 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1798 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1799 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1800 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1801 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1802 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1803 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1805 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1806 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1807 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1808 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1809 (while l (org-defkey org-agenda-mode-map
1810 (int-to-string (pop l)) 'digit-argument)))
1812 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1813 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1814 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1815 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1816 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1817 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1818 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1819 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1820 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1821 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1822 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1823 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1824 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1825 'org-clock-modify-effort-estimate)
1826 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1827 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1828 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1829 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1830 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1831 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1832 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1833 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1834 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1835 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1836 (substitute-key-definition 'next-line 'org-agenda-next-line
1837 org-agenda-mode-map global-map)
1838 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1839 org-agenda-mode-map global-map)
1840 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1841 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1842 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1843 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1844 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1845 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1846 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1847 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1848 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1849 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1850 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1851 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1852 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1853 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1854 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1855 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1856 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1857 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1858 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1859 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1860 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1861 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1862 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1863 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1864 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1865 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1866 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1867 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1868 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1869 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1871 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1872 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1873 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1874 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1875 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1876 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1877 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1878 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1879 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1880 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1882 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1883 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1884 (when org-agenda-mouse-1-follows-link
1885 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1886 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1887 '("Agenda"
1888 ("Agenda Files")
1889 "--"
1890 ("Agenda Dates"
1891 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1892 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1893 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1894 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1895 "--"
1896 ("View"
1897 ["Day View" org-agenda-day-view
1898 :active (org-agenda-check-type nil 'agenda)
1899 :style radio :selected (eq org-agenda-current-span 'day)
1900 :keys "v d (or just d)"]
1901 ["Week View" org-agenda-week-view
1902 :active (org-agenda-check-type nil 'agenda)
1903 :style radio :selected (eq org-agenda-current-span 'week)
1904 :keys "v w (or just w)"]
1905 ["Month View" org-agenda-month-view
1906 :active (org-agenda-check-type nil 'agenda)
1907 :style radio :selected (eq org-agenda-current-span 'month)
1908 :keys "v m"]
1909 ["Year View" org-agenda-year-view
1910 :active (org-agenda-check-type nil 'agenda)
1911 :style radio :selected (eq org-agenda-current-span 'year)
1912 :keys "v y"]
1913 "--"
1914 ["Include Diary" org-agenda-toggle-diary
1915 :style toggle :selected org-agenda-include-diary
1916 :active (org-agenda-check-type nil 'agenda)]
1917 ["Include Deadlines" org-agenda-toggle-deadlines
1918 :style toggle :selected org-agenda-include-deadlines
1919 :active (org-agenda-check-type nil 'agenda)]
1920 ["Use Time Grid" org-agenda-toggle-time-grid
1921 :style toggle :selected org-agenda-use-time-grid
1922 :active (org-agenda-check-type nil 'agenda)]
1923 "--"
1924 ["Show clock report" org-agenda-clockreport-mode
1925 :style toggle :selected org-agenda-clockreport-mode
1926 :active (org-agenda-check-type nil 'agenda)]
1927 ["Show some entry text" org-agenda-entry-text-mode
1928 :style toggle :selected org-agenda-entry-text-mode
1929 :active t]
1930 "--"
1931 ["Show Logbook entries" org-agenda-log-mode
1932 :style toggle :selected org-agenda-show-log
1933 :active (org-agenda-check-type nil 'agenda 'timeline)
1934 :keys "v l (or just l)"]
1935 ["Include archived trees" org-agenda-archives-mode
1936 :style toggle :selected org-agenda-archives-mode :active t
1937 :keys "v a"]
1938 ["Include archive files" (org-agenda-archives-mode t)
1939 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1940 :keys "v A"]
1941 "--"
1942 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1943 ["Write view to file" org-write-agenda t]
1944 ["Rebuild buffer" org-agenda-redo t]
1945 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1946 "--"
1947 ["Show original entry" org-agenda-show t]
1948 ["Go To (other window)" org-agenda-goto t]
1949 ["Go To (this window)" org-agenda-switch-to t]
1950 ["Follow Mode" org-agenda-follow-mode
1951 :style toggle :selected org-agenda-follow-mode :active t]
1952 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1953 "--"
1954 ("TODO"
1955 ["Cycle TODO" org-agenda-todo t]
1956 ["Next TODO set" org-agenda-todo-nextset t]
1957 ["Previous TODO set" org-agenda-todo-previousset t]
1958 ["Add note" org-agenda-add-note t])
1959 ("Archive/Refile/Delete"
1960 ["Archive default" org-agenda-archive-default t]
1961 ["Archive default" org-agenda-archive-default-with-confirmation t]
1962 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1963 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1964 ["Archive subtree" org-agenda-archive t]
1965 "--"
1966 ["Refile" org-agenda-refile t]
1967 "--"
1968 ["Delete subtree" org-agenda-kill t])
1969 ("Bulk action"
1970 ["Mark entry" org-agenda-bulk-mark t]
1971 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
1972 ["Unmark entry" org-agenda-bulk-unmark t]
1973 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1974 ["Act on all marked" org-agenda-bulk-action t]
1975 "--"
1976 ("Tags and Properties"
1977 ["Show all Tags" org-agenda-show-tags t]
1978 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1979 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1980 "--"
1981 ["Column View" org-columns t])
1982 ("Deadline/Schedule"
1983 ["Schedule" org-agenda-schedule t]
1984 ["Set Deadline" org-agenda-deadline t]
1985 "--"
1986 ["Mark item" org-agenda-action :active t :keys "k m"]
1987 ["Show mark item" org-agenda-action :active t :keys "k v"]
1988 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1989 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1990 "--"
1991 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1992 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1993 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1994 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1995 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1996 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1997 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1998 ("Clock and Effort"
1999 ["Clock in" org-agenda-clock-in t]
2000 ["Clock out" org-agenda-clock-out t]
2001 ["Clock cancel" org-agenda-clock-cancel t]
2002 ["Goto running clock" org-clock-goto t]
2003 "--"
2004 ["Set Effort" org-agenda-set-effort t]
2005 ["Change clocked effort" org-clock-modify-effort-estimate
2006 (org-clock-is-active)])
2007 ("Priority"
2008 ["Set Priority" org-agenda-priority t]
2009 ["Increase Priority" org-agenda-priority-up t]
2010 ["Decrease Priority" org-agenda-priority-down t]
2011 ["Show Priority" org-agenda-show-priority t])
2012 ("Calendar/Diary"
2013 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2014 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2015 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2016 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2017 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2018 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2019 "--"
2020 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2021 "--"
2022 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2023 "--"
2024 ("MobileOrg"
2025 ["Push Files and Views" org-mobile-push t]
2026 ["Get Captured and Flagged" org-mobile-pull t]
2027 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2028 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2029 "--"
2030 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2031 "--"
2032 ["Quit" org-agenda-quit t]
2033 ["Exit and Release Buffers" org-agenda-exit t]
2036 ;;; Agenda undo
2038 (defvar org-agenda-allow-remote-undo t
2039 "Non-nil means allow remote undo from the agenda buffer.")
2040 (defvar org-agenda-undo-list nil
2041 "List of undoable operations in the agenda since last refresh.")
2042 (defvar org-agenda-undo-has-started-in nil
2043 "Buffers that have already seen `undo-start' in the current undo sequence.")
2044 (defvar org-agenda-pending-undo-list nil
2045 "In a series of undo commands, this is the list of remaining undo items.")
2047 (defun org-agenda-undo ()
2048 "Undo a remote editing step in the agenda.
2049 This undoes changes both in the agenda buffer and in the remote buffer
2050 that have been changed along."
2051 (interactive)
2052 (or org-agenda-allow-remote-undo
2053 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2054 (if (not (eq this-command last-command))
2055 (setq org-agenda-undo-has-started-in nil
2056 org-agenda-pending-undo-list org-agenda-undo-list))
2057 (if (not org-agenda-pending-undo-list)
2058 (error "No further undo information"))
2059 (let* ((entry (pop org-agenda-pending-undo-list))
2060 buf line cmd rembuf)
2061 (setq cmd (pop entry) line (pop entry))
2062 (setq rembuf (nth 2 entry))
2063 (org-with-remote-undo rembuf
2064 (while (bufferp (setq buf (pop entry)))
2065 (if (pop entry)
2066 (with-current-buffer buf
2067 (let ((last-undo-buffer buf)
2068 (inhibit-read-only t))
2069 (unless (memq buf org-agenda-undo-has-started-in)
2070 (push buf org-agenda-undo-has-started-in)
2071 (make-local-variable 'pending-undo-list)
2072 (undo-start))
2073 (while (and pending-undo-list
2074 (listp pending-undo-list)
2075 (not (car pending-undo-list)))
2076 (pop pending-undo-list))
2077 (undo-more 1))))))
2078 (org-goto-line line)
2079 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2081 (defun org-verify-change-for-undo (l1 l2)
2082 "Verify that a real change occurred between the undo lists L1 and L2."
2083 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2084 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2085 (not (eq l1 l2)))
2087 ;;; Agenda dispatch
2089 (defvar org-agenda-restrict nil)
2090 (defvar org-agenda-restrict-begin (make-marker))
2091 (defvar org-agenda-restrict-end (make-marker))
2092 (defvar org-agenda-last-dispatch-buffer nil)
2093 (defvar org-agenda-overriding-restriction nil)
2095 ;;;###autoload
2096 (defun org-agenda (&optional arg keys restriction)
2097 "Dispatch agenda commands to collect entries to the agenda buffer.
2098 Prompts for a command to execute. Any prefix arg will be passed
2099 on to the selected command. The default selections are:
2101 a Call `org-agenda-list' to display the agenda for current day or week.
2102 t Call `org-todo-list' to display the global todo list.
2103 T Call `org-todo-list' to display the global todo list, select only
2104 entries with a specific TODO keyword (the user gets a prompt).
2105 m Call `org-tags-view' to display headlines with tags matching
2106 a condition (the user is prompted for the condition).
2107 M Like `m', but select only TODO entries, no ordinary headlines.
2108 L Create a timeline for the current buffer.
2109 e Export views to associated files.
2110 s Search entries for keywords.
2111 / Multi occur across all agenda files and also files listed
2112 in `org-agenda-text-search-extra-files'.
2113 < Restrict agenda commands to buffer, subtree, or region.
2114 Press several times to get the desired effect.
2115 > Remove a previous restriction.
2116 # List \"stuck\" projects.
2117 ! Configure what \"stuck\" means.
2118 C Configure custom agenda commands.
2120 More commands can be added by configuring the variable
2121 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2122 searches can be pre-defined in this way.
2124 If the current buffer is in Org-mode and visiting a file, you can also
2125 first press `<' once to indicate that the agenda should be temporarily
2126 \(until the next use of \\[org-agenda]) restricted to the current file.
2127 Pressing `<' twice means to restrict to the current subtree or region
2128 \(if active)."
2129 (interactive "P")
2130 (catch 'exit
2131 (let* ((prefix-descriptions nil)
2132 (org-agenda-window-setup (if (equal (buffer-name)
2133 org-agenda-buffer-name)
2134 'current-window
2135 org-agenda-window-setup))
2136 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2137 (org-agenda-custom-commands
2138 ;; normalize different versions
2139 (delq nil
2140 (mapcar
2141 (lambda (x)
2142 (cond ((stringp (cdr x))
2143 (push x prefix-descriptions)
2144 nil)
2145 ((stringp (nth 1 x)) x)
2146 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2147 (t (cons (car x) (cons "" (cdr x))))))
2148 org-agenda-custom-commands)))
2149 (buf (current-buffer))
2150 (bfn (buffer-file-name (buffer-base-buffer)))
2151 entry key type match lprops ans)
2152 ;; Turn off restriction unless there is an overriding one,
2153 (unless org-agenda-overriding-restriction
2154 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2155 ;; There is a request to keep the file list in place
2156 (put 'org-agenda-files 'org-restrict nil))
2157 (setq org-agenda-restrict nil)
2158 (move-marker org-agenda-restrict-begin nil)
2159 (move-marker org-agenda-restrict-end nil))
2160 ;; Delete old local properties
2161 (put 'org-agenda-redo-command 'org-lprops nil)
2162 ;; Delete previously set last-arguments
2163 (put 'org-agenda-redo-command 'last-args nil)
2164 ;; Remember where this call originated
2165 (setq org-agenda-last-dispatch-buffer (current-buffer))
2166 (unless keys
2167 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2168 keys (car ans)
2169 restriction (cdr ans)))
2170 ;; Establish the restriction, if any
2171 (when (and (not org-agenda-overriding-restriction) restriction)
2172 (put 'org-agenda-files 'org-restrict (list bfn))
2173 (cond
2174 ((eq restriction 'region)
2175 (setq org-agenda-restrict t)
2176 (move-marker org-agenda-restrict-begin (region-beginning))
2177 (move-marker org-agenda-restrict-end (region-end)))
2178 ((eq restriction 'subtree)
2179 (save-excursion
2180 (setq org-agenda-restrict t)
2181 (org-back-to-heading t)
2182 (move-marker org-agenda-restrict-begin (point))
2183 (move-marker org-agenda-restrict-end
2184 (progn (org-end-of-subtree t)))))))
2186 ;; For example the todo list should not need it (but does...)
2187 (cond
2188 ((setq entry (assoc keys org-agenda-custom-commands))
2189 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2190 (progn
2191 (setq type (nth 2 entry) match (eval (nth 3 entry))
2192 lprops (nth 4 entry))
2193 (put 'org-agenda-redo-command 'org-lprops lprops)
2194 (cond
2195 ((eq type 'agenda)
2196 (org-let lprops '(org-agenda-list current-prefix-arg)))
2197 ((eq type 'alltodo)
2198 (org-let lprops '(org-todo-list current-prefix-arg)))
2199 ((eq type 'search)
2200 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2201 ((eq type 'stuck)
2202 (org-let lprops '(org-agenda-list-stuck-projects
2203 current-prefix-arg)))
2204 ((eq type 'tags)
2205 (org-let lprops '(org-tags-view current-prefix-arg match)))
2206 ((eq type 'tags-todo)
2207 (org-let lprops '(org-tags-view '(4) match)))
2208 ((eq type 'todo)
2209 (org-let lprops '(org-todo-list match)))
2210 ((eq type 'tags-tree)
2211 (org-check-for-org-mode)
2212 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2213 ((eq type 'todo-tree)
2214 (org-check-for-org-mode)
2215 (org-let lprops
2216 '(org-occur (concat "^" outline-regexp "[ \t]*"
2217 (regexp-quote match) "\\>"))))
2218 ((eq type 'occur-tree)
2219 (org-check-for-org-mode)
2220 (org-let lprops '(org-occur match)))
2221 ((functionp type)
2222 (org-let lprops '(funcall type match)))
2223 ((fboundp type)
2224 (org-let lprops '(funcall type match)))
2225 (t (error "Invalid custom agenda command type %s" type))))
2226 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2227 ((equal keys "C")
2228 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2229 (customize-variable 'org-agenda-custom-commands))
2230 ((equal keys "a") (call-interactively 'org-agenda-list))
2231 ((equal keys "s") (call-interactively 'org-search-view))
2232 ((equal keys "t") (call-interactively 'org-todo-list))
2233 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2234 ((equal keys "m") (call-interactively 'org-tags-view))
2235 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2236 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2237 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2238 (org-add-hook
2239 'post-command-hook
2240 (lambda ()
2241 (unless (current-message)
2242 (let* ((m (org-agenda-get-any-marker))
2243 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2244 (when note
2245 (message (concat
2246 "FLAGGING-NOTE ([?] for more info): "
2247 (org-add-props
2248 (replace-regexp-in-string
2249 "\\\\n" "//"
2250 (copy-sequence note))
2251 nil 'face 'org-warning)))))))
2252 t t))
2253 ((equal keys "L")
2254 (unless (org-mode-p)
2255 (error "This is not an Org-mode file"))
2256 (unless restriction
2257 (put 'org-agenda-files 'org-restrict (list bfn))
2258 (org-call-with-arg 'org-timeline arg)))
2259 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2260 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2261 ((equal keys "!") (customize-variable 'org-stuck-projects))
2262 (t (error "Invalid agenda key"))))))
2264 (defun org-agenda-append-agenda ()
2265 "Append another agenda view to the current one.
2266 This function allows interactive building of block agendas.
2267 Agenda views are separated by `org-agenda-block-separator'."
2268 (interactive)
2269 (unless (string= (buffer-name) org-agenda-buffer-name)
2270 (error "Can only append from within agenda buffer"))
2271 (let ((org-agenda-multi t))
2272 (org-agenda)
2273 (widen)))
2275 (defun org-agenda-normalize-custom-commands (cmds)
2276 (delq nil
2277 (mapcar
2278 (lambda (x)
2279 (cond ((stringp (cdr x)) nil)
2280 ((stringp (nth 1 x)) x)
2281 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2282 (t (cons (car x) (cons "" (cdr x))))))
2283 cmds)))
2285 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2286 "The user interface for selecting an agenda command."
2287 (catch 'exit
2288 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2289 (restrict-ok (and bfn (org-mode-p)))
2290 (region-p (org-region-active-p))
2291 (custom org-agenda-custom-commands)
2292 (selstring "")
2293 restriction second-time
2294 c entry key type match prefixes rmheader header-end custom1 desc
2295 line lines left right n n1)
2296 (save-window-excursion
2297 (delete-other-windows)
2298 (org-switch-to-buffer-other-window " *Agenda Commands*")
2299 (erase-buffer)
2300 (insert (eval-when-compile
2301 (let ((header
2303 Press key for an agenda command: < Buffer, subtree/region restriction
2304 -------------------------------- > Remove restriction
2305 a Agenda for current week or day e Export agenda views
2306 t List of all TODO entries T Entries with special TODO kwd
2307 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2308 L Timeline for current buffer # List stuck projects (!=configure)
2309 s Search for keywords C Configure custom agenda commands
2310 / Multi-occur ? Find :FLAGGED: entries
2312 (start 0))
2313 (while (string-match
2314 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2315 header start)
2316 (setq start (match-end 0))
2317 (add-text-properties (match-beginning 2) (match-end 2)
2318 '(face bold) header))
2319 header)))
2320 (setq header-end (move-marker (make-marker) (point)))
2321 (while t
2322 (setq custom1 custom)
2323 (when (eq rmheader t)
2324 (org-goto-line 1)
2325 (re-search-forward ":" nil t)
2326 (delete-region (match-end 0) (point-at-eol))
2327 (forward-char 1)
2328 (looking-at "-+")
2329 (delete-region (match-end 0) (point-at-eol))
2330 (move-marker header-end (match-end 0)))
2331 (goto-char header-end)
2332 (delete-region (point) (point-max))
2334 ;; Produce all the lines that describe custom commands and prefixes
2335 (setq lines nil)
2336 (while (setq entry (pop custom1))
2337 (setq key (car entry) desc (nth 1 entry)
2338 type (nth 2 entry)
2339 match (nth 3 entry))
2340 (if (> (length key) 1)
2341 (add-to-list 'prefixes (string-to-char key))
2342 (setq line
2343 (format
2344 "%-4s%-14s"
2345 (org-add-props (copy-sequence key)
2346 '(face bold))
2347 (cond
2348 ((string-match "\\S-" desc) desc)
2349 ((eq type 'agenda) "Agenda for current week or day")
2350 ((eq type 'alltodo) "List of all TODO entries")
2351 ((eq type 'search) "Word search")
2352 ((eq type 'stuck) "List of stuck projects")
2353 ((eq type 'todo) "TODO keyword")
2354 ((eq type 'tags) "Tags query")
2355 ((eq type 'tags-todo) "Tags (TODO)")
2356 ((eq type 'tags-tree) "Tags tree")
2357 ((eq type 'todo-tree) "TODO kwd tree")
2358 ((eq type 'occur-tree) "Occur tree")
2359 ((functionp type) (if (symbolp type)
2360 (symbol-name type)
2361 "Lambda expression"))
2362 (t "???"))))
2363 (if org-agenda-menu-show-matcher
2364 (setq line
2365 (concat line ": "
2366 (cond
2367 ((stringp match)
2368 (setq match (copy-sequence match))
2369 (org-add-props match nil 'face 'org-warning))
2370 (match
2371 (format "set of %d commands" (length match)))
2372 (t ""))))
2373 (if (org-string-nw-p match)
2374 (add-text-properties
2375 0 (length line) (list 'help-echo
2376 (concat "Matcher: "match)) line)))
2377 (push line lines)))
2378 (setq lines (nreverse lines))
2379 (when prefixes
2380 (mapc (lambda (x)
2381 (push
2382 (format "%s %s"
2383 (org-add-props (char-to-string x)
2384 nil 'face 'bold)
2385 (or (cdr (assoc (concat selstring
2386 (char-to-string x))
2387 prefix-descriptions))
2388 "Prefix key"))
2389 lines))
2390 prefixes))
2392 ;; Check if we should display in two columns
2393 (if org-agenda-menu-two-column
2394 (progn
2395 (setq n (length lines)
2396 n1 (+ (/ n 2) (mod n 2))
2397 right (nthcdr n1 lines)
2398 left (copy-sequence lines))
2399 (setcdr (nthcdr (1- n1) left) nil))
2400 (setq left lines right nil))
2401 (while left
2402 (insert "\n" (pop left))
2403 (when right
2404 (if (< (current-column) 40)
2405 (move-to-column 40 t)
2406 (insert " "))
2407 (insert (pop right))))
2409 ;; Make the window the right size
2410 (goto-char (point-min))
2411 (if second-time
2412 (if (not (pos-visible-in-window-p (point-max)))
2413 (org-fit-window-to-buffer))
2414 (setq second-time t)
2415 (org-fit-window-to-buffer))
2417 ;; Ask for selection
2418 (message "Press key for agenda command%s:"
2419 (if (or restrict-ok org-agenda-overriding-restriction)
2420 (if org-agenda-overriding-restriction
2421 " (restriction lock active)"
2422 (if restriction
2423 (format " (restricted to %s)" restriction)
2424 " (unrestricted)"))
2425 ""))
2426 (setq c (read-char-exclusive))
2427 (message "")
2428 (cond
2429 ((assoc (char-to-string c) custom)
2430 (setq selstring (concat selstring (char-to-string c)))
2431 (throw 'exit (cons selstring restriction)))
2432 ((memq c prefixes)
2433 (setq selstring (concat selstring (char-to-string c))
2434 prefixes nil
2435 rmheader (or rmheader t)
2436 custom (delq nil (mapcar
2437 (lambda (x)
2438 (if (or (= (length (car x)) 1)
2439 (/= (string-to-char (car x)) c))
2441 (cons (substring (car x) 1) (cdr x))))
2442 custom))))
2443 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2444 (message "Restriction is only possible in Org-mode buffers")
2445 (ding) (sit-for 1))
2446 ((eq c ?1)
2447 (org-agenda-remove-restriction-lock 'noupdate)
2448 (setq restriction 'buffer))
2449 ((eq c ?0)
2450 (org-agenda-remove-restriction-lock 'noupdate)
2451 (setq restriction (if region-p 'region 'subtree)))
2452 ((eq c ?<)
2453 (org-agenda-remove-restriction-lock 'noupdate)
2454 (setq restriction
2455 (cond
2456 ((eq restriction 'buffer)
2457 (if region-p 'region 'subtree))
2458 ((memq restriction '(subtree region))
2459 nil)
2460 (t 'buffer))))
2461 ((eq c ?>)
2462 (org-agenda-remove-restriction-lock 'noupdate)
2463 (setq restriction nil))
2464 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2465 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2466 ((and (> (length selstring) 0) (eq c ?\d))
2467 (delete-window)
2468 (org-agenda-get-restriction-and-command prefix-descriptions))
2470 ((equal c ?q) (error "Abort"))
2471 (t (error "Invalid key %c" c))))))))
2473 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2474 (defvar org-agenda-last-arguments nil
2475 "The arguments of the previous call to `org-agenda'.")
2476 (defun org-run-agenda-series (name series)
2477 (org-let (nth 1 series) '(org-prepare-agenda name))
2478 (let* ((org-agenda-multi t)
2479 (redo (list 'org-run-agenda-series name (list 'quote series)))
2480 (org-agenda-overriding-arguments
2481 (or org-agenda-overriding-arguments
2482 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2483 (get 'org-agenda-redo-command 'last-args))))
2484 (cmds (car series))
2485 (gprops (nth 1 series))
2486 match ;; The byte compiler incorrectly complains about this. Keep it!
2487 cmd type lprops)
2488 (while (setq cmd (pop cmds))
2489 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2490 (cond
2491 ((eq type 'agenda)
2492 (org-let2 gprops lprops
2493 '(call-interactively 'org-agenda-list)))
2494 ((eq type 'alltodo)
2495 (org-let2 gprops lprops
2496 '(call-interactively 'org-todo-list)))
2497 ((eq type 'search)
2498 (org-let2 gprops lprops
2499 '(org-search-view current-prefix-arg match nil)))
2500 ((eq type 'stuck)
2501 (org-let2 gprops lprops
2502 '(call-interactively 'org-agenda-list-stuck-projects)))
2503 ((eq type 'tags)
2504 (org-let2 gprops lprops
2505 '(org-tags-view current-prefix-arg match)))
2506 ((eq type 'tags-todo)
2507 (org-let2 gprops lprops
2508 '(org-tags-view '(4) match)))
2509 ((eq type 'todo)
2510 (org-let2 gprops lprops
2511 '(org-todo-list match)))
2512 ((fboundp type)
2513 (org-let2 gprops lprops
2514 '(funcall type match)))
2515 (t (error "Invalid type in command series"))))
2516 (widen)
2517 (setq org-agenda-redo-command redo)
2518 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2519 (goto-char (point-min)))
2520 (org-fit-agenda-window)
2521 (org-let (nth 1 series) '(org-finalize-agenda)))
2523 ;;;###autoload
2524 (defmacro org-batch-agenda (cmd-key &rest parameters)
2525 "Run an agenda command in batch mode and send the result to STDOUT.
2526 If CMD-KEY is a string of length 1, it is used as a key in
2527 `org-agenda-custom-commands' and triggers this command. If it is a
2528 longer string it is used as a tags/todo match string.
2529 Parameters are alternating variable names and values that will be bound
2530 before running the agenda command."
2531 (let (pars)
2532 (while parameters
2533 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2534 (if (> (length cmd-key) 2)
2535 (eval (list 'let (nreverse pars)
2536 (list 'org-tags-view nil cmd-key)))
2537 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2538 (set-buffer org-agenda-buffer-name)
2539 (princ (org-encode-for-stdout (buffer-string)))))
2541 ;(defun org-encode-for-stdout (string)
2542 ; (if (fboundp 'encode-coding-string)
2543 ; (encode-coding-string string buffer-file-coding-system)
2544 ; string))
2546 (defun org-encode-for-stdout (string)
2547 string)
2549 (defvar org-agenda-info nil)
2551 ;;;###autoload
2552 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2553 "Run an agenda command in batch mode and send the result to STDOUT.
2554 If CMD-KEY is a string of length 1, it is used as a key in
2555 `org-agenda-custom-commands' and triggers this command. If it is a
2556 longer string it is used as a tags/todo match string.
2557 Parameters are alternating variable names and values that will be bound
2558 before running the agenda command.
2560 The output gives a line for each selected agenda item. Each
2561 item is a list of comma-separated values, like this:
2563 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2565 category The category of the item
2566 head The headline, without TODO kwd, TAGS and PRIORITY
2567 type The type of the agenda entry, can be
2568 todo selected in TODO match
2569 tagsmatch selected in tags match
2570 diary imported from diary
2571 deadline a deadline on given date
2572 scheduled scheduled on given date
2573 timestamp entry has timestamp on given date
2574 closed entry was closed on given date
2575 upcoming-deadline warning about deadline
2576 past-scheduled forwarded scheduled item
2577 block entry has date block including g. date
2578 todo The todo keyword, if any
2579 tags All tags including inherited ones, separated by colons
2580 date The relevant date, like 2007-2-14
2581 time The time, like 15:00-16:50
2582 extra Sting with extra planning info
2583 priority-l The priority letter if any was given
2584 priority-n The computed numerical priority
2585 agenda-day The day in the agenda where this is listed"
2587 (let (pars)
2588 (while parameters
2589 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2590 (push (list 'org-agenda-remove-tags t) pars)
2591 (if (> (length cmd-key) 2)
2592 (eval (list 'let (nreverse pars)
2593 (list 'org-tags-view nil cmd-key)))
2594 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2595 (set-buffer org-agenda-buffer-name)
2596 (let* ((lines (org-split-string (buffer-string) "\n"))
2597 line)
2598 (while (setq line (pop lines))
2599 (catch 'next
2600 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2601 (setq org-agenda-info
2602 (org-fix-agenda-info (text-properties-at 0 line)))
2603 (princ
2604 (org-encode-for-stdout
2605 (mapconcat 'org-agenda-export-csv-mapper
2606 '(org-category txt type todo tags date time extra
2607 priority-letter priority agenda-day)
2608 ",")))
2609 (princ "\n"))))))
2611 (defun org-fix-agenda-info (props)
2612 "Make sure all properties on an agenda item have a canonical form.
2613 This ensures the export commands can easily use it."
2614 (let (tmp re)
2615 (when (setq tmp (plist-get props 'tags))
2616 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2617 (when (setq tmp (plist-get props 'date))
2618 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2619 (let ((calendar-date-display-form '(year "-" month "-" day)))
2620 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2622 (setq tmp (calendar-date-string tmp)))
2623 (setq props (plist-put props 'date tmp)))
2624 (when (setq tmp (plist-get props 'day))
2625 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2626 (let ((calendar-date-display-form '(year "-" month "-" day)))
2627 (setq tmp (calendar-date-string tmp)))
2628 (setq props (plist-put props 'day tmp))
2629 (setq props (plist-put props 'agenda-day tmp)))
2630 (when (setq tmp (plist-get props 'txt))
2631 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2632 (plist-put props 'priority-letter (match-string 1 tmp))
2633 (setq tmp (replace-match "" t t tmp)))
2634 (when (and (setq re (plist-get props 'org-todo-regexp))
2635 (setq re (concat "\\`\\.*" re " ?"))
2636 (string-match re tmp))
2637 (plist-put props 'todo (match-string 1 tmp))
2638 (setq tmp (replace-match "" t t tmp)))
2639 (plist-put props 'txt tmp)))
2640 props)
2642 (defun org-agenda-export-csv-mapper (prop)
2643 (let ((res (plist-get org-agenda-info prop)))
2644 (setq res
2645 (cond
2646 ((not res) "")
2647 ((stringp res) res)
2648 (t (prin1-to-string res))))
2649 (while (string-match "," res)
2650 (setq res (replace-match ";" t t res)))
2651 (org-trim res)))
2654 ;;;###autoload
2655 (defun org-store-agenda-views (&rest parameters)
2656 (interactive)
2657 (eval (list 'org-batch-store-agenda-views)))
2659 ;; FIXME, why is this a macro?????
2660 ;;;###autoload
2661 (defmacro org-batch-store-agenda-views (&rest parameters)
2662 "Run all custom agenda commands that have a file argument."
2663 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2664 (pop-up-frames nil)
2665 (dir default-directory)
2666 pars cmd thiscmdkey files opts cmd-or-set)
2667 (while parameters
2668 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2669 (setq pars (reverse pars))
2670 (save-window-excursion
2671 (while cmds
2672 (setq cmd (pop cmds)
2673 thiscmdkey (car cmd)
2674 cmd-or-set (nth 2 cmd)
2675 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2676 files (nth (if (listp cmd-or-set) 4 5) cmd))
2677 (if (stringp files) (setq files (list files)))
2678 (when files
2679 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2680 (list 'org-agenda nil thiscmdkey)))
2681 (set-buffer org-agenda-buffer-name)
2682 (while files
2683 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2684 (list 'org-write-agenda
2685 (expand-file-name (pop files) dir) nil t))))
2686 (and (get-buffer org-agenda-buffer-name)
2687 (kill-buffer org-agenda-buffer-name)))))))
2689 (defun org-agenda-mark-header-line (pos)
2690 "Mark the line at POS as an agenda structure header."
2691 (save-excursion
2692 (goto-char pos)
2693 (put-text-property (point-at-bol) (point-at-eol)
2694 'org-agenda-structural-header t)
2695 (when org-agenda-title-append
2696 (put-text-property (point-at-bol) (point-at-eol)
2697 'org-agenda-title-append org-agenda-title-append))))
2699 (defvar org-mobile-creating-agendas)
2700 (defun org-write-agenda (file &optional open nosettings)
2701 "Write the current buffer (an agenda view) as a file.
2702 Depending on the extension of the file name, plain text (.txt),
2703 HTML (.html or .htm) or Postscript (.ps) is produced.
2704 If the extension is .ics, run icalendar export over all files used
2705 to construct the agenda and limit the export to entries listed in the
2706 agenda now.
2707 With prefix argument OPEN, open the new file immediately.
2708 If NOSETTINGS is given, do not scope the settings of
2709 `org-agenda-exporter-settings' into the export commands. This is used when
2710 the settings have already been scoped and we do not wish to overrule other,
2711 higher priority settings."
2712 (interactive "FWrite agenda to file: \nP")
2713 (if (not (file-writable-p file))
2714 (error "Cannot write agenda to file %s" file))
2715 (org-let (if nosettings nil org-agenda-exporter-settings)
2716 '(save-excursion
2717 (save-window-excursion
2718 (org-agenda-mark-filtered-text)
2719 (let ((bs (copy-sequence (buffer-string))) beg)
2720 (org-agenda-unmark-filtered-text)
2721 (with-temp-buffer
2722 (rename-buffer "Agenda View" t)
2723 (set-buffer-modified-p nil)
2724 (insert bs)
2725 (org-agenda-remove-marked-text 'org-filtered)
2726 (while (setq beg (text-property-any (point-min) (point-max)
2727 'org-filtered t))
2728 (delete-region
2729 beg (or (next-single-property-change beg 'org-filtered)
2730 (point-max))))
2731 (run-hooks 'org-agenda-before-write-hook)
2732 (cond
2733 ((org-bound-and-true-p org-mobile-creating-agendas)
2734 (org-mobile-write-agenda-for-mobile file))
2735 ((string-match "\\.html?\\'" file)
2736 (require 'htmlize)
2737 (set-buffer (htmlize-buffer (current-buffer)))
2739 (when (and org-agenda-export-html-style
2740 (string-match "<style>" org-agenda-export-html-style))
2741 ;; replace <style> section with org-agenda-export-html-style
2742 (goto-char (point-min))
2743 (kill-region (- (search-forward "<style") 6)
2744 (search-forward "</style>"))
2745 (insert org-agenda-export-html-style))
2746 (write-file file)
2747 (kill-buffer (current-buffer))
2748 (message "HTML written to %s" file))
2749 ((string-match "\\.ps\\'" file)
2750 (require 'ps-print)
2751 (ps-print-buffer-with-faces file)
2752 (message "Postscript written to %s" file))
2753 ((string-match "\\.pdf\\'" file)
2754 (require 'ps-print)
2755 (ps-print-buffer-with-faces
2756 (concat (file-name-sans-extension file) ".ps"))
2757 (call-process "ps2pdf" nil nil nil
2758 (expand-file-name
2759 (concat (file-name-sans-extension file) ".ps"))
2760 (expand-file-name file))
2761 (delete-file (concat (file-name-sans-extension file) ".ps"))
2762 (message "PDF written to %s" file))
2763 ((string-match "\\.ics\\'" file)
2764 (require 'org-icalendar)
2765 (let ((org-agenda-marker-table
2766 (org-create-marker-find-array
2767 (org-agenda-collect-markers)))
2768 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2769 (org-combined-agenda-icalendar-file file))
2770 (apply 'org-export-icalendar 'combine
2771 (org-agenda-files nil 'ifmode))))
2773 (let ((bs (buffer-string)))
2774 (find-file file)
2775 (erase-buffer)
2776 (insert bs)
2777 (save-buffer 0)
2778 (kill-buffer (current-buffer))
2779 (message "Plain text written to %s" file))))))))
2780 (set-buffer org-agenda-buffer-name))
2781 (when open (org-open-file file)))
2783 (defvar org-agenda-filter-overlays nil)
2785 (defun org-agenda-mark-filtered-text ()
2786 "Mark all text hidden by filtering with a text property."
2787 (let ((inhibit-read-only t))
2788 (mapc
2789 (lambda (o)
2790 (when (equal (overlay-buffer o) (current-buffer))
2791 (put-text-property
2792 (overlay-start o) (overlay-end o)
2793 'org-filtered t)))
2794 org-agenda-filter-overlays)))
2796 (defun org-agenda-unmark-filtered-text ()
2797 "Remove the filtering text property."
2798 (let ((inhibit-read-only t))
2799 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2801 (defun org-agenda-remove-marked-text (property &optional value)
2802 "Delete all text marked with VALUE of PROPERTY.
2803 VALUE defaults to t."
2804 (let (beg)
2805 (setq value (or value t))
2806 (while (setq beg (text-property-any (point-min) (point-max)
2807 property value))
2808 (delete-region
2809 beg (or (next-single-property-change beg 'org-filtered)
2810 (point-max))))))
2812 (defun org-agenda-add-entry-text ()
2813 "Add entry text to agenda lines.
2814 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2815 entry text following headings shown in the agenda.
2816 Drawers will be excluded, also the line with scheduling/deadline info."
2817 (when (and (> org-agenda-add-entry-text-maxlines 0)
2818 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2819 (let (m txt)
2820 (goto-char (point-min))
2821 (while (not (eobp))
2822 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2823 (beginning-of-line 2)
2824 (setq txt (org-agenda-get-some-entry-text
2825 m org-agenda-add-entry-text-maxlines " > "))
2826 (end-of-line 1)
2827 (if (string-match "\\S-" txt)
2828 (insert "\n" txt)
2829 (or (eobp) (forward-char 1))))))))
2831 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2832 &rest keep)
2833 "Extract entry text from MARKER, at most N-LINES lines.
2834 This will ignore drawers etc, just get the text.
2835 If INDENT is given, prefix every line with this string. If KEEP is
2836 given, it is a list of symbols, defining stuff that should not be
2837 removed from the entry content. Currently only `planning' is allowed here."
2838 (let (txt drawer-re kwd-time-re ind)
2839 (save-excursion
2840 (with-current-buffer (marker-buffer marker)
2841 (if (not (org-mode-p))
2842 (setq txt "")
2843 (save-excursion
2844 (save-restriction
2845 (widen)
2846 (goto-char marker)
2847 (end-of-line 1)
2848 (setq txt (buffer-substring
2849 (min (1+ (point)) (point-max))
2850 (progn (outline-next-heading) (point)))
2851 drawer-re org-drawer-regexp
2852 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2853 ".*\n?"))
2854 (with-temp-buffer
2855 (insert txt)
2856 (when org-agenda-add-entry-text-descriptive-links
2857 (goto-char (point-min))
2858 (while (org-activate-bracket-links (point-max))
2859 (add-text-properties (match-beginning 0) (match-end 0)
2860 '(face org-link))))
2861 (goto-char (point-min))
2862 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2863 (set-text-properties (match-beginning 0) (match-end 0)
2864 nil))
2865 (goto-char (point-min))
2866 (while (re-search-forward drawer-re nil t)
2867 (delete-region
2868 (match-beginning 0)
2869 (progn (re-search-forward
2870 "^[ \t]*:END:.*\n?" nil 'move)
2871 (point))))
2872 (unless (member 'planning keep)
2873 (goto-char (point-min))
2874 (while (re-search-forward kwd-time-re nil t)
2875 (replace-match "")))
2876 (goto-char (point-min))
2877 (when org-agenda-entry-text-exclude-regexps
2878 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2879 (while (setq re (pop re-list))
2880 (goto-char (point-min))
2881 (while (re-search-forward re nil t)
2882 (replace-match "")))))
2883 (goto-char (point-max))
2884 (skip-chars-backward " \t\n")
2885 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2887 ;; find and remove min common indentation
2888 (goto-char (point-min))
2889 (untabify (point-min) (point-max))
2890 (setq ind (org-get-indentation))
2891 (while (not (eobp))
2892 (unless (looking-at "[ \t]*$")
2893 (setq ind (min ind (org-get-indentation))))
2894 (beginning-of-line 2))
2895 (goto-char (point-min))
2896 (while (not (eobp))
2897 (unless (looking-at "[ \t]*$")
2898 (move-to-column ind)
2899 (delete-region (point-at-bol) (point)))
2900 (beginning-of-line 2))
2902 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2904 (goto-char (point-min))
2905 (when indent
2906 (while (and (not (eobp)) (re-search-forward "^" nil t))
2907 (replace-match indent t t)))
2908 (goto-char (point-min))
2909 (while (looking-at "[ \t]*\n") (replace-match ""))
2910 (goto-char (point-max))
2911 (when (> (org-current-line)
2912 n-lines)
2913 (org-goto-line (1+ n-lines))
2914 (backward-char 1))
2915 (setq txt (buffer-substring (point-min) (point)))))))))
2916 txt))
2918 (defun org-agenda-collect-markers ()
2919 "Collect the markers pointing to entries in the agenda buffer."
2920 (let (m markers)
2921 (save-excursion
2922 (goto-char (point-min))
2923 (while (not (eobp))
2924 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2925 (org-get-at-bol 'org-marker)))
2926 (push m markers))
2927 (beginning-of-line 2)))
2928 (nreverse markers)))
2930 (defun org-create-marker-find-array (marker-list)
2931 "Create a alist of files names with all marker positions in that file."
2932 (let (f tbl m a p)
2933 (while (setq m (pop marker-list))
2934 (setq p (marker-position m)
2935 f (buffer-file-name (or (buffer-base-buffer
2936 (marker-buffer m))
2937 (marker-buffer m))))
2938 (if (setq a (assoc f tbl))
2939 (push (marker-position m) (cdr a))
2940 (push (list f p) tbl)))
2941 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2942 tbl)))
2944 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2945 (defun org-check-agenda-marker-table ()
2946 "Check of the current entry is on the marker list."
2947 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2949 (and (setq a (assoc file org-agenda-marker-table))
2950 (save-match-data
2951 (save-excursion
2952 (org-back-to-heading t)
2953 (member (point) (cdr a)))))))
2955 (defun org-check-for-org-mode ()
2956 "Make sure current buffer is in org-mode. Error if not."
2957 (or (org-mode-p)
2958 (error "Cannot execute org-mode agenda command on buffer in %s"
2959 major-mode)))
2961 (defun org-fit-agenda-window ()
2962 "Fit the window to the buffer size."
2963 (and (memq org-agenda-window-setup '(reorganize-frame))
2964 (fboundp 'fit-window-to-buffer)
2965 (org-fit-window-to-buffer
2967 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2968 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2970 ;;; Agenda prepare and finalize
2972 (defvar org-agenda-multi nil) ; dynamically scoped
2973 (defvar org-agenda-buffer-name "*Org Agenda*")
2974 (defvar org-pre-agenda-window-conf nil)
2975 (defvar org-agenda-columns-active nil)
2976 (defvar org-agenda-name nil)
2977 (defvar org-agenda-filter nil)
2978 (defvar org-agenda-filter-while-redo nil)
2979 (defvar org-agenda-filter-preset nil
2980 "A preset of the tags filter used for secondary agenda filtering.
2981 This must be a list of strings, each string must be a single tag preceded
2982 by \"+\" or \"-\".
2983 This variable should not be set directly, but agenda custom commands can
2984 bind it in the options section. The preset filter is a global property of
2985 the entire agenda view. In a block agenda, it will not work reliably to
2986 define a filter for one of the individual blocks. You need to set it in
2987 the global options and expect it to be applied to the entire view.")
2989 (defun org-prepare-agenda (&optional name)
2990 (setq org-todo-keywords-for-agenda nil)
2991 (setq org-done-keywords-for-agenda nil)
2992 (setq org-drawers-for-agenda nil)
2993 (unless org-agenda-persistent-filter
2994 (setq org-agenda-filter nil))
2995 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2996 (if org-agenda-multi
2997 (progn
2998 (setq buffer-read-only nil)
2999 (goto-char (point-max))
3000 (unless (or (bobp) org-agenda-compact-blocks)
3001 (insert "\n"
3002 (if (stringp org-agenda-block-separator)
3003 org-agenda-block-separator
3004 (make-string (window-width) org-agenda-block-separator))
3005 "\n"))
3006 (narrow-to-region (point) (point-max)))
3007 (org-agenda-reset-markers)
3008 (setq org-agenda-contributing-files nil)
3009 (setq org-agenda-columns-active nil)
3010 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3011 (setq org-todo-keywords-for-agenda
3012 (org-uniquify org-todo-keywords-for-agenda))
3013 (setq org-done-keywords-for-agenda
3014 (org-uniquify org-done-keywords-for-agenda))
3015 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3016 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
3017 (awin (get-buffer-window abuf)))
3018 (cond
3019 ((equal (current-buffer) abuf) nil)
3020 (awin (select-window awin))
3021 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3022 ((equal org-agenda-window-setup 'current-window)
3023 (switch-to-buffer abuf))
3024 ((equal org-agenda-window-setup 'other-window)
3025 (org-switch-to-buffer-other-window abuf))
3026 ((equal org-agenda-window-setup 'other-frame)
3027 (switch-to-buffer-other-frame abuf))
3028 ((equal org-agenda-window-setup 'reorganize-frame)
3029 (delete-other-windows)
3030 (org-switch-to-buffer-other-window abuf)))
3031 ;; additional test in case agenda is invoked from within agenda
3032 ;; buffer via elisp link
3033 (unless (equal (current-buffer) abuf)
3034 (switch-to-buffer abuf)))
3035 (setq buffer-read-only nil)
3036 (let ((inhibit-read-only t)) (erase-buffer))
3037 (org-agenda-mode)
3038 (and name (not org-agenda-name)
3039 (org-set-local 'org-agenda-name name)))
3040 (setq buffer-read-only nil))
3042 (defun org-finalize-agenda ()
3043 "Finishing touch for the agenda buffer, called just before displaying it."
3044 (unless org-agenda-multi
3045 (save-excursion
3046 (let ((inhibit-read-only t))
3047 (goto-char (point-min))
3048 (while (org-activate-bracket-links (point-max))
3049 (add-text-properties (match-beginning 0) (match-end 0)
3050 '(face org-link)))
3051 (org-agenda-align-tags)
3052 (unless org-agenda-with-colors
3053 (remove-text-properties (point-min) (point-max) '(face nil))))
3054 (if (and (boundp 'org-agenda-overriding-columns-format)
3055 org-agenda-overriding-columns-format)
3056 (org-set-local 'org-agenda-overriding-columns-format
3057 org-agenda-overriding-columns-format))
3058 (if (and (boundp 'org-agenda-view-columns-initially)
3059 org-agenda-view-columns-initially)
3060 (org-agenda-columns))
3061 (when org-agenda-fontify-priorities
3062 (org-agenda-fontify-priorities))
3063 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3064 (org-agenda-dim-blocked-tasks))
3065 (org-agenda-mark-clocking-task)
3066 (when org-agenda-entry-text-mode
3067 (org-agenda-entry-text-hide)
3068 (org-agenda-entry-text-show))
3069 (if (functionp 'org-habit-insert-consistency-graphs)
3070 (org-habit-insert-consistency-graphs))
3071 (run-hooks 'org-finalize-agenda-hook)
3072 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3073 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3074 (org-agenda-filter-apply org-agenda-filter))
3077 (defun org-agenda-mark-clocking-task ()
3078 "Mark the current clock entry in the agenda if it is present."
3079 (mapc (lambda (o)
3080 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3081 (delete-overlay o)))
3082 (overlays-in (point-min) (point-max)))
3083 (when (marker-buffer org-clock-hd-marker)
3084 (save-excursion
3085 (goto-char (point-min))
3086 (let (s ov)
3087 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3088 (goto-char s)
3089 (when (equal (org-get-at-bol 'org-hd-marker)
3090 org-clock-hd-marker)
3091 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3092 (overlay-put ov 'type 'org-agenda-clocking)
3093 (overlay-put ov 'face 'org-agenda-clocking)
3094 (overlay-put ov 'help-echo
3095 "The clock is running in this item")))))))
3097 (defun org-agenda-fontify-priorities ()
3098 "Make highest priority lines bold, and lowest italic."
3099 (interactive)
3100 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3101 (delete-overlay o)))
3102 (overlays-in (point-min) (point-max)))
3103 (save-excursion
3104 (let ((inhibit-read-only t)
3105 b e p ov h l)
3106 (goto-char (point-min))
3107 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3108 (setq h (or (get-char-property (point) 'org-highest-priority)
3109 org-highest-priority)
3110 l (or (get-char-property (point) 'org-lowest-priority)
3111 org-lowest-priority)
3112 p (string-to-char (match-string 1))
3113 b (match-beginning 0)
3114 e (if (eq org-agenda-fontify-priorities 'cookies)
3115 (match-end 0)
3116 (point-at-eol))
3117 ov (make-overlay b e))
3118 (overlay-put
3119 ov 'face
3120 (cond ((org-face-from-face-or-color
3121 'priority nil
3122 (cdr (assoc p org-priority-faces))))
3123 ((and (listp org-agenda-fontify-priorities)
3124 (org-face-from-face-or-color
3125 'priority nil
3126 (cdr (assoc p org-agenda-fontify-priorities)))))
3127 ((equal p l) 'italic)
3128 ((equal p h) 'bold)))
3129 (overlay-put ov 'org-type 'org-priority)))))
3131 (defun org-agenda-dim-blocked-tasks ()
3132 "Dim currently blocked TODO's in the agenda display."
3133 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3134 (delete-overlay o)))
3135 (overlays-in (point-min) (point-max)))
3136 (save-excursion
3137 (let ((inhibit-read-only t)
3138 (org-depend-tag-blocked nil)
3139 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3140 org-blocked-by-checkboxes
3141 invis1 b e p ov h l)
3142 (goto-char (point-min))
3143 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3144 (and pos (goto-char (1+ pos))))
3145 (setq org-blocked-by-checkboxes nil invis1 invis)
3146 (let ((marker (org-get-at-bol 'org-hd-marker)))
3147 (when (and marker
3148 (not (with-current-buffer (marker-buffer marker)
3149 (save-excursion
3150 (goto-char marker)
3151 (if (org-entry-get nil "NOBLOCKING")
3152 t ;; Never block this entry
3153 (run-hook-with-args-until-failure
3154 'org-blocker-hook
3155 (list :type 'todo-state-change
3156 :position marker
3157 :from 'todo
3158 :to 'done)))))))
3159 (if org-blocked-by-checkboxes (setq invis1 nil))
3160 (setq b (if invis1
3161 (max (point-min) (1- (point-at-bol)))
3162 (point-at-bol))
3163 e (point-at-eol)
3164 ov (make-overlay b e))
3165 (if invis1
3166 (overlay-put ov 'invisible t)
3167 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3168 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3170 (defvar org-agenda-skip-function nil
3171 "Function to be called at each match during agenda construction.
3172 If this function returns nil, the current match should not be skipped.
3173 Otherwise, the function must return a position from where the search
3174 should be continued.
3175 This may also be a Lisp form, it will be evaluated.
3176 Never set this variable using `setq' or so, because then it will apply
3177 to all future agenda commands. If you do want a global skipping condition,
3178 use the option `org-agenda-skip-function-global' instead.
3179 The correct usage for `org-agenda-skip-function' is to bind it with
3180 `let' to scope it dynamically into the agenda-constructing command.
3181 A good way to set it is through options in `org-agenda-custom-commands'.")
3183 (defun org-agenda-skip ()
3184 "Throw to `:skip' in places that should be skipped.
3185 Also moves point to the end of the skipped region, so that search can
3186 continue from there."
3187 (let ((p (point-at-bol)) to)
3188 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3189 (get-text-property p :org-archived)
3190 (org-end-of-subtree t)
3191 (throw :skip t))
3192 (and org-agenda-skip-comment-trees
3193 (get-text-property p :org-comment)
3194 (org-end-of-subtree t)
3195 (throw :skip t))
3196 (if (equal (char-after p) ?#) (throw :skip t))
3197 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3198 (org-agenda-skip-eval org-agenda-skip-function)))
3199 (goto-char to)
3200 (throw :skip t))))
3202 (defun org-agenda-skip-eval (form)
3203 "If FORM is a function or a list, call (or eval) is and return result.
3204 `save-excursion' and `save-match-data' are wrapped around the call, so point
3205 and match data are returned to the previous state no matter what these
3206 functions do."
3207 (let (fp)
3208 (and form
3209 (or (setq fp (functionp form))
3210 (consp form))
3211 (save-excursion
3212 (save-match-data
3213 (if fp
3214 (funcall form)
3215 (eval form)))))))
3217 (defvar org-agenda-markers nil
3218 "List of all currently active markers created by `org-agenda'.")
3219 (defvar org-agenda-last-marker-time (org-float-time)
3220 "Creation time of the last agenda marker.")
3222 (defun org-agenda-new-marker (&optional pos)
3223 "Return a new agenda marker.
3224 Org-mode keeps a list of these markers and resets them when they are
3225 no longer in use."
3226 (let ((m (copy-marker (or pos (point)))))
3227 (setq org-agenda-last-marker-time (org-float-time))
3228 (push m org-agenda-markers)
3231 (defun org-agenda-reset-markers ()
3232 "Reset markers created by `org-agenda'."
3233 (while org-agenda-markers
3234 (move-marker (pop org-agenda-markers) nil)))
3236 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3237 "Save relative positions of markers in region."
3238 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3239 org-agenda-markers))
3241 ;;; Entry text mode
3243 (defun org-agenda-entry-text-show-here ()
3244 "Add some text from the entry as context to the current line."
3245 (let (m txt o)
3246 (setq m (org-get-at-bol 'org-hd-marker))
3247 (unless (marker-buffer m)
3248 (error "No marker points to an entry here"))
3249 (setq txt (concat "\n" (org-no-properties
3250 (org-agenda-get-some-entry-text
3251 m org-agenda-entry-text-maxlines " > "))))
3252 (when (string-match "\\S-" txt)
3253 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3254 (overlay-put o 'evaporate t)
3255 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3256 (overlay-put o 'after-string txt))))
3258 (defun org-agenda-entry-text-show ()
3259 "Add entry context for all agenda lines."
3260 (interactive)
3261 (save-excursion
3262 (goto-char (point-max))
3263 (beginning-of-line 1)
3264 (while (not (bobp))
3265 (when (org-get-at-bol 'org-hd-marker)
3266 (org-agenda-entry-text-show-here))
3267 (beginning-of-line 0))))
3269 (defun org-agenda-entry-text-hide ()
3270 "Remove any shown entry context."
3271 (delq nil
3272 (mapcar (lambda (o)
3273 (if (eq (overlay-get o 'org-overlay-type)
3274 'agenda-entry-content)
3275 (progn (delete-overlay o) t)))
3276 (overlays-in (point-min) (point-max)))))
3278 (defun org-agenda-get-day-face (date)
3279 "Return the face DATE should be displayed with."
3280 (or (and (functionp org-agenda-day-face-function)
3281 (funcall org-agenda-day-face-function date))
3282 (cond ((org-agenda-todayp date)
3283 'org-agenda-date-today)
3284 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3285 'org-agenda-date-weekend)
3286 (t 'org-agenda-date))))
3288 ;;; Agenda timeline
3290 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3292 (defun org-timeline (&optional include-all)
3293 "Show a time-sorted view of the entries in the current org file.
3294 Only entries with a time stamp of today or later will be listed. With
3295 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3296 under the current date.
3297 If the buffer contains an active region, only check the region for
3298 dates."
3299 (interactive "P")
3300 (org-compile-prefix-format 'timeline)
3301 (org-set-sorting-strategy 'timeline)
3302 (let* ((dopast t)
3303 (dotodo include-all)
3304 (doclosed org-agenda-show-log)
3305 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3306 (current-buffer))))
3307 (date (calendar-current-date))
3308 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3309 (end (if (org-region-active-p) (region-end) (point-max)))
3310 (day-numbers (org-get-all-dates beg end 'no-ranges
3311 t doclosed ; always include today
3312 org-timeline-show-empty-dates))
3313 (org-deadline-warning-days 0)
3314 (org-agenda-only-exact-dates t)
3315 (today (org-today))
3316 (past t)
3317 args
3318 s e rtn d emptyp)
3319 (setq org-agenda-redo-command
3320 (list 'progn
3321 (list 'org-switch-to-buffer-other-window (current-buffer))
3322 (list 'org-timeline (list 'quote include-all))))
3323 (if (not dopast)
3324 ;; Remove past dates from the list of dates.
3325 (setq day-numbers (delq nil (mapcar (lambda(x)
3326 (if (>= x today) x nil))
3327 day-numbers))))
3328 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3329 (if doclosed (push :closed args))
3330 (push :timestamp args)
3331 (push :deadline args)
3332 (push :scheduled args)
3333 (push :sexp args)
3334 (if dotodo (push :todo args))
3335 (insert "Timeline of file " entry "\n")
3336 (add-text-properties (point-min) (point)
3337 (list 'face 'org-agenda-structure))
3338 (org-agenda-mark-header-line (point-min))
3339 (while (setq d (pop day-numbers))
3340 (if (and (listp d) (eq (car d) :omitted))
3341 (progn
3342 (setq s (point))
3343 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3344 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3345 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3346 (if (and (>= d today)
3347 dopast
3348 past)
3349 (progn
3350 (setq past nil)
3351 (insert (make-string 79 ?-) "\n")))
3352 (setq date (calendar-gregorian-from-absolute d))
3353 (setq s (point))
3354 (setq rtn (and (not emptyp)
3355 (apply 'org-agenda-get-day-entries entry
3356 date args)))
3357 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3358 (progn
3359 (insert
3360 (if (stringp org-agenda-format-date)
3361 (format-time-string org-agenda-format-date
3362 (org-time-from-absolute date))
3363 (funcall org-agenda-format-date date))
3364 "\n")
3365 (put-text-property s (1- (point)) 'face
3366 (org-agenda-get-day-face date))
3367 (put-text-property s (1- (point)) 'org-date-line t)
3368 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3369 (if (equal d today)
3370 (put-text-property s (1- (point)) 'org-today t))
3371 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3372 (put-text-property s (1- (point)) 'day d)))))
3373 (goto-char (point-min))
3374 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3375 (point-min)))
3376 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3377 (org-finalize-agenda)
3378 (setq buffer-read-only t)))
3380 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3381 "Return a list of all relevant day numbers from BEG to END buffer positions.
3382 If NO-RANGES is non-nil, include only the start and end dates of a range,
3383 not every single day in the range. If FORCE-TODAY is non-nil, make
3384 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3385 inactive time stamps (those in square brackets) are included.
3386 When EMPTY is non-nil, also include days without any entries."
3387 (let ((re (concat
3388 (if pre-re pre-re "")
3389 (if inactive org-ts-regexp-both org-ts-regexp)))
3390 dates dates1 date day day1 day2 ts1 ts2)
3391 (if force-today
3392 (setq dates (list (org-today))))
3393 (save-excursion
3394 (goto-char beg)
3395 (while (re-search-forward re end t)
3396 (setq day (time-to-days (org-time-string-to-time
3397 (substring (match-string 1) 0 10))))
3398 (or (memq day dates) (push day dates)))
3399 (unless no-ranges
3400 (goto-char beg)
3401 (while (re-search-forward org-tr-regexp end t)
3402 (setq ts1 (substring (match-string 1) 0 10)
3403 ts2 (substring (match-string 2) 0 10)
3404 day1 (time-to-days (org-time-string-to-time ts1))
3405 day2 (time-to-days (org-time-string-to-time ts2)))
3406 (while (< (setq day1 (1+ day1)) day2)
3407 (or (memq day1 dates) (push day1 dates)))))
3408 (setq dates (sort dates '<))
3409 (when empty
3410 (while (setq day (pop dates))
3411 (setq day2 (car dates))
3412 (push day dates1)
3413 (when (and day2 empty)
3414 (if (or (eq empty t)
3415 (and (numberp empty) (<= (- day2 day) empty)))
3416 (while (< (setq day (1+ day)) day2)
3417 (push (list day) dates1))
3418 (push (cons :omitted (- day2 day)) dates1))))
3419 (setq dates (nreverse dates1)))
3420 dates)))
3422 ;;; Agenda Daily/Weekly
3424 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3425 "Custom commands can set this variable in the options section.")
3426 (defvar org-starting-day nil) ; local variable in the agenda buffer
3427 (defvar org-agenda-current-span nil
3428 "The current span used in the agenda view.") ; local variable in the agenda buffer
3429 (defvar org-include-all-loc nil) ; local variable
3431 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3432 "List of types searched for when creating the daily/weekly agenda.
3433 This variable is a list of symbols that controls the types of
3434 items that appear in the daily/weekly agenda. Allowed symbols in this
3435 list are are
3437 :timestamp List items containing a date stamp or date range matching
3438 the selected date. This includes sexp entries in
3439 angular brackets.
3441 :sexp List entries resulting from plain diary-like sexps.
3443 :deadline List deadline due on that date. When the date is today,
3444 also list any deadlines past due, or due within
3445 `org-deadline-warning-days'. `:deadline' must appear before
3446 `:scheduled' if the setting of
3447 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3448 any effect.
3450 :scheduled List all items which are scheduled for the given date.
3451 The diary for *today* also contains items which were
3452 scheduled earlier and are not yet marked DONE.
3454 By default, all four types are turned on.
3456 Never set this variable globally using `setq', because then it
3457 will apply to all future agenda commands. Instead, bind it with
3458 `let' to scope it dynamically into the the agenda-constructing
3459 command. A good way to set it is through options in
3460 `org-agenda-custom-commands'. For a more flexible (though
3461 somewhat less efficient) way of determining what is included in
3462 the daily/weekly agenda, see `org-agenda-skip-function'.")
3464 ;;;###autoload
3465 (defun org-agenda-list (&optional include-all start-day span)
3466 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3467 The view will be for the current day or week, but from the overview buffer
3468 you will be able to go to other days/weeks.
3470 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3471 all unfinished TODO items will also be shown, before the agenda.
3472 This feature is considered obsolete, please use the TODO list or a block
3473 agenda instead.
3475 With a numeric prefix argument in an interactive call, the agenda will
3476 span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
3477 the number of days. SPAN defaults to `org-agenda-span'.
3479 START-DAY defaults to TODAY, or to the most recent match for the weekday
3480 given in `org-agenda-start-on-weekday'."
3481 (interactive "P")
3482 (if (and (integerp include-all) (> include-all 0))
3483 (setq span include-all include-all nil))
3484 (setq start-day (or start-day org-agenda-start-day))
3485 (if org-agenda-overriding-arguments
3486 (setq include-all (car org-agenda-overriding-arguments)
3487 start-day (nth 1 org-agenda-overriding-arguments)
3488 span (nth 2 org-agenda-overriding-arguments)))
3489 (if (stringp start-day)
3490 ;; Convert to an absolute day number
3491 (setq start-day (time-to-days (org-read-date nil t start-day))))
3492 (setq org-agenda-last-arguments (list include-all start-day span))
3493 (org-compile-prefix-format 'agenda)
3494 (org-set-sorting-strategy 'agenda)
3495 (let* ((span (org-agenda-ndays-to-span (or span
3496 org-agenda-current-span
3497 org-agenda-ndays
3498 org-agenda-span)))
3499 (today (org-today))
3500 (sd (or start-day today))
3501 (ndays (org-agenda-span-to-ndays span sd))
3502 (org-agenda-start-on-weekday
3503 (if (eq ndays 7)
3504 org-agenda-start-on-weekday))
3505 (thefiles (org-agenda-files nil 'ifmode))
3506 (files thefiles)
3507 (start (if (or (null org-agenda-start-on-weekday)
3508 (< ndays 7))
3510 (let* ((nt (calendar-day-of-week
3511 (calendar-gregorian-from-absolute sd)))
3512 (n1 org-agenda-start-on-weekday)
3513 (d (- nt n1)))
3514 (- sd (+ (if (< d 0) 7 0) d)))))
3515 (day-numbers (list start))
3516 (day-cnt 0)
3517 (inhibit-redisplay (not debug-on-error))
3518 s e rtn rtnall file date d start-pos end-pos todayp
3519 clocktable-start clocktable-end filter)
3520 (setq org-agenda-redo-command
3521 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3522 (dotimes (n (1- ndays))
3523 (push (1+ (car day-numbers)) day-numbers))
3524 (setq day-numbers (nreverse day-numbers))
3525 (setq clocktable-start (car day-numbers)
3526 clocktable-end (1+ (or (org-last day-numbers) 0)))
3527 (org-prepare-agenda "Day/Week")
3528 (org-set-local 'org-starting-day (car day-numbers))
3529 (org-set-local 'org-include-all-loc include-all)
3530 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3531 (when (and (or include-all org-agenda-include-all-todo)
3532 (member today day-numbers))
3533 (setq files thefiles
3534 rtnall nil)
3535 (while (setq file (pop files))
3536 (catch 'nextfile
3537 (org-check-agenda-file file)
3538 (setq date (calendar-gregorian-from-absolute today)
3539 rtn (org-agenda-get-day-entries
3540 file date :todo))
3541 (setq rtnall (append rtnall rtn))))
3542 (when rtnall
3543 (insert "All currently open TODO items:\n")
3544 (add-text-properties (point-min) (1- (point))
3545 (list 'face 'org-agenda-structure
3546 'short-heading "All TODO items"))
3547 (org-agenda-mark-header-line (point-min))
3548 (insert (org-finalize-agenda-entries rtnall) "\n")))
3549 (unless org-agenda-compact-blocks
3550 (let* ((d1 (car day-numbers))
3551 (d2 (org-last day-numbers))
3552 (w1 (org-days-to-iso-week d1))
3553 (w2 (org-days-to-iso-week d2)))
3554 (setq s (point))
3555 (if org-agenda-overriding-header
3556 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3557 nil 'face 'org-agenda-structure) "\n")
3558 (insert (org-agenda-span-name span)
3559 "-agenda"
3560 (if (< (- d2 d1) 350)
3561 (if (= w1 w2)
3562 (format " (W%02d)" w1)
3563 (format " (W%02d-W%02d)" w1 w2))
3565 ":\n")))
3566 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3567 'org-date-line t))
3568 (org-agenda-mark-header-line s))
3569 (while (setq d (pop day-numbers))
3570 (setq date (calendar-gregorian-from-absolute d)
3571 s (point))
3572 (if (or (setq todayp (= d today))
3573 (and (not start-pos) (= d sd)))
3574 (setq start-pos (point))
3575 (if (and start-pos (not end-pos))
3576 (setq end-pos (point))))
3577 (setq files thefiles
3578 rtnall nil)
3579 (while (setq file (pop files))
3580 (catch 'nextfile
3581 (org-check-agenda-file file)
3582 (let ((org-agenda-entry-types org-agenda-entry-types))
3583 (unless org-agenda-include-deadlines
3584 (setq org-agenda-entry-types
3585 (delq :deadline org-agenda-entry-types)))
3586 (cond
3587 ((eq org-agenda-show-log 'only)
3588 (setq rtn (org-agenda-get-day-entries
3589 file date :closed)))
3590 (org-agenda-show-log
3591 (setq rtn (apply 'org-agenda-get-day-entries
3592 file date
3593 (append '(:closed) org-agenda-entry-types))))
3595 (setq rtn (apply 'org-agenda-get-day-entries
3596 file date
3597 org-agenda-entry-types)))))
3598 (setq rtnall (append rtnall rtn))))
3599 (if org-agenda-include-diary
3600 (let ((org-agenda-search-headline-for-time t))
3601 (require 'diary-lib)
3602 (setq rtn (org-get-entries-from-diary date))
3603 (setq rtnall (append rtnall rtn))))
3604 (if (or rtnall org-agenda-show-all-dates)
3605 (progn
3606 (setq day-cnt (1+ day-cnt))
3607 (insert
3608 (if (stringp org-agenda-format-date)
3609 (format-time-string org-agenda-format-date
3610 (org-time-from-absolute date))
3611 (funcall org-agenda-format-date date))
3612 "\n")
3613 (put-text-property s (1- (point)) 'face
3614 (org-agenda-get-day-face date))
3615 (put-text-property s (1- (point)) 'org-date-line t)
3616 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3617 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3618 (when todayp
3619 (put-text-property s (1- (point)) 'org-today t))
3620 (if rtnall (insert
3621 (org-finalize-agenda-entries
3622 (org-agenda-add-time-grid-maybe
3623 rtnall ndays todayp))
3624 "\n"))
3625 (put-text-property s (1- (point)) 'day d)
3626 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3627 (when (and org-agenda-clockreport-mode clocktable-start)
3628 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3629 ;; the above line is to ensure the restricted range!
3630 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3631 tbl)
3632 (setq p (org-plist-delete p :block))
3633 (setq p (plist-put p :tstart clocktable-start))
3634 (setq p (plist-put p :tend clocktable-end))
3635 (setq p (plist-put p :scope 'agenda))
3636 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3637 (setq filter (or org-agenda-filter-while-redo
3638 (get 'org-agenda-filter :preset-filter))))
3639 (setq p (plist-put p :tags (mapconcat (lambda (x)
3640 (if (string-match "[<>=]" x)
3643 filter ""))))
3644 (setq tbl (apply 'org-get-clocktable p))
3645 (insert tbl)))
3646 (goto-char (point-min))
3647 (or org-agenda-multi (org-fit-agenda-window))
3648 (unless (and (pos-visible-in-window-p (point-min))
3649 (pos-visible-in-window-p (point-max)))
3650 (goto-char (1- (point-max)))
3651 (recenter -1)
3652 (if (not (pos-visible-in-window-p (or start-pos 1)))
3653 (progn
3654 (goto-char (or start-pos 1))
3655 (recenter 1))))
3656 (goto-char (or start-pos 1))
3657 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3658 (org-finalize-agenda)
3659 (setq buffer-read-only t)
3660 (message "")))
3662 (defun org-agenda-ndays-to-span (n)
3663 "Return a span symbol for a span of N days, or N if none matches."
3664 (cond ((symbolp n) n)
3665 ((= n 1) 'day)
3666 ((= n 7) 'week)
3667 (t n)))
3669 (defun org-agenda-span-to-ndays (span start-day)
3670 "Return ndays from SPAN starting at START-DAY."
3671 (cond ((numberp span) span)
3672 ((eq span 'day) 1)
3673 ((eq span 'week) 7)
3674 ((eq span 'month)
3675 (let ((date (calendar-gregorian-from-absolute start-day)))
3676 (calendar-last-day-of-month (car date) (caddr date))))
3677 ((eq span 'year)
3678 (let ((date (calendar-gregorian-from-absolute start-day)))
3679 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3681 (defun org-agenda-span-name (span)
3682 "Return a SPAN name."
3683 (if (null span)
3685 (if (symbolp span)
3686 (capitalize (symbol-name span))
3687 (format "%d days" span))))
3689 ;;; Agenda word search
3691 (defvar org-agenda-search-history nil)
3692 (defvar org-todo-only nil)
3694 (defvar org-search-syntax-table nil
3695 "Special syntax table for org-mode search.
3696 In this table, we have single quotes not as word constituents, to
3697 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3699 (defun org-search-syntax-table ()
3700 (unless org-search-syntax-table
3701 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3702 (modify-syntax-entry ?' "." org-search-syntax-table)
3703 (modify-syntax-entry ?` "." org-search-syntax-table))
3704 org-search-syntax-table)
3706 (defvar org-agenda-last-search-view-search-was-boolean nil)
3708 ;;;###autoload
3709 (defun org-search-view (&optional todo-only string edit-at)
3710 "Show all entries that contain a phrase or words or regular expressions.
3712 With optional prefix argument TODO-ONLY, only consider entries that are
3713 TODO entries. The argument STRING can be used to pass a default search
3714 string into this function. If EDIT-AT is non-nil, it means that the
3715 user should get a chance to edit this string, with cursor at position
3716 EDIT-AT.
3718 The search string can be viewed either as a phrase that should be found as
3719 is, or it can be broken into a number of snippets, each of which must match
3720 in a Boolean way to select an entry. The default depends on the variable
3721 `org-agenda-search-view-always-boolean'.
3722 Even if this is turned off (the default) you can always switch to
3723 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3725 The default is a direct search of the whole phrase, where each space in
3726 the search string can expand to an arbitrary amount of whitespace,
3727 including newlines.
3729 If using a Boolean search, the search string is split on whitespace and
3730 each snippet is searched separately, with logical AND to select an entry.
3731 Words prefixed with a minus must *not* occur in the entry. Words without
3732 a prefix or prefixed with a plus must occur in the entry. Matching is
3733 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3734 match whole words, not parts of a word) if
3735 `org-agenda-search-view-force-full-words' is set (default is nil).
3737 Boolean search snippets enclosed by curly braces are interpreted as
3738 regular expressions that must or (when preceded with \"-\") must not
3739 match in the entry. Snippets enclosed into double quotes will be taken
3740 as a whole, to include whitespace.
3742 - If the search string starts with an asterisk, search only in headlines.
3743 - If (possibly after the leading star) the search string starts with an
3744 exclamation mark, this also means to look at TODO entries only, an effect
3745 that can also be achieved with a prefix argument.
3746 - If (possibly after star and exclamation mark) the search string starts
3747 with a colon, this will mean that the (non-regexp) snippets of the
3748 Boolean search must match as full words.
3750 This command searches the agenda files, and in addition the files listed
3751 in `org-agenda-text-search-extra-files'."
3752 (interactive "P")
3753 (org-compile-prefix-format 'search)
3754 (org-set-sorting-strategy 'search)
3755 (org-prepare-agenda "SEARCH")
3756 (let* ((props (list 'face nil
3757 'done-face 'org-agenda-done
3758 'org-not-done-regexp org-not-done-regexp
3759 'org-todo-regexp org-todo-regexp
3760 'org-complex-heading-regexp org-complex-heading-regexp
3761 'mouse-face 'highlight
3762 'help-echo (format "mouse-2 or RET jump to location")))
3763 (full-words org-agenda-search-view-force-full-words)
3764 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3765 regexp rtn rtnall files file pos
3766 marker category tags c neg re boolean
3767 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3768 (unless (and (not edit-at)
3769 (stringp string)
3770 (string-match "\\S-" string))
3771 (setq string (read-string
3772 (if org-agenda-search-view-always-boolean
3773 "[+-]Word/{Regexp} ...: "
3774 "Phrase, or [+-]Word/{Regexp} ...: ")
3775 (cond
3776 ((integerp edit-at) (cons string edit-at))
3777 (edit-at string))
3778 'org-agenda-search-history)))
3779 (org-set-local 'org-todo-only todo-only)
3780 (setq org-agenda-redo-command
3781 (list 'org-search-view (if todo-only t nil) string
3782 '(if current-prefix-arg 1 nil)))
3783 (setq org-agenda-query-string string)
3785 (if (equal (string-to-char string) ?*)
3786 (setq hdl-only t
3787 words (substring string 1))
3788 (setq words string))
3789 (when (equal (string-to-char words) ?!)
3790 (setq todo-only t
3791 words (substring words 1)))
3792 (when (equal (string-to-char words) ?:)
3793 (setq full-words t
3794 words (substring words 1)))
3795 (if (or org-agenda-search-view-always-boolean
3796 (member (string-to-char words) '(?- ?+ ?\{)))
3797 (setq boolean t))
3798 (setq words (org-split-string words))
3799 (let (www w)
3800 (while (setq w (pop words))
3801 (while (and (string-match "\\\\\\'" w) words)
3802 (setq w (concat (substring w 0 -1) " " (pop words))))
3803 (push w www))
3804 (setq words (nreverse www) www nil)
3805 (while (setq w (pop words))
3806 (when (and (string-match "\\`[-+]?{" w)
3807 (not (string-match "}\\'" w)))
3808 (while (and words (not (string-match "}\\'" (car words))))
3809 (setq w (concat w " " (pop words))))
3810 (setq w (concat w " " (pop words))))
3811 (push w www))
3812 (setq words (nreverse www)))
3813 (setq org-agenda-last-search-view-search-was-boolean boolean)
3814 (when boolean
3815 (let (wds w)
3816 (while (setq w (pop words))
3817 (if (or (equal (substring w 0 1) "\"")
3818 (and (> (length w) 1)
3819 (member (substring w 0 1) '("+" "-"))
3820 (equal (substring w 1 2) "\"")))
3821 (while (and words (not (equal (substring w -1) "\"")))
3822 (setq w (concat w " " (pop words)))))
3823 (and (string-match "\\`\\([-+]?\\)\"" w)
3824 (setq w (replace-match "\\1" nil nil w)))
3825 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3826 (push w wds))
3827 (setq words (nreverse wds))))
3828 (if boolean
3829 (mapc (lambda (w)
3830 (setq c (string-to-char w))
3831 (if (equal c ?-)
3832 (setq neg t w (substring w 1))
3833 (if (equal c ?+)
3834 (setq neg nil w (substring w 1))
3835 (setq neg nil)))
3836 (if (string-match "\\`{.*}\\'" w)
3837 (setq re (substring w 1 -1))
3838 (if full-words
3839 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3840 (setq re (regexp-quote (downcase w)))))
3841 (if neg (push re regexps-) (push re regexps+)))
3842 words)
3843 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3844 regexps+))
3845 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3846 (if (not regexps+)
3847 (setq regexp (concat "^" org-outline-regexp))
3848 (setq regexp (pop regexps+))
3849 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3850 regexp))))
3851 (setq files (org-agenda-files nil 'ifmode))
3852 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3853 (pop org-agenda-text-search-extra-files)
3854 (setq files (org-add-archive-files files)))
3855 (setq files (append files org-agenda-text-search-extra-files)
3856 rtnall nil)
3857 (while (setq file (pop files))
3858 (setq ee nil)
3859 (catch 'nextfile
3860 (org-check-agenda-file file)
3861 (setq buffer (if (file-exists-p file)
3862 (org-get-agenda-file-buffer file)
3863 (error "No such file %s" file)))
3864 (if (not buffer)
3865 ;; If file does not exist, make sure an error message is sent
3866 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3867 file))))
3868 (with-current-buffer buffer
3869 (with-syntax-table (org-search-syntax-table)
3870 (unless (org-mode-p)
3871 (error "Agenda file %s is not in `org-mode'" file))
3872 (let ((case-fold-search t))
3873 (save-excursion
3874 (save-restriction
3875 (if org-agenda-restrict
3876 (narrow-to-region org-agenda-restrict-begin
3877 org-agenda-restrict-end)
3878 (widen))
3879 (goto-char (point-min))
3880 (unless (or (org-on-heading-p)
3881 (outline-next-heading))
3882 (throw 'nextfile t))
3883 (goto-char (max (point-min) (1- (point))))
3884 (while (re-search-forward regexp nil t)
3885 (org-back-to-heading t)
3886 (skip-chars-forward "* ")
3887 (setq beg (point-at-bol)
3888 beg1 (point)
3889 end (progn (outline-next-heading) (point)))
3890 (catch :skip
3891 (goto-char beg)
3892 (org-agenda-skip)
3893 (setq str (buffer-substring-no-properties
3894 (point-at-bol)
3895 (if hdl-only (point-at-eol) end)))
3896 (mapc (lambda (wr) (when (string-match wr str)
3897 (goto-char (1- end))
3898 (throw :skip t)))
3899 regexps-)
3900 (mapc (lambda (wr) (unless (string-match wr str)
3901 (goto-char (1- end))
3902 (throw :skip t)))
3903 (if todo-only
3904 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3905 regexps+)
3906 regexps+))
3907 (goto-char beg)
3908 (setq marker (org-agenda-new-marker (point))
3909 category (org-get-category)
3910 tags (org-get-tags-at (point))
3911 txt (org-format-agenda-item
3913 (buffer-substring-no-properties
3914 beg1 (point-at-eol))
3915 category tags))
3916 (org-add-props txt props
3917 'org-marker marker 'org-hd-marker marker
3918 'org-todo-regexp org-todo-regexp
3919 'org-complex-heading-regexp org-complex-heading-regexp
3920 'priority 1000 'org-category category
3921 'type "search")
3922 (push txt ee)
3923 (goto-char (1- end))))))))))
3924 (setq rtn (nreverse ee))
3925 (setq rtnall (append rtnall rtn)))
3926 (if org-agenda-overriding-header
3927 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3928 nil 'face 'org-agenda-structure) "\n")
3929 (insert "Search words: ")
3930 (add-text-properties (point-min) (1- (point))
3931 (list 'face 'org-agenda-structure))
3932 (setq pos (point))
3933 (insert string "\n")
3934 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3935 (setq pos (point))
3936 (unless org-agenda-multi
3937 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3938 (add-text-properties pos (1- (point))
3939 (list 'face 'org-agenda-structure))))
3940 (org-agenda-mark-header-line (point-min))
3941 (when rtnall
3942 (insert (org-finalize-agenda-entries rtnall) "\n"))
3943 (goto-char (point-min))
3944 (or org-agenda-multi (org-fit-agenda-window))
3945 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3946 (org-finalize-agenda)
3947 (setq buffer-read-only t)))
3949 ;;; Agenda TODO list
3951 (defvar org-select-this-todo-keyword nil)
3952 (defvar org-last-arg nil)
3954 ;;;###autoload
3955 (defun org-todo-list (arg)
3956 "Show all (not done) TODO entries from all agenda file in a single list.
3957 The prefix arg can be used to select a specific TODO keyword and limit
3958 the list to these. When using \\[universal-argument], you will be prompted
3959 for a keyword. A numeric prefix directly selects the Nth keyword in
3960 `org-todo-keywords-1'."
3961 (interactive "P")
3962 (org-compile-prefix-format 'todo)
3963 (org-set-sorting-strategy 'todo)
3964 (org-prepare-agenda "TODO")
3965 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3966 (let* ((today (org-today))
3967 (date (calendar-gregorian-from-absolute today))
3968 (kwds org-todo-keywords-for-agenda)
3969 (completion-ignore-case t)
3970 (org-select-this-todo-keyword
3971 (if (stringp arg) arg
3972 (and arg (integerp arg) (> arg 0)
3973 (nth (1- arg) kwds))))
3974 rtn rtnall files file pos)
3975 (when (equal arg '(4))
3976 (setq org-select-this-todo-keyword
3977 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3978 (mapcar 'list kwds) nil nil)))
3979 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3980 (org-set-local 'org-last-arg arg)
3981 (setq org-agenda-redo-command
3982 '(org-todo-list (or current-prefix-arg org-last-arg)))
3983 (setq files (org-agenda-files nil 'ifmode)
3984 rtnall nil)
3985 (while (setq file (pop files))
3986 (catch 'nextfile
3987 (org-check-agenda-file file)
3988 (setq rtn (org-agenda-get-day-entries file date :todo))
3989 (setq rtnall (append rtnall rtn))))
3990 (if org-agenda-overriding-header
3991 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3992 nil 'face 'org-agenda-structure) "\n")
3993 (insert "Global list of TODO items of type: ")
3994 (add-text-properties (point-min) (1- (point))
3995 (list 'face 'org-agenda-structure
3996 'short-heading
3997 (concat "ToDo: "
3998 (or org-select-this-todo-keyword "ALL"))))
3999 (org-agenda-mark-header-line (point-min))
4000 (setq pos (point))
4001 (insert (or org-select-this-todo-keyword "ALL") "\n")
4002 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4003 (setq pos (point))
4004 (unless org-agenda-multi
4005 (insert "Available with `N r': (0)ALL")
4006 (let ((n 0) s)
4007 (mapc (lambda (x)
4008 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4009 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4010 (insert "\n "))
4011 (insert " " s))
4012 kwds))
4013 (insert "\n"))
4014 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4015 (org-agenda-mark-header-line (point-min))
4016 (when rtnall
4017 (insert (org-finalize-agenda-entries rtnall) "\n"))
4018 (goto-char (point-min))
4019 (or org-agenda-multi (org-fit-agenda-window))
4020 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4021 (org-finalize-agenda)
4022 (setq buffer-read-only t)))
4024 ;;; Agenda tags match
4026 ;;;###autoload
4027 (defun org-tags-view (&optional todo-only match)
4028 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4029 The prefix arg TODO-ONLY limits the search to TODO entries."
4030 (interactive "P")
4031 (org-compile-prefix-format 'tags)
4032 (org-set-sorting-strategy 'tags)
4033 (let* ((org-tags-match-list-sublevels
4034 org-tags-match-list-sublevels)
4035 (completion-ignore-case t)
4036 rtn rtnall files file pos matcher
4037 buffer)
4038 (when (and (stringp match) (not (string-match "\\S-" match)))
4039 (setq match nil))
4040 (setq matcher (org-make-tags-matcher match)
4041 match (car matcher) matcher (cdr matcher))
4042 (org-prepare-agenda (concat "TAGS " match))
4043 (setq org-agenda-query-string match)
4044 (setq org-agenda-redo-command
4045 (list 'org-tags-view (list 'quote todo-only)
4046 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4047 (setq files (org-agenda-files nil 'ifmode)
4048 rtnall nil)
4049 (while (setq file (pop files))
4050 (catch 'nextfile
4051 (org-check-agenda-file file)
4052 (setq buffer (if (file-exists-p file)
4053 (org-get-agenda-file-buffer file)
4054 (error "No such file %s" file)))
4055 (if (not buffer)
4056 ;; If file does not exist, error message to agenda
4057 (setq rtn (list
4058 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4059 rtnall (append rtnall rtn))
4060 (with-current-buffer buffer
4061 (unless (org-mode-p)
4062 (error "Agenda file %s is not in `org-mode'" file))
4063 (save-excursion
4064 (save-restriction
4065 (if org-agenda-restrict
4066 (narrow-to-region org-agenda-restrict-begin
4067 org-agenda-restrict-end)
4068 (widen))
4069 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4070 (setq rtnall (append rtnall rtn))))))))
4071 (if org-agenda-overriding-header
4072 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4073 nil 'face 'org-agenda-structure) "\n")
4074 (insert "Headlines with TAGS match: ")
4075 (add-text-properties (point-min) (1- (point))
4076 (list 'face 'org-agenda-structure
4077 'short-heading
4078 (concat "Match: " match)))
4079 (setq pos (point))
4080 (insert match "\n")
4081 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4082 (setq pos (point))
4083 (unless org-agenda-multi
4084 (insert "Press `C-u r' to search again with new search string\n"))
4085 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4086 (org-agenda-mark-header-line (point-min))
4087 (when rtnall
4088 (insert (org-finalize-agenda-entries rtnall) "\n"))
4089 (goto-char (point-min))
4090 (or org-agenda-multi (org-fit-agenda-window))
4091 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4092 (org-finalize-agenda)
4093 (setq buffer-read-only t)))
4095 ;;; Agenda Finding stuck projects
4097 (defvar org-agenda-skip-regexp nil
4098 "Regular expression used in skipping subtrees for the agenda.
4099 This is basically a temporary global variable that can be set and then
4100 used by user-defined selections using `org-agenda-skip-function'.")
4102 (defvar org-agenda-overriding-header nil
4103 "When this is set during todo and tags searches, will replace header.
4104 This variable should not be set directly, but custom commands can bind it
4105 in the options section.")
4107 (defun org-agenda-skip-entry-when-regexp-matches ()
4108 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4109 If yes, it returns the end position of this entry, causing agenda commands
4110 to skip the entry but continuing the search in the subtree. This is a
4111 function that can be put into `org-agenda-skip-function' for the duration
4112 of a command."
4113 (let ((end (save-excursion (org-end-of-subtree t)))
4114 skip)
4115 (save-excursion
4116 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4117 (and skip end)))
4119 (defun org-agenda-skip-subtree-when-regexp-matches ()
4120 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4121 If yes, it returns the end position of this tree, causing agenda commands
4122 to skip this subtree. This is a function that can be put into
4123 `org-agenda-skip-function' for the duration of a command."
4124 (let ((end (save-excursion (org-end-of-subtree t)))
4125 skip)
4126 (save-excursion
4127 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4128 (and skip end)))
4130 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4131 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4132 If yes, it returns the end position of the current entry (NOT the tree),
4133 causing agenda commands to skip the entry but continuing the search in
4134 the subtree. This is a function that can be put into
4135 `org-agenda-skip-function' for the duration of a command. An important
4136 use of this function is for the stuck project list."
4137 (let ((end (save-excursion (org-end-of-subtree t)))
4138 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4139 skip)
4140 (save-excursion
4141 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4142 (and skip entry-end)))
4144 (defun org-agenda-skip-entry-if (&rest conditions)
4145 "Skip entry if any of CONDITIONS is true.
4146 See `org-agenda-skip-if' for details."
4147 (org-agenda-skip-if nil conditions))
4149 (defun org-agenda-skip-subtree-if (&rest conditions)
4150 "Skip entry if any of CONDITIONS is true.
4151 See `org-agenda-skip-if' for details."
4152 (org-agenda-skip-if t conditions))
4154 (defun org-agenda-skip-if (subtree conditions)
4155 "Checks current entity for CONDITIONS.
4156 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4157 the entry, i.e. the text before the next heading is checked.
4159 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4160 from different tests. Valid conditions are:
4162 scheduled Check if there is a scheduled cookie
4163 notscheduled Check if there is no scheduled cookie
4164 deadline Check if there is a deadline
4165 notdeadline Check if there is no deadline
4166 timestamp Check if there is a timestamp (also deadline or scheduled)
4167 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4168 regexp Check if regexp matches
4169 notregexp Check if regexp does not match.
4170 todo Check if TODO keyword matches
4171 nottodo Check if TODO keyword does not match
4173 The regexp is taken from the conditions list, it must come right after
4174 the `regexp' or `notregexp' element.
4176 `todo' and `nottodo' accept as an argument a list of todo
4177 keywords, which may include \"*\" to match any todo keyword.
4179 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4181 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4183 Instead of a list a keyword class may be given
4185 (org-agenda-skip-entry-if 'nottodo 'done)
4187 would skip entries that haven't been marked with any of \"DONE\"
4188 keywords. Possible classes are: `todo', `done', `any'.
4190 If any of these conditions is met, this function returns the end point of
4191 the entity, causing the search to continue from there. This is a function
4192 that can be put into `org-agenda-skip-function' for the duration of a command."
4193 (let (beg end m)
4194 (org-back-to-heading t)
4195 (setq beg (point)
4196 end (if subtree
4197 (progn (org-end-of-subtree t) (point))
4198 (progn (outline-next-heading) (1- (point)))))
4199 (goto-char beg)
4200 (and
4202 (and (memq 'scheduled conditions)
4203 (re-search-forward org-scheduled-time-regexp end t))
4204 (and (memq 'notscheduled conditions)
4205 (not (re-search-forward org-scheduled-time-regexp end t)))
4206 (and (memq 'deadline conditions)
4207 (re-search-forward org-deadline-time-regexp end t))
4208 (and (memq 'notdeadline conditions)
4209 (not (re-search-forward org-deadline-time-regexp end t)))
4210 (and (memq 'timestamp conditions)
4211 (re-search-forward org-ts-regexp end t))
4212 (and (memq 'nottimestamp conditions)
4213 (not (re-search-forward org-ts-regexp end t)))
4214 (and (setq m (memq 'regexp conditions))
4215 (stringp (nth 1 m))
4216 (re-search-forward (nth 1 m) end t))
4217 (and (setq m (memq 'notregexp conditions))
4218 (stringp (nth 1 m))
4219 (not (re-search-forward (nth 1 m) end t)))
4220 (and (or
4221 (setq m (memq 'todo conditions))
4222 (setq m (memq 'nottodo conditions)))
4223 (org-agenda-skip-if-todo m end)))
4224 end)))
4226 (defun org-agenda-skip-if-todo (args end)
4227 "Helper function for `org-agenda-skip-if', do not use it directly.
4228 ARGS is a list with first element either `todo' or `nottodo'.
4229 The remainder is either a list of TODO keywords, or a state symbol
4230 `todo' or `done' or `any'."
4231 (let ((kw (car args))
4232 (arg (cadr args))
4233 todo-wds todo-re)
4234 (setq todo-wds
4235 (org-uniquify
4236 (cond
4237 ((listp arg) ;; list of keywords
4238 (if (member "*" arg)
4239 (mapcar 'substring-no-properties org-todo-keywords-1)
4240 arg))
4241 ((symbolp arg) ;; keyword class name
4242 (cond
4243 ((eq arg 'todo)
4244 (org-delete-all org-done-keywords
4245 (mapcar 'substring-no-properties
4246 org-todo-keywords-1)))
4247 ((eq arg 'done) org-done-keywords)
4248 ((eq arg 'any)
4249 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4250 (setq todo-re
4251 (concat "^\\*+[ \t]+\\<\\("
4252 (mapconcat 'identity todo-wds "\\|")
4253 "\\)\\>"))
4254 (if (eq kw 'todo)
4255 (re-search-forward todo-re end t)
4256 (not (re-search-forward todo-re end t)))))
4258 ;;;###autoload
4259 (defun org-agenda-list-stuck-projects (&rest ignore)
4260 "Create agenda view for projects that are stuck.
4261 Stuck projects are project that have no next actions. For the definitions
4262 of what a project is and how to check if it stuck, customize the variable
4263 `org-stuck-projects'."
4264 (interactive)
4265 (let* ((org-agenda-skip-function
4266 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4267 ;; We could have used org-agenda-skip-if here.
4268 (org-agenda-overriding-header
4269 (or org-agenda-overriding-header "List of stuck projects: "))
4270 (matcher (nth 0 org-stuck-projects))
4271 (todo (nth 1 org-stuck-projects))
4272 (todo-wds (if (member "*" todo)
4273 (progn
4274 (org-prepare-agenda-buffers (org-agenda-files
4275 nil 'ifmode))
4276 (org-delete-all
4277 org-done-keywords-for-agenda
4278 (copy-sequence org-todo-keywords-for-agenda)))
4279 todo))
4280 (todo-re (concat "^\\*+[ \t]+\\("
4281 (mapconcat 'identity todo-wds "\\|")
4282 "\\)\\>"))
4283 (tags (nth 2 org-stuck-projects))
4284 (tags-re (if (member "*" tags)
4285 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4286 (if tags
4287 (concat "^\\*+ .*:\\("
4288 (mapconcat 'identity tags "\\|")
4289 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4290 (gen-re (nth 3 org-stuck-projects))
4291 (re-list
4292 (delq nil
4293 (list
4294 (if todo todo-re)
4295 (if tags tags-re)
4296 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4297 gen-re)))))
4298 (setq org-agenda-skip-regexp
4299 (if re-list
4300 (mapconcat 'identity re-list "\\|")
4301 (error "No information how to identify unstuck projects")))
4302 (org-tags-view nil matcher)
4303 (with-current-buffer org-agenda-buffer-name
4304 (setq org-agenda-redo-command
4305 '(org-agenda-list-stuck-projects
4306 (or current-prefix-arg org-last-arg))))))
4308 ;;; Diary integration
4310 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4311 (defvar list-diary-entries-hook)
4312 (defvar diary-time-regexp)
4313 (defun org-get-entries-from-diary (date)
4314 "Get the (Emacs Calendar) diary entries for DATE."
4315 (require 'diary-lib)
4316 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4317 (diary-display-hook '(fancy-diary-display))
4318 (diary-display-function 'fancy-diary-display)
4319 (pop-up-frames nil)
4320 (list-diary-entries-hook
4321 (cons 'org-diary-default-entry list-diary-entries-hook))
4322 (diary-file-name-prefix-function nil) ; turn this feature off
4323 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4324 entries
4325 (org-disable-agenda-to-diary t))
4326 (save-excursion
4327 (save-window-excursion
4328 (funcall (if (fboundp 'diary-list-entries)
4329 'diary-list-entries 'list-diary-entries)
4330 date 1)))
4331 (if (not (get-buffer diary-fancy-buffer))
4332 (setq entries nil)
4333 (with-current-buffer diary-fancy-buffer
4334 (setq buffer-read-only nil)
4335 (if (zerop (buffer-size))
4336 ;; No entries
4337 (setq entries nil)
4338 ;; Omit the date and other unnecessary stuff
4339 (org-agenda-cleanup-fancy-diary)
4340 ;; Add prefix to each line and extend the text properties
4341 (if (zerop (buffer-size))
4342 (setq entries nil)
4343 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4344 (setq entries
4345 (with-temp-buffer
4346 (insert entries) (goto-char (point-min))
4347 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4348 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4349 (replace-match (concat "; " (match-string 1)))))
4350 (buffer-string)))))
4351 (set-buffer-modified-p nil)
4352 (kill-buffer diary-fancy-buffer)))
4353 (when entries
4354 (setq entries (org-split-string entries "\n"))
4355 (setq entries
4356 (mapcar
4357 (lambda (x)
4358 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4359 ;; Extend the text properties to the beginning of the line
4360 (org-add-props x (text-properties-at (1- (length x)) x)
4361 'type "diary" 'date date 'face 'org-agenda-diary))
4362 entries)))))
4364 (defvar org-agenda-cleanup-fancy-diary-hook nil
4365 "Hook run when the fancy diary buffer is cleaned up.")
4367 (defun org-agenda-cleanup-fancy-diary ()
4368 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4369 This gets rid of the date, the underline under the date, and
4370 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4371 date. It also removes lines that contain only whitespace."
4372 (goto-char (point-min))
4373 (if (looking-at ".*?:[ \t]*")
4374 (progn
4375 (replace-match "")
4376 (re-search-forward "\n=+$" nil t)
4377 (replace-match "")
4378 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4379 (re-search-forward "\n=+$" nil t)
4380 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4381 (goto-char (point-min))
4382 (while (re-search-forward "^ +\n" nil t)
4383 (replace-match ""))
4384 (goto-char (point-min))
4385 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4386 (replace-match ""))
4387 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4389 ;; Make sure entries from the diary have the right text properties.
4390 (eval-after-load "diary-lib"
4391 '(if (boundp 'diary-modify-entry-list-string-function)
4392 ;; We can rely on the hook, nothing to do
4394 ;; Hook not available, must use advice to make this work
4395 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4396 "Make the position visible."
4397 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4398 (stringp string)
4399 buffer-file-name)
4400 (setq string (org-modify-diary-entry-string string))))))
4402 (defun org-modify-diary-entry-string (string)
4403 "Add text properties to string, allowing org-mode to act on it."
4404 (org-add-props string nil
4405 'mouse-face 'highlight
4406 'help-echo (if buffer-file-name
4407 (format "mouse-2 or RET jump to diary file %s"
4408 (abbreviate-file-name buffer-file-name))
4410 'org-agenda-diary-link t
4411 'org-marker (org-agenda-new-marker (point-at-bol))))
4413 (defun org-diary-default-entry ()
4414 "Add a dummy entry to the diary.
4415 Needed to avoid empty dates which mess up holiday display."
4416 ;; Catch the error if dealing with the new add-to-diary-alist
4417 (when org-disable-agenda-to-diary
4418 (condition-case nil
4419 (org-add-to-diary-list original-date "Org-mode dummy" "")
4420 (error
4421 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4423 (defun org-add-to-diary-list (&rest args)
4424 (if (fboundp 'diary-add-to-list)
4425 (apply 'diary-add-to-list args)
4426 (apply 'add-to-diary-list args)))
4428 (defvar org-diary-last-run-time nil)
4430 ;;;###autoload
4431 (defun org-diary (&rest args)
4432 "Return diary information from org-files.
4433 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4434 It accesses org files and extracts information from those files to be
4435 listed in the diary. The function accepts arguments specifying what
4436 items should be listed. For a list of arguments allowed here, see the
4437 variable `org-agenda-entry-types'.
4439 The call in the diary file should look like this:
4441 &%%(org-diary) ~/path/to/some/orgfile.org
4443 Use a separate line for each org file to check. Or, if you omit the file name,
4444 all files listed in `org-agenda-files' will be checked automatically:
4446 &%%(org-diary)
4448 If you don't give any arguments (as in the example above), the default
4449 arguments (:deadline :scheduled :timestamp :sexp) are used.
4450 So the example above may also be written as
4452 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4454 The function expects the lisp variables `entry' and `date' to be provided
4455 by the caller, because this is how the calendar works. Don't use this
4456 function from a program - use `org-agenda-get-day-entries' instead."
4457 (when (> (- (org-float-time)
4458 org-agenda-last-marker-time)
4460 (org-agenda-reset-markers))
4461 (org-compile-prefix-format 'agenda)
4462 (org-set-sorting-strategy 'agenda)
4463 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4464 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4465 (list entry)
4466 (org-agenda-files t)))
4467 (time (org-float-time))
4468 file rtn results)
4469 (when (or (not org-diary-last-run-time)
4470 (> (- time
4471 org-diary-last-run-time)
4473 (org-prepare-agenda-buffers files))
4474 (setq org-diary-last-run-time time)
4475 ;; If this is called during org-agenda, don't return any entries to
4476 ;; the calendar. Org Agenda will list these entries itself.
4477 (if org-disable-agenda-to-diary (setq files nil))
4478 (while (setq file (pop files))
4479 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4480 (setq results (append results rtn)))
4481 (if results
4482 (concat (org-finalize-agenda-entries results) "\n"))))
4484 ;;; Agenda entry finders
4486 (defun org-agenda-get-day-entries (file date &rest args)
4487 "Does the work for `org-diary' and `org-agenda'.
4488 FILE is the path to a file to be checked for entries. DATE is date like
4489 the one returned by `calendar-current-date'. ARGS are symbols indicating
4490 which kind of entries should be extracted. For details about these, see
4491 the documentation of `org-diary'."
4492 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4493 (let* ((org-startup-folded nil)
4494 (org-startup-align-all-tables nil)
4495 (buffer (if (file-exists-p file)
4496 (org-get-agenda-file-buffer file)
4497 (error "No such file %s" file)))
4498 arg results rtn deadline-results)
4499 (if (not buffer)
4500 ;; If file does not exist, make sure an error message ends up in diary
4501 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4502 (with-current-buffer buffer
4503 (unless (org-mode-p)
4504 (error "Agenda file %s is not in `org-mode'" file))
4505 (let ((case-fold-search nil))
4506 (save-excursion
4507 (save-restriction
4508 (if org-agenda-restrict
4509 (narrow-to-region org-agenda-restrict-begin
4510 org-agenda-restrict-end)
4511 (widen))
4512 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4513 (while (setq arg (pop args))
4514 (cond
4515 ((and (eq arg :todo)
4516 (equal date (calendar-gregorian-from-absolute
4517 (org-today))))
4518 (setq rtn (org-agenda-get-todos))
4519 (setq results (append results rtn)))
4520 ((eq arg :timestamp)
4521 (setq rtn (org-agenda-get-blocks))
4522 (setq results (append results rtn))
4523 (setq rtn (org-agenda-get-timestamps))
4524 (setq results (append results rtn)))
4525 ((eq arg :sexp)
4526 (setq rtn (org-agenda-get-sexps))
4527 (setq results (append results rtn)))
4528 ((eq arg :scheduled)
4529 (setq rtn (org-agenda-get-scheduled deadline-results))
4530 (setq results (append results rtn)))
4531 ((eq arg :closed)
4532 (setq rtn (org-agenda-get-progress))
4533 (setq results (append results rtn)))
4534 ((eq arg :deadline)
4535 (setq rtn (org-agenda-get-deadlines))
4536 (setq deadline-results (copy-sequence rtn))
4537 (setq results (append results rtn))))))))
4538 results))))
4540 (defun org-agenda-get-todos ()
4541 "Return the TODO information for agenda display."
4542 (let* ((props (list 'face nil
4543 'done-face 'org-agenda-done
4544 'org-not-done-regexp org-not-done-regexp
4545 'org-todo-regexp org-todo-regexp
4546 'org-complex-heading-regexp org-complex-heading-regexp
4547 'mouse-face 'highlight
4548 'help-echo
4549 (format "mouse-2 or RET jump to org file %s"
4550 (abbreviate-file-name buffer-file-name))))
4551 (regexp (concat "^\\*+[ \t]+\\("
4552 (if org-select-this-todo-keyword
4553 (if (equal org-select-this-todo-keyword "*")
4554 org-todo-regexp
4555 (concat "\\<\\("
4556 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4557 "\\)\\>"))
4558 org-not-done-regexp)
4559 "[^\n\r]*\\)"))
4560 marker priority category tags todo-state
4561 ee txt beg end)
4562 (goto-char (point-min))
4563 (while (re-search-forward regexp nil t)
4564 (catch :skip
4565 (save-match-data
4566 (beginning-of-line)
4567 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4568 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4569 (goto-char (1+ beg))
4570 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4571 (throw :skip nil)))
4572 (goto-char beg)
4573 (org-agenda-skip)
4574 (goto-char (match-beginning 1))
4575 (setq marker (org-agenda-new-marker (match-beginning 0))
4576 category (org-get-category)
4577 txt (match-string 1)
4578 tags (org-get-tags-at (point))
4579 txt (org-format-agenda-item "" txt category tags)
4580 priority (1+ (org-get-priority txt))
4581 todo-state (org-get-todo-state))
4582 (org-add-props txt props
4583 'org-marker marker 'org-hd-marker marker
4584 'priority priority 'org-category category
4585 'type "todo" 'todo-state todo-state)
4586 (push txt ee)
4587 (if org-agenda-todo-list-sublevels
4588 (goto-char (match-end 1))
4589 (org-end-of-subtree 'invisible))))
4590 (nreverse ee)))
4592 (defun org-agenda-todo-custom-ignore-p (time n)
4593 "Check whether timestamp is farther away then n number of days.
4594 This function is invoked if `org-agenda-todo-ignore-deadlines',
4595 `org-agenda-todo-ignore-scheduled' or
4596 `org-agenda-todo-ignore-timestamp' is set to an integer."
4597 (let ((days (org-days-to-time time)))
4598 (if (>= n 0)
4599 (>= days n)
4600 (<= days n))))
4602 ;;;###autoload
4603 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4604 (&optional end)
4605 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4606 (when (or org-agenda-todo-ignore-with-date
4607 org-agenda-todo-ignore-scheduled
4608 org-agenda-todo-ignore-deadlines
4609 org-agenda-todo-ignore-timestamp)
4610 (setq end (or end (save-excursion (outline-next-heading) (point))))
4611 (save-excursion
4612 (or (and org-agenda-todo-ignore-with-date
4613 (re-search-forward org-ts-regexp end t))
4614 (and org-agenda-todo-ignore-scheduled
4615 (re-search-forward org-scheduled-time-regexp end t)
4616 (cond
4617 ((eq org-agenda-todo-ignore-scheduled 'future)
4618 (> (org-days-to-time (match-string 1)) 0))
4619 ((eq org-agenda-todo-ignore-scheduled 'past)
4620 (<= (org-days-to-time (match-string 1)) 0))
4621 ((numberp org-agenda-todo-ignore-scheduled)
4622 (org-agenda-todo-custom-ignore-p
4623 (match-string 1) org-agenda-todo-ignore-scheduled))
4624 (t)))
4625 (and org-agenda-todo-ignore-deadlines
4626 (re-search-forward org-deadline-time-regexp end t)
4627 (cond
4628 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4629 ((eq org-agenda-todo-ignore-deadlines 'far)
4630 (not (org-deadline-close (match-string 1))))
4631 ((eq org-agenda-todo-ignore-deadlines 'future)
4632 (> (org-days-to-time (match-string 1)) 0))
4633 ((eq org-agenda-todo-ignore-deadlines 'past)
4634 (<= (org-days-to-time (match-string 1)) 0))
4635 ((numberp org-agenda-todo-ignore-deadlines)
4636 (org-agenda-todo-custom-ignore-p
4637 (match-string 1) org-agenda-todo-ignore-deadlines))
4638 (t (org-deadline-close (match-string 1)))))
4639 (and org-agenda-todo-ignore-timestamp
4640 (let ((buffer (current-buffer))
4641 (regexp
4642 (concat
4643 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4644 (start (point)))
4645 ;; Copy current buffer into a temporary one
4646 (with-temp-buffer
4647 (insert-buffer-substring buffer start end)
4648 (goto-char (point-min))
4649 ;; Delete SCHEDULED and DEADLINE items
4650 (while (re-search-forward regexp end t)
4651 (delete-region (match-beginning 0) (match-end 0)))
4652 (goto-char (point-min))
4653 ;; No search for timestamp left
4654 (when (re-search-forward org-ts-regexp nil t)
4655 (cond
4656 ((eq org-agenda-todo-ignore-timestamp 'future)
4657 (> (org-days-to-time (match-string 1)) 0))
4658 ((eq org-agenda-todo-ignore-timestamp 'past)
4659 (<= (org-days-to-time (match-string 1)) 0))
4660 ((numberp org-agenda-todo-ignore-timestamp)
4661 (org-agenda-todo-custom-ignore-p
4662 (match-string 1) org-agenda-todo-ignore-timestamp))
4663 (t))))))))))
4665 (defconst org-agenda-no-heading-message
4666 "No heading for this item in buffer or region.")
4668 (defun org-agenda-get-timestamps ()
4669 "Return the date stamp information for agenda display."
4670 (let* ((props (list 'face nil
4671 'org-not-done-regexp org-not-done-regexp
4672 'org-todo-regexp org-todo-regexp
4673 'org-complex-heading-regexp org-complex-heading-regexp
4674 'mouse-face 'highlight
4675 'help-echo
4676 (format "mouse-2 or RET jump to org file %s"
4677 (abbreviate-file-name buffer-file-name))))
4678 (d1 (calendar-absolute-from-gregorian date))
4679 (remove-re
4680 (concat
4681 (regexp-quote
4682 (format-time-string
4683 "<%Y-%m-%d"
4684 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4685 ".*?>"))
4686 (regexp
4687 (concat
4688 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4689 (regexp-quote
4690 (substring
4691 (format-time-string
4692 (car org-time-stamp-formats)
4693 (apply 'encode-time ; DATE bound by calendar
4694 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4695 1 11))
4696 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4697 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4698 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4699 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4700 todo-state end-of-match show-all)
4701 (goto-char (point-min))
4702 (while (setq end-of-match (re-search-forward regexp nil t))
4703 (setq b0 (match-beginning 0)
4704 b3 (match-beginning 3) e3 (match-end 3)
4705 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4706 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4707 (member todo-state
4708 org-agenda-repeating-timestamp-show-all)))
4709 (catch :skip
4710 (and (org-at-date-range-p) (throw :skip nil))
4711 (org-agenda-skip)
4712 (if (and (match-end 1)
4713 (not (= d1 (org-time-string-to-absolute
4714 (match-string 1) d1 nil show-all))))
4715 (throw :skip nil))
4716 (if (and e3
4717 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4718 (throw :skip nil))
4719 (setq tmp (buffer-substring (max (point-min)
4720 (- b0 org-ds-keyword-length))
4722 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4723 inactivep (= (char-after b0) ?\[)
4724 deadlinep (string-match org-deadline-regexp tmp)
4725 scheduledp (string-match org-scheduled-regexp tmp)
4726 closedp (and org-agenda-include-inactive-timestamps
4727 (string-match org-closed-string tmp))
4728 clockp (and org-agenda-include-inactive-timestamps
4729 (or (string-match org-clock-string tmp)
4730 (string-match "]-+\\'" tmp)))
4731 donep (member todo-state org-done-keywords))
4732 (if (or scheduledp deadlinep closedp clockp
4733 (and donep org-agenda-skip-timestamp-if-done))
4734 (throw :skip t))
4735 (if (string-match ">" timestr)
4736 ;; substring should only run to end of time stamp
4737 (setq timestr (substring timestr 0 (match-end 0))))
4738 (setq marker (org-agenda-new-marker b0)
4739 category (org-get-category b0))
4740 (save-excursion
4741 (if (not (re-search-backward "^\\*+ " nil t))
4742 (setq txt org-agenda-no-heading-message)
4743 (goto-char (match-beginning 0))
4744 (setq hdmarker (org-agenda-new-marker)
4745 tags (org-get-tags-at))
4746 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4747 (setq head (match-string 1))
4748 (setq txt (org-format-agenda-item
4749 (if inactivep org-agenda-inactive-leader nil)
4750 head category tags timestr nil
4751 remove-re)))
4752 (setq priority (org-get-priority txt))
4753 (org-add-props txt props
4754 'org-marker marker 'org-hd-marker hdmarker)
4755 (org-add-props txt nil 'priority priority
4756 'org-category category 'date date
4757 'todo-state todo-state
4758 'type "timestamp")
4759 (push txt ee))
4760 (if org-agenda-skip-additional-timestamps-same-entry
4761 (outline-next-heading)
4762 (goto-char end-of-match))))
4763 (nreverse ee)))
4765 (defun org-agenda-get-sexps ()
4766 "Return the sexp information for agenda display."
4767 (require 'diary-lib)
4768 (let* ((props (list 'mouse-face 'highlight
4769 'help-echo
4770 (format "mouse-2 or RET jump to org file %s"
4771 (abbreviate-file-name buffer-file-name))))
4772 (regexp "^&?%%(")
4773 marker category ee txt tags entry result beg b sexp sexp-entry
4774 todo-state)
4775 (goto-char (point-min))
4776 (while (re-search-forward regexp nil t)
4777 (catch :skip
4778 (org-agenda-skip)
4779 (setq beg (match-beginning 0))
4780 (goto-char (1- (match-end 0)))
4781 (setq b (point))
4782 (forward-sexp 1)
4783 (setq sexp (buffer-substring b (point)))
4784 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4785 (org-trim (match-string 1))
4786 ""))
4787 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4788 (when result
4789 (setq marker (org-agenda-new-marker beg)
4790 category (org-get-category beg)
4791 todo-state (org-get-todo-state))
4793 (dolist (r (if (stringp result)
4794 (list result)
4795 result)) ;; we expect a list here
4796 (if (string-match "\\S-" r)
4797 (setq txt r)
4798 (setq txt "SEXP entry returned empty string"))
4800 (setq txt (org-format-agenda-item
4801 "" txt category tags 'time))
4802 (org-add-props txt props 'org-marker marker)
4803 (org-add-props txt nil
4804 'org-category category 'date date 'todo-state todo-state
4805 'type "sexp")
4806 (push txt ee)))))
4807 (nreverse ee)))
4809 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4810 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4811 The order of the first 2 times 3 arguments depends on the variable
4812 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4813 So for American calendars, give this as MONTH DAY YEAR, for European as
4814 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4815 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4816 is any number of ISO weeks in the block period for which the item should
4817 be skipped."
4818 (let* ((date1 (calendar-absolute-from-gregorian
4819 (org-order-calendar-date-args m1 d1 y1)))
4820 (date2 (calendar-absolute-from-gregorian
4821 (org-order-calendar-date-args m2 d2 y2)))
4822 (d (calendar-absolute-from-gregorian date)))
4823 (and
4824 (<= date1 d)
4825 (<= d date2)
4826 (= (calendar-day-of-week date) dayname)
4827 (or (not skip-weeks)
4828 (progn
4829 (require 'cal-iso)
4830 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4831 entry)))
4833 (defalias 'org-get-closed 'org-agenda-get-progress)
4834 (defun org-agenda-get-progress ()
4835 "Return the logged TODO entries for agenda display."
4836 (let* ((props (list 'mouse-face 'highlight
4837 'org-not-done-regexp org-not-done-regexp
4838 'org-todo-regexp org-todo-regexp
4839 'org-complex-heading-regexp org-complex-heading-regexp
4840 'help-echo
4841 (format "mouse-2 or RET jump to org file %s"
4842 (abbreviate-file-name buffer-file-name))))
4843 (items (if (consp org-agenda-show-log)
4844 org-agenda-show-log
4845 org-agenda-log-mode-items))
4846 (parts
4847 (delq nil
4848 (list
4849 (if (memq 'closed items) (concat "\\<" org-closed-string))
4850 (if (memq 'clock items) (concat "\\<" org-clock-string))
4851 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4852 (parts-re (if parts (mapconcat 'identity parts "\\|")
4853 (error "`org-agenda-log-mode-items' is empty")))
4854 (regexp (concat
4855 "\\(" parts-re "\\)"
4856 " *\\["
4857 (regexp-quote
4858 (substring
4859 (format-time-string
4860 (car org-time-stamp-formats)
4861 (apply 'encode-time ; DATE bound by calendar
4862 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4863 1 11))))
4864 (org-agenda-search-headline-for-time nil)
4865 marker hdmarker priority category tags closedp statep clockp state
4866 ee txt extra timestr rest clocked)
4867 (goto-char (point-min))
4868 (while (re-search-forward regexp nil t)
4869 (catch :skip
4870 (org-agenda-skip)
4871 (setq marker (org-agenda-new-marker (match-beginning 0))
4872 closedp (equal (match-string 1) org-closed-string)
4873 statep (equal (string-to-char (match-string 1)) ?-)
4874 clockp (not (or closedp statep))
4875 state (and statep (match-string 2))
4876 category (org-get-category (match-beginning 0))
4877 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4879 (when (string-match "\\]" timestr)
4880 ;; substring should only run to end of time stamp
4881 (setq rest (substring timestr (match-end 0))
4882 timestr (substring timestr 0 (match-end 0)))
4883 (if (and (not closedp) (not statep)
4884 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4885 (progn (setq timestr (concat (substring timestr 0 -1)
4886 "-" (match-string 1 rest) "]"))
4887 (setq clocked (match-string 2 rest)))
4888 (setq clocked "-")))
4889 (save-excursion
4890 (setq extra
4891 (cond
4892 ((not org-agenda-log-mode-add-notes) nil)
4893 (statep
4894 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4895 (match-string 1)))
4896 (clockp
4897 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4898 (match-string 1)))))
4899 (if (not (re-search-backward "^\\*+ " nil t))
4900 (setq txt org-agenda-no-heading-message)
4901 (goto-char (match-beginning 0))
4902 (setq hdmarker (org-agenda-new-marker)
4903 tags (org-get-tags-at))
4904 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4905 (setq txt (match-string 1))
4906 (when extra
4907 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4908 (setq txt (concat (substring txt 0 (match-beginning 1))
4909 " - " extra " " (match-string 2 txt)))
4910 (setq txt (concat txt " - " extra))))
4911 (setq txt (org-format-agenda-item
4912 (cond
4913 (closedp "Closed: ")
4914 (statep (concat "State: (" state ")"))
4915 (t (concat "Clocked: (" clocked ")")))
4916 txt category tags timestr)))
4917 (setq priority 100000)
4918 (org-add-props txt props
4919 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4920 'priority priority 'org-category category
4921 'type "closed" 'date date
4922 'undone-face 'org-warning 'done-face 'org-agenda-done)
4923 (push txt ee))
4924 (goto-char (point-at-eol))))
4925 (nreverse ee)))
4927 (defun org-agenda-get-deadlines ()
4928 "Return the deadline information for agenda display."
4929 (let* ((props (list 'mouse-face 'highlight
4930 'org-not-done-regexp org-not-done-regexp
4931 'org-todo-regexp org-todo-regexp
4932 'org-complex-heading-regexp org-complex-heading-regexp
4933 'help-echo
4934 (format "mouse-2 or RET jump to org file %s"
4935 (abbreviate-file-name buffer-file-name))))
4936 (regexp org-deadline-time-regexp)
4937 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4938 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4939 d2 diff dfrac wdays pos pos1 category tags
4940 suppress-prewarning
4941 ee txt head face s todo-state show-all upcomingp donep timestr)
4942 (goto-char (point-min))
4943 (while (re-search-forward regexp nil t)
4944 (setq suppress-prewarning nil)
4945 (catch :skip
4946 (org-agenda-skip)
4947 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4948 (save-match-data
4949 (string-match org-scheduled-time-regexp
4950 (buffer-substring (point-at-bol)
4951 (point-at-eol)))))
4952 (setq suppress-prewarning
4953 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4954 org-agenda-skip-deadline-prewarning-if-scheduled
4955 0)))
4956 (setq s (match-string 1)
4957 txt nil
4958 pos (1- (match-beginning 1))
4959 todo-state (save-match-data (org-get-todo-state))
4960 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4961 (member todo-state
4962 org-agenda-repeating-timestamp-show-all))
4963 d2 (org-time-string-to-absolute
4964 (match-string 1) d1 'past show-all)
4965 diff (- d2 d1)
4966 wdays (if suppress-prewarning
4967 (let ((org-deadline-warning-days suppress-prewarning))
4968 (org-get-wdays s))
4969 (org-get-wdays s))
4970 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4971 upcomingp (and todayp (> diff 0)))
4972 ;; When to show a deadline in the calendar:
4973 ;; If the expiration is within wdays warning time.
4974 ;; Past-due deadlines are only shown on the current date
4975 (if (and (or (and (<= diff wdays)
4976 (and todayp (not org-agenda-only-exact-dates)))
4977 (= diff 0)))
4978 (save-excursion
4979 ;; (setq todo-state (org-get-todo-state))
4980 (setq donep (member todo-state org-done-keywords))
4981 (if (and donep
4982 (or org-agenda-skip-deadline-if-done
4983 (not (= diff 0))))
4984 (setq txt nil)
4985 (setq category (org-get-category))
4986 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4987 (setq txt org-agenda-no-heading-message)
4988 (goto-char (match-end 0))
4989 (setq pos1 (match-beginning 0))
4990 (setq tags (org-get-tags-at pos1))
4991 (setq head (buffer-substring-no-properties
4992 (point)
4993 (progn (skip-chars-forward "^\r\n")
4994 (point))))
4995 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4996 (setq timestr
4997 (concat (substring s (match-beginning 1)) " "))
4998 (setq timestr 'time))
4999 (setq txt (org-format-agenda-item
5000 (if (= diff 0)
5001 (car org-agenda-deadline-leaders)
5002 (if (functionp
5003 (nth 1 org-agenda-deadline-leaders))
5004 (funcall
5005 (nth 1 org-agenda-deadline-leaders)
5006 diff date)
5007 (format (nth 1 org-agenda-deadline-leaders)
5008 diff)))
5009 head category tags
5010 (if (not (= diff 0)) nil timestr)))))
5011 (when txt
5012 (setq face (org-agenda-deadline-face dfrac wdays))
5013 (org-add-props txt props
5014 'org-marker (org-agenda-new-marker pos)
5015 'org-hd-marker (org-agenda-new-marker pos1)
5016 'priority (+ (- diff)
5017 (org-get-priority txt))
5018 'org-category category
5019 'todo-state todo-state
5020 'type (if upcomingp "upcoming-deadline" "deadline")
5021 'date (if upcomingp date d2)
5022 'face (if donep 'org-agenda-done face)
5023 'undone-face face 'done-face 'org-agenda-done)
5024 (push txt ee))))))
5025 (nreverse ee)))
5027 (defun org-agenda-deadline-face (fraction &optional wdays)
5028 "Return the face to displaying a deadline item.
5029 FRACTION is what fraction of the head-warning time has passed."
5030 (if (equal wdays 0) (setq fraction 1.))
5031 (let ((faces org-agenda-deadline-faces) f)
5032 (catch 'exit
5033 (while (setq f (pop faces))
5034 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5036 (defun org-agenda-get-scheduled (&optional deadline-results)
5037 "Return the scheduled information for agenda display."
5038 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5039 'org-todo-regexp org-todo-regexp
5040 'org-complex-heading-regexp org-complex-heading-regexp
5041 'done-face 'org-agenda-done
5042 'mouse-face 'highlight
5043 'help-echo
5044 (format "mouse-2 or RET jump to org file %s"
5045 (abbreviate-file-name buffer-file-name))))
5046 (regexp org-scheduled-time-regexp)
5047 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5048 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5050 (deadline-position-alist
5051 (mapcar (lambda (a) (and (setq mm (get-text-property
5052 0 'org-hd-marker a))
5053 (cons (marker-position mm) a)))
5054 deadline-results))
5055 d2 diff pos pos1 category tags donep
5056 ee txt head pastschedp todo-state face timestr s habitp show-all)
5057 (goto-char (point-min))
5058 (while (re-search-forward regexp nil t)
5059 (catch :skip
5060 (org-agenda-skip)
5061 (setq s (match-string 1)
5062 txt nil
5063 pos (1- (match-beginning 1))
5064 todo-state (save-match-data (org-get-todo-state))
5065 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5066 (member todo-state
5067 org-agenda-repeating-timestamp-show-all))
5068 d2 (org-time-string-to-absolute
5069 (match-string 1) d1 'past show-all)
5070 diff (- d2 d1))
5071 (setq pastschedp (and todayp (< diff 0)))
5072 ;; When to show a scheduled item in the calendar:
5073 ;; If it is on or past the date.
5074 (when (or (and (< diff 0)
5075 (< (abs diff) org-scheduled-past-days)
5076 (and todayp (not org-agenda-only-exact-dates)))
5077 (= diff 0))
5078 (save-excursion
5079 (setq donep (member todo-state org-done-keywords))
5080 (if (and donep
5081 (or org-agenda-skip-scheduled-if-done
5082 (not (= diff 0))
5083 (and (functionp 'org-is-habit-p)
5084 (org-is-habit-p))))
5085 (setq txt nil)
5086 (setq habitp (and (functionp 'org-is-habit-p)
5087 (org-is-habit-p)))
5088 (setq category (org-get-category))
5089 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5090 (setq txt org-agenda-no-heading-message)
5091 (goto-char (match-end 0))
5092 (setq pos1 (match-beginning 0))
5093 (if habitp
5094 (if (or (not org-habit-show-habits)
5095 (and (not todayp)
5096 org-habit-show-habits-only-for-today))
5097 (throw :skip nil))
5098 (if (and
5099 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5100 (and org-agenda-skip-scheduled-if-deadline-is-shown
5101 pastschedp))
5102 (setq mm (assoc pos1 deadline-position-alist)))
5103 (throw :skip nil)))
5104 (setq tags (org-get-tags-at))
5105 (setq head (buffer-substring-no-properties
5106 (point)
5107 (progn (skip-chars-forward "^\r\n") (point))))
5108 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5109 (setq timestr
5110 (concat (substring s (match-beginning 1)) " "))
5111 (setq timestr 'time))
5112 (setq txt (org-format-agenda-item
5113 (if (= diff 0)
5114 (car org-agenda-scheduled-leaders)
5115 (format (nth 1 org-agenda-scheduled-leaders)
5116 (- 1 diff)))
5117 head category tags
5118 (if (not (= diff 0)) nil timestr)
5119 nil nil habitp))))
5120 (when txt
5121 (setq face
5122 (cond
5123 ((and (not habitp) pastschedp)
5124 'org-scheduled-previously)
5125 (todayp 'org-scheduled-today)
5126 (t 'org-scheduled))
5127 habitp (and habitp (org-habit-parse-todo)))
5128 (org-add-props txt props
5129 'undone-face face
5130 'face (if donep 'org-agenda-done face)
5131 'org-marker (org-agenda-new-marker pos)
5132 'org-hd-marker (org-agenda-new-marker pos1)
5133 'type (if pastschedp "past-scheduled" "scheduled")
5134 'date (if pastschedp d2 date)
5135 'priority (if habitp
5136 (org-habit-get-priority habitp)
5137 (+ 94 (- 5 diff) (org-get-priority txt)))
5138 'org-category category
5139 'org-habit-p habitp
5140 'todo-state todo-state)
5141 (push txt ee))))))
5142 (nreverse ee)))
5144 (defun org-agenda-get-blocks ()
5145 "Return the date-range information for agenda display."
5146 (let* ((props (list 'face nil
5147 'org-not-done-regexp org-not-done-regexp
5148 'org-todo-regexp org-todo-regexp
5149 'org-complex-heading-regexp org-complex-heading-regexp
5150 'mouse-face 'highlight
5151 'help-echo
5152 (format "mouse-2 or RET jump to org file %s"
5153 (abbreviate-file-name buffer-file-name))))
5154 (regexp org-tr-regexp)
5155 (d0 (calendar-absolute-from-gregorian date))
5156 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5157 head donep)
5158 (goto-char (point-min))
5159 (while (re-search-forward regexp nil t)
5160 (catch :skip
5161 (org-agenda-skip)
5162 (setq pos (point))
5163 (let ((start-time (match-string 1))
5164 (end-time (match-string 2)))
5165 (setq s1 (match-string 1)
5166 s2 (match-string 2)
5167 d1 (time-to-days (org-time-string-to-time s1))
5168 d2 (time-to-days (org-time-string-to-time s2)))
5169 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5170 ;; Only allow days between the limits, because the normal
5171 ;; date stamps will catch the limits.
5172 (save-excursion
5173 (setq todo-state (org-get-todo-state))
5174 (setq donep (member todo-state org-done-keywords))
5175 (if (and donep org-agenda-skip-timestamp-if-done)
5176 (throw :skip t))
5177 (setq marker (org-agenda-new-marker (point)))
5178 (setq category (org-get-category))
5179 (if (not (re-search-backward "^\\*+ " nil t))
5180 (setq txt org-agenda-no-heading-message)
5181 (goto-char (match-beginning 0))
5182 (setq hdmarker (org-agenda-new-marker (point)))
5183 (setq tags (org-get-tags-at))
5184 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5185 (setq head (match-string 1))
5186 (let ((remove-re
5187 (if org-agenda-remove-timeranges-from-blocks
5188 (concat
5189 "<" (regexp-quote s1) ".*?>"
5190 "--"
5191 "<" (regexp-quote s2) ".*?>")
5192 nil)))
5193 (setq txt (org-format-agenda-item
5194 (format
5195 (nth (if (= d1 d2) 0 1)
5196 org-agenda-timerange-leaders)
5197 (1+ (- d0 d1)) (1+ (- d2 d1)))
5198 head category tags
5199 (cond ((= d1 d0)
5200 (concat "<" start-time ">"))
5201 ((= d2 d0)
5202 (concat "<" end-time ">"))
5203 (t nil))
5204 remove-re))))
5205 (org-add-props txt props
5206 'org-marker marker 'org-hd-marker hdmarker
5207 'type "block" 'date date
5208 'todo-state todo-state
5209 'priority (org-get-priority txt) 'org-category category)
5210 (push txt ee))))
5211 (goto-char pos)))
5212 ;; Sort the entries by expiration date.
5213 (nreverse ee)))
5215 ;;; Agenda presentation and sorting
5217 (defvar org-prefix-has-time nil
5218 "A flag, set by `org-compile-prefix-format'.
5219 The flag is set if the currently compiled format contains a `%t'.")
5220 (defvar org-prefix-has-tag nil
5221 "A flag, set by `org-compile-prefix-format'.
5222 The flag is set if the currently compiled format contains a `%T'.")
5223 (defvar org-prefix-has-effort nil
5224 "A flag, set by `org-compile-prefix-format'.
5225 The flag is set if the currently compiled format contains a `%e'.")
5226 (defvar org-prefix-category-length nil
5227 "Used by `org-compile-prefix-format' to remember the category field width.")
5228 (defvar org-prefix-category-max-length nil
5229 "Used by `org-compile-prefix-format' to remember the category field width.")
5231 (defun org-agenda-get-category-icon (category)
5232 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5233 (dolist (entry org-agenda-category-icon-alist)
5234 (when (org-string-match-p (car entry) category)
5235 (if (listp (cadr entry))
5236 (return (cadr entry))
5237 (return (apply 'create-image (cdr entry)))))))
5239 (defun org-format-agenda-item (extra txt &optional category tags dotime
5240 noprefix remove-re habitp)
5241 "Format TXT to be inserted into the agenda buffer.
5242 In particular, it adds the prefix and corresponding text properties. EXTRA
5243 must be a string and replaces the `%s' specifier in the prefix format.
5244 CATEGORY (string, symbol or nil) may be used to overrule the default
5245 category taken from local variable or file name. It will replace the `%c'
5246 specifier in the format. DOTIME, when non-nil, indicates that a
5247 time-of-day should be extracted from TXT for sorting of this entry, and for
5248 the `%t' specifier in the format. When DOTIME is a string, this string is
5249 searched for a time before TXT is. NOPREFIX is a flag and indicates that
5250 only the correctly processes TXT should be returned - this is used by
5251 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
5252 Any match of REMOVE-RE will be removed from TXT."
5253 (save-match-data
5254 ;; Diary entries sometimes have extra whitespace at the beginning
5255 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5257 ;; Fix the tags part in txt
5258 (setq txt (org-agenda-fix-displayed-tags
5259 txt tags
5260 org-agenda-show-inherited-tags
5261 org-agenda-hide-tags-regexp))
5262 (let* ((category (or category
5263 (if (stringp org-category)
5264 org-category
5265 (and org-category (symbol-name org-category)))
5266 (if buffer-file-name
5267 (file-name-sans-extension
5268 (file-name-nondirectory buffer-file-name))
5269 "")))
5270 (category-icon (org-agenda-get-category-icon category))
5271 (category-icon (if category-icon
5272 (propertize " " 'display category-icon)
5273 ""))
5274 ;; time, tag, effort are needed for the eval of the prefix format
5275 (tag (if tags (nth (1- (length tags)) tags) ""))
5276 time effort neffort
5277 (ts (if dotime (concat
5278 (if (stringp dotime) dotime "")
5279 (and org-agenda-search-headline-for-time txt))))
5280 (time-of-day (and dotime (org-get-time-of-day ts)))
5281 stamp plain s0 s1 s2 rtn srp l
5282 duration thecategory)
5283 (and (org-mode-p) buffer-file-name
5284 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5285 (when (and dotime time-of-day)
5286 ;; Extract starting and ending time and move them to prefix
5287 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5288 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5289 (setq s0 (match-string 0 ts)
5290 srp (and stamp (match-end 3))
5291 s1 (match-string (if plain 1 2) ts)
5292 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5294 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5295 ;; them, we might want to remove them there to avoid duplication.
5296 ;; The user can turn this off with a variable.
5297 (if (and org-prefix-has-time
5298 org-agenda-remove-times-when-in-prefix (or stamp plain)
5299 (string-match (concat (regexp-quote s0) " *") txt)
5300 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5301 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5302 (= (match-beginning 0) 0)
5304 (setq txt (replace-match "" nil nil txt))))
5305 ;; Normalize the time(s) to 24 hour
5306 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5307 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5309 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5310 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5311 (setq s2
5312 (org-minutes-to-hh:mm-string
5313 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5315 ;; Compute the duration
5316 (when s2
5317 (setq duration (- (org-hh:mm-string-to-minutes s2)
5318 (org-hh:mm-string-to-minutes s1)))))
5320 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5321 txt)
5322 ;; Tags are in the string
5323 (if (or (eq org-agenda-remove-tags t)
5324 (and org-agenda-remove-tags
5325 org-prefix-has-tag))
5326 (setq txt (replace-match "" t t txt))
5327 (setq txt (replace-match
5328 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5329 (match-string 2 txt))
5330 t t txt))))
5331 (when (org-mode-p)
5332 (setq effort
5333 (condition-case nil
5334 (org-get-effort
5335 (or (get-text-property 0 'org-hd-marker txt)
5336 (get-text-property 0 'org-marker txt)))
5337 (error nil)))
5338 (when effort
5339 (setq neffort (org-hh:mm-string-to-minutes effort)
5340 effort (setq effort (concat "[" effort "]" )))))
5342 (when remove-re
5343 (while (string-match remove-re txt)
5344 (setq txt (replace-match "" t t txt))))
5346 ;; Create the final string
5347 (if noprefix
5348 (setq rtn txt)
5349 ;; Prepare the variables needed in the eval of the compiled format
5350 (setq time (cond (s2 (concat
5351 (org-agenda-time-of-day-to-ampm-maybe s1)
5352 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5353 (if org-agenda-timegrid-use-ampm " ")))
5354 (s1 (concat
5355 (org-agenda-time-of-day-to-ampm-maybe s1)
5356 (if org-agenda-timegrid-use-ampm
5357 "........ "
5358 "......")))
5359 (t ""))
5360 extra (or (and (not habitp) extra) "")
5361 category (if (symbolp category) (symbol-name category) category)
5362 thecategory (copy-sequence category))
5363 (if (string-match org-bracket-link-regexp category)
5364 (progn
5365 (setq l (if (match-end 3)
5366 (- (match-end 3) (match-beginning 3))
5367 (- (match-end 1) (match-beginning 1))))
5368 (when (< l (or org-prefix-category-length 0))
5369 (setq category (copy-sequence category))
5370 (org-add-props category nil
5371 'extra-space (make-string
5372 (- org-prefix-category-length l 1) ?\ ))))
5373 (if (and org-prefix-category-max-length
5374 (>= (length category) org-prefix-category-max-length))
5375 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5376 ;; Evaluate the compiled format
5377 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5379 ;; And finally add the text properties
5380 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5381 (org-add-props rtn nil
5382 'org-category (if thecategory (downcase thecategory) category)
5383 'tags (mapcar 'org-downcase-keep-props tags)
5384 'org-highest-priority org-highest-priority
5385 'org-lowest-priority org-lowest-priority
5386 'prefix-length (- (length rtn) (length txt))
5387 'time-of-day time-of-day
5388 'duration duration
5389 'effort effort
5390 'effort-minutes neffort
5391 'txt txt
5392 'time time
5393 'extra extra
5394 'dotime dotime))))
5396 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5397 "Remove tags string from TXT, and add a modified list of tags.
5398 The modified list may contain inherited tags, and tags matched by
5399 `org-agenda-hide-tags-regexp' will be removed."
5400 (when (or add-inherited hide-re)
5401 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5402 (setq txt (substring txt 0 (match-beginning 0))))
5403 (setq tags
5404 (delq nil
5405 (mapcar (lambda (tg)
5406 (if (or (and hide-re (string-match hide-re tg))
5407 (and (not add-inherited)
5408 (get-text-property 0 'inherited tg)))
5410 tg))
5411 tags)))
5412 (when tags
5413 (let ((have-i (get-text-property 0 'inherited (car tags)))
5415 (setq txt (concat txt " :"
5416 (mapconcat
5417 (lambda (x)
5418 (setq i (get-text-property 0 'inherited x))
5419 (if (and have-i (not i))
5420 (progn
5421 (setq have-i nil)
5422 (concat ":" x))
5424 tags ":")
5425 (if have-i "::" ":"))))))
5426 txt)
5428 (defun org-downcase-keep-props (s)
5429 (let ((props (text-properties-at 0 s)))
5430 (setq s (downcase s))
5431 (add-text-properties 0 (length s) props s)
5434 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5435 (defvar org-agenda-sorting-strategy-selected nil)
5437 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5438 (catch 'exit
5439 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5440 ((and todayp (member 'today (car org-agenda-time-grid))))
5441 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5442 ((member 'weekly (car org-agenda-time-grid)))
5443 (t (throw 'exit list)))
5444 (let* ((have (delq nil (mapcar
5445 (lambda (x) (get-text-property 1 'time-of-day x))
5446 list)))
5447 (string (nth 1 org-agenda-time-grid))
5448 (gridtimes (nth 2 org-agenda-time-grid))
5449 (req (car org-agenda-time-grid))
5450 (remove (member 'remove-match req))
5451 new time)
5452 (if (and (member 'require-timed req) (not have))
5453 ;; don't show empty grid
5454 (throw 'exit list))
5455 (while (setq time (pop gridtimes))
5456 (unless (and remove (member time have))
5457 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5458 (push (org-format-agenda-item
5459 nil string "" nil
5460 (concat (substring time 0 -2) ":" (substring time -2)))
5461 new)
5462 (put-text-property
5463 2 (length (car new)) 'face 'org-time-grid (car new))))
5464 (when (and todayp org-agenda-show-current-time-in-grid)
5465 (push (org-format-agenda-item
5466 nil
5467 org-agenda-current-time-string
5468 "" nil
5469 (format-time-string "%H:%M "))
5470 new)
5471 (put-text-property
5472 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5474 (if (member 'time-up org-agenda-sorting-strategy-selected)
5475 (append new list)
5476 (append list new)))))
5478 (defun org-compile-prefix-format (key)
5479 "Compile the prefix format into a Lisp form that can be evaluated.
5480 The resulting form is returned and stored in the variable
5481 `org-prefix-format-compiled'."
5482 (setq org-prefix-has-time nil org-prefix-has-tag nil
5483 org-prefix-category-length nil org-prefix-has-effort nil)
5484 (let ((s (cond
5485 ((stringp org-agenda-prefix-format)
5486 org-agenda-prefix-format)
5487 ((assq key org-agenda-prefix-format)
5488 (cdr (assq key org-agenda-prefix-format)))
5489 (t " %-12:c%?-12t% s")))
5490 (start 0)
5491 varform vars var e c f opt)
5492 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5493 s start)
5494 (setq var (or (cdr (assoc (match-string 4 s)
5495 '(("c" . category) ("t" . time) ("s" . extra)
5496 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5497 'eval)
5498 c (or (match-string 3 s) "")
5499 opt (match-beginning 1)
5500 start (1+ (match-beginning 0)))
5501 (if (equal var 'time) (setq org-prefix-has-time t))
5502 (if (equal var 'tag) (setq org-prefix-has-tag t))
5503 (if (equal var 'effort) (setq org-prefix-has-effort t))
5504 (setq f (concat "%" (match-string 2 s) "s"))
5505 (when (equal var 'category)
5506 (setq org-prefix-category-length
5507 (floor (abs (string-to-number (match-string 2 s)))))
5508 (setq org-prefix-category-max-length
5509 (let ((x (match-string 2 s)))
5510 (save-match-data
5511 (if (string-match "\\.[0-9]+" x)
5512 (string-to-number (substring (match-string 0 x) 1)))))))
5513 (if (eq var 'eval)
5514 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5515 (if opt
5516 (setq varform
5517 `(if (equal "" ,var)
5519 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5520 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5521 (setq s (replace-match "%s" t nil s))
5522 (push varform vars))
5523 (setq vars (nreverse vars))
5524 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5526 (defun org-set-sorting-strategy (key)
5527 (if (symbolp (car org-agenda-sorting-strategy))
5528 ;; the old format
5529 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5530 (setq org-agenda-sorting-strategy-selected
5531 (or (cdr (assq key org-agenda-sorting-strategy))
5532 (cdr (assq 'agenda org-agenda-sorting-strategy))
5533 '(time-up category-keep priority-down)))))
5535 (defun org-get-time-of-day (s &optional string mod24)
5536 "Check string S for a time of day.
5537 If found, return it as a military time number between 0 and 2400.
5538 If not found, return nil.
5539 The optional STRING argument forces conversion into a 5 character wide string
5540 HH:MM."
5541 (save-match-data
5542 (when
5543 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5544 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5545 (let* ((h (string-to-number (match-string 1 s)))
5546 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5547 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5548 (am-p (equal ampm "am"))
5549 (h1 (cond ((not ampm) h)
5550 ((= h 12) (if am-p 0 12))
5551 (t (+ h (if am-p 0 12)))))
5552 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5553 (mod h1 24) h1))
5554 (t0 (+ (* 100 h2) m))
5555 (t1 (concat (if (>= h1 24) "+" " ")
5556 (if (and org-agenda-time-leading-zero
5557 (< t0 1000)) "0" "")
5558 (if (< t0 100) "0" "")
5559 (if (< t0 10) "0" "")
5560 (int-to-string t0))))
5561 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5563 (defvar org-agenda-before-sorting-filter-function nil
5564 "Function to be applied to agenda items prior to sorting.
5565 Prior to sorting also means just before they are inserted into the agenda.
5567 To aid sorting, you may revisit the original entries and add more text
5568 properties which will later be used by the sorting functions.
5570 The function should take a string argument, an agenda line.
5571 It has access to the text properties in that line, which contain among
5572 other things, the property `org-hd-marker' that points to the entry
5573 where the line comes from. Note that not all lines going into the agenda
5574 have this property, only most.
5576 The function should return the modified string. It is probably best
5577 to ONLY change text properties.
5579 You can also use this function as a filter, by returning nil for lines
5580 you don't want to have in the agenda at all. For this application, you
5581 could bind the variable in the options section of a custom command.")
5583 (defun org-finalize-agenda-entries (list &optional nosort)
5584 "Sort and concatenate the agenda items."
5585 (setq list (mapcar 'org-agenda-highlight-todo list))
5586 (if nosort
5587 list
5588 (when org-agenda-before-sorting-filter-function
5589 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5590 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5592 (defun org-agenda-highlight-todo (x)
5593 (let ((org-done-keywords org-done-keywords-for-agenda)
5594 (case-fold-search nil)
5595 re pl)
5596 (if (eq x 'line)
5597 (save-excursion
5598 (beginning-of-line 1)
5599 (setq re (org-get-at-bol 'org-todo-regexp))
5600 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5601 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5602 (add-text-properties (match-beginning 0) (match-end 1)
5603 (list 'face (org-get-todo-face 1)))
5604 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5605 (delete-region (match-beginning 1) (1- (match-end 0)))
5606 (goto-char (match-beginning 1))
5607 (insert (format org-agenda-todo-keyword-format s)))))
5608 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5609 pl (get-text-property 0 'prefix-length x))
5610 (when (and re
5611 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5612 x (or pl 0)) pl))
5613 (add-text-properties
5614 (or (match-end 1) (match-end 0)) (match-end 0)
5615 (list 'face (org-get-todo-face (match-string 2 x)))
5617 (when (match-end 1)
5618 (setq x (concat (substring x 0 (match-end 1))
5619 (format org-agenda-todo-keyword-format
5620 (match-string 2 x))
5621 (org-add-props " " (text-properties-at 0 x))
5622 (substring x (match-end 3))))))
5623 x)))
5625 (defsubst org-cmp-priority (a b)
5626 "Compare the priorities of string A and B."
5627 (let ((pa (or (get-text-property 1 'priority a) 0))
5628 (pb (or (get-text-property 1 'priority b) 0)))
5629 (cond ((> pa pb) +1)
5630 ((< pa pb) -1)
5631 (t nil))))
5633 (defsubst org-cmp-effort (a b)
5634 "Compare the priorities of string A and B."
5635 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5636 (ea (or (get-text-property 1 'effort-minutes a) def))
5637 (eb (or (get-text-property 1 'effort-minutes b) def)))
5638 (cond ((> ea eb) +1)
5639 ((< ea eb) -1)
5640 (t nil))))
5642 (defsubst org-cmp-category (a b)
5643 "Compare the string values of categories of strings A and B."
5644 (let ((ca (or (get-text-property 1 'org-category a) ""))
5645 (cb (or (get-text-property 1 'org-category b) "")))
5646 (cond ((string-lessp ca cb) -1)
5647 ((string-lessp cb ca) +1)
5648 (t nil))))
5650 (defsubst org-cmp-todo-state (a b)
5651 "Compare the todo states of strings A and B."
5652 (let* ((ma (or (get-text-property 1 'org-marker a)
5653 (get-text-property 1 'org-hd-marker a)))
5654 (mb (or (get-text-property 1 'org-marker b)
5655 (get-text-property 1 'org-hd-marker b)))
5656 (fa (and ma (marker-buffer ma)))
5657 (fb (and mb (marker-buffer mb)))
5658 (todo-kwds
5659 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5660 (and fb (with-current-buffer fb org-todo-keywords-1))))
5661 (ta (or (get-text-property 1 'todo-state a) ""))
5662 (tb (or (get-text-property 1 'todo-state b) ""))
5663 (la (- (length (member ta todo-kwds))))
5664 (lb (- (length (member tb todo-kwds))))
5665 (donepa (member ta org-done-keywords-for-agenda))
5666 (donepb (member tb org-done-keywords-for-agenda)))
5667 (cond ((and donepa (not donepb)) -1)
5668 ((and (not donepa) donepb) +1)
5669 ((< la lb) -1)
5670 ((< lb la) +1)
5671 (t nil))))
5673 (defsubst org-cmp-alpha (a b)
5674 "Compare the headlines, alphabetically."
5675 (let* ((pla (get-text-property 0 'prefix-length a))
5676 (plb (get-text-property 0 'prefix-length b))
5677 (ta (and pla (substring a pla)))
5678 (tb (and plb (substring b plb))))
5679 (when pla
5680 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5681 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5682 (setq ta (substring ta (match-end 0))))
5683 (setq ta (downcase ta)))
5684 (when plb
5685 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5686 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5687 (setq tb (substring tb (match-end 0))))
5688 (setq tb (downcase tb)))
5689 (cond ((not ta) +1)
5690 ((not tb) -1)
5691 ((string-lessp ta tb) -1)
5692 ((string-lessp tb ta) +1)
5693 (t nil))))
5695 (defsubst org-cmp-tag (a b)
5696 "Compare the string values of the first tags of A and B."
5697 (let ((ta (car (last (get-text-property 1 'tags a))))
5698 (tb (car (last (get-text-property 1 'tags b)))))
5699 (cond ((not ta) +1)
5700 ((not tb) -1)
5701 ((string-lessp ta tb) -1)
5702 ((string-lessp tb ta) +1)
5703 (t nil))))
5705 (defsubst org-cmp-time (a b)
5706 "Compare the time-of-day values of strings A and B."
5707 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5708 (ta (or (get-text-property 1 'time-of-day a) def))
5709 (tb (or (get-text-property 1 'time-of-day b) def)))
5710 (cond ((< ta tb) -1)
5711 ((< tb ta) +1)
5712 (t nil))))
5714 (defsubst org-cmp-habit-p (a b)
5715 "Compare the todo states of strings A and B."
5716 (let ((ha (get-text-property 1 'org-habit-p a))
5717 (hb (get-text-property 1 'org-habit-p b)))
5718 (cond ((and ha (not hb)) -1)
5719 ((and (not ha) hb) +1)
5720 (t nil))))
5722 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5724 (defun org-entries-lessp (a b)
5725 "Predicate for sorting agenda entries."
5726 ;; The following variables will be used when the form is evaluated.
5727 ;; So even though the compiler complains, keep them.
5728 (let* ((ss org-agenda-sorting-strategy-selected)
5729 (time-up (and (org-em 'time-up 'time-down ss)
5730 (org-cmp-time a b)))
5731 (time-down (if time-up (- time-up) nil))
5732 (priority-up (and (org-em 'priority-up 'priority-down ss)
5733 (org-cmp-priority a b)))
5734 (priority-down (if priority-up (- priority-up) nil))
5735 (effort-up (and (org-em 'effort-up 'effort-down ss)
5736 (org-cmp-effort a b)))
5737 (effort-down (if effort-up (- effort-up) nil))
5738 (category-up (and (or (org-em 'category-up 'category-down ss)
5739 (memq 'category-keep ss))
5740 (org-cmp-category a b)))
5741 (category-down (if category-up (- category-up) nil))
5742 (category-keep (if category-up +1 nil))
5743 (tag-up (and (org-em 'tag-up 'tag-down ss)
5744 (org-cmp-tag a b)))
5745 (tag-down (if tag-up (- tag-up) nil))
5746 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5747 (org-cmp-todo-state a b)))
5748 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5749 (habit-up (and (org-em 'habit-up 'habit-down ss)
5750 (org-cmp-habit-p a b)))
5751 (habit-down (if habit-up (- habit-up) nil))
5752 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5753 (org-cmp-alpha a b)))
5754 (alpha-down (if alpha-up (- alpha-up) nil))
5755 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5756 user-defined-up user-defined-down)
5757 (if (and need-user-cmp org-agenda-cmp-user-defined
5758 (functionp org-agenda-cmp-user-defined))
5759 (setq user-defined-up
5760 (funcall org-agenda-cmp-user-defined a b)
5761 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5762 (cdr (assoc
5763 (eval (cons 'or org-agenda-sorting-strategy-selected))
5764 '((-1 . t) (1 . nil) (nil . nil))))))
5766 ;;; Agenda restriction lock
5768 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5769 "Overlay to mark the headline to which agenda commands are restricted.")
5770 (overlay-put org-agenda-restriction-lock-overlay
5771 'face 'org-agenda-restriction-lock)
5772 (overlay-put org-agenda-restriction-lock-overlay
5773 'help-echo "Agendas are currently limited to this subtree.")
5774 (org-detach-overlay org-agenda-restriction-lock-overlay)
5776 (defun org-agenda-set-restriction-lock (&optional type)
5777 "Set restriction lock for agenda, to current subtree or file.
5778 Restriction will be the file if TYPE is `file', or if type is the
5779 universal prefix '(4), or if the cursor is before the first headline
5780 in the file. Otherwise, restriction will be to the current subtree."
5781 (interactive "P")
5782 (and (equal type '(4)) (setq type 'file))
5783 (setq type (cond
5784 (type type)
5785 ((org-at-heading-p) 'subtree)
5786 ((condition-case nil (org-back-to-heading t) (error nil))
5787 'subtree)
5788 (t 'file)))
5789 (if (eq type 'subtree)
5790 (progn
5791 (setq org-agenda-restrict t)
5792 (setq org-agenda-overriding-restriction 'subtree)
5793 (put 'org-agenda-files 'org-restrict
5794 (list (buffer-file-name (buffer-base-buffer))))
5795 (org-back-to-heading t)
5796 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5797 (move-marker org-agenda-restrict-begin (point))
5798 (move-marker org-agenda-restrict-end
5799 (save-excursion (org-end-of-subtree t)))
5800 (message "Locking agenda restriction to subtree"))
5801 (put 'org-agenda-files 'org-restrict
5802 (list (buffer-file-name (buffer-base-buffer))))
5803 (setq org-agenda-restrict nil)
5804 (setq org-agenda-overriding-restriction 'file)
5805 (move-marker org-agenda-restrict-begin nil)
5806 (move-marker org-agenda-restrict-end nil)
5807 (message "Locking agenda restriction to file"))
5808 (setq current-prefix-arg nil)
5809 (org-agenda-maybe-redo))
5811 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5812 "Remove the agenda restriction lock."
5813 (interactive "P")
5814 (org-detach-overlay org-agenda-restriction-lock-overlay)
5815 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5816 (setq org-agenda-overriding-restriction nil)
5817 (setq org-agenda-restrict nil)
5818 (put 'org-agenda-files 'org-restrict nil)
5819 (move-marker org-agenda-restrict-begin nil)
5820 (move-marker org-agenda-restrict-end nil)
5821 (setq current-prefix-arg nil)
5822 (message "Agenda restriction lock removed")
5823 (or noupdate (org-agenda-maybe-redo)))
5825 (defun org-agenda-maybe-redo ()
5826 "If there is any window showing the agenda view, update it."
5827 (let ((w (get-buffer-window org-agenda-buffer-name t))
5828 (w0 (selected-window)))
5829 (when w
5830 (select-window w)
5831 (org-agenda-redo)
5832 (select-window w0)
5833 (if org-agenda-overriding-restriction
5834 (message "Agenda view shifted to new %s restriction"
5835 org-agenda-overriding-restriction)
5836 (message "Agenda restriction lock removed")))))
5838 ;;; Agenda commands
5840 (defun org-agenda-check-type (error &rest types)
5841 "Check if agenda buffer is of allowed type.
5842 If ERROR is non-nil, throw an error, otherwise just return nil."
5843 (if (memq org-agenda-type types)
5845 (if error
5846 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5847 nil)))
5849 (defun org-agenda-quit ()
5850 "Exit agenda by removing the window or the buffer."
5851 (interactive)
5852 (if org-agenda-columns-active
5853 (org-columns-quit)
5854 (let ((buf (current-buffer)))
5855 (if (eq org-agenda-window-setup 'other-frame)
5856 (progn
5857 (kill-buffer buf)
5858 (org-agenda-reset-markers)
5859 (org-columns-remove-overlays)
5860 (setq org-agenda-archives-mode nil)
5861 (delete-frame))
5862 (and (not (eq org-agenda-window-setup 'current-window))
5863 (not (one-window-p))
5864 (delete-window))
5865 (kill-buffer buf)
5866 (org-agenda-reset-markers)
5867 (org-columns-remove-overlays)
5868 (setq org-agenda-archives-mode nil)))
5869 ;; Maybe restore the pre-agenda window configuration.
5870 (and org-agenda-restore-windows-after-quit
5871 (not (eq org-agenda-window-setup 'other-frame))
5872 org-pre-agenda-window-conf
5873 (set-window-configuration org-pre-agenda-window-conf))))
5875 (defun org-agenda-exit ()
5876 "Exit agenda by removing the window or the buffer.
5877 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5878 Org-mode buffers visited directly by the user will not be touched."
5879 (interactive)
5880 (org-release-buffers org-agenda-new-buffers)
5881 (setq org-agenda-new-buffers nil)
5882 (org-agenda-quit))
5884 (defun org-agenda-execute (arg)
5885 "Execute another agenda command, keeping same window.
5886 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5887 in the agenda."
5888 (interactive "P")
5889 (let ((org-agenda-window-setup 'current-window))
5890 (org-agenda arg)))
5892 (defun org-agenda-redo ()
5893 "Rebuild Agenda.
5894 When this is the global TODO list, a prefix argument will be interpreted."
5895 (interactive)
5896 (let* ((org-agenda-keep-modes t)
5897 (filter org-agenda-filter)
5898 (preset (get 'org-agenda-filter :preset-filter))
5899 (org-agenda-filter-while-redo (or filter preset))
5900 (cols org-agenda-columns-active)
5901 (line (org-current-line))
5902 (window-line (- line (org-current-line (window-start))))
5903 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5904 (put 'org-agenda-filter :preset-filter nil)
5905 (and cols (org-columns-quit))
5906 (message "Rebuilding agenda buffer...")
5907 (org-let lprops '(eval org-agenda-redo-command))
5908 (setq org-agenda-undo-list nil
5909 org-agenda-pending-undo-list nil)
5910 (message "Rebuilding agenda buffer...done")
5911 (put 'org-agenda-filter :preset-filter preset)
5912 (and (or filter preset) (org-agenda-filter-apply filter))
5913 (and cols (interactive-p) (org-agenda-columns))
5914 (org-goto-line line)
5915 (recenter window-line)))
5918 (defvar org-global-tags-completion-table nil)
5919 (defvar org-agenda-filter-form nil)
5920 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5921 "Keep only those lines in the agenda buffer that have a specific tag.
5922 The tag is selected with its fast selection letter, as configured.
5923 With prefix argument STRIP, remove all lines that do have the tag.
5924 A lisp caller can specify CHAR. NARROW means that the new tag should be
5925 used to narrow the search - the interactive user can also press `-' or `+'
5926 to switch to narrowing."
5927 (interactive "P")
5928 (let* ((alist org-tag-alist-for-agenda)
5929 (tag-chars (mapconcat
5930 (lambda (x) (if (and (not (symbolp (car x)))
5931 (cdr x))
5932 (char-to-string (cdr x))
5933 ""))
5934 alist ""))
5935 (efforts (org-split-string
5936 (or (cdr (assoc (concat org-effort-property "_ALL")
5937 org-global-properties))
5938 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5939 (effort-op org-agenda-filter-effort-default-operator)
5940 (effort-prompt "")
5941 (inhibit-read-only t)
5942 (current org-agenda-filter)
5943 maybe-reftresh a n tag)
5944 (unless char
5945 (message
5946 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5947 (if narrow "Narrow" "Filter") tag-chars
5948 (if org-agenda-auto-exclude-function "[RET], " ""))
5949 (setq char (read-char)))
5950 (when (member char '(?+ ?-))
5951 ;; Narrowing down
5952 (cond ((equal char ?-) (setq strip t narrow t))
5953 ((equal char ?+) (setq strip nil narrow t)))
5954 (message
5955 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5956 (setq char (read-char)))
5957 (when (member char '(?< ?> ?= ??))
5958 ;; An effort operator
5959 (setq effort-op (char-to-string char))
5960 (setq alist nil) ; to make sure it will be interpreted as effort.
5961 (unless (equal char ??)
5962 (loop for i from 0 to 9 do
5963 (setq effort-prompt
5964 (concat
5965 effort-prompt " ["
5966 (if (= i 9) "0" (int-to-string (1+ i)))
5967 "]" (nth i efforts))))
5968 (message "Effort%s: %s " effort-op effort-prompt)
5969 (setq char (read-char))
5970 (when (or (< char ?0) (> char ?9))
5971 (error "Need 1-9,0 to select effort" ))))
5972 (when (equal char ?\t)
5973 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5974 (org-set-local 'org-global-tags-completion-table
5975 (org-global-tags-completion-table)))
5976 (let ((completion-ignore-case t))
5977 (setq tag (org-icompleting-read
5978 "Tag: " org-global-tags-completion-table))))
5979 (cond
5980 ((equal char ?\r)
5981 (org-agenda-filter-by-tag-show-all)
5982 (when org-agenda-auto-exclude-function
5983 (setq org-agenda-filter '())
5984 (dolist (tag (org-agenda-get-represented-tags))
5985 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5986 (if modifier
5987 (push modifier org-agenda-filter))))
5988 (if (not (null org-agenda-filter))
5989 (org-agenda-filter-apply org-agenda-filter)))
5990 (setq maybe-reftresh t))
5991 ((equal char ?/)
5992 (org-agenda-filter-by-tag-show-all)
5993 (when (get 'org-agenda-filter :preset-filter)
5994 (org-agenda-filter-apply org-agenda-filter))
5995 (setq maybe-reftresh t))
5996 ((or (equal char ?\ )
5997 (setq a (rassoc char alist))
5998 (and (>= char ?0) (<= char ?9)
5999 (setq n (if (= char ?0) 9 (- char ?0 1))
6000 tag (concat effort-op (nth n efforts))
6001 a (cons tag nil)))
6002 (and (= char ??)
6003 (setq tag "?eff")
6004 a (cons tag nil))
6005 (and tag (setq a (cons tag nil))))
6006 (org-agenda-filter-by-tag-show-all)
6007 (setq tag (car a))
6008 (setq org-agenda-filter
6009 (cons (concat (if strip "-" "+") tag)
6010 (if narrow current nil)))
6011 (org-agenda-filter-apply org-agenda-filter)
6012 (setq maybe-reftresh t))
6013 (t (error "Invalid tag selection character %c" char)))
6014 (when (and maybe-reftresh
6015 (eq org-agenda-clockreport-mode 'with-filter))
6016 (org-agenda-redo))))
6018 (defun org-agenda-get-represented-tags ()
6019 "Get a list of all tags currently represented in the agenda."
6020 (let (p tags)
6021 (save-excursion
6022 (goto-char (point-min))
6023 (while (setq p (next-single-property-change (point) 'tags))
6024 (goto-char p)
6025 (mapc (lambda (x) (add-to-list 'tags x))
6026 (get-text-property (point) 'tags))))
6027 tags))
6029 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6030 "Refine the current filter. See `org-agenda-filter-by-tag."
6031 (interactive "P")
6032 (org-agenda-filter-by-tag strip char 'refine))
6034 (defun org-agenda-filter-make-matcher ()
6035 "Create the form that tests a line for the agenda filter."
6036 (let (f f1)
6037 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6038 org-agenda-filter))
6039 (if (member x '("-" "+"))
6040 (setq f1 (if (equal x "-") 'tags '(not tags)))
6041 (if (string-match "[<=>?]" x)
6042 (setq f1 (org-agenda-filter-effort-form x))
6043 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6044 (if (equal (string-to-char x) ?-)
6045 (setq f1 (list 'not f1))))
6046 (push f1 f))
6047 (cons 'and (nreverse f))))
6049 (defun org-agenda-filter-effort-form (e)
6050 "Return the form to compare the effort of the current line with what E says.
6051 E looks like \"+<2:25\"."
6052 (let (op)
6053 (setq e (substring e 1))
6054 (setq op (string-to-char e) e (substring e 1))
6055 (setq op (cond ((equal op ?<) '<=)
6056 ((equal op ?>) '>=)
6057 ((equal op ??) op)
6058 (t '=)))
6059 (list 'org-agenda-compare-effort (list 'quote op)
6060 (org-hh:mm-string-to-minutes e))))
6062 (defun org-agenda-compare-effort (op value)
6063 "Compare the effort of the current line with VALUE, using OP.
6064 If the line does not have an effort defined, return nil."
6065 (let ((eff (org-get-at-bol 'effort-minutes)))
6066 (if (equal op ??)
6067 (not eff)
6068 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6069 value))))
6071 (defun org-agenda-filter-apply (filter)
6072 "Set FILTER as the new agenda filter and apply it."
6073 (let (tags)
6074 (setq org-agenda-filter filter
6075 org-agenda-filter-form (org-agenda-filter-make-matcher))
6076 (org-agenda-set-mode-name)
6077 (save-excursion
6078 (goto-char (point-min))
6079 (while (not (eobp))
6080 (if (org-get-at-bol 'org-marker)
6081 (progn
6082 (setq tags (org-get-at-bol 'tags)) ; used in eval
6083 (if (not (eval org-agenda-filter-form))
6084 (org-agenda-filter-by-tag-hide-line))
6085 (beginning-of-line 2))
6086 (beginning-of-line 2))))
6087 (if (get-char-property (point) 'invisible)
6088 (org-agenda-previous-line))))
6090 (defun org-agenda-filter-by-tag-hide-line ()
6091 (let (ov)
6092 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6093 (point-at-eol)))
6094 (overlay-put ov 'invisible t)
6095 (overlay-put ov 'type 'tags-filter)
6096 (push ov org-agenda-filter-overlays)))
6098 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6099 (setq pos (or pos (point)))
6100 (save-excursion
6101 (dolist (ov (overlays-at pos))
6102 (when (and (overlay-get ov 'invisible)
6103 (eq (overlay-get ov 'type) 'tags-filter))
6104 (goto-char pos)
6105 (if (< (overlay-start ov) (point-at-eol))
6106 (move-overlay ov (point-at-eol)
6107 (overlay-end ov)))))))
6109 (defun org-agenda-filter-by-tag-show-all ()
6110 (mapc 'delete-overlay org-agenda-filter-overlays)
6111 (setq org-agenda-filter-overlays nil)
6112 (setq org-agenda-filter nil)
6113 (setq org-agenda-filter-form nil)
6114 (org-agenda-set-mode-name))
6116 (defun org-agenda-manipulate-query-add ()
6117 "Manipulate the query by adding a search term with positive selection.
6118 Positive selection means the term must be matched for selection of an entry."
6119 (interactive)
6120 (org-agenda-manipulate-query ?\[))
6121 (defun org-agenda-manipulate-query-subtract ()
6122 "Manipulate the query by adding a search term with negative selection.
6123 Negative selection means term must not be matched for selection of an entry."
6124 (interactive)
6125 (org-agenda-manipulate-query ?\]))
6126 (defun org-agenda-manipulate-query-add-re ()
6127 "Manipulate the query by adding a search regexp with positive selection.
6128 Positive selection means the regexp must match for selection of an entry."
6129 (interactive)
6130 (org-agenda-manipulate-query ?\{))
6131 (defun org-agenda-manipulate-query-subtract-re ()
6132 "Manipulate the query by adding a search regexp with negative selection.
6133 Negative selection means regexp must not match for selection of an entry."
6134 (interactive)
6135 (org-agenda-manipulate-query ?\}))
6136 (defun org-agenda-manipulate-query (char)
6137 (cond
6138 ((memq org-agenda-type '(timeline agenda))
6139 (let ((org-agenda-include-inactive-timestamps t))
6140 (org-agenda-redo))
6141 (message "Display now includes inactive timestamps as well"))
6142 ((eq org-agenda-type 'search)
6143 (org-add-to-string
6144 'org-agenda-query-string
6145 (if org-agenda-last-search-view-search-was-boolean
6146 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6147 (?\{ . " +{}") (?\} . " -{}"))))
6148 " "))
6149 (setq org-agenda-redo-command
6150 (list 'org-search-view
6151 org-todo-only
6152 org-agenda-query-string
6153 (+ (length org-agenda-query-string)
6154 (if (member char '(?\{ ?\})) 0 1))))
6155 (set-register org-agenda-query-register org-agenda-query-string)
6156 (org-agenda-redo))
6157 (t (error "Cannot manipulate query for %s-type agenda buffers"
6158 org-agenda-type))))
6160 (defun org-add-to-string (var string)
6161 (set var (concat (symbol-value var) string)))
6163 (defun org-agenda-goto-date (date)
6164 "Jump to DATE in agenda."
6165 (interactive (list (let ((org-read-date-prefer-future
6166 (eval org-agenda-jump-prefer-future)))
6167 (org-read-date))))
6168 (org-agenda-list nil date))
6170 (defun org-agenda-goto-today ()
6171 "Go to today."
6172 (interactive)
6173 (org-agenda-check-type t 'timeline 'agenda)
6174 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6175 (cond
6176 (tdpos (goto-char tdpos))
6177 ((eq org-agenda-type 'agenda)
6178 (let* ((sd (org-agenda-compute-starting-span
6179 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6180 (org-agenda-overriding-arguments org-agenda-last-arguments))
6181 (setf (nth 1 org-agenda-overriding-arguments) sd)
6182 (org-agenda-redo)
6183 (org-agenda-find-same-or-today-or-agenda)))
6184 (t (error "Cannot find today")))))
6186 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6187 (goto-char
6188 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6189 (text-property-any (point-min) (point-max) 'org-today t)
6190 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6191 (point-min))))
6193 (defun org-agenda-later (arg)
6194 "Go forward in time by thee current span.
6195 With prefix ARG, go forward that many times the current span."
6196 (interactive "p")
6197 (org-agenda-check-type t 'agenda)
6198 (let* ((span org-agenda-current-span)
6199 (sd org-starting-day)
6200 (greg (calendar-gregorian-from-absolute sd))
6201 (cnt (org-get-at-bol 'org-day-cnt))
6202 greg2)
6203 (cond
6204 ((eq span 'day)
6205 (setq sd (+ arg sd)))
6206 ((eq span 'week)
6207 (setq sd (+ (* 7 arg) sd)))
6208 ((eq span 'month)
6209 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6210 sd (calendar-absolute-from-gregorian greg2))
6211 (setcar greg2 (1+ (car greg2))))
6212 ((eq span 'year)
6213 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6214 sd (calendar-absolute-from-gregorian greg2))
6215 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6217 (setq sd (+ (* span arg) sd))))
6218 (let ((org-agenda-overriding-arguments
6219 (list (car org-agenda-last-arguments) sd span t)))
6220 (org-agenda-redo)
6221 (org-agenda-find-same-or-today-or-agenda cnt))))
6223 (defun org-agenda-earlier (arg)
6224 "Go backward in time by the current span.
6225 With prefix ARG, go backward that many times the current span."
6226 (interactive "p")
6227 (org-agenda-later (- arg)))
6229 (defun org-agenda-view-mode-dispatch ()
6230 "Call one of the view mode commands."
6231 (interactive)
6232 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6233 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6234 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6235 (let ((a (read-char-exclusive)))
6236 (case a
6237 (?\ (call-interactively 'org-agenda-reset-view))
6238 (?d (call-interactively 'org-agenda-day-view))
6239 (?w (call-interactively 'org-agenda-week-view))
6240 (?m (call-interactively 'org-agenda-month-view))
6241 (?y (call-interactively 'org-agenda-year-view))
6242 (?l (call-interactively 'org-agenda-log-mode))
6243 (?L (org-agenda-log-mode '(4)))
6244 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6245 (?a (call-interactively 'org-agenda-archives-mode))
6246 (?A (org-agenda-archives-mode 'files))
6247 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6248 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6249 (?G (call-interactively 'org-agenda-toggle-time-grid))
6250 (?D (call-interactively 'org-agenda-toggle-diary))
6251 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6252 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6253 (org-agenda-check-type t 'timeline 'agenda)
6254 (org-agenda-redo))
6255 (message "Display now includes inactive timestamps as well"))
6256 (?q (message "Abort"))
6257 (otherwise (error "Invalid key" )))))
6259 (defun org-agenda-reset-view ()
6260 "Switch to default view for agenda."
6261 (interactive)
6262 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6263 (defun org-agenda-day-view (&optional day-of-year)
6264 "Switch to daily view for agenda.
6265 With argument DAY-OF-YEAR, switch to that day of the year."
6266 (interactive "P")
6267 (org-agenda-change-time-span 'day day-of-year))
6268 (defun org-agenda-week-view (&optional iso-week)
6269 "Switch to daily view for agenda.
6270 With argument ISO-WEEK, switch to the corresponding ISO week.
6271 If ISO-WEEK has more then 2 digits, only the last two encode the
6272 week. Any digits before this encode a year. So 200712 means
6273 week 12 of year 2007. Years in the range 1938-2037 can also be
6274 written as 2-digit years."
6275 (interactive "P")
6276 (org-agenda-change-time-span 'week iso-week))
6277 (defun org-agenda-month-view (&optional month)
6278 "Switch to monthly view for agenda.
6279 With argument MONTH, switch to that month."
6280 (interactive "P")
6281 (org-agenda-change-time-span 'month month))
6282 (defun org-agenda-year-view (&optional year)
6283 "Switch to yearly view for agenda.
6284 With argument YEAR, switch to that year.
6285 If MONTH has more then 2 digits, only the last two encode the
6286 month. Any digits before this encode a year. So 200712 means
6287 December year 2007. Years in the range 1938-2037 can also be
6288 written as 2-digit years."
6289 (interactive "P")
6290 (when year
6291 (setq year (org-small-year-to-year year)))
6292 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6293 (org-agenda-change-time-span 'year year)
6294 (error "Abort")))
6296 (defun org-agenda-change-time-span (span &optional n)
6297 "Change the agenda view to SPAN.
6298 SPAN may be `day', `week', `month', `year'."
6299 (org-agenda-check-type t 'agenda)
6300 (if (and (not n) (equal org-agenda-current-span span))
6301 (error "Viewing span is already \"%s\"" span))
6302 (let* ((sd (or (org-get-at-bol 'day)
6303 org-starting-day))
6304 (sd (org-agenda-compute-starting-span sd span n))
6305 (org-agenda-overriding-arguments
6306 (or org-agenda-overriding-arguments
6307 (list (car org-agenda-last-arguments) sd span t))))
6308 (org-agenda-redo)
6309 (org-agenda-find-same-or-today-or-agenda))
6310 (org-agenda-set-mode-name)
6311 (message "Switched to %s view" span))
6313 (defun org-agenda-compute-starting-span (sd span &optional n)
6314 "Compute starting date for agenda.
6315 SPAN may be `day', `week', `month', `year'. The return value
6316 is a cons cell with the starting date and the number of days,
6317 so that the date SD will be in that range."
6318 (let* ((greg (calendar-gregorian-from-absolute sd))
6319 (dg (nth 1 greg))
6320 (mg (car greg))
6321 (yg (nth 2 greg)))
6322 (cond
6323 ((eq span 'day)
6324 (when n
6325 (setq sd (+ (calendar-absolute-from-gregorian
6326 (list mg 1 yg))
6327 n -1))))
6328 ((eq span 'week)
6329 (let* ((nt (calendar-day-of-week
6330 (calendar-gregorian-from-absolute sd)))
6331 (d (if org-agenda-start-on-weekday
6332 (- nt org-agenda-start-on-weekday)
6335 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6336 (when n
6337 (require 'cal-iso)
6338 (when (> n 99)
6339 (setq y1 (org-small-year-to-year (/ n 100))
6340 n (mod n 100)))
6341 (setq sd
6342 (calendar-absolute-from-iso
6343 (list n 1
6344 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6345 ((eq span 'month)
6346 (let (y1)
6347 (when (and n (> n 99))
6348 (setq y1 (org-small-year-to-year (/ n 100))
6349 n (mod n 100)))
6350 (setq sd (calendar-absolute-from-gregorian
6351 (list (or n mg) 1 (or y1 yg))))))
6352 ((eq span 'year)
6353 (setq sd (calendar-absolute-from-gregorian
6354 (list 1 1 (or n yg))))))
6355 sd))
6357 (defun org-agenda-next-date-line (&optional arg)
6358 "Jump to the next line indicating a date in agenda buffer."
6359 (interactive "p")
6360 (org-agenda-check-type t 'agenda 'timeline)
6361 (beginning-of-line 1)
6362 ;; This does not work if user makes date format that starts with a blank
6363 (if (looking-at "^\\S-") (forward-char 1))
6364 (if (not (re-search-forward "^\\S-" nil t arg))
6365 (progn
6366 (backward-char 1)
6367 (error "No next date after this line in this buffer")))
6368 (goto-char (match-beginning 0)))
6370 (defun org-agenda-previous-date-line (&optional arg)
6371 "Jump to the previous line indicating a date in agenda buffer."
6372 (interactive "p")
6373 (org-agenda-check-type t 'agenda 'timeline)
6374 (beginning-of-line 1)
6375 (if (not (re-search-backward "^\\S-" nil t arg))
6376 (error "No previous date before this line in this buffer")))
6378 ;; Initialize the highlight
6379 (defvar org-hl (make-overlay 1 1))
6380 (overlay-put org-hl 'face 'highlight)
6382 (defun org-highlight (begin end &optional buffer)
6383 "Highlight a region with overlay."
6384 (move-overlay org-hl begin end (or buffer (current-buffer))))
6386 (defun org-unhighlight ()
6387 "Detach overlay INDEX."
6388 (org-detach-overlay org-hl))
6390 ;; FIXME this is currently not used.
6391 (defun org-highlight-until-next-command (beg end &optional buffer)
6392 "Move the highlight overlay to BEG/END, remove it before the next command."
6393 (org-highlight beg end buffer)
6394 (add-hook 'pre-command-hook 'org-unhighlight-once))
6395 (defun org-unhighlight-once ()
6396 "Remove the highlight from its position, and this function from the hook."
6397 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6398 (org-unhighlight))
6400 (defun org-agenda-follow-mode ()
6401 "Toggle follow mode in an agenda buffer."
6402 (interactive)
6403 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6404 (org-agenda-set-mode-name)
6405 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6406 (org-agenda-show))
6407 (message "Follow mode is %s"
6408 (if org-agenda-follow-mode "on" "off")))
6410 (defun org-agenda-entry-text-mode (&optional arg)
6411 "Toggle entry text mode in an agenda buffer."
6412 (interactive "P")
6413 (setq org-agenda-entry-text-mode (or (integerp arg)
6414 (not org-agenda-entry-text-mode)))
6415 (org-agenda-entry-text-hide)
6416 (and org-agenda-entry-text-mode
6417 (let ((org-agenda-entry-text-maxlines
6418 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6419 (org-agenda-entry-text-show)))
6420 (org-agenda-set-mode-name)
6421 (message "Entry text mode is %s. Maximum number of lines is %d"
6422 (if org-agenda-entry-text-mode "on" "off")
6423 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6425 (defun org-agenda-clockreport-mode (&optional with-filter)
6426 "Toggle clocktable mode in an agenda buffer.
6427 With prefix arg WITH-FILTER, make the clocktable respect the current
6428 agenda filter."
6429 (interactive "P")
6430 (org-agenda-check-type t 'agenda)
6431 (if with-filter
6432 (setq org-agenda-clockreport-mode 'with-filter)
6433 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6434 (org-agenda-set-mode-name)
6435 (org-agenda-redo)
6436 (message "Clocktable mode is %s"
6437 (if org-agenda-clockreport-mode "on" "off")))
6439 (defun org-agenda-log-mode (&optional special)
6440 "Toggle log mode in an agenda buffer.
6441 With argument SPECIAL, show all possible log items, not only the ones
6442 configured in `org-agenda-log-mode-items'.
6443 With a double `C-u' prefix arg, show *only* log items, nothing else."
6444 (interactive "P")
6445 (org-agenda-check-type t 'agenda 'timeline)
6446 (setq org-agenda-show-log
6447 (if (equal special '(16))
6448 'only
6449 (if special '(closed clock state)
6450 (not org-agenda-show-log))))
6451 (org-agenda-set-mode-name)
6452 (org-agenda-redo)
6453 (message "Log mode is %s"
6454 (if org-agenda-show-log "on" "off")))
6456 (defun org-agenda-archives-mode (&optional with-files)
6457 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6458 When called with a prefix argument, include all archive files as well."
6459 (interactive "P")
6460 (setq org-agenda-archives-mode
6461 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6462 (org-agenda-set-mode-name)
6463 (org-agenda-redo)
6464 (message
6465 "%s"
6466 (cond
6467 ((eq org-agenda-archives-mode nil)
6468 "No archives are included")
6469 ((eq org-agenda-archives-mode 'trees)
6470 (format "Trees with :%s: tag are included" org-archive-tag))
6471 ((eq org-agenda-archives-mode t)
6472 (format "Trees with :%s: tag and all active archive files are included"
6473 org-archive-tag)))))
6475 (defun org-agenda-toggle-diary ()
6476 "Toggle diary inclusion in an agenda buffer."
6477 (interactive)
6478 (org-agenda-check-type t 'agenda)
6479 (setq org-agenda-include-diary (not org-agenda-include-diary))
6480 (org-agenda-redo)
6481 (org-agenda-set-mode-name)
6482 (message "Diary inclusion turned %s"
6483 (if org-agenda-include-diary "on" "off")))
6485 (defun org-agenda-toggle-deadlines ()
6486 "Toggle inclusion of entries with a deadline in an agenda buffer."
6487 (interactive)
6488 (org-agenda-check-type t 'agenda)
6489 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6490 (org-agenda-redo)
6491 (org-agenda-set-mode-name)
6492 (message "Deadlines inclusion turned %s"
6493 (if org-agenda-include-deadlines "on" "off")))
6495 (defun org-agenda-toggle-time-grid ()
6496 "Toggle time grid in an agenda buffer."
6497 (interactive)
6498 (org-agenda-check-type t 'agenda)
6499 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6500 (org-agenda-redo)
6501 (org-agenda-set-mode-name)
6502 (message "Time-grid turned %s"
6503 (if org-agenda-use-time-grid "on" "off")))
6505 (defun org-agenda-set-mode-name ()
6506 "Set the mode name to indicate all the small mode settings."
6507 (setq mode-name
6508 (list "Org-Agenda"
6509 (if (get 'org-agenda-files 'org-restrict) " []" "")
6511 '(:eval (org-agenda-span-name org-agenda-current-span))
6512 (if org-agenda-follow-mode " Follow" "")
6513 (if org-agenda-entry-text-mode " ETxt" "")
6514 (if org-agenda-include-diary " Diary" "")
6515 (if org-agenda-include-deadlines " Ddl" "")
6516 (if org-agenda-use-time-grid " Grid" "")
6517 (if (and (boundp 'org-habit-show-habits)
6518 org-habit-show-habits) " Habit" "")
6519 (if (consp org-agenda-show-log) " LogAll"
6520 (if org-agenda-show-log " Log" ""))
6521 (if (or org-agenda-filter (get 'org-agenda-filter
6522 :preset-filter))
6523 (concat " {" (mapconcat
6524 'identity
6525 (append (get 'org-agenda-filter
6526 :preset-filter)
6527 org-agenda-filter) "") "}")
6529 (if org-agenda-archives-mode
6530 (if (eq org-agenda-archives-mode t)
6531 " Archives"
6532 (format " :%s:" org-archive-tag))
6534 (if org-agenda-clockreport-mode
6535 (if (eq org-agenda-clockreport-mode 'with-filter)
6536 " Clock{}" " Clock")
6537 "")))
6538 (force-mode-line-update))
6540 (defun org-agenda-post-command-hook ()
6541 (setq org-agenda-type
6542 (or (get-text-property (point) 'org-agenda-type)
6543 (get-text-property (max (point-min) (1- (point)))
6544 'org-agenda-type))))
6546 (defun org-agenda-next-line ()
6547 "Move cursor to the next line, and show if follow mode is active."
6548 (interactive)
6549 (call-interactively 'next-line)
6550 (org-agenda-do-context-action))
6552 (defun org-agenda-previous-line ()
6553 "Move cursor to the previous line, and show if follow-mode is active."
6554 (interactive)
6555 (call-interactively 'previous-line)
6556 (org-agenda-do-context-action))
6558 (defun org-agenda-do-context-action ()
6559 "Show outline path and, maybe, follow mode window."
6560 (let ((m (org-get-at-bol 'org-marker)))
6561 (if (and org-agenda-follow-mode m)
6562 (org-agenda-show))
6563 (if (and m org-agenda-show-outline-path)
6564 (org-with-point-at m
6565 (org-display-outline-path t)))))
6567 (defun org-agenda-show-priority ()
6568 "Show the priority of the current item.
6569 This priority is composed of the main priority given with the [#A] cookies,
6570 and by additional input from the age of a schedules or deadline entry."
6571 (interactive)
6572 (let* ((pri (org-get-at-bol 'priority)))
6573 (message "Priority is %d" (if pri pri -1000))))
6575 (defun org-agenda-show-tags ()
6576 "Show the tags applicable to the current item."
6577 (interactive)
6578 (let* ((tags (org-get-at-bol 'tags)))
6579 (if tags
6580 (message "Tags are :%s:"
6581 (org-no-properties (mapconcat 'identity tags ":")))
6582 (message "No tags associated with this line"))))
6584 (defun org-agenda-goto (&optional highlight)
6585 "Go to the Org-mode file which contains the item at point."
6586 (interactive)
6587 (let* ((marker (or (org-get-at-bol 'org-marker)
6588 (org-agenda-error)))
6589 (buffer (marker-buffer marker))
6590 (pos (marker-position marker)))
6591 (switch-to-buffer-other-window buffer)
6592 (widen)
6593 (push-mark)
6594 (goto-char pos)
6595 (when (org-mode-p)
6596 (org-show-context 'agenda)
6597 (save-excursion
6598 (and (outline-next-heading)
6599 (org-flag-heading nil)))) ; show the next heading
6600 (when (outline-invisible-p)
6601 (show-entry)) ; display invisible text
6602 (recenter (/ (window-height) 2))
6603 (run-hooks 'org-agenda-after-show-hook)
6604 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6606 (defvar org-agenda-after-show-hook nil
6607 "Normal hook run after an item has been shown from the agenda.
6608 Point is in the buffer where the item originated.")
6610 (defun org-agenda-kill ()
6611 "Kill the entry or subtree belonging to the current agenda entry."
6612 (interactive)
6613 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6614 (let* ((marker (or (org-get-at-bol 'org-marker)
6615 (org-agenda-error)))
6616 (buffer (marker-buffer marker))
6617 (pos (marker-position marker))
6618 (type (org-get-at-bol 'type))
6619 dbeg dend (n 0) conf)
6620 (org-with-remote-undo buffer
6621 (with-current-buffer buffer
6622 (save-excursion
6623 (goto-char pos)
6624 (if (and (org-mode-p) (not (member type '("sexp"))))
6625 (setq dbeg (progn (org-back-to-heading t) (point))
6626 dend (org-end-of-subtree t t))
6627 (setq dbeg (point-at-bol)
6628 dend (min (point-max) (1+ (point-at-eol)))))
6629 (goto-char dbeg)
6630 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6631 (setq conf (or (eq t org-agenda-confirm-kill)
6632 (and (numberp org-agenda-confirm-kill)
6633 (> n org-agenda-confirm-kill))))
6634 (and conf
6635 (not (y-or-n-p
6636 (format "Delete entry with %d lines in buffer \"%s\"? "
6637 n (buffer-name buffer))))
6638 (error "Abort"))
6639 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6640 (with-current-buffer buffer (delete-region dbeg dend))
6641 (message "Agenda item and source killed"))))
6643 (defvar org-archive-default-command)
6644 (defun org-agenda-archive-default ()
6645 "Archive the entry or subtree belonging to the current agenda entry."
6646 (interactive)
6647 (require 'org-archive)
6648 (org-agenda-archive-with org-archive-default-command))
6650 (defun org-agenda-archive-default-with-confirmation ()
6651 "Archive the entry or subtree belonging to the current agenda entry."
6652 (interactive)
6653 (require 'org-archive)
6654 (org-agenda-archive-with org-archive-default-command 'confirm))
6656 (defun org-agenda-archive ()
6657 "Archive the entry or subtree belonging to the current agenda entry."
6658 (interactive)
6659 (org-agenda-archive-with 'org-archive-subtree))
6661 (defun org-agenda-archive-to-archive-sibling ()
6662 "Move the entry to the archive sibling."
6663 (interactive)
6664 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6666 (defun org-agenda-archive-with (cmd &optional confirm)
6667 "Move the entry to the archive sibling."
6668 (interactive)
6669 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6670 (let* ((marker (or (org-get-at-bol 'org-marker)
6671 (org-agenda-error)))
6672 (buffer (marker-buffer marker))
6673 (pos (marker-position marker)))
6674 (org-with-remote-undo buffer
6675 (with-current-buffer buffer
6676 (if (org-mode-p)
6677 (if (and confirm
6678 (not (y-or-n-p "Archive this subtree or entry? ")))
6679 (error "Abort")
6680 (save-excursion
6681 (goto-char pos)
6682 (org-remove-subtree-entries-from-agenda)
6683 (org-back-to-heading t)
6684 (funcall cmd)))
6685 (error "Archiving works only in Org-mode files"))))))
6687 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6688 "Remove all lines in the agenda that correspond to a given subtree.
6689 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6690 If this information is not given, the function uses the tree at point."
6691 (let ((buf (or buf (current-buffer))) m p)
6692 (save-excursion
6693 (unless (and beg end)
6694 (org-back-to-heading t)
6695 (setq beg (point))
6696 (org-end-of-subtree t)
6697 (setq end (point)))
6698 (set-buffer (get-buffer org-agenda-buffer-name))
6699 (save-excursion
6700 (goto-char (point-max))
6701 (beginning-of-line 1)
6702 (while (not (bobp))
6703 (when (and (setq m (org-get-at-bol 'org-marker))
6704 (equal buf (marker-buffer m))
6705 (setq p (marker-position m))
6706 (>= p beg)
6707 (< p end))
6708 (let ((inhibit-read-only t))
6709 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6710 (beginning-of-line 0))))))
6712 (defun org-agenda-refile (&optional goto rfloc no-update)
6713 "Refile the item at point."
6714 (interactive "P")
6715 (if (equal goto '(16))
6716 (org-refile-goto-last-stored)
6717 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6718 (org-agenda-error)))
6719 (buffer (marker-buffer marker))
6720 (pos (marker-position marker))
6721 (rfloc (or rfloc
6722 (org-refile-get-location
6723 (if goto "Goto" "Refile to") buffer
6724 org-refile-allow-creating-parent-nodes))))
6725 (with-current-buffer buffer
6726 (save-excursion
6727 (save-restriction
6728 (widen)
6729 (goto-char marker)
6730 (org-remove-subtree-entries-from-agenda)
6731 (org-refile goto buffer rfloc)))))
6732 (unless no-update (org-agenda-redo))))
6734 (defun org-agenda-open-link (&optional arg)
6735 "Follow the link in the current line, if any.
6736 This looks for a link in the displayed line in the agenda. It also looks
6737 at the text of the entry itself."
6738 (interactive "P")
6739 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6740 (org-get-at-bol 'org-marker)))
6741 (buffer (and marker (marker-buffer marker)))
6742 (prefix (buffer-substring
6743 (point-at-bol)
6744 (+ (point-at-bol)
6745 (or (org-get-at-bol 'prefix-length) 0)))))
6746 (cond
6747 (buffer
6748 (with-current-buffer buffer
6749 (save-excursion
6750 (save-restriction
6751 (widen)
6752 (goto-char marker)
6753 (org-offer-links-in-entry arg prefix)))))
6754 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6755 (save-excursion
6756 (beginning-of-line 1)
6757 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6758 (org-open-link-from-string (match-string 1)))
6759 (t (error "No link to open here")))))
6761 (defun org-agenda-copy-local-variable (var)
6762 "Get a variable from a referenced buffer and install it here."
6763 (let ((m (org-get-at-bol 'org-marker)))
6764 (when (and m (buffer-live-p (marker-buffer m)))
6765 (org-set-local var (with-current-buffer (marker-buffer m)
6766 (symbol-value var))))))
6768 (defun org-agenda-switch-to (&optional delete-other-windows)
6769 "Go to the Org-mode file which contains the item at point."
6770 (interactive)
6771 (if (and org-return-follows-link
6772 (not (org-get-at-bol 'org-marker))
6773 (org-in-regexp org-bracket-link-regexp))
6774 (org-open-link-from-string (match-string 0))
6775 (let* ((marker (or (org-get-at-bol 'org-marker)
6776 (org-agenda-error)))
6777 (buffer (marker-buffer marker))
6778 (pos (marker-position marker)))
6779 (switch-to-buffer buffer)
6780 (and delete-other-windows (delete-other-windows))
6781 (widen)
6782 (goto-char pos)
6783 (when (org-mode-p)
6784 (org-show-context 'agenda)
6785 (save-excursion
6786 (and (outline-next-heading)
6787 (org-flag-heading nil))) ; show the next heading
6788 (when (outline-invisible-p)
6789 (show-entry)))))) ; display invisible text
6791 (defun org-agenda-goto-mouse (ev)
6792 "Go to the Org-mode file which contains the item at the mouse click."
6793 (interactive "e")
6794 (mouse-set-point ev)
6795 (org-agenda-goto))
6797 (defun org-agenda-show (&optional full-entry)
6798 "Display the Org-mode file which contains the item at point.
6799 With prefix argument FULL-ENTRY, make the entire entry visible
6800 if it was hidden in the outline."
6801 (interactive "P")
6802 (let ((win (selected-window)))
6803 (if full-entry
6804 (let ((org-show-entry-below t))
6805 (org-agenda-goto t))
6806 (org-agenda-goto t))
6807 (select-window win)))
6809 (defvar org-agenda-show-window nil)
6810 (defun org-agenda-show-and-scroll-up ()
6811 "Display the Org-mode file which contains the item at point.
6812 When called repeatedly, scroll the window that is displaying the buffer."
6813 (interactive)
6814 (let ((win (selected-window)))
6815 (if (and (window-live-p org-agenda-show-window)
6816 (eq this-command last-command))
6817 (progn
6818 (select-window org-agenda-show-window)
6819 (ignore-errors (scroll-up)))
6820 (org-agenda-goto t)
6821 (show-subtree)
6822 (setq org-agenda-show-window (selected-window)))
6823 (select-window win)))
6825 (defun org-agenda-show-scroll-down ()
6826 "Scroll down the window showing the agenda."
6827 (interactive)
6828 (let ((win (selected-window)))
6829 (when (window-live-p org-agenda-show-window)
6830 (select-window org-agenda-show-window)
6831 (ignore-errors (scroll-down))
6832 (select-window win))))
6834 (defun org-agenda-show-1 (&optional more)
6835 "Display the Org-mode file which contains the item at point.
6836 The prefix arg selects the amount of information to display:
6838 0 hide the subtree
6839 1 just show the entry according to defaults.
6840 2 show the children view
6841 3 show the subtree view
6842 4 show the entire subtree and any LOGBOOK drawers
6843 5 show the entire subtree and any drawers
6844 With prefix argument FULL-ENTRY, make the entire entry visible
6845 if it was hidden in the outline."
6846 (interactive "p")
6847 (let ((win (selected-window)))
6848 (org-agenda-goto t)
6849 (org-recenter-heading 1)
6850 (cond
6851 ((= more 0)
6852 (hide-subtree)
6853 (save-excursion
6854 (org-back-to-heading)
6855 (run-hook-with-args 'org-cycle-hook 'folded))
6856 (message "Remote: FOLDED"))
6857 ((and (interactive-p) (= more 1))
6858 (message "Remote: show with default settings"))
6859 ((= more 2)
6860 (show-entry)
6861 (show-children)
6862 (save-excursion
6863 (org-back-to-heading)
6864 (run-hook-with-args 'org-cycle-hook 'children))
6865 (message "Remote: CHILDREN"))
6866 ((= more 3)
6867 (show-subtree)
6868 (save-excursion
6869 (org-back-to-heading)
6870 (run-hook-with-args 'org-cycle-hook 'subtree))
6871 (message "Remote: SUBTREE"))
6872 ((= more 4)
6873 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6874 (org-drawer-regexp
6875 (concat "^[ \t]*:\\("
6876 (mapconcat 'regexp-quote org-drawers "\\|")
6877 "\\):[ \t]*$")))
6878 (show-subtree)
6879 (save-excursion
6880 (org-back-to-heading)
6881 (org-cycle-hide-drawers 'subtree)))
6882 (message "Remote: SUBTREE AND LOGBOOK"))
6883 ((> more 4)
6884 (show-subtree)
6885 (message "Remote: SUBTREE AND ALL DRAWERS")))
6886 (select-window win)))
6888 (defun org-recenter-heading (n)
6889 (save-excursion
6890 (org-back-to-heading)
6891 (recenter n)))
6893 (defvar org-agenda-cycle-counter nil)
6894 (defun org-agenda-cycle-show (&optional n)
6895 "Show the current entry in another window, with default settings.
6896 Default settings are taken from `org-show-hierarchy-above' and siblings.
6897 When use repeatedly in immediate succession, the remote entry will cycle
6898 through visibility
6900 children -> subtree -> folded
6902 When called with a numeric prefix arg, that arg will be passed through to
6903 `org-agenda-show-1'. For the interpretation of that argument, see the
6904 docstring of `org-agenda-show-1'."
6905 (interactive "P")
6906 (if (integerp n)
6907 (setq org-agenda-cycle-counter n)
6908 (if (not (eq last-command this-command))
6909 (setq org-agenda-cycle-counter 1)
6910 (if (equal org-agenda-cycle-counter 0)
6911 (setq org-agenda-cycle-counter 2)
6912 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6913 (if (> org-agenda-cycle-counter 3)
6914 (setq org-agenda-cycle-counter 0)))))
6915 (org-agenda-show-1 org-agenda-cycle-counter))
6917 (defun org-agenda-recenter (arg)
6918 "Display the Org-mode file which contains the item at point and recenter."
6919 (interactive "P")
6920 (let ((win (selected-window)))
6921 (org-agenda-goto t)
6922 (recenter arg)
6923 (select-window win)))
6925 (defun org-agenda-show-mouse (ev)
6926 "Display the Org-mode file which contains the item at the mouse click."
6927 (interactive "e")
6928 (mouse-set-point ev)
6929 (org-agenda-show))
6931 (defun org-agenda-check-no-diary ()
6932 "Check if the entry is a diary link and abort if yes."
6933 (if (org-get-at-bol 'org-agenda-diary-link)
6934 (org-agenda-error)))
6936 (defun org-agenda-error ()
6937 (error "Command not allowed in this line"))
6939 (defun org-agenda-tree-to-indirect-buffer ()
6940 "Show the subtree corresponding to the current entry in an indirect buffer.
6941 This calls the command `org-tree-to-indirect-buffer' from the original
6942 Org-mode buffer.
6943 With numerical prefix arg ARG, go up to this level and then take that tree.
6944 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6945 use the dedicated frame)."
6946 (interactive)
6947 (org-agenda-check-no-diary)
6948 (let* ((marker (or (org-get-at-bol 'org-marker)
6949 (org-agenda-error)))
6950 (buffer (marker-buffer marker))
6951 (pos (marker-position marker)))
6952 (with-current-buffer buffer
6953 (save-excursion
6954 (goto-char pos)
6955 (call-interactively 'org-tree-to-indirect-buffer)))))
6957 (defvar org-last-heading-marker (make-marker)
6958 "Marker pointing to the headline that last changed its TODO state
6959 by a remote command from the agenda.")
6961 (defun org-agenda-todo-nextset ()
6962 "Switch TODO entry to next sequence."
6963 (interactive)
6964 (org-agenda-todo 'nextset))
6966 (defun org-agenda-todo-previousset ()
6967 "Switch TODO entry to previous sequence."
6968 (interactive)
6969 (org-agenda-todo 'previousset))
6971 (defun org-agenda-todo (&optional arg)
6972 "Cycle TODO state of line at point, also in Org-mode file.
6973 This changes the line at point, all other lines in the agenda referring to
6974 the same tree node, and the headline of the tree node in the Org-mode file."
6975 (interactive "P")
6976 (org-agenda-check-no-diary)
6977 (let* ((col (current-column))
6978 (marker (or (org-get-at-bol 'org-marker)
6979 (org-agenda-error)))
6980 (buffer (marker-buffer marker))
6981 (pos (marker-position marker))
6982 (hdmarker (org-get-at-bol 'org-hd-marker))
6983 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6984 (inhibit-read-only t)
6985 org-agenda-headline-snapshot-before-repeat newhead just-one)
6986 (org-with-remote-undo buffer
6987 (with-current-buffer buffer
6988 (widen)
6989 (goto-char pos)
6990 (org-show-context 'agenda)
6991 (save-excursion
6992 (and (outline-next-heading)
6993 (org-flag-heading nil))) ; show the next heading
6994 (let ((current-prefix-arg arg))
6995 (call-interactively 'org-todo))
6996 (and (bolp) (forward-char 1))
6997 (setq newhead (org-get-heading))
6998 (when (and (org-bound-and-true-p
6999 org-agenda-headline-snapshot-before-repeat)
7000 (not (equal org-agenda-headline-snapshot-before-repeat
7001 newhead))
7002 todayp)
7003 (setq newhead org-agenda-headline-snapshot-before-repeat
7004 just-one t))
7005 (save-excursion
7006 (org-back-to-heading)
7007 (move-marker org-last-heading-marker (point))))
7008 (beginning-of-line 1)
7009 (save-excursion
7010 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7011 (org-move-to-column col))))
7013 (defun org-agenda-add-note (&optional arg)
7014 "Add a time-stamped note to the entry at point."
7015 (interactive "P")
7016 (org-agenda-check-no-diary)
7017 (let* ((marker (or (org-get-at-bol 'org-marker)
7018 (org-agenda-error)))
7019 (buffer (marker-buffer marker))
7020 (pos (marker-position marker))
7021 (hdmarker (org-get-at-bol 'org-hd-marker))
7022 (inhibit-read-only t))
7023 (with-current-buffer buffer
7024 (widen)
7025 (goto-char pos)
7026 (org-show-context 'agenda)
7027 (save-excursion
7028 (and (outline-next-heading)
7029 (org-flag-heading nil))) ; show the next heading
7030 (org-add-note))))
7032 (defun org-agenda-change-all-lines (newhead hdmarker
7033 &optional fixface just-this)
7034 "Change all lines in the agenda buffer which match HDMARKER.
7035 The new content of the line will be NEWHEAD (as modified by
7036 `org-format-agenda-item'). HDMARKER is checked with
7037 `equal' against all `org-hd-marker' text properties in the file.
7038 If FIXFACE is non-nil, the face of each item is modified according to
7039 the new TODO state.
7040 If JUST-THIS is non-nil, change just the current line, not all.
7041 If FORCE-TAGS is non nil, the car of it returns the new tags."
7042 (let* ((inhibit-read-only t)
7043 (line (org-current-line))
7044 (thetags (with-current-buffer (marker-buffer hdmarker)
7045 (save-excursion (save-restriction (widen)
7046 (goto-char hdmarker)
7047 (org-get-tags-at)))))
7048 props m pl undone-face done-face finish new dotime cat tags)
7049 (save-excursion
7050 (goto-char (point-max))
7051 (beginning-of-line 1)
7052 (while (not finish)
7053 (setq finish (bobp))
7054 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7055 (or (not just-this) (= (org-current-line) line))
7056 (equal m hdmarker))
7057 (setq props (text-properties-at (point))
7058 dotime (org-get-at-bol 'dotime)
7059 cat (org-get-at-bol 'org-category)
7060 tags thetags
7061 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
7062 pl (org-get-at-bol 'prefix-length)
7063 undone-face (org-get-at-bol 'undone-face)
7064 done-face (org-get-at-bol 'done-face))
7065 (goto-char (+ (point) pl))
7066 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
7067 (cond
7068 ((equal new "")
7069 (beginning-of-line 1)
7070 (and (looking-at ".*\n?") (replace-match "")))
7071 ((looking-at ".*")
7072 (replace-match new t t)
7073 (beginning-of-line 1)
7074 (add-text-properties (point-at-bol) (point-at-eol) props)
7075 (when fixface
7076 (add-text-properties
7077 (point-at-bol) (point-at-eol)
7078 (list 'face
7079 (if org-last-todo-state-is-todo
7080 undone-face done-face))))
7081 (org-agenda-highlight-todo 'line)
7082 (beginning-of-line 1))
7083 (t (error "Line update did not work"))))
7084 (beginning-of-line 0)))
7085 (org-finalize-agenda)))
7087 (defun org-agenda-align-tags (&optional line)
7088 "Align all tags in agenda items to `org-agenda-tags-column'."
7089 (let ((inhibit-read-only t) l c)
7090 (save-excursion
7091 (goto-char (if line (point-at-bol) (point-min)))
7092 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7093 (if line (point-at-eol) nil) t)
7094 (add-text-properties
7095 (match-beginning 2) (match-end 2)
7096 (list 'face (delq nil (let ((prop (get-text-property
7097 (match-beginning 2) 'face)))
7098 (or (listp prop) (setq prop (list prop)))
7099 (if (memq 'org-tag prop)
7100 prop
7101 (cons 'org-tag prop))))))
7102 (setq l (- (match-end 2) (match-beginning 2))
7103 c (if (< org-agenda-tags-column 0)
7104 (- (abs org-agenda-tags-column) l)
7105 org-agenda-tags-column))
7106 (delete-region (match-beginning 1) (match-end 1))
7107 (goto-char (match-beginning 1))
7108 (insert (org-add-props
7109 (make-string (max 1 (- c (current-column))) ?\ )
7110 (plist-put (copy-sequence (text-properties-at (point)))
7111 'face nil))))
7112 (goto-char (point-min))
7113 (org-font-lock-add-tag-faces (point-max)))))
7115 (defun org-agenda-priority-up ()
7116 "Increase the priority of line at point, also in Org-mode file."
7117 (interactive)
7118 (org-agenda-priority 'up))
7120 (defun org-agenda-priority-down ()
7121 "Decrease the priority of line at point, also in Org-mode file."
7122 (interactive)
7123 (org-agenda-priority 'down))
7125 (defun org-agenda-priority (&optional force-direction)
7126 "Set the priority of line at point, also in Org-mode file.
7127 This changes the line at point, all other lines in the agenda referring to
7128 the same tree node, and the headline of the tree node in the Org-mode file."
7129 (interactive)
7130 (unless org-enable-priority-commands
7131 (error "Priority commands are disabled"))
7132 (org-agenda-check-no-diary)
7133 (let* ((marker (or (org-get-at-bol 'org-marker)
7134 (org-agenda-error)))
7135 (hdmarker (org-get-at-bol 'org-hd-marker))
7136 (buffer (marker-buffer hdmarker))
7137 (pos (marker-position hdmarker))
7138 (inhibit-read-only t)
7139 newhead)
7140 (org-with-remote-undo buffer
7141 (with-current-buffer buffer
7142 (widen)
7143 (goto-char pos)
7144 (org-show-context 'agenda)
7145 (save-excursion
7146 (and (outline-next-heading)
7147 (org-flag-heading nil))) ; show the next heading
7148 (funcall 'org-priority force-direction)
7149 (end-of-line 1)
7150 (setq newhead (org-get-heading)))
7151 (org-agenda-change-all-lines newhead hdmarker)
7152 (beginning-of-line 1))))
7154 ;; FIXME: should fix the tags property of the agenda line.
7155 (defun org-agenda-set-tags (&optional tag onoff)
7156 "Set tags for the current headline."
7157 (interactive)
7158 (org-agenda-check-no-diary)
7159 (if (and (org-region-active-p) (interactive-p))
7160 (call-interactively 'org-change-tag-in-region)
7161 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7162 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7163 (org-agenda-error)))
7164 (buffer (marker-buffer hdmarker))
7165 (pos (marker-position hdmarker))
7166 (inhibit-read-only t)
7167 newhead)
7168 (org-with-remote-undo buffer
7169 (with-current-buffer buffer
7170 (widen)
7171 (goto-char pos)
7172 (save-excursion
7173 (org-show-context 'agenda))
7174 (save-excursion
7175 (and (outline-next-heading)
7176 (org-flag-heading nil))) ; show the next heading
7177 (goto-char pos)
7178 (if tag
7179 (org-toggle-tag tag onoff)
7180 (call-interactively 'org-set-tags))
7181 (end-of-line 1)
7182 (setq newhead (org-get-heading)))
7183 (org-agenda-change-all-lines newhead hdmarker)
7184 (beginning-of-line 1)))))
7186 (defun org-agenda-set-property ()
7187 "Set a property for the current headline."
7188 (interactive)
7189 (org-agenda-check-no-diary)
7190 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7191 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7192 (org-agenda-error)))
7193 (buffer (marker-buffer hdmarker))
7194 (pos (marker-position hdmarker))
7195 (inhibit-read-only t)
7196 newhead)
7197 (org-with-remote-undo buffer
7198 (with-current-buffer buffer
7199 (widen)
7200 (goto-char pos)
7201 (save-excursion
7202 (org-show-context 'agenda))
7203 (save-excursion
7204 (and (outline-next-heading)
7205 (org-flag-heading nil))) ; show the next heading
7206 (goto-char pos)
7207 (call-interactively 'org-set-property)))))
7209 (defun org-agenda-set-effort ()
7210 "Set the effort property for the current headline."
7211 (interactive)
7212 (org-agenda-check-no-diary)
7213 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7214 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7215 (org-agenda-error)))
7216 (buffer (marker-buffer hdmarker))
7217 (pos (marker-position hdmarker))
7218 (inhibit-read-only t)
7219 newhead)
7220 (org-with-remote-undo buffer
7221 (with-current-buffer buffer
7222 (widen)
7223 (goto-char pos)
7224 (save-excursion
7225 (org-show-context 'agenda))
7226 (save-excursion
7227 (and (outline-next-heading)
7228 (org-flag-heading nil))) ; show the next heading
7229 (goto-char pos)
7230 (call-interactively 'org-set-effort)
7231 (end-of-line 1)))))
7233 (defun org-agenda-toggle-archive-tag ()
7234 "Toggle the archive tag for the current entry."
7235 (interactive)
7236 (org-agenda-check-no-diary)
7237 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7238 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7239 (org-agenda-error)))
7240 (buffer (marker-buffer hdmarker))
7241 (pos (marker-position hdmarker))
7242 (inhibit-read-only t)
7243 newhead)
7244 (org-with-remote-undo buffer
7245 (with-current-buffer buffer
7246 (widen)
7247 (goto-char pos)
7248 (org-show-context 'agenda)
7249 (save-excursion
7250 (and (outline-next-heading)
7251 (org-flag-heading nil))) ; show the next heading
7252 (call-interactively 'org-toggle-archive-tag)
7253 (end-of-line 1)
7254 (setq newhead (org-get-heading)))
7255 (org-agenda-change-all-lines newhead hdmarker)
7256 (beginning-of-line 1))))
7258 (defun org-agenda-do-date-later (arg)
7259 (interactive "P")
7260 (cond
7261 ((or (equal arg '(16))
7262 (memq last-command
7263 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7264 (setq this-command 'org-agenda-date-later-minutes)
7265 (org-agenda-date-later-minutes 1))
7266 ((or (equal arg '(4))
7267 (memq last-command
7268 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7269 (setq this-command 'org-agenda-date-later-hours)
7270 (org-agenda-date-later-hours 1))
7272 (org-agenda-date-later (prefix-numeric-value arg)))))
7274 (defun org-agenda-do-date-earlier (arg)
7275 (interactive "P")
7276 (cond
7277 ((or (equal arg '(16))
7278 (memq last-command
7279 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7280 (setq this-command 'org-agenda-date-earlier-minutes)
7281 (org-agenda-date-earlier-minutes 1))
7282 ((or (equal arg '(4))
7283 (memq last-command
7284 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7285 (setq this-command 'org-agenda-date-earlier-hours)
7286 (org-agenda-date-earlier-hours 1))
7288 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7290 (defun org-agenda-date-later (arg &optional what)
7291 "Change the date of this item to ARG day(s) later."
7292 (interactive "p")
7293 (org-agenda-check-type t 'agenda 'timeline)
7294 (org-agenda-check-no-diary)
7295 (let* ((marker (or (org-get-at-bol 'org-marker)
7296 (org-agenda-error)))
7297 (buffer (marker-buffer marker))
7298 (pos (marker-position marker)))
7299 (org-with-remote-undo buffer
7300 (with-current-buffer buffer
7301 (widen)
7302 (goto-char pos)
7303 (if (not (org-at-timestamp-p))
7304 (error "Cannot find time stamp"))
7305 (org-timestamp-change arg (or what 'day)))
7306 (org-agenda-show-new-time marker org-last-changed-timestamp))
7307 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7309 (defun org-agenda-date-earlier (arg &optional what)
7310 "Change the date of this item to ARG day(s) earlier."
7311 (interactive "p")
7312 (org-agenda-date-later (- arg) what))
7314 (defun org-agenda-date-later-minutes (arg)
7315 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7316 (interactive "p")
7317 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7318 (org-agenda-date-later arg 'minute))
7320 (defun org-agenda-date-earlier-minutes (arg)
7321 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7322 (interactive "p")
7323 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7324 (org-agenda-date-earlier arg 'minute))
7326 (defun org-agenda-date-later-hours (arg)
7327 "Change the time of this item, in hour steps."
7328 (interactive "p")
7329 (org-agenda-date-later arg 'hour))
7331 (defun org-agenda-date-earlier-hours (arg)
7332 "Change the time of this item, in hour steps."
7333 (interactive "p")
7334 (org-agenda-date-earlier arg 'hour))
7336 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7337 "Show new date stamp via text properties."
7338 ;; We use text properties to make this undoable
7339 (let ((inhibit-read-only t)
7340 (buffer-invisibility-spec))
7341 (setq stamp (concat " " prefix " => " stamp))
7342 (save-excursion
7343 (goto-char (point-max))
7344 (while (not (bobp))
7345 (when (equal marker (org-get-at-bol 'org-marker))
7346 (org-move-to-column (- (window-width) (length stamp)) t)
7347 (org-agenda-fix-tags-filter-overlays-at (point))
7348 (if (featurep 'xemacs)
7349 ;; Use `duplicable' property to trigger undo recording
7350 (let ((ex (make-extent nil nil))
7351 (gl (make-glyph stamp)))
7352 (set-glyph-face gl 'secondary-selection)
7353 (set-extent-properties
7354 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7355 (insert-extent ex (1- (point)) (point-at-eol)))
7356 (add-text-properties
7357 (1- (point)) (point-at-eol)
7358 (list 'display (org-add-props stamp nil
7359 'face 'secondary-selection))))
7360 (beginning-of-line 1))
7361 (beginning-of-line 0)))))
7363 (defun org-agenda-date-prompt (arg)
7364 "Change the date of this item. Date is prompted for, with default today.
7365 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7366 be used to request time specification in the time stamp."
7367 (interactive "P")
7368 (org-agenda-check-type t 'agenda 'timeline)
7369 (org-agenda-check-no-diary)
7370 (let* ((marker (or (org-get-at-bol 'org-marker)
7371 (org-agenda-error)))
7372 (buffer (marker-buffer marker))
7373 (pos (marker-position marker)))
7374 (org-with-remote-undo buffer
7375 (with-current-buffer buffer
7376 (widen)
7377 (goto-char pos)
7378 (if (not (org-at-timestamp-p t))
7379 (error "Cannot find time stamp"))
7380 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7381 (org-agenda-show-new-time marker org-last-changed-timestamp))
7382 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7384 (defun org-agenda-schedule (arg &optional time)
7385 "Schedule the item at point.
7386 Arg is passed through to `org-schedule'."
7387 (interactive "P")
7388 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7389 (org-agenda-check-no-diary)
7390 (let* ((marker (or (org-get-at-bol 'org-marker)
7391 (org-agenda-error)))
7392 (type (marker-insertion-type marker))
7393 (buffer (marker-buffer marker))
7394 (pos (marker-position marker))
7395 (org-insert-labeled-timestamps-at-point nil)
7397 (set-marker-insertion-type marker t)
7398 (org-with-remote-undo buffer
7399 (with-current-buffer buffer
7400 (widen)
7401 (goto-char pos)
7402 (setq ts (org-schedule arg time)))
7403 (org-agenda-show-new-time marker ts "S"))
7404 (message "Item scheduled for %s" ts)))
7406 (defun org-agenda-deadline (arg &optional time)
7407 "Schedule the item at point.
7408 Arg is passed through to `org-deadline'."
7409 (interactive "P")
7410 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7411 (org-agenda-check-no-diary)
7412 (let* ((marker (or (org-get-at-bol 'org-marker)
7413 (org-agenda-error)))
7414 (buffer (marker-buffer marker))
7415 (pos (marker-position marker))
7416 (org-insert-labeled-timestamps-at-point nil)
7418 (org-with-remote-undo buffer
7419 (with-current-buffer buffer
7420 (widen)
7421 (goto-char pos)
7422 (setq ts (org-deadline arg time)))
7423 (org-agenda-show-new-time marker ts "D"))
7424 (message "Deadline for this item set to %s" ts)))
7426 (defun org-agenda-action ()
7427 "Select entry for agenda action, or execute an agenda action.
7428 This command prompts for another letter. Valid inputs are:
7430 m Mark the entry at point for an agenda action
7431 s Schedule the marked entry to the date at the cursor
7432 d Set the deadline of the marked entry to the date at the cursor
7433 r Call `org-remember' with cursor date as the default date
7434 c Call `org-capture' with cursor date as the default date
7435 SPC Show marked entry in other window
7436 TAB Visit marked entry in other window
7438 The cursor may be at a date in the calendar, or in the Org agenda."
7439 (interactive)
7440 (let (ans)
7441 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7442 (setq ans (read-char-exclusive))
7443 (cond
7444 ((equal ans ?m)
7445 ;; Mark this entry
7446 (if (eq major-mode 'org-agenda-mode)
7447 (let ((m (or (org-get-at-bol 'org-hd-marker)
7448 (org-get-at-bol 'org-marker))))
7449 (if m
7450 (progn
7451 (move-marker org-agenda-action-marker
7452 (marker-position m) (marker-buffer m))
7453 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7454 (error "Don't know which entry to mark")))
7455 (error "This command works only in the agenda")))
7456 ((equal ans ?s)
7457 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7458 ((equal ans ?d)
7459 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7460 ((equal ans ?r)
7461 (org-agenda-do-action '(org-remember) t))
7462 ((equal ans ?c)
7463 (org-agenda-do-action '(org-capture) t))
7464 ((equal ans ?\ )
7465 (let ((cw (selected-window)))
7466 (org-switch-to-buffer-other-window
7467 (marker-buffer org-agenda-action-marker))
7468 (goto-char org-agenda-action-marker)
7469 (org-show-context 'agenda)
7470 (select-window cw)))
7471 ((equal ans ?\C-i)
7472 (org-switch-to-buffer-other-window
7473 (marker-buffer org-agenda-action-marker))
7474 (goto-char org-agenda-action-marker)
7475 (org-show-context 'agenda))
7476 (t (error "Invalid agenda action %c" ans)))))
7478 (defun org-agenda-do-action (form &optional current-buffer)
7479 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7480 (let ((org-overriding-default-time (org-get-cursor-date)))
7481 (if current-buffer
7482 (eval form)
7483 (if (not (marker-buffer org-agenda-action-marker))
7484 (error "No entry has been selected for agenda action")
7485 (with-current-buffer (marker-buffer org-agenda-action-marker)
7486 (save-excursion
7487 (save-restriction
7488 (widen)
7489 (goto-char org-agenda-action-marker)
7490 (eval form))))))))
7492 (defun org-agenda-clock-in (&optional arg)
7493 "Start the clock on the currently selected item."
7494 (interactive "P")
7495 (org-agenda-check-no-diary)
7496 (if (equal arg '(4))
7497 (org-clock-in arg)
7498 (let* ((marker (or (org-get-at-bol 'org-marker)
7499 (org-agenda-error)))
7500 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7501 marker))
7502 (pos (marker-position marker))
7503 newhead)
7504 (org-with-remote-undo (marker-buffer marker)
7505 (with-current-buffer (marker-buffer marker)
7506 (widen)
7507 (goto-char pos)
7508 (org-show-context 'agenda)
7509 (org-show-entry)
7510 (org-cycle-hide-drawers 'children)
7511 (org-clock-in arg)
7512 (setq newhead (org-get-heading)))
7513 (org-agenda-change-all-lines newhead hdmarker)))))
7515 (defun org-agenda-clock-out ()
7516 "Stop the currently running clock."
7517 (interactive)
7518 (unless (marker-buffer org-clock-marker)
7519 (error "No running clock"))
7520 (let ((marker (make-marker)) newhead)
7521 (org-with-remote-undo (marker-buffer org-clock-marker)
7522 (with-current-buffer (marker-buffer org-clock-marker)
7523 (save-excursion
7524 (save-restriction
7525 (widen)
7526 (goto-char org-clock-marker)
7527 (org-back-to-heading t)
7528 (move-marker marker (point))
7529 (org-clock-out)
7530 (setq newhead (org-get-heading))))))
7531 (org-agenda-change-all-lines newhead marker)
7532 (move-marker marker nil)))
7534 (defun org-agenda-clock-cancel (&optional arg)
7535 "Cancel the currently running clock."
7536 (interactive "P")
7537 (unless (marker-buffer org-clock-marker)
7538 (error "No running clock"))
7539 (org-with-remote-undo (marker-buffer org-clock-marker)
7540 (org-clock-cancel)))
7542 (defun org-agenda-clock-goto ()
7543 "Jump to the currently clocked in task within the agenda.
7544 If the currently clocked in task is not listed in the agenda
7545 buffer, display it in another window."
7546 (interactive)
7547 (let (pos)
7548 (mapc (lambda (o)
7549 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7550 (setq pos (overlay-start o))))
7551 (overlays-in (point-min) (point-max)))
7552 (cond (pos (goto-char pos))
7553 ;; If the currently clocked entry is not in the agenda
7554 ;; buffer, we visit it in another window:
7555 (org-clock-current-task
7556 (org-switch-to-buffer-other-window (org-clock-goto)))
7557 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7559 (defun org-agenda-diary-entry-in-org-file ()
7560 "Make a diary entry in the file `org-agenda-diary-file'."
7561 (let (d1 d2 char (text "") dp1 dp2)
7562 (if (equal (buffer-name) "*Calendar*")
7563 (setq d1 (calendar-cursor-to-date t)
7564 d2 (car calendar-mark-ring))
7565 (setq dp1 (get-text-property (point-at-bol) 'day))
7566 (unless dp1 (error "No date defined in current line"))
7567 (setq d1 (calendar-gregorian-from-absolute dp1)
7568 d2 (and (ignore-errors (mark))
7569 (save-excursion
7570 (goto-char (mark))
7571 (setq dp2 (get-text-property (point-at-bol) 'day)))
7572 (calendar-gregorian-from-absolute dp2))))
7573 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7574 (setq char (read-char-exclusive))
7575 (cond
7576 ((equal char ?d)
7577 (setq text (read-string "Day entry: "))
7578 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7579 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7580 ((equal char ?a)
7581 (setq d1 (list (car d1) (nth 1 d1)
7582 (read-number (format "Reference year [%d]: " (nth 2 d1))
7583 (nth 2 d1))))
7584 (setq text (read-string "Anniversary (use %d to show years): "))
7585 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7586 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7587 ((equal char ?b)
7588 (setq text (read-string "Block entry: "))
7589 (unless (and d1 d2 (not (equal d1 d2)))
7590 (error "No block of days selected"))
7591 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7592 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7593 ((equal char ?j)
7594 (org-switch-to-buffer-other-window
7595 (find-file-noselect org-agenda-diary-file))
7596 (require 'org-datetree)
7597 (org-datetree-find-date-create d1)
7598 (org-reveal t))
7599 (t (error "Invalid selection character `%c'" char)))))
7601 (defcustom org-agenda-insert-diary-strategy 'date-tree
7602 "Where in `org-agenda-diary-file' should new entries be added?
7603 Valid values:
7605 date-tree in the date tree, as child of the date
7606 top-level as top-level entries at the end of the file."
7607 :group 'org-agenda
7608 :type '(choice
7609 (const :tag "in a date tree" date-tree)
7610 (const :tag "as top level at end of file" top-level)))
7612 (defcustom org-agenda-insert-diary-extract-time nil
7613 "Non-nil means extract any time specification from the diary entry."
7614 :group 'org-agenda
7615 :type 'boolean)
7617 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7618 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7619 If TEXT is not empty, it will become the headline of the new entry, and
7620 the resulting entry will not be shown. When TEXT is empty, switch to
7621 `org-agenda-diary-file' and let the user finish the entry there."
7622 (let ((cw (current-window-configuration)))
7623 (org-switch-to-buffer-other-window
7624 (find-file-noselect org-agenda-diary-file))
7625 (widen)
7626 (goto-char (point-min))
7627 (cond
7628 ((eq type 'anniversary)
7629 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7630 (progn
7631 (or (org-on-heading-p t)
7632 (progn
7633 (outline-next-heading)
7634 (insert "* Anniversaries\n\n")
7635 (beginning-of-line -1)))))
7636 (outline-next-heading)
7637 (org-back-over-empty-lines)
7638 (backward-char 1)
7639 (insert "\n")
7640 (require 'diary-lib)
7641 (let ((calendar-date-display-form
7642 (if (if (boundp 'calendar-date-style)
7643 (eq calendar-date-style 'european)
7644 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7645 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7646 '(day " " month " " year)
7647 '(month " " day " " year))))
7649 (insert (format "%%%%(diary-anniversary %s) %s"
7650 (calendar-date-string d1 nil t) text))))
7651 ((eq type 'day)
7652 (let ((org-prefix-has-time t)
7653 (org-agenda-time-leading-zero t)
7654 fmt time time2)
7655 (if org-agenda-insert-diary-extract-time
7656 ;; Use org-format-agenda-item to parse text for a time-range and
7657 ;; remove it. FIXME: This is a hack, we should refactor
7658 ;; that function to make time extraction available separately
7659 (setq fmt (org-format-agenda-item nil text nil nil t)
7660 time (get-text-property 0 'time fmt)
7661 time2 (if (> (length time) 0)
7662 ;; split-string removes trailing ...... if
7663 ;; no end time given. First space
7664 ;; separates time from date.
7665 (concat " " (car (split-string time "\\.")))
7666 nil)
7667 text (get-text-property 0 'txt fmt)))
7668 (if (eq org-agenda-insert-diary-strategy 'top-level)
7669 (org-agenda-insert-diary-as-top-level text)
7670 (require 'org-datetree)
7671 (org-datetree-find-date-create d1)
7672 (org-agenda-insert-diary-make-new-entry text))
7673 (org-insert-time-stamp (org-time-from-absolute
7674 (calendar-absolute-from-gregorian d1))
7675 nil nil nil nil time2))
7676 (end-of-line 0))
7677 ((eq type 'block)
7678 (if (> (calendar-absolute-from-gregorian d1)
7679 (calendar-absolute-from-gregorian d2))
7680 (setq d1 (prog1 d2 (setq d2 d1))))
7681 (if (eq org-agenda-insert-diary-strategy 'top-level)
7682 (org-agenda-insert-diary-as-top-level text)
7683 (require 'org-datetree)
7684 (org-datetree-find-date-create d1)
7685 (org-agenda-insert-diary-make-new-entry text))
7686 (org-insert-time-stamp (org-time-from-absolute
7687 (calendar-absolute-from-gregorian d1)))
7688 (insert "--")
7689 (org-insert-time-stamp (org-time-from-absolute
7690 (calendar-absolute-from-gregorian d2)))
7691 (end-of-line 0)))
7692 (if (string-match "\\S-" text)
7693 (progn
7694 (set-window-configuration cw)
7695 (message "%s entry added to %s"
7696 (capitalize (symbol-name type))
7697 (abbreviate-file-name org-agenda-diary-file)))
7698 (org-reveal t)
7699 (message "Please finish entry here"))))
7701 (defun org-agenda-insert-diary-as-top-level (text)
7702 "Make new entry as a top-level entry at the end of the file.
7703 Add TEXT as headline, and position the cursor in the second line so that
7704 a timestamp can be added there."
7705 (widen)
7706 (goto-char (point-max))
7707 (or (bolp) (insert "\n"))
7708 (insert "* " text "\n")
7709 (if org-adapt-indentation (org-indent-to-column 2)))
7711 (defun org-agenda-insert-diary-make-new-entry (text)
7712 "Make new entry as last child of current entry.
7713 Add TEXT as headline, and position the cursor in the second line so that
7714 a timestamp can be added there."
7715 (let ((org-show-following-heading t)
7716 (org-show-siblings t)
7717 (org-show-hierarchy-above t)
7718 (org-show-entry-below t)
7719 col)
7720 (outline-next-heading)
7721 (org-back-over-empty-lines)
7722 (or (looking-at "[ \t]*$")
7723 (progn (insert "\n") (backward-char 1)))
7724 (org-insert-heading nil t)
7725 (org-do-demote)
7726 (setq col (current-column))
7727 (insert text "\n")
7728 (if org-adapt-indentation (org-indent-to-column col))
7729 (let ((org-show-following-heading t)
7730 (org-show-siblings t)
7731 (org-show-hierarchy-above t)
7732 (org-show-entry-below t))
7733 (org-show-context))))
7735 (defun org-agenda-diary-entry ()
7736 "Make a diary entry, like the `i' command from the calendar.
7737 All the standard commands work: block, weekly etc.
7738 When `org-agenda-diary-file' points to a file,
7739 `org-agenda-diary-entry-in-org-file' is called instead to create
7740 entries in that Org-mode file."
7741 (interactive)
7742 (org-agenda-check-type t 'agenda 'timeline)
7743 (if (not (eq org-agenda-diary-file 'diary-file))
7744 (org-agenda-diary-entry-in-org-file)
7745 (require 'diary-lib)
7746 (let* ((char (progn
7747 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7748 (read-char-exclusive)))
7749 (cmd (cdr (assoc char
7750 '((?d . insert-diary-entry)
7751 (?w . insert-weekly-diary-entry)
7752 (?m . insert-monthly-diary-entry)
7753 (?y . insert-yearly-diary-entry)
7754 (?a . insert-anniversary-diary-entry)
7755 (?b . insert-block-diary-entry)
7756 (?c . insert-cyclic-diary-entry)))))
7757 (oldf (symbol-function 'calendar-cursor-to-date))
7758 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7759 (point (point))
7760 (mark (or (mark t) (point))))
7761 (unless cmd
7762 (error "No command associated with <%c>" char))
7763 (unless (and (get-text-property point 'day)
7764 (or (not (equal ?b char))
7765 (get-text-property mark 'day)))
7766 (error "Don't know which date to use for diary entry"))
7767 ;; We implement this by hacking the `calendar-cursor-to-date' function
7768 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7769 (let ((calendar-mark-ring
7770 (list (calendar-gregorian-from-absolute
7771 (or (get-text-property mark 'day)
7772 (get-text-property point 'day))))))
7773 (unwind-protect
7774 (progn
7775 (fset 'calendar-cursor-to-date
7776 (lambda (&optional error dummy)
7777 (calendar-gregorian-from-absolute
7778 (get-text-property point 'day))))
7779 (call-interactively cmd))
7780 (fset 'calendar-cursor-to-date oldf))))))
7782 (defun org-agenda-execute-calendar-command (cmd)
7783 "Execute a calendar command from the agenda, with the date associated to
7784 the cursor position."
7785 (org-agenda-check-type t 'agenda 'timeline)
7786 (require 'diary-lib)
7787 (unless (get-text-property (point) 'day)
7788 (error "Don't know which date to use for calendar command"))
7789 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7790 (point (point))
7791 (date (calendar-gregorian-from-absolute
7792 (get-text-property point 'day)))
7793 ;; the following 2 vars are needed in the calendar
7794 (displayed-month (car date))
7795 (displayed-year (nth 2 date)))
7796 (unwind-protect
7797 (progn
7798 (fset 'calendar-cursor-to-date
7799 (lambda (&optional error dummy)
7800 (calendar-gregorian-from-absolute
7801 (get-text-property point 'day))))
7802 (call-interactively cmd))
7803 (fset 'calendar-cursor-to-date oldf))))
7805 (defun org-agenda-phases-of-moon ()
7806 "Display the phases of the moon for the 3 months around the cursor date."
7807 (interactive)
7808 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7810 (defun org-agenda-holidays ()
7811 "Display the holidays for the 3 months around the cursor date."
7812 (interactive)
7813 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7815 (defvar calendar-longitude)
7816 (defvar calendar-latitude)
7817 (defvar calendar-location-name)
7819 (defun org-agenda-sunrise-sunset (arg)
7820 "Display sunrise and sunset for the cursor date.
7821 Latitude and longitude can be specified with the variables
7822 `calendar-latitude' and `calendar-longitude'. When called with prefix
7823 argument, latitude and longitude will be prompted for."
7824 (interactive "P")
7825 (require 'solar)
7826 (let ((calendar-longitude (if arg nil calendar-longitude))
7827 (calendar-latitude (if arg nil calendar-latitude))
7828 (calendar-location-name
7829 (if arg "the given coordinates" calendar-location-name)))
7830 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7832 (defun org-agenda-goto-calendar ()
7833 "Open the Emacs calendar with the date at the cursor."
7834 (interactive)
7835 (org-agenda-check-type t 'agenda 'timeline)
7836 (let* ((day (or (get-text-property (point) 'day)
7837 (error "Don't know which date to open in calendar")))
7838 (date (calendar-gregorian-from-absolute day))
7839 (calendar-move-hook nil)
7840 (calendar-view-holidays-initially-flag nil)
7841 (calendar-view-diary-initially-flag nil))
7842 (calendar)
7843 (calendar-goto-date date)))
7845 ;;;###autoload
7846 (defun org-calendar-goto-agenda ()
7847 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7848 This is a command that has to be installed in `calendar-mode-map'."
7849 (interactive)
7850 (org-agenda-list nil (calendar-absolute-from-gregorian
7851 (calendar-cursor-to-date))
7852 nil))
7854 (defun org-agenda-convert-date ()
7855 (interactive)
7856 (org-agenda-check-type t 'agenda 'timeline)
7857 (let ((day (get-text-property (point) 'day))
7858 date s)
7859 (unless day
7860 (error "Don't know which date to convert"))
7861 (setq date (calendar-gregorian-from-absolute day))
7862 (setq s (concat
7863 "Gregorian: " (calendar-date-string date) "\n"
7864 "ISO: " (calendar-iso-date-string date) "\n"
7865 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7866 "Julian: " (calendar-julian-date-string date) "\n"
7867 "Astron. JD: " (calendar-astro-date-string date)
7868 " (Julian date number at noon UTC)\n"
7869 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7870 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7871 "French: " (calendar-french-date-string date) "\n"
7872 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7873 "Mayan: " (calendar-mayan-date-string date) "\n"
7874 "Coptic: " (calendar-coptic-date-string date) "\n"
7875 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7876 "Persian: " (calendar-persian-date-string date) "\n"
7877 "Chinese: " (calendar-chinese-date-string date) "\n"))
7878 (with-output-to-temp-buffer "*Dates*"
7879 (princ s))
7880 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7882 ;;; Bulk commands
7884 (defvar org-agenda-bulk-marked-entries nil
7885 "List of markers that refer to marked entries in the agenda.")
7887 (defun org-agenda-bulk-marked-p ()
7888 (eq (get-char-property (point-at-bol) 'type)
7889 'org-marked-entry-overlay))
7891 (defun org-agenda-bulk-mark (&optional arg)
7892 "Mark the entry at point for future bulk action."
7893 (interactive "p")
7894 (dotimes (i (max arg 1))
7895 (unless (org-get-at-bol 'org-agenda-diary-link)
7896 (let* ((m (org-get-at-bol 'org-hd-marker))
7898 (unless (org-agenda-bulk-marked-p)
7899 (unless m (error "Nothing to mark at point"))
7900 (push m org-agenda-bulk-marked-entries)
7901 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7902 (org-overlay-display ov "> "
7903 (org-get-todo-face "TODO")
7904 'evaporate)
7905 (overlay-put ov 'type 'org-marked-entry-overlay))
7906 (beginning-of-line 2)
7907 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7908 (beginning-of-line 2))
7909 (message "%d entries marked for bulk action"
7910 (length org-agenda-bulk-marked-entries))))))
7912 (defun org-agenda-bulk-mark-regexp (regexp)
7913 "Mark entries match REGEXP."
7914 (interactive "sMark entries matching regexp: ")
7915 (let (entries-marked)
7916 (save-excursion
7917 (goto-char (point-min))
7918 (goto-char (next-single-property-change (point) 'txt))
7919 (while (re-search-forward regexp nil t)
7920 (when (string-match regexp (get-text-property (point) 'txt))
7921 (setq entries-marked (+ entries-marked 1))
7922 (call-interactively 'org-agenda-bulk-mark))))
7923 (if (not entries-marked)
7924 (message "No entry matching this regexp."))))
7926 (defun org-agenda-bulk-unmark ()
7927 "Unmark the entry at point for future bulk action."
7928 (interactive)
7929 (when (org-agenda-bulk-marked-p)
7930 (org-agenda-bulk-remove-overlays
7931 (point-at-bol) (+ 2 (point-at-bol)))
7932 (setq org-agenda-bulk-marked-entries
7933 (delete (org-get-at-bol 'org-hd-marker)
7934 org-agenda-bulk-marked-entries)))
7935 (beginning-of-line 2)
7936 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7937 (beginning-of-line 2))
7938 (message "%d entries marked for bulk action"
7939 (length org-agenda-bulk-marked-entries)))
7941 (defun org-agenda-bulk-toggle ()
7942 "Toggle marking the entry at point for bulk action."
7943 (interactive)
7944 (if (org-agenda-bulk-marked-p)
7945 (org-agenda-bulk-unmark)
7946 (org-agenda-bulk-mark)))
7948 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7949 "Remove the mark overlays between BEG and END in the agenda buffer.
7950 BEG and END default to the buffer limits.
7952 This only removes the overlays, it does not remove the markers
7953 from the list in `org-agenda-bulk-marked-entries'."
7954 (interactive)
7955 (mapc (lambda (ov)
7956 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7957 (delete-overlay ov)))
7958 (overlays-in (or beg (point-min)) (or end (point-max)))))
7960 (defun org-agenda-bulk-remove-all-marks ()
7961 "Remove all marks in the agenda buffer.
7962 This will remove the markers, and the overlays."
7963 (interactive)
7964 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7965 (setq org-agenda-bulk-marked-entries nil)
7966 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7968 (defun org-agenda-bulk-action (&optional arg)
7969 "Execute an remote-editing action on all marked entries.
7970 The prefix arg is passed through to the command if possible."
7971 (interactive "P")
7972 (unless org-agenda-bulk-marked-entries
7973 (error "No entries are marked"))
7974 (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
7975 (let* ((action (read-char-exclusive))
7976 (org-log-refile (if org-log-refile 'time nil))
7977 (entries (reverse org-agenda-bulk-marked-entries))
7978 redo-at-end
7979 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7980 (cond
7981 ((equal action ?$)
7982 (setq cmd '(org-agenda-archive)))
7984 ((equal action ?A)
7985 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7987 ((member action '(?r ?w))
7988 (setq rfloc (org-refile-get-location
7989 "Refile to"
7990 (marker-buffer (car org-agenda-bulk-marked-entries))
7991 org-refile-allow-creating-parent-nodes))
7992 (if (nth 3 rfloc)
7993 (setcar (nthcdr 3 rfloc)
7994 (move-marker (make-marker) (nth 3 rfloc)
7995 (or (get-file-buffer (nth 1 rfloc))
7996 (find-buffer-visiting (nth 1 rfloc))
7997 (error "This should not happen")))))
7999 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8000 redo-at-end t))
8002 ((equal action ?t)
8003 (setq state (org-icompleting-read
8004 "Todo state: "
8005 (with-current-buffer (marker-buffer (car entries))
8006 (mapcar 'list org-todo-keywords-1))))
8007 (setq cmd `(let ((org-inhibit-blocking t)
8008 (org-inhibit-logging 'note))
8009 (org-agenda-todo ,state))))
8011 ((memq action '(?- ?+))
8012 (setq tag (org-icompleting-read
8013 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8014 (with-current-buffer (marker-buffer (car entries))
8015 (delq nil
8016 (mapcar (lambda (x)
8017 (if (stringp (car x)) x)) org-tag-alist)))))
8018 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8020 ((memq action '(?s ?d))
8021 (let* ((date (unless arg
8022 (org-read-date
8023 nil nil nil
8024 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8025 (ans (if arg nil org-read-date-final-answer))
8026 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8027 (setq cmd `(let* ((bound (fboundp 'read-string))
8028 (old (and bound (symbol-function 'read-string))))
8029 (unwind-protect
8030 (progn
8031 (fset 'read-string (lambda (&rest ignore) ,ans))
8032 (eval '(,c1 arg)))
8033 (if bound
8034 (fset 'read-string old)
8035 (fmakunbound 'read-string)))))))
8037 ((equal action ?S)
8038 (if (not (org-agenda-check-type nil 'agenda 'timeline))
8039 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8040 (let ((days (read-number
8041 (format "Scatter tasks across how many %sdays: "
8042 (if arg "week" "")) 7)))
8043 (setq cmd
8044 `(let ((distance (1+ (random ,days))))
8045 (if arg
8046 (let ((dist distance)
8047 (day-of-week
8048 (calendar-day-of-week
8049 (calendar-gregorian-from-absolute (org-today)))))
8050 (dotimes (i (1+ dist))
8051 (while (member day-of-week org-agenda-weekend-days)
8052 (incf distance)
8053 (incf day-of-week)
8054 (if (= day-of-week 7)
8055 (setq day-of-week 0)))
8056 (incf day-of-week)
8057 (if (= day-of-week 7)
8058 (setq day-of-week 0)))))
8059 ;; silently fail when try to replan a sexp entry
8060 (condition-case nil
8061 (org-agenda-date-later distance)
8062 (error nil)))))))
8064 (t (error "Invalid bulk action")))
8066 ;; Sort the markers, to make sure that parents are handled before children
8067 (setq entries (sort entries
8068 (lambda (a b)
8069 (cond
8070 ((equal (marker-buffer a) (marker-buffer b))
8071 (< (marker-position a) (marker-position b)))
8073 (string< (buffer-name (marker-buffer a))
8074 (buffer-name (marker-buffer b))))))))
8076 ;; Now loop over all markers and apply cmd
8077 (while (setq e (pop entries))
8078 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8079 (if (not pos)
8080 (progn (message "Skipping removed entry at %s" e)
8081 (setq cntskip (1+ cntskip)))
8082 (goto-char pos)
8083 (eval cmd)
8084 (setq org-agenda-bulk-marked-entries
8085 (delete e org-agenda-bulk-marked-entries))
8086 (setq cnt (1+ cnt))))
8087 (setq org-agenda-bulk-marked-entries nil)
8088 (org-agenda-bulk-remove-all-marks)
8089 (when redo-at-end (org-agenda-redo))
8090 (message "Acted on %d entries%s"
8092 (if (= cntskip 0)
8094 (format ", skipped %d (disappeared before their turn)"
8095 cntskip)))))
8097 ;;; Flagging notes
8099 (defun org-agenda-show-the-flagging-note ()
8100 "Display the flagging note in the other window.
8101 When called a second time in direct sequence, offer to remove the FLAGGING
8102 tag and (if present) the flagging note."
8103 (interactive)
8104 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8105 (win (selected-window))
8106 note heading newhead)
8107 (unless hdmarker
8108 (error "No linked entry at point"))
8109 (if (and (eq this-command last-command)
8110 (y-or-n-p "Unflag and remove any flagging note? "))
8111 (progn
8112 (org-agenda-remove-flag hdmarker)
8113 (let ((win (get-buffer-window "*Flagging Note*")))
8114 (and win (delete-window win)))
8115 (message "Entry unflaged"))
8116 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8117 (unless note
8118 (error "No flagging note"))
8119 (org-kill-new note)
8120 (org-switch-to-buffer-other-window "*Flagging Note*")
8121 (erase-buffer)
8122 (insert note)
8123 (goto-char (point-min))
8124 (while (re-search-forward "\\\\n" nil t)
8125 (replace-match "\n" t t))
8126 (goto-char (point-min))
8127 (select-window win)
8128 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8130 (defun org-agenda-remove-flag (marker)
8131 "Remove the FLAGGED tag and any flagging note in the entry."
8132 (let (newhead)
8133 (org-with-point-at marker
8134 (org-toggle-tag "FLAGGED" 'off)
8135 (org-entry-delete nil "THEFLAGGINGNOTE")
8136 (setq newhead (org-get-heading)))
8137 (org-agenda-change-all-lines newhead marker)
8138 (message "Entry unflaged")))
8140 (defun org-agenda-get-any-marker (&optional pos)
8141 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8142 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8144 ;;; Appointment reminders
8146 (defvar appt-time-msg-list)
8148 ;;;###autoload
8149 (defun org-agenda-to-appt (&optional refresh filter)
8150 "Activate appointments found in `org-agenda-files'.
8151 With a \\[universal-argument] prefix, refresh the list of
8152 appointments.
8154 If FILTER is t, interactively prompt the user for a regular
8155 expression, and filter out entries that don't match it.
8157 If FILTER is a string, use this string as a regular expression
8158 for filtering entries out.
8160 FILTER can also be an alist with the car of each cell being
8161 either 'headline or 'category. For example:
8163 '((headline \"IMPORTANT\")
8164 (category \"Work\"))
8166 will only add headlines containing IMPORTANT or headlines
8167 belonging to the \"Work\" category."
8168 (interactive "P")
8169 (if refresh (setq appt-time-msg-list nil))
8170 (if (eq filter t)
8171 (setq filter (read-from-minibuffer "Regexp filter: ")))
8172 (let* ((cnt 0) ; count added events
8173 (org-agenda-new-buffers nil)
8174 (org-deadline-warning-days 0)
8175 ;; Do not use `org-today' here because appt only takes
8176 ;; time and without date as argument, so it may pass wrong
8177 ;; information otherwise
8178 (today (org-date-to-gregorian
8179 (time-to-days (current-time))))
8180 (org-agenda-restrict nil)
8181 (files (org-agenda-files 'unrestricted)) entries file)
8182 ;; Get all entries which may contain an appt
8183 (org-prepare-agenda-buffers files)
8184 (while (setq file (pop files))
8185 (setq entries
8186 (append entries
8187 (org-agenda-get-day-entries
8188 file today :timestamp :scheduled :deadline))))
8189 (setq entries (delq nil entries))
8190 ;; Map thru entries and find if we should filter them out
8191 (mapc
8192 (lambda(x)
8193 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8194 (cat (get-text-property 1 'org-category x))
8195 (tod (get-text-property 1 'time-of-day x))
8196 (ok (or (null filter)
8197 (and (stringp filter) (string-match filter evt))
8198 (and (listp filter)
8199 (or (string-match
8200 (cadr (assoc 'category filter)) cat)
8201 (string-match
8202 (cadr (assoc 'headline filter)) evt))))))
8203 ;; FIXME: Shall we remove text-properties for the appt text?
8204 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8205 (when (and ok tod)
8206 (setq tod (concat "00" (number-to-string tod))
8207 tod (when (string-match
8208 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8209 (concat (match-string 1 tod) ":"
8210 (match-string 2 tod))))
8211 (appt-add tod evt)
8212 (setq cnt (1+ cnt))))) entries)
8213 (org-release-buffers org-agenda-new-buffers)
8214 (if (eq cnt 0)
8215 (message "No event to add")
8216 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8218 (defun org-agenda-todayp (date)
8219 "Does DATE mean today, when considering `org-extend-today-until'?"
8220 (let ((today (org-today))
8221 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8222 date)))
8223 (eq date today)))
8225 (provide 'org-agenda)
8227 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8229 ;;; org-agenda.el ends here