org-agenda.el: fix bug about wrong current span.
[org-mode/org-jambu.git] / lisp / org-agenda.el
blob2c81184b5be3d4f6462a4f66045a70b8c9ed50d8
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.4
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
93 :group 'org-agenda
94 :type 'boolean)
96 (defcustom org-agenda-block-separator ?=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group 'org-agenda-export
125 :type '(repeat
126 (list
127 (variable)
128 (sexp :tag "Value"))))
130 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group 'org-agenda-export
134 :type 'hook
135 :options '(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines 0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
148 :group 'org-agenda
149 :type 'integer)
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
156 :group 'org-agenda
157 :type 'boolean)
159 (defcustom org-agenda-export-html-style ""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group 'org-agenda-export
198 :group 'org-export-html
199 :type 'string)
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-span)
246 (choice (const :tag "Day" 'day)
247 (const :tag "Week" 'week)
248 (const :tag "Month" 'month)
249 (const :tag "Year" 'year)
250 (integer :tag "Custom")))
251 (list :tag "Fixed starting date"
252 (const org-agenda-start-day)
253 (string :value "2007-11-01"))
254 (list :tag "Start on day of week"
255 (const org-agenda-start-on-weekday)
256 (choice :value 1
257 (const :tag "Today" nil)
258 (integer :tag "Weekday No.")))
259 (list :tag "Include data from diary"
260 (const org-agenda-include-diary)
261 (boolean))
262 (list :tag "Deadline Warning days"
263 (const org-deadline-warning-days)
264 (integer :value 1))
265 (list :tag "Tags filter preset"
266 (const org-agenda-filter-preset)
267 (list
268 (const :format "" quote)
269 (repeat
270 (string :tag "+tag or -tag"))))
271 (list :tag "Set daily/weekly entry types"
272 (const org-agenda-entry-types)
273 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
274 (const :deadline)
275 (const :scheduled)
276 (const :timestamp)
277 (const :sexp)))
278 (list :tag "Standard skipping condition"
279 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
280 (const org-agenda-skip-function)
281 (list
282 (const :format "" quote)
283 (list
284 (choice
285 :tag "Skipping range"
286 (const :tag "Skip entry" org-agenda-skip-entry-if)
287 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
288 (repeat :inline t :tag "Conditions for skipping"
289 (choice
290 :tag "Condition type"
291 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
292 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
293 (list :tag "TODO state is" :inline t
294 (const 'todo)
295 (choice
296 (const :tag "any not-done state" 'todo)
297 (const :tag "any done state" 'done)
298 (const :tag "any state" 'any)
299 (list :tag "Keyword list"
300 (const :format "" quote)
301 (repeat (string :tag "Keyword")))))
302 (list :tag "TODO state is not" :inline t
303 (const 'nottodo)
304 (choice
305 (const :tag "any not-done state" 'todo)
306 (const :tag "any done state" 'done)
307 (const :tag "any state" 'any)
308 (list :tag "Keyword list"
309 (const :format "" quote)
310 (repeat (string :tag "Keyword")))))
311 (const :tag "scheduled" 'scheduled)
312 (const :tag "not scheduled" 'notscheduled)
313 (const :tag "deadline" 'deadline)
314 (const :tag "no deadline" 'notdeadline)
315 (const :tag "timestamp" 'timestamp)
316 (const :tag "no timestamp" 'nottimestamp))))))
317 (list :tag "Non-standard skipping condition"
318 :value (org-agenda-skip-function)
319 (const org-agenda-skip-function)
320 (sexp :tag "Function or form (quoted!)"))
321 (list :tag "Any variable"
322 (variable :tag "Variable")
323 (sexp :tag "Value (sexp)"))))
324 "Selection of examples for agenda command settings.
325 This will be spliced into the custom type of
326 `org-agenda-custom-commands'.")
329 (defcustom org-agenda-custom-commands nil
330 "Custom commands for the agenda.
331 These commands will be offered on the splash screen displayed by the
332 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
334 (key desc type match settings files)
336 key The key (one or more characters as a string) to be associated
337 with the command.
338 desc A description of the command, when omitted or nil, a default
339 description is built using MATCH.
340 type The command type, any of the following symbols:
341 agenda The daily/weekly agenda.
342 todo Entries with a specific TODO keyword, in all agenda files.
343 search Entries containing search words entry or headline.
344 tags Tags/Property/TODO match in all agenda files.
345 tags-todo Tags/P/T match in all agenda files, TODO entries only.
346 todo-tree Sparse tree of specific TODO keyword in *current* file.
347 tags-tree Sparse tree with all tags matches in *current* file.
348 occur-tree Occur sparse tree for *current* file.
349 ... A user-defined function.
350 match What to search for:
351 - a single keyword for TODO keyword searches
352 - a tags match expression for tags searches
353 - a word search expression for text searches.
354 - a regular expression for occur searches
355 For all other commands, this should be the empty string.
356 settings A list of option settings, similar to that in a let form, so like
357 this: ((opt1 val1) (opt2 val2) ...). The values will be
358 evaluated at the moment of execution, so quote them when needed.
359 files A list of files file to write the produced agenda buffer to
360 with the command `org-store-agenda-views'.
361 If a file name ends in \".html\", an HTML version of the buffer
362 is written out. If it ends in \".ps\", a postscript version is
363 produced. Otherwise, only the plain text is written to the file.
365 You can also define a set of commands, to create a composite agenda buffer.
366 In this case, an entry looks like this:
368 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
370 where
372 desc A description string to be displayed in the dispatcher menu.
373 cmd An agenda command, similar to the above. However, tree commands
374 are no allowed, but instead you can get agenda and global todo list.
375 So valid commands for a set are:
376 (agenda \"\" settings)
377 (alltodo \"\" settings)
378 (stuck \"\" settings)
379 (todo \"match\" settings files)
380 (search \"match\" settings files)
381 (tags \"match\" settings files)
382 (tags-todo \"match\" settings files)
384 Each command can carry a list of options, and another set of options can be
385 given for the whole set of commands. Individual command options take
386 precedence over the general options.
388 When using several characters as key to a command, the first characters
389 are prefix commands. For the dispatcher to display useful information, you
390 should provide a description for the prefix, like
392 (setq org-agenda-custom-commands
393 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
394 (\"hl\" tags \"+HOME+Lisa\")
395 (\"hp\" tags \"+HOME+Peter\")
396 (\"hk\" tags \"+HOME+Kim\")))"
397 :group 'org-agenda-custom-commands
398 :type `(repeat
399 (choice :value ("x" "Describe command here" tags "" nil)
400 (list :tag "Single command"
401 (string :tag "Access Key(s) ")
402 (option (string :tag "Description"))
403 (choice
404 (const :tag "Agenda" agenda)
405 (const :tag "TODO list" alltodo)
406 (const :tag "Search words" search)
407 (const :tag "Stuck projects" stuck)
408 (const :tag "Tags/Property match (all agenda files)" tags)
409 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
410 (const :tag "TODO keyword search (all agenda files)" todo)
411 (const :tag "Tags sparse tree (current buffer)" tags-tree)
412 (const :tag "TODO keyword tree (current buffer)" todo-tree)
413 (const :tag "Occur tree (current buffer)" occur-tree)
414 (sexp :tag "Other, user-defined function"))
415 (string :tag "Match (only for some commands)")
416 ,org-agenda-custom-commands-local-options
417 (option (repeat :tag "Export" (file :tag "Export to"))))
418 (list :tag "Command series, all agenda files"
419 (string :tag "Access Key(s)")
420 (string :tag "Description ")
421 (repeat :tag "Component"
422 (choice
423 (list :tag "Agenda"
424 (const :format "" agenda)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "TODO list (all keywords)"
428 (const :format "" alltodo)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Search words"
432 (const :format "" search)
433 (string :tag "Match")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Stuck projects"
436 (const :format "" stuck)
437 (const :tag "" :format "" "")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search"
440 (const :format "" tags)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search, TODO entries only"
444 (const :format "" tags-todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "TODO keyword search"
448 (const :format "" todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "Other, user-defined function"
452 (symbol :tag "function")
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)))
456 (repeat :tag "Settings for entire command set"
457 (list (variable :tag "Any variable")
458 (sexp :tag "Value")))
459 (option (repeat :tag "Export" (file :tag "Export to"))))
460 (cons :tag "Prefix key documentation"
461 (string :tag "Access Key(s)")
462 (string :tag "Description ")))))
464 (defcustom org-agenda-query-register ?o
465 "The register holding the current query string.
466 The purpose of this is that if you construct a query string interactively,
467 you can then use it to define a custom command."
468 :group 'org-agenda-custom-commands
469 :type 'character)
471 (defcustom org-stuck-projects
472 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
473 "How to identify stuck projects.
474 This is a list of four items:
475 1. A tags/todo/property matcher string that is used to identify a project.
476 See the manual for a description of tag and property searches.
477 The entire tree below a headline matched by this is considered one project.
478 2. A list of TODO keywords identifying non-stuck projects.
479 If the project subtree contains any headline with one of these todo
480 keywords, the project is considered to be not stuck. If you specify
481 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
482 3. A list of tags identifying non-stuck projects.
483 If the project subtree contains any headline with one of these tags,
484 the project is considered to be not stuck. If you specify \"*\" as
485 a tag, any tag will mark the project unstuck. Note that this is about
486 the explicit presence of a tag somewhere in the subtree, inherited
487 tags to not count here. If inherited tags make a project not stuck,
488 use \"-TAG\" in the tags part of the matcher under (1.) above.
489 4. An arbitrary regular expression matching non-stuck projects.
491 If the project turns out to be not stuck, search continues also in the
492 subtree to see if any of the subtasks have project status.
494 See also the variable `org-tags-match-list-sublevels' which applies
495 to projects matched by this search as well.
497 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
498 or `C-c a #' to produce the list."
499 :group 'org-agenda-custom-commands
500 :type '(list
501 (string :tag "Tags/TODO match to identify a project")
502 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
503 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
504 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
506 (defcustom org-agenda-filter-effort-default-operator "<"
507 "The default operator for effort estimate filtering.
508 If you select an effort estimate limit without first pressing an operator,
509 this one will be used."
510 :group 'org-agenda-custom-commands
511 :type '(choice (const :tag "less or equal" "<")
512 (const :tag "greater or equal"">")
513 (const :tag "equal" "=")))
515 (defgroup org-agenda-skip nil
516 "Options concerning skipping parts of agenda files."
517 :tag "Org Agenda Skip"
518 :group 'org-agenda)
520 (defcustom org-agenda-skip-function-global nil
521 "Function to be called at each match during agenda construction.
522 If this function returns nil, the current match should not be skipped.
523 If the function decided to skip an agenda match, is must return the
524 buffer position from which the search should be continued.
525 This may also be a Lisp form, which will be evaluated.
527 This variable will be applied to every agenda match, including
528 tags/property searches and TODO lists. So try to make the test function
529 do its checking as efficiently as possible. To implement a skipping
530 condition just for specific agenda commands, use the variable
531 `org-agenda-skip-function' which can be set in the options section
532 of custom agenda commands."
533 :group 'org-agenda-skip
534 :type 'sexp)
536 (defgroup org-agenda-daily/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag "Org Agenda Daily/Weekly"
539 :group 'org-agenda)
540 (defgroup org-agenda-todo-list nil
541 "Options concerning the global todo list agenda view."
542 :tag "Org Agenda Todo List"
543 :group 'org-agenda)
544 (defgroup org-agenda-match-view nil
545 "Options concerning the general tags/property/todo match agenda view."
546 :tag "Org Agenda Match View"
547 :group 'org-agenda)
548 (defgroup org-agenda-search-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
553 (defvar org-agenda-archives-mode nil
554 "Non-nil means the agenda will include archived items.
555 If this is the symbol `trees', trees in the selected agenda scope
556 that are marked with the ARCHIVE tag will be included anyway. When this is
557 t, also all archive files associated with the current selection of agenda
558 files will be included.")
560 (defcustom org-agenda-skip-comment-trees t
561 "Non-nil means skip trees that start with the COMMENT keyword.
562 When nil, these trees are also scanned by agenda commands."
563 :group 'org-agenda-skip
564 :type 'boolean)
566 (defcustom org-agenda-todo-list-sublevels t
567 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
568 When nil, the sublevels of a TODO entry are not checked, resulting in
569 potentially much shorter TODO lists."
570 :group 'org-agenda-skip
571 :group 'org-agenda-todo-list
572 :type 'boolean)
574 (defcustom org-agenda-todo-ignore-with-date nil
575 "Non-nil means don't show entries with a date in the global todo list.
576 You can use this if you prefer to mark mere appointments with a TODO keyword,
577 but don't want them to show up in the TODO list.
578 When this is set, it also covers deadlines and scheduled items, the settings
579 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
580 will be ignored.
581 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
582 :group 'org-agenda-skip
583 :group 'org-agenda-todo-list
584 :type 'boolean)
586 (defcustom org-agenda-todo-ignore-timestamp nil
587 "Non-nil means don't show entries with a timestamp.
588 This applies when creating the global todo list.
589 Valid values are:
591 past Don't show entries for today or in the past.
593 future Don't show entries with a timestamp in the future.
594 The idea behind this is that if it has a future
595 timestamp, you don't want to think about it until the
596 date.
598 all Don't show any entries with a timestamp in the global todo list.
599 The idea behind this is that by setting a timestamp, you
600 have already \"taken care\" of this item.
602 This variable can also have an integer as a value. If positive (N),
603 todos with a timestamp N or more days in the future will be ignored. If
604 negative (-N), todos with a timestamp N or more days in the past will be
605 ignored. If 0, todos with a timestamp either today or in the future will
606 be ignored. For example, a value of -1 will exclude todos with a
607 timestamp in the past (yesterday or earlier), while a value of 7 will
608 exclude todos with a timestamp a week or more in the future.
610 See also `org-agenda-todo-ignore-with-date'.
611 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
612 to make his option also apply to the tags-todo list."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type '(choice
616 (const :tag "Ignore future timestamp todos" future)
617 (const :tag "Ignore past or present timestamp todos" past)
618 (const :tag "Ignore all timestamp todos" all)
619 (const :tag "Show timestamp todos" nil)
620 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
622 (defcustom org-agenda-todo-ignore-scheduled nil
623 "Non-nil means, ignore some scheduled TODO items when making TODO list.
624 This applies when creating the global todo list.
625 Valid values are:
627 past Don't show entries scheduled today or in the past.
629 future Don't show entries scheduled in the future.
630 The idea behind this is that by scheduling it, you don't want to
631 think about it until the scheduled date.
633 all Don't show any scheduled entries in the global todo list.
634 The idea behind this is that by scheduling it, you have already
635 \"taken care\" of this item.
637 t Same as `all', for backward compatibility.
639 This variable can also have an integer as a value. See
640 `org-agenda-todo-ignore-timestamp' for more details.
642 See also `org-agenda-todo-ignore-with-date'.
643 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
644 to make his option also apply to the tags-todo list."
645 :group 'org-agenda-skip
646 :group 'org-agenda-todo-list
647 :type '(choice
648 (const :tag "Ignore future-scheduled todos" future)
649 (const :tag "Ignore past- or present-scheduled todos" past)
650 (const :tag "Ignore all scheduled todos" all)
651 (const :tag "Ignore all scheduled todos (compatibility)" t)
652 (const :tag "Show scheduled todos" nil)
653 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
655 (defcustom org-agenda-todo-ignore-deadlines nil
656 "Non-nil means ignore some deadlined TODO items when making TODO list.
657 There are different motivations for using different values, please think
658 carefully when configuring this variable.
660 This applies when creating the global todo list.
661 Valid values are:
663 near Don't show near deadline entries. A deadline is near when it is
664 closer than `org-deadline-warning-days' days. The idea behind this
665 is that such items will appear in the agenda anyway.
667 far Don't show TODO entries where a deadline has been defined, but
668 the deadline is not near. This is useful if you don't want to
669 use the todo list to figure out what to do now.
671 past Don't show entries with a deadline timestamp for today or in the past.
673 future Don't show entries with a deadline timestamp in the future, not even
674 when they become `near' ones. Use it with caution.
676 all Ignore all TODO entries that do have a deadline.
678 t Same as `near', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore near deadlines" near)
690 (const :tag "Ignore near deadlines (compatibility)" t)
691 (const :tag "Ignore far deadlines" far)
692 (const :tag "Ignore all TODOs with a deadlines" all)
693 (const :tag "Show all TODOs, even if they have a deadline" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-tags-todo-honor-ignore-options nil
697 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
698 The variables
699 `org-agenda-todo-ignore-with-date',
700 `org-agenda-todo-ignore-timestamp',
701 `org-agenda-todo-ignore-scheduled',
702 `org-agenda-todo-ignore-deadlines'
703 make the global TODO list skip entries that have time stamps of certain
704 kinds. If this option is set, the same options will also apply for the
705 tags-todo search, which is the general tags/property matcher
706 restricted to unfinished TODO entries only."
707 :group 'org-agenda-skip
708 :group 'org-agenda-todo-list
709 :group 'org-agenda-match-view
710 :type 'boolean)
712 (defcustom org-agenda-skip-scheduled-if-done nil
713 "Non-nil means don't show scheduled items in agenda when they are done.
714 This is relevant for the daily/weekly agenda, not for the TODO list. And
715 it applies only to the actual date of the scheduling. Warnings about
716 an item with a past scheduling dates are always turned off when the item
717 is DONE."
718 :group 'org-agenda-skip
719 :group 'org-agenda-daily/weekly
720 :type 'boolean)
722 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
723 "Non-nil means skip scheduling line if same entry shows because of deadline.
724 In the agenda of today, an entry can show up multiple times because
725 it is both scheduled and has a nearby deadline, and maybe a plain time
726 stamp as well.
727 When this variable is t, then only the deadline is shown and the fact that
728 the entry is scheduled today or was scheduled previously is not shown.
729 When this variable is nil, the entry will be shown several times. When
730 the variable is the symbol `not-today', then skip scheduled previously,
731 but not scheduled today."
732 :group 'org-agenda-skip
733 :group 'org-agenda-daily/weekly
734 :type '(choice
735 (const :tag "Never" nil)
736 (const :tag "Always" t)
737 (const :tag "Not when scheduled today" not-today)))
739 (defcustom org-agenda-skip-deadline-if-done nil
740 "Non-nil means don't show deadlines when the corresponding item is done.
741 When nil, the deadline is still shown and should give you a happy feeling.
742 This is relevant for the daily/weekly agenda. And it applied only to the
743 actually date of the deadline. Warnings about approaching and past-due
744 deadlines are always turned off when the item is DONE."
745 :group 'org-agenda-skip
746 :group 'org-agenda-daily/weekly
747 :type 'boolean)
749 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
750 "Non-nil means skip deadline prewarning when entry is also scheduled.
751 This will apply on all days where a prewarning for the deadline would
752 be shown, but not at the day when the entry is actually due. On that day,
753 the deadline will be shown anyway.
754 This variable may be set to nil, t, or a number which will then give
755 the number of days before the actual deadline when the prewarnings
756 should resume.
757 This can be used in a workflow where the first showing of the deadline will
758 trigger you to schedule it, and then you don't want to be reminded of it
759 because you will take care of it on the day when scheduled."
760 :group 'org-agenda-skip
761 :group 'org-agenda-daily/weekly
762 :type '(choice
763 (const :tag "Alwas show prewarning" nil)
764 (const :tag "Remove prewarning if entry is scheduled" t)
765 (integer :tag "Restart prewarning N days before deadline")))
767 (defcustom org-agenda-skip-additional-timestamps-same-entry t
768 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
769 When non-nil, after the search for timestamps has matched once in an
770 entry, the rest of the entry will not be searched."
771 :group 'org-agenda-skip
772 :type 'boolean)
774 (defcustom org-agenda-skip-timestamp-if-done nil
775 "Non-nil means don't select item by timestamp or -range if it is DONE."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type 'boolean)
780 (defcustom org-agenda-dim-blocked-tasks t
781 "Non-nil means dim blocked tasks in the agenda display.
782 This causes some overhead during agenda construction, but if you
783 have turned on `org-enforce-todo-dependencies',
784 `org-enforce-todo-checkbox-dependencies', or any other blocking
785 mechanism, this will create useful feedback in the agenda.
787 Instead of t, this variable can also have the value `invisible'.
788 Then blocked tasks will be invisible and only become visible when
789 they become unblocked. An exemption to this behavior is when a task is
790 blocked because of unchecked checkboxes below it. Since checkboxes do
791 not show up in the agenda views, making this task invisible you remove any
792 trace from agenda views that there is something to do. Therefore, a task
793 that is blocked because of checkboxes will never be made invisible, it
794 will only be dimmed."
795 :group 'org-agenda-daily/weekly
796 :group 'org-agenda-todo-list
797 :type '(choice
798 (const :tag "Do not dim" nil)
799 (const :tag "Dim to a grey face" t)
800 (const :tag "Make invisible" invisible)))
802 (defcustom org-timeline-show-empty-dates 3
803 "Non-nil means `org-timeline' also shows dates without an entry.
804 When nil, only the days which actually have entries are shown.
805 When t, all days between the first and the last date are shown.
806 When an integer, show also empty dates, but if there is a gap of more than
807 N days, just insert a special line indicating the size of the gap."
808 :group 'org-agenda-skip
809 :type '(choice
810 (const :tag "None" nil)
811 (const :tag "All" t)
812 (integer :tag "at most")))
814 (defgroup org-agenda-startup nil
815 "Options concerning initial settings in the Agenda in Org Mode."
816 :tag "Org Agenda Startup"
817 :group 'org-agenda)
819 (defcustom org-agenda-menu-show-matcher t
820 "Non-nil means show the match string in the agenda dispatcher menu.
821 When nil, the matcher string is not shown, but is put into the help-echo
822 property so than moving the mouse over the command shows it.
823 Setting it to nil is good if matcher strings are very long and/or if
824 you want to use two-column display (see `org-agenda-menu-two-column')."
825 :group 'org-agenda
826 :type 'boolean)
828 (defcustom org-agenda-menu-two-column nil
829 "Non-nil means, use two columns to show custom commands in the dispatcher.
830 If you use this, you probably want to set `org-agenda-menu-show-matcher'
831 to nil."
832 :group 'org-agenda
833 :type 'boolean)
835 (defcustom org-finalize-agenda-hook nil
836 "Hook run just before displaying an agenda buffer."
837 :group 'org-agenda-startup
838 :type 'hook)
840 (defcustom org-agenda-mouse-1-follows-link nil
841 "Non-nil means mouse-1 on a link will follow the link in the agenda.
842 A longer mouse click will still set point. Does not work on XEmacs.
843 Needs to be set before org.el is loaded."
844 :group 'org-agenda-startup
845 :type 'boolean)
847 (defcustom org-agenda-start-with-follow-mode nil
848 "The initial value of follow mode in a newly created agenda window."
849 :group 'org-agenda-startup
850 :type 'boolean)
852 (defcustom org-agenda-show-outline-path t
853 "Non-nil means show outline path in echo area after line motion."
854 :group 'org-agenda-startup
855 :type 'boolean)
857 (defcustom org-agenda-start-with-entry-text-mode nil
858 "The initial value of entry-text-mode in a newly created agenda window."
859 :group 'org-agenda-startup
860 :type 'boolean)
862 (defcustom org-agenda-entry-text-maxlines 5
863 "Number of text lines to be added when `E' is pressed in the agenda.
865 Note that this variable only used during agenda display. Add add entry text
866 when exporting the agenda, configure the variable
867 `org-agenda-add-entry-ext-maxlines'."
868 :group 'org-agenda
869 :type 'integer)
871 (defcustom org-agenda-entry-text-exclude-regexps nil
872 "List of regular expressions to clean up entry text.
873 The complete matches of all regular expressions in this list will be
874 removed from entry text before it is shown in the agenda."
875 :group 'org-agenda
876 :type '(repeat (regexp)))
878 (defvar org-agenda-entry-text-cleanup-hook nil
879 "Hook that is run after basic cleanup of entry text to be shown in agenda.
880 This cleanup is done in a temporary buffer, so the function may inspect and
881 change the entire buffer.
882 Some default stuff like drawers and scheduling/deadline dates will already
883 have been removed when this is called, as will any matches for regular
884 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
886 (defvar org-agenda-include-inactive-timestamps nil
887 "Non-nil means include inactive time stamps in agenda and timeline.")
889 (defgroup org-agenda-windows nil
890 "Options concerning the windows used by the Agenda in Org Mode."
891 :tag "Org Agenda Windows"
892 :group 'org-agenda)
894 (defcustom org-agenda-window-setup 'reorganize-frame
895 "How the agenda buffer should be displayed.
896 Possible values for this option are:
898 current-window Show agenda in the current window, keeping all other windows.
899 other-window Use `switch-to-buffer-other-window' to display agenda.
900 reorganize-frame Show only two windows on the current frame, the current
901 window and the agenda.
902 other-frame Use `switch-to-buffer-other-frame' to display agenda.
903 Also, when exiting the agenda, kill that frame.
904 See also the variable `org-agenda-restore-windows-after-quit'."
905 :group 'org-agenda-windows
906 :type '(choice
907 (const current-window)
908 (const other-frame)
909 (const other-window)
910 (const reorganize-frame)))
912 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
913 "The min and max height of the agenda window as a fraction of frame height.
914 The value of the variable is a cons cell with two numbers between 0 and 1.
915 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
916 :group 'org-agenda-windows
917 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
919 (defcustom org-agenda-restore-windows-after-quit nil
920 "Non-nil means restore window configuration open 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 "B" 'org-agenda-bulk-action)
1769 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1770 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1771 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1772 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1773 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1774 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1775 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1776 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1777 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1778 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1779 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1780 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1781 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1782 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1783 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1784 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1785 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1786 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1787 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1788 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1789 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1790 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1791 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1792 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1793 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1794 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1795 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1796 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1797 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1798 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1799 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1800 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1801 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1802 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1804 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1805 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1806 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1807 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1808 (while l (org-defkey org-agenda-mode-map
1809 (int-to-string (pop l)) 'digit-argument)))
1811 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1812 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1813 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1814 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1815 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1816 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1817 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1818 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1819 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1820 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1821 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1822 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1823 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1824 'org-clock-modify-effort-estimate)
1825 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1826 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1827 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1828 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1829 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1830 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1831 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1832 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1833 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1834 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1835 (substitute-key-definition 'next-line 'org-agenda-next-line
1836 org-agenda-mode-map global-map)
1837 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1838 org-agenda-mode-map global-map)
1839 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1840 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1841 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1842 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1843 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1844 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1845 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1846 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1847 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1848 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1849 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1850 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1851 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1852 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1853 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1854 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1855 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1856 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1857 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1858 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1859 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1860 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1861 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1862 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1863 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1864 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1865 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1866 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1867 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1868 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1870 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1871 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1872 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1873 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1874 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1875 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1876 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1877 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1878 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1879 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1881 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1882 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1883 (when org-agenda-mouse-1-follows-link
1884 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1885 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1886 '("Agenda"
1887 ("Agenda Files")
1888 "--"
1889 ("Agenda Dates"
1890 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1891 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1892 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1893 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1894 "--"
1895 ("View"
1896 ["Day View" org-agenda-day-view
1897 :active (org-agenda-check-type nil 'agenda)
1898 :style radio :selected (eq org-agenda-current-span 'day)
1899 :keys "v d (or just d)"]
1900 ["Week View" org-agenda-week-view
1901 :active (org-agenda-check-type nil 'agenda)
1902 :style radio :selected (eq org-agenda-current-span 'week)
1903 :keys "v w (or just w)"]
1904 ["Month View" org-agenda-month-view
1905 :active (org-agenda-check-type nil 'agenda)
1906 :style radio :selected (eq org-agenda-current-span 'month)
1907 :keys "v m"]
1908 ["Year View" org-agenda-year-view
1909 :active (org-agenda-check-type nil 'agenda)
1910 :style radio :selected (eq org-agenda-current-span 'year)
1911 :keys "v y"]
1912 "--"
1913 ["Include Diary" org-agenda-toggle-diary
1914 :style toggle :selected org-agenda-include-diary
1915 :active (org-agenda-check-type nil 'agenda)]
1916 ["Include Deadlines" org-agenda-toggle-deadlines
1917 :style toggle :selected org-agenda-include-deadlines
1918 :active (org-agenda-check-type nil 'agenda)]
1919 ["Use Time Grid" org-agenda-toggle-time-grid
1920 :style toggle :selected org-agenda-use-time-grid
1921 :active (org-agenda-check-type nil 'agenda)]
1922 "--"
1923 ["Show clock report" org-agenda-clockreport-mode
1924 :style toggle :selected org-agenda-clockreport-mode
1925 :active (org-agenda-check-type nil 'agenda)]
1926 ["Show some entry text" org-agenda-entry-text-mode
1927 :style toggle :selected org-agenda-entry-text-mode
1928 :active t]
1929 "--"
1930 ["Show Logbook entries" org-agenda-log-mode
1931 :style toggle :selected org-agenda-show-log
1932 :active (org-agenda-check-type nil 'agenda 'timeline)
1933 :keys "v l (or just l)"]
1934 ["Include archived trees" org-agenda-archives-mode
1935 :style toggle :selected org-agenda-archives-mode :active t
1936 :keys "v a"]
1937 ["Include archive files" (org-agenda-archives-mode t)
1938 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1939 :keys "v A"]
1940 "--"
1941 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1942 ["Write view to file" org-write-agenda t]
1943 ["Rebuild buffer" org-agenda-redo t]
1944 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1945 "--"
1946 ["Show original entry" org-agenda-show t]
1947 ["Go To (other window)" org-agenda-goto t]
1948 ["Go To (this window)" org-agenda-switch-to t]
1949 ["Follow Mode" org-agenda-follow-mode
1950 :style toggle :selected org-agenda-follow-mode :active t]
1951 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1952 "--"
1953 ("TODO"
1954 ["Cycle TODO" org-agenda-todo t]
1955 ["Next TODO set" org-agenda-todo-nextset t]
1956 ["Previous TODO set" org-agenda-todo-previousset t]
1957 ["Add note" org-agenda-add-note t])
1958 ("Archive/Refile/Delete"
1959 ["Archive default" org-agenda-archive-default t]
1960 ["Archive default" org-agenda-archive-default-with-confirmation t]
1961 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1962 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1963 ["Archive subtree" org-agenda-archive t]
1964 "--"
1965 ["Refile" org-agenda-refile t]
1966 "--"
1967 ["Delete subtree" org-agenda-kill t])
1968 ("Bulk action"
1969 ["Mark entry" org-agenda-bulk-mark t]
1970 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
1971 ["Unmark entry" org-agenda-bulk-unmark t]
1972 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1973 ["Act on all marked" org-agenda-bulk-action t]
1974 "--"
1975 ("Tags and Properties"
1976 ["Show all Tags" org-agenda-show-tags t]
1977 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1978 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1979 "--"
1980 ["Column View" org-columns t])
1981 ("Deadline/Schedule"
1982 ["Schedule" org-agenda-schedule t]
1983 ["Set Deadline" org-agenda-deadline t]
1984 "--"
1985 ["Mark item" org-agenda-action :active t :keys "k m"]
1986 ["Show mark item" org-agenda-action :active t :keys "k v"]
1987 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1988 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1989 "--"
1990 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1991 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1992 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1993 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1994 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1995 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1996 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1997 ("Clock and Effort"
1998 ["Clock in" org-agenda-clock-in t]
1999 ["Clock out" org-agenda-clock-out t]
2000 ["Clock cancel" org-agenda-clock-cancel t]
2001 ["Goto running clock" org-clock-goto t]
2002 "--"
2003 ["Set Effort" org-agenda-set-effort t]
2004 ["Change clocked effort" org-clock-modify-effort-estimate
2005 (org-clock-is-active)])
2006 ("Priority"
2007 ["Set Priority" org-agenda-priority t]
2008 ["Increase Priority" org-agenda-priority-up t]
2009 ["Decrease Priority" org-agenda-priority-down t]
2010 ["Show Priority" org-agenda-show-priority t])
2011 ("Calendar/Diary"
2012 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2013 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2014 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2015 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2016 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2017 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2018 "--"
2019 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2020 "--"
2021 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2022 "--"
2023 ("MobileOrg"
2024 ["Push Files and Views" org-mobile-push t]
2025 ["Get Captured and Flagged" org-mobile-pull t]
2026 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2027 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2028 "--"
2029 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2030 "--"
2031 ["Quit" org-agenda-quit t]
2032 ["Exit and Release Buffers" org-agenda-exit t]
2035 ;;; Agenda undo
2037 (defvar org-agenda-allow-remote-undo t
2038 "Non-nil means allow remote undo from the agenda buffer.")
2039 (defvar org-agenda-undo-list nil
2040 "List of undoable operations in the agenda since last refresh.")
2041 (defvar org-agenda-undo-has-started-in nil
2042 "Buffers that have already seen `undo-start' in the current undo sequence.")
2043 (defvar org-agenda-pending-undo-list nil
2044 "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 ;; Remember where this call originated
2163 (setq org-agenda-last-dispatch-buffer (current-buffer))
2164 (kill-local-variable 'org-agenda-current-span)
2165 (unless keys
2166 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2167 keys (car ans)
2168 restriction (cdr ans)))
2169 ;; Establish the restriction, if any
2170 (when (and (not org-agenda-overriding-restriction) restriction)
2171 (put 'org-agenda-files 'org-restrict (list bfn))
2172 (cond
2173 ((eq restriction 'region)
2174 (setq org-agenda-restrict t)
2175 (move-marker org-agenda-restrict-begin (region-beginning))
2176 (move-marker org-agenda-restrict-end (region-end)))
2177 ((eq restriction 'subtree)
2178 (save-excursion
2179 (setq org-agenda-restrict t)
2180 (org-back-to-heading t)
2181 (move-marker org-agenda-restrict-begin (point))
2182 (move-marker org-agenda-restrict-end
2183 (progn (org-end-of-subtree t)))))))
2185 ;; For example the todo list should not need it (but does...)
2186 (cond
2187 ((setq entry (assoc keys org-agenda-custom-commands))
2188 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2189 (progn
2190 (setq type (nth 2 entry) match (eval (nth 3 entry))
2191 lprops (nth 4 entry))
2192 (put 'org-agenda-redo-command 'org-lprops lprops)
2193 (cond
2194 ((eq type 'agenda)
2195 (org-let lprops '(org-agenda-list current-prefix-arg)))
2196 ((eq type 'alltodo)
2197 (org-let lprops '(org-todo-list current-prefix-arg)))
2198 ((eq type 'search)
2199 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2200 ((eq type 'stuck)
2201 (org-let lprops '(org-agenda-list-stuck-projects
2202 current-prefix-arg)))
2203 ((eq type 'tags)
2204 (org-let lprops '(org-tags-view current-prefix-arg match)))
2205 ((eq type 'tags-todo)
2206 (org-let lprops '(org-tags-view '(4) match)))
2207 ((eq type 'todo)
2208 (org-let lprops '(org-todo-list match)))
2209 ((eq type 'tags-tree)
2210 (org-check-for-org-mode)
2211 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2212 ((eq type 'todo-tree)
2213 (org-check-for-org-mode)
2214 (org-let lprops
2215 '(org-occur (concat "^" outline-regexp "[ \t]*"
2216 (regexp-quote match) "\\>"))))
2217 ((eq type 'occur-tree)
2218 (org-check-for-org-mode)
2219 (org-let lprops '(org-occur match)))
2220 ((functionp type)
2221 (org-let lprops '(funcall type match)))
2222 ((fboundp type)
2223 (org-let lprops '(funcall type match)))
2224 (t (error "Invalid custom agenda command type %s" type))))
2225 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2226 ((equal keys "C")
2227 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2228 (customize-variable 'org-agenda-custom-commands))
2229 ((equal keys "a") (call-interactively 'org-agenda-list))
2230 ((equal keys "s") (call-interactively 'org-search-view))
2231 ((equal keys "t") (call-interactively 'org-todo-list))
2232 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2233 ((equal keys "m") (call-interactively 'org-tags-view))
2234 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2235 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2236 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2237 (org-add-hook
2238 'post-command-hook
2239 (lambda ()
2240 (unless (current-message)
2241 (let* ((m (org-agenda-get-any-marker))
2242 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2243 (when note
2244 (message (concat
2245 "FLAGGING-NOTE ([?] for more info): "
2246 (org-add-props
2247 (replace-regexp-in-string
2248 "\\\\n" "//"
2249 (copy-sequence note))
2250 nil 'face 'org-warning)))))))
2251 t t))
2252 ((equal keys "L")
2253 (unless (org-mode-p)
2254 (error "This is not an Org-mode file"))
2255 (unless restriction
2256 (put 'org-agenda-files 'org-restrict (list bfn))
2257 (org-call-with-arg 'org-timeline arg)))
2258 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2259 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2260 ((equal keys "!") (customize-variable 'org-stuck-projects))
2261 (t (error "Invalid agenda key"))))))
2263 (defun org-agenda-normalize-custom-commands (cmds)
2264 (delq nil
2265 (mapcar
2266 (lambda (x)
2267 (cond ((stringp (cdr x)) nil)
2268 ((stringp (nth 1 x)) x)
2269 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2270 (t (cons (car x) (cons "" (cdr x))))))
2271 cmds)))
2273 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2274 "The user interface for selecting an agenda command."
2275 (catch 'exit
2276 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2277 (restrict-ok (and bfn (org-mode-p)))
2278 (region-p (org-region-active-p))
2279 (custom org-agenda-custom-commands)
2280 (selstring "")
2281 restriction second-time
2282 c entry key type match prefixes rmheader header-end custom1 desc
2283 line lines left right n n1)
2284 (save-window-excursion
2285 (delete-other-windows)
2286 (org-switch-to-buffer-other-window " *Agenda Commands*")
2287 (erase-buffer)
2288 (insert (eval-when-compile
2289 (let ((header
2291 Press key for an agenda command: < Buffer, subtree/region restriction
2292 -------------------------------- > Remove restriction
2293 a Agenda for current week or day e Export agenda views
2294 t List of all TODO entries T Entries with special TODO kwd
2295 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2296 L Timeline for current buffer # List stuck projects (!=configure)
2297 s Search for keywords C Configure custom agenda commands
2298 / Multi-occur ? Find :FLAGGED: entries
2300 (start 0))
2301 (while (string-match
2302 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2303 header start)
2304 (setq start (match-end 0))
2305 (add-text-properties (match-beginning 2) (match-end 2)
2306 '(face bold) header))
2307 header)))
2308 (setq header-end (move-marker (make-marker) (point)))
2309 (while t
2310 (setq custom1 custom)
2311 (when (eq rmheader t)
2312 (org-goto-line 1)
2313 (re-search-forward ":" nil t)
2314 (delete-region (match-end 0) (point-at-eol))
2315 (forward-char 1)
2316 (looking-at "-+")
2317 (delete-region (match-end 0) (point-at-eol))
2318 (move-marker header-end (match-end 0)))
2319 (goto-char header-end)
2320 (delete-region (point) (point-max))
2322 ;; Produce all the lines that describe custom commands and prefixes
2323 (setq lines nil)
2324 (while (setq entry (pop custom1))
2325 (setq key (car entry) desc (nth 1 entry)
2326 type (nth 2 entry)
2327 match (nth 3 entry))
2328 (if (> (length key) 1)
2329 (add-to-list 'prefixes (string-to-char key))
2330 (setq line
2331 (format
2332 "%-4s%-14s"
2333 (org-add-props (copy-sequence key)
2334 '(face bold))
2335 (cond
2336 ((string-match "\\S-" desc) desc)
2337 ((eq type 'agenda) "Agenda for current week or day")
2338 ((eq type 'alltodo) "List of all TODO entries")
2339 ((eq type 'search) "Word search")
2340 ((eq type 'stuck) "List of stuck projects")
2341 ((eq type 'todo) "TODO keyword")
2342 ((eq type 'tags) "Tags query")
2343 ((eq type 'tags-todo) "Tags (TODO)")
2344 ((eq type 'tags-tree) "Tags tree")
2345 ((eq type 'todo-tree) "TODO kwd tree")
2346 ((eq type 'occur-tree) "Occur tree")
2347 ((functionp type) (if (symbolp type)
2348 (symbol-name type)
2349 "Lambda expression"))
2350 (t "???"))))
2351 (if org-agenda-menu-show-matcher
2352 (setq line
2353 (concat line ": "
2354 (cond
2355 ((stringp match)
2356 (setq match (copy-sequence match))
2357 (org-add-props match nil 'face 'org-warning))
2358 (match
2359 (format "set of %d commands" (length match)))
2360 (t ""))))
2361 (if (org-string-nw-p match)
2362 (add-text-properties
2363 0 (length line) (list 'help-echo
2364 (concat "Matcher: "match)) line)))
2365 (push line lines)))
2366 (setq lines (nreverse lines))
2367 (when prefixes
2368 (mapc (lambda (x)
2369 (push
2370 (format "%s %s"
2371 (org-add-props (char-to-string x)
2372 nil 'face 'bold)
2373 (or (cdr (assoc (concat selstring
2374 (char-to-string x))
2375 prefix-descriptions))
2376 "Prefix key"))
2377 lines))
2378 prefixes))
2380 ;; Check if we should display in two columns
2381 (if org-agenda-menu-two-column
2382 (progn
2383 (setq n (length lines)
2384 n1 (+ (/ n 2) (mod n 2))
2385 right (nthcdr n1 lines)
2386 left (copy-sequence lines))
2387 (setcdr (nthcdr (1- n1) left) nil))
2388 (setq left lines right nil))
2389 (while left
2390 (insert "\n" (pop left))
2391 (when right
2392 (if (< (current-column) 40)
2393 (move-to-column 40 t)
2394 (insert " "))
2395 (insert (pop right))))
2397 ;; Make the window the right size
2398 (goto-char (point-min))
2399 (if second-time
2400 (if (not (pos-visible-in-window-p (point-max)))
2401 (org-fit-window-to-buffer))
2402 (setq second-time t)
2403 (org-fit-window-to-buffer))
2405 ;; Ask for selection
2406 (message "Press key for agenda command%s:"
2407 (if (or restrict-ok org-agenda-overriding-restriction)
2408 (if org-agenda-overriding-restriction
2409 " (restriction lock active)"
2410 (if restriction
2411 (format " (restricted to %s)" restriction)
2412 " (unrestricted)"))
2413 ""))
2414 (setq c (read-char-exclusive))
2415 (message "")
2416 (cond
2417 ((assoc (char-to-string c) custom)
2418 (setq selstring (concat selstring (char-to-string c)))
2419 (throw 'exit (cons selstring restriction)))
2420 ((memq c prefixes)
2421 (setq selstring (concat selstring (char-to-string c))
2422 prefixes nil
2423 rmheader (or rmheader t)
2424 custom (delq nil (mapcar
2425 (lambda (x)
2426 (if (or (= (length (car x)) 1)
2427 (/= (string-to-char (car x)) c))
2429 (cons (substring (car x) 1) (cdr x))))
2430 custom))))
2431 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2432 (message "Restriction is only possible in Org-mode buffers")
2433 (ding) (sit-for 1))
2434 ((eq c ?1)
2435 (org-agenda-remove-restriction-lock 'noupdate)
2436 (setq restriction 'buffer))
2437 ((eq c ?0)
2438 (org-agenda-remove-restriction-lock 'noupdate)
2439 (setq restriction (if region-p 'region 'subtree)))
2440 ((eq c ?<)
2441 (org-agenda-remove-restriction-lock 'noupdate)
2442 (setq restriction
2443 (cond
2444 ((eq restriction 'buffer)
2445 (if region-p 'region 'subtree))
2446 ((memq restriction '(subtree region))
2447 nil)
2448 (t 'buffer))))
2449 ((eq c ?>)
2450 (org-agenda-remove-restriction-lock 'noupdate)
2451 (setq restriction nil))
2452 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2453 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2454 ((and (> (length selstring) 0) (eq c ?\d))
2455 (delete-window)
2456 (org-agenda-get-restriction-and-command prefix-descriptions))
2458 ((equal c ?q) (error "Abort"))
2459 (t (error "Invalid key %c" c))))))))
2461 (defun org-run-agenda-series (name series)
2462 (org-let (nth 1 series) '(org-prepare-agenda name))
2463 (let* ((org-agenda-multi t)
2464 (redo (list 'org-run-agenda-series name (list 'quote series)))
2465 (cmds (car series))
2466 (gprops (nth 1 series))
2467 match ;; The byte compiler incorrectly complains about this. Keep it!
2468 cmd type lprops)
2469 (while (setq cmd (pop cmds))
2470 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2471 (cond
2472 ((eq type 'agenda)
2473 (org-let2 gprops lprops
2474 '(call-interactively 'org-agenda-list)))
2475 ((eq type 'alltodo)
2476 (org-let2 gprops lprops
2477 '(call-interactively 'org-todo-list)))
2478 ((eq type 'search)
2479 (org-let2 gprops lprops
2480 '(org-search-view current-prefix-arg match nil)))
2481 ((eq type 'stuck)
2482 (org-let2 gprops lprops
2483 '(call-interactively 'org-agenda-list-stuck-projects)))
2484 ((eq type 'tags)
2485 (org-let2 gprops lprops
2486 '(org-tags-view current-prefix-arg match)))
2487 ((eq type 'tags-todo)
2488 (org-let2 gprops lprops
2489 '(org-tags-view '(4) match)))
2490 ((eq type 'todo)
2491 (org-let2 gprops lprops
2492 '(org-todo-list match)))
2493 ((fboundp type)
2494 (org-let2 gprops lprops
2495 '(funcall type match)))
2496 (t (error "Invalid type in command series"))))
2497 (widen)
2498 (setq org-agenda-redo-command redo)
2499 (goto-char (point-min)))
2500 (org-fit-agenda-window)
2501 (org-let (nth 1 series) '(org-finalize-agenda)))
2503 ;;;###autoload
2504 (defmacro org-batch-agenda (cmd-key &rest parameters)
2505 "Run an agenda command in batch mode and send the result to STDOUT.
2506 If CMD-KEY is a string of length 1, it is used as a key in
2507 `org-agenda-custom-commands' and triggers this command. If it is a
2508 longer string it is used as a tags/todo match string.
2509 Parameters are alternating variable names and values that will be bound
2510 before running the agenda command."
2511 (let (pars)
2512 (while parameters
2513 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2514 (if (> (length cmd-key) 2)
2515 (eval (list 'let (nreverse pars)
2516 (list 'org-tags-view nil cmd-key)))
2517 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2518 (set-buffer org-agenda-buffer-name)
2519 (princ (org-encode-for-stdout (buffer-string)))))
2521 ;(defun org-encode-for-stdout (string)
2522 ; (if (fboundp 'encode-coding-string)
2523 ; (encode-coding-string string buffer-file-coding-system)
2524 ; string))
2526 (defun org-encode-for-stdout (string)
2527 string)
2529 (defvar org-agenda-info nil)
2531 ;;;###autoload
2532 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2533 "Run an agenda command in batch mode and send the result to STDOUT.
2534 If CMD-KEY is a string of length 1, it is used as a key in
2535 `org-agenda-custom-commands' and triggers this command. If it is a
2536 longer string it is used as a tags/todo match string.
2537 Parameters are alternating variable names and values that will be bound
2538 before running the agenda command.
2540 The output gives a line for each selected agenda item. Each
2541 item is a list of comma-separated values, like this:
2543 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2545 category The category of the item
2546 head The headline, without TODO kwd, TAGS and PRIORITY
2547 type The type of the agenda entry, can be
2548 todo selected in TODO match
2549 tagsmatch selected in tags match
2550 diary imported from diary
2551 deadline a deadline on given date
2552 scheduled scheduled on given date
2553 timestamp entry has timestamp on given date
2554 closed entry was closed on given date
2555 upcoming-deadline warning about deadline
2556 past-scheduled forwarded scheduled item
2557 block entry has date block including g. date
2558 todo The todo keyword, if any
2559 tags All tags including inherited ones, separated by colons
2560 date The relevant date, like 2007-2-14
2561 time The time, like 15:00-16:50
2562 extra Sting with extra planning info
2563 priority-l The priority letter if any was given
2564 priority-n The computed numerical priority
2565 agenda-day The day in the agenda where this is listed"
2567 (let (pars)
2568 (while parameters
2569 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2570 (push (list 'org-agenda-remove-tags t) pars)
2571 (if (> (length cmd-key) 2)
2572 (eval (list 'let (nreverse pars)
2573 (list 'org-tags-view nil cmd-key)))
2574 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2575 (set-buffer org-agenda-buffer-name)
2576 (let* ((lines (org-split-string (buffer-string) "\n"))
2577 line)
2578 (while (setq line (pop lines))
2579 (catch 'next
2580 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2581 (setq org-agenda-info
2582 (org-fix-agenda-info (text-properties-at 0 line)))
2583 (princ
2584 (org-encode-for-stdout
2585 (mapconcat 'org-agenda-export-csv-mapper
2586 '(org-category txt type todo tags date time extra
2587 priority-letter priority agenda-day)
2588 ",")))
2589 (princ "\n"))))))
2591 (defun org-fix-agenda-info (props)
2592 "Make sure all properties on an agenda item have a canonical form.
2593 This ensures the export commands can easily use it."
2594 (let (tmp re)
2595 (when (setq tmp (plist-get props 'tags))
2596 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2597 (when (setq tmp (plist-get props 'date))
2598 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2599 (let ((calendar-date-display-form '(year "-" month "-" day)))
2600 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2602 (setq tmp (calendar-date-string tmp)))
2603 (setq props (plist-put props 'date tmp)))
2604 (when (setq tmp (plist-get props 'day))
2605 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2606 (let ((calendar-date-display-form '(year "-" month "-" day)))
2607 (setq tmp (calendar-date-string tmp)))
2608 (setq props (plist-put props 'day tmp))
2609 (setq props (plist-put props 'agenda-day tmp)))
2610 (when (setq tmp (plist-get props 'txt))
2611 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2612 (plist-put props 'priority-letter (match-string 1 tmp))
2613 (setq tmp (replace-match "" t t tmp)))
2614 (when (and (setq re (plist-get props 'org-todo-regexp))
2615 (setq re (concat "\\`\\.*" re " ?"))
2616 (string-match re tmp))
2617 (plist-put props 'todo (match-string 1 tmp))
2618 (setq tmp (replace-match "" t t tmp)))
2619 (plist-put props 'txt tmp)))
2620 props)
2622 (defun org-agenda-export-csv-mapper (prop)
2623 (let ((res (plist-get org-agenda-info prop)))
2624 (setq res
2625 (cond
2626 ((not res) "")
2627 ((stringp res) res)
2628 (t (prin1-to-string res))))
2629 (while (string-match "," res)
2630 (setq res (replace-match ";" t t res)))
2631 (org-trim res)))
2634 ;;;###autoload
2635 (defun org-store-agenda-views (&rest parameters)
2636 (interactive)
2637 (eval (list 'org-batch-store-agenda-views)))
2639 ;; FIXME, why is this a macro?????
2640 ;;;###autoload
2641 (defmacro org-batch-store-agenda-views (&rest parameters)
2642 "Run all custom agenda commands that have a file argument."
2643 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2644 (pop-up-frames nil)
2645 (dir default-directory)
2646 pars cmd thiscmdkey files opts cmd-or-set)
2647 (while parameters
2648 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2649 (setq pars (reverse pars))
2650 (save-window-excursion
2651 (while cmds
2652 (setq cmd (pop cmds)
2653 thiscmdkey (car cmd)
2654 cmd-or-set (nth 2 cmd)
2655 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2656 files (nth (if (listp cmd-or-set) 4 5) cmd))
2657 (if (stringp files) (setq files (list files)))
2658 (when files
2659 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2660 (list 'org-agenda nil thiscmdkey)))
2661 (set-buffer org-agenda-buffer-name)
2662 (while files
2663 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2664 (list 'org-write-agenda
2665 (expand-file-name (pop files) dir) nil t))))
2666 (and (get-buffer org-agenda-buffer-name)
2667 (kill-buffer org-agenda-buffer-name)))))))
2669 (defun org-agenda-mark-header-line (pos)
2670 "Mark the line at POS as an agenda structure header."
2671 (save-excursion
2672 (goto-char pos)
2673 (put-text-property (point-at-bol) (point-at-eol)
2674 'org-agenda-structural-header t)
2675 (when org-agenda-title-append
2676 (put-text-property (point-at-bol) (point-at-eol)
2677 'org-agenda-title-append org-agenda-title-append))))
2679 (defvar org-mobile-creating-agendas)
2680 (defun org-write-agenda (file &optional open nosettings)
2681 "Write the current buffer (an agenda view) as a file.
2682 Depending on the extension of the file name, plain text (.txt),
2683 HTML (.html or .htm) or Postscript (.ps) is produced.
2684 If the extension is .ics, run icalendar export over all files used
2685 to construct the agenda and limit the export to entries listed in the
2686 agenda now.
2687 With prefix argument OPEN, open the new file immediately.
2688 If NOSETTINGS is given, do not scope the settings of
2689 `org-agenda-exporter-settings' into the export commands. This is used when
2690 the settings have already been scoped and we do not wish to overrule other,
2691 higher priority settings."
2692 (interactive "FWrite agenda to file: \nP")
2693 (if (not (file-writable-p file))
2694 (error "Cannot write agenda to file %s" file))
2695 (org-let (if nosettings nil org-agenda-exporter-settings)
2696 '(save-excursion
2697 (save-window-excursion
2698 (org-agenda-mark-filtered-text)
2699 (let ((bs (copy-sequence (buffer-string))) beg)
2700 (org-agenda-unmark-filtered-text)
2701 (with-temp-buffer
2702 (rename-buffer "Agenda View" t)
2703 (set-buffer-modified-p nil)
2704 (insert bs)
2705 (org-agenda-remove-marked-text 'org-filtered)
2706 (while (setq beg (text-property-any (point-min) (point-max)
2707 'org-filtered t))
2708 (delete-region
2709 beg (or (next-single-property-change beg 'org-filtered)
2710 (point-max))))
2711 (run-hooks 'org-agenda-before-write-hook)
2712 (cond
2713 ((org-bound-and-true-p org-mobile-creating-agendas)
2714 (org-mobile-write-agenda-for-mobile file))
2715 ((string-match "\\.html?\\'" file)
2716 (require 'htmlize)
2717 (set-buffer (htmlize-buffer (current-buffer)))
2719 (when (and org-agenda-export-html-style
2720 (string-match "<style>" org-agenda-export-html-style))
2721 ;; replace <style> section with org-agenda-export-html-style
2722 (goto-char (point-min))
2723 (kill-region (- (search-forward "<style") 6)
2724 (search-forward "</style>"))
2725 (insert org-agenda-export-html-style))
2726 (write-file file)
2727 (kill-buffer (current-buffer))
2728 (message "HTML written to %s" file))
2729 ((string-match "\\.ps\\'" file)
2730 (require 'ps-print)
2731 (ps-print-buffer-with-faces file)
2732 (message "Postscript written to %s" file))
2733 ((string-match "\\.pdf\\'" file)
2734 (require 'ps-print)
2735 (ps-print-buffer-with-faces
2736 (concat (file-name-sans-extension file) ".ps"))
2737 (call-process "ps2pdf" nil nil nil
2738 (expand-file-name
2739 (concat (file-name-sans-extension file) ".ps"))
2740 (expand-file-name file))
2741 (delete-file (concat (file-name-sans-extension file) ".ps"))
2742 (message "PDF written to %s" file))
2743 ((string-match "\\.ics\\'" file)
2744 (require 'org-icalendar)
2745 (let ((org-agenda-marker-table
2746 (org-create-marker-find-array
2747 (org-agenda-collect-markers)))
2748 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2749 (org-combined-agenda-icalendar-file file))
2750 (apply 'org-export-icalendar 'combine
2751 (org-agenda-files nil 'ifmode))))
2753 (let ((bs (buffer-string)))
2754 (find-file file)
2755 (erase-buffer)
2756 (insert bs)
2757 (save-buffer 0)
2758 (kill-buffer (current-buffer))
2759 (message "Plain text written to %s" file))))))))
2760 (set-buffer org-agenda-buffer-name))
2761 (when open (org-open-file file)))
2763 (defvar org-agenda-filter-overlays nil)
2765 (defun org-agenda-mark-filtered-text ()
2766 "Mark all text hidden by filtering with a text property."
2767 (let ((inhibit-read-only t))
2768 (mapc
2769 (lambda (o)
2770 (when (equal (overlay-buffer o) (current-buffer))
2771 (put-text-property
2772 (overlay-start o) (overlay-end o)
2773 'org-filtered t)))
2774 org-agenda-filter-overlays)))
2776 (defun org-agenda-unmark-filtered-text ()
2777 "Remove the filtering text property."
2778 (let ((inhibit-read-only t))
2779 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2781 (defun org-agenda-remove-marked-text (property &optional value)
2782 "Delete all text marked with VALUE of PROPERTY.
2783 VALUE defaults to t."
2784 (let (beg)
2785 (setq value (or value t))
2786 (while (setq beg (text-property-any (point-min) (point-max)
2787 property value))
2788 (delete-region
2789 beg (or (next-single-property-change beg 'org-filtered)
2790 (point-max))))))
2792 (defun org-agenda-add-entry-text ()
2793 "Add entry text to agenda lines.
2794 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2795 entry text following headings shown in the agenda.
2796 Drawers will be excluded, also the line with scheduling/deadline info."
2797 (when (and (> org-agenda-add-entry-text-maxlines 0)
2798 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2799 (let (m txt)
2800 (goto-char (point-min))
2801 (while (not (eobp))
2802 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2803 (beginning-of-line 2)
2804 (setq txt (org-agenda-get-some-entry-text
2805 m org-agenda-add-entry-text-maxlines " > "))
2806 (end-of-line 1)
2807 (if (string-match "\\S-" txt)
2808 (insert "\n" txt)
2809 (or (eobp) (forward-char 1))))))))
2811 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2812 &rest keep)
2813 "Extract entry text from MARKER, at most N-LINES lines.
2814 This will ignore drawers etc, just get the text.
2815 If INDENT is given, prefix every line with this string. If KEEP is
2816 given, it is a list of symbols, defining stuff that should not be
2817 removed from the entry content. Currently only `planning' is allowed here."
2818 (let (txt drawer-re kwd-time-re ind)
2819 (save-excursion
2820 (with-current-buffer (marker-buffer marker)
2821 (if (not (org-mode-p))
2822 (setq txt "")
2823 (save-excursion
2824 (save-restriction
2825 (widen)
2826 (goto-char marker)
2827 (end-of-line 1)
2828 (setq txt (buffer-substring
2829 (min (1+ (point)) (point-max))
2830 (progn (outline-next-heading) (point)))
2831 drawer-re org-drawer-regexp
2832 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2833 ".*\n?"))
2834 (with-temp-buffer
2835 (insert txt)
2836 (when org-agenda-add-entry-text-descriptive-links
2837 (goto-char (point-min))
2838 (while (org-activate-bracket-links (point-max))
2839 (add-text-properties (match-beginning 0) (match-end 0)
2840 '(face org-link))))
2841 (goto-char (point-min))
2842 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2843 (set-text-properties (match-beginning 0) (match-end 0)
2844 nil))
2845 (goto-char (point-min))
2846 (while (re-search-forward drawer-re nil t)
2847 (delete-region
2848 (match-beginning 0)
2849 (progn (re-search-forward
2850 "^[ \t]*:END:.*\n?" nil 'move)
2851 (point))))
2852 (unless (member 'planning keep)
2853 (goto-char (point-min))
2854 (while (re-search-forward kwd-time-re nil t)
2855 (replace-match "")))
2856 (goto-char (point-min))
2857 (when org-agenda-entry-text-exclude-regexps
2858 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2859 (while (setq re (pop re-list))
2860 (goto-char (point-min))
2861 (while (re-search-forward re nil t)
2862 (replace-match "")))))
2863 (goto-char (point-max))
2864 (skip-chars-backward " \t\n")
2865 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2867 ;; find and remove min common indentation
2868 (goto-char (point-min))
2869 (untabify (point-min) (point-max))
2870 (setq ind (org-get-indentation))
2871 (while (not (eobp))
2872 (unless (looking-at "[ \t]*$")
2873 (setq ind (min ind (org-get-indentation))))
2874 (beginning-of-line 2))
2875 (goto-char (point-min))
2876 (while (not (eobp))
2877 (unless (looking-at "[ \t]*$")
2878 (move-to-column ind)
2879 (delete-region (point-at-bol) (point)))
2880 (beginning-of-line 2))
2882 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2884 (goto-char (point-min))
2885 (when indent
2886 (while (and (not (eobp)) (re-search-forward "^" nil t))
2887 (replace-match indent t t)))
2888 (goto-char (point-min))
2889 (while (looking-at "[ \t]*\n") (replace-match ""))
2890 (goto-char (point-max))
2891 (when (> (org-current-line)
2892 n-lines)
2893 (org-goto-line (1+ n-lines))
2894 (backward-char 1))
2895 (setq txt (buffer-substring (point-min) (point)))))))))
2896 txt))
2898 (defun org-agenda-collect-markers ()
2899 "Collect the markers pointing to entries in the agenda buffer."
2900 (let (m markers)
2901 (save-excursion
2902 (goto-char (point-min))
2903 (while (not (eobp))
2904 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2905 (org-get-at-bol 'org-marker)))
2906 (push m markers))
2907 (beginning-of-line 2)))
2908 (nreverse markers)))
2910 (defun org-create-marker-find-array (marker-list)
2911 "Create a alist of files names with all marker positions in that file."
2912 (let (f tbl m a p)
2913 (while (setq m (pop marker-list))
2914 (setq p (marker-position m)
2915 f (buffer-file-name (or (buffer-base-buffer
2916 (marker-buffer m))
2917 (marker-buffer m))))
2918 (if (setq a (assoc f tbl))
2919 (push (marker-position m) (cdr a))
2920 (push (list f p) tbl)))
2921 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2922 tbl)))
2924 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2925 (defun org-check-agenda-marker-table ()
2926 "Check of the current entry is on the marker list."
2927 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2929 (and (setq a (assoc file org-agenda-marker-table))
2930 (save-match-data
2931 (save-excursion
2932 (org-back-to-heading t)
2933 (member (point) (cdr a)))))))
2935 (defun org-check-for-org-mode ()
2936 "Make sure current buffer is in org-mode. Error if not."
2937 (or (org-mode-p)
2938 (error "Cannot execute org-mode agenda command on buffer in %s"
2939 major-mode)))
2941 (defun org-fit-agenda-window ()
2942 "Fit the window to the buffer size."
2943 (and (memq org-agenda-window-setup '(reorganize-frame))
2944 (fboundp 'fit-window-to-buffer)
2945 (org-fit-window-to-buffer
2947 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2948 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2950 ;;; Agenda prepare and finalize
2952 (defvar org-agenda-multi nil) ; dynamically scoped
2953 (defvar org-agenda-buffer-name "*Org Agenda*")
2954 (defvar org-pre-agenda-window-conf nil)
2955 (defvar org-agenda-columns-active nil)
2956 (defvar org-agenda-name nil)
2957 (defvar org-agenda-filter nil)
2958 (defvar org-agenda-filter-while-redo nil)
2959 (defvar org-agenda-filter-preset nil
2960 "A preset of the tags filter used for secondary agenda filtering.
2961 This must be a list of strings, each string must be a single tag preceded
2962 by \"+\" or \"-\".
2963 This variable should not be set directly, but agenda custom commands can
2964 bind it in the options section. The preset filter is a global property of
2965 the entire agenda view. In a block agenda, it will not work reliably to
2966 define a filter for one of the individual blocks. You need to set it in
2967 the global options and expect it to be applied to the entire view.")
2969 (defun org-prepare-agenda (&optional name)
2970 (setq org-todo-keywords-for-agenda nil)
2971 (setq org-done-keywords-for-agenda nil)
2972 (setq org-drawers-for-agenda nil)
2973 (unless org-agenda-persistent-filter
2974 (setq org-agenda-filter nil))
2975 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2976 (if org-agenda-multi
2977 (progn
2978 (setq buffer-read-only nil)
2979 (goto-char (point-max))
2980 (unless (or (bobp) org-agenda-compact-blocks)
2981 (insert "\n"
2982 (if (stringp org-agenda-block-separator)
2983 org-agenda-block-separator
2984 (make-string (window-width) org-agenda-block-separator))
2985 "\n"))
2986 (narrow-to-region (point) (point-max)))
2987 (org-agenda-reset-markers)
2988 (setq org-agenda-contributing-files nil)
2989 (setq org-agenda-columns-active nil)
2990 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2991 (setq org-todo-keywords-for-agenda
2992 (org-uniquify org-todo-keywords-for-agenda))
2993 (setq org-done-keywords-for-agenda
2994 (org-uniquify org-done-keywords-for-agenda))
2995 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2996 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2997 (awin (get-buffer-window abuf)))
2998 (cond
2999 ((equal (current-buffer) abuf) nil)
3000 (awin (select-window awin))
3001 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3002 ((equal org-agenda-window-setup 'current-window)
3003 (switch-to-buffer abuf))
3004 ((equal org-agenda-window-setup 'other-window)
3005 (org-switch-to-buffer-other-window abuf))
3006 ((equal org-agenda-window-setup 'other-frame)
3007 (switch-to-buffer-other-frame abuf))
3008 ((equal org-agenda-window-setup 'reorganize-frame)
3009 (delete-other-windows)
3010 (org-switch-to-buffer-other-window abuf)))
3011 ;; additional test in case agenda is invoked from within agenda
3012 ;; buffer via elisp link
3013 (unless (equal (current-buffer) abuf)
3014 (switch-to-buffer abuf)))
3015 (setq buffer-read-only nil)
3016 (let ((inhibit-read-only t)) (erase-buffer))
3017 (org-agenda-mode)
3018 (and name (not org-agenda-name)
3019 (org-set-local 'org-agenda-name name)))
3020 (setq buffer-read-only nil))
3022 (defun org-finalize-agenda ()
3023 "Finishing touch for the agenda buffer, called just before displaying it."
3024 (unless org-agenda-multi
3025 (save-excursion
3026 (let ((inhibit-read-only t))
3027 (goto-char (point-min))
3028 (while (org-activate-bracket-links (point-max))
3029 (add-text-properties (match-beginning 0) (match-end 0)
3030 '(face org-link)))
3031 (org-agenda-align-tags)
3032 (unless org-agenda-with-colors
3033 (remove-text-properties (point-min) (point-max) '(face nil))))
3034 (if (and (boundp 'org-agenda-overriding-columns-format)
3035 org-agenda-overriding-columns-format)
3036 (org-set-local 'org-agenda-overriding-columns-format
3037 org-agenda-overriding-columns-format))
3038 (if (and (boundp 'org-agenda-view-columns-initially)
3039 org-agenda-view-columns-initially)
3040 (org-agenda-columns))
3041 (when org-agenda-fontify-priorities
3042 (org-agenda-fontify-priorities))
3043 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3044 (org-agenda-dim-blocked-tasks))
3045 (org-agenda-mark-clocking-task)
3046 (when org-agenda-entry-text-mode
3047 (org-agenda-entry-text-hide)
3048 (org-agenda-entry-text-show))
3049 (if (functionp 'org-habit-insert-consistency-graphs)
3050 (org-habit-insert-consistency-graphs))
3051 (run-hooks 'org-finalize-agenda-hook)
3052 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3053 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3054 (org-agenda-filter-apply org-agenda-filter))
3057 (defun org-agenda-mark-clocking-task ()
3058 "Mark the current clock entry in the agenda if it is present."
3059 (mapc (lambda (o)
3060 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3061 (delete-overlay o)))
3062 (overlays-in (point-min) (point-max)))
3063 (when (marker-buffer org-clock-hd-marker)
3064 (save-excursion
3065 (goto-char (point-min))
3066 (let (s ov)
3067 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3068 (goto-char s)
3069 (when (equal (org-get-at-bol 'org-hd-marker)
3070 org-clock-hd-marker)
3071 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3072 (overlay-put ov 'type 'org-agenda-clocking)
3073 (overlay-put ov 'face 'org-agenda-clocking)
3074 (overlay-put ov 'help-echo
3075 "The clock is running in this item")))))))
3077 (defun org-agenda-fontify-priorities ()
3078 "Make highest priority lines bold, and lowest italic."
3079 (interactive)
3080 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3081 (delete-overlay o)))
3082 (overlays-in (point-min) (point-max)))
3083 (save-excursion
3084 (let ((inhibit-read-only t)
3085 b e p ov h l)
3086 (goto-char (point-min))
3087 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3088 (setq h (or (get-char-property (point) 'org-highest-priority)
3089 org-highest-priority)
3090 l (or (get-char-property (point) 'org-lowest-priority)
3091 org-lowest-priority)
3092 p (string-to-char (match-string 1))
3093 b (match-beginning 0)
3094 e (if (eq org-agenda-fontify-priorities 'cookies)
3095 (match-end 0)
3096 (point-at-eol))
3097 ov (make-overlay b e))
3098 (overlay-put
3099 ov 'face
3100 (cond ((org-face-from-face-or-color
3101 'priority nil
3102 (cdr (assoc p org-priority-faces))))
3103 ((and (listp org-agenda-fontify-priorities)
3104 (org-face-from-face-or-color
3105 'priority nil
3106 (cdr (assoc p org-agenda-fontify-priorities)))))
3107 ((equal p l) 'italic)
3108 ((equal p h) 'bold)))
3109 (overlay-put ov 'org-type 'org-priority)))))
3111 (defun org-agenda-dim-blocked-tasks ()
3112 "Dim currently blocked TODO's in the agenda display."
3113 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3114 (delete-overlay o)))
3115 (overlays-in (point-min) (point-max)))
3116 (save-excursion
3117 (let ((inhibit-read-only t)
3118 (org-depend-tag-blocked nil)
3119 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3120 org-blocked-by-checkboxes
3121 invis1 b e p ov h l)
3122 (goto-char (point-min))
3123 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3124 (and pos (goto-char (1+ pos))))
3125 (setq org-blocked-by-checkboxes nil invis1 invis)
3126 (let ((marker (org-get-at-bol 'org-hd-marker)))
3127 (when (and marker
3128 (not (with-current-buffer (marker-buffer marker)
3129 (save-excursion
3130 (goto-char marker)
3131 (if (org-entry-get nil "NOBLOCKING")
3132 t ;; Never block this entry
3133 (run-hook-with-args-until-failure
3134 'org-blocker-hook
3135 (list :type 'todo-state-change
3136 :position marker
3137 :from 'todo
3138 :to 'done)))))))
3139 (if org-blocked-by-checkboxes (setq invis1 nil))
3140 (setq b (if invis1
3141 (max (point-min) (1- (point-at-bol)))
3142 (point-at-bol))
3143 e (point-at-eol)
3144 ov (make-overlay b e))
3145 (if invis1
3146 (overlay-put ov 'invisible t)
3147 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3148 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3150 (defvar org-agenda-skip-function nil
3151 "Function to be called at each match during agenda construction.
3152 If this function returns nil, the current match should not be skipped.
3153 Otherwise, the function must return a position from where the search
3154 should be continued.
3155 This may also be a Lisp form, it will be evaluated.
3156 Never set this variable using `setq' or so, because then it will apply
3157 to all future agenda commands. If you do want a global skipping condition,
3158 use the option `org-agenda-skip-function-global' instead.
3159 The correct usage for `org-agenda-skip-function' is to bind it with
3160 `let' to scope it dynamically into the agenda-constructing command.
3161 A good way to set it is through options in `org-agenda-custom-commands'.")
3163 (defun org-agenda-skip ()
3164 "Throw to `:skip' in places that should be skipped.
3165 Also moves point to the end of the skipped region, so that search can
3166 continue from there."
3167 (let ((p (point-at-bol)) to)
3168 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3169 (get-text-property p :org-archived)
3170 (org-end-of-subtree t)
3171 (throw :skip t))
3172 (and org-agenda-skip-comment-trees
3173 (get-text-property p :org-comment)
3174 (org-end-of-subtree t)
3175 (throw :skip t))
3176 (if (equal (char-after p) ?#) (throw :skip t))
3177 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3178 (org-agenda-skip-eval org-agenda-skip-function)))
3179 (goto-char to)
3180 (throw :skip t))))
3182 (defun org-agenda-skip-eval (form)
3183 "If FORM is a function or a list, call (or eval) is and return result.
3184 `save-excursion' and `save-match-data' are wrapped around the call, so point
3185 and match data are returned to the previous state no matter what these
3186 functions do."
3187 (let (fp)
3188 (and form
3189 (or (setq fp (functionp form))
3190 (consp form))
3191 (save-excursion
3192 (save-match-data
3193 (if fp
3194 (funcall form)
3195 (eval form)))))))
3197 (defvar org-agenda-markers nil
3198 "List of all currently active markers created by `org-agenda'.")
3199 (defvar org-agenda-last-marker-time (org-float-time)
3200 "Creation time of the last agenda marker.")
3202 (defun org-agenda-new-marker (&optional pos)
3203 "Return a new agenda marker.
3204 Org-mode keeps a list of these markers and resets them when they are
3205 no longer in use."
3206 (let ((m (copy-marker (or pos (point)))))
3207 (setq org-agenda-last-marker-time (org-float-time))
3208 (push m org-agenda-markers)
3211 (defun org-agenda-reset-markers ()
3212 "Reset markers created by `org-agenda'."
3213 (while org-agenda-markers
3214 (move-marker (pop org-agenda-markers) nil)))
3216 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3217 "Save relative positions of markers in region."
3218 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3219 org-agenda-markers))
3221 ;;; Entry text mode
3223 (defun org-agenda-entry-text-show-here ()
3224 "Add some text from the entry as context to the current line."
3225 (let (m txt o)
3226 (setq m (org-get-at-bol 'org-hd-marker))
3227 (unless (marker-buffer m)
3228 (error "No marker points to an entry here"))
3229 (setq txt (concat "\n" (org-no-properties
3230 (org-agenda-get-some-entry-text
3231 m org-agenda-entry-text-maxlines " > "))))
3232 (when (string-match "\\S-" txt)
3233 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3234 (overlay-put o 'evaporate t)
3235 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3236 (overlay-put o 'after-string txt))))
3238 (defun org-agenda-entry-text-show ()
3239 "Add entry context for all agenda lines."
3240 (interactive)
3241 (save-excursion
3242 (goto-char (point-max))
3243 (beginning-of-line 1)
3244 (while (not (bobp))
3245 (when (org-get-at-bol 'org-hd-marker)
3246 (org-agenda-entry-text-show-here))
3247 (beginning-of-line 0))))
3249 (defun org-agenda-entry-text-hide ()
3250 "Remove any shown entry context."
3251 (delq nil
3252 (mapcar (lambda (o)
3253 (if (eq (overlay-get o 'org-overlay-type)
3254 'agenda-entry-content)
3255 (progn (delete-overlay o) t)))
3256 (overlays-in (point-min) (point-max)))))
3258 (defun org-agenda-get-day-face (date)
3259 "Return the face DATE should be displayed with."
3260 (or (and (functionp org-agenda-day-face-function)
3261 (funcall org-agenda-day-face-function date))
3262 (cond ((org-agenda-todayp date)
3263 'org-agenda-date-today)
3264 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3265 'org-agenda-date-weekend)
3266 (t 'org-agenda-date))))
3268 ;;; Agenda timeline
3270 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3272 (defun org-timeline (&optional include-all)
3273 "Show a time-sorted view of the entries in the current org file.
3274 Only entries with a time stamp of today or later will be listed. With
3275 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3276 under the current date.
3277 If the buffer contains an active region, only check the region for
3278 dates."
3279 (interactive "P")
3280 (org-compile-prefix-format 'timeline)
3281 (org-set-sorting-strategy 'timeline)
3282 (let* ((dopast t)
3283 (dotodo include-all)
3284 (doclosed org-agenda-show-log)
3285 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3286 (current-buffer))))
3287 (date (calendar-current-date))
3288 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3289 (end (if (org-region-active-p) (region-end) (point-max)))
3290 (day-numbers (org-get-all-dates beg end 'no-ranges
3291 t doclosed ; always include today
3292 org-timeline-show-empty-dates))
3293 (org-deadline-warning-days 0)
3294 (org-agenda-only-exact-dates t)
3295 (today (org-today))
3296 (past t)
3297 args
3298 s e rtn d emptyp)
3299 (setq org-agenda-redo-command
3300 (list 'progn
3301 (list 'org-switch-to-buffer-other-window (current-buffer))
3302 (list 'org-timeline (list 'quote include-all))))
3303 (if (not dopast)
3304 ;; Remove past dates from the list of dates.
3305 (setq day-numbers (delq nil (mapcar (lambda(x)
3306 (if (>= x today) x nil))
3307 day-numbers))))
3308 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3309 (if doclosed (push :closed args))
3310 (push :timestamp args)
3311 (push :deadline args)
3312 (push :scheduled args)
3313 (push :sexp args)
3314 (if dotodo (push :todo args))
3315 (insert "Timeline of file " entry "\n")
3316 (add-text-properties (point-min) (point)
3317 (list 'face 'org-agenda-structure))
3318 (org-agenda-mark-header-line (point-min))
3319 (while (setq d (pop day-numbers))
3320 (if (and (listp d) (eq (car d) :omitted))
3321 (progn
3322 (setq s (point))
3323 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3324 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3325 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3326 (if (and (>= d today)
3327 dopast
3328 past)
3329 (progn
3330 (setq past nil)
3331 (insert (make-string 79 ?-) "\n")))
3332 (setq date (calendar-gregorian-from-absolute d))
3333 (setq s (point))
3334 (setq rtn (and (not emptyp)
3335 (apply 'org-agenda-get-day-entries entry
3336 date args)))
3337 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3338 (progn
3339 (insert
3340 (if (stringp org-agenda-format-date)
3341 (format-time-string org-agenda-format-date
3342 (org-time-from-absolute date))
3343 (funcall org-agenda-format-date date))
3344 "\n")
3345 (put-text-property s (1- (point)) 'face
3346 (org-agenda-get-day-face date))
3347 (put-text-property s (1- (point)) 'org-date-line t)
3348 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3349 (if (equal d today)
3350 (put-text-property s (1- (point)) 'org-today t))
3351 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3352 (put-text-property s (1- (point)) 'day d)))))
3353 (goto-char (point-min))
3354 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3355 (point-min)))
3356 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3357 (org-finalize-agenda)
3358 (setq buffer-read-only t)))
3360 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3361 "Return a list of all relevant day numbers from BEG to END buffer positions.
3362 If NO-RANGES is non-nil, include only the start and end dates of a range,
3363 not every single day in the range. If FORCE-TODAY is non-nil, make
3364 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3365 inactive time stamps (those in square brackets) are included.
3366 When EMPTY is non-nil, also include days without any entries."
3367 (let ((re (concat
3368 (if pre-re pre-re "")
3369 (if inactive org-ts-regexp-both org-ts-regexp)))
3370 dates dates1 date day day1 day2 ts1 ts2)
3371 (if force-today
3372 (setq dates (list (org-today))))
3373 (save-excursion
3374 (goto-char beg)
3375 (while (re-search-forward re end t)
3376 (setq day (time-to-days (org-time-string-to-time
3377 (substring (match-string 1) 0 10))))
3378 (or (memq day dates) (push day dates)))
3379 (unless no-ranges
3380 (goto-char beg)
3381 (while (re-search-forward org-tr-regexp end t)
3382 (setq ts1 (substring (match-string 1) 0 10)
3383 ts2 (substring (match-string 2) 0 10)
3384 day1 (time-to-days (org-time-string-to-time ts1))
3385 day2 (time-to-days (org-time-string-to-time ts2)))
3386 (while (< (setq day1 (1+ day1)) day2)
3387 (or (memq day1 dates) (push day1 dates)))))
3388 (setq dates (sort dates '<))
3389 (when empty
3390 (while (setq day (pop dates))
3391 (setq day2 (car dates))
3392 (push day dates1)
3393 (when (and day2 empty)
3394 (if (or (eq empty t)
3395 (and (numberp empty) (<= (- day2 day) empty)))
3396 (while (< (setq day (1+ day)) day2)
3397 (push (list day) dates1))
3398 (push (cons :omitted (- day2 day)) dates1))))
3399 (setq dates (nreverse dates1)))
3400 dates)))
3402 ;;; Agenda Daily/Weekly
3404 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3405 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3406 "Custom commands can set this variable in the options section.")
3407 (defvar org-agenda-last-arguments nil
3408 "The arguments of the previous call to `org-agenda'.")
3409 (defvar org-starting-day nil) ; local variable in the agenda buffer
3410 (defvar org-agenda-current-span nil
3411 "The current span used in the agenda view.") ; local variable in the agenda buffer
3412 (defvar org-include-all-loc nil) ; local variable
3414 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3415 "List of types searched for when creating the daily/weekly agenda.
3416 This variable is a list of symbols that controls the types of
3417 items that appear in the daily/weekly agenda. Allowed symbols in this
3418 list are are
3420 :timestamp List items containing a date stamp or date range matching
3421 the selected date. This includes sexp entries in
3422 angular brackets.
3424 :sexp List entries resulting from plain diary-like sexps.
3426 :deadline List deadline due on that date. When the date is today,
3427 also list any deadlines past due, or due within
3428 `org-deadline-warning-days'. `:deadline' must appear before
3429 `:scheduled' if the setting of
3430 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3431 any effect.
3433 :scheduled List all items which are scheduled for the given date.
3434 The diary for *today* also contains items which were
3435 scheduled earlier and are not yet marked DONE.
3437 By default, all four types are turned on.
3439 Never set this variable globally using `setq', because then it
3440 will apply to all future agenda commands. Instead, bind it with
3441 `let' to scope it dynamically into the the agenda-constructing
3442 command. A good way to set it is through options in
3443 `org-agenda-custom-commands'. For a more flexible (though
3444 somewhat less efficient) way of determining what is included in
3445 the daily/weekly agenda, see `org-agenda-skip-function'.")
3447 ;;;###autoload
3448 (defun org-agenda-list (&optional include-all start-day span)
3449 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3450 The view will be for the current day or week, but from the overview buffer
3451 you will be able to go to other days/weeks.
3453 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3454 all unfinished TODO items will also be shown, before the agenda.
3455 This feature is considered obsolete, please use the TODO list or a block
3456 agenda instead.
3458 With a numeric prefix argument in an interactive call, the agenda will
3459 span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
3460 the number of days. SPAN defaults to `org-agenda-span'.
3462 START-DAY defaults to TODAY, or to the most recent match for the weekday
3463 given in `org-agenda-start-on-weekday'."
3464 (interactive "P")
3465 (if (and (integerp include-all) (> include-all 0))
3466 (setq span include-all include-all nil))
3467 (setq start-day (or start-day org-agenda-start-day))
3468 (if org-agenda-overriding-arguments
3469 (setq include-all (car org-agenda-overriding-arguments)
3470 start-day (nth 1 org-agenda-overriding-arguments)
3471 span (nth 2 org-agenda-overriding-arguments)))
3472 (if (stringp start-day)
3473 ;; Convert to an absolute day number
3474 (setq start-day (time-to-days (org-read-date nil t start-day))))
3475 (setq org-agenda-last-arguments (list include-all start-day span))
3476 (org-compile-prefix-format 'agenda)
3477 (org-set-sorting-strategy 'agenda)
3478 (let* ((span (org-agenda-ndays-to-span (or span
3479 org-agenda-current-span
3480 org-agenda-ndays
3481 org-agenda-span)))
3482 (today (org-today))
3483 (sd (or start-day today))
3484 (ndays (org-agenda-span-to-ndays span sd))
3485 (org-agenda-start-on-weekday
3486 (if (eq ndays 7)
3487 org-agenda-start-on-weekday))
3488 (thefiles (org-agenda-files nil 'ifmode))
3489 (files thefiles)
3490 (start (if (or (null org-agenda-start-on-weekday)
3491 (< ndays 7))
3493 (let* ((nt (calendar-day-of-week
3494 (calendar-gregorian-from-absolute sd)))
3495 (n1 org-agenda-start-on-weekday)
3496 (d (- nt n1)))
3497 (- sd (+ (if (< d 0) 7 0) d)))))
3498 (day-numbers (list start))
3499 (day-cnt 0)
3500 (inhibit-redisplay (not debug-on-error))
3501 s e rtn rtnall file date d start-pos end-pos todayp
3502 clocktable-start clocktable-end filter)
3503 (setq org-agenda-redo-command
3504 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3505 (dotimes (n (1- ndays))
3506 (push (1+ (car day-numbers)) day-numbers))
3507 (setq day-numbers (nreverse day-numbers))
3508 (setq clocktable-start (car day-numbers)
3509 clocktable-end (1+ (or (org-last day-numbers) 0)))
3510 (org-prepare-agenda "Day/Week")
3511 (org-set-local 'org-starting-day (car day-numbers))
3512 (org-set-local 'org-include-all-loc include-all)
3513 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3514 (when (and (or include-all org-agenda-include-all-todo)
3515 (member today day-numbers))
3516 (setq files thefiles
3517 rtnall nil)
3518 (while (setq file (pop files))
3519 (catch 'nextfile
3520 (org-check-agenda-file file)
3521 (setq date (calendar-gregorian-from-absolute today)
3522 rtn (org-agenda-get-day-entries
3523 file date :todo))
3524 (setq rtnall (append rtnall rtn))))
3525 (when rtnall
3526 (insert "All currently open TODO items:\n")
3527 (add-text-properties (point-min) (1- (point))
3528 (list 'face 'org-agenda-structure
3529 'short-heading "All TODO items"))
3530 (org-agenda-mark-header-line (point-min))
3531 (insert (org-finalize-agenda-entries rtnall) "\n")))
3532 (unless org-agenda-compact-blocks
3533 (let* ((d1 (car day-numbers))
3534 (d2 (org-last day-numbers))
3535 (w1 (org-days-to-iso-week d1))
3536 (w2 (org-days-to-iso-week d2)))
3537 (setq s (point))
3538 (if org-agenda-overriding-header
3539 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3540 nil 'face 'org-agenda-structure) "\n")
3541 (insert (org-agenda-span-name span)
3542 "-agenda"
3543 (if (< (- d2 d1) 350)
3544 (if (= w1 w2)
3545 (format " (W%02d)" w1)
3546 (format " (W%02d-W%02d)" w1 w2))
3548 ":\n")))
3549 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3550 'org-date-line t))
3551 (org-agenda-mark-header-line s))
3552 (while (setq d (pop day-numbers))
3553 (setq date (calendar-gregorian-from-absolute d)
3554 s (point))
3555 (if (or (setq todayp (= d today))
3556 (and (not start-pos) (= d sd)))
3557 (setq start-pos (point))
3558 (if (and start-pos (not end-pos))
3559 (setq end-pos (point))))
3560 (setq files thefiles
3561 rtnall nil)
3562 (while (setq file (pop files))
3563 (catch 'nextfile
3564 (org-check-agenda-file file)
3565 (let ((org-agenda-entry-types org-agenda-entry-types))
3566 (unless org-agenda-include-deadlines
3567 (setq org-agenda-entry-types
3568 (delq :deadline org-agenda-entry-types)))
3569 (cond
3570 ((eq org-agenda-show-log 'only)
3571 (setq rtn (org-agenda-get-day-entries
3572 file date :closed)))
3573 (org-agenda-show-log
3574 (setq rtn (apply 'org-agenda-get-day-entries
3575 file date
3576 (append '(:closed) org-agenda-entry-types))))
3578 (setq rtn (apply 'org-agenda-get-day-entries
3579 file date
3580 org-agenda-entry-types)))))
3581 (setq rtnall (append rtnall rtn))))
3582 (if org-agenda-include-diary
3583 (let ((org-agenda-search-headline-for-time t))
3584 (require 'diary-lib)
3585 (setq rtn (org-get-entries-from-diary date))
3586 (setq rtnall (append rtnall rtn))))
3587 (if (or rtnall org-agenda-show-all-dates)
3588 (progn
3589 (setq day-cnt (1+ day-cnt))
3590 (insert
3591 (if (stringp org-agenda-format-date)
3592 (format-time-string org-agenda-format-date
3593 (org-time-from-absolute date))
3594 (funcall org-agenda-format-date date))
3595 "\n")
3596 (put-text-property s (1- (point)) 'face
3597 (org-agenda-get-day-face date))
3598 (put-text-property s (1- (point)) 'org-date-line t)
3599 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3600 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3601 (when todayp
3602 (put-text-property s (1- (point)) 'org-today t))
3603 (if rtnall (insert
3604 (org-finalize-agenda-entries
3605 (org-agenda-add-time-grid-maybe
3606 rtnall ndays todayp))
3607 "\n"))
3608 (put-text-property s (1- (point)) 'day d)
3609 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3610 (when (and org-agenda-clockreport-mode clocktable-start)
3611 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3612 ;; the above line is to ensure the restricted range!
3613 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3614 tbl)
3615 (setq p (org-plist-delete p :block))
3616 (setq p (plist-put p :tstart clocktable-start))
3617 (setq p (plist-put p :tend clocktable-end))
3618 (setq p (plist-put p :scope 'agenda))
3619 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3620 (setq filter (or org-agenda-filter-while-redo
3621 (get 'org-agenda-filter :preset-filter))))
3622 (setq p (plist-put p :tags (mapconcat (lambda (x)
3623 (if (string-match "[<>=]" x)
3626 filter ""))))
3627 (setq tbl (apply 'org-get-clocktable p))
3628 (insert tbl)))
3629 (goto-char (point-min))
3630 (or org-agenda-multi (org-fit-agenda-window))
3631 (unless (and (pos-visible-in-window-p (point-min))
3632 (pos-visible-in-window-p (point-max)))
3633 (goto-char (1- (point-max)))
3634 (recenter -1)
3635 (if (not (pos-visible-in-window-p (or start-pos 1)))
3636 (progn
3637 (goto-char (or start-pos 1))
3638 (recenter 1))))
3639 (goto-char (or start-pos 1))
3640 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3641 (org-finalize-agenda)
3642 (setq buffer-read-only t)
3643 (message "")))
3645 (defun org-agenda-ndays-to-span (n)
3646 "Return a span symbol for a span of N days, or N if none matches."
3647 (cond ((symbolp n) n)
3648 ((= n 1) 'day)
3649 ((= n 7) 'week)
3650 (t n)))
3652 (defun org-agenda-span-to-ndays (span start-day)
3653 "Return ndays from SPAN starting at START-DAY."
3654 (cond ((numberp span) span)
3655 ((eq span 'day) 1)
3656 ((eq span 'week) 7)
3657 ((eq span 'month)
3658 (let ((date (calendar-gregorian-from-absolute start-day)))
3659 (calendar-last-day-of-month (car date) (caddr date))))
3660 ((eq span 'year)
3661 (let ((date (calendar-gregorian-from-absolute start-day)))
3662 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3664 (defun org-agenda-span-name (span)
3665 "Return a SPAN name."
3666 (if (null span)
3668 (if (symbolp span)
3669 (capitalize (symbol-name span))
3670 (format "%d days" span))))
3672 ;;; Agenda word search
3674 (defvar org-agenda-search-history nil)
3675 (defvar org-todo-only nil)
3677 (defvar org-search-syntax-table nil
3678 "Special syntax table for org-mode search.
3679 In this table, we have single quotes not as word constituents, to
3680 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3682 (defun org-search-syntax-table ()
3683 (unless org-search-syntax-table
3684 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3685 (modify-syntax-entry ?' "." org-search-syntax-table)
3686 (modify-syntax-entry ?` "." org-search-syntax-table))
3687 org-search-syntax-table)
3689 (defvar org-agenda-last-search-view-search-was-boolean nil)
3691 ;;;###autoload
3692 (defun org-search-view (&optional todo-only string edit-at)
3693 "Show all entries that contain a phrase or words or regular expressions.
3695 With optional prefix argument TODO-ONLY, only consider entries that are
3696 TODO entries. The argument STRING can be used to pass a default search
3697 string into this function. If EDIT-AT is non-nil, it means that the
3698 user should get a chance to edit this string, with cursor at position
3699 EDIT-AT.
3701 The search string can be viewed either as a phrase that should be found as
3702 is, or it can be broken into a number of snippets, each of which must match
3703 in a Boolean way to select an entry. The default depends on the variable
3704 `org-agenda-search-view-always-boolean'.
3705 Even if this is turned off (the default) you can always switch to
3706 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3708 The default is a direct search of the whole phrase, where each space in
3709 the search string can expand to an arbitrary amount of whitespace,
3710 including newlines.
3712 If using a Boolean search, the search string is split on whitespace and
3713 each snippet is searched separately, with logical AND to select an entry.
3714 Words prefixed with a minus must *not* occur in the entry. Words without
3715 a prefix or prefixed with a plus must occur in the entry. Matching is
3716 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3717 match whole words, not parts of a word) if
3718 `org-agenda-search-view-force-full-words' is set (default is nil).
3720 Boolean search snippets enclosed by curly braces are interpreted as
3721 regular expressions that must or (when preceded with \"-\") must not
3722 match in the entry. Snippets enclosed into double quotes will be taken
3723 as a whole, to include whitespace.
3725 - If the search string starts with an asterisk, search only in headlines.
3726 - If (possibly after the leading star) the search string starts with an
3727 exclamation mark, this also means to look at TODO entries only, an effect
3728 that can also be achieved with a prefix argument.
3729 - If (possibly after star and exclamation mark) the search string starts
3730 with a colon, this will mean that the (non-regexp) snippets of the
3731 Boolean search must match as full words.
3733 This command searches the agenda files, and in addition the files listed
3734 in `org-agenda-text-search-extra-files'."
3735 (interactive "P")
3736 (org-compile-prefix-format 'search)
3737 (org-set-sorting-strategy 'search)
3738 (org-prepare-agenda "SEARCH")
3739 (let* ((props (list 'face nil
3740 'done-face 'org-agenda-done
3741 'org-not-done-regexp org-not-done-regexp
3742 'org-todo-regexp org-todo-regexp
3743 'org-complex-heading-regexp org-complex-heading-regexp
3744 'mouse-face 'highlight
3745 'help-echo (format "mouse-2 or RET jump to location")))
3746 (full-words org-agenda-search-view-force-full-words)
3747 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3748 regexp rtn rtnall files file pos
3749 marker category tags c neg re boolean
3750 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3751 (unless (and (not edit-at)
3752 (stringp string)
3753 (string-match "\\S-" string))
3754 (setq string (read-string
3755 (if org-agenda-search-view-always-boolean
3756 "[+-]Word/{Regexp} ...: "
3757 "Phrase, or [+-]Word/{Regexp} ...: ")
3758 (cond
3759 ((integerp edit-at) (cons string edit-at))
3760 (edit-at string))
3761 'org-agenda-search-history)))
3762 (org-set-local 'org-todo-only todo-only)
3763 (setq org-agenda-redo-command
3764 (list 'org-search-view (if todo-only t nil) string
3765 '(if current-prefix-arg 1 nil)))
3766 (setq org-agenda-query-string string)
3768 (if (equal (string-to-char string) ?*)
3769 (setq hdl-only t
3770 words (substring string 1))
3771 (setq words string))
3772 (when (equal (string-to-char words) ?!)
3773 (setq todo-only t
3774 words (substring words 1)))
3775 (when (equal (string-to-char words) ?:)
3776 (setq full-words t
3777 words (substring words 1)))
3778 (if (or org-agenda-search-view-always-boolean
3779 (member (string-to-char words) '(?- ?+ ?\{)))
3780 (setq boolean t))
3781 (setq words (org-split-string words))
3782 (let (www w)
3783 (while (setq w (pop words))
3784 (while (and (string-match "\\\\\\'" w) words)
3785 (setq w (concat (substring w 0 -1) " " (pop words))))
3786 (push w www))
3787 (setq words (nreverse www) www nil)
3788 (while (setq w (pop words))
3789 (when (and (string-match "\\`[-+]?{" w)
3790 (not (string-match "}\\'" w)))
3791 (while (and words (not (string-match "}\\'" (car words))))
3792 (setq w (concat w " " (pop words))))
3793 (setq w (concat w " " (pop words))))
3794 (push w www))
3795 (setq words (nreverse www)))
3796 (setq org-agenda-last-search-view-search-was-boolean boolean)
3797 (when boolean
3798 (let (wds w)
3799 (while (setq w (pop words))
3800 (if (or (equal (substring w 0 1) "\"")
3801 (and (> (length w) 1)
3802 (member (substring w 0 1) '("+" "-"))
3803 (equal (substring w 1 2) "\"")))
3804 (while (and words (not (equal (substring w -1) "\"")))
3805 (setq w (concat w " " (pop words)))))
3806 (and (string-match "\\`\\([-+]?\\)\"" w)
3807 (setq w (replace-match "\\1" nil nil w)))
3808 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3809 (push w wds))
3810 (setq words (nreverse wds))))
3811 (if boolean
3812 (mapc (lambda (w)
3813 (setq c (string-to-char w))
3814 (if (equal c ?-)
3815 (setq neg t w (substring w 1))
3816 (if (equal c ?+)
3817 (setq neg nil w (substring w 1))
3818 (setq neg nil)))
3819 (if (string-match "\\`{.*}\\'" w)
3820 (setq re (substring w 1 -1))
3821 (if full-words
3822 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3823 (setq re (regexp-quote (downcase w)))))
3824 (if neg (push re regexps-) (push re regexps+)))
3825 words)
3826 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3827 regexps+))
3828 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3829 (if (not regexps+)
3830 (setq regexp (concat "^" org-outline-regexp))
3831 (setq regexp (pop regexps+))
3832 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3833 regexp))))
3834 (setq files (org-agenda-files nil 'ifmode))
3835 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3836 (pop org-agenda-text-search-extra-files)
3837 (setq files (org-add-archive-files files)))
3838 (setq files (append files org-agenda-text-search-extra-files)
3839 rtnall nil)
3840 (while (setq file (pop files))
3841 (setq ee nil)
3842 (catch 'nextfile
3843 (org-check-agenda-file file)
3844 (setq buffer (if (file-exists-p file)
3845 (org-get-agenda-file-buffer file)
3846 (error "No such file %s" file)))
3847 (if (not buffer)
3848 ;; If file does not exist, make sure an error message is sent
3849 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3850 file))))
3851 (with-current-buffer buffer
3852 (with-syntax-table (org-search-syntax-table)
3853 (unless (org-mode-p)
3854 (error "Agenda file %s is not in `org-mode'" file))
3855 (let ((case-fold-search t))
3856 (save-excursion
3857 (save-restriction
3858 (if org-agenda-restrict
3859 (narrow-to-region org-agenda-restrict-begin
3860 org-agenda-restrict-end)
3861 (widen))
3862 (goto-char (point-min))
3863 (unless (or (org-on-heading-p)
3864 (outline-next-heading))
3865 (throw 'nextfile t))
3866 (goto-char (max (point-min) (1- (point))))
3867 (while (re-search-forward regexp nil t)
3868 (org-back-to-heading t)
3869 (skip-chars-forward "* ")
3870 (setq beg (point-at-bol)
3871 beg1 (point)
3872 end (progn (outline-next-heading) (point)))
3873 (catch :skip
3874 (goto-char beg)
3875 (org-agenda-skip)
3876 (setq str (buffer-substring-no-properties
3877 (point-at-bol)
3878 (if hdl-only (point-at-eol) end)))
3879 (mapc (lambda (wr) (when (string-match wr str)
3880 (goto-char (1- end))
3881 (throw :skip t)))
3882 regexps-)
3883 (mapc (lambda (wr) (unless (string-match wr str)
3884 (goto-char (1- end))
3885 (throw :skip t)))
3886 (if todo-only
3887 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3888 regexps+)
3889 regexps+))
3890 (goto-char beg)
3891 (setq marker (org-agenda-new-marker (point))
3892 category (org-get-category)
3893 tags (org-get-tags-at (point))
3894 txt (org-format-agenda-item
3896 (buffer-substring-no-properties
3897 beg1 (point-at-eol))
3898 category tags))
3899 (org-add-props txt props
3900 'org-marker marker 'org-hd-marker marker
3901 'org-todo-regexp org-todo-regexp
3902 'org-complex-heading-regexp org-complex-heading-regexp
3903 'priority 1000 'org-category category
3904 'type "search")
3905 (push txt ee)
3906 (goto-char (1- end))))))))))
3907 (setq rtn (nreverse ee))
3908 (setq rtnall (append rtnall rtn)))
3909 (if org-agenda-overriding-header
3910 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3911 nil 'face 'org-agenda-structure) "\n")
3912 (insert "Search words: ")
3913 (add-text-properties (point-min) (1- (point))
3914 (list 'face 'org-agenda-structure))
3915 (setq pos (point))
3916 (insert string "\n")
3917 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3918 (setq pos (point))
3919 (unless org-agenda-multi
3920 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3921 (add-text-properties pos (1- (point))
3922 (list 'face 'org-agenda-structure))))
3923 (org-agenda-mark-header-line (point-min))
3924 (when rtnall
3925 (insert (org-finalize-agenda-entries rtnall) "\n"))
3926 (goto-char (point-min))
3927 (or org-agenda-multi (org-fit-agenda-window))
3928 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3929 (org-finalize-agenda)
3930 (setq buffer-read-only t)))
3932 ;;; Agenda TODO list
3934 (defvar org-select-this-todo-keyword nil)
3935 (defvar org-last-arg nil)
3937 ;;;###autoload
3938 (defun org-todo-list (arg)
3939 "Show all (not done) TODO entries from all agenda file in a single list.
3940 The prefix arg can be used to select a specific TODO keyword and limit
3941 the list to these. When using \\[universal-argument], you will be prompted
3942 for a keyword. A numeric prefix directly selects the Nth keyword in
3943 `org-todo-keywords-1'."
3944 (interactive "P")
3945 (org-compile-prefix-format 'todo)
3946 (org-set-sorting-strategy 'todo)
3947 (org-prepare-agenda "TODO")
3948 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3949 (let* ((today (org-today))
3950 (date (calendar-gregorian-from-absolute today))
3951 (kwds org-todo-keywords-for-agenda)
3952 (completion-ignore-case t)
3953 (org-select-this-todo-keyword
3954 (if (stringp arg) arg
3955 (and arg (integerp arg) (> arg 0)
3956 (nth (1- arg) kwds))))
3957 rtn rtnall files file pos)
3958 (when (equal arg '(4))
3959 (setq org-select-this-todo-keyword
3960 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3961 (mapcar 'list kwds) nil nil)))
3962 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3963 (org-set-local 'org-last-arg arg)
3964 (setq org-agenda-redo-command
3965 '(org-todo-list (or current-prefix-arg org-last-arg)))
3966 (setq files (org-agenda-files nil 'ifmode)
3967 rtnall nil)
3968 (while (setq file (pop files))
3969 (catch 'nextfile
3970 (org-check-agenda-file file)
3971 (setq rtn (org-agenda-get-day-entries file date :todo))
3972 (setq rtnall (append rtnall rtn))))
3973 (if org-agenda-overriding-header
3974 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3975 nil 'face 'org-agenda-structure) "\n")
3976 (insert "Global list of TODO items of type: ")
3977 (add-text-properties (point-min) (1- (point))
3978 (list 'face 'org-agenda-structure
3979 'short-heading
3980 (concat "ToDo: "
3981 (or org-select-this-todo-keyword "ALL"))))
3982 (org-agenda-mark-header-line (point-min))
3983 (setq pos (point))
3984 (insert (or org-select-this-todo-keyword "ALL") "\n")
3985 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3986 (setq pos (point))
3987 (unless org-agenda-multi
3988 (insert "Available with `N r': (0)ALL")
3989 (let ((n 0) s)
3990 (mapc (lambda (x)
3991 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3992 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3993 (insert "\n "))
3994 (insert " " s))
3995 kwds))
3996 (insert "\n"))
3997 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3998 (org-agenda-mark-header-line (point-min))
3999 (when rtnall
4000 (insert (org-finalize-agenda-entries rtnall) "\n"))
4001 (goto-char (point-min))
4002 (or org-agenda-multi (org-fit-agenda-window))
4003 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4004 (org-finalize-agenda)
4005 (setq buffer-read-only t)))
4007 ;;; Agenda tags match
4009 ;;;###autoload
4010 (defun org-tags-view (&optional todo-only match)
4011 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4012 The prefix arg TODO-ONLY limits the search to TODO entries."
4013 (interactive "P")
4014 (org-compile-prefix-format 'tags)
4015 (org-set-sorting-strategy 'tags)
4016 (let* ((org-tags-match-list-sublevels
4017 org-tags-match-list-sublevels)
4018 (completion-ignore-case t)
4019 rtn rtnall files file pos matcher
4020 buffer)
4021 (when (and (stringp match) (not (string-match "\\S-" match)))
4022 (setq match nil))
4023 (setq matcher (org-make-tags-matcher match)
4024 match (car matcher) matcher (cdr matcher))
4025 (org-prepare-agenda (concat "TAGS " match))
4026 (setq org-agenda-query-string match)
4027 (setq org-agenda-redo-command
4028 (list 'org-tags-view (list 'quote todo-only)
4029 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4030 (setq files (org-agenda-files nil 'ifmode)
4031 rtnall nil)
4032 (while (setq file (pop files))
4033 (catch 'nextfile
4034 (org-check-agenda-file file)
4035 (setq buffer (if (file-exists-p file)
4036 (org-get-agenda-file-buffer file)
4037 (error "No such file %s" file)))
4038 (if (not buffer)
4039 ;; If file does not exist, error message to agenda
4040 (setq rtn (list
4041 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4042 rtnall (append rtnall rtn))
4043 (with-current-buffer buffer
4044 (unless (org-mode-p)
4045 (error "Agenda file %s is not in `org-mode'" file))
4046 (save-excursion
4047 (save-restriction
4048 (if org-agenda-restrict
4049 (narrow-to-region org-agenda-restrict-begin
4050 org-agenda-restrict-end)
4051 (widen))
4052 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4053 (setq rtnall (append rtnall rtn))))))))
4054 (if org-agenda-overriding-header
4055 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4056 nil 'face 'org-agenda-structure) "\n")
4057 (insert "Headlines with TAGS match: ")
4058 (add-text-properties (point-min) (1- (point))
4059 (list 'face 'org-agenda-structure
4060 'short-heading
4061 (concat "Match: " match)))
4062 (setq pos (point))
4063 (insert match "\n")
4064 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4065 (setq pos (point))
4066 (unless org-agenda-multi
4067 (insert "Press `C-u r' to search again with new search string\n"))
4068 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4069 (org-agenda-mark-header-line (point-min))
4070 (when rtnall
4071 (insert (org-finalize-agenda-entries rtnall) "\n"))
4072 (goto-char (point-min))
4073 (or org-agenda-multi (org-fit-agenda-window))
4074 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4075 (org-finalize-agenda)
4076 (setq buffer-read-only t)))
4078 ;;; Agenda Finding stuck projects
4080 (defvar org-agenda-skip-regexp nil
4081 "Regular expression used in skipping subtrees for the agenda.
4082 This is basically a temporary global variable that can be set and then
4083 used by user-defined selections using `org-agenda-skip-function'.")
4085 (defvar org-agenda-overriding-header nil
4086 "When this is set during todo and tags searches, will replace header.
4087 This variable should not be set directly, but custom commands can bind it
4088 in the options section.")
4090 (defun org-agenda-skip-entry-when-regexp-matches ()
4091 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4092 If yes, it returns the end position of this entry, causing agenda commands
4093 to skip the entry but continuing the search in the subtree. This is a
4094 function that can be put into `org-agenda-skip-function' for the duration
4095 of a command."
4096 (let ((end (save-excursion (org-end-of-subtree t)))
4097 skip)
4098 (save-excursion
4099 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4100 (and skip end)))
4102 (defun org-agenda-skip-subtree-when-regexp-matches ()
4103 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4104 If yes, it returns the end position of this tree, causing agenda commands
4105 to skip this subtree. This is a function that can be put into
4106 `org-agenda-skip-function' for the duration of a command."
4107 (let ((end (save-excursion (org-end-of-subtree t)))
4108 skip)
4109 (save-excursion
4110 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4111 (and skip end)))
4113 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4114 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4115 If yes, it returns the end position of the current entry (NOT the tree),
4116 causing agenda commands to skip the entry but continuing the search in
4117 the subtree. This is a function that can be put into
4118 `org-agenda-skip-function' for the duration of a command. An important
4119 use of this function is for the stuck project list."
4120 (let ((end (save-excursion (org-end-of-subtree t)))
4121 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4122 skip)
4123 (save-excursion
4124 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4125 (and skip entry-end)))
4127 (defun org-agenda-skip-entry-if (&rest conditions)
4128 "Skip entry if any of CONDITIONS is true.
4129 See `org-agenda-skip-if' for details."
4130 (org-agenda-skip-if nil conditions))
4132 (defun org-agenda-skip-subtree-if (&rest conditions)
4133 "Skip entry if any of CONDITIONS is true.
4134 See `org-agenda-skip-if' for details."
4135 (org-agenda-skip-if t conditions))
4137 (defun org-agenda-skip-if (subtree conditions)
4138 "Checks current entity for CONDITIONS.
4139 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4140 the entry, i.e. the text before the next heading is checked.
4142 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4143 from different tests. Valid conditions are:
4145 scheduled Check if there is a scheduled cookie
4146 notscheduled Check if there is no scheduled cookie
4147 deadline Check if there is a deadline
4148 notdeadline Check if there is no deadline
4149 timestamp Check if there is a timestamp (also deadline or scheduled)
4150 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4151 regexp Check if regexp matches
4152 notregexp Check if regexp does not match.
4153 todo Check if TODO keyword matches
4154 nottodo Check if TODO keyword does not match
4156 The regexp is taken from the conditions list, it must come right after
4157 the `regexp' or `notregexp' element.
4159 `todo' and `nottodo' accept as an argument a list of todo
4160 keywords, which may include \"*\" to match any todo keyword.
4162 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4164 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4166 Instead of a list a keyword class may be given
4168 (org-agenda-skip-entry-if 'nottodo 'done)
4170 would skip entries that haven't been marked with any of \"DONE\"
4171 keywords. Possible classes are: `todo', `done', `any'.
4173 If any of these conditions is met, this function returns the end point of
4174 the entity, causing the search to continue from there. This is a function
4175 that can be put into `org-agenda-skip-function' for the duration of a command."
4176 (let (beg end m)
4177 (org-back-to-heading t)
4178 (setq beg (point)
4179 end (if subtree
4180 (progn (org-end-of-subtree t) (point))
4181 (progn (outline-next-heading) (1- (point)))))
4182 (goto-char beg)
4183 (and
4185 (and (memq 'scheduled conditions)
4186 (re-search-forward org-scheduled-time-regexp end t))
4187 (and (memq 'notscheduled conditions)
4188 (not (re-search-forward org-scheduled-time-regexp end t)))
4189 (and (memq 'deadline conditions)
4190 (re-search-forward org-deadline-time-regexp end t))
4191 (and (memq 'notdeadline conditions)
4192 (not (re-search-forward org-deadline-time-regexp end t)))
4193 (and (memq 'timestamp conditions)
4194 (re-search-forward org-ts-regexp end t))
4195 (and (memq 'nottimestamp conditions)
4196 (not (re-search-forward org-ts-regexp end t)))
4197 (and (setq m (memq 'regexp conditions))
4198 (stringp (nth 1 m))
4199 (re-search-forward (nth 1 m) end t))
4200 (and (setq m (memq 'notregexp conditions))
4201 (stringp (nth 1 m))
4202 (not (re-search-forward (nth 1 m) end t)))
4203 (and (or
4204 (setq m (memq 'todo conditions))
4205 (setq m (memq 'nottodo conditions)))
4206 (org-agenda-skip-if-todo m end)))
4207 end)))
4209 (defun org-agenda-skip-if-todo (args end)
4210 "Helper function for `org-agenda-skip-if', do not use it directly.
4211 ARGS is a list with first element either `todo' or `nottodo'.
4212 The remainder is either a list of TODO keywords, or a state symbol
4213 `todo' or `done' or `any'."
4214 (let ((kw (car args))
4215 (arg (cadr args))
4216 todo-wds todo-re)
4217 (setq todo-wds
4218 (org-uniquify
4219 (cond
4220 ((listp arg) ;; list of keywords
4221 (if (member "*" arg)
4222 (mapcar 'substring-no-properties org-todo-keywords-1)
4223 arg))
4224 ((symbolp arg) ;; keyword class name
4225 (cond
4226 ((eq arg 'todo)
4227 (org-delete-all org-done-keywords
4228 (mapcar 'substring-no-properties
4229 org-todo-keywords-1)))
4230 ((eq arg 'done) org-done-keywords)
4231 ((eq arg 'any)
4232 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4233 (setq todo-re
4234 (concat "^\\*+[ \t]+\\<\\("
4235 (mapconcat 'identity todo-wds "\\|")
4236 "\\)\\>"))
4237 (if (eq kw 'todo)
4238 (re-search-forward todo-re end t)
4239 (not (re-search-forward todo-re end t)))))
4241 ;;;###autoload
4242 (defun org-agenda-list-stuck-projects (&rest ignore)
4243 "Create agenda view for projects that are stuck.
4244 Stuck projects are project that have no next actions. For the definitions
4245 of what a project is and how to check if it stuck, customize the variable
4246 `org-stuck-projects'."
4247 (interactive)
4248 (let* ((org-agenda-skip-function
4249 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4250 ;; We could have used org-agenda-skip-if here.
4251 (org-agenda-overriding-header
4252 (or org-agenda-overriding-header "List of stuck projects: "))
4253 (matcher (nth 0 org-stuck-projects))
4254 (todo (nth 1 org-stuck-projects))
4255 (todo-wds (if (member "*" todo)
4256 (progn
4257 (org-prepare-agenda-buffers (org-agenda-files
4258 nil 'ifmode))
4259 (org-delete-all
4260 org-done-keywords-for-agenda
4261 (copy-sequence org-todo-keywords-for-agenda)))
4262 todo))
4263 (todo-re (concat "^\\*+[ \t]+\\("
4264 (mapconcat 'identity todo-wds "\\|")
4265 "\\)\\>"))
4266 (tags (nth 2 org-stuck-projects))
4267 (tags-re (if (member "*" tags)
4268 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4269 (if tags
4270 (concat "^\\*+ .*:\\("
4271 (mapconcat 'identity tags "\\|")
4272 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4273 (gen-re (nth 3 org-stuck-projects))
4274 (re-list
4275 (delq nil
4276 (list
4277 (if todo todo-re)
4278 (if tags tags-re)
4279 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4280 gen-re)))))
4281 (setq org-agenda-skip-regexp
4282 (if re-list
4283 (mapconcat 'identity re-list "\\|")
4284 (error "No information how to identify unstuck projects")))
4285 (org-tags-view nil matcher)
4286 (with-current-buffer org-agenda-buffer-name
4287 (setq org-agenda-redo-command
4288 '(org-agenda-list-stuck-projects
4289 (or current-prefix-arg org-last-arg))))))
4291 ;;; Diary integration
4293 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4294 (defvar list-diary-entries-hook)
4296 (defun org-get-entries-from-diary (date)
4297 "Get the (Emacs Calendar) diary entries for DATE."
4298 (require 'diary-lib)
4299 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4300 (diary-display-hook '(fancy-diary-display))
4301 (diary-display-function 'fancy-diary-display)
4302 (pop-up-frames nil)
4303 (list-diary-entries-hook
4304 (cons 'org-diary-default-entry list-diary-entries-hook))
4305 (diary-file-name-prefix-function nil) ; turn this feature off
4306 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4307 entries
4308 (org-disable-agenda-to-diary t))
4309 (save-excursion
4310 (save-window-excursion
4311 (funcall (if (fboundp 'diary-list-entries)
4312 'diary-list-entries 'list-diary-entries)
4313 date 1)))
4314 (if (not (get-buffer diary-fancy-buffer))
4315 (setq entries nil)
4316 (with-current-buffer diary-fancy-buffer
4317 (setq buffer-read-only nil)
4318 (if (zerop (buffer-size))
4319 ;; No entries
4320 (setq entries nil)
4321 ;; Omit the date and other unnecessary stuff
4322 (org-agenda-cleanup-fancy-diary)
4323 ;; Add prefix to each line and extend the text properties
4324 (if (zerop (buffer-size))
4325 (setq entries nil)
4326 (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
4327 (set-buffer-modified-p nil)
4328 (kill-buffer diary-fancy-buffer)))
4329 (when entries
4330 (setq entries (org-split-string entries "\n"))
4331 (setq entries
4332 (mapcar
4333 (lambda (x)
4334 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4335 ;; Extend the text properties to the beginning of the line
4336 (org-add-props x (text-properties-at (1- (length x)) x)
4337 'type "diary" 'date date 'face 'org-agenda-diary))
4338 entries)))))
4340 (defvar org-agenda-cleanup-fancy-diary-hook nil
4341 "Hook run when the fancy diary buffer is cleaned up.")
4343 (defun org-agenda-cleanup-fancy-diary ()
4344 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4345 This gets rid of the date, the underline under the date, and
4346 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4347 date. It also removes lines that contain only whitespace."
4348 (goto-char (point-min))
4349 (if (looking-at ".*?:[ \t]*")
4350 (progn
4351 (replace-match "")
4352 (re-search-forward "\n=+$" nil t)
4353 (replace-match "")
4354 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4355 (re-search-forward "\n=+$" nil t)
4356 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4357 (goto-char (point-min))
4358 (while (re-search-forward "^ +\n" nil t)
4359 (replace-match ""))
4360 (goto-char (point-min))
4361 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4362 (replace-match ""))
4363 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4365 ;; Make sure entries from the diary have the right text properties.
4366 (eval-after-load "diary-lib"
4367 '(if (boundp 'diary-modify-entry-list-string-function)
4368 ;; We can rely on the hook, nothing to do
4370 ;; Hook not available, must use advice to make this work
4371 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4372 "Make the position visible."
4373 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4374 (stringp string)
4375 buffer-file-name)
4376 (setq string (org-modify-diary-entry-string string))))))
4378 (defun org-modify-diary-entry-string (string)
4379 "Add text properties to string, allowing org-mode to act on it."
4380 (org-add-props string nil
4381 'mouse-face 'highlight
4382 'help-echo (if buffer-file-name
4383 (format "mouse-2 or RET jump to diary file %s"
4384 (abbreviate-file-name buffer-file-name))
4386 'org-agenda-diary-link t
4387 'org-marker (org-agenda-new-marker (point-at-bol))))
4389 (defun org-diary-default-entry ()
4390 "Add a dummy entry to the diary.
4391 Needed to avoid empty dates which mess up holiday display."
4392 ;; Catch the error if dealing with the new add-to-diary-alist
4393 (when org-disable-agenda-to-diary
4394 (condition-case nil
4395 (org-add-to-diary-list original-date "Org-mode dummy" "")
4396 (error
4397 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4399 (defun org-add-to-diary-list (&rest args)
4400 (if (fboundp 'diary-add-to-list)
4401 (apply 'diary-add-to-list args)
4402 (apply 'add-to-diary-list args)))
4404 (defvar org-diary-last-run-time nil)
4406 ;;;###autoload
4407 (defun org-diary (&rest args)
4408 "Return diary information from org-files.
4409 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4410 It accesses org files and extracts information from those files to be
4411 listed in the diary. The function accepts arguments specifying what
4412 items should be listed. For a list of arguments allowed here, see the
4413 variable `org-agenda-entry-types'.
4415 The call in the diary file should look like this:
4417 &%%(org-diary) ~/path/to/some/orgfile.org
4419 Use a separate line for each org file to check. Or, if you omit the file name,
4420 all files listed in `org-agenda-files' will be checked automatically:
4422 &%%(org-diary)
4424 If you don't give any arguments (as in the example above), the default
4425 arguments (:deadline :scheduled :timestamp :sexp) are used.
4426 So the example above may also be written as
4428 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4430 The function expects the lisp variables `entry' and `date' to be provided
4431 by the caller, because this is how the calendar works. Don't use this
4432 function from a program - use `org-agenda-get-day-entries' instead."
4433 (when (> (- (org-float-time)
4434 org-agenda-last-marker-time)
4436 (org-agenda-reset-markers))
4437 (org-compile-prefix-format 'agenda)
4438 (org-set-sorting-strategy 'agenda)
4439 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4440 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4441 (list entry)
4442 (org-agenda-files t)))
4443 (time (org-float-time))
4444 file rtn results)
4445 (when (or (not org-diary-last-run-time)
4446 (> (- time
4447 org-diary-last-run-time)
4449 (org-prepare-agenda-buffers files))
4450 (setq org-diary-last-run-time time)
4451 ;; If this is called during org-agenda, don't return any entries to
4452 ;; the calendar. Org Agenda will list these entries itself.
4453 (if org-disable-agenda-to-diary (setq files nil))
4454 (while (setq file (pop files))
4455 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4456 (setq results (append results rtn)))
4457 (if results
4458 (concat (org-finalize-agenda-entries results) "\n"))))
4460 ;;; Agenda entry finders
4462 (defun org-agenda-get-day-entries (file date &rest args)
4463 "Does the work for `org-diary' and `org-agenda'.
4464 FILE is the path to a file to be checked for entries. DATE is date like
4465 the one returned by `calendar-current-date'. ARGS are symbols indicating
4466 which kind of entries should be extracted. For details about these, see
4467 the documentation of `org-diary'."
4468 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4469 (let* ((org-startup-folded nil)
4470 (org-startup-align-all-tables nil)
4471 (buffer (if (file-exists-p file)
4472 (org-get-agenda-file-buffer file)
4473 (error "No such file %s" file)))
4474 arg results rtn deadline-results)
4475 (if (not buffer)
4476 ;; If file does not exist, make sure an error message ends up in diary
4477 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4478 (with-current-buffer buffer
4479 (unless (org-mode-p)
4480 (error "Agenda file %s is not in `org-mode'" file))
4481 (let ((case-fold-search nil))
4482 (save-excursion
4483 (save-restriction
4484 (if org-agenda-restrict
4485 (narrow-to-region org-agenda-restrict-begin
4486 org-agenda-restrict-end)
4487 (widen))
4488 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4489 (while (setq arg (pop args))
4490 (cond
4491 ((and (eq arg :todo)
4492 (equal date (calendar-gregorian-from-absolute
4493 (org-today))))
4494 (setq rtn (org-agenda-get-todos))
4495 (setq results (append results rtn)))
4496 ((eq arg :timestamp)
4497 (setq rtn (org-agenda-get-blocks))
4498 (setq results (append results rtn))
4499 (setq rtn (org-agenda-get-timestamps))
4500 (setq results (append results rtn)))
4501 ((eq arg :sexp)
4502 (setq rtn (org-agenda-get-sexps))
4503 (setq results (append results rtn)))
4504 ((eq arg :scheduled)
4505 (setq rtn (org-agenda-get-scheduled deadline-results))
4506 (setq results (append results rtn)))
4507 ((eq arg :closed)
4508 (setq rtn (org-agenda-get-progress))
4509 (setq results (append results rtn)))
4510 ((eq arg :deadline)
4511 (setq rtn (org-agenda-get-deadlines))
4512 (setq deadline-results (copy-sequence rtn))
4513 (setq results (append results rtn))))))))
4514 results))))
4516 (defun org-agenda-get-todos ()
4517 "Return the TODO information for agenda display."
4518 (let* ((props (list 'face nil
4519 'done-face 'org-agenda-done
4520 'org-not-done-regexp org-not-done-regexp
4521 'org-todo-regexp org-todo-regexp
4522 'org-complex-heading-regexp org-complex-heading-regexp
4523 'mouse-face 'highlight
4524 'help-echo
4525 (format "mouse-2 or RET jump to org file %s"
4526 (abbreviate-file-name buffer-file-name))))
4527 (regexp (concat "^\\*+[ \t]+\\("
4528 (if org-select-this-todo-keyword
4529 (if (equal org-select-this-todo-keyword "*")
4530 org-todo-regexp
4531 (concat "\\<\\("
4532 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4533 "\\)\\>"))
4534 org-not-done-regexp)
4535 "[^\n\r]*\\)"))
4536 marker priority category tags todo-state
4537 ee txt beg end)
4538 (goto-char (point-min))
4539 (while (re-search-forward regexp nil t)
4540 (catch :skip
4541 (save-match-data
4542 (beginning-of-line)
4543 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4544 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4545 (goto-char (1+ beg))
4546 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4547 (throw :skip nil)))
4548 (goto-char beg)
4549 (org-agenda-skip)
4550 (goto-char (match-beginning 1))
4551 (setq marker (org-agenda-new-marker (match-beginning 0))
4552 category (org-get-category)
4553 txt (match-string 1)
4554 tags (org-get-tags-at (point))
4555 txt (org-format-agenda-item "" txt category tags)
4556 priority (1+ (org-get-priority txt))
4557 todo-state (org-get-todo-state))
4558 (org-add-props txt props
4559 'org-marker marker 'org-hd-marker marker
4560 'priority priority 'org-category category
4561 'type "todo" 'todo-state todo-state)
4562 (push txt ee)
4563 (if org-agenda-todo-list-sublevels
4564 (goto-char (match-end 1))
4565 (org-end-of-subtree 'invisible))))
4566 (nreverse ee)))
4568 (defun org-agenda-todo-custom-ignore-p (time n)
4569 "Check whether timestamp is farther away then n number of days.
4570 This function is invoked if `org-agenda-todo-ignore-deadlines',
4571 `org-agenda-todo-ignore-scheduled' or
4572 `org-agenda-todo-ignore-timestamp' is set to an integer."
4573 (let ((days (org-days-to-time time)))
4574 (if (>= n 0)
4575 (>= days n)
4576 (<= days n))))
4578 ;;;###autoload
4579 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4580 (&optional end)
4581 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4582 (when (or org-agenda-todo-ignore-with-date
4583 org-agenda-todo-ignore-scheduled
4584 org-agenda-todo-ignore-deadlines
4585 org-agenda-todo-ignore-timestamp)
4586 (setq end (or end (save-excursion (outline-next-heading) (point))))
4587 (save-excursion
4588 (or (and org-agenda-todo-ignore-with-date
4589 (re-search-forward org-ts-regexp end t))
4590 (and org-agenda-todo-ignore-scheduled
4591 (re-search-forward org-scheduled-time-regexp end t)
4592 (cond
4593 ((eq org-agenda-todo-ignore-scheduled 'future)
4594 (> (org-days-to-time (match-string 1)) 0))
4595 ((eq org-agenda-todo-ignore-scheduled 'past)
4596 (<= (org-days-to-time (match-string 1)) 0))
4597 ((numberp org-agenda-todo-ignore-scheduled)
4598 (org-agenda-todo-custom-ignore-p
4599 (match-string 1) org-agenda-todo-ignore-scheduled))
4600 (t)))
4601 (and org-agenda-todo-ignore-deadlines
4602 (re-search-forward org-deadline-time-regexp end t)
4603 (cond
4604 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4605 ((eq org-agenda-todo-ignore-deadlines 'far)
4606 (not (org-deadline-close (match-string 1))))
4607 ((eq org-agenda-todo-ignore-deadlines 'future)
4608 (> (org-days-to-time (match-string 1)) 0))
4609 ((eq org-agenda-todo-ignore-deadlines 'past)
4610 (<= (org-days-to-time (match-string 1)) 0))
4611 ((numberp org-agenda-todo-ignore-deadlines)
4612 (org-agenda-todo-custom-ignore-p
4613 (match-string 1) org-agenda-todo-ignore-deadlines))
4614 (t (org-deadline-close (match-string 1)))))
4615 (and org-agenda-todo-ignore-timestamp
4616 (let ((buffer (current-buffer))
4617 (regexp
4618 (concat
4619 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4620 (start (point)))
4621 ;; Copy current buffer into a temporary one
4622 (with-temp-buffer
4623 (insert-buffer-substring buffer start end)
4624 (goto-char (point-min))
4625 ;; Delete SCHEDULED and DEADLINE items
4626 (while (re-search-forward regexp end t)
4627 (delete-region (match-beginning 0) (match-end 0)))
4628 (goto-char (point-min))
4629 ;; No search for timestamp left
4630 (when (re-search-forward org-ts-regexp nil t)
4631 (cond
4632 ((eq org-agenda-todo-ignore-timestamp 'future)
4633 (> (org-days-to-time (match-string 1)) 0))
4634 ((eq org-agenda-todo-ignore-timestamp 'past)
4635 (<= (org-days-to-time (match-string 1)) 0))
4636 ((numberp org-agenda-todo-ignore-timestamp)
4637 (org-agenda-todo-custom-ignore-p
4638 (match-string 1) org-agenda-todo-ignore-timestamp))
4639 (t))))))))))
4641 (defconst org-agenda-no-heading-message
4642 "No heading for this item in buffer or region.")
4644 (defun org-agenda-get-timestamps ()
4645 "Return the date stamp information for agenda display."
4646 (let* ((props (list 'face nil
4647 'org-not-done-regexp org-not-done-regexp
4648 'org-todo-regexp org-todo-regexp
4649 'org-complex-heading-regexp org-complex-heading-regexp
4650 'mouse-face 'highlight
4651 'help-echo
4652 (format "mouse-2 or RET jump to org file %s"
4653 (abbreviate-file-name buffer-file-name))))
4654 (d1 (calendar-absolute-from-gregorian date))
4655 (remove-re
4656 (concat
4657 (regexp-quote
4658 (format-time-string
4659 "<%Y-%m-%d"
4660 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4661 ".*?>"))
4662 (regexp
4663 (concat
4664 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4665 (regexp-quote
4666 (substring
4667 (format-time-string
4668 (car org-time-stamp-formats)
4669 (apply 'encode-time ; DATE bound by calendar
4670 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4671 1 11))
4672 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4673 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4674 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4675 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4676 todo-state end-of-match)
4677 (goto-char (point-min))
4678 (while (setq end-of-match (re-search-forward regexp nil t))
4679 (setq b0 (match-beginning 0)
4680 b3 (match-beginning 3) e3 (match-end 3)
4681 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4682 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4683 (member todo-state
4684 org-agenda-repeating-timestamp-show-all)))
4685 (catch :skip
4686 (and (org-at-date-range-p) (throw :skip nil))
4687 (org-agenda-skip)
4688 (if (and (match-end 1)
4689 (not (= d1 (org-time-string-to-absolute
4690 (match-string 1) d1 nil show-all))))
4691 (throw :skip nil))
4692 (if (and e3
4693 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4694 (throw :skip nil))
4695 (setq tmp (buffer-substring (max (point-min)
4696 (- b0 org-ds-keyword-length))
4698 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4699 inactivep (= (char-after b0) ?\[)
4700 deadlinep (string-match org-deadline-regexp tmp)
4701 scheduledp (string-match org-scheduled-regexp tmp)
4702 closedp (and org-agenda-include-inactive-timestamps
4703 (string-match org-closed-string tmp))
4704 clockp (and org-agenda-include-inactive-timestamps
4705 (or (string-match org-clock-string tmp)
4706 (string-match "]-+\\'" tmp)))
4707 donep (member todo-state org-done-keywords))
4708 (if (or scheduledp deadlinep closedp clockp
4709 (and donep org-agenda-skip-timestamp-if-done))
4710 (throw :skip t))
4711 (if (string-match ">" timestr)
4712 ;; substring should only run to end of time stamp
4713 (setq timestr (substring timestr 0 (match-end 0))))
4714 (setq marker (org-agenda-new-marker b0)
4715 category (org-get-category b0))
4716 (save-excursion
4717 (if (not (re-search-backward "^\\*+ " nil t))
4718 (setq txt org-agenda-no-heading-message)
4719 (goto-char (match-beginning 0))
4720 (setq hdmarker (org-agenda-new-marker)
4721 tags (org-get-tags-at))
4722 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4723 (setq head (match-string 1))
4724 (setq txt (org-format-agenda-item
4725 (if inactivep org-agenda-inactive-leader nil)
4726 head category tags timestr nil
4727 remove-re)))
4728 (setq priority (org-get-priority txt))
4729 (org-add-props txt props
4730 'org-marker marker 'org-hd-marker hdmarker)
4731 (org-add-props txt nil 'priority priority
4732 'org-category category 'date date
4733 'todo-state todo-state
4734 'type "timestamp")
4735 (push txt ee))
4736 (if org-agenda-skip-additional-timestamps-same-entry
4737 (outline-next-heading)
4738 (goto-char end-of-match))))
4739 (nreverse ee)))
4741 (defun org-agenda-get-sexps ()
4742 "Return the sexp information for agenda display."
4743 (require 'diary-lib)
4744 (let* ((props (list 'mouse-face 'highlight
4745 'help-echo
4746 (format "mouse-2 or RET jump to org file %s"
4747 (abbreviate-file-name buffer-file-name))))
4748 (regexp "^&?%%(")
4749 marker category ee txt tags entry result beg b sexp sexp-entry
4750 todo-state)
4751 (goto-char (point-min))
4752 (while (re-search-forward regexp nil t)
4753 (catch :skip
4754 (org-agenda-skip)
4755 (setq beg (match-beginning 0))
4756 (goto-char (1- (match-end 0)))
4757 (setq b (point))
4758 (forward-sexp 1)
4759 (setq sexp (buffer-substring b (point)))
4760 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4761 (org-trim (match-string 1))
4762 ""))
4763 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4764 (when result
4765 (setq marker (org-agenda-new-marker beg)
4766 category (org-get-category beg)
4767 todo-state (org-get-todo-state))
4769 (dolist (r (if (stringp result)
4770 (list result)
4771 result)) ;; we expect a list here
4772 (if (string-match "\\S-" r)
4773 (setq txt r)
4774 (setq txt "SEXP entry returned empty string"))
4776 (setq txt (org-format-agenda-item
4777 "" txt category tags 'time))
4778 (org-add-props txt props 'org-marker marker)
4779 (org-add-props txt nil
4780 'org-category category 'date date 'todo-state todo-state
4781 'type "sexp")
4782 (push txt ee)))))
4783 (nreverse ee)))
4785 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4786 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4787 The order of the first 2 times 3 arguments depends on the variable
4788 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4789 So for American calendars, give this as MONTH DAY YEAR, for European as
4790 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4791 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4792 is any number of ISO weeks in the block period for which the item should
4793 be skipped."
4794 (let* ((date1 (calendar-absolute-from-gregorian
4795 (org-order-calendar-date-args m1 d1 y1)))
4796 (date2 (calendar-absolute-from-gregorian
4797 (org-order-calendar-date-args m2 d2 y2)))
4798 (d (calendar-absolute-from-gregorian date)))
4799 (and
4800 (<= date1 d)
4801 (<= d date2)
4802 (= (calendar-day-of-week date) dayname)
4803 (or (not skip-weeks)
4804 (progn
4805 (require 'cal-iso)
4806 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4807 entry)))
4809 (defalias 'org-get-closed 'org-agenda-get-progress)
4810 (defun org-agenda-get-progress ()
4811 "Return the logged TODO entries for agenda display."
4812 (let* ((props (list 'mouse-face 'highlight
4813 'org-not-done-regexp org-not-done-regexp
4814 'org-todo-regexp org-todo-regexp
4815 'org-complex-heading-regexp org-complex-heading-regexp
4816 'help-echo
4817 (format "mouse-2 or RET jump to org file %s"
4818 (abbreviate-file-name buffer-file-name))))
4819 (items (if (consp org-agenda-show-log)
4820 org-agenda-show-log
4821 org-agenda-log-mode-items))
4822 (parts
4823 (delq nil
4824 (list
4825 (if (memq 'closed items) (concat "\\<" org-closed-string))
4826 (if (memq 'clock items) (concat "\\<" org-clock-string))
4827 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4828 (parts-re (if parts (mapconcat 'identity parts "\\|")
4829 (error "`org-agenda-log-mode-items' is empty")))
4830 (regexp (concat
4831 "\\(" parts-re "\\)"
4832 " *\\["
4833 (regexp-quote
4834 (substring
4835 (format-time-string
4836 (car org-time-stamp-formats)
4837 (apply 'encode-time ; DATE bound by calendar
4838 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4839 1 11))))
4840 (org-agenda-search-headline-for-time nil)
4841 marker hdmarker priority category tags closedp statep clockp state
4842 ee txt extra timestr rest clocked)
4843 (goto-char (point-min))
4844 (while (re-search-forward regexp nil t)
4845 (catch :skip
4846 (org-agenda-skip)
4847 (setq marker (org-agenda-new-marker (match-beginning 0))
4848 closedp (equal (match-string 1) org-closed-string)
4849 statep (equal (string-to-char (match-string 1)) ?-)
4850 clockp (not (or closedp statep))
4851 state (and statep (match-string 2))
4852 category (org-get-category (match-beginning 0))
4853 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4855 (when (string-match "\\]" timestr)
4856 ;; substring should only run to end of time stamp
4857 (setq rest (substring timestr (match-end 0))
4858 timestr (substring timestr 0 (match-end 0)))
4859 (if (and (not closedp) (not statep)
4860 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4861 (progn (setq timestr (concat (substring timestr 0 -1)
4862 "-" (match-string 1 rest) "]"))
4863 (setq clocked (match-string 2 rest)))
4864 (setq clocked "-")))
4865 (save-excursion
4866 (setq extra
4867 (cond
4868 ((not org-agenda-log-mode-add-notes) nil)
4869 (statep
4870 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4871 (match-string 1)))
4872 (clockp
4873 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4874 (match-string 1)))))
4875 (if (not (re-search-backward "^\\*+ " nil t))
4876 (setq txt org-agenda-no-heading-message)
4877 (goto-char (match-beginning 0))
4878 (setq hdmarker (org-agenda-new-marker)
4879 tags (org-get-tags-at))
4880 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4881 (setq txt (match-string 1))
4882 (when extra
4883 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4884 (setq txt (concat (substring txt 0 (match-beginning 1))
4885 " - " extra " " (match-string 2 txt)))
4886 (setq txt (concat txt " - " extra))))
4887 (setq txt (org-format-agenda-item
4888 (cond
4889 (closedp "Closed: ")
4890 (statep (concat "State: (" state ")"))
4891 (t (concat "Clocked: (" clocked ")")))
4892 txt category tags timestr)))
4893 (setq priority 100000)
4894 (org-add-props txt props
4895 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4896 'priority priority 'org-category category
4897 'type "closed" 'date date
4898 'undone-face 'org-warning 'done-face 'org-agenda-done)
4899 (push txt ee))
4900 (goto-char (point-at-eol))))
4901 (nreverse ee)))
4903 (defun org-agenda-get-deadlines ()
4904 "Return the deadline information for agenda display."
4905 (let* ((props (list 'mouse-face 'highlight
4906 'org-not-done-regexp org-not-done-regexp
4907 'org-todo-regexp org-todo-regexp
4908 'org-complex-heading-regexp org-complex-heading-regexp
4909 'help-echo
4910 (format "mouse-2 or RET jump to org file %s"
4911 (abbreviate-file-name buffer-file-name))))
4912 (regexp org-deadline-time-regexp)
4913 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4914 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4915 d2 diff dfrac wdays pos pos1 category tags
4916 suppress-prewarning
4917 ee txt head face s todo-state show-all upcomingp donep timestr)
4918 (goto-char (point-min))
4919 (while (re-search-forward regexp nil t)
4920 (setq suppress-prewarning nil)
4921 (catch :skip
4922 (org-agenda-skip)
4923 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4924 (save-match-data
4925 (string-match org-scheduled-time-regexp
4926 (buffer-substring (point-at-bol)
4927 (point-at-eol)))))
4928 (setq suppress-prewarning
4929 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4930 org-agenda-skip-deadline-prewarning-if-scheduled
4931 0)))
4932 (setq s (match-string 1)
4933 txt nil
4934 pos (1- (match-beginning 1))
4935 todo-state (save-match-data (org-get-todo-state))
4936 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4937 (member todo-state
4938 org-agenda-repeating-timestamp-show-all))
4939 d2 (org-time-string-to-absolute
4940 (match-string 1) d1 'past show-all)
4941 diff (- d2 d1)
4942 wdays (if suppress-prewarning
4943 (let ((org-deadline-warning-days suppress-prewarning))
4944 (org-get-wdays s))
4945 (org-get-wdays s))
4946 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4947 upcomingp (and todayp (> diff 0)))
4948 ;; When to show a deadline in the calendar:
4949 ;; If the expiration is within wdays warning time.
4950 ;; Past-due deadlines are only shown on the current date
4951 (if (and (or (and (<= diff wdays)
4952 (and todayp (not org-agenda-only-exact-dates)))
4953 (= diff 0)))
4954 (save-excursion
4955 ;; (setq todo-state (org-get-todo-state))
4956 (setq donep (member todo-state org-done-keywords))
4957 (if (and donep
4958 (or org-agenda-skip-deadline-if-done
4959 (not (= diff 0))))
4960 (setq txt nil)
4961 (setq category (org-get-category))
4962 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4963 (setq txt org-agenda-no-heading-message)
4964 (goto-char (match-end 0))
4965 (setq pos1 (match-beginning 0))
4966 (setq tags (org-get-tags-at pos1))
4967 (setq head (buffer-substring-no-properties
4968 (point)
4969 (progn (skip-chars-forward "^\r\n")
4970 (point))))
4971 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4972 (setq timestr
4973 (concat (substring s (match-beginning 1)) " "))
4974 (setq timestr 'time))
4975 (setq txt (org-format-agenda-item
4976 (if (= diff 0)
4977 (car org-agenda-deadline-leaders)
4978 (if (functionp
4979 (nth 1 org-agenda-deadline-leaders))
4980 (funcall
4981 (nth 1 org-agenda-deadline-leaders)
4982 diff date)
4983 (format (nth 1 org-agenda-deadline-leaders)
4984 diff)))
4985 head category tags
4986 (if (not (= diff 0)) nil timestr)))))
4987 (when txt
4988 (setq face (org-agenda-deadline-face dfrac wdays))
4989 (org-add-props txt props
4990 'org-marker (org-agenda-new-marker pos)
4991 'org-hd-marker (org-agenda-new-marker pos1)
4992 'priority (+ (- diff)
4993 (org-get-priority txt))
4994 'org-category category
4995 'todo-state todo-state
4996 'type (if upcomingp "upcoming-deadline" "deadline")
4997 'date (if upcomingp date d2)
4998 'face (if donep 'org-agenda-done face)
4999 'undone-face face 'done-face 'org-agenda-done)
5000 (push txt ee))))))
5001 (nreverse ee)))
5003 (defun org-agenda-deadline-face (fraction &optional wdays)
5004 "Return the face to displaying a deadline item.
5005 FRACTION is what fraction of the head-warning time has passed."
5006 (if (equal wdays 0) (setq fraction 1.))
5007 (let ((faces org-agenda-deadline-faces) f)
5008 (catch 'exit
5009 (while (setq f (pop faces))
5010 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5012 (defun org-agenda-get-scheduled (&optional deadline-results)
5013 "Return the scheduled information for agenda display."
5014 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5015 'org-todo-regexp org-todo-regexp
5016 'org-complex-heading-regexp org-complex-heading-regexp
5017 'done-face 'org-agenda-done
5018 'mouse-face 'highlight
5019 'help-echo
5020 (format "mouse-2 or RET jump to org file %s"
5021 (abbreviate-file-name buffer-file-name))))
5022 (regexp org-scheduled-time-regexp)
5023 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5024 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5026 (deadline-position-alist
5027 (mapcar (lambda (a) (and (setq mm (get-text-property
5028 0 'org-hd-marker a))
5029 (cons (marker-position mm) a)))
5030 deadline-results))
5031 d2 diff pos pos1 category tags donep
5032 ee txt head pastschedp todo-state face timestr s habitp)
5033 (goto-char (point-min))
5034 (while (re-search-forward regexp nil t)
5035 (catch :skip
5036 (org-agenda-skip)
5037 (setq s (match-string 1)
5038 txt nil
5039 pos (1- (match-beginning 1))
5040 todo-state (save-match-data (org-get-todo-state))
5041 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5042 (member todo-state
5043 org-agenda-repeating-timestamp-show-all))
5044 d2 (org-time-string-to-absolute
5045 (match-string 1) d1 'past show-all)
5046 diff (- d2 d1))
5047 (setq pastschedp (and todayp (< diff 0)))
5048 ;; When to show a scheduled item in the calendar:
5049 ;; If it is on or past the date.
5050 (when (or (and (< diff 0)
5051 (< (abs diff) org-scheduled-past-days)
5052 (and todayp (not org-agenda-only-exact-dates)))
5053 (= diff 0))
5054 (save-excursion
5055 (setq donep (member todo-state org-done-keywords))
5056 (if (and donep
5057 (or org-agenda-skip-scheduled-if-done
5058 (not (= diff 0))
5059 (and (functionp 'org-is-habit-p)
5060 (org-is-habit-p))))
5061 (setq txt nil)
5062 (setq habitp (and (functionp 'org-is-habit-p)
5063 (org-is-habit-p)))
5064 (setq category (org-get-category))
5065 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5066 (setq txt org-agenda-no-heading-message)
5067 (goto-char (match-end 0))
5068 (setq pos1 (match-beginning 0))
5069 (if habitp
5070 (if (or (not org-habit-show-habits)
5071 (and (not todayp)
5072 org-habit-show-habits-only-for-today))
5073 (throw :skip nil))
5074 (if (and
5075 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5076 (and org-agenda-skip-scheduled-if-deadline-is-shown
5077 pastschedp))
5078 (setq mm (assoc pos1 deadline-position-alist)))
5079 (throw :skip nil)))
5080 (setq tags (org-get-tags-at))
5081 (setq head (buffer-substring-no-properties
5082 (point)
5083 (progn (skip-chars-forward "^\r\n") (point))))
5084 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5085 (setq timestr
5086 (concat (substring s (match-beginning 1)) " "))
5087 (setq timestr 'time))
5088 (setq txt (org-format-agenda-item
5089 (if (= diff 0)
5090 (car org-agenda-scheduled-leaders)
5091 (format (nth 1 org-agenda-scheduled-leaders)
5092 (- 1 diff)))
5093 head category tags
5094 (if (not (= diff 0)) nil timestr)
5095 nil nil habitp))))
5096 (when txt
5097 (setq face
5098 (cond
5099 ((and (not habitp) pastschedp)
5100 'org-scheduled-previously)
5101 (todayp 'org-scheduled-today)
5102 (t 'org-scheduled))
5103 habitp (and habitp (org-habit-parse-todo)))
5104 (org-add-props txt props
5105 'undone-face face
5106 'face (if donep 'org-agenda-done face)
5107 'org-marker (org-agenda-new-marker pos)
5108 'org-hd-marker (org-agenda-new-marker pos1)
5109 'type (if pastschedp "past-scheduled" "scheduled")
5110 'date (if pastschedp d2 date)
5111 'priority (if habitp
5112 (org-habit-get-priority habitp)
5113 (+ 94 (- 5 diff) (org-get-priority txt)))
5114 'org-category category
5115 'org-habit-p habitp
5116 'todo-state todo-state)
5117 (push txt ee))))))
5118 (nreverse ee)))
5120 (defun org-agenda-get-blocks ()
5121 "Return the date-range information for agenda display."
5122 (let* ((props (list 'face nil
5123 'org-not-done-regexp org-not-done-regexp
5124 'org-todo-regexp org-todo-regexp
5125 'org-complex-heading-regexp org-complex-heading-regexp
5126 'mouse-face 'highlight
5127 'help-echo
5128 (format "mouse-2 or RET jump to org file %s"
5129 (abbreviate-file-name buffer-file-name))))
5130 (regexp org-tr-regexp)
5131 (d0 (calendar-absolute-from-gregorian date))
5132 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5133 head donep)
5134 (goto-char (point-min))
5135 (while (re-search-forward regexp nil t)
5136 (catch :skip
5137 (org-agenda-skip)
5138 (setq pos (point))
5139 (let ((start-time (match-string 1))
5140 (end-time (match-string 2)))
5141 (setq s1 (match-string 1)
5142 s2 (match-string 2)
5143 d1 (time-to-days (org-time-string-to-time s1))
5144 d2 (time-to-days (org-time-string-to-time s2)))
5145 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5146 ;; Only allow days between the limits, because the normal
5147 ;; date stamps will catch the limits.
5148 (save-excursion
5149 (setq todo-state (org-get-todo-state))
5150 (setq donep (member todo-state org-done-keywords))
5151 (if (and donep org-agenda-skip-timestamp-if-done)
5152 (throw :skip t))
5153 (setq marker (org-agenda-new-marker (point)))
5154 (setq category (org-get-category))
5155 (if (not (re-search-backward "^\\*+ " nil t))
5156 (setq txt org-agenda-no-heading-message)
5157 (goto-char (match-beginning 0))
5158 (setq hdmarker (org-agenda-new-marker (point)))
5159 (setq tags (org-get-tags-at))
5160 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5161 (setq head (match-string 1))
5162 (let ((remove-re
5163 (if org-agenda-remove-timeranges-from-blocks
5164 (concat
5165 "<" (regexp-quote s1) ".*?>"
5166 "--"
5167 "<" (regexp-quote s2) ".*?>")
5168 nil)))
5169 (setq txt (org-format-agenda-item
5170 (format
5171 (nth (if (= d1 d2) 0 1)
5172 org-agenda-timerange-leaders)
5173 (1+ (- d0 d1)) (1+ (- d2 d1)))
5174 head category tags
5175 (cond ((= d1 d0)
5176 (concat "<" start-time ">"))
5177 ((= d2 d0)
5178 (concat "<" end-time ">"))
5179 (t nil))
5180 remove-re))))
5181 (org-add-props txt props
5182 'org-marker marker 'org-hd-marker hdmarker
5183 'type "block" 'date date
5184 'todo-state todo-state
5185 'priority (org-get-priority txt) 'org-category category)
5186 (push txt ee))))
5187 (goto-char pos)))
5188 ;; Sort the entries by expiration date.
5189 (nreverse ee)))
5191 ;;; Agenda presentation and sorting
5193 (defvar org-prefix-has-time nil
5194 "A flag, set by `org-compile-prefix-format'.
5195 The flag is set if the currently compiled format contains a `%t'.")
5196 (defvar org-prefix-has-tag nil
5197 "A flag, set by `org-compile-prefix-format'.
5198 The flag is set if the currently compiled format contains a `%T'.")
5199 (defvar org-prefix-has-effort nil
5200 "A flag, set by `org-compile-prefix-format'.
5201 The flag is set if the currently compiled format contains a `%e'.")
5202 (defvar org-prefix-category-length nil
5203 "Used by `org-compile-prefix-format' to remember the category field width.")
5204 (defvar org-prefix-category-max-length nil
5205 "Used by `org-compile-prefix-format' to remember the category field width.")
5207 (defun org-agenda-get-category-icon (category)
5208 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5209 (dolist (entry org-agenda-category-icon-alist)
5210 (when (org-string-match-p (car entry) category)
5211 (if (listp (cadr entry))
5212 (return (cadr entry))
5213 (return (apply 'create-image (cdr entry)))))))
5215 (defun org-format-agenda-item (extra txt &optional category tags dotime
5216 noprefix remove-re habitp)
5217 "Format TXT to be inserted into the agenda buffer.
5218 In particular, it adds the prefix and corresponding text properties. EXTRA
5219 must be a string and replaces the `%s' specifier in the prefix format.
5220 CATEGORY (string, symbol or nil) may be used to overrule the default
5221 category taken from local variable or file name. It will replace the `%c'
5222 specifier in the format. DOTIME, when non-nil, indicates that a
5223 time-of-day should be extracted from TXT for sorting of this entry, and for
5224 the `%t' specifier in the format. When DOTIME is a string, this string is
5225 searched for a time before TXT is. NOPREFIX is a flag and indicates that
5226 only the correctly processes TXT should be returned - this is used by
5227 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
5228 Any match of REMOVE-RE will be removed from TXT."
5229 (save-match-data
5230 ;; Diary entries sometimes have extra whitespace at the beginning
5231 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5233 ;; Fix the tags part in txt
5234 (setq txt (org-agenda-fix-displayed-tags
5235 txt tags
5236 org-agenda-show-inherited-tags
5237 org-agenda-hide-tags-regexp))
5238 (let* ((category (or category
5239 (if (stringp org-category)
5240 org-category
5241 (and org-category (symbol-name org-category)))
5242 (if buffer-file-name
5243 (file-name-sans-extension
5244 (file-name-nondirectory buffer-file-name))
5245 "")))
5246 (category-icon (org-agenda-get-category-icon category))
5247 (category-icon (if category-icon
5248 (propertize " " 'display category-icon)
5249 ""))
5250 ;; time, tag, effort are needed for the eval of the prefix format
5251 (tag (if tags (nth (1- (length tags)) tags) ""))
5252 time effort neffort
5253 (ts (if dotime (concat
5254 (if (stringp dotime) dotime "")
5255 (and org-agenda-search-headline-for-time txt))))
5256 (time-of-day (and dotime (org-get-time-of-day ts)))
5257 stamp plain s0 s1 s2 rtn srp l
5258 duration thecategory)
5259 (and (org-mode-p) buffer-file-name
5260 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5261 (when (and dotime time-of-day)
5262 ;; Extract starting and ending time and move them to prefix
5263 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5264 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5265 (setq s0 (match-string 0 ts)
5266 srp (and stamp (match-end 3))
5267 s1 (match-string (if plain 1 2) ts)
5268 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5270 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5271 ;; them, we might want to remove them there to avoid duplication.
5272 ;; The user can turn this off with a variable.
5273 (if (and org-prefix-has-time
5274 org-agenda-remove-times-when-in-prefix (or stamp plain)
5275 (string-match (concat (regexp-quote s0) " *") txt)
5276 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5277 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5278 (= (match-beginning 0) 0)
5280 (setq txt (replace-match "" nil nil txt))))
5281 ;; Normalize the time(s) to 24 hour
5282 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5283 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5285 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5286 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5287 (setq s2
5288 (org-minutes-to-hh:mm-string
5289 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5291 ;; Compute the duration
5292 (when s2
5293 (setq duration (- (org-hh:mm-string-to-minutes s2)
5294 (org-hh:mm-string-to-minutes s1)))))
5296 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5297 txt)
5298 ;; Tags are in the string
5299 (if (or (eq org-agenda-remove-tags t)
5300 (and org-agenda-remove-tags
5301 org-prefix-has-tag))
5302 (setq txt (replace-match "" t t txt))
5303 (setq txt (replace-match
5304 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5305 (match-string 2 txt))
5306 t t txt))))
5307 (when (org-mode-p)
5308 (setq effort
5309 (condition-case nil
5310 (org-get-effort
5311 (or (get-text-property 0 'org-hd-marker txt)
5312 (get-text-property 0 'org-marker txt)))
5313 (error nil)))
5314 (when effort
5315 (setq neffort (org-hh:mm-string-to-minutes effort)
5316 effort (setq effort (concat "[" effort "]" )))))
5318 (when remove-re
5319 (while (string-match remove-re txt)
5320 (setq txt (replace-match "" t t txt))))
5322 ;; Create the final string
5323 (if noprefix
5324 (setq rtn txt)
5325 ;; Prepare the variables needed in the eval of the compiled format
5326 (setq time (cond (s2 (concat
5327 (org-agenda-time-of-day-to-ampm-maybe s1)
5328 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5329 (if org-agenda-timegrid-use-ampm " ")))
5330 (s1 (concat
5331 (org-agenda-time-of-day-to-ampm-maybe s1)
5332 (if org-agenda-timegrid-use-ampm
5333 "........ "
5334 "......")))
5335 (t ""))
5336 extra (or (and (not habitp) extra) "")
5337 category (if (symbolp category) (symbol-name category) category)
5338 thecategory (copy-sequence category))
5339 (if (string-match org-bracket-link-regexp category)
5340 (progn
5341 (setq l (if (match-end 3)
5342 (- (match-end 3) (match-beginning 3))
5343 (- (match-end 1) (match-beginning 1))))
5344 (when (< l (or org-prefix-category-length 0))
5345 (setq category (copy-sequence category))
5346 (org-add-props category nil
5347 'extra-space (make-string
5348 (- org-prefix-category-length l 1) ?\ ))))
5349 (if (and org-prefix-category-max-length
5350 (>= (length category) org-prefix-category-max-length))
5351 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5352 ;; Evaluate the compiled format
5353 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5355 ;; And finally add the text properties
5356 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5357 (org-add-props rtn nil
5358 'org-category (if thecategory (downcase thecategory) category)
5359 'tags (mapcar 'org-downcase-keep-props tags)
5360 'org-highest-priority org-highest-priority
5361 'org-lowest-priority org-lowest-priority
5362 'prefix-length (- (length rtn) (length txt))
5363 'time-of-day time-of-day
5364 'duration duration
5365 'effort effort
5366 'effort-minutes neffort
5367 'txt txt
5368 'time time
5369 'extra extra
5370 'dotime dotime))))
5372 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5373 "Remove tags string from TXT, and add a modified list of tags.
5374 The modified list may contain inherited tags, and tags matched by
5375 `org-agenda-hide-tags-regexp' will be removed."
5376 (when (or add-inherited hide-re)
5377 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5378 (setq txt (substring txt 0 (match-beginning 0))))
5379 (setq tags
5380 (delq nil
5381 (mapcar (lambda (tg)
5382 (if (or (and hide-re (string-match hide-re tg))
5383 (and (not add-inherited)
5384 (get-text-property 0 'inherited tg)))
5386 tg))
5387 tags)))
5388 (when tags
5389 (let ((have-i (get-text-property 0 'inherited (car tags)))
5391 (setq txt (concat txt " :"
5392 (mapconcat
5393 (lambda (x)
5394 (setq i (get-text-property 0 'inherited x))
5395 (if (and have-i (not i))
5396 (progn
5397 (setq have-i nil)
5398 (concat ":" x))
5400 tags ":")
5401 (if have-i "::" ":"))))))
5402 txt)
5404 (defun org-downcase-keep-props (s)
5405 (let ((props (text-properties-at 0 s)))
5406 (setq s (downcase s))
5407 (add-text-properties 0 (length s) props s)
5410 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5411 (defvar org-agenda-sorting-strategy-selected nil)
5413 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5414 (catch 'exit
5415 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5416 ((and todayp (member 'today (car org-agenda-time-grid))))
5417 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5418 ((member 'weekly (car org-agenda-time-grid)))
5419 (t (throw 'exit list)))
5420 (let* ((have (delq nil (mapcar
5421 (lambda (x) (get-text-property 1 'time-of-day x))
5422 list)))
5423 (string (nth 1 org-agenda-time-grid))
5424 (gridtimes (nth 2 org-agenda-time-grid))
5425 (req (car org-agenda-time-grid))
5426 (remove (member 'remove-match req))
5427 new time)
5428 (if (and (member 'require-timed req) (not have))
5429 ;; don't show empty grid
5430 (throw 'exit list))
5431 (while (setq time (pop gridtimes))
5432 (unless (and remove (member time have))
5433 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5434 (push (org-format-agenda-item
5435 nil string "" nil
5436 (concat (substring time 0 -2) ":" (substring time -2)))
5437 new)
5438 (put-text-property
5439 2 (length (car new)) 'face 'org-time-grid (car new))))
5440 (when (and todayp org-agenda-show-current-time-in-grid)
5441 (push (org-format-agenda-item
5442 nil
5443 org-agenda-current-time-string
5444 "" nil
5445 (format-time-string "%H:%M "))
5446 new)
5447 (put-text-property
5448 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5450 (if (member 'time-up org-agenda-sorting-strategy-selected)
5451 (append new list)
5452 (append list new)))))
5454 (defun org-eval (form)
5455 "Eval FORM and return result."
5456 (condition-case error
5457 (eval form)
5458 (error (format "%%![Error: %s]" error))))
5460 (defun org-compile-prefix-format (key)
5461 "Compile the prefix format into a Lisp form that can be evaluated.
5462 The resulting form is returned and stored in the variable
5463 `org-prefix-format-compiled'."
5464 (setq org-prefix-has-time nil org-prefix-has-tag nil
5465 org-prefix-category-length nil org-prefix-has-effort nil)
5466 (let ((s (cond
5467 ((stringp org-agenda-prefix-format)
5468 org-agenda-prefix-format)
5469 ((assq key org-agenda-prefix-format)
5470 (cdr (assq key org-agenda-prefix-format)))
5471 (t " %-12:c%?-12t% s")))
5472 (start 0)
5473 varform vars var e c f opt)
5474 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5475 s start)
5476 (setq var (or (cdr (assoc (match-string 4 s)
5477 '(("c" . category) ("t" . time) ("s" . extra)
5478 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5479 'eval)
5480 c (or (match-string 3 s) "")
5481 opt (match-beginning 1)
5482 start (1+ (match-beginning 0)))
5483 (if (equal var 'time) (setq org-prefix-has-time t))
5484 (if (equal var 'tag) (setq org-prefix-has-tag t))
5485 (if (equal var 'effort) (setq org-prefix-has-effort t))
5486 (setq f (concat "%" (match-string 2 s) "s"))
5487 (when (equal var 'category)
5488 (setq org-prefix-category-length
5489 (floor (abs (string-to-number (match-string 2 s)))))
5490 (setq org-prefix-category-max-length
5491 (let ((x (match-string 2 s)))
5492 (save-match-data
5493 (if (string-match "\\.[0-9]+" x)
5494 (string-to-number (substring (match-string 0 x) 1)))))))
5495 (if (eq var 'eval)
5496 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5497 (if opt
5498 (setq varform
5499 `(if (equal "" ,var)
5501 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5502 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5503 (setq s (replace-match "%s" t nil s))
5504 (push varform vars))
5505 (setq vars (nreverse vars))
5506 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5508 (defun org-set-sorting-strategy (key)
5509 (if (symbolp (car org-agenda-sorting-strategy))
5510 ;; the old format
5511 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5512 (setq org-agenda-sorting-strategy-selected
5513 (or (cdr (assq key org-agenda-sorting-strategy))
5514 (cdr (assq 'agenda org-agenda-sorting-strategy))
5515 '(time-up category-keep priority-down)))))
5517 (defun org-get-time-of-day (s &optional string mod24)
5518 "Check string S for a time of day.
5519 If found, return it as a military time number between 0 and 2400.
5520 If not found, return nil.
5521 The optional STRING argument forces conversion into a 5 character wide string
5522 HH:MM."
5523 (save-match-data
5524 (when
5525 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5526 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5527 (let* ((h (string-to-number (match-string 1 s)))
5528 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5529 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5530 (am-p (equal ampm "am"))
5531 (h1 (cond ((not ampm) h)
5532 ((= h 12) (if am-p 0 12))
5533 (t (+ h (if am-p 0 12)))))
5534 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5535 (mod h1 24) h1))
5536 (t0 (+ (* 100 h2) m))
5537 (t1 (concat (if (>= h1 24) "+" " ")
5538 (if (and org-agenda-time-leading-zero
5539 (< t0 1000)) "0" "")
5540 (if (< t0 100) "0" "")
5541 (if (< t0 10) "0" "")
5542 (int-to-string t0))))
5543 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5545 (defvar org-agenda-before-sorting-filter-function nil
5546 "Function to be applied to agenda items prior to sorting.
5547 Prior to sorting also means just before they are inserted into the agenda.
5549 To aid sorting, you may revisit the original entries and add more text
5550 properties which will later be used by the sorting functions.
5552 The function should take a string argument, an agenda line.
5553 It has access to the text properties in that line, which contain among
5554 other things, the property `org-hd-marker' that points to the entry
5555 where the line comes from. Note that not all lines going into the agenda
5556 have this property, only most.
5558 The function should return the modified string. It is probably best
5559 to ONLY change text properties.
5561 You can also use this function as a filter, by returning nil for lines
5562 you don't want to have in the agenda at all. For this application, you
5563 could bind the variable in the options section of a custom command.")
5565 (defun org-finalize-agenda-entries (list &optional nosort)
5566 "Sort and concatenate the agenda items."
5567 (setq list (mapcar 'org-agenda-highlight-todo list))
5568 (if nosort
5569 list
5570 (when org-agenda-before-sorting-filter-function
5571 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5572 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5574 (defun org-agenda-highlight-todo (x)
5575 (let ((org-done-keywords org-done-keywords-for-agenda)
5576 (case-fold-search nil)
5577 re pl)
5578 (if (eq x 'line)
5579 (save-excursion
5580 (beginning-of-line 1)
5581 (setq re (org-get-at-bol 'org-todo-regexp))
5582 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5583 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5584 (add-text-properties (match-beginning 0) (match-end 1)
5585 (list 'face (org-get-todo-face 1)))
5586 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5587 (delete-region (match-beginning 1) (1- (match-end 0)))
5588 (goto-char (match-beginning 1))
5589 (insert (format org-agenda-todo-keyword-format s)))))
5590 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5591 pl (get-text-property 0 'prefix-length x))
5592 (when (and re
5593 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5594 x (or pl 0)) pl))
5595 (add-text-properties
5596 (or (match-end 1) (match-end 0)) (match-end 0)
5597 (list 'face (org-get-todo-face (match-string 2 x)))
5599 (when (match-end 1)
5600 (setq x (concat (substring x 0 (match-end 1))
5601 (format org-agenda-todo-keyword-format
5602 (match-string 2 x))
5603 (org-add-props " " (text-properties-at 0 x))
5604 (substring x (match-end 3))))))
5605 x)))
5607 (defsubst org-cmp-priority (a b)
5608 "Compare the priorities of string A and B."
5609 (let ((pa (or (get-text-property 1 'priority a) 0))
5610 (pb (or (get-text-property 1 'priority b) 0)))
5611 (cond ((> pa pb) +1)
5612 ((< pa pb) -1)
5613 (t nil))))
5615 (defsubst org-cmp-effort (a b)
5616 "Compare the priorities of string A and B."
5617 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5618 (ea (or (get-text-property 1 'effort-minutes a) def))
5619 (eb (or (get-text-property 1 'effort-minutes b) def)))
5620 (cond ((> ea eb) +1)
5621 ((< ea eb) -1)
5622 (t nil))))
5624 (defsubst org-cmp-category (a b)
5625 "Compare the string values of categories of strings A and B."
5626 (let ((ca (or (get-text-property 1 'org-category a) ""))
5627 (cb (or (get-text-property 1 'org-category b) "")))
5628 (cond ((string-lessp ca cb) -1)
5629 ((string-lessp cb ca) +1)
5630 (t nil))))
5632 (defsubst org-cmp-todo-state (a b)
5633 "Compare the todo states of strings A and B."
5634 (let* ((ma (or (get-text-property 1 'org-marker a)
5635 (get-text-property 1 'org-hd-marker a)))
5636 (mb (or (get-text-property 1 'org-marker b)
5637 (get-text-property 1 'org-hd-marker b)))
5638 (fa (and ma (marker-buffer ma)))
5639 (fb (and mb (marker-buffer mb)))
5640 (todo-kwds
5641 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5642 (and fb (with-current-buffer fb org-todo-keywords-1))))
5643 (ta (or (get-text-property 1 'todo-state a) ""))
5644 (tb (or (get-text-property 1 'todo-state b) ""))
5645 (la (- (length (member ta todo-kwds))))
5646 (lb (- (length (member tb todo-kwds))))
5647 (donepa (member ta org-done-keywords-for-agenda))
5648 (donepb (member tb org-done-keywords-for-agenda)))
5649 (cond ((and donepa (not donepb)) -1)
5650 ((and (not donepa) donepb) +1)
5651 ((< la lb) -1)
5652 ((< lb la) +1)
5653 (t nil))))
5655 (defsubst org-cmp-alpha (a b)
5656 "Compare the headlines, alphabetically."
5657 (let* ((pla (get-text-property 0 'prefix-length a))
5658 (plb (get-text-property 0 'prefix-length b))
5659 (ta (and pla (substring a pla)))
5660 (tb (and plb (substring b plb))))
5661 (when pla
5662 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5663 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5664 (setq ta (substring ta (match-end 0))))
5665 (setq ta (downcase ta)))
5666 (when plb
5667 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5668 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5669 (setq tb (substring tb (match-end 0))))
5670 (setq tb (downcase tb)))
5671 (cond ((not ta) +1)
5672 ((not tb) -1)
5673 ((string-lessp ta tb) -1)
5674 ((string-lessp tb ta) +1)
5675 (t nil))))
5677 (defsubst org-cmp-tag (a b)
5678 "Compare the string values of the first tags of A and B."
5679 (let ((ta (car (last (get-text-property 1 'tags a))))
5680 (tb (car (last (get-text-property 1 'tags b)))))
5681 (cond ((not ta) +1)
5682 ((not tb) -1)
5683 ((string-lessp ta tb) -1)
5684 ((string-lessp tb ta) +1)
5685 (t nil))))
5687 (defsubst org-cmp-time (a b)
5688 "Compare the time-of-day values of strings A and B."
5689 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5690 (ta (or (get-text-property 1 'time-of-day a) def))
5691 (tb (or (get-text-property 1 'time-of-day b) def)))
5692 (cond ((< ta tb) -1)
5693 ((< tb ta) +1)
5694 (t nil))))
5696 (defsubst org-cmp-habit-p (a b)
5697 "Compare the todo states of strings A and B."
5698 (let ((ha (get-text-property 1 'org-habit-p a))
5699 (hb (get-text-property 1 'org-habit-p b)))
5700 (cond ((and ha (not hb)) -1)
5701 ((and (not ha) hb) +1)
5702 (t nil))))
5704 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5706 (defun org-entries-lessp (a b)
5707 "Predicate for sorting agenda entries."
5708 ;; The following variables will be used when the form is evaluated.
5709 ;; So even though the compiler complains, keep them.
5710 (let* ((ss org-agenda-sorting-strategy-selected)
5711 (time-up (and (org-em 'time-up 'time-down ss)
5712 (org-cmp-time a b)))
5713 (time-down (if time-up (- time-up) nil))
5714 (priority-up (and (org-em 'priority-up 'priority-down ss)
5715 (org-cmp-priority a b)))
5716 (priority-down (if priority-up (- priority-up) nil))
5717 (effort-up (and (org-em 'effort-up 'effort-down ss)
5718 (org-cmp-effort a b)))
5719 (effort-down (if effort-up (- effort-up) nil))
5720 (category-up (and (or (org-em 'category-up 'category-down ss)
5721 (memq 'category-keep ss))
5722 (org-cmp-category a b)))
5723 (category-down (if category-up (- category-up) nil))
5724 (category-keep (if category-up +1 nil))
5725 (tag-up (and (org-em 'tag-up 'tag-down ss)
5726 (org-cmp-tag a b)))
5727 (tag-down (if tag-up (- tag-up) nil))
5728 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5729 (org-cmp-todo-state a b)))
5730 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5731 (habit-up (and (org-em 'habit-up 'habit-down ss)
5732 (org-cmp-habit-p a b)))
5733 (habit-down (if habit-up (- habit-up) nil))
5734 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5735 (org-cmp-alpha a b)))
5736 (alpha-down (if alpha-up (- alpha-up) nil))
5737 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5738 user-defined-up user-defined-down)
5739 (if (and need-user-cmp org-agenda-cmp-user-defined
5740 (functionp org-agenda-cmp-user-defined))
5741 (setq user-defined-up
5742 (funcall org-agenda-cmp-user-defined a b)
5743 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5744 (cdr (assoc
5745 (eval (cons 'or org-agenda-sorting-strategy-selected))
5746 '((-1 . t) (1 . nil) (nil . nil))))))
5748 ;;; Agenda restriction lock
5750 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5751 "Overlay to mark the headline to which agenda commands are restricted.")
5752 (overlay-put org-agenda-restriction-lock-overlay
5753 'face 'org-agenda-restriction-lock)
5754 (overlay-put org-agenda-restriction-lock-overlay
5755 'help-echo "Agendas are currently limited to this subtree.")
5756 (org-detach-overlay org-agenda-restriction-lock-overlay)
5758 (defun org-agenda-set-restriction-lock (&optional type)
5759 "Set restriction lock for agenda, to current subtree or file.
5760 Restriction will be the file if TYPE is `file', or if type is the
5761 universal prefix '(4), or if the cursor is before the first headline
5762 in the file. Otherwise, restriction will be to the current subtree."
5763 (interactive "P")
5764 (and (equal type '(4)) (setq type 'file))
5765 (setq type (cond
5766 (type type)
5767 ((org-at-heading-p) 'subtree)
5768 ((condition-case nil (org-back-to-heading t) (error nil))
5769 'subtree)
5770 (t 'file)))
5771 (if (eq type 'subtree)
5772 (progn
5773 (setq org-agenda-restrict t)
5774 (setq org-agenda-overriding-restriction 'subtree)
5775 (put 'org-agenda-files 'org-restrict
5776 (list (buffer-file-name (buffer-base-buffer))))
5777 (org-back-to-heading t)
5778 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5779 (move-marker org-agenda-restrict-begin (point))
5780 (move-marker org-agenda-restrict-end
5781 (save-excursion (org-end-of-subtree t)))
5782 (message "Locking agenda restriction to subtree"))
5783 (put 'org-agenda-files 'org-restrict
5784 (list (buffer-file-name (buffer-base-buffer))))
5785 (setq org-agenda-restrict nil)
5786 (setq org-agenda-overriding-restriction 'file)
5787 (move-marker org-agenda-restrict-begin nil)
5788 (move-marker org-agenda-restrict-end nil)
5789 (message "Locking agenda restriction to file"))
5790 (setq current-prefix-arg nil)
5791 (org-agenda-maybe-redo))
5793 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5794 "Remove the agenda restriction lock."
5795 (interactive "P")
5796 (org-detach-overlay org-agenda-restriction-lock-overlay)
5797 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5798 (setq org-agenda-overriding-restriction nil)
5799 (setq org-agenda-restrict nil)
5800 (put 'org-agenda-files 'org-restrict nil)
5801 (move-marker org-agenda-restrict-begin nil)
5802 (move-marker org-agenda-restrict-end nil)
5803 (setq current-prefix-arg nil)
5804 (message "Agenda restriction lock removed")
5805 (or noupdate (org-agenda-maybe-redo)))
5807 (defun org-agenda-maybe-redo ()
5808 "If there is any window showing the agenda view, update it."
5809 (let ((w (get-buffer-window org-agenda-buffer-name t))
5810 (w0 (selected-window)))
5811 (when w
5812 (select-window w)
5813 (org-agenda-redo)
5814 (select-window w0)
5815 (if org-agenda-overriding-restriction
5816 (message "Agenda view shifted to new %s restriction"
5817 org-agenda-overriding-restriction)
5818 (message "Agenda restriction lock removed")))))
5820 ;;; Agenda commands
5822 (defun org-agenda-check-type (error &rest types)
5823 "Check if agenda buffer is of allowed type.
5824 If ERROR is non-nil, throw an error, otherwise just return nil."
5825 (if (memq org-agenda-type types)
5827 (if error
5828 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5829 nil)))
5831 (defun org-agenda-quit ()
5832 "Exit agenda by removing the window or the buffer."
5833 (interactive)
5834 (if org-agenda-columns-active
5835 (org-columns-quit)
5836 (let ((buf (current-buffer)))
5837 (if (eq org-agenda-window-setup 'other-frame)
5838 (progn
5839 (kill-buffer buf)
5840 (org-agenda-reset-markers)
5841 (org-columns-remove-overlays)
5842 (setq org-agenda-archives-mode nil)
5843 (delete-frame))
5844 (and (not (eq org-agenda-window-setup 'current-window))
5845 (not (one-window-p))
5846 (delete-window))
5847 (kill-buffer buf)
5848 (org-agenda-reset-markers)
5849 (org-columns-remove-overlays)
5850 (setq org-agenda-archives-mode nil)))
5851 ;; Maybe restore the pre-agenda window configuration.
5852 (and org-agenda-restore-windows-after-quit
5853 (not (eq org-agenda-window-setup 'other-frame))
5854 org-pre-agenda-window-conf
5855 (set-window-configuration org-pre-agenda-window-conf))))
5857 (defun org-agenda-exit ()
5858 "Exit agenda by removing the window or the buffer.
5859 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5860 Org-mode buffers visited directly by the user will not be touched."
5861 (interactive)
5862 (org-release-buffers org-agenda-new-buffers)
5863 (setq org-agenda-new-buffers nil)
5864 (org-agenda-quit))
5866 (defun org-agenda-execute (arg)
5867 "Execute another agenda command, keeping same window.
5868 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5869 in the agenda."
5870 (interactive "P")
5871 (let ((org-agenda-window-setup 'current-window))
5872 (org-agenda arg)))
5874 (defun org-agenda-redo ()
5875 "Rebuild Agenda.
5876 When this is the global TODO list, a prefix argument will be interpreted."
5877 (interactive)
5878 (let* ((org-agenda-keep-modes t)
5879 (filter org-agenda-filter)
5880 (preset (get 'org-agenda-filter :preset-filter))
5881 (org-agenda-filter-while-redo (or filter preset))
5882 (cols org-agenda-columns-active)
5883 (line (org-current-line))
5884 (window-line (- line (org-current-line (window-start))))
5885 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5886 (put 'org-agenda-filter :preset-filter nil)
5887 (and cols (org-columns-quit))
5888 (message "Rebuilding agenda buffer...")
5889 (org-let lprops '(eval org-agenda-redo-command))
5890 (setq org-agenda-undo-list nil
5891 org-agenda-pending-undo-list nil)
5892 (message "Rebuilding agenda buffer...done")
5893 (put 'org-agenda-filter :preset-filter preset)
5894 (and (or filter preset) (org-agenda-filter-apply filter))
5895 (and cols (interactive-p) (org-agenda-columns))
5896 (org-goto-line line)
5897 (recenter window-line)))
5900 (defvar org-global-tags-completion-table nil)
5901 (defvar org-agenda-filter-form nil)
5902 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5903 "Keep only those lines in the agenda buffer that have a specific tag.
5904 The tag is selected with its fast selection letter, as configured.
5905 With prefix argument STRIP, remove all lines that do have the tag.
5906 A lisp caller can specify CHAR. NARROW means that the new tag should be
5907 used to narrow the search - the interactive user can also press `-' or `+'
5908 to switch to narrowing."
5909 (interactive "P")
5910 (let* ((alist org-tag-alist-for-agenda)
5911 (tag-chars (mapconcat
5912 (lambda (x) (if (and (not (symbolp (car x)))
5913 (cdr x))
5914 (char-to-string (cdr x))
5915 ""))
5916 alist ""))
5917 (efforts (org-split-string
5918 (or (cdr (assoc (concat org-effort-property "_ALL")
5919 org-global-properties))
5920 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5921 (effort-op org-agenda-filter-effort-default-operator)
5922 (effort-prompt "")
5923 (inhibit-read-only t)
5924 (current org-agenda-filter)
5925 maybe-reftresh a n tag)
5926 (unless char
5927 (message
5928 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5929 (if narrow "Narrow" "Filter") tag-chars
5930 (if org-agenda-auto-exclude-function "[RET], " ""))
5931 (setq char (read-char)))
5932 (when (member char '(?+ ?-))
5933 ;; Narrowing down
5934 (cond ((equal char ?-) (setq strip t narrow t))
5935 ((equal char ?+) (setq strip nil narrow t)))
5936 (message
5937 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5938 (setq char (read-char)))
5939 (when (member char '(?< ?> ?= ??))
5940 ;; An effort operator
5941 (setq effort-op (char-to-string char))
5942 (setq alist nil) ; to make sure it will be interpreted as effort.
5943 (unless (equal char ??)
5944 (loop for i from 0 to 9 do
5945 (setq effort-prompt
5946 (concat
5947 effort-prompt " ["
5948 (if (= i 9) "0" (int-to-string (1+ i)))
5949 "]" (nth i efforts))))
5950 (message "Effort%s: %s " effort-op effort-prompt)
5951 (setq char (read-char))
5952 (when (or (< char ?0) (> char ?9))
5953 (error "Need 1-9,0 to select effort" ))))
5954 (when (equal char ?\t)
5955 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5956 (org-set-local 'org-global-tags-completion-table
5957 (org-global-tags-completion-table)))
5958 (let ((completion-ignore-case t))
5959 (setq tag (org-icompleting-read
5960 "Tag: " org-global-tags-completion-table))))
5961 (cond
5962 ((equal char ?\r)
5963 (org-agenda-filter-by-tag-show-all)
5964 (when org-agenda-auto-exclude-function
5965 (setq org-agenda-filter '())
5966 (dolist (tag (org-agenda-get-represented-tags))
5967 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5968 (if modifier
5969 (push modifier org-agenda-filter))))
5970 (if (not (null org-agenda-filter))
5971 (org-agenda-filter-apply org-agenda-filter)))
5972 (setq maybe-reftresh t))
5973 ((equal char ?/)
5974 (org-agenda-filter-by-tag-show-all)
5975 (when (get 'org-agenda-filter :preset-filter)
5976 (org-agenda-filter-apply org-agenda-filter))
5977 (setq maybe-reftresh t))
5978 ((or (equal char ?\ )
5979 (setq a (rassoc char alist))
5980 (and (>= char ?0) (<= char ?9)
5981 (setq n (if (= char ?0) 9 (- char ?0 1))
5982 tag (concat effort-op (nth n efforts))
5983 a (cons tag nil)))
5984 (and (= char ??)
5985 (setq tag "?eff")
5986 a (cons tag nil))
5987 (and tag (setq a (cons tag nil))))
5988 (org-agenda-filter-by-tag-show-all)
5989 (setq tag (car a))
5990 (setq org-agenda-filter
5991 (cons (concat (if strip "-" "+") tag)
5992 (if narrow current nil)))
5993 (org-agenda-filter-apply org-agenda-filter)
5994 (setq maybe-reftresh t))
5995 (t (error "Invalid tag selection character %c" char)))
5996 (when (and maybe-reftresh
5997 (eq org-agenda-clockreport-mode 'with-filter))
5998 (org-agenda-redo))))
6000 (defun org-agenda-get-represented-tags ()
6001 "Get a list of all tags currently represented in the agenda."
6002 (let (p tags)
6003 (save-excursion
6004 (goto-char (point-min))
6005 (while (setq p (next-single-property-change (point) 'tags))
6006 (goto-char p)
6007 (mapc (lambda (x) (add-to-list 'tags x))
6008 (get-text-property (point) 'tags))))
6009 tags))
6011 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6012 "Refine the current filter. See `org-agenda-filter-by-tag."
6013 (interactive "P")
6014 (org-agenda-filter-by-tag strip char 'refine))
6016 (defun org-agenda-filter-make-matcher ()
6017 "Create the form that tests a line for the agenda filter."
6018 (let (f f1)
6019 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6020 org-agenda-filter))
6021 (if (member x '("-" "+"))
6022 (setq f1 (if (equal x "-") 'tags '(not tags)))
6023 (if (string-match "[<=>?]" x)
6024 (setq f1 (org-agenda-filter-effort-form x))
6025 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6026 (if (equal (string-to-char x) ?-)
6027 (setq f1 (list 'not f1))))
6028 (push f1 f))
6029 (cons 'and (nreverse f))))
6031 (defun org-agenda-filter-effort-form (e)
6032 "Return the form to compare the effort of the current line with what E says.
6033 E looks like \"+<2:25\"."
6034 (let (op)
6035 (setq e (substring e 1))
6036 (setq op (string-to-char e) e (substring e 1))
6037 (setq op (cond ((equal op ?<) '<=)
6038 ((equal op ?>) '>=)
6039 ((equal op ??) op)
6040 (t '=)))
6041 (list 'org-agenda-compare-effort (list 'quote op)
6042 (org-hh:mm-string-to-minutes e))))
6044 (defun org-agenda-compare-effort (op value)
6045 "Compare the effort of the current line with VALUE, using OP.
6046 If the line does not have an effort defined, return nil."
6047 (let ((eff (org-get-at-bol 'effort-minutes)))
6048 (if (equal op ??)
6049 (not eff)
6050 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6051 value))))
6053 (defun org-agenda-filter-apply (filter)
6054 "Set FILTER as the new agenda filter and apply it."
6055 (let (tags)
6056 (setq org-agenda-filter filter
6057 org-agenda-filter-form (org-agenda-filter-make-matcher))
6058 (org-agenda-set-mode-name)
6059 (save-excursion
6060 (goto-char (point-min))
6061 (while (not (eobp))
6062 (if (org-get-at-bol 'org-marker)
6063 (progn
6064 (setq tags (org-get-at-bol 'tags)) ; used in eval
6065 (if (not (eval org-agenda-filter-form))
6066 (org-agenda-filter-by-tag-hide-line))
6067 (beginning-of-line 2))
6068 (beginning-of-line 2))))
6069 (if (get-char-property (point) 'invisible)
6070 (org-agenda-previous-line))))
6072 (defun org-agenda-filter-by-tag-hide-line ()
6073 (let (ov)
6074 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6075 (point-at-eol)))
6076 (overlay-put ov 'invisible t)
6077 (overlay-put ov 'type 'tags-filter)
6078 (push ov org-agenda-filter-overlays)))
6080 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6081 (setq pos (or pos (point)))
6082 (save-excursion
6083 (dolist (ov (overlays-at pos))
6084 (when (and (overlay-get ov 'invisible)
6085 (eq (overlay-get ov 'type) 'tags-filter))
6086 (goto-char pos)
6087 (if (< (overlay-start ov) (point-at-eol))
6088 (move-overlay ov (point-at-eol)
6089 (overlay-end ov)))))))
6091 (defun org-agenda-filter-by-tag-show-all ()
6092 (mapc 'delete-overlay org-agenda-filter-overlays)
6093 (setq org-agenda-filter-overlays nil)
6094 (setq org-agenda-filter nil)
6095 (setq org-agenda-filter-form nil)
6096 (org-agenda-set-mode-name))
6098 (defun org-agenda-manipulate-query-add ()
6099 "Manipulate the query by adding a search term with positive selection.
6100 Positive selection means the term must be matched for selection of an entry."
6101 (interactive)
6102 (org-agenda-manipulate-query ?\[))
6103 (defun org-agenda-manipulate-query-subtract ()
6104 "Manipulate the query by adding a search term with negative selection.
6105 Negative selection means term must not be matched for selection of an entry."
6106 (interactive)
6107 (org-agenda-manipulate-query ?\]))
6108 (defun org-agenda-manipulate-query-add-re ()
6109 "Manipulate the query by adding a search regexp with positive selection.
6110 Positive selection means the regexp must match for selection of an entry."
6111 (interactive)
6112 (org-agenda-manipulate-query ?\{))
6113 (defun org-agenda-manipulate-query-subtract-re ()
6114 "Manipulate the query by adding a search regexp with negative selection.
6115 Negative selection means regexp must not match for selection of an entry."
6116 (interactive)
6117 (org-agenda-manipulate-query ?\}))
6118 (defun org-agenda-manipulate-query (char)
6119 (cond
6120 ((memq org-agenda-type '(timeline agenda))
6121 (let ((org-agenda-include-inactive-timestamps t))
6122 (org-agenda-redo))
6123 (message "Display now includes inactive timestamps as well"))
6124 ((eq org-agenda-type 'search)
6125 (org-add-to-string
6126 'org-agenda-query-string
6127 (if org-agenda-last-search-view-search-was-boolean
6128 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6129 (?\{ . " +{}") (?\} . " -{}"))))
6130 " "))
6131 (setq org-agenda-redo-command
6132 (list 'org-search-view
6133 org-todo-only
6134 org-agenda-query-string
6135 (+ (length org-agenda-query-string)
6136 (if (member char '(?\{ ?\})) 0 1))))
6137 (set-register org-agenda-query-register org-agenda-query-string)
6138 (org-agenda-redo))
6139 (t (error "Cannot manipulate query for %s-type agenda buffers"
6140 org-agenda-type))))
6142 (defun org-add-to-string (var string)
6143 (set var (concat (symbol-value var) string)))
6145 (defun org-agenda-goto-date (date)
6146 "Jump to DATE in agenda."
6147 (interactive (list (let ((org-read-date-prefer-future
6148 (eval org-agenda-jump-prefer-future)))
6149 (org-read-date))))
6150 (org-agenda-list nil date))
6152 (defun org-agenda-goto-today ()
6153 "Go to today."
6154 (interactive)
6155 (org-agenda-check-type t 'timeline 'agenda)
6156 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6157 (cond
6158 (tdpos (goto-char tdpos))
6159 ((eq org-agenda-type 'agenda)
6160 (let* ((sd (org-agenda-compute-starting-span
6161 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6162 (org-agenda-overriding-arguments org-agenda-last-arguments))
6163 (setf (nth 1 org-agenda-overriding-arguments) sd)
6164 (org-agenda-redo)
6165 (org-agenda-find-same-or-today-or-agenda)))
6166 (t (error "Cannot find today")))))
6168 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6169 (goto-char
6170 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6171 (text-property-any (point-min) (point-max) 'org-today t)
6172 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6173 (point-min))))
6175 (defun org-agenda-later (arg)
6176 "Go forward in time by thee current span.
6177 With prefix ARG, go forward that many times the current span."
6178 (interactive "p")
6179 (org-agenda-check-type t 'agenda)
6180 (let* ((span org-agenda-current-span)
6181 (sd org-starting-day)
6182 (greg (calendar-gregorian-from-absolute sd))
6183 (cnt (org-get-at-bol 'org-day-cnt))
6184 greg2)
6185 (cond
6186 ((eq span 'day)
6187 (setq sd (+ arg sd)))
6188 ((eq span 'week)
6189 (setq sd (+ (* 7 arg) sd)))
6190 ((eq span 'month)
6191 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6192 sd (calendar-absolute-from-gregorian greg2))
6193 (setcar greg2 (1+ (car greg2))))
6194 ((eq span 'year)
6195 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6196 sd (calendar-absolute-from-gregorian greg2))
6197 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6199 (setq sd (+ (* span arg) sd))))
6200 (let ((org-agenda-overriding-arguments
6201 (list (car org-agenda-last-arguments) sd span t)))
6202 (org-agenda-redo)
6203 (org-agenda-find-same-or-today-or-agenda cnt))))
6205 (defun org-agenda-earlier (arg)
6206 "Go backward in time by the current span.
6207 With prefix ARG, go backward that many times the current span."
6208 (interactive "p")
6209 (org-agenda-later (- arg)))
6211 (defun org-agenda-view-mode-dispatch ()
6212 "Call one of the view mode commands."
6213 (interactive)
6214 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6215 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6216 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6217 (let ((a (read-char-exclusive)))
6218 (case a
6219 (?\ (call-interactively 'org-agenda-reset-view))
6220 (?d (call-interactively 'org-agenda-day-view))
6221 (?w (call-interactively 'org-agenda-week-view))
6222 (?m (call-interactively 'org-agenda-month-view))
6223 (?y (call-interactively 'org-agenda-year-view))
6224 (?l (call-interactively 'org-agenda-log-mode))
6225 (?L (org-agenda-log-mode '(4)))
6226 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6227 (?a (call-interactively 'org-agenda-archives-mode))
6228 (?A (org-agenda-archives-mode 'files))
6229 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6230 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6231 (?G (call-interactively 'org-agenda-toggle-time-grid))
6232 (?D (call-interactively 'org-agenda-toggle-diary))
6233 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6234 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6235 (org-agenda-check-type t 'timeline 'agenda)
6236 (org-agenda-redo))
6237 (message "Display now includes inactive timestamps as well"))
6238 (?q (message "Abort"))
6239 (otherwise (error "Invalid key" )))))
6241 (defun org-agenda-reset-view ()
6242 "Switch to default view for agenda."
6243 (interactive)
6244 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6245 (defun org-agenda-day-view (&optional day-of-year)
6246 "Switch to daily view for agenda.
6247 With argument DAY-OF-YEAR, switch to that day of the year."
6248 (interactive "P")
6249 (org-agenda-change-time-span 'day day-of-year))
6250 (defun org-agenda-week-view (&optional iso-week)
6251 "Switch to daily view for agenda.
6252 With argument ISO-WEEK, switch to the corresponding ISO week.
6253 If ISO-WEEK has more then 2 digits, only the last two encode the
6254 week. Any digits before this encode a year. So 200712 means
6255 week 12 of year 2007. Years in the range 1938-2037 can also be
6256 written as 2-digit years."
6257 (interactive "P")
6258 (org-agenda-change-time-span 'week iso-week))
6259 (defun org-agenda-month-view (&optional month)
6260 "Switch to monthly view for agenda.
6261 With argument MONTH, switch to that month."
6262 (interactive "P")
6263 (org-agenda-change-time-span 'month month))
6264 (defun org-agenda-year-view (&optional year)
6265 "Switch to yearly view for agenda.
6266 With argument YEAR, switch to that year.
6267 If MONTH has more then 2 digits, only the last two encode the
6268 month. Any digits before this encode a year. So 200712 means
6269 December year 2007. Years in the range 1938-2037 can also be
6270 written as 2-digit years."
6271 (interactive "P")
6272 (when year
6273 (setq year (org-small-year-to-year year)))
6274 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6275 (org-agenda-change-time-span 'year year)
6276 (error "Abort")))
6278 (defun org-agenda-change-time-span (span &optional n)
6279 "Change the agenda view to SPAN.
6280 SPAN may be `day', `week', `month', `year'."
6281 (org-agenda-check-type t 'agenda)
6282 (if (and (not n) (equal org-agenda-current-span span))
6283 (error "Viewing span is already \"%s\"" span))
6284 (let* ((sd (or (org-get-at-bol 'day)
6285 org-starting-day))
6286 (sd (org-agenda-compute-starting-span sd span n))
6287 (org-agenda-overriding-arguments
6288 (list (car org-agenda-last-arguments) sd span t)))
6289 (org-agenda-redo)
6290 (org-agenda-find-same-or-today-or-agenda))
6291 (org-agenda-set-mode-name)
6292 (message "Switched to %s view" span))
6294 (defun org-agenda-compute-starting-span (sd span &optional n)
6295 "Compute starting date for agenda.
6296 SPAN may be `day', `week', `month', `year'. The return value
6297 is a cons cell with the starting date and the number of days,
6298 so that the date SD will be in that range."
6299 (let* ((greg (calendar-gregorian-from-absolute sd))
6300 (dg (nth 1 greg))
6301 (mg (car greg))
6302 (yg (nth 2 greg)))
6303 (cond
6304 ((eq span 'day)
6305 (when n
6306 (setq sd (+ (calendar-absolute-from-gregorian
6307 (list mg 1 yg))
6308 n -1))))
6309 ((eq span 'week)
6310 (let* ((nt (calendar-day-of-week
6311 (calendar-gregorian-from-absolute sd)))
6312 (d (if org-agenda-start-on-weekday
6313 (- nt org-agenda-start-on-weekday)
6316 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6317 (when n
6318 (require 'cal-iso)
6319 (when (> n 99)
6320 (setq y1 (org-small-year-to-year (/ n 100))
6321 n (mod n 100)))
6322 (setq sd
6323 (calendar-absolute-from-iso
6324 (list n 1
6325 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6326 ((eq span 'month)
6327 (let (y1)
6328 (when (and n (> n 99))
6329 (setq y1 (org-small-year-to-year (/ n 100))
6330 n (mod n 100)))
6331 (setq sd (calendar-absolute-from-gregorian
6332 (list (or n mg) 1 (or y1 yg))))))
6333 ((eq span 'year)
6334 (setq sd (calendar-absolute-from-gregorian
6335 (list 1 1 (or n yg))))))
6336 sd))
6338 (defun org-agenda-next-date-line (&optional arg)
6339 "Jump to the next line indicating a date in agenda buffer."
6340 (interactive "p")
6341 (org-agenda-check-type t 'agenda 'timeline)
6342 (beginning-of-line 1)
6343 ;; This does not work if user makes date format that starts with a blank
6344 (if (looking-at "^\\S-") (forward-char 1))
6345 (if (not (re-search-forward "^\\S-" nil t arg))
6346 (progn
6347 (backward-char 1)
6348 (error "No next date after this line in this buffer")))
6349 (goto-char (match-beginning 0)))
6351 (defun org-agenda-previous-date-line (&optional arg)
6352 "Jump to the previous line indicating a date in agenda buffer."
6353 (interactive "p")
6354 (org-agenda-check-type t 'agenda 'timeline)
6355 (beginning-of-line 1)
6356 (if (not (re-search-backward "^\\S-" nil t arg))
6357 (error "No previous date before this line in this buffer")))
6359 ;; Initialize the highlight
6360 (defvar org-hl (make-overlay 1 1))
6361 (overlay-put org-hl 'face 'highlight)
6363 (defun org-highlight (begin end &optional buffer)
6364 "Highlight a region with overlay."
6365 (move-overlay org-hl begin end (or buffer (current-buffer))))
6367 (defun org-unhighlight ()
6368 "Detach overlay INDEX."
6369 (org-detach-overlay org-hl))
6371 ;; FIXME this is currently not used.
6372 (defun org-highlight-until-next-command (beg end &optional buffer)
6373 "Move the highlight overlay to BEG/END, remove it before the next command."
6374 (org-highlight beg end buffer)
6375 (add-hook 'pre-command-hook 'org-unhighlight-once))
6376 (defun org-unhighlight-once ()
6377 "Remove the highlight from its position, and this function from the hook."
6378 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6379 (org-unhighlight))
6381 (defun org-agenda-follow-mode ()
6382 "Toggle follow mode in an agenda buffer."
6383 (interactive)
6384 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6385 (org-agenda-set-mode-name)
6386 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6387 (org-agenda-show))
6388 (message "Follow mode is %s"
6389 (if org-agenda-follow-mode "on" "off")))
6391 (defun org-agenda-entry-text-mode (&optional arg)
6392 "Toggle entry text mode in an agenda buffer."
6393 (interactive "P")
6394 (setq org-agenda-entry-text-mode (or (integerp arg)
6395 (not org-agenda-entry-text-mode)))
6396 (org-agenda-entry-text-hide)
6397 (and org-agenda-entry-text-mode
6398 (let ((org-agenda-entry-text-maxlines
6399 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6400 (org-agenda-entry-text-show)))
6401 (org-agenda-set-mode-name)
6402 (message "Entry text mode is %s. Maximum number of lines is %d"
6403 (if org-agenda-entry-text-mode "on" "off")
6404 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6406 (defun org-agenda-clockreport-mode (&optional with-filter)
6407 "Toggle clocktable mode in an agenda buffer.
6408 With prefix arg WITH-FILTER, make the clocktable respect the current
6409 agenda filter."
6410 (interactive "P")
6411 (org-agenda-check-type t 'agenda)
6412 (if with-filter
6413 (setq org-agenda-clockreport-mode 'with-filter)
6414 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6415 (org-agenda-set-mode-name)
6416 (org-agenda-redo)
6417 (message "Clocktable mode is %s"
6418 (if org-agenda-clockreport-mode "on" "off")))
6420 (defun org-agenda-log-mode (&optional special)
6421 "Toggle log mode in an agenda buffer.
6422 With argument SPECIAL, show all possible log items, not only the ones
6423 configured in `org-agenda-log-mode-items'.
6424 With a double `C-u' prefix arg, show *only* log items, nothing else."
6425 (interactive "P")
6426 (org-agenda-check-type t 'agenda 'timeline)
6427 (setq org-agenda-show-log
6428 (if (equal special '(16))
6429 'only
6430 (if special '(closed clock state)
6431 (not org-agenda-show-log))))
6432 (org-agenda-set-mode-name)
6433 (org-agenda-redo)
6434 (message "Log mode is %s"
6435 (if org-agenda-show-log "on" "off")))
6437 (defun org-agenda-archives-mode (&optional with-files)
6438 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6439 When called with a prefix argument, include all archive files as well."
6440 (interactive "P")
6441 (setq org-agenda-archives-mode
6442 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6443 (org-agenda-set-mode-name)
6444 (org-agenda-redo)
6445 (message
6446 "%s"
6447 (cond
6448 ((eq org-agenda-archives-mode nil)
6449 "No archives are included")
6450 ((eq org-agenda-archives-mode 'trees)
6451 (format "Trees with :%s: tag are included" org-archive-tag))
6452 ((eq org-agenda-archives-mode t)
6453 (format "Trees with :%s: tag and all active archive files are included"
6454 org-archive-tag)))))
6456 (defun org-agenda-toggle-diary ()
6457 "Toggle diary inclusion in an agenda buffer."
6458 (interactive)
6459 (org-agenda-check-type t 'agenda)
6460 (setq org-agenda-include-diary (not org-agenda-include-diary))
6461 (org-agenda-redo)
6462 (org-agenda-set-mode-name)
6463 (message "Diary inclusion turned %s"
6464 (if org-agenda-include-diary "on" "off")))
6466 (defun org-agenda-toggle-deadlines ()
6467 "Toggle inclusion of entries with a deadline in an agenda buffer."
6468 (interactive)
6469 (org-agenda-check-type t 'agenda)
6470 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6471 (org-agenda-redo)
6472 (org-agenda-set-mode-name)
6473 (message "Deadlines inclusion turned %s"
6474 (if org-agenda-include-deadlines "on" "off")))
6476 (defun org-agenda-toggle-time-grid ()
6477 "Toggle time grid in an agenda buffer."
6478 (interactive)
6479 (org-agenda-check-type t 'agenda)
6480 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6481 (org-agenda-redo)
6482 (org-agenda-set-mode-name)
6483 (message "Time-grid turned %s"
6484 (if org-agenda-use-time-grid "on" "off")))
6486 (defun org-agenda-set-mode-name ()
6487 "Set the mode name to indicate all the small mode settings."
6488 (setq mode-name
6489 (list "Org-Agenda"
6490 (if (get 'org-agenda-files 'org-restrict) " []" "")
6492 '(:eval (org-agenda-span-name org-agenda-current-span))
6493 (if org-agenda-follow-mode " Follow" "")
6494 (if org-agenda-entry-text-mode " ETxt" "")
6495 (if org-agenda-include-diary " Diary" "")
6496 (if org-agenda-include-deadlines " Ddl" "")
6497 (if org-agenda-use-time-grid " Grid" "")
6498 (if (and (boundp 'org-habit-show-habits)
6499 org-habit-show-habits) " Habit" "")
6500 (if (consp org-agenda-show-log) " LogAll"
6501 (if org-agenda-show-log " Log" ""))
6502 (if (or org-agenda-filter (get 'org-agenda-filter
6503 :preset-filter))
6504 (concat " {" (mapconcat
6505 'identity
6506 (append (get 'org-agenda-filter
6507 :preset-filter)
6508 org-agenda-filter) "") "}")
6510 (if org-agenda-archives-mode
6511 (if (eq org-agenda-archives-mode t)
6512 " Archives"
6513 (format " :%s:" org-archive-tag))
6515 (if org-agenda-clockreport-mode
6516 (if (eq org-agenda-clockreport-mode 'with-filter)
6517 " Clock{}" " Clock")
6518 "")))
6519 (force-mode-line-update))
6521 (defun org-agenda-post-command-hook ()
6522 (setq org-agenda-type
6523 (or (get-text-property (point) 'org-agenda-type)
6524 (get-text-property (max (point-min) (1- (point)))
6525 'org-agenda-type))))
6527 (defun org-agenda-next-line ()
6528 "Move cursor to the next line, and show if follow mode is active."
6529 (interactive)
6530 (call-interactively 'next-line)
6531 (org-agenda-do-context-action))
6533 (defun org-agenda-previous-line ()
6534 "Move cursor to the previous line, and show if follow-mode is active."
6535 (interactive)
6536 (call-interactively 'previous-line)
6537 (org-agenda-do-context-action))
6539 (defun org-agenda-do-context-action ()
6540 "Show outline path and, maybe, follow mode window."
6541 (let ((m (org-get-at-bol 'org-marker)))
6542 (if (and org-agenda-follow-mode m)
6543 (org-agenda-show))
6544 (if (and m org-agenda-show-outline-path)
6545 (org-with-point-at m
6546 (org-display-outline-path t)))))
6548 (defun org-agenda-show-priority ()
6549 "Show the priority of the current item.
6550 This priority is composed of the main priority given with the [#A] cookies,
6551 and by additional input from the age of a schedules or deadline entry."
6552 (interactive)
6553 (let* ((pri (org-get-at-bol 'priority)))
6554 (message "Priority is %d" (if pri pri -1000))))
6556 (defun org-agenda-show-tags ()
6557 "Show the tags applicable to the current item."
6558 (interactive)
6559 (let* ((tags (org-get-at-bol 'tags)))
6560 (if tags
6561 (message "Tags are :%s:"
6562 (org-no-properties (mapconcat 'identity tags ":")))
6563 (message "No tags associated with this line"))))
6565 (defun org-agenda-goto (&optional highlight)
6566 "Go to the Org-mode file which contains the item at point."
6567 (interactive)
6568 (let* ((marker (or (org-get-at-bol 'org-marker)
6569 (org-agenda-error)))
6570 (buffer (marker-buffer marker))
6571 (pos (marker-position marker)))
6572 (switch-to-buffer-other-window buffer)
6573 (widen)
6574 (push-mark)
6575 (goto-char pos)
6576 (when (org-mode-p)
6577 (org-show-context 'agenda)
6578 (save-excursion
6579 (and (outline-next-heading)
6580 (org-flag-heading nil)))) ; show the next heading
6581 (when (outline-invisible-p)
6582 (show-entry)) ; display invisible text
6583 (recenter (/ (window-height) 2))
6584 (run-hooks 'org-agenda-after-show-hook)
6585 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6587 (defvar org-agenda-after-show-hook nil
6588 "Normal hook run after an item has been shown from the agenda.
6589 Point is in the buffer where the item originated.")
6591 (defun org-agenda-kill ()
6592 "Kill the entry or subtree belonging to the current agenda entry."
6593 (interactive)
6594 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6595 (let* ((marker (or (org-get-at-bol 'org-marker)
6596 (org-agenda-error)))
6597 (buffer (marker-buffer marker))
6598 (pos (marker-position marker))
6599 (type (org-get-at-bol 'type))
6600 dbeg dend (n 0) conf)
6601 (org-with-remote-undo buffer
6602 (with-current-buffer buffer
6603 (save-excursion
6604 (goto-char pos)
6605 (if (and (org-mode-p) (not (member type '("sexp"))))
6606 (setq dbeg (progn (org-back-to-heading t) (point))
6607 dend (org-end-of-subtree t t))
6608 (setq dbeg (point-at-bol)
6609 dend (min (point-max) (1+ (point-at-eol)))))
6610 (goto-char dbeg)
6611 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6612 (setq conf (or (eq t org-agenda-confirm-kill)
6613 (and (numberp org-agenda-confirm-kill)
6614 (> n org-agenda-confirm-kill))))
6615 (and conf
6616 (not (y-or-n-p
6617 (format "Delete entry with %d lines in buffer \"%s\"? "
6618 n (buffer-name buffer))))
6619 (error "Abort"))
6620 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6621 (with-current-buffer buffer (delete-region dbeg dend))
6622 (message "Agenda item and source killed"))))
6624 (defvar org-archive-default-command)
6625 (defun org-agenda-archive-default ()
6626 "Archive the entry or subtree belonging to the current agenda entry."
6627 (interactive)
6628 (require 'org-archive)
6629 (org-agenda-archive-with org-archive-default-command))
6631 (defun org-agenda-archive-default-with-confirmation ()
6632 "Archive the entry or subtree belonging to the current agenda entry."
6633 (interactive)
6634 (require 'org-archive)
6635 (org-agenda-archive-with org-archive-default-command 'confirm))
6637 (defun org-agenda-archive ()
6638 "Archive the entry or subtree belonging to the current agenda entry."
6639 (interactive)
6640 (org-agenda-archive-with 'org-archive-subtree))
6642 (defun org-agenda-archive-to-archive-sibling ()
6643 "Move the entry to the archive sibling."
6644 (interactive)
6645 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6647 (defun org-agenda-archive-with (cmd &optional confirm)
6648 "Move the entry to the archive sibling."
6649 (interactive)
6650 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6651 (let* ((marker (or (org-get-at-bol 'org-marker)
6652 (org-agenda-error)))
6653 (buffer (marker-buffer marker))
6654 (pos (marker-position marker)))
6655 (org-with-remote-undo buffer
6656 (with-current-buffer buffer
6657 (if (org-mode-p)
6658 (if (and confirm
6659 (not (y-or-n-p "Archive this subtree or entry? ")))
6660 (error "Abort")
6661 (save-excursion
6662 (goto-char pos)
6663 (org-remove-subtree-entries-from-agenda)
6664 (org-back-to-heading t)
6665 (funcall cmd)))
6666 (error "Archiving works only in Org-mode files"))))))
6668 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6669 "Remove all lines in the agenda that correspond to a given subtree.
6670 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6671 If this information is not given, the function uses the tree at point."
6672 (let ((buf (or buf (current-buffer))) m p)
6673 (save-excursion
6674 (unless (and beg end)
6675 (org-back-to-heading t)
6676 (setq beg (point))
6677 (org-end-of-subtree t)
6678 (setq end (point)))
6679 (set-buffer (get-buffer org-agenda-buffer-name))
6680 (save-excursion
6681 (goto-char (point-max))
6682 (beginning-of-line 1)
6683 (while (not (bobp))
6684 (when (and (setq m (org-get-at-bol 'org-marker))
6685 (equal buf (marker-buffer m))
6686 (setq p (marker-position m))
6687 (>= p beg)
6688 (< p end))
6689 (let ((inhibit-read-only t))
6690 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6691 (beginning-of-line 0))))))
6693 (defun org-agenda-refile (&optional goto rfloc no-update)
6694 "Refile the item at point."
6695 (interactive "P")
6696 (if (equal goto '(16))
6697 (org-refile-goto-last-stored)
6698 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6699 (org-agenda-error)))
6700 (buffer (marker-buffer marker))
6701 (pos (marker-position marker))
6702 (rfloc (or rfloc
6703 (org-refile-get-location
6704 (if goto "Goto: " "Refile to: ") buffer
6705 org-refile-allow-creating-parent-nodes))))
6706 (with-current-buffer buffer
6707 (save-excursion
6708 (save-restriction
6709 (widen)
6710 (goto-char marker)
6711 (org-remove-subtree-entries-from-agenda)
6712 (org-refile goto buffer rfloc)))))
6713 (unless no-update (org-agenda-redo))))
6715 (defun org-agenda-open-link (&optional arg)
6716 "Follow the link in the current line, if any.
6717 This looks for a link in the displayed line in the agenda. It also looks
6718 at the text of the entry itself."
6719 (interactive "P")
6720 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6721 (org-get-at-bol 'org-marker)))
6722 (buffer (and marker (marker-buffer marker)))
6723 (prefix (buffer-substring
6724 (point-at-bol)
6725 (+ (point-at-bol)
6726 (or (org-get-at-bol 'prefix-length) 0)))))
6727 (cond
6728 (buffer
6729 (with-current-buffer buffer
6730 (save-excursion
6731 (save-restriction
6732 (widen)
6733 (goto-char marker)
6734 (org-offer-links-in-entry arg prefix)))))
6735 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6736 (save-excursion
6737 (beginning-of-line 1)
6738 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6739 (org-open-link-from-string (match-string 1)))
6740 (t (error "No link to open here")))))
6742 (defun org-agenda-copy-local-variable (var)
6743 "Get a variable from a referenced buffer and install it here."
6744 (let ((m (org-get-at-bol 'org-marker)))
6745 (when (and m (buffer-live-p (marker-buffer m)))
6746 (org-set-local var (with-current-buffer (marker-buffer m)
6747 (symbol-value var))))))
6749 (defun org-agenda-switch-to (&optional delete-other-windows)
6750 "Go to the Org-mode file which contains the item at point."
6751 (interactive)
6752 (if (and org-return-follows-link
6753 (not (org-get-at-bol 'org-marker))
6754 (org-in-regexp org-bracket-link-regexp))
6755 (org-open-link-from-string (match-string 0))
6756 (let* ((marker (or (org-get-at-bol 'org-marker)
6757 (org-agenda-error)))
6758 (buffer (marker-buffer marker))
6759 (pos (marker-position marker)))
6760 (switch-to-buffer buffer)
6761 (and delete-other-windows (delete-other-windows))
6762 (widen)
6763 (goto-char pos)
6764 (when (org-mode-p)
6765 (org-show-context 'agenda)
6766 (save-excursion
6767 (and (outline-next-heading)
6768 (org-flag-heading nil))) ; show the next heading
6769 (when (outline-invisible-p)
6770 (show-entry)))))) ; display invisible text
6772 (defun org-agenda-goto-mouse (ev)
6773 "Go to the Org-mode file which contains the item at the mouse click."
6774 (interactive "e")
6775 (mouse-set-point ev)
6776 (org-agenda-goto))
6778 (defun org-agenda-show (&optional full-entry)
6779 "Display the Org-mode file which contains the item at point.
6780 With prefix argument FULL-ENTRY, make the entire entry visible
6781 if it was hidden in the outline."
6782 (interactive "P")
6783 (let ((win (selected-window)))
6784 (if full-entry
6785 (let ((org-show-entry-below t))
6786 (org-agenda-goto t))
6787 (org-agenda-goto t))
6788 (select-window win)))
6790 (defvar org-agenda-show-window nil)
6791 (defun org-agenda-show-and-scroll-up ()
6792 "Display the Org-mode file which contains the item at point.
6793 When called repeatedly, scroll the window that is displaying the buffer."
6794 (interactive)
6795 (let ((win (selected-window)))
6796 (if (and (window-live-p org-agenda-show-window)
6797 (eq this-command last-command))
6798 (progn
6799 (select-window org-agenda-show-window)
6800 (ignore-errors (scroll-up)))
6801 (org-agenda-goto t)
6802 (show-subtree)
6803 (setq org-agenda-show-window (selected-window)))
6804 (select-window win)))
6806 (defun org-agenda-show-scroll-down ()
6807 "Scroll down the window showing the agenda."
6808 (interactive)
6809 (let ((win (selected-window)))
6810 (when (window-live-p org-agenda-show-window)
6811 (select-window org-agenda-show-window)
6812 (ignore-errors (scroll-down))
6813 (select-window win))))
6815 (defun org-agenda-show-1 (&optional more)
6816 "Display the Org-mode file which contains the item at point.
6817 The prefix arg selects the amount of information to display:
6819 0 hide the subtree
6820 1 just show the entry according to defaults.
6821 2 show the children view
6822 3 show the subtree view
6823 4 show the entire subtree and any LOGBOOK drawers
6824 5 show the entire subtree and any drawers
6825 With prefix argument FULL-ENTRY, make the entire entry visible
6826 if it was hidden in the outline."
6827 (interactive "p")
6828 (let ((win (selected-window)))
6829 (org-agenda-goto t)
6830 (org-recenter-heading 1)
6831 (cond
6832 ((= more 0)
6833 (hide-subtree)
6834 (save-excursion
6835 (org-back-to-heading)
6836 (run-hook-with-args 'org-cycle-hook 'folded))
6837 (message "Remote: FOLDED"))
6838 ((and (interactive-p) (= more 1))
6839 (message "Remote: show with default settings"))
6840 ((= more 2)
6841 (show-entry)
6842 (show-children)
6843 (save-excursion
6844 (org-back-to-heading)
6845 (run-hook-with-args 'org-cycle-hook 'children))
6846 (message "Remote: CHILDREN"))
6847 ((= more 3)
6848 (show-subtree)
6849 (save-excursion
6850 (org-back-to-heading)
6851 (run-hook-with-args 'org-cycle-hook 'subtree))
6852 (message "Remote: SUBTREE"))
6853 ((= more 4)
6854 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6855 (org-drawer-regexp
6856 (concat "^[ \t]*:\\("
6857 (mapconcat 'regexp-quote org-drawers "\\|")
6858 "\\):[ \t]*$")))
6859 (show-subtree)
6860 (save-excursion
6861 (org-back-to-heading)
6862 (org-cycle-hide-drawers 'subtree)))
6863 (message "Remote: SUBTREE AND LOGBOOK"))
6864 ((> more 4)
6865 (show-subtree)
6866 (message "Remote: SUBTREE AND ALL DRAWERS")))
6867 (select-window win)))
6869 (defun org-recenter-heading (n)
6870 (save-excursion
6871 (org-back-to-heading)
6872 (recenter n)))
6874 (defvar org-agenda-cycle-counter nil)
6875 (defun org-agenda-cycle-show (&optional n)
6876 "Show the current entry in another window, with default settings.
6877 Default settings are taken from `org-show-hierarchy-above' and siblings.
6878 When use repeatedly in immediate succession, the remote entry will cycle
6879 through visibility
6881 children -> subtree -> folded
6883 When called with a numeric prefix arg, that arg will be passed through to
6884 `org-agenda-show-1'. For the interpretation of that argument, see the
6885 docstring of `org-agenda-show-1'."
6886 (interactive "P")
6887 (if (integerp n)
6888 (setq org-agenda-cycle-counter n)
6889 (if (not (eq last-command this-command))
6890 (setq org-agenda-cycle-counter 1)
6891 (if (equal org-agenda-cycle-counter 0)
6892 (setq org-agenda-cycle-counter 2)
6893 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6894 (if (> org-agenda-cycle-counter 3)
6895 (setq org-agenda-cycle-counter 0)))))
6896 (org-agenda-show-1 org-agenda-cycle-counter))
6898 (defun org-agenda-recenter (arg)
6899 "Display the Org-mode file which contains the item at point and recenter."
6900 (interactive "P")
6901 (let ((win (selected-window)))
6902 (org-agenda-goto t)
6903 (recenter arg)
6904 (select-window win)))
6906 (defun org-agenda-show-mouse (ev)
6907 "Display the Org-mode file which contains the item at the mouse click."
6908 (interactive "e")
6909 (mouse-set-point ev)
6910 (org-agenda-show))
6912 (defun org-agenda-check-no-diary ()
6913 "Check if the entry is a diary link and abort if yes."
6914 (if (org-get-at-bol 'org-agenda-diary-link)
6915 (org-agenda-error)))
6917 (defun org-agenda-error ()
6918 (error "Command not allowed in this line"))
6920 (defun org-agenda-tree-to-indirect-buffer ()
6921 "Show the subtree corresponding to the current entry in an indirect buffer.
6922 This calls the command `org-tree-to-indirect-buffer' from the original
6923 Org-mode buffer.
6924 With numerical prefix arg ARG, go up to this level and then take that tree.
6925 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6926 use the dedicated frame)."
6927 (interactive)
6928 (org-agenda-check-no-diary)
6929 (let* ((marker (or (org-get-at-bol 'org-marker)
6930 (org-agenda-error)))
6931 (buffer (marker-buffer marker))
6932 (pos (marker-position marker)))
6933 (with-current-buffer buffer
6934 (save-excursion
6935 (goto-char pos)
6936 (call-interactively 'org-tree-to-indirect-buffer)))))
6938 (defvar org-last-heading-marker (make-marker)
6939 "Marker pointing to the headline that last changed its TODO state
6940 by a remote command from the agenda.")
6942 (defun org-agenda-todo-nextset ()
6943 "Switch TODO entry to next sequence."
6944 (interactive)
6945 (org-agenda-todo 'nextset))
6947 (defun org-agenda-todo-previousset ()
6948 "Switch TODO entry to previous sequence."
6949 (interactive)
6950 (org-agenda-todo 'previousset))
6952 (defun org-agenda-todo (&optional arg)
6953 "Cycle TODO state of line at point, also in Org-mode file.
6954 This changes the line at point, all other lines in the agenda referring to
6955 the same tree node, and the headline of the tree node in the Org-mode file."
6956 (interactive "P")
6957 (org-agenda-check-no-diary)
6958 (let* ((col (current-column))
6959 (marker (or (org-get-at-bol 'org-marker)
6960 (org-agenda-error)))
6961 (buffer (marker-buffer marker))
6962 (pos (marker-position marker))
6963 (hdmarker (org-get-at-bol 'org-hd-marker))
6964 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6965 (inhibit-read-only t)
6966 org-agenda-headline-snapshot-before-repeat newhead just-one)
6967 (org-with-remote-undo buffer
6968 (with-current-buffer buffer
6969 (widen)
6970 (goto-char pos)
6971 (org-show-context 'agenda)
6972 (save-excursion
6973 (and (outline-next-heading)
6974 (org-flag-heading nil))) ; show the next heading
6975 (let ((current-prefix-arg arg))
6976 (call-interactively 'org-todo))
6977 (and (bolp) (forward-char 1))
6978 (setq newhead (org-get-heading))
6979 (when (and (org-bound-and-true-p
6980 org-agenda-headline-snapshot-before-repeat)
6981 (not (equal org-agenda-headline-snapshot-before-repeat
6982 newhead))
6983 todayp)
6984 (setq newhead org-agenda-headline-snapshot-before-repeat
6985 just-one t))
6986 (save-excursion
6987 (org-back-to-heading)
6988 (move-marker org-last-heading-marker (point))))
6989 (beginning-of-line 1)
6990 (save-excursion
6991 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6992 (org-move-to-column col))))
6994 (defun org-agenda-add-note (&optional arg)
6995 "Add a time-stamped note to the entry at point."
6996 (interactive "P")
6997 (org-agenda-check-no-diary)
6998 (let* ((marker (or (org-get-at-bol 'org-marker)
6999 (org-agenda-error)))
7000 (buffer (marker-buffer marker))
7001 (pos (marker-position marker))
7002 (hdmarker (org-get-at-bol 'org-hd-marker))
7003 (inhibit-read-only t))
7004 (with-current-buffer buffer
7005 (widen)
7006 (goto-char pos)
7007 (org-show-context 'agenda)
7008 (save-excursion
7009 (and (outline-next-heading)
7010 (org-flag-heading nil))) ; show the next heading
7011 (org-add-note))))
7013 (defun org-agenda-change-all-lines (newhead hdmarker
7014 &optional fixface just-this)
7015 "Change all lines in the agenda buffer which match HDMARKER.
7016 The new content of the line will be NEWHEAD (as modified by
7017 `org-format-agenda-item'). HDMARKER is checked with
7018 `equal' against all `org-hd-marker' text properties in the file.
7019 If FIXFACE is non-nil, the face of each item is modified according to
7020 the new TODO state.
7021 If JUST-THIS is non-nil, change just the current line, not all.
7022 If FORCE-TAGS is non nil, the car of it returns the new tags."
7023 (let* ((inhibit-read-only t)
7024 (line (org-current-line))
7025 (thetags (with-current-buffer (marker-buffer hdmarker)
7026 (save-excursion (save-restriction (widen)
7027 (goto-char hdmarker)
7028 (org-get-tags-at)))))
7029 props m pl undone-face done-face finish new dotime cat tags)
7030 (save-excursion
7031 (goto-char (point-max))
7032 (beginning-of-line 1)
7033 (while (not finish)
7034 (setq finish (bobp))
7035 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7036 (or (not just-this) (= (org-current-line) line))
7037 (equal m hdmarker))
7038 (setq props (text-properties-at (point))
7039 dotime (org-get-at-bol 'dotime)
7040 cat (org-get-at-bol 'org-category)
7041 tags thetags
7042 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
7043 pl (org-get-at-bol 'prefix-length)
7044 undone-face (org-get-at-bol 'undone-face)
7045 done-face (org-get-at-bol 'done-face))
7046 (goto-char (+ (point) pl))
7047 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
7048 (cond
7049 ((equal new "")
7050 (beginning-of-line 1)
7051 (and (looking-at ".*\n?") (replace-match "")))
7052 ((looking-at ".*")
7053 (replace-match new t t)
7054 (beginning-of-line 1)
7055 (add-text-properties (point-at-bol) (point-at-eol) props)
7056 (when fixface
7057 (add-text-properties
7058 (point-at-bol) (point-at-eol)
7059 (list 'face
7060 (if org-last-todo-state-is-todo
7061 undone-face done-face))))
7062 (org-agenda-highlight-todo 'line)
7063 (beginning-of-line 1))
7064 (t (error "Line update did not work"))))
7065 (beginning-of-line 0)))
7066 (org-finalize-agenda)))
7068 (defun org-agenda-align-tags (&optional line)
7069 "Align all tags in agenda items to `org-agenda-tags-column'."
7070 (let ((inhibit-read-only t) l c)
7071 (save-excursion
7072 (goto-char (if line (point-at-bol) (point-min)))
7073 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7074 (if line (point-at-eol) nil) t)
7075 (add-text-properties
7076 (match-beginning 2) (match-end 2)
7077 (list 'face (delq nil (let ((prop (get-text-property
7078 (match-beginning 2) 'face)))
7079 (or (listp prop) (setq prop (list prop)))
7080 (if (memq 'org-tag prop)
7081 prop
7082 (cons 'org-tag prop))))))
7083 (setq l (- (match-end 2) (match-beginning 2))
7084 c (if (< org-agenda-tags-column 0)
7085 (- (abs org-agenda-tags-column) l)
7086 org-agenda-tags-column))
7087 (delete-region (match-beginning 1) (match-end 1))
7088 (goto-char (match-beginning 1))
7089 (insert (org-add-props
7090 (make-string (max 1 (- c (current-column))) ?\ )
7091 (plist-put (copy-sequence (text-properties-at (point)))
7092 'face nil))))
7093 (goto-char (point-min))
7094 (org-font-lock-add-tag-faces (point-max)))))
7096 (defun org-agenda-priority-up ()
7097 "Increase the priority of line at point, also in Org-mode file."
7098 (interactive)
7099 (org-agenda-priority 'up))
7101 (defun org-agenda-priority-down ()
7102 "Decrease the priority of line at point, also in Org-mode file."
7103 (interactive)
7104 (org-agenda-priority 'down))
7106 (defun org-agenda-priority (&optional force-direction)
7107 "Set the priority of line at point, also in Org-mode file.
7108 This changes the line at point, all other lines in the agenda referring to
7109 the same tree node, and the headline of the tree node in the Org-mode file."
7110 (interactive)
7111 (unless org-enable-priority-commands
7112 (error "Priority commands are disabled"))
7113 (org-agenda-check-no-diary)
7114 (let* ((marker (or (org-get-at-bol 'org-marker)
7115 (org-agenda-error)))
7116 (hdmarker (org-get-at-bol 'org-hd-marker))
7117 (buffer (marker-buffer hdmarker))
7118 (pos (marker-position hdmarker))
7119 (inhibit-read-only t)
7120 newhead)
7121 (org-with-remote-undo buffer
7122 (with-current-buffer buffer
7123 (widen)
7124 (goto-char pos)
7125 (org-show-context 'agenda)
7126 (save-excursion
7127 (and (outline-next-heading)
7128 (org-flag-heading nil))) ; show the next heading
7129 (funcall 'org-priority force-direction)
7130 (end-of-line 1)
7131 (setq newhead (org-get-heading)))
7132 (org-agenda-change-all-lines newhead hdmarker)
7133 (beginning-of-line 1))))
7135 ;; FIXME: should fix the tags property of the agenda line.
7136 (defun org-agenda-set-tags (&optional tag onoff)
7137 "Set tags for the current headline."
7138 (interactive)
7139 (org-agenda-check-no-diary)
7140 (if (and (org-region-active-p) (interactive-p))
7141 (call-interactively 'org-change-tag-in-region)
7142 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7143 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7144 (org-agenda-error)))
7145 (buffer (marker-buffer hdmarker))
7146 (pos (marker-position hdmarker))
7147 (inhibit-read-only t)
7148 newhead)
7149 (org-with-remote-undo buffer
7150 (with-current-buffer buffer
7151 (widen)
7152 (goto-char pos)
7153 (save-excursion
7154 (org-show-context 'agenda))
7155 (save-excursion
7156 (and (outline-next-heading)
7157 (org-flag-heading nil))) ; show the next heading
7158 (goto-char pos)
7159 (if tag
7160 (org-toggle-tag tag onoff)
7161 (call-interactively 'org-set-tags))
7162 (end-of-line 1)
7163 (setq newhead (org-get-heading)))
7164 (org-agenda-change-all-lines newhead hdmarker)
7165 (beginning-of-line 1)))))
7167 (defun org-agenda-set-property ()
7168 "Set a property for the current headline."
7169 (interactive)
7170 (org-agenda-check-no-diary)
7171 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7172 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7173 (org-agenda-error)))
7174 (buffer (marker-buffer hdmarker))
7175 (pos (marker-position hdmarker))
7176 (inhibit-read-only t)
7177 newhead)
7178 (org-with-remote-undo buffer
7179 (with-current-buffer buffer
7180 (widen)
7181 (goto-char pos)
7182 (save-excursion
7183 (org-show-context 'agenda))
7184 (save-excursion
7185 (and (outline-next-heading)
7186 (org-flag-heading nil))) ; show the next heading
7187 (goto-char pos)
7188 (call-interactively 'org-set-property)))))
7190 (defun org-agenda-set-effort ()
7191 "Set the effort property for the current headline."
7192 (interactive)
7193 (org-agenda-check-no-diary)
7194 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7195 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7196 (org-agenda-error)))
7197 (buffer (marker-buffer hdmarker))
7198 (pos (marker-position hdmarker))
7199 (inhibit-read-only t)
7200 newhead)
7201 (org-with-remote-undo buffer
7202 (with-current-buffer buffer
7203 (widen)
7204 (goto-char pos)
7205 (save-excursion
7206 (org-show-context 'agenda))
7207 (save-excursion
7208 (and (outline-next-heading)
7209 (org-flag-heading nil))) ; show the next heading
7210 (goto-char pos)
7211 (call-interactively 'org-set-effort)
7212 (end-of-line 1)))))
7214 (defun org-agenda-toggle-archive-tag ()
7215 "Toggle the archive tag for the current entry."
7216 (interactive)
7217 (org-agenda-check-no-diary)
7218 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7219 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7220 (org-agenda-error)))
7221 (buffer (marker-buffer hdmarker))
7222 (pos (marker-position hdmarker))
7223 (inhibit-read-only t)
7224 newhead)
7225 (org-with-remote-undo buffer
7226 (with-current-buffer buffer
7227 (widen)
7228 (goto-char pos)
7229 (org-show-context 'agenda)
7230 (save-excursion
7231 (and (outline-next-heading)
7232 (org-flag-heading nil))) ; show the next heading
7233 (call-interactively 'org-toggle-archive-tag)
7234 (end-of-line 1)
7235 (setq newhead (org-get-heading)))
7236 (org-agenda-change-all-lines newhead hdmarker)
7237 (beginning-of-line 1))))
7239 (defun org-agenda-do-date-later (arg)
7240 (interactive "P")
7241 (cond
7242 ((or (equal arg '(16))
7243 (memq last-command
7244 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7245 (setq this-command 'org-agenda-date-later-minutes)
7246 (org-agenda-date-later-minutes 1))
7247 ((or (equal arg '(4))
7248 (memq last-command
7249 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7250 (setq this-command 'org-agenda-date-later-hours)
7251 (org-agenda-date-later-hours 1))
7253 (org-agenda-date-later (prefix-numeric-value arg)))))
7255 (defun org-agenda-do-date-earlier (arg)
7256 (interactive "P")
7257 (cond
7258 ((or (equal arg '(16))
7259 (memq last-command
7260 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7261 (setq this-command 'org-agenda-date-earlier-minutes)
7262 (org-agenda-date-earlier-minutes 1))
7263 ((or (equal arg '(4))
7264 (memq last-command
7265 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7266 (setq this-command 'org-agenda-date-earlier-hours)
7267 (org-agenda-date-earlier-hours 1))
7269 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7271 (defun org-agenda-date-later (arg &optional what)
7272 "Change the date of this item to one day later."
7273 (interactive "p")
7274 (org-agenda-check-type t 'agenda 'timeline)
7275 (org-agenda-check-no-diary)
7276 (let* ((marker (or (org-get-at-bol 'org-marker)
7277 (org-agenda-error)))
7278 (buffer (marker-buffer marker))
7279 (pos (marker-position marker)))
7280 (org-with-remote-undo buffer
7281 (with-current-buffer buffer
7282 (widen)
7283 (goto-char pos)
7284 (if (not (org-at-timestamp-p))
7285 (error "Cannot find time stamp"))
7286 (org-timestamp-change arg (or what 'day)))
7287 (org-agenda-show-new-time marker org-last-changed-timestamp))
7288 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7290 (defun org-agenda-date-earlier (arg &optional what)
7291 "Change the date of this item to one day earlier."
7292 (interactive "p")
7293 (org-agenda-date-later (- arg) what))
7295 (defun org-agenda-date-later-minutes (arg)
7296 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7297 (interactive "p")
7298 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7299 (org-agenda-date-later arg 'minute))
7301 (defun org-agenda-date-earlier-minutes (arg)
7302 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7303 (interactive "p")
7304 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7305 (org-agenda-date-earlier arg 'minute))
7307 (defun org-agenda-date-later-hours (arg)
7308 "Change the time of this item, in hour steps."
7309 (interactive "p")
7310 (org-agenda-date-later arg 'hour))
7312 (defun org-agenda-date-earlier-hours (arg)
7313 "Change the time of this item, in hour steps."
7314 (interactive "p")
7315 (org-agenda-date-earlier arg 'hour))
7317 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7318 "Show new date stamp via text properties."
7319 ;; We use text properties to make this undoable
7320 (let ((inhibit-read-only t)
7321 (buffer-invisibility-spec))
7322 (setq stamp (concat " " prefix " => " stamp))
7323 (save-excursion
7324 (goto-char (point-max))
7325 (while (not (bobp))
7326 (when (equal marker (org-get-at-bol 'org-marker))
7327 (org-move-to-column (- (window-width) (length stamp)) t)
7328 (org-agenda-fix-tags-filter-overlays-at (point))
7329 (if (featurep 'xemacs)
7330 ;; Use `duplicable' property to trigger undo recording
7331 (let ((ex (make-extent nil nil))
7332 (gl (make-glyph stamp)))
7333 (set-glyph-face gl 'secondary-selection)
7334 (set-extent-properties
7335 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7336 (insert-extent ex (1- (point)) (point-at-eol)))
7337 (add-text-properties
7338 (1- (point)) (point-at-eol)
7339 (list 'display (org-add-props stamp nil
7340 'face 'secondary-selection))))
7341 (beginning-of-line 1))
7342 (beginning-of-line 0)))))
7344 (defun org-agenda-date-prompt (arg)
7345 "Change the date of this item. Date is prompted for, with default today.
7346 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7347 be used to request time specification in the time stamp."
7348 (interactive "P")
7349 (org-agenda-check-type t 'agenda 'timeline)
7350 (org-agenda-check-no-diary)
7351 (let* ((marker (or (org-get-at-bol 'org-marker)
7352 (org-agenda-error)))
7353 (buffer (marker-buffer marker))
7354 (pos (marker-position marker)))
7355 (org-with-remote-undo buffer
7356 (with-current-buffer buffer
7357 (widen)
7358 (goto-char pos)
7359 (if (not (org-at-timestamp-p t))
7360 (error "Cannot find time stamp"))
7361 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7362 (org-agenda-show-new-time marker org-last-changed-timestamp))
7363 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7365 (defun org-agenda-schedule (arg &optional time)
7366 "Schedule the item at point.
7367 Arg is passed through to `org-schedule'."
7368 (interactive "P")
7369 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7370 (org-agenda-check-no-diary)
7371 (let* ((marker (or (org-get-at-bol 'org-marker)
7372 (org-agenda-error)))
7373 (type (marker-insertion-type marker))
7374 (buffer (marker-buffer marker))
7375 (pos (marker-position marker))
7376 (org-insert-labeled-timestamps-at-point nil)
7378 (set-marker-insertion-type marker t)
7379 (org-with-remote-undo buffer
7380 (with-current-buffer buffer
7381 (widen)
7382 (goto-char pos)
7383 (setq ts (org-schedule arg time)))
7384 (org-agenda-show-new-time marker ts "S"))
7385 (message "Item scheduled for %s" ts)))
7387 (defun org-agenda-deadline (arg &optional time)
7388 "Schedule the item at point.
7389 Arg is passed through to `org-deadline'."
7390 (interactive "P")
7391 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7392 (org-agenda-check-no-diary)
7393 (let* ((marker (or (org-get-at-bol 'org-marker)
7394 (org-agenda-error)))
7395 (buffer (marker-buffer marker))
7396 (pos (marker-position marker))
7397 (org-insert-labeled-timestamps-at-point nil)
7399 (org-with-remote-undo buffer
7400 (with-current-buffer buffer
7401 (widen)
7402 (goto-char pos)
7403 (setq ts (org-deadline arg time)))
7404 (org-agenda-show-new-time marker ts "D"))
7405 (message "Deadline for this item set to %s" ts)))
7407 (defun org-agenda-action ()
7408 "Select entry for agenda action, or execute an agenda action.
7409 This command prompts for another letter. Valid inputs are:
7411 m Mark the entry at point for an agenda action
7412 s Schedule the marked entry to the date at the cursor
7413 d Set the deadline of the marked entry to the date at the cursor
7414 r Call `org-remember' with cursor date as the default date
7415 c Call `org-capture' with cursor date as the default date
7416 SPC Show marked entry in other window
7417 TAB Visit marked entry in other window
7419 The cursor may be at a date in the calendar, or in the Org agenda."
7420 (interactive)
7421 (let (ans)
7422 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7423 (setq ans (read-char-exclusive))
7424 (cond
7425 ((equal ans ?m)
7426 ;; Mark this entry
7427 (if (eq major-mode 'org-agenda-mode)
7428 (let ((m (or (org-get-at-bol 'org-hd-marker)
7429 (org-get-at-bol 'org-marker))))
7430 (if m
7431 (progn
7432 (move-marker org-agenda-action-marker
7433 (marker-position m) (marker-buffer m))
7434 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7435 (error "Don't know which entry to mark")))
7436 (error "This command works only in the agenda")))
7437 ((equal ans ?s)
7438 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7439 ((equal ans ?d)
7440 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7441 ((equal ans ?r)
7442 (org-agenda-do-action '(org-remember) t))
7443 ((equal ans ?c)
7444 (org-agenda-do-action '(org-capture) t))
7445 ((equal ans ?\ )
7446 (let ((cw (selected-window)))
7447 (org-switch-to-buffer-other-window
7448 (marker-buffer org-agenda-action-marker))
7449 (goto-char org-agenda-action-marker)
7450 (org-show-context 'agenda)
7451 (select-window cw)))
7452 ((equal ans ?\C-i)
7453 (org-switch-to-buffer-other-window
7454 (marker-buffer org-agenda-action-marker))
7455 (goto-char org-agenda-action-marker)
7456 (org-show-context 'agenda))
7457 (t (error "Invalid agenda action %c" ans)))))
7459 (defun org-agenda-do-action (form &optional current-buffer)
7460 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7461 (let ((org-overriding-default-time (org-get-cursor-date)))
7462 (if current-buffer
7463 (eval form)
7464 (if (not (marker-buffer org-agenda-action-marker))
7465 (error "No entry has been selected for agenda action")
7466 (with-current-buffer (marker-buffer org-agenda-action-marker)
7467 (save-excursion
7468 (save-restriction
7469 (widen)
7470 (goto-char org-agenda-action-marker)
7471 (eval form))))))))
7473 (defun org-agenda-clock-in (&optional arg)
7474 "Start the clock on the currently selected item."
7475 (interactive "P")
7476 (org-agenda-check-no-diary)
7477 (if (equal arg '(4))
7478 (org-clock-in arg)
7479 (let* ((marker (or (org-get-at-bol 'org-marker)
7480 (org-agenda-error)))
7481 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7482 marker))
7483 (pos (marker-position marker))
7484 newhead)
7485 (org-with-remote-undo (marker-buffer marker)
7486 (with-current-buffer (marker-buffer marker)
7487 (widen)
7488 (goto-char pos)
7489 (org-show-context 'agenda)
7490 (org-show-entry)
7491 (org-cycle-hide-drawers 'children)
7492 (org-clock-in arg)
7493 (setq newhead (org-get-heading)))
7494 (org-agenda-change-all-lines newhead hdmarker)))))
7496 (defun org-agenda-clock-out ()
7497 "Stop the currently running clock."
7498 (interactive)
7499 (unless (marker-buffer org-clock-marker)
7500 (error "No running clock"))
7501 (let ((marker (make-marker)) newhead)
7502 (org-with-remote-undo (marker-buffer org-clock-marker)
7503 (with-current-buffer (marker-buffer org-clock-marker)
7504 (save-excursion
7505 (save-restriction
7506 (widen)
7507 (goto-char org-clock-marker)
7508 (org-back-to-heading t)
7509 (move-marker marker (point))
7510 (org-clock-out)
7511 (setq newhead (org-get-heading))))))
7512 (org-agenda-change-all-lines newhead marker)
7513 (move-marker marker nil)))
7515 (defun org-agenda-clock-cancel (&optional arg)
7516 "Cancel the currently running clock."
7517 (interactive "P")
7518 (unless (marker-buffer org-clock-marker)
7519 (error "No running clock"))
7520 (org-with-remote-undo (marker-buffer org-clock-marker)
7521 (org-clock-cancel)))
7523 (defun org-agenda-clock-goto ()
7524 "Jump to the currently clocked in task within the agenda.
7525 If the currently clocked in task is not listed in the agenda
7526 buffer, display it in another window."
7527 (interactive)
7528 (let (pos)
7529 (mapc (lambda (o)
7530 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7531 (setq pos (overlay-start o))))
7532 (overlays-in (point-min) (point-max)))
7533 (cond (pos (goto-char pos))
7534 ;; If the currently clocked entry is not in the agenda
7535 ;; buffer, we visit it in another window:
7536 (org-clock-current-task
7537 (org-switch-to-buffer-other-window (org-clock-goto)))
7538 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7540 (defun org-agenda-diary-entry-in-org-file ()
7541 "Make a diary entry in the file `org-agenda-diary-file'."
7542 (let (d1 d2 char (text "") dp1 dp2)
7543 (if (equal (buffer-name) "*Calendar*")
7544 (setq d1 (calendar-cursor-to-date t)
7545 d2 (car calendar-mark-ring))
7546 (setq dp1 (get-text-property (point-at-bol) 'day))
7547 (unless dp1 (error "No date defined in current line"))
7548 (setq d1 (calendar-gregorian-from-absolute dp1)
7549 d2 (and (ignore-errors (mark))
7550 (save-excursion
7551 (goto-char (mark))
7552 (setq dp2 (get-text-property (point-at-bol) 'day)))
7553 (calendar-gregorian-from-absolute dp2))))
7554 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7555 (setq char (read-char-exclusive))
7556 (cond
7557 ((equal char ?d)
7558 (setq text (read-string "Day entry: "))
7559 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7560 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7561 ((equal char ?a)
7562 (setq d1 (list (car d1) (nth 1 d1)
7563 (read-number (format "Reference year [%d]: " (nth 2 d1))
7564 (nth 2 d1))))
7565 (setq text (read-string "Anniversary (use %d to show years): "))
7566 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7567 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7568 ((equal char ?b)
7569 (setq text (read-string "Block entry: "))
7570 (unless (and d1 d2 (not (equal d1 d2)))
7571 (error "No block of days selected"))
7572 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7573 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7574 ((equal char ?j)
7575 (org-switch-to-buffer-other-window
7576 (find-file-noselect org-agenda-diary-file))
7577 (require 'org-datetree)
7578 (org-datetree-find-date-create d1)
7579 (org-reveal t))
7580 (t (error "Invalid selection character `%c'" char)))))
7582 (defcustom org-agenda-insert-diary-strategy 'date-tree
7583 "Where in `org-agenda-diary-file' should new entries be added?
7584 Valid values:
7586 date-tree in the date tree, as child of the date
7587 top-level as top-level entries at the end of the file."
7588 :group 'org-agenda
7589 :type '(choice
7590 (const :tag "in a date tree" date-tree)
7591 (const :tag "as top level at end of file" top-level)))
7593 (defcustom org-agenda-insert-diary-extract-time nil
7594 "Non-nil means extract any time specification from the diary entry."
7595 :group 'org-agenda
7596 :type 'boolean)
7598 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7599 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7600 If TEXT is not empty, it will become the headline of the new entry, and
7601 the resulting entry will not be shown. When TEXT is empty, switch to
7602 `org-agenda-diary-file' and let the user finish the entry there."
7603 (let ((cw (current-window-configuration)))
7604 (org-switch-to-buffer-other-window
7605 (find-file-noselect org-agenda-diary-file))
7606 (widen)
7607 (goto-char (point-min))
7608 (cond
7609 ((eq type 'anniversary)
7610 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7611 (progn
7612 (or (org-on-heading-p t)
7613 (progn
7614 (outline-next-heading)
7615 (insert "* Anniversaries\n\n")
7616 (beginning-of-line -1)))))
7617 (outline-next-heading)
7618 (org-back-over-empty-lines)
7619 (backward-char 1)
7620 (insert "\n")
7621 (require 'diary-lib)
7622 (let ((calendar-date-display-form
7623 (if (if (boundp 'calendar-date-style)
7624 (eq calendar-date-style 'european)
7625 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7626 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7627 '(day " " month " " year)
7628 '(month " " day " " year))))
7630 (insert (format "%%%%(diary-anniversary %s) %s"
7631 (calendar-date-string d1 nil t) text))))
7632 ((eq type 'day)
7633 (let ((org-prefix-has-time t)
7634 (org-agenda-time-leading-zero t)
7635 fmt time time2)
7636 (if org-agenda-insert-diary-extract-time
7637 ;; Use org-format-agenda-item to parse text for a time-range and
7638 ;; remove it. FIXME: This is a hack, we should refactor
7639 ;; that function to make time extraction available separately
7640 (setq fmt (org-format-agenda-item nil text nil nil t)
7641 time (get-text-property 0 'time fmt)
7642 time2 (if (> (length time) 0)
7643 ;; split-string removes trailing ...... if
7644 ;; no end time given. First space
7645 ;; separates time from date.
7646 (concat " " (car (split-string time "\\.")))
7647 nil)
7648 text (get-text-property 0 'txt fmt)))
7649 (if (eq org-agenda-insert-diary-strategy 'top-level)
7650 (org-agenda-insert-diary-as-top-level text)
7651 (require 'org-datetree)
7652 (org-datetree-find-date-create d1)
7653 (org-agenda-insert-diary-make-new-entry text))
7654 (org-insert-time-stamp (org-time-from-absolute
7655 (calendar-absolute-from-gregorian d1))
7656 nil nil nil nil time2))
7657 (end-of-line 0))
7658 ((eq type 'block)
7659 (if (> (calendar-absolute-from-gregorian d1)
7660 (calendar-absolute-from-gregorian d2))
7661 (setq d1 (prog1 d2 (setq d2 d1))))
7662 (if (eq org-agenda-insert-diary-strategy 'top-level)
7663 (org-agenda-insert-diary-as-top-level text)
7664 (require 'org-datetree)
7665 (org-datetree-find-date-create d1)
7666 (org-agenda-insert-diary-make-new-entry text))
7667 (org-insert-time-stamp (org-time-from-absolute
7668 (calendar-absolute-from-gregorian d1)))
7669 (insert "--")
7670 (org-insert-time-stamp (org-time-from-absolute
7671 (calendar-absolute-from-gregorian d2)))
7672 (end-of-line 0)))
7673 (if (string-match "\\S-" text)
7674 (progn
7675 (set-window-configuration cw)
7676 (message "%s entry added to %s"
7677 (capitalize (symbol-name type))
7678 (abbreviate-file-name org-agenda-diary-file)))
7679 (org-reveal t)
7680 (message "Please finish entry here"))))
7682 (defun org-agenda-insert-diary-as-top-level (text)
7683 "Make new entry as a top-level entry at the end of the file.
7684 Add TEXT as headline, and position the cursor in the second line so that
7685 a timestamp can be added there."
7686 (widen)
7687 (goto-char (point-max))
7688 (or (bolp) (insert "\n"))
7689 (insert "* " text "\n")
7690 (if org-adapt-indentation (org-indent-to-column 2)))
7692 (defun org-agenda-insert-diary-make-new-entry (text)
7693 "Make new entry as last child of current entry.
7694 Add TEXT as headline, and position the cursor in the second line so that
7695 a timestamp can be added there."
7696 (let ((org-show-following-heading t)
7697 (org-show-siblings t)
7698 (org-show-hierarchy-above t)
7699 (org-show-entry-below t)
7700 col)
7701 (outline-next-heading)
7702 (org-back-over-empty-lines)
7703 (or (looking-at "[ \t]*$")
7704 (progn (insert "\n") (backward-char 1)))
7705 (org-insert-heading nil t)
7706 (org-do-demote)
7707 (setq col (current-column))
7708 (insert text "\n")
7709 (if org-adapt-indentation (org-indent-to-column col))
7710 (let ((org-show-following-heading t)
7711 (org-show-siblings t)
7712 (org-show-hierarchy-above t)
7713 (org-show-entry-below t))
7714 (org-show-context))))
7716 (defun org-agenda-diary-entry ()
7717 "Make a diary entry, like the `i' command from the calendar.
7718 All the standard commands work: block, weekly etc.
7719 When `org-agenda-diary-file' points to a file,
7720 `org-agenda-diary-entry-in-org-file' is called instead to create
7721 entries in that Org-mode file."
7722 (interactive)
7723 (org-agenda-check-type t 'agenda 'timeline)
7724 (if (not (eq org-agenda-diary-file 'diary-file))
7725 (org-agenda-diary-entry-in-org-file)
7726 (require 'diary-lib)
7727 (let* ((char (progn
7728 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7729 (read-char-exclusive)))
7730 (cmd (cdr (assoc char
7731 '((?d . insert-diary-entry)
7732 (?w . insert-weekly-diary-entry)
7733 (?m . insert-monthly-diary-entry)
7734 (?y . insert-yearly-diary-entry)
7735 (?a . insert-anniversary-diary-entry)
7736 (?b . insert-block-diary-entry)
7737 (?c . insert-cyclic-diary-entry)))))
7738 (oldf (symbol-function 'calendar-cursor-to-date))
7739 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7740 (point (point))
7741 (mark (or (mark t) (point))))
7742 (unless cmd
7743 (error "No command associated with <%c>" char))
7744 (unless (and (get-text-property point 'day)
7745 (or (not (equal ?b char))
7746 (get-text-property mark 'day)))
7747 (error "Don't know which date to use for diary entry"))
7748 ;; We implement this by hacking the `calendar-cursor-to-date' function
7749 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7750 (let ((calendar-mark-ring
7751 (list (calendar-gregorian-from-absolute
7752 (or (get-text-property mark 'day)
7753 (get-text-property point 'day))))))
7754 (unwind-protect
7755 (progn
7756 (fset 'calendar-cursor-to-date
7757 (lambda (&optional error dummy)
7758 (calendar-gregorian-from-absolute
7759 (get-text-property point 'day))))
7760 (call-interactively cmd))
7761 (fset 'calendar-cursor-to-date oldf))))))
7763 (defun org-agenda-execute-calendar-command (cmd)
7764 "Execute a calendar command from the agenda, with the date associated to
7765 the cursor position."
7766 (org-agenda-check-type t 'agenda 'timeline)
7767 (require 'diary-lib)
7768 (unless (get-text-property (point) 'day)
7769 (error "Don't know which date to use for calendar command"))
7770 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7771 (point (point))
7772 (date (calendar-gregorian-from-absolute
7773 (get-text-property point 'day)))
7774 ;; the following 2 vars are needed in the calendar
7775 (displayed-month (car date))
7776 (displayed-year (nth 2 date)))
7777 (unwind-protect
7778 (progn
7779 (fset 'calendar-cursor-to-date
7780 (lambda (&optional error dummy)
7781 (calendar-gregorian-from-absolute
7782 (get-text-property point 'day))))
7783 (call-interactively cmd))
7784 (fset 'calendar-cursor-to-date oldf))))
7786 (defun org-agenda-phases-of-moon ()
7787 "Display the phases of the moon for the 3 months around the cursor date."
7788 (interactive)
7789 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7791 (defun org-agenda-holidays ()
7792 "Display the holidays for the 3 months around the cursor date."
7793 (interactive)
7794 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7796 (defvar calendar-longitude)
7797 (defvar calendar-latitude)
7798 (defvar calendar-location-name)
7800 (defun org-agenda-sunrise-sunset (arg)
7801 "Display sunrise and sunset for the cursor date.
7802 Latitude and longitude can be specified with the variables
7803 `calendar-latitude' and `calendar-longitude'. When called with prefix
7804 argument, latitude and longitude will be prompted for."
7805 (interactive "P")
7806 (require 'solar)
7807 (let ((calendar-longitude (if arg nil calendar-longitude))
7808 (calendar-latitude (if arg nil calendar-latitude))
7809 (calendar-location-name
7810 (if arg "the given coordinates" calendar-location-name)))
7811 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7813 (defun org-agenda-goto-calendar ()
7814 "Open the Emacs calendar with the date at the cursor."
7815 (interactive)
7816 (org-agenda-check-type t 'agenda 'timeline)
7817 (let* ((day (or (get-text-property (point) 'day)
7818 (error "Don't know which date to open in calendar")))
7819 (date (calendar-gregorian-from-absolute day))
7820 (calendar-move-hook nil)
7821 (calendar-view-holidays-initially-flag nil)
7822 (calendar-view-diary-initially-flag nil))
7823 (calendar)
7824 (calendar-goto-date date)))
7826 ;;;###autoload
7827 (defun org-calendar-goto-agenda ()
7828 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7829 This is a command that has to be installed in `calendar-mode-map'."
7830 (interactive)
7831 (org-agenda-list nil (calendar-absolute-from-gregorian
7832 (calendar-cursor-to-date))
7833 nil))
7835 (defun org-agenda-convert-date ()
7836 (interactive)
7837 (org-agenda-check-type t 'agenda 'timeline)
7838 (let ((day (get-text-property (point) 'day))
7839 date s)
7840 (unless day
7841 (error "Don't know which date to convert"))
7842 (setq date (calendar-gregorian-from-absolute day))
7843 (setq s (concat
7844 "Gregorian: " (calendar-date-string date) "\n"
7845 "ISO: " (calendar-iso-date-string date) "\n"
7846 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7847 "Julian: " (calendar-julian-date-string date) "\n"
7848 "Astron. JD: " (calendar-astro-date-string date)
7849 " (Julian date number at noon UTC)\n"
7850 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7851 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7852 "French: " (calendar-french-date-string date) "\n"
7853 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7854 "Mayan: " (calendar-mayan-date-string date) "\n"
7855 "Coptic: " (calendar-coptic-date-string date) "\n"
7856 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7857 "Persian: " (calendar-persian-date-string date) "\n"
7858 "Chinese: " (calendar-chinese-date-string date) "\n"))
7859 (with-output-to-temp-buffer "*Dates*"
7860 (princ s))
7861 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7863 ;;; Bulk commands
7865 (defvar org-agenda-bulk-marked-entries nil
7866 "List of markers that refer to marked entries in the agenda.")
7868 (defun org-agenda-bulk-marked-p ()
7869 (eq (get-char-property (point-at-bol) 'type)
7870 'org-marked-entry-overlay))
7872 (defun org-agenda-bulk-mark (&optional arg)
7873 "Mark the entry at point for future bulk action."
7874 (interactive "p")
7875 (dotimes (i (max arg 1))
7876 (unless (org-get-at-bol 'org-agenda-diary-link)
7877 (let* ((m (org-get-at-bol 'org-hd-marker))
7879 (unless (org-agenda-bulk-marked-p)
7880 (unless m (error "Nothing to mark at point"))
7881 (push m org-agenda-bulk-marked-entries)
7882 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7883 (org-overlay-display ov "> "
7884 (org-get-todo-face "TODO")
7885 'evaporate)
7886 (overlay-put ov 'type 'org-marked-entry-overlay))
7887 (beginning-of-line 2)
7888 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7889 (beginning-of-line 2))
7890 (message "%d entries marked for bulk action"
7891 (length org-agenda-bulk-marked-entries))))))
7893 (defun org-agenda-bulk-mark-regexp (regexp)
7894 "Mark entries match REGEXP."
7895 (interactive "sRegexp: ")
7896 (save-excursion
7897 (goto-char (point-min))
7898 (while (re-search-forward regexp nil t)
7899 (call-interactively 'org-agenda-bulk-mark))))
7901 (defun org-agenda-bulk-unmark ()
7902 "Unmark the entry at point for future bulk action."
7903 (interactive)
7904 (when (org-agenda-bulk-marked-p)
7905 (org-agenda-bulk-remove-overlays
7906 (point-at-bol) (+ 2 (point-at-bol)))
7907 (setq org-agenda-bulk-marked-entries
7908 (delete (org-get-at-bol 'org-hd-marker)
7909 org-agenda-bulk-marked-entries)))
7910 (beginning-of-line 2)
7911 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7912 (beginning-of-line 2))
7913 (message "%d entries marked for bulk action"
7914 (length org-agenda-bulk-marked-entries)))
7916 (defun org-agenda-bulk-toggle ()
7917 "Toggle marking the entry at point for bulk action."
7918 (interactive)
7919 (if (org-agenda-bulk-marked-p)
7920 (org-agenda-bulk-unmark)
7921 (org-agenda-bulk-mark)))
7923 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7924 "Remove the mark overlays between BEG and END in the agenda buffer.
7925 BEG and END default to the buffer limits.
7927 This only removes the overlays, it does not remove the markers
7928 from the list in `org-agenda-bulk-marked-entries'."
7929 (interactive)
7930 (mapc (lambda (ov)
7931 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7932 (delete-overlay ov)))
7933 (overlays-in (or beg (point-min)) (or end (point-max)))))
7935 (defun org-agenda-bulk-remove-all-marks ()
7936 "Remove all marks in the agenda buffer.
7937 This will remove the markers, and the overlays."
7938 (interactive)
7939 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7940 (setq org-agenda-bulk-marked-entries nil)
7941 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7943 (defun org-agenda-bulk-action (&optional arg)
7944 "Execute an remote-editing action on all marked entries.
7945 The prefix arg is passed through to the command if possible."
7946 (interactive "P")
7947 (unless org-agenda-bulk-marked-entries
7948 (error "No entries are marked"))
7949 (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
7950 (let* ((action (read-char-exclusive))
7951 (org-log-refile (if org-log-refile 'time nil))
7952 (entries (reverse org-agenda-bulk-marked-entries))
7953 redo-at-end
7954 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7955 (cond
7956 ((equal action ?$)
7957 (setq cmd '(org-agenda-archive)))
7959 ((equal action ?A)
7960 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7962 ((member action '(?r ?w))
7963 (setq rfloc (org-refile-get-location
7964 "Refile to: "
7965 (marker-buffer (car org-agenda-bulk-marked-entries))
7966 org-refile-allow-creating-parent-nodes))
7967 (if (nth 3 rfloc)
7968 (setcar (nthcdr 3 rfloc)
7969 (move-marker (make-marker) (nth 3 rfloc)
7970 (or (get-file-buffer (nth 1 rfloc))
7971 (find-buffer-visiting (nth 1 rfloc))
7972 (error "This should not happen")))))
7974 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7975 redo-at-end t))
7977 ((equal action ?t)
7978 (setq state (org-icompleting-read
7979 "Todo state: "
7980 (with-current-buffer (marker-buffer (car entries))
7981 (mapcar 'list org-todo-keywords-1))))
7982 (setq cmd `(let ((org-inhibit-blocking t)
7983 (org-inhibit-logging 'note))
7984 (org-agenda-todo ,state))))
7986 ((memq action '(?- ?+))
7987 (setq tag (org-icompleting-read
7988 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
7989 (with-current-buffer (marker-buffer (car entries))
7990 (delq nil
7991 (mapcar (lambda (x)
7992 (if (stringp (car x)) x)) org-tag-alist)))))
7993 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
7995 ((memq action '(?s ?d))
7996 (let* ((date (unless arg
7997 (org-read-date
7998 nil nil nil
7999 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8000 (ans (if arg nil org-read-date-final-answer))
8001 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8002 (setq cmd `(let* ((bound (fboundp 'read-string))
8003 (old (and bound (symbol-function 'read-string))))
8004 (unwind-protect
8005 (progn
8006 (fset 'read-string (lambda (&rest ignore) ,ans))
8007 (eval '(,c1 arg)))
8008 (if bound
8009 (fset 'read-string old)
8010 (fmakunbound 'read-string)))))))
8012 ((eq action '?S)
8013 (let ((days (read-number
8014 (format "Scatter tasks across how many %sdays: "
8015 (if arg "week" "")) 7)))
8016 (setq cmd
8017 `(let ((distance (1+ (random ,days))))
8018 (if arg
8019 (let ((dist distance)
8020 (day-of-week
8021 (calendar-day-of-week
8022 (calendar-gregorian-from-absolute (org-today)))))
8023 (dotimes (i (1+ dist))
8024 (while (member day-of-week org-agenda-weekend-days)
8025 (incf distance)
8026 (incf day-of-week)
8027 (if (= day-of-week 7)
8028 (setq day-of-week 0)))
8029 (incf day-of-week)
8030 (if (= day-of-week 7)
8031 (setq day-of-week 0)))))
8032 (org-agenda-schedule nil (current-time))
8033 (org-agenda-date-later distance)))))
8035 (t (error "Invalid bulk action")))
8037 ;; Sort the markers, to make sure that parents are handled before children
8038 (setq entries (sort entries
8039 (lambda (a b)
8040 (cond
8041 ((equal (marker-buffer a) (marker-buffer b))
8042 (< (marker-position a) (marker-position b)))
8044 (string< (buffer-name (marker-buffer a))
8045 (buffer-name (marker-buffer b))))))))
8047 ;; Now loop over all markers and apply cmd
8048 (while (setq e (pop entries))
8049 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8050 (if (not pos)
8051 (progn (message "Skipping removed entry at %s" e)
8052 (setq cntskip (1+ cntskip)))
8053 (goto-char pos)
8054 (eval cmd)
8055 (setq org-agenda-bulk-marked-entries
8056 (delete e org-agenda-bulk-marked-entries))
8057 (setq cnt (1+ cnt))))
8058 (setq org-agenda-bulk-marked-entries nil)
8059 (org-agenda-bulk-remove-all-marks)
8060 (when redo-at-end (org-agenda-redo))
8061 (message "Acted on %d entries%s"
8063 (if (= cntskip 0)
8065 (format ", skipped %d (disappeared before their turn)"
8066 cntskip)))))
8068 ;;; Flagging notes
8070 (defun org-agenda-show-the-flagging-note ()
8071 "Display the flagging note in the other window.
8072 When called a second time in direct sequence, offer to remove the FLAGGING
8073 tag and (if present) the flagging note."
8074 (interactive)
8075 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8076 (win (selected-window))
8077 note heading newhead)
8078 (unless hdmarker
8079 (error "No linked entry at point"))
8080 (if (and (eq this-command last-command)
8081 (y-or-n-p "Unflag and remove any flagging note? "))
8082 (progn
8083 (org-agenda-remove-flag hdmarker)
8084 (let ((win (get-buffer-window "*Flagging Note*")))
8085 (and win (delete-window win)))
8086 (message "Entry unflaged"))
8087 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8088 (unless note
8089 (error "No flagging note"))
8090 (org-kill-new note)
8091 (org-switch-to-buffer-other-window "*Flagging Note*")
8092 (erase-buffer)
8093 (insert note)
8094 (goto-char (point-min))
8095 (while (re-search-forward "\\\\n" nil t)
8096 (replace-match "\n" t t))
8097 (goto-char (point-min))
8098 (select-window win)
8099 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8101 (defun org-agenda-remove-flag (marker)
8102 "Remove the FLAGGED tag and any flagging note in the entry."
8103 (let (newhead)
8104 (org-with-point-at marker
8105 (org-toggle-tag "FLAGGED" 'off)
8106 (org-entry-delete nil "THEFLAGGINGNOTE")
8107 (setq newhead (org-get-heading)))
8108 (org-agenda-change-all-lines newhead marker)
8109 (message "Entry unflaged")))
8111 (defun org-agenda-get-any-marker (&optional pos)
8112 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8113 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8115 ;;; Appointment reminders
8117 (defvar appt-time-msg-list)
8119 ;;;###autoload
8120 (defun org-agenda-to-appt (&optional refresh filter)
8121 "Activate appointments found in `org-agenda-files'.
8122 With a \\[universal-argument] prefix, refresh the list of
8123 appointments.
8125 If FILTER is t, interactively prompt the user for a regular
8126 expression, and filter out entries that don't match it.
8128 If FILTER is a string, use this string as a regular expression
8129 for filtering entries out.
8131 FILTER can also be an alist with the car of each cell being
8132 either 'headline or 'category. For example:
8134 '((headline \"IMPORTANT\")
8135 (category \"Work\"))
8137 will only add headlines containing IMPORTANT or headlines
8138 belonging to the \"Work\" category."
8139 (interactive "P")
8140 (if refresh (setq appt-time-msg-list nil))
8141 (if (eq filter t)
8142 (setq filter (read-from-minibuffer "Regexp filter: ")))
8143 (let* ((cnt 0) ; count added events
8144 (org-agenda-new-buffers nil)
8145 (org-deadline-warning-days 0)
8146 ;; Do not use `org-today' here because appt only takes
8147 ;; time and without date as argument, so it may pass wrong
8148 ;; information otherwise
8149 (today (org-date-to-gregorian
8150 (time-to-days (current-time))))
8151 (org-agenda-restrict nil)
8152 (files (org-agenda-files 'unrestricted)) entries file)
8153 ;; Get all entries which may contain an appt
8154 (org-prepare-agenda-buffers files)
8155 (while (setq file (pop files))
8156 (setq entries
8157 (append entries
8158 (org-agenda-get-day-entries
8159 file today :timestamp :scheduled :deadline))))
8160 (setq entries (delq nil entries))
8161 ;; Map thru entries and find if we should filter them out
8162 (mapc
8163 (lambda(x)
8164 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8165 (cat (get-text-property 1 'org-category x))
8166 (tod (get-text-property 1 'time-of-day x))
8167 (ok (or (null filter)
8168 (and (stringp filter) (string-match filter evt))
8169 (and (listp filter)
8170 (or (string-match
8171 (cadr (assoc 'category filter)) cat)
8172 (string-match
8173 (cadr (assoc 'headline filter)) evt))))))
8174 ;; FIXME: Shall we remove text-properties for the appt text?
8175 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8176 (when (and ok tod)
8177 (setq tod (concat "00" (number-to-string tod))
8178 tod (when (string-match
8179 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8180 (concat (match-string 1 tod) ":"
8181 (match-string 2 tod))))
8182 (appt-add tod evt)
8183 (setq cnt (1+ cnt))))) entries)
8184 (org-release-buffers org-agenda-new-buffers)
8185 (if (eq cnt 0)
8186 (message "No event to add")
8187 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8189 (defun org-agenda-todayp (date)
8190 "Does DATE mean today, when considering `org-extend-today-until'?"
8191 (let ((today (org-today))
8192 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8193 date)))
8194 (eq date today)))
8196 (provide 'org-agenda)
8198 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8200 ;;; org-agenda.el ends here