Refactor unescaping functions
[org-mode.git] / lisp / org-agenda.el
blob54de7750516df4f93b33e7a92c1472607289e65a
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
9 ;; Version: 7.4
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;; This file contains the code for creating and using the Agenda for Org-mode.
31 ;;; Code:
33 (require 'org)
34 (eval-when-compile
35 (require 'cl))
37 (declare-function diary-add-to-list "diary-lib"
38 (date string specifier &optional marker globcolor literal))
39 (declare-function calendar-absolute-from-iso "cal-iso" (date))
40 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
41 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
42 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
43 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
44 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
45 (declare-function calendar-french-date-string "cal-french" (&optional date))
46 (declare-function calendar-goto-date "cal-move" (date))
47 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
48 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
49 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
50 (declare-function calendar-iso-from-absolute "cal-iso" (date))
51 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
52 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
53 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
54 (declare-function org-datetree-find-date-create "org-datetree"
55 (date &optional keep-restriction))
56 (declare-function org-columns-quit "org-colview" ())
57 (declare-function diary-date-display-form "diary-lib" (&optional type))
58 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
59 (declare-function org-habit-insert-consistency-graphs
60 "org-habit" (&optional line))
61 (declare-function org-is-habit-p "org-habit" (&optional pom))
62 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
63 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
64 (defvar calendar-mode-map)
65 (defvar org-clock-current-task) ; defined in org-clock.el
66 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
67 (defvar org-habit-show-habits)
68 (defvar org-habit-show-habits-only-for-today)
70 ;; Defined somewhere in this file, but used before definition.
71 (defvar org-agenda-buffer-name)
72 (defvar org-agenda-overriding-header)
73 (defvar org-agenda-title-append nil)
74 (defvar entry)
75 (defvar date)
76 (defvar org-agenda-undo-list)
77 (defvar org-agenda-pending-undo-list)
78 (defvar original-date) ; dynamically scoped, calendar.el does scope this
80 (defcustom org-agenda-confirm-kill 1
81 "When set, remote killing from the agenda buffer needs confirmation.
82 When t, a confirmation is always needed. When a number N, confirmation is
83 only needed when the text to be killed contains more than N non-white lines."
84 :group 'org-agenda
85 :type '(choice
86 (const :tag "Never" nil)
87 (const :tag "Always" t)
88 (integer :tag "When more than N lines")))
90 (defcustom org-agenda-compact-blocks nil
91 "Non-nil means make the block agenda more compact.
92 This is done by leaving out unnecessary lines."
93 :group 'org-agenda
94 :type 'boolean)
96 (defcustom org-agenda-block-separator ?=
97 "The separator between blocks in the agenda.
98 If this is a string, it will be used as the separator, with a newline added.
99 If it is a character, it will be repeated to fill the window width."
100 :group 'org-agenda
101 :type '(choice
102 (character)
103 (string)))
105 (defgroup org-agenda-export nil
106 "Options concerning exporting agenda views in Org-mode."
107 :tag "Org Agenda Export"
108 :group 'org-agenda)
110 (defcustom org-agenda-with-colors t
111 "Non-nil means use colors in agenda views."
112 :group 'org-agenda-export
113 :type 'boolean)
115 (defcustom org-agenda-exporter-settings nil
116 "Alist of variable/value pairs that should be active during agenda export.
117 This is a good place to set options for ps-print and for htmlize.
118 Note that the way this is implemented, the values will be evaluated
119 before assigned to the variables. So make sure to quote values you do
120 *not* want evaluated, for example
122 (setq org-agenda-exporter-settings
123 '((ps-print-color-p 'black-white)))"
124 :group 'org-agenda-export
125 :type '(repeat
126 (list
127 (variable)
128 (sexp :tag "Value"))))
130 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
131 "Hook run in temporary buffer before writing it to an export file.
132 A useful function is `org-agenda-add-entry-text'."
133 :group 'org-agenda-export
134 :type 'hook
135 :options '(org-agenda-add-entry-text))
137 (defcustom org-agenda-add-entry-text-maxlines 0
138 "Maximum number of entry text lines to be added to agenda.
139 This is only relevant when `org-agenda-add-entry-text' is part of
140 `org-agenda-before-write-hook', which it is by default.
141 When this is 0, nothing will happen. When it is greater than 0, it
142 specifies the maximum number of lines that will be added for each entry
143 that is listed in the agenda view.
145 Note that this variable is not used during display, only when exporting
146 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
147 and `org-agenda-entry-text-maxlines'."
148 :group 'org-agenda
149 :type 'integer)
151 (defcustom org-agenda-add-entry-text-descriptive-links t
152 "Non-nil means export org-links as descriptive links in agenda added text.
153 This variable applies to the text added to the agenda when
154 `org-agenda-add-entry-text-maxlines' is larger than 0.
155 When this variable nil, the URL will (also) be shown."
156 :group 'org-agenda
157 :type 'boolean)
159 (defcustom org-agenda-export-html-style ""
160 "The style specification for exported HTML Agenda files.
161 If this variable contains a string, it will replace the default <style>
162 section as produced by `htmlize'.
163 Since there are different ways of setting style information, this variable
164 needs to contain the full HTML structure to provide a style, including the
165 surrounding HTML tags. The style specifications should include definitions
166 the fonts used by the agenda, here is an example:
168 <style type=\"text/css\">
169 p { font-weight: normal; color: gray; }
170 .org-agenda-structure {
171 font-size: 110%;
172 color: #003399;
173 font-weight: 600;
175 .org-todo {
176 color: #cc6666;
177 font-weight: bold;
179 .org-agenda-done {
180 color: #339933;
182 .org-done {
183 color: #339933;
185 .title { text-align: center; }
186 .todo, .deadline { color: red; }
187 .done { color: green; }
188 </style>
190 or, if you want to keep the style in a file,
192 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
194 As the value of this option simply gets inserted into the HTML <head> header,
195 you can \"misuse\" it to also add other text to the header. However,
196 <style>...</style> is required, if not present the variable will be ignored."
197 :group 'org-agenda-export
198 :group 'org-export-html
199 :type 'string)
201 (defcustom org-agenda-persistent-filter nil
202 "When set, keep filters from one agenda view to the next."
203 :group 'org-agenda
204 :type 'boolean)
206 (defgroup org-agenda-custom-commands nil
207 "Options concerning agenda views in Org-mode."
208 :tag "Org Agenda Custom Commands"
209 :group 'org-agenda)
211 (defconst org-sorting-choice
212 '(choice
213 (const time-up) (const time-down)
214 (const category-keep) (const category-up) (const category-down)
215 (const tag-down) (const tag-up)
216 (const priority-up) (const priority-down)
217 (const todo-state-up) (const todo-state-down)
218 (const effort-up) (const effort-down)
219 (const habit-up) (const habit-down)
220 (const alpha-up) (const alpha-down)
221 (const user-defined-up) (const user-defined-down))
222 "Sorting choices.")
224 (defconst org-agenda-custom-commands-local-options
225 `(repeat :tag "Local settings for this command. Remember to quote values"
226 (choice :tag "Setting"
227 (list :tag "Heading for this block"
228 (const org-agenda-overriding-header)
229 (string :tag "Headline"))
230 (list :tag "Files to be searched"
231 (const org-agenda-files)
232 (list
233 (const :format "" quote)
234 (repeat (file))))
235 (list :tag "Sorting strategy"
236 (const org-agenda-sorting-strategy)
237 (list
238 (const :format "" quote)
239 (repeat
240 ,org-sorting-choice)))
241 (list :tag "Prefix format"
242 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
243 (string))
244 (list :tag "Number of days in agenda"
245 (const org-agenda-span)
246 (choice (const :tag "Day" 'day)
247 (const :tag "Week" 'week)
248 (const :tag "Month" 'month)
249 (const :tag "Year" 'year)
250 (integer :tag "Custom")))
251 (list :tag "Fixed starting date"
252 (const org-agenda-start-day)
253 (string :value "2007-11-01"))
254 (list :tag "Start on day of week"
255 (const org-agenda-start-on-weekday)
256 (choice :value 1
257 (const :tag "Today" nil)
258 (integer :tag "Weekday No.")))
259 (list :tag "Include data from diary"
260 (const org-agenda-include-diary)
261 (boolean))
262 (list :tag "Deadline Warning days"
263 (const org-deadline-warning-days)
264 (integer :value 1))
265 (list :tag "Tags filter preset"
266 (const org-agenda-filter-preset)
267 (list
268 (const :format "" quote)
269 (repeat
270 (string :tag "+tag or -tag"))))
271 (list :tag "Set daily/weekly entry types"
272 (const org-agenda-entry-types)
273 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
274 (const :deadline)
275 (const :scheduled)
276 (const :timestamp)
277 (const :sexp)))
278 (list :tag "Standard skipping condition"
279 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
280 (const org-agenda-skip-function)
281 (list
282 (const :format "" quote)
283 (list
284 (choice
285 :tag "Skipping range"
286 (const :tag "Skip entry" org-agenda-skip-entry-if)
287 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
288 (repeat :inline t :tag "Conditions for skipping"
289 (choice
290 :tag "Condition type"
291 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
292 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
293 (list :tag "TODO state is" :inline t
294 (const 'todo)
295 (choice
296 (const :tag "any not-done state" 'todo)
297 (const :tag "any done state" 'done)
298 (const :tag "any state" 'any)
299 (list :tag "Keyword list"
300 (const :format "" quote)
301 (repeat (string :tag "Keyword")))))
302 (list :tag "TODO state is not" :inline t
303 (const 'nottodo)
304 (choice
305 (const :tag "any not-done state" 'todo)
306 (const :tag "any done state" 'done)
307 (const :tag "any state" 'any)
308 (list :tag "Keyword list"
309 (const :format "" quote)
310 (repeat (string :tag "Keyword")))))
311 (const :tag "scheduled" 'scheduled)
312 (const :tag "not scheduled" 'notscheduled)
313 (const :tag "deadline" 'deadline)
314 (const :tag "no deadline" 'notdeadline)
315 (const :tag "timestamp" 'timestamp)
316 (const :tag "no timestamp" 'nottimestamp))))))
317 (list :tag "Non-standard skipping condition"
318 :value (org-agenda-skip-function)
319 (const org-agenda-skip-function)
320 (sexp :tag "Function or form (quoted!)"))
321 (list :tag "Any variable"
322 (variable :tag "Variable")
323 (sexp :tag "Value (sexp)"))))
324 "Selection of examples for agenda command settings.
325 This will be spliced into the custom type of
326 `org-agenda-custom-commands'.")
329 (defcustom org-agenda-custom-commands nil
330 "Custom commands for the agenda.
331 These commands will be offered on the splash screen displayed by the
332 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
334 (key desc type match settings files)
336 key The key (one or more characters as a string) to be associated
337 with the command.
338 desc A description of the command, when omitted or nil, a default
339 description is built using MATCH.
340 type The command type, any of the following symbols:
341 agenda The daily/weekly agenda.
342 todo Entries with a specific TODO keyword, in all agenda files.
343 search Entries containing search words entry or headline.
344 tags Tags/Property/TODO match in all agenda files.
345 tags-todo Tags/P/T match in all agenda files, TODO entries only.
346 todo-tree Sparse tree of specific TODO keyword in *current* file.
347 tags-tree Sparse tree with all tags matches in *current* file.
348 occur-tree Occur sparse tree for *current* file.
349 ... A user-defined function.
350 match What to search for:
351 - a single keyword for TODO keyword searches
352 - a tags match expression for tags searches
353 - a word search expression for text searches.
354 - a regular expression for occur searches
355 For all other commands, this should be the empty string.
356 settings A list of option settings, similar to that in a let form, so like
357 this: ((opt1 val1) (opt2 val2) ...). The values will be
358 evaluated at the moment of execution, so quote them when needed.
359 files A list of files file to write the produced agenda buffer to
360 with the command `org-store-agenda-views'.
361 If a file name ends in \".html\", an HTML version of the buffer
362 is written out. If it ends in \".ps\", a postscript version is
363 produced. Otherwise, only the plain text is written to the file.
365 You can also define a set of commands, to create a composite agenda buffer.
366 In this case, an entry looks like this:
368 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
370 where
372 desc A description string to be displayed in the dispatcher menu.
373 cmd An agenda command, similar to the above. However, tree commands
374 are no allowed, but instead you can get agenda and global todo list.
375 So valid commands for a set are:
376 (agenda \"\" settings)
377 (alltodo \"\" settings)
378 (stuck \"\" settings)
379 (todo \"match\" settings files)
380 (search \"match\" settings files)
381 (tags \"match\" settings files)
382 (tags-todo \"match\" settings files)
384 Each command can carry a list of options, and another set of options can be
385 given for the whole set of commands. Individual command options take
386 precedence over the general options.
388 When using several characters as key to a command, the first characters
389 are prefix commands. For the dispatcher to display useful information, you
390 should provide a description for the prefix, like
392 (setq org-agenda-custom-commands
393 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
394 (\"hl\" tags \"+HOME+Lisa\")
395 (\"hp\" tags \"+HOME+Peter\")
396 (\"hk\" tags \"+HOME+Kim\")))"
397 :group 'org-agenda-custom-commands
398 :type `(repeat
399 (choice :value ("x" "Describe command here" tags "" nil)
400 (list :tag "Single command"
401 (string :tag "Access Key(s) ")
402 (option (string :tag "Description"))
403 (choice
404 (const :tag "Agenda" agenda)
405 (const :tag "TODO list" alltodo)
406 (const :tag "Search words" search)
407 (const :tag "Stuck projects" stuck)
408 (const :tag "Tags/Property match (all agenda files)" tags)
409 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
410 (const :tag "TODO keyword search (all agenda files)" todo)
411 (const :tag "Tags sparse tree (current buffer)" tags-tree)
412 (const :tag "TODO keyword tree (current buffer)" todo-tree)
413 (const :tag "Occur tree (current buffer)" occur-tree)
414 (sexp :tag "Other, user-defined function"))
415 (string :tag "Match (only for some commands)")
416 ,org-agenda-custom-commands-local-options
417 (option (repeat :tag "Export" (file :tag "Export to"))))
418 (list :tag "Command series, all agenda files"
419 (string :tag "Access Key(s)")
420 (string :tag "Description ")
421 (repeat :tag "Component"
422 (choice
423 (list :tag "Agenda"
424 (const :format "" agenda)
425 (const :tag "" :format "" "")
426 ,org-agenda-custom-commands-local-options)
427 (list :tag "TODO list (all keywords)"
428 (const :format "" alltodo)
429 (const :tag "" :format "" "")
430 ,org-agenda-custom-commands-local-options)
431 (list :tag "Search words"
432 (const :format "" search)
433 (string :tag "Match")
434 ,org-agenda-custom-commands-local-options)
435 (list :tag "Stuck projects"
436 (const :format "" stuck)
437 (const :tag "" :format "" "")
438 ,org-agenda-custom-commands-local-options)
439 (list :tag "Tags search"
440 (const :format "" tags)
441 (string :tag "Match")
442 ,org-agenda-custom-commands-local-options)
443 (list :tag "Tags search, TODO entries only"
444 (const :format "" tags-todo)
445 (string :tag "Match")
446 ,org-agenda-custom-commands-local-options)
447 (list :tag "TODO keyword search"
448 (const :format "" todo)
449 (string :tag "Match")
450 ,org-agenda-custom-commands-local-options)
451 (list :tag "Other, user-defined function"
452 (symbol :tag "function")
453 (string :tag "Match")
454 ,org-agenda-custom-commands-local-options)))
456 (repeat :tag "Settings for entire command set"
457 (list (variable :tag "Any variable")
458 (sexp :tag "Value")))
459 (option (repeat :tag "Export" (file :tag "Export to"))))
460 (cons :tag "Prefix key documentation"
461 (string :tag "Access Key(s)")
462 (string :tag "Description ")))))
464 (defcustom org-agenda-query-register ?o
465 "The register holding the current query string.
466 The purpose of this is that if you construct a query string interactively,
467 you can then use it to define a custom command."
468 :group 'org-agenda-custom-commands
469 :type 'character)
471 (defcustom org-stuck-projects
472 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
473 "How to identify stuck projects.
474 This is a list of four items:
475 1. A tags/todo/property matcher string that is used to identify a project.
476 See the manual for a description of tag and property searches.
477 The entire tree below a headline matched by this is considered one project.
478 2. A list of TODO keywords identifying non-stuck projects.
479 If the project subtree contains any headline with one of these todo
480 keywords, the project is considered to be not stuck. If you specify
481 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
482 3. A list of tags identifying non-stuck projects.
483 If the project subtree contains any headline with one of these tags,
484 the project is considered to be not stuck. If you specify \"*\" as
485 a tag, any tag will mark the project unstuck. Note that this is about
486 the explicit presence of a tag somewhere in the subtree, inherited
487 tags to not count here. If inherited tags make a project not stuck,
488 use \"-TAG\" in the tags part of the matcher under (1.) above.
489 4. An arbitrary regular expression matching non-stuck projects.
491 If the project turns out to be not stuck, search continues also in the
492 subtree to see if any of the subtasks have project status.
494 See also the variable `org-tags-match-list-sublevels' which applies
495 to projects matched by this search as well.
497 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
498 or `C-c a #' to produce the list."
499 :group 'org-agenda-custom-commands
500 :type '(list
501 (string :tag "Tags/TODO match to identify a project")
502 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
503 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
504 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
506 (defcustom org-agenda-filter-effort-default-operator "<"
507 "The default operator for effort estimate filtering.
508 If you select an effort estimate limit without first pressing an operator,
509 this one will be used."
510 :group 'org-agenda-custom-commands
511 :type '(choice (const :tag "less or equal" "<")
512 (const :tag "greater or equal"">")
513 (const :tag "equal" "=")))
515 (defgroup org-agenda-skip nil
516 "Options concerning skipping parts of agenda files."
517 :tag "Org Agenda Skip"
518 :group 'org-agenda)
520 (defcustom org-agenda-skip-function-global nil
521 "Function to be called at each match during agenda construction.
522 If this function returns nil, the current match should not be skipped.
523 If the function decided to skip an agenda match, is must return the
524 buffer position from which the search should be continued.
525 This may also be a Lisp form, which will be evaluated.
527 This variable will be applied to every agenda match, including
528 tags/property searches and TODO lists. So try to make the test function
529 do its checking as efficiently as possible. To implement a skipping
530 condition just for specific agenda commands, use the variable
531 `org-agenda-skip-function' which can be set in the options section
532 of custom agenda commands."
533 :group 'org-agenda-skip
534 :type 'sexp)
536 (defgroup org-agenda-daily/weekly nil
537 "Options concerning the daily/weekly agenda."
538 :tag "Org Agenda Daily/Weekly"
539 :group 'org-agenda)
540 (defgroup org-agenda-todo-list nil
541 "Options concerning the global todo list agenda view."
542 :tag "Org Agenda Todo List"
543 :group 'org-agenda)
544 (defgroup org-agenda-match-view nil
545 "Options concerning the general tags/property/todo match agenda view."
546 :tag "Org Agenda Match View"
547 :group 'org-agenda)
548 (defgroup org-agenda-search-view nil
549 "Options concerning the general tags/property/todo match agenda view."
550 :tag "Org Agenda Match View"
551 :group 'org-agenda)
553 (defvar org-agenda-archives-mode nil
554 "Non-nil means the agenda will include archived items.
555 If this is the symbol `trees', trees in the selected agenda scope
556 that are marked with the ARCHIVE tag will be included anyway. When this is
557 t, also all archive files associated with the current selection of agenda
558 files will be included.")
560 (defcustom org-agenda-skip-comment-trees t
561 "Non-nil means skip trees that start with the COMMENT keyword.
562 When nil, these trees are also scanned by agenda commands."
563 :group 'org-agenda-skip
564 :type 'boolean)
566 (defcustom org-agenda-todo-list-sublevels t
567 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
568 When nil, the sublevels of a TODO entry are not checked, resulting in
569 potentially much shorter TODO lists."
570 :group 'org-agenda-skip
571 :group 'org-agenda-todo-list
572 :type 'boolean)
574 (defcustom org-agenda-todo-ignore-with-date nil
575 "Non-nil means don't show entries with a date in the global todo list.
576 You can use this if you prefer to mark mere appointments with a TODO keyword,
577 but don't want them to show up in the TODO list.
578 When this is set, it also covers deadlines and scheduled items, the settings
579 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
580 will be ignored.
581 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
582 :group 'org-agenda-skip
583 :group 'org-agenda-todo-list
584 :type 'boolean)
586 (defcustom org-agenda-todo-ignore-timestamp nil
587 "Non-nil means don't show entries with a timestamp.
588 This applies when creating the global todo list.
589 Valid values are:
591 past Don't show entries for today or in the past.
593 future Don't show entries with a timestamp in the future.
594 The idea behind this is that if it has a future
595 timestamp, you don't want to think about it until the
596 date.
598 all Don't show any entries with a timestamp in the global todo list.
599 The idea behind this is that by setting a timestamp, you
600 have already \"taken care\" of this item.
602 This variable can also have an integer as a value. If positive (N),
603 todos with a timestamp N or more days in the future will be ignored. If
604 negative (-N), todos with a timestamp N or more days in the past will be
605 ignored. If 0, todos with a timestamp either today or in the future will
606 be ignored. For example, a value of -1 will exclude todos with a
607 timestamp in the past (yesterday or earlier), while a value of 7 will
608 exclude todos with a timestamp a week or more in the future.
610 See also `org-agenda-todo-ignore-with-date'.
611 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
612 to make his option also apply to the tags-todo list."
613 :group 'org-agenda-skip
614 :group 'org-agenda-todo-list
615 :type '(choice
616 (const :tag "Ignore future timestamp todos" future)
617 (const :tag "Ignore past or present timestamp todos" past)
618 (const :tag "Ignore all timestamp todos" all)
619 (const :tag "Show timestamp todos" nil)
620 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
622 (defcustom org-agenda-todo-ignore-scheduled nil
623 "Non-nil means, ignore some scheduled TODO items when making TODO list.
624 This applies when creating the global todo list.
625 Valid values are:
627 past Don't show entries scheduled today or in the past.
629 future Don't show entries scheduled in the future.
630 The idea behind this is that by scheduling it, you don't want to
631 think about it until the scheduled date.
633 all Don't show any scheduled entries in the global todo list.
634 The idea behind this is that by scheduling it, you have already
635 \"taken care\" of this item.
637 t Same as `all', for backward compatibility.
639 This variable can also have an integer as a value. See
640 `org-agenda-todo-ignore-timestamp' for more details.
642 See also `org-agenda-todo-ignore-with-date'.
643 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
644 to make his option also apply to the tags-todo list."
645 :group 'org-agenda-skip
646 :group 'org-agenda-todo-list
647 :type '(choice
648 (const :tag "Ignore future-scheduled todos" future)
649 (const :tag "Ignore past- or present-scheduled todos" past)
650 (const :tag "Ignore all scheduled todos" all)
651 (const :tag "Ignore all scheduled todos (compatibility)" t)
652 (const :tag "Show scheduled todos" nil)
653 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
655 (defcustom org-agenda-todo-ignore-deadlines nil
656 "Non-nil means ignore some deadlined TODO items when making TODO list.
657 There are different motivations for using different values, please think
658 carefully when configuring this variable.
660 This applies when creating the global todo list.
661 Valid values are:
663 near Don't show near deadline entries. A deadline is near when it is
664 closer than `org-deadline-warning-days' days. The idea behind this
665 is that such items will appear in the agenda anyway.
667 far Don't show TODO entries where a deadline has been defined, but
668 the deadline is not near. This is useful if you don't want to
669 use the todo list to figure out what to do now.
671 past Don't show entries with a deadline timestamp for today or in the past.
673 future Don't show entries with a deadline timestamp in the future, not even
674 when they become `near' ones. Use it with caution.
676 all Ignore all TODO entries that do have a deadline.
678 t Same as `near', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore near deadlines" near)
690 (const :tag "Ignore near deadlines (compatibility)" t)
691 (const :tag "Ignore far deadlines" far)
692 (const :tag "Ignore all TODOs with a deadlines" all)
693 (const :tag "Show all TODOs, even if they have a deadline" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-tags-todo-honor-ignore-options nil
697 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
698 The variables
699 `org-agenda-todo-ignore-with-date',
700 `org-agenda-todo-ignore-timestamp',
701 `org-agenda-todo-ignore-scheduled',
702 `org-agenda-todo-ignore-deadlines'
703 make the global TODO list skip entries that have time stamps of certain
704 kinds. If this option is set, the same options will also apply for the
705 tags-todo search, which is the general tags/property matcher
706 restricted to unfinished TODO entries only."
707 :group 'org-agenda-skip
708 :group 'org-agenda-todo-list
709 :group 'org-agenda-match-view
710 :type 'boolean)
712 (defcustom org-agenda-skip-scheduled-if-done nil
713 "Non-nil means don't show scheduled items in agenda when they are done.
714 This is relevant for the daily/weekly agenda, not for the TODO list. And
715 it applies only to the actual date of the scheduling. Warnings about
716 an item with a past scheduling dates are always turned off when the item
717 is DONE."
718 :group 'org-agenda-skip
719 :group 'org-agenda-daily/weekly
720 :type 'boolean)
722 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
723 "Non-nil means skip scheduling line if same entry shows because of deadline.
724 In the agenda of today, an entry can show up multiple times because
725 it is both scheduled and has a nearby deadline, and maybe a plain time
726 stamp as well.
727 When this variable is t, then only the deadline is shown and the fact that
728 the entry is scheduled today or was scheduled previously is not shown.
729 When this variable is nil, the entry will be shown several times. When
730 the variable is the symbol `not-today', then skip scheduled previously,
731 but not scheduled today."
732 :group 'org-agenda-skip
733 :group 'org-agenda-daily/weekly
734 :type '(choice
735 (const :tag "Never" nil)
736 (const :tag "Always" t)
737 (const :tag "Not when scheduled today" not-today)))
739 (defcustom org-agenda-skip-deadline-if-done nil
740 "Non-nil means don't show deadlines when the corresponding item is done.
741 When nil, the deadline is still shown and should give you a happy feeling.
742 This is relevant for the daily/weekly agenda. And it applied only to the
743 actually date of the deadline. Warnings about approaching and past-due
744 deadlines are always turned off when the item is DONE."
745 :group 'org-agenda-skip
746 :group 'org-agenda-daily/weekly
747 :type 'boolean)
749 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
750 "Non-nil means skip deadline prewarning when entry is also scheduled.
751 This will apply on all days where a prewarning for the deadline would
752 be shown, but not at the day when the entry is actually due. On that day,
753 the deadline will be shown anyway.
754 This variable may be set to nil, t, or a number which will then give
755 the number of days before the actual deadline when the prewarnings
756 should resume.
757 This can be used in a workflow where the first showing of the deadline will
758 trigger you to schedule it, and then you don't want to be reminded of it
759 because you will take care of it on the day when scheduled."
760 :group 'org-agenda-skip
761 :group 'org-agenda-daily/weekly
762 :type '(choice
763 (const :tag "Alwas show prewarning" nil)
764 (const :tag "Remove prewarning if entry is scheduled" t)
765 (integer :tag "Restart prewarning N days before deadline")))
767 (defcustom org-agenda-skip-additional-timestamps-same-entry t
768 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
769 When non-nil, after the search for timestamps has matched once in an
770 entry, the rest of the entry will not be searched."
771 :group 'org-agenda-skip
772 :type 'boolean)
774 (defcustom org-agenda-skip-timestamp-if-done nil
775 "Non-nil means don't select item by timestamp or -range if it is DONE."
776 :group 'org-agenda-skip
777 :group 'org-agenda-daily/weekly
778 :type 'boolean)
780 (defcustom org-agenda-dim-blocked-tasks t
781 "Non-nil means dim blocked tasks in the agenda display.
782 This causes some overhead during agenda construction, but if you
783 have turned on `org-enforce-todo-dependencies',
784 `org-enforce-todo-checkbox-dependencies', or any other blocking
785 mechanism, this will create useful feedback in the agenda.
787 Instead of t, this variable can also have the value `invisible'.
788 Then blocked tasks will be invisible and only become visible when
789 they become unblocked. An exemption to this behavior is when a task is
790 blocked because of unchecked checkboxes below it. Since checkboxes do
791 not show up in the agenda views, making this task invisible you remove any
792 trace from agenda views that there is something to do. Therefore, a task
793 that is blocked because of checkboxes will never be made invisible, it
794 will only be dimmed."
795 :group 'org-agenda-daily/weekly
796 :group 'org-agenda-todo-list
797 :type '(choice
798 (const :tag "Do not dim" nil)
799 (const :tag "Dim to a grey face" t)
800 (const :tag "Make invisible" invisible)))
802 (defcustom org-timeline-show-empty-dates 3
803 "Non-nil means `org-timeline' also shows dates without an entry.
804 When nil, only the days which actually have entries are shown.
805 When t, all days between the first and the last date are shown.
806 When an integer, show also empty dates, but if there is a gap of more than
807 N days, just insert a special line indicating the size of the gap."
808 :group 'org-agenda-skip
809 :type '(choice
810 (const :tag "None" nil)
811 (const :tag "All" t)
812 (integer :tag "at most")))
814 (defgroup org-agenda-startup nil
815 "Options concerning initial settings in the Agenda in Org Mode."
816 :tag "Org Agenda Startup"
817 :group 'org-agenda)
819 (defcustom org-agenda-menu-show-matcher t
820 "Non-nil means show the match string in the agenda dispatcher menu.
821 When nil, the matcher string is not shown, but is put into the help-echo
822 property so than moving the mouse over the command shows it.
823 Setting it to nil is good if matcher strings are very long and/or if
824 you want to use two-column display (see `org-agenda-menu-two-column')."
825 :group 'org-agenda
826 :type 'boolean)
828 (defcustom org-agenda-menu-two-column nil
829 "Non-nil means, use two columns to show custom commands in the dispatcher.
830 If you use this, you probably want to set `org-agenda-menu-show-matcher'
831 to nil."
832 :group 'org-agenda
833 :type 'boolean)
835 (defcustom org-finalize-agenda-hook nil
836 "Hook run just before displaying an agenda buffer."
837 :group 'org-agenda-startup
838 :type 'hook)
840 (defcustom org-agenda-mouse-1-follows-link nil
841 "Non-nil means mouse-1 on a link will follow the link in the agenda.
842 A longer mouse click will still set point. Does not work on XEmacs.
843 Needs to be set before org.el is loaded."
844 :group 'org-agenda-startup
845 :type 'boolean)
847 (defcustom org-agenda-start-with-follow-mode nil
848 "The initial value of follow mode in a newly created agenda window."
849 :group 'org-agenda-startup
850 :type 'boolean)
852 (defcustom org-agenda-show-outline-path t
853 "Non-nil means show outline path in echo area after line motion."
854 :group 'org-agenda-startup
855 :type 'boolean)
857 (defcustom org-agenda-start-with-entry-text-mode nil
858 "The initial value of entry-text-mode in a newly created agenda window."
859 :group 'org-agenda-startup
860 :type 'boolean)
862 (defcustom org-agenda-entry-text-maxlines 5
863 "Number of text lines to be added when `E' is pressed in the agenda.
865 Note that this variable only used during agenda display. Add add entry text
866 when exporting the agenda, configure the variable
867 `org-agenda-add-entry-ext-maxlines'."
868 :group 'org-agenda
869 :type 'integer)
871 (defcustom org-agenda-entry-text-exclude-regexps nil
872 "List of regular expressions to clean up entry text.
873 The complete matches of all regular expressions in this list will be
874 removed from entry text before it is shown in the agenda."
875 :group 'org-agenda
876 :type '(repeat (regexp)))
878 (defvar org-agenda-entry-text-cleanup-hook nil
879 "Hook that is run after basic cleanup of entry text to be shown in agenda.
880 This cleanup is done in a temporary buffer, so the function may inspect and
881 change the entire buffer.
882 Some default stuff like drawers and scheduling/deadline dates will already
883 have been removed when this is called, as will any matches for regular
884 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
886 (defvar org-agenda-include-inactive-timestamps nil
887 "Non-nil means include inactive time stamps in agenda and timeline.")
889 (defgroup org-agenda-windows nil
890 "Options concerning the windows used by the Agenda in Org Mode."
891 :tag "Org Agenda Windows"
892 :group 'org-agenda)
894 (defcustom org-agenda-window-setup 'reorganize-frame
895 "How the agenda buffer should be displayed.
896 Possible values for this option are:
898 current-window Show agenda in the current window, keeping all other windows.
899 other-window Use `switch-to-buffer-other-window' to display agenda.
900 reorganize-frame Show only two windows on the current frame, the current
901 window and the agenda.
902 other-frame Use `switch-to-buffer-other-frame' to display agenda.
903 Also, when exiting the agenda, kill that frame.
904 See also the variable `org-agenda-restore-windows-after-quit'."
905 :group 'org-agenda-windows
906 :type '(choice
907 (const current-window)
908 (const other-frame)
909 (const other-window)
910 (const reorganize-frame)))
912 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
913 "The min and max height of the agenda window as a fraction of frame height.
914 The value of the variable is a cons cell with two numbers between 0 and 1.
915 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
916 :group 'org-agenda-windows
917 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
919 (defcustom org-agenda-restore-windows-after-quit nil
920 "Non-nil means restore window configuration upon exiting agenda.
921 Before the window configuration is changed for displaying the agenda,
922 the current status is recorded. When the agenda is exited with
923 `q' or `x' and this option is set, the old state is restored. If
924 `org-agenda-window-setup' is `other-frame', the value of this
925 option will be ignored."
926 :group 'org-agenda-windows
927 :type 'boolean)
929 (defcustom org-agenda-ndays nil
930 "Number of days to include in overview display.
931 Should be 1 or 7.
932 Obsolete, see `org-agenda-span'."
933 :group 'org-agenda-daily/weekly
934 :type 'integer)
936 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
938 (defcustom org-agenda-span 'week
939 "Number of days to include in overview display.
940 Can be day, week, month, year, or any number of days.
941 Custom commands can set this variable in the options section."
942 :group 'org-agenda-daily/weekly
943 :type '(choice (const :tag "Day" day)
944 (const :tag "Week" week)
945 (const :tag "Month" month)
946 (const :tag "Year" year)
947 (integer :tag "Custom")))
949 (defcustom org-agenda-start-on-weekday 1
950 "Non-nil means start the overview always on the specified weekday.
951 0 denotes Sunday, 1 denotes Monday etc.
952 When nil, always start on the current day.
953 Custom commands can set this variable in the options section."
954 :group 'org-agenda-daily/weekly
955 :type '(choice (const :tag "Today" nil)
956 (integer :tag "Weekday No.")))
958 (defcustom org-agenda-show-all-dates t
959 "Non-nil means `org-agenda' shows every day in the selected range.
960 When nil, only the days which actually have entries are shown."
961 :group 'org-agenda-daily/weekly
962 :type 'boolean)
964 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
965 "Format string for displaying dates in the agenda.
966 Used by the daily/weekly agenda and by the timeline. This should be
967 a format string understood by `format-time-string', or a function returning
968 the formatted date as a string. The function must take a single argument,
969 a calendar-style date list like (month day year)."
970 :group 'org-agenda-daily/weekly
971 :type '(choice
972 (string :tag "Format string")
973 (function :tag "Function")))
975 (defun org-agenda-format-date-aligned (date)
976 "Format a date string for display in the daily/weekly agenda, or timeline.
977 This function makes sure that dates are aligned for easy reading."
978 (require 'cal-iso)
979 (let* ((dayname (calendar-day-name date))
980 (day (cadr date))
981 (day-of-week (calendar-day-of-week date))
982 (month (car date))
983 (monthname (calendar-month-name month))
984 (year (nth 2 date))
985 (iso-week (org-days-to-iso-week
986 (calendar-absolute-from-gregorian date)))
987 (weekyear (cond ((and (= month 1) (>= iso-week 52))
988 (1- year))
989 ((and (= month 12) (<= iso-week 1))
990 (1+ year))
991 (t year)))
992 (weekstring (if (= day-of-week 1)
993 (format " W%02d" iso-week)
994 "")))
995 (format "%-10s %2d %s %4d%s"
996 dayname day monthname year weekstring)))
998 (defcustom org-agenda-time-leading-zero nil
999 "Non-nil means use leading zero for military times in agenda.
1000 For example, 9:30am would become 09:30 rather than 9:30."
1001 :group 'org-agenda-daily/weekly
1002 :type 'boolean)
1004 (defcustom org-agenda-timegrid-use-ampm nil
1005 "When set, show AM/PM style timestamps on the timegrid."
1006 :group 'org-agenda
1007 :type 'boolean)
1009 (defun org-agenda-time-of-day-to-ampm (time)
1010 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1011 (let* ((hour-number (string-to-number (substring time 0 -3)))
1012 (minute (substring time -2))
1013 (ampm "am"))
1014 (cond
1015 ((equal hour-number 12)
1016 (setq ampm "pm"))
1017 ((> hour-number 12)
1018 (setq ampm "pm")
1019 (setq hour-number (- hour-number 12))))
1020 (concat
1021 (if org-agenda-time-leading-zero
1022 (format "%02d" hour-number)
1023 (format "%02s" (number-to-string hour-number)))
1024 ":" minute ampm)))
1026 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1027 "Conditionally convert TIME to AM/PM format
1028 based on `org-agenda-timegrid-use-ampm'"
1029 (if org-agenda-timegrid-use-ampm
1030 (org-agenda-time-of-day-to-ampm time)
1031 time))
1033 (defcustom org-agenda-weekend-days '(6 0)
1034 "Which days are weekend?
1035 These days get the special face `org-agenda-date-weekend' in the agenda
1036 and timeline buffers."
1037 :group 'org-agenda-daily/weekly
1038 :type '(set :greedy t
1039 (const :tag "Monday" 1)
1040 (const :tag "Tuesday" 2)
1041 (const :tag "Wednesday" 3)
1042 (const :tag "Thursday" 4)
1043 (const :tag "Friday" 5)
1044 (const :tag "Saturday" 6)
1045 (const :tag "Sunday" 0)))
1047 (defcustom org-agenda-include-diary nil
1048 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1049 Custom commands can set this variable in the options section."
1050 :group 'org-agenda-daily/weekly
1051 :type 'boolean)
1053 (defcustom org-agenda-include-deadlines t
1054 "If non-nil, include entries within their deadline warning period.
1055 Custom commands can set this variable in the options section."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-include-all-todo nil
1060 "Set means weekly/daily agenda will always contain all TODO entries.
1061 The TODO entries will be listed at the top of the agenda, before
1062 the entries for specific days.
1063 This option is deprecated, it is better to define a block agenda instead."
1064 :group 'org-agenda-daily/weekly
1065 :type 'boolean)
1067 (defcustom org-agenda-repeating-timestamp-show-all t
1068 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1069 When set to a list of strings, only show occurrences of repeating
1070 stamps for these TODO keywords. When nil, only one occurrence is
1071 shown, either today or the nearest into the future."
1072 :group 'org-agenda-daily/weekly
1073 :type '(choice
1074 (const :tag "Show repeating stamps" t)
1075 (repeat :tag "Show repeating stamps for these TODO keywords"
1076 (string :tag "TODO Keyword"))
1077 (const :tag "Don't show repeating stamps" nil)))
1079 (defcustom org-scheduled-past-days 10000
1080 "No. of days to continue listing scheduled items that are not marked DONE.
1081 When an item is scheduled on a date, it shows up in the agenda on this
1082 day and will be listed until it is marked done for the number of days
1083 given here."
1084 :group 'org-agenda-daily/weekly
1085 :type 'integer)
1087 (defcustom org-agenda-log-mode-items '(closed clock)
1088 "List of items that should be shown in agenda log mode.
1089 This list may contain the following symbols:
1091 closed Show entries that have been closed on that day.
1092 clock Show entries that have received clocked time on that day.
1093 state Show all logged state changes.
1094 Note that instead of changing this variable, you can also press `C-u l' in
1095 the agenda to display all available LOG items temporarily."
1096 :group 'org-agenda-daily/weekly
1097 :type '(set :greedy t (const closed) (const clock) (const state)))
1099 (defcustom org-agenda-log-mode-add-notes t
1100 "Non-nil means add first line of notes to log entries in agenda views.
1101 If a log item like a state change or a clock entry is associated with
1102 notes, the first line of these notes will be added to the entry in the
1103 agenda display."
1104 :group 'org-agenda-daily/weekly
1105 :type 'boolean)
1107 (defcustom org-agenda-start-with-log-mode nil
1108 "The initial value of log-mode in a newly created agenda window."
1109 :group 'org-agenda-startup
1110 :group 'org-agenda-daily/weekly
1111 :type 'boolean)
1113 (defcustom org-agenda-start-with-clockreport-mode nil
1114 "The initial value of clockreport-mode in a newly created agenda window."
1115 :group 'org-agenda-startup
1116 :group 'org-agenda-daily/weekly
1117 :type 'boolean)
1119 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1120 "Property list with parameters for the clocktable in clockreport mode.
1121 This is the display mode that shows a clock table in the daily/weekly
1122 agenda, the properties for this dynamic block can be set here.
1123 The usual clocktable parameters are allowed here, but you cannot set
1124 the properties :name, :tstart, :tend, :block, and :scope - these will
1125 be overwritten to make sure the content accurately reflects the
1126 current display in the agenda."
1127 :group 'org-agenda-daily/weekly
1128 :type 'plist)
1130 (defcustom org-agenda-search-view-always-boolean nil
1131 "Non-nil means the search string is interpreted as individual parts.
1133 The search string for search view can either be interpreted as a phrase,
1134 or as a list of snippets that define a boolean search for a number of
1135 strings.
1137 When this is non-nil, the string will be split on whitespace, and each
1138 snippet will be searched individually, and all must match in order to
1139 select an entry. A snippet is then a single string of non-white
1140 characters, or a string in double quotes, or a regexp in {} braces.
1141 If a snippet is preceded by \"-\", the snippet must *not* match.
1142 \"+\" is syntactic sugar for positive selection. Each snippet may
1143 be found as a full word or a partial word, but see the variable
1144 `org-agenda-search-view-force-full-words'.
1146 When this is nil, search will look for the entire search phrase as one,
1147 with each space character matching any amount of whitespace, including
1148 line breaks.
1150 Even when this is nil, you can still switch to Boolean search dynamically
1151 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1152 is a regexp marked with braces like \"{abc}\", this will also switch to
1153 boolean search."
1154 :group 'org-agenda-search-view
1155 :type 'boolean)
1157 (if (fboundp 'defvaralias)
1158 (defvaralias 'org-agenda-search-view-search-words-only
1159 'org-agenda-search-view-always-boolean))
1161 (defcustom org-agenda-search-view-force-full-words nil
1162 "Non-nil means, search words must be matches as complete words.
1163 When nil, they may also match part of a word."
1164 :group 'org-agenda-search-view
1165 :type 'boolean)
1167 (defgroup org-agenda-time-grid nil
1168 "Options concerning the time grid in the Org-mode Agenda."
1169 :tag "Org Agenda Time Grid"
1170 :group 'org-agenda)
1172 (defcustom org-agenda-search-headline-for-time t
1173 "Non-nil means search headline for a time-of-day.
1174 If the headline contains a time-of-day in one format or another, it will
1175 be used to sort the entry into the time sequence of items for a day.
1176 Some people have time stamps in the headline that refer to the creation
1177 time or so, and then this produces an unwanted side effect. If this is
1178 the case for your, use this variable to turn off searching the headline
1179 for a time."
1180 :group 'org-agenda-time-grid
1181 :type 'boolean)
1183 (defcustom org-agenda-use-time-grid t
1184 "Non-nil means show a time grid in the agenda schedule.
1185 A time grid is a set of lines for specific times (like every two hours between
1186 8:00 and 20:00). The items scheduled for a day at specific times are
1187 sorted in between these lines.
1188 For details about when the grid will be shown, and what it will look like, see
1189 the variable `org-agenda-time-grid'."
1190 :group 'org-agenda-time-grid
1191 :type 'boolean)
1193 (defcustom org-agenda-time-grid
1194 '((daily today require-timed)
1195 "----------------"
1196 (800 1000 1200 1400 1600 1800 2000))
1198 "The settings for time grid for agenda display.
1199 This is a list of three items. The first item is again a list. It contains
1200 symbols specifying conditions when the grid should be displayed:
1202 daily if the agenda shows a single day
1203 weekly if the agenda shows an entire week
1204 today show grid on current date, independent of daily/weekly display
1205 require-timed show grid only if at least one item has a time specification
1207 The second item is a string which will be placed behind the grid time.
1209 The third item is a list of integers, indicating the times that should have
1210 a grid line."
1211 :group 'org-agenda-time-grid
1212 :type
1213 '(list
1214 (set :greedy t :tag "Grid Display Options"
1215 (const :tag "Show grid in single day agenda display" daily)
1216 (const :tag "Show grid in weekly agenda display" weekly)
1217 (const :tag "Always show grid for today" today)
1218 (const :tag "Show grid only if any timed entries are present"
1219 require-timed)
1220 (const :tag "Skip grid times already present in an entry"
1221 remove-match))
1222 (string :tag "Grid String")
1223 (repeat :tag "Grid Times" (integer :tag "Time"))))
1225 (defcustom org-agenda-show-current-time-in-grid t
1226 "Non-nil means show the current time in the time grid."
1227 :group 'org-agenda-time-grid
1228 :type 'boolean)
1230 (defcustom org-agenda-current-time-string
1231 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1232 "The string for the current time marker in the agenda."
1233 :group 'org-agenda-time-grid
1234 :type 'string)
1236 (defgroup org-agenda-sorting nil
1237 "Options concerning sorting in the Org-mode Agenda."
1238 :tag "Org Agenda Sorting"
1239 :group 'org-agenda)
1241 (defcustom org-agenda-sorting-strategy
1242 '((agenda habit-down time-up priority-down category-keep)
1243 (todo priority-down category-keep)
1244 (tags priority-down category-keep)
1245 (search category-keep))
1246 "Sorting structure for the agenda items of a single day.
1247 This is a list of symbols which will be used in sequence to determine
1248 if an entry should be listed before another entry. The following
1249 symbols are recognized:
1251 time-up Put entries with time-of-day indications first, early first
1252 time-down Put entries with time-of-day indications first, late first
1253 category-keep Keep the default order of categories, corresponding to the
1254 sequence in `org-agenda-files'.
1255 category-up Sort alphabetically by category, A-Z.
1256 category-down Sort alphabetically by category, Z-A.
1257 tag-up Sort alphabetically by last tag, A-Z.
1258 tag-down Sort alphabetically by last tag, Z-A.
1259 priority-up Sort numerically by priority, high priority last.
1260 priority-down Sort numerically by priority, high priority first.
1261 todo-state-up Sort by todo state, tasks that are done last.
1262 todo-state-down Sort by todo state, tasks that are done first.
1263 effort-up Sort numerically by estimated effort, high effort last.
1264 effort-down Sort numerically by estimated effort, high effort first.
1265 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1266 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1267 habit-up Put entries that are habits first
1268 habit-down Put entries that are habits last
1269 alpha-up Sort headlines alphabetically
1270 alpha-down Sort headlines alphabetically, reversed
1272 The different possibilities will be tried in sequence, and testing stops
1273 if one comparison returns a \"not-equal\". For example, the default
1274 '(time-up category-keep priority-down)
1275 means: Pull out all entries having a specified time of day and sort them,
1276 in order to make a time schedule for the current day the first thing in the
1277 agenda listing for the day. Of the entries without a time indication, keep
1278 the grouped in categories, don't sort the categories, but keep them in
1279 the sequence given in `org-agenda-files'. Within each category sort by
1280 priority.
1282 Leaving out `category-keep' would mean that items will be sorted across
1283 categories by priority.
1285 Instead of a single list, this can also be a set of list for specific
1286 contents, with a context symbol in the car of the list, any of
1287 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1289 Custom commands can bind this variable in the options section."
1290 :group 'org-agenda-sorting
1291 :type `(choice
1292 (repeat :tag "General" ,org-sorting-choice)
1293 (list :tag "Individually"
1294 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1295 (repeat ,org-sorting-choice))
1296 (cons (const :tag "Strategy for TODO lists" todo)
1297 (repeat ,org-sorting-choice))
1298 (cons (const :tag "Strategy for Tags matches" tags)
1299 (repeat ,org-sorting-choice))
1300 (cons (const :tag "Strategy for search matches" search)
1301 (repeat ,org-sorting-choice)))))
1303 (defcustom org-agenda-cmp-user-defined nil
1304 "A function to define the comparison `user-defined'.
1305 This function must receive two arguments, agenda entry a and b.
1306 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1307 the user comparison, return nil.
1308 When this is defined, you can make `user-defined-up' and `user-defined-down'
1309 part of an agenda sorting strategy."
1310 :group 'org-agenda-sorting
1311 :type 'symbol)
1313 (defcustom org-sort-agenda-notime-is-late t
1314 "Non-nil means items without time are considered late.
1315 This is only relevant for sorting. When t, items which have no explicit
1316 time like 15:30 will be considered as 99:01, i.e. later than any items which
1317 do have a time. When nil, the default time is before 0:00. You can use this
1318 option to decide if the schedule for today should come before or after timeless
1319 agenda entries."
1320 :group 'org-agenda-sorting
1321 :type 'boolean)
1323 (defcustom org-sort-agenda-noeffort-is-high t
1324 "Non-nil means items without effort estimate are sorted as high effort.
1325 This also applies when filtering an agenda view with respect to the
1326 < or > effort operator. Then, tasks with no effort defined will be treated
1327 as tasks with high effort.
1328 When nil, such items are sorted as 0 minutes effort."
1329 :group 'org-agenda-sorting
1330 :type 'boolean)
1332 (defgroup org-agenda-line-format nil
1333 "Options concerning the entry prefix in the Org-mode agenda display."
1334 :tag "Org Agenda Line Format"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-prefix-format
1338 '((agenda . " %i %-12:c%?-12t% s")
1339 (timeline . " % s")
1340 (todo . " %i %-12:c")
1341 (tags . " %i %-12:c")
1342 (search . " %i %-12:c"))
1343 "Format specifications for the prefix of items in the agenda views.
1344 An alist with four entries, for the different agenda types. The keys to the
1345 sublists are `agenda', `timeline', `todo', `search' and `tags'. The values
1346 are format strings.
1347 This format works similar to a printf format, with the following meaning:
1349 %c the category of the item, \"Diary\" for entries from the diary, or
1350 as given by the CATEGORY keyword or derived from the file name.
1351 %i the icon category of the item, as give in
1352 `org-agenda-category-icon-alist'.
1353 %T the *last* tag of the item. Last because inherited tags come
1354 first in the list.
1355 %t the time-of-day specification if one applies to the entry, in the
1356 format HH:MM
1357 %s Scheduling/Deadline information, a short string
1358 %(expression) Eval EXPRESSION and replace the control string
1359 by the result
1361 All specifiers work basically like the standard `%s' of printf, but may
1362 contain two additional characters: A question mark just after the `%' and
1363 a whitespace/punctuation character just before the final letter.
1365 If the first character after `%' is a question mark, the entire field
1366 will only be included if the corresponding value applies to the
1367 current entry. This is useful for fields which should have fixed
1368 width when present, but zero width when absent. For example,
1369 \"%?-12t\" will result in a 12 character time field if a time of the
1370 day is specified, but will completely disappear in entries which do
1371 not contain a time.
1373 If there is punctuation or whitespace character just before the final
1374 format letter, this character will be appended to the field value if
1375 the value is not empty. For example, the format \"%-12:c\" leads to
1376 \"Diary: \" if the category is \"Diary\". If the category were be
1377 empty, no additional colon would be inserted.
1379 The default value of this option is \" %-12:c%?-12t% s\", meaning:
1380 - Indent the line with two space characters
1381 - Give the category in a 12 chars wide field, padded with whitespace on
1382 the right (because of `-'). Append a colon if there is a category
1383 (because of `:').
1384 - If there is a time-of-day, put it into a 12 chars wide field. If no
1385 time, don't put in an empty field, just skip it (because of '?').
1386 - Finally, put the scheduling information and append a whitespace.
1388 As another example, if you don't want the time-of-day of entries in
1389 the prefix, you could use:
1391 (setq org-agenda-prefix-format \" %-11:c% s\")
1393 See also the variables `org-agenda-remove-times-when-in-prefix' and
1394 `org-agenda-remove-tags'.
1396 Custom commands can set this variable in the options section."
1397 :type '(choice
1398 (string :tag "General format")
1399 (list :greedy t :tag "View dependent"
1400 (cons (const agenda) (string :tag "Format"))
1401 (cons (const timeline) (string :tag "Format"))
1402 (cons (const todo) (string :tag "Format"))
1403 (cons (const tags) (string :tag "Format"))
1404 (cons (const search) (string :tag "Format"))))
1405 :group 'org-agenda-line-format)
1407 (defvar org-prefix-format-compiled nil
1408 "The compiled version of the most recently used prefix format.
1409 See the variable `org-agenda-prefix-format'.")
1411 (defcustom org-agenda-todo-keyword-format "%-1s"
1412 "Format for the TODO keyword in agenda lines.
1413 Set this to something like \"%-12s\" if you want all TODO keywords
1414 to occupy a fixed space in the agenda display."
1415 :group 'org-agenda-line-format
1416 :type 'string)
1418 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1419 "Text preceding timerange entries in the agenda view.
1420 This is a list with two strings. The first applies when the range
1421 is entirely on one day. The second applies if the range spans several days.
1422 The strings may have two \"%d\" format specifiers which will be filled
1423 with the sequence number of the days, and the total number of days in the
1424 range, respectively."
1425 :group 'org-agenda-line-format
1426 :type '(list
1427 (string :tag "Deadline today ")
1428 (choice :tag "Deadline relative"
1429 (string :tag "Format string")
1430 (function))))
1432 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1433 "Text preceding scheduled items in the agenda view.
1434 This is a list with two strings. The first applies when the item is
1435 scheduled on the current day. The second applies when it has been scheduled
1436 previously, it may contain a %d indicating that this is the nth time that
1437 this item is scheduled, due to automatic rescheduling of unfinished items
1438 for the following day. So this number is one larger than the number of days
1439 that passed since this item was scheduled first."
1440 :group 'org-agenda-line-format
1441 :type '(list
1442 (string :tag "Scheduled today ")
1443 (string :tag "Scheduled previously")))
1445 (defcustom org-agenda-inactive-leader "["
1446 "Text preceding item pulled into the agenda by inactive time stamps.
1447 These entries are added to the agenda when pressing \"[\"."
1448 :group 'org-agenda-line-format
1449 :type '(list
1450 (string :tag "Scheduled today ")
1451 (string :tag "Scheduled previously")))
1453 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1454 "Text preceding deadline items in the agenda view.
1455 This is a list with two strings. The first applies when the item has its
1456 deadline on the current day. The second applies when it is in the past or
1457 in the future, it may contain %d to capture how many days away the deadline
1458 is (was)."
1459 :group 'org-agenda-line-format
1460 :type '(list
1461 (string :tag "Deadline today ")
1462 (choice :tag "Deadline relative"
1463 (string :tag "Format string")
1464 (function))))
1466 (defcustom org-agenda-remove-times-when-in-prefix t
1467 "Non-nil means remove duplicate time specifications in agenda items.
1468 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1469 time-of-day specification in a headline or diary entry is extracted and
1470 placed into the prefix. If this option is non-nil, the original specification
1471 \(a timestamp or -range, or just a plain time(range) specification like
1472 11:30-4pm) will be removed for agenda display. This makes the agenda less
1473 cluttered.
1474 The option can be t or nil. It may also be the symbol `beg', indicating
1475 that the time should only be removed when it is located at the beginning of
1476 the headline/diary entry."
1477 :group 'org-agenda-line-format
1478 :type '(choice
1479 (const :tag "Always" t)
1480 (const :tag "Never" nil)
1481 (const :tag "When at beginning of entry" beg)))
1483 (defcustom org-agenda-remove-timeranges-from-blocks nil
1484 "Non-nil means remove time ranges specifications in agenda
1485 items that span on several days."
1486 :group 'org-agenda-line-format
1487 :type 'boolean)
1489 (defcustom org-agenda-default-appointment-duration nil
1490 "Default duration for appointments that only have a starting time.
1491 When nil, no duration is specified in such cases.
1492 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1493 :group 'org-agenda-line-format
1494 :type '(choice
1495 (integer :tag "Minutes")
1496 (const :tag "No default duration")))
1498 (defcustom org-agenda-show-inherited-tags t
1499 "Non-nil means show inherited tags in each agenda line."
1500 :group 'org-agenda-line-format
1501 :type 'boolean)
1503 (defcustom org-agenda-hide-tags-regexp nil
1504 "Regular expression used to filter away specific tags in agenda views.
1505 This means that these tags will be present, but not be shown in the agenda
1506 line. Secondary filtering will still work on the hidden tags.
1507 Nil means don't hide any tags."
1508 :group 'org-agenda-line-format
1509 :type '(choice
1510 (const :tag "Hide none" nil)
1511 (string :tag "Regexp ")))
1513 (defcustom org-agenda-remove-tags nil
1514 "Non-nil means remove the tags from the headline copy in the agenda.
1515 When this is the symbol `prefix', only remove tags when
1516 `org-agenda-prefix-format' contains a `%T' specifier."
1517 :group 'org-agenda-line-format
1518 :type '(choice
1519 (const :tag "Always" t)
1520 (const :tag "Never" nil)
1521 (const :tag "When prefix format contains %T" prefix)))
1523 (if (fboundp 'defvaralias)
1524 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1525 'org-agenda-remove-tags))
1527 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1528 "Shift tags in agenda items to this column.
1529 If this number is positive, it specifies the column. If it is negative,
1530 it means that the tags should be flushright to that column. For example,
1531 -80 works well for a normal 80 character screen."
1532 :group 'org-agenda-line-format
1533 :type 'integer)
1535 (if (fboundp 'defvaralias)
1536 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1538 (defcustom org-agenda-fontify-priorities 'cookies
1539 "Non-nil means highlight low and high priorities in agenda.
1540 When t, the highest priority entries are bold, lowest priority italic.
1541 However, settings in `org-priority-faces' will overrule these faces.
1542 When this variable is the symbol `cookies', only fontify the
1543 cookies, not the entire task.
1544 This may also be an association list of priority faces, whose
1545 keys are the character values of `org-highest-priority',
1546 `org-default-priority', and `org-lowest-priority' (the default values
1547 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1548 color as a string, or a list like `(:background \"Red\")'.
1549 If it is a color, the variable `org-faces-easy-properties'
1550 determines if it is a foreground or a background color."
1551 :group 'org-agenda-line-format
1552 :type '(choice
1553 (const :tag "Never" nil)
1554 (const :tag "Defaults" t)
1555 (const :tag "Cookies only" cookies)
1556 (repeat :tag "Specify"
1557 (list (character :tag "Priority" :value ?A)
1558 (choice :tag "Face "
1559 (string :tag "Color")
1560 (sexp :tag "Face"))))))
1562 (defcustom org-agenda-day-face-function nil
1563 "Function called to determine what face should be used to display a day.
1564 The only argument passed to that function is the day. It should
1565 returns a face, or nil if does not want to specify a face and let
1566 the normal rules apply."
1567 :group 'org-agenda-line-format
1568 :type 'function)
1570 (defcustom org-agenda-category-icon-alist nil
1571 "Alist of category icon to be displayed in agenda views.
1573 Each entry should have the following format:
1575 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1577 Where CATEGORY-REGEXP is a regexp matching the categories where
1578 the icon should be displayed.
1579 FILE-OR-DATA either a file path or a string containing image data.
1581 The other fields can be omited safely if not needed:
1582 TYPE indicates the image type.
1583 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1584 image data.
1585 PROPS are additional image attributes to assign to the image,
1586 like, e.g. `:ascent center'.
1588 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1590 If you want to set the display properties yourself, just put a
1591 list as second element:
1593 (CATEGORY-REGEXP (MY PROPERTY LIST))
1595 For example, to display a 16px horizontal space for Emacs
1596 category, you can use:
1598 (\"Emacs\" '(space . (:width (16))))"
1599 :group 'org-agenda-line-format
1600 :type '(alist :key-type (string :tag "Regexp matching category")
1601 :value-type (choice (list :tag "Icon"
1602 (string :tag "File or data")
1603 (symbol :tag "Type")
1604 (boolean :tag "Data?")
1605 (repeat :tag "Extra image properties" :inline t symbol))
1606 (list :tag "Display properties" sexp))))
1608 (defgroup org-agenda-column-view nil
1609 "Options concerning column view in the agenda."
1610 :tag "Org Agenda Column View"
1611 :group 'org-agenda)
1613 (defcustom org-agenda-columns-show-summaries t
1614 "Non-nil means show summaries for columns displayed in the agenda view."
1615 :group 'org-agenda-column-view
1616 :type 'boolean)
1618 (defcustom org-agenda-columns-remove-prefix-from-item t
1619 "Non-nil means remove the prefix from a headline for agenda column view.
1620 The special ITEM field in the columns format contains the current line, with
1621 all information shown in other columns (like the TODO state or a tag).
1622 When this variable is non-nil, also the agenda prefix will be removed from
1623 the content of the ITEM field, to make sure as much as possible of the
1624 headline can be shown in the limited width of the field."
1625 :group 'org-agenda
1626 :type 'boolean)
1628 (defcustom org-agenda-columns-compute-summary-properties t
1629 "Non-nil means recompute all summary properties before column view.
1630 When column view in the agenda is listing properties that have a summary
1631 operator, it can go to all relevant buffers and recompute the summaries
1632 there. This can mean overhead for the agenda column view, but is necessary
1633 to have thing up to date.
1634 As a special case, a CLOCKSUM property also makes sure that the clock
1635 computations are current."
1636 :group 'org-agenda-column-view
1637 :type 'boolean)
1639 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1640 "Non-nil means the duration of an appointment will add to day effort.
1641 The property to which appointment durations will be added is the one given
1642 in the option `org-effort-property'. If an appointment does not have
1643 an end time, `org-agenda-default-appointment-duration' will be used. If that
1644 is not set, an appointment without end time will not contribute to the time
1645 estimate."
1646 :group 'org-agenda-column-view
1647 :type 'boolean)
1649 (defcustom org-agenda-auto-exclude-function nil
1650 "A function called with a tag to decide if it is filtered on '/ RET'.
1651 The sole argument to the function, which is called once for each
1652 possible tag, is a string giving the name of the tag. The
1653 function should return either nil if the tag should be included
1654 as normal, or \"-<TAG>\" to exclude the tag.
1655 Note that for the purpose of tag filtering, only the lower-case version of
1656 all tags will be considered, so that this function will only ever see
1657 the lower-case version of all tags."
1658 :group 'org-agenda
1659 :type 'function)
1661 (eval-when-compile
1662 (require 'cl))
1663 (require 'org)
1665 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1666 "Execute BODY with point at location given by `org-hd-marker' property.
1667 If STRING is non-nil, the text property will be fetched from position 0
1668 in that string. If STRING is nil, it will be fetched from the beginning
1669 of the current line."
1670 `(let ((marker (get-text-property (if string 0 (point-at-bol))
1671 'org-hd-marker string)))
1672 (with-current-buffer (marker-buffer marker)
1673 (save-excursion
1674 (goto-char marker)
1675 ,@body))))
1677 (defun org-add-agenda-custom-command (entry)
1678 "Replace or add a command in `org-agenda-custom-commands'.
1679 This is mostly for hacking and trying a new command - once the command
1680 works you probably want to add it to `org-agenda-custom-commands' for good."
1681 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1682 (if ass
1683 (setcdr ass (cdr entry))
1684 (push entry org-agenda-custom-commands))))
1686 ;;; Define the Org-agenda-mode
1688 (defvar org-agenda-mode-map (make-sparse-keymap)
1689 "Keymap for `org-agenda-mode'.")
1690 (if (fboundp 'defvaralias)
1691 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1693 (defvar org-agenda-menu) ; defined later in this file.
1694 (defvar org-agenda-restrict) ; defined later in this file.
1695 (defvar org-agenda-follow-mode nil)
1696 (defvar org-agenda-entry-text-mode nil)
1697 (defvar org-agenda-clockreport-mode nil)
1698 (defvar org-agenda-show-log nil)
1699 (defvar org-agenda-redo-command nil)
1700 (defvar org-agenda-query-string nil)
1701 (defvar org-agenda-mode-hook nil
1702 "Hook for `org-agenda-mode', run after the mode is turned on.")
1703 (defvar org-agenda-type nil)
1704 (defvar org-agenda-force-single-file nil)
1705 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1707 (defun org-agenda-mode ()
1708 "Mode for time-sorted view on action items in Org-mode files.
1710 The following commands are available:
1712 \\{org-agenda-mode-map}"
1713 (interactive)
1714 (kill-all-local-variables)
1715 (setq org-agenda-undo-list nil
1716 org-agenda-pending-undo-list nil
1717 org-agenda-bulk-marked-entries nil)
1718 (setq major-mode 'org-agenda-mode)
1719 ;; Keep global-font-lock-mode from turning on font-lock-mode
1720 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1721 (setq mode-name "Org-Agenda")
1722 (use-local-map org-agenda-mode-map)
1723 (easy-menu-add org-agenda-menu)
1724 (if org-startup-truncated (setq truncate-lines t))
1725 (org-set-local 'line-move-visual nil)
1726 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1727 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1728 ;; Make sure properties are removed when copying text
1729 (when (boundp 'buffer-substring-filters)
1730 (org-set-local 'buffer-substring-filters
1731 (cons (lambda (x)
1732 (set-text-properties 0 (length x) nil x) x)
1733 buffer-substring-filters)))
1734 (unless org-agenda-keep-modes
1735 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1736 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1737 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1738 org-agenda-show-log org-agenda-start-with-log-mode))
1740 (easy-menu-change
1741 '("Agenda") "Agenda Files"
1742 (append
1743 (list
1744 (vector
1745 (if (get 'org-agenda-files 'org-restrict)
1746 "Restricted to single file"
1747 "Edit File List")
1748 '(org-edit-agenda-file-list)
1749 (not (get 'org-agenda-files 'org-restrict)))
1750 "--")
1751 (mapcar 'org-file-menu-entry (org-agenda-files))))
1752 (org-agenda-set-mode-name)
1753 (apply
1754 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1755 (list 'org-agenda-mode-hook)))
1757 (substitute-key-definition 'undo 'org-agenda-undo
1758 org-agenda-mode-map global-map)
1759 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1760 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1761 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1762 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1763 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1764 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1765 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1766 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1767 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1768 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1769 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1770 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1771 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1772 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1773 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1774 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1775 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1776 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1777 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1778 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1779 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1780 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1781 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1782 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1783 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1784 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1785 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1786 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1787 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1788 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1789 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1790 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1791 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1792 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1793 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1794 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1795 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1796 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1797 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1798 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
1799 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
1800 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
1801 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
1802 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
1804 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
1805 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
1806 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
1807 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
1808 (while l (org-defkey org-agenda-mode-map
1809 (int-to-string (pop l)) 'digit-argument)))
1811 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
1812 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
1813 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
1814 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
1815 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
1816 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
1817 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
1818 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
1819 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
1820 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
1821 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
1822 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
1823 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
1824 'org-clock-modify-effort-estimate)
1825 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
1826 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
1827 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
1828 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
1829 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
1830 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
1831 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
1832 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
1833 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
1834 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
1835 (substitute-key-definition 'next-line 'org-agenda-next-line
1836 org-agenda-mode-map global-map)
1837 (substitute-key-definition 'previous-line 'org-agenda-previous-line
1838 org-agenda-mode-map global-map)
1839 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
1840 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
1841 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
1842 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
1843 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
1844 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
1845 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
1846 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
1847 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
1848 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
1849 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
1850 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
1851 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
1852 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
1853 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
1854 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
1855 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
1856 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
1857 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
1858 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
1859 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
1860 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
1861 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
1862 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
1863 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
1864 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
1865 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
1866 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
1867 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
1868 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
1870 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
1871 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
1872 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
1873 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
1874 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
1875 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
1876 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
1877 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
1878 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
1879 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
1881 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
1882 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
1883 (when org-agenda-mouse-1-follows-link
1884 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
1885 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
1886 '("Agenda"
1887 ("Agenda Files")
1888 "--"
1889 ("Agenda Dates"
1890 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
1891 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
1892 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
1893 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
1894 "--"
1895 ("View"
1896 ["Day View" org-agenda-day-view
1897 :active (org-agenda-check-type nil 'agenda)
1898 :style radio :selected (eq org-agenda-current-span 'day)
1899 :keys "v d (or just d)"]
1900 ["Week View" org-agenda-week-view
1901 :active (org-agenda-check-type nil 'agenda)
1902 :style radio :selected (eq org-agenda-current-span 'week)
1903 :keys "v w (or just w)"]
1904 ["Month View" org-agenda-month-view
1905 :active (org-agenda-check-type nil 'agenda)
1906 :style radio :selected (eq org-agenda-current-span 'month)
1907 :keys "v m"]
1908 ["Year View" org-agenda-year-view
1909 :active (org-agenda-check-type nil 'agenda)
1910 :style radio :selected (eq org-agenda-current-span 'year)
1911 :keys "v y"]
1912 "--"
1913 ["Include Diary" org-agenda-toggle-diary
1914 :style toggle :selected org-agenda-include-diary
1915 :active (org-agenda-check-type nil 'agenda)]
1916 ["Include Deadlines" org-agenda-toggle-deadlines
1917 :style toggle :selected org-agenda-include-deadlines
1918 :active (org-agenda-check-type nil 'agenda)]
1919 ["Use Time Grid" org-agenda-toggle-time-grid
1920 :style toggle :selected org-agenda-use-time-grid
1921 :active (org-agenda-check-type nil 'agenda)]
1922 "--"
1923 ["Show clock report" org-agenda-clockreport-mode
1924 :style toggle :selected org-agenda-clockreport-mode
1925 :active (org-agenda-check-type nil 'agenda)]
1926 ["Show some entry text" org-agenda-entry-text-mode
1927 :style toggle :selected org-agenda-entry-text-mode
1928 :active t]
1929 "--"
1930 ["Show Logbook entries" org-agenda-log-mode
1931 :style toggle :selected org-agenda-show-log
1932 :active (org-agenda-check-type nil 'agenda 'timeline)
1933 :keys "v l (or just l)"]
1934 ["Include archived trees" org-agenda-archives-mode
1935 :style toggle :selected org-agenda-archives-mode :active t
1936 :keys "v a"]
1937 ["Include archive files" (org-agenda-archives-mode t)
1938 :style toggle :selected (eq org-agenda-archives-mode t) :active t
1939 :keys "v A"]
1940 "--"
1941 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
1942 ["Write view to file" org-write-agenda t]
1943 ["Rebuild buffer" org-agenda-redo t]
1944 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
1945 "--"
1946 ["Show original entry" org-agenda-show t]
1947 ["Go To (other window)" org-agenda-goto t]
1948 ["Go To (this window)" org-agenda-switch-to t]
1949 ["Follow Mode" org-agenda-follow-mode
1950 :style toggle :selected org-agenda-follow-mode :active t]
1951 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
1952 "--"
1953 ("TODO"
1954 ["Cycle TODO" org-agenda-todo t]
1955 ["Next TODO set" org-agenda-todo-nextset t]
1956 ["Previous TODO set" org-agenda-todo-previousset t]
1957 ["Add note" org-agenda-add-note t])
1958 ("Archive/Refile/Delete"
1959 ["Archive default" org-agenda-archive-default t]
1960 ["Archive default" org-agenda-archive-default-with-confirmation t]
1961 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
1962 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
1963 ["Archive subtree" org-agenda-archive t]
1964 "--"
1965 ["Refile" org-agenda-refile t]
1966 "--"
1967 ["Delete subtree" org-agenda-kill t])
1968 ("Bulk action"
1969 ["Mark entry" org-agenda-bulk-mark t]
1970 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
1971 ["Unmark entry" org-agenda-bulk-unmark t]
1972 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
1973 ["Act on all marked" org-agenda-bulk-action t]
1974 "--"
1975 ("Tags and Properties"
1976 ["Show all Tags" org-agenda-show-tags t]
1977 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
1978 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
1979 "--"
1980 ["Column View" org-columns t])
1981 ("Deadline/Schedule"
1982 ["Schedule" org-agenda-schedule t]
1983 ["Set Deadline" org-agenda-deadline t]
1984 "--"
1985 ["Mark item" org-agenda-action :active t :keys "k m"]
1986 ["Show mark item" org-agenda-action :active t :keys "k v"]
1987 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
1988 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
1989 "--"
1990 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
1991 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
1992 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
1993 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
1994 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
1995 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
1996 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
1997 ("Clock and Effort"
1998 ["Clock in" org-agenda-clock-in t]
1999 ["Clock out" org-agenda-clock-out t]
2000 ["Clock cancel" org-agenda-clock-cancel t]
2001 ["Goto running clock" org-clock-goto t]
2002 "--"
2003 ["Set Effort" org-agenda-set-effort t]
2004 ["Change clocked effort" org-clock-modify-effort-estimate
2005 (org-clock-is-active)])
2006 ("Priority"
2007 ["Set Priority" org-agenda-priority t]
2008 ["Increase Priority" org-agenda-priority-up t]
2009 ["Decrease Priority" org-agenda-priority-down t]
2010 ["Show Priority" org-agenda-show-priority t])
2011 ("Calendar/Diary"
2012 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2013 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2014 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2015 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2016 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2017 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2018 "--"
2019 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2020 "--"
2021 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2022 "--"
2023 ("MobileOrg"
2024 ["Push Files and Views" org-mobile-push t]
2025 ["Get Captured and Flagged" org-mobile-pull t]
2026 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2027 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2028 "--"
2029 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2030 "--"
2031 ["Quit" org-agenda-quit t]
2032 ["Exit and Release Buffers" org-agenda-exit t]
2035 ;;; Agenda undo
2037 (defvar org-agenda-allow-remote-undo t
2038 "Non-nil means allow remote undo from the agenda buffer.")
2039 (defvar org-agenda-undo-list nil
2040 "List of undoable operations in the agenda since last refresh.")
2041 (defvar org-agenda-undo-has-started-in nil
2042 "Buffers that have already seen `undo-start' in the current undo sequence.")
2043 (defvar org-agenda-pending-undo-list nil
2044 "In a series of undo commands, this is the list of remaining undo items.")
2047 (defun org-agenda-undo ()
2048 "Undo a remote editing step in the agenda.
2049 This undoes changes both in the agenda buffer and in the remote buffer
2050 that have been changed along."
2051 (interactive)
2052 (or org-agenda-allow-remote-undo
2053 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2054 (if (not (eq this-command last-command))
2055 (setq org-agenda-undo-has-started-in nil
2056 org-agenda-pending-undo-list org-agenda-undo-list))
2057 (if (not org-agenda-pending-undo-list)
2058 (error "No further undo information"))
2059 (let* ((entry (pop org-agenda-pending-undo-list))
2060 buf line cmd rembuf)
2061 (setq cmd (pop entry) line (pop entry))
2062 (setq rembuf (nth 2 entry))
2063 (org-with-remote-undo rembuf
2064 (while (bufferp (setq buf (pop entry)))
2065 (if (pop entry)
2066 (with-current-buffer buf
2067 (let ((last-undo-buffer buf)
2068 (inhibit-read-only t))
2069 (unless (memq buf org-agenda-undo-has-started-in)
2070 (push buf org-agenda-undo-has-started-in)
2071 (make-local-variable 'pending-undo-list)
2072 (undo-start))
2073 (while (and pending-undo-list
2074 (listp pending-undo-list)
2075 (not (car pending-undo-list)))
2076 (pop pending-undo-list))
2077 (undo-more 1))))))
2078 (org-goto-line line)
2079 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2081 (defun org-verify-change-for-undo (l1 l2)
2082 "Verify that a real change occurred between the undo lists L1 and L2."
2083 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2084 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2085 (not (eq l1 l2)))
2087 ;;; Agenda dispatch
2089 (defvar org-agenda-restrict nil)
2090 (defvar org-agenda-restrict-begin (make-marker))
2091 (defvar org-agenda-restrict-end (make-marker))
2092 (defvar org-agenda-last-dispatch-buffer nil)
2093 (defvar org-agenda-overriding-restriction nil)
2095 ;;;###autoload
2096 (defun org-agenda (&optional arg keys restriction)
2097 "Dispatch agenda commands to collect entries to the agenda buffer.
2098 Prompts for a command to execute. Any prefix arg will be passed
2099 on to the selected command. The default selections are:
2101 a Call `org-agenda-list' to display the agenda for current day or week.
2102 t Call `org-todo-list' to display the global todo list.
2103 T Call `org-todo-list' to display the global todo list, select only
2104 entries with a specific TODO keyword (the user gets a prompt).
2105 m Call `org-tags-view' to display headlines with tags matching
2106 a condition (the user is prompted for the condition).
2107 M Like `m', but select only TODO entries, no ordinary headlines.
2108 L Create a timeline for the current buffer.
2109 e Export views to associated files.
2110 s Search entries for keywords.
2111 / Multi occur across all agenda files and also files listed
2112 in `org-agenda-text-search-extra-files'.
2113 < Restrict agenda commands to buffer, subtree, or region.
2114 Press several times to get the desired effect.
2115 > Remove a previous restriction.
2116 # List \"stuck\" projects.
2117 ! Configure what \"stuck\" means.
2118 C Configure custom agenda commands.
2120 More commands can be added by configuring the variable
2121 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2122 searches can be pre-defined in this way.
2124 If the current buffer is in Org-mode and visiting a file, you can also
2125 first press `<' once to indicate that the agenda should be temporarily
2126 \(until the next use of \\[org-agenda]) restricted to the current file.
2127 Pressing `<' twice means to restrict to the current subtree or region
2128 \(if active)."
2129 (interactive "P")
2130 (catch 'exit
2131 (let* ((prefix-descriptions nil)
2132 (org-agenda-window-setup (if (equal (buffer-name)
2133 org-agenda-buffer-name)
2134 'current-window
2135 org-agenda-window-setup))
2136 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2137 (org-agenda-custom-commands
2138 ;; normalize different versions
2139 (delq nil
2140 (mapcar
2141 (lambda (x)
2142 (cond ((stringp (cdr x))
2143 (push x prefix-descriptions)
2144 nil)
2145 ((stringp (nth 1 x)) x)
2146 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2147 (t (cons (car x) (cons "" (cdr x))))))
2148 org-agenda-custom-commands)))
2149 (buf (current-buffer))
2150 (bfn (buffer-file-name (buffer-base-buffer)))
2151 entry key type match lprops ans)
2152 ;; Turn off restriction unless there is an overriding one,
2153 (unless org-agenda-overriding-restriction
2154 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2155 ;; There is a request to keep the file list in place
2156 (put 'org-agenda-files 'org-restrict nil))
2157 (setq org-agenda-restrict nil)
2158 (move-marker org-agenda-restrict-begin nil)
2159 (move-marker org-agenda-restrict-end nil))
2160 ;; Delete old local properties
2161 (put 'org-agenda-redo-command 'org-lprops nil)
2162 ;; Remember where this call originated
2163 (setq org-agenda-last-dispatch-buffer (current-buffer))
2164 (kill-local-variable 'org-agenda-current-span)
2165 (unless keys
2166 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2167 keys (car ans)
2168 restriction (cdr ans)))
2169 ;; Establish the restriction, if any
2170 (when (and (not org-agenda-overriding-restriction) restriction)
2171 (put 'org-agenda-files 'org-restrict (list bfn))
2172 (cond
2173 ((eq restriction 'region)
2174 (setq org-agenda-restrict t)
2175 (move-marker org-agenda-restrict-begin (region-beginning))
2176 (move-marker org-agenda-restrict-end (region-end)))
2177 ((eq restriction 'subtree)
2178 (save-excursion
2179 (setq org-agenda-restrict t)
2180 (org-back-to-heading t)
2181 (move-marker org-agenda-restrict-begin (point))
2182 (move-marker org-agenda-restrict-end
2183 (progn (org-end-of-subtree t)))))))
2185 ;; For example the todo list should not need it (but does...)
2186 (cond
2187 ((setq entry (assoc keys org-agenda-custom-commands))
2188 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2189 (progn
2190 (setq type (nth 2 entry) match (eval (nth 3 entry))
2191 lprops (nth 4 entry))
2192 (put 'org-agenda-redo-command 'org-lprops lprops)
2193 (cond
2194 ((eq type 'agenda)
2195 (org-let lprops '(org-agenda-list current-prefix-arg)))
2196 ((eq type 'alltodo)
2197 (org-let lprops '(org-todo-list current-prefix-arg)))
2198 ((eq type 'search)
2199 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2200 ((eq type 'stuck)
2201 (org-let lprops '(org-agenda-list-stuck-projects
2202 current-prefix-arg)))
2203 ((eq type 'tags)
2204 (org-let lprops '(org-tags-view current-prefix-arg match)))
2205 ((eq type 'tags-todo)
2206 (org-let lprops '(org-tags-view '(4) match)))
2207 ((eq type 'todo)
2208 (org-let lprops '(org-todo-list match)))
2209 ((eq type 'tags-tree)
2210 (org-check-for-org-mode)
2211 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2212 ((eq type 'todo-tree)
2213 (org-check-for-org-mode)
2214 (org-let lprops
2215 '(org-occur (concat "^" outline-regexp "[ \t]*"
2216 (regexp-quote match) "\\>"))))
2217 ((eq type 'occur-tree)
2218 (org-check-for-org-mode)
2219 (org-let lprops '(org-occur match)))
2220 ((functionp type)
2221 (org-let lprops '(funcall type match)))
2222 ((fboundp type)
2223 (org-let lprops '(funcall type match)))
2224 (t (error "Invalid custom agenda command type %s" type))))
2225 (org-run-agenda-series (nth 1 entry) (cddr entry))))
2226 ((equal keys "C")
2227 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2228 (customize-variable 'org-agenda-custom-commands))
2229 ((equal keys "a") (call-interactively 'org-agenda-list))
2230 ((equal keys "s") (call-interactively 'org-search-view))
2231 ((equal keys "t") (call-interactively 'org-todo-list))
2232 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2233 ((equal keys "m") (call-interactively 'org-tags-view))
2234 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2235 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2236 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2237 (org-add-hook
2238 'post-command-hook
2239 (lambda ()
2240 (unless (current-message)
2241 (let* ((m (org-agenda-get-any-marker))
2242 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2243 (when note
2244 (message (concat
2245 "FLAGGING-NOTE ([?] for more info): "
2246 (org-add-props
2247 (replace-regexp-in-string
2248 "\\\\n" "//"
2249 (copy-sequence note))
2250 nil 'face 'org-warning)))))))
2251 t t))
2252 ((equal keys "L")
2253 (unless (org-mode-p)
2254 (error "This is not an Org-mode file"))
2255 (unless restriction
2256 (put 'org-agenda-files 'org-restrict (list bfn))
2257 (org-call-with-arg 'org-timeline arg)))
2258 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2259 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2260 ((equal keys "!") (customize-variable 'org-stuck-projects))
2261 (t (error "Invalid agenda key"))))))
2263 (defun org-agenda-normalize-custom-commands (cmds)
2264 (delq nil
2265 (mapcar
2266 (lambda (x)
2267 (cond ((stringp (cdr x)) nil)
2268 ((stringp (nth 1 x)) x)
2269 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2270 (t (cons (car x) (cons "" (cdr x))))))
2271 cmds)))
2273 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2274 "The user interface for selecting an agenda command."
2275 (catch 'exit
2276 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2277 (restrict-ok (and bfn (org-mode-p)))
2278 (region-p (org-region-active-p))
2279 (custom org-agenda-custom-commands)
2280 (selstring "")
2281 restriction second-time
2282 c entry key type match prefixes rmheader header-end custom1 desc
2283 line lines left right n n1)
2284 (save-window-excursion
2285 (delete-other-windows)
2286 (org-switch-to-buffer-other-window " *Agenda Commands*")
2287 (erase-buffer)
2288 (insert (eval-when-compile
2289 (let ((header
2291 Press key for an agenda command: < Buffer, subtree/region restriction
2292 -------------------------------- > Remove restriction
2293 a Agenda for current week or day e Export agenda views
2294 t List of all TODO entries T Entries with special TODO kwd
2295 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2296 L Timeline for current buffer # List stuck projects (!=configure)
2297 s Search for keywords C Configure custom agenda commands
2298 / Multi-occur ? Find :FLAGGED: entries
2300 (start 0))
2301 (while (string-match
2302 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2303 header start)
2304 (setq start (match-end 0))
2305 (add-text-properties (match-beginning 2) (match-end 2)
2306 '(face bold) header))
2307 header)))
2308 (setq header-end (move-marker (make-marker) (point)))
2309 (while t
2310 (setq custom1 custom)
2311 (when (eq rmheader t)
2312 (org-goto-line 1)
2313 (re-search-forward ":" nil t)
2314 (delete-region (match-end 0) (point-at-eol))
2315 (forward-char 1)
2316 (looking-at "-+")
2317 (delete-region (match-end 0) (point-at-eol))
2318 (move-marker header-end (match-end 0)))
2319 (goto-char header-end)
2320 (delete-region (point) (point-max))
2322 ;; Produce all the lines that describe custom commands and prefixes
2323 (setq lines nil)
2324 (while (setq entry (pop custom1))
2325 (setq key (car entry) desc (nth 1 entry)
2326 type (nth 2 entry)
2327 match (nth 3 entry))
2328 (if (> (length key) 1)
2329 (add-to-list 'prefixes (string-to-char key))
2330 (setq line
2331 (format
2332 "%-4s%-14s"
2333 (org-add-props (copy-sequence key)
2334 '(face bold))
2335 (cond
2336 ((string-match "\\S-" desc) desc)
2337 ((eq type 'agenda) "Agenda for current week or day")
2338 ((eq type 'alltodo) "List of all TODO entries")
2339 ((eq type 'search) "Word search")
2340 ((eq type 'stuck) "List of stuck projects")
2341 ((eq type 'todo) "TODO keyword")
2342 ((eq type 'tags) "Tags query")
2343 ((eq type 'tags-todo) "Tags (TODO)")
2344 ((eq type 'tags-tree) "Tags tree")
2345 ((eq type 'todo-tree) "TODO kwd tree")
2346 ((eq type 'occur-tree) "Occur tree")
2347 ((functionp type) (if (symbolp type)
2348 (symbol-name type)
2349 "Lambda expression"))
2350 (t "???"))))
2351 (if org-agenda-menu-show-matcher
2352 (setq line
2353 (concat line ": "
2354 (cond
2355 ((stringp match)
2356 (setq match (copy-sequence match))
2357 (org-add-props match nil 'face 'org-warning))
2358 (match
2359 (format "set of %d commands" (length match)))
2360 (t ""))))
2361 (if (org-string-nw-p match)
2362 (add-text-properties
2363 0 (length line) (list 'help-echo
2364 (concat "Matcher: "match)) line)))
2365 (push line lines)))
2366 (setq lines (nreverse lines))
2367 (when prefixes
2368 (mapc (lambda (x)
2369 (push
2370 (format "%s %s"
2371 (org-add-props (char-to-string x)
2372 nil 'face 'bold)
2373 (or (cdr (assoc (concat selstring
2374 (char-to-string x))
2375 prefix-descriptions))
2376 "Prefix key"))
2377 lines))
2378 prefixes))
2380 ;; Check if we should display in two columns
2381 (if org-agenda-menu-two-column
2382 (progn
2383 (setq n (length lines)
2384 n1 (+ (/ n 2) (mod n 2))
2385 right (nthcdr n1 lines)
2386 left (copy-sequence lines))
2387 (setcdr (nthcdr (1- n1) left) nil))
2388 (setq left lines right nil))
2389 (while left
2390 (insert "\n" (pop left))
2391 (when right
2392 (if (< (current-column) 40)
2393 (move-to-column 40 t)
2394 (insert " "))
2395 (insert (pop right))))
2397 ;; Make the window the right size
2398 (goto-char (point-min))
2399 (if second-time
2400 (if (not (pos-visible-in-window-p (point-max)))
2401 (org-fit-window-to-buffer))
2402 (setq second-time t)
2403 (org-fit-window-to-buffer))
2405 ;; Ask for selection
2406 (message "Press key for agenda command%s:"
2407 (if (or restrict-ok org-agenda-overriding-restriction)
2408 (if org-agenda-overriding-restriction
2409 " (restriction lock active)"
2410 (if restriction
2411 (format " (restricted to %s)" restriction)
2412 " (unrestricted)"))
2413 ""))
2414 (setq c (read-char-exclusive))
2415 (message "")
2416 (cond
2417 ((assoc (char-to-string c) custom)
2418 (setq selstring (concat selstring (char-to-string c)))
2419 (throw 'exit (cons selstring restriction)))
2420 ((memq c prefixes)
2421 (setq selstring (concat selstring (char-to-string c))
2422 prefixes nil
2423 rmheader (or rmheader t)
2424 custom (delq nil (mapcar
2425 (lambda (x)
2426 (if (or (= (length (car x)) 1)
2427 (/= (string-to-char (car x)) c))
2429 (cons (substring (car x) 1) (cdr x))))
2430 custom))))
2431 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2432 (message "Restriction is only possible in Org-mode buffers")
2433 (ding) (sit-for 1))
2434 ((eq c ?1)
2435 (org-agenda-remove-restriction-lock 'noupdate)
2436 (setq restriction 'buffer))
2437 ((eq c ?0)
2438 (org-agenda-remove-restriction-lock 'noupdate)
2439 (setq restriction (if region-p 'region 'subtree)))
2440 ((eq c ?<)
2441 (org-agenda-remove-restriction-lock 'noupdate)
2442 (setq restriction
2443 (cond
2444 ((eq restriction 'buffer)
2445 (if region-p 'region 'subtree))
2446 ((memq restriction '(subtree region))
2447 nil)
2448 (t 'buffer))))
2449 ((eq c ?>)
2450 (org-agenda-remove-restriction-lock 'noupdate)
2451 (setq restriction nil))
2452 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2453 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2454 ((and (> (length selstring) 0) (eq c ?\d))
2455 (delete-window)
2456 (org-agenda-get-restriction-and-command prefix-descriptions))
2458 ((equal c ?q) (error "Abort"))
2459 (t (error "Invalid key %c" c))))))))
2461 (defun org-run-agenda-series (name series)
2462 (org-let (nth 1 series) '(org-prepare-agenda name))
2463 (let* ((org-agenda-multi t)
2464 (redo (list 'org-run-agenda-series name (list 'quote series)))
2465 (cmds (car series))
2466 (gprops (nth 1 series))
2467 match ;; The byte compiler incorrectly complains about this. Keep it!
2468 cmd type lprops)
2469 (while (setq cmd (pop cmds))
2470 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2471 (cond
2472 ((eq type 'agenda)
2473 (org-let2 gprops lprops
2474 '(call-interactively 'org-agenda-list)))
2475 ((eq type 'alltodo)
2476 (org-let2 gprops lprops
2477 '(call-interactively 'org-todo-list)))
2478 ((eq type 'search)
2479 (org-let2 gprops lprops
2480 '(org-search-view current-prefix-arg match nil)))
2481 ((eq type 'stuck)
2482 (org-let2 gprops lprops
2483 '(call-interactively 'org-agenda-list-stuck-projects)))
2484 ((eq type 'tags)
2485 (org-let2 gprops lprops
2486 '(org-tags-view current-prefix-arg match)))
2487 ((eq type 'tags-todo)
2488 (org-let2 gprops lprops
2489 '(org-tags-view '(4) match)))
2490 ((eq type 'todo)
2491 (org-let2 gprops lprops
2492 '(org-todo-list match)))
2493 ((fboundp type)
2494 (org-let2 gprops lprops
2495 '(funcall type match)))
2496 (t (error "Invalid type in command series"))))
2497 (widen)
2498 (setq org-agenda-redo-command redo)
2499 (goto-char (point-min)))
2500 (org-fit-agenda-window)
2501 (org-let (nth 1 series) '(org-finalize-agenda)))
2503 ;;;###autoload
2504 (defmacro org-batch-agenda (cmd-key &rest parameters)
2505 "Run an agenda command in batch mode and send the result to STDOUT.
2506 If CMD-KEY is a string of length 1, it is used as a key in
2507 `org-agenda-custom-commands' and triggers this command. If it is a
2508 longer string it is used as a tags/todo match string.
2509 Parameters are alternating variable names and values that will be bound
2510 before running the agenda command."
2511 (let (pars)
2512 (while parameters
2513 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2514 (if (> (length cmd-key) 2)
2515 (eval (list 'let (nreverse pars)
2516 (list 'org-tags-view nil cmd-key)))
2517 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2518 (set-buffer org-agenda-buffer-name)
2519 (princ (org-encode-for-stdout (buffer-string)))))
2521 ;(defun org-encode-for-stdout (string)
2522 ; (if (fboundp 'encode-coding-string)
2523 ; (encode-coding-string string buffer-file-coding-system)
2524 ; string))
2526 (defun org-encode-for-stdout (string)
2527 string)
2529 (defvar org-agenda-info nil)
2531 ;;;###autoload
2532 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2533 "Run an agenda command in batch mode and send the result to STDOUT.
2534 If CMD-KEY is a string of length 1, it is used as a key in
2535 `org-agenda-custom-commands' and triggers this command. If it is a
2536 longer string it is used as a tags/todo match string.
2537 Parameters are alternating variable names and values that will be bound
2538 before running the agenda command.
2540 The output gives a line for each selected agenda item. Each
2541 item is a list of comma-separated values, like this:
2543 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2545 category The category of the item
2546 head The headline, without TODO kwd, TAGS and PRIORITY
2547 type The type of the agenda entry, can be
2548 todo selected in TODO match
2549 tagsmatch selected in tags match
2550 diary imported from diary
2551 deadline a deadline on given date
2552 scheduled scheduled on given date
2553 timestamp entry has timestamp on given date
2554 closed entry was closed on given date
2555 upcoming-deadline warning about deadline
2556 past-scheduled forwarded scheduled item
2557 block entry has date block including g. date
2558 todo The todo keyword, if any
2559 tags All tags including inherited ones, separated by colons
2560 date The relevant date, like 2007-2-14
2561 time The time, like 15:00-16:50
2562 extra Sting with extra planning info
2563 priority-l The priority letter if any was given
2564 priority-n The computed numerical priority
2565 agenda-day The day in the agenda where this is listed"
2567 (let (pars)
2568 (while parameters
2569 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2570 (push (list 'org-agenda-remove-tags t) pars)
2571 (if (> (length cmd-key) 2)
2572 (eval (list 'let (nreverse pars)
2573 (list 'org-tags-view nil cmd-key)))
2574 (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
2575 (set-buffer org-agenda-buffer-name)
2576 (let* ((lines (org-split-string (buffer-string) "\n"))
2577 line)
2578 (while (setq line (pop lines))
2579 (catch 'next
2580 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2581 (setq org-agenda-info
2582 (org-fix-agenda-info (text-properties-at 0 line)))
2583 (princ
2584 (org-encode-for-stdout
2585 (mapconcat 'org-agenda-export-csv-mapper
2586 '(org-category txt type todo tags date time extra
2587 priority-letter priority agenda-day)
2588 ",")))
2589 (princ "\n"))))))
2591 (defun org-fix-agenda-info (props)
2592 "Make sure all properties on an agenda item have a canonical form.
2593 This ensures the export commands can easily use it."
2594 (let (tmp re)
2595 (when (setq tmp (plist-get props 'tags))
2596 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2597 (when (setq tmp (plist-get props 'date))
2598 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2599 (let ((calendar-date-display-form '(year "-" month "-" day)))
2600 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2602 (setq tmp (calendar-date-string tmp)))
2603 (setq props (plist-put props 'date tmp)))
2604 (when (setq tmp (plist-get props 'day))
2605 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2606 (let ((calendar-date-display-form '(year "-" month "-" day)))
2607 (setq tmp (calendar-date-string tmp)))
2608 (setq props (plist-put props 'day tmp))
2609 (setq props (plist-put props 'agenda-day tmp)))
2610 (when (setq tmp (plist-get props 'txt))
2611 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2612 (plist-put props 'priority-letter (match-string 1 tmp))
2613 (setq tmp (replace-match "" t t tmp)))
2614 (when (and (setq re (plist-get props 'org-todo-regexp))
2615 (setq re (concat "\\`\\.*" re " ?"))
2616 (string-match re tmp))
2617 (plist-put props 'todo (match-string 1 tmp))
2618 (setq tmp (replace-match "" t t tmp)))
2619 (plist-put props 'txt tmp)))
2620 props)
2622 (defun org-agenda-export-csv-mapper (prop)
2623 (let ((res (plist-get org-agenda-info prop)))
2624 (setq res
2625 (cond
2626 ((not res) "")
2627 ((stringp res) res)
2628 (t (prin1-to-string res))))
2629 (while (string-match "," res)
2630 (setq res (replace-match ";" t t res)))
2631 (org-trim res)))
2634 ;;;###autoload
2635 (defun org-store-agenda-views (&rest parameters)
2636 (interactive)
2637 (eval (list 'org-batch-store-agenda-views)))
2639 ;; FIXME, why is this a macro?????
2640 ;;;###autoload
2641 (defmacro org-batch-store-agenda-views (&rest parameters)
2642 "Run all custom agenda commands that have a file argument."
2643 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2644 (pop-up-frames nil)
2645 (dir default-directory)
2646 pars cmd thiscmdkey files opts cmd-or-set)
2647 (while parameters
2648 (push (list (pop parameters) (if parameters (pop parameters))) pars))
2649 (setq pars (reverse pars))
2650 (save-window-excursion
2651 (while cmds
2652 (setq cmd (pop cmds)
2653 thiscmdkey (car cmd)
2654 cmd-or-set (nth 2 cmd)
2655 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2656 files (nth (if (listp cmd-or-set) 4 5) cmd))
2657 (if (stringp files) (setq files (list files)))
2658 (when files
2659 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2660 (list 'org-agenda nil thiscmdkey)))
2661 (set-buffer org-agenda-buffer-name)
2662 (while files
2663 (eval (list 'let (append org-agenda-exporter-settings opts pars)
2664 (list 'org-write-agenda
2665 (expand-file-name (pop files) dir) nil t))))
2666 (and (get-buffer org-agenda-buffer-name)
2667 (kill-buffer org-agenda-buffer-name)))))))
2669 (defun org-agenda-mark-header-line (pos)
2670 "Mark the line at POS as an agenda structure header."
2671 (save-excursion
2672 (goto-char pos)
2673 (put-text-property (point-at-bol) (point-at-eol)
2674 'org-agenda-structural-header t)
2675 (when org-agenda-title-append
2676 (put-text-property (point-at-bol) (point-at-eol)
2677 'org-agenda-title-append org-agenda-title-append))))
2679 (defvar org-mobile-creating-agendas)
2680 (defun org-write-agenda (file &optional open nosettings)
2681 "Write the current buffer (an agenda view) as a file.
2682 Depending on the extension of the file name, plain text (.txt),
2683 HTML (.html or .htm) or Postscript (.ps) is produced.
2684 If the extension is .ics, run icalendar export over all files used
2685 to construct the agenda and limit the export to entries listed in the
2686 agenda now.
2687 With prefix argument OPEN, open the new file immediately.
2688 If NOSETTINGS is given, do not scope the settings of
2689 `org-agenda-exporter-settings' into the export commands. This is used when
2690 the settings have already been scoped and we do not wish to overrule other,
2691 higher priority settings."
2692 (interactive "FWrite agenda to file: \nP")
2693 (if (not (file-writable-p file))
2694 (error "Cannot write agenda to file %s" file))
2695 (org-let (if nosettings nil org-agenda-exporter-settings)
2696 '(save-excursion
2697 (save-window-excursion
2698 (org-agenda-mark-filtered-text)
2699 (let ((bs (copy-sequence (buffer-string))) beg)
2700 (org-agenda-unmark-filtered-text)
2701 (with-temp-buffer
2702 (rename-buffer "Agenda View" t)
2703 (set-buffer-modified-p nil)
2704 (insert bs)
2705 (org-agenda-remove-marked-text 'org-filtered)
2706 (while (setq beg (text-property-any (point-min) (point-max)
2707 'org-filtered t))
2708 (delete-region
2709 beg (or (next-single-property-change beg 'org-filtered)
2710 (point-max))))
2711 (run-hooks 'org-agenda-before-write-hook)
2712 (cond
2713 ((org-bound-and-true-p org-mobile-creating-agendas)
2714 (org-mobile-write-agenda-for-mobile file))
2715 ((string-match "\\.html?\\'" file)
2716 (require 'htmlize)
2717 (set-buffer (htmlize-buffer (current-buffer)))
2719 (when (and org-agenda-export-html-style
2720 (string-match "<style>" org-agenda-export-html-style))
2721 ;; replace <style> section with org-agenda-export-html-style
2722 (goto-char (point-min))
2723 (kill-region (- (search-forward "<style") 6)
2724 (search-forward "</style>"))
2725 (insert org-agenda-export-html-style))
2726 (write-file file)
2727 (kill-buffer (current-buffer))
2728 (message "HTML written to %s" file))
2729 ((string-match "\\.ps\\'" file)
2730 (require 'ps-print)
2731 (ps-print-buffer-with-faces file)
2732 (message "Postscript written to %s" file))
2733 ((string-match "\\.pdf\\'" file)
2734 (require 'ps-print)
2735 (ps-print-buffer-with-faces
2736 (concat (file-name-sans-extension file) ".ps"))
2737 (call-process "ps2pdf" nil nil nil
2738 (expand-file-name
2739 (concat (file-name-sans-extension file) ".ps"))
2740 (expand-file-name file))
2741 (delete-file (concat (file-name-sans-extension file) ".ps"))
2742 (message "PDF written to %s" file))
2743 ((string-match "\\.ics\\'" file)
2744 (require 'org-icalendar)
2745 (let ((org-agenda-marker-table
2746 (org-create-marker-find-array
2747 (org-agenda-collect-markers)))
2748 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2749 (org-combined-agenda-icalendar-file file))
2750 (apply 'org-export-icalendar 'combine
2751 (org-agenda-files nil 'ifmode))))
2753 (let ((bs (buffer-string)))
2754 (find-file file)
2755 (erase-buffer)
2756 (insert bs)
2757 (save-buffer 0)
2758 (kill-buffer (current-buffer))
2759 (message "Plain text written to %s" file))))))))
2760 (set-buffer org-agenda-buffer-name))
2761 (when open (org-open-file file)))
2763 (defvar org-agenda-filter-overlays nil)
2765 (defun org-agenda-mark-filtered-text ()
2766 "Mark all text hidden by filtering with a text property."
2767 (let ((inhibit-read-only t))
2768 (mapc
2769 (lambda (o)
2770 (when (equal (overlay-buffer o) (current-buffer))
2771 (put-text-property
2772 (overlay-start o) (overlay-end o)
2773 'org-filtered t)))
2774 org-agenda-filter-overlays)))
2776 (defun org-agenda-unmark-filtered-text ()
2777 "Remove the filtering text property."
2778 (let ((inhibit-read-only t))
2779 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
2781 (defun org-agenda-remove-marked-text (property &optional value)
2782 "Delete all text marked with VALUE of PROPERTY.
2783 VALUE defaults to t."
2784 (let (beg)
2785 (setq value (or value t))
2786 (while (setq beg (text-property-any (point-min) (point-max)
2787 property value))
2788 (delete-region
2789 beg (or (next-single-property-change beg 'org-filtered)
2790 (point-max))))))
2792 (defun org-agenda-add-entry-text ()
2793 "Add entry text to agenda lines.
2794 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
2795 entry text following headings shown in the agenda.
2796 Drawers will be excluded, also the line with scheduling/deadline info."
2797 (when (and (> org-agenda-add-entry-text-maxlines 0)
2798 (not (org-bound-and-true-p org-mobile-creating-agendas)))
2799 (let (m txt)
2800 (goto-char (point-min))
2801 (while (not (eobp))
2802 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
2803 (beginning-of-line 2)
2804 (setq txt (org-agenda-get-some-entry-text
2805 m org-agenda-add-entry-text-maxlines " > "))
2806 (end-of-line 1)
2807 (if (string-match "\\S-" txt)
2808 (insert "\n" txt)
2809 (or (eobp) (forward-char 1))))))))
2811 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
2812 &rest keep)
2813 "Extract entry text from MARKER, at most N-LINES lines.
2814 This will ignore drawers etc, just get the text.
2815 If INDENT is given, prefix every line with this string. If KEEP is
2816 given, it is a list of symbols, defining stuff that should not be
2817 removed from the entry content. Currently only `planning' is allowed here."
2818 (let (txt drawer-re kwd-time-re ind)
2819 (save-excursion
2820 (with-current-buffer (marker-buffer marker)
2821 (if (not (org-mode-p))
2822 (setq txt "")
2823 (save-excursion
2824 (save-restriction
2825 (widen)
2826 (goto-char marker)
2827 (end-of-line 1)
2828 (setq txt (buffer-substring
2829 (min (1+ (point)) (point-max))
2830 (progn (outline-next-heading) (point)))
2831 drawer-re org-drawer-regexp
2832 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
2833 ".*\n?"))
2834 (with-temp-buffer
2835 (insert txt)
2836 (when org-agenda-add-entry-text-descriptive-links
2837 (goto-char (point-min))
2838 (while (org-activate-bracket-links (point-max))
2839 (add-text-properties (match-beginning 0) (match-end 0)
2840 '(face org-link))))
2841 (goto-char (point-min))
2842 (while (re-search-forward org-bracket-link-regexp (point-max) t)
2843 (set-text-properties (match-beginning 0) (match-end 0)
2844 nil))
2845 (goto-char (point-min))
2846 (while (re-search-forward drawer-re nil t)
2847 (delete-region
2848 (match-beginning 0)
2849 (progn (re-search-forward
2850 "^[ \t]*:END:.*\n?" nil 'move)
2851 (point))))
2852 (unless (member 'planning keep)
2853 (goto-char (point-min))
2854 (while (re-search-forward kwd-time-re nil t)
2855 (replace-match "")))
2856 (goto-char (point-min))
2857 (when org-agenda-entry-text-exclude-regexps
2858 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
2859 (while (setq re (pop re-list))
2860 (goto-char (point-min))
2861 (while (re-search-forward re nil t)
2862 (replace-match "")))))
2863 (goto-char (point-max))
2864 (skip-chars-backward " \t\n")
2865 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
2867 ;; find and remove min common indentation
2868 (goto-char (point-min))
2869 (untabify (point-min) (point-max))
2870 (setq ind (org-get-indentation))
2871 (while (not (eobp))
2872 (unless (looking-at "[ \t]*$")
2873 (setq ind (min ind (org-get-indentation))))
2874 (beginning-of-line 2))
2875 (goto-char (point-min))
2876 (while (not (eobp))
2877 (unless (looking-at "[ \t]*$")
2878 (move-to-column ind)
2879 (delete-region (point-at-bol) (point)))
2880 (beginning-of-line 2))
2882 (run-hooks 'org-agenda-entry-text-cleanup-hook)
2884 (goto-char (point-min))
2885 (when indent
2886 (while (and (not (eobp)) (re-search-forward "^" nil t))
2887 (replace-match indent t t)))
2888 (goto-char (point-min))
2889 (while (looking-at "[ \t]*\n") (replace-match ""))
2890 (goto-char (point-max))
2891 (when (> (org-current-line)
2892 n-lines)
2893 (org-goto-line (1+ n-lines))
2894 (backward-char 1))
2895 (setq txt (buffer-substring (point-min) (point)))))))))
2896 txt))
2898 (defun org-agenda-collect-markers ()
2899 "Collect the markers pointing to entries in the agenda buffer."
2900 (let (m markers)
2901 (save-excursion
2902 (goto-char (point-min))
2903 (while (not (eobp))
2904 (when (setq m (or (org-get-at-bol 'org-hd-marker)
2905 (org-get-at-bol 'org-marker)))
2906 (push m markers))
2907 (beginning-of-line 2)))
2908 (nreverse markers)))
2910 (defun org-create-marker-find-array (marker-list)
2911 "Create a alist of files names with all marker positions in that file."
2912 (let (f tbl m a p)
2913 (while (setq m (pop marker-list))
2914 (setq p (marker-position m)
2915 f (buffer-file-name (or (buffer-base-buffer
2916 (marker-buffer m))
2917 (marker-buffer m))))
2918 (if (setq a (assoc f tbl))
2919 (push (marker-position m) (cdr a))
2920 (push (list f p) tbl)))
2921 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
2922 tbl)))
2924 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
2925 (defun org-check-agenda-marker-table ()
2926 "Check of the current entry is on the marker list."
2927 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2929 (and (setq a (assoc file org-agenda-marker-table))
2930 (save-match-data
2931 (save-excursion
2932 (org-back-to-heading t)
2933 (member (point) (cdr a)))))))
2935 (defun org-check-for-org-mode ()
2936 "Make sure current buffer is in org-mode. Error if not."
2937 (or (org-mode-p)
2938 (error "Cannot execute org-mode agenda command on buffer in %s"
2939 major-mode)))
2941 (defun org-fit-agenda-window ()
2942 "Fit the window to the buffer size."
2943 (and (memq org-agenda-window-setup '(reorganize-frame))
2944 (fboundp 'fit-window-to-buffer)
2945 (org-fit-window-to-buffer
2947 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2948 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2950 ;;; Agenda prepare and finalize
2952 (defvar org-agenda-multi nil) ; dynamically scoped
2953 (defvar org-agenda-buffer-name "*Org Agenda*")
2954 (defvar org-pre-agenda-window-conf nil)
2955 (defvar org-agenda-columns-active nil)
2956 (defvar org-agenda-name nil)
2957 (defvar org-agenda-filter nil)
2958 (defvar org-agenda-filter-while-redo nil)
2959 (defvar org-agenda-filter-preset nil
2960 "A preset of the tags filter used for secondary agenda filtering.
2961 This must be a list of strings, each string must be a single tag preceded
2962 by \"+\" or \"-\".
2963 This variable should not be set directly, but agenda custom commands can
2964 bind it in the options section. The preset filter is a global property of
2965 the entire agenda view. In a block agenda, it will not work reliably to
2966 define a filter for one of the individual blocks. You need to set it in
2967 the global options and expect it to be applied to the entire view.")
2969 (defun org-prepare-agenda (&optional name)
2970 (setq org-todo-keywords-for-agenda nil)
2971 (setq org-done-keywords-for-agenda nil)
2972 (setq org-drawers-for-agenda nil)
2973 (unless org-agenda-persistent-filter
2974 (setq org-agenda-filter nil))
2975 (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
2976 (if org-agenda-multi
2977 (progn
2978 (setq buffer-read-only nil)
2979 (goto-char (point-max))
2980 (unless (or (bobp) org-agenda-compact-blocks)
2981 (insert "\n"
2982 (if (stringp org-agenda-block-separator)
2983 org-agenda-block-separator
2984 (make-string (window-width) org-agenda-block-separator))
2985 "\n"))
2986 (narrow-to-region (point) (point-max)))
2987 (org-agenda-reset-markers)
2988 (setq org-agenda-contributing-files nil)
2989 (setq org-agenda-columns-active nil)
2990 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
2991 (setq org-todo-keywords-for-agenda
2992 (org-uniquify org-todo-keywords-for-agenda))
2993 (setq org-done-keywords-for-agenda
2994 (org-uniquify org-done-keywords-for-agenda))
2995 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
2996 (let* ((abuf (get-buffer-create org-agenda-buffer-name))
2997 (awin (get-buffer-window abuf)))
2998 (cond
2999 ((equal (current-buffer) abuf) nil)
3000 (awin (select-window awin))
3001 ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
3002 ((equal org-agenda-window-setup 'current-window)
3003 (switch-to-buffer abuf))
3004 ((equal org-agenda-window-setup 'other-window)
3005 (org-switch-to-buffer-other-window abuf))
3006 ((equal org-agenda-window-setup 'other-frame)
3007 (switch-to-buffer-other-frame abuf))
3008 ((equal org-agenda-window-setup 'reorganize-frame)
3009 (delete-other-windows)
3010 (org-switch-to-buffer-other-window abuf)))
3011 ;; additional test in case agenda is invoked from within agenda
3012 ;; buffer via elisp link
3013 (unless (equal (current-buffer) abuf)
3014 (switch-to-buffer abuf)))
3015 (setq buffer-read-only nil)
3016 (let ((inhibit-read-only t)) (erase-buffer))
3017 (org-agenda-mode)
3018 (and name (not org-agenda-name)
3019 (org-set-local 'org-agenda-name name)))
3020 (setq buffer-read-only nil))
3022 (defun org-finalize-agenda ()
3023 "Finishing touch for the agenda buffer, called just before displaying it."
3024 (unless org-agenda-multi
3025 (save-excursion
3026 (let ((inhibit-read-only t))
3027 (goto-char (point-min))
3028 (while (org-activate-bracket-links (point-max))
3029 (add-text-properties (match-beginning 0) (match-end 0)
3030 '(face org-link)))
3031 (org-agenda-align-tags)
3032 (unless org-agenda-with-colors
3033 (remove-text-properties (point-min) (point-max) '(face nil))))
3034 (if (and (boundp 'org-agenda-overriding-columns-format)
3035 org-agenda-overriding-columns-format)
3036 (org-set-local 'org-agenda-overriding-columns-format
3037 org-agenda-overriding-columns-format))
3038 (if (and (boundp 'org-agenda-view-columns-initially)
3039 org-agenda-view-columns-initially)
3040 (org-agenda-columns))
3041 (when org-agenda-fontify-priorities
3042 (org-agenda-fontify-priorities))
3043 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3044 (org-agenda-dim-blocked-tasks))
3045 (org-agenda-mark-clocking-task)
3046 (when org-agenda-entry-text-mode
3047 (org-agenda-entry-text-hide)
3048 (org-agenda-entry-text-show))
3049 (if (functionp 'org-habit-insert-consistency-graphs)
3050 (org-habit-insert-consistency-graphs))
3051 (run-hooks 'org-finalize-agenda-hook)
3052 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3053 (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
3054 (org-agenda-filter-apply org-agenda-filter))
3057 (defun org-agenda-mark-clocking-task ()
3058 "Mark the current clock entry in the agenda if it is present."
3059 (mapc (lambda (o)
3060 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3061 (delete-overlay o)))
3062 (overlays-in (point-min) (point-max)))
3063 (when (marker-buffer org-clock-hd-marker)
3064 (save-excursion
3065 (goto-char (point-min))
3066 (let (s ov)
3067 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3068 (goto-char s)
3069 (when (equal (org-get-at-bol 'org-hd-marker)
3070 org-clock-hd-marker)
3071 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3072 (overlay-put ov 'type 'org-agenda-clocking)
3073 (overlay-put ov 'face 'org-agenda-clocking)
3074 (overlay-put ov 'help-echo
3075 "The clock is running in this item")))))))
3077 (defun org-agenda-fontify-priorities ()
3078 "Make highest priority lines bold, and lowest italic."
3079 (interactive)
3080 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3081 (delete-overlay o)))
3082 (overlays-in (point-min) (point-max)))
3083 (save-excursion
3084 (let ((inhibit-read-only t)
3085 b e p ov h l)
3086 (goto-char (point-min))
3087 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3088 (setq h (or (get-char-property (point) 'org-highest-priority)
3089 org-highest-priority)
3090 l (or (get-char-property (point) 'org-lowest-priority)
3091 org-lowest-priority)
3092 p (string-to-char (match-string 1))
3093 b (match-beginning 0)
3094 e (if (eq org-agenda-fontify-priorities 'cookies)
3095 (match-end 0)
3096 (point-at-eol))
3097 ov (make-overlay b e))
3098 (overlay-put
3099 ov 'face
3100 (cond ((org-face-from-face-or-color
3101 'priority nil
3102 (cdr (assoc p org-priority-faces))))
3103 ((and (listp org-agenda-fontify-priorities)
3104 (org-face-from-face-or-color
3105 'priority nil
3106 (cdr (assoc p org-agenda-fontify-priorities)))))
3107 ((equal p l) 'italic)
3108 ((equal p h) 'bold)))
3109 (overlay-put ov 'org-type 'org-priority)))))
3111 (defun org-agenda-dim-blocked-tasks ()
3112 "Dim currently blocked TODO's in the agenda display."
3113 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3114 (delete-overlay o)))
3115 (overlays-in (point-min) (point-max)))
3116 (save-excursion
3117 (let ((inhibit-read-only t)
3118 (org-depend-tag-blocked nil)
3119 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3120 org-blocked-by-checkboxes
3121 invis1 b e p ov h l)
3122 (goto-char (point-min))
3123 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3124 (and pos (goto-char (1+ pos))))
3125 (setq org-blocked-by-checkboxes nil invis1 invis)
3126 (let ((marker (org-get-at-bol 'org-hd-marker)))
3127 (when (and marker
3128 (not (with-current-buffer (marker-buffer marker)
3129 (save-excursion
3130 (goto-char marker)
3131 (if (org-entry-get nil "NOBLOCKING")
3132 t ;; Never block this entry
3133 (run-hook-with-args-until-failure
3134 'org-blocker-hook
3135 (list :type 'todo-state-change
3136 :position marker
3137 :from 'todo
3138 :to 'done)))))))
3139 (if org-blocked-by-checkboxes (setq invis1 nil))
3140 (setq b (if invis1
3141 (max (point-min) (1- (point-at-bol)))
3142 (point-at-bol))
3143 e (point-at-eol)
3144 ov (make-overlay b e))
3145 (if invis1
3146 (overlay-put ov 'invisible t)
3147 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3148 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3150 (defvar org-agenda-skip-function nil
3151 "Function to be called at each match during agenda construction.
3152 If this function returns nil, the current match should not be skipped.
3153 Otherwise, the function must return a position from where the search
3154 should be continued.
3155 This may also be a Lisp form, it will be evaluated.
3156 Never set this variable using `setq' or so, because then it will apply
3157 to all future agenda commands. If you do want a global skipping condition,
3158 use the option `org-agenda-skip-function-global' instead.
3159 The correct usage for `org-agenda-skip-function' is to bind it with
3160 `let' to scope it dynamically into the agenda-constructing command.
3161 A good way to set it is through options in `org-agenda-custom-commands'.")
3163 (defun org-agenda-skip ()
3164 "Throw to `:skip' in places that should be skipped.
3165 Also moves point to the end of the skipped region, so that search can
3166 continue from there."
3167 (let ((p (point-at-bol)) to)
3168 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3169 (get-text-property p :org-archived)
3170 (org-end-of-subtree t)
3171 (throw :skip t))
3172 (and org-agenda-skip-comment-trees
3173 (get-text-property p :org-comment)
3174 (org-end-of-subtree t)
3175 (throw :skip t))
3176 (if (equal (char-after p) ?#) (throw :skip t))
3177 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3178 (org-agenda-skip-eval org-agenda-skip-function)))
3179 (goto-char to)
3180 (throw :skip t))))
3182 (defun org-agenda-skip-eval (form)
3183 "If FORM is a function or a list, call (or eval) is and return result.
3184 `save-excursion' and `save-match-data' are wrapped around the call, so point
3185 and match data are returned to the previous state no matter what these
3186 functions do."
3187 (let (fp)
3188 (and form
3189 (or (setq fp (functionp form))
3190 (consp form))
3191 (save-excursion
3192 (save-match-data
3193 (if fp
3194 (funcall form)
3195 (eval form)))))))
3197 (defvar org-agenda-markers nil
3198 "List of all currently active markers created by `org-agenda'.")
3199 (defvar org-agenda-last-marker-time (org-float-time)
3200 "Creation time of the last agenda marker.")
3202 (defun org-agenda-new-marker (&optional pos)
3203 "Return a new agenda marker.
3204 Org-mode keeps a list of these markers and resets them when they are
3205 no longer in use."
3206 (let ((m (copy-marker (or pos (point)))))
3207 (setq org-agenda-last-marker-time (org-float-time))
3208 (push m org-agenda-markers)
3211 (defun org-agenda-reset-markers ()
3212 "Reset markers created by `org-agenda'."
3213 (while org-agenda-markers
3214 (move-marker (pop org-agenda-markers) nil)))
3216 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3217 "Save relative positions of markers in region."
3218 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3219 org-agenda-markers))
3221 ;;; Entry text mode
3223 (defun org-agenda-entry-text-show-here ()
3224 "Add some text from the entry as context to the current line."
3225 (let (m txt o)
3226 (setq m (org-get-at-bol 'org-hd-marker))
3227 (unless (marker-buffer m)
3228 (error "No marker points to an entry here"))
3229 (setq txt (concat "\n" (org-no-properties
3230 (org-agenda-get-some-entry-text
3231 m org-agenda-entry-text-maxlines " > "))))
3232 (when (string-match "\\S-" txt)
3233 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3234 (overlay-put o 'evaporate t)
3235 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3236 (overlay-put o 'after-string txt))))
3238 (defun org-agenda-entry-text-show ()
3239 "Add entry context for all agenda lines."
3240 (interactive)
3241 (save-excursion
3242 (goto-char (point-max))
3243 (beginning-of-line 1)
3244 (while (not (bobp))
3245 (when (org-get-at-bol 'org-hd-marker)
3246 (org-agenda-entry-text-show-here))
3247 (beginning-of-line 0))))
3249 (defun org-agenda-entry-text-hide ()
3250 "Remove any shown entry context."
3251 (delq nil
3252 (mapcar (lambda (o)
3253 (if (eq (overlay-get o 'org-overlay-type)
3254 'agenda-entry-content)
3255 (progn (delete-overlay o) t)))
3256 (overlays-in (point-min) (point-max)))))
3258 (defun org-agenda-get-day-face (date)
3259 "Return the face DATE should be displayed with."
3260 (or (and (functionp org-agenda-day-face-function)
3261 (funcall org-agenda-day-face-function date))
3262 (cond ((org-agenda-todayp date)
3263 'org-agenda-date-today)
3264 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3265 'org-agenda-date-weekend)
3266 (t 'org-agenda-date))))
3268 ;;; Agenda timeline
3270 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3272 (defun org-timeline (&optional include-all)
3273 "Show a time-sorted view of the entries in the current org file.
3274 Only entries with a time stamp of today or later will be listed. With
3275 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3276 under the current date.
3277 If the buffer contains an active region, only check the region for
3278 dates."
3279 (interactive "P")
3280 (org-compile-prefix-format 'timeline)
3281 (org-set-sorting-strategy 'timeline)
3282 (let* ((dopast t)
3283 (dotodo include-all)
3284 (doclosed org-agenda-show-log)
3285 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3286 (current-buffer))))
3287 (date (calendar-current-date))
3288 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3289 (end (if (org-region-active-p) (region-end) (point-max)))
3290 (day-numbers (org-get-all-dates beg end 'no-ranges
3291 t doclosed ; always include today
3292 org-timeline-show-empty-dates))
3293 (org-deadline-warning-days 0)
3294 (org-agenda-only-exact-dates t)
3295 (today (org-today))
3296 (past t)
3297 args
3298 s e rtn d emptyp)
3299 (setq org-agenda-redo-command
3300 (list 'progn
3301 (list 'org-switch-to-buffer-other-window (current-buffer))
3302 (list 'org-timeline (list 'quote include-all))))
3303 (if (not dopast)
3304 ;; Remove past dates from the list of dates.
3305 (setq day-numbers (delq nil (mapcar (lambda(x)
3306 (if (>= x today) x nil))
3307 day-numbers))))
3308 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3309 (if doclosed (push :closed args))
3310 (push :timestamp args)
3311 (push :deadline args)
3312 (push :scheduled args)
3313 (push :sexp args)
3314 (if dotodo (push :todo args))
3315 (insert "Timeline of file " entry "\n")
3316 (add-text-properties (point-min) (point)
3317 (list 'face 'org-agenda-structure))
3318 (org-agenda-mark-header-line (point-min))
3319 (while (setq d (pop day-numbers))
3320 (if (and (listp d) (eq (car d) :omitted))
3321 (progn
3322 (setq s (point))
3323 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3324 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3325 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3326 (if (and (>= d today)
3327 dopast
3328 past)
3329 (progn
3330 (setq past nil)
3331 (insert (make-string 79 ?-) "\n")))
3332 (setq date (calendar-gregorian-from-absolute d))
3333 (setq s (point))
3334 (setq rtn (and (not emptyp)
3335 (apply 'org-agenda-get-day-entries entry
3336 date args)))
3337 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3338 (progn
3339 (insert
3340 (if (stringp org-agenda-format-date)
3341 (format-time-string org-agenda-format-date
3342 (org-time-from-absolute date))
3343 (funcall org-agenda-format-date date))
3344 "\n")
3345 (put-text-property s (1- (point)) 'face
3346 (org-agenda-get-day-face date))
3347 (put-text-property s (1- (point)) 'org-date-line t)
3348 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3349 (if (equal d today)
3350 (put-text-property s (1- (point)) 'org-today t))
3351 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3352 (put-text-property s (1- (point)) 'day d)))))
3353 (goto-char (point-min))
3354 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3355 (point-min)))
3356 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3357 (org-finalize-agenda)
3358 (setq buffer-read-only t)))
3360 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3361 "Return a list of all relevant day numbers from BEG to END buffer positions.
3362 If NO-RANGES is non-nil, include only the start and end dates of a range,
3363 not every single day in the range. If FORCE-TODAY is non-nil, make
3364 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3365 inactive time stamps (those in square brackets) are included.
3366 When EMPTY is non-nil, also include days without any entries."
3367 (let ((re (concat
3368 (if pre-re pre-re "")
3369 (if inactive org-ts-regexp-both org-ts-regexp)))
3370 dates dates1 date day day1 day2 ts1 ts2)
3371 (if force-today
3372 (setq dates (list (org-today))))
3373 (save-excursion
3374 (goto-char beg)
3375 (while (re-search-forward re end t)
3376 (setq day (time-to-days (org-time-string-to-time
3377 (substring (match-string 1) 0 10))))
3378 (or (memq day dates) (push day dates)))
3379 (unless no-ranges
3380 (goto-char beg)
3381 (while (re-search-forward org-tr-regexp end t)
3382 (setq ts1 (substring (match-string 1) 0 10)
3383 ts2 (substring (match-string 2) 0 10)
3384 day1 (time-to-days (org-time-string-to-time ts1))
3385 day2 (time-to-days (org-time-string-to-time ts2)))
3386 (while (< (setq day1 (1+ day1)) day2)
3387 (or (memq day1 dates) (push day1 dates)))))
3388 (setq dates (sort dates '<))
3389 (when empty
3390 (while (setq day (pop dates))
3391 (setq day2 (car dates))
3392 (push day dates1)
3393 (when (and day2 empty)
3394 (if (or (eq empty t)
3395 (and (numberp empty) (<= (- day2 day) empty)))
3396 (while (< (setq day (1+ day)) day2)
3397 (push (list day) dates1))
3398 (push (cons :omitted (- day2 day)) dates1))))
3399 (setq dates (nreverse dates1)))
3400 dates)))
3402 ;;; Agenda Daily/Weekly
3404 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
3405 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3406 "Custom commands can set this variable in the options section.")
3407 (defvar org-agenda-last-arguments nil
3408 "The arguments of the previous call to `org-agenda'.")
3409 (defvar org-starting-day nil) ; local variable in the agenda buffer
3410 (defvar org-agenda-current-span nil
3411 "The current span used in the agenda view.") ; local variable in the agenda buffer
3412 (defvar org-include-all-loc nil) ; local variable
3414 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3415 "List of types searched for when creating the daily/weekly agenda.
3416 This variable is a list of symbols that controls the types of
3417 items that appear in the daily/weekly agenda. Allowed symbols in this
3418 list are are
3420 :timestamp List items containing a date stamp or date range matching
3421 the selected date. This includes sexp entries in
3422 angular brackets.
3424 :sexp List entries resulting from plain diary-like sexps.
3426 :deadline List deadline due on that date. When the date is today,
3427 also list any deadlines past due, or due within
3428 `org-deadline-warning-days'. `:deadline' must appear before
3429 `:scheduled' if the setting of
3430 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3431 any effect.
3433 :scheduled List all items which are scheduled for the given date.
3434 The diary for *today* also contains items which were
3435 scheduled earlier and are not yet marked DONE.
3437 By default, all four types are turned on.
3439 Never set this variable globally using `setq', because then it
3440 will apply to all future agenda commands. Instead, bind it with
3441 `let' to scope it dynamically into the the agenda-constructing
3442 command. A good way to set it is through options in
3443 `org-agenda-custom-commands'. For a more flexible (though
3444 somewhat less efficient) way of determining what is included in
3445 the daily/weekly agenda, see `org-agenda-skip-function'.")
3447 ;;;###autoload
3448 (defun org-agenda-list (&optional include-all start-day span)
3449 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3450 The view will be for the current day or week, but from the overview buffer
3451 you will be able to go to other days/weeks.
3453 With one \\[universal-argument] prefix argument INCLUDE-ALL,
3454 all unfinished TODO items will also be shown, before the agenda.
3455 This feature is considered obsolete, please use the TODO list or a block
3456 agenda instead.
3458 With a numeric prefix argument in an interactive call, the agenda will
3459 span INCLUDE-ALL days. Lisp programs should instead specify SPAN to change
3460 the number of days. SPAN defaults to `org-agenda-span'.
3462 START-DAY defaults to TODAY, or to the most recent match for the weekday
3463 given in `org-agenda-start-on-weekday'."
3464 (interactive "P")
3465 (if (and (integerp include-all) (> include-all 0))
3466 (setq span include-all include-all nil))
3467 (setq start-day (or start-day org-agenda-start-day))
3468 (if org-agenda-overriding-arguments
3469 (setq include-all (car org-agenda-overriding-arguments)
3470 start-day (nth 1 org-agenda-overriding-arguments)
3471 span (nth 2 org-agenda-overriding-arguments)))
3472 (if (stringp start-day)
3473 ;; Convert to an absolute day number
3474 (setq start-day (time-to-days (org-read-date nil t start-day))))
3475 (setq org-agenda-last-arguments (list include-all start-day span))
3476 (org-compile-prefix-format 'agenda)
3477 (org-set-sorting-strategy 'agenda)
3478 (let* ((span (org-agenda-ndays-to-span (or span
3479 org-agenda-current-span
3480 org-agenda-ndays
3481 org-agenda-span)))
3482 (today (org-today))
3483 (sd (or start-day today))
3484 (ndays (org-agenda-span-to-ndays span sd))
3485 (org-agenda-start-on-weekday
3486 (if (eq ndays 7)
3487 org-agenda-start-on-weekday))
3488 (thefiles (org-agenda-files nil 'ifmode))
3489 (files thefiles)
3490 (start (if (or (null org-agenda-start-on-weekday)
3491 (< ndays 7))
3493 (let* ((nt (calendar-day-of-week
3494 (calendar-gregorian-from-absolute sd)))
3495 (n1 org-agenda-start-on-weekday)
3496 (d (- nt n1)))
3497 (- sd (+ (if (< d 0) 7 0) d)))))
3498 (day-numbers (list start))
3499 (day-cnt 0)
3500 (inhibit-redisplay (not debug-on-error))
3501 s e rtn rtnall file date d start-pos end-pos todayp
3502 clocktable-start clocktable-end filter)
3503 (setq org-agenda-redo-command
3504 (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
3505 (dotimes (n (1- ndays))
3506 (push (1+ (car day-numbers)) day-numbers))
3507 (setq day-numbers (nreverse day-numbers))
3508 (setq clocktable-start (car day-numbers)
3509 clocktable-end (1+ (or (org-last day-numbers) 0)))
3510 (org-prepare-agenda "Day/Week")
3511 (org-set-local 'org-starting-day (car day-numbers))
3512 (org-set-local 'org-include-all-loc include-all)
3513 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3514 (when (and (or include-all org-agenda-include-all-todo)
3515 (member today day-numbers))
3516 (setq files thefiles
3517 rtnall nil)
3518 (while (setq file (pop files))
3519 (catch 'nextfile
3520 (org-check-agenda-file file)
3521 (setq date (calendar-gregorian-from-absolute today)
3522 rtn (org-agenda-get-day-entries
3523 file date :todo))
3524 (setq rtnall (append rtnall rtn))))
3525 (when rtnall
3526 (insert "All currently open TODO items:\n")
3527 (add-text-properties (point-min) (1- (point))
3528 (list 'face 'org-agenda-structure
3529 'short-heading "All TODO items"))
3530 (org-agenda-mark-header-line (point-min))
3531 (insert (org-finalize-agenda-entries rtnall) "\n")))
3532 (unless org-agenda-compact-blocks
3533 (let* ((d1 (car day-numbers))
3534 (d2 (org-last day-numbers))
3535 (w1 (org-days-to-iso-week d1))
3536 (w2 (org-days-to-iso-week d2)))
3537 (setq s (point))
3538 (if org-agenda-overriding-header
3539 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3540 nil 'face 'org-agenda-structure) "\n")
3541 (insert (org-agenda-span-name span)
3542 "-agenda"
3543 (if (< (- d2 d1) 350)
3544 (if (= w1 w2)
3545 (format " (W%02d)" w1)
3546 (format " (W%02d-W%02d)" w1 w2))
3548 ":\n")))
3549 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3550 'org-date-line t))
3551 (org-agenda-mark-header-line s))
3552 (while (setq d (pop day-numbers))
3553 (setq date (calendar-gregorian-from-absolute d)
3554 s (point))
3555 (if (or (setq todayp (= d today))
3556 (and (not start-pos) (= d sd)))
3557 (setq start-pos (point))
3558 (if (and start-pos (not end-pos))
3559 (setq end-pos (point))))
3560 (setq files thefiles
3561 rtnall nil)
3562 (while (setq file (pop files))
3563 (catch 'nextfile
3564 (org-check-agenda-file file)
3565 (let ((org-agenda-entry-types org-agenda-entry-types))
3566 (unless org-agenda-include-deadlines
3567 (setq org-agenda-entry-types
3568 (delq :deadline org-agenda-entry-types)))
3569 (cond
3570 ((eq org-agenda-show-log 'only)
3571 (setq rtn (org-agenda-get-day-entries
3572 file date :closed)))
3573 (org-agenda-show-log
3574 (setq rtn (apply 'org-agenda-get-day-entries
3575 file date
3576 (append '(:closed) org-agenda-entry-types))))
3578 (setq rtn (apply 'org-agenda-get-day-entries
3579 file date
3580 org-agenda-entry-types)))))
3581 (setq rtnall (append rtnall rtn))))
3582 (if org-agenda-include-diary
3583 (let ((org-agenda-search-headline-for-time t))
3584 (require 'diary-lib)
3585 (setq rtn (org-get-entries-from-diary date))
3586 (setq rtnall (append rtnall rtn))))
3587 (if (or rtnall org-agenda-show-all-dates)
3588 (progn
3589 (setq day-cnt (1+ day-cnt))
3590 (insert
3591 (if (stringp org-agenda-format-date)
3592 (format-time-string org-agenda-format-date
3593 (org-time-from-absolute date))
3594 (funcall org-agenda-format-date date))
3595 "\n")
3596 (put-text-property s (1- (point)) 'face
3597 (org-agenda-get-day-face date))
3598 (put-text-property s (1- (point)) 'org-date-line t)
3599 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3600 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3601 (when todayp
3602 (put-text-property s (1- (point)) 'org-today t))
3603 (if rtnall (insert
3604 (org-finalize-agenda-entries
3605 (org-agenda-add-time-grid-maybe
3606 rtnall ndays todayp))
3607 "\n"))
3608 (put-text-property s (1- (point)) 'day d)
3609 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3610 (when (and org-agenda-clockreport-mode clocktable-start)
3611 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3612 ;; the above line is to ensure the restricted range!
3613 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3614 tbl)
3615 (setq p (org-plist-delete p :block))
3616 (setq p (plist-put p :tstart clocktable-start))
3617 (setq p (plist-put p :tend clocktable-end))
3618 (setq p (plist-put p :scope 'agenda))
3619 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3620 (setq filter (or org-agenda-filter-while-redo
3621 (get 'org-agenda-filter :preset-filter))))
3622 (setq p (plist-put p :tags (mapconcat (lambda (x)
3623 (if (string-match "[<>=]" x)
3626 filter ""))))
3627 (setq tbl (apply 'org-get-clocktable p))
3628 (insert tbl)))
3629 (goto-char (point-min))
3630 (or org-agenda-multi (org-fit-agenda-window))
3631 (unless (and (pos-visible-in-window-p (point-min))
3632 (pos-visible-in-window-p (point-max)))
3633 (goto-char (1- (point-max)))
3634 (recenter -1)
3635 (if (not (pos-visible-in-window-p (or start-pos 1)))
3636 (progn
3637 (goto-char (or start-pos 1))
3638 (recenter 1))))
3639 (goto-char (or start-pos 1))
3640 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3641 (org-finalize-agenda)
3642 (setq buffer-read-only t)
3643 (message "")))
3645 (defun org-agenda-ndays-to-span (n)
3646 "Return a span symbol for a span of N days, or N if none matches."
3647 (cond ((symbolp n) n)
3648 ((= n 1) 'day)
3649 ((= n 7) 'week)
3650 (t n)))
3652 (defun org-agenda-span-to-ndays (span start-day)
3653 "Return ndays from SPAN starting at START-DAY."
3654 (cond ((numberp span) span)
3655 ((eq span 'day) 1)
3656 ((eq span 'week) 7)
3657 ((eq span 'month)
3658 (let ((date (calendar-gregorian-from-absolute start-day)))
3659 (calendar-last-day-of-month (car date) (caddr date))))
3660 ((eq span 'year)
3661 (let ((date (calendar-gregorian-from-absolute start-day)))
3662 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3664 (defun org-agenda-span-name (span)
3665 "Return a SPAN name."
3666 (if (null span)
3668 (if (symbolp span)
3669 (capitalize (symbol-name span))
3670 (format "%d days" span))))
3672 ;;; Agenda word search
3674 (defvar org-agenda-search-history nil)
3675 (defvar org-todo-only nil)
3677 (defvar org-search-syntax-table nil
3678 "Special syntax table for org-mode search.
3679 In this table, we have single quotes not as word constituents, to
3680 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3682 (defun org-search-syntax-table ()
3683 (unless org-search-syntax-table
3684 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3685 (modify-syntax-entry ?' "." org-search-syntax-table)
3686 (modify-syntax-entry ?` "." org-search-syntax-table))
3687 org-search-syntax-table)
3689 (defvar org-agenda-last-search-view-search-was-boolean nil)
3691 ;;;###autoload
3692 (defun org-search-view (&optional todo-only string edit-at)
3693 "Show all entries that contain a phrase or words or regular expressions.
3695 With optional prefix argument TODO-ONLY, only consider entries that are
3696 TODO entries. The argument STRING can be used to pass a default search
3697 string into this function. If EDIT-AT is non-nil, it means that the
3698 user should get a chance to edit this string, with cursor at position
3699 EDIT-AT.
3701 The search string can be viewed either as a phrase that should be found as
3702 is, or it can be broken into a number of snippets, each of which must match
3703 in a Boolean way to select an entry. The default depends on the variable
3704 `org-agenda-search-view-always-boolean'.
3705 Even if this is turned off (the default) you can always switch to
3706 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3708 The default is a direct search of the whole phrase, where each space in
3709 the search string can expand to an arbitrary amount of whitespace,
3710 including newlines.
3712 If using a Boolean search, the search string is split on whitespace and
3713 each snippet is searched separately, with logical AND to select an entry.
3714 Words prefixed with a minus must *not* occur in the entry. Words without
3715 a prefix or prefixed with a plus must occur in the entry. Matching is
3716 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3717 match whole words, not parts of a word) if
3718 `org-agenda-search-view-force-full-words' is set (default is nil).
3720 Boolean search snippets enclosed by curly braces are interpreted as
3721 regular expressions that must or (when preceded with \"-\") must not
3722 match in the entry. Snippets enclosed into double quotes will be taken
3723 as a whole, to include whitespace.
3725 - If the search string starts with an asterisk, search only in headlines.
3726 - If (possibly after the leading star) the search string starts with an
3727 exclamation mark, this also means to look at TODO entries only, an effect
3728 that can also be achieved with a prefix argument.
3729 - If (possibly after star and exclamation mark) the search string starts
3730 with a colon, this will mean that the (non-regexp) snippets of the
3731 Boolean search must match as full words.
3733 This command searches the agenda files, and in addition the files listed
3734 in `org-agenda-text-search-extra-files'."
3735 (interactive "P")
3736 (org-compile-prefix-format 'search)
3737 (org-set-sorting-strategy 'search)
3738 (org-prepare-agenda "SEARCH")
3739 (let* ((props (list 'face nil
3740 'done-face 'org-agenda-done
3741 'org-not-done-regexp org-not-done-regexp
3742 'org-todo-regexp org-todo-regexp
3743 'org-complex-heading-regexp org-complex-heading-regexp
3744 'mouse-face 'highlight
3745 'help-echo (format "mouse-2 or RET jump to location")))
3746 (full-words org-agenda-search-view-force-full-words)
3747 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
3748 regexp rtn rtnall files file pos
3749 marker category tags c neg re boolean
3750 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
3751 (unless (and (not edit-at)
3752 (stringp string)
3753 (string-match "\\S-" string))
3754 (setq string (read-string
3755 (if org-agenda-search-view-always-boolean
3756 "[+-]Word/{Regexp} ...: "
3757 "Phrase, or [+-]Word/{Regexp} ...: ")
3758 (cond
3759 ((integerp edit-at) (cons string edit-at))
3760 (edit-at string))
3761 'org-agenda-search-history)))
3762 (org-set-local 'org-todo-only todo-only)
3763 (setq org-agenda-redo-command
3764 (list 'org-search-view (if todo-only t nil) string
3765 '(if current-prefix-arg 1 nil)))
3766 (setq org-agenda-query-string string)
3768 (if (equal (string-to-char string) ?*)
3769 (setq hdl-only t
3770 words (substring string 1))
3771 (setq words string))
3772 (when (equal (string-to-char words) ?!)
3773 (setq todo-only t
3774 words (substring words 1)))
3775 (when (equal (string-to-char words) ?:)
3776 (setq full-words t
3777 words (substring words 1)))
3778 (if (or org-agenda-search-view-always-boolean
3779 (member (string-to-char words) '(?- ?+ ?\{)))
3780 (setq boolean t))
3781 (setq words (org-split-string words))
3782 (let (www w)
3783 (while (setq w (pop words))
3784 (while (and (string-match "\\\\\\'" w) words)
3785 (setq w (concat (substring w 0 -1) " " (pop words))))
3786 (push w www))
3787 (setq words (nreverse www) www nil)
3788 (while (setq w (pop words))
3789 (when (and (string-match "\\`[-+]?{" w)
3790 (not (string-match "}\\'" w)))
3791 (while (and words (not (string-match "}\\'" (car words))))
3792 (setq w (concat w " " (pop words))))
3793 (setq w (concat w " " (pop words))))
3794 (push w www))
3795 (setq words (nreverse www)))
3796 (setq org-agenda-last-search-view-search-was-boolean boolean)
3797 (when boolean
3798 (let (wds w)
3799 (while (setq w (pop words))
3800 (if (or (equal (substring w 0 1) "\"")
3801 (and (> (length w) 1)
3802 (member (substring w 0 1) '("+" "-"))
3803 (equal (substring w 1 2) "\"")))
3804 (while (and words (not (equal (substring w -1) "\"")))
3805 (setq w (concat w " " (pop words)))))
3806 (and (string-match "\\`\\([-+]?\\)\"" w)
3807 (setq w (replace-match "\\1" nil nil w)))
3808 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
3809 (push w wds))
3810 (setq words (nreverse wds))))
3811 (if boolean
3812 (mapc (lambda (w)
3813 (setq c (string-to-char w))
3814 (if (equal c ?-)
3815 (setq neg t w (substring w 1))
3816 (if (equal c ?+)
3817 (setq neg nil w (substring w 1))
3818 (setq neg nil)))
3819 (if (string-match "\\`{.*}\\'" w)
3820 (setq re (substring w 1 -1))
3821 (if full-words
3822 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
3823 (setq re (regexp-quote (downcase w)))))
3824 (if neg (push re regexps-) (push re regexps+)))
3825 words)
3826 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
3827 regexps+))
3828 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
3829 (if (not regexps+)
3830 (setq regexp (concat "^" org-outline-regexp))
3831 (setq regexp (pop regexps+))
3832 (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
3833 regexp))))
3834 (setq files (org-agenda-files nil 'ifmode))
3835 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
3836 (pop org-agenda-text-search-extra-files)
3837 (setq files (org-add-archive-files files)))
3838 (setq files (append files org-agenda-text-search-extra-files)
3839 rtnall nil)
3840 (while (setq file (pop files))
3841 (setq ee nil)
3842 (catch 'nextfile
3843 (org-check-agenda-file file)
3844 (setq buffer (if (file-exists-p file)
3845 (org-get-agenda-file-buffer file)
3846 (error "No such file %s" file)))
3847 (if (not buffer)
3848 ;; If file does not exist, make sure an error message is sent
3849 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
3850 file))))
3851 (with-current-buffer buffer
3852 (with-syntax-table (org-search-syntax-table)
3853 (unless (org-mode-p)
3854 (error "Agenda file %s is not in `org-mode'" file))
3855 (let ((case-fold-search t))
3856 (save-excursion
3857 (save-restriction
3858 (if org-agenda-restrict
3859 (narrow-to-region org-agenda-restrict-begin
3860 org-agenda-restrict-end)
3861 (widen))
3862 (goto-char (point-min))
3863 (unless (or (org-on-heading-p)
3864 (outline-next-heading))
3865 (throw 'nextfile t))
3866 (goto-char (max (point-min) (1- (point))))
3867 (while (re-search-forward regexp nil t)
3868 (org-back-to-heading t)
3869 (skip-chars-forward "* ")
3870 (setq beg (point-at-bol)
3871 beg1 (point)
3872 end (progn (outline-next-heading) (point)))
3873 (catch :skip
3874 (goto-char beg)
3875 (org-agenda-skip)
3876 (setq str (buffer-substring-no-properties
3877 (point-at-bol)
3878 (if hdl-only (point-at-eol) end)))
3879 (mapc (lambda (wr) (when (string-match wr str)
3880 (goto-char (1- end))
3881 (throw :skip t)))
3882 regexps-)
3883 (mapc (lambda (wr) (unless (string-match wr str)
3884 (goto-char (1- end))
3885 (throw :skip t)))
3886 (if todo-only
3887 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
3888 regexps+)
3889 regexps+))
3890 (goto-char beg)
3891 (setq marker (org-agenda-new-marker (point))
3892 category (org-get-category)
3893 tags (org-get-tags-at (point))
3894 txt (org-format-agenda-item
3896 (buffer-substring-no-properties
3897 beg1 (point-at-eol))
3898 category tags))
3899 (org-add-props txt props
3900 'org-marker marker 'org-hd-marker marker
3901 'org-todo-regexp org-todo-regexp
3902 'org-complex-heading-regexp org-complex-heading-regexp
3903 'priority 1000 'org-category category
3904 'type "search")
3905 (push txt ee)
3906 (goto-char (1- end))))))))))
3907 (setq rtn (nreverse ee))
3908 (setq rtnall (append rtnall rtn)))
3909 (if org-agenda-overriding-header
3910 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3911 nil 'face 'org-agenda-structure) "\n")
3912 (insert "Search words: ")
3913 (add-text-properties (point-min) (1- (point))
3914 (list 'face 'org-agenda-structure))
3915 (setq pos (point))
3916 (insert string "\n")
3917 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3918 (setq pos (point))
3919 (unless org-agenda-multi
3920 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
3921 (add-text-properties pos (1- (point))
3922 (list 'face 'org-agenda-structure))))
3923 (org-agenda-mark-header-line (point-min))
3924 (when rtnall
3925 (insert (org-finalize-agenda-entries rtnall) "\n"))
3926 (goto-char (point-min))
3927 (or org-agenda-multi (org-fit-agenda-window))
3928 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
3929 (org-finalize-agenda)
3930 (setq buffer-read-only t)))
3932 ;;; Agenda TODO list
3934 (defvar org-select-this-todo-keyword nil)
3935 (defvar org-last-arg nil)
3937 ;;;###autoload
3938 (defun org-todo-list (arg)
3939 "Show all (not done) TODO entries from all agenda file in a single list.
3940 The prefix arg can be used to select a specific TODO keyword and limit
3941 the list to these. When using \\[universal-argument], you will be prompted
3942 for a keyword. A numeric prefix directly selects the Nth keyword in
3943 `org-todo-keywords-1'."
3944 (interactive "P")
3945 (org-compile-prefix-format 'todo)
3946 (org-set-sorting-strategy 'todo)
3947 (org-prepare-agenda "TODO")
3948 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
3949 (let* ((today (org-today))
3950 (date (calendar-gregorian-from-absolute today))
3951 (kwds org-todo-keywords-for-agenda)
3952 (completion-ignore-case t)
3953 (org-select-this-todo-keyword
3954 (if (stringp arg) arg
3955 (and arg (integerp arg) (> arg 0)
3956 (nth (1- arg) kwds))))
3957 rtn rtnall files file pos)
3958 (when (equal arg '(4))
3959 (setq org-select-this-todo-keyword
3960 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
3961 (mapcar 'list kwds) nil nil)))
3962 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
3963 (org-set-local 'org-last-arg arg)
3964 (setq org-agenda-redo-command
3965 '(org-todo-list (or current-prefix-arg org-last-arg)))
3966 (setq files (org-agenda-files nil 'ifmode)
3967 rtnall nil)
3968 (while (setq file (pop files))
3969 (catch 'nextfile
3970 (org-check-agenda-file file)
3971 (setq rtn (org-agenda-get-day-entries file date :todo))
3972 (setq rtnall (append rtnall rtn))))
3973 (if org-agenda-overriding-header
3974 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3975 nil 'face 'org-agenda-structure) "\n")
3976 (insert "Global list of TODO items of type: ")
3977 (add-text-properties (point-min) (1- (point))
3978 (list 'face 'org-agenda-structure
3979 'short-heading
3980 (concat "ToDo: "
3981 (or org-select-this-todo-keyword "ALL"))))
3982 (org-agenda-mark-header-line (point-min))
3983 (setq pos (point))
3984 (insert (or org-select-this-todo-keyword "ALL") "\n")
3985 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
3986 (setq pos (point))
3987 (unless org-agenda-multi
3988 (insert "Available with `N r': (0)ALL")
3989 (let ((n 0) s)
3990 (mapc (lambda (x)
3991 (setq s (format "(%d)%s" (setq n (1+ n)) x))
3992 (if (> (+ (current-column) (string-width s) 1) (frame-width))
3993 (insert "\n "))
3994 (insert " " s))
3995 kwds))
3996 (insert "\n"))
3997 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
3998 (org-agenda-mark-header-line (point-min))
3999 (when rtnall
4000 (insert (org-finalize-agenda-entries rtnall) "\n"))
4001 (goto-char (point-min))
4002 (or org-agenda-multi (org-fit-agenda-window))
4003 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4004 (org-finalize-agenda)
4005 (setq buffer-read-only t)))
4007 ;;; Agenda tags match
4009 ;;;###autoload
4010 (defun org-tags-view (&optional todo-only match)
4011 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4012 The prefix arg TODO-ONLY limits the search to TODO entries."
4013 (interactive "P")
4014 (org-compile-prefix-format 'tags)
4015 (org-set-sorting-strategy 'tags)
4016 (let* ((org-tags-match-list-sublevels
4017 org-tags-match-list-sublevels)
4018 (completion-ignore-case t)
4019 rtn rtnall files file pos matcher
4020 buffer)
4021 (when (and (stringp match) (not (string-match "\\S-" match)))
4022 (setq match nil))
4023 (setq matcher (org-make-tags-matcher match)
4024 match (car matcher) matcher (cdr matcher))
4025 (org-prepare-agenda (concat "TAGS " match))
4026 (setq org-agenda-query-string match)
4027 (setq org-agenda-redo-command
4028 (list 'org-tags-view (list 'quote todo-only)
4029 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4030 (setq files (org-agenda-files nil 'ifmode)
4031 rtnall nil)
4032 (while (setq file (pop files))
4033 (catch 'nextfile
4034 (org-check-agenda-file file)
4035 (setq buffer (if (file-exists-p file)
4036 (org-get-agenda-file-buffer file)
4037 (error "No such file %s" file)))
4038 (if (not buffer)
4039 ;; If file does not exist, error message to agenda
4040 (setq rtn (list
4041 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4042 rtnall (append rtnall rtn))
4043 (with-current-buffer buffer
4044 (unless (org-mode-p)
4045 (error "Agenda file %s is not in `org-mode'" file))
4046 (save-excursion
4047 (save-restriction
4048 (if org-agenda-restrict
4049 (narrow-to-region org-agenda-restrict-begin
4050 org-agenda-restrict-end)
4051 (widen))
4052 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4053 (setq rtnall (append rtnall rtn))))))))
4054 (if org-agenda-overriding-header
4055 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4056 nil 'face 'org-agenda-structure) "\n")
4057 (insert "Headlines with TAGS match: ")
4058 (add-text-properties (point-min) (1- (point))
4059 (list 'face 'org-agenda-structure
4060 'short-heading
4061 (concat "Match: " match)))
4062 (setq pos (point))
4063 (insert match "\n")
4064 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4065 (setq pos (point))
4066 (unless org-agenda-multi
4067 (insert "Press `C-u r' to search again with new search string\n"))
4068 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4069 (org-agenda-mark-header-line (point-min))
4070 (when rtnall
4071 (insert (org-finalize-agenda-entries rtnall) "\n"))
4072 (goto-char (point-min))
4073 (or org-agenda-multi (org-fit-agenda-window))
4074 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4075 (org-finalize-agenda)
4076 (setq buffer-read-only t)))
4078 ;;; Agenda Finding stuck projects
4080 (defvar org-agenda-skip-regexp nil
4081 "Regular expression used in skipping subtrees for the agenda.
4082 This is basically a temporary global variable that can be set and then
4083 used by user-defined selections using `org-agenda-skip-function'.")
4085 (defvar org-agenda-overriding-header nil
4086 "When this is set during todo and tags searches, will replace header.
4087 This variable should not be set directly, but custom commands can bind it
4088 in the options section.")
4090 (defun org-agenda-skip-entry-when-regexp-matches ()
4091 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4092 If yes, it returns the end position of this entry, causing agenda commands
4093 to skip the entry but continuing the search in the subtree. This is a
4094 function that can be put into `org-agenda-skip-function' for the duration
4095 of a command."
4096 (let ((end (save-excursion (org-end-of-subtree t)))
4097 skip)
4098 (save-excursion
4099 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4100 (and skip end)))
4102 (defun org-agenda-skip-subtree-when-regexp-matches ()
4103 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4104 If yes, it returns the end position of this tree, causing agenda commands
4105 to skip this subtree. This is a function that can be put into
4106 `org-agenda-skip-function' for the duration of a command."
4107 (let ((end (save-excursion (org-end-of-subtree t)))
4108 skip)
4109 (save-excursion
4110 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4111 (and skip end)))
4113 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4114 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4115 If yes, it returns the end position of the current entry (NOT the tree),
4116 causing agenda commands to skip the entry but continuing the search in
4117 the subtree. This is a function that can be put into
4118 `org-agenda-skip-function' for the duration of a command. An important
4119 use of this function is for the stuck project list."
4120 (let ((end (save-excursion (org-end-of-subtree t)))
4121 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4122 skip)
4123 (save-excursion
4124 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4125 (and skip entry-end)))
4127 (defun org-agenda-skip-entry-if (&rest conditions)
4128 "Skip entry if any of CONDITIONS is true.
4129 See `org-agenda-skip-if' for details."
4130 (org-agenda-skip-if nil conditions))
4132 (defun org-agenda-skip-subtree-if (&rest conditions)
4133 "Skip entry if any of CONDITIONS is true.
4134 See `org-agenda-skip-if' for details."
4135 (org-agenda-skip-if t conditions))
4137 (defun org-agenda-skip-if (subtree conditions)
4138 "Checks current entity for CONDITIONS.
4139 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4140 the entry, i.e. the text before the next heading is checked.
4142 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4143 from different tests. Valid conditions are:
4145 scheduled Check if there is a scheduled cookie
4146 notscheduled Check if there is no scheduled cookie
4147 deadline Check if there is a deadline
4148 notdeadline Check if there is no deadline
4149 timestamp Check if there is a timestamp (also deadline or scheduled)
4150 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4151 regexp Check if regexp matches
4152 notregexp Check if regexp does not match.
4153 todo Check if TODO keyword matches
4154 nottodo Check if TODO keyword does not match
4156 The regexp is taken from the conditions list, it must come right after
4157 the `regexp' or `notregexp' element.
4159 `todo' and `nottodo' accept as an argument a list of todo
4160 keywords, which may include \"*\" to match any todo keyword.
4162 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4164 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4166 Instead of a list a keyword class may be given
4168 (org-agenda-skip-entry-if 'nottodo 'done)
4170 would skip entries that haven't been marked with any of \"DONE\"
4171 keywords. Possible classes are: `todo', `done', `any'.
4173 If any of these conditions is met, this function returns the end point of
4174 the entity, causing the search to continue from there. This is a function
4175 that can be put into `org-agenda-skip-function' for the duration of a command."
4176 (let (beg end m)
4177 (org-back-to-heading t)
4178 (setq beg (point)
4179 end (if subtree
4180 (progn (org-end-of-subtree t) (point))
4181 (progn (outline-next-heading) (1- (point)))))
4182 (goto-char beg)
4183 (and
4185 (and (memq 'scheduled conditions)
4186 (re-search-forward org-scheduled-time-regexp end t))
4187 (and (memq 'notscheduled conditions)
4188 (not (re-search-forward org-scheduled-time-regexp end t)))
4189 (and (memq 'deadline conditions)
4190 (re-search-forward org-deadline-time-regexp end t))
4191 (and (memq 'notdeadline conditions)
4192 (not (re-search-forward org-deadline-time-regexp end t)))
4193 (and (memq 'timestamp conditions)
4194 (re-search-forward org-ts-regexp end t))
4195 (and (memq 'nottimestamp conditions)
4196 (not (re-search-forward org-ts-regexp end t)))
4197 (and (setq m (memq 'regexp conditions))
4198 (stringp (nth 1 m))
4199 (re-search-forward (nth 1 m) end t))
4200 (and (setq m (memq 'notregexp conditions))
4201 (stringp (nth 1 m))
4202 (not (re-search-forward (nth 1 m) end t)))
4203 (and (or
4204 (setq m (memq 'todo conditions))
4205 (setq m (memq 'nottodo conditions)))
4206 (org-agenda-skip-if-todo m end)))
4207 end)))
4209 (defun org-agenda-skip-if-todo (args end)
4210 "Helper function for `org-agenda-skip-if', do not use it directly.
4211 ARGS is a list with first element either `todo' or `nottodo'.
4212 The remainder is either a list of TODO keywords, or a state symbol
4213 `todo' or `done' or `any'."
4214 (let ((kw (car args))
4215 (arg (cadr args))
4216 todo-wds todo-re)
4217 (setq todo-wds
4218 (org-uniquify
4219 (cond
4220 ((listp arg) ;; list of keywords
4221 (if (member "*" arg)
4222 (mapcar 'substring-no-properties org-todo-keywords-1)
4223 arg))
4224 ((symbolp arg) ;; keyword class name
4225 (cond
4226 ((eq arg 'todo)
4227 (org-delete-all org-done-keywords
4228 (mapcar 'substring-no-properties
4229 org-todo-keywords-1)))
4230 ((eq arg 'done) org-done-keywords)
4231 ((eq arg 'any)
4232 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4233 (setq todo-re
4234 (concat "^\\*+[ \t]+\\<\\("
4235 (mapconcat 'identity todo-wds "\\|")
4236 "\\)\\>"))
4237 (if (eq kw 'todo)
4238 (re-search-forward todo-re end t)
4239 (not (re-search-forward todo-re end t)))))
4241 ;;;###autoload
4242 (defun org-agenda-list-stuck-projects (&rest ignore)
4243 "Create agenda view for projects that are stuck.
4244 Stuck projects are project that have no next actions. For the definitions
4245 of what a project is and how to check if it stuck, customize the variable
4246 `org-stuck-projects'."
4247 (interactive)
4248 (let* ((org-agenda-skip-function
4249 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4250 ;; We could have used org-agenda-skip-if here.
4251 (org-agenda-overriding-header
4252 (or org-agenda-overriding-header "List of stuck projects: "))
4253 (matcher (nth 0 org-stuck-projects))
4254 (todo (nth 1 org-stuck-projects))
4255 (todo-wds (if (member "*" todo)
4256 (progn
4257 (org-prepare-agenda-buffers (org-agenda-files
4258 nil 'ifmode))
4259 (org-delete-all
4260 org-done-keywords-for-agenda
4261 (copy-sequence org-todo-keywords-for-agenda)))
4262 todo))
4263 (todo-re (concat "^\\*+[ \t]+\\("
4264 (mapconcat 'identity todo-wds "\\|")
4265 "\\)\\>"))
4266 (tags (nth 2 org-stuck-projects))
4267 (tags-re (if (member "*" tags)
4268 (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
4269 (if tags
4270 (concat "^\\*+ .*:\\("
4271 (mapconcat 'identity tags "\\|")
4272 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4273 (gen-re (nth 3 org-stuck-projects))
4274 (re-list
4275 (delq nil
4276 (list
4277 (if todo todo-re)
4278 (if tags tags-re)
4279 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4280 gen-re)))))
4281 (setq org-agenda-skip-regexp
4282 (if re-list
4283 (mapconcat 'identity re-list "\\|")
4284 (error "No information how to identify unstuck projects")))
4285 (org-tags-view nil matcher)
4286 (with-current-buffer org-agenda-buffer-name
4287 (setq org-agenda-redo-command
4288 '(org-agenda-list-stuck-projects
4289 (or current-prefix-arg org-last-arg))))))
4291 ;;; Diary integration
4293 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4294 (defvar list-diary-entries-hook)
4296 (defun org-get-entries-from-diary (date)
4297 "Get the (Emacs Calendar) diary entries for DATE."
4298 (require 'diary-lib)
4299 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4300 (diary-display-hook '(fancy-diary-display))
4301 (diary-display-function 'fancy-diary-display)
4302 (pop-up-frames nil)
4303 (list-diary-entries-hook
4304 (cons 'org-diary-default-entry list-diary-entries-hook))
4305 (diary-file-name-prefix-function nil) ; turn this feature off
4306 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4307 entries
4308 (org-disable-agenda-to-diary t))
4309 (save-excursion
4310 (save-window-excursion
4311 (funcall (if (fboundp 'diary-list-entries)
4312 'diary-list-entries 'list-diary-entries)
4313 date 1)))
4314 (if (not (get-buffer diary-fancy-buffer))
4315 (setq entries nil)
4316 (with-current-buffer diary-fancy-buffer
4317 (setq buffer-read-only nil)
4318 (if (zerop (buffer-size))
4319 ;; No entries
4320 (setq entries nil)
4321 ;; Omit the date and other unnecessary stuff
4322 (org-agenda-cleanup-fancy-diary)
4323 ;; Add prefix to each line and extend the text properties
4324 (if (zerop (buffer-size))
4325 (setq entries nil)
4326 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4327 (setq entries
4328 (with-temp-buffer
4329 (insert entries) (goto-char (point-min))
4330 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4331 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4332 (replace-match (concat "; " (match-string 1)))))
4333 (buffer-string)))))
4334 (set-buffer-modified-p nil)
4335 (kill-buffer diary-fancy-buffer)))
4336 (when entries
4337 (setq entries (org-split-string entries "\n"))
4338 (setq entries
4339 (mapcar
4340 (lambda (x)
4341 (setq x (org-format-agenda-item "" x "Diary" nil 'time))
4342 ;; Extend the text properties to the beginning of the line
4343 (org-add-props x (text-properties-at (1- (length x)) x)
4344 'type "diary" 'date date 'face 'org-agenda-diary))
4345 entries)))))
4347 (defvar org-agenda-cleanup-fancy-diary-hook nil
4348 "Hook run when the fancy diary buffer is cleaned up.")
4350 (defun org-agenda-cleanup-fancy-diary ()
4351 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4352 This gets rid of the date, the underline under the date, and
4353 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4354 date. It also removes lines that contain only whitespace."
4355 (goto-char (point-min))
4356 (if (looking-at ".*?:[ \t]*")
4357 (progn
4358 (replace-match "")
4359 (re-search-forward "\n=+$" nil t)
4360 (replace-match "")
4361 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4362 (re-search-forward "\n=+$" nil t)
4363 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4364 (goto-char (point-min))
4365 (while (re-search-forward "^ +\n" nil t)
4366 (replace-match ""))
4367 (goto-char (point-min))
4368 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4369 (replace-match ""))
4370 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4372 ;; Make sure entries from the diary have the right text properties.
4373 (eval-after-load "diary-lib"
4374 '(if (boundp 'diary-modify-entry-list-string-function)
4375 ;; We can rely on the hook, nothing to do
4377 ;; Hook not available, must use advice to make this work
4378 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4379 "Make the position visible."
4380 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4381 (stringp string)
4382 buffer-file-name)
4383 (setq string (org-modify-diary-entry-string string))))))
4385 (defun org-modify-diary-entry-string (string)
4386 "Add text properties to string, allowing org-mode to act on it."
4387 (org-add-props string nil
4388 'mouse-face 'highlight
4389 'help-echo (if buffer-file-name
4390 (format "mouse-2 or RET jump to diary file %s"
4391 (abbreviate-file-name buffer-file-name))
4393 'org-agenda-diary-link t
4394 'org-marker (org-agenda-new-marker (point-at-bol))))
4396 (defun org-diary-default-entry ()
4397 "Add a dummy entry to the diary.
4398 Needed to avoid empty dates which mess up holiday display."
4399 ;; Catch the error if dealing with the new add-to-diary-alist
4400 (when org-disable-agenda-to-diary
4401 (condition-case nil
4402 (org-add-to-diary-list original-date "Org-mode dummy" "")
4403 (error
4404 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4406 (defun org-add-to-diary-list (&rest args)
4407 (if (fboundp 'diary-add-to-list)
4408 (apply 'diary-add-to-list args)
4409 (apply 'add-to-diary-list args)))
4411 (defvar org-diary-last-run-time nil)
4413 ;;;###autoload
4414 (defun org-diary (&rest args)
4415 "Return diary information from org-files.
4416 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4417 It accesses org files and extracts information from those files to be
4418 listed in the diary. The function accepts arguments specifying what
4419 items should be listed. For a list of arguments allowed here, see the
4420 variable `org-agenda-entry-types'.
4422 The call in the diary file should look like this:
4424 &%%(org-diary) ~/path/to/some/orgfile.org
4426 Use a separate line for each org file to check. Or, if you omit the file name,
4427 all files listed in `org-agenda-files' will be checked automatically:
4429 &%%(org-diary)
4431 If you don't give any arguments (as in the example above), the default
4432 arguments (:deadline :scheduled :timestamp :sexp) are used.
4433 So the example above may also be written as
4435 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4437 The function expects the lisp variables `entry' and `date' to be provided
4438 by the caller, because this is how the calendar works. Don't use this
4439 function from a program - use `org-agenda-get-day-entries' instead."
4440 (when (> (- (org-float-time)
4441 org-agenda-last-marker-time)
4443 (org-agenda-reset-markers))
4444 (org-compile-prefix-format 'agenda)
4445 (org-set-sorting-strategy 'agenda)
4446 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4447 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4448 (list entry)
4449 (org-agenda-files t)))
4450 (time (org-float-time))
4451 file rtn results)
4452 (when (or (not org-diary-last-run-time)
4453 (> (- time
4454 org-diary-last-run-time)
4456 (org-prepare-agenda-buffers files))
4457 (setq org-diary-last-run-time time)
4458 ;; If this is called during org-agenda, don't return any entries to
4459 ;; the calendar. Org Agenda will list these entries itself.
4460 (if org-disable-agenda-to-diary (setq files nil))
4461 (while (setq file (pop files))
4462 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4463 (setq results (append results rtn)))
4464 (if results
4465 (concat (org-finalize-agenda-entries results) "\n"))))
4467 ;;; Agenda entry finders
4469 (defun org-agenda-get-day-entries (file date &rest args)
4470 "Does the work for `org-diary' and `org-agenda'.
4471 FILE is the path to a file to be checked for entries. DATE is date like
4472 the one returned by `calendar-current-date'. ARGS are symbols indicating
4473 which kind of entries should be extracted. For details about these, see
4474 the documentation of `org-diary'."
4475 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4476 (let* ((org-startup-folded nil)
4477 (org-startup-align-all-tables nil)
4478 (buffer (if (file-exists-p file)
4479 (org-get-agenda-file-buffer file)
4480 (error "No such file %s" file)))
4481 arg results rtn deadline-results)
4482 (if (not buffer)
4483 ;; If file does not exist, make sure an error message ends up in diary
4484 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4485 (with-current-buffer buffer
4486 (unless (org-mode-p)
4487 (error "Agenda file %s is not in `org-mode'" file))
4488 (let ((case-fold-search nil))
4489 (save-excursion
4490 (save-restriction
4491 (if org-agenda-restrict
4492 (narrow-to-region org-agenda-restrict-begin
4493 org-agenda-restrict-end)
4494 (widen))
4495 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4496 (while (setq arg (pop args))
4497 (cond
4498 ((and (eq arg :todo)
4499 (equal date (calendar-gregorian-from-absolute
4500 (org-today))))
4501 (setq rtn (org-agenda-get-todos))
4502 (setq results (append results rtn)))
4503 ((eq arg :timestamp)
4504 (setq rtn (org-agenda-get-blocks))
4505 (setq results (append results rtn))
4506 (setq rtn (org-agenda-get-timestamps))
4507 (setq results (append results rtn)))
4508 ((eq arg :sexp)
4509 (setq rtn (org-agenda-get-sexps))
4510 (setq results (append results rtn)))
4511 ((eq arg :scheduled)
4512 (setq rtn (org-agenda-get-scheduled deadline-results))
4513 (setq results (append results rtn)))
4514 ((eq arg :closed)
4515 (setq rtn (org-agenda-get-progress))
4516 (setq results (append results rtn)))
4517 ((eq arg :deadline)
4518 (setq rtn (org-agenda-get-deadlines))
4519 (setq deadline-results (copy-sequence rtn))
4520 (setq results (append results rtn))))))))
4521 results))))
4523 (defun org-agenda-get-todos ()
4524 "Return the TODO information for agenda display."
4525 (let* ((props (list 'face nil
4526 'done-face 'org-agenda-done
4527 'org-not-done-regexp org-not-done-regexp
4528 'org-todo-regexp org-todo-regexp
4529 'org-complex-heading-regexp org-complex-heading-regexp
4530 'mouse-face 'highlight
4531 'help-echo
4532 (format "mouse-2 or RET jump to org file %s"
4533 (abbreviate-file-name buffer-file-name))))
4534 (regexp (concat "^\\*+[ \t]+\\("
4535 (if org-select-this-todo-keyword
4536 (if (equal org-select-this-todo-keyword "*")
4537 org-todo-regexp
4538 (concat "\\<\\("
4539 (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
4540 "\\)\\>"))
4541 org-not-done-regexp)
4542 "[^\n\r]*\\)"))
4543 marker priority category tags todo-state
4544 ee txt beg end)
4545 (goto-char (point-min))
4546 (while (re-search-forward regexp nil t)
4547 (catch :skip
4548 (save-match-data
4549 (beginning-of-line)
4550 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4551 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4552 (goto-char (1+ beg))
4553 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4554 (throw :skip nil)))
4555 (goto-char beg)
4556 (org-agenda-skip)
4557 (goto-char (match-beginning 1))
4558 (setq marker (org-agenda-new-marker (match-beginning 0))
4559 category (org-get-category)
4560 txt (match-string 1)
4561 tags (org-get-tags-at (point))
4562 txt (org-format-agenda-item "" txt category tags)
4563 priority (1+ (org-get-priority txt))
4564 todo-state (org-get-todo-state))
4565 (org-add-props txt props
4566 'org-marker marker 'org-hd-marker marker
4567 'priority priority 'org-category category
4568 'type "todo" 'todo-state todo-state)
4569 (push txt ee)
4570 (if org-agenda-todo-list-sublevels
4571 (goto-char (match-end 1))
4572 (org-end-of-subtree 'invisible))))
4573 (nreverse ee)))
4575 (defun org-agenda-todo-custom-ignore-p (time n)
4576 "Check whether timestamp is farther away then n number of days.
4577 This function is invoked if `org-agenda-todo-ignore-deadlines',
4578 `org-agenda-todo-ignore-scheduled' or
4579 `org-agenda-todo-ignore-timestamp' is set to an integer."
4580 (let ((days (org-days-to-time time)))
4581 (if (>= n 0)
4582 (>= days n)
4583 (<= days n))))
4585 ;;;###autoload
4586 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4587 (&optional end)
4588 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4589 (when (or org-agenda-todo-ignore-with-date
4590 org-agenda-todo-ignore-scheduled
4591 org-agenda-todo-ignore-deadlines
4592 org-agenda-todo-ignore-timestamp)
4593 (setq end (or end (save-excursion (outline-next-heading) (point))))
4594 (save-excursion
4595 (or (and org-agenda-todo-ignore-with-date
4596 (re-search-forward org-ts-regexp end t))
4597 (and org-agenda-todo-ignore-scheduled
4598 (re-search-forward org-scheduled-time-regexp end t)
4599 (cond
4600 ((eq org-agenda-todo-ignore-scheduled 'future)
4601 (> (org-days-to-time (match-string 1)) 0))
4602 ((eq org-agenda-todo-ignore-scheduled 'past)
4603 (<= (org-days-to-time (match-string 1)) 0))
4604 ((numberp org-agenda-todo-ignore-scheduled)
4605 (org-agenda-todo-custom-ignore-p
4606 (match-string 1) org-agenda-todo-ignore-scheduled))
4607 (t)))
4608 (and org-agenda-todo-ignore-deadlines
4609 (re-search-forward org-deadline-time-regexp end t)
4610 (cond
4611 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4612 ((eq org-agenda-todo-ignore-deadlines 'far)
4613 (not (org-deadline-close (match-string 1))))
4614 ((eq org-agenda-todo-ignore-deadlines 'future)
4615 (> (org-days-to-time (match-string 1)) 0))
4616 ((eq org-agenda-todo-ignore-deadlines 'past)
4617 (<= (org-days-to-time (match-string 1)) 0))
4618 ((numberp org-agenda-todo-ignore-deadlines)
4619 (org-agenda-todo-custom-ignore-p
4620 (match-string 1) org-agenda-todo-ignore-deadlines))
4621 (t (org-deadline-close (match-string 1)))))
4622 (and org-agenda-todo-ignore-timestamp
4623 (let ((buffer (current-buffer))
4624 (regexp
4625 (concat
4626 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4627 (start (point)))
4628 ;; Copy current buffer into a temporary one
4629 (with-temp-buffer
4630 (insert-buffer-substring buffer start end)
4631 (goto-char (point-min))
4632 ;; Delete SCHEDULED and DEADLINE items
4633 (while (re-search-forward regexp end t)
4634 (delete-region (match-beginning 0) (match-end 0)))
4635 (goto-char (point-min))
4636 ;; No search for timestamp left
4637 (when (re-search-forward org-ts-regexp nil t)
4638 (cond
4639 ((eq org-agenda-todo-ignore-timestamp 'future)
4640 (> (org-days-to-time (match-string 1)) 0))
4641 ((eq org-agenda-todo-ignore-timestamp 'past)
4642 (<= (org-days-to-time (match-string 1)) 0))
4643 ((numberp org-agenda-todo-ignore-timestamp)
4644 (org-agenda-todo-custom-ignore-p
4645 (match-string 1) org-agenda-todo-ignore-timestamp))
4646 (t))))))))))
4648 (defconst org-agenda-no-heading-message
4649 "No heading for this item in buffer or region.")
4651 (defun org-agenda-get-timestamps ()
4652 "Return the date stamp information for agenda display."
4653 (let* ((props (list 'face nil
4654 'org-not-done-regexp org-not-done-regexp
4655 'org-todo-regexp org-todo-regexp
4656 'org-complex-heading-regexp org-complex-heading-regexp
4657 'mouse-face 'highlight
4658 'help-echo
4659 (format "mouse-2 or RET jump to org file %s"
4660 (abbreviate-file-name buffer-file-name))))
4661 (d1 (calendar-absolute-from-gregorian date))
4662 (remove-re
4663 (concat
4664 (regexp-quote
4665 (format-time-string
4666 "<%Y-%m-%d"
4667 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4668 ".*?>"))
4669 (regexp
4670 (concat
4671 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4672 (regexp-quote
4673 (substring
4674 (format-time-string
4675 (car org-time-stamp-formats)
4676 (apply 'encode-time ; DATE bound by calendar
4677 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4678 1 11))
4679 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4680 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4681 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4682 donep tmp priority category ee txt timestr tags b0 b3 e3 head
4683 todo-state end-of-match)
4684 (goto-char (point-min))
4685 (while (setq end-of-match (re-search-forward regexp nil t))
4686 (setq b0 (match-beginning 0)
4687 b3 (match-beginning 3) e3 (match-end 3)
4688 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4689 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4690 (member todo-state
4691 org-agenda-repeating-timestamp-show-all)))
4692 (catch :skip
4693 (and (org-at-date-range-p) (throw :skip nil))
4694 (org-agenda-skip)
4695 (if (and (match-end 1)
4696 (not (= d1 (org-time-string-to-absolute
4697 (match-string 1) d1 nil show-all))))
4698 (throw :skip nil))
4699 (if (and e3
4700 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4701 (throw :skip nil))
4702 (setq tmp (buffer-substring (max (point-min)
4703 (- b0 org-ds-keyword-length))
4705 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4706 inactivep (= (char-after b0) ?\[)
4707 deadlinep (string-match org-deadline-regexp tmp)
4708 scheduledp (string-match org-scheduled-regexp tmp)
4709 closedp (and org-agenda-include-inactive-timestamps
4710 (string-match org-closed-string tmp))
4711 clockp (and org-agenda-include-inactive-timestamps
4712 (or (string-match org-clock-string tmp)
4713 (string-match "]-+\\'" tmp)))
4714 donep (member todo-state org-done-keywords))
4715 (if (or scheduledp deadlinep closedp clockp
4716 (and donep org-agenda-skip-timestamp-if-done))
4717 (throw :skip t))
4718 (if (string-match ">" timestr)
4719 ;; substring should only run to end of time stamp
4720 (setq timestr (substring timestr 0 (match-end 0))))
4721 (setq marker (org-agenda-new-marker b0)
4722 category (org-get-category b0))
4723 (save-excursion
4724 (if (not (re-search-backward "^\\*+ " nil t))
4725 (setq txt org-agenda-no-heading-message)
4726 (goto-char (match-beginning 0))
4727 (setq hdmarker (org-agenda-new-marker)
4728 tags (org-get-tags-at))
4729 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4730 (setq head (match-string 1))
4731 (setq txt (org-format-agenda-item
4732 (if inactivep org-agenda-inactive-leader nil)
4733 head category tags timestr nil
4734 remove-re)))
4735 (setq priority (org-get-priority txt))
4736 (org-add-props txt props
4737 'org-marker marker 'org-hd-marker hdmarker)
4738 (org-add-props txt nil 'priority priority
4739 'org-category category 'date date
4740 'todo-state todo-state
4741 'type "timestamp")
4742 (push txt ee))
4743 (if org-agenda-skip-additional-timestamps-same-entry
4744 (outline-next-heading)
4745 (goto-char end-of-match))))
4746 (nreverse ee)))
4748 (defun org-agenda-get-sexps ()
4749 "Return the sexp information for agenda display."
4750 (require 'diary-lib)
4751 (let* ((props (list 'mouse-face 'highlight
4752 'help-echo
4753 (format "mouse-2 or RET jump to org file %s"
4754 (abbreviate-file-name buffer-file-name))))
4755 (regexp "^&?%%(")
4756 marker category ee txt tags entry result beg b sexp sexp-entry
4757 todo-state)
4758 (goto-char (point-min))
4759 (while (re-search-forward regexp nil t)
4760 (catch :skip
4761 (org-agenda-skip)
4762 (setq beg (match-beginning 0))
4763 (goto-char (1- (match-end 0)))
4764 (setq b (point))
4765 (forward-sexp 1)
4766 (setq sexp (buffer-substring b (point)))
4767 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
4768 (org-trim (match-string 1))
4769 ""))
4770 (setq result (org-diary-sexp-entry sexp sexp-entry date))
4771 (when result
4772 (setq marker (org-agenda-new-marker beg)
4773 category (org-get-category beg)
4774 todo-state (org-get-todo-state))
4776 (dolist (r (if (stringp result)
4777 (list result)
4778 result)) ;; we expect a list here
4779 (if (string-match "\\S-" r)
4780 (setq txt r)
4781 (setq txt "SEXP entry returned empty string"))
4783 (setq txt (org-format-agenda-item
4784 "" txt category tags 'time))
4785 (org-add-props txt props 'org-marker marker)
4786 (org-add-props txt nil
4787 'org-category category 'date date 'todo-state todo-state
4788 'type "sexp")
4789 (push txt ee)))))
4790 (nreverse ee)))
4792 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
4793 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
4794 The order of the first 2 times 3 arguments depends on the variable
4795 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
4796 So for American calendars, give this as MONTH DAY YEAR, for European as
4797 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
4798 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
4799 is any number of ISO weeks in the block period for which the item should
4800 be skipped."
4801 (let* ((date1 (calendar-absolute-from-gregorian
4802 (org-order-calendar-date-args m1 d1 y1)))
4803 (date2 (calendar-absolute-from-gregorian
4804 (org-order-calendar-date-args m2 d2 y2)))
4805 (d (calendar-absolute-from-gregorian date)))
4806 (and
4807 (<= date1 d)
4808 (<= d date2)
4809 (= (calendar-day-of-week date) dayname)
4810 (or (not skip-weeks)
4811 (progn
4812 (require 'cal-iso)
4813 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
4814 entry)))
4816 (defalias 'org-get-closed 'org-agenda-get-progress)
4817 (defun org-agenda-get-progress ()
4818 "Return the logged TODO entries for agenda display."
4819 (let* ((props (list 'mouse-face 'highlight
4820 'org-not-done-regexp org-not-done-regexp
4821 'org-todo-regexp org-todo-regexp
4822 'org-complex-heading-regexp org-complex-heading-regexp
4823 'help-echo
4824 (format "mouse-2 or RET jump to org file %s"
4825 (abbreviate-file-name buffer-file-name))))
4826 (items (if (consp org-agenda-show-log)
4827 org-agenda-show-log
4828 org-agenda-log-mode-items))
4829 (parts
4830 (delq nil
4831 (list
4832 (if (memq 'closed items) (concat "\\<" org-closed-string))
4833 (if (memq 'clock items) (concat "\\<" org-clock-string))
4834 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
4835 (parts-re (if parts (mapconcat 'identity parts "\\|")
4836 (error "`org-agenda-log-mode-items' is empty")))
4837 (regexp (concat
4838 "\\(" parts-re "\\)"
4839 " *\\["
4840 (regexp-quote
4841 (substring
4842 (format-time-string
4843 (car org-time-stamp-formats)
4844 (apply 'encode-time ; DATE bound by calendar
4845 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4846 1 11))))
4847 (org-agenda-search-headline-for-time nil)
4848 marker hdmarker priority category tags closedp statep clockp state
4849 ee txt extra timestr rest clocked)
4850 (goto-char (point-min))
4851 (while (re-search-forward regexp nil t)
4852 (catch :skip
4853 (org-agenda-skip)
4854 (setq marker (org-agenda-new-marker (match-beginning 0))
4855 closedp (equal (match-string 1) org-closed-string)
4856 statep (equal (string-to-char (match-string 1)) ?-)
4857 clockp (not (or closedp statep))
4858 state (and statep (match-string 2))
4859 category (org-get-category (match-beginning 0))
4860 timestr (buffer-substring (match-beginning 0) (point-at-eol))
4862 (when (string-match "\\]" timestr)
4863 ;; substring should only run to end of time stamp
4864 (setq rest (substring timestr (match-end 0))
4865 timestr (substring timestr 0 (match-end 0)))
4866 (if (and (not closedp) (not statep)
4867 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
4868 (progn (setq timestr (concat (substring timestr 0 -1)
4869 "-" (match-string 1 rest) "]"))
4870 (setq clocked (match-string 2 rest)))
4871 (setq clocked "-")))
4872 (save-excursion
4873 (setq extra
4874 (cond
4875 ((not org-agenda-log-mode-add-notes) nil)
4876 (statep
4877 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
4878 (match-string 1)))
4879 (clockp
4880 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
4881 (match-string 1)))))
4882 (if (not (re-search-backward "^\\*+ " nil t))
4883 (setq txt org-agenda-no-heading-message)
4884 (goto-char (match-beginning 0))
4885 (setq hdmarker (org-agenda-new-marker)
4886 tags (org-get-tags-at))
4887 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
4888 (setq txt (match-string 1))
4889 (when extra
4890 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
4891 (setq txt (concat (substring txt 0 (match-beginning 1))
4892 " - " extra " " (match-string 2 txt)))
4893 (setq txt (concat txt " - " extra))))
4894 (setq txt (org-format-agenda-item
4895 (cond
4896 (closedp "Closed: ")
4897 (statep (concat "State: (" state ")"))
4898 (t (concat "Clocked: (" clocked ")")))
4899 txt category tags timestr)))
4900 (setq priority 100000)
4901 (org-add-props txt props
4902 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
4903 'priority priority 'org-category category
4904 'type "closed" 'date date
4905 'undone-face 'org-warning 'done-face 'org-agenda-done)
4906 (push txt ee))
4907 (goto-char (point-at-eol))))
4908 (nreverse ee)))
4910 (defun org-agenda-get-deadlines ()
4911 "Return the deadline information for agenda display."
4912 (let* ((props (list 'mouse-face 'highlight
4913 'org-not-done-regexp org-not-done-regexp
4914 'org-todo-regexp org-todo-regexp
4915 'org-complex-heading-regexp org-complex-heading-regexp
4916 'help-echo
4917 (format "mouse-2 or RET jump to org file %s"
4918 (abbreviate-file-name buffer-file-name))))
4919 (regexp org-deadline-time-regexp)
4920 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
4921 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
4922 d2 diff dfrac wdays pos pos1 category tags
4923 suppress-prewarning
4924 ee txt head face s todo-state show-all upcomingp donep timestr)
4925 (goto-char (point-min))
4926 (while (re-search-forward regexp nil t)
4927 (setq suppress-prewarning nil)
4928 (catch :skip
4929 (org-agenda-skip)
4930 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
4931 (save-match-data
4932 (string-match org-scheduled-time-regexp
4933 (buffer-substring (point-at-bol)
4934 (point-at-eol)))))
4935 (setq suppress-prewarning
4936 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
4937 org-agenda-skip-deadline-prewarning-if-scheduled
4938 0)))
4939 (setq s (match-string 1)
4940 txt nil
4941 pos (1- (match-beginning 1))
4942 todo-state (save-match-data (org-get-todo-state))
4943 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4944 (member todo-state
4945 org-agenda-repeating-timestamp-show-all))
4946 d2 (org-time-string-to-absolute
4947 (match-string 1) d1 'past show-all)
4948 diff (- d2 d1)
4949 wdays (if suppress-prewarning
4950 (let ((org-deadline-warning-days suppress-prewarning))
4951 (org-get-wdays s))
4952 (org-get-wdays s))
4953 dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
4954 upcomingp (and todayp (> diff 0)))
4955 ;; When to show a deadline in the calendar:
4956 ;; If the expiration is within wdays warning time.
4957 ;; Past-due deadlines are only shown on the current date
4958 (if (and (or (and (<= diff wdays)
4959 (and todayp (not org-agenda-only-exact-dates)))
4960 (= diff 0)))
4961 (save-excursion
4962 ;; (setq todo-state (org-get-todo-state))
4963 (setq donep (member todo-state org-done-keywords))
4964 (if (and donep
4965 (or org-agenda-skip-deadline-if-done
4966 (not (= diff 0))))
4967 (setq txt nil)
4968 (setq category (org-get-category))
4969 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
4970 (setq txt org-agenda-no-heading-message)
4971 (goto-char (match-end 0))
4972 (setq pos1 (match-beginning 0))
4973 (setq tags (org-get-tags-at pos1))
4974 (setq head (buffer-substring-no-properties
4975 (point)
4976 (progn (skip-chars-forward "^\r\n")
4977 (point))))
4978 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
4979 (setq timestr
4980 (concat (substring s (match-beginning 1)) " "))
4981 (setq timestr 'time))
4982 (setq txt (org-format-agenda-item
4983 (if (= diff 0)
4984 (car org-agenda-deadline-leaders)
4985 (if (functionp
4986 (nth 1 org-agenda-deadline-leaders))
4987 (funcall
4988 (nth 1 org-agenda-deadline-leaders)
4989 diff date)
4990 (format (nth 1 org-agenda-deadline-leaders)
4991 diff)))
4992 head category tags
4993 (if (not (= diff 0)) nil timestr)))))
4994 (when txt
4995 (setq face (org-agenda-deadline-face dfrac wdays))
4996 (org-add-props txt props
4997 'org-marker (org-agenda-new-marker pos)
4998 'org-hd-marker (org-agenda-new-marker pos1)
4999 'priority (+ (- diff)
5000 (org-get-priority txt))
5001 'org-category category
5002 'todo-state todo-state
5003 'type (if upcomingp "upcoming-deadline" "deadline")
5004 'date (if upcomingp date d2)
5005 'face (if donep 'org-agenda-done face)
5006 'undone-face face 'done-face 'org-agenda-done)
5007 (push txt ee))))))
5008 (nreverse ee)))
5010 (defun org-agenda-deadline-face (fraction &optional wdays)
5011 "Return the face to displaying a deadline item.
5012 FRACTION is what fraction of the head-warning time has passed."
5013 (if (equal wdays 0) (setq fraction 1.))
5014 (let ((faces org-agenda-deadline-faces) f)
5015 (catch 'exit
5016 (while (setq f (pop faces))
5017 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5019 (defun org-agenda-get-scheduled (&optional deadline-results)
5020 "Return the scheduled information for agenda display."
5021 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5022 'org-todo-regexp org-todo-regexp
5023 'org-complex-heading-regexp org-complex-heading-regexp
5024 'done-face 'org-agenda-done
5025 'mouse-face 'highlight
5026 'help-echo
5027 (format "mouse-2 or RET jump to org file %s"
5028 (abbreviate-file-name buffer-file-name))))
5029 (regexp org-scheduled-time-regexp)
5030 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5031 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5033 (deadline-position-alist
5034 (mapcar (lambda (a) (and (setq mm (get-text-property
5035 0 'org-hd-marker a))
5036 (cons (marker-position mm) a)))
5037 deadline-results))
5038 d2 diff pos pos1 category tags donep
5039 ee txt head pastschedp todo-state face timestr s habitp)
5040 (goto-char (point-min))
5041 (while (re-search-forward regexp nil t)
5042 (catch :skip
5043 (org-agenda-skip)
5044 (setq s (match-string 1)
5045 txt nil
5046 pos (1- (match-beginning 1))
5047 todo-state (save-match-data (org-get-todo-state))
5048 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5049 (member todo-state
5050 org-agenda-repeating-timestamp-show-all))
5051 d2 (org-time-string-to-absolute
5052 (match-string 1) d1 'past show-all)
5053 diff (- d2 d1))
5054 (setq pastschedp (and todayp (< diff 0)))
5055 ;; When to show a scheduled item in the calendar:
5056 ;; If it is on or past the date.
5057 (when (or (and (< diff 0)
5058 (< (abs diff) org-scheduled-past-days)
5059 (and todayp (not org-agenda-only-exact-dates)))
5060 (= diff 0))
5061 (save-excursion
5062 (setq donep (member todo-state org-done-keywords))
5063 (if (and donep
5064 (or org-agenda-skip-scheduled-if-done
5065 (not (= diff 0))
5066 (and (functionp 'org-is-habit-p)
5067 (org-is-habit-p))))
5068 (setq txt nil)
5069 (setq habitp (and (functionp 'org-is-habit-p)
5070 (org-is-habit-p)))
5071 (setq category (org-get-category))
5072 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5073 (setq txt org-agenda-no-heading-message)
5074 (goto-char (match-end 0))
5075 (setq pos1 (match-beginning 0))
5076 (if habitp
5077 (if (or (not org-habit-show-habits)
5078 (and (not todayp)
5079 org-habit-show-habits-only-for-today))
5080 (throw :skip nil))
5081 (if (and
5082 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5083 (and org-agenda-skip-scheduled-if-deadline-is-shown
5084 pastschedp))
5085 (setq mm (assoc pos1 deadline-position-alist)))
5086 (throw :skip nil)))
5087 (setq tags (org-get-tags-at))
5088 (setq head (buffer-substring-no-properties
5089 (point)
5090 (progn (skip-chars-forward "^\r\n") (point))))
5091 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5092 (setq timestr
5093 (concat (substring s (match-beginning 1)) " "))
5094 (setq timestr 'time))
5095 (setq txt (org-format-agenda-item
5096 (if (= diff 0)
5097 (car org-agenda-scheduled-leaders)
5098 (format (nth 1 org-agenda-scheduled-leaders)
5099 (- 1 diff)))
5100 head category tags
5101 (if (not (= diff 0)) nil timestr)
5102 nil nil habitp))))
5103 (when txt
5104 (setq face
5105 (cond
5106 ((and (not habitp) pastschedp)
5107 'org-scheduled-previously)
5108 (todayp 'org-scheduled-today)
5109 (t 'org-scheduled))
5110 habitp (and habitp (org-habit-parse-todo)))
5111 (org-add-props txt props
5112 'undone-face face
5113 'face (if donep 'org-agenda-done face)
5114 'org-marker (org-agenda-new-marker pos)
5115 'org-hd-marker (org-agenda-new-marker pos1)
5116 'type (if pastschedp "past-scheduled" "scheduled")
5117 'date (if pastschedp d2 date)
5118 'priority (if habitp
5119 (org-habit-get-priority habitp)
5120 (+ 94 (- 5 diff) (org-get-priority txt)))
5121 'org-category category
5122 'org-habit-p habitp
5123 'todo-state todo-state)
5124 (push txt ee))))))
5125 (nreverse ee)))
5127 (defun org-agenda-get-blocks ()
5128 "Return the date-range information for agenda display."
5129 (let* ((props (list 'face nil
5130 'org-not-done-regexp org-not-done-regexp
5131 'org-todo-regexp org-todo-regexp
5132 'org-complex-heading-regexp org-complex-heading-regexp
5133 'mouse-face 'highlight
5134 'help-echo
5135 (format "mouse-2 or RET jump to org file %s"
5136 (abbreviate-file-name buffer-file-name))))
5137 (regexp org-tr-regexp)
5138 (d0 (calendar-absolute-from-gregorian date))
5139 marker hdmarker ee txt d1 d2 s1 s2 category todo-state tags pos
5140 head donep)
5141 (goto-char (point-min))
5142 (while (re-search-forward regexp nil t)
5143 (catch :skip
5144 (org-agenda-skip)
5145 (setq pos (point))
5146 (let ((start-time (match-string 1))
5147 (end-time (match-string 2)))
5148 (setq s1 (match-string 1)
5149 s2 (match-string 2)
5150 d1 (time-to-days (org-time-string-to-time s1))
5151 d2 (time-to-days (org-time-string-to-time s2)))
5152 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5153 ;; Only allow days between the limits, because the normal
5154 ;; date stamps will catch the limits.
5155 (save-excursion
5156 (setq todo-state (org-get-todo-state))
5157 (setq donep (member todo-state org-done-keywords))
5158 (if (and donep org-agenda-skip-timestamp-if-done)
5159 (throw :skip t))
5160 (setq marker (org-agenda-new-marker (point)))
5161 (setq category (org-get-category))
5162 (if (not (re-search-backward "^\\*+ " nil t))
5163 (setq txt org-agenda-no-heading-message)
5164 (goto-char (match-beginning 0))
5165 (setq hdmarker (org-agenda-new-marker (point)))
5166 (setq tags (org-get-tags-at))
5167 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5168 (setq head (match-string 1))
5169 (let ((remove-re
5170 (if org-agenda-remove-timeranges-from-blocks
5171 (concat
5172 "<" (regexp-quote s1) ".*?>"
5173 "--"
5174 "<" (regexp-quote s2) ".*?>")
5175 nil)))
5176 (setq txt (org-format-agenda-item
5177 (format
5178 (nth (if (= d1 d2) 0 1)
5179 org-agenda-timerange-leaders)
5180 (1+ (- d0 d1)) (1+ (- d2 d1)))
5181 head category tags
5182 (cond ((= d1 d0)
5183 (concat "<" start-time ">"))
5184 ((= d2 d0)
5185 (concat "<" end-time ">"))
5186 (t nil))
5187 remove-re))))
5188 (org-add-props txt props
5189 'org-marker marker 'org-hd-marker hdmarker
5190 'type "block" 'date date
5191 'todo-state todo-state
5192 'priority (org-get-priority txt) 'org-category category)
5193 (push txt ee))))
5194 (goto-char pos)))
5195 ;; Sort the entries by expiration date.
5196 (nreverse ee)))
5198 ;;; Agenda presentation and sorting
5200 (defvar org-prefix-has-time nil
5201 "A flag, set by `org-compile-prefix-format'.
5202 The flag is set if the currently compiled format contains a `%t'.")
5203 (defvar org-prefix-has-tag nil
5204 "A flag, set by `org-compile-prefix-format'.
5205 The flag is set if the currently compiled format contains a `%T'.")
5206 (defvar org-prefix-has-effort nil
5207 "A flag, set by `org-compile-prefix-format'.
5208 The flag is set if the currently compiled format contains a `%e'.")
5209 (defvar org-prefix-category-length nil
5210 "Used by `org-compile-prefix-format' to remember the category field width.")
5211 (defvar org-prefix-category-max-length nil
5212 "Used by `org-compile-prefix-format' to remember the category field width.")
5214 (defun org-agenda-get-category-icon (category)
5215 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5216 (dolist (entry org-agenda-category-icon-alist)
5217 (when (org-string-match-p (car entry) category)
5218 (if (listp (cadr entry))
5219 (return (cadr entry))
5220 (return (apply 'create-image (cdr entry)))))))
5222 (defun org-format-agenda-item (extra txt &optional category tags dotime
5223 noprefix remove-re habitp)
5224 "Format TXT to be inserted into the agenda buffer.
5225 In particular, it adds the prefix and corresponding text properties. EXTRA
5226 must be a string and replaces the `%s' specifier in the prefix format.
5227 CATEGORY (string, symbol or nil) may be used to overrule the default
5228 category taken from local variable or file name. It will replace the `%c'
5229 specifier in the format. DOTIME, when non-nil, indicates that a
5230 time-of-day should be extracted from TXT for sorting of this entry, and for
5231 the `%t' specifier in the format. When DOTIME is a string, this string is
5232 searched for a time before TXT is. NOPREFIX is a flag and indicates that
5233 only the correctly processes TXT should be returned - this is used by
5234 `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
5235 Any match of REMOVE-RE will be removed from TXT."
5236 (save-match-data
5237 ;; Diary entries sometimes have extra whitespace at the beginning
5238 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5240 ;; Fix the tags part in txt
5241 (setq txt (org-agenda-fix-displayed-tags
5242 txt tags
5243 org-agenda-show-inherited-tags
5244 org-agenda-hide-tags-regexp))
5245 (let* ((category (or category
5246 (if (stringp org-category)
5247 org-category
5248 (and org-category (symbol-name org-category)))
5249 (if buffer-file-name
5250 (file-name-sans-extension
5251 (file-name-nondirectory buffer-file-name))
5252 "")))
5253 (category-icon (org-agenda-get-category-icon category))
5254 (category-icon (if category-icon
5255 (propertize " " 'display category-icon)
5256 ""))
5257 ;; time, tag, effort are needed for the eval of the prefix format
5258 (tag (if tags (nth (1- (length tags)) tags) ""))
5259 time effort neffort
5260 (ts (if dotime (concat
5261 (if (stringp dotime) dotime "")
5262 (and org-agenda-search-headline-for-time txt))))
5263 (time-of-day (and dotime (org-get-time-of-day ts)))
5264 stamp plain s0 s1 s2 rtn srp l
5265 duration thecategory)
5266 (and (org-mode-p) buffer-file-name
5267 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5268 (when (and dotime time-of-day)
5269 ;; Extract starting and ending time and move them to prefix
5270 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5271 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5272 (setq s0 (match-string 0 ts)
5273 srp (and stamp (match-end 3))
5274 s1 (match-string (if plain 1 2) ts)
5275 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5277 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5278 ;; them, we might want to remove them there to avoid duplication.
5279 ;; The user can turn this off with a variable.
5280 (if (and org-prefix-has-time
5281 org-agenda-remove-times-when-in-prefix (or stamp plain)
5282 (string-match (concat (regexp-quote s0) " *") txt)
5283 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5284 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5285 (= (match-beginning 0) 0)
5287 (setq txt (replace-match "" nil nil txt))))
5288 ;; Normalize the time(s) to 24 hour
5289 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5290 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5292 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5293 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5294 (setq s2
5295 (org-minutes-to-hh:mm-string
5296 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5298 ;; Compute the duration
5299 (when s2
5300 (setq duration (- (org-hh:mm-string-to-minutes s2)
5301 (org-hh:mm-string-to-minutes s1)))))
5303 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5304 txt)
5305 ;; Tags are in the string
5306 (if (or (eq org-agenda-remove-tags t)
5307 (and org-agenda-remove-tags
5308 org-prefix-has-tag))
5309 (setq txt (replace-match "" t t txt))
5310 (setq txt (replace-match
5311 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5312 (match-string 2 txt))
5313 t t txt))))
5314 (when (org-mode-p)
5315 (setq effort
5316 (condition-case nil
5317 (org-get-effort
5318 (or (get-text-property 0 'org-hd-marker txt)
5319 (get-text-property 0 'org-marker txt)))
5320 (error nil)))
5321 (when effort
5322 (setq neffort (org-hh:mm-string-to-minutes effort)
5323 effort (setq effort (concat "[" effort "]" )))))
5325 (when remove-re
5326 (while (string-match remove-re txt)
5327 (setq txt (replace-match "" t t txt))))
5329 ;; Create the final string
5330 (if noprefix
5331 (setq rtn txt)
5332 ;; Prepare the variables needed in the eval of the compiled format
5333 (setq time (cond (s2 (concat
5334 (org-agenda-time-of-day-to-ampm-maybe s1)
5335 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5336 (if org-agenda-timegrid-use-ampm " ")))
5337 (s1 (concat
5338 (org-agenda-time-of-day-to-ampm-maybe s1)
5339 (if org-agenda-timegrid-use-ampm
5340 "........ "
5341 "......")))
5342 (t ""))
5343 extra (or (and (not habitp) extra) "")
5344 category (if (symbolp category) (symbol-name category) category)
5345 thecategory (copy-sequence category))
5346 (if (string-match org-bracket-link-regexp category)
5347 (progn
5348 (setq l (if (match-end 3)
5349 (- (match-end 3) (match-beginning 3))
5350 (- (match-end 1) (match-beginning 1))))
5351 (when (< l (or org-prefix-category-length 0))
5352 (setq category (copy-sequence category))
5353 (org-add-props category nil
5354 'extra-space (make-string
5355 (- org-prefix-category-length l 1) ?\ ))))
5356 (if (and org-prefix-category-max-length
5357 (>= (length category) org-prefix-category-max-length))
5358 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5359 ;; Evaluate the compiled format
5360 (setq rtn (concat (eval org-prefix-format-compiled) txt)))
5362 ;; And finally add the text properties
5363 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5364 (org-add-props rtn nil
5365 'org-category (if thecategory (downcase thecategory) category)
5366 'tags (mapcar 'org-downcase-keep-props tags)
5367 'org-highest-priority org-highest-priority
5368 'org-lowest-priority org-lowest-priority
5369 'prefix-length (- (length rtn) (length txt))
5370 'time-of-day time-of-day
5371 'duration duration
5372 'effort effort
5373 'effort-minutes neffort
5374 'txt txt
5375 'time time
5376 'extra extra
5377 'dotime dotime))))
5379 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5380 "Remove tags string from TXT, and add a modified list of tags.
5381 The modified list may contain inherited tags, and tags matched by
5382 `org-agenda-hide-tags-regexp' will be removed."
5383 (when (or add-inherited hide-re)
5384 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5385 (setq txt (substring txt 0 (match-beginning 0))))
5386 (setq tags
5387 (delq nil
5388 (mapcar (lambda (tg)
5389 (if (or (and hide-re (string-match hide-re tg))
5390 (and (not add-inherited)
5391 (get-text-property 0 'inherited tg)))
5393 tg))
5394 tags)))
5395 (when tags
5396 (let ((have-i (get-text-property 0 'inherited (car tags)))
5398 (setq txt (concat txt " :"
5399 (mapconcat
5400 (lambda (x)
5401 (setq i (get-text-property 0 'inherited x))
5402 (if (and have-i (not i))
5403 (progn
5404 (setq have-i nil)
5405 (concat ":" x))
5407 tags ":")
5408 (if have-i "::" ":"))))))
5409 txt)
5411 (defun org-downcase-keep-props (s)
5412 (let ((props (text-properties-at 0 s)))
5413 (setq s (downcase s))
5414 (add-text-properties 0 (length s) props s)
5417 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5418 (defvar org-agenda-sorting-strategy-selected nil)
5420 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5421 (catch 'exit
5422 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5423 ((and todayp (member 'today (car org-agenda-time-grid))))
5424 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5425 ((member 'weekly (car org-agenda-time-grid)))
5426 (t (throw 'exit list)))
5427 (let* ((have (delq nil (mapcar
5428 (lambda (x) (get-text-property 1 'time-of-day x))
5429 list)))
5430 (string (nth 1 org-agenda-time-grid))
5431 (gridtimes (nth 2 org-agenda-time-grid))
5432 (req (car org-agenda-time-grid))
5433 (remove (member 'remove-match req))
5434 new time)
5435 (if (and (member 'require-timed req) (not have))
5436 ;; don't show empty grid
5437 (throw 'exit list))
5438 (while (setq time (pop gridtimes))
5439 (unless (and remove (member time have))
5440 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5441 (push (org-format-agenda-item
5442 nil string "" nil
5443 (concat (substring time 0 -2) ":" (substring time -2)))
5444 new)
5445 (put-text-property
5446 2 (length (car new)) 'face 'org-time-grid (car new))))
5447 (when (and todayp org-agenda-show-current-time-in-grid)
5448 (push (org-format-agenda-item
5449 nil
5450 org-agenda-current-time-string
5451 "" nil
5452 (format-time-string "%H:%M "))
5453 new)
5454 (put-text-property
5455 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5457 (if (member 'time-up org-agenda-sorting-strategy-selected)
5458 (append new list)
5459 (append list new)))))
5461 (defun org-eval (form)
5462 "Eval FORM and return result."
5463 (condition-case error
5464 (eval form)
5465 (error (format "%%![Error: %s]" error))))
5467 (defun org-compile-prefix-format (key)
5468 "Compile the prefix format into a Lisp form that can be evaluated.
5469 The resulting form is returned and stored in the variable
5470 `org-prefix-format-compiled'."
5471 (setq org-prefix-has-time nil org-prefix-has-tag nil
5472 org-prefix-category-length nil org-prefix-has-effort nil)
5473 (let ((s (cond
5474 ((stringp org-agenda-prefix-format)
5475 org-agenda-prefix-format)
5476 ((assq key org-agenda-prefix-format)
5477 (cdr (assq key org-agenda-prefix-format)))
5478 (t " %-12:c%?-12t% s")))
5479 (start 0)
5480 varform vars var e c f opt)
5481 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5482 s start)
5483 (setq var (or (cdr (assoc (match-string 4 s)
5484 '(("c" . category) ("t" . time) ("s" . extra)
5485 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5486 'eval)
5487 c (or (match-string 3 s) "")
5488 opt (match-beginning 1)
5489 start (1+ (match-beginning 0)))
5490 (if (equal var 'time) (setq org-prefix-has-time t))
5491 (if (equal var 'tag) (setq org-prefix-has-tag t))
5492 (if (equal var 'effort) (setq org-prefix-has-effort t))
5493 (setq f (concat "%" (match-string 2 s) "s"))
5494 (when (equal var 'category)
5495 (setq org-prefix-category-length
5496 (floor (abs (string-to-number (match-string 2 s)))))
5497 (setq org-prefix-category-max-length
5498 (let ((x (match-string 2 s)))
5499 (save-match-data
5500 (if (string-match "\\.[0-9]+" x)
5501 (string-to-number (substring (match-string 0 x) 1)))))))
5502 (if (eq var 'eval)
5503 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5504 (if opt
5505 (setq varform
5506 `(if (equal "" ,var)
5508 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5509 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5510 (setq s (replace-match "%s" t nil s))
5511 (push varform vars))
5512 (setq vars (nreverse vars))
5513 (setq org-prefix-format-compiled `(format ,s ,@vars))))
5515 (defun org-set-sorting-strategy (key)
5516 (if (symbolp (car org-agenda-sorting-strategy))
5517 ;; the old format
5518 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
5519 (setq org-agenda-sorting-strategy-selected
5520 (or (cdr (assq key org-agenda-sorting-strategy))
5521 (cdr (assq 'agenda org-agenda-sorting-strategy))
5522 '(time-up category-keep priority-down)))))
5524 (defun org-get-time-of-day (s &optional string mod24)
5525 "Check string S for a time of day.
5526 If found, return it as a military time number between 0 and 2400.
5527 If not found, return nil.
5528 The optional STRING argument forces conversion into a 5 character wide string
5529 HH:MM."
5530 (save-match-data
5531 (when
5532 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
5533 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
5534 (let* ((h (string-to-number (match-string 1 s)))
5535 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
5536 (ampm (if (match-end 4) (downcase (match-string 4 s))))
5537 (am-p (equal ampm "am"))
5538 (h1 (cond ((not ampm) h)
5539 ((= h 12) (if am-p 0 12))
5540 (t (+ h (if am-p 0 12)))))
5541 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
5542 (mod h1 24) h1))
5543 (t0 (+ (* 100 h2) m))
5544 (t1 (concat (if (>= h1 24) "+" " ")
5545 (if (and org-agenda-time-leading-zero
5546 (< t0 1000)) "0" "")
5547 (if (< t0 100) "0" "")
5548 (if (< t0 10) "0" "")
5549 (int-to-string t0))))
5550 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
5552 (defvar org-agenda-before-sorting-filter-function nil
5553 "Function to be applied to agenda items prior to sorting.
5554 Prior to sorting also means just before they are inserted into the agenda.
5556 To aid sorting, you may revisit the original entries and add more text
5557 properties which will later be used by the sorting functions.
5559 The function should take a string argument, an agenda line.
5560 It has access to the text properties in that line, which contain among
5561 other things, the property `org-hd-marker' that points to the entry
5562 where the line comes from. Note that not all lines going into the agenda
5563 have this property, only most.
5565 The function should return the modified string. It is probably best
5566 to ONLY change text properties.
5568 You can also use this function as a filter, by returning nil for lines
5569 you don't want to have in the agenda at all. For this application, you
5570 could bind the variable in the options section of a custom command.")
5572 (defun org-finalize-agenda-entries (list &optional nosort)
5573 "Sort and concatenate the agenda items."
5574 (setq list (mapcar 'org-agenda-highlight-todo list))
5575 (if nosort
5576 list
5577 (when org-agenda-before-sorting-filter-function
5578 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
5579 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
5581 (defun org-agenda-highlight-todo (x)
5582 (let ((org-done-keywords org-done-keywords-for-agenda)
5583 (case-fold-search nil)
5584 re pl)
5585 (if (eq x 'line)
5586 (save-excursion
5587 (beginning-of-line 1)
5588 (setq re (org-get-at-bol 'org-todo-regexp))
5589 (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
5590 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
5591 (add-text-properties (match-beginning 0) (match-end 1)
5592 (list 'face (org-get-todo-face 1)))
5593 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
5594 (delete-region (match-beginning 1) (1- (match-end 0)))
5595 (goto-char (match-beginning 1))
5596 (insert (format org-agenda-todo-keyword-format s)))))
5597 (setq re (concat (get-text-property 0 'org-todo-regexp x))
5598 pl (get-text-property 0 'prefix-length x))
5599 (when (and re
5600 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
5601 x (or pl 0)) pl))
5602 (add-text-properties
5603 (or (match-end 1) (match-end 0)) (match-end 0)
5604 (list 'face (org-get-todo-face (match-string 2 x)))
5606 (when (match-end 1)
5607 (setq x (concat (substring x 0 (match-end 1))
5608 (format org-agenda-todo-keyword-format
5609 (match-string 2 x))
5610 (org-add-props " " (text-properties-at 0 x))
5611 (substring x (match-end 3))))))
5612 x)))
5614 (defsubst org-cmp-priority (a b)
5615 "Compare the priorities of string A and B."
5616 (let ((pa (or (get-text-property 1 'priority a) 0))
5617 (pb (or (get-text-property 1 'priority b) 0)))
5618 (cond ((> pa pb) +1)
5619 ((< pa pb) -1)
5620 (t nil))))
5622 (defsubst org-cmp-effort (a b)
5623 "Compare the priorities of string A and B."
5624 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
5625 (ea (or (get-text-property 1 'effort-minutes a) def))
5626 (eb (or (get-text-property 1 'effort-minutes b) def)))
5627 (cond ((> ea eb) +1)
5628 ((< ea eb) -1)
5629 (t nil))))
5631 (defsubst org-cmp-category (a b)
5632 "Compare the string values of categories of strings A and B."
5633 (let ((ca (or (get-text-property 1 'org-category a) ""))
5634 (cb (or (get-text-property 1 'org-category b) "")))
5635 (cond ((string-lessp ca cb) -1)
5636 ((string-lessp cb ca) +1)
5637 (t nil))))
5639 (defsubst org-cmp-todo-state (a b)
5640 "Compare the todo states of strings A and B."
5641 (let* ((ma (or (get-text-property 1 'org-marker a)
5642 (get-text-property 1 'org-hd-marker a)))
5643 (mb (or (get-text-property 1 'org-marker b)
5644 (get-text-property 1 'org-hd-marker b)))
5645 (fa (and ma (marker-buffer ma)))
5646 (fb (and mb (marker-buffer mb)))
5647 (todo-kwds
5648 (or (and fa (with-current-buffer fa org-todo-keywords-1))
5649 (and fb (with-current-buffer fb org-todo-keywords-1))))
5650 (ta (or (get-text-property 1 'todo-state a) ""))
5651 (tb (or (get-text-property 1 'todo-state b) ""))
5652 (la (- (length (member ta todo-kwds))))
5653 (lb (- (length (member tb todo-kwds))))
5654 (donepa (member ta org-done-keywords-for-agenda))
5655 (donepb (member tb org-done-keywords-for-agenda)))
5656 (cond ((and donepa (not donepb)) -1)
5657 ((and (not donepa) donepb) +1)
5658 ((< la lb) -1)
5659 ((< lb la) +1)
5660 (t nil))))
5662 (defsubst org-cmp-alpha (a b)
5663 "Compare the headlines, alphabetically."
5664 (let* ((pla (get-text-property 0 'prefix-length a))
5665 (plb (get-text-property 0 'prefix-length b))
5666 (ta (and pla (substring a pla)))
5667 (tb (and plb (substring b plb))))
5668 (when pla
5669 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
5670 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
5671 (setq ta (substring ta (match-end 0))))
5672 (setq ta (downcase ta)))
5673 (when plb
5674 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
5675 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
5676 (setq tb (substring tb (match-end 0))))
5677 (setq tb (downcase tb)))
5678 (cond ((not ta) +1)
5679 ((not tb) -1)
5680 ((string-lessp ta tb) -1)
5681 ((string-lessp tb ta) +1)
5682 (t nil))))
5684 (defsubst org-cmp-tag (a b)
5685 "Compare the string values of the first tags of A and B."
5686 (let ((ta (car (last (get-text-property 1 'tags a))))
5687 (tb (car (last (get-text-property 1 'tags b)))))
5688 (cond ((not ta) +1)
5689 ((not tb) -1)
5690 ((string-lessp ta tb) -1)
5691 ((string-lessp tb ta) +1)
5692 (t nil))))
5694 (defsubst org-cmp-time (a b)
5695 "Compare the time-of-day values of strings A and B."
5696 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
5697 (ta (or (get-text-property 1 'time-of-day a) def))
5698 (tb (or (get-text-property 1 'time-of-day b) def)))
5699 (cond ((< ta tb) -1)
5700 ((< tb ta) +1)
5701 (t nil))))
5703 (defsubst org-cmp-habit-p (a b)
5704 "Compare the todo states of strings A and B."
5705 (let ((ha (get-text-property 1 'org-habit-p a))
5706 (hb (get-text-property 1 'org-habit-p b)))
5707 (cond ((and ha (not hb)) -1)
5708 ((and (not ha) hb) +1)
5709 (t nil))))
5711 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
5713 (defun org-entries-lessp (a b)
5714 "Predicate for sorting agenda entries."
5715 ;; The following variables will be used when the form is evaluated.
5716 ;; So even though the compiler complains, keep them.
5717 (let* ((ss org-agenda-sorting-strategy-selected)
5718 (time-up (and (org-em 'time-up 'time-down ss)
5719 (org-cmp-time a b)))
5720 (time-down (if time-up (- time-up) nil))
5721 (priority-up (and (org-em 'priority-up 'priority-down ss)
5722 (org-cmp-priority a b)))
5723 (priority-down (if priority-up (- priority-up) nil))
5724 (effort-up (and (org-em 'effort-up 'effort-down ss)
5725 (org-cmp-effort a b)))
5726 (effort-down (if effort-up (- effort-up) nil))
5727 (category-up (and (or (org-em 'category-up 'category-down ss)
5728 (memq 'category-keep ss))
5729 (org-cmp-category a b)))
5730 (category-down (if category-up (- category-up) nil))
5731 (category-keep (if category-up +1 nil))
5732 (tag-up (and (org-em 'tag-up 'tag-down ss)
5733 (org-cmp-tag a b)))
5734 (tag-down (if tag-up (- tag-up) nil))
5735 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
5736 (org-cmp-todo-state a b)))
5737 (todo-state-down (if todo-state-up (- todo-state-up) nil))
5738 (habit-up (and (org-em 'habit-up 'habit-down ss)
5739 (org-cmp-habit-p a b)))
5740 (habit-down (if habit-up (- habit-up) nil))
5741 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
5742 (org-cmp-alpha a b)))
5743 (alpha-down (if alpha-up (- alpha-up) nil))
5744 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
5745 user-defined-up user-defined-down)
5746 (if (and need-user-cmp org-agenda-cmp-user-defined
5747 (functionp org-agenda-cmp-user-defined))
5748 (setq user-defined-up
5749 (funcall org-agenda-cmp-user-defined a b)
5750 user-defined-down (if user-defined-up (- user-defined-up) nil)))
5751 (cdr (assoc
5752 (eval (cons 'or org-agenda-sorting-strategy-selected))
5753 '((-1 . t) (1 . nil) (nil . nil))))))
5755 ;;; Agenda restriction lock
5757 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
5758 "Overlay to mark the headline to which agenda commands are restricted.")
5759 (overlay-put org-agenda-restriction-lock-overlay
5760 'face 'org-agenda-restriction-lock)
5761 (overlay-put org-agenda-restriction-lock-overlay
5762 'help-echo "Agendas are currently limited to this subtree.")
5763 (org-detach-overlay org-agenda-restriction-lock-overlay)
5765 (defun org-agenda-set-restriction-lock (&optional type)
5766 "Set restriction lock for agenda, to current subtree or file.
5767 Restriction will be the file if TYPE is `file', or if type is the
5768 universal prefix '(4), or if the cursor is before the first headline
5769 in the file. Otherwise, restriction will be to the current subtree."
5770 (interactive "P")
5771 (and (equal type '(4)) (setq type 'file))
5772 (setq type (cond
5773 (type type)
5774 ((org-at-heading-p) 'subtree)
5775 ((condition-case nil (org-back-to-heading t) (error nil))
5776 'subtree)
5777 (t 'file)))
5778 (if (eq type 'subtree)
5779 (progn
5780 (setq org-agenda-restrict t)
5781 (setq org-agenda-overriding-restriction 'subtree)
5782 (put 'org-agenda-files 'org-restrict
5783 (list (buffer-file-name (buffer-base-buffer))))
5784 (org-back-to-heading t)
5785 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
5786 (move-marker org-agenda-restrict-begin (point))
5787 (move-marker org-agenda-restrict-end
5788 (save-excursion (org-end-of-subtree t)))
5789 (message "Locking agenda restriction to subtree"))
5790 (put 'org-agenda-files 'org-restrict
5791 (list (buffer-file-name (buffer-base-buffer))))
5792 (setq org-agenda-restrict nil)
5793 (setq org-agenda-overriding-restriction 'file)
5794 (move-marker org-agenda-restrict-begin nil)
5795 (move-marker org-agenda-restrict-end nil)
5796 (message "Locking agenda restriction to file"))
5797 (setq current-prefix-arg nil)
5798 (org-agenda-maybe-redo))
5800 (defun org-agenda-remove-restriction-lock (&optional noupdate)
5801 "Remove the agenda restriction lock."
5802 (interactive "P")
5803 (org-detach-overlay org-agenda-restriction-lock-overlay)
5804 (org-detach-overlay org-speedbar-restriction-lock-overlay)
5805 (setq org-agenda-overriding-restriction nil)
5806 (setq org-agenda-restrict nil)
5807 (put 'org-agenda-files 'org-restrict nil)
5808 (move-marker org-agenda-restrict-begin nil)
5809 (move-marker org-agenda-restrict-end nil)
5810 (setq current-prefix-arg nil)
5811 (message "Agenda restriction lock removed")
5812 (or noupdate (org-agenda-maybe-redo)))
5814 (defun org-agenda-maybe-redo ()
5815 "If there is any window showing the agenda view, update it."
5816 (let ((w (get-buffer-window org-agenda-buffer-name t))
5817 (w0 (selected-window)))
5818 (when w
5819 (select-window w)
5820 (org-agenda-redo)
5821 (select-window w0)
5822 (if org-agenda-overriding-restriction
5823 (message "Agenda view shifted to new %s restriction"
5824 org-agenda-overriding-restriction)
5825 (message "Agenda restriction lock removed")))))
5827 ;;; Agenda commands
5829 (defun org-agenda-check-type (error &rest types)
5830 "Check if agenda buffer is of allowed type.
5831 If ERROR is non-nil, throw an error, otherwise just return nil."
5832 (if (memq org-agenda-type types)
5834 (if error
5835 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
5836 nil)))
5838 (defun org-agenda-quit ()
5839 "Exit agenda by removing the window or the buffer."
5840 (interactive)
5841 (if org-agenda-columns-active
5842 (org-columns-quit)
5843 (let ((buf (current-buffer)))
5844 (if (eq org-agenda-window-setup 'other-frame)
5845 (progn
5846 (kill-buffer buf)
5847 (org-agenda-reset-markers)
5848 (org-columns-remove-overlays)
5849 (setq org-agenda-archives-mode nil)
5850 (delete-frame))
5851 (and (not (eq org-agenda-window-setup 'current-window))
5852 (not (one-window-p))
5853 (delete-window))
5854 (kill-buffer buf)
5855 (org-agenda-reset-markers)
5856 (org-columns-remove-overlays)
5857 (setq org-agenda-archives-mode nil)))
5858 ;; Maybe restore the pre-agenda window configuration.
5859 (and org-agenda-restore-windows-after-quit
5860 (not (eq org-agenda-window-setup 'other-frame))
5861 org-pre-agenda-window-conf
5862 (set-window-configuration org-pre-agenda-window-conf))))
5864 (defun org-agenda-exit ()
5865 "Exit agenda by removing the window or the buffer.
5866 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
5867 Org-mode buffers visited directly by the user will not be touched."
5868 (interactive)
5869 (org-release-buffers org-agenda-new-buffers)
5870 (setq org-agenda-new-buffers nil)
5871 (org-agenda-quit))
5873 (defun org-agenda-execute (arg)
5874 "Execute another agenda command, keeping same window.
5875 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
5876 in the agenda."
5877 (interactive "P")
5878 (let ((org-agenda-window-setup 'current-window))
5879 (org-agenda arg)))
5881 (defun org-agenda-redo ()
5882 "Rebuild Agenda.
5883 When this is the global TODO list, a prefix argument will be interpreted."
5884 (interactive)
5885 (let* ((org-agenda-keep-modes t)
5886 (filter org-agenda-filter)
5887 (preset (get 'org-agenda-filter :preset-filter))
5888 (org-agenda-filter-while-redo (or filter preset))
5889 (cols org-agenda-columns-active)
5890 (line (org-current-line))
5891 (window-line (- line (org-current-line (window-start))))
5892 (lprops (get 'org-agenda-redo-command 'org-lprops)))
5893 (put 'org-agenda-filter :preset-filter nil)
5894 (and cols (org-columns-quit))
5895 (message "Rebuilding agenda buffer...")
5896 (org-let lprops '(eval org-agenda-redo-command))
5897 (setq org-agenda-undo-list nil
5898 org-agenda-pending-undo-list nil)
5899 (message "Rebuilding agenda buffer...done")
5900 (put 'org-agenda-filter :preset-filter preset)
5901 (and (or filter preset) (org-agenda-filter-apply filter))
5902 (and cols (interactive-p) (org-agenda-columns))
5903 (org-goto-line line)
5904 (recenter window-line)))
5907 (defvar org-global-tags-completion-table nil)
5908 (defvar org-agenda-filter-form nil)
5909 (defun org-agenda-filter-by-tag (strip &optional char narrow)
5910 "Keep only those lines in the agenda buffer that have a specific tag.
5911 The tag is selected with its fast selection letter, as configured.
5912 With prefix argument STRIP, remove all lines that do have the tag.
5913 A lisp caller can specify CHAR. NARROW means that the new tag should be
5914 used to narrow the search - the interactive user can also press `-' or `+'
5915 to switch to narrowing."
5916 (interactive "P")
5917 (let* ((alist org-tag-alist-for-agenda)
5918 (tag-chars (mapconcat
5919 (lambda (x) (if (and (not (symbolp (car x)))
5920 (cdr x))
5921 (char-to-string (cdr x))
5922 ""))
5923 alist ""))
5924 (efforts (org-split-string
5925 (or (cdr (assoc (concat org-effort-property "_ALL")
5926 org-global-properties))
5927 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
5928 (effort-op org-agenda-filter-effort-default-operator)
5929 (effort-prompt "")
5930 (inhibit-read-only t)
5931 (current org-agenda-filter)
5932 maybe-reftresh a n tag)
5933 (unless char
5934 (message
5935 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
5936 (if narrow "Narrow" "Filter") tag-chars
5937 (if org-agenda-auto-exclude-function "[RET], " ""))
5938 (setq char (read-char)))
5939 (when (member char '(?+ ?-))
5940 ;; Narrowing down
5941 (cond ((equal char ?-) (setq strip t narrow t))
5942 ((equal char ?+) (setq strip nil narrow t)))
5943 (message
5944 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
5945 (setq char (read-char)))
5946 (when (member char '(?< ?> ?= ??))
5947 ;; An effort operator
5948 (setq effort-op (char-to-string char))
5949 (setq alist nil) ; to make sure it will be interpreted as effort.
5950 (unless (equal char ??)
5951 (loop for i from 0 to 9 do
5952 (setq effort-prompt
5953 (concat
5954 effort-prompt " ["
5955 (if (= i 9) "0" (int-to-string (1+ i)))
5956 "]" (nth i efforts))))
5957 (message "Effort%s: %s " effort-op effort-prompt)
5958 (setq char (read-char))
5959 (when (or (< char ?0) (> char ?9))
5960 (error "Need 1-9,0 to select effort" ))))
5961 (when (equal char ?\t)
5962 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
5963 (org-set-local 'org-global-tags-completion-table
5964 (org-global-tags-completion-table)))
5965 (let ((completion-ignore-case t))
5966 (setq tag (org-icompleting-read
5967 "Tag: " org-global-tags-completion-table))))
5968 (cond
5969 ((equal char ?\r)
5970 (org-agenda-filter-by-tag-show-all)
5971 (when org-agenda-auto-exclude-function
5972 (setq org-agenda-filter '())
5973 (dolist (tag (org-agenda-get-represented-tags))
5974 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
5975 (if modifier
5976 (push modifier org-agenda-filter))))
5977 (if (not (null org-agenda-filter))
5978 (org-agenda-filter-apply org-agenda-filter)))
5979 (setq maybe-reftresh t))
5980 ((equal char ?/)
5981 (org-agenda-filter-by-tag-show-all)
5982 (when (get 'org-agenda-filter :preset-filter)
5983 (org-agenda-filter-apply org-agenda-filter))
5984 (setq maybe-reftresh t))
5985 ((or (equal char ?\ )
5986 (setq a (rassoc char alist))
5987 (and (>= char ?0) (<= char ?9)
5988 (setq n (if (= char ?0) 9 (- char ?0 1))
5989 tag (concat effort-op (nth n efforts))
5990 a (cons tag nil)))
5991 (and (= char ??)
5992 (setq tag "?eff")
5993 a (cons tag nil))
5994 (and tag (setq a (cons tag nil))))
5995 (org-agenda-filter-by-tag-show-all)
5996 (setq tag (car a))
5997 (setq org-agenda-filter
5998 (cons (concat (if strip "-" "+") tag)
5999 (if narrow current nil)))
6000 (org-agenda-filter-apply org-agenda-filter)
6001 (setq maybe-reftresh t))
6002 (t (error "Invalid tag selection character %c" char)))
6003 (when (and maybe-reftresh
6004 (eq org-agenda-clockreport-mode 'with-filter))
6005 (org-agenda-redo))))
6007 (defun org-agenda-get-represented-tags ()
6008 "Get a list of all tags currently represented in the agenda."
6009 (let (p tags)
6010 (save-excursion
6011 (goto-char (point-min))
6012 (while (setq p (next-single-property-change (point) 'tags))
6013 (goto-char p)
6014 (mapc (lambda (x) (add-to-list 'tags x))
6015 (get-text-property (point) 'tags))))
6016 tags))
6018 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6019 "Refine the current filter. See `org-agenda-filter-by-tag."
6020 (interactive "P")
6021 (org-agenda-filter-by-tag strip char 'refine))
6023 (defun org-agenda-filter-make-matcher ()
6024 "Create the form that tests a line for the agenda filter."
6025 (let (f f1)
6026 (dolist (x (append (get 'org-agenda-filter :preset-filter)
6027 org-agenda-filter))
6028 (if (member x '("-" "+"))
6029 (setq f1 (if (equal x "-") 'tags '(not tags)))
6030 (if (string-match "[<=>?]" x)
6031 (setq f1 (org-agenda-filter-effort-form x))
6032 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6033 (if (equal (string-to-char x) ?-)
6034 (setq f1 (list 'not f1))))
6035 (push f1 f))
6036 (cons 'and (nreverse f))))
6038 (defun org-agenda-filter-effort-form (e)
6039 "Return the form to compare the effort of the current line with what E says.
6040 E looks like \"+<2:25\"."
6041 (let (op)
6042 (setq e (substring e 1))
6043 (setq op (string-to-char e) e (substring e 1))
6044 (setq op (cond ((equal op ?<) '<=)
6045 ((equal op ?>) '>=)
6046 ((equal op ??) op)
6047 (t '=)))
6048 (list 'org-agenda-compare-effort (list 'quote op)
6049 (org-hh:mm-string-to-minutes e))))
6051 (defun org-agenda-compare-effort (op value)
6052 "Compare the effort of the current line with VALUE, using OP.
6053 If the line does not have an effort defined, return nil."
6054 (let ((eff (org-get-at-bol 'effort-minutes)))
6055 (if (equal op ??)
6056 (not eff)
6057 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6058 value))))
6060 (defun org-agenda-filter-apply (filter)
6061 "Set FILTER as the new agenda filter and apply it."
6062 (let (tags)
6063 (setq org-agenda-filter filter
6064 org-agenda-filter-form (org-agenda-filter-make-matcher))
6065 (org-agenda-set-mode-name)
6066 (save-excursion
6067 (goto-char (point-min))
6068 (while (not (eobp))
6069 (if (org-get-at-bol 'org-marker)
6070 (progn
6071 (setq tags (org-get-at-bol 'tags)) ; used in eval
6072 (if (not (eval org-agenda-filter-form))
6073 (org-agenda-filter-by-tag-hide-line))
6074 (beginning-of-line 2))
6075 (beginning-of-line 2))))
6076 (if (get-char-property (point) 'invisible)
6077 (org-agenda-previous-line))))
6079 (defun org-agenda-filter-by-tag-hide-line ()
6080 (let (ov)
6081 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6082 (point-at-eol)))
6083 (overlay-put ov 'invisible t)
6084 (overlay-put ov 'type 'tags-filter)
6085 (push ov org-agenda-filter-overlays)))
6087 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6088 (setq pos (or pos (point)))
6089 (save-excursion
6090 (dolist (ov (overlays-at pos))
6091 (when (and (overlay-get ov 'invisible)
6092 (eq (overlay-get ov 'type) 'tags-filter))
6093 (goto-char pos)
6094 (if (< (overlay-start ov) (point-at-eol))
6095 (move-overlay ov (point-at-eol)
6096 (overlay-end ov)))))))
6098 (defun org-agenda-filter-by-tag-show-all ()
6099 (mapc 'delete-overlay org-agenda-filter-overlays)
6100 (setq org-agenda-filter-overlays nil)
6101 (setq org-agenda-filter nil)
6102 (setq org-agenda-filter-form nil)
6103 (org-agenda-set-mode-name))
6105 (defun org-agenda-manipulate-query-add ()
6106 "Manipulate the query by adding a search term with positive selection.
6107 Positive selection means the term must be matched for selection of an entry."
6108 (interactive)
6109 (org-agenda-manipulate-query ?\[))
6110 (defun org-agenda-manipulate-query-subtract ()
6111 "Manipulate the query by adding a search term with negative selection.
6112 Negative selection means term must not be matched for selection of an entry."
6113 (interactive)
6114 (org-agenda-manipulate-query ?\]))
6115 (defun org-agenda-manipulate-query-add-re ()
6116 "Manipulate the query by adding a search regexp with positive selection.
6117 Positive selection means the regexp must match for selection of an entry."
6118 (interactive)
6119 (org-agenda-manipulate-query ?\{))
6120 (defun org-agenda-manipulate-query-subtract-re ()
6121 "Manipulate the query by adding a search regexp with negative selection.
6122 Negative selection means regexp must not match for selection of an entry."
6123 (interactive)
6124 (org-agenda-manipulate-query ?\}))
6125 (defun org-agenda-manipulate-query (char)
6126 (cond
6127 ((memq org-agenda-type '(timeline agenda))
6128 (let ((org-agenda-include-inactive-timestamps t))
6129 (org-agenda-redo))
6130 (message "Display now includes inactive timestamps as well"))
6131 ((eq org-agenda-type 'search)
6132 (org-add-to-string
6133 'org-agenda-query-string
6134 (if org-agenda-last-search-view-search-was-boolean
6135 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6136 (?\{ . " +{}") (?\} . " -{}"))))
6137 " "))
6138 (setq org-agenda-redo-command
6139 (list 'org-search-view
6140 org-todo-only
6141 org-agenda-query-string
6142 (+ (length org-agenda-query-string)
6143 (if (member char '(?\{ ?\})) 0 1))))
6144 (set-register org-agenda-query-register org-agenda-query-string)
6145 (org-agenda-redo))
6146 (t (error "Cannot manipulate query for %s-type agenda buffers"
6147 org-agenda-type))))
6149 (defun org-add-to-string (var string)
6150 (set var (concat (symbol-value var) string)))
6152 (defun org-agenda-goto-date (date)
6153 "Jump to DATE in agenda."
6154 (interactive (list (let ((org-read-date-prefer-future
6155 (eval org-agenda-jump-prefer-future)))
6156 (org-read-date))))
6157 (org-agenda-list nil date))
6159 (defun org-agenda-goto-today ()
6160 "Go to today."
6161 (interactive)
6162 (org-agenda-check-type t 'timeline 'agenda)
6163 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6164 (cond
6165 (tdpos (goto-char tdpos))
6166 ((eq org-agenda-type 'agenda)
6167 (let* ((sd (org-agenda-compute-starting-span
6168 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6169 (org-agenda-overriding-arguments org-agenda-last-arguments))
6170 (setf (nth 1 org-agenda-overriding-arguments) sd)
6171 (org-agenda-redo)
6172 (org-agenda-find-same-or-today-or-agenda)))
6173 (t (error "Cannot find today")))))
6175 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6176 (goto-char
6177 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6178 (text-property-any (point-min) (point-max) 'org-today t)
6179 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6180 (point-min))))
6182 (defun org-agenda-later (arg)
6183 "Go forward in time by thee current span.
6184 With prefix ARG, go forward that many times the current span."
6185 (interactive "p")
6186 (org-agenda-check-type t 'agenda)
6187 (let* ((span org-agenda-current-span)
6188 (sd org-starting-day)
6189 (greg (calendar-gregorian-from-absolute sd))
6190 (cnt (org-get-at-bol 'org-day-cnt))
6191 greg2)
6192 (cond
6193 ((eq span 'day)
6194 (setq sd (+ arg sd)))
6195 ((eq span 'week)
6196 (setq sd (+ (* 7 arg) sd)))
6197 ((eq span 'month)
6198 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6199 sd (calendar-absolute-from-gregorian greg2))
6200 (setcar greg2 (1+ (car greg2))))
6201 ((eq span 'year)
6202 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6203 sd (calendar-absolute-from-gregorian greg2))
6204 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6206 (setq sd (+ (* span arg) sd))))
6207 (let ((org-agenda-overriding-arguments
6208 (list (car org-agenda-last-arguments) sd span t)))
6209 (org-agenda-redo)
6210 (org-agenda-find-same-or-today-or-agenda cnt))))
6212 (defun org-agenda-earlier (arg)
6213 "Go backward in time by the current span.
6214 With prefix ARG, go backward that many times the current span."
6215 (interactive "p")
6216 (org-agenda-later (- arg)))
6218 (defun org-agenda-view-mode-dispatch ()
6219 "Call one of the view mode commands."
6220 (interactive)
6221 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6222 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
6223 [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
6224 (let ((a (read-char-exclusive)))
6225 (case a
6226 (?\ (call-interactively 'org-agenda-reset-view))
6227 (?d (call-interactively 'org-agenda-day-view))
6228 (?w (call-interactively 'org-agenda-week-view))
6229 (?m (call-interactively 'org-agenda-month-view))
6230 (?y (call-interactively 'org-agenda-year-view))
6231 (?l (call-interactively 'org-agenda-log-mode))
6232 (?L (org-agenda-log-mode '(4)))
6233 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6234 (?a (call-interactively 'org-agenda-archives-mode))
6235 (?A (org-agenda-archives-mode 'files))
6236 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6237 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6238 (?G (call-interactively 'org-agenda-toggle-time-grid))
6239 (?D (call-interactively 'org-agenda-toggle-diary))
6240 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6241 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6242 (org-agenda-check-type t 'timeline 'agenda)
6243 (org-agenda-redo))
6244 (message "Display now includes inactive timestamps as well"))
6245 (?q (message "Abort"))
6246 (otherwise (error "Invalid key" )))))
6248 (defun org-agenda-reset-view ()
6249 "Switch to default view for agenda."
6250 (interactive)
6251 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6252 (defun org-agenda-day-view (&optional day-of-year)
6253 "Switch to daily view for agenda.
6254 With argument DAY-OF-YEAR, switch to that day of the year."
6255 (interactive "P")
6256 (org-agenda-change-time-span 'day day-of-year))
6257 (defun org-agenda-week-view (&optional iso-week)
6258 "Switch to daily view for agenda.
6259 With argument ISO-WEEK, switch to the corresponding ISO week.
6260 If ISO-WEEK has more then 2 digits, only the last two encode the
6261 week. Any digits before this encode a year. So 200712 means
6262 week 12 of year 2007. Years in the range 1938-2037 can also be
6263 written as 2-digit years."
6264 (interactive "P")
6265 (org-agenda-change-time-span 'week iso-week))
6266 (defun org-agenda-month-view (&optional month)
6267 "Switch to monthly view for agenda.
6268 With argument MONTH, switch to that month."
6269 (interactive "P")
6270 (org-agenda-change-time-span 'month month))
6271 (defun org-agenda-year-view (&optional year)
6272 "Switch to yearly view for agenda.
6273 With argument YEAR, switch to that year.
6274 If MONTH has more then 2 digits, only the last two encode the
6275 month. Any digits before this encode a year. So 200712 means
6276 December year 2007. Years in the range 1938-2037 can also be
6277 written as 2-digit years."
6278 (interactive "P")
6279 (when year
6280 (setq year (org-small-year-to-year year)))
6281 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6282 (org-agenda-change-time-span 'year year)
6283 (error "Abort")))
6285 (defun org-agenda-change-time-span (span &optional n)
6286 "Change the agenda view to SPAN.
6287 SPAN may be `day', `week', `month', `year'."
6288 (org-agenda-check-type t 'agenda)
6289 (if (and (not n) (equal org-agenda-current-span span))
6290 (error "Viewing span is already \"%s\"" span))
6291 (let* ((sd (or (org-get-at-bol 'day)
6292 org-starting-day))
6293 (sd (org-agenda-compute-starting-span sd span n))
6294 (org-agenda-overriding-arguments
6295 (list (car org-agenda-last-arguments) sd span t)))
6296 (org-agenda-redo)
6297 (org-agenda-find-same-or-today-or-agenda))
6298 (org-agenda-set-mode-name)
6299 (message "Switched to %s view" span))
6301 (defun org-agenda-compute-starting-span (sd span &optional n)
6302 "Compute starting date for agenda.
6303 SPAN may be `day', `week', `month', `year'. The return value
6304 is a cons cell with the starting date and the number of days,
6305 so that the date SD will be in that range."
6306 (let* ((greg (calendar-gregorian-from-absolute sd))
6307 (dg (nth 1 greg))
6308 (mg (car greg))
6309 (yg (nth 2 greg)))
6310 (cond
6311 ((eq span 'day)
6312 (when n
6313 (setq sd (+ (calendar-absolute-from-gregorian
6314 (list mg 1 yg))
6315 n -1))))
6316 ((eq span 'week)
6317 (let* ((nt (calendar-day-of-week
6318 (calendar-gregorian-from-absolute sd)))
6319 (d (if org-agenda-start-on-weekday
6320 (- nt org-agenda-start-on-weekday)
6323 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6324 (when n
6325 (require 'cal-iso)
6326 (when (> n 99)
6327 (setq y1 (org-small-year-to-year (/ n 100))
6328 n (mod n 100)))
6329 (setq sd
6330 (calendar-absolute-from-iso
6331 (list n 1
6332 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6333 ((eq span 'month)
6334 (let (y1)
6335 (when (and n (> n 99))
6336 (setq y1 (org-small-year-to-year (/ n 100))
6337 n (mod n 100)))
6338 (setq sd (calendar-absolute-from-gregorian
6339 (list (or n mg) 1 (or y1 yg))))))
6340 ((eq span 'year)
6341 (setq sd (calendar-absolute-from-gregorian
6342 (list 1 1 (or n yg))))))
6343 sd))
6345 (defun org-agenda-next-date-line (&optional arg)
6346 "Jump to the next line indicating a date in agenda buffer."
6347 (interactive "p")
6348 (org-agenda-check-type t 'agenda 'timeline)
6349 (beginning-of-line 1)
6350 ;; This does not work if user makes date format that starts with a blank
6351 (if (looking-at "^\\S-") (forward-char 1))
6352 (if (not (re-search-forward "^\\S-" nil t arg))
6353 (progn
6354 (backward-char 1)
6355 (error "No next date after this line in this buffer")))
6356 (goto-char (match-beginning 0)))
6358 (defun org-agenda-previous-date-line (&optional arg)
6359 "Jump to the previous line indicating a date in agenda buffer."
6360 (interactive "p")
6361 (org-agenda-check-type t 'agenda 'timeline)
6362 (beginning-of-line 1)
6363 (if (not (re-search-backward "^\\S-" nil t arg))
6364 (error "No previous date before this line in this buffer")))
6366 ;; Initialize the highlight
6367 (defvar org-hl (make-overlay 1 1))
6368 (overlay-put org-hl 'face 'highlight)
6370 (defun org-highlight (begin end &optional buffer)
6371 "Highlight a region with overlay."
6372 (move-overlay org-hl begin end (or buffer (current-buffer))))
6374 (defun org-unhighlight ()
6375 "Detach overlay INDEX."
6376 (org-detach-overlay org-hl))
6378 ;; FIXME this is currently not used.
6379 (defun org-highlight-until-next-command (beg end &optional buffer)
6380 "Move the highlight overlay to BEG/END, remove it before the next command."
6381 (org-highlight beg end buffer)
6382 (add-hook 'pre-command-hook 'org-unhighlight-once))
6383 (defun org-unhighlight-once ()
6384 "Remove the highlight from its position, and this function from the hook."
6385 (remove-hook 'pre-command-hook 'org-unhighlight-once)
6386 (org-unhighlight))
6388 (defun org-agenda-follow-mode ()
6389 "Toggle follow mode in an agenda buffer."
6390 (interactive)
6391 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
6392 (org-agenda-set-mode-name)
6393 (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
6394 (org-agenda-show))
6395 (message "Follow mode is %s"
6396 (if org-agenda-follow-mode "on" "off")))
6398 (defun org-agenda-entry-text-mode (&optional arg)
6399 "Toggle entry text mode in an agenda buffer."
6400 (interactive "P")
6401 (setq org-agenda-entry-text-mode (or (integerp arg)
6402 (not org-agenda-entry-text-mode)))
6403 (org-agenda-entry-text-hide)
6404 (and org-agenda-entry-text-mode
6405 (let ((org-agenda-entry-text-maxlines
6406 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6407 (org-agenda-entry-text-show)))
6408 (org-agenda-set-mode-name)
6409 (message "Entry text mode is %s. Maximum number of lines is %d"
6410 (if org-agenda-entry-text-mode "on" "off")
6411 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
6413 (defun org-agenda-clockreport-mode (&optional with-filter)
6414 "Toggle clocktable mode in an agenda buffer.
6415 With prefix arg WITH-FILTER, make the clocktable respect the current
6416 agenda filter."
6417 (interactive "P")
6418 (org-agenda-check-type t 'agenda)
6419 (if with-filter
6420 (setq org-agenda-clockreport-mode 'with-filter)
6421 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
6422 (org-agenda-set-mode-name)
6423 (org-agenda-redo)
6424 (message "Clocktable mode is %s"
6425 (if org-agenda-clockreport-mode "on" "off")))
6427 (defun org-agenda-log-mode (&optional special)
6428 "Toggle log mode in an agenda buffer.
6429 With argument SPECIAL, show all possible log items, not only the ones
6430 configured in `org-agenda-log-mode-items'.
6431 With a double `C-u' prefix arg, show *only* log items, nothing else."
6432 (interactive "P")
6433 (org-agenda-check-type t 'agenda 'timeline)
6434 (setq org-agenda-show-log
6435 (if (equal special '(16))
6436 'only
6437 (if special '(closed clock state)
6438 (not org-agenda-show-log))))
6439 (org-agenda-set-mode-name)
6440 (org-agenda-redo)
6441 (message "Log mode is %s"
6442 (if org-agenda-show-log "on" "off")))
6444 (defun org-agenda-archives-mode (&optional with-files)
6445 "Toggle inclusion of items in trees marked with :ARCHIVE:.
6446 When called with a prefix argument, include all archive files as well."
6447 (interactive "P")
6448 (setq org-agenda-archives-mode
6449 (if with-files t (if org-agenda-archives-mode nil 'trees)))
6450 (org-agenda-set-mode-name)
6451 (org-agenda-redo)
6452 (message
6453 "%s"
6454 (cond
6455 ((eq org-agenda-archives-mode nil)
6456 "No archives are included")
6457 ((eq org-agenda-archives-mode 'trees)
6458 (format "Trees with :%s: tag are included" org-archive-tag))
6459 ((eq org-agenda-archives-mode t)
6460 (format "Trees with :%s: tag and all active archive files are included"
6461 org-archive-tag)))))
6463 (defun org-agenda-toggle-diary ()
6464 "Toggle diary inclusion in an agenda buffer."
6465 (interactive)
6466 (org-agenda-check-type t 'agenda)
6467 (setq org-agenda-include-diary (not org-agenda-include-diary))
6468 (org-agenda-redo)
6469 (org-agenda-set-mode-name)
6470 (message "Diary inclusion turned %s"
6471 (if org-agenda-include-diary "on" "off")))
6473 (defun org-agenda-toggle-deadlines ()
6474 "Toggle inclusion of entries with a deadline in an agenda buffer."
6475 (interactive)
6476 (org-agenda-check-type t 'agenda)
6477 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
6478 (org-agenda-redo)
6479 (org-agenda-set-mode-name)
6480 (message "Deadlines inclusion turned %s"
6481 (if org-agenda-include-deadlines "on" "off")))
6483 (defun org-agenda-toggle-time-grid ()
6484 "Toggle time grid in an agenda buffer."
6485 (interactive)
6486 (org-agenda-check-type t 'agenda)
6487 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
6488 (org-agenda-redo)
6489 (org-agenda-set-mode-name)
6490 (message "Time-grid turned %s"
6491 (if org-agenda-use-time-grid "on" "off")))
6493 (defun org-agenda-set-mode-name ()
6494 "Set the mode name to indicate all the small mode settings."
6495 (setq mode-name
6496 (list "Org-Agenda"
6497 (if (get 'org-agenda-files 'org-restrict) " []" "")
6499 '(:eval (org-agenda-span-name org-agenda-current-span))
6500 (if org-agenda-follow-mode " Follow" "")
6501 (if org-agenda-entry-text-mode " ETxt" "")
6502 (if org-agenda-include-diary " Diary" "")
6503 (if org-agenda-include-deadlines " Ddl" "")
6504 (if org-agenda-use-time-grid " Grid" "")
6505 (if (and (boundp 'org-habit-show-habits)
6506 org-habit-show-habits) " Habit" "")
6507 (if (consp org-agenda-show-log) " LogAll"
6508 (if org-agenda-show-log " Log" ""))
6509 (if (or org-agenda-filter (get 'org-agenda-filter
6510 :preset-filter))
6511 (concat " {" (mapconcat
6512 'identity
6513 (append (get 'org-agenda-filter
6514 :preset-filter)
6515 org-agenda-filter) "") "}")
6517 (if org-agenda-archives-mode
6518 (if (eq org-agenda-archives-mode t)
6519 " Archives"
6520 (format " :%s:" org-archive-tag))
6522 (if org-agenda-clockreport-mode
6523 (if (eq org-agenda-clockreport-mode 'with-filter)
6524 " Clock{}" " Clock")
6525 "")))
6526 (force-mode-line-update))
6528 (defun org-agenda-post-command-hook ()
6529 (setq org-agenda-type
6530 (or (get-text-property (point) 'org-agenda-type)
6531 (get-text-property (max (point-min) (1- (point)))
6532 'org-agenda-type))))
6534 (defun org-agenda-next-line ()
6535 "Move cursor to the next line, and show if follow mode is active."
6536 (interactive)
6537 (call-interactively 'next-line)
6538 (org-agenda-do-context-action))
6540 (defun org-agenda-previous-line ()
6541 "Move cursor to the previous line, and show if follow-mode is active."
6542 (interactive)
6543 (call-interactively 'previous-line)
6544 (org-agenda-do-context-action))
6546 (defun org-agenda-do-context-action ()
6547 "Show outline path and, maybe, follow mode window."
6548 (let ((m (org-get-at-bol 'org-marker)))
6549 (if (and org-agenda-follow-mode m)
6550 (org-agenda-show))
6551 (if (and m org-agenda-show-outline-path)
6552 (org-with-point-at m
6553 (org-display-outline-path t)))))
6555 (defun org-agenda-show-priority ()
6556 "Show the priority of the current item.
6557 This priority is composed of the main priority given with the [#A] cookies,
6558 and by additional input from the age of a schedules or deadline entry."
6559 (interactive)
6560 (let* ((pri (org-get-at-bol 'priority)))
6561 (message "Priority is %d" (if pri pri -1000))))
6563 (defun org-agenda-show-tags ()
6564 "Show the tags applicable to the current item."
6565 (interactive)
6566 (let* ((tags (org-get-at-bol 'tags)))
6567 (if tags
6568 (message "Tags are :%s:"
6569 (org-no-properties (mapconcat 'identity tags ":")))
6570 (message "No tags associated with this line"))))
6572 (defun org-agenda-goto (&optional highlight)
6573 "Go to the Org-mode file which contains the item at point."
6574 (interactive)
6575 (let* ((marker (or (org-get-at-bol 'org-marker)
6576 (org-agenda-error)))
6577 (buffer (marker-buffer marker))
6578 (pos (marker-position marker)))
6579 (switch-to-buffer-other-window buffer)
6580 (widen)
6581 (push-mark)
6582 (goto-char pos)
6583 (when (org-mode-p)
6584 (org-show-context 'agenda)
6585 (save-excursion
6586 (and (outline-next-heading)
6587 (org-flag-heading nil)))) ; show the next heading
6588 (when (outline-invisible-p)
6589 (show-entry)) ; display invisible text
6590 (recenter (/ (window-height) 2))
6591 (run-hooks 'org-agenda-after-show-hook)
6592 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
6594 (defvar org-agenda-after-show-hook nil
6595 "Normal hook run after an item has been shown from the agenda.
6596 Point is in the buffer where the item originated.")
6598 (defun org-agenda-kill ()
6599 "Kill the entry or subtree belonging to the current agenda entry."
6600 (interactive)
6601 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6602 (let* ((marker (or (org-get-at-bol 'org-marker)
6603 (org-agenda-error)))
6604 (buffer (marker-buffer marker))
6605 (pos (marker-position marker))
6606 (type (org-get-at-bol 'type))
6607 dbeg dend (n 0) conf)
6608 (org-with-remote-undo buffer
6609 (with-current-buffer buffer
6610 (save-excursion
6611 (goto-char pos)
6612 (if (and (org-mode-p) (not (member type '("sexp"))))
6613 (setq dbeg (progn (org-back-to-heading t) (point))
6614 dend (org-end-of-subtree t t))
6615 (setq dbeg (point-at-bol)
6616 dend (min (point-max) (1+ (point-at-eol)))))
6617 (goto-char dbeg)
6618 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
6619 (setq conf (or (eq t org-agenda-confirm-kill)
6620 (and (numberp org-agenda-confirm-kill)
6621 (> n org-agenda-confirm-kill))))
6622 (and conf
6623 (not (y-or-n-p
6624 (format "Delete entry with %d lines in buffer \"%s\"? "
6625 n (buffer-name buffer))))
6626 (error "Abort"))
6627 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
6628 (with-current-buffer buffer (delete-region dbeg dend))
6629 (message "Agenda item and source killed"))))
6631 (defvar org-archive-default-command)
6632 (defun org-agenda-archive-default ()
6633 "Archive the entry or subtree belonging to the current agenda entry."
6634 (interactive)
6635 (require 'org-archive)
6636 (org-agenda-archive-with org-archive-default-command))
6638 (defun org-agenda-archive-default-with-confirmation ()
6639 "Archive the entry or subtree belonging to the current agenda entry."
6640 (interactive)
6641 (require 'org-archive)
6642 (org-agenda-archive-with org-archive-default-command 'confirm))
6644 (defun org-agenda-archive ()
6645 "Archive the entry or subtree belonging to the current agenda entry."
6646 (interactive)
6647 (org-agenda-archive-with 'org-archive-subtree))
6649 (defun org-agenda-archive-to-archive-sibling ()
6650 "Move the entry to the archive sibling."
6651 (interactive)
6652 (org-agenda-archive-with 'org-archive-to-archive-sibling))
6654 (defun org-agenda-archive-with (cmd &optional confirm)
6655 "Move the entry to the archive sibling."
6656 (interactive)
6657 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
6658 (let* ((marker (or (org-get-at-bol 'org-marker)
6659 (org-agenda-error)))
6660 (buffer (marker-buffer marker))
6661 (pos (marker-position marker)))
6662 (org-with-remote-undo buffer
6663 (with-current-buffer buffer
6664 (if (org-mode-p)
6665 (if (and confirm
6666 (not (y-or-n-p "Archive this subtree or entry? ")))
6667 (error "Abort")
6668 (save-excursion
6669 (goto-char pos)
6670 (org-remove-subtree-entries-from-agenda)
6671 (org-back-to-heading t)
6672 (funcall cmd)))
6673 (error "Archiving works only in Org-mode files"))))))
6675 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
6676 "Remove all lines in the agenda that correspond to a given subtree.
6677 The subtree is the one in buffer BUF, starting at BEG and ending at END.
6678 If this information is not given, the function uses the tree at point."
6679 (let ((buf (or buf (current-buffer))) m p)
6680 (save-excursion
6681 (unless (and beg end)
6682 (org-back-to-heading t)
6683 (setq beg (point))
6684 (org-end-of-subtree t)
6685 (setq end (point)))
6686 (set-buffer (get-buffer org-agenda-buffer-name))
6687 (save-excursion
6688 (goto-char (point-max))
6689 (beginning-of-line 1)
6690 (while (not (bobp))
6691 (when (and (setq m (org-get-at-bol 'org-marker))
6692 (equal buf (marker-buffer m))
6693 (setq p (marker-position m))
6694 (>= p beg)
6695 (< p end))
6696 (let ((inhibit-read-only t))
6697 (delete-region (point-at-bol) (1+ (point-at-eol)))))
6698 (beginning-of-line 0))))))
6700 (defun org-agenda-refile (&optional goto rfloc no-update)
6701 "Refile the item at point."
6702 (interactive "P")
6703 (if (equal goto '(16))
6704 (org-refile-goto-last-stored)
6705 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6706 (org-agenda-error)))
6707 (buffer (marker-buffer marker))
6708 (pos (marker-position marker))
6709 (rfloc (or rfloc
6710 (org-refile-get-location
6711 (if goto "Goto: " "Refile to: ") buffer
6712 org-refile-allow-creating-parent-nodes))))
6713 (with-current-buffer buffer
6714 (save-excursion
6715 (save-restriction
6716 (widen)
6717 (goto-char marker)
6718 (org-remove-subtree-entries-from-agenda)
6719 (org-refile goto buffer rfloc)))))
6720 (unless no-update (org-agenda-redo))))
6722 (defun org-agenda-open-link (&optional arg)
6723 "Follow the link in the current line, if any.
6724 This looks for a link in the displayed line in the agenda. It also looks
6725 at the text of the entry itself."
6726 (interactive "P")
6727 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
6728 (org-get-at-bol 'org-marker)))
6729 (buffer (and marker (marker-buffer marker)))
6730 (prefix (buffer-substring
6731 (point-at-bol)
6732 (+ (point-at-bol)
6733 (or (org-get-at-bol 'prefix-length) 0)))))
6734 (cond
6735 (buffer
6736 (with-current-buffer buffer
6737 (save-excursion
6738 (save-restriction
6739 (widen)
6740 (goto-char marker)
6741 (org-offer-links-in-entry arg prefix)))))
6742 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
6743 (save-excursion
6744 (beginning-of-line 1)
6745 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
6746 (org-open-link-from-string (match-string 1)))
6747 (t (error "No link to open here")))))
6749 (defun org-agenda-copy-local-variable (var)
6750 "Get a variable from a referenced buffer and install it here."
6751 (let ((m (org-get-at-bol 'org-marker)))
6752 (when (and m (buffer-live-p (marker-buffer m)))
6753 (org-set-local var (with-current-buffer (marker-buffer m)
6754 (symbol-value var))))))
6756 (defun org-agenda-switch-to (&optional delete-other-windows)
6757 "Go to the Org-mode file which contains the item at point."
6758 (interactive)
6759 (if (and org-return-follows-link
6760 (not (org-get-at-bol 'org-marker))
6761 (org-in-regexp org-bracket-link-regexp))
6762 (org-open-link-from-string (match-string 0))
6763 (let* ((marker (or (org-get-at-bol 'org-marker)
6764 (org-agenda-error)))
6765 (buffer (marker-buffer marker))
6766 (pos (marker-position marker)))
6767 (switch-to-buffer buffer)
6768 (and delete-other-windows (delete-other-windows))
6769 (widen)
6770 (goto-char pos)
6771 (when (org-mode-p)
6772 (org-show-context 'agenda)
6773 (save-excursion
6774 (and (outline-next-heading)
6775 (org-flag-heading nil))) ; show the next heading
6776 (when (outline-invisible-p)
6777 (show-entry)))))) ; display invisible text
6779 (defun org-agenda-goto-mouse (ev)
6780 "Go to the Org-mode file which contains the item at the mouse click."
6781 (interactive "e")
6782 (mouse-set-point ev)
6783 (org-agenda-goto))
6785 (defun org-agenda-show (&optional full-entry)
6786 "Display the Org-mode file which contains the item at point.
6787 With prefix argument FULL-ENTRY, make the entire entry visible
6788 if it was hidden in the outline."
6789 (interactive "P")
6790 (let ((win (selected-window)))
6791 (if full-entry
6792 (let ((org-show-entry-below t))
6793 (org-agenda-goto t))
6794 (org-agenda-goto t))
6795 (select-window win)))
6797 (defvar org-agenda-show-window nil)
6798 (defun org-agenda-show-and-scroll-up ()
6799 "Display the Org-mode file which contains the item at point.
6800 When called repeatedly, scroll the window that is displaying the buffer."
6801 (interactive)
6802 (let ((win (selected-window)))
6803 (if (and (window-live-p org-agenda-show-window)
6804 (eq this-command last-command))
6805 (progn
6806 (select-window org-agenda-show-window)
6807 (ignore-errors (scroll-up)))
6808 (org-agenda-goto t)
6809 (show-subtree)
6810 (setq org-agenda-show-window (selected-window)))
6811 (select-window win)))
6813 (defun org-agenda-show-scroll-down ()
6814 "Scroll down the window showing the agenda."
6815 (interactive)
6816 (let ((win (selected-window)))
6817 (when (window-live-p org-agenda-show-window)
6818 (select-window org-agenda-show-window)
6819 (ignore-errors (scroll-down))
6820 (select-window win))))
6822 (defun org-agenda-show-1 (&optional more)
6823 "Display the Org-mode file which contains the item at point.
6824 The prefix arg selects the amount of information to display:
6826 0 hide the subtree
6827 1 just show the entry according to defaults.
6828 2 show the children view
6829 3 show the subtree view
6830 4 show the entire subtree and any LOGBOOK drawers
6831 5 show the entire subtree and any drawers
6832 With prefix argument FULL-ENTRY, make the entire entry visible
6833 if it was hidden in the outline."
6834 (interactive "p")
6835 (let ((win (selected-window)))
6836 (org-agenda-goto t)
6837 (org-recenter-heading 1)
6838 (cond
6839 ((= more 0)
6840 (hide-subtree)
6841 (save-excursion
6842 (org-back-to-heading)
6843 (run-hook-with-args 'org-cycle-hook 'folded))
6844 (message "Remote: FOLDED"))
6845 ((and (interactive-p) (= more 1))
6846 (message "Remote: show with default settings"))
6847 ((= more 2)
6848 (show-entry)
6849 (show-children)
6850 (save-excursion
6851 (org-back-to-heading)
6852 (run-hook-with-args 'org-cycle-hook 'children))
6853 (message "Remote: CHILDREN"))
6854 ((= more 3)
6855 (show-subtree)
6856 (save-excursion
6857 (org-back-to-heading)
6858 (run-hook-with-args 'org-cycle-hook 'subtree))
6859 (message "Remote: SUBTREE"))
6860 ((= more 4)
6861 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
6862 (org-drawer-regexp
6863 (concat "^[ \t]*:\\("
6864 (mapconcat 'regexp-quote org-drawers "\\|")
6865 "\\):[ \t]*$")))
6866 (show-subtree)
6867 (save-excursion
6868 (org-back-to-heading)
6869 (org-cycle-hide-drawers 'subtree)))
6870 (message "Remote: SUBTREE AND LOGBOOK"))
6871 ((> more 4)
6872 (show-subtree)
6873 (message "Remote: SUBTREE AND ALL DRAWERS")))
6874 (select-window win)))
6876 (defun org-recenter-heading (n)
6877 (save-excursion
6878 (org-back-to-heading)
6879 (recenter n)))
6881 (defvar org-agenda-cycle-counter nil)
6882 (defun org-agenda-cycle-show (&optional n)
6883 "Show the current entry in another window, with default settings.
6884 Default settings are taken from `org-show-hierarchy-above' and siblings.
6885 When use repeatedly in immediate succession, the remote entry will cycle
6886 through visibility
6888 children -> subtree -> folded
6890 When called with a numeric prefix arg, that arg will be passed through to
6891 `org-agenda-show-1'. For the interpretation of that argument, see the
6892 docstring of `org-agenda-show-1'."
6893 (interactive "P")
6894 (if (integerp n)
6895 (setq org-agenda-cycle-counter n)
6896 (if (not (eq last-command this-command))
6897 (setq org-agenda-cycle-counter 1)
6898 (if (equal org-agenda-cycle-counter 0)
6899 (setq org-agenda-cycle-counter 2)
6900 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
6901 (if (> org-agenda-cycle-counter 3)
6902 (setq org-agenda-cycle-counter 0)))))
6903 (org-agenda-show-1 org-agenda-cycle-counter))
6905 (defun org-agenda-recenter (arg)
6906 "Display the Org-mode file which contains the item at point and recenter."
6907 (interactive "P")
6908 (let ((win (selected-window)))
6909 (org-agenda-goto t)
6910 (recenter arg)
6911 (select-window win)))
6913 (defun org-agenda-show-mouse (ev)
6914 "Display the Org-mode file which contains the item at the mouse click."
6915 (interactive "e")
6916 (mouse-set-point ev)
6917 (org-agenda-show))
6919 (defun org-agenda-check-no-diary ()
6920 "Check if the entry is a diary link and abort if yes."
6921 (if (org-get-at-bol 'org-agenda-diary-link)
6922 (org-agenda-error)))
6924 (defun org-agenda-error ()
6925 (error "Command not allowed in this line"))
6927 (defun org-agenda-tree-to-indirect-buffer ()
6928 "Show the subtree corresponding to the current entry in an indirect buffer.
6929 This calls the command `org-tree-to-indirect-buffer' from the original
6930 Org-mode buffer.
6931 With numerical prefix arg ARG, go up to this level and then take that tree.
6932 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
6933 use the dedicated frame)."
6934 (interactive)
6935 (org-agenda-check-no-diary)
6936 (let* ((marker (or (org-get-at-bol 'org-marker)
6937 (org-agenda-error)))
6938 (buffer (marker-buffer marker))
6939 (pos (marker-position marker)))
6940 (with-current-buffer buffer
6941 (save-excursion
6942 (goto-char pos)
6943 (call-interactively 'org-tree-to-indirect-buffer)))))
6945 (defvar org-last-heading-marker (make-marker)
6946 "Marker pointing to the headline that last changed its TODO state
6947 by a remote command from the agenda.")
6949 (defun org-agenda-todo-nextset ()
6950 "Switch TODO entry to next sequence."
6951 (interactive)
6952 (org-agenda-todo 'nextset))
6954 (defun org-agenda-todo-previousset ()
6955 "Switch TODO entry to previous sequence."
6956 (interactive)
6957 (org-agenda-todo 'previousset))
6959 (defun org-agenda-todo (&optional arg)
6960 "Cycle TODO state of line at point, also in Org-mode file.
6961 This changes the line at point, all other lines in the agenda referring to
6962 the same tree node, and the headline of the tree node in the Org-mode file."
6963 (interactive "P")
6964 (org-agenda-check-no-diary)
6965 (let* ((col (current-column))
6966 (marker (or (org-get-at-bol 'org-marker)
6967 (org-agenda-error)))
6968 (buffer (marker-buffer marker))
6969 (pos (marker-position marker))
6970 (hdmarker (org-get-at-bol 'org-hd-marker))
6971 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
6972 (inhibit-read-only t)
6973 org-agenda-headline-snapshot-before-repeat newhead just-one)
6974 (org-with-remote-undo buffer
6975 (with-current-buffer buffer
6976 (widen)
6977 (goto-char pos)
6978 (org-show-context 'agenda)
6979 (save-excursion
6980 (and (outline-next-heading)
6981 (org-flag-heading nil))) ; show the next heading
6982 (let ((current-prefix-arg arg))
6983 (call-interactively 'org-todo))
6984 (and (bolp) (forward-char 1))
6985 (setq newhead (org-get-heading))
6986 (when (and (org-bound-and-true-p
6987 org-agenda-headline-snapshot-before-repeat)
6988 (not (equal org-agenda-headline-snapshot-before-repeat
6989 newhead))
6990 todayp)
6991 (setq newhead org-agenda-headline-snapshot-before-repeat
6992 just-one t))
6993 (save-excursion
6994 (org-back-to-heading)
6995 (move-marker org-last-heading-marker (point))))
6996 (beginning-of-line 1)
6997 (save-excursion
6998 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
6999 (org-move-to-column col))))
7001 (defun org-agenda-add-note (&optional arg)
7002 "Add a time-stamped note to the entry at point."
7003 (interactive "P")
7004 (org-agenda-check-no-diary)
7005 (let* ((marker (or (org-get-at-bol 'org-marker)
7006 (org-agenda-error)))
7007 (buffer (marker-buffer marker))
7008 (pos (marker-position marker))
7009 (hdmarker (org-get-at-bol 'org-hd-marker))
7010 (inhibit-read-only t))
7011 (with-current-buffer buffer
7012 (widen)
7013 (goto-char pos)
7014 (org-show-context 'agenda)
7015 (save-excursion
7016 (and (outline-next-heading)
7017 (org-flag-heading nil))) ; show the next heading
7018 (org-add-note))))
7020 (defun org-agenda-change-all-lines (newhead hdmarker
7021 &optional fixface just-this)
7022 "Change all lines in the agenda buffer which match HDMARKER.
7023 The new content of the line will be NEWHEAD (as modified by
7024 `org-format-agenda-item'). HDMARKER is checked with
7025 `equal' against all `org-hd-marker' text properties in the file.
7026 If FIXFACE is non-nil, the face of each item is modified according to
7027 the new TODO state.
7028 If JUST-THIS is non-nil, change just the current line, not all.
7029 If FORCE-TAGS is non nil, the car of it returns the new tags."
7030 (let* ((inhibit-read-only t)
7031 (line (org-current-line))
7032 (thetags (with-current-buffer (marker-buffer hdmarker)
7033 (save-excursion (save-restriction (widen)
7034 (goto-char hdmarker)
7035 (org-get-tags-at)))))
7036 props m pl undone-face done-face finish new dotime cat tags)
7037 (save-excursion
7038 (goto-char (point-max))
7039 (beginning-of-line 1)
7040 (while (not finish)
7041 (setq finish (bobp))
7042 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7043 (or (not just-this) (= (org-current-line) line))
7044 (equal m hdmarker))
7045 (setq props (text-properties-at (point))
7046 dotime (org-get-at-bol 'dotime)
7047 cat (org-get-at-bol 'org-category)
7048 tags thetags
7049 new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
7050 pl (org-get-at-bol 'prefix-length)
7051 undone-face (org-get-at-bol 'undone-face)
7052 done-face (org-get-at-bol 'done-face))
7053 (goto-char (+ (point) pl))
7054 ;; (org-move-to-column pl) FIXME: does the above line work correctly?
7055 (cond
7056 ((equal new "")
7057 (beginning-of-line 1)
7058 (and (looking-at ".*\n?") (replace-match "")))
7059 ((looking-at ".*")
7060 (replace-match new t t)
7061 (beginning-of-line 1)
7062 (add-text-properties (point-at-bol) (point-at-eol) props)
7063 (when fixface
7064 (add-text-properties
7065 (point-at-bol) (point-at-eol)
7066 (list 'face
7067 (if org-last-todo-state-is-todo
7068 undone-face done-face))))
7069 (org-agenda-highlight-todo 'line)
7070 (beginning-of-line 1))
7071 (t (error "Line update did not work"))))
7072 (beginning-of-line 0)))
7073 (org-finalize-agenda)))
7075 (defun org-agenda-align-tags (&optional line)
7076 "Align all tags in agenda items to `org-agenda-tags-column'."
7077 (let ((inhibit-read-only t) l c)
7078 (save-excursion
7079 (goto-char (if line (point-at-bol) (point-min)))
7080 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7081 (if line (point-at-eol) nil) t)
7082 (add-text-properties
7083 (match-beginning 2) (match-end 2)
7084 (list 'face (delq nil (let ((prop (get-text-property
7085 (match-beginning 2) 'face)))
7086 (or (listp prop) (setq prop (list prop)))
7087 (if (memq 'org-tag prop)
7088 prop
7089 (cons 'org-tag prop))))))
7090 (setq l (- (match-end 2) (match-beginning 2))
7091 c (if (< org-agenda-tags-column 0)
7092 (- (abs org-agenda-tags-column) l)
7093 org-agenda-tags-column))
7094 (delete-region (match-beginning 1) (match-end 1))
7095 (goto-char (match-beginning 1))
7096 (insert (org-add-props
7097 (make-string (max 1 (- c (current-column))) ?\ )
7098 (plist-put (copy-sequence (text-properties-at (point)))
7099 'face nil))))
7100 (goto-char (point-min))
7101 (org-font-lock-add-tag-faces (point-max)))))
7103 (defun org-agenda-priority-up ()
7104 "Increase the priority of line at point, also in Org-mode file."
7105 (interactive)
7106 (org-agenda-priority 'up))
7108 (defun org-agenda-priority-down ()
7109 "Decrease the priority of line at point, also in Org-mode file."
7110 (interactive)
7111 (org-agenda-priority 'down))
7113 (defun org-agenda-priority (&optional force-direction)
7114 "Set the priority of line at point, also in Org-mode file.
7115 This changes the line at point, all other lines in the agenda referring to
7116 the same tree node, and the headline of the tree node in the Org-mode file."
7117 (interactive)
7118 (unless org-enable-priority-commands
7119 (error "Priority commands are disabled"))
7120 (org-agenda-check-no-diary)
7121 (let* ((marker (or (org-get-at-bol 'org-marker)
7122 (org-agenda-error)))
7123 (hdmarker (org-get-at-bol 'org-hd-marker))
7124 (buffer (marker-buffer hdmarker))
7125 (pos (marker-position hdmarker))
7126 (inhibit-read-only t)
7127 newhead)
7128 (org-with-remote-undo buffer
7129 (with-current-buffer buffer
7130 (widen)
7131 (goto-char pos)
7132 (org-show-context 'agenda)
7133 (save-excursion
7134 (and (outline-next-heading)
7135 (org-flag-heading nil))) ; show the next heading
7136 (funcall 'org-priority force-direction)
7137 (end-of-line 1)
7138 (setq newhead (org-get-heading)))
7139 (org-agenda-change-all-lines newhead hdmarker)
7140 (beginning-of-line 1))))
7142 ;; FIXME: should fix the tags property of the agenda line.
7143 (defun org-agenda-set-tags (&optional tag onoff)
7144 "Set tags for the current headline."
7145 (interactive)
7146 (org-agenda-check-no-diary)
7147 (if (and (org-region-active-p) (interactive-p))
7148 (call-interactively 'org-change-tag-in-region)
7149 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7150 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7151 (org-agenda-error)))
7152 (buffer (marker-buffer hdmarker))
7153 (pos (marker-position hdmarker))
7154 (inhibit-read-only t)
7155 newhead)
7156 (org-with-remote-undo buffer
7157 (with-current-buffer buffer
7158 (widen)
7159 (goto-char pos)
7160 (save-excursion
7161 (org-show-context 'agenda))
7162 (save-excursion
7163 (and (outline-next-heading)
7164 (org-flag-heading nil))) ; show the next heading
7165 (goto-char pos)
7166 (if tag
7167 (org-toggle-tag tag onoff)
7168 (call-interactively 'org-set-tags))
7169 (end-of-line 1)
7170 (setq newhead (org-get-heading)))
7171 (org-agenda-change-all-lines newhead hdmarker)
7172 (beginning-of-line 1)))))
7174 (defun org-agenda-set-property ()
7175 "Set a property for the current headline."
7176 (interactive)
7177 (org-agenda-check-no-diary)
7178 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7179 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7180 (org-agenda-error)))
7181 (buffer (marker-buffer hdmarker))
7182 (pos (marker-position hdmarker))
7183 (inhibit-read-only t)
7184 newhead)
7185 (org-with-remote-undo buffer
7186 (with-current-buffer buffer
7187 (widen)
7188 (goto-char pos)
7189 (save-excursion
7190 (org-show-context 'agenda))
7191 (save-excursion
7192 (and (outline-next-heading)
7193 (org-flag-heading nil))) ; show the next heading
7194 (goto-char pos)
7195 (call-interactively 'org-set-property)))))
7197 (defun org-agenda-set-effort ()
7198 "Set the effort property for the current headline."
7199 (interactive)
7200 (org-agenda-check-no-diary)
7201 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7202 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7203 (org-agenda-error)))
7204 (buffer (marker-buffer hdmarker))
7205 (pos (marker-position hdmarker))
7206 (inhibit-read-only t)
7207 newhead)
7208 (org-with-remote-undo buffer
7209 (with-current-buffer buffer
7210 (widen)
7211 (goto-char pos)
7212 (save-excursion
7213 (org-show-context 'agenda))
7214 (save-excursion
7215 (and (outline-next-heading)
7216 (org-flag-heading nil))) ; show the next heading
7217 (goto-char pos)
7218 (call-interactively 'org-set-effort)
7219 (end-of-line 1)))))
7221 (defun org-agenda-toggle-archive-tag ()
7222 "Toggle the archive tag for the current entry."
7223 (interactive)
7224 (org-agenda-check-no-diary)
7225 (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
7226 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7227 (org-agenda-error)))
7228 (buffer (marker-buffer hdmarker))
7229 (pos (marker-position hdmarker))
7230 (inhibit-read-only t)
7231 newhead)
7232 (org-with-remote-undo buffer
7233 (with-current-buffer buffer
7234 (widen)
7235 (goto-char pos)
7236 (org-show-context 'agenda)
7237 (save-excursion
7238 (and (outline-next-heading)
7239 (org-flag-heading nil))) ; show the next heading
7240 (call-interactively 'org-toggle-archive-tag)
7241 (end-of-line 1)
7242 (setq newhead (org-get-heading)))
7243 (org-agenda-change-all-lines newhead hdmarker)
7244 (beginning-of-line 1))))
7246 (defun org-agenda-do-date-later (arg)
7247 (interactive "P")
7248 (cond
7249 ((or (equal arg '(16))
7250 (memq last-command
7251 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7252 (setq this-command 'org-agenda-date-later-minutes)
7253 (org-agenda-date-later-minutes 1))
7254 ((or (equal arg '(4))
7255 (memq last-command
7256 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7257 (setq this-command 'org-agenda-date-later-hours)
7258 (org-agenda-date-later-hours 1))
7260 (org-agenda-date-later (prefix-numeric-value arg)))))
7262 (defun org-agenda-do-date-earlier (arg)
7263 (interactive "P")
7264 (cond
7265 ((or (equal arg '(16))
7266 (memq last-command
7267 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7268 (setq this-command 'org-agenda-date-earlier-minutes)
7269 (org-agenda-date-earlier-minutes 1))
7270 ((or (equal arg '(4))
7271 (memq last-command
7272 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7273 (setq this-command 'org-agenda-date-earlier-hours)
7274 (org-agenda-date-earlier-hours 1))
7276 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7278 (defun org-agenda-date-later (arg &optional what)
7279 "Change the date of this item to ARG day(s) later."
7280 (interactive "p")
7281 (org-agenda-check-type t 'agenda 'timeline)
7282 (org-agenda-check-no-diary)
7283 (let* ((marker (or (org-get-at-bol 'org-marker)
7284 (org-agenda-error)))
7285 (buffer (marker-buffer marker))
7286 (pos (marker-position marker)))
7287 (org-with-remote-undo buffer
7288 (with-current-buffer buffer
7289 (widen)
7290 (goto-char pos)
7291 (if (not (org-at-timestamp-p))
7292 (error "Cannot find time stamp"))
7293 (org-timestamp-change arg (or what 'day)))
7294 (org-agenda-show-new-time marker org-last-changed-timestamp))
7295 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7297 (defun org-agenda-date-earlier (arg &optional what)
7298 "Change the date of this item to ARG day(s) earlier."
7299 (interactive "p")
7300 (org-agenda-date-later (- arg) what))
7302 (defun org-agenda-date-later-minutes (arg)
7303 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7304 (interactive "p")
7305 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7306 (org-agenda-date-later arg 'minute))
7308 (defun org-agenda-date-earlier-minutes (arg)
7309 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7310 (interactive "p")
7311 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7312 (org-agenda-date-earlier arg 'minute))
7314 (defun org-agenda-date-later-hours (arg)
7315 "Change the time of this item, in hour steps."
7316 (interactive "p")
7317 (org-agenda-date-later arg 'hour))
7319 (defun org-agenda-date-earlier-hours (arg)
7320 "Change the time of this item, in hour steps."
7321 (interactive "p")
7322 (org-agenda-date-earlier arg 'hour))
7324 (defun org-agenda-show-new-time (marker stamp &optional prefix)
7325 "Show new date stamp via text properties."
7326 ;; We use text properties to make this undoable
7327 (let ((inhibit-read-only t)
7328 (buffer-invisibility-spec))
7329 (setq stamp (concat " " prefix " => " stamp))
7330 (save-excursion
7331 (goto-char (point-max))
7332 (while (not (bobp))
7333 (when (equal marker (org-get-at-bol 'org-marker))
7334 (org-move-to-column (- (window-width) (length stamp)) t)
7335 (org-agenda-fix-tags-filter-overlays-at (point))
7336 (if (featurep 'xemacs)
7337 ;; Use `duplicable' property to trigger undo recording
7338 (let ((ex (make-extent nil nil))
7339 (gl (make-glyph stamp)))
7340 (set-glyph-face gl 'secondary-selection)
7341 (set-extent-properties
7342 ex (list 'invisible t 'end-glyph gl 'duplicable t))
7343 (insert-extent ex (1- (point)) (point-at-eol)))
7344 (add-text-properties
7345 (1- (point)) (point-at-eol)
7346 (list 'display (org-add-props stamp nil
7347 'face 'secondary-selection))))
7348 (beginning-of-line 1))
7349 (beginning-of-line 0)))))
7351 (defun org-agenda-date-prompt (arg)
7352 "Change the date of this item. Date is prompted for, with default today.
7353 The prefix ARG is passed to the `org-time-stamp' command and can therefore
7354 be used to request time specification in the time stamp."
7355 (interactive "P")
7356 (org-agenda-check-type t 'agenda 'timeline)
7357 (org-agenda-check-no-diary)
7358 (let* ((marker (or (org-get-at-bol 'org-marker)
7359 (org-agenda-error)))
7360 (buffer (marker-buffer marker))
7361 (pos (marker-position marker)))
7362 (org-with-remote-undo buffer
7363 (with-current-buffer buffer
7364 (widen)
7365 (goto-char pos)
7366 (if (not (org-at-timestamp-p t))
7367 (error "Cannot find time stamp"))
7368 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
7369 (org-agenda-show-new-time marker org-last-changed-timestamp))
7370 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7372 (defun org-agenda-schedule (arg &optional time)
7373 "Schedule the item at point.
7374 Arg is passed through to `org-schedule'."
7375 (interactive "P")
7376 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7377 (org-agenda-check-no-diary)
7378 (let* ((marker (or (org-get-at-bol 'org-marker)
7379 (org-agenda-error)))
7380 (type (marker-insertion-type marker))
7381 (buffer (marker-buffer marker))
7382 (pos (marker-position marker))
7383 (org-insert-labeled-timestamps-at-point nil)
7385 (set-marker-insertion-type marker t)
7386 (org-with-remote-undo buffer
7387 (with-current-buffer buffer
7388 (widen)
7389 (goto-char pos)
7390 (setq ts (org-schedule arg time)))
7391 (org-agenda-show-new-time marker ts "S"))
7392 (message "Item scheduled for %s" ts)))
7394 (defun org-agenda-deadline (arg &optional time)
7395 "Schedule the item at point.
7396 Arg is passed through to `org-deadline'."
7397 (interactive "P")
7398 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
7399 (org-agenda-check-no-diary)
7400 (let* ((marker (or (org-get-at-bol 'org-marker)
7401 (org-agenda-error)))
7402 (buffer (marker-buffer marker))
7403 (pos (marker-position marker))
7404 (org-insert-labeled-timestamps-at-point nil)
7406 (org-with-remote-undo buffer
7407 (with-current-buffer buffer
7408 (widen)
7409 (goto-char pos)
7410 (setq ts (org-deadline arg time)))
7411 (org-agenda-show-new-time marker ts "D"))
7412 (message "Deadline for this item set to %s" ts)))
7414 (defun org-agenda-action ()
7415 "Select entry for agenda action, or execute an agenda action.
7416 This command prompts for another letter. Valid inputs are:
7418 m Mark the entry at point for an agenda action
7419 s Schedule the marked entry to the date at the cursor
7420 d Set the deadline of the marked entry to the date at the cursor
7421 r Call `org-remember' with cursor date as the default date
7422 c Call `org-capture' with cursor date as the default date
7423 SPC Show marked entry in other window
7424 TAB Visit marked entry in other window
7426 The cursor may be at a date in the calendar, or in the Org agenda."
7427 (interactive)
7428 (let (ans)
7429 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
7430 (setq ans (read-char-exclusive))
7431 (cond
7432 ((equal ans ?m)
7433 ;; Mark this entry
7434 (if (eq major-mode 'org-agenda-mode)
7435 (let ((m (or (org-get-at-bol 'org-hd-marker)
7436 (org-get-at-bol 'org-marker))))
7437 (if m
7438 (progn
7439 (move-marker org-agenda-action-marker
7440 (marker-position m) (marker-buffer m))
7441 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
7442 (error "Don't know which entry to mark")))
7443 (error "This command works only in the agenda")))
7444 ((equal ans ?s)
7445 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
7446 ((equal ans ?d)
7447 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
7448 ((equal ans ?r)
7449 (org-agenda-do-action '(org-remember) t))
7450 ((equal ans ?c)
7451 (org-agenda-do-action '(org-capture) t))
7452 ((equal ans ?\ )
7453 (let ((cw (selected-window)))
7454 (org-switch-to-buffer-other-window
7455 (marker-buffer org-agenda-action-marker))
7456 (goto-char org-agenda-action-marker)
7457 (org-show-context 'agenda)
7458 (select-window cw)))
7459 ((equal ans ?\C-i)
7460 (org-switch-to-buffer-other-window
7461 (marker-buffer org-agenda-action-marker))
7462 (goto-char org-agenda-action-marker)
7463 (org-show-context 'agenda))
7464 (t (error "Invalid agenda action %c" ans)))))
7466 (defun org-agenda-do-action (form &optional current-buffer)
7467 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
7468 (let ((org-overriding-default-time (org-get-cursor-date)))
7469 (if current-buffer
7470 (eval form)
7471 (if (not (marker-buffer org-agenda-action-marker))
7472 (error "No entry has been selected for agenda action")
7473 (with-current-buffer (marker-buffer org-agenda-action-marker)
7474 (save-excursion
7475 (save-restriction
7476 (widen)
7477 (goto-char org-agenda-action-marker)
7478 (eval form))))))))
7480 (defun org-agenda-clock-in (&optional arg)
7481 "Start the clock on the currently selected item."
7482 (interactive "P")
7483 (org-agenda-check-no-diary)
7484 (if (equal arg '(4))
7485 (org-clock-in arg)
7486 (let* ((marker (or (org-get-at-bol 'org-marker)
7487 (org-agenda-error)))
7488 (hdmarker (or (org-get-at-bol 'org-hd-marker)
7489 marker))
7490 (pos (marker-position marker))
7491 newhead)
7492 (org-with-remote-undo (marker-buffer marker)
7493 (with-current-buffer (marker-buffer marker)
7494 (widen)
7495 (goto-char pos)
7496 (org-show-context 'agenda)
7497 (org-show-entry)
7498 (org-cycle-hide-drawers 'children)
7499 (org-clock-in arg)
7500 (setq newhead (org-get-heading)))
7501 (org-agenda-change-all-lines newhead hdmarker)))))
7503 (defun org-agenda-clock-out ()
7504 "Stop the currently running clock."
7505 (interactive)
7506 (unless (marker-buffer org-clock-marker)
7507 (error "No running clock"))
7508 (let ((marker (make-marker)) newhead)
7509 (org-with-remote-undo (marker-buffer org-clock-marker)
7510 (with-current-buffer (marker-buffer org-clock-marker)
7511 (save-excursion
7512 (save-restriction
7513 (widen)
7514 (goto-char org-clock-marker)
7515 (org-back-to-heading t)
7516 (move-marker marker (point))
7517 (org-clock-out)
7518 (setq newhead (org-get-heading))))))
7519 (org-agenda-change-all-lines newhead marker)
7520 (move-marker marker nil)))
7522 (defun org-agenda-clock-cancel (&optional arg)
7523 "Cancel the currently running clock."
7524 (interactive "P")
7525 (unless (marker-buffer org-clock-marker)
7526 (error "No running clock"))
7527 (org-with-remote-undo (marker-buffer org-clock-marker)
7528 (org-clock-cancel)))
7530 (defun org-agenda-clock-goto ()
7531 "Jump to the currently clocked in task within the agenda.
7532 If the currently clocked in task is not listed in the agenda
7533 buffer, display it in another window."
7534 (interactive)
7535 (let (pos)
7536 (mapc (lambda (o)
7537 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
7538 (setq pos (overlay-start o))))
7539 (overlays-in (point-min) (point-max)))
7540 (cond (pos (goto-char pos))
7541 ;; If the currently clocked entry is not in the agenda
7542 ;; buffer, we visit it in another window:
7543 (org-clock-current-task
7544 (org-switch-to-buffer-other-window (org-clock-goto)))
7545 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
7547 (defun org-agenda-diary-entry-in-org-file ()
7548 "Make a diary entry in the file `org-agenda-diary-file'."
7549 (let (d1 d2 char (text "") dp1 dp2)
7550 (if (equal (buffer-name) "*Calendar*")
7551 (setq d1 (calendar-cursor-to-date t)
7552 d2 (car calendar-mark-ring))
7553 (setq dp1 (get-text-property (point-at-bol) 'day))
7554 (unless dp1 (error "No date defined in current line"))
7555 (setq d1 (calendar-gregorian-from-absolute dp1)
7556 d2 (and (ignore-errors (mark))
7557 (save-excursion
7558 (goto-char (mark))
7559 (setq dp2 (get-text-property (point-at-bol) 'day)))
7560 (calendar-gregorian-from-absolute dp2))))
7561 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
7562 (setq char (read-char-exclusive))
7563 (cond
7564 ((equal char ?d)
7565 (setq text (read-string "Day entry: "))
7566 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
7567 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7568 ((equal char ?a)
7569 (setq d1 (list (car d1) (nth 1 d1)
7570 (read-number (format "Reference year [%d]: " (nth 2 d1))
7571 (nth 2 d1))))
7572 (setq text (read-string "Anniversary (use %d to show years): "))
7573 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
7574 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7575 ((equal char ?b)
7576 (setq text (read-string "Block entry: "))
7577 (unless (and d1 d2 (not (equal d1 d2)))
7578 (error "No block of days selected"))
7579 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
7580 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
7581 ((equal char ?j)
7582 (org-switch-to-buffer-other-window
7583 (find-file-noselect org-agenda-diary-file))
7584 (require 'org-datetree)
7585 (org-datetree-find-date-create d1)
7586 (org-reveal t))
7587 (t (error "Invalid selection character `%c'" char)))))
7589 (defcustom org-agenda-insert-diary-strategy 'date-tree
7590 "Where in `org-agenda-diary-file' should new entries be added?
7591 Valid values:
7593 date-tree in the date tree, as child of the date
7594 top-level as top-level entries at the end of the file."
7595 :group 'org-agenda
7596 :type '(choice
7597 (const :tag "in a date tree" date-tree)
7598 (const :tag "as top level at end of file" top-level)))
7600 (defcustom org-agenda-insert-diary-extract-time nil
7601 "Non-nil means extract any time specification from the diary entry."
7602 :group 'org-agenda
7603 :type 'boolean)
7605 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
7606 "Add a diary entry with TYPE to `org-agenda-diary-file'.
7607 If TEXT is not empty, it will become the headline of the new entry, and
7608 the resulting entry will not be shown. When TEXT is empty, switch to
7609 `org-agenda-diary-file' and let the user finish the entry there."
7610 (let ((cw (current-window-configuration)))
7611 (org-switch-to-buffer-other-window
7612 (find-file-noselect org-agenda-diary-file))
7613 (widen)
7614 (goto-char (point-min))
7615 (cond
7616 ((eq type 'anniversary)
7617 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
7618 (progn
7619 (or (org-on-heading-p t)
7620 (progn
7621 (outline-next-heading)
7622 (insert "* Anniversaries\n\n")
7623 (beginning-of-line -1)))))
7624 (outline-next-heading)
7625 (org-back-over-empty-lines)
7626 (backward-char 1)
7627 (insert "\n")
7628 (require 'diary-lib)
7629 (let ((calendar-date-display-form
7630 (if (if (boundp 'calendar-date-style)
7631 (eq calendar-date-style 'european)
7632 (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
7633 (org-bound-and-true-p european-calendar-style))) ; Emacs 22
7634 '(day " " month " " year)
7635 '(month " " day " " year))))
7637 (insert (format "%%%%(diary-anniversary %s) %s"
7638 (calendar-date-string d1 nil t) text))))
7639 ((eq type 'day)
7640 (let ((org-prefix-has-time t)
7641 (org-agenda-time-leading-zero t)
7642 fmt time time2)
7643 (if org-agenda-insert-diary-extract-time
7644 ;; Use org-format-agenda-item to parse text for a time-range and
7645 ;; remove it. FIXME: This is a hack, we should refactor
7646 ;; that function to make time extraction available separately
7647 (setq fmt (org-format-agenda-item nil text nil nil t)
7648 time (get-text-property 0 'time fmt)
7649 time2 (if (> (length time) 0)
7650 ;; split-string removes trailing ...... if
7651 ;; no end time given. First space
7652 ;; separates time from date.
7653 (concat " " (car (split-string time "\\.")))
7654 nil)
7655 text (get-text-property 0 'txt fmt)))
7656 (if (eq org-agenda-insert-diary-strategy 'top-level)
7657 (org-agenda-insert-diary-as-top-level text)
7658 (require 'org-datetree)
7659 (org-datetree-find-date-create d1)
7660 (org-agenda-insert-diary-make-new-entry text))
7661 (org-insert-time-stamp (org-time-from-absolute
7662 (calendar-absolute-from-gregorian d1))
7663 nil nil nil nil time2))
7664 (end-of-line 0))
7665 ((eq type 'block)
7666 (if (> (calendar-absolute-from-gregorian d1)
7667 (calendar-absolute-from-gregorian d2))
7668 (setq d1 (prog1 d2 (setq d2 d1))))
7669 (if (eq org-agenda-insert-diary-strategy 'top-level)
7670 (org-agenda-insert-diary-as-top-level text)
7671 (require 'org-datetree)
7672 (org-datetree-find-date-create d1)
7673 (org-agenda-insert-diary-make-new-entry text))
7674 (org-insert-time-stamp (org-time-from-absolute
7675 (calendar-absolute-from-gregorian d1)))
7676 (insert "--")
7677 (org-insert-time-stamp (org-time-from-absolute
7678 (calendar-absolute-from-gregorian d2)))
7679 (end-of-line 0)))
7680 (if (string-match "\\S-" text)
7681 (progn
7682 (set-window-configuration cw)
7683 (message "%s entry added to %s"
7684 (capitalize (symbol-name type))
7685 (abbreviate-file-name org-agenda-diary-file)))
7686 (org-reveal t)
7687 (message "Please finish entry here"))))
7689 (defun org-agenda-insert-diary-as-top-level (text)
7690 "Make new entry as a top-level entry at the end of the file.
7691 Add TEXT as headline, and position the cursor in the second line so that
7692 a timestamp can be added there."
7693 (widen)
7694 (goto-char (point-max))
7695 (or (bolp) (insert "\n"))
7696 (insert "* " text "\n")
7697 (if org-adapt-indentation (org-indent-to-column 2)))
7699 (defun org-agenda-insert-diary-make-new-entry (text)
7700 "Make new entry as last child of current entry.
7701 Add TEXT as headline, and position the cursor in the second line so that
7702 a timestamp can be added there."
7703 (let ((org-show-following-heading t)
7704 (org-show-siblings t)
7705 (org-show-hierarchy-above t)
7706 (org-show-entry-below t)
7707 col)
7708 (outline-next-heading)
7709 (org-back-over-empty-lines)
7710 (or (looking-at "[ \t]*$")
7711 (progn (insert "\n") (backward-char 1)))
7712 (org-insert-heading nil t)
7713 (org-do-demote)
7714 (setq col (current-column))
7715 (insert text "\n")
7716 (if org-adapt-indentation (org-indent-to-column col))
7717 (let ((org-show-following-heading t)
7718 (org-show-siblings t)
7719 (org-show-hierarchy-above t)
7720 (org-show-entry-below t))
7721 (org-show-context))))
7723 (defun org-agenda-diary-entry ()
7724 "Make a diary entry, like the `i' command from the calendar.
7725 All the standard commands work: block, weekly etc.
7726 When `org-agenda-diary-file' points to a file,
7727 `org-agenda-diary-entry-in-org-file' is called instead to create
7728 entries in that Org-mode file."
7729 (interactive)
7730 (org-agenda-check-type t 'agenda 'timeline)
7731 (if (not (eq org-agenda-diary-file 'diary-file))
7732 (org-agenda-diary-entry-in-org-file)
7733 (require 'diary-lib)
7734 (let* ((char (progn
7735 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
7736 (read-char-exclusive)))
7737 (cmd (cdr (assoc char
7738 '((?d . insert-diary-entry)
7739 (?w . insert-weekly-diary-entry)
7740 (?m . insert-monthly-diary-entry)
7741 (?y . insert-yearly-diary-entry)
7742 (?a . insert-anniversary-diary-entry)
7743 (?b . insert-block-diary-entry)
7744 (?c . insert-cyclic-diary-entry)))))
7745 (oldf (symbol-function 'calendar-cursor-to-date))
7746 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
7747 (point (point))
7748 (mark (or (mark t) (point))))
7749 (unless cmd
7750 (error "No command associated with <%c>" char))
7751 (unless (and (get-text-property point 'day)
7752 (or (not (equal ?b char))
7753 (get-text-property mark 'day)))
7754 (error "Don't know which date to use for diary entry"))
7755 ;; We implement this by hacking the `calendar-cursor-to-date' function
7756 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
7757 (let ((calendar-mark-ring
7758 (list (calendar-gregorian-from-absolute
7759 (or (get-text-property mark 'day)
7760 (get-text-property point 'day))))))
7761 (unwind-protect
7762 (progn
7763 (fset 'calendar-cursor-to-date
7764 (lambda (&optional error dummy)
7765 (calendar-gregorian-from-absolute
7766 (get-text-property point 'day))))
7767 (call-interactively cmd))
7768 (fset 'calendar-cursor-to-date oldf))))))
7770 (defun org-agenda-execute-calendar-command (cmd)
7771 "Execute a calendar command from the agenda, with the date associated to
7772 the cursor position."
7773 (org-agenda-check-type t 'agenda 'timeline)
7774 (require 'diary-lib)
7775 (unless (get-text-property (point) 'day)
7776 (error "Don't know which date to use for calendar command"))
7777 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
7778 (point (point))
7779 (date (calendar-gregorian-from-absolute
7780 (get-text-property point 'day)))
7781 ;; the following 2 vars are needed in the calendar
7782 (displayed-month (car date))
7783 (displayed-year (nth 2 date)))
7784 (unwind-protect
7785 (progn
7786 (fset 'calendar-cursor-to-date
7787 (lambda (&optional error dummy)
7788 (calendar-gregorian-from-absolute
7789 (get-text-property point 'day))))
7790 (call-interactively cmd))
7791 (fset 'calendar-cursor-to-date oldf))))
7793 (defun org-agenda-phases-of-moon ()
7794 "Display the phases of the moon for the 3 months around the cursor date."
7795 (interactive)
7796 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
7798 (defun org-agenda-holidays ()
7799 "Display the holidays for the 3 months around the cursor date."
7800 (interactive)
7801 (org-agenda-execute-calendar-command 'list-calendar-holidays))
7803 (defvar calendar-longitude)
7804 (defvar calendar-latitude)
7805 (defvar calendar-location-name)
7807 (defun org-agenda-sunrise-sunset (arg)
7808 "Display sunrise and sunset for the cursor date.
7809 Latitude and longitude can be specified with the variables
7810 `calendar-latitude' and `calendar-longitude'. When called with prefix
7811 argument, latitude and longitude will be prompted for."
7812 (interactive "P")
7813 (require 'solar)
7814 (let ((calendar-longitude (if arg nil calendar-longitude))
7815 (calendar-latitude (if arg nil calendar-latitude))
7816 (calendar-location-name
7817 (if arg "the given coordinates" calendar-location-name)))
7818 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
7820 (defun org-agenda-goto-calendar ()
7821 "Open the Emacs calendar with the date at the cursor."
7822 (interactive)
7823 (org-agenda-check-type t 'agenda 'timeline)
7824 (let* ((day (or (get-text-property (point) 'day)
7825 (error "Don't know which date to open in calendar")))
7826 (date (calendar-gregorian-from-absolute day))
7827 (calendar-move-hook nil)
7828 (calendar-view-holidays-initially-flag nil)
7829 (calendar-view-diary-initially-flag nil))
7830 (calendar)
7831 (calendar-goto-date date)))
7833 ;;;###autoload
7834 (defun org-calendar-goto-agenda ()
7835 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
7836 This is a command that has to be installed in `calendar-mode-map'."
7837 (interactive)
7838 (org-agenda-list nil (calendar-absolute-from-gregorian
7839 (calendar-cursor-to-date))
7840 nil))
7842 (defun org-agenda-convert-date ()
7843 (interactive)
7844 (org-agenda-check-type t 'agenda 'timeline)
7845 (let ((day (get-text-property (point) 'day))
7846 date s)
7847 (unless day
7848 (error "Don't know which date to convert"))
7849 (setq date (calendar-gregorian-from-absolute day))
7850 (setq s (concat
7851 "Gregorian: " (calendar-date-string date) "\n"
7852 "ISO: " (calendar-iso-date-string date) "\n"
7853 "Day of Yr: " (calendar-day-of-year-string date) "\n"
7854 "Julian: " (calendar-julian-date-string date) "\n"
7855 "Astron. JD: " (calendar-astro-date-string date)
7856 " (Julian date number at noon UTC)\n"
7857 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
7858 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
7859 "French: " (calendar-french-date-string date) "\n"
7860 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
7861 "Mayan: " (calendar-mayan-date-string date) "\n"
7862 "Coptic: " (calendar-coptic-date-string date) "\n"
7863 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
7864 "Persian: " (calendar-persian-date-string date) "\n"
7865 "Chinese: " (calendar-chinese-date-string date) "\n"))
7866 (with-output-to-temp-buffer "*Dates*"
7867 (princ s))
7868 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
7870 ;;; Bulk commands
7872 (defvar org-agenda-bulk-marked-entries nil
7873 "List of markers that refer to marked entries in the agenda.")
7875 (defun org-agenda-bulk-marked-p ()
7876 (eq (get-char-property (point-at-bol) 'type)
7877 'org-marked-entry-overlay))
7879 (defun org-agenda-bulk-mark (&optional arg)
7880 "Mark the entry at point for future bulk action."
7881 (interactive "p")
7882 (dotimes (i (max arg 1))
7883 (unless (org-get-at-bol 'org-agenda-diary-link)
7884 (let* ((m (org-get-at-bol 'org-hd-marker))
7886 (unless (org-agenda-bulk-marked-p)
7887 (unless m (error "Nothing to mark at point"))
7888 (push m org-agenda-bulk-marked-entries)
7889 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
7890 (org-overlay-display ov "> "
7891 (org-get-todo-face "TODO")
7892 'evaporate)
7893 (overlay-put ov 'type 'org-marked-entry-overlay))
7894 (beginning-of-line 2)
7895 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7896 (beginning-of-line 2))
7897 (message "%d entries marked for bulk action"
7898 (length org-agenda-bulk-marked-entries))))))
7900 (defun org-agenda-bulk-mark-regexp (regexp)
7901 "Mark entries match REGEXP."
7902 (interactive "sMark entries matching regexp: ")
7903 (let (entries-marked)
7904 (save-excursion
7905 (goto-char (point-min))
7906 (goto-char (next-single-property-change (point) 'txt))
7907 (while (re-search-forward regexp nil t)
7908 (when (string-match regexp (get-text-property (point) 'txt))
7909 (setq entries-marked (+ entries-marked 1))
7910 (call-interactively 'org-agenda-bulk-mark))))
7911 (if (not entries-marked)
7912 (message "No entry matching this regexp."))))
7914 (defun org-agenda-bulk-unmark ()
7915 "Unmark the entry at point for future bulk action."
7916 (interactive)
7917 (when (org-agenda-bulk-marked-p)
7918 (org-agenda-bulk-remove-overlays
7919 (point-at-bol) (+ 2 (point-at-bol)))
7920 (setq org-agenda-bulk-marked-entries
7921 (delete (org-get-at-bol 'org-hd-marker)
7922 org-agenda-bulk-marked-entries)))
7923 (beginning-of-line 2)
7924 (while (and (get-char-property (point) 'invisible) (not (eobp)))
7925 (beginning-of-line 2))
7926 (message "%d entries marked for bulk action"
7927 (length org-agenda-bulk-marked-entries)))
7929 (defun org-agenda-bulk-toggle ()
7930 "Toggle marking the entry at point for bulk action."
7931 (interactive)
7932 (if (org-agenda-bulk-marked-p)
7933 (org-agenda-bulk-unmark)
7934 (org-agenda-bulk-mark)))
7936 (defun org-agenda-bulk-remove-overlays (&optional beg end)
7937 "Remove the mark overlays between BEG and END in the agenda buffer.
7938 BEG and END default to the buffer limits.
7940 This only removes the overlays, it does not remove the markers
7941 from the list in `org-agenda-bulk-marked-entries'."
7942 (interactive)
7943 (mapc (lambda (ov)
7944 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
7945 (delete-overlay ov)))
7946 (overlays-in (or beg (point-min)) (or end (point-max)))))
7948 (defun org-agenda-bulk-remove-all-marks ()
7949 "Remove all marks in the agenda buffer.
7950 This will remove the markers, and the overlays."
7951 (interactive)
7952 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
7953 (setq org-agenda-bulk-marked-entries nil)
7954 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
7956 (defun org-agenda-bulk-action (&optional arg)
7957 "Execute an remote-editing action on all marked entries.
7958 The prefix arg is passed through to the command if possible."
7959 (interactive "P")
7960 (unless org-agenda-bulk-marked-entries
7961 (error "No entries are marked"))
7962 (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
7963 (let* ((action (read-char-exclusive))
7964 (org-log-refile (if org-log-refile 'time nil))
7965 (entries (reverse org-agenda-bulk-marked-entries))
7966 redo-at-end
7967 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
7968 (cond
7969 ((equal action ?$)
7970 (setq cmd '(org-agenda-archive)))
7972 ((equal action ?A)
7973 (setq cmd '(org-agenda-archive-to-archive-sibling)))
7975 ((member action '(?r ?w))
7976 (setq rfloc (org-refile-get-location
7977 "Refile to: "
7978 (marker-buffer (car org-agenda-bulk-marked-entries))
7979 org-refile-allow-creating-parent-nodes))
7980 (if (nth 3 rfloc)
7981 (setcar (nthcdr 3 rfloc)
7982 (move-marker (make-marker) (nth 3 rfloc)
7983 (or (get-file-buffer (nth 1 rfloc))
7984 (find-buffer-visiting (nth 1 rfloc))
7985 (error "This should not happen")))))
7987 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
7988 redo-at-end t))
7990 ((equal action ?t)
7991 (setq state (org-icompleting-read
7992 "Todo state: "
7993 (with-current-buffer (marker-buffer (car entries))
7994 (mapcar 'list org-todo-keywords-1))))
7995 (setq cmd `(let ((org-inhibit-blocking t)
7996 (org-inhibit-logging 'note))
7997 (org-agenda-todo ,state))))
7999 ((memq action '(?- ?+))
8000 (setq tag (org-icompleting-read
8001 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8002 (with-current-buffer (marker-buffer (car entries))
8003 (delq nil
8004 (mapcar (lambda (x)
8005 (if (stringp (car x)) x)) org-tag-alist)))))
8006 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8008 ((memq action '(?s ?d))
8009 (let* ((date (unless arg
8010 (org-read-date
8011 nil nil nil
8012 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8013 (ans (if arg nil org-read-date-final-answer))
8014 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8015 (setq cmd `(let* ((bound (fboundp 'read-string))
8016 (old (and bound (symbol-function 'read-string))))
8017 (unwind-protect
8018 (progn
8019 (fset 'read-string (lambda (&rest ignore) ,ans))
8020 (eval '(,c1 arg)))
8021 (if bound
8022 (fset 'read-string old)
8023 (fmakunbound 'read-string)))))))
8025 ((equal action ?S)
8026 (if (not (org-agenda-check-type nil 'agenda 'timeline))
8027 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8028 (let ((days (read-number
8029 (format "Scatter tasks across how many %sdays: "
8030 (if arg "week" "")) 7)))
8031 (setq cmd
8032 `(let ((distance (1+ (random ,days))))
8033 (if arg
8034 (let ((dist distance)
8035 (day-of-week
8036 (calendar-day-of-week
8037 (calendar-gregorian-from-absolute (org-today)))))
8038 (dotimes (i (1+ dist))
8039 (while (member day-of-week org-agenda-weekend-days)
8040 (incf distance)
8041 (incf day-of-week)
8042 (if (= day-of-week 7)
8043 (setq day-of-week 0)))
8044 (incf day-of-week)
8045 (if (= day-of-week 7)
8046 (setq day-of-week 0)))))
8047 ;; silently fail when try to replan a sexp entry
8048 (condition-case nil
8049 (org-agenda-date-later distance)
8050 (error nil)))))))
8052 (t (error "Invalid bulk action")))
8054 ;; Sort the markers, to make sure that parents are handled before children
8055 (setq entries (sort entries
8056 (lambda (a b)
8057 (cond
8058 ((equal (marker-buffer a) (marker-buffer b))
8059 (< (marker-position a) (marker-position b)))
8061 (string< (buffer-name (marker-buffer a))
8062 (buffer-name (marker-buffer b))))))))
8064 ;; Now loop over all markers and apply cmd
8065 (while (setq e (pop entries))
8066 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8067 (if (not pos)
8068 (progn (message "Skipping removed entry at %s" e)
8069 (setq cntskip (1+ cntskip)))
8070 (goto-char pos)
8071 (eval cmd)
8072 (setq org-agenda-bulk-marked-entries
8073 (delete e org-agenda-bulk-marked-entries))
8074 (setq cnt (1+ cnt))))
8075 (setq org-agenda-bulk-marked-entries nil)
8076 (org-agenda-bulk-remove-all-marks)
8077 (when redo-at-end (org-agenda-redo))
8078 (message "Acted on %d entries%s"
8080 (if (= cntskip 0)
8082 (format ", skipped %d (disappeared before their turn)"
8083 cntskip)))))
8085 ;;; Flagging notes
8087 (defun org-agenda-show-the-flagging-note ()
8088 "Display the flagging note in the other window.
8089 When called a second time in direct sequence, offer to remove the FLAGGING
8090 tag and (if present) the flagging note."
8091 (interactive)
8092 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8093 (win (selected-window))
8094 note heading newhead)
8095 (unless hdmarker
8096 (error "No linked entry at point"))
8097 (if (and (eq this-command last-command)
8098 (y-or-n-p "Unflag and remove any flagging note? "))
8099 (progn
8100 (org-agenda-remove-flag hdmarker)
8101 (let ((win (get-buffer-window "*Flagging Note*")))
8102 (and win (delete-window win)))
8103 (message "Entry unflaged"))
8104 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8105 (unless note
8106 (error "No flagging note"))
8107 (org-kill-new note)
8108 (org-switch-to-buffer-other-window "*Flagging Note*")
8109 (erase-buffer)
8110 (insert note)
8111 (goto-char (point-min))
8112 (while (re-search-forward "\\\\n" nil t)
8113 (replace-match "\n" t t))
8114 (goto-char (point-min))
8115 (select-window win)
8116 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8118 (defun org-agenda-remove-flag (marker)
8119 "Remove the FLAGGED tag and any flagging note in the entry."
8120 (let (newhead)
8121 (org-with-point-at marker
8122 (org-toggle-tag "FLAGGED" 'off)
8123 (org-entry-delete nil "THEFLAGGINGNOTE")
8124 (setq newhead (org-get-heading)))
8125 (org-agenda-change-all-lines newhead marker)
8126 (message "Entry unflaged")))
8128 (defun org-agenda-get-any-marker (&optional pos)
8129 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8130 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8132 ;;; Appointment reminders
8134 (defvar appt-time-msg-list)
8136 ;;;###autoload
8137 (defun org-agenda-to-appt (&optional refresh filter)
8138 "Activate appointments found in `org-agenda-files'.
8139 With a \\[universal-argument] prefix, refresh the list of
8140 appointments.
8142 If FILTER is t, interactively prompt the user for a regular
8143 expression, and filter out entries that don't match it.
8145 If FILTER is a string, use this string as a regular expression
8146 for filtering entries out.
8148 FILTER can also be an alist with the car of each cell being
8149 either 'headline or 'category. For example:
8151 '((headline \"IMPORTANT\")
8152 (category \"Work\"))
8154 will only add headlines containing IMPORTANT or headlines
8155 belonging to the \"Work\" category."
8156 (interactive "P")
8157 (if refresh (setq appt-time-msg-list nil))
8158 (if (eq filter t)
8159 (setq filter (read-from-minibuffer "Regexp filter: ")))
8160 (let* ((cnt 0) ; count added events
8161 (org-agenda-new-buffers nil)
8162 (org-deadline-warning-days 0)
8163 ;; Do not use `org-today' here because appt only takes
8164 ;; time and without date as argument, so it may pass wrong
8165 ;; information otherwise
8166 (today (org-date-to-gregorian
8167 (time-to-days (current-time))))
8168 (org-agenda-restrict nil)
8169 (files (org-agenda-files 'unrestricted)) entries file)
8170 ;; Get all entries which may contain an appt
8171 (org-prepare-agenda-buffers files)
8172 (while (setq file (pop files))
8173 (setq entries
8174 (append entries
8175 (org-agenda-get-day-entries
8176 file today :timestamp :scheduled :deadline))))
8177 (setq entries (delq nil entries))
8178 ;; Map thru entries and find if we should filter them out
8179 (mapc
8180 (lambda(x)
8181 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8182 (cat (get-text-property 1 'org-category x))
8183 (tod (get-text-property 1 'time-of-day x))
8184 (ok (or (null filter)
8185 (and (stringp filter) (string-match filter evt))
8186 (and (listp filter)
8187 (or (string-match
8188 (cadr (assoc 'category filter)) cat)
8189 (string-match
8190 (cadr (assoc 'headline filter)) evt))))))
8191 ;; FIXME: Shall we remove text-properties for the appt text?
8192 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8193 (when (and ok tod)
8194 (setq tod (concat "00" (number-to-string tod))
8195 tod (when (string-match
8196 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8197 (concat (match-string 1 tod) ":"
8198 (match-string 2 tod))))
8199 (appt-add tod evt)
8200 (setq cnt (1+ cnt))))) entries)
8201 (org-release-buffers org-agenda-new-buffers)
8202 (if (eq cnt 0)
8203 (message "No event to add")
8204 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8206 (defun org-agenda-todayp (date)
8207 "Does DATE mean today, when considering `org-extend-today-until'?"
8208 (let ((today (org-today))
8209 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8210 date)))
8211 (eq date today)))
8213 (provide 'org-agenda)
8215 ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
8217 ;;; org-agenda.el ends here