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