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