Release 7.5
[org-mode/org-tableheadings.git] / lisp / org-agenda.el
blob5b48a2fffc9326231953d2ae46639e39b86301cc
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.5
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
93 :group 'org-agenda
94 :type 'boolean)
96 (defcustom org-agenda-block-separator ?=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group 'org-agenda-export
125 :type '(repeat
126 (list
127 (variable)
128 (sexp :tag "Value"))))
130 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group 'org-agenda-export
134 :type 'hook
135 :options '(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines 0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
148 :group 'org-agenda
149 :type 'integer)
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
156 :group 'org-agenda
157 :type 'boolean)
159 (defcustom org-agenda-export-html-style ""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group 'org-agenda-export
198 :group 'org-export-html
199 :type 'string)
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-span)
246 (choice (const :tag "Day" 'day)
247 (const :tag "Week" 'week)
248 (const :tag "Month" 'month)
249 (const :tag "Year" 'year)
250 (integer :tag "Custom")))
251 (list :tag "Fixed starting date"
252 (const org-agenda-start-day)
253 (string :value "2007-11-01"))
254 (list :tag "Start on day of week"
255 (const org-agenda-start-on-weekday)
256 (choice :value 1
257 (const :tag "Today" nil)
258 (integer :tag "Weekday No.")))
259 (list :tag "Include data from diary"
260 (const org-agenda-include-diary)
261 (boolean))
262 (list :tag "Deadline Warning days"
263 (const org-deadline-warning-days)
264 (integer :value 1))
265 (list :tag "Tags filter preset"
266 (const org-agenda-filter-preset)
267 (list
268 (const :format "" quote)
269 (repeat
270 (string :tag "+tag or -tag"))))
271 (list :tag "Set daily/weekly entry types"
272 (const org-agenda-entry-types)
273 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
274 (const :deadline)
275 (const :scheduled)
276 (const :timestamp)
277 (const :sexp)))
278 (list :tag "Standard skipping condition"
279 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
280 (const org-agenda-skip-function)
281 (list
282 (const :format "" quote)
283 (list
284 (choice
285 :tag "Skipping range"
286 (const :tag "Skip entry" org-agenda-skip-entry-if)
287 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
288 (repeat :inline t :tag "Conditions for skipping"
289 (choice
290 :tag "Condition type"
291 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
292 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
293 (list :tag "TODO state is" :inline t
294 (const 'todo)
295 (choice
296 (const :tag "any not-done state" 'todo)
297 (const :tag "any done state" 'done)
298 (const :tag "any state" 'any)
299 (list :tag "Keyword list"
300 (const :format "" quote)
301 (repeat (string :tag "Keyword")))))
302 (list :tag "TODO state is not" :inline t
303 (const 'nottodo)
304 (choice
305 (const :tag "any not-done state" 'todo)
306 (const :tag "any done state" 'done)
307 (const :tag "any state" 'any)
308 (list :tag "Keyword list"
309 (const :format "" quote)
310 (repeat (string :tag "Keyword")))))
311 (const :tag "scheduled" 'scheduled)
312 (const :tag "not scheduled" 'notscheduled)
313 (const :tag "deadline" 'deadline)
314 (const :tag "no deadline" 'notdeadline)
315 (const :tag "timestamp" 'timestamp)
316 (const :tag "no timestamp" 'nottimestamp))))))
317 (list :tag "Non-standard skipping condition"
318 :value (org-agenda-skip-function)
319 (const org-agenda-skip-function)
320 (sexp :tag "Function or form (quoted!)"))
321 (list :tag "Any variable"
322 (variable :tag "Variable")
323 (sexp :tag "Value (sexp)"))))
324 "Selection of examples for agenda command settings.
325 This will be spliced into the custom type of
326 `org-agenda-custom-commands'.")
329 (defcustom org-agenda-custom-commands nil
330 "Custom commands for the agenda.
331 These commands will be offered on the splash screen displayed by the
332 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
334 (key desc type match settings files)
336 key The key (one or more characters as a string) to be associated
337 with the command.
338 desc A description of the command, when omitted or nil, a default
339 description is built using MATCH.
340 type The command type, any of the following symbols:
341 agenda The daily/weekly agenda.
342 todo Entries with a specific TODO keyword, in all agenda files.
343 search Entries containing search words entry or headline.
344 tags Tags/Property/TODO match in all agenda files.
345 tags-todo Tags/P/T match in all agenda files, TODO entries only.
346 todo-tree Sparse tree of specific TODO keyword in *current* file.
347 tags-tree Sparse tree with all tags matches in *current* file.
348 occur-tree Occur sparse tree for *current* file.
349 ... A user-defined function.
350 match What to search for:
351 - a single keyword for TODO keyword searches
352 - a tags match expression for tags searches
353 - a word search expression for text searches.
354 - a regular expression for occur searches
355 For all other commands, this should be the empty string.
356 settings A list of option settings, similar to that in a let form, so like
357 this: ((opt1 val1) (opt2 val2) ...). The values will be
358 evaluated at the moment of execution, so quote them when needed.
359 files A list of files file to write the produced agenda buffer to
360 with the command `org-store-agenda-views'.
361 If a file name ends in \".html\", an HTML version of the buffer
362 is written out. If it ends in \".ps\", a postscript version is
363 produced. Otherwise, only the plain text is written to the file.
365 You can also define a set of commands, to create a composite agenda buffer.
366 In this case, an entry looks like this:
368 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
370 where
372 desc A description string to be displayed in the dispatcher menu.
373 cmd An agenda command, similar to the above. However, tree commands
374 are no allowed, but instead you can get agenda and global todo list.
375 So valid commands for a set are:
376 (agenda \"\" settings)
377 (alltodo \"\" settings)
378 (stuck \"\" settings)
379 (todo \"match\" settings files)
380 (search \"match\" settings files)
381 (tags \"match\" settings files)
382 (tags-todo \"match\" settings files)
384 Each command can carry a list of options, and another set of options can be
385 given for the whole set of commands. Individual command options take
386 precedence over the general options.
388 When using several characters as key to a command, the first characters
389 are prefix commands. For the dispatcher to display useful information, you
390 should provide a description for the prefix, like
392 (setq org-agenda-custom-commands
393 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
394 (\"hl\" tags \"+HOME+Lisa\")
395 (\"hp\" tags \"+HOME+Peter\")
396 (\"hk\" tags \"+HOME+Kim\")))"
397 :group 'org-agenda-custom-commands
398 :type `(repeat
399 (choice :value ("x" "Describe command here" tags "" nil)
400 (list :tag "Single command"
401 (string :tag "Access Key(s) ")
402 (option (string :tag "Description"))
403 (choice
404 (const :tag "Agenda" agenda)
405 (const :tag "TODO list" alltodo)
406 (const :tag "Search words" search)
407 (const :tag "Stuck projects" stuck)
408 (const :tag "Tags/Property match (all agenda files)" tags)
409 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
410 (const :tag "TODO keyword search (all agenda files)" todo)
411 (const :tag "Tags sparse tree (current buffer)" tags-tree)
412 (const :tag "TODO keyword tree (current buffer)" todo-tree)
413 (const :tag "Occur tree (current buffer)" occur-tree)
414 (sexp :tag "Other, user-defined function"))
415 (string :tag "Match (only for some commands)")
416 ,org-agenda-custom-commands-local-options
417 (option (repeat :tag "Export" (file :tag "Export to"))))
418 (list :tag "Command series, all agenda files"
419 (string :tag "Access Key(s)")
420 (string :tag "Description ")
421 (repeat :tag "Component"
422 (choice
423 (list :tag "Agenda"
424 (const :format "" agenda)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "TODO list (all keywords)"
428 (const :format "" alltodo)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Search words"
432 (const :format "" search)
433 (string :tag "Match")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Stuck projects"
436 (const :format "" stuck)
437 (const :tag "" :format "" "")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search"
440 (const :format "" tags)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search, TODO entries only"
444 (const :format "" tags-todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "TODO keyword search"
448 (const :format "" todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "Other, user-defined function"
452 (symbol :tag "function")
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)))
456 (repeat :tag "Settings for entire command set"
457 (list (variable :tag "Any variable")
458 (sexp :tag "Value")))
459 (option (repeat :tag "Export" (file :tag "Export to"))))
460 (cons :tag "Prefix key documentation"
461 (string :tag "Access Key(s)")
462 (string :tag "Description ")))))
464 (defcustom org-agenda-query-register ?o
465 "The register holding the current query string.
466 The purpose of this is that if you construct a query string interactively,
467 you can then use it to define a custom command."
468 :group 'org-agenda-custom-commands
469 :type 'character)
471 (defcustom org-stuck-projects
472 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
473 "How to identify stuck projects.
474 This is a list of four items:
475 1. A tags/todo/property matcher string that is used to identify a project.
476 See the manual for a description of tag and property searches.
477 The entire tree below a headline matched by this is considered one project.
478 2. A list of TODO keywords identifying non-stuck projects.
479 If the project subtree contains any headline with one of these todo
480 keywords, the project is considered to be not stuck. If you specify
481 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
482 3. A list of tags identifying non-stuck projects.
483 If the project subtree contains any headline with one of these tags,
484 the project is considered to be not stuck. If you specify \"*\" as
485 a tag, any tag will mark the project unstuck. Note that this is about
486 the explicit presence of a tag somewhere in the subtree, inherited
487 tags to not count here. If inherited tags make a project not stuck,
488 use \"-TAG\" in the tags part of the matcher under (1.) above.
489 4. An arbitrary regular expression matching non-stuck projects.
491 If the project turns out to be not stuck, search continues also in the
492 subtree to see if any of the subtasks have project status.
494 See also the variable `org-tags-match-list-sublevels' which applies
495 to projects matched by this search as well.
497 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
498 or `C-c a #' to produce the list."
499 :group 'org-agenda-custom-commands
500 :type '(list
501 (string :tag "Tags/TODO match to identify a project")
502 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
503 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
504 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
506 (defcustom org-agenda-filter-effort-default-operator "<"
507 "The default operator for effort estimate filtering.
508 If you select an effort estimate limit without first pressing an operator,
509 this one will be used."
510 :group 'org-agenda-custom-commands
511 :type '(choice (const :tag "less or equal" "<")
512 (const :tag "greater or equal"">")
513 (const :tag "equal" "=")))
515 (defgroup org-agenda-skip nil
516 "Options concerning skipping parts of agenda files."
517 :tag "Org Agenda Skip"
518 :group 'org-agenda)
520 (defcustom org-agenda-skip-function-global nil
521 "Function to be called at each match during agenda construction.
522 If this function returns nil, the current match should not be skipped.
523 If the function decided to skip an agenda match, is must return the
524 buffer position from which the search should be continued.
525 This may also be a Lisp form, which will be evaluated.
527 This variable will be applied to every agenda match, including
528 tags/property searches and TODO lists. So try to make the test function
529 do its checking as efficiently as possible. To implement a skipping
530 condition just for specific agenda commands, use the variable
531 `org-agenda-skip-function' which can be set in the options section
532 of custom agenda commands."
533 :group 'org-agenda-skip
534 :type 'sexp)
536 (defgroup org-agenda-daily/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag "Org Agenda Daily/Weekly"
539 :group 'org-agenda)
540 (defgroup org-agenda-todo-list nil
541 "Options concerning the global todo list agenda view."
542 :tag "Org Agenda Todo List"
543 :group 'org-agenda)
544 (defgroup org-agenda-match-view nil
545 "Options concerning the general tags/property/todo match agenda view."
546 :tag "Org Agenda Match View"
547 :group 'org-agenda)
548 (defgroup org-agenda-search-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
553 (defvar org-agenda-archives-mode nil
554 "Non-nil means the agenda will include archived items.
555 If this is the symbol `trees', trees in the selected agenda scope
556 that are marked with the ARCHIVE tag will be included anyway. When this is
557 t, also all archive files associated with the current selection of agenda
558 files will be included.")
560 (defcustom org-agenda-skip-comment-trees t
561 "Non-nil means skip trees that start with the COMMENT keyword.
562 When nil, these trees are also scanned by agenda commands."
563 :group 'org-agenda-skip
564 :type 'boolean)
566 (defcustom org-agenda-todo-list-sublevels t
567 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
568 When nil, the sublevels of a TODO entry are not checked, resulting in
569 potentially much shorter TODO lists."
570 :group 'org-agenda-skip
571 :group 'org-agenda-todo-list
572 :type 'boolean)
574 (defcustom org-agenda-todo-ignore-with-date nil
575 "Non-nil means don't show entries with a date in the global todo list.
576 You can use this if you prefer to mark mere appointments with a TODO keyword,
577 but don't want them to show up in the TODO list.
578 When this is set, it also covers deadlines and scheduled items, the settings
579 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
580 will be ignored.
581 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
582 :group 'org-agenda-skip
583 :group 'org-agenda-todo-list
584 :type 'boolean)
586 (defcustom org-agenda-todo-ignore-timestamp nil
587 "Non-nil means don't show entries with a timestamp.
588 This applies when creating the global todo list.
589 Valid values are:
591 past Don't show entries for today or in the past.
593 future Don't show entries with a timestamp in the future.
594 The idea behind this is that if it has a future
595 timestamp, you don't want to think about it until the
596 date.
598 all Don't show any entries with a timestamp in the global todo list.
599 The idea behind this is that by setting a timestamp, you
600 have already \"taken care\" of this item.
602 This variable can also have an integer as a value. If positive (N),
603 todos with a timestamp N or more days in the future will be ignored. If
604 negative (-N), todos with a timestamp N or more days in the past will be
605 ignored. If 0, todos with a timestamp either today or in the future will
606 be ignored. For example, a value of -1 will exclude todos with a
607 timestamp in the past (yesterday or earlier), while a value of 7 will
608 exclude todos with a timestamp a week or more in the future.
610 See also `org-agenda-todo-ignore-with-date'.
611 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
612 to make his option also apply to the tags-todo list."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type '(choice
616 (const :tag "Ignore future timestamp todos" future)
617 (const :tag "Ignore past or present timestamp todos" past)
618 (const :tag "Ignore all timestamp todos" all)
619 (const :tag "Show timestamp todos" nil)
620 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
622 (defcustom org-agenda-todo-ignore-scheduled nil
623 "Non-nil means, ignore some scheduled TODO items when making TODO list.
624 This applies when creating the global todo list.
625 Valid values are:
627 past Don't show entries scheduled today or in the past.
629 future Don't show entries scheduled in the future.
630 The idea behind this is that by scheduling it, you don't want to
631 think about it until the scheduled date.
633 all Don't show any scheduled entries in the global todo list.
634 The idea behind this is that by scheduling it, you have already
635 \"taken care\" of this item.
637 t Same as `all', for backward compatibility.
639 This variable can also have an integer as a value. See
640 `org-agenda-todo-ignore-timestamp' for more details.
642 See also `org-agenda-todo-ignore-with-date'.
643 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
644 to make his option also apply to the tags-todo list."
645 :group 'org-agenda-skip
646 :group 'org-agenda-todo-list
647 :type '(choice
648 (const :tag "Ignore future-scheduled todos" future)
649 (const :tag "Ignore past- or present-scheduled todos" past)
650 (const :tag "Ignore all scheduled todos" all)
651 (const :tag "Ignore all scheduled todos (compatibility)" t)
652 (const :tag "Show scheduled todos" nil)
653 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
655 (defcustom org-agenda-todo-ignore-deadlines nil
656 "Non-nil means ignore some deadlined TODO items when making TODO list.
657 There are different motivations for using different values, please think
658 carefully when configuring this variable.
660 This applies when creating the global todo list.
661 Valid values are:
663 near Don't show near deadline entries. A deadline is near when it is
664 closer than `org-deadline-warning-days' days. The idea behind this
665 is that such items will appear in the agenda anyway.
667 far Don't show TODO entries where a deadline has been defined, but
668 the deadline is not near. This is useful if you don't want to
669 use the todo list to figure out what to do now.
671 past Don't show entries with a deadline timestamp for today or in the past.
673 future Don't show entries with a deadline timestamp in the future, not even
674 when they become `near' ones. Use it with caution.
676 all Ignore all TODO entries that do have a deadline.
678 t Same as `near', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore near deadlines" near)
690 (const :tag "Ignore near deadlines (compatibility)" t)
691 (const :tag "Ignore far deadlines" far)
692 (const :tag "Ignore all TODOs with a deadlines" all)
693 (const :tag "Show all TODOs, even if they have a deadline" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-tags-todo-honor-ignore-options nil
697 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
698 The variables
699 `org-agenda-todo-ignore-with-date',
700 `org-agenda-todo-ignore-timestamp',
701 `org-agenda-todo-ignore-scheduled',
702 `org-agenda-todo-ignore-deadlines'
703 make the global TODO list skip entries that have time stamps of certain
704 kinds. If this option is set, the same options will also apply for the
705 tags-todo search, which is the general tags/property matcher
706 restricted to unfinished TODO entries only."
707 :group 'org-agenda-skip
708 :group 'org-agenda-todo-list
709 :group 'org-agenda-match-view
710 :type 'boolean)
712 (defcustom org-agenda-skip-scheduled-if-done nil
713 "Non-nil means don't show scheduled items in agenda when they are done.
714 This is relevant for the daily/weekly agenda, not for the TODO list. And
715 it applies only to the actual date of the scheduling. Warnings about
716 an item with a past scheduling dates are always turned off when the item
717 is DONE."
718 :group 'org-agenda-skip
719 :group 'org-agenda-daily/weekly
720 :type 'boolean)
722 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
723 "Non-nil means skip scheduling line if same entry shows because of deadline.
724 In the agenda of today, an entry can show up multiple times because
725 it is both scheduled and has a nearby deadline, and maybe a plain time
726 stamp as well.
727 When this variable is t, then only the deadline is shown and the fact that
728 the entry is scheduled today or was scheduled previously is not shown.
729 When this variable is nil, the entry will be shown several times. When
730 the variable is the symbol `not-today', then skip scheduled previously,
731 but not scheduled today."
732 :group 'org-agenda-skip
733 :group 'org-agenda-daily/weekly
734 :type '(choice
735 (const :tag "Never" nil)
736 (const :tag "Always" t)
737 (const :tag "Not when scheduled today" not-today)))
739 (defcustom org-agenda-skip-deadline-if-done nil
740 "Non-nil means don't show deadlines when the corresponding item is done.
741 When nil, the deadline is still shown and should give you a happy feeling.
742 This is relevant for the daily/weekly agenda. And it applied only to the
743 actually date of the deadline. Warnings about approaching and past-due
744 deadlines are always turned off when the item is DONE."
745 :group 'org-agenda-skip
746 :group 'org-agenda-daily/weekly
747 :type 'boolean)
749 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
750 "Non-nil means skip deadline prewarning when entry is also scheduled.
751 This will apply on all days where a prewarning for the deadline would
752 be shown, but not at the day when the entry is actually due. On that day,
753 the deadline will be shown anyway.
754 This variable may be set to nil, t, or a number which will then give
755 the number of days before the actual deadline when the prewarnings
756 should resume.
757 This can be used in a workflow where the first showing of the deadline will
758 trigger you to schedule it, and then you don't want to be reminded of it
759 because you will take care of it on the day when scheduled."
760 :group 'org-agenda-skip
761 :group 'org-agenda-daily/weekly
762 :type '(choice
763 (const :tag "Alwas show prewarning" nil)
764 (const :tag "Remove prewarning if entry is scheduled" t)
765 (integer :tag "Restart prewarning N days before deadline")))
767 (defcustom org-agenda-skip-additional-timestamps-same-entry t
768 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
769 When non-nil, after the search for timestamps has matched once in an
770 entry, the rest of the entry will not be searched."
771 :group 'org-agenda-skip
772 :type 'boolean)
774 (defcustom org-agenda-skip-timestamp-if-done nil
775 "Non-nil means don't select item by timestamp or -range if it is DONE."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type 'boolean)
780 (defcustom org-agenda-dim-blocked-tasks t
781 "Non-nil means dim blocked tasks in the agenda display.
782 This causes some overhead during agenda construction, but if you
783 have turned on `org-enforce-todo-dependencies',
784 `org-enforce-todo-checkbox-dependencies', or any other blocking
785 mechanism, this will create useful feedback in the agenda.
787 Instead of t, this variable can also have the value `invisible'.
788 Then blocked tasks will be invisible and only become visible when
789 they become unblocked. An exemption to this behavior is when a task is
790 blocked because of unchecked checkboxes below it. Since checkboxes do
791 not show up in the agenda views, making this task invisible you remove any
792 trace from agenda views that there is something to do. Therefore, a task
793 that is blocked because of checkboxes will never be made invisible, it
794 will only be dimmed."
795 :group 'org-agenda-daily/weekly
796 :group 'org-agenda-todo-list
797 :type '(choice
798 (const :tag "Do not dim" nil)
799 (const :tag "Dim to a grey face" t)
800 (const :tag "Make invisible" invisible)))
802 (defcustom org-timeline-show-empty-dates 3
803 "Non-nil means `org-timeline' also shows dates without an entry.
804 When nil, only the days which actually have entries are shown.
805 When t, all days between the first and the last date are shown.
806 When an integer, show also empty dates, but if there is a gap of more than
807 N days, just insert a special line indicating the size of the gap."
808 :group 'org-agenda-skip
809 :type '(choice
810 (const :tag "None" nil)
811 (const :tag "All" t)
812 (integer :tag "at most")))
814 (defgroup org-agenda-startup nil
815 "Options concerning initial settings in the Agenda in Org Mode."
816 :tag "Org Agenda Startup"
817 :group 'org-agenda)
819 (defcustom org-agenda-menu-show-matcher t
820 "Non-nil means show the match string in the agenda dispatcher menu.
821 When nil, the matcher string is not shown, but is put into the help-echo
822 property so than moving the mouse over the command shows it.
823 Setting it to nil is good if matcher strings are very long and/or if
824 you want to use two-column display (see `org-agenda-menu-two-column')."
825 :group 'org-agenda
826 :type 'boolean)
828 (defcustom org-agenda-menu-two-column nil
829 "Non-nil means, use two columns to show custom commands in the dispatcher.
830 If you use this, you probably want to set `org-agenda-menu-show-matcher'
831 to nil."
832 :group 'org-agenda
833 :type 'boolean)
835 (defcustom org-finalize-agenda-hook nil
836 "Hook run just before displaying an agenda buffer."
837 :group 'org-agenda-startup
838 :type 'hook)
840 (defcustom org-agenda-mouse-1-follows-link nil
841 "Non-nil means mouse-1 on a link will follow the link in the agenda.
842 A longer mouse click will still set point. Does not work on XEmacs.
843 Needs to be set before org.el is loaded."
844 :group 'org-agenda-startup
845 :type 'boolean)
847 (defcustom org-agenda-start-with-follow-mode nil
848 "The initial value of follow mode in a newly created agenda window."
849 :group 'org-agenda-startup
850 :type 'boolean)
852 (defcustom org-agenda-show-outline-path t
853 "Non-nil means show outline path in echo area after line motion."
854 :group 'org-agenda-startup
855 :type 'boolean)
857 (defcustom org-agenda-start-with-entry-text-mode nil
858 "The initial value of entry-text-mode in a newly created agenda window."
859 :group 'org-agenda-startup
860 :type 'boolean)
862 (defcustom org-agenda-entry-text-maxlines 5
863 "Number of text lines to be added when `E' is pressed in the agenda.
865 Note that this variable only used during agenda display. Add add entry text
866 when exporting the agenda, configure the variable
867 `org-agenda-add-entry-ext-maxlines'."
868 :group 'org-agenda
869 :type 'integer)
871 (defcustom org-agenda-entry-text-exclude-regexps nil
872 "List of regular expressions to clean up entry text.
873 The complete matches of all regular expressions in this list will be
874 removed from entry text before it is shown in the agenda."
875 :group 'org-agenda
876 :type '(repeat (regexp)))
878 (defvar org-agenda-entry-text-cleanup-hook nil
879 "Hook that is run after basic cleanup of entry text to be shown in agenda.
880 This cleanup is done in a temporary buffer, so the function may inspect and
881 change the entire buffer.
882 Some default stuff like drawers and scheduling/deadline dates will already
883 have been removed when this is called, as will any matches for regular
884 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
886 (defvar org-agenda-include-inactive-timestamps nil
887 "Non-nil means include inactive time stamps in agenda and timeline.")
889 (defgroup org-agenda-windows nil
890 "Options concerning the windows used by the Agenda in Org Mode."
891 :tag "Org Agenda Windows"
892 :group 'org-agenda)
894 (defcustom org-agenda-window-setup 'reorganize-frame
895 "How the agenda buffer should be displayed.
896 Possible values for this option are:
898 current-window Show agenda in the current window, keeping all other windows.
899 other-window Use `switch-to-buffer-other-window' to display agenda.
900 reorganize-frame Show only two windows on the current frame, the current
901 window and the agenda.
902 other-frame Use `switch-to-buffer-other-frame' to display agenda.
903 Also, when exiting the agenda, kill that frame.
904 See also the variable `org-agenda-restore-windows-after-quit'."
905 :group 'org-agenda-windows
906 :type '(choice
907 (const current-window)
908 (const other-frame)
909 (const other-window)
910 (const reorganize-frame)))
912 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
913 "The min and max height of the agenda window as a fraction of frame height.
914 The value of the variable is a cons cell with two numbers between 0 and 1.
915 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
916 :group 'org-agenda-windows
917 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
919 (defcustom org-agenda-restore-windows-after-quit nil
920 "Non-nil means restore window configuration upon exiting agenda.
921 Before the window configuration is changed for displaying the agenda,
922 the current status is recorded. When the agenda is exited with
923 `q' or `x' and this option is set, the old state is restored. If
924 `org-agenda-window-setup' is `other-frame', the value of this
925 option will be ignored."
926 :group 'org-agenda-windows
927 :type 'boolean)
929 (defcustom org-agenda-ndays nil
930 "Number of days to include in overview display.
931 Should be 1 or 7.
932 Obsolete, see `org-agenda-span'."
933 :group 'org-agenda-daily/weekly
934 :type 'integer)
936 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
938 (defcustom org-agenda-span 'week
939 "Number of days to include in overview display.
940 Can be day, week, month, year, or any number of days.
941 Custom commands can set this variable in the options section."
942 :group 'org-agenda-daily/weekly
943 :type '(choice (const :tag "Day" day)
944 (const :tag "Week" week)
945 (const :tag "Month" month)
946 (const :tag "Year" year)
947 (integer :tag "Custom")))
949 (defcustom org-agenda-start-on-weekday 1
950 "Non-nil means start the overview always on the specified weekday.
951 0 denotes Sunday, 1 denotes Monday etc.
952 When nil, always start on the current day.
953 Custom commands can set this variable in the options section."
954 :group 'org-agenda-daily/weekly
955 :type '(choice (const :tag "Today" nil)
956 (integer :tag "Weekday No.")))
958 (defcustom org-agenda-show-all-dates t
959 "Non-nil means `org-agenda' shows every day in the selected range.
960 When nil, only the days which actually have entries are shown."
961 :group 'org-agenda-daily/weekly
962 :type 'boolean)
964 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
965 "Format string for displaying dates in the agenda.
966 Used by the daily/weekly agenda and by the timeline. This should be
967 a format string understood by `format-time-string', or a function returning
968 the formatted date as a string. The function must take a single argument,
969 a calendar-style date list like (month day year)."
970 :group 'org-agenda-daily/weekly
971 :type '(choice
972 (string :tag "Format string")
973 (function :tag "Function")))
975 (defun org-agenda-format-date-aligned (date)
976 "Format a date string for display in the daily/weekly agenda, or timeline.
977 This function makes sure that dates are aligned for easy reading."
978 (require 'cal-iso)
979 (let* ((dayname (calendar-day-name date))
980 (day (cadr date))
981 (day-of-week (calendar-day-of-week date))
982 (month (car date))
983 (monthname (calendar-month-name month))
984 (year (nth 2 date))
985 (iso-week (org-days-to-iso-week
986 (calendar-absolute-from-gregorian date)))
987 (weekyear (cond ((and (= month 1) (>= iso-week 52))
988 (1- year))
989 ((and (= month 12) (<= iso-week 1))
990 (1+ year))
991 (t year)))
992 (weekstring (if (= day-of-week 1)
993 (format " W%02d" iso-week)
994 "")))
995 (format "%-10s %2d %s %4d%s"
996 dayname day monthname year weekstring)))
998 (defcustom org-agenda-time-leading-zero nil
999 "Non-nil means use leading zero for military times in agenda.
1000 For example, 9:30am would become 09:30 rather than 9:30."
1001 :group 'org-agenda-daily/weekly
1002 :type 'boolean)
1004 (defcustom org-agenda-timegrid-use-ampm nil
1005 "When set, show AM/PM style timestamps on the timegrid."
1006 :group 'org-agenda
1007 :type 'boolean)
1009 (defun org-agenda-time-of-day-to-ampm (time)
1010 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1011 (let* ((hour-number (string-to-number (substring time 0 -3)))
1012 (minute (substring time -2))
1013 (ampm "am"))
1014 (cond
1015 ((equal hour-number 12)
1016 (setq ampm "pm"))
1017 ((> hour-number 12)
1018 (setq ampm "pm")
1019 (setq hour-number (- hour-number 12))))
1020 (concat
1021 (if org-agenda-time-leading-zero
1022 (format "%02d" hour-number)
1023 (format "%02s" (number-to-string hour-number)))
1024 ":" minute ampm)))
1026 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1027 "Conditionally convert TIME to AM/PM format
1028 based on `org-agenda-timegrid-use-ampm'"
1029 (if org-agenda-timegrid-use-ampm
1030 (org-agenda-time-of-day-to-ampm time)
1031 time))
1033 (defcustom org-agenda-weekend-days '(6 0)
1034 "Which days are weekend?
1035 These days get the special face `org-agenda-date-weekend' in the agenda
1036 and timeline buffers."
1037 :group 'org-agenda-daily/weekly
1038 :type '(set :greedy t
1039 (const :tag "Monday" 1)
1040 (const :tag "Tuesday" 2)
1041 (const :tag "Wednesday" 3)
1042 (const :tag "Thursday" 4)
1043 (const :tag "Friday" 5)
1044 (const :tag "Saturday" 6)
1045 (const :tag "Sunday" 0)))
1047 (defcustom org-agenda-include-diary nil
1048 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1049 Custom commands can set this variable in the options section."
1050 :group 'org-agenda-daily/weekly
1051 :type 'boolean)
1053 (defcustom org-agenda-include-deadlines t
1054 "If non-nil, include entries within their deadline warning period.
1055 Custom commands can set this variable in the options section."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-include-all-todo nil
1060 "Set means weekly/daily agenda will always contain all TODO entries.
1061 The TODO entries will be listed at the top of the agenda, before
1062 the entries for specific days.
1063 This option is deprecated, it is better to define a block agenda instead."
1064 :group 'org-agenda-daily/weekly
1065 :type 'boolean)
1067 (defcustom org-agenda-repeating-timestamp-show-all t
1068 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1069 When set to a list of strings, only show occurrences of repeating
1070 stamps for these TODO keywords. When nil, only one occurrence is
1071 shown, either today or the nearest into the future."
1072 :group 'org-agenda-daily/weekly
1073 :type '(choice
1074 (const :tag "Show repeating stamps" t)
1075 (repeat :tag "Show repeating stamps for these TODO keywords"
1076 (string :tag "TODO Keyword"))
1077 (const :tag "Don't show repeating stamps" nil)))
1079 (defcustom org-scheduled-past-days 10000
1080 "No. of days to continue listing scheduled items that are not marked DONE.
1081 When an item is scheduled on a date, it shows up in the agenda on this
1082 day and will be listed until it is marked done for the number of days
1083 given here."
1084 :group 'org-agenda-daily/weekly
1085 :type 'integer)
1087 (defcustom org-agenda-log-mode-items '(closed clock)
1088 "List of items that should be shown in agenda log mode.
1089 This list may contain the following symbols:
1091 closed Show entries that have been closed on that day.
1092 clock Show entries that have received clocked time on that day.
1093 state Show all logged state changes.
1094 Note that instead of changing this variable, you can also press `C-u l' in
1095 the agenda to display all available LOG items temporarily."
1096 :group 'org-agenda-daily/weekly
1097 :type '(set :greedy t (const closed) (const clock) (const state)))
1099 (defcustom org-agenda-log-mode-add-notes t
1100 "Non-nil means add first line of notes to log entries in agenda views.
1101 If a log item like a state change or a clock entry is associated with
1102 notes, the first line of these notes will be added to the entry in the
1103 agenda display."
1104 :group 'org-agenda-daily/weekly
1105 :type 'boolean)
1107 (defcustom org-agenda-start-with-log-mode nil
1108 "The initial value of log-mode in a newly created agenda window."
1109 :group 'org-agenda-startup
1110 :group 'org-agenda-daily/weekly
1111 :type 'boolean)
1113 (defcustom org-agenda-start-with-clockreport-mode nil
1114 "The initial value of clockreport-mode in a newly created agenda window."
1115 :group 'org-agenda-startup
1116 :group 'org-agenda-daily/weekly
1117 :type 'boolean)
1119 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1120 "Property list with parameters for the clocktable in clockreport mode.
1121 This is the display mode that shows a clock table in the daily/weekly
1122 agenda, the properties for this dynamic block can be set here.
1123 The usual clocktable parameters are allowed here, but you cannot set
1124 the properties :name, :tstart, :tend, :block, and :scope - these will
1125 be overwritten to make sure the content accurately reflects the
1126 current display in the agenda."
1127 :group 'org-agenda-daily/weekly
1128 :type 'plist)
1130 (defcustom org-agenda-search-view-always-boolean nil
1131 "Non-nil means the search string is interpreted as individual parts.
1133 The search string for search view can either be interpreted as a phrase,
1134 or as a list of snippets that define a boolean search for a number of
1135 strings.
1137 When this is non-nil, the string will be split on whitespace, and each
1138 snippet will be searched individually, and all must match in order to
1139 select an entry. A snippet is then a single string of non-white
1140 characters, or a string in double quotes, or a regexp in {} braces.
1141 If a snippet is preceded by \"-\", the snippet must *not* match.
1142 \"+\" is syntactic sugar for positive selection. Each snippet may
1143 be found as a full word or a partial word, but see the variable
1144 `org-agenda-search-view-force-full-words'.
1146 When this is nil, search will look for the entire search phrase as one,
1147 with each space character matching any amount of whitespace, including
1148 line breaks.
1150 Even when this is nil, you can still switch to Boolean search dynamically
1151 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1152 is a regexp marked with braces like \"{abc}\", this will also switch to
1153 boolean search."
1154 :group 'org-agenda-search-view
1155 :type 'boolean)
1157 (if (fboundp 'defvaralias)
1158 (defvaralias 'org-agenda-search-view-search-words-only
1159 'org-agenda-search-view-always-boolean))
1161 (defcustom org-agenda-search-view-force-full-words nil
1162 "Non-nil means, search words must be matches as complete words.
1163 When nil, they may also match part of a word."
1164 :group 'org-agenda-search-view
1165 :type 'boolean)
1167 (defgroup org-agenda-time-grid nil
1168 "Options concerning the time grid in the Org-mode Agenda."
1169 :tag "Org Agenda Time Grid"
1170 :group 'org-agenda)
1172 (defcustom org-agenda-search-headline-for-time t
1173 "Non-nil means search headline for a time-of-day.
1174 If the headline contains a time-of-day in one format or another, it will
1175 be used to sort the entry into the time sequence of items for a day.
1176 Some people have time stamps in the headline that refer to the creation
1177 time or so, and then this produces an unwanted side effect. If this is
1178 the case for your, use this variable to turn off searching the headline
1179 for a time."
1180 :group 'org-agenda-time-grid
1181 :type 'boolean)
1183 (defcustom org-agenda-use-time-grid t
1184 "Non-nil means show a time grid in the agenda schedule.
1185 A time grid is a set of lines for specific times (like every two hours between
1186 8:00 and 20:00). The items scheduled for a day at specific times are
1187 sorted in between these lines.
1188 For details about when the grid will be shown, and what it will look like, see
1189 the variable `org-agenda-time-grid'."
1190 :group 'org-agenda-time-grid
1191 :type 'boolean)
1193 (defcustom org-agenda-time-grid
1194 '((daily today require-timed)
1195 "----------------"
1196 (800 1000 1200 1400 1600 1800 2000))
1198 "The settings for time grid for agenda display.
1199 This is a list of three items. The first item is again a list. It contains
1200 symbols specifying conditions when the grid should be displayed:
1202 daily if the agenda shows a single day
1203 weekly if the agenda shows an entire week
1204 today show grid on current date, independent of daily/weekly display
1205 require-timed show grid only if at least one item has a time specification
1207 The second item is a string which will be placed behind the grid time.
1209 The third item is a list of integers, indicating the times that should have
1210 a grid line."
1211 :group 'org-agenda-time-grid
1212 :type
1213 '(list
1214 (set :greedy t :tag "Grid Display Options"
1215 (const :tag "Show grid in single day agenda display" daily)
1216 (const :tag "Show grid in weekly agenda display" weekly)
1217 (const :tag "Always show grid for today" today)
1218 (const :tag "Show grid only if any timed entries are present"
1219 require-timed)
1220 (const :tag "Skip grid times already present in an entry"
1221 remove-match))
1222 (string :tag "Grid String")
1223 (repeat :tag "Grid Times" (integer :tag "Time"))))
1225 (defcustom org-agenda-show-current-time-in-grid t
1226 "Non-nil means show the current time in the time grid."
1227 :group 'org-agenda-time-grid
1228 :type 'boolean)
1230 (defcustom org-agenda-current-time-string
1231 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1232 "The string for the current time marker in the agenda."
1233 :group 'org-agenda-time-grid
1234 :type 'string)
1236 (defgroup org-agenda-sorting nil
1237 "Options concerning sorting in the Org-mode Agenda."
1238 :tag "Org Agenda Sorting"
1239 :group 'org-agenda)
1241 (defcustom org-agenda-sorting-strategy
1242 '((agenda habit-down time-up priority-down category-keep)
1243 (todo priority-down category-keep)
1244 (tags priority-down category-keep)
1245 (search category-keep))
1246 "Sorting structure for the agenda items of a single day.
1247 This is a list of symbols which will be used in sequence to determine
1248 if an entry should be listed before another entry. The following
1249 symbols are recognized:
1251 time-up Put entries with time-of-day indications first, early first
1252 time-down Put entries with time-of-day indications first, late first
1253 category-keep Keep the default order of categories, corresponding to the
1254 sequence in `org-agenda-files'.
1255 category-up Sort alphabetically by category, A-Z.
1256 category-down Sort alphabetically by category, Z-A.
1257 tag-up Sort alphabetically by last tag, A-Z.
1258 tag-down Sort alphabetically by last tag, Z-A.
1259 priority-up Sort numerically by priority, high priority last.
1260 priority-down Sort numerically by priority, high priority first.
1261 todo-state-up Sort by todo state, tasks that are done last.
1262 todo-state-down Sort by todo state, tasks that are done first.
1263 effort-up Sort numerically by estimated effort, high effort last.
1264 effort-down Sort numerically by estimated effort, high effort first.
1265 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1266 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1267 habit-up Put entries that are habits first
1268 habit-down Put entries that are habits last
1269 alpha-up Sort headlines alphabetically
1270 alpha-down Sort headlines alphabetically, reversed
1272 The different possibilities will be tried in sequence, and testing stops
1273 if one comparison returns a \"not-equal\". For example, the default
1274 '(time-up category-keep priority-down)
1275 means: Pull out all entries having a specified time of day and sort them,
1276 in order to make a time schedule for the current day the first thing in the
1277 agenda listing for the day. Of the entries without a time indication, keep
1278 the grouped in categories, don't sort the categories, but keep them in
1279 the sequence given in `org-agenda-files'. Within each category sort by
1280 priority.
1282 Leaving out `category-keep' would mean that items will be sorted across
1283 categories by priority.
1285 Instead of a single list, this can also be a set of list for specific
1286 contents, with a context symbol in the car of the list, any of
1287 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1289 Custom commands can bind this variable in the options section."
1290 :group 'org-agenda-sorting
1291 :type `(choice
1292 (repeat :tag "General" ,org-sorting-choice)
1293 (list :tag "Individually"
1294 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1295 (repeat ,org-sorting-choice))
1296 (cons (const :tag "Strategy for TODO lists" todo)
1297 (repeat ,org-sorting-choice))
1298 (cons (const :tag "Strategy for Tags matches" tags)
1299 (repeat ,org-sorting-choice))
1300 (cons (const :tag "Strategy for search matches" search)
1301 (repeat ,org-sorting-choice)))))
1303 (defcustom org-agenda-cmp-user-defined nil
1304 "A function to define the comparison `user-defined'.
1305 This function must receive two arguments, agenda entry a and b.
1306 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1307 the user comparison, return nil.
1308 When this is defined, you can make `user-defined-up' and `user-defined-down'
1309 part of an agenda sorting strategy."
1310 :group 'org-agenda-sorting
1311 :type 'symbol)
1313 (defcustom org-sort-agenda-notime-is-late t
1314 "Non-nil means items without time are considered late.
1315 This is only relevant for sorting. When t, items which have no explicit
1316 time like 15:30 will be considered as 99:01, i.e. later than any items which
1317 do have a time. When nil, the default time is before 0:00. You can use this
1318 option to decide if the schedule for today should come before or after timeless
1319 agenda entries."
1320 :group 'org-agenda-sorting
1321 :type 'boolean)
1323 (defcustom org-sort-agenda-noeffort-is-high t
1324 "Non-nil means items without effort estimate are sorted as high effort.
1325 This also applies when filtering an agenda view with respect to the
1326 < or > effort operator. Then, tasks with no effort defined will be treated
1327 as tasks with high effort.
1328 When nil, such items are sorted as 0 minutes effort."
1329 :group 'org-agenda-sorting
1330 :type 'boolean)
1332 (defgroup org-agenda-line-format nil
1333 "Options concerning the entry prefix in the Org-mode agenda display."
1334 :tag "Org Agenda Line Format"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-prefix-format
1338 '((agenda . " %i %-12:c%?-12t% s")
1339 (timeline . " % s")
1340 (todo . " %i %-12:c")
1341 (tags . " %i %-12:c")
1342 (search . " %i %-12:c"))
1343 "Format specifications for the prefix of items in the agenda views.
1344 An alist with four entries, for the different agenda types. The keys to the
1345 sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
1346 are format strings.
1347 This format works similar to a printf format, with the following meaning:
1349 %c the category of the item, \"Diary\" for entries from the diary, or
1350 as given by the CATEGORY keyword or derived from the file name.
1351 %i the icon category of the item, as give in
1352 `org-agenda-category-icon-alist'.
1353 %T the *last* tag of the item. Last because inherited tags come
1354 first in the list.
1355 %t the time-of-day specification if one applies to the entry, in the
1356 format HH:MM
1357 %s Scheduling/Deadline information, a short string
1358 %(expression) Eval EXPRESSION and replace the control string
1359 by the result
1361 All specifiers work basically like the standard `%s' of printf, but may
1362 contain two additional characters: A question mark just after the `%' and
1363 a whitespace/punctuation character just before the final letter.
1365 If the first character after `%' is a question mark, the entire field
1366 will only be included if the corresponding value applies to the
1367 current entry. This is useful for fields which should have fixed
1368 width when present, but zero width when absent. For example,
1369 \"%?-12t\" will result in a 12 character time field if a time of the
1370 day is specified, but will completely disappear in entries which do
1371 not contain a time.
1373 If there is punctuation or whitespace character just before the final
1374 format letter, this character will be appended to the field value if
1375 the value is not empty. For example, the format \"%-12:c\" leads to
1376 \"Diary: \" if the category is \"Diary\". If the category were be
1377 empty, no additional colon would be inserted.
1379 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1380 - Indent the line with two space characters
1381 - Give the category in a 12 chars wide field, padded with whitespace on
1382 the right (because of `-'). Append a colon if there is a category
1383 (because of `:').
1384 - If there is a time-of-day, put it into a 12 chars wide field. If no
1385 time, don't put in an empty field, just skip it (because of '?').
1386 - Finally, put the scheduling information and append a whitespace.
1388 As another example, if you don't want the time-of-day of entries in
1389 the prefix, you could use:
1391 (setq org-agenda-prefix-format \" %-11:c% s\")
1393 See also the variables `org-agenda-remove-times-when-in-prefix' and
1394 `org-agenda-remove-tags'.
1396 Custom commands can set this variable in the options section."
1397 :type '(choice
1398 (string :tag "General format")
1399 (list :greedy t :tag "View dependent"
1400 (cons (const agenda) (string :tag "Format"))
1401 (cons (const timeline) (string :tag "Format"))
1402 (cons (const todo) (string :tag "Format"))
1403 (cons (const tags) (string :tag "Format"))
1404 (cons (const search) (string :tag "Format"))))
1405 :group 'org-agenda-line-format)
1407 (defvar org-prefix-format-compiled nil
1408 "The compiled version of the most recently used prefix format.
1409 See the variable `org-agenda-prefix-format'.")
1411 (defcustom org-agenda-todo-keyword-format "%-1s"
1412 "Format for the TODO keyword in agenda lines.
1413 Set this to something like \"%-12s\" if you want all TODO keywords
1414 to occupy a fixed space in the agenda display."
1415 :group 'org-agenda-line-format
1416 :type 'string)
1418 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1419 "Text preceding timerange entries in the agenda view.
1420 This is a list with two strings. The first applies when the range
1421 is entirely on one day. The second applies if the range spans several days.
1422 The strings may have two \"%d\" format specifiers which will be filled
1423 with the sequence number of the days, and the total number of days in the
1424 range, respectively."
1425 :group 'org-agenda-line-format
1426 :type '(list
1427 (string :tag "Deadline today ")
1428 (choice :tag "Deadline relative"
1429 (string :tag "Format string")
1430 (function))))
1432 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1433 "Text preceding scheduled items in the agenda view.
1434 This is a list with two strings. The first applies when the item is
1435 scheduled on the current day. The second applies when it has been scheduled
1436 previously, it may contain a %d indicating that this is the nth time that
1437 this item is scheduled, due to automatic rescheduling of unfinished items
1438 for the following day. So this number is one larger than the number of days
1439 that passed since this item was scheduled first."
1440 :group 'org-agenda-line-format
1441 :type '(list
1442 (string :tag "Scheduled today ")
1443 (string :tag "Scheduled previously")))
1445 (defcustom org-agenda-inactive-leader "["
1446 "Text preceding item pulled into the agenda by inactive time stamps.
1447 These entries are added to the agenda when pressing \"[\"."
1448 :group 'org-agenda-line-format
1449 :type '(list
1450 (string :tag "Scheduled today ")
1451 (string :tag "Scheduled previously")))
1453 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1454 "Text preceding deadline items in the agenda view.
1455 This is a list with two strings. The first applies when the item has its
1456 deadline on the current day. The second applies when it is in the past or
1457 in the future, it may contain %d to capture how many days away the deadline
1458 is (was)."
1459 :group 'org-agenda-line-format
1460 :type '(list
1461 (string :tag "Deadline today ")
1462 (choice :tag "Deadline relative"
1463 (string :tag "Format string")
1464 (function))))
1466 (defcustom org-agenda-remove-times-when-in-prefix t
1467 "Non-nil means remove duplicate time specifications in agenda items.
1468 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1469 time-of-day specification in a headline or diary entry is extracted and
1470 placed into the prefix. If this option is non-nil, the original specification
1471 \(a timestamp or -range, or just a plain time(range) specification like
1472 11:30-4pm) will be removed for agenda display. This makes the agenda less
1473 cluttered.
1474 The option can be t or nil. It may also be the symbol `beg', indicating
1475 that the time should only be removed when it is located at the beginning of
1476 the headline/diary entry."
1477 :group 'org-agenda-line-format
1478 :type '(choice
1479 (const :tag "Always" t)
1480 (const :tag "Never" nil)
1481 (const :tag "When at beginning of entry" beg)))
1483 (defcustom org-agenda-remove-timeranges-from-blocks nil
1484 "Non-nil means remove time ranges specifications in agenda
1485 items that span on several days."
1486 :group 'org-agenda-line-format
1487 :type 'boolean)
1489 (defcustom org-agenda-default-appointment-duration nil
1490 "Default duration for appointments that only have a starting time.
1491 When nil, no duration is specified in such cases.
1492 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1493 :group 'org-agenda-line-format
1494 :type '(choice
1495 (integer :tag "Minutes")
1496 (const :tag "No default duration")))
1498 (defcustom org-agenda-show-inherited-tags t
1499 "Non-nil means show inherited tags in each agenda line."
1500 :group 'org-agenda-line-format
1501 :type 'boolean)
1503 (defcustom org-agenda-hide-tags-regexp nil
1504 "Regular expression used to filter away specific tags in agenda views.
1505 This means that these tags will be present, but not be shown in the agenda
1506 line. Secondary filtering will still work on the hidden tags.
1507 Nil means don't hide any tags."
1508 :group 'org-agenda-line-format
1509 :type '(choice
1510 (const :tag "Hide none" nil)
1511 (string :tag "Regexp ")))
1513 (defcustom org-agenda-remove-tags nil
1514 "Non-nil means remove the tags from the headline copy in the agenda.
1515 When this is the symbol `prefix', only remove tags when
1516 `org-agenda-prefix-format' contains a `%T' specifier."
1517 :group 'org-agenda-line-format
1518 :type '(choice
1519 (const :tag "Always" t)
1520 (const :tag "Never" nil)
1521 (const :tag "When prefix format contains %T" prefix)))
1523 (if (fboundp 'defvaralias)
1524 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1525 'org-agenda-remove-tags))
1527 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1528 "Shift tags in agenda items to this column.
1529 If this number is positive, it specifies the column. If it is negative,
1530 it means that the tags should be flushright to that column. For example,
1531 -80 works well for a normal 80 character screen."
1532 :group 'org-agenda-line-format
1533 :type 'integer)
1535 (if (fboundp 'defvaralias)
1536 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1538 (defcustom org-agenda-fontify-priorities 'cookies
1539 "Non-nil means highlight low and high priorities in agenda.
1540 When t, the highest priority entries are bold, lowest priority italic.
1541 However, settings in `org-priority-faces' will overrule these faces.
1542 When this variable is the symbol `cookies', only fontify the
1543 cookies, not the entire task.
1544 This may also be an association list of priority faces, whose
1545 keys are the character values of `org-highest-priority',
1546 `org-default-priority', and `org-lowest-priority' (the default values
1547 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1548 color as a string, or a list like `(:background \"Red\")'.
1549 If it is a color, the variable `org-faces-easy-properties'
1550 determines if it is a foreground or a background color."
1551 :group 'org-agenda-line-format
1552 :type '(choice
1553 (const :tag "Never" nil)
1554 (const :tag "Defaults" t)
1555 (const :tag "Cookies only" cookies)
1556 (repeat :tag "Specify"
1557 (list (character :tag "Priority" :value ?A)
1558 (choice :tag "Face "
1559 (string :tag "Color")
1560 (sexp :tag "Face"))))))
1562 (defcustom org-agenda-day-face-function nil
1563 "Function called to determine what face should be used to display a day.
1564 The only argument passed to that function is the day. It should
1565 returns a face, or nil if does not want to specify a face and let
1566 the normal rules apply."
1567 :group 'org-agenda-line-format
1568 :type 'function)
1570 (defcustom org-agenda-category-icon-alist nil
1571 "Alist of category icon to be displayed in agenda views.
1573 Each entry should have the following format:
1575 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1577 Where CATEGORY-REGEXP is a regexp matching the categories where
1578 the icon should be displayed.
1579 FILE-OR-DATA either a file path or a string containing image data.
1581 The other fields can be omited safely if not needed:
1582 TYPE indicates the image type.
1583 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1584 image data.
1585 PROPS are additional image attributes to assign to the image,
1586 like, e.g. `:ascent center'.
1588 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1590 If you want to set the display properties yourself, just put a
1591 list as second element:
1593 (CATEGORY-REGEXP (MY PROPERTY LIST))
1595 For example, to display a 16px horizontal space for Emacs
1596 category, you can use:
1598 (\"Emacs\" '(space . (:width (16))))"
1599 :group 'org-agenda-line-format
1600 :type '(alist :key-type (string :tag "Regexp matching category")
1601 :value-type (choice (list :tag "Icon"
1602 (string :tag "File or data")
1603 (symbol :tag "Type")
1604 (boolean :tag "Data?")
1605 (repeat :tag "Extra image properties" :inline t symbol))
1606 (list :tag "Display properties" sexp))))
1608 (defgroup org-agenda-column-view nil
1609 "Options concerning column view in the agenda."
1610 :tag "Org Agenda Column View"
1611 :group 'org-agenda)
1613 (defcustom org-agenda-columns-show-summaries t
1614 "Non-nil means show summaries for columns displayed in the agenda view."
1615 :group 'org-agenda-column-view
1616 :type 'boolean)
1618 (defcustom org-agenda-columns-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-agenda-run-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-agenda-run-series (name series)
2477 (org-let (nth 1 series) '(org-prepare-agenda name))
2478 (let* ((org-agenda-multi t)
2479 (redo (list 'org-agenda-run-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
3496 (or span org-agenda-ndays org-agenda-span)))
3497 (today (org-today))
3498 (sd (or start-day today))
3499 (ndays (org-agenda-span-to-ndays span sd))
3500 (org-agenda-start-on-weekday
3501 (if (eq ndays 7)
3502 org-agenda-start-on-weekday))
3503 (thefiles (org-agenda-files nil 'ifmode))
3504 (files thefiles)
3505 (start (if (or (null org-agenda-start-on-weekday)
3506 (< ndays 7))
3508 (let* ((nt (calendar-day-of-week
3509 (calendar-gregorian-from-absolute sd)))
3510 (n1 org-agenda-start-on-weekday)
3511 (d (- nt n1)))
3512 (- sd (+ (if (< d 0) 7 0) d)))))
3513 (day-numbers (list start))
3514 (day-cnt 0)
3515 (inhibit-redisplay (not debug-on-error))
3516 s e rtn rtnall file date d start-pos end-pos todayp
3517 clocktable-start clocktable-end filter)
3518 (setq org-agenda-redo-command
3519 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3520 (dotimes (n (1- ndays))
3521 (push (1+ (car day-numbers)) day-numbers))
3522 (setq day-numbers (nreverse day-numbers))
3523 (setq clocktable-start (car day-numbers)
3524 clocktable-end (1+ (or (org-last day-numbers) 0)))
3525 (org-prepare-agenda "Day/Week")
3526 (org-set-local 'org-starting-day (car day-numbers))
3527 (org-set-local 'org-include-all-loc include-all)
3528 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3529 (when (and (or include-all org-agenda-include-all-todo)
3530 (member today day-numbers))
3531 (setq files thefiles
3532 rtnall nil)
3533 (while (setq file (pop files))
3534 (catch 'nextfile
3535 (org-check-agenda-file file)
3536 (setq date (calendar-gregorian-from-absolute today)
3537 rtn (org-agenda-get-day-entries
3538 file date :todo))
3539 (setq rtnall (append rtnall rtn))))
3540 (when rtnall
3541 (insert "All currently open TODO items:\n")
3542 (add-text-properties (point-min) (1- (point))
3543 (list 'face 'org-agenda-structure
3544 'short-heading "All TODO items"))
3545 (org-agenda-mark-header-line (point-min))
3546 (insert (org-finalize-agenda-entries rtnall) "\n")))
3547 (unless org-agenda-compact-blocks
3548 (let* ((d1 (car day-numbers))
3549 (d2 (org-last day-numbers))
3550 (w1 (org-days-to-iso-week d1))
3551 (w2 (org-days-to-iso-week d2)))
3552 (setq s (point))
3553 (if org-agenda-overriding-header
3554 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3555 nil 'face 'org-agenda-structure) "\n")
3556 (insert (org-agenda-span-name span)
3557 "-agenda"
3558 (if (< (- d2 d1) 350)
3559 (if (= w1 w2)
3560 (format " (W%02d)" w1)
3561 (format " (W%02d-W%02d)" w1 w2))
3563 ":\n")))
3564 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3565 'org-date-line t))
3566 (org-agenda-mark-header-line s))
3567 (while (setq d (pop day-numbers))
3568 (setq date (calendar-gregorian-from-absolute d)
3569 s (point))
3570 (if (or (setq todayp (= d today))
3571 (and (not start-pos) (= d sd)))
3572 (setq start-pos (point))
3573 (if (and start-pos (not end-pos))
3574 (setq end-pos (point))))
3575 (setq files thefiles
3576 rtnall nil)
3577 (while (setq file (pop files))
3578 (catch 'nextfile
3579 (org-check-agenda-file file)
3580 (let ((org-agenda-entry-types org-agenda-entry-types))
3581 (unless org-agenda-include-deadlines
3582 (setq org-agenda-entry-types
3583 (delq :deadline org-agenda-entry-types)))
3584 (cond
3585 ((eq org-agenda-show-log 'only)
3586 (setq rtn (org-agenda-get-day-entries
3587 file date :closed)))
3588 (org-agenda-show-log
3589 (setq rtn (apply 'org-agenda-get-day-entries
3590 file date
3591 (append '(:closed) org-agenda-entry-types))))
3593 (setq rtn (apply 'org-agenda-get-day-entries
3594 file date
3595 org-agenda-entry-types)))))
3596 (setq rtnall (append rtnall rtn))))
3597 (if org-agenda-include-diary
3598 (let ((org-agenda-search-headline-for-time t))
3599 (require 'diary-lib)
3600 (setq rtn (org-get-entries-from-diary date))
3601 (setq rtnall (append rtnall rtn))))
3602 (if (or rtnall org-agenda-show-all-dates)
3603 (progn
3604 (setq day-cnt (1+ day-cnt))
3605 (insert
3606 (if (stringp org-agenda-format-date)
3607 (format-time-string org-agenda-format-date
3608 (org-time-from-absolute date))
3609 (funcall org-agenda-format-date date))
3610 "\n")
3611 (put-text-property s (1- (point)) 'face
3612 (org-agenda-get-day-face date))
3613 (put-text-property s (1- (point)) 'org-date-line t)
3614 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3615 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3616 (when todayp
3617 (put-text-property s (1- (point)) 'org-today t))
3618 (if rtnall (insert
3619 (org-finalize-agenda-entries
3620 (org-agenda-add-time-grid-maybe
3621 rtnall ndays todayp))
3622 "\n"))
3623 (put-text-property s (1- (point)) 'day d)
3624 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3625 (when (and org-agenda-clockreport-mode clocktable-start)
3626 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3627 ;; the above line is to ensure the restricted range!
3628 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3629 tbl)
3630 (setq p (org-plist-delete p :block))
3631 (setq p (plist-put p :tstart clocktable-start))
3632 (setq p (plist-put p :tend clocktable-end))
3633 (setq p (plist-put p :scope 'agenda))
3634 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3635 (setq filter (or org-agenda-filter-while-redo
3636 (get 'org-agenda-filter :preset-filter))))
3637 (setq p (plist-put p :tags (mapconcat (lambda (x)
3638 (if (string-match "[<>=]" x)
3641 filter ""))))
3642 (setq tbl (apply 'org-get-clocktable p))
3643 (insert tbl)))
3644 (goto-char (point-min))
3645 (or org-agenda-multi (org-fit-agenda-window))
3646 (unless (and (pos-visible-in-window-p (point-min))
3647 (pos-visible-in-window-p (point-max)))
3648 (goto-char (1- (point-max)))
3649 (recenter -1)
3650 (if (not (pos-visible-in-window-p (or start-pos 1)))
3651 (progn
3652 (goto-char (or start-pos 1))
3653 (recenter 1))))
3654 (goto-char (or start-pos 1))
3655 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3656 (org-finalize-agenda)
3657 (setq buffer-read-only t)
3658 (message "")))
3660 (defun org-agenda-ndays-to-span (n)
3661 "Return a span symbol for a span of N days, or N if none matches."
3662 (cond ((symbolp n) n)
3663 ((= n 1) 'day)
3664 ((= n 7) 'week)
3665 (t n)))
3667 (defun org-agenda-span-to-ndays (span start-day)
3668 "Return ndays from SPAN starting at START-DAY."
3669 (cond ((numberp span) span)
3670 ((eq span 'day) 1)
3671 ((eq span 'week) 7)
3672 ((eq span 'month)
3673 (let ((date (calendar-gregorian-from-absolute start-day)))
3674 (calendar-last-day-of-month (car date) (caddr date))))
3675 ((eq span 'year)
3676 (let ((date (calendar-gregorian-from-absolute start-day)))
3677 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3679 (defun org-agenda-span-name (span)
3680 "Return a SPAN name."
3681 (if (null span)
3683 (if (symbolp span)
3684 (capitalize (symbol-name span))
3685 (format "%d days" span))))
3687 ;;; Agenda word search
3689 (defvar org-agenda-search-history nil)
3690 (defvar org-todo-only nil)
3692 (defvar org-search-syntax-table nil
3693 "Special syntax table for org-mode search.
3694 In this table, we have single quotes not as word constituents, to
3695 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3697 (defun org-search-syntax-table ()
3698 (unless org-search-syntax-table
3699 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3700 (modify-syntax-entry ?' "." org-search-syntax-table)
3701 (modify-syntax-entry ?` "." org-search-syntax-table))
3702 org-search-syntax-table)
3704 (defvar org-agenda-last-search-view-search-was-boolean nil)
3706 ;;;###autoload
3707 (defun org-search-view (&optional todo-only string edit-at)
3708 "Show all entries that contain a phrase or words or regular expressions.
3710 With optional prefix argument TODO-ONLY, only consider entries that are
3711 TODO entries. The argument STRING can be used to pass a default search
3712 string into this function. If EDIT-AT is non-nil, it means that the
3713 user should get a chance to edit this string, with cursor at position
3714 EDIT-AT.
3716 The search string can be viewed either as a phrase that should be found as
3717 is, or it can be broken into a number of snippets, each of which must match
3718 in a Boolean way to select an entry. The default depends on the variable
3719 `org-agenda-search-view-always-boolean'.
3720 Even if this is turned off (the default) you can always switch to
3721 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3723 The default is a direct search of the whole phrase, where each space in
3724 the search string can expand to an arbitrary amount of whitespace,
3725 including newlines.
3727 If using a Boolean search, the search string is split on whitespace and
3728 each snippet is searched separately, with logical AND to select an entry.
3729 Words prefixed with a minus must *not* occur in the entry. Words without
3730 a prefix or prefixed with a plus must occur in the entry. Matching is
3731 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3732 match whole words, not parts of a word) if
3733 `org-agenda-search-view-force-full-words' is set (default is nil).
3735 Boolean search snippets enclosed by curly braces are interpreted as
3736 regular expressions that must or (when preceded with \"-\") must not
3737 match in the entry. Snippets enclosed into double quotes will be taken
3738 as a whole, to include whitespace.
3740 - If the search string starts with an asterisk, search only in headlines.
3741 - If (possibly after the leading star) the search string starts with an
3742 exclamation mark, this also means to look at TODO entries only, an effect
3743 that can also be achieved with a prefix argument.
3744 - If (possibly after star and exclamation mark) the search string starts
3745 with a colon, this will mean that the (non-regexp) snippets of the
3746 Boolean search must match as full words.
3748 This command searches the agenda files, and in addition the files listed
3749 in `org-agenda-text-search-extra-files'."
3750 (interactive "P")
3751 (org-compile-prefix-format 'search)
3752 (org-set-sorting-strategy 'search)
3753 (org-prepare-agenda "SEARCH")
3754 (let* ((props (list 'face nil
3755 'done-face 'org-agenda-done
3756 'org-not-done-regexp org-not-done-regexp
3757 'org-todo-regexp org-todo-regexp
3758 'org-complex-heading-regexp org-complex-heading-regexp
3759 'mouse-face 'highlight
3760 'help-echo (format "mouse-2 or RET jump to location")))
3761 (full-words org-agenda-search-view-force-full-words)
3762 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3763 regexp rtn rtnall files file pos
3764 marker category tags c neg re boolean
3765 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3766 (unless (and (not edit-at)
3767 (stringp string)
3768 (string-match "\\S-" string))
3769 (setq string (read-string
3770 (if org-agenda-search-view-always-boolean
3771 "[+-]Word/{Regexp} ...: "
3772 "Phrase, or [+-]Word/{Regexp} ...: ")
3773 (cond
3774 ((integerp edit-at) (cons string edit-at))
3775 (edit-at string))
3776 'org-agenda-search-history)))
3777 (org-set-local 'org-todo-only todo-only)
3778 (setq org-agenda-redo-command
3779 (list 'org-search-view (if todo-only t nil) string
3780 '(if current-prefix-arg 1 nil)))
3781 (setq org-agenda-query-string string)
3783 (if (equal (string-to-char string) ?*)
3784 (setq hdl-only t
3785 words (substring string 1))
3786 (setq words string))
3787 (when (equal (string-to-char words) ?!)
3788 (setq todo-only t
3789 words (substring words 1)))
3790 (when (equal (string-to-char words) ?:)
3791 (setq full-words t
3792 words (substring words 1)))
3793 (if (or org-agenda-search-view-always-boolean
3794 (member (string-to-char words) '(?- ?+ ?\{)))
3795 (setq boolean t))
3796 (setq words (org-split-string words))
3797 (let (www w)
3798 (while (setq w (pop words))
3799 (while (and (string-match "\\\\\\'" w) words)
3800 (setq w (concat (substring w 0 -1) " " (pop words))))
3801 (push w www))
3802 (setq words (nreverse www) www nil)
3803 (while (setq w (pop words))
3804 (when (and (string-match "\\`[-+]?{" w)
3805 (not (string-match "}\\'" w)))
3806 (while (and words (not (string-match "}\\'" (car words))))
3807 (setq w (concat w " " (pop words))))
3808 (setq w (concat w " " (pop words))))
3809 (push w www))
3810 (setq words (nreverse www)))
3811 (setq org-agenda-last-search-view-search-was-boolean boolean)
3812 (when boolean
3813 (let (wds w)
3814 (while (setq w (pop words))
3815 (if (or (equal (substring w 0 1) "\"")
3816 (and (> (length w) 1)
3817 (member (substring w 0 1) '("+" "-"))
3818 (equal (substring w 1 2) "\"")))
3819 (while (and words (not (equal (substring w -1) "\"")))
3820 (setq w (concat w " " (pop words)))))
3821 (and (string-match "\\`\\([-+]?\\)\"" w)
3822 (setq w (replace-match "\\1" nil nil w)))
3823 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3824 (push w wds))
3825 (setq words (nreverse wds))))
3826 (if boolean
3827 (mapc (lambda (w)
3828 (setq c (string-to-char w))
3829 (if (equal c ?-)
3830 (setq neg t w (substring w 1))
3831 (if (equal c ?+)
3832 (setq neg nil w (substring w 1))
3833 (setq neg nil)))
3834 (if (string-match "\\`{.*}\\'" w)
3835 (setq re (substring w 1 -1))
3836 (if full-words
3837 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3838 (setq re (regexp-quote (downcase w)))))
3839 (if neg (push re regexps-) (push re regexps+)))
3840 words)
3841 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3842 regexps+))
3843 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3844 (if (not regexps+)
3845 (setq regexp (concat "^" org-outline-regexp))
3846 (setq regexp (pop regexps+))
3847 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3848 regexp))))
3849 (setq files (org-agenda-files nil 'ifmode))
3850 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3851 (pop org-agenda-text-search-extra-files)
3852 (setq files (org-add-archive-files files)))
3853 (setq files (append files org-agenda-text-search-extra-files)
3854 rtnall nil)
3855 (while (setq file (pop files))
3856 (setq ee nil)
3857 (catch 'nextfile
3858 (org-check-agenda-file file)
3859 (setq buffer (if (file-exists-p file)
3860 (org-get-agenda-file-buffer file)
3861 (error "No such file %s" file)))
3862 (if (not buffer)
3863 ;; If file does not exist, make sure an error message is sent
3864 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3865 file))))
3866 (with-current-buffer buffer
3867 (with-syntax-table (org-search-syntax-table)
3868 (unless (org-mode-p)
3869 (error "Agenda file %s is not in `org-mode'" file))
3870 (let ((case-fold-search t))
3871 (save-excursion
3872 (save-restriction
3873 (if org-agenda-restrict
3874 (narrow-to-region org-agenda-restrict-begin
3875 org-agenda-restrict-end)
3876 (widen))
3877 (goto-char (point-min))
3878 (unless (or (org-on-heading-p)
3879 (outline-next-heading))
3880 (throw 'nextfile t))
3881 (goto-char (max (point-min) (1- (point))))
3882 (while (re-search-forward regexp nil t)
3883 (org-back-to-heading t)
3884 (skip-chars-forward "* ")
3885 (setq beg (point-at-bol)
3886 beg1 (point)
3887 end (progn (outline-next-heading) (point)))
3888 (catch :skip
3889 (goto-char beg)
3890 (org-agenda-skip)
3891 (setq str (buffer-substring-no-properties
3892 (point-at-bol)
3893 (if hdl-only (point-at-eol) end)))
3894 (mapc (lambda (wr) (when (string-match wr str)
3895 (goto-char (1- end))
3896 (throw :skip t)))
3897 regexps-)
3898 (mapc (lambda (wr) (unless (string-match wr str)
3899 (goto-char (1- end))
3900 (throw :skip t)))
3901 (if todo-only
3902 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3903 regexps+)
3904 regexps+))
3905 (goto-char beg)
3906 (setq marker (org-agenda-new-marker (point))
3907 category (org-get-category)
3908 tags (org-get-tags-at (point))
3909 txt (org-format-agenda-item
3911 (buffer-substring-no-properties
3912 beg1 (point-at-eol))
3913 category tags))
3914 (org-add-props txt props
3915 'org-marker marker 'org-hd-marker marker
3916 'org-todo-regexp org-todo-regexp
3917 'org-complex-heading-regexp org-complex-heading-regexp
3918 'priority 1000 'org-category category
3919 'type "search")
3920 (push txt ee)
3921 (goto-char (1- end))))))))))
3922 (setq rtn (nreverse ee))
3923 (setq rtnall (append rtnall rtn)))
3924 (if org-agenda-overriding-header
3925 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3926 nil 'face 'org-agenda-structure) "\n")
3927 (insert "Search words: ")
3928 (add-text-properties (point-min) (1- (point))
3929 (list 'face 'org-agenda-structure))
3930 (setq pos (point))
3931 (insert string "\n")
3932 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3933 (setq pos (point))
3934 (unless org-agenda-multi
3935 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3936 (add-text-properties pos (1- (point))
3937 (list 'face 'org-agenda-structure))))
3938 (org-agenda-mark-header-line (point-min))
3939 (when rtnall
3940 (insert (org-finalize-agenda-entries rtnall) "\n"))
3941 (goto-char (point-min))
3942 (or org-agenda-multi (org-fit-agenda-window))
3943 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3944 (org-finalize-agenda)
3945 (setq buffer-read-only t)))
3947 ;;; Agenda TODO list
3949 (defvar org-select-this-todo-keyword nil)
3950 (defvar org-last-arg nil)
3952 ;;;###autoload
3953 (defun org-todo-list (arg)
3954 "Show all (not done) TODO entries from all agenda file in a single list.
3955 The prefix arg can be used to select a specific TODO keyword and limit
3956 the list to these. When using \\[universal-argument], you will be prompted
3957 for a keyword. A numeric prefix directly selects the Nth keyword in
3958 `org-todo-keywords-1'."
3959 (interactive "P")
3960 (org-compile-prefix-format 'todo)
3961 (org-set-sorting-strategy 'todo)
3962 (org-prepare-agenda "TODO")
3963 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3964 (let* ((today (org-today))
3965 (date (calendar-gregorian-from-absolute today))
3966 (kwds org-todo-keywords-for-agenda)
3967 (completion-ignore-case t)
3968 (org-select-this-todo-keyword
3969 (if (stringp arg) arg
3970 (and arg (integerp arg) (> arg 0)
3971 (nth (1- arg) kwds))))
3972 rtn rtnall files file pos)
3973 (when (equal arg '(4))
3974 (setq org-select-this-todo-keyword
3975 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3976 (mapcar 'list kwds) nil nil)))
3977 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3978 (org-set-local 'org-last-arg arg)
3979 (setq org-agenda-redo-command
3980 '(org-todo-list (or current-prefix-arg org-last-arg)))
3981 (setq files (org-agenda-files nil 'ifmode)
3982 rtnall nil)
3983 (while (setq file (pop files))
3984 (catch 'nextfile
3985 (org-check-agenda-file file)
3986 (setq rtn (org-agenda-get-day-entries file date :todo))
3987 (setq rtnall (append rtnall rtn))))
3988 (if org-agenda-overriding-header
3989 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3990 nil 'face 'org-agenda-structure) "\n")
3991 (insert "Global list of TODO items of type: ")
3992 (add-text-properties (point-min) (1- (point))
3993 (list 'face 'org-agenda-structure
3994 'short-heading
3995 (concat "ToDo: "
3996 (or org-select-this-todo-keyword "ALL"))))
3997 (org-agenda-mark-header-line (point-min))
3998 (setq pos (point))
3999 (insert (or org-select-this-todo-keyword "ALL") "\n")
4000 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4001 (setq pos (point))
4002 (unless org-agenda-multi
4003 (insert "Available with `N r': (0)ALL")
4004 (let ((n 0) s)
4005 (mapc (lambda (x)
4006 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4007 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4008 (insert "\n "))
4009 (insert " " s))
4010 kwds))
4011 (insert "\n"))
4012 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4013 (org-agenda-mark-header-line (point-min))
4014 (when rtnall
4015 (insert (org-finalize-agenda-entries rtnall) "\n"))
4016 (goto-char (point-min))
4017 (or org-agenda-multi (org-fit-agenda-window))
4018 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4019 (org-finalize-agenda)
4020 (setq buffer-read-only t)))
4022 ;;; Agenda tags match
4024 ;;;###autoload
4025 (defun org-tags-view (&optional todo-only match)
4026 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4027 The prefix arg TODO-ONLY limits the search to TODO entries."
4028 (interactive "P")
4029 (org-compile-prefix-format 'tags)
4030 (org-set-sorting-strategy 'tags)
4031 (let* ((org-tags-match-list-sublevels
4032 org-tags-match-list-sublevels)
4033 (completion-ignore-case t)
4034 rtn rtnall files file pos matcher
4035 buffer)
4036 (when (and (stringp match) (not (string-match "\\S-" match)))
4037 (setq match nil))
4038 (setq matcher (org-make-tags-matcher match)
4039 match (car matcher) matcher (cdr matcher))
4040 (org-prepare-agenda (concat "TAGS " match))
4041 (setq org-agenda-query-string match)
4042 (setq org-agenda-redo-command
4043 (list 'org-tags-view (list 'quote todo-only)
4044 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4045 (setq files (org-agenda-files nil 'ifmode)
4046 rtnall nil)
4047 (while (setq file (pop files))
4048 (catch 'nextfile
4049 (org-check-agenda-file file)
4050 (setq buffer (if (file-exists-p file)
4051 (org-get-agenda-file-buffer file)
4052 (error "No such file %s" file)))
4053 (if (not buffer)
4054 ;; If file does not exist, error message to agenda
4055 (setq rtn (list
4056 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4057 rtnall (append rtnall rtn))
4058 (with-current-buffer buffer
4059 (unless (org-mode-p)
4060 (error "Agenda file %s is not in `org-mode'" file))
4061 (save-excursion
4062 (save-restriction
4063 (if org-agenda-restrict
4064 (narrow-to-region org-agenda-restrict-begin
4065 org-agenda-restrict-end)
4066 (widen))
4067 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4068 (setq rtnall (append rtnall rtn))))))))
4069 (if org-agenda-overriding-header
4070 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4071 nil 'face 'org-agenda-structure) "\n")
4072 (insert "Headlines with TAGS match: ")
4073 (add-text-properties (point-min) (1- (point))
4074 (list 'face 'org-agenda-structure
4075 'short-heading
4076 (concat "Match: " match)))
4077 (setq pos (point))
4078 (insert match "\n")
4079 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4080 (setq pos (point))
4081 (unless org-agenda-multi
4082 (insert "Press `C-u r' to search again with new search string\n"))
4083 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4084 (org-agenda-mark-header-line (point-min))
4085 (when rtnall
4086 (insert (org-finalize-agenda-entries rtnall) "\n"))
4087 (goto-char (point-min))
4088 (or org-agenda-multi (org-fit-agenda-window))
4089 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4090 (org-finalize-agenda)
4091 (setq buffer-read-only t)))
4093 ;;; Agenda Finding stuck projects
4095 (defvar org-agenda-skip-regexp nil
4096 "Regular expression used in skipping subtrees for the agenda.
4097 This is basically a temporary global variable that can be set and then
4098 used by user-defined selections using `org-agenda-skip-function'.")
4100 (defvar org-agenda-overriding-header nil
4101 "When this is set during todo and tags searches, will replace header.
4102 This variable should not be set directly, but custom commands can bind it
4103 in the options section.")
4105 (defun org-agenda-skip-entry-when-regexp-matches ()
4106 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4107 If yes, it returns the end position of this entry, causing agenda commands
4108 to skip the entry but continuing the search in the subtree. This is a
4109 function that can be put into `org-agenda-skip-function' for the duration
4110 of a command."
4111 (let ((end (save-excursion (org-end-of-subtree t)))
4112 skip)
4113 (save-excursion
4114 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4115 (and skip end)))
4117 (defun org-agenda-skip-subtree-when-regexp-matches ()
4118 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4119 If yes, it returns the end position of this tree, causing agenda commands
4120 to skip this subtree. This is a function that can be put into
4121 `org-agenda-skip-function' for the duration of a command."
4122 (let ((end (save-excursion (org-end-of-subtree t)))
4123 skip)
4124 (save-excursion
4125 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4126 (and skip end)))
4128 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4129 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4130 If yes, it returns the end position of the current entry (NOT the tree),
4131 causing agenda commands to skip the entry but continuing the search in
4132 the subtree. This is a function that can be put into
4133 `org-agenda-skip-function' for the duration of a command. An important
4134 use of this function is for the stuck project list."
4135 (let ((end (save-excursion (org-end-of-subtree t)))
4136 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4137 skip)
4138 (save-excursion
4139 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4140 (and skip entry-end)))
4142 (defun org-agenda-skip-entry-if (&rest conditions)
4143 "Skip entry if any of CONDITIONS is true.
4144 See `org-agenda-skip-if' for details."
4145 (org-agenda-skip-if nil conditions))
4147 (defun org-agenda-skip-subtree-if (&rest conditions)
4148 "Skip entry if any of CONDITIONS is true.
4149 See `org-agenda-skip-if' for details."
4150 (org-agenda-skip-if t conditions))
4152 (defun org-agenda-skip-if (subtree conditions)
4153 "Checks current entity for CONDITIONS.
4154 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4155 the entry, i.e. the text before the next heading is checked.
4157 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4158 from different tests. Valid conditions are:
4160 scheduled Check if there is a scheduled cookie
4161 notscheduled Check if there is no scheduled cookie
4162 deadline Check if there is a deadline
4163 notdeadline Check if there is no deadline
4164 timestamp Check if there is a timestamp (also deadline or scheduled)
4165 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4166 regexp Check if regexp matches
4167 notregexp Check if regexp does not match.
4168 todo Check if TODO keyword matches
4169 nottodo Check if TODO keyword does not match
4171 The regexp is taken from the conditions list, it must come right after
4172 the `regexp' or `notregexp' element.
4174 `todo' and `nottodo' accept as an argument a list of todo
4175 keywords, which may include \"*\" to match any todo keyword.
4177 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4179 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4181 Instead of a list a keyword class may be given
4183 (org-agenda-skip-entry-if 'nottodo 'done)
4185 would skip entries that haven't been marked with any of \"DONE\"
4186 keywords. Possible classes are: `todo', `done', `any'.
4188 If any of these conditions is met, this function returns the end point of
4189 the entity, causing the search to continue from there. This is a function
4190 that can be put into `org-agenda-skip-function' for the duration of a command."
4191 (let (beg end m)
4192 (org-back-to-heading t)
4193 (setq beg (point)
4194 end (if subtree
4195 (progn (org-end-of-subtree t) (point))
4196 (progn (outline-next-heading) (1- (point)))))
4197 (goto-char beg)
4198 (and
4200 (and (memq 'scheduled conditions)
4201 (re-search-forward org-scheduled-time-regexp end t))
4202 (and (memq 'notscheduled conditions)
4203 (not (re-search-forward org-scheduled-time-regexp end t)))
4204 (and (memq 'deadline conditions)
4205 (re-search-forward org-deadline-time-regexp end t))
4206 (and (memq 'notdeadline conditions)
4207 (not (re-search-forward org-deadline-time-regexp end t)))
4208 (and (memq 'timestamp conditions)
4209 (re-search-forward org-ts-regexp end t))
4210 (and (memq 'nottimestamp conditions)
4211 (not (re-search-forward org-ts-regexp end t)))
4212 (and (setq m (memq 'regexp conditions))
4213 (stringp (nth 1 m))
4214 (re-search-forward (nth 1 m) end t))
4215 (and (setq m (memq 'notregexp conditions))
4216 (stringp (nth 1 m))
4217 (not (re-search-forward (nth 1 m) end t)))
4218 (and (or
4219 (setq m (memq 'todo conditions))
4220 (setq m (memq 'nottodo conditions)))
4221 (org-agenda-skip-if-todo m end)))
4222 end)))
4224 (defun org-agenda-skip-if-todo (args end)
4225 "Helper function for `org-agenda-skip-if', do not use it directly.
4226 ARGS is a list with first element either `todo' or `nottodo'.
4227 The remainder is either a list of TODO keywords, or a state symbol
4228 `todo' or `done' or `any'."
4229 (let ((kw (car args))
4230 (arg (cadr args))
4231 todo-wds todo-re)
4232 (setq todo-wds
4233 (org-uniquify
4234 (cond
4235 ((listp arg) ;; list of keywords
4236 (if (member "*" arg)
4237 (mapcar 'substring-no-properties org-todo-keywords-1)
4238 arg))
4239 ((symbolp arg) ;; keyword class name
4240 (cond
4241 ((eq arg 'todo)
4242 (org-delete-all org-done-keywords
4243 (mapcar 'substring-no-properties
4244 org-todo-keywords-1)))
4245 ((eq arg 'done) org-done-keywords)
4246 ((eq arg 'any)
4247 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4248 (setq todo-re
4249 (concat "^\\*+[ \t]+\\<\\("
4250 (mapconcat 'identity todo-wds "\\|")
4251 "\\)\\>"))
4252 (if (eq kw 'todo)
4253 (re-search-forward todo-re end t)
4254 (not (re-search-forward todo-re end t)))))
4256 ;;;###autoload
4257 (defun org-agenda-list-stuck-projects (&rest ignore)
4258 "Create agenda view for projects that are stuck.
4259 Stuck projects are project that have no next actions. For the definitions
4260 of what a project is and how to check if it stuck, customize the variable
4261 `org-stuck-projects'."
4262 (interactive)
4263 (let* ((org-agenda-skip-function
4264 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4265 ;; We could have used org-agenda-skip-if here.
4266 (org-agenda-overriding-header
4267 (or org-agenda-overriding-header "List of stuck projects: "))
4268 (matcher (nth 0 org-stuck-projects))
4269 (todo (nth 1 org-stuck-projects))
4270 (todo-wds (if (member "*" todo)
4271 (progn
4272 (org-prepare-agenda-buffers (org-agenda-files
4273 nil 'ifmode))
4274 (org-delete-all
4275 org-done-keywords-for-agenda
4276 (copy-sequence org-todo-keywords-for-agenda)))
4277 todo))
4278 (todo-re (concat "^\\*+[ \t]+\\("
4279 (mapconcat 'identity todo-wds "\\|")
4280 "\\)\\>"))
4281 (tags (nth 2 org-stuck-projects))
4282 (tags-re (if (member "*" tags)
4283 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4284 (if tags
4285 (concat "^\\*+ .*:\\("
4286 (mapconcat 'identity tags "\\|")
4287 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4288 (gen-re (nth 3 org-stuck-projects))
4289 (re-list
4290 (delq nil
4291 (list
4292 (if todo todo-re)
4293 (if tags tags-re)
4294 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4295 gen-re)))))
4296 (setq org-agenda-skip-regexp
4297 (if re-list
4298 (mapconcat 'identity re-list "\\|")
4299 (error "No information how to identify unstuck projects")))
4300 (org-tags-view nil matcher)
4301 (with-current-buffer org-agenda-buffer-name
4302 (setq org-agenda-redo-command
4303 '(org-agenda-list-stuck-projects
4304 (or current-prefix-arg org-last-arg))))))
4306 ;;; Diary integration
4308 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4309 (defvar list-diary-entries-hook)
4310 (defvar diary-time-regexp)
4311 (defun org-get-entries-from-diary (date)
4312 "Get the (Emacs Calendar) diary entries for DATE."
4313 (require 'diary-lib)
4314 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4315 (diary-display-hook '(fancy-diary-display))
4316 (diary-display-function 'fancy-diary-display)
4317 (pop-up-frames nil)
4318 (list-diary-entries-hook
4319 (cons 'org-diary-default-entry list-diary-entries-hook))
4320 (diary-file-name-prefix-function nil) ; turn this feature off
4321 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4322 entries
4323 (org-disable-agenda-to-diary t))
4324 (save-excursion
4325 (save-window-excursion
4326 (funcall (if (fboundp 'diary-list-entries)
4327 'diary-list-entries 'list-diary-entries)
4328 date 1)))
4329 (if (not (get-buffer diary-fancy-buffer))
4330 (setq entries nil)
4331 (with-current-buffer diary-fancy-buffer
4332 (setq buffer-read-only nil)
4333 (if (zerop (buffer-size))
4334 ;; No entries
4335 (setq entries nil)
4336 ;; Omit the date and other unnecessary stuff
4337 (org-agenda-cleanup-fancy-diary)
4338 ;; Add prefix to each line and extend the text properties
4339 (if (zerop (buffer-size))
4340 (setq entries nil)
4341 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4342 (setq entries
4343 (with-temp-buffer
4344 (insert entries) (goto-char (point-min))
4345 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4346 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4347 (replace-match (concat "; " (match-string 1)))))
4348 (buffer-string)))))
4349 (set-buffer-modified-p nil)
4350 (kill-buffer diary-fancy-buffer)))
4351 (when entries
4352 (setq entries (org-split-string entries "\n"))
4353 (setq entries
4354 (mapcar
4355 (lambda (x)
4356 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4357 ;; Extend the text properties to the beginning of the line
4358 (org-add-props x (text-properties-at (1- (length x)) x)
4359 'type "diary" 'date date 'face 'org-agenda-diary))
4360 entries)))))
4362 (defvar org-agenda-cleanup-fancy-diary-hook nil
4363 "Hook run when the fancy diary buffer is cleaned up.")
4365 (defun org-agenda-cleanup-fancy-diary ()
4366 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4367 This gets rid of the date, the underline under the date, and
4368 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4369 date. It also removes lines that contain only whitespace."
4370 (goto-char (point-min))
4371 (if (looking-at ".*?:[ \t]*")
4372 (progn
4373 (replace-match "")
4374 (re-search-forward "\n=+$" nil t)
4375 (replace-match "")
4376 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4377 (re-search-forward "\n=+$" nil t)
4378 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4379 (goto-char (point-min))
4380 (while (re-search-forward "^ +\n" nil t)
4381 (replace-match ""))
4382 (goto-char (point-min))
4383 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4384 (replace-match ""))
4385 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4387 ;; Make sure entries from the diary have the right text properties.
4388 (eval-after-load "diary-lib"
4389 '(if (boundp 'diary-modify-entry-list-string-function)
4390 ;; We can rely on the hook, nothing to do
4392 ;; Hook not available, must use advice to make this work
4393 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4394 "Make the position visible."
4395 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4396 (stringp string)
4397 buffer-file-name)
4398 (setq string (org-modify-diary-entry-string string))))))
4400 (defun org-modify-diary-entry-string (string)
4401 "Add text properties to string, allowing org-mode to act on it."
4402 (org-add-props string nil
4403 'mouse-face 'highlight
4404 'help-echo (if buffer-file-name
4405 (format "mouse-2 or RET jump to diary file %s"
4406 (abbreviate-file-name buffer-file-name))
4408 'org-agenda-diary-link t
4409 'org-marker (org-agenda-new-marker (point-at-bol))))
4411 (defun org-diary-default-entry ()
4412 "Add a dummy entry to the diary.
4413 Needed to avoid empty dates which mess up holiday display."
4414 ;; Catch the error if dealing with the new add-to-diary-alist
4415 (when org-disable-agenda-to-diary
4416 (condition-case nil
4417 (org-add-to-diary-list original-date "Org-mode dummy" "")
4418 (error
4419 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4421 (defun org-add-to-diary-list (&rest args)
4422 (if (fboundp 'diary-add-to-list)
4423 (apply 'diary-add-to-list args)
4424 (apply 'add-to-diary-list args)))
4426 (defvar org-diary-last-run-time nil)
4428 ;;;###autoload
4429 (defun org-diary (&rest args)
4430 "Return diary information from org-files.
4431 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4432 It accesses org files and extracts information from those files to be
4433 listed in the diary. The function accepts arguments specifying what
4434 items should be listed. For a list of arguments allowed here, see the
4435 variable `org-agenda-entry-types'.
4437 The call in the diary file should look like this:
4439 &%%(org-diary) ~/path/to/some/orgfile.org
4441 Use a separate line for each org file to check. Or, if you omit the file name,
4442 all files listed in `org-agenda-files' will be checked automatically:
4444 &%%(org-diary)
4446 If you don't give any arguments (as in the example above), the default
4447 arguments (:deadline :scheduled :timestamp :sexp) are used.
4448 So the example above may also be written as
4450 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4452 The function expects the lisp variables `entry' and `date' to be provided
4453 by the caller, because this is how the calendar works. Don't use this
4454 function from a program - use `org-agenda-get-day-entries' instead."
4455 (when (> (- (org-float-time)
4456 org-agenda-last-marker-time)
4458 (org-agenda-reset-markers))
4459 (org-compile-prefix-format 'agenda)
4460 (org-set-sorting-strategy 'agenda)
4461 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4462 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4463 (list entry)
4464 (org-agenda-files t)))
4465 (time (org-float-time))
4466 file rtn results)
4467 (when (or (not org-diary-last-run-time)
4468 (> (- time
4469 org-diary-last-run-time)
4471 (org-prepare-agenda-buffers files))
4472 (setq org-diary-last-run-time time)
4473 ;; If this is called during org-agenda, don't return any entries to
4474 ;; the calendar. Org Agenda will list these entries itself.
4475 (if org-disable-agenda-to-diary (setq files nil))
4476 (while (setq file (pop files))
4477 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4478 (setq results (append results rtn)))
4479 (if results
4480 (concat (org-finalize-agenda-entries results) "\n"))))
4482 ;;; Agenda entry finders
4484 (defun org-agenda-get-day-entries (file date &rest args)
4485 "Does the work for `org-diary' and `org-agenda'.
4486 FILE is the path to a file to be checked for entries. DATE is date like
4487 the one returned by `calendar-current-date'. ARGS are symbols indicating
4488 which kind of entries should be extracted. For details about these, see
4489 the documentation of `org-diary'."
4490 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4491 (let* ((org-startup-folded nil)
4492 (org-startup-align-all-tables nil)
4493 (buffer (if (file-exists-p file)
4494 (org-get-agenda-file-buffer file)
4495 (error "No such file %s" file)))
4496 arg results rtn deadline-results)
4497 (if (not buffer)
4498 ;; If file does not exist, make sure an error message ends up in diary
4499 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4500 (with-current-buffer buffer
4501 (unless (org-mode-p)
4502 (error "Agenda file %s is not in `org-mode'" file))
4503 (let ((case-fold-search nil))
4504 (save-excursion
4505 (save-restriction
4506 (if org-agenda-restrict
4507 (narrow-to-region org-agenda-restrict-begin
4508 org-agenda-restrict-end)
4509 (widen))
4510 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4511 (while (setq arg (pop args))
4512 (cond
4513 ((and (eq arg :todo)
4514 (equal date (calendar-gregorian-from-absolute
4515 (org-today))))
4516 (setq rtn (org-agenda-get-todos))
4517 (setq results (append results rtn)))
4518 ((eq arg :timestamp)
4519 (setq rtn (org-agenda-get-blocks))
4520 (setq results (append results rtn))
4521 (setq rtn (org-agenda-get-timestamps))
4522 (setq results (append results rtn)))
4523 ((eq arg :sexp)
4524 (setq rtn (org-agenda-get-sexps))
4525 (setq results (append results rtn)))
4526 ((eq arg :scheduled)
4527 (setq rtn (org-agenda-get-scheduled deadline-results))
4528 (setq results (append results rtn)))
4529 ((eq arg :closed)
4530 (setq rtn (org-agenda-get-progress))
4531 (setq results (append results rtn)))
4532 ((eq arg :deadline)
4533 (setq rtn (org-agenda-get-deadlines))
4534 (setq deadline-results (copy-sequence rtn))
4535 (setq results (append results rtn))))))))
4536 results))))
4538 (defun org-agenda-get-todos ()
4539 "Return the TODO information for agenda display."
4540 (let* ((props (list 'face nil
4541 'done-face 'org-agenda-done
4542 'org-not-done-regexp org-not-done-regexp
4543 'org-todo-regexp org-todo-regexp
4544 'org-complex-heading-regexp org-complex-heading-regexp
4545 'mouse-face 'highlight
4546 'help-echo
4547 (format "mouse-2 or RET jump to org file %s"
4548 (abbreviate-file-name buffer-file-name))))
4549 (regexp (concat "^\\*+[ \t]+\\("
4550 (if org-select-this-todo-keyword
4551 (if (equal org-select-this-todo-keyword "*")
4552 org-todo-regexp
4553 (concat "\\<\\("
4554 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4555 "\\)\\>"))
4556 org-not-done-regexp)
4557 "[^\n\r]*\\)"))
4558 marker priority category tags todo-state
4559 ee txt beg end)
4560 (goto-char (point-min))
4561 (while (re-search-forward regexp nil t)
4562 (catch :skip
4563 (save-match-data
4564 (beginning-of-line)
4565 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4566 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4567 (goto-char (1+ beg))
4568 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4569 (throw :skip nil)))
4570 (goto-char beg)
4571 (org-agenda-skip)
4572 (goto-char (match-beginning 1))
4573 (setq marker (org-agenda-new-marker (match-beginning 0))
4574 category (org-get-category)
4575 txt (match-string 1)
4576 tags (org-get-tags-at (point))
4577 txt (org-format-agenda-item "" txt category tags)
4578 priority (1+ (org-get-priority txt))
4579 todo-state (org-get-todo-state))
4580 (org-add-props txt props
4581 'org-marker marker 'org-hd-marker marker
4582 'priority priority 'org-category category
4583 'type "todo" 'todo-state todo-state)
4584 (push txt ee)
4585 (if org-agenda-todo-list-sublevels
4586 (goto-char (match-end 1))
4587 (org-end-of-subtree 'invisible))))
4588 (nreverse ee)))
4590 (defun org-agenda-todo-custom-ignore-p (time n)
4591 "Check whether timestamp is farther away then n number of days.
4592 This function is invoked if `org-agenda-todo-ignore-deadlines',
4593 `org-agenda-todo-ignore-scheduled' or
4594 `org-agenda-todo-ignore-timestamp' is set to an integer."
4595 (let ((days (org-days-to-time time)))
4596 (if (>= n 0)
4597 (>= days n)
4598 (<= days n))))
4600 ;;;###autoload
4601 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4602 (&optional end)
4603 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4604 (when (or org-agenda-todo-ignore-with-date
4605 org-agenda-todo-ignore-scheduled
4606 org-agenda-todo-ignore-deadlines
4607 org-agenda-todo-ignore-timestamp)
4608 (setq end (or end (save-excursion (outline-next-heading) (point))))
4609 (save-excursion
4610 (or (and org-agenda-todo-ignore-with-date
4611 (re-search-forward org-ts-regexp end t))
4612 (and org-agenda-todo-ignore-scheduled
4613 (re-search-forward org-scheduled-time-regexp end t)
4614 (cond
4615 ((eq org-agenda-todo-ignore-scheduled 'future)
4616 (> (org-days-to-time (match-string 1)) 0))
4617 ((eq org-agenda-todo-ignore-scheduled 'past)
4618 (<= (org-days-to-time (match-string 1)) 0))
4619 ((numberp org-agenda-todo-ignore-scheduled)
4620 (org-agenda-todo-custom-ignore-p
4621 (match-string 1) org-agenda-todo-ignore-scheduled))
4622 (t)))
4623 (and org-agenda-todo-ignore-deadlines
4624 (re-search-forward org-deadline-time-regexp end t)
4625 (cond
4626 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4627 ((eq org-agenda-todo-ignore-deadlines 'far)
4628 (not (org-deadline-close (match-string 1))))
4629 ((eq org-agenda-todo-ignore-deadlines 'future)
4630 (> (org-days-to-time (match-string 1)) 0))
4631 ((eq org-agenda-todo-ignore-deadlines 'past)
4632 (<= (org-days-to-time (match-string 1)) 0))
4633 ((numberp org-agenda-todo-ignore-deadlines)
4634 (org-agenda-todo-custom-ignore-p
4635 (match-string 1) org-agenda-todo-ignore-deadlines))
4636 (t (org-deadline-close (match-string 1)))))
4637 (and org-agenda-todo-ignore-timestamp
4638 (let ((buffer (current-buffer))
4639 (regexp
4640 (concat
4641 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4642 (start (point)))
4643 ;; Copy current buffer into a temporary one
4644 (with-temp-buffer
4645 (insert-buffer-substring buffer start end)
4646 (goto-char (point-min))
4647 ;; Delete SCHEDULED and DEADLINE items
4648 (while (re-search-forward regexp end t)
4649 (delete-region (match-beginning 0) (match-end 0)))
4650 (goto-char (point-min))
4651 ;; No search for timestamp left
4652 (when (re-search-forward org-ts-regexp nil t)
4653 (cond
4654 ((eq org-agenda-todo-ignore-timestamp 'future)
4655 (> (org-days-to-time (match-string 1)) 0))
4656 ((eq org-agenda-todo-ignore-timestamp 'past)
4657 (<= (org-days-to-time (match-string 1)) 0))
4658 ((numberp org-agenda-todo-ignore-timestamp)
4659 (org-agenda-todo-custom-ignore-p
4660 (match-string 1) org-agenda-todo-ignore-timestamp))
4661 (t))))))))))
4663 (defconst org-agenda-no-heading-message
4664 "No heading for this item in buffer or region.")
4666 (defun org-agenda-get-timestamps ()
4667 "Return the date stamp information for agenda display."
4668 (let* ((props (list 'face nil
4669 'org-not-done-regexp org-not-done-regexp
4670 'org-todo-regexp org-todo-regexp
4671 'org-complex-heading-regexp org-complex-heading-regexp
4672 'mouse-face 'highlight
4673 'help-echo
4674 (format "mouse-2 or RET jump to org file %s"
4675 (abbreviate-file-name buffer-file-name))))
4676 (d1 (calendar-absolute-from-gregorian date))
4677 (remove-re
4678 (concat
4679 (regexp-quote
4680 (format-time-string
4681 "<%Y-%m-%d"
4682 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4683 ".*?>"))
4684 (regexp
4685 (concat
4686 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4687 (regexp-quote
4688 (substring
4689 (format-time-string
4690 (car org-time-stamp-formats)
4691 (apply 'encode-time ; DATE bound by calendar
4692 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4693 1 11))
4694 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4695 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4696 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4697 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4698 todo-state end-of-match show-all)
4699 (goto-char (point-min))
4700 (while (setq end-of-match (re-search-forward regexp nil t))
4701 (setq b0 (match-beginning 0)
4702 b3 (match-beginning 3) e3 (match-end 3)
4703 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4704 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4705 (member todo-state
4706 org-agenda-repeating-timestamp-show-all)))
4707 (catch :skip
4708 (and (org-at-date-range-p) (throw :skip nil))
4709 (org-agenda-skip)
4710 (if (and (match-end 1)
4711 (not (= d1 (org-time-string-to-absolute
4712 (match-string 1) d1 nil show-all))))
4713 (throw :skip nil))
4714 (if (and e3
4715 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4716 (throw :skip nil))
4717 (setq tmp (buffer-substring (max (point-min)
4718 (- b0 org-ds-keyword-length))
4720 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4721 inactivep (= (char-after b0) ?\[)
4722 deadlinep (string-match org-deadline-regexp tmp)
4723 scheduledp (string-match org-scheduled-regexp tmp)
4724 closedp (and org-agenda-include-inactive-timestamps
4725 (string-match org-closed-string tmp))
4726 clockp (and org-agenda-include-inactive-timestamps
4727 (or (string-match org-clock-string tmp)
4728 (string-match "]-+\\'" tmp)))
4729 donep (member todo-state org-done-keywords))
4730 (if (or scheduledp deadlinep closedp clockp
4731 (and donep org-agenda-skip-timestamp-if-done))
4732 (throw :skip t))
4733 (if (string-match ">" timestr)
4734 ;; substring should only run to end of time stamp
4735 (setq timestr (substring timestr 0 (match-end 0))))
4736 (setq marker (org-agenda-new-marker b0)
4737 category (org-get-category b0))
4738 (save-excursion
4739 (if (not (re-search-backward "^\\*+ " nil t))
4740 (setq txt org-agenda-no-heading-message)
4741 (goto-char (match-beginning 0))
4742 (setq hdmarker (org-agenda-new-marker)
4743 tags (org-get-tags-at))
4744 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4745 (setq head (match-string 1))
4746 (setq txt (org-format-agenda-item
4747 (if inactivep org-agenda-inactive-leader nil)
4748 head category tags timestr nil
4749 remove-re)))
4750 (setq priority (org-get-priority txt))
4751 (org-add-props txt props
4752 'org-marker marker 'org-hd-marker hdmarker)
4753 (org-add-props txt nil 'priority priority
4754 'org-category category 'date date
4755 'todo-state todo-state
4756 'type "timestamp")
4757 (push txt ee))
4758 (if org-agenda-skip-additional-timestamps-same-entry
4759 (outline-next-heading)
4760 (goto-char end-of-match))))
4761 (nreverse ee)))
4763 (defun org-agenda-get-sexps ()
4764 "Return the sexp information for agenda display."
4765 (require 'diary-lib)
4766 (let* ((props (list 'mouse-face 'highlight
4767 'help-echo
4768 (format "mouse-2 or RET jump to org file %s"
4769 (abbreviate-file-name buffer-file-name))))
4770 (regexp "^&?%%(")
4771 marker category ee txt tags entry result beg b sexp sexp-entry
4772 todo-state)
4773 (goto-char (point-min))
4774 (while (re-search-forward regexp nil t)
4775 (catch :skip
4776 (org-agenda-skip)
4777 (setq beg (match-beginning 0))
4778 (goto-char (1- (match-end 0)))
4779 (setq b (point))
4780 (forward-sexp 1)
4781 (setq sexp (buffer-substring b (point)))
4782 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4783 (org-trim (match-string 1))
4784 ""))
4785 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4786 (when result
4787 (setq marker (org-agenda-new-marker beg)
4788 category (org-get-category beg)
4789 todo-state (org-get-todo-state))
4791 (dolist (r (if (stringp result)
4792 (list result)
4793 result)) ;; we expect a list here
4794 (if (string-match "\\S-" r)
4795 (setq txt r)
4796 (setq txt "SEXP entry returned empty string"))
4798 (setq txt (org-format-agenda-item
4799 "" txt category tags 'time))
4800 (org-add-props txt props 'org-marker marker)
4801 (org-add-props txt nil
4802 'org-category category 'date date 'todo-state todo-state
4803 'type "sexp")
4804 (push txt ee)))))
4805 (nreverse ee)))
4807 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4808 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4809 The order of the first 2 times 3 arguments depends on the variable
4810 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4811 So for American calendars, give this as MONTH DAY YEAR, for European as
4812 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4813 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4814 is any number of ISO weeks in the block period for which the item should
4815 be skipped."
4816 (let* ((date1 (calendar-absolute-from-gregorian
4817 (org-order-calendar-date-args m1 d1 y1)))
4818 (date2 (calendar-absolute-from-gregorian
4819 (org-order-calendar-date-args m2 d2 y2)))
4820 (d (calendar-absolute-from-gregorian date)))
4821 (and
4822 (<= date1 d)
4823 (<= d date2)
4824 (= (calendar-day-of-week date) dayname)
4825 (or (not skip-weeks)
4826 (progn
4827 (require 'cal-iso)
4828 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4829 entry)))
4831 (defalias 'org-get-closed 'org-agenda-get-progress)
4832 (defun org-agenda-get-progress ()
4833 "Return the logged TODO entries for agenda display."
4834 (let* ((props (list 'mouse-face 'highlight
4835 'org-not-done-regexp org-not-done-regexp
4836 'org-todo-regexp org-todo-regexp
4837 'org-complex-heading-regexp org-complex-heading-regexp
4838 'help-echo
4839 (format "mouse-2 or RET jump to org file %s"
4840 (abbreviate-file-name buffer-file-name))))
4841 (items (if (consp org-agenda-show-log)
4842 org-agenda-show-log
4843 org-agenda-log-mode-items))
4844 (parts
4845 (delq nil
4846 (list
4847 (if (memq 'closed items) (concat "\\<" org-closed-string))
4848 (if (memq 'clock items) (concat "\\<" org-clock-string))
4849 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4850 (parts-re (if parts (mapconcat 'identity parts "\\|")
4851 (error "`org-agenda-log-mode-items' is empty")))
4852 (regexp (concat
4853 "\\(" parts-re "\\)"
4854 " *\\["
4855 (regexp-quote
4856 (substring
4857 (format-time-string
4858 (car org-time-stamp-formats)
4859 (apply 'encode-time ; DATE bound by calendar
4860 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4861 1 11))))
4862 (org-agenda-search-headline-for-time nil)
4863 marker hdmarker priority category tags closedp statep clockp state
4864 ee txt extra timestr rest clocked)
4865 (goto-char (point-min))
4866 (while (re-search-forward regexp nil t)
4867 (catch :skip
4868 (org-agenda-skip)
4869 (setq marker (org-agenda-new-marker (match-beginning 0))
4870 closedp (equal (match-string 1) org-closed-string)
4871 statep (equal (string-to-char (match-string 1)) ?-)
4872 clockp (not (or closedp statep))
4873 state (and statep (match-string 2))
4874 category (org-get-category (match-beginning 0))
4875 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4877 (when (string-match "\\]" timestr)
4878 ;; substring should only run to end of time stamp
4879 (setq rest (substring timestr (match-end 0))
4880 timestr (substring timestr 0 (match-end 0)))
4881 (if (and (not closedp) (not statep)
4882 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4883 (progn (setq timestr (concat (substring timestr 0 -1)
4884 "-" (match-string 1 rest) "]"))
4885 (setq clocked (match-string 2 rest)))
4886 (setq clocked "-")))
4887 (save-excursion
4888 (setq extra
4889 (cond
4890 ((not org-agenda-log-mode-add-notes) nil)
4891 (statep
4892 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4893 (match-string 1)))
4894 (clockp
4895 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4896 (match-string 1)))))
4897 (if (not (re-search-backward "^\\*+ " nil t))
4898 (setq txt org-agenda-no-heading-message)
4899 (goto-char (match-beginning 0))
4900 (setq hdmarker (org-agenda-new-marker)
4901 tags (org-get-tags-at))
4902 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4903 (setq txt (match-string 1))
4904 (when extra
4905 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4906 (setq txt (concat (substring txt 0 (match-beginning 1))
4907 " - " extra " " (match-string 2 txt)))
4908 (setq txt (concat txt " - " extra))))
4909 (setq txt (org-format-agenda-item
4910 (cond
4911 (closedp "Closed: ")
4912 (statep (concat "State: (" state ")"))
4913 (t (concat "Clocked: (" clocked ")")))
4914 txt category tags timestr)))
4915 (setq priority 100000)
4916 (org-add-props txt props
4917 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4918 'priority priority 'org-category category
4919 'type "closed" 'date date
4920 'undone-face 'org-warning 'done-face 'org-agenda-done)
4921 (push txt ee))
4922 (goto-char (point-at-eol))))
4923 (nreverse ee)))
4925 (defun org-agenda-get-deadlines ()
4926 "Return the deadline information for agenda display."
4927 (let* ((props (list 'mouse-face 'highlight
4928 'org-not-done-regexp org-not-done-regexp
4929 'org-todo-regexp org-todo-regexp
4930 'org-complex-heading-regexp org-complex-heading-regexp
4931 'help-echo
4932 (format "mouse-2 or RET jump to org file %s"
4933 (abbreviate-file-name buffer-file-name))))
4934 (regexp org-deadline-time-regexp)
4935 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4936 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4937 d2 diff dfrac wdays pos pos1 category tags
4938 suppress-prewarning
4939 ee txt head face s todo-state show-all upcomingp donep timestr)
4940 (goto-char (point-min))
4941 (while (re-search-forward regexp nil t)
4942 (setq suppress-prewarning nil)
4943 (catch :skip
4944 (org-agenda-skip)
4945 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4946 (save-match-data
4947 (string-match org-scheduled-time-regexp
4948 (buffer-substring (point-at-bol)
4949 (point-at-eol)))))
4950 (setq suppress-prewarning
4951 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4952 org-agenda-skip-deadline-prewarning-if-scheduled
4953 0)))
4954 (setq s (match-string 1)
4955 txt nil
4956 pos (1- (match-beginning 1))
4957 todo-state (save-match-data (org-get-todo-state))
4958 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4959 (member todo-state
4960 org-agenda-repeating-timestamp-show-all))
4961 d2 (org-time-string-to-absolute
4962 (match-string 1) d1 'past show-all)
4963 diff (- d2 d1)
4964 wdays (if suppress-prewarning
4965 (let ((org-deadline-warning-days suppress-prewarning))
4966 (org-get-wdays s))
4967 (org-get-wdays s))
4968 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4969 upcomingp (and todayp (> diff 0)))
4970 ;; When to show a deadline in the calendar:
4971 ;; If the expiration is within wdays warning time.
4972 ;; Past-due deadlines are only shown on the current date
4973 (if (and (or (and (<= diff wdays)
4974 (and todayp (not org-agenda-only-exact-dates)))
4975 (= diff 0)))
4976 (save-excursion
4977 ;; (setq todo-state (org-get-todo-state))
4978 (setq donep (member todo-state org-done-keywords))
4979 (if (and donep
4980 (or org-agenda-skip-deadline-if-done
4981 (not (= diff 0))))
4982 (setq txt nil)
4983 (setq category (org-get-category))
4984 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4985 (setq txt org-agenda-no-heading-message)
4986 (goto-char (match-end 0))
4987 (setq pos1 (match-beginning 0))
4988 (setq tags (org-get-tags-at pos1))
4989 (setq head (buffer-substring-no-properties
4990 (point)
4991 (progn (skip-chars-forward "^\r\n")
4992 (point))))
4993 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4994 (setq timestr
4995 (concat (substring s (match-beginning 1)) " "))
4996 (setq timestr 'time))
4997 (setq txt (org-format-agenda-item
4998 (if (= diff 0)
4999 (car org-agenda-deadline-leaders)
5000 (if (functionp
5001 (nth 1 org-agenda-deadline-leaders))
5002 (funcall
5003 (nth 1 org-agenda-deadline-leaders)
5004 diff date)
5005 (format (nth 1 org-agenda-deadline-leaders)
5006 diff)))
5007 head category tags
5008 (if (not (= diff 0)) nil timestr)))))
5009 (when txt
5010 (setq face (org-agenda-deadline-face dfrac wdays))
5011 (org-add-props txt props
5012 'org-marker (org-agenda-new-marker pos)
5013 'org-hd-marker (org-agenda-new-marker pos1)
5014 'priority (+ (- diff)
5015 (org-get-priority txt))
5016 'org-category category
5017 'todo-state todo-state
5018 'type (if upcomingp "upcoming-deadline" "deadline")
5019 'date (if upcomingp date d2)
5020 'face (if donep 'org-agenda-done face)
5021 'undone-face face 'done-face 'org-agenda-done)
5022 (push txt ee))))))
5023 (nreverse ee)))
5025 (defun org-agenda-deadline-face (fraction &optional wdays)
5026 "Return the face to displaying a deadline item.
5027 FRACTION is what fraction of the head-warning time has passed."
5028 (if (equal wdays 0) (setq fraction 1.))
5029 (let ((faces org-agenda-deadline-faces) f)
5030 (catch 'exit
5031 (while (setq f (pop faces))
5032 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5034 (defun org-agenda-get-scheduled (&optional deadline-results)
5035 "Return the scheduled information for agenda display."
5036 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5037 'org-todo-regexp org-todo-regexp
5038 'org-complex-heading-regexp org-complex-heading-regexp
5039 'done-face 'org-agenda-done
5040 'mouse-face 'highlight
5041 'help-echo
5042 (format "mouse-2 or RET jump to org file %s"
5043 (abbreviate-file-name buffer-file-name))))
5044 (regexp org-scheduled-time-regexp)
5045 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5046 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5048 (deadline-position-alist
5049 (mapcar (lambda (a) (and (setq mm (get-text-property
5050 0 'org-hd-marker a))
5051 (cons (marker-position mm) a)))
5052 deadline-results))
5053 d2 diff pos pos1 category tags donep
5054 ee txt head pastschedp todo-state face timestr s habitp show-all)
5055 (goto-char (point-min))
5056 (while (re-search-forward regexp nil t)
5057 (catch :skip
5058 (org-agenda-skip)
5059 (setq s (match-string 1)
5060 txt nil
5061 pos (1- (match-beginning 1))
5062 todo-state (save-match-data (org-get-todo-state))
5063 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5064 (member todo-state
5065 org-agenda-repeating-timestamp-show-all))
5066 d2 (org-time-string-to-absolute
5067 (match-string 1) d1 'past show-all)
5068 diff (- d2 d1))
5069 (setq pastschedp (and todayp (< diff 0)))
5070 ;; When to show a scheduled item in the calendar:
5071 ;; If it is on or past the date.
5072 (when (or (and (< diff 0)
5073 (< (abs diff) org-scheduled-past-days)
5074 (and todayp (not org-agenda-only-exact-dates)))
5075 (= diff 0))
5076 (save-excursion
5077 (setq donep (member todo-state org-done-keywords))
5078 (if (and donep
5079 (or org-agenda-skip-scheduled-if-done
5080 (not (= diff 0))
5081 (and (functionp 'org-is-habit-p)
5082 (org-is-habit-p))))
5083 (setq txt nil)
5084 (setq habitp (and (functionp 'org-is-habit-p)
5085 (org-is-habit-p)))
5086 (setq category (org-get-category))
5087 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5088 (setq txt org-agenda-no-heading-message)
5089 (goto-char (match-end 0))
5090 (setq pos1 (match-beginning 0))
5091 (if habitp
5092 (if (or (not org-habit-show-habits)
5093 (and (not todayp)
5094 org-habit-show-habits-only-for-today))
5095 (throw :skip nil))
5096 (if (and
5097 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5098 (and org-agenda-skip-scheduled-if-deadline-is-shown
5099 pastschedp))
5100 (setq mm (assoc pos1 deadline-position-alist)))
5101 (throw :skip nil)))
5102 (setq tags (org-get-tags-at))
5103 (setq head (buffer-substring-no-properties
5104 (point)
5105 (progn (skip-chars-forward "^\r\n") (point))))
5106 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5107 (setq timestr
5108 (concat (substring s (match-beginning 1)) " "))
5109 (setq timestr 'time))
5110 (setq txt (org-format-agenda-item
5111 (if (= diff 0)
5112 (car org-agenda-scheduled-leaders)
5113 (format (nth 1 org-agenda-scheduled-leaders)
5114 (- 1 diff)))
5115 head category tags
5116 (if (not (= diff 0)) nil timestr)
5117 nil nil habitp))))
5118 (when txt
5119 (setq face
5120 (cond
5121 ((and (not habitp) pastschedp)
5122 'org-scheduled-previously)
5123 (todayp 'org-scheduled-today)
5124 (t 'org-scheduled))
5125 habitp (and habitp (org-habit-parse-todo)))
5126 (org-add-props txt props
5127 'undone-face face
5128 'face (if donep 'org-agenda-done face)
5129 'org-marker (org-agenda-new-marker pos)
5130 'org-hd-marker (org-agenda-new-marker pos1)
5131 'type (if pastschedp "past-scheduled" "scheduled")
5132 'date (if pastschedp d2 date)
5133 'priority (if habitp
5134 (org-habit-get-priority habitp)
5135 (+ 94 (- 5 diff) (org-get-priority txt)))
5136 'org-category category
5137 'org-habit-p habitp
5138 'todo-state todo-state)
5139 (push txt ee))))))
5140 (nreverse ee)))
5142 (defun org-agenda-get-blocks ()
5143 "Return the date-range information for agenda display."
5144 (let* ((props (list 'face nil
5145 'org-not-done-regexp org-not-done-regexp
5146 'org-todo-regexp org-todo-regexp
5147 'org-complex-heading-regexp org-complex-heading-regexp
5148 'mouse-face 'highlight
5149 'help-echo
5150 (format "mouse-2 or RET jump to org file %s"
5151 (abbreviate-file-name buffer-file-name))))
5152 (regexp org-tr-regexp)
5153 (d0 (calendar-absolute-from-gregorian date))
5154 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5155 head donep)
5156 (goto-char (point-min))
5157 (while (re-search-forward regexp nil t)
5158 (catch :skip
5159 (org-agenda-skip)
5160 (setq pos (point))
5161 (let ((start-time (match-string 1))
5162 (end-time (match-string 2)))
5163 (setq s1 (match-string 1)
5164 s2 (match-string 2)
5165 d1 (time-to-days (org-time-string-to-time s1))
5166 d2 (time-to-days (org-time-string-to-time s2)))
5167 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5168 ;; Only allow days between the limits, because the normal
5169 ;; date stamps will catch the limits.
5170 (save-excursion
5171 (setq todo-state (org-get-todo-state))
5172 (setq donep (member todo-state org-done-keywords))
5173 (if (and donep org-agenda-skip-timestamp-if-done)
5174 (throw :skip t))
5175 (setq marker (org-agenda-new-marker (point)))
5176 (setq category (org-get-category))
5177 (if (not (re-search-backward "^\\*+ " nil t))
5178 (setq txt org-agenda-no-heading-message)
5179 (goto-char (match-beginning 0))
5180 (setq hdmarker (org-agenda-new-marker (point)))
5181 (setq tags (org-get-tags-at))
5182 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5183 (setq head (match-string 1))
5184 (let ((remove-re
5185 (if org-agenda-remove-timeranges-from-blocks
5186 (concat
5187 "<" (regexp-quote s1) ".*?>"
5188 "--"
5189 "<" (regexp-quote s2) ".*?>")
5190 nil)))
5191 (setq txt (org-format-agenda-item
5192 (format
5193 (nth (if (= d1 d2) 0 1)
5194 org-agenda-timerange-leaders)
5195 (1+ (- d0 d1)) (1+ (- d2 d1)))
5196 head category tags
5197 (cond ((= d1 d0)
5198 (concat "<" start-time ">"))
5199 ((= d2 d0)
5200 (concat "<" end-time ">"))
5201 (t nil))
5202 remove-re))))
5203 (org-add-props txt props
5204 'org-marker marker 'org-hd-marker hdmarker
5205 'type "block" 'date date
5206 'todo-state todo-state
5207 'priority (org-get-priority txt) 'org-category category)
5208 (push txt ee))))
5209 (goto-char pos)))
5210 ;; Sort the entries by expiration date.
5211 (nreverse ee)))
5213 ;;; Agenda presentation and sorting
5215 (defvar org-prefix-has-time nil
5216 "A flag, set by `org-compile-prefix-format'.
5217 The flag is set if the currently compiled format contains a `%t'.")
5218 (defvar org-prefix-has-tag nil
5219 "A flag, set by `org-compile-prefix-format'.
5220 The flag is set if the currently compiled format contains a `%T'.")
5221 (defvar org-prefix-has-effort nil
5222 "A flag, set by `org-compile-prefix-format'.
5223 The flag is set if the currently compiled format contains a `%e'.")
5224 (defvar org-prefix-category-length nil
5225 "Used by `org-compile-prefix-format' to remember the category field width.")
5226 (defvar org-prefix-category-max-length nil
5227 "Used by `org-compile-prefix-format' to remember the category field width.")
5229 (defun org-agenda-get-category-icon (category)
5230 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5231 (dolist (entry org-agenda-category-icon-alist)
5232 (when (org-string-match-p (car entry) category)
5233 (if (listp (cadr entry))
5234 (return (cadr entry))
5235 (return (apply 'create-image (cdr entry)))))))
5237 (defun org-format-agenda-item (extra txt &optional category tags dotime
5238 noprefix remove-re habitp)
5239 "Format TXT to be inserted into the agenda buffer.
5240 In particular, it adds the prefix and corresponding text properties. EXTRA
5241 must be a string and replaces the `%s' specifier in the prefix format.
5242 CATEGORY (string, symbol or nil) may be used to overrule the default
5243 category taken from local variable or file name. It will replace the `%c'
5244 specifier in the format. DOTIME, when non-nil, indicates that a
5245 time-of-day should be extracted from TXT for sorting of this entry, and for
5246 the `%t' specifier in the format. When DOTIME is a string, this string is
5247 searched for a time before TXT is. NOPREFIX is a flag and indicates that
5248 only the correctly processes TXT should be returned - this is used by
5249 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
5250 Any match of REMOVE-RE will be removed from TXT."
5251 (save-match-data
5252 ;; Diary entries sometimes have extra whitespace at the beginning
5253 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5255 ;; Fix the tags part in txt
5256 (setq txt (org-agenda-fix-displayed-tags
5257 txt tags
5258 org-agenda-show-inherited-tags
5259 org-agenda-hide-tags-regexp))
5260 (let* ((category (or category
5261 (if (stringp org-category)
5262 org-category
5263 (and org-category (symbol-name org-category)))
5264 (if buffer-file-name
5265 (file-name-sans-extension
5266 (file-name-nondirectory buffer-file-name))
5267 "")))
5268 (category-icon (org-agenda-get-category-icon category))
5269 (category-icon (if category-icon
5270 (propertize " " 'display category-icon)
5271 ""))
5272 ;; time, tag, effort are needed for the eval of the prefix format
5273 (tag (if tags (nth (1- (length tags)) tags) ""))
5274 time effort neffort
5275 (ts (if dotime (concat
5276 (if (stringp dotime) dotime "")
5277 (and org-agenda-search-headline-for-time txt))))
5278 (time-of-day (and dotime (org-get-time-of-day ts)))
5279 stamp plain s0 s1 s2 rtn srp l
5280 duration thecategory)
5281 (and (org-mode-p) buffer-file-name
5282 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5283 (when (and dotime time-of-day)
5284 ;; Extract starting and ending time and move them to prefix
5285 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5286 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5287 (setq s0 (match-string 0 ts)
5288 srp (and stamp (match-end 3))
5289 s1 (match-string (if plain 1 2) ts)
5290 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5292 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5293 ;; them, we might want to remove them there to avoid duplication.
5294 ;; The user can turn this off with a variable.
5295 (if (and org-prefix-has-time
5296 org-agenda-remove-times-when-in-prefix (or stamp plain)
5297 (string-match (concat (regexp-quote s0) " *") txt)
5298 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5299 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5300 (= (match-beginning 0) 0)
5302 (setq txt (replace-match "" nil nil txt))))
5303 ;; Normalize the time(s) to 24 hour
5304 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5305 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5307 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5308 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5309 (setq s2
5310 (org-minutes-to-hh:mm-string
5311 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5313 ;; Compute the duration
5314 (when s2
5315 (setq duration (- (org-hh:mm-string-to-minutes s2)
5316 (org-hh:mm-string-to-minutes s1)))))
5318 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5319 txt)
5320 ;; Tags are in the string
5321 (if (or (eq org-agenda-remove-tags t)
5322 (and org-agenda-remove-tags
5323 org-prefix-has-tag))
5324 (setq txt (replace-match "" t t txt))
5325 (setq txt (replace-match
5326 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5327 (match-string 2 txt))
5328 t t txt))))
5329 (when (org-mode-p)
5330 (setq effort
5331 (condition-case nil
5332 (org-get-effort
5333 (or (get-text-property 0 'org-hd-marker txt)
5334 (get-text-property 0 'org-marker txt)))
5335 (error nil)))
5336 (when effort
5337 (setq neffort (org-duration-string-to-minutes effort)
5338 effort (setq effort (concat "[" effort "]" )))))
5340 (when remove-re
5341 (while (string-match remove-re txt)
5342 (setq txt (replace-match "" t t txt))))
5344 ;; Create the final string
5345 (if noprefix
5346 (setq rtn txt)
5347 ;; Prepare the variables needed in the eval of the compiled format
5348 (setq time (cond (s2 (concat
5349 (org-agenda-time-of-day-to-ampm-maybe s1)
5350 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5351 (if org-agenda-timegrid-use-ampm " ")))
5352 (s1 (concat
5353 (org-agenda-time-of-day-to-ampm-maybe s1)
5354 (if org-agenda-timegrid-use-ampm
5355 "........ "
5356 "......")))
5357 (t ""))
5358 extra (or (and (not habitp) extra) "")
5359 category (if (symbolp category) (symbol-name category) category)
5360 thecategory (copy-sequence category))
5361 (if (string-match org-bracket-link-regexp category)
5362 (progn
5363 (setq l (if (match-end 3)
5364 (- (match-end 3) (match-beginning 3))
5365 (- (match-end 1) (match-beginning 1))))
5366 (when (< l (or org-prefix-category-length 0))
5367 (setq category (copy-sequence category))
5368 (org-add-props category nil
5369 'extra-space (make-string
5370 (- org-prefix-category-length l 1) ?\ ))))
5371 (if (and org-prefix-category-max-length
5372 (>= (length category) org-prefix-category-max-length))
5373 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5374 ;; Evaluate the compiled format
5375 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5377 ;; And finally add the text properties
5378 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5379 (org-add-props rtn nil
5380 'org-category (if thecategory (downcase thecategory) category)
5381 'tags (mapcar 'org-downcase-keep-props tags)
5382 'org-highest-priority org-highest-priority
5383 'org-lowest-priority org-lowest-priority
5384 'prefix-length (- (length rtn) (length txt))
5385 'time-of-day time-of-day
5386 'duration duration
5387 'effort effort
5388 'effort-minutes neffort
5389 'txt txt
5390 'time time
5391 'extra extra
5392 'dotime dotime))))
5394 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5395 "Remove tags string from TXT, and add a modified list of tags.
5396 The modified list may contain inherited tags, and tags matched by
5397 `org-agenda-hide-tags-regexp' will be removed."
5398 (when (or add-inherited hide-re)
5399 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5400 (setq txt (substring txt 0 (match-beginning 0))))
5401 (setq tags
5402 (delq nil
5403 (mapcar (lambda (tg)
5404 (if (or (and hide-re (string-match hide-re tg))
5405 (and (not add-inherited)
5406 (get-text-property 0 'inherited tg)))
5408 tg))
5409 tags)))
5410 (when tags
5411 (let ((have-i (get-text-property 0 'inherited (car tags)))
5413 (setq txt (concat txt " :"
5414 (mapconcat
5415 (lambda (x)
5416 (setq i (get-text-property 0 'inherited x))
5417 (if (and have-i (not i))
5418 (progn
5419 (setq have-i nil)
5420 (concat ":" x))
5422 tags ":")
5423 (if have-i "::" ":"))))))
5424 txt)
5426 (defun org-downcase-keep-props (s)
5427 (let ((props (text-properties-at 0 s)))
5428 (setq s (downcase s))
5429 (add-text-properties 0 (length s) props s)
5432 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5433 (defvar org-agenda-sorting-strategy-selected nil)
5435 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5436 (catch 'exit
5437 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5438 ((and todayp (member 'today (car org-agenda-time-grid))))
5439 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5440 ((member 'weekly (car org-agenda-time-grid)))
5441 (t (throw 'exit list)))
5442 (let* ((have (delq nil (mapcar
5443 (lambda (x) (get-text-property 1 'time-of-day x))
5444 list)))
5445 (string (nth 1 org-agenda-time-grid))
5446 (gridtimes (nth 2 org-agenda-time-grid))
5447 (req (car org-agenda-time-grid))
5448 (remove (member 'remove-match req))
5449 new time)
5450 (if (and (member 'require-timed req) (not have))
5451 ;; don't show empty grid
5452 (throw 'exit list))
5453 (while (setq time (pop gridtimes))
5454 (unless (and remove (member time have))
5455 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5456 (push (org-format-agenda-item
5457 nil string "" nil
5458 (concat (substring time 0 -2) ":" (substring time -2)))
5459 new)
5460 (put-text-property
5461 2 (length (car new)) 'face 'org-time-grid (car new))))
5462 (when (and todayp org-agenda-show-current-time-in-grid)
5463 (push (org-format-agenda-item
5464 nil
5465 org-agenda-current-time-string
5466 "" nil
5467 (format-time-string "%H:%M "))
5468 new)
5469 (put-text-property
5470 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5472 (if (member 'time-up org-agenda-sorting-strategy-selected)
5473 (append new list)
5474 (append list new)))))
5476 (defun org-compile-prefix-format (key)
5477 "Compile the prefix format into a Lisp form that can be evaluated.
5478 The resulting form is returned and stored in the variable
5479 `org-prefix-format-compiled'."
5480 (setq org-prefix-has-time nil org-prefix-has-tag nil
5481 org-prefix-category-length nil org-prefix-has-effort nil)
5482 (let ((s (cond
5483 ((stringp org-agenda-prefix-format)
5484 org-agenda-prefix-format)
5485 ((assq key org-agenda-prefix-format)
5486 (cdr (assq key org-agenda-prefix-format)))
5487 (t " %-12:c%?-12t% s")))
5488 (start 0)
5489 varform vars var e c f opt)
5490 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5491 s start)
5492 (setq var (or (cdr (assoc (match-string 4 s)
5493 '(("c" . category) ("t" . time) ("s" . extra)
5494 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5495 'eval)
5496 c (or (match-string 3 s) "")
5497 opt (match-beginning 1)
5498 start (1+ (match-beginning 0)))
5499 (if (equal var 'time) (setq org-prefix-has-time t))
5500 (if (equal var 'tag) (setq org-prefix-has-tag t))
5501 (if (equal var 'effort) (setq org-prefix-has-effort t))
5502 (setq f (concat "%" (match-string 2 s) "s"))
5503 (when (equal var 'category)
5504 (setq org-prefix-category-length
5505 (floor (abs (string-to-number (match-string 2 s)))))
5506 (setq org-prefix-category-max-length
5507 (let ((x (match-string 2 s)))
5508 (save-match-data
5509 (if (string-match "\\.[0-9]+" x)
5510 (string-to-number (substring (match-string 0 x) 1)))))))
5511 (if (eq var 'eval)
5512 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5513 (if opt
5514 (setq varform
5515 `(if (equal "" ,var)
5517 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5518 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5519 (setq s (replace-match "%s" t nil s))
5520 (push varform vars))
5521 (setq vars (nreverse vars))
5522 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5524 (defun org-set-sorting-strategy (key)
5525 (if (symbolp (car org-agenda-sorting-strategy))
5526 ;; the old format
5527 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5528 (setq org-agenda-sorting-strategy-selected
5529 (or (cdr (assq key org-agenda-sorting-strategy))
5530 (cdr (assq 'agenda org-agenda-sorting-strategy))
5531 '(time-up category-keep priority-down)))))
5533 (defun org-get-time-of-day (s &optional string mod24)
5534 "Check string S for a time of day.
5535 If found, return it as a military time number between 0 and 2400.
5536 If not found, return nil.
5537 The optional STRING argument forces conversion into a 5 character wide string
5538 HH:MM."
5539 (save-match-data
5540 (when
5541 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5542 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5543 (let* ((h (string-to-number (match-string 1 s)))
5544 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5545 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5546 (am-p (equal ampm "am"))
5547 (h1 (cond ((not ampm) h)
5548 ((= h 12) (if am-p 0 12))
5549 (t (+ h (if am-p 0 12)))))
5550 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5551 (mod h1 24) h1))
5552 (t0 (+ (* 100 h2) m))
5553 (t1 (concat (if (>= h1 24) "+" " ")
5554 (if (and org-agenda-time-leading-zero
5555 (< t0 1000)) "0" "")
5556 (if (< t0 100) "0" "")
5557 (if (< t0 10) "0" "")
5558 (int-to-string t0))))
5559 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5561 (defvar org-agenda-before-sorting-filter-function nil
5562 "Function to be applied to agenda items prior to sorting.
5563 Prior to sorting also means just before they are inserted into the agenda.
5565 To aid sorting, you may revisit the original entries and add more text
5566 properties which will later be used by the sorting functions.
5568 The function should take a string argument, an agenda line.
5569 It has access to the text properties in that line, which contain among
5570 other things, the property `org-hd-marker' that points to the entry
5571 where the line comes from. Note that not all lines going into the agenda
5572 have this property, only most.
5574 The function should return the modified string. It is probably best
5575 to ONLY change text properties.
5577 You can also use this function as a filter, by returning nil for lines
5578 you don't want to have in the agenda at all. For this application, you
5579 could bind the variable in the options section of a custom command.")
5581 (defun org-finalize-agenda-entries (list &optional nosort)
5582 "Sort and concatenate the agenda items."
5583 (setq list (mapcar 'org-agenda-highlight-todo list))
5584 (if nosort
5585 list
5586 (when org-agenda-before-sorting-filter-function
5587 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5588 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5590 (defun org-agenda-highlight-todo (x)
5591 (let ((org-done-keywords org-done-keywords-for-agenda)
5592 (case-fold-search nil)
5593 re pl)
5594 (if (eq x 'line)
5595 (save-excursion
5596 (beginning-of-line 1)
5597 (setq re (org-get-at-bol 'org-todo-regexp))
5598 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5599 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5600 (add-text-properties (match-beginning 0) (match-end 1)
5601 (list 'face (org-get-todo-face 1)))
5602 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5603 (delete-region (match-beginning 1) (1- (match-end 0)))
5604 (goto-char (match-beginning 1))
5605 (insert (format org-agenda-todo-keyword-format s)))))
5606 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5607 pl (get-text-property 0 'prefix-length x))
5608 (when (and re
5609 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5610 x (or pl 0)) pl))
5611 (add-text-properties
5612 (or (match-end 1) (match-end 0)) (match-end 0)
5613 (list 'face (org-get-todo-face (match-string 2 x)))
5615 (when (match-end 1)
5616 (setq x (concat (substring x 0 (match-end 1))
5617 (format org-agenda-todo-keyword-format
5618 (match-string 2 x))
5619 (org-add-props " " (text-properties-at 0 x))
5620 (substring x (match-end 3))))))
5621 x)))
5623 (defsubst org-cmp-priority (a b)
5624 "Compare the priorities of string A and B."
5625 (let ((pa (or (get-text-property 1 'priority a) 0))
5626 (pb (or (get-text-property 1 'priority b) 0)))
5627 (cond ((> pa pb) +1)
5628 ((< pa pb) -1)
5629 (t nil))))
5631 (defsubst org-cmp-effort (a b)
5632 "Compare the priorities of string A and B."
5633 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5634 (ea (or (get-text-property 1 'effort-minutes a) def))
5635 (eb (or (get-text-property 1 'effort-minutes b) def)))
5636 (cond ((> ea eb) +1)
5637 ((< ea eb) -1)
5638 (t nil))))
5640 (defsubst org-cmp-category (a b)
5641 "Compare the string values of categories of strings A and B."
5642 (let ((ca (or (get-text-property 1 'org-category a) ""))
5643 (cb (or (get-text-property 1 'org-category b) "")))
5644 (cond ((string-lessp ca cb) -1)
5645 ((string-lessp cb ca) +1)
5646 (t nil))))
5648 (defsubst org-cmp-todo-state (a b)
5649 "Compare the todo states of strings A and B."
5650 (let* ((ma (or (get-text-property 1 'org-marker a)
5651 (get-text-property 1 'org-hd-marker a)))
5652 (mb (or (get-text-property 1 'org-marker b)
5653 (get-text-property 1 'org-hd-marker b)))
5654 (fa (and ma (marker-buffer ma)))
5655 (fb (and mb (marker-buffer mb)))
5656 (todo-kwds
5657 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5658 (and fb (with-current-buffer fb org-todo-keywords-1))))
5659 (ta (or (get-text-property 1 'todo-state a) ""))
5660 (tb (or (get-text-property 1 'todo-state b) ""))
5661 (la (- (length (member ta todo-kwds))))
5662 (lb (- (length (member tb todo-kwds))))
5663 (donepa (member ta org-done-keywords-for-agenda))
5664 (donepb (member tb org-done-keywords-for-agenda)))
5665 (cond ((and donepa (not donepb)) -1)
5666 ((and (not donepa) donepb) +1)
5667 ((< la lb) -1)
5668 ((< lb la) +1)
5669 (t nil))))
5671 (defsubst org-cmp-alpha (a b)
5672 "Compare the headlines, alphabetically."
5673 (let* ((pla (get-text-property 0 'prefix-length a))
5674 (plb (get-text-property 0 'prefix-length b))
5675 (ta (and pla (substring a pla)))
5676 (tb (and plb (substring b plb))))
5677 (when pla
5678 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5679 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5680 (setq ta (substring ta (match-end 0))))
5681 (setq ta (downcase ta)))
5682 (when plb
5683 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5684 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5685 (setq tb (substring tb (match-end 0))))
5686 (setq tb (downcase tb)))
5687 (cond ((not ta) +1)
5688 ((not tb) -1)
5689 ((string-lessp ta tb) -1)
5690 ((string-lessp tb ta) +1)
5691 (t nil))))
5693 (defsubst org-cmp-tag (a b)
5694 "Compare the string values of the first tags of A and B."
5695 (let ((ta (car (last (get-text-property 1 'tags a))))
5696 (tb (car (last (get-text-property 1 'tags b)))))
5697 (cond ((not ta) +1)
5698 ((not tb) -1)
5699 ((string-lessp ta tb) -1)
5700 ((string-lessp tb ta) +1)
5701 (t nil))))
5703 (defsubst org-cmp-time (a b)
5704 "Compare the time-of-day values of strings A and B."
5705 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5706 (ta (or (get-text-property 1 'time-of-day a) def))
5707 (tb (or (get-text-property 1 'time-of-day b) def)))
5708 (cond ((< ta tb) -1)
5709 ((< tb ta) +1)
5710 (t nil))))
5712 (defsubst org-cmp-habit-p (a b)
5713 "Compare the todo states of strings A and B."
5714 (let ((ha (get-text-property 1 'org-habit-p a))
5715 (hb (get-text-property 1 'org-habit-p b)))
5716 (cond ((and ha (not hb)) -1)
5717 ((and (not ha) hb) +1)
5718 (t nil))))
5720 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5722 (defun org-entries-lessp (a b)
5723 "Predicate for sorting agenda entries."
5724 ;; The following variables will be used when the form is evaluated.
5725 ;; So even though the compiler complains, keep them.
5726 (let* ((ss org-agenda-sorting-strategy-selected)
5727 (time-up (and (org-em 'time-up 'time-down ss)
5728 (org-cmp-time a b)))
5729 (time-down (if time-up (- time-up) nil))
5730 (priority-up (and (org-em 'priority-up 'priority-down ss)
5731 (org-cmp-priority a b)))
5732 (priority-down (if priority-up (- priority-up) nil))
5733 (effort-up (and (org-em 'effort-up 'effort-down ss)
5734 (org-cmp-effort a b)))
5735 (effort-down (if effort-up (- effort-up) nil))
5736 (category-up (and (or (org-em 'category-up 'category-down ss)
5737 (memq 'category-keep ss))
5738 (org-cmp-category a b)))
5739 (category-down (if category-up (- category-up) nil))
5740 (category-keep (if category-up +1 nil))
5741 (tag-up (and (org-em 'tag-up 'tag-down ss)
5742 (org-cmp-tag a b)))
5743 (tag-down (if tag-up (- tag-up) nil))
5744 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5745 (org-cmp-todo-state a b)))
5746 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5747 (habit-up (and (org-em 'habit-up 'habit-down ss)
5748 (org-cmp-habit-p a b)))
5749 (habit-down (if habit-up (- habit-up) nil))
5750 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5751 (org-cmp-alpha a b)))
5752 (alpha-down (if alpha-up (- alpha-up) nil))
5753 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5754 user-defined-up user-defined-down)
5755 (if (and need-user-cmp org-agenda-cmp-user-defined
5756 (functionp org-agenda-cmp-user-defined))
5757 (setq user-defined-up
5758 (funcall org-agenda-cmp-user-defined a b)
5759 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5760 (cdr (assoc
5761 (eval (cons 'or org-agenda-sorting-strategy-selected))
5762 '((-1 . t) (1 . nil) (nil . nil))))))
5764 ;;; Agenda restriction lock
5766 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5767 "Overlay to mark the headline to which agenda commands are restricted.")
5768 (overlay-put org-agenda-restriction-lock-overlay
5769 'face 'org-agenda-restriction-lock)
5770 (overlay-put org-agenda-restriction-lock-overlay
5771 'help-echo "Agendas are currently limited to this subtree.")
5772 (org-detach-overlay org-agenda-restriction-lock-overlay)
5774 (defun org-agenda-set-restriction-lock (&optional type)
5775 "Set restriction lock for agenda, to current subtree or file.
5776 Restriction will be the file if TYPE is `file', or if type is the
5777 universal prefix '(4), or if the cursor is before the first headline
5778 in the file. Otherwise, restriction will be to the current subtree."
5779 (interactive "P")
5780 (and (equal type '(4)) (setq type 'file))
5781 (setq type (cond
5782 (type type)
5783 ((org-at-heading-p) 'subtree)
5784 ((condition-case nil (org-back-to-heading t) (error nil))
5785 'subtree)
5786 (t 'file)))
5787 (if (eq type 'subtree)
5788 (progn
5789 (setq org-agenda-restrict t)
5790 (setq org-agenda-overriding-restriction 'subtree)
5791 (put 'org-agenda-files 'org-restrict
5792 (list (buffer-file-name (buffer-base-buffer))))
5793 (org-back-to-heading t)
5794 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5795 (move-marker org-agenda-restrict-begin (point))
5796 (move-marker org-agenda-restrict-end
5797 (save-excursion (org-end-of-subtree t)))
5798 (message "Locking agenda restriction to subtree"))
5799 (put 'org-agenda-files 'org-restrict
5800 (list (buffer-file-name (buffer-base-buffer))))
5801 (setq org-agenda-restrict nil)
5802 (setq org-agenda-overriding-restriction 'file)
5803 (move-marker org-agenda-restrict-begin nil)
5804 (move-marker org-agenda-restrict-end nil)
5805 (message "Locking agenda restriction to file"))
5806 (setq current-prefix-arg nil)
5807 (org-agenda-maybe-redo))
5809 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5810 "Remove the agenda restriction lock."
5811 (interactive "P")
5812 (org-detach-overlay org-agenda-restriction-lock-overlay)
5813 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5814 (setq org-agenda-overriding-restriction nil)
5815 (setq org-agenda-restrict nil)
5816 (put 'org-agenda-files 'org-restrict nil)
5817 (move-marker org-agenda-restrict-begin nil)
5818 (move-marker org-agenda-restrict-end nil)
5819 (setq current-prefix-arg nil)
5820 (message "Agenda restriction lock removed")
5821 (or noupdate (org-agenda-maybe-redo)))
5823 (defun org-agenda-maybe-redo ()
5824 "If there is any window showing the agenda view, update it."
5825 (let ((w (get-buffer-window org-agenda-buffer-name t))
5826 (w0 (selected-window)))
5827 (when w
5828 (select-window w)
5829 (org-agenda-redo)
5830 (select-window w0)
5831 (if org-agenda-overriding-restriction
5832 (message "Agenda view shifted to new %s restriction"
5833 org-agenda-overriding-restriction)
5834 (message "Agenda restriction lock removed")))))
5836 ;;; Agenda commands
5838 (defun org-agenda-check-type (error &rest types)
5839 "Check if agenda buffer is of allowed type.
5840 If ERROR is non-nil, throw an error, otherwise just return nil."
5841 (if (memq org-agenda-type types)
5843 (if error
5844 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5845 nil)))
5847 (defun org-agenda-quit ()
5848 "Exit agenda by removing the window or the buffer."
5849 (interactive)
5850 (if org-agenda-columns-active
5851 (org-columns-quit)
5852 (let ((buf (current-buffer)))
5853 (if (eq org-agenda-window-setup 'other-frame)
5854 (progn
5855 (kill-buffer buf)
5856 (org-agenda-reset-markers)
5857 (org-columns-remove-overlays)
5858 (setq org-agenda-archives-mode nil)
5859 (delete-frame))
5860 (and (not (eq org-agenda-window-setup 'current-window))
5861 (not (one-window-p))
5862 (delete-window))
5863 (kill-buffer buf)
5864 (org-agenda-reset-markers)
5865 (org-columns-remove-overlays)
5866 (setq org-agenda-archives-mode nil)))
5867 ;; Maybe restore the pre-agenda window configuration.
5868 (and org-agenda-restore-windows-after-quit
5869 (not (eq org-agenda-window-setup 'other-frame))
5870 org-pre-agenda-window-conf
5871 (set-window-configuration org-pre-agenda-window-conf))))
5873 (defun org-agenda-exit ()
5874 "Exit agenda by removing the window or the buffer.
5875 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5876 Org-mode buffers visited directly by the user will not be touched."
5877 (interactive)
5878 (org-release-buffers org-agenda-new-buffers)
5879 (setq org-agenda-new-buffers nil)
5880 (org-agenda-quit))
5882 (defun org-agenda-execute (arg)
5883 "Execute another agenda command, keeping same window.
5884 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5885 in the agenda."
5886 (interactive "P")
5887 (let ((org-agenda-window-setup 'current-window))
5888 (org-agenda arg)))
5890 (defun org-agenda-redo ()
5891 "Rebuild Agenda.
5892 When this is the global TODO list, a prefix argument will be interpreted."
5893 (interactive)
5894 (let* ((org-agenda-keep-modes t)
5895 (filter org-agenda-filter)
5896 (preset (get 'org-agenda-filter :preset-filter))
5897 (org-agenda-filter-while-redo (or filter preset))
5898 (cols org-agenda-columns-active)
5899 (line (org-current-line))
5900 (window-line (- line (org-current-line (window-start))))
5901 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5902 (put 'org-agenda-filter :preset-filter nil)
5903 (and cols (org-columns-quit))
5904 (message "Rebuilding agenda buffer...")
5905 (org-let lprops '(eval org-agenda-redo-command))
5906 (setq org-agenda-undo-list nil
5907 org-agenda-pending-undo-list nil)
5908 (message "Rebuilding agenda buffer...done")
5909 (put 'org-agenda-filter :preset-filter preset)
5910 (and (or filter preset) (org-agenda-filter-apply filter))
5911 (and cols (interactive-p) (org-agenda-columns))
5912 (org-goto-line line)
5913 (recenter window-line)))
5916 (defvar org-global-tags-completion-table nil)
5917 (defvar org-agenda-filter-form nil)
5918 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5919 "Keep only those lines in the agenda buffer that have a specific tag.
5920 The tag is selected with its fast selection letter, as configured.
5921 With prefix argument STRIP, remove all lines that do have the tag.
5922 A lisp caller can specify CHAR. NARROW means that the new tag should be
5923 used to narrow the search - the interactive user can also press `-' or `+'
5924 to switch to narrowing."
5925 (interactive "P")
5926 (let* ((alist org-tag-alist-for-agenda)
5927 (tag-chars (mapconcat
5928 (lambda (x) (if (and (not (symbolp (car x)))
5929 (cdr x))
5930 (char-to-string (cdr x))
5931 ""))
5932 alist ""))
5933 (efforts (org-split-string
5934 (or (cdr (assoc (concat org-effort-property "_ALL")
5935 org-global-properties))
5936 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5937 (effort-op org-agenda-filter-effort-default-operator)
5938 (effort-prompt "")
5939 (inhibit-read-only t)
5940 (current org-agenda-filter)
5941 maybe-reftresh a n tag)
5942 (unless char
5943 (message
5944 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5945 (if narrow "Narrow" "Filter") tag-chars
5946 (if org-agenda-auto-exclude-function "[RET], " ""))
5947 (setq char (read-char)))
5948 (when (member char '(?+ ?-))
5949 ;; Narrowing down
5950 (cond ((equal char ?-) (setq strip t narrow t))
5951 ((equal char ?+) (setq strip nil narrow t)))
5952 (message
5953 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5954 (setq char (read-char)))
5955 (when (member char '(?< ?> ?= ??))
5956 ;; An effort operator
5957 (setq effort-op (char-to-string char))
5958 (setq alist nil) ; to make sure it will be interpreted as effort.
5959 (unless (equal char ??)
5960 (loop for i from 0 to 9 do
5961 (setq effort-prompt
5962 (concat
5963 effort-prompt " ["
5964 (if (= i 9) "0" (int-to-string (1+ i)))
5965 "]" (nth i efforts))))
5966 (message "Effort%s: %s " effort-op effort-prompt)
5967 (setq char (read-char))
5968 (when (or (< char ?0) (> char ?9))
5969 (error "Need 1-9,0 to select effort" ))))
5970 (when (equal char ?\t)
5971 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5972 (org-set-local 'org-global-tags-completion-table
5973 (org-global-tags-completion-table)))
5974 (let ((completion-ignore-case t))
5975 (setq tag (org-icompleting-read
5976 "Tag: " org-global-tags-completion-table))))
5977 (cond
5978 ((equal char ?\r)
5979 (org-agenda-filter-by-tag-show-all)
5980 (when org-agenda-auto-exclude-function
5981 (setq org-agenda-filter '())
5982 (dolist (tag (org-agenda-get-represented-tags))
5983 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5984 (if modifier
5985 (push modifier org-agenda-filter))))
5986 (if (not (null org-agenda-filter))
5987 (org-agenda-filter-apply org-agenda-filter)))
5988 (setq maybe-reftresh t))
5989 ((equal char ?/)
5990 (org-agenda-filter-by-tag-show-all)
5991 (when (get 'org-agenda-filter :preset-filter)
5992 (org-agenda-filter-apply org-agenda-filter))
5993 (setq maybe-reftresh t))
5994 ((or (equal char ?\ )
5995 (setq a (rassoc char alist))
5996 (and (>= char ?0) (<= char ?9)
5997 (setq n (if (= char ?0) 9 (- char ?0 1))
5998 tag (concat effort-op (nth n efforts))
5999 a (cons tag nil)))
6000 (and (= char ??)
6001 (setq tag "?eff")
6002 a (cons tag nil))
6003 (and tag (setq a (cons tag nil))))
6004 (org-agenda-filter-by-tag-show-all)
6005 (setq tag (car a))
6006 (setq org-agenda-filter
6007 (cons (concat (if strip "-" "+") tag)
6008 (if narrow current nil)))
6009 (org-agenda-filter-apply org-agenda-filter)
6010 (setq maybe-reftresh t))
6011 (t (error "Invalid tag selection character %c" char)))
6012 (when (and maybe-reftresh
6013 (eq org-agenda-clockreport-mode 'with-filter))
6014 (org-agenda-redo))))
6016 (defun org-agenda-get-represented-tags ()
6017 "Get a list of all tags currently represented in the agenda."
6018 (let (p tags)
6019 (save-excursion
6020 (goto-char (point-min))
6021 (while (setq p (next-single-property-change (point) 'tags))
6022 (goto-char p)
6023 (mapc (lambda (x) (add-to-list 'tags x))
6024 (get-text-property (point) 'tags))))
6025 tags))
6027 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6028 "Refine the current filter. See `org-agenda-filter-by-tag."
6029 (interactive "P")
6030 (org-agenda-filter-by-tag strip char 'refine))
6032 (defun org-agenda-filter-make-matcher ()
6033 "Create the form that tests a line for the agenda filter."
6034 (let (f f1)
6035 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6036 org-agenda-filter))
6037 (if (member x '("-" "+"))
6038 (setq f1 (if (equal x "-") 'tags '(not tags)))
6039 (if (string-match "[<=>?]" x)
6040 (setq f1 (org-agenda-filter-effort-form x))
6041 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6042 (if (equal (string-to-char x) ?-)
6043 (setq f1 (list 'not f1))))
6044 (push f1 f))
6045 (cons 'and (nreverse f))))
6047 (defun org-agenda-filter-effort-form (e)
6048 "Return the form to compare the effort of the current line with what E says.
6049 E looks like \"+<2:25\"."
6050 (let (op)
6051 (setq e (substring e 1))
6052 (setq op (string-to-char e) e (substring e 1))
6053 (setq op (cond ((equal op ?<) '<=)
6054 ((equal op ?>) '>=)
6055 ((equal op ??) op)
6056 (t '=)))
6057 (list 'org-agenda-compare-effort (list 'quote op)
6058 (org-duration-string-to-minutes e))))
6060 (defun org-agenda-compare-effort (op value)
6061 "Compare the effort of the current line with VALUE, using OP.
6062 If the line does not have an effort defined, return nil."
6063 (let ((eff (org-get-at-bol 'effort-minutes)))
6064 (if (equal op ??)
6065 (not eff)
6066 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6067 value))))
6069 (defun org-agenda-filter-apply (filter)
6070 "Set FILTER as the new agenda filter and apply it."
6071 (let (tags)
6072 (setq org-agenda-filter filter
6073 org-agenda-filter-form (org-agenda-filter-make-matcher))
6074 (org-agenda-set-mode-name)
6075 (save-excursion
6076 (goto-char (point-min))
6077 (while (not (eobp))
6078 (if (org-get-at-bol 'org-marker)
6079 (progn
6080 (setq tags (org-get-at-bol 'tags)) ; used in eval
6081 (if (not (eval org-agenda-filter-form))
6082 (org-agenda-filter-by-tag-hide-line))
6083 (beginning-of-line 2))
6084 (beginning-of-line 2))))
6085 (if (get-char-property (point) 'invisible)
6086 (org-agenda-previous-line))))
6088 (defun org-agenda-filter-by-tag-hide-line ()
6089 (let (ov)
6090 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6091 (point-at-eol)))
6092 (overlay-put ov 'invisible t)
6093 (overlay-put ov 'type 'tags-filter)
6094 (push ov org-agenda-filter-overlays)))
6096 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6097 (setq pos (or pos (point)))
6098 (save-excursion
6099 (dolist (ov (overlays-at pos))
6100 (when (and (overlay-get ov 'invisible)
6101 (eq (overlay-get ov 'type) 'tags-filter))
6102 (goto-char pos)
6103 (if (< (overlay-start ov) (point-at-eol))
6104 (move-overlay ov (point-at-eol)
6105 (overlay-end ov)))))))
6107 (defun org-agenda-filter-by-tag-show-all ()
6108 (mapc 'delete-overlay org-agenda-filter-overlays)
6109 (setq org-agenda-filter-overlays nil)
6110 (setq org-agenda-filter nil)
6111 (setq org-agenda-filter-form nil)
6112 (org-agenda-set-mode-name))
6114 (defun org-agenda-manipulate-query-add ()
6115 "Manipulate the query by adding a search term with positive selection.
6116 Positive selection means the term must be matched for selection of an entry."
6117 (interactive)
6118 (org-agenda-manipulate-query ?\[))
6119 (defun org-agenda-manipulate-query-subtract ()
6120 "Manipulate the query by adding a search term with negative selection.
6121 Negative selection means term must not be matched for selection of an entry."
6122 (interactive)
6123 (org-agenda-manipulate-query ?\]))
6124 (defun org-agenda-manipulate-query-add-re ()
6125 "Manipulate the query by adding a search regexp with positive selection.
6126 Positive selection means the regexp must match for selection of an entry."
6127 (interactive)
6128 (org-agenda-manipulate-query ?\{))
6129 (defun org-agenda-manipulate-query-subtract-re ()
6130 "Manipulate the query by adding a search regexp with negative selection.
6131 Negative selection means regexp must not match for selection of an entry."
6132 (interactive)
6133 (org-agenda-manipulate-query ?\}))
6134 (defun org-agenda-manipulate-query (char)
6135 (cond
6136 ((memq org-agenda-type '(timeline agenda))
6137 (let ((org-agenda-include-inactive-timestamps t))
6138 (org-agenda-redo))
6139 (message "Display now includes inactive timestamps as well"))
6140 ((eq org-agenda-type 'search)
6141 (org-add-to-string
6142 'org-agenda-query-string
6143 (if org-agenda-last-search-view-search-was-boolean
6144 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6145 (?\{ . " +{}") (?\} . " -{}"))))
6146 " "))
6147 (setq org-agenda-redo-command
6148 (list 'org-search-view
6149 org-todo-only
6150 org-agenda-query-string
6151 (+ (length org-agenda-query-string)
6152 (if (member char '(?\{ ?\})) 0 1))))
6153 (set-register org-agenda-query-register org-agenda-query-string)
6154 (org-agenda-redo))
6155 (t (error "Cannot manipulate query for %s-type agenda buffers"
6156 org-agenda-type))))
6158 (defun org-add-to-string (var string)
6159 (set var (concat (symbol-value var) string)))
6161 (defun org-agenda-goto-date (date)
6162 "Jump to DATE in agenda."
6163 (interactive (list (let ((org-read-date-prefer-future
6164 (eval org-agenda-jump-prefer-future)))
6165 (org-read-date))))
6166 (org-agenda-list nil date))
6168 (defun org-agenda-goto-today ()
6169 "Go to today."
6170 (interactive)
6171 (org-agenda-check-type t 'timeline 'agenda)
6172 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6173 (cond
6174 (tdpos (goto-char tdpos))
6175 ((eq org-agenda-type 'agenda)
6176 (let* ((sd (org-agenda-compute-starting-span
6177 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6178 (org-agenda-overriding-arguments org-agenda-last-arguments))
6179 (setf (nth 1 org-agenda-overriding-arguments) sd)
6180 (org-agenda-redo)
6181 (org-agenda-find-same-or-today-or-agenda)))
6182 (t (error "Cannot find today")))))
6184 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6185 (goto-char
6186 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6187 (text-property-any (point-min) (point-max) 'org-today t)
6188 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6189 (point-min))))
6191 (defun org-agenda-later (arg)
6192 "Go forward in time by thee current span.
6193 With prefix ARG, go forward that many times the current span."
6194 (interactive "p")
6195 (org-agenda-check-type t 'agenda)
6196 (let* ((span org-agenda-current-span)
6197 (sd org-starting-day)
6198 (greg (calendar-gregorian-from-absolute sd))
6199 (cnt (org-get-at-bol 'org-day-cnt))
6200 greg2)
6201 (cond
6202 ((eq span 'day)
6203 (setq sd (+ arg sd)))
6204 ((eq span 'week)
6205 (setq sd (+ (* 7 arg) sd)))
6206 ((eq span 'month)
6207 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6208 sd (calendar-absolute-from-gregorian greg2))
6209 (setcar greg2 (1+ (car greg2))))
6210 ((eq span 'year)
6211 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6212 sd (calendar-absolute-from-gregorian greg2))
6213 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6215 (setq sd (+ (* span arg) sd))))
6216 (let ((org-agenda-overriding-arguments
6217 (list (car org-agenda-last-arguments) sd span t)))
6218 (org-agenda-redo)
6219 (org-agenda-find-same-or-today-or-agenda cnt))))
6221 (defun org-agenda-earlier (arg)
6222 "Go backward in time by the current span.
6223 With prefix ARG, go backward that many times the current span."
6224 (interactive "p")
6225 (org-agenda-later (- arg)))
6227 (defun org-agenda-view-mode-dispatch ()
6228 "Call one of the view mode commands."
6229 (interactive)
6230 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6231 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6232 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6233 (let ((a (read-char-exclusive)))
6234 (case a
6235 (?\ (call-interactively 'org-agenda-reset-view))
6236 (?d (call-interactively 'org-agenda-day-view))
6237 (?w (call-interactively 'org-agenda-week-view))
6238 (?m (call-interactively 'org-agenda-month-view))
6239 (?y (call-interactively 'org-agenda-year-view))
6240 (?l (call-interactively 'org-agenda-log-mode))
6241 (?L (org-agenda-log-mode '(4)))
6242 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6243 (?a (call-interactively 'org-agenda-archives-mode))
6244 (?A (org-agenda-archives-mode 'files))
6245 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6246 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6247 (?G (call-interactively 'org-agenda-toggle-time-grid))
6248 (?D (call-interactively 'org-agenda-toggle-diary))
6249 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6250 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6251 (org-agenda-check-type t 'timeline 'agenda)
6252 (org-agenda-redo))
6253 (message "Display now includes inactive timestamps as well"))
6254 (?q (message "Abort"))
6255 (otherwise (error "Invalid key" )))))
6257 (defun org-agenda-reset-view ()
6258 "Switch to default view for agenda."
6259 (interactive)
6260 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6261 (defun org-agenda-day-view (&optional day-of-year)
6262 "Switch to daily view for agenda.
6263 With argument DAY-OF-YEAR, switch to that day of the year."
6264 (interactive "P")
6265 (org-agenda-change-time-span 'day day-of-year))
6266 (defun org-agenda-week-view (&optional iso-week)
6267 "Switch to daily view for agenda.
6268 With argument ISO-WEEK, switch to the corresponding ISO week.
6269 If ISO-WEEK has more then 2 digits, only the last two encode the
6270 week. Any digits before this encode a year. So 200712 means
6271 week 12 of year 2007. Years in the range 1938-2037 can also be
6272 written as 2-digit years."
6273 (interactive "P")
6274 (org-agenda-change-time-span 'week iso-week))
6275 (defun org-agenda-month-view (&optional month)
6276 "Switch to monthly view for agenda.
6277 With argument MONTH, switch to that month."
6278 (interactive "P")
6279 (org-agenda-change-time-span 'month month))
6280 (defun org-agenda-year-view (&optional year)
6281 "Switch to yearly view for agenda.
6282 With argument YEAR, switch to that year.
6283 If MONTH has more then 2 digits, only the last two encode the
6284 month. Any digits before this encode a year. So 200712 means
6285 December year 2007. Years in the range 1938-2037 can also be
6286 written as 2-digit years."
6287 (interactive "P")
6288 (when year
6289 (setq year (org-small-year-to-year year)))
6290 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6291 (org-agenda-change-time-span 'year year)
6292 (error "Abort")))
6294 (defun org-agenda-change-time-span (span &optional n)
6295 "Change the agenda view to SPAN.
6296 SPAN may be `day', `week', `month', `year'."
6297 (org-agenda-check-type t 'agenda)
6298 (if (and (not n) (equal org-agenda-current-span span))
6299 (error "Viewing span is already \"%s\"" span))
6300 (let* ((sd (or (org-get-at-bol 'day)
6301 org-starting-day))
6302 (sd (org-agenda-compute-starting-span sd span n))
6303 (org-agenda-overriding-arguments
6304 (or org-agenda-overriding-arguments
6305 (list (car org-agenda-last-arguments) sd span t))))
6306 (org-agenda-redo)
6307 (org-agenda-find-same-or-today-or-agenda))
6308 (org-agenda-set-mode-name)
6309 (message "Switched to %s view" span))
6311 (defun org-agenda-compute-starting-span (sd span &optional n)
6312 "Compute starting date for agenda.
6313 SPAN may be `day', `week', `month', `year'. The return value
6314 is a cons cell with the starting date and the number of days,
6315 so that the date SD will be in that range."
6316 (let* ((greg (calendar-gregorian-from-absolute sd))
6317 (dg (nth 1 greg))
6318 (mg (car greg))
6319 (yg (nth 2 greg)))
6320 (cond
6321 ((eq span 'day)
6322 (when n
6323 (setq sd (+ (calendar-absolute-from-gregorian
6324 (list mg 1 yg))
6325 n -1))))
6326 ((eq span 'week)
6327 (let* ((nt (calendar-day-of-week
6328 (calendar-gregorian-from-absolute sd)))
6329 (d (if org-agenda-start-on-weekday
6330 (- nt org-agenda-start-on-weekday)
6333 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6334 (when n
6335 (require 'cal-iso)
6336 (when (> n 99)
6337 (setq y1 (org-small-year-to-year (/ n 100))
6338 n (mod n 100)))
6339 (setq sd
6340 (calendar-absolute-from-iso
6341 (list n 1
6342 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6343 ((eq span 'month)
6344 (let (y1)
6345 (when (and n (> n 99))
6346 (setq y1 (org-small-year-to-year (/ n 100))
6347 n (mod n 100)))
6348 (setq sd (calendar-absolute-from-gregorian
6349 (list (or n mg) 1 (or y1 yg))))))
6350 ((eq span 'year)
6351 (setq sd (calendar-absolute-from-gregorian
6352 (list 1 1 (or n yg))))))
6353 sd))
6355 (defun org-agenda-next-date-line (&optional arg)
6356 "Jump to the next line indicating a date in agenda buffer."
6357 (interactive "p")
6358 (org-agenda-check-type t 'agenda 'timeline)
6359 (beginning-of-line 1)
6360 ;; This does not work if user makes date format that starts with a blank
6361 (if (looking-at "^\\S-") (forward-char 1))
6362 (if (not (re-search-forward "^\\S-" nil t arg))
6363 (progn
6364 (backward-char 1)
6365 (error "No next date after this line in this buffer")))
6366 (goto-char (match-beginning 0)))
6368 (defun org-agenda-previous-date-line (&optional arg)
6369 "Jump to the previous line indicating a date in agenda buffer."
6370 (interactive "p")
6371 (org-agenda-check-type t 'agenda 'timeline)
6372 (beginning-of-line 1)
6373 (if (not (re-search-backward "^\\S-" nil t arg))
6374 (error "No previous date before this line in this buffer")))
6376 ;; Initialize the highlight
6377 (defvar org-hl (make-overlay 1 1))
6378 (overlay-put org-hl 'face 'highlight)
6380 (defun org-highlight (begin end &optional buffer)
6381 "Highlight a region with overlay."
6382 (move-overlay org-hl begin end (or buffer (current-buffer))))
6384 (defun org-unhighlight ()
6385 "Detach overlay INDEX."
6386 (org-detach-overlay org-hl))
6388 ;; FIXME this is currently not used.
6389 (defun org-highlight-until-next-command (beg end &optional buffer)
6390 "Move the highlight overlay to BEG/END, remove it before the next command."
6391 (org-highlight beg end buffer)
6392 (add-hook 'pre-command-hook 'org-unhighlight-once))
6393 (defun org-unhighlight-once ()
6394 "Remove the highlight from its position, and this function from the hook."
6395 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6396 (org-unhighlight))
6398 (defun org-agenda-follow-mode ()
6399 "Toggle follow mode in an agenda buffer."
6400 (interactive)
6401 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6402 (org-agenda-set-mode-name)
6403 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6404 (org-agenda-show))
6405 (message "Follow mode is %s"
6406 (if org-agenda-follow-mode "on" "off")))
6408 (defun org-agenda-entry-text-mode (&optional arg)
6409 "Toggle entry text mode in an agenda buffer."
6410 (interactive "P")
6411 (setq org-agenda-entry-text-mode (or (integerp arg)
6412 (not org-agenda-entry-text-mode)))
6413 (org-agenda-entry-text-hide)
6414 (and org-agenda-entry-text-mode
6415 (let ((org-agenda-entry-text-maxlines
6416 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6417 (org-agenda-entry-text-show)))
6418 (org-agenda-set-mode-name)
6419 (message "Entry text mode is %s. Maximum number of lines is %d"
6420 (if org-agenda-entry-text-mode "on" "off")
6421 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6423 (defun org-agenda-clockreport-mode (&optional with-filter)
6424 "Toggle clocktable mode in an agenda buffer.
6425 With prefix arg WITH-FILTER, make the clocktable respect the current
6426 agenda filter."
6427 (interactive "P")
6428 (org-agenda-check-type t 'agenda)
6429 (if with-filter
6430 (setq org-agenda-clockreport-mode 'with-filter)
6431 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6432 (org-agenda-set-mode-name)
6433 (org-agenda-redo)
6434 (message "Clocktable mode is %s"
6435 (if org-agenda-clockreport-mode "on" "off")))
6437 (defun org-agenda-log-mode (&optional special)
6438 "Toggle log mode in an agenda buffer.
6439 With argument SPECIAL, show all possible log items, not only the ones
6440 configured in `org-agenda-log-mode-items'.
6441 With a double `C-u' prefix arg, show *only* log items, nothing else."
6442 (interactive "P")
6443 (org-agenda-check-type t 'agenda 'timeline)
6444 (setq org-agenda-show-log
6445 (if (equal special '(16))
6446 'only
6447 (if special '(closed clock state)
6448 (not org-agenda-show-log))))
6449 (org-agenda-set-mode-name)
6450 (org-agenda-redo)
6451 (message "Log mode is %s"
6452 (if org-agenda-show-log "on" "off")))
6454 (defun org-agenda-archives-mode (&optional with-files)
6455 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6456 When called with a prefix argument, include all archive files as well."
6457 (interactive "P")
6458 (setq org-agenda-archives-mode
6459 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6460 (org-agenda-set-mode-name)
6461 (org-agenda-redo)
6462 (message
6463 "%s"
6464 (cond
6465 ((eq org-agenda-archives-mode nil)
6466 "No archives are included")
6467 ((eq org-agenda-archives-mode 'trees)
6468 (format "Trees with :%s: tag are included" org-archive-tag))
6469 ((eq org-agenda-archives-mode t)
6470 (format "Trees with :%s: tag and all active archive files are included"
6471 org-archive-tag)))))
6473 (defun org-agenda-toggle-diary ()
6474 "Toggle diary inclusion in an agenda buffer."
6475 (interactive)
6476 (org-agenda-check-type t 'agenda)
6477 (setq org-agenda-include-diary (not org-agenda-include-diary))
6478 (org-agenda-redo)
6479 (org-agenda-set-mode-name)
6480 (message "Diary inclusion turned %s"
6481 (if org-agenda-include-diary "on" "off")))
6483 (defun org-agenda-toggle-deadlines ()
6484 "Toggle inclusion of entries with a deadline in an agenda buffer."
6485 (interactive)
6486 (org-agenda-check-type t 'agenda)
6487 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6488 (org-agenda-redo)
6489 (org-agenda-set-mode-name)
6490 (message "Deadlines inclusion turned %s"
6491 (if org-agenda-include-deadlines "on" "off")))
6493 (defun org-agenda-toggle-time-grid ()
6494 "Toggle time grid in an agenda buffer."
6495 (interactive)
6496 (org-agenda-check-type t 'agenda)
6497 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6498 (org-agenda-redo)
6499 (org-agenda-set-mode-name)
6500 (message "Time-grid turned %s"
6501 (if org-agenda-use-time-grid "on" "off")))
6503 (defun org-agenda-set-mode-name ()
6504 "Set the mode name to indicate all the small mode settings."
6505 (setq mode-name
6506 (list "Org-Agenda"
6507 (if (get 'org-agenda-files 'org-restrict) " []" "")
6509 '(:eval (org-agenda-span-name org-agenda-current-span))
6510 (if org-agenda-follow-mode " Follow" "")
6511 (if org-agenda-entry-text-mode " ETxt" "")
6512 (if org-agenda-include-diary " Diary" "")
6513 (if org-agenda-include-deadlines " Ddl" "")
6514 (if org-agenda-use-time-grid " Grid" "")
6515 (if (and (boundp 'org-habit-show-habits)
6516 org-habit-show-habits) " Habit" "")
6517 (if (consp org-agenda-show-log) " LogAll"
6518 (if org-agenda-show-log " Log" ""))
6519 (if (or org-agenda-filter (get 'org-agenda-filter
6520 :preset-filter))
6521 (concat " {" (mapconcat
6522 'identity
6523 (append (get 'org-agenda-filter
6524 :preset-filter)
6525 org-agenda-filter) "") "}")
6527 (if org-agenda-archives-mode
6528 (if (eq org-agenda-archives-mode t)
6529 " Archives"
6530 (format " :%s:" org-archive-tag))
6532 (if org-agenda-clockreport-mode
6533 (if (eq org-agenda-clockreport-mode 'with-filter)
6534 " Clock{}" " Clock")
6535 "")))
6536 (force-mode-line-update))
6538 (defun org-agenda-post-command-hook ()
6539 (setq org-agenda-type
6540 (or (get-text-property (point) 'org-agenda-type)
6541 (get-text-property (max (point-min) (1- (point)))
6542 'org-agenda-type))))
6544 (defun org-agenda-next-line ()
6545 "Move cursor to the next line, and show if follow mode is active."
6546 (interactive)
6547 (call-interactively 'next-line)
6548 (org-agenda-do-context-action))
6550 (defun org-agenda-previous-line ()
6551 "Move cursor to the previous line, and show if follow-mode is active."
6552 (interactive)
6553 (call-interactively 'previous-line)
6554 (org-agenda-do-context-action))
6556 (defun org-agenda-do-context-action ()
6557 "Show outline path and, maybe, follow mode window."
6558 (let ((m (org-get-at-bol 'org-marker)))
6559 (if (and org-agenda-follow-mode m)
6560 (org-agenda-show))
6561 (if (and m org-agenda-show-outline-path)
6562 (org-with-point-at m
6563 (org-display-outline-path t)))))
6565 (defun org-agenda-show-priority ()
6566 "Show the priority of the current item.
6567 This priority is composed of the main priority given with the [#A] cookies,
6568 and by additional input from the age of a schedules or deadline entry."
6569 (interactive)
6570 (let* ((pri (org-get-at-bol 'priority)))
6571 (message "Priority is %d" (if pri pri -1000))))
6573 (defun org-agenda-show-tags ()
6574 "Show the tags applicable to the current item."
6575 (interactive)
6576 (let* ((tags (org-get-at-bol 'tags)))
6577 (if tags
6578 (message "Tags are :%s:"
6579 (org-no-properties (mapconcat 'identity tags ":")))
6580 (message "No tags associated with this line"))))
6582 (defun org-agenda-goto (&optional highlight)
6583 "Go to the Org-mode file which contains the item at point."
6584 (interactive)
6585 (let* ((marker (or (org-get-at-bol 'org-marker)
6586 (org-agenda-error)))
6587 (buffer (marker-buffer marker))
6588 (pos (marker-position marker)))
6589 (switch-to-buffer-other-window buffer)
6590 (widen)
6591 (push-mark)
6592 (goto-char pos)
6593 (when (org-mode-p)
6594 (org-show-context 'agenda)
6595 (save-excursion
6596 (and (outline-next-heading)
6597 (org-flag-heading nil)))) ; show the next heading
6598 (when (outline-invisible-p)
6599 (show-entry)) ; display invisible text
6600 (recenter (/ (window-height) 2))
6601 (run-hooks 'org-agenda-after-show-hook)
6602 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6604 (defvar org-agenda-after-show-hook nil
6605 "Normal hook run after an item has been shown from the agenda.
6606 Point is in the buffer where the item originated.")
6608 (defun org-agenda-kill ()
6609 "Kill the entry or subtree belonging to the current agenda entry."
6610 (interactive)
6611 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6612 (let* ((marker (or (org-get-at-bol 'org-marker)
6613 (org-agenda-error)))
6614 (buffer (marker-buffer marker))
6615 (pos (marker-position marker))
6616 (type (org-get-at-bol 'type))
6617 dbeg dend (n 0) conf)
6618 (org-with-remote-undo buffer
6619 (with-current-buffer buffer
6620 (save-excursion
6621 (goto-char pos)
6622 (if (and (org-mode-p) (not (member type '("sexp"))))
6623 (setq dbeg (progn (org-back-to-heading t) (point))
6624 dend (org-end-of-subtree t t))
6625 (setq dbeg (point-at-bol)
6626 dend (min (point-max) (1+ (point-at-eol)))))
6627 (goto-char dbeg)
6628 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6629 (setq conf (or (eq t org-agenda-confirm-kill)
6630 (and (numberp org-agenda-confirm-kill)
6631 (> n org-agenda-confirm-kill))))
6632 (and conf
6633 (not (y-or-n-p
6634 (format "Delete entry with %d lines in buffer \"%s\"? "
6635 n (buffer-name buffer))))
6636 (error "Abort"))
6637 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6638 (with-current-buffer buffer (delete-region dbeg dend))
6639 (message "Agenda item and source killed"))))
6641 (defvar org-archive-default-command)
6642 (defun org-agenda-archive-default ()
6643 "Archive the entry or subtree belonging to the current agenda entry."
6644 (interactive)
6645 (require 'org-archive)
6646 (org-agenda-archive-with org-archive-default-command))
6648 (defun org-agenda-archive-default-with-confirmation ()
6649 "Archive the entry or subtree belonging to the current agenda entry."
6650 (interactive)
6651 (require 'org-archive)
6652 (org-agenda-archive-with org-archive-default-command 'confirm))
6654 (defun org-agenda-archive ()
6655 "Archive the entry or subtree belonging to the current agenda entry."
6656 (interactive)
6657 (org-agenda-archive-with 'org-archive-subtree))
6659 (defun org-agenda-archive-to-archive-sibling ()
6660 "Move the entry to the archive sibling."
6661 (interactive)
6662 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6664 (defun org-agenda-archive-with (cmd &optional confirm)
6665 "Move the entry to the archive sibling."
6666 (interactive)
6667 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6668 (let* ((marker (or (org-get-at-bol 'org-marker)
6669 (org-agenda-error)))
6670 (buffer (marker-buffer marker))
6671 (pos (marker-position marker)))
6672 (org-with-remote-undo buffer
6673 (with-current-buffer buffer
6674 (if (org-mode-p)
6675 (if (and confirm
6676 (not (y-or-n-p "Archive this subtree or entry? ")))
6677 (error "Abort")
6678 (save-excursion
6679 (goto-char pos)
6680 (org-remove-subtree-entries-from-agenda)
6681 (org-back-to-heading t)
6682 (funcall cmd)))
6683 (error "Archiving works only in Org-mode files"))))))
6685 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6686 "Remove all lines in the agenda that correspond to a given subtree.
6687 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6688 If this information is not given, the function uses the tree at point."
6689 (let ((buf (or buf (current-buffer))) m p)
6690 (save-excursion
6691 (unless (and beg end)
6692 (org-back-to-heading t)
6693 (setq beg (point))
6694 (org-end-of-subtree t)
6695 (setq end (point)))
6696 (set-buffer (get-buffer org-agenda-buffer-name))
6697 (save-excursion
6698 (goto-char (point-max))
6699 (beginning-of-line 1)
6700 (while (not (bobp))
6701 (when (and (setq m (org-get-at-bol 'org-marker))
6702 (equal buf (marker-buffer m))
6703 (setq p (marker-position m))
6704 (>= p beg)
6705 (< p end))
6706 (let ((inhibit-read-only t))
6707 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6708 (beginning-of-line 0))))))
6710 (defun org-agenda-refile (&optional goto rfloc no-update)
6711 "Refile the item at point."
6712 (interactive "P")
6713 (if (equal goto '(16))
6714 (org-refile-goto-last-stored)
6715 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6716 (org-agenda-error)))
6717 (buffer (marker-buffer marker))
6718 (pos (marker-position marker))
6719 (rfloc (or rfloc
6720 (org-refile-get-location
6721 (if goto "Goto" "Refile to") buffer
6722 org-refile-allow-creating-parent-nodes))))
6723 (with-current-buffer buffer
6724 (save-excursion
6725 (save-restriction
6726 (widen)
6727 (goto-char marker)
6728 (org-remove-subtree-entries-from-agenda)
6729 (org-refile goto buffer rfloc)))))
6730 (unless no-update (org-agenda-redo))))
6732 (defun org-agenda-open-link (&optional arg)
6733 "Follow the link in the current line, if any.
6734 This looks for a link in the displayed line in the agenda. It also looks
6735 at the text of the entry itself."
6736 (interactive "P")
6737 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6738 (org-get-at-bol 'org-marker)))
6739 (buffer (and marker (marker-buffer marker)))
6740 (prefix (buffer-substring
6741 (point-at-bol)
6742 (+ (point-at-bol)
6743 (or (org-get-at-bol 'prefix-length) 0)))))
6744 (cond
6745 (buffer
6746 (with-current-buffer buffer
6747 (save-excursion
6748 (save-restriction
6749 (widen)
6750 (goto-char marker)
6751 (org-offer-links-in-entry arg prefix)))))
6752 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6753 (save-excursion
6754 (beginning-of-line 1)
6755 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6756 (org-open-link-from-string (match-string 1)))
6757 (t (error "No link to open here")))))
6759 (defun org-agenda-copy-local-variable (var)
6760 "Get a variable from a referenced buffer and install it here."
6761 (let ((m (org-get-at-bol 'org-marker)))
6762 (when (and m (buffer-live-p (marker-buffer m)))
6763 (org-set-local var (with-current-buffer (marker-buffer m)
6764 (symbol-value var))))))
6766 (defun org-agenda-switch-to (&optional delete-other-windows)
6767 "Go to the Org-mode file which contains the item at point."
6768 (interactive)
6769 (if (and org-return-follows-link
6770 (not (org-get-at-bol 'org-marker))
6771 (org-in-regexp org-bracket-link-regexp))
6772 (org-open-link-from-string (match-string 0))
6773 (let* ((marker (or (org-get-at-bol 'org-marker)
6774 (org-agenda-error)))
6775 (buffer (marker-buffer marker))
6776 (pos (marker-position marker)))
6777 (switch-to-buffer buffer)
6778 (and delete-other-windows (delete-other-windows))
6779 (widen)
6780 (goto-char pos)
6781 (when (org-mode-p)
6782 (org-show-context 'agenda)
6783 (save-excursion
6784 (and (outline-next-heading)
6785 (org-flag-heading nil))) ; show the next heading
6786 (when (outline-invisible-p)
6787 (show-entry)))))) ; display invisible text
6789 (defun org-agenda-goto-mouse (ev)
6790 "Go to the Org-mode file which contains the item at the mouse click."
6791 (interactive "e")
6792 (mouse-set-point ev)
6793 (org-agenda-goto))
6795 (defun org-agenda-show (&optional full-entry)
6796 "Display the Org-mode file which contains the item at point.
6797 With prefix argument FULL-ENTRY, make the entire entry visible
6798 if it was hidden in the outline."
6799 (interactive "P")
6800 (let ((win (selected-window)))
6801 (if full-entry
6802 (let ((org-show-entry-below t))
6803 (org-agenda-goto t))
6804 (org-agenda-goto t))
6805 (select-window win)))
6807 (defvar org-agenda-show-window nil)
6808 (defun org-agenda-show-and-scroll-up ()
6809 "Display the Org-mode file which contains the item at point.
6810 When called repeatedly, scroll the window that is displaying the buffer."
6811 (interactive)
6812 (let ((win (selected-window)))
6813 (if (and (window-live-p org-agenda-show-window)
6814 (eq this-command last-command))
6815 (progn
6816 (select-window org-agenda-show-window)
6817 (ignore-errors (scroll-up)))
6818 (org-agenda-goto t)
6819 (show-subtree)
6820 (setq org-agenda-show-window (selected-window)))
6821 (select-window win)))
6823 (defun org-agenda-show-scroll-down ()
6824 "Scroll down the window showing the agenda."
6825 (interactive)
6826 (let ((win (selected-window)))
6827 (when (window-live-p org-agenda-show-window)
6828 (select-window org-agenda-show-window)
6829 (ignore-errors (scroll-down))
6830 (select-window win))))
6832 (defun org-agenda-show-1 (&optional more)
6833 "Display the Org-mode file which contains the item at point.
6834 The prefix arg selects the amount of information to display:
6836 0 hide the subtree
6837 1 just show the entry according to defaults.
6838 2 show the children view
6839 3 show the subtree view
6840 4 show the entire subtree and any LOGBOOK drawers
6841 5 show the entire subtree and any drawers
6842 With prefix argument FULL-ENTRY, make the entire entry visible
6843 if it was hidden in the outline."
6844 (interactive "p")
6845 (let ((win (selected-window)))
6846 (org-agenda-goto t)
6847 (org-recenter-heading 1)
6848 (cond
6849 ((= more 0)
6850 (hide-subtree)
6851 (save-excursion
6852 (org-back-to-heading)
6853 (run-hook-with-args 'org-cycle-hook 'folded))
6854 (message "Remote: FOLDED"))
6855 ((and (interactive-p) (= more 1))
6856 (message "Remote: show with default settings"))
6857 ((= more 2)
6858 (show-entry)
6859 (show-children)
6860 (save-excursion
6861 (org-back-to-heading)
6862 (run-hook-with-args 'org-cycle-hook 'children))
6863 (message "Remote: CHILDREN"))
6864 ((= more 3)
6865 (show-subtree)
6866 (save-excursion
6867 (org-back-to-heading)
6868 (run-hook-with-args 'org-cycle-hook 'subtree))
6869 (message "Remote: SUBTREE"))
6870 ((= more 4)
6871 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6872 (org-drawer-regexp
6873 (concat "^[ \t]*:\\("
6874 (mapconcat 'regexp-quote org-drawers "\\|")
6875 "\\):[ \t]*$")))
6876 (show-subtree)
6877 (save-excursion
6878 (org-back-to-heading)
6879 (org-cycle-hide-drawers 'subtree)))
6880 (message "Remote: SUBTREE AND LOGBOOK"))
6881 ((> more 4)
6882 (show-subtree)
6883 (message "Remote: SUBTREE AND ALL DRAWERS")))
6884 (select-window win)))
6886 (defun org-recenter-heading (n)
6887 (save-excursion
6888 (org-back-to-heading)
6889 (recenter n)))
6891 (defvar org-agenda-cycle-counter nil)
6892 (defun org-agenda-cycle-show (&optional n)
6893 "Show the current entry in another window, with default settings.
6894 Default settings are taken from `org-show-hierarchy-above' and siblings.
6895 When use repeatedly in immediate succession, the remote entry will cycle
6896 through visibility
6898 children -> subtree -> folded
6900 When called with a numeric prefix arg, that arg will be passed through to
6901 `org-agenda-show-1'. For the interpretation of that argument, see the
6902 docstring of `org-agenda-show-1'."
6903 (interactive "P")
6904 (if (integerp n)
6905 (setq org-agenda-cycle-counter n)
6906 (if (not (eq last-command this-command))
6907 (setq org-agenda-cycle-counter 1)
6908 (if (equal org-agenda-cycle-counter 0)
6909 (setq org-agenda-cycle-counter 2)
6910 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6911 (if (> org-agenda-cycle-counter 3)
6912 (setq org-agenda-cycle-counter 0)))))
6913 (org-agenda-show-1 org-agenda-cycle-counter))
6915 (defun org-agenda-recenter (arg)
6916 "Display the Org-mode file which contains the item at point and recenter."
6917 (interactive "P")
6918 (let ((win (selected-window)))
6919 (org-agenda-goto t)
6920 (recenter arg)
6921 (select-window win)))
6923 (defun org-agenda-show-mouse (ev)
6924 "Display the Org-mode file which contains the item at the mouse click."
6925 (interactive "e")
6926 (mouse-set-point ev)
6927 (org-agenda-show))
6929 (defun org-agenda-check-no-diary ()
6930 "Check if the entry is a diary link and abort if yes."
6931 (if (org-get-at-bol 'org-agenda-diary-link)
6932 (org-agenda-error)))
6934 (defun org-agenda-error ()
6935 (error "Command not allowed in this line"))
6937 (defun org-agenda-tree-to-indirect-buffer ()
6938 "Show the subtree corresponding to the current entry in an indirect buffer.
6939 This calls the command `org-tree-to-indirect-buffer' from the original
6940 Org-mode buffer.
6941 With numerical prefix arg ARG, go up to this level and then take that tree.
6942 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6943 use the dedicated frame)."
6944 (interactive)
6945 (org-agenda-check-no-diary)
6946 (let* ((marker (or (org-get-at-bol 'org-marker)
6947 (org-agenda-error)))
6948 (buffer (marker-buffer marker))
6949 (pos (marker-position marker)))
6950 (with-current-buffer buffer
6951 (save-excursion
6952 (goto-char pos)
6953 (call-interactively 'org-tree-to-indirect-buffer)))))
6955 (defvar org-last-heading-marker (make-marker)
6956 "Marker pointing to the headline that last changed its TODO state
6957 by a remote command from the agenda.")
6959 (defun org-agenda-todo-nextset ()
6960 "Switch TODO entry to next sequence."
6961 (interactive)
6962 (org-agenda-todo 'nextset))
6964 (defun org-agenda-todo-previousset ()
6965 "Switch TODO entry to previous sequence."
6966 (interactive)
6967 (org-agenda-todo 'previousset))
6969 (defun org-agenda-todo (&optional arg)
6970 "Cycle TODO state of line at point, also in Org-mode file.
6971 This changes the line at point, all other lines in the agenda referring to
6972 the same tree node, and the headline of the tree node in the Org-mode file."
6973 (interactive "P")
6974 (org-agenda-check-no-diary)
6975 (let* ((col (current-column))
6976 (marker (or (org-get-at-bol 'org-marker)
6977 (org-agenda-error)))
6978 (buffer (marker-buffer marker))
6979 (pos (marker-position marker))
6980 (hdmarker (org-get-at-bol 'org-hd-marker))
6981 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6982 (inhibit-read-only t)
6983 org-agenda-headline-snapshot-before-repeat newhead just-one)
6984 (org-with-remote-undo buffer
6985 (with-current-buffer buffer
6986 (widen)
6987 (goto-char pos)
6988 (org-show-context 'agenda)
6989 (save-excursion
6990 (and (outline-next-heading)
6991 (org-flag-heading nil))) ; show the next heading
6992 (let ((current-prefix-arg arg))
6993 (call-interactively 'org-todo))
6994 (and (bolp) (forward-char 1))
6995 (setq newhead (org-get-heading))
6996 (when (and (org-bound-and-true-p
6997 org-agenda-headline-snapshot-before-repeat)
6998 (not (equal org-agenda-headline-snapshot-before-repeat
6999 newhead))
7000 todayp)
7001 (setq newhead org-agenda-headline-snapshot-before-repeat
7002 just-one t))
7003 (save-excursion
7004 (org-back-to-heading)
7005 (move-marker org-last-heading-marker (point))))
7006 (beginning-of-line 1)
7007 (save-excursion
7008 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7009 (org-move-to-column col))))
7011 (defun org-agenda-add-note (&optional arg)
7012 "Add a time-stamped note to the entry at point."
7013 (interactive "P")
7014 (org-agenda-check-no-diary)
7015 (let* ((marker (or (org-get-at-bol 'org-marker)
7016 (org-agenda-error)))
7017 (buffer (marker-buffer marker))
7018 (pos (marker-position marker))
7019 (hdmarker (org-get-at-bol 'org-hd-marker))
7020 (inhibit-read-only t))
7021 (with-current-buffer buffer
7022 (widen)
7023 (goto-char pos)
7024 (org-show-context 'agenda)
7025 (save-excursion
7026 (and (outline-next-heading)
7027 (org-flag-heading nil))) ; show the next heading
7028 (org-add-note))))
7030 (defun org-agenda-change-all-lines (newhead hdmarker
7031 &optional fixface just-this)
7032 "Change all lines in the agenda buffer which match HDMARKER.
7033 The new content of the line will be NEWHEAD (as modified by
7034 `org-format-agenda-item'). HDMARKER is checked with
7035 `equal' against all `org-hd-marker' text properties in the file.
7036 If FIXFACE is non-nil, the face of each item is modified according to
7037 the new TODO state.
7038 If JUST-THIS is non-nil, change just the current line, not all.
7039 If FORCE-TAGS is non nil, the car of it returns the new tags."
7040 (let* ((inhibit-read-only t)
7041 (line (org-current-line))
7042 (thetags (with-current-buffer (marker-buffer hdmarker)
7043 (save-excursion (save-restriction (widen)
7044 (goto-char hdmarker)
7045 (org-get-tags-at)))))
7046 props m pl undone-face done-face finish new dotime cat tags)
7047 (save-excursion
7048 (goto-char (point-max))
7049 (beginning-of-line 1)
7050 (while (not finish)
7051 (setq finish (bobp))
7052 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7053 (or (not just-this) (= (org-current-line) line))
7054 (equal m hdmarker))
7055 (setq props (text-properties-at (point))
7056 dotime (org-get-at-bol 'dotime)
7057 cat (org-get-at-bol 'org-category)
7058 tags thetags
7059 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
7060 pl (org-get-at-bol 'prefix-length)
7061 undone-face (org-get-at-bol 'undone-face)
7062 done-face (org-get-at-bol 'done-face))
7063 (goto-char (+ (point) pl))
7064 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
7065 (cond
7066 ((equal new "")
7067 (beginning-of-line 1)
7068 (and (looking-at ".*\n?") (replace-match "")))
7069 ((looking-at ".*")
7070 (replace-match new t t)
7071 (beginning-of-line 1)
7072 (add-text-properties (point-at-bol) (point-at-eol) props)
7073 (when fixface
7074 (add-text-properties
7075 (point-at-bol) (point-at-eol)
7076 (list 'face
7077 (if org-last-todo-state-is-todo
7078 undone-face done-face))))
7079 (org-agenda-highlight-todo 'line)
7080 (beginning-of-line 1))
7081 (t (error "Line update did not work"))))
7082 (beginning-of-line 0)))
7083 (org-finalize-agenda)))
7085 (defun org-agenda-align-tags (&optional line)
7086 "Align all tags in agenda items to `org-agenda-tags-column'."
7087 (let ((inhibit-read-only t) l c)
7088 (save-excursion
7089 (goto-char (if line (point-at-bol) (point-min)))
7090 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7091 (if line (point-at-eol) nil) t)
7092 (add-text-properties
7093 (match-beginning 2) (match-end 2)
7094 (list 'face (delq nil (let ((prop (get-text-property
7095 (match-beginning 2) 'face)))
7096 (or (listp prop) (setq prop (list prop)))
7097 (if (memq 'org-tag prop)
7098 prop
7099 (cons 'org-tag prop))))))
7100 (setq l (- (match-end 2) (match-beginning 2))
7101 c (if (< org-agenda-tags-column 0)
7102 (- (abs org-agenda-tags-column) l)
7103 org-agenda-tags-column))
7104 (delete-region (match-beginning 1) (match-end 1))
7105 (goto-char (match-beginning 1))
7106 (insert (org-add-props
7107 (make-string (max 1 (- c (current-column))) ?\ )
7108 (plist-put (copy-sequence (text-properties-at (point)))
7109 'face nil))))
7110 (goto-char (point-min))
7111 (org-font-lock-add-tag-faces (point-max)))))
7113 (defun org-agenda-priority-up ()
7114 "Increase the priority of line at point, also in Org-mode file."
7115 (interactive)
7116 (org-agenda-priority 'up))
7118 (defun org-agenda-priority-down ()
7119 "Decrease the priority of line at point, also in Org-mode file."
7120 (interactive)
7121 (org-agenda-priority 'down))
7123 (defun org-agenda-priority (&optional force-direction)
7124 "Set the priority of line at point, also in Org-mode file.
7125 This changes the line at point, all other lines in the agenda referring to
7126 the same tree node, and the headline of the tree node in the Org-mode file."
7127 (interactive)
7128 (unless org-enable-priority-commands
7129 (error "Priority commands are disabled"))
7130 (org-agenda-check-no-diary)
7131 (let* ((marker (or (org-get-at-bol 'org-marker)
7132 (org-agenda-error)))
7133 (hdmarker (org-get-at-bol 'org-hd-marker))
7134 (buffer (marker-buffer hdmarker))
7135 (pos (marker-position hdmarker))
7136 (inhibit-read-only t)
7137 newhead)
7138 (org-with-remote-undo buffer
7139 (with-current-buffer buffer
7140 (widen)
7141 (goto-char pos)
7142 (org-show-context 'agenda)
7143 (save-excursion
7144 (and (outline-next-heading)
7145 (org-flag-heading nil))) ; show the next heading
7146 (funcall 'org-priority force-direction)
7147 (end-of-line 1)
7148 (setq newhead (org-get-heading)))
7149 (org-agenda-change-all-lines newhead hdmarker)
7150 (beginning-of-line 1))))
7152 ;; FIXME: should fix the tags property of the agenda line.
7153 (defun org-agenda-set-tags (&optional tag onoff)
7154 "Set tags for the current headline."
7155 (interactive)
7156 (org-agenda-check-no-diary)
7157 (if (and (org-region-active-p) (interactive-p))
7158 (call-interactively 'org-change-tag-in-region)
7159 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7160 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7161 (org-agenda-error)))
7162 (buffer (marker-buffer hdmarker))
7163 (pos (marker-position hdmarker))
7164 (inhibit-read-only t)
7165 newhead)
7166 (org-with-remote-undo buffer
7167 (with-current-buffer buffer
7168 (widen)
7169 (goto-char pos)
7170 (save-excursion
7171 (org-show-context 'agenda))
7172 (save-excursion
7173 (and (outline-next-heading)
7174 (org-flag-heading nil))) ; show the next heading
7175 (goto-char pos)
7176 (if tag
7177 (org-toggle-tag tag onoff)
7178 (call-interactively 'org-set-tags))
7179 (end-of-line 1)
7180 (setq newhead (org-get-heading)))
7181 (org-agenda-change-all-lines newhead hdmarker)
7182 (beginning-of-line 1)))))
7184 (defun org-agenda-set-property ()
7185 "Set a property for the current headline."
7186 (interactive)
7187 (org-agenda-check-no-diary)
7188 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7189 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7190 (org-agenda-error)))
7191 (buffer (marker-buffer hdmarker))
7192 (pos (marker-position hdmarker))
7193 (inhibit-read-only t)
7194 newhead)
7195 (org-with-remote-undo buffer
7196 (with-current-buffer buffer
7197 (widen)
7198 (goto-char pos)
7199 (save-excursion
7200 (org-show-context 'agenda))
7201 (save-excursion
7202 (and (outline-next-heading)
7203 (org-flag-heading nil))) ; show the next heading
7204 (goto-char pos)
7205 (call-interactively 'org-set-property)))))
7207 (defun org-agenda-set-effort ()
7208 "Set the effort property for the current headline."
7209 (interactive)
7210 (org-agenda-check-no-diary)
7211 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7212 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7213 (org-agenda-error)))
7214 (buffer (marker-buffer hdmarker))
7215 (pos (marker-position hdmarker))
7216 (inhibit-read-only t)
7217 newhead)
7218 (org-with-remote-undo buffer
7219 (with-current-buffer buffer
7220 (widen)
7221 (goto-char pos)
7222 (save-excursion
7223 (org-show-context 'agenda))
7224 (save-excursion
7225 (and (outline-next-heading)
7226 (org-flag-heading nil))) ; show the next heading
7227 (goto-char pos)
7228 (call-interactively 'org-set-effort)
7229 (end-of-line 1)))))
7231 (defun org-agenda-toggle-archive-tag ()
7232 "Toggle the archive tag for the current entry."
7233 (interactive)
7234 (org-agenda-check-no-diary)
7235 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7236 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7237 (org-agenda-error)))
7238 (buffer (marker-buffer hdmarker))
7239 (pos (marker-position hdmarker))
7240 (inhibit-read-only t)
7241 newhead)
7242 (org-with-remote-undo buffer
7243 (with-current-buffer buffer
7244 (widen)
7245 (goto-char pos)
7246 (org-show-context 'agenda)
7247 (save-excursion
7248 (and (outline-next-heading)
7249 (org-flag-heading nil))) ; show the next heading
7250 (call-interactively 'org-toggle-archive-tag)
7251 (end-of-line 1)
7252 (setq newhead (org-get-heading)))
7253 (org-agenda-change-all-lines newhead hdmarker)
7254 (beginning-of-line 1))))
7256 (defun org-agenda-do-date-later (arg)
7257 (interactive "P")
7258 (cond
7259 ((or (equal arg '(16))
7260 (memq last-command
7261 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7262 (setq this-command 'org-agenda-date-later-minutes)
7263 (org-agenda-date-later-minutes 1))
7264 ((or (equal arg '(4))
7265 (memq last-command
7266 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7267 (setq this-command 'org-agenda-date-later-hours)
7268 (org-agenda-date-later-hours 1))
7270 (org-agenda-date-later (prefix-numeric-value arg)))))
7272 (defun org-agenda-do-date-earlier (arg)
7273 (interactive "P")
7274 (cond
7275 ((or (equal arg '(16))
7276 (memq last-command
7277 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7278 (setq this-command 'org-agenda-date-earlier-minutes)
7279 (org-agenda-date-earlier-minutes 1))
7280 ((or (equal arg '(4))
7281 (memq last-command
7282 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7283 (setq this-command 'org-agenda-date-earlier-hours)
7284 (org-agenda-date-earlier-hours 1))
7286 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7288 (defun org-agenda-date-later (arg &optional what)
7289 "Change the date of this item to ARG day(s) later."
7290 (interactive "p")
7291 (org-agenda-check-type t 'agenda 'timeline)
7292 (org-agenda-check-no-diary)
7293 (let* ((marker (or (org-get-at-bol 'org-marker)
7294 (org-agenda-error)))
7295 (buffer (marker-buffer marker))
7296 (pos (marker-position marker)))
7297 (org-with-remote-undo buffer
7298 (with-current-buffer buffer
7299 (widen)
7300 (goto-char pos)
7301 (if (not (org-at-timestamp-p))
7302 (error "Cannot find time stamp"))
7303 (org-timestamp-change arg (or what 'day)))
7304 (org-agenda-show-new-time marker org-last-changed-timestamp))
7305 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7307 (defun org-agenda-date-earlier (arg &optional what)
7308 "Change the date of this item to ARG day(s) earlier."
7309 (interactive "p")
7310 (org-agenda-date-later (- arg) what))
7312 (defun org-agenda-date-later-minutes (arg)
7313 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7314 (interactive "p")
7315 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7316 (org-agenda-date-later arg 'minute))
7318 (defun org-agenda-date-earlier-minutes (arg)
7319 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7320 (interactive "p")
7321 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7322 (org-agenda-date-earlier arg 'minute))
7324 (defun org-agenda-date-later-hours (arg)
7325 "Change the time of this item, in hour steps."
7326 (interactive "p")
7327 (org-agenda-date-later arg 'hour))
7329 (defun org-agenda-date-earlier-hours (arg)
7330 "Change the time of this item, in hour steps."
7331 (interactive "p")
7332 (org-agenda-date-earlier arg 'hour))
7334 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7335 "Show new date stamp via text properties."
7336 ;; We use text properties to make this undoable
7337 (let ((inhibit-read-only t)
7338 (buffer-invisibility-spec))
7339 (setq stamp (concat " " prefix " => " stamp))
7340 (save-excursion
7341 (goto-char (point-max))
7342 (while (not (bobp))
7343 (when (equal marker (org-get-at-bol 'org-marker))
7344 (org-move-to-column (- (window-width) (length stamp)) t)
7345 (org-agenda-fix-tags-filter-overlays-at (point))
7346 (if (featurep 'xemacs)
7347 ;; Use `duplicable' property to trigger undo recording
7348 (let ((ex (make-extent nil nil))
7349 (gl (make-glyph stamp)))
7350 (set-glyph-face gl 'secondary-selection)
7351 (set-extent-properties
7352 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7353 (insert-extent ex (1- (point)) (point-at-eol)))
7354 (add-text-properties
7355 (1- (point)) (point-at-eol)
7356 (list 'display (org-add-props stamp nil
7357 'face 'secondary-selection))))
7358 (beginning-of-line 1))
7359 (beginning-of-line 0)))))
7361 (defun org-agenda-date-prompt (arg)
7362 "Change the date of this item. Date is prompted for, with default today.
7363 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7364 be used to request time specification in the time stamp."
7365 (interactive "P")
7366 (org-agenda-check-type t 'agenda 'timeline)
7367 (org-agenda-check-no-diary)
7368 (let* ((marker (or (org-get-at-bol 'org-marker)
7369 (org-agenda-error)))
7370 (buffer (marker-buffer marker))
7371 (pos (marker-position marker)))
7372 (org-with-remote-undo buffer
7373 (with-current-buffer buffer
7374 (widen)
7375 (goto-char pos)
7376 (if (not (org-at-timestamp-p t))
7377 (error "Cannot find time stamp"))
7378 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7379 (org-agenda-show-new-time marker org-last-changed-timestamp))
7380 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7382 (defun org-agenda-schedule (arg &optional time)
7383 "Schedule the item at point.
7384 Arg is passed through to `org-schedule'."
7385 (interactive "P")
7386 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7387 (org-agenda-check-no-diary)
7388 (let* ((marker (or (org-get-at-bol 'org-marker)
7389 (org-agenda-error)))
7390 (type (marker-insertion-type marker))
7391 (buffer (marker-buffer marker))
7392 (pos (marker-position marker))
7393 (org-insert-labeled-timestamps-at-point nil)
7395 (set-marker-insertion-type marker t)
7396 (org-with-remote-undo buffer
7397 (with-current-buffer buffer
7398 (widen)
7399 (goto-char pos)
7400 (setq ts (org-schedule arg time)))
7401 (org-agenda-show-new-time marker ts "S"))
7402 (message "Item scheduled for %s" ts)))
7404 (defun org-agenda-deadline (arg &optional time)
7405 "Schedule the item at point.
7406 Arg is passed through to `org-deadline'."
7407 (interactive "P")
7408 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7409 (org-agenda-check-no-diary)
7410 (let* ((marker (or (org-get-at-bol 'org-marker)
7411 (org-agenda-error)))
7412 (buffer (marker-buffer marker))
7413 (pos (marker-position marker))
7414 (org-insert-labeled-timestamps-at-point nil)
7416 (org-with-remote-undo buffer
7417 (with-current-buffer buffer
7418 (widen)
7419 (goto-char pos)
7420 (setq ts (org-deadline arg time)))
7421 (org-agenda-show-new-time marker ts "D"))
7422 (message "Deadline for this item set to %s" ts)))
7424 (defun org-agenda-action ()
7425 "Select entry for agenda action, or execute an agenda action.
7426 This command prompts for another letter. Valid inputs are:
7428 m Mark the entry at point for an agenda action
7429 s Schedule the marked entry to the date at the cursor
7430 d Set the deadline of the marked entry to the date at the cursor
7431 r Call `org-remember' with cursor date as the default date
7432 c Call `org-capture' with cursor date as the default date
7433 SPC Show marked entry in other window
7434 TAB Visit marked entry in other window
7436 The cursor may be at a date in the calendar, or in the Org agenda."
7437 (interactive)
7438 (let (ans)
7439 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7440 (setq ans (read-char-exclusive))
7441 (cond
7442 ((equal ans ?m)
7443 ;; Mark this entry
7444 (if (eq major-mode 'org-agenda-mode)
7445 (let ((m (or (org-get-at-bol 'org-hd-marker)
7446 (org-get-at-bol 'org-marker))))
7447 (if m
7448 (progn
7449 (move-marker org-agenda-action-marker
7450 (marker-position m) (marker-buffer m))
7451 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7452 (error "Don't know which entry to mark")))
7453 (error "This command works only in the agenda")))
7454 ((equal ans ?s)
7455 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7456 ((equal ans ?d)
7457 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7458 ((equal ans ?r)
7459 (org-agenda-do-action '(org-remember) t))
7460 ((equal ans ?c)
7461 (org-agenda-do-action '(org-capture) t))
7462 ((equal ans ?\ )
7463 (let ((cw (selected-window)))
7464 (org-switch-to-buffer-other-window
7465 (marker-buffer org-agenda-action-marker))
7466 (goto-char org-agenda-action-marker)
7467 (org-show-context 'agenda)
7468 (select-window cw)))
7469 ((equal ans ?\C-i)
7470 (org-switch-to-buffer-other-window
7471 (marker-buffer org-agenda-action-marker))
7472 (goto-char org-agenda-action-marker)
7473 (org-show-context 'agenda))
7474 (t (error "Invalid agenda action %c" ans)))))
7476 (defun org-agenda-do-action (form &optional current-buffer)
7477 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7478 (let ((org-overriding-default-time (org-get-cursor-date)))
7479 (if current-buffer
7480 (eval form)
7481 (if (not (marker-buffer org-agenda-action-marker))
7482 (error "No entry has been selected for agenda action")
7483 (with-current-buffer (marker-buffer org-agenda-action-marker)
7484 (save-excursion
7485 (save-restriction
7486 (widen)
7487 (goto-char org-agenda-action-marker)
7488 (eval form))))))))
7490 (defun org-agenda-clock-in (&optional arg)
7491 "Start the clock on the currently selected item."
7492 (interactive "P")
7493 (org-agenda-check-no-diary)
7494 (if (equal arg '(4))
7495 (org-clock-in arg)
7496 (let* ((marker (or (org-get-at-bol 'org-marker)
7497 (org-agenda-error)))
7498 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7499 marker))
7500 (pos (marker-position marker))
7501 newhead)
7502 (org-with-remote-undo (marker-buffer marker)
7503 (with-current-buffer (marker-buffer marker)
7504 (widen)
7505 (goto-char pos)
7506 (org-show-context 'agenda)
7507 (org-show-entry)
7508 (org-cycle-hide-drawers 'children)
7509 (org-clock-in arg)
7510 (setq newhead (org-get-heading)))
7511 (org-agenda-change-all-lines newhead hdmarker)))))
7513 (defun org-agenda-clock-out ()
7514 "Stop the currently running clock."
7515 (interactive)
7516 (unless (marker-buffer org-clock-marker)
7517 (error "No running clock"))
7518 (let ((marker (make-marker)) newhead)
7519 (org-with-remote-undo (marker-buffer org-clock-marker)
7520 (with-current-buffer (marker-buffer org-clock-marker)
7521 (save-excursion
7522 (save-restriction
7523 (widen)
7524 (goto-char org-clock-marker)
7525 (org-back-to-heading t)
7526 (move-marker marker (point))
7527 (org-clock-out)
7528 (setq newhead (org-get-heading))))))
7529 (org-agenda-change-all-lines newhead marker)
7530 (move-marker marker nil)))
7532 (defun org-agenda-clock-cancel (&optional arg)
7533 "Cancel the currently running clock."
7534 (interactive "P")
7535 (unless (marker-buffer org-clock-marker)
7536 (error "No running clock"))
7537 (org-with-remote-undo (marker-buffer org-clock-marker)
7538 (org-clock-cancel)))
7540 (defun org-agenda-clock-goto ()
7541 "Jump to the currently clocked in task within the agenda.
7542 If the currently clocked in task is not listed in the agenda
7543 buffer, display it in another window."
7544 (interactive)
7545 (let (pos)
7546 (mapc (lambda (o)
7547 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7548 (setq pos (overlay-start o))))
7549 (overlays-in (point-min) (point-max)))
7550 (cond (pos (goto-char pos))
7551 ;; If the currently clocked entry is not in the agenda
7552 ;; buffer, we visit it in another window:
7553 (org-clock-current-task
7554 (org-switch-to-buffer-other-window (org-clock-goto)))
7555 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7557 (defun org-agenda-diary-entry-in-org-file ()
7558 "Make a diary entry in the file `org-agenda-diary-file'."
7559 (let (d1 d2 char (text "") dp1 dp2)
7560 (if (equal (buffer-name) "*Calendar*")
7561 (setq d1 (calendar-cursor-to-date t)
7562 d2 (car calendar-mark-ring))
7563 (setq dp1 (get-text-property (point-at-bol) 'day))
7564 (unless dp1 (error "No date defined in current line"))
7565 (setq d1 (calendar-gregorian-from-absolute dp1)
7566 d2 (and (ignore-errors (mark))
7567 (save-excursion
7568 (goto-char (mark))
7569 (setq dp2 (get-text-property (point-at-bol) 'day)))
7570 (calendar-gregorian-from-absolute dp2))))
7571 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7572 (setq char (read-char-exclusive))
7573 (cond
7574 ((equal char ?d)
7575 (setq text (read-string "Day entry: "))
7576 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7577 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7578 ((equal char ?a)
7579 (setq d1 (list (car d1) (nth 1 d1)
7580 (read-number (format "Reference year [%d]: " (nth 2 d1))
7581 (nth 2 d1))))
7582 (setq text (read-string "Anniversary (use %d to show years): "))
7583 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7584 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7585 ((equal char ?b)
7586 (setq text (read-string "Block entry: "))
7587 (unless (and d1 d2 (not (equal d1 d2)))
7588 (error "No block of days selected"))
7589 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7590 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7591 ((equal char ?j)
7592 (org-switch-to-buffer-other-window
7593 (find-file-noselect org-agenda-diary-file))
7594 (require 'org-datetree)
7595 (org-datetree-find-date-create d1)
7596 (org-reveal t))
7597 (t (error "Invalid selection character `%c'" char)))))
7599 (defcustom org-agenda-insert-diary-strategy 'date-tree
7600 "Where in `org-agenda-diary-file' should new entries be added?
7601 Valid values:
7603 date-tree in the date tree, as child of the date
7604 top-level as top-level entries at the end of the file."
7605 :group 'org-agenda
7606 :type '(choice
7607 (const :tag "in a date tree" date-tree)
7608 (const :tag "as top level at end of file" top-level)))
7610 (defcustom org-agenda-insert-diary-extract-time nil
7611 "Non-nil means extract any time specification from the diary entry."
7612 :group 'org-agenda
7613 :type 'boolean)
7615 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7616 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7617 If TEXT is not empty, it will become the headline of the new entry, and
7618 the resulting entry will not be shown. When TEXT is empty, switch to
7619 `org-agenda-diary-file' and let the user finish the entry there."
7620 (let ((cw (current-window-configuration)))
7621 (org-switch-to-buffer-other-window
7622 (find-file-noselect org-agenda-diary-file))
7623 (widen)
7624 (goto-char (point-min))
7625 (cond
7626 ((eq type 'anniversary)
7627 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7628 (progn
7629 (or (org-on-heading-p t)
7630 (progn
7631 (outline-next-heading)
7632 (insert "* Anniversaries\n\n")
7633 (beginning-of-line -1)))))
7634 (outline-next-heading)
7635 (org-back-over-empty-lines)
7636 (backward-char 1)
7637 (insert "\n")
7638 (require 'diary-lib)
7639 (let ((calendar-date-display-form
7640 (if (if (boundp 'calendar-date-style)
7641 (eq calendar-date-style 'european)
7642 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7643 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7644 '(day " " month " " year)
7645 '(month " " day " " year))))
7647 (insert (format "%%%%(diary-anniversary %s) %s"
7648 (calendar-date-string d1 nil t) text))))
7649 ((eq type 'day)
7650 (let ((org-prefix-has-time t)
7651 (org-agenda-time-leading-zero t)
7652 fmt time time2)
7653 (if org-agenda-insert-diary-extract-time
7654 ;; Use org-format-agenda-item to parse text for a time-range and
7655 ;; remove it. FIXME: This is a hack, we should refactor
7656 ;; that function to make time extraction available separately
7657 (setq fmt (org-format-agenda-item nil text nil nil t)
7658 time (get-text-property 0 'time fmt)
7659 time2 (if (> (length time) 0)
7660 ;; split-string removes trailing ...... if
7661 ;; no end time given. First space
7662 ;; separates time from date.
7663 (concat " " (car (split-string time "\\.")))
7664 nil)
7665 text (get-text-property 0 'txt fmt)))
7666 (if (eq org-agenda-insert-diary-strategy 'top-level)
7667 (org-agenda-insert-diary-as-top-level text)
7668 (require 'org-datetree)
7669 (org-datetree-find-date-create d1)
7670 (org-agenda-insert-diary-make-new-entry text))
7671 (org-insert-time-stamp (org-time-from-absolute
7672 (calendar-absolute-from-gregorian d1))
7673 nil nil nil nil time2))
7674 (end-of-line 0))
7675 ((eq type 'block)
7676 (if (> (calendar-absolute-from-gregorian d1)
7677 (calendar-absolute-from-gregorian d2))
7678 (setq d1 (prog1 d2 (setq d2 d1))))
7679 (if (eq org-agenda-insert-diary-strategy 'top-level)
7680 (org-agenda-insert-diary-as-top-level text)
7681 (require 'org-datetree)
7682 (org-datetree-find-date-create d1)
7683 (org-agenda-insert-diary-make-new-entry text))
7684 (org-insert-time-stamp (org-time-from-absolute
7685 (calendar-absolute-from-gregorian d1)))
7686 (insert "--")
7687 (org-insert-time-stamp (org-time-from-absolute
7688 (calendar-absolute-from-gregorian d2)))
7689 (end-of-line 0)))
7690 (if (string-match "\\S-" text)
7691 (progn
7692 (set-window-configuration cw)
7693 (message "%s entry added to %s"
7694 (capitalize (symbol-name type))
7695 (abbreviate-file-name org-agenda-diary-file)))
7696 (org-reveal t)
7697 (message "Please finish entry here"))))
7699 (defun org-agenda-insert-diary-as-top-level (text)
7700 "Make new entry as a top-level entry at the end of the file.
7701 Add TEXT as headline, and position the cursor in the second line so that
7702 a timestamp can be added there."
7703 (widen)
7704 (goto-char (point-max))
7705 (or (bolp) (insert "\n"))
7706 (insert "* " text "\n")
7707 (if org-adapt-indentation (org-indent-to-column 2)))
7709 (defun org-agenda-insert-diary-make-new-entry (text)
7710 "Make new entry as last child of current entry.
7711 Add TEXT as headline, and position the cursor in the second line so that
7712 a timestamp can be added there."
7713 (let ((org-show-following-heading t)
7714 (org-show-siblings t)
7715 (org-show-hierarchy-above t)
7716 (org-show-entry-below t)
7717 col)
7718 (outline-next-heading)
7719 (org-back-over-empty-lines)
7720 (or (looking-at "[ \t]*$")
7721 (progn (insert "\n") (backward-char 1)))
7722 (org-insert-heading nil t)
7723 (org-do-demote)
7724 (setq col (current-column))
7725 (insert text "\n")
7726 (if org-adapt-indentation (org-indent-to-column col))
7727 (let ((org-show-following-heading t)
7728 (org-show-siblings t)
7729 (org-show-hierarchy-above t)
7730 (org-show-entry-below t))
7731 (org-show-context))))
7733 (defun org-agenda-diary-entry ()
7734 "Make a diary entry, like the `i' command from the calendar.
7735 All the standard commands work: block, weekly etc.
7736 When `org-agenda-diary-file' points to a file,
7737 `org-agenda-diary-entry-in-org-file' is called instead to create
7738 entries in that Org-mode file."
7739 (interactive)
7740 (org-agenda-check-type t 'agenda 'timeline)
7741 (if (not (eq org-agenda-diary-file 'diary-file))
7742 (org-agenda-diary-entry-in-org-file)
7743 (require 'diary-lib)
7744 (let* ((char (progn
7745 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7746 (read-char-exclusive)))
7747 (cmd (cdr (assoc char
7748 '((?d . insert-diary-entry)
7749 (?w . insert-weekly-diary-entry)
7750 (?m . insert-monthly-diary-entry)
7751 (?y . insert-yearly-diary-entry)
7752 (?a . insert-anniversary-diary-entry)
7753 (?b . insert-block-diary-entry)
7754 (?c . insert-cyclic-diary-entry)))))
7755 (oldf (symbol-function 'calendar-cursor-to-date))
7756 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7757 (point (point))
7758 (mark (or (mark t) (point))))
7759 (unless cmd
7760 (error "No command associated with <%c>" char))
7761 (unless (and (get-text-property point 'day)
7762 (or (not (equal ?b char))
7763 (get-text-property mark 'day)))
7764 (error "Don't know which date to use for diary entry"))
7765 ;; We implement this by hacking the `calendar-cursor-to-date' function
7766 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7767 (let ((calendar-mark-ring
7768 (list (calendar-gregorian-from-absolute
7769 (or (get-text-property mark 'day)
7770 (get-text-property point 'day))))))
7771 (unwind-protect
7772 (progn
7773 (fset 'calendar-cursor-to-date
7774 (lambda (&optional error dummy)
7775 (calendar-gregorian-from-absolute
7776 (get-text-property point 'day))))
7777 (call-interactively cmd))
7778 (fset 'calendar-cursor-to-date oldf))))))
7780 (defun org-agenda-execute-calendar-command (cmd)
7781 "Execute a calendar command from the agenda, with the date associated to
7782 the cursor position."
7783 (org-agenda-check-type t 'agenda 'timeline)
7784 (require 'diary-lib)
7785 (unless (get-text-property (point) 'day)
7786 (error "Don't know which date to use for calendar command"))
7787 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7788 (point (point))
7789 (date (calendar-gregorian-from-absolute
7790 (get-text-property point 'day)))
7791 ;; the following 2 vars are needed in the calendar
7792 (displayed-month (car date))
7793 (displayed-year (nth 2 date)))
7794 (unwind-protect
7795 (progn
7796 (fset 'calendar-cursor-to-date
7797 (lambda (&optional error dummy)
7798 (calendar-gregorian-from-absolute
7799 (get-text-property point 'day))))
7800 (call-interactively cmd))
7801 (fset 'calendar-cursor-to-date oldf))))
7803 (defun org-agenda-phases-of-moon ()
7804 "Display the phases of the moon for the 3 months around the cursor date."
7805 (interactive)
7806 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7808 (defun org-agenda-holidays ()
7809 "Display the holidays for the 3 months around the cursor date."
7810 (interactive)
7811 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7813 (defvar calendar-longitude)
7814 (defvar calendar-latitude)
7815 (defvar calendar-location-name)
7817 (defun org-agenda-sunrise-sunset (arg)
7818 "Display sunrise and sunset for the cursor date.
7819 Latitude and longitude can be specified with the variables
7820 `calendar-latitude' and `calendar-longitude'. When called with prefix
7821 argument, latitude and longitude will be prompted for."
7822 (interactive "P")
7823 (require 'solar)
7824 (let ((calendar-longitude (if arg nil calendar-longitude))
7825 (calendar-latitude (if arg nil calendar-latitude))
7826 (calendar-location-name
7827 (if arg "the given coordinates" calendar-location-name)))
7828 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7830 (defun org-agenda-goto-calendar ()
7831 "Open the Emacs calendar with the date at the cursor."
7832 (interactive)
7833 (org-agenda-check-type t 'agenda 'timeline)
7834 (let* ((day (or (get-text-property (point) 'day)
7835 (error "Don't know which date to open in calendar")))
7836 (date (calendar-gregorian-from-absolute day))
7837 (calendar-move-hook nil)
7838 (calendar-view-holidays-initially-flag nil)
7839 (calendar-view-diary-initially-flag nil))
7840 (calendar)
7841 (calendar-goto-date date)))
7843 ;;;###autoload
7844 (defun org-calendar-goto-agenda ()
7845 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7846 This is a command that has to be installed in `calendar-mode-map'."
7847 (interactive)
7848 (org-agenda-list nil (calendar-absolute-from-gregorian
7849 (calendar-cursor-to-date))
7850 nil))
7852 (defun org-agenda-convert-date ()
7853 (interactive)
7854 (org-agenda-check-type t 'agenda 'timeline)
7855 (let ((day (get-text-property (point) 'day))
7856 date s)
7857 (unless day
7858 (error "Don't know which date to convert"))
7859 (setq date (calendar-gregorian-from-absolute day))
7860 (setq s (concat
7861 "Gregorian: " (calendar-date-string date) "\n"
7862 "ISO: " (calendar-iso-date-string date) "\n"
7863 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7864 "Julian: " (calendar-julian-date-string date) "\n"
7865 "Astron. JD: " (calendar-astro-date-string date)
7866 " (Julian date number at noon UTC)\n"
7867 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7868 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7869 "French: " (calendar-french-date-string date) "\n"
7870 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7871 "Mayan: " (calendar-mayan-date-string date) "\n"
7872 "Coptic: " (calendar-coptic-date-string date) "\n"
7873 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7874 "Persian: " (calendar-persian-date-string date) "\n"
7875 "Chinese: " (calendar-chinese-date-string date) "\n"))
7876 (with-output-to-temp-buffer "*Dates*"
7877 (princ s))
7878 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7880 ;;; Bulk commands
7882 (defvar org-agenda-bulk-marked-entries nil
7883 "List of markers that refer to marked entries in the agenda.")
7885 (defun org-agenda-bulk-marked-p ()
7886 (eq (get-char-property (point-at-bol) 'type)
7887 'org-marked-entry-overlay))
7889 (defun org-agenda-bulk-mark (&optional arg)
7890 "Mark the entry at point for future bulk action."
7891 (interactive "p")
7892 (dotimes (i (max arg 1))
7893 (unless (org-get-at-bol 'org-agenda-diary-link)
7894 (let* ((m (org-get-at-bol 'org-hd-marker))
7896 (unless (org-agenda-bulk-marked-p)
7897 (unless m (error "Nothing to mark at point"))
7898 (push m org-agenda-bulk-marked-entries)
7899 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7900 (org-overlay-display ov "> "
7901 (org-get-todo-face "TODO")
7902 'evaporate)
7903 (overlay-put ov 'type 'org-marked-entry-overlay))
7904 (beginning-of-line 2)
7905 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7906 (beginning-of-line 2))
7907 (message "%d entries marked for bulk action"
7908 (length org-agenda-bulk-marked-entries))))))
7910 (defun org-agenda-bulk-mark-regexp (regexp)
7911 "Mark entries match REGEXP."
7912 (interactive "sMark entries matching regexp: ")
7913 (let (entries-marked)
7914 (save-excursion
7915 (goto-char (point-min))
7916 (goto-char (next-single-property-change (point) 'txt))
7917 (while (re-search-forward regexp nil t)
7918 (when (string-match regexp (get-text-property (point) 'txt))
7919 (setq entries-marked (+ entries-marked 1))
7920 (call-interactively 'org-agenda-bulk-mark))))
7921 (if (not entries-marked)
7922 (message "No entry matching this regexp."))))
7924 (defun org-agenda-bulk-unmark ()
7925 "Unmark the entry at point for future bulk action."
7926 (interactive)
7927 (when (org-agenda-bulk-marked-p)
7928 (org-agenda-bulk-remove-overlays
7929 (point-at-bol) (+ 2 (point-at-bol)))
7930 (setq org-agenda-bulk-marked-entries
7931 (delete (org-get-at-bol 'org-hd-marker)
7932 org-agenda-bulk-marked-entries)))
7933 (beginning-of-line 2)
7934 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7935 (beginning-of-line 2))
7936 (message "%d entries marked for bulk action"
7937 (length org-agenda-bulk-marked-entries)))
7939 (defun org-agenda-bulk-toggle ()
7940 "Toggle marking the entry at point for bulk action."
7941 (interactive)
7942 (if (org-agenda-bulk-marked-p)
7943 (org-agenda-bulk-unmark)
7944 (org-agenda-bulk-mark)))
7946 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7947 "Remove the mark overlays between BEG and END in the agenda buffer.
7948 BEG and END default to the buffer limits.
7950 This only removes the overlays, it does not remove the markers
7951 from the list in `org-agenda-bulk-marked-entries'."
7952 (interactive)
7953 (mapc (lambda (ov)
7954 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7955 (delete-overlay ov)))
7956 (overlays-in (or beg (point-min)) (or end (point-max)))))
7958 (defun org-agenda-bulk-remove-all-marks ()
7959 "Remove all marks in the agenda buffer.
7960 This will remove the markers, and the overlays."
7961 (interactive)
7962 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7963 (setq org-agenda-bulk-marked-entries nil)
7964 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7966 (defun org-agenda-bulk-action (&optional arg)
7967 "Execute an remote-editing action on all marked entries.
7968 The prefix arg is passed through to the command if possible."
7969 (interactive "P")
7970 (unless org-agenda-bulk-marked-entries
7971 (error "No entries are marked"))
7972 (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
7973 (let* ((action (read-char-exclusive))
7974 (org-log-refile (if org-log-refile 'time nil))
7975 (entries (reverse org-agenda-bulk-marked-entries))
7976 redo-at-end
7977 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7978 (cond
7979 ((equal action ?$)
7980 (setq cmd '(org-agenda-archive)))
7982 ((equal action ?A)
7983 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7985 ((member action '(?r ?w))
7986 (setq rfloc (org-refile-get-location
7987 "Refile to"
7988 (marker-buffer (car org-agenda-bulk-marked-entries))
7989 org-refile-allow-creating-parent-nodes))
7990 (if (nth 3 rfloc)
7991 (setcar (nthcdr 3 rfloc)
7992 (move-marker (make-marker) (nth 3 rfloc)
7993 (or (get-file-buffer (nth 1 rfloc))
7994 (find-buffer-visiting (nth 1 rfloc))
7995 (error "This should not happen")))))
7997 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7998 redo-at-end t))
8000 ((equal action ?t)
8001 (setq state (org-icompleting-read
8002 "Todo state: "
8003 (with-current-buffer (marker-buffer (car entries))
8004 (mapcar 'list org-todo-keywords-1))))
8005 (setq cmd `(let ((org-inhibit-blocking t)
8006 (org-inhibit-logging 'note))
8007 (org-agenda-todo ,state))))
8009 ((memq action '(?- ?+))
8010 (setq tag (org-icompleting-read
8011 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8012 (with-current-buffer (marker-buffer (car entries))
8013 (delq nil
8014 (mapcar (lambda (x)
8015 (if (stringp (car x)) x)) org-tag-alist)))))
8016 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8018 ((memq action '(?s ?d))
8019 (let* ((date (unless arg
8020 (org-read-date
8021 nil nil nil
8022 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8023 (ans (if arg nil org-read-date-final-answer))
8024 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8025 (setq cmd `(let* ((bound (fboundp 'read-string))
8026 (old (and bound (symbol-function 'read-string))))
8027 (unwind-protect
8028 (progn
8029 (fset 'read-string (lambda (&rest ignore) ,ans))
8030 (eval '(,c1 arg)))
8031 (if bound
8032 (fset 'read-string old)
8033 (fmakunbound 'read-string)))))))
8035 ((equal action ?S)
8036 (if (not (org-agenda-check-type nil 'agenda 'timeline))
8037 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8038 (let ((days (read-number
8039 (format "Scatter tasks across how many %sdays: "
8040 (if arg "week" "")) 7)))
8041 (setq cmd
8042 `(let ((distance (1+ (random ,days))))
8043 (if arg
8044 (let ((dist distance)
8045 (day-of-week
8046 (calendar-day-of-week
8047 (calendar-gregorian-from-absolute (org-today)))))
8048 (dotimes (i (1+ dist))
8049 (while (member day-of-week org-agenda-weekend-days)
8050 (incf distance)
8051 (incf day-of-week)
8052 (if (= day-of-week 7)
8053 (setq day-of-week 0)))
8054 (incf day-of-week)
8055 (if (= day-of-week 7)
8056 (setq day-of-week 0)))))
8057 ;; silently fail when try to replan a sexp entry
8058 (condition-case nil
8059 (org-agenda-date-later distance)
8060 (error nil)))))))
8062 (t (error "Invalid bulk action")))
8064 ;; Sort the markers, to make sure that parents are handled before children
8065 (setq entries (sort entries
8066 (lambda (a b)
8067 (cond
8068 ((equal (marker-buffer a) (marker-buffer b))
8069 (< (marker-position a) (marker-position b)))
8071 (string< (buffer-name (marker-buffer a))
8072 (buffer-name (marker-buffer b))))))))
8074 ;; Now loop over all markers and apply cmd
8075 (while (setq e (pop entries))
8076 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8077 (if (not pos)
8078 (progn (message "Skipping removed entry at %s" e)
8079 (setq cntskip (1+ cntskip)))
8080 (goto-char pos)
8081 (eval cmd)
8082 (setq org-agenda-bulk-marked-entries
8083 (delete e org-agenda-bulk-marked-entries))
8084 (setq cnt (1+ cnt))))
8085 (setq org-agenda-bulk-marked-entries nil)
8086 (org-agenda-bulk-remove-all-marks)
8087 (when redo-at-end (org-agenda-redo))
8088 (message "Acted on %d entries%s"
8090 (if (= cntskip 0)
8092 (format ", skipped %d (disappeared before their turn)"
8093 cntskip)))))
8095 ;;; Flagging notes
8097 (defun org-agenda-show-the-flagging-note ()
8098 "Display the flagging note in the other window.
8099 When called a second time in direct sequence, offer to remove the FLAGGING
8100 tag and (if present) the flagging note."
8101 (interactive)
8102 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8103 (win (selected-window))
8104 note heading newhead)
8105 (unless hdmarker
8106 (error "No linked entry at point"))
8107 (if (and (eq this-command last-command)
8108 (y-or-n-p "Unflag and remove any flagging note? "))
8109 (progn
8110 (org-agenda-remove-flag hdmarker)
8111 (let ((win (get-buffer-window "*Flagging Note*")))
8112 (and win (delete-window win)))
8113 (message "Entry unflaged"))
8114 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8115 (unless note
8116 (error "No flagging note"))
8117 (org-kill-new note)
8118 (org-switch-to-buffer-other-window "*Flagging Note*")
8119 (erase-buffer)
8120 (insert note)
8121 (goto-char (point-min))
8122 (while (re-search-forward "\\\\n" nil t)
8123 (replace-match "\n" t t))
8124 (goto-char (point-min))
8125 (select-window win)
8126 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8128 (defun org-agenda-remove-flag (marker)
8129 "Remove the FLAGGED tag and any flagging note in the entry."
8130 (let (newhead)
8131 (org-with-point-at marker
8132 (org-toggle-tag "FLAGGED" 'off)
8133 (org-entry-delete nil "THEFLAGGINGNOTE")
8134 (setq newhead (org-get-heading)))
8135 (org-agenda-change-all-lines newhead marker)
8136 (message "Entry unflaged")))
8138 (defun org-agenda-get-any-marker (&optional pos)
8139 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8140 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8142 ;;; Appointment reminders
8144 (defvar appt-time-msg-list)
8146 ;;;###autoload
8147 (defun org-agenda-to-appt (&optional refresh filter)
8148 "Activate appointments found in `org-agenda-files'.
8149 With a \\[universal-argument] prefix, refresh the list of
8150 appointments.
8152 If FILTER is t, interactively prompt the user for a regular
8153 expression, and filter out entries that don't match it.
8155 If FILTER is a string, use this string as a regular expression
8156 for filtering entries out.
8158 FILTER can also be an alist with the car of each cell being
8159 either 'headline or 'category. For example:
8161 '((headline \"IMPORTANT\")
8162 (category \"Work\"))
8164 will only add headlines containing IMPORTANT or headlines
8165 belonging to the \"Work\" category."
8166 (interactive "P")
8167 (if refresh (setq appt-time-msg-list nil))
8168 (if (eq filter t)
8169 (setq filter (read-from-minibuffer "Regexp filter: ")))
8170 (let* ((cnt 0) ; count added events
8171 (org-agenda-new-buffers nil)
8172 (org-deadline-warning-days 0)
8173 ;; Do not use `org-today' here because appt only takes
8174 ;; time and without date as argument, so it may pass wrong
8175 ;; information otherwise
8176 (today (org-date-to-gregorian
8177 (time-to-days (current-time))))
8178 (org-agenda-restrict nil)
8179 (files (org-agenda-files 'unrestricted)) entries file)
8180 ;; Get all entries which may contain an appt
8181 (org-prepare-agenda-buffers files)
8182 (while (setq file (pop files))
8183 (setq entries
8184 (append entries
8185 (org-agenda-get-day-entries
8186 file today :timestamp :scheduled :deadline))))
8187 (setq entries (delq nil entries))
8188 ;; Map thru entries and find if we should filter them out
8189 (mapc
8190 (lambda(x)
8191 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8192 (cat (get-text-property 1 'org-category x))
8193 (tod (get-text-property 1 'time-of-day x))
8194 (ok (or (null filter)
8195 (and (stringp filter) (string-match filter evt))
8196 (and (listp filter)
8197 (or (string-match
8198 (cadr (assoc 'category filter)) cat)
8199 (string-match
8200 (cadr (assoc 'headline filter)) evt))))))
8201 ;; FIXME: Shall we remove text-properties for the appt text?
8202 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8203 (when (and ok tod)
8204 (setq tod (concat "00" (number-to-string tod))
8205 tod (when (string-match
8206 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8207 (concat (match-string 1 tod) ":"
8208 (match-string 2 tod))))
8209 (appt-add tod evt)
8210 (setq cnt (1+ cnt))))) entries)
8211 (org-release-buffers org-agenda-new-buffers)
8212 (if (eq cnt 0)
8213 (message "No event to add")
8214 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8216 (defun org-agenda-todayp (date)
8217 "Does DATE mean today, when considering `org-extend-today-until'?"
8218 (let ((today (org-today))
8219 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8220 date)))
8221 (eq date today)))
8223 (provide 'org-agenda)
8225 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8227 ;;; org-agenda.el ends here