org-element: Allow links in captions
[org-mode.git] / lisp / org-agenda.el
blob43427bb7ab7f15ac8e314dc39088338e2452232c
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, or a number which will then give
831 the number of days before the actual deadline when the prewarnings
832 should resume.
833 This can be used in a workflow where the first showing of the deadline will
834 trigger you to schedule it, and then you don't want to be reminded of it
835 because you will take care of it on the day when scheduled."
836 :group 'org-agenda-skip
837 :group 'org-agenda-daily/weekly
838 :version "24.1"
839 :type '(choice
840 (const :tag "Alwas show prewarning" nil)
841 (const :tag "Remove prewarning if entry is scheduled" t)
842 (integer :tag "Restart prewarning N days before deadline")))
844 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
845 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
846 When non-nil, after the search for timestamps has matched once in an
847 entry, the rest of the entry will not be searched."
848 :group 'org-agenda-skip
849 :type 'boolean)
851 (defcustom org-agenda-skip-timestamp-if-done nil
852 "Non-nil means don't select item by timestamp or -range if it is DONE."
853 :group 'org-agenda-skip
854 :group 'org-agenda-daily/weekly
855 :type 'boolean)
857 (defcustom org-agenda-dim-blocked-tasks t
858 "Non-nil means dim blocked tasks in the agenda display.
859 This causes some overhead during agenda construction, but if you
860 have turned on `org-enforce-todo-dependencies',
861 `org-enforce-todo-checkbox-dependencies', or any other blocking
862 mechanism, this will create useful feedback in the agenda.
864 Instead of t, this variable can also have the value `invisible'.
865 Then blocked tasks will be invisible and only become visible when
866 they become unblocked. An exemption to this behavior is when a task is
867 blocked because of unchecked checkboxes below it. Since checkboxes do
868 not show up in the agenda views, making this task invisible you remove any
869 trace from agenda views that there is something to do. Therefore, a task
870 that is blocked because of checkboxes will never be made invisible, it
871 will only be dimmed."
872 :group 'org-agenda-daily/weekly
873 :group 'org-agenda-todo-list
874 :type '(choice
875 (const :tag "Do not dim" nil)
876 (const :tag "Dim to a gray face" t)
877 (const :tag "Make invisible" invisible)))
879 (defcustom org-timeline-show-empty-dates 3
880 "Non-nil means `org-timeline' also shows dates without an entry.
881 When nil, only the days which actually have entries are shown.
882 When t, all days between the first and the last date are shown.
883 When an integer, show also empty dates, but if there is a gap of more than
884 N days, just insert a special line indicating the size of the gap."
885 :group 'org-agenda-skip
886 :type '(choice
887 (const :tag "None" nil)
888 (const :tag "All" t)
889 (integer :tag "at most")))
891 (defgroup org-agenda-startup nil
892 "Options concerning initial settings in the Agenda in Org Mode."
893 :tag "Org Agenda Startup"
894 :group 'org-agenda)
896 (defcustom org-agenda-menu-show-matcher t
897 "Non-nil means show the match string in the agenda dispatcher menu.
898 When nil, the matcher string is not shown, but is put into the help-echo
899 property so than moving the mouse over the command shows it.
900 Setting it to nil is good if matcher strings are very long and/or if
901 you want to use two-columns display (see `org-agenda-menu-two-columns')."
902 :group 'org-agenda
903 :version "24.1"
904 :type 'boolean)
906 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
908 (defcustom org-agenda-menu-two-columns nil
909 "Non-nil means, use two columns to show custom commands in the dispatcher.
910 If you use this, you probably want to set `org-agenda-menu-show-matcher'
911 to nil."
912 :group 'org-agenda
913 :version "24.1"
914 :type 'boolean)
916 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
917 (defcustom org-agenda-finalize-hook nil
918 "Hook run just before displaying an agenda buffer.
919 The buffer is still writable when the hook is called.
921 You can modify some of the buffer substrings but you should be
922 extra careful not to modify the text properties of the agenda
923 headlines as the agenda display heavily relies on them."
924 :group 'org-agenda-startup
925 :type 'hook)
927 (defcustom org-agenda-mouse-1-follows-link nil
928 "Non-nil means mouse-1 on a link will follow the link in the agenda.
929 A longer mouse click will still set point. Does not work on XEmacs.
930 Needs to be set before org.el is loaded."
931 :group 'org-agenda-startup
932 :type 'boolean)
934 (defcustom org-agenda-start-with-follow-mode nil
935 "The initial value of follow mode in a newly created agenda window."
936 :group 'org-agenda-startup
937 :type 'boolean)
939 (defcustom org-agenda-follow-indirect nil
940 "Non-nil means `org-agenda-follow-mode' displays only the
941 current item's tree, in an indirect buffer."
942 :group 'org-agenda
943 :version "24.1"
944 :type 'boolean)
946 (defcustom org-agenda-show-outline-path t
947 "Non-nil means show outline path in echo area after line motion."
948 :group 'org-agenda-startup
949 :type 'boolean)
951 (defcustom org-agenda-start-with-entry-text-mode nil
952 "The initial value of entry-text-mode in a newly created agenda window."
953 :group 'org-agenda-startup
954 :type 'boolean)
956 (defcustom org-agenda-entry-text-maxlines 5
957 "Number of text lines to be added when `E' is pressed in the agenda.
959 Note that this variable only used during agenda display. Add add entry text
960 when exporting the agenda, configure the variable
961 `org-agenda-add-entry-ext-maxlines'."
962 :group 'org-agenda
963 :type 'integer)
965 (defcustom org-agenda-entry-text-exclude-regexps nil
966 "List of regular expressions to clean up entry text.
967 The complete matches of all regular expressions in this list will be
968 removed from entry text before it is shown in the agenda."
969 :group 'org-agenda
970 :type '(repeat (regexp)))
972 (defvar org-agenda-entry-text-cleanup-hook nil
973 "Hook that is run after basic cleanup of entry text to be shown in agenda.
974 This cleanup is done in a temporary buffer, so the function may inspect and
975 change the entire buffer.
976 Some default stuff like drawers and scheduling/deadline dates will already
977 have been removed when this is called, as will any matches for regular
978 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
980 (defvar org-agenda-include-inactive-timestamps nil
981 "Non-nil means include inactive time stamps in agenda and timeline.
982 Dynamically scoped.")
984 (defgroup org-agenda-windows nil
985 "Options concerning the windows used by the Agenda in Org Mode."
986 :tag "Org Agenda Windows"
987 :group 'org-agenda)
989 (defcustom org-agenda-window-setup 'reorganize-frame
990 "How the agenda buffer should be displayed.
991 Possible values for this option are:
993 current-window Show agenda in the current window, keeping all other windows.
994 other-window Use `switch-to-buffer-other-window' to display agenda.
995 reorganize-frame Show only two windows on the current frame, the current
996 window and the agenda.
997 other-frame Use `switch-to-buffer-other-frame' to display agenda.
998 Also, when exiting the agenda, kill that frame.
999 See also the variable `org-agenda-restore-windows-after-quit'."
1000 :group 'org-agenda-windows
1001 :type '(choice
1002 (const current-window)
1003 (const other-frame)
1004 (const other-window)
1005 (const reorganize-frame)))
1007 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1008 "The min and max height of the agenda window as a fraction of frame height.
1009 The value of the variable is a cons cell with two numbers between 0 and 1.
1010 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1011 :group 'org-agenda-windows
1012 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1014 (defcustom org-agenda-restore-windows-after-quit nil
1015 "Non-nil means restore window configuration upon exiting agenda.
1016 Before the window configuration is changed for displaying the agenda,
1017 the current status is recorded. When the agenda is exited with
1018 `q' or `x' and this option is set, the old state is restored. If
1019 `org-agenda-window-setup' is `other-frame', the value of this
1020 option will be ignored."
1021 :group 'org-agenda-windows
1022 :type 'boolean)
1024 (defcustom org-agenda-ndays nil
1025 "Number of days to include in overview display.
1026 Should be 1 or 7.
1027 Obsolete, see `org-agenda-span'."
1028 :group 'org-agenda-daily/weekly
1029 :type 'integer)
1031 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1033 (defcustom org-agenda-span 'week
1034 "Number of days to include in overview display.
1035 Can be day, week, month, year, or any number of days.
1036 Custom commands can set this variable in the options section."
1037 :group 'org-agenda-daily/weekly
1038 :type '(choice (const :tag "Day" day)
1039 (const :tag "Week" week)
1040 (const :tag "Month" month)
1041 (const :tag "Year" year)
1042 (integer :tag "Custom")))
1044 (defcustom org-agenda-start-on-weekday 1
1045 "Non-nil means start the overview always on the specified weekday.
1046 0 denotes Sunday, 1 denotes Monday etc.
1047 When nil, always start on the current day.
1048 Custom commands can set this variable in the options section."
1049 :group 'org-agenda-daily/weekly
1050 :type '(choice (const :tag "Today" nil)
1051 (integer :tag "Weekday No.")))
1053 (defcustom org-agenda-show-all-dates t
1054 "Non-nil means `org-agenda' shows every day in the selected range.
1055 When nil, only the days which actually have entries are shown."
1056 :group 'org-agenda-daily/weekly
1057 :type 'boolean)
1059 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1060 "Format string for displaying dates in the agenda.
1061 Used by the daily/weekly agenda and by the timeline. This should be
1062 a format string understood by `format-time-string', or a function returning
1063 the formatted date as a string. The function must take a single argument,
1064 a calendar-style date list like (month day year)."
1065 :group 'org-agenda-daily/weekly
1066 :type '(choice
1067 (string :tag "Format string")
1068 (function :tag "Function")))
1070 (defun org-agenda-format-date-aligned (date)
1071 "Format a date string for display in the daily/weekly agenda, or timeline.
1072 This function makes sure that dates are aligned for easy reading."
1073 (require 'cal-iso)
1074 (let* ((dayname (calendar-day-name date))
1075 (day (cadr date))
1076 (day-of-week (calendar-day-of-week date))
1077 (month (car date))
1078 (monthname (calendar-month-name month))
1079 (year (nth 2 date))
1080 (iso-week (org-days-to-iso-week
1081 (calendar-absolute-from-gregorian date)))
1082 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1083 (1- year))
1084 ((and (= month 12) (<= iso-week 1))
1085 (1+ year))
1086 (t year)))
1087 (weekstring (if (= day-of-week 1)
1088 (format " W%02d" iso-week)
1089 "")))
1090 (format "%-10s %2d %s %4d%s"
1091 dayname day monthname year weekstring)))
1093 (defcustom org-agenda-time-leading-zero nil
1094 "Non-nil means use leading zero for military times in agenda.
1095 For example, 9:30am would become 09:30 rather than 9:30."
1096 :group 'org-agenda-daily/weekly
1097 :version "24.1"
1098 :type 'boolean)
1100 (defcustom org-agenda-timegrid-use-ampm nil
1101 "When set, show AM/PM style timestamps on the timegrid."
1102 :group 'org-agenda
1103 :version "24.1"
1104 :type 'boolean)
1106 (defun org-agenda-time-of-day-to-ampm (time)
1107 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1108 (let* ((hour-number (string-to-number (substring time 0 -3)))
1109 (minute (substring time -2))
1110 (ampm "am"))
1111 (cond
1112 ((equal hour-number 12)
1113 (setq ampm "pm"))
1114 ((> hour-number 12)
1115 (setq ampm "pm")
1116 (setq hour-number (- hour-number 12))))
1117 (concat
1118 (if org-agenda-time-leading-zero
1119 (format "%02d" hour-number)
1120 (format "%02s" (number-to-string hour-number)))
1121 ":" minute ampm)))
1123 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1124 "Conditionally convert TIME to AM/PM format
1125 based on `org-agenda-timegrid-use-ampm'"
1126 (if org-agenda-timegrid-use-ampm
1127 (org-agenda-time-of-day-to-ampm time)
1128 time))
1130 (defcustom org-agenda-weekend-days '(6 0)
1131 "Which days are weekend?
1132 These days get the special face `org-agenda-date-weekend' in the agenda
1133 and timeline buffers."
1134 :group 'org-agenda-daily/weekly
1135 :type '(set :greedy t
1136 (const :tag "Monday" 1)
1137 (const :tag "Tuesday" 2)
1138 (const :tag "Wednesday" 3)
1139 (const :tag "Thursday" 4)
1140 (const :tag "Friday" 5)
1141 (const :tag "Saturday" 6)
1142 (const :tag "Sunday" 0)))
1144 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1145 "Non-nil means jump to today when moving a past date forward in time.
1146 When using S-right in the agenda to move a a date forward, and the date
1147 stamp currently points to the past, the first key press will move it
1148 to today. WHen nil, just move one day forward even if the date stays
1149 in the past."
1150 :group 'org-agenda-daily/weekly
1151 :version "24.1"
1152 :type 'boolean)
1154 (defcustom org-agenda-include-diary nil
1155 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1156 Custom commands can set this variable in the options section."
1157 :group 'org-agenda-daily/weekly
1158 :type 'boolean)
1160 (defcustom org-agenda-include-deadlines t
1161 "If non-nil, include entries within their deadline warning period.
1162 Custom commands can set this variable in the options section."
1163 :group 'org-agenda-daily/weekly
1164 :version "24.1"
1165 :type 'boolean)
1167 (defcustom org-agenda-repeating-timestamp-show-all t
1168 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1169 When set to a list of strings, only show occurrences of repeating
1170 stamps for these TODO keywords. When nil, only one occurrence is
1171 shown, either today or the nearest into the future."
1172 :group 'org-agenda-daily/weekly
1173 :type '(choice
1174 (const :tag "Show repeating stamps" t)
1175 (repeat :tag "Show repeating stamps for these TODO keywords"
1176 (string :tag "TODO Keyword"))
1177 (const :tag "Don't show repeating stamps" nil)))
1179 (defcustom org-scheduled-past-days 10000
1180 "No. of days to continue listing scheduled items that are not marked DONE.
1181 When an item is scheduled on a date, it shows up in the agenda on this
1182 day and will be listed until it is marked done for the number of days
1183 given here."
1184 :group 'org-agenda-daily/weekly
1185 :type 'integer)
1187 (defcustom org-agenda-log-mode-items '(closed clock)
1188 "List of items that should be shown in agenda log mode.
1189 This list may contain the following symbols:
1191 closed Show entries that have been closed on that day.
1192 clock Show entries that have received clocked time on that day.
1193 state Show all logged state changes.
1194 Note that instead of changing this variable, you can also press `C-u l' in
1195 the agenda to display all available LOG items temporarily."
1196 :group 'org-agenda-daily/weekly
1197 :type '(set :greedy t (const closed) (const clock) (const state)))
1199 (defcustom org-agenda-clock-consistency-checks
1200 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1201 :gap-ok-around ("4:00")
1202 :default-face ((:background "DarkRed") (:foreground "white"))
1203 :overlap-face nil :gap-face nil :no-end-time-face nil
1204 :long-face nil :short-face nil)
1205 "This is a property list, with the following keys:
1207 :max-duration Mark clocking chunks that are longer than this time.
1208 This is a time string like \"HH:MM\", or the number
1209 of minutes as an integer.
1211 :min-duration Mark clocking chunks that are shorter that this.
1212 This is a time string like \"HH:MM\", or the number
1213 of minutes as an integer.
1215 :max-gap Mark gaps between clocking chunks that are longer than
1216 this duration. A number of minutes, or a string
1217 like \"HH:MM\".
1219 :gap-ok-around List of times during the day which are usually not working
1220 times. When a gap is detected, but the gap contains any
1221 of these times, the gap is *not* reported. For example,
1222 if this is (\"4:00\" \"13:00\") then gaps that contain
1223 4:00 in the morning (i.e. the night) and 13:00
1224 (i.e. a typical lunch time) do not cause a warning.
1225 You should have at least one time during the night in this
1226 list, or otherwise the first task each morning will trigger
1227 a warning because it follows a long gap.
1229 Furthermore, the following properties can be used to define faces for
1230 issue display.
1232 :default-face the default face, if the specific face is undefined
1233 :overlap-face face for overlapping clocks
1234 :gap-face face for gaps between clocks
1235 :no-end-time-face face for incomplete clocks
1236 :long-face face for clock intervals that are too long
1237 :short-face face for clock intervals that are too short"
1238 :group 'org-agenda-daily/weekly
1239 :group 'org-clock
1240 :version "24.1"
1241 :type 'plist)
1243 (defcustom org-agenda-log-mode-add-notes t
1244 "Non-nil means add first line of notes to log entries in agenda views.
1245 If a log item like a state change or a clock entry is associated with
1246 notes, the first line of these notes will be added to the entry in the
1247 agenda display."
1248 :group 'org-agenda-daily/weekly
1249 :type 'boolean)
1251 (defcustom org-agenda-start-with-log-mode nil
1252 "The initial value of log-mode in a newly created agenda window.
1253 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1254 explanations on the possible values."
1255 :group 'org-agenda-startup
1256 :group 'org-agenda-daily/weekly
1257 :type '(choice (const :tag "Don't show log items" nil)
1258 (const :tag "Show only log items" 'only)
1259 (const :tag "Show all possible log items" 'clockcheck)
1260 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1261 (choice (const :tag "Show closed log items" 'closed)
1262 (const :tag "Show clocked log items" 'clock)
1263 (const :tag "Show all logged state changes" 'state)))))
1265 (defcustom org-agenda-start-with-clockreport-mode nil
1266 "The initial value of clockreport-mode in a newly created agenda window."
1267 :group 'org-agenda-startup
1268 :group 'org-agenda-daily/weekly
1269 :type 'boolean)
1271 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1272 "Property list with parameters for the clocktable in clockreport mode.
1273 This is the display mode that shows a clock table in the daily/weekly
1274 agenda, the properties for this dynamic block can be set here.
1275 The usual clocktable parameters are allowed here, but you cannot set
1276 the properties :name, :tstart, :tend, :block, and :scope - these will
1277 be overwritten to make sure the content accurately reflects the
1278 current display in the agenda."
1279 :group 'org-agenda-daily/weekly
1280 :type 'plist)
1282 (defcustom org-agenda-search-view-always-boolean nil
1283 "Non-nil means the search string is interpreted as individual parts.
1285 The search string for search view can either be interpreted as a phrase,
1286 or as a list of snippets that define a boolean search for a number of
1287 strings.
1289 When this is non-nil, the string will be split on whitespace, and each
1290 snippet will be searched individually, and all must match in order to
1291 select an entry. A snippet is then a single string of non-white
1292 characters, or a string in double quotes, or a regexp in {} braces.
1293 If a snippet is preceded by \"-\", the snippet must *not* match.
1294 \"+\" is syntactic sugar for positive selection. Each snippet may
1295 be found as a full word or a partial word, but see the variable
1296 `org-agenda-search-view-force-full-words'.
1298 When this is nil, search will look for the entire search phrase as one,
1299 with each space character matching any amount of whitespace, including
1300 line breaks.
1302 Even when this is nil, you can still switch to Boolean search dynamically
1303 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1304 is a regexp marked with braces like \"{abc}\", this will also switch to
1305 boolean search."
1306 :group 'org-agenda-search-view
1307 :version "24.1"
1308 :type 'boolean)
1310 (if (fboundp 'defvaralias)
1311 (defvaralias 'org-agenda-search-view-search-words-only
1312 'org-agenda-search-view-always-boolean))
1314 (defcustom org-agenda-search-view-force-full-words nil
1315 "Non-nil means, search words must be matches as complete words.
1316 When nil, they may also match part of a word."
1317 :group 'org-agenda-search-view
1318 :version "24.1"
1319 :type 'boolean)
1321 (defgroup org-agenda-time-grid nil
1322 "Options concerning the time grid in the Org-mode Agenda."
1323 :tag "Org Agenda Time Grid"
1324 :group 'org-agenda)
1326 (defcustom org-agenda-search-headline-for-time t
1327 "Non-nil means search headline for a time-of-day.
1328 If the headline contains a time-of-day in one format or another, it will
1329 be used to sort the entry into the time sequence of items for a day.
1330 Some people have time stamps in the headline that refer to the creation
1331 time or so, and then this produces an unwanted side effect. If this is
1332 the case for your, use this variable to turn off searching the headline
1333 for a time."
1334 :group 'org-agenda-time-grid
1335 :type 'boolean)
1337 (defcustom org-agenda-use-time-grid t
1338 "Non-nil means show a time grid in the agenda schedule.
1339 A time grid is a set of lines for specific times (like every two hours between
1340 8:00 and 20:00). The items scheduled for a day at specific times are
1341 sorted in between these lines.
1342 For details about when the grid will be shown, and what it will look like, see
1343 the variable `org-agenda-time-grid'."
1344 :group 'org-agenda-time-grid
1345 :type 'boolean)
1347 (defcustom org-agenda-time-grid
1348 '((daily today require-timed)
1349 "----------------"
1350 (800 1000 1200 1400 1600 1800 2000))
1352 "The settings for time grid for agenda display.
1353 This is a list of three items. The first item is again a list. It contains
1354 symbols specifying conditions when the grid should be displayed:
1356 daily if the agenda shows a single day
1357 weekly if the agenda shows an entire week
1358 today show grid on current date, independent of daily/weekly display
1359 require-timed show grid only if at least one item has a time specification
1361 The second item is a string which will be placed behind the grid time.
1363 The third item is a list of integers, indicating the times that should have
1364 a grid line."
1365 :group 'org-agenda-time-grid
1366 :type
1367 '(list
1368 (set :greedy t :tag "Grid Display Options"
1369 (const :tag "Show grid in single day agenda display" daily)
1370 (const :tag "Show grid in weekly agenda display" weekly)
1371 (const :tag "Always show grid for today" today)
1372 (const :tag "Show grid only if any timed entries are present"
1373 require-timed)
1374 (const :tag "Skip grid times already present in an entry"
1375 remove-match))
1376 (string :tag "Grid String")
1377 (repeat :tag "Grid Times" (integer :tag "Time"))))
1379 (defcustom org-agenda-show-current-time-in-grid t
1380 "Non-nil means show the current time in the time grid."
1381 :group 'org-agenda-time-grid
1382 :version "24.1"
1383 :type 'boolean)
1385 (defcustom org-agenda-current-time-string
1386 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1387 "The string for the current time marker in the agenda."
1388 :group 'org-agenda-time-grid
1389 :version "24.1"
1390 :type 'string)
1392 (defgroup org-agenda-sorting nil
1393 "Options concerning sorting in the Org-mode Agenda."
1394 :tag "Org Agenda Sorting"
1395 :group 'org-agenda)
1397 (defcustom org-agenda-sorting-strategy
1398 '((agenda habit-down time-up priority-down category-keep)
1399 (todo priority-down category-keep)
1400 (tags priority-down category-keep)
1401 (search category-keep))
1402 "Sorting structure for the agenda items of a single day.
1403 This is a list of symbols which will be used in sequence to determine
1404 if an entry should be listed before another entry. The following
1405 symbols are recognized:
1407 time-up Put entries with time-of-day indications first, early first
1408 time-down Put entries with time-of-day indications first, late first
1409 category-keep Keep the default order of categories, corresponding to the
1410 sequence in `org-agenda-files'.
1411 category-up Sort alphabetically by category, A-Z.
1412 category-down Sort alphabetically by category, Z-A.
1413 tag-up Sort alphabetically by last tag, A-Z.
1414 tag-down Sort alphabetically by last tag, Z-A.
1415 priority-up Sort numerically by priority, high priority last.
1416 priority-down Sort numerically by priority, high priority first.
1417 todo-state-up Sort by todo state, tasks that are done last.
1418 todo-state-down Sort by todo state, tasks that are done first.
1419 effort-up Sort numerically by estimated effort, high effort last.
1420 effort-down Sort numerically by estimated effort, high effort first.
1421 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1422 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1423 habit-up Put entries that are habits first
1424 habit-down Put entries that are habits last
1425 alpha-up Sort headlines alphabetically
1426 alpha-down Sort headlines alphabetically, reversed
1428 The different possibilities will be tried in sequence, and testing stops
1429 if one comparison returns a \"not-equal\". For example, the default
1430 '(time-up category-keep priority-down)
1431 means: Pull out all entries having a specified time of day and sort them,
1432 in order to make a time schedule for the current day the first thing in the
1433 agenda listing for the day. Of the entries without a time indication, keep
1434 the grouped in categories, don't sort the categories, but keep them in
1435 the sequence given in `org-agenda-files'. Within each category sort by
1436 priority.
1438 Leaving out `category-keep' would mean that items will be sorted across
1439 categories by priority.
1441 Instead of a single list, this can also be a set of list for specific
1442 contents, with a context symbol in the car of the list, any of
1443 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1445 Custom commands can bind this variable in the options section."
1446 :group 'org-agenda-sorting
1447 :type `(choice
1448 (repeat :tag "General" ,org-sorting-choice)
1449 (list :tag "Individually"
1450 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1451 (repeat ,org-sorting-choice))
1452 (cons (const :tag "Strategy for TODO lists" todo)
1453 (repeat ,org-sorting-choice))
1454 (cons (const :tag "Strategy for Tags matches" tags)
1455 (repeat ,org-sorting-choice))
1456 (cons (const :tag "Strategy for search matches" search)
1457 (repeat ,org-sorting-choice)))))
1459 (defcustom org-agenda-cmp-user-defined nil
1460 "A function to define the comparison `user-defined'.
1461 This function must receive two arguments, agenda entry a and b.
1462 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1463 the user comparison, return nil.
1464 When this is defined, you can make `user-defined-up' and `user-defined-down'
1465 part of an agenda sorting strategy."
1466 :group 'org-agenda-sorting
1467 :type 'symbol)
1469 (defcustom org-sort-agenda-notime-is-late t
1470 "Non-nil means items without time are considered late.
1471 This is only relevant for sorting. When t, items which have no explicit
1472 time like 15:30 will be considered as 99:01, i.e. later than any items which
1473 do have a time. When nil, the default time is before 0:00. You can use this
1474 option to decide if the schedule for today should come before or after timeless
1475 agenda entries."
1476 :group 'org-agenda-sorting
1477 :type 'boolean)
1479 (defcustom org-sort-agenda-noeffort-is-high t
1480 "Non-nil means items without effort estimate are sorted as high effort.
1481 This also applies when filtering an agenda view with respect to the
1482 < or > effort operator. Then, tasks with no effort defined will be treated
1483 as tasks with high effort.
1484 When nil, such items are sorted as 0 minutes effort."
1485 :group 'org-agenda-sorting
1486 :type 'boolean)
1488 (defgroup org-agenda-line-format nil
1489 "Options concerning the entry prefix in the Org-mode agenda display."
1490 :tag "Org Agenda Line Format"
1491 :group 'org-agenda)
1493 (defcustom org-agenda-prefix-format
1494 '((agenda . " %i %-12:c%?-12t% s")
1495 (timeline . " % s")
1496 (todo . " %i %-12:c")
1497 (tags . " %i %-12:c")
1498 (search . " %i %-12:c"))
1499 "Format specifications for the prefix of items in the agenda views.
1500 An alist with five entries, each for the different agenda types. The
1501 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1502 The values are format strings.
1504 This format works similar to a printf format, with the following meaning:
1506 %c the category of the item, \"Diary\" for entries from the diary,
1507 or as given by the CATEGORY keyword or derived from the file name
1508 %e the effort required by the item
1509 %l the level of the item (insert X space(s) if item is of level X)
1510 %i the icon category of the item, see `org-agenda-category-icon-alist'
1511 %T the last tag of the item (ignore inherited tags, which come first)
1512 %t the HH:MM time-of-day specification if one applies to the entry
1513 %s Scheduling/Deadline information, a short string
1514 %(expression) Eval EXPRESSION and replace the control string
1515 by the result
1517 All specifiers work basically like the standard `%s' of printf, but may
1518 contain two additional characters: a question mark just after the `%'
1519 and a whitespace/punctuation character just before the final letter.
1521 If the first character after `%' is a question mark, the entire field
1522 will only be included if the corresponding value applies to the current
1523 entry. This is useful for fields which should have fixed width when
1524 present, but zero width when absent. For example, \"%?-12t\" will
1525 result in a 12 character time field if a time of the day is specified,
1526 but will completely disappear in entries which do not contain a time.
1528 If there is punctuation or whitespace character just before the final
1529 format letter, this character will be appended to the field value if
1530 the value is not empty. For example, the format \"%-12:c\" leads to
1531 \"Diary: \" if the category is \"Diary\". If the category were be
1532 empty, no additional colon would be inserted.
1534 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1535 which means:
1537 - Indent the line with two space characters
1538 - Give the category a 12 chars wide field, padded with whitespace on
1539 the right (because of `-'). Append a colon if there is a category
1540 (because of `:').
1541 - If there is a time-of-day, put it into a 12 chars wide field. If no
1542 time, don't put in an empty field, just skip it (because of '?').
1543 - Finally, put the scheduling information.
1545 See also the variables `org-agenda-remove-times-when-in-prefix' and
1546 `org-agenda-remove-tags'.
1548 Custom commands can set this variable in the options section."
1549 :type '(choice
1550 (string :tag "General format")
1551 (list :greedy t :tag "View dependent"
1552 (cons (const agenda) (string :tag "Format"))
1553 (cons (const timeline) (string :tag "Format"))
1554 (cons (const todo) (string :tag "Format"))
1555 (cons (const tags) (string :tag "Format"))
1556 (cons (const search) (string :tag "Format"))))
1557 :group 'org-agenda-line-format)
1559 (defvar org-prefix-format-compiled nil
1560 "The compiled prefix format and associated variables.
1561 This is a list where first element is a list of variable bindings, and second
1562 element is the compiled format expression. See the variable
1563 `org-agenda-prefix-format'.")
1565 (defcustom org-agenda-todo-keyword-format "%-1s"
1566 "Format for the TODO keyword in agenda lines.
1567 Set this to something like \"%-12s\" if you want all TODO keywords
1568 to occupy a fixed space in the agenda display."
1569 :group 'org-agenda-line-format
1570 :type 'string)
1572 (defcustom org-agenda-diary-sexp-prefix nil
1573 "A regexp that matches part of a diary sexp entry
1574 which should be treated as scheduling/deadline information in
1575 `org-agenda'.
1577 For example, you can use this to extract the `diary-remind-message' from
1578 `diary-remind' entries."
1579 :group 'org-agenda-line-format
1580 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1582 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1583 "Text preceding timerange entries in the agenda view.
1584 This is a list with two strings. The first applies when the range
1585 is entirely on one day. The second applies if the range spans several days.
1586 The strings may have two \"%d\" format specifiers which will be filled
1587 with the sequence number of the days, and the total number of days in the
1588 range, respectively."
1589 :group 'org-agenda-line-format
1590 :type '(list
1591 (string :tag "Deadline today ")
1592 (choice :tag "Deadline relative"
1593 (string :tag "Format string")
1594 (function))))
1596 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1597 "Text preceding scheduled items in the agenda view.
1598 This is a list with two strings. The first applies when the item is
1599 scheduled on the current day. The second applies when it has been scheduled
1600 previously, it may contain a %d indicating that this is the nth time that
1601 this item is scheduled, due to automatic rescheduling of unfinished items
1602 for the following day. So this number is one larger than the number of days
1603 that passed since this item was scheduled first."
1604 :group 'org-agenda-line-format
1605 :type '(list
1606 (string :tag "Scheduled today ")
1607 (string :tag "Scheduled previously")))
1609 (defcustom org-agenda-inactive-leader "["
1610 "Text preceding item pulled into the agenda by inactive time stamps.
1611 These entries are added to the agenda when pressing \"[\"."
1612 :group 'org-agenda-line-format
1613 :version "24.1"
1614 :type '(list
1615 (string :tag "Scheduled today ")
1616 (string :tag "Scheduled previously")))
1618 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1619 "Text preceding deadline items in the agenda view.
1620 This is a list with two strings. The first applies when the item has its
1621 deadline on the current day. The second applies when it is in the past or
1622 in the future, it may contain %d to capture how many days away the deadline
1623 is (was)."
1624 :group 'org-agenda-line-format
1625 :type '(list
1626 (string :tag "Deadline today ")
1627 (choice :tag "Deadline relative"
1628 (string :tag "Format string")
1629 (function))))
1631 (defcustom org-agenda-remove-times-when-in-prefix t
1632 "Non-nil means remove duplicate time specifications in agenda items.
1633 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1634 time-of-day specification in a headline or diary entry is extracted and
1635 placed into the prefix. If this option is non-nil, the original specification
1636 \(a timestamp or -range, or just a plain time(range) specification like
1637 11:30-4pm) will be removed for agenda display. This makes the agenda less
1638 cluttered.
1639 The option can be t or nil. It may also be the symbol `beg', indicating
1640 that the time should only be removed when it is located at the beginning of
1641 the headline/diary entry."
1642 :group 'org-agenda-line-format
1643 :type '(choice
1644 (const :tag "Always" t)
1645 (const :tag "Never" nil)
1646 (const :tag "When at beginning of entry" beg)))
1648 (defcustom org-agenda-remove-timeranges-from-blocks nil
1649 "Non-nil means remove time ranges specifications in agenda
1650 items that span on several days."
1651 :group 'org-agenda-line-format
1652 :version "24.1"
1653 :type 'boolean)
1655 (defcustom org-agenda-default-appointment-duration nil
1656 "Default duration for appointments that only have a starting time.
1657 When nil, no duration is specified in such cases.
1658 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1659 :group 'org-agenda-line-format
1660 :type '(choice
1661 (integer :tag "Minutes")
1662 (const :tag "No default duration")))
1664 (defcustom org-agenda-show-inherited-tags t
1665 "Non-nil means show inherited tags in each agenda line."
1666 :group 'org-agenda-line-format
1667 :type 'boolean)
1669 (defcustom org-agenda-hide-tags-regexp nil
1670 "Regular expression used to filter away specific tags in agenda views.
1671 This means that these tags will be present, but not be shown in the agenda
1672 line. Secondary filtering will still work on the hidden tags.
1673 Nil means don't hide any tags."
1674 :group 'org-agenda-line-format
1675 :type '(choice
1676 (const :tag "Hide none" nil)
1677 (string :tag "Regexp ")))
1679 (defcustom org-agenda-remove-tags nil
1680 "Non-nil means remove the tags from the headline copy in the agenda.
1681 When this is the symbol `prefix', only remove tags when
1682 `org-agenda-prefix-format' contains a `%T' specifier."
1683 :group 'org-agenda-line-format
1684 :type '(choice
1685 (const :tag "Always" t)
1686 (const :tag "Never" nil)
1687 (const :tag "When prefix format contains %T" prefix)))
1689 (if (fboundp 'defvaralias)
1690 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1691 'org-agenda-remove-tags))
1693 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1694 "Shift tags in agenda items to this column.
1695 If this number is positive, it specifies the column. If it is negative,
1696 it means that the tags should be flushright to that column. For example,
1697 -80 works well for a normal 80 character screen."
1698 :group 'org-agenda-line-format
1699 :type 'integer)
1701 (if (fboundp 'defvaralias)
1702 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1704 (defcustom org-agenda-fontify-priorities 'cookies
1705 "Non-nil means highlight low and high priorities in agenda.
1706 When t, the highest priority entries are bold, lowest priority italic.
1707 However, settings in `org-priority-faces' will overrule these faces.
1708 When this variable is the symbol `cookies', only fontify the
1709 cookies, not the entire task.
1710 This may also be an association list of priority faces, whose
1711 keys are the character values of `org-highest-priority',
1712 `org-default-priority', and `org-lowest-priority' (the default values
1713 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1714 color as a string, or a list like `(:background \"Red\")'.
1715 If it is a color, the variable `org-faces-easy-properties'
1716 determines if it is a foreground or a background color."
1717 :group 'org-agenda-line-format
1718 :type '(choice
1719 (const :tag "Never" nil)
1720 (const :tag "Defaults" t)
1721 (const :tag "Cookies only" cookies)
1722 (repeat :tag "Specify"
1723 (list (character :tag "Priority" :value ?A)
1724 (choice :tag "Face "
1725 (string :tag "Color")
1726 (sexp :tag "Face"))))))
1728 (defcustom org-agenda-day-face-function nil
1729 "Function called to determine what face should be used to display a day.
1730 The only argument passed to that function is the day. It should
1731 returns a face, or nil if does not want to specify a face and let
1732 the normal rules apply."
1733 :group 'org-agenda-line-format
1734 :version "24.1"
1735 :type 'function)
1737 (defcustom org-agenda-category-icon-alist nil
1738 "Alist of category icon to be displayed in agenda views.
1740 Each entry should have the following format:
1742 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1744 Where CATEGORY-REGEXP is a regexp matching the categories where
1745 the icon should be displayed.
1746 FILE-OR-DATA either a file path or a string containing image data.
1748 The other fields can be omitted safely if not needed:
1749 TYPE indicates the image type.
1750 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1751 image data.
1752 PROPS are additional image attributes to assign to the image,
1753 like, e.g. `:ascent center'.
1755 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1757 If you want to set the display properties yourself, just put a
1758 list as second element:
1760 (CATEGORY-REGEXP (MY PROPERTY LIST))
1762 For example, to display a 16px horizontal space for Emacs
1763 category, you can use:
1765 (\"Emacs\" '(space . (:width (16))))"
1766 :group 'org-agenda-line-format
1767 :version "24.1"
1768 :type '(alist :key-type (string :tag "Regexp matching category")
1769 :value-type (choice (list :tag "Icon"
1770 (string :tag "File or data")
1771 (symbol :tag "Type")
1772 (boolean :tag "Data?")
1773 (repeat :tag "Extra image properties" :inline t symbol))
1774 (list :tag "Display properties" sexp))))
1776 (defgroup org-agenda-column-view nil
1777 "Options concerning column view in the agenda."
1778 :tag "Org Agenda Column View"
1779 :group 'org-agenda)
1781 (defcustom org-agenda-columns-show-summaries t
1782 "Non-nil means show summaries for columns displayed in the agenda view."
1783 :group 'org-agenda-column-view
1784 :type 'boolean)
1786 (defcustom org-agenda-columns-compute-summary-properties t
1787 "Non-nil means recompute all summary properties before column view.
1788 When column view in the agenda is listing properties that have a summary
1789 operator, it can go to all relevant buffers and recompute the summaries
1790 there. This can mean overhead for the agenda column view, but is necessary
1791 to have thing up to date.
1792 As a special case, a CLOCKSUM property also makes sure that the clock
1793 computations are current."
1794 :group 'org-agenda-column-view
1795 :type 'boolean)
1797 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1798 "Non-nil means the duration of an appointment will add to day effort.
1799 The property to which appointment durations will be added is the one given
1800 in the option `org-effort-property'. If an appointment does not have
1801 an end time, `org-agenda-default-appointment-duration' will be used. If that
1802 is not set, an appointment without end time will not contribute to the time
1803 estimate."
1804 :group 'org-agenda-column-view
1805 :type 'boolean)
1807 (defcustom org-agenda-auto-exclude-function nil
1808 "A function called with a tag to decide if it is filtered on '/ RET'.
1809 The sole argument to the function, which is called once for each
1810 possible tag, is a string giving the name of the tag. The
1811 function should return either nil if the tag should be included
1812 as normal, or \"-<TAG>\" to exclude the tag.
1813 Note that for the purpose of tag filtering, only the lower-case version of
1814 all tags will be considered, so that this function will only ever see
1815 the lower-case version of all tags."
1816 :group 'org-agenda
1817 :type 'function)
1819 (defcustom org-agenda-bulk-custom-functions nil
1820 "Alist of characters and custom functions for bulk actions.
1821 For example, this value makes those two functions available:
1823 '((?R set-category)
1824 (?C bulk-cut))
1826 With selected entries in an agenda buffer, `B R' will call
1827 the custom function `set-category' on the selected entries.
1828 Note that functions in this alist don't need to be quoted."
1829 :type 'alist
1830 :version "24.1"
1831 :group 'org-agenda)
1833 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1834 "Execute BODY with point at location given by `org-hd-marker' property.
1835 If STRING is non-nil, the text property will be fetched from position 0
1836 in that string. If STRING is nil, it will be fetched from the beginning
1837 of the current line."
1838 (org-with-gensyms (marker)
1839 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1840 'org-hd-marker ,string)))
1841 (with-current-buffer (marker-buffer ,marker)
1842 (save-excursion
1843 (goto-char ,marker)
1844 ,@body)))))
1845 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1847 (defun org-add-agenda-custom-command (entry)
1848 "Replace or add a command in `org-agenda-custom-commands'.
1849 This is mostly for hacking and trying a new command - once the command
1850 works you probably want to add it to `org-agenda-custom-commands' for good."
1851 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1852 (if ass
1853 (setcdr ass (cdr entry))
1854 (push entry org-agenda-custom-commands))))
1856 ;;; Define the org-agenda-mode
1858 (defvar org-agenda-mode-map (make-sparse-keymap)
1859 "Keymap for `org-agenda-mode'.")
1860 (if (fboundp 'defvaralias)
1861 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1863 (defvar org-agenda-menu) ; defined later in this file.
1864 (defvar org-agenda-restrict nil) ; defined later in this file.
1865 (defvar org-agenda-follow-mode nil)
1866 (defvar org-agenda-entry-text-mode nil)
1867 (defvar org-agenda-clockreport-mode nil)
1868 (defvar org-agenda-show-log nil)
1869 (defvar org-agenda-redo-command nil)
1870 (defvar org-agenda-query-string nil)
1871 (defvar org-agenda-mode-hook nil
1872 "Hook run after `org-agenda-mode' is turned on.
1873 The buffer is still writable when this hook is called.")
1874 (defvar org-agenda-type nil)
1875 (defvar org-agenda-force-single-file nil)
1876 (defvar org-agenda-bulk-marked-entries nil
1877 "List of markers that refer to marked entries in the agenda.")
1879 ;;; Multiple agenda buffers support
1881 (defcustom org-agenda-sticky nil
1882 "Non-nil means agenda q key will bury agenda buffers.
1883 Agenda commands will then show existing buffer instead of generating new ones.
1884 When nil, `q' will kill the single agenda buffer."
1885 :group 'org-agenda
1886 :version "24.3"
1887 :type 'boolean)
1889 ;;;###autoload
1890 (defun org-toggle-sticky-agenda (&optional arg)
1891 "Toggle `org-agenda-sticky'."
1892 (interactive "P")
1893 (let ((new-value (if arg
1894 (> (prefix-numeric-value arg) 0)
1895 (not org-agenda-sticky))))
1896 (if (equal new-value org-agenda-sticky)
1897 (and (org-called-interactively-p 'interactive)
1898 (message "Sticky agenda was already %s"
1899 (if org-agenda-sticky "enabled" "disabled")))
1900 (setq org-agenda-sticky new-value)
1901 (org-agenda-kill-all-agenda-buffers)
1902 (and (org-called-interactively-p 'interactive)
1903 (message "Sticky agenda was %s"
1904 (if org-agenda-sticky "enabled" "disabled"))))))
1906 (defvar org-agenda-buffer nil
1907 "Agenda buffer currently being generated.")
1909 (defvar org-agenda-last-prefix-arg nil)
1910 (defvar org-agenda-this-buffer-name nil)
1911 (defvar org-agenda-doing-sticky-redo nil)
1912 (defvar org-agenda-this-buffer-is-sticky nil)
1914 (defconst org-agenda-local-vars
1915 '(org-agenda-this-buffer-name
1916 org-agenda-undo-list
1917 org-agenda-pending-undo-list
1918 org-agenda-follow-mode
1919 org-agenda-entry-text-mode
1920 org-agenda-clockreport-mode
1921 org-agenda-show-log
1922 org-agenda-redo-command
1923 org-agenda-query-string
1924 org-agenda-type
1925 org-agenda-bulk-marked-entries
1926 org-agenda-undo-has-started-in
1927 org-agenda-info
1928 org-agenda-tag-filter-overlays
1929 org-agenda-cat-filter-overlays
1930 org-agenda-pre-window-conf
1931 org-agenda-columns-active
1932 org-agenda-tag-filter
1933 org-agenda-category-filter
1934 org-agenda-markers
1935 org-agenda-last-search-view-search-was-boolean
1936 org-agenda-filtered-by-category
1937 org-agenda-filter-form
1938 org-agenda-show-window
1939 org-agenda-cycle-counter
1940 org-agenda-last-prefix-arg)
1941 "Variables that must be local in agenda buffers to allow multiple buffers.")
1943 (defun org-agenda-mode ()
1944 "Mode for time-sorted view on action items in Org-mode files.
1946 The following commands are available:
1948 \\{org-agenda-mode-map}"
1949 (interactive)
1950 (cond (org-agenda-doing-sticky-redo
1951 ;; Refreshing sticky agenda-buffer
1953 ;; Preserve the value of `org-agenda-local-vars' variables,
1954 ;; while letting `kill-all-local-variables' kill the rest
1955 (let ((save (buffer-local-variables)))
1956 (kill-all-local-variables)
1957 (mapc 'make-local-variable org-agenda-local-vars)
1958 (dolist (elem save)
1959 (let ((var (car elem))
1960 (val (cdr elem)))
1961 (when (and val
1962 (member var org-agenda-local-vars))
1963 (set var val)))))
1964 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1965 (org-agenda-sticky
1966 ;; Creating a sticky Agenda buffer for the first time
1967 (kill-all-local-variables)
1968 (mapc 'make-local-variable org-agenda-local-vars)
1969 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1971 ;; Creating a non-sticky agenda buffer
1972 (kill-all-local-variables)
1973 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1974 (setq org-agenda-undo-list nil
1975 org-agenda-pending-undo-list nil
1976 org-agenda-bulk-marked-entries nil)
1977 (setq major-mode 'org-agenda-mode)
1978 ;; Keep global-font-lock-mode from turning on font-lock-mode
1979 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1980 (setq mode-name "Org-Agenda")
1981 (use-local-map org-agenda-mode-map)
1982 (easy-menu-add org-agenda-menu)
1983 (if org-startup-truncated (setq truncate-lines t))
1984 (org-set-local 'line-move-visual nil)
1985 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
1986 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1987 ;; Make sure properties are removed when copying text
1988 (make-local-variable 'filter-buffer-substring-functions)
1989 (add-hook 'filter-buffer-substring-functions
1990 (lambda (fun start end delete)
1991 (substring-no-properties (funcall fun start end delete))))
1992 (unless org-agenda-keep-modes
1993 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1994 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1995 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1996 org-agenda-show-log org-agenda-start-with-log-mode))
1998 (easy-menu-change
1999 '("Agenda") "Agenda Files"
2000 (append
2001 (list
2002 (vector
2003 (if (get 'org-agenda-files 'org-restrict)
2004 "Restricted to single file"
2005 "Edit File List")
2006 '(org-edit-agenda-file-list)
2007 (not (get 'org-agenda-files 'org-restrict)))
2008 "--")
2009 (mapcar 'org-file-menu-entry (org-agenda-files))))
2010 (org-agenda-set-mode-name)
2011 (apply
2012 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2013 (list 'org-agenda-mode-hook)))
2015 (substitute-key-definition 'undo 'org-agenda-undo
2016 org-agenda-mode-map global-map)
2017 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2018 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2019 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2020 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2021 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2022 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2023 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2024 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2025 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2026 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2027 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2028 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2029 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2030 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2031 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2032 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2033 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2034 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2035 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2036 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2037 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2038 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2039 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2040 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2041 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2042 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2043 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2044 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2045 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2046 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2047 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2048 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2049 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2050 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2051 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2052 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2053 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2054 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2055 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2056 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2057 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2058 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2059 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2060 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2061 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2063 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2064 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2065 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2066 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2067 (while l (org-defkey org-agenda-mode-map
2068 (int-to-string (pop l)) 'digit-argument)))
2070 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2071 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2072 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2073 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2074 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2075 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2076 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2077 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2078 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2079 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2080 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2081 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2082 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2083 'org-clock-modify-effort-estimate)
2084 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2085 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2086 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2087 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2088 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2089 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2090 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2091 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2092 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2093 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2094 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2095 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2096 (substitute-key-definition 'next-line 'org-agenda-next-line
2097 org-agenda-mode-map global-map)
2098 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2099 org-agenda-mode-map global-map)
2100 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2101 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2102 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2103 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2104 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2105 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2106 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2107 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2108 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2109 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2110 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2111 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2112 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2113 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2114 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2115 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2116 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2117 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2119 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2120 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2121 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2122 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2123 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2124 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2125 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2126 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2127 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2128 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2129 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2131 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2132 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2133 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2134 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2135 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2136 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2137 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2138 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2139 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2140 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2141 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2142 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2144 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2145 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2146 (when org-agenda-mouse-1-follows-link
2147 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2148 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2149 '("Agenda"
2150 ("Agenda Files")
2151 "--"
2152 ("Agenda Dates"
2153 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2154 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2155 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2156 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2157 "--"
2158 ("View"
2159 ["Day View" org-agenda-day-view
2160 :active (org-agenda-check-type nil 'agenda)
2161 :style radio :selected (eq org-agenda-current-span 'day)
2162 :keys "v d (or just d)"]
2163 ["Week View" org-agenda-week-view
2164 :active (org-agenda-check-type nil 'agenda)
2165 :style radio :selected (eq org-agenda-current-span 'week)
2166 :keys "v w (or just w)"]
2167 ["Month View" org-agenda-month-view
2168 :active (org-agenda-check-type nil 'agenda)
2169 :style radio :selected (eq org-agenda-current-span 'month)
2170 :keys "v m"]
2171 ["Year View" org-agenda-year-view
2172 :active (org-agenda-check-type nil 'agenda)
2173 :style radio :selected (eq org-agenda-current-span 'year)
2174 :keys "v y"]
2175 "--"
2176 ["Include Diary" org-agenda-toggle-diary
2177 :style toggle :selected org-agenda-include-diary
2178 :active (org-agenda-check-type nil 'agenda)]
2179 ["Include Deadlines" org-agenda-toggle-deadlines
2180 :style toggle :selected org-agenda-include-deadlines
2181 :active (org-agenda-check-type nil 'agenda)]
2182 ["Use Time Grid" org-agenda-toggle-time-grid
2183 :style toggle :selected org-agenda-use-time-grid
2184 :active (org-agenda-check-type nil 'agenda)]
2185 "--"
2186 ["Show clock report" org-agenda-clockreport-mode
2187 :style toggle :selected org-agenda-clockreport-mode
2188 :active (org-agenda-check-type nil 'agenda)]
2189 ["Show some entry text" org-agenda-entry-text-mode
2190 :style toggle :selected org-agenda-entry-text-mode
2191 :active t]
2192 "--"
2193 ["Show Logbook entries" org-agenda-log-mode
2194 :style toggle :selected org-agenda-show-log
2195 :active (org-agenda-check-type nil 'agenda 'timeline)
2196 :keys "v l (or just l)"]
2197 ["Include archived trees" org-agenda-archives-mode
2198 :style toggle :selected org-agenda-archives-mode :active t
2199 :keys "v a"]
2200 ["Include archive files" (org-agenda-archives-mode t)
2201 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2202 :keys "v A"]
2203 "--"
2204 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2205 ["Write view to file" org-agenda-write t]
2206 ["Rebuild buffer" org-agenda-redo t]
2207 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2208 "--"
2209 ["Show original entry" org-agenda-show t]
2210 ["Go To (other window)" org-agenda-goto t]
2211 ["Go To (this window)" org-agenda-switch-to t]
2212 ["Capture with cursor date" org-agenda-capture t]
2213 ["Follow Mode" org-agenda-follow-mode
2214 :style toggle :selected org-agenda-follow-mode :active t]
2215 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2216 "--"
2217 ("TODO"
2218 ["Cycle TODO" org-agenda-todo t]
2219 ["Next TODO set" org-agenda-todo-nextset t]
2220 ["Previous TODO set" org-agenda-todo-previousset t]
2221 ["Add note" org-agenda-add-note t])
2222 ("Archive/Refile/Delete"
2223 ["Archive default" org-agenda-archive-default t]
2224 ["Archive default" org-agenda-archive-default-with-confirmation t]
2225 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2226 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2227 ["Archive subtree" org-agenda-archive t]
2228 "--"
2229 ["Refile" org-agenda-refile t]
2230 "--"
2231 ["Delete subtree" org-agenda-kill t])
2232 ("Bulk action"
2233 ["Mark entry" org-agenda-bulk-mark t]
2234 ["Mark all" org-agenda-bulk-mark-all t]
2235 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2236 ["Unmark entry" org-agenda-bulk-unmark t]
2237 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2238 ["Act on all marked" org-agenda-bulk-action t]
2239 "--"
2240 ("Tags and Properties"
2241 ["Show all Tags" org-agenda-show-tags t]
2242 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2243 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2244 "--"
2245 ["Column View" org-columns t])
2246 ("Deadline/Schedule"
2247 ["Schedule" org-agenda-schedule t]
2248 ["Set Deadline" org-agenda-deadline t]
2249 "--"
2250 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2251 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2252 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2253 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2254 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2255 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2256 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2257 ("Clock and Effort"
2258 ["Clock in" org-agenda-clock-in t]
2259 ["Clock out" org-agenda-clock-out t]
2260 ["Clock cancel" org-agenda-clock-cancel t]
2261 ["Goto running clock" org-clock-goto t]
2262 "--"
2263 ["Set Effort" org-agenda-set-effort t]
2264 ["Change clocked effort" org-clock-modify-effort-estimate
2265 (org-clock-is-active)])
2266 ("Priority"
2267 ["Set Priority" org-agenda-priority t]
2268 ["Increase Priority" org-agenda-priority-up t]
2269 ["Decrease Priority" org-agenda-priority-down t]
2270 ["Show Priority" org-show-priority t])
2271 ("Calendar/Diary"
2272 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2273 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2274 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2275 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2276 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2277 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2278 "--"
2279 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2280 "--"
2281 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2282 "--"
2283 ("MobileOrg"
2284 ["Push Files and Views" org-mobile-push t]
2285 ["Get Captured and Flagged" org-mobile-pull t]
2286 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2287 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2288 "--"
2289 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2290 "--"
2291 ["Quit" org-agenda-quit t]
2292 ["Exit and Release Buffers" org-agenda-exit t]
2295 ;;; Agenda undo
2297 (defvar org-agenda-allow-remote-undo t
2298 "Non-nil means allow remote undo from the agenda buffer.")
2299 (defvar org-agenda-undo-has-started-in nil
2300 "Buffers that have already seen `undo-start' in the current undo sequence.")
2302 (defun org-agenda-undo ()
2303 "Undo a remote editing step in the agenda.
2304 This undoes changes both in the agenda buffer and in the remote buffer
2305 that have been changed along."
2306 (interactive)
2307 (or org-agenda-allow-remote-undo
2308 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2309 (if (not (eq this-command last-command))
2310 (setq org-agenda-undo-has-started-in nil
2311 org-agenda-pending-undo-list org-agenda-undo-list))
2312 (if (not org-agenda-pending-undo-list)
2313 (error "No further undo information"))
2314 (let* ((entry (pop org-agenda-pending-undo-list))
2315 buf line cmd rembuf)
2316 (setq cmd (pop entry) line (pop entry))
2317 (setq rembuf (nth 2 entry))
2318 (org-with-remote-undo rembuf
2319 (while (bufferp (setq buf (pop entry)))
2320 (if (pop entry)
2321 (with-current-buffer buf
2322 (let ((last-undo-buffer buf)
2323 (inhibit-read-only t))
2324 (unless (memq buf org-agenda-undo-has-started-in)
2325 (push buf org-agenda-undo-has-started-in)
2326 (make-local-variable 'pending-undo-list)
2327 (undo-start))
2328 (while (and pending-undo-list
2329 (listp pending-undo-list)
2330 (not (car pending-undo-list)))
2331 (pop pending-undo-list))
2332 (undo-more 1))))))
2333 (org-goto-line line)
2334 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2336 (defun org-verify-change-for-undo (l1 l2)
2337 "Verify that a real change occurred between the undo lists L1 and L2."
2338 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2339 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2340 (not (eq l1 l2)))
2342 ;;; Agenda dispatch
2344 (defvar org-agenda-restrict-begin (make-marker))
2345 (defvar org-agenda-restrict-end (make-marker))
2346 (defvar org-agenda-last-dispatch-buffer nil)
2347 (defvar org-agenda-overriding-restriction nil)
2349 (defcustom org-agenda-custom-commands-contexts nil
2350 "Alist of custom agenda keys and contextual rules.
2352 For example, if you have a custom agenda command \"p\" and you
2353 want this command to be accessible only from plain text files,
2354 use this:
2356 '((\"p\" (in-file . \"\\.txt\")))
2358 Here are the available contexts definitions:
2360 in-file: command displayed only in matching files
2361 in-mode: command displayed only in matching modes
2362 not-in-file: command not displayed in matching files
2363 not-in-mode: command not displayed in matching modes
2364 [function]: a custom function taking no argument
2366 If you define several checks, the agenda command will be
2367 accessible if there is at least one valid check.
2369 You can also bind a key to another agenda custom command
2370 depending on contextual rules.
2372 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2374 Here it means: in .txt files, use \"p\" as the key for the
2375 agenda command otherwise associated with \"q\". (The command
2376 originally associated with \"q\" is not displayed to avoid
2377 duplicates.)"
2378 :version "24.3"
2379 :group 'org-agenda-custom-commands
2380 :type '(repeat (list :tag "Rule"
2381 (string :tag " Agenda key")
2382 (string :tag "Replace by command")
2383 (repeat :tag "Available when"
2384 (choice
2385 (cons :tag "Condition"
2386 (choice
2387 (const :tag "In file" in-file)
2388 (const :tag "Not in file" not-in-file)
2389 (const :tag "In mode" in-mode)
2390 (const :tag "Not in mode" not-in-mode))
2391 (regexp))
2392 (function :tag "Custom function"))))))
2394 (defvar org-keys nil)
2395 (defvar org-match nil)
2396 ;;;###autoload
2397 (defun org-agenda (&optional arg org-keys restriction)
2398 "Dispatch agenda commands to collect entries to the agenda buffer.
2399 Prompts for a command to execute. Any prefix arg will be passed
2400 on to the selected command. The default selections are:
2402 a Call `org-agenda-list' to display the agenda for current day or week.
2403 t Call `org-todo-list' to display the global todo list.
2404 T Call `org-todo-list' to display the global todo list, select only
2405 entries with a specific TODO keyword (the user gets a prompt).
2406 m Call `org-tags-view' to display headlines with tags matching
2407 a condition (the user is prompted for the condition).
2408 M Like `m', but select only TODO entries, no ordinary headlines.
2409 L Create a timeline for the current buffer.
2410 e Export views to associated files.
2411 s Search entries for keywords.
2412 S Search entries for keywords, only with TODO keywords.
2413 / Multi occur across all agenda files and also files listed
2414 in `org-agenda-text-search-extra-files'.
2415 < Restrict agenda commands to buffer, subtree, or region.
2416 Press several times to get the desired effect.
2417 > Remove a previous restriction.
2418 # List \"stuck\" projects.
2419 ! Configure what \"stuck\" means.
2420 C Configure custom agenda commands.
2422 More commands can be added by configuring the variable
2423 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2424 searches can be pre-defined in this way.
2426 If the current buffer is in Org-mode and visiting a file, you can also
2427 first press `<' once to indicate that the agenda should be temporarily
2428 \(until the next use of \\[org-agenda]) restricted to the current file.
2429 Pressing `<' twice means to restrict to the current subtree or region
2430 \(if active)."
2431 (interactive "P")
2432 (catch 'exit
2433 (let* ((prefix-descriptions nil)
2434 (org-agenda-buffer-name org-agenda-buffer-name)
2435 (org-agenda-window-setup (if (equal (buffer-name)
2436 org-agenda-buffer-name)
2437 'current-window
2438 org-agenda-window-setup))
2439 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2440 (org-agenda-custom-commands
2441 ;; normalize different versions
2442 (delq nil
2443 (mapcar
2444 (lambda (x)
2445 (cond ((stringp (cdr x))
2446 (push x prefix-descriptions)
2447 nil)
2448 ((stringp (nth 1 x)) x)
2449 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2450 (t (cons (car x) (cons "" (cdr x))))))
2451 org-agenda-custom-commands)))
2452 (org-agenda-custom-commands
2453 (org-contextualize-keys
2454 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2455 (buf (current-buffer))
2456 (bfn (buffer-file-name (buffer-base-buffer)))
2457 entry key type org-match lprops ans)
2458 ;; Turn off restriction unless there is an overriding one,
2459 (unless org-agenda-overriding-restriction
2460 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2461 ;; There is a request to keep the file list in place
2462 (put 'org-agenda-files 'org-restrict nil))
2463 (setq org-agenda-restrict nil)
2464 (move-marker org-agenda-restrict-begin nil)
2465 (move-marker org-agenda-restrict-end nil))
2466 ;; Delete old local properties
2467 (put 'org-agenda-redo-command 'org-lprops nil)
2468 ;; Delete previously set last-arguments
2469 (put 'org-agenda-redo-command 'last-args nil)
2470 ;; Remember where this call originated
2471 (setq org-agenda-last-dispatch-buffer (current-buffer))
2472 (unless org-keys
2473 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2474 org-keys (car ans)
2475 restriction (cdr ans)))
2476 ;; If we have sticky agenda buffers, set a name for the buffer,
2477 ;; depending on the invoking keys. The user may still set this
2478 ;; as a command option, which will overwrite what we do here.
2479 (if org-agenda-sticky
2480 (setq org-agenda-buffer-name
2481 (format "*Org Agenda(%s)*" org-keys)))
2482 ;; Establish the restriction, if any
2483 (when (and (not org-agenda-overriding-restriction) restriction)
2484 (put 'org-agenda-files 'org-restrict (list bfn))
2485 (cond
2486 ((eq restriction 'region)
2487 (setq org-agenda-restrict t)
2488 (move-marker org-agenda-restrict-begin (region-beginning))
2489 (move-marker org-agenda-restrict-end (region-end)))
2490 ((eq restriction 'subtree)
2491 (save-excursion
2492 (setq org-agenda-restrict t)
2493 (org-back-to-heading t)
2494 (move-marker org-agenda-restrict-begin (point))
2495 (move-marker org-agenda-restrict-end
2496 (progn (org-end-of-subtree t)))))))
2498 ;; For example the todo list should not need it (but does...)
2499 (cond
2500 ((setq entry (assoc org-keys org-agenda-custom-commands))
2501 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2502 (progn
2503 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2504 lprops (nth 4 entry))
2505 (if org-agenda-sticky
2506 (setq org-agenda-buffer-name
2507 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2508 (format "*Org Agenda(%s)*" org-keys))))
2509 (put 'org-agenda-redo-command 'org-lprops lprops)
2510 (cond
2511 ((eq type 'agenda)
2512 (org-let lprops '(org-agenda-list current-prefix-arg)))
2513 ((eq type 'alltodo)
2514 (org-let lprops '(org-todo-list current-prefix-arg)))
2515 ((eq type 'search)
2516 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2517 ((eq type 'stuck)
2518 (org-let lprops '(org-agenda-list-stuck-projects
2519 current-prefix-arg)))
2520 ((eq type 'tags)
2521 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2522 ((eq type 'tags-todo)
2523 (org-let lprops '(org-tags-view '(4) org-match)))
2524 ((eq type 'todo)
2525 (org-let lprops '(org-todo-list org-match)))
2526 ((eq type 'tags-tree)
2527 (org-check-for-org-mode)
2528 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2529 ((eq type 'todo-tree)
2530 (org-check-for-org-mode)
2531 (org-let lprops
2532 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2533 (regexp-quote org-match) "\\>"))))
2534 ((eq type 'occur-tree)
2535 (org-check-for-org-mode)
2536 (org-let lprops '(org-occur org-match)))
2537 ((functionp type)
2538 (org-let lprops '(funcall type org-match)))
2539 ((fboundp type)
2540 (org-let lprops '(funcall type org-match)))
2541 (t (error "Invalid custom agenda command type %s" type))))
2542 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2543 ((equal org-keys "C")
2544 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2545 (customize-variable 'org-agenda-custom-commands))
2546 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2547 ((equal org-keys "s") (call-interactively 'org-search-view))
2548 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2549 ((equal org-keys "t") (call-interactively 'org-todo-list))
2550 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2551 ((equal org-keys "m") (call-interactively 'org-tags-view))
2552 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2553 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2554 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2555 (org-add-hook
2556 'post-command-hook
2557 (lambda ()
2558 (unless (current-message)
2559 (let* ((m (org-agenda-get-any-marker))
2560 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2561 (when note
2562 (message (concat
2563 "FLAGGING-NOTE ([?] for more info): "
2564 (org-add-props
2565 (replace-regexp-in-string
2566 "\\\\n" "//"
2567 (copy-sequence note))
2568 nil 'face 'org-warning)))))))
2569 t t))
2570 ((equal org-keys "L")
2571 (unless (derived-mode-p 'org-mode)
2572 (error "This is not an Org-mode file"))
2573 (unless restriction
2574 (put 'org-agenda-files 'org-restrict (list bfn))
2575 (org-call-with-arg 'org-timeline arg)))
2576 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2577 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2578 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2579 (t (error "Invalid agenda key"))))))
2581 (defun org-agenda-append-agenda ()
2582 "Append another agenda view to the current one.
2583 This function allows interactive building of block agendas.
2584 Agenda views are separated by `org-agenda-block-separator'."
2585 (interactive)
2586 (unless (derived-mode-p 'org-agenda-mode)
2587 (error "Can only append from within agenda buffer"))
2588 (let ((org-agenda-multi t))
2589 (org-agenda)
2590 (widen)
2591 (org-agenda-finalize)
2592 (org-agenda-fit-window-to-buffer)))
2594 (defun org-agenda-normalize-custom-commands (cmds)
2595 (delq nil
2596 (mapcar
2597 (lambda (x)
2598 (cond ((stringp (cdr x)) nil)
2599 ((stringp (nth 1 x)) x)
2600 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2601 (t (cons (car x) (cons "" (cdr x))))))
2602 cmds)))
2604 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2605 "The user interface for selecting an agenda command."
2606 (catch 'exit
2607 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2608 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2609 (region-p (org-region-active-p))
2610 (custom org-agenda-custom-commands)
2611 (selstring "")
2612 restriction second-time
2613 c entry key type match prefixes rmheader header-end custom1 desc
2614 line lines left right n n1)
2615 (save-window-excursion
2616 (delete-other-windows)
2617 (org-switch-to-buffer-other-window " *Agenda Commands*")
2618 (erase-buffer)
2619 (insert (eval-when-compile
2620 (let ((header
2621 "Press key for an agenda command: < Buffer, subtree/region restriction
2622 -------------------------------- > Remove restriction
2623 a Agenda for current week or day e Export agenda views
2624 t List of all TODO entries T Entries with special TODO kwd
2625 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2626 s Search for keywords S Like s, but only TODO entries
2627 L Timeline for current buffer # List stuck projects (!=configure)
2628 / Multi-occur C Configure custom agenda commands
2629 ? Find :FLAGGED: entries * Toggle sticky agenda views
2631 (start 0))
2632 (while (string-match
2633 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2634 header start)
2635 (setq start (match-end 0))
2636 (add-text-properties (match-beginning 2) (match-end 2)
2637 '(face bold) header))
2638 header)))
2639 (setq header-end (move-marker (make-marker) (point)))
2640 (while t
2641 (setq custom1 custom)
2642 (when (eq rmheader t)
2643 (org-goto-line 1)
2644 (re-search-forward ":" nil t)
2645 (delete-region (match-end 0) (point-at-eol))
2646 (forward-char 1)
2647 (looking-at "-+")
2648 (delete-region (match-end 0) (point-at-eol))
2649 (move-marker header-end (match-end 0)))
2650 (goto-char header-end)
2651 (delete-region (point) (point-max))
2653 ;; Produce all the lines that describe custom commands and prefixes
2654 (setq lines nil)
2655 (while (setq entry (pop custom1))
2656 (setq key (car entry) desc (nth 1 entry)
2657 type (nth 2 entry)
2658 match (nth 3 entry))
2659 (if (> (length key) 1)
2660 (add-to-list 'prefixes (string-to-char key))
2661 (setq line
2662 (format
2663 "%-4s%-14s"
2664 (org-add-props (copy-sequence key)
2665 '(face bold))
2666 (cond
2667 ((string-match "\\S-" desc) desc)
2668 ((eq type 'agenda) "Agenda for current week or day")
2669 ((eq type 'alltodo) "List of all TODO entries")
2670 ((eq type 'search) "Word search")
2671 ((eq type 'stuck) "List of stuck projects")
2672 ((eq type 'todo) "TODO keyword")
2673 ((eq type 'tags) "Tags query")
2674 ((eq type 'tags-todo) "Tags (TODO)")
2675 ((eq type 'tags-tree) "Tags tree")
2676 ((eq type 'todo-tree) "TODO kwd tree")
2677 ((eq type 'occur-tree) "Occur tree")
2678 ((functionp type) (if (symbolp type)
2679 (symbol-name type)
2680 "Lambda expression"))
2681 (t "???"))))
2682 (if org-agenda-menu-show-matcher
2683 (setq line
2684 (concat line ": "
2685 (cond
2686 ((stringp match)
2687 (setq match (copy-sequence match))
2688 (org-add-props match nil 'face 'org-warning))
2689 ((listp type)
2690 (format "set of %d commands" (length type))))))
2691 (if (org-string-nw-p match)
2692 (add-text-properties
2693 0 (length line) (list 'help-echo
2694 (concat "Matcher: " match)) line)))
2695 (push line lines)))
2696 (setq lines (nreverse lines))
2697 (when prefixes
2698 (mapc (lambda (x)
2699 (push
2700 (format "%s %s"
2701 (org-add-props (char-to-string x)
2702 nil 'face 'bold)
2703 (or (cdr (assoc (concat selstring
2704 (char-to-string x))
2705 prefix-descriptions))
2706 "Prefix key"))
2707 lines))
2708 prefixes))
2710 ;; Check if we should display in two columns
2711 (if org-agenda-menu-two-columns
2712 (progn
2713 (setq n (length lines)
2714 n1 (+ (/ n 2) (mod n 2))
2715 right (nthcdr n1 lines)
2716 left (copy-sequence lines))
2717 (setcdr (nthcdr (1- n1) left) nil))
2718 (setq left lines right nil))
2719 (while left
2720 (insert "\n" (pop left))
2721 (when right
2722 (if (< (current-column) 40)
2723 (move-to-column 40 t)
2724 (insert " "))
2725 (insert (pop right))))
2727 ;; Make the window the right size
2728 (goto-char (point-min))
2729 (if second-time
2730 (if (not (pos-visible-in-window-p (point-max)))
2731 (org-fit-window-to-buffer))
2732 (setq second-time t)
2733 (org-fit-window-to-buffer))
2735 ;; Ask for selection
2736 (message "Press key for agenda command%s:"
2737 (if (or restrict-ok org-agenda-overriding-restriction)
2738 (if org-agenda-overriding-restriction
2739 " (restriction lock active)"
2740 (if restriction
2741 (format " (restricted to %s)" restriction)
2742 " (unrestricted)"))
2743 ""))
2744 (setq c (read-char-exclusive))
2745 (message "")
2746 (cond
2747 ((assoc (char-to-string c) custom)
2748 (setq selstring (concat selstring (char-to-string c)))
2749 (throw 'exit (cons selstring restriction)))
2750 ((memq c prefixes)
2751 (setq selstring (concat selstring (char-to-string c))
2752 prefixes nil
2753 rmheader (or rmheader t)
2754 custom (delq nil (mapcar
2755 (lambda (x)
2756 (if (or (= (length (car x)) 1)
2757 (/= (string-to-char (car x)) c))
2759 (cons (substring (car x) 1) (cdr x))))
2760 custom))))
2761 ((eq c ?*)
2762 (call-interactively 'org-toggle-sticky-agenda)
2763 (sit-for 2))
2764 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2765 (message "Restriction is only possible in Org-mode buffers")
2766 (ding) (sit-for 1))
2767 ((eq c ?1)
2768 (org-agenda-remove-restriction-lock 'noupdate)
2769 (setq restriction 'buffer))
2770 ((eq c ?0)
2771 (org-agenda-remove-restriction-lock 'noupdate)
2772 (setq restriction (if region-p 'region 'subtree)))
2773 ((eq c ?<)
2774 (org-agenda-remove-restriction-lock 'noupdate)
2775 (setq restriction
2776 (cond
2777 ((eq restriction 'buffer)
2778 (if region-p 'region 'subtree))
2779 ((memq restriction '(subtree region))
2780 nil)
2781 (t 'buffer))))
2782 ((eq c ?>)
2783 (org-agenda-remove-restriction-lock 'noupdate)
2784 (setq restriction nil))
2785 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2786 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2787 ((and (> (length selstring) 0) (eq c ?\d))
2788 (delete-window)
2789 (org-agenda-get-restriction-and-command prefix-descriptions))
2791 ((equal c ?q) (error "Abort"))
2792 (t (error "Invalid key %c" c))))))))
2794 (defun org-agenda-fit-window-to-buffer ()
2795 "Fit the window to the buffer size."
2796 (and (memq org-agenda-window-setup '(reorganize-frame))
2797 (fboundp 'fit-window-to-buffer)
2798 (org-fit-window-to-buffer
2800 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2801 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2803 (defvar org-cmd nil)
2804 (defvar org-agenda-overriding-cmd nil)
2805 (defvar org-agenda-overriding-arguments nil)
2806 (defvar org-agenda-overriding-cmd-arguments nil)
2807 (defun org-agenda-run-series (name series)
2808 (org-let (nth 1 series) '(org-agenda-prepare name))
2809 ;; We need to reset agenda markers here, because when constructing a
2810 ;; block agenda, the individual blocks do not do that.
2811 (org-agenda-reset-markers)
2812 (let* ((org-agenda-multi t)
2813 (redo (list 'org-agenda-run-series name (list 'quote series)))
2814 (cmds (car series))
2815 (gprops (nth 1 series))
2816 match ;; The byte compiler incorrectly complains about this. Keep it!
2817 org-cmd type lprops)
2818 (while (setq org-cmd (pop cmds))
2819 (setq type (car org-cmd)
2820 match (eval (nth 1 org-cmd))
2821 lprops (nth 2 org-cmd))
2822 (let ((org-agenda-overriding-arguments
2823 (if (eq org-agenda-overriding-cmd org-cmd)
2824 (or org-agenda-overriding-arguments
2825 org-agenda-overriding-cmd-arguments))))
2826 (cond
2827 ((eq type 'agenda)
2828 (org-let2 gprops lprops
2829 '(call-interactively 'org-agenda-list)))
2830 ((eq type 'alltodo)
2831 (org-let2 gprops lprops
2832 '(call-interactively 'org-todo-list)))
2833 ((eq type 'search)
2834 (org-let2 gprops lprops
2835 '(org-search-view current-prefix-arg match nil)))
2836 ((eq type 'stuck)
2837 (org-let2 gprops lprops
2838 '(call-interactively 'org-agenda-list-stuck-projects)))
2839 ((eq type 'tags)
2840 (org-let2 gprops lprops
2841 '(org-tags-view current-prefix-arg match)))
2842 ((eq type 'tags-todo)
2843 (org-let2 gprops lprops
2844 '(org-tags-view '(4) match)))
2845 ((eq type 'todo)
2846 (org-let2 gprops lprops
2847 '(org-todo-list match)))
2848 ((fboundp type)
2849 (org-let2 gprops lprops
2850 '(funcall type match)))
2851 (t (error "Invalid type in command series")))))
2852 (widen)
2853 (let ((inhibit-read-only t))
2854 (add-text-properties (point-min) (point-max)
2855 `(org-serie t org-serie-redo-cmd ,redo)))
2856 (setq org-agenda-redo-command redo)
2857 (goto-char (point-min)))
2858 (org-agenda-fit-window-to-buffer)
2859 (org-let (nth 1 series) '(org-agenda-finalize)))
2861 ;;;###autoload
2862 (defmacro org-batch-agenda (cmd-key &rest parameters)
2863 "Run an agenda command in batch mode and send the result to STDOUT.
2864 If CMD-KEY is a string of length 1, it is used as a key in
2865 `org-agenda-custom-commands' and triggers this command. If it is a
2866 longer string it is used as a tags/todo match string.
2867 Parameters are alternating variable names and values that will be bound
2868 before running the agenda command."
2869 (org-eval-in-environment (org-make-parameter-alist parameters)
2870 (if (> (length cmd-key) 2)
2871 (org-tags-view nil cmd-key)
2872 (org-agenda nil cmd-key)))
2873 (set-buffer org-agenda-buffer-name)
2874 (princ (buffer-string)))
2875 (def-edebug-spec org-batch-agenda (form &rest sexp))
2877 (defvar org-agenda-info nil)
2879 ;;;###autoload
2880 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2881 "Run an agenda command in batch mode and send the result to STDOUT.
2882 If CMD-KEY is a string of length 1, it is used as a key in
2883 `org-agenda-custom-commands' and triggers this command. If it is a
2884 longer string it is used as a tags/todo match string.
2885 Parameters are alternating variable names and values that will be bound
2886 before running the agenda command.
2888 The output gives a line for each selected agenda item. Each
2889 item is a list of comma-separated values, like this:
2891 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2893 category The category of the item
2894 head The headline, without TODO kwd, TAGS and PRIORITY
2895 type The type of the agenda entry, can be
2896 todo selected in TODO match
2897 tagsmatch selected in tags match
2898 diary imported from diary
2899 deadline a deadline on given date
2900 scheduled scheduled on given date
2901 timestamp entry has timestamp on given date
2902 closed entry was closed on given date
2903 upcoming-deadline warning about deadline
2904 past-scheduled forwarded scheduled item
2905 block entry has date block including g. date
2906 todo The todo keyword, if any
2907 tags All tags including inherited ones, separated by colons
2908 date The relevant date, like 2007-2-14
2909 time The time, like 15:00-16:50
2910 extra Sting with extra planning info
2911 priority-l The priority letter if any was given
2912 priority-n The computed numerical priority
2913 agenda-day The day in the agenda where this is listed"
2914 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2915 (org-make-parameter-alist parameters))
2916 (if (> (length cmd-key) 2)
2917 (org-tags-view nil cmd-key)
2918 (org-agenda nil cmd-key)))
2919 (set-buffer org-agenda-buffer-name)
2920 (let* ((lines (org-split-string (buffer-string) "\n"))
2921 line)
2922 (while (setq line (pop lines))
2923 (catch 'next
2924 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2925 (setq org-agenda-info
2926 (org-fix-agenda-info (text-properties-at 0 line)))
2927 (princ
2928 (mapconcat 'org-agenda-export-csv-mapper
2929 '(org-category txt type todo tags date time extra
2930 priority-letter priority agenda-day)
2931 ","))
2932 (princ "\n")))))
2933 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2935 (defun org-fix-agenda-info (props)
2936 "Make sure all properties on an agenda item have a canonical form.
2937 This ensures the export commands can easily use it."
2938 (let (tmp re)
2939 (when (setq tmp (plist-get props 'tags))
2940 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2941 (when (setq tmp (plist-get props 'date))
2942 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2943 (let ((calendar-date-display-form '(year "-" month "-" day)))
2944 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2946 (setq tmp (calendar-date-string tmp)))
2947 (setq props (plist-put props 'date tmp)))
2948 (when (setq tmp (plist-get props 'day))
2949 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2950 (let ((calendar-date-display-form '(year "-" month "-" day)))
2951 (setq tmp (calendar-date-string tmp)))
2952 (setq props (plist-put props 'day tmp))
2953 (setq props (plist-put props 'agenda-day tmp)))
2954 (when (setq tmp (plist-get props 'txt))
2955 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2956 (plist-put props 'priority-letter (match-string 1 tmp))
2957 (setq tmp (replace-match "" t t tmp)))
2958 (when (and (setq re (plist-get props 'org-todo-regexp))
2959 (setq re (concat "\\`\\.*" re " ?"))
2960 (string-match re tmp))
2961 (plist-put props 'todo (match-string 1 tmp))
2962 (setq tmp (replace-match "" t t tmp)))
2963 (plist-put props 'txt tmp)))
2964 props)
2966 (defun org-agenda-export-csv-mapper (prop)
2967 (let ((res (plist-get org-agenda-info prop)))
2968 (setq res
2969 (cond
2970 ((not res) "")
2971 ((stringp res) res)
2972 (t (prin1-to-string res))))
2973 (while (string-match "," res)
2974 (setq res (replace-match ";" t t res)))
2975 (org-trim res)))
2977 ;;;###autoload
2978 (defun org-store-agenda-views (&rest parameters)
2979 (interactive)
2980 (eval (list 'org-batch-store-agenda-views)))
2982 ;;;###autoload
2983 (defmacro org-batch-store-agenda-views (&rest parameters)
2984 "Run all custom agenda commands that have a file argument."
2985 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2986 (pop-up-frames nil)
2987 (dir default-directory)
2988 (pars (org-make-parameter-alist parameters))
2989 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
2990 (save-window-excursion
2991 (while cmds
2992 (setq cmd (pop cmds)
2993 thiscmdkey (car cmd)
2994 thiscmdcmd (cdr cmd)
2995 match (nth 2 thiscmdcmd)
2996 bufname (if org-agenda-sticky
2997 (or (and (stringp match)
2998 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
2999 (format "*Org Agenda(%s)*" thiscmdkey))
3000 org-agenda-buffer-name)
3001 cmd-or-set (nth 2 cmd)
3002 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3003 files (nth (if (listp cmd-or-set) 4 5) cmd))
3004 (if (stringp files) (setq files (list files)))
3005 (when files
3006 (org-eval-in-environment (append org-agenda-exporter-settings
3007 opts pars)
3008 (org-agenda nil thiscmdkey))
3009 (set-buffer bufname)
3010 (while files
3011 (org-eval-in-environment (append org-agenda-exporter-settings
3012 opts pars)
3013 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3014 (and (get-buffer bufname)
3015 (kill-buffer bufname)))))))
3016 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3018 (defvar org-agenda-current-span nil
3019 "The current span used in the agenda view.") ; local variable in the agenda buffer
3020 (defun org-agenda-mark-header-line (pos)
3021 "Mark the line at POS as an agenda structure header."
3022 (save-excursion
3023 (goto-char pos)
3024 (put-text-property (point-at-bol) (point-at-eol)
3025 'org-agenda-structural-header t)
3026 (when org-agenda-title-append
3027 (put-text-property (point-at-bol) (point-at-eol)
3028 'org-agenda-title-append org-agenda-title-append))))
3030 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3031 (defvar org-agenda-write-buffer-name "Agenda View")
3032 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3033 "Write the current buffer (an agenda view) as a file.
3034 Depending on the extension of the file name, plain text (.txt),
3035 HTML (.html or .htm) or Postscript (.ps) is produced.
3036 If the extension is .ics, run icalendar export over all files used
3037 to construct the agenda and limit the export to entries listed in the
3038 agenda now.
3039 With prefix argument OPEN, open the new file immediately.
3040 If NOSETTINGS is given, do not scope the settings of
3041 `org-agenda-exporter-settings' into the export commands. This is used when
3042 the settings have already been scoped and we do not wish to overrule other,
3043 higher priority settings.
3044 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3045 (interactive "FWrite agenda to file: \nP")
3046 (if (not (file-writable-p file))
3047 (error "Cannot write agenda to file %s" file))
3048 (org-let (if nosettings nil org-agenda-exporter-settings)
3049 '(save-excursion
3050 (save-window-excursion
3051 (org-agenda-mark-filtered-text)
3052 (let ((bs (copy-sequence (buffer-string))) beg)
3053 (org-agenda-unmark-filtered-text)
3054 (with-temp-buffer
3055 (rename-buffer org-agenda-write-buffer-name t)
3056 (set-buffer-modified-p nil)
3057 (insert bs)
3058 (org-agenda-remove-marked-text 'org-filtered)
3059 (while (setq beg (text-property-any (point-min) (point-max)
3060 'org-filtered t))
3061 (delete-region
3062 beg (or (next-single-property-change beg 'org-filtered)
3063 (point-max))))
3064 (run-hooks 'org-agenda-before-write-hook)
3065 (cond
3066 ((org-bound-and-true-p org-mobile-creating-agendas)
3067 (org-mobile-write-agenda-for-mobile file))
3068 ((string-match "\\.html?\\'" file)
3069 (require 'htmlize)
3070 (set-buffer (htmlize-buffer (current-buffer)))
3071 (when org-agenda-export-html-style
3072 ;; replace <style> section with org-agenda-export-html-style
3073 (goto-char (point-min))
3074 (kill-region (- (search-forward "<style") 6)
3075 (search-forward "</style>"))
3076 (insert org-agenda-export-html-style))
3077 (write-file file)
3078 (kill-buffer (current-buffer))
3079 (message "HTML written to %s" file))
3080 ((string-match "\\.ps\\'" file)
3081 (require 'ps-print)
3082 (ps-print-buffer-with-faces file)
3083 (message "Postscript written to %s" file))
3084 ((string-match "\\.pdf\\'" file)
3085 (require 'ps-print)
3086 (ps-print-buffer-with-faces
3087 (concat (file-name-sans-extension file) ".ps"))
3088 (call-process "ps2pdf" nil nil nil
3089 (expand-file-name
3090 (concat (file-name-sans-extension file) ".ps"))
3091 (expand-file-name file))
3092 (delete-file (concat (file-name-sans-extension file) ".ps"))
3093 (message "PDF written to %s" file))
3094 ((string-match "\\.ics\\'" file)
3095 (require 'org-icalendar)
3096 (let ((org-agenda-marker-table
3097 (org-create-marker-find-array
3098 (org-agenda-collect-markers)))
3099 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3100 (org-combined-agenda-icalendar-file file))
3101 (apply 'org-export-icalendar 'combine
3102 (org-agenda-files nil 'ifmode))))
3104 (let ((bs (buffer-string)))
3105 (find-file file)
3106 (erase-buffer)
3107 (insert bs)
3108 (save-buffer 0)
3109 (kill-buffer (current-buffer))
3110 (message "Plain text written to %s" file))))))))
3111 (set-buffer (or agenda-bufname
3112 (and (called-interactively-p 'any) (buffer-name))
3113 org-agenda-buffer-name)))
3114 (when open (org-open-file file)))
3116 (defvar org-agenda-tag-filter-overlays nil)
3117 (defvar org-agenda-cat-filter-overlays nil)
3119 (defun org-agenda-mark-filtered-text ()
3120 "Mark all text hidden by filtering with a text property."
3121 (let ((inhibit-read-only t))
3122 (mapc
3123 (lambda (o)
3124 (when (equal (overlay-buffer o) (current-buffer))
3125 (put-text-property
3126 (overlay-start o) (overlay-end o)
3127 'org-filtered t)))
3128 (append org-agenda-tag-filter-overlays
3129 org-agenda-cat-filter-overlays))))
3131 (defun org-agenda-unmark-filtered-text ()
3132 "Remove the filtering text property."
3133 (let ((inhibit-read-only t))
3134 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3136 (defun org-agenda-remove-marked-text (property &optional value)
3137 "Delete all text marked with VALUE of PROPERTY.
3138 VALUE defaults to t."
3139 (let (beg)
3140 (setq value (or value t))
3141 (while (setq beg (text-property-any (point-min) (point-max)
3142 property value))
3143 (delete-region
3144 beg (or (next-single-property-change beg 'org-filtered)
3145 (point-max))))))
3147 (defun org-agenda-add-entry-text ()
3148 "Add entry text to agenda lines.
3149 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3150 entry text following headings shown in the agenda.
3151 Drawers will be excluded, also the line with scheduling/deadline info."
3152 (when (and (> org-agenda-add-entry-text-maxlines 0)
3153 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3154 (let (m txt)
3155 (goto-char (point-min))
3156 (while (not (eobp))
3157 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3158 (beginning-of-line 2)
3159 (setq txt (org-agenda-get-some-entry-text
3160 m org-agenda-add-entry-text-maxlines " > "))
3161 (end-of-line 1)
3162 (if (string-match "\\S-" txt)
3163 (insert "\n" txt)
3164 (or (eobp) (forward-char 1))))))))
3166 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3167 &rest keep)
3168 "Extract entry text from MARKER, at most N-LINES lines.
3169 This will ignore drawers etc, just get the text.
3170 If INDENT is given, prefix every line with this string. If KEEP is
3171 given, it is a list of symbols, defining stuff that should not be
3172 removed from the entry content. Currently only `planning' is allowed here."
3173 (let (txt drawer-re kwd-time-re ind)
3174 (save-excursion
3175 (with-current-buffer (marker-buffer marker)
3176 (if (not (derived-mode-p 'org-mode))
3177 (setq txt "")
3178 (save-excursion
3179 (save-restriction
3180 (widen)
3181 (goto-char marker)
3182 (end-of-line 1)
3183 (setq txt (buffer-substring
3184 (min (1+ (point)) (point-max))
3185 (progn (outline-next-heading) (point)))
3186 drawer-re org-drawer-regexp
3187 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3188 ".*\n?"))
3189 (with-temp-buffer
3190 (insert txt)
3191 (when org-agenda-add-entry-text-descriptive-links
3192 (goto-char (point-min))
3193 (while (org-activate-bracket-links (point-max))
3194 (add-text-properties (match-beginning 0) (match-end 0)
3195 '(face org-link))))
3196 (goto-char (point-min))
3197 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3198 (set-text-properties (match-beginning 0) (match-end 0)
3199 nil))
3200 (goto-char (point-min))
3201 (while (re-search-forward drawer-re nil t)
3202 (delete-region
3203 (match-beginning 0)
3204 (progn (re-search-forward
3205 "^[ \t]*:END:.*\n?" nil 'move)
3206 (point))))
3207 (unless (member 'planning keep)
3208 (goto-char (point-min))
3209 (while (re-search-forward kwd-time-re nil t)
3210 (replace-match "")))
3211 (goto-char (point-min))
3212 (when org-agenda-entry-text-exclude-regexps
3213 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3214 (while (setq re (pop re-list))
3215 (goto-char (point-min))
3216 (while (re-search-forward re nil t)
3217 (replace-match "")))))
3218 (goto-char (point-max))
3219 (skip-chars-backward " \t\n")
3220 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3222 ;; find and remove min common indentation
3223 (goto-char (point-min))
3224 (untabify (point-min) (point-max))
3225 (setq ind (org-get-indentation))
3226 (while (not (eobp))
3227 (unless (looking-at "[ \t]*$")
3228 (setq ind (min ind (org-get-indentation))))
3229 (beginning-of-line 2))
3230 (goto-char (point-min))
3231 (while (not (eobp))
3232 (unless (looking-at "[ \t]*$")
3233 (move-to-column ind)
3234 (delete-region (point-at-bol) (point)))
3235 (beginning-of-line 2))
3237 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3239 (goto-char (point-min))
3240 (when indent
3241 (while (and (not (eobp)) (re-search-forward "^" nil t))
3242 (replace-match indent t t)))
3243 (goto-char (point-min))
3244 (while (looking-at "[ \t]*\n") (replace-match ""))
3245 (goto-char (point-max))
3246 (when (> (org-current-line)
3247 n-lines)
3248 (org-goto-line (1+ n-lines))
3249 (backward-char 1))
3250 (setq txt (buffer-substring (point-min) (point)))))))))
3251 txt))
3253 (defun org-agenda-collect-markers ()
3254 "Collect the markers pointing to entries in the agenda buffer."
3255 (let (m markers)
3256 (save-excursion
3257 (goto-char (point-min))
3258 (while (not (eobp))
3259 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3260 (org-get-at-bol 'org-marker)))
3261 (push m markers))
3262 (beginning-of-line 2)))
3263 (nreverse markers)))
3265 (defun org-create-marker-find-array (marker-list)
3266 "Create a alist of files names with all marker positions in that file."
3267 (let (f tbl m a p)
3268 (while (setq m (pop marker-list))
3269 (setq p (marker-position m)
3270 f (buffer-file-name (or (buffer-base-buffer
3271 (marker-buffer m))
3272 (marker-buffer m))))
3273 (if (setq a (assoc f tbl))
3274 (push (marker-position m) (cdr a))
3275 (push (list f p) tbl)))
3276 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3277 tbl)))
3279 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3280 (defun org-check-agenda-marker-table ()
3281 "Check of the current entry is on the marker list."
3282 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3284 (and (setq a (assoc file org-agenda-marker-table))
3285 (save-match-data
3286 (save-excursion
3287 (org-back-to-heading t)
3288 (member (point) (cdr a)))))))
3290 (defun org-check-for-org-mode ()
3291 "Make sure current buffer is in org-mode. Error if not."
3292 (or (derived-mode-p 'org-mode)
3293 (error "Cannot execute org-mode agenda command on buffer in %s"
3294 major-mode)))
3296 ;;; Agenda prepare and finalize
3298 (defvar org-agenda-multi nil) ; dynamically scoped
3299 (defvar org-agenda-pre-window-conf nil)
3300 (defvar org-agenda-columns-active nil)
3301 (defvar org-agenda-name nil)
3302 (defvar org-agenda-tag-filter nil)
3303 (defvar org-agenda-category-filter nil)
3304 (defvar org-agenda-top-category-filter nil)
3305 (defvar org-agenda-tag-filter-while-redo nil)
3306 (defvar org-agenda-tag-filter-preset nil
3307 "A preset of the tags filter used for secondary agenda filtering.
3308 This must be a list of strings, each string must be a single tag preceded
3309 by \"+\" or \"-\".
3310 This variable should not be set directly, but agenda custom commands can
3311 bind it in the options section. The preset filter is a global property of
3312 the entire agenda view. In a block agenda, it will not work reliably to
3313 define a filter for one of the individual blocks. You need to set it in
3314 the global options and expect it to be applied to the entire view.")
3316 (defvar org-agenda-category-filter-preset nil
3317 "A preset of the category filter used for secondary agenda filtering.
3318 This must be a list of strings, each string must be a single category
3319 preceded by \"+\" or \"-\".
3320 This variable should not be set directly, but agenda custom commands can
3321 bind it in the options section. The preset filter is a global property of
3322 the entire agenda view. In a block agenda, it will not work reliably to
3323 define a filter for one of the individual blocks. You need to set it in
3324 the global options and expect it to be applied to the entire view.")
3327 (defun org-agenda-use-sticky-p ()
3328 "Return non-nil if an agenda buffer named
3329 `org-agenda-buffer-name' exists and should be shown instead of
3330 generating a new one."
3331 (and
3332 ;; turned off by user
3333 org-agenda-sticky
3334 ;; For multi-agenda buffer already exists
3335 (not org-agenda-multi)
3336 ;; buffer found
3337 (get-buffer org-agenda-buffer-name)
3338 ;; C-u parameter is same as last call
3339 (with-current-buffer (get-buffer org-agenda-buffer-name)
3340 (and
3341 (equal current-prefix-arg
3342 org-agenda-last-prefix-arg)
3343 ;; In case user turned stickiness on, while having existing
3344 ;; Agenda buffer active, don't reuse that buffer, because it
3345 ;; does not have org variables local
3346 org-agenda-this-buffer-is-sticky))))
3348 (defun org-agenda-prepare-window (abuf)
3349 "Setup agenda buffer in the window."
3350 (let* ((awin (get-buffer-window abuf))
3351 wconf)
3352 (cond
3353 ((equal (current-buffer) abuf) nil)
3354 (awin (select-window awin))
3355 ((not (setq wconf (current-window-configuration))))
3356 ((equal org-agenda-window-setup 'current-window)
3357 (org-pop-to-buffer-same-window abuf))
3358 ((equal org-agenda-window-setup 'other-window)
3359 (org-switch-to-buffer-other-window abuf))
3360 ((equal org-agenda-window-setup 'other-frame)
3361 (switch-to-buffer-other-frame abuf))
3362 ((equal org-agenda-window-setup 'reorganize-frame)
3363 (delete-other-windows)
3364 (org-switch-to-buffer-other-window abuf)))
3365 ;; additional test in case agenda is invoked from within agenda
3366 ;; buffer via elisp link
3367 (unless (equal (current-buffer) abuf)
3368 (org-pop-to-buffer-same-window abuf))
3369 (setq org-agenda-pre-window-conf
3370 (or org-agenda-pre-window-conf wconf))))
3372 (defun org-agenda-prepare (&optional name)
3373 (if (org-agenda-use-sticky-p)
3374 (progn
3375 ;; Popup existing buffer
3376 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3377 (message "Sticky Agenda buffer, use `r' to refresh")
3378 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3379 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3380 (setq org-todo-keywords-for-agenda nil)
3381 (setq org-drawers-for-agenda nil)
3382 (unless org-agenda-persistent-filter
3383 (setq org-agenda-tag-filter nil
3384 org-agenda-category-filter nil))
3385 (put 'org-agenda-tag-filter :preset-filter
3386 org-agenda-tag-filter-preset)
3387 (put 'org-agenda-category-filter :preset-filter
3388 org-agenda-category-filter-preset)
3389 (if org-agenda-multi
3390 (progn
3391 (setq buffer-read-only nil)
3392 (goto-char (point-max))
3393 (unless (or (bobp) org-agenda-compact-blocks
3394 (not org-agenda-block-separator))
3395 (insert "\n"
3396 (if (stringp org-agenda-block-separator)
3397 org-agenda-block-separator
3398 (make-string (window-width) org-agenda-block-separator))
3399 "\n"))
3400 (narrow-to-region (point) (point-max)))
3401 (setq org-done-keywords-for-agenda nil)
3403 ;; Setting any org variables that are in org-agenda-local-vars
3404 ;; list need to be done after the prepare call
3405 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3406 (setq buffer-read-only nil)
3407 (org-agenda-reset-markers)
3408 (let ((inhibit-read-only t)) (erase-buffer))
3409 (org-agenda-mode)
3410 (setq org-agenda-buffer (current-buffer))
3411 (setq org-agenda-contributing-files nil)
3412 (setq org-agenda-columns-active nil)
3413 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3414 (setq org-todo-keywords-for-agenda
3415 (org-uniquify org-todo-keywords-for-agenda))
3416 (setq org-done-keywords-for-agenda
3417 (org-uniquify org-done-keywords-for-agenda))
3418 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3419 (setq org-agenda-last-prefix-arg current-prefix-arg)
3420 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3421 (and name (not org-agenda-name)
3422 (org-set-local 'org-agenda-name name)))
3423 (setq buffer-read-only nil)))
3425 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3426 (defun org-agenda-finalize ()
3427 "Finishing touch for the agenda buffer, called just before displaying it."
3428 (unless org-agenda-multi
3429 (save-excursion
3430 (let ((inhibit-read-only t))
3431 (goto-char (point-min))
3432 (while (org-activate-bracket-links (point-max))
3433 (add-text-properties (match-beginning 0) (match-end 0)
3434 '(face org-link)))
3435 (org-agenda-align-tags)
3436 (unless org-agenda-with-colors
3437 (remove-text-properties (point-min) (point-max) '(face nil))))
3438 (if (and (boundp 'org-agenda-overriding-columns-format)
3439 org-agenda-overriding-columns-format)
3440 (org-set-local 'org-agenda-overriding-columns-format
3441 org-agenda-overriding-columns-format))
3442 (if (and (boundp 'org-agenda-view-columns-initially)
3443 org-agenda-view-columns-initially)
3444 (org-agenda-columns))
3445 (when org-agenda-fontify-priorities
3446 (org-agenda-fontify-priorities))
3447 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3448 (org-agenda-dim-blocked-tasks))
3449 (org-agenda-mark-clocking-task)
3450 (when org-agenda-entry-text-mode
3451 (org-agenda-entry-text-hide)
3452 (org-agenda-entry-text-show))
3453 (if (functionp 'org-habit-insert-consistency-graphs)
3454 (org-habit-insert-consistency-graphs))
3455 (let ((inhibit-read-only t))
3456 (run-hooks 'org-agenda-finalize-hook))
3457 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3458 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3459 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3460 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3461 (org-agenda-filter-apply org-agenda-category-filter 'category))
3462 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3464 (defun org-agenda-mark-clocking-task ()
3465 "Mark the current clock entry in the agenda if it is present."
3466 (mapc (lambda (o)
3467 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3468 (delete-overlay o)))
3469 (overlays-in (point-min) (point-max)))
3470 (when (marker-buffer org-clock-hd-marker)
3471 (save-excursion
3472 (goto-char (point-min))
3473 (let (s ov)
3474 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3475 (goto-char s)
3476 (when (equal (org-get-at-bol 'org-hd-marker)
3477 org-clock-hd-marker)
3478 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3479 (overlay-put ov 'type 'org-agenda-clocking)
3480 (overlay-put ov 'face 'org-agenda-clocking)
3481 (overlay-put ov 'help-echo
3482 "The clock is running in this item")))))))
3484 (defun org-agenda-fontify-priorities ()
3485 "Make highest priority lines bold, and lowest italic."
3486 (interactive)
3487 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3488 (delete-overlay o)))
3489 (overlays-in (point-min) (point-max)))
3490 (save-excursion
3491 (let ((inhibit-read-only t)
3492 b e p ov h l)
3493 (goto-char (point-min))
3494 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3495 (setq h (or (get-char-property (point) 'org-highest-priority)
3496 org-highest-priority)
3497 l (or (get-char-property (point) 'org-lowest-priority)
3498 org-lowest-priority)
3499 p (string-to-char (match-string 1))
3500 b (match-beginning 0)
3501 e (if (eq org-agenda-fontify-priorities 'cookies)
3502 (match-end 0)
3503 (point-at-eol))
3504 ov (make-overlay b e))
3505 (overlay-put
3506 ov 'face
3507 (cond ((org-face-from-face-or-color
3508 'priority nil
3509 (cdr (assoc p org-priority-faces))))
3510 ((and (listp org-agenda-fontify-priorities)
3511 (org-face-from-face-or-color
3512 'priority nil
3513 (cdr (assoc p org-agenda-fontify-priorities)))))
3514 ((equal p l) 'italic)
3515 ((equal p h) 'bold)))
3516 (overlay-put ov 'org-type 'org-priority)))))
3518 (defun org-agenda-dim-blocked-tasks ()
3519 "Dim currently blocked TODO's in the agenda display."
3520 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3521 (delete-overlay o)))
3522 (overlays-in (point-min) (point-max)))
3523 (save-excursion
3524 (let ((inhibit-read-only t)
3525 (org-depend-tag-blocked nil)
3526 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3527 org-blocked-by-checkboxes
3528 invis1 b e p ov h l)
3529 (goto-char (point-min))
3530 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3531 (and pos (goto-char (1+ pos))))
3532 (setq org-blocked-by-checkboxes nil invis1 invis)
3533 (let ((marker (org-get-at-bol 'org-hd-marker)))
3534 (when (and marker
3535 (with-current-buffer (marker-buffer marker)
3536 (save-excursion (goto-char marker)
3537 (org-entry-blocked-p))))
3538 (if org-blocked-by-checkboxes (setq invis1 nil))
3539 (setq b (if invis1
3540 (max (point-min) (1- (point-at-bol)))
3541 (point-at-bol))
3542 e (point-at-eol)
3543 ov (make-overlay b e))
3544 (if invis1
3545 (overlay-put ov 'invisible t)
3546 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3547 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3549 (defvar org-agenda-skip-function nil
3550 "Function to be called at each match during agenda construction.
3551 If this function returns nil, the current match should not be skipped.
3552 Otherwise, the function must return a position from where the search
3553 should be continued.
3554 This may also be a Lisp form, it will be evaluated.
3555 Never set this variable using `setq' or so, because then it will apply
3556 to all future agenda commands. If you do want a global skipping condition,
3557 use the option `org-agenda-skip-function-global' instead.
3558 The correct usage for `org-agenda-skip-function' is to bind it with
3559 `let' to scope it dynamically into the agenda-constructing command.
3560 A good way to set it is through options in `org-agenda-custom-commands'.")
3562 (defun org-agenda-skip ()
3563 "Throw to `:skip' in places that should be skipped.
3564 Also moves point to the end of the skipped region, so that search can
3565 continue from there."
3566 (let ((p (point-at-bol)) to)
3567 (when (org-in-src-block-p) (throw :skip t))
3568 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3569 (get-text-property p :org-archived)
3570 (org-end-of-subtree t)
3571 (throw :skip t))
3572 (and org-agenda-skip-comment-trees
3573 (get-text-property p :org-comment)
3574 (org-end-of-subtree t)
3575 (throw :skip t))
3576 (if (equal (char-after p) ?#) (throw :skip t))
3577 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3578 (org-agenda-skip-eval org-agenda-skip-function)))
3579 (goto-char to)
3580 (throw :skip t))))
3582 (defun org-agenda-skip-eval (form)
3583 "If FORM is a function or a list, call (or eval) is and return result.
3584 `save-excursion' and `save-match-data' are wrapped around the call, so point
3585 and match data are returned to the previous state no matter what these
3586 functions do."
3587 (let (fp)
3588 (and form
3589 (or (setq fp (functionp form))
3590 (consp form))
3591 (save-excursion
3592 (save-match-data
3593 (if fp
3594 (funcall form)
3595 (eval form)))))))
3597 (defvar org-agenda-markers nil
3598 "List of all currently active markers created by `org-agenda'.")
3599 (defvar org-agenda-last-marker-time (org-float-time)
3600 "Creation time of the last agenda marker.")
3602 (defun org-agenda-new-marker (&optional pos)
3603 "Return a new agenda marker.
3604 Org-mode keeps a list of these markers and resets them when they are
3605 no longer in use."
3606 (let ((m (copy-marker (or pos (point)))))
3607 (setq org-agenda-last-marker-time (org-float-time))
3608 (if org-agenda-buffer
3609 (with-current-buffer org-agenda-buffer
3610 (push m org-agenda-markers))
3611 (push m org-agenda-markers))
3614 (defun org-agenda-reset-markers ()
3615 "Reset markers created by `org-agenda'."
3616 (while org-agenda-markers
3617 (move-marker (pop org-agenda-markers) nil)))
3619 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3620 "Save relative positions of markers in region.
3621 This check for agenda markers in all agenda buffers currently active."
3622 (dolist (buf (buffer-list))
3623 (with-current-buffer buf
3624 (when (eq major-mode 'org-agenda-mode)
3625 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3626 org-agenda-markers)))))
3628 ;;; Entry text mode
3630 (defun org-agenda-entry-text-show-here ()
3631 "Add some text from the entry as context to the current line."
3632 (let (m txt o)
3633 (setq m (org-get-at-bol 'org-hd-marker))
3634 (unless (marker-buffer m)
3635 (error "No marker points to an entry here"))
3636 (setq txt (concat "\n" (org-no-properties
3637 (org-agenda-get-some-entry-text
3638 m org-agenda-entry-text-maxlines " > "))))
3639 (when (string-match "\\S-" txt)
3640 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3641 (overlay-put o 'evaporate t)
3642 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3643 (overlay-put o 'after-string txt))))
3645 (defun org-agenda-entry-text-show ()
3646 "Add entry context for all agenda lines."
3647 (interactive)
3648 (save-excursion
3649 (goto-char (point-max))
3650 (beginning-of-line 1)
3651 (while (not (bobp))
3652 (when (org-get-at-bol 'org-hd-marker)
3653 (org-agenda-entry-text-show-here))
3654 (beginning-of-line 0))))
3656 (defun org-agenda-entry-text-hide ()
3657 "Remove any shown entry context."
3658 (delq nil
3659 (mapcar (lambda (o)
3660 (if (eq (overlay-get o 'org-overlay-type)
3661 'agenda-entry-content)
3662 (progn (delete-overlay o) t)))
3663 (overlays-in (point-min) (point-max)))))
3665 (defun org-agenda-get-day-face (date)
3666 "Return the face DATE should be displayed with."
3667 (or (and (functionp org-agenda-day-face-function)
3668 (funcall org-agenda-day-face-function date))
3669 (cond ((org-agenda-todayp date)
3670 'org-agenda-date-today)
3671 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3672 'org-agenda-date-weekend)
3673 (t 'org-agenda-date))))
3675 ;;; Agenda timeline
3677 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3679 (defun org-timeline (&optional dotodo)
3680 "Show a time-sorted view of the entries in the current org file.
3681 Only entries with a time stamp of today or later will be listed. With
3682 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3683 under the current date.
3684 If the buffer contains an active region, only check the region for
3685 dates."
3686 (interactive "P")
3687 (let* ((dopast t)
3688 (org-agenda-show-log-scoped org-agenda-show-log)
3689 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3690 (current-buffer))))
3691 (date (calendar-current-date))
3692 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3693 (end (if (org-region-active-p) (region-end) (point-max)))
3694 (day-numbers (org-get-all-dates
3695 beg end 'no-ranges
3696 t org-agenda-show-log-scoped ; always include today
3697 org-timeline-show-empty-dates))
3698 (org-deadline-warning-days 0)
3699 (org-agenda-only-exact-dates t)
3700 (today (org-today))
3701 (past t)
3702 args
3703 s e rtn d emptyp)
3704 (setq org-agenda-redo-command
3705 (list 'progn
3706 (list 'org-switch-to-buffer-other-window (current-buffer))
3707 (list 'org-timeline (list 'quote dotodo))))
3708 (if (not dopast)
3709 ;; Remove past dates from the list of dates.
3710 (setq day-numbers (delq nil (mapcar (lambda(x)
3711 (if (>= x today) x nil))
3712 day-numbers))))
3713 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3714 (org-compile-prefix-format 'timeline)
3715 (org-set-sorting-strategy 'timeline)
3716 (if org-agenda-show-log-scoped (push :closed args))
3717 (push :timestamp args)
3718 (push :deadline args)
3719 (push :scheduled args)
3720 (push :sexp args)
3721 (if dotodo (push :todo args))
3722 (insert "Timeline of file " entry "\n")
3723 (add-text-properties (point-min) (point)
3724 (list 'face 'org-agenda-structure))
3725 (org-agenda-mark-header-line (point-min))
3726 (while (setq d (pop day-numbers))
3727 (if (and (listp d) (eq (car d) :omitted))
3728 (progn
3729 (setq s (point))
3730 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3731 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3732 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3733 (if (and (>= d today)
3734 dopast
3735 past)
3736 (progn
3737 (setq past nil)
3738 (insert (make-string 79 ?-) "\n")))
3739 (setq date (calendar-gregorian-from-absolute d))
3740 (setq s (point))
3741 (setq rtn (and (not emptyp)
3742 (apply 'org-agenda-get-day-entries entry
3743 date args)))
3744 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3745 (progn
3746 (insert
3747 (if (stringp org-agenda-format-date)
3748 (format-time-string org-agenda-format-date
3749 (org-time-from-absolute date))
3750 (funcall org-agenda-format-date date))
3751 "\n")
3752 (put-text-property s (1- (point)) 'face
3753 (org-agenda-get-day-face date))
3754 (put-text-property s (1- (point)) 'org-date-line t)
3755 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3756 (if (equal d today)
3757 (put-text-property s (1- (point)) 'org-today t))
3758 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3759 (put-text-property s (1- (point)) 'day d)))))
3760 (goto-char (point-min))
3761 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3762 (point-min)))
3763 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3764 (org-agenda-finalize)
3765 (setq buffer-read-only t)))
3767 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3768 "Return a list of all relevant day numbers from BEG to END buffer positions.
3769 If NO-RANGES is non-nil, include only the start and end dates of a range,
3770 not every single day in the range. If FORCE-TODAY is non-nil, make
3771 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3772 inactive time stamps (those in square brackets) are included.
3773 When EMPTY is non-nil, also include days without any entries."
3774 (let ((re (concat
3775 (if pre-re pre-re "")
3776 (if inactive org-ts-regexp-both org-ts-regexp)))
3777 dates dates1 date day day1 day2 ts1 ts2 pos)
3778 (if force-today
3779 (setq dates (list (org-today))))
3780 (save-excursion
3781 (goto-char beg)
3782 (while (re-search-forward re end t)
3783 (setq day (time-to-days (org-time-string-to-time
3784 (substring (match-string 1) 0 10)
3785 (current-buffer) (match-beginning 0))))
3786 (or (memq day dates) (push day dates)))
3787 (unless no-ranges
3788 (goto-char beg)
3789 (while (re-search-forward org-tr-regexp end t)
3790 (setq pos (match-beginning 0))
3791 (setq ts1 (substring (match-string 1) 0 10)
3792 ts2 (substring (match-string 2) 0 10)
3793 day1 (time-to-days (org-time-string-to-time
3794 ts1 (current-buffer) pos))
3795 day2 (time-to-days (org-time-string-to-time
3796 ts2 (current-buffer) pos)))
3797 (while (< (setq day1 (1+ day1)) day2)
3798 (or (memq day1 dates) (push day1 dates)))))
3799 (setq dates (sort dates '<))
3800 (when empty
3801 (while (setq day (pop dates))
3802 (setq day2 (car dates))
3803 (push day dates1)
3804 (when (and day2 empty)
3805 (if (or (eq empty t)
3806 (and (numberp empty) (<= (- day2 day) empty)))
3807 (while (< (setq day (1+ day)) day2)
3808 (push (list day) dates1))
3809 (push (cons :omitted (- day2 day)) dates1))))
3810 (setq dates (nreverse dates1)))
3811 dates)))
3813 ;;; Agenda Daily/Weekly
3815 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3816 "Start day for the agenda view.
3817 Custom commands can set this variable in the options section.")
3818 (defvar org-starting-day nil) ; local variable in the agenda buffer
3819 (defvar org-arg-loc nil) ; local variable
3821 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3822 "List of types searched for when creating the daily/weekly agenda.
3823 This variable is a list of symbols that controls the types of
3824 items that appear in the daily/weekly agenda. Allowed symbols in this
3825 list are are
3827 :timestamp List items containing a date stamp or date range matching
3828 the selected date. This includes sexp entries in
3829 angular brackets.
3831 :sexp List entries resulting from plain diary-like sexps.
3833 :deadline List deadline due on that date. When the date is today,
3834 also list any deadlines past due, or due within
3835 `org-deadline-warning-days'. `:deadline' must appear before
3836 `:scheduled' if the setting of
3837 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3838 any effect.
3840 :scheduled List all items which are scheduled for the given date.
3841 The diary for *today* also contains items which were
3842 scheduled earlier and are not yet marked DONE.
3844 By default, all four types are turned on.
3846 Never set this variable globally using `setq', because then it
3847 will apply to all future agenda commands. Instead, bind it with
3848 `let' to scope it dynamically into the agenda-constructing
3849 command. A good way to set it is through options in
3850 `org-agenda-custom-commands'. For a more flexible (though
3851 somewhat less efficient) way of determining what is included in
3852 the daily/weekly agenda, see `org-agenda-skip-function'.")
3854 (defvar org-agenda-buffer-tmp-name nil)
3855 ;;;###autoload
3856 (defun org-agenda-list (&optional arg start-day span)
3857 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3858 The view will be for the current day or week, but from the overview buffer
3859 you will be able to go to other days/weeks.
3861 With a numeric prefix argument in an interactive call, the agenda will
3862 span ARG days. Lisp programs should instead specify SPAN to change
3863 the number of days. SPAN defaults to `org-agenda-span'.
3865 START-DAY defaults to TODAY, or to the most recent match for the weekday
3866 given in `org-agenda-start-on-weekday'."
3867 (interactive "P")
3868 (if org-agenda-overriding-arguments
3869 (setq arg (car org-agenda-overriding-arguments)
3870 start-day (nth 1 org-agenda-overriding-arguments)
3871 span (nth 2 org-agenda-overriding-arguments)))
3872 (if (and (integerp arg) (> arg 0))
3873 (setq span arg arg nil))
3874 (catch 'exit
3875 (setq org-agenda-buffer-name
3876 (or org-agenda-buffer-tmp-name
3877 (if org-agenda-sticky
3878 (cond ((and org-keys (stringp org-match))
3879 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3880 (org-keys
3881 (format "*Org Agenda(%s)*" org-keys))
3882 (t "*Org Agenda(a)*")))
3883 org-agenda-buffer-name))
3884 (org-agenda-prepare "Day/Week")
3885 (setq start-day (or start-day org-agenda-start-day))
3886 (if (stringp start-day)
3887 ;; Convert to an absolute day number
3888 (setq start-day (time-to-days (org-read-date nil t start-day))))
3889 (org-compile-prefix-format 'agenda)
3890 (org-set-sorting-strategy 'agenda)
3891 (let* ((span (org-agenda-ndays-to-span
3892 (or span org-agenda-ndays org-agenda-span)))
3893 (today (org-today))
3894 (sd (or start-day today))
3895 (ndays (org-agenda-span-to-ndays span sd))
3896 (org-agenda-start-on-weekday
3897 (if (eq ndays 7)
3898 org-agenda-start-on-weekday))
3899 (thefiles (org-agenda-files nil 'ifmode))
3900 (files thefiles)
3901 (start (if (or (null org-agenda-start-on-weekday)
3902 (< ndays 7))
3904 (let* ((nt (calendar-day-of-week
3905 (calendar-gregorian-from-absolute sd)))
3906 (n1 org-agenda-start-on-weekday)
3907 (d (- nt n1)))
3908 (- sd (+ (if (< d 0) 7 0) d)))))
3909 (day-numbers (list start))
3910 (day-cnt 0)
3911 (inhibit-redisplay (not debug-on-error))
3912 (org-agenda-show-log-scoped org-agenda-show-log)
3913 s e rtn rtnall file date d start-pos end-pos todayp
3914 clocktable-start clocktable-end filter)
3915 (setq org-agenda-redo-command
3916 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3917 (dotimes (n (1- ndays))
3918 (push (1+ (car day-numbers)) day-numbers))
3919 (setq day-numbers (nreverse day-numbers))
3920 (setq clocktable-start (car day-numbers)
3921 clocktable-end (1+ (or (org-last day-numbers) 0)))
3922 (org-set-local 'org-starting-day (car day-numbers))
3923 (org-set-local 'org-arg-loc arg)
3924 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3925 (unless org-agenda-compact-blocks
3926 (let* ((d1 (car day-numbers))
3927 (d2 (org-last day-numbers))
3928 (w1 (org-days-to-iso-week d1))
3929 (w2 (org-days-to-iso-week d2)))
3930 (setq s (point))
3931 (if org-agenda-overriding-header
3932 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3933 nil 'face 'org-agenda-structure) "\n")
3934 (insert (org-agenda-span-name span)
3935 "-agenda"
3936 (if (< (- d2 d1) 350)
3937 (if (= w1 w2)
3938 (format " (W%02d)" w1)
3939 (format " (W%02d-W%02d)" w1 w2))
3941 ":\n")))
3942 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3943 'org-date-line t))
3944 (org-agenda-mark-header-line s))
3945 (while (setq d (pop day-numbers))
3946 (setq date (calendar-gregorian-from-absolute d)
3947 s (point))
3948 (if (or (setq todayp (= d today))
3949 (and (not start-pos) (= d sd)))
3950 (setq start-pos (point))
3951 (if (and start-pos (not end-pos))
3952 (setq end-pos (point))))
3953 (setq files thefiles
3954 rtnall nil)
3955 (while (setq file (pop files))
3956 (catch 'nextfile
3957 (org-check-agenda-file file)
3958 (let ((org-agenda-entry-types org-agenda-entry-types))
3959 (unless org-agenda-include-deadlines
3960 (setq org-agenda-entry-types
3961 (delq :deadline org-agenda-entry-types)))
3962 (cond
3963 ((memq org-agenda-show-log-scoped '(only clockcheck))
3964 (setq rtn (org-agenda-get-day-entries
3965 file date :closed)))
3966 (org-agenda-show-log-scoped
3967 (setq rtn (apply 'org-agenda-get-day-entries
3968 file date
3969 (append '(:closed) org-agenda-entry-types))))
3971 (setq rtn (apply 'org-agenda-get-day-entries
3972 file date
3973 org-agenda-entry-types)))))
3974 (setq rtnall (append rtnall rtn)))) ;; all entries
3975 (if org-agenda-include-diary
3976 (let ((org-agenda-search-headline-for-time t))
3977 (require 'diary-lib)
3978 (setq rtn (org-get-entries-from-diary date))
3979 (setq rtnall (append rtnall rtn))))
3980 (if (or rtnall org-agenda-show-all-dates)
3981 (progn
3982 (setq day-cnt (1+ day-cnt))
3983 (insert
3984 (if (stringp org-agenda-format-date)
3985 (format-time-string org-agenda-format-date
3986 (org-time-from-absolute date))
3987 (funcall org-agenda-format-date date))
3988 "\n")
3989 (put-text-property s (1- (point)) 'face
3990 (org-agenda-get-day-face date))
3991 (put-text-property s (1- (point)) 'org-date-line t)
3992 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3993 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3994 (when todayp
3995 (put-text-property s (1- (point)) 'org-today t))
3996 (setq rtnall
3997 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3998 (if rtnall (insert ;; all entries
3999 (org-agenda-finalize-entries rtnall)
4000 "\n"))
4001 (put-text-property s (1- (point)) 'day d)
4002 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4003 (when (and org-agenda-clockreport-mode clocktable-start)
4004 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4005 ;; the above line is to ensure the restricted range!
4006 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4007 tbl)
4008 (setq p (org-plist-delete p :block))
4009 (setq p (plist-put p :tstart clocktable-start))
4010 (setq p (plist-put p :tend clocktable-end))
4011 (setq p (plist-put p :scope 'agenda))
4012 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4013 (setq filter (or org-agenda-tag-filter-while-redo
4014 (get 'org-agenda-tag-filter :preset-filter))))
4015 (setq p (plist-put p :tags (mapconcat (lambda (x)
4016 (if (string-match "[<>=]" x)
4019 filter ""))))
4020 (setq tbl (apply 'org-get-clocktable p))
4021 (insert tbl)))
4022 (goto-char (point-min))
4023 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4024 (unless (and (pos-visible-in-window-p (point-min))
4025 (pos-visible-in-window-p (point-max)))
4026 (goto-char (1- (point-max)))
4027 (recenter -1)
4028 (if (not (pos-visible-in-window-p (or start-pos 1)))
4029 (progn
4030 (goto-char (or start-pos 1))
4031 (recenter 1))))
4032 (goto-char (or start-pos 1))
4033 (add-text-properties (point-min) (point-max)
4034 `(org-agenda-type agenda
4035 org-last-args (,arg ,start-day ,span)
4036 org-redo-cmd ,org-agenda-redo-command
4037 org-serie-cmd ,org-cmd))
4038 (if (eq org-agenda-show-log-scoped 'clockcheck)
4039 (org-agenda-show-clocking-issues))
4040 (org-agenda-finalize)
4041 (setq buffer-read-only t)
4042 (message ""))))
4044 (defun org-agenda-ndays-to-span (n)
4045 "Return a span symbol for a span of N days, or N if none matches."
4046 (cond ((symbolp n) n)
4047 ((= n 1) 'day)
4048 ((= n 7) 'week)
4049 (t n)))
4051 (defun org-agenda-span-to-ndays (span &optional start-day)
4052 "Return ndays from SPAN, possibly starting at START-DAY."
4053 (cond ((numberp span) span)
4054 ((eq span 'day) 1)
4055 ((eq span 'week) 7)
4056 ((eq span 'month)
4057 (let ((date (calendar-gregorian-from-absolute start-day)))
4058 (calendar-last-day-of-month (car date) (caddr date))))
4059 ((eq span 'year)
4060 (let ((date (calendar-gregorian-from-absolute start-day)))
4061 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4063 (defun org-agenda-span-name (span)
4064 "Return a SPAN name."
4065 (if (null span)
4067 (if (symbolp span)
4068 (capitalize (symbol-name span))
4069 (format "%d days" span))))
4071 ;;; Agenda word search
4073 (defvar org-agenda-search-history nil)
4075 (defvar org-search-syntax-table nil
4076 "Special syntax table for org-mode search.
4077 In this table, we have single quotes not as word constituents, to
4078 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4080 (defvar org-mode-syntax-table) ; From org.el
4081 (defun org-search-syntax-table ()
4082 (unless org-search-syntax-table
4083 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4084 (modify-syntax-entry ?' "." org-search-syntax-table)
4085 (modify-syntax-entry ?` "." org-search-syntax-table))
4086 org-search-syntax-table)
4088 (defvar org-agenda-last-search-view-search-was-boolean nil)
4090 ;;;###autoload
4091 (defun org-search-view (&optional todo-only string edit-at)
4092 "Show all entries that contain a phrase or words or regular expressions.
4094 With optional prefix argument TODO-ONLY, only consider entries that are
4095 TODO entries. The argument STRING can be used to pass a default search
4096 string into this function. If EDIT-AT is non-nil, it means that the
4097 user should get a chance to edit this string, with cursor at position
4098 EDIT-AT.
4100 The search string can be viewed either as a phrase that should be found as
4101 is, or it can be broken into a number of snippets, each of which must match
4102 in a Boolean way to select an entry. The default depends on the variable
4103 `org-agenda-search-view-always-boolean'.
4104 Even if this is turned off (the default) you can always switch to
4105 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4107 The default is a direct search of the whole phrase, where each space in
4108 the search string can expand to an arbitrary amount of whitespace,
4109 including newlines.
4111 If using a Boolean search, the search string is split on whitespace and
4112 each snippet is searched separately, with logical AND to select an entry.
4113 Words prefixed with a minus must *not* occur in the entry. Words without
4114 a prefix or prefixed with a plus must occur in the entry. Matching is
4115 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4116 match whole words, not parts of a word) if
4117 `org-agenda-search-view-force-full-words' is set (default is nil).
4119 Boolean search snippets enclosed by curly braces are interpreted as
4120 regular expressions that must or (when preceded with \"-\") must not
4121 match in the entry. Snippets enclosed into double quotes will be taken
4122 as a whole, to include whitespace.
4124 - If the search string starts with an asterisk, search only in headlines.
4125 - If (possibly after the leading star) the search string starts with an
4126 exclamation mark, this also means to look at TODO entries only, an effect
4127 that can also be achieved with a prefix argument.
4128 - If (possibly after star and exclamation mark) the search string starts
4129 with a colon, this will mean that the (non-regexp) snippets of the
4130 Boolean search must match as full words.
4132 This command searches the agenda files, and in addition the files listed
4133 in `org-agenda-text-search-extra-files'."
4134 (interactive "P")
4135 (if org-agenda-overriding-arguments
4136 (setq todo-only (car org-agenda-overriding-arguments)
4137 string (nth 1 org-agenda-overriding-arguments)
4138 edit-at (nth 2 org-agenda-overriding-arguments)))
4139 (let* ((props (list 'face nil
4140 'done-face 'org-agenda-done
4141 'org-not-done-regexp org-not-done-regexp
4142 'org-todo-regexp org-todo-regexp
4143 'org-complex-heading-regexp org-complex-heading-regexp
4144 'mouse-face 'highlight
4145 'help-echo (format "mouse-2 or RET jump to location")))
4146 (full-words org-agenda-search-view-force-full-words)
4147 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4148 regexp rtn rtnall files file pos
4149 marker category category-pos level tags c neg re boolean
4150 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4151 (unless (and (not edit-at)
4152 (stringp string)
4153 (string-match "\\S-" string))
4154 (setq string (read-string
4155 (if org-agenda-search-view-always-boolean
4156 "[+-]Word/{Regexp} ...: "
4157 "Phrase or [+-]Word/{Regexp} ...: ")
4158 (cond
4159 ((integerp edit-at) (cons string edit-at))
4160 (edit-at string))
4161 'org-agenda-search-history)))
4162 (catch 'exit
4163 (if org-agenda-sticky
4164 (setq org-agenda-buffer-name
4165 (if (stringp string)
4166 (format "*Org Agenda(%s:%s)*"
4167 (or org-keys (or (and todo-only "S") "s")) string)
4168 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4169 (org-agenda-prepare "SEARCH")
4170 (org-compile-prefix-format 'search)
4171 (org-set-sorting-strategy 'search)
4172 (setq org-agenda-redo-command
4173 (list 'org-search-view (if todo-only t nil)
4174 (list 'if 'current-prefix-arg nil string)))
4175 (setq org-agenda-query-string string)
4176 (if (equal (string-to-char string) ?*)
4177 (setq hdl-only t
4178 words (substring string 1))
4179 (setq words string))
4180 (when (equal (string-to-char words) ?!)
4181 (setq todo-only t
4182 words (substring words 1)))
4183 (when (equal (string-to-char words) ?:)
4184 (setq full-words t
4185 words (substring words 1)))
4186 (if (or org-agenda-search-view-always-boolean
4187 (member (string-to-char words) '(?- ?+ ?\{)))
4188 (setq boolean t))
4189 (setq words (org-split-string words))
4190 (let (www w)
4191 (while (setq w (pop words))
4192 (while (and (string-match "\\\\\\'" w) words)
4193 (setq w (concat (substring w 0 -1) " " (pop words))))
4194 (push w www))
4195 (setq words (nreverse www) www nil)
4196 (while (setq w (pop words))
4197 (when (and (string-match "\\`[-+]?{" w)
4198 (not (string-match "}\\'" w)))
4199 (while (and words (not (string-match "}\\'" (car words))))
4200 (setq w (concat w " " (pop words))))
4201 (setq w (concat w " " (pop words))))
4202 (push w www))
4203 (setq words (nreverse www)))
4204 (setq org-agenda-last-search-view-search-was-boolean boolean)
4205 (when boolean
4206 (let (wds w)
4207 (while (setq w (pop words))
4208 (if (or (equal (substring w 0 1) "\"")
4209 (and (> (length w) 1)
4210 (member (substring w 0 1) '("+" "-"))
4211 (equal (substring w 1 2) "\"")))
4212 (while (and words (not (equal (substring w -1) "\"")))
4213 (setq w (concat w " " (pop words)))))
4214 (and (string-match "\\`\\([-+]?\\)\"" w)
4215 (setq w (replace-match "\\1" nil nil w)))
4216 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4217 (push w wds))
4218 (setq words (nreverse wds))))
4219 (if boolean
4220 (mapc (lambda (w)
4221 (setq c (string-to-char w))
4222 (if (equal c ?-)
4223 (setq neg t w (substring w 1))
4224 (if (equal c ?+)
4225 (setq neg nil w (substring w 1))
4226 (setq neg nil)))
4227 (if (string-match "\\`{.*}\\'" w)
4228 (setq re (substring w 1 -1))
4229 (if full-words
4230 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4231 (setq re (regexp-quote (downcase w)))))
4232 (if neg (push re regexps-) (push re regexps+)))
4233 words)
4234 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4235 regexps+))
4236 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4237 (if (not regexps+)
4238 (setq regexp org-outline-regexp-bol)
4239 (setq regexp (pop regexps+))
4240 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4241 regexp))))
4242 (setq files (org-agenda-files nil 'ifmode))
4243 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4244 (pop org-agenda-text-search-extra-files)
4245 (setq files (org-add-archive-files files)))
4246 (setq files (append files org-agenda-text-search-extra-files)
4247 rtnall nil)
4248 (while (setq file (pop files))
4249 (setq ee nil)
4250 (catch 'nextfile
4251 (org-check-agenda-file file)
4252 (setq buffer (if (file-exists-p file)
4253 (org-get-agenda-file-buffer file)
4254 (error "No such file %s" file)))
4255 (if (not buffer)
4256 ;; If file does not exist, make sure an error message is sent
4257 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4258 file))))
4259 (with-current-buffer buffer
4260 (with-syntax-table (org-search-syntax-table)
4261 (unless (derived-mode-p 'org-mode)
4262 (error "Agenda file %s is not in `org-mode'" file))
4263 (let ((case-fold-search t))
4264 (save-excursion
4265 (save-restriction
4266 (if org-agenda-restrict
4267 (narrow-to-region org-agenda-restrict-begin
4268 org-agenda-restrict-end)
4269 (widen))
4270 (goto-char (point-min))
4271 (unless (or (org-at-heading-p)
4272 (outline-next-heading))
4273 (throw 'nextfile t))
4274 (goto-char (max (point-min) (1- (point))))
4275 (while (re-search-forward regexp nil t)
4276 (org-back-to-heading t)
4277 (skip-chars-forward "* ")
4278 (setq beg (point-at-bol)
4279 beg1 (point)
4280 end (progn (outline-next-heading) (point)))
4281 (catch :skip
4282 (goto-char beg)
4283 (org-agenda-skip)
4284 (setq str (buffer-substring-no-properties
4285 (point-at-bol)
4286 (if hdl-only (point-at-eol) end)))
4287 (mapc (lambda (wr) (when (string-match wr str)
4288 (goto-char (1- end))
4289 (throw :skip t)))
4290 regexps-)
4291 (mapc (lambda (wr) (unless (string-match wr str)
4292 (goto-char (1- end))
4293 (throw :skip t)))
4294 (if todo-only
4295 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4296 regexps+)
4297 regexps+))
4298 (goto-char beg)
4299 (setq marker (org-agenda-new-marker (point))
4300 category (org-get-category)
4301 level (make-string (org-reduced-level (org-outline-level)) ? )
4302 category-pos (get-text-property (point) 'org-category-position)
4303 tags (org-get-tags-at (point))
4304 txt (org-agenda-format-item
4306 (buffer-substring-no-properties
4307 beg1 (point-at-eol))
4308 level category tags t))
4309 (org-add-props txt props
4310 'org-marker marker 'org-hd-marker marker
4311 'org-todo-regexp org-todo-regexp
4312 'level level
4313 'org-complex-heading-regexp org-complex-heading-regexp
4314 'priority 1000 'org-category category
4315 'org-category-position category-pos
4316 'type "search")
4317 (push txt ee)
4318 (goto-char (1- end))))))))))
4319 (setq rtn (nreverse ee))
4320 (setq rtnall (append rtnall rtn)))
4321 (if org-agenda-overriding-header
4322 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4323 nil 'face 'org-agenda-structure) "\n")
4324 (insert "Search words: ")
4325 (add-text-properties (point-min) (1- (point))
4326 (list 'face 'org-agenda-structure))
4327 (setq pos (point))
4328 (insert string "\n")
4329 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4330 (setq pos (point))
4331 (unless org-agenda-multi
4332 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4333 (add-text-properties pos (1- (point))
4334 (list 'face 'org-agenda-structure))))
4335 (org-agenda-mark-header-line (point-min))
4336 (when rtnall
4337 (insert (org-agenda-finalize-entries rtnall) "\n"))
4338 (goto-char (point-min))
4339 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4340 (add-text-properties (point-min) (point-max)
4341 `(org-agenda-type search
4342 org-last-args (,todo-only ,string ,edit-at)
4343 org-redo-cmd ,org-agenda-redo-command
4344 org-serie-cmd ,org-cmd))
4345 (org-agenda-finalize)
4346 (setq buffer-read-only t))))
4348 ;;; Agenda TODO list
4350 (defvar org-select-this-todo-keyword nil)
4351 (defvar org-last-arg nil)
4353 ;;;###autoload
4354 (defun org-todo-list (&optional arg)
4355 "Show all (not done) TODO entries from all agenda file in a single list.
4356 The prefix arg can be used to select a specific TODO keyword and limit
4357 the list to these. When using \\[universal-argument], you will be prompted
4358 for a keyword. A numeric prefix directly selects the Nth keyword in
4359 `org-todo-keywords-1'."
4360 (interactive "P")
4361 (if org-agenda-overriding-arguments
4362 (setq arg org-agenda-overriding-arguments))
4363 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4364 (let* ((today (org-today))
4365 (date (calendar-gregorian-from-absolute today))
4366 (kwds org-todo-keywords-for-agenda)
4367 (completion-ignore-case t)
4368 (org-select-this-todo-keyword
4369 (if (stringp arg) arg
4370 (and arg (integerp arg) (> arg 0)
4371 (nth (1- arg) kwds))))
4372 rtn rtnall files file pos)
4373 (when (equal arg '(4))
4374 (setq org-select-this-todo-keyword
4375 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4376 (mapcar 'list kwds) nil nil)))
4377 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4378 (catch 'exit
4379 (if org-agenda-sticky
4380 (setq org-agenda-buffer-name
4381 (if (stringp org-select-this-todo-keyword)
4382 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4383 org-select-this-todo-keyword)
4384 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4385 (org-agenda-prepare "TODO")
4386 (org-compile-prefix-format 'todo)
4387 (org-set-sorting-strategy 'todo)
4388 (setq org-agenda-redo-command
4389 `(org-todo-list (or (and (numberp current-prefix-arg)
4390 current-prefix-arg)
4391 ,org-select-this-todo-keyword
4392 current-prefix-arg ,arg)))
4393 (setq files (org-agenda-files nil 'ifmode)
4394 rtnall nil)
4395 (while (setq file (pop files))
4396 (catch 'nextfile
4397 (org-check-agenda-file file)
4398 (setq rtn (org-agenda-get-day-entries file date :todo))
4399 (setq rtnall (append rtnall rtn))))
4400 (if org-agenda-overriding-header
4401 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4402 nil 'face 'org-agenda-structure) "\n")
4403 (insert "Global list of TODO items of type: ")
4404 (add-text-properties (point-min) (1- (point))
4405 (list 'face 'org-agenda-structure
4406 'short-heading
4407 (concat "ToDo: "
4408 (or org-select-this-todo-keyword "ALL"))))
4409 (org-agenda-mark-header-line (point-min))
4410 (setq pos (point))
4411 (insert (or org-select-this-todo-keyword "ALL") "\n")
4412 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4413 (setq pos (point))
4414 (unless org-agenda-multi
4415 (insert "Available with `N r': (0)[ALL]")
4416 (let ((n 0) s)
4417 (mapc (lambda (x)
4418 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4419 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4420 (insert "\n "))
4421 (insert " " s))
4422 kwds))
4423 (insert "\n"))
4424 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4425 (org-agenda-mark-header-line (point-min))
4426 (when rtnall
4427 (insert (org-agenda-finalize-entries rtnall) "\n"))
4428 (goto-char (point-min))
4429 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4430 (add-text-properties (point-min) (point-max)
4431 `(org-agenda-type todo
4432 org-last-args ,arg
4433 org-redo-cmd ,org-agenda-redo-command
4434 org-serie-cmd ,org-cmd))
4435 (org-agenda-finalize)
4436 (setq buffer-read-only t))))
4438 ;;; Agenda tags match
4440 ;;;###autoload
4441 (defun org-tags-view (&optional todo-only match)
4442 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4443 The prefix arg TODO-ONLY limits the search to TODO entries."
4444 (interactive "P")
4445 (if org-agenda-overriding-arguments
4446 (setq todo-only (car org-agenda-overriding-arguments)
4447 match (nth 1 org-agenda-overriding-arguments)))
4448 (let* ((org-tags-match-list-sublevels
4449 org-tags-match-list-sublevels)
4450 (completion-ignore-case t)
4451 rtn rtnall files file pos matcher
4452 buffer)
4453 (when (and (stringp match) (not (string-match "\\S-" match)))
4454 (setq match nil))
4455 (setq matcher (org-make-tags-matcher match)
4456 match (car matcher) matcher (cdr matcher))
4457 (catch 'exit
4458 (if org-agenda-sticky
4459 (setq org-agenda-buffer-name
4460 (if (stringp match)
4461 (format "*Org Agenda(%s:%s)*"
4462 (or org-keys (or (and todo-only "M") "m")) match)
4463 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4464 (org-agenda-prepare (concat "TAGS " match))
4465 (org-compile-prefix-format 'tags)
4466 (org-set-sorting-strategy 'tags)
4467 (setq org-agenda-query-string match)
4468 (setq org-agenda-redo-command
4469 (list 'org-tags-view `(quote ,todo-only)
4470 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4471 (setq files (org-agenda-files nil 'ifmode)
4472 rtnall nil)
4473 (while (setq file (pop files))
4474 (catch 'nextfile
4475 (org-check-agenda-file file)
4476 (setq buffer (if (file-exists-p file)
4477 (org-get-agenda-file-buffer file)
4478 (error "No such file %s" file)))
4479 (if (not buffer)
4480 ;; If file does not exist, error message to agenda
4481 (setq rtn (list
4482 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4483 rtnall (append rtnall rtn))
4484 (with-current-buffer buffer
4485 (unless (derived-mode-p 'org-mode)
4486 (error "Agenda file %s is not in `org-mode'" file))
4487 (save-excursion
4488 (save-restriction
4489 (if org-agenda-restrict
4490 (narrow-to-region org-agenda-restrict-begin
4491 org-agenda-restrict-end)
4492 (widen))
4493 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4494 (setq rtnall (append rtnall rtn))))))))
4495 (if org-agenda-overriding-header
4496 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4497 nil 'face 'org-agenda-structure) "\n")
4498 (insert "Headlines with TAGS match: ")
4499 (add-text-properties (point-min) (1- (point))
4500 (list 'face 'org-agenda-structure
4501 'short-heading
4502 (concat "Match: " match)))
4503 (setq pos (point))
4504 (insert match "\n")
4505 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4506 (setq pos (point))
4507 (unless org-agenda-multi
4508 (insert "Press `C-u r' to search again with new search string\n"))
4509 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4510 (org-agenda-mark-header-line (point-min))
4511 (when rtnall
4512 (insert (org-agenda-finalize-entries rtnall) "\n"))
4513 (goto-char (point-min))
4514 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4515 (add-text-properties (point-min) (point-max)
4516 `(org-agenda-type tags
4517 org-last-args (,todo-only ,match)
4518 org-redo-cmd ,org-agenda-redo-command
4519 org-serie-cmd ,org-cmd))
4520 (org-agenda-finalize)
4521 (setq buffer-read-only t))))
4523 ;;; Agenda Finding stuck projects
4525 (defvar org-agenda-skip-regexp nil
4526 "Regular expression used in skipping subtrees for the agenda.
4527 This is basically a temporary global variable that can be set and then
4528 used by user-defined selections using `org-agenda-skip-function'.")
4530 (defvar org-agenda-overriding-header nil
4531 "When set during agenda, todo and tags searches it replaces the header.
4532 This variable should not be set directly, but custom commands can bind it
4533 in the options section.")
4535 (defun org-agenda-skip-entry-when-regexp-matches ()
4536 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4537 If yes, it returns the end position of this entry, causing agenda commands
4538 to skip the entry but continuing the search in the subtree. This is a
4539 function that can be put into `org-agenda-skip-function' for the duration
4540 of a command."
4541 (let ((end (save-excursion (org-end-of-subtree t)))
4542 skip)
4543 (save-excursion
4544 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4545 (and skip end)))
4547 (defun org-agenda-skip-subtree-when-regexp-matches ()
4548 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4549 If yes, it returns the end position of this tree, causing agenda commands
4550 to skip this subtree. This is a function that can be put into
4551 `org-agenda-skip-function' for the duration of a command."
4552 (let ((end (save-excursion (org-end-of-subtree t)))
4553 skip)
4554 (save-excursion
4555 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4556 (and skip end)))
4558 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4559 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4560 If yes, it returns the end position of the current entry (NOT the tree),
4561 causing agenda commands to skip the entry but continuing the search in
4562 the subtree. This is a function that can be put into
4563 `org-agenda-skip-function' for the duration of a command. An important
4564 use of this function is for the stuck project list."
4565 (let ((end (save-excursion (org-end-of-subtree t)))
4566 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4567 skip)
4568 (save-excursion
4569 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4570 (and skip entry-end)))
4572 (defun org-agenda-skip-entry-if (&rest conditions)
4573 "Skip entry if any of CONDITIONS is true.
4574 See `org-agenda-skip-if' for details."
4575 (org-agenda-skip-if nil conditions))
4577 (defun org-agenda-skip-subtree-if (&rest conditions)
4578 "Skip entry if any of CONDITIONS is true.
4579 See `org-agenda-skip-if' for details."
4580 (org-agenda-skip-if t conditions))
4582 (defun org-agenda-skip-if (subtree conditions)
4583 "Checks current entity for CONDITIONS.
4584 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4585 the entry (i.e. the text before the next heading) is checked.
4587 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4588 from different tests. Valid conditions are:
4590 scheduled Check if there is a scheduled cookie
4591 notscheduled Check if there is no scheduled cookie
4592 deadline Check if there is a deadline
4593 notdeadline Check if there is no deadline
4594 timestamp Check if there is a timestamp (also deadline or scheduled)
4595 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4596 regexp Check if regexp matches
4597 notregexp Check if regexp does not match.
4598 todo Check if TODO keyword matches
4599 nottodo Check if TODO keyword does not match
4601 The regexp is taken from the conditions list, it must come right after
4602 the `regexp' or `notregexp' element.
4604 `todo' and `nottodo' accept as an argument a list of todo
4605 keywords, which may include \"*\" to match any todo keyword.
4607 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4609 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4611 Instead of a list, a keyword class may be given. For example:
4613 (org-agenda-skip-entry-if 'nottodo 'done)
4615 would skip entries that haven't been marked with any of \"DONE\"
4616 keywords. Possible classes are: `todo', `done', `any'.
4618 If any of these conditions is met, this function returns the end point of
4619 the entity, causing the search to continue from there. This is a function
4620 that can be put into `org-agenda-skip-function' for the duration of a command."
4621 (let (beg end m)
4622 (org-back-to-heading t)
4623 (setq beg (point)
4624 end (if subtree
4625 (progn (org-end-of-subtree t) (point))
4626 (progn (outline-next-heading) (1- (point)))))
4627 (goto-char beg)
4628 (and
4630 (and (memq 'scheduled conditions)
4631 (re-search-forward org-scheduled-time-regexp end t))
4632 (and (memq 'notscheduled conditions)
4633 (not (re-search-forward org-scheduled-time-regexp end t)))
4634 (and (memq 'deadline conditions)
4635 (re-search-forward org-deadline-time-regexp end t))
4636 (and (memq 'notdeadline conditions)
4637 (not (re-search-forward org-deadline-time-regexp end t)))
4638 (and (memq 'timestamp conditions)
4639 (re-search-forward org-ts-regexp end t))
4640 (and (memq 'nottimestamp conditions)
4641 (not (re-search-forward org-ts-regexp end t)))
4642 (and (setq m (memq 'regexp conditions))
4643 (stringp (nth 1 m))
4644 (re-search-forward (nth 1 m) end t))
4645 (and (setq m (memq 'notregexp conditions))
4646 (stringp (nth 1 m))
4647 (not (re-search-forward (nth 1 m) end t)))
4648 (and (or
4649 (setq m (memq 'nottodo conditions))
4650 (setq m (memq 'todo-unblocked conditions))
4651 (setq m (memq 'nottodo-unblocked conditions))
4652 (setq m (memq 'todo conditions)))
4653 (org-agenda-skip-if-todo m end)))
4654 end)))
4656 (defun org-agenda-skip-if-todo (args end)
4657 "Helper function for `org-agenda-skip-if', do not use it directly.
4658 ARGS is a list with first element either `todo', `nottodo',
4659 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4660 a list of TODO keywords, or a state symbol `todo' or `done' or
4661 `any'."
4662 (let ((kw (car args))
4663 (arg (cadr args))
4664 todo-wds todo-re)
4665 (setq todo-wds
4666 (org-uniquify
4667 (cond
4668 ((listp arg) ;; list of keywords
4669 (if (member "*" arg)
4670 (mapcar 'substring-no-properties org-todo-keywords-1)
4671 arg))
4672 ((symbolp arg) ;; keyword class name
4673 (cond
4674 ((eq arg 'todo)
4675 (org-delete-all org-done-keywords
4676 (mapcar 'substring-no-properties
4677 org-todo-keywords-1)))
4678 ((eq arg 'done) org-done-keywords)
4679 ((eq arg 'any)
4680 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4681 (setq todo-re
4682 (concat "^\\*+[ \t]+\\<\\("
4683 (mapconcat 'identity todo-wds "\\|")
4684 "\\)\\>"))
4685 (cond
4686 ((eq kw 'todo) (re-search-forward todo-re end t))
4687 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4688 ((eq kw 'todo-unblocked)
4689 (catch 'unblocked
4690 (while (re-search-forward todo-re end t)
4691 (or (org-entry-blocked-p) (throw 'unblocked t)))
4692 nil))
4693 ((eq kw 'nottodo-unblocked)
4694 (catch 'unblocked
4695 (while (re-search-forward todo-re end t)
4696 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4700 ;;;###autoload
4701 (defun org-agenda-list-stuck-projects (&rest ignore)
4702 "Create agenda view for projects that are stuck.
4703 Stuck projects are project that have no next actions. For the definitions
4704 of what a project is and how to check if it stuck, customize the variable
4705 `org-stuck-projects'."
4706 (interactive)
4707 (let* ((org-agenda-skip-function
4708 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4709 ;; We could have used org-agenda-skip-if here.
4710 (org-agenda-overriding-header
4711 (or org-agenda-overriding-header "List of stuck projects: "))
4712 (matcher (nth 0 org-stuck-projects))
4713 (todo (nth 1 org-stuck-projects))
4714 (todo-wds (if (member "*" todo)
4715 (progn
4716 (org-agenda-prepare-buffers (org-agenda-files
4717 nil 'ifmode))
4718 (org-delete-all
4719 org-done-keywords-for-agenda
4720 (copy-sequence org-todo-keywords-for-agenda)))
4721 todo))
4722 (todo-re (concat "^\\*+[ \t]+\\("
4723 (mapconcat 'identity todo-wds "\\|")
4724 "\\)\\>"))
4725 (tags (nth 2 org-stuck-projects))
4726 (tags-re (if (member "*" tags)
4727 (concat org-outline-regexp-bol
4728 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4729 (if tags
4730 (concat org-outline-regexp-bol
4731 ".*:\\("
4732 (mapconcat 'identity tags "\\|")
4733 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4734 (gen-re (nth 3 org-stuck-projects))
4735 (re-list
4736 (delq nil
4737 (list
4738 (if todo todo-re)
4739 (if tags tags-re)
4740 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4741 gen-re)))))
4742 (setq org-agenda-skip-regexp
4743 (if re-list
4744 (mapconcat 'identity re-list "\\|")
4745 (error "No information how to identify unstuck projects")))
4746 (org-tags-view nil matcher)
4747 (with-current-buffer org-agenda-buffer-name
4748 (setq org-agenda-redo-command
4749 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4751 ;;; Diary integration
4753 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4754 (defvar diary-list-entries-hook)
4755 (defvar diary-time-regexp)
4756 (defun org-get-entries-from-diary (date)
4757 "Get the (Emacs Calendar) diary entries for DATE."
4758 (require 'diary-lib)
4759 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4760 (diary-display-hook '(fancy-diary-display))
4761 (diary-display-function 'fancy-diary-display)
4762 (pop-up-frames nil)
4763 (diary-list-entries-hook
4764 (cons 'org-diary-default-entry diary-list-entries-hook))
4765 (diary-file-name-prefix-function nil) ; turn this feature off
4766 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4767 entries
4768 (org-disable-agenda-to-diary t))
4769 (save-excursion
4770 (save-window-excursion
4771 (funcall (if (fboundp 'diary-list-entries)
4772 'diary-list-entries 'list-diary-entries)
4773 date 1)))
4774 (if (not (get-buffer diary-fancy-buffer))
4775 (setq entries nil)
4776 (with-current-buffer diary-fancy-buffer
4777 (setq buffer-read-only nil)
4778 (if (zerop (buffer-size))
4779 ;; No entries
4780 (setq entries nil)
4781 ;; Omit the date and other unnecessary stuff
4782 (org-agenda-cleanup-fancy-diary)
4783 ;; Add prefix to each line and extend the text properties
4784 (if (zerop (buffer-size))
4785 (setq entries nil)
4786 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4787 (setq entries
4788 (with-temp-buffer
4789 (insert entries) (goto-char (point-min))
4790 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4791 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4792 (replace-match (concat "; " (match-string 1)))))
4793 (buffer-string)))))
4794 (set-buffer-modified-p nil)
4795 (kill-buffer diary-fancy-buffer)))
4796 (when entries
4797 (setq entries (org-split-string entries "\n"))
4798 (setq entries
4799 (mapcar
4800 (lambda (x)
4801 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
4802 ;; Extend the text properties to the beginning of the line
4803 (org-add-props x (text-properties-at (1- (length x)) x)
4804 'type "diary" 'date date 'face 'org-agenda-diary))
4805 entries)))))
4807 (defvar org-agenda-cleanup-fancy-diary-hook nil
4808 "Hook run when the fancy diary buffer is cleaned up.")
4810 (defun org-agenda-cleanup-fancy-diary ()
4811 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4812 This gets rid of the date, the underline under the date, and
4813 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4814 date. It also removes lines that contain only whitespace."
4815 (goto-char (point-min))
4816 (if (looking-at ".*?:[ \t]*")
4817 (progn
4818 (replace-match "")
4819 (re-search-forward "\n=+$" nil t)
4820 (replace-match "")
4821 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4822 (re-search-forward "\n=+$" nil t)
4823 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4824 (goto-char (point-min))
4825 (while (re-search-forward "^ +\n" nil t)
4826 (replace-match ""))
4827 (goto-char (point-min))
4828 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4829 (replace-match ""))
4830 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4832 ;; Make sure entries from the diary have the right text properties.
4833 (eval-after-load "diary-lib"
4834 '(if (boundp 'diary-modify-entry-list-string-function)
4835 ;; We can rely on the hook, nothing to do
4837 ;; Hook not available, must use advice to make this work
4838 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4839 "Make the position visible."
4840 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4841 (stringp string)
4842 buffer-file-name)
4843 (setq string (org-modify-diary-entry-string string))))))
4845 (defun org-modify-diary-entry-string (string)
4846 "Add text properties to string, allowing org-mode to act on it."
4847 (org-add-props string nil
4848 'mouse-face 'highlight
4849 'help-echo (if buffer-file-name
4850 (format "mouse-2 or RET jump to diary file %s"
4851 (abbreviate-file-name buffer-file-name))
4853 'org-agenda-diary-link t
4854 'org-marker (org-agenda-new-marker (point-at-bol))))
4856 (defun org-diary-default-entry ()
4857 "Add a dummy entry to the diary.
4858 Needed to avoid empty dates which mess up holiday display."
4859 ;; Catch the error if dealing with the new add-to-diary-alist
4860 (when org-disable-agenda-to-diary
4861 (condition-case nil
4862 (org-add-to-diary-list original-date "Org-mode dummy" "")
4863 (error
4864 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4866 (defun org-add-to-diary-list (&rest args)
4867 (if (fboundp 'diary-add-to-list)
4868 (apply 'diary-add-to-list args)
4869 (apply 'add-to-diary-list args)))
4871 (defvar org-diary-last-run-time nil)
4873 ;;;###autoload
4874 (defun org-diary (&rest args)
4875 "Return diary information from org files.
4876 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4877 It accesses org files and extracts information from those files to be
4878 listed in the diary. The function accepts arguments specifying what
4879 items should be listed. For a list of arguments allowed here, see the
4880 variable `org-agenda-entry-types'.
4882 The call in the diary file should look like this:
4884 &%%(org-diary) ~/path/to/some/orgfile.org
4886 Use a separate line for each org file to check. Or, if you omit the file name,
4887 all files listed in `org-agenda-files' will be checked automatically:
4889 &%%(org-diary)
4891 If you don't give any arguments (as in the example above), the default
4892 arguments (:deadline :scheduled :timestamp :sexp) are used.
4893 So the example above may also be written as
4895 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4897 The function expects the lisp variables `entry' and `date' to be provided
4898 by the caller, because this is how the calendar works. Don't use this
4899 function from a program - use `org-agenda-get-day-entries' instead."
4900 (when (> (- (org-float-time)
4901 org-agenda-last-marker-time)
4903 ;; I am not sure if this works with sticky agendas, because the marker
4904 ;; list is then no longer a global variable.
4905 (org-agenda-reset-markers))
4906 (org-compile-prefix-format 'agenda)
4907 (org-set-sorting-strategy 'agenda)
4908 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4909 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4910 (list entry)
4911 (org-agenda-files t)))
4912 (time (org-float-time))
4913 file rtn results)
4914 (when (or (not org-diary-last-run-time)
4915 (> (- time
4916 org-diary-last-run-time)
4918 (org-agenda-prepare-buffers files))
4919 (setq org-diary-last-run-time time)
4920 ;; If this is called during org-agenda, don't return any entries to
4921 ;; the calendar. Org Agenda will list these entries itself.
4922 (if org-disable-agenda-to-diary (setq files nil))
4923 (while (setq file (pop files))
4924 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4925 (setq results (append results rtn)))
4926 (if results
4927 (concat (org-agenda-finalize-entries results) "\n"))))
4929 ;;; Agenda entry finders
4931 (defun org-agenda-get-day-entries (file date &rest args)
4932 "Does the work for `org-diary' and `org-agenda'.
4933 FILE is the path to a file to be checked for entries. DATE is date like
4934 the one returned by `calendar-current-date'. ARGS are symbols indicating
4935 which kind of entries should be extracted. For details about these, see
4936 the documentation of `org-diary'."
4937 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4938 (let* ((org-startup-folded nil)
4939 (org-startup-align-all-tables nil)
4940 (buffer (if (file-exists-p file)
4941 (org-get-agenda-file-buffer file)
4942 (error "No such file %s" file)))
4943 arg results rtn deadline-results)
4944 (if (not buffer)
4945 ;; If file does not exist, make sure an error message ends up in diary
4946 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4947 (with-current-buffer buffer
4948 (unless (derived-mode-p 'org-mode)
4949 (error "Agenda file %s is not in `org-mode'" file))
4950 (setq org-agenda-buffer (or org-agenda-buffer buffer))
4951 (let ((case-fold-search nil))
4952 (save-excursion
4953 (save-restriction
4954 (if org-agenda-restrict
4955 (narrow-to-region org-agenda-restrict-begin
4956 org-agenda-restrict-end)
4957 (widen))
4958 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4959 (while (setq arg (pop args))
4960 (cond
4961 ((and (eq arg :todo)
4962 (equal date (calendar-gregorian-from-absolute
4963 (org-today))))
4964 (setq rtn (org-agenda-get-todos))
4965 (setq results (append results rtn)))
4966 ((eq arg :timestamp)
4967 (setq rtn (org-agenda-get-blocks))
4968 (setq results (append results rtn))
4969 (setq rtn (org-agenda-get-timestamps deadline-results))
4970 (setq results (append results rtn)))
4971 ((eq arg :sexp)
4972 (setq rtn (org-agenda-get-sexps))
4973 (setq results (append results rtn)))
4974 ((eq arg :scheduled)
4975 (setq rtn (org-agenda-get-scheduled deadline-results))
4976 (setq results (append results rtn)))
4977 ((eq arg :closed)
4978 (setq rtn (org-agenda-get-progress))
4979 (setq results (append results rtn)))
4980 ((eq arg :deadline)
4981 (setq rtn (org-agenda-get-deadlines))
4982 (setq deadline-results (copy-sequence rtn))
4983 (setq results (append results rtn))))))))
4984 results))))
4986 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4987 (defun org-agenda-get-todos ()
4988 "Return the TODO information for agenda display."
4989 (let* ((props (list 'face nil
4990 'done-face 'org-agenda-done
4991 'org-not-done-regexp org-not-done-regexp
4992 'org-todo-regexp org-todo-regexp
4993 'org-complex-heading-regexp org-complex-heading-regexp
4994 'mouse-face 'highlight
4995 'help-echo
4996 (format "mouse-2 or RET jump to org file %s"
4997 (abbreviate-file-name buffer-file-name))))
4998 (regexp (format org-heading-keyword-regexp-format
4999 (cond
5000 ((and org-select-this-todo-keyword
5001 (equal org-select-this-todo-keyword "*"))
5002 org-todo-regexp)
5003 (org-select-this-todo-keyword
5004 (concat "\\("
5005 (mapconcat 'identity
5006 (org-split-string
5007 org-select-this-todo-keyword
5008 "|")
5009 "\\|") "\\)"))
5010 (t org-not-done-regexp))))
5011 marker priority category category-pos level tags todo-state
5012 ee txt beg end)
5013 (goto-char (point-min))
5014 (while (re-search-forward regexp nil t)
5015 (catch :skip
5016 (save-match-data
5017 (beginning-of-line)
5018 (org-agenda-skip)
5019 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5020 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5021 (goto-char (1+ beg))
5022 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5023 (throw :skip nil)))
5024 (goto-char (match-beginning 2))
5025 (setq marker (org-agenda-new-marker (match-beginning 0))
5026 category (org-get-category)
5027 category-pos (get-text-property (point) 'org-category-position)
5028 txt (org-trim
5029 (buffer-substring (match-beginning 2) (match-end 0)))
5030 tags (org-get-tags-at (point))
5031 level (make-string (org-reduced-level (org-outline-level)) ? )
5032 txt (org-agenda-format-item "" txt level category tags t)
5033 priority (1+ (org-get-priority txt))
5034 todo-state (org-get-todo-state))
5035 (org-add-props txt props
5036 'org-marker marker 'org-hd-marker marker
5037 'priority priority 'org-category category
5038 'level level
5039 'org-category-position category-pos
5040 'type "todo" 'todo-state todo-state)
5041 (push txt ee)
5042 (if org-agenda-todo-list-sublevels
5043 (goto-char (match-end 2))
5044 (org-end-of-subtree 'invisible))))
5045 (nreverse ee)))
5047 (defun org-agenda-todo-custom-ignore-p (time n)
5048 "Check whether timestamp is farther away than n number of days.
5049 This function is invoked if `org-agenda-todo-ignore-deadlines',
5050 `org-agenda-todo-ignore-scheduled' or
5051 `org-agenda-todo-ignore-timestamp' is set to an integer."
5052 (let ((days (org-time-stamp-to-now
5053 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5054 (if (>= n 0)
5055 (>= days n)
5056 (<= days n))))
5058 ;;;###autoload
5059 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5060 (&optional end)
5061 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5062 (when (or org-agenda-todo-ignore-with-date
5063 org-agenda-todo-ignore-scheduled
5064 org-agenda-todo-ignore-deadlines
5065 org-agenda-todo-ignore-timestamp)
5066 (setq end (or end (save-excursion (outline-next-heading) (point))))
5067 (save-excursion
5068 (or (and org-agenda-todo-ignore-with-date
5069 (re-search-forward org-ts-regexp end t))
5070 (and org-agenda-todo-ignore-scheduled
5071 (re-search-forward org-scheduled-time-regexp end t)
5072 (cond
5073 ((eq org-agenda-todo-ignore-scheduled 'future)
5074 (> (org-time-stamp-to-now
5075 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5076 ((eq org-agenda-todo-ignore-scheduled 'past)
5077 (<= (org-time-stamp-to-now
5078 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5079 ((numberp org-agenda-todo-ignore-scheduled)
5080 (org-agenda-todo-custom-ignore-p
5081 (match-string 1) org-agenda-todo-ignore-scheduled))
5082 (t)))
5083 (and org-agenda-todo-ignore-deadlines
5084 (re-search-forward org-deadline-time-regexp end t)
5085 (cond
5086 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5087 ((eq org-agenda-todo-ignore-deadlines 'far)
5088 (not (org-deadline-close (match-string 1))))
5089 ((eq org-agenda-todo-ignore-deadlines 'future)
5090 (> (org-time-stamp-to-now
5091 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5092 ((eq org-agenda-todo-ignore-deadlines 'past)
5093 (<= (org-time-stamp-to-now
5094 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5095 ((numberp org-agenda-todo-ignore-deadlines)
5096 (org-agenda-todo-custom-ignore-p
5097 (match-string 1) org-agenda-todo-ignore-deadlines))
5098 (t (org-deadline-close (match-string 1)))))
5099 (and org-agenda-todo-ignore-timestamp
5100 (let ((buffer (current-buffer))
5101 (regexp
5102 (concat
5103 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5104 (start (point)))
5105 ;; Copy current buffer into a temporary one
5106 (with-temp-buffer
5107 (insert-buffer-substring buffer start end)
5108 (goto-char (point-min))
5109 ;; Delete SCHEDULED and DEADLINE items
5110 (while (re-search-forward regexp end t)
5111 (delete-region (match-beginning 0) (match-end 0)))
5112 (goto-char (point-min))
5113 ;; No search for timestamp left
5114 (when (re-search-forward org-ts-regexp nil t)
5115 (cond
5116 ((eq org-agenda-todo-ignore-timestamp 'future)
5117 (> (org-time-stamp-to-now
5118 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5119 ((eq org-agenda-todo-ignore-timestamp 'past)
5120 (<= (org-time-stamp-to-now
5121 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5122 ((numberp org-agenda-todo-ignore-timestamp)
5123 (org-agenda-todo-custom-ignore-p
5124 (match-string 1) org-agenda-todo-ignore-timestamp))
5125 (t))))))))))
5127 (defconst org-agenda-no-heading-message
5128 "No heading for this item in buffer or region.")
5130 (defun org-agenda-get-timestamps (&optional deadline-results)
5131 "Return the date stamp information for agenda display."
5132 (let* ((props (list 'face 'org-agenda-calendar-event
5133 'org-not-done-regexp org-not-done-regexp
5134 'org-todo-regexp org-todo-regexp
5135 'org-complex-heading-regexp org-complex-heading-regexp
5136 'mouse-face 'highlight
5137 'help-echo
5138 (format "mouse-2 or RET jump to org file %s"
5139 (abbreviate-file-name buffer-file-name))))
5140 (d1 (calendar-absolute-from-gregorian date))
5142 (deadline-position-alist
5143 (mapcar (lambda (a) (and (setq mm (get-text-property
5144 0 'org-hd-marker a))
5145 (cons (marker-position mm) a)))
5146 deadline-results))
5147 (remove-re org-ts-regexp)
5148 (regexp
5149 (concat
5150 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5151 (regexp-quote
5152 (substring
5153 (format-time-string
5154 (car org-time-stamp-formats)
5155 (apply 'encode-time ; DATE bound by calendar
5156 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5157 1 11))
5158 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5159 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5160 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5161 donep tmp priority category category-pos level ee txt timestr tags
5162 b0 b3 e3 head todo-state end-of-match show-all warntime)
5163 (goto-char (point-min))
5164 (while (setq end-of-match (re-search-forward regexp nil t))
5165 (setq b0 (match-beginning 0)
5166 b3 (match-beginning 3) e3 (match-end 3)
5167 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5168 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5169 (member todo-state
5170 org-agenda-repeating-timestamp-show-all)))
5171 (catch :skip
5172 (and (org-at-date-range-p) (throw :skip nil))
5173 (org-agenda-skip)
5174 (if (and (match-end 1)
5175 (not (= d1 (org-time-string-to-absolute
5176 (match-string 1) d1 nil show-all
5177 (current-buffer) b0))))
5178 (throw :skip nil))
5179 (if (and e3
5180 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5181 (throw :skip nil))
5182 (setq tmp (buffer-substring (max (point-min)
5183 (- b0 org-ds-keyword-length))
5185 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5186 inactivep (= (char-after b0) ?\[)
5187 deadlinep (string-match org-deadline-regexp tmp)
5188 scheduledp (string-match org-scheduled-regexp tmp)
5189 closedp (and org-agenda-include-inactive-timestamps
5190 (string-match org-closed-string tmp))
5191 clockp (and org-agenda-include-inactive-timestamps
5192 (or (string-match org-clock-string tmp)
5193 (string-match "]-+\\'" tmp)))
5194 warntime (org-entry-get (point) "APPT_WARNTIME")
5195 donep (member todo-state org-done-keywords))
5196 (if (or scheduledp deadlinep closedp clockp
5197 (and donep org-agenda-skip-timestamp-if-done))
5198 (throw :skip t))
5199 (if (string-match ">" timestr)
5200 ;; substring should only run to end of time stamp
5201 (setq timestr (substring timestr 0 (match-end 0))))
5202 (setq marker (org-agenda-new-marker b0)
5203 category (org-get-category b0)
5204 category-pos (get-text-property b0 'org-category-position))
5205 (save-excursion
5206 (if (not (re-search-backward org-outline-regexp-bol nil t))
5207 (setq txt org-agenda-no-heading-message)
5208 (goto-char (match-beginning 0))
5209 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5210 (assoc (point) deadline-position-alist))
5211 (throw :skip nil))
5212 (setq hdmarker (org-agenda-new-marker)
5213 tags (org-get-tags-at)
5214 level (make-string (org-reduced-level (org-outline-level)) ? ))
5215 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5216 (setq head (or (match-string 1) ""))
5217 (setq txt (org-agenda-format-item
5218 (if inactivep org-agenda-inactive-leader nil)
5219 head level category tags timestr
5220 remove-re t)))
5221 (setq priority (org-get-priority txt))
5222 (org-add-props txt props 'priority priority
5223 'org-marker marker 'org-hd-marker hdmarker
5224 'org-category category 'date date
5225 'level level
5226 'org-category-position category-pos
5227 'todo-state todo-state
5228 'warntime warntime
5229 'type "timestamp")
5230 (push txt ee))
5231 (if org-agenda-skip-additional-timestamps-same-entry
5232 (outline-next-heading)
5233 (goto-char end-of-match))))
5234 (nreverse ee)))
5236 (defun org-agenda-get-sexps ()
5237 "Return the sexp information for agenda display."
5238 (require 'diary-lib)
5239 (let* ((props (list 'face 'org-agenda-calendar-sexp
5240 'mouse-face 'highlight
5241 'help-echo
5242 (format "mouse-2 or RET jump to org file %s"
5243 (abbreviate-file-name buffer-file-name))))
5244 (regexp "^&?%%(")
5245 marker category extra category-pos level ee txt tags entry
5246 result beg b sexp sexp-entry todo-state warntime)
5247 (goto-char (point-min))
5248 (while (re-search-forward regexp nil t)
5249 (catch :skip
5250 (org-agenda-skip)
5251 (setq beg (match-beginning 0))
5252 (goto-char (1- (match-end 0)))
5253 (setq b (point))
5254 (forward-sexp 1)
5255 (setq sexp (buffer-substring b (point)))
5256 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5257 (org-trim (match-string 1))
5258 ""))
5259 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5260 (when result
5261 (setq marker (org-agenda-new-marker beg)
5262 level (make-string (org-reduced-level (org-outline-level)) ? )
5263 category (org-get-category beg)
5264 category-pos (get-text-property beg 'org-category-position)
5265 tags (save-excursion (org-backward-heading-same-level 0)
5266 (org-get-tags-at))
5267 todo-state (org-get-todo-state)
5268 warntime (org-entry-get (point) "APPT_WARNTIME"))
5270 (dolist (r (if (stringp result)
5271 (list result)
5272 result)) ;; we expect a list here
5273 (when (and org-agenda-diary-sexp-prefix
5274 (string-match org-agenda-diary-sexp-prefix r))
5275 (setq extra (match-string 0 r)
5276 r (replace-match "" nil nil r)))
5277 (if (string-match "\\S-" r)
5278 (setq txt r)
5279 (setq txt "SEXP entry returned empty string"))
5280 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5281 (org-add-props txt props 'org-marker marker
5282 'org-category category 'date date 'todo-state todo-state
5283 'org-category-position category-pos 'tags tags
5284 'level level
5285 'type "sexp" 'warntime warntime)
5286 (push txt ee)))))
5287 (nreverse ee)))
5289 ;; Calendar sanity: define some functions that are independent of
5290 ;; `calendar-date-style'.
5291 ;; Normally I would like to use ISO format when calling the diary functions,
5292 ;; but to make sure we still have Emacs 22 compatibility we bind
5293 ;; also `european-calendar-style' and use european format
5294 (defun org-anniversary (year month day &optional mark)
5295 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5296 (org-no-warnings
5297 (let ((calendar-date-style 'european) (european-calendar-style t))
5298 (diary-anniversary day month year mark))))
5299 (defun org-cyclic (N year month day &optional mark)
5300 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5301 (org-no-warnings
5302 (let ((calendar-date-style 'european) (european-calendar-style t))
5303 (diary-cyclic N day month year mark))))
5304 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5305 "Like `diary-block', but with fixed (ISO) order of arguments."
5306 (org-no-warnings
5307 (let ((calendar-date-style 'european) (european-calendar-style t))
5308 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5309 (defun org-date (year month day &optional mark)
5310 "Like `diary-date', but with fixed (ISO) order of arguments."
5311 (org-no-warnings
5312 (let ((calendar-date-style 'european) (european-calendar-style t))
5313 (diary-date day month year mark))))
5314 (defalias 'org-float 'diary-float)
5316 ;; Define the` org-class' function
5317 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5318 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5319 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5320 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5321 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5322 `holidays', then any date that is known by the Emacs calendar to be a
5323 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5324 then those holidays will be skipped."
5325 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5326 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5327 (d (calendar-absolute-from-gregorian date))
5328 (h (when skip-weeks (calendar-check-holidays date))))
5329 (and
5330 (<= date1 d)
5331 (<= d date2)
5332 (= (calendar-day-of-week date) dayname)
5333 (or (not skip-weeks)
5334 (progn
5335 (require 'cal-iso)
5336 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5337 (not (or (and h (memq 'holidays skip-weeks))
5338 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5339 entry)))
5341 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5342 "Like `org-class', but honor `calendar-date-style'.
5343 The order of the first 2 times 3 arguments depends on the variable
5344 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5345 So for American calendars, give this as MONTH DAY YEAR, for European as
5346 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5347 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5348 is any number of ISO weeks in the block period for which the item should
5349 be skipped.
5351 This function is here only for backward compatibility and it is deprecated,
5352 please use `org-class' instead."
5353 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5354 (date2 (org-order-calendar-date-args m2 d2 y2)))
5355 (org-class
5356 (nth 2 date1) (car date1) (nth 1 date1)
5357 (nth 2 date2) (car date2) (nth 1 date2)
5358 dayname skip-weeks)))
5359 (make-obsolete 'org-diary-class 'org-class "")
5361 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5362 (defalias 'org-get-closed 'org-agenda-get-progress)
5363 (defun org-agenda-get-progress ()
5364 "Return the logged TODO entries for agenda display."
5365 (let* ((props (list 'mouse-face 'highlight
5366 'org-not-done-regexp org-not-done-regexp
5367 'org-todo-regexp org-todo-regexp
5368 'org-complex-heading-regexp org-complex-heading-regexp
5369 'help-echo
5370 (format "mouse-2 or RET jump to org file %s"
5371 (abbreviate-file-name buffer-file-name))))
5372 (items (if (consp org-agenda-show-log-scoped)
5373 org-agenda-show-log-scoped
5374 (if (eq org-agenda-show-log-scoped 'clockcheck)
5375 '(clock)
5376 org-agenda-log-mode-items)))
5377 (parts
5378 (delq nil
5379 (list
5380 (if (memq 'closed items) (concat "\\<" org-closed-string))
5381 (if (memq 'clock items) (concat "\\<" org-clock-string))
5382 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5383 (parts-re (if parts (mapconcat 'identity parts "\\|")
5384 (error "`org-agenda-log-mode-items' is empty")))
5385 (regexp (concat
5386 "\\(" parts-re "\\)"
5387 " *\\["
5388 (regexp-quote
5389 (substring
5390 (format-time-string
5391 (car org-time-stamp-formats)
5392 (apply 'encode-time ; DATE bound by calendar
5393 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5394 1 11))))
5395 (org-agenda-search-headline-for-time nil)
5396 marker hdmarker priority category category-pos level tags closedp
5397 statep clockp state ee txt extra timestr rest clocked)
5398 (goto-char (point-min))
5399 (while (re-search-forward regexp nil t)
5400 (catch :skip
5401 (org-agenda-skip)
5402 (setq marker (org-agenda-new-marker (match-beginning 0))
5403 closedp (equal (match-string 1) org-closed-string)
5404 statep (equal (string-to-char (match-string 1)) ?-)
5405 clockp (not (or closedp statep))
5406 state (and statep (match-string 2))
5407 category (org-get-category (match-beginning 0))
5408 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5409 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5410 (when (string-match "\\]" timestr)
5411 ;; substring should only run to end of time stamp
5412 (setq rest (substring timestr (match-end 0))
5413 timestr (substring timestr 0 (match-end 0)))
5414 (if (and (not closedp) (not statep)
5415 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5416 rest))
5417 (progn (setq timestr (concat (substring timestr 0 -1)
5418 "-" (match-string 1 rest) "]"))
5419 (setq clocked (match-string 2 rest)))
5420 (setq clocked "-")))
5421 (save-excursion
5422 (setq extra
5423 (cond
5424 ((not org-agenda-log-mode-add-notes) nil)
5425 (statep
5426 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5427 (match-string 1)))
5428 (clockp
5429 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5430 (match-string 1)))))
5431 (if (not (re-search-backward org-outline-regexp-bol nil t))
5432 (setq txt org-agenda-no-heading-message)
5433 (goto-char (match-beginning 0))
5434 (setq hdmarker (org-agenda-new-marker)
5435 tags (org-get-tags-at)
5436 level (make-string (org-reduced-level (org-outline-level)) ? ))
5437 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5438 (setq txt (match-string 1))
5439 (when extra
5440 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5441 (setq txt (concat (substring txt 0 (match-beginning 1))
5442 " - " extra " " (match-string 2 txt)))
5443 (setq txt (concat txt " - " extra))))
5444 (setq txt (org-agenda-format-item
5445 (cond
5446 (closedp "Closed: ")
5447 (statep (concat "State: (" state ")"))
5448 (t (concat "Clocked: (" clocked ")")))
5449 txt level category tags timestr)))
5450 (setq priority 100000)
5451 (org-add-props txt props
5452 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5453 'priority priority 'org-category category
5454 'org-category-position category-pos
5455 'level level
5456 'type "closed" 'date date
5457 'undone-face 'org-warning 'done-face 'org-agenda-done)
5458 (push txt ee))
5459 (goto-char (point-at-eol))))
5460 (nreverse ee)))
5462 (defun org-agenda-show-clocking-issues ()
5463 "Add overlays, showing issues with clocking.
5464 See also the user option `org-agenda-clock-consistency-checks'."
5465 (interactive)
5466 (let* ((pl org-agenda-clock-consistency-checks)
5467 (re (concat "^[ \t]*"
5468 org-clock-string
5469 "[ \t]+"
5470 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5471 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5472 (tlstart 0.)
5473 (tlend 0.)
5474 (maxtime (org-hh:mm-string-to-minutes
5475 (or (plist-get pl :max-duration) "24:00")))
5476 (mintime (org-hh:mm-string-to-minutes
5477 (or (plist-get pl :min-duration) 0)))
5478 (maxgap (org-hh:mm-string-to-minutes
5479 ;; default 30:00 means never complain
5480 (or (plist-get pl :max-gap) "30:00")))
5481 (gapok (mapcar 'org-hh:mm-string-to-minutes
5482 (plist-get pl :gap-ok-around)))
5483 (def-face (or (plist-get pl :default-face)
5484 '((:background "DarkRed") (:foreground "white"))))
5485 issue face m te ts dt ov)
5486 (goto-char (point-min))
5487 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5488 (setq issue nil face def-face)
5489 (catch 'next
5490 (setq m (org-get-at-bol 'org-marker)
5491 te nil ts nil)
5492 (unless (and m (markerp m))
5493 (setq issue "No valid clock line") (throw 'next t))
5494 (org-with-point-at m
5495 (save-excursion
5496 (goto-char (point-at-bol))
5497 (unless (looking-at re)
5498 (error "No valid Clock line")
5499 (throw 'next t))
5500 (unless (match-end 3)
5501 (setq issue "No end time"
5502 face (or (plist-get pl :no-end-time-face) face))
5503 (throw 'next t))
5504 (setq ts (match-string 1)
5505 te (match-string 3)
5506 ts (org-float-time
5507 (apply 'encode-time (org-parse-time-string ts)))
5508 te (org-float-time
5509 (apply 'encode-time (org-parse-time-string te)))
5510 dt (- te ts))))
5511 (cond
5512 ((> dt (* 60 maxtime))
5513 ;; a very long clocking chunk
5514 (setq issue (format "Clocking interval is very long: %s"
5515 (org-minutes-to-hh:mm-string
5516 (floor (/ (float dt) 60.))))
5517 face (or (plist-get pl :long-face) face)))
5518 ((< dt (* 60 mintime))
5519 ;; a very short clocking chunk
5520 (setq issue (format "Clocking interval is very short: %s"
5521 (org-minutes-to-hh:mm-string
5522 (floor (/ (float dt) 60.))))
5523 face (or (plist-get pl :short-face) face)))
5524 ((and (> tlend 0) (< ts tlend))
5525 ;; Two clock entries are overlapping
5526 (setq issue (format "Clocking overlap: %d minutes"
5527 (/ (- tlend ts) 60))
5528 face (or (plist-get pl :overlap-face) face)))
5529 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5530 ;; There is a gap, lets see if we need to report it
5531 (unless (org-agenda-check-clock-gap tlend ts gapok)
5532 (setq issue (format "Clocking gap: %d minutes"
5533 (/ (- ts tlend) 60))
5534 face (or (plist-get pl :gap-face) face))))
5535 (t nil)))
5536 (setq tlend (or te tlend) tlstart (or ts tlstart))
5537 (when issue
5538 ;; OK, there was some issue, add an overlay to show the issue
5539 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5540 (overlay-put ov 'before-string
5541 (concat
5542 (org-add-props
5543 (format "%-43s" (concat " " issue))
5545 'face face)
5546 "\n"))
5547 (overlay-put ov 'evaporate t)))))
5549 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5550 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5551 (catch 'exit
5552 (unless ok-list
5553 ;; there are no OK times for gaps...
5554 (throw 'exit nil))
5555 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5556 ;; This is more than 24 hours, so it is OK.
5557 ;; because we have at least one OK time, that must be in the
5558 ;; 24 hour interval.
5559 (throw 'exit t))
5560 ;; We have a shorter gap.
5561 ;; Now we have to get the minute of the day when these times are
5562 (let* ((t1dec (decode-time (seconds-to-time t1)))
5563 (t2dec (decode-time (seconds-to-time t2)))
5564 ;; compute the minute on the day
5565 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5566 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5567 (when (< min2 min1)
5568 ;; if min2 is smaller than min1, this means it is on the next day.
5569 ;; Wrap it to after midnight.
5570 (setq min2 (+ min2 1440)))
5571 ;; Now check if any of the OK times is in the gap
5572 (mapc (lambda (x)
5573 ;; Wrap the time to after midnight if necessary
5574 (if (< x min1) (setq x (+ x 1440)))
5575 ;; Check if in interval
5576 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5577 ok-list)
5578 ;; Nope, this gap is not OK
5579 nil)))
5581 (defun org-agenda-get-deadlines ()
5582 "Return the deadline information for agenda display."
5583 (let* ((props (list 'mouse-face 'highlight
5584 'org-not-done-regexp org-not-done-regexp
5585 'org-todo-regexp org-todo-regexp
5586 'org-complex-heading-regexp org-complex-heading-regexp
5587 'help-echo
5588 (format "mouse-2 or RET jump to org file %s"
5589 (abbreviate-file-name buffer-file-name))))
5590 (regexp org-deadline-time-regexp)
5591 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5592 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5593 d2 diff dfrac wdays pos pos1 category category-pos level
5594 tags suppress-prewarning ee txt head face s todo-state
5595 show-all upcomingp donep timestr warntime)
5596 (goto-char (point-min))
5597 (while (re-search-forward regexp nil t)
5598 (setq suppress-prewarning nil)
5599 (catch :skip
5600 (org-agenda-skip)
5601 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5602 (save-match-data
5603 (string-match org-scheduled-time-regexp
5604 (buffer-substring (point-at-bol)
5605 (point-at-eol)))))
5606 (setq suppress-prewarning
5607 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5608 org-agenda-skip-deadline-prewarning-if-scheduled
5609 0)))
5610 (setq s (match-string 1)
5611 txt nil
5612 pos (1- (match-beginning 1))
5613 todo-state (save-match-data (org-get-todo-state))
5614 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5615 (member todo-state
5616 org-agenda-repeating-timestamp-show-all))
5617 d2 (org-time-string-to-absolute
5618 (match-string 1) d1 'past show-all
5619 (current-buffer) pos)
5620 diff (- d2 d1)
5621 wdays (if suppress-prewarning
5622 (let ((org-deadline-warning-days suppress-prewarning))
5623 (org-get-wdays s))
5624 (org-get-wdays s))
5625 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5626 upcomingp (and todayp (> diff 0)))
5627 ;; When to show a deadline in the calendar:
5628 ;; If the expiration is within wdays warning time.
5629 ;; Past-due deadlines are only shown on the current date
5630 (if (and (or (and (<= diff wdays)
5631 (and todayp (not org-agenda-only-exact-dates)))
5632 (= diff 0)))
5633 (save-excursion
5634 ;; (setq todo-state (org-get-todo-state))
5635 (setq donep (member todo-state org-done-keywords))
5636 (if (and donep
5637 (or org-agenda-skip-deadline-if-done
5638 (not (= diff 0))))
5639 (setq txt nil)
5640 (setq category (org-get-category)
5641 warntime (org-entry-get (point) "APPT_WARNTIME")
5642 category-pos (get-text-property (point) 'org-category-position))
5643 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5644 (setq txt org-agenda-no-heading-message)
5645 (goto-char (match-end 0))
5646 (setq pos1 (match-beginning 0))
5647 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5648 (setq tags (org-get-tags-at pos1))
5649 (setq head (buffer-substring-no-properties
5650 (point)
5651 (progn (skip-chars-forward "^\r\n")
5652 (point))))
5653 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5654 (setq timestr
5655 (concat (substring s (match-beginning 1)) " "))
5656 (setq timestr 'time))
5657 (setq txt (org-agenda-format-item
5658 (if (= diff 0)
5659 (car org-agenda-deadline-leaders)
5660 (if (functionp
5661 (nth 1 org-agenda-deadline-leaders))
5662 (funcall
5663 (nth 1 org-agenda-deadline-leaders)
5664 diff date)
5665 (format (nth 1 org-agenda-deadline-leaders)
5666 diff)))
5667 head level category tags
5668 (if (not (= diff 0)) nil timestr)))))
5669 (when txt
5670 (setq face (org-agenda-deadline-face dfrac))
5671 (org-add-props txt props
5672 'org-marker (org-agenda-new-marker pos)
5673 'warntime warntime
5674 'level level
5675 'org-hd-marker (org-agenda-new-marker pos1)
5676 'priority (+ (- diff)
5677 (org-get-priority txt))
5678 'org-category category
5679 'org-category-position category-pos
5680 'todo-state todo-state
5681 'type (if upcomingp "upcoming-deadline" "deadline")
5682 'date (if upcomingp date d2)
5683 'face (if donep 'org-agenda-done face)
5684 'undone-face face 'done-face 'org-agenda-done)
5685 (push txt ee))))))
5686 (nreverse ee)))
5688 (defun org-agenda-deadline-face (fraction)
5689 "Return the face to displaying a deadline item.
5690 FRACTION is what fraction of the head-warning time has passed."
5691 (let ((faces org-agenda-deadline-faces) f)
5692 (catch 'exit
5693 (while (setq f (pop faces))
5694 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5696 (defun org-agenda-get-scheduled (&optional deadline-results)
5697 "Return the scheduled information for agenda display."
5698 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5699 'org-todo-regexp org-todo-regexp
5700 'org-complex-heading-regexp org-complex-heading-regexp
5701 'done-face 'org-agenda-done
5702 'mouse-face 'highlight
5703 'help-echo
5704 (format "mouse-2 or RET jump to org file %s"
5705 (abbreviate-file-name buffer-file-name))))
5706 (regexp org-scheduled-time-regexp)
5707 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5708 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5710 (deadline-position-alist
5711 (mapcar (lambda (a) (and (setq mm (get-text-property
5712 0 'org-hd-marker a))
5713 (cons (marker-position mm) a)))
5714 deadline-results))
5715 d2 diff pos pos1 category category-pos level tags donep
5716 ee txt head pastschedp todo-state face timestr s habitp show-all
5717 did-habit-check-p warntime)
5718 (goto-char (point-min))
5719 (while (re-search-forward regexp nil t)
5720 (catch :skip
5721 (org-agenda-skip)
5722 (setq s (match-string 1)
5723 txt nil
5724 pos (1- (match-beginning 1))
5725 todo-state (save-match-data (org-get-todo-state))
5726 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5727 (member todo-state
5728 org-agenda-repeating-timestamp-show-all))
5729 d2 (org-time-string-to-absolute
5730 (match-string 1) d1 'past show-all
5731 (current-buffer) pos)
5732 diff (- d2 d1)
5733 warntime (org-entry-get (point) "APPT_WARNTIME"))
5734 (setq pastschedp (and todayp (< diff 0)))
5735 (setq did-habit-check-p nil)
5736 ;; When to show a scheduled item in the calendar:
5737 ;; If it is on or past the date.
5738 (when (or (and (< diff 0)
5739 (< (abs diff) org-scheduled-past-days)
5740 (and todayp (not org-agenda-only-exact-dates)))
5741 (= diff 0)
5742 ;; org-is-habit-p uses org-entry-get, which is expansive
5743 ;; so we go extra mile to only call it once
5744 (and todayp
5745 (boundp 'org-habit-show-all-today)
5746 org-habit-show-all-today
5747 (setq did-habit-check-p t)
5748 (setq habitp (and (functionp 'org-is-habit-p)
5749 (org-is-habit-p)))))
5750 (save-excursion
5751 (setq donep (member todo-state org-done-keywords))
5752 (if (and donep
5753 (or org-agenda-skip-scheduled-if-done
5754 (not (= diff 0))
5755 (and (functionp 'org-is-habit-p)
5756 (org-is-habit-p))))
5757 (setq txt nil)
5758 (setq habitp (if did-habit-check-p habitp
5759 (and (functionp 'org-is-habit-p)
5760 (org-is-habit-p))))
5761 (setq category (org-get-category)
5762 category-pos (get-text-property (point) 'org-category-position))
5763 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5764 (setq txt org-agenda-no-heading-message)
5765 (goto-char (match-end 0))
5766 (setq pos1 (match-beginning 0))
5767 (if habitp
5768 (if (or (not org-habit-show-habits)
5769 (and (not todayp)
5770 (boundp 'org-habit-show-habits-only-for-today)
5771 org-habit-show-habits-only-for-today))
5772 (throw :skip nil))
5773 (if (and
5774 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5775 (and org-agenda-skip-scheduled-if-deadline-is-shown
5776 pastschedp))
5777 (setq mm (assoc pos1 deadline-position-alist)))
5778 (throw :skip nil)))
5779 (setq tags (org-get-tags-at))
5780 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5781 (setq head (buffer-substring-no-properties
5782 (point)
5783 (progn (skip-chars-forward "^\r\n") (point))))
5784 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5785 (setq timestr
5786 (concat (substring s (match-beginning 1)) " "))
5787 (setq timestr 'time))
5788 (setq txt (org-agenda-format-item
5789 (if (= diff 0)
5790 (car org-agenda-scheduled-leaders)
5791 (format (nth 1 org-agenda-scheduled-leaders)
5792 (- 1 diff)))
5793 head level category tags
5794 (if (not (= diff 0)) nil timestr)
5795 nil habitp))))
5796 (when txt
5797 (setq face
5798 (cond
5799 ((and (not habitp) pastschedp)
5800 'org-scheduled-previously)
5801 (todayp 'org-scheduled-today)
5802 (t 'org-scheduled))
5803 habitp (and habitp (org-habit-parse-todo)))
5804 (org-add-props txt props
5805 'undone-face face
5806 'face (if donep 'org-agenda-done face)
5807 'org-marker (org-agenda-new-marker pos)
5808 'org-hd-marker (org-agenda-new-marker pos1)
5809 'type (if pastschedp "past-scheduled" "scheduled")
5810 'date (if pastschedp d2 date)
5811 'warntime warntime
5812 'level level
5813 'priority (if habitp
5814 (org-habit-get-priority habitp)
5815 (+ 94 (- 5 diff) (org-get-priority txt)))
5816 'org-category category
5817 'category-position category-pos
5818 'org-habit-p habitp
5819 'todo-state todo-state)
5820 (push txt ee))))))
5821 (nreverse ee)))
5823 (defun org-agenda-get-blocks ()
5824 "Return the date-range information for agenda display."
5825 (let* ((props (list 'face nil
5826 'org-not-done-regexp org-not-done-regexp
5827 'org-todo-regexp org-todo-regexp
5828 'org-complex-heading-regexp org-complex-heading-regexp
5829 'mouse-face 'highlight
5830 'help-echo
5831 (format "mouse-2 or RET jump to org file %s"
5832 (abbreviate-file-name buffer-file-name))))
5833 (regexp org-tr-regexp)
5834 (d0 (calendar-absolute-from-gregorian date))
5835 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5836 level todo-state tags pos head donep)
5837 (goto-char (point-min))
5838 (while (re-search-forward regexp nil t)
5839 (catch :skip
5840 (org-agenda-skip)
5841 (setq pos (point))
5842 (let ((start-time (match-string 1))
5843 (end-time (match-string 2)))
5844 (setq s1 (match-string 1)
5845 s2 (match-string 2)
5846 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5847 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5848 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5849 ;; Only allow days between the limits, because the normal
5850 ;; date stamps will catch the limits.
5851 (save-excursion
5852 (setq todo-state (org-get-todo-state))
5853 (setq donep (member todo-state org-done-keywords))
5854 (if (and donep org-agenda-skip-timestamp-if-done)
5855 (throw :skip t))
5856 (setq marker (org-agenda-new-marker (point)))
5857 (setq category (org-get-category)
5858 category-pos (get-text-property (point) 'org-category-position))
5859 (if (not (re-search-backward org-outline-regexp-bol nil t))
5860 (setq txt org-agenda-no-heading-message)
5861 (goto-char (match-beginning 0))
5862 (setq hdmarker (org-agenda-new-marker (point)))
5863 (setq tags (org-get-tags-at))
5864 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5865 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5866 (setq head (match-string 1))
5867 (let ((remove-re
5868 (if org-agenda-remove-timeranges-from-blocks
5869 (concat
5870 "<" (regexp-quote s1) ".*?>"
5871 "--"
5872 "<" (regexp-quote s2) ".*?>")
5873 nil)))
5874 (setq txt (org-agenda-format-item
5875 (format
5876 (nth (if (= d1 d2) 0 1)
5877 org-agenda-timerange-leaders)
5878 (1+ (- d0 d1)) (1+ (- d2 d1)))
5879 head level category tags
5880 (cond ((and (= d1 d0) (= d2 d0))
5881 (concat "<" start-time ">--<" end-time ">"))
5882 ((= d1 d0)
5883 (concat "<" start-time ">"))
5884 ((= d2 d0)
5885 (concat "<" end-time ">")))
5886 remove-re t))))
5887 (org-add-props txt props
5888 'org-marker marker 'org-hd-marker hdmarker
5889 'type "block" 'date date
5890 'level level
5891 'todo-state todo-state
5892 'priority (org-get-priority txt) 'org-category category
5893 'org-category-position category-pos)
5894 (push txt ee))))
5895 (goto-char pos)))
5896 ;; Sort the entries by expiration date.
5897 (nreverse ee)))
5899 ;;; Agenda presentation and sorting
5901 (defvar org-prefix-has-time nil
5902 "A flag, set by `org-compile-prefix-format'.
5903 The flag is set if the currently compiled format contains a `%t'.")
5904 (defvar org-prefix-has-tag nil
5905 "A flag, set by `org-compile-prefix-format'.
5906 The flag is set if the currently compiled format contains a `%T'.")
5907 (defvar org-prefix-has-effort nil
5908 "A flag, set by `org-compile-prefix-format'.
5909 The flag is set if the currently compiled format contains a `%e'.")
5910 (defvar org-prefix-category-length nil
5911 "Used by `org-compile-prefix-format' to remember the category field width.")
5912 (defvar org-prefix-category-max-length nil
5913 "Used by `org-compile-prefix-format' to remember the category field width.")
5915 (defun org-agenda-get-category-icon (category)
5916 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5917 (dolist (entry org-agenda-category-icon-alist)
5918 (when (org-string-match-p (car entry) category)
5919 (if (listp (cadr entry))
5920 (return (cadr entry))
5921 (return (apply 'create-image (cdr entry)))))))
5923 (defun org-agenda-format-item (extra txt &optional level category tags dotime
5924 remove-re habitp)
5925 "Format TXT to be inserted into the agenda buffer.
5926 In particular, add the prefix and corresponding text properties.
5928 EXTRA must be a string to replace the `%s' specifier in the prefix format.
5929 LEVEL may be a string to replace the `%l' specifier.
5930 CATEGORY (a string, a symbol or nil) may be used to overrule the default
5931 category taken from local variable or file name. It will replace the `%c'
5932 specifier in the format.
5933 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
5934 TXT for sorting of this entry, and for the `%t' specifier in the format.
5935 When DOTIME is a string, this string is searched for a time before TXT is.
5936 TAGS can be the tags of the headline.
5937 Any match of REMOVE-RE will be removed from TXT."
5938 ;; We keep the org-prefix-* variable values along with a compiled
5939 ;; formatter, so that multiple agendas existing at the same time do
5940 ;; not step on each other toes.
5942 ;; It was inconvenient to make these variables buffer local in
5943 ;; Agenda buffers, because this function expects to be called with
5944 ;; the buffer where item comes from being current, and not agenda
5945 ;; buffer
5946 (let* ((bindings (car org-prefix-format-compiled))
5947 (formatter (cadr org-prefix-format-compiled)))
5948 (loop for (var value) in bindings
5949 do (set var value))
5950 (save-match-data
5951 ;; Diary entries sometimes have extra whitespace at the beginning
5952 (setq txt (org-trim txt))
5954 ;; Fix the tags part in txt
5955 (setq txt (org-agenda-fix-displayed-tags
5956 txt tags
5957 org-agenda-show-inherited-tags
5958 org-agenda-hide-tags-regexp))
5960 (let* ((category (or category
5961 (if (stringp org-category)
5962 org-category
5963 (and org-category (symbol-name org-category)))
5964 (if buffer-file-name
5965 (file-name-sans-extension
5966 (file-name-nondirectory buffer-file-name))
5967 "")))
5968 (category-icon (org-agenda-get-category-icon category))
5969 (category-icon (if category-icon
5970 (propertize " " 'display category-icon)
5971 ""))
5972 ;; time, tag, effort are needed for the eval of the prefix format
5973 (tag (if tags (nth (1- (length tags)) tags) ""))
5974 time effort neffort
5975 (ts (if dotime (concat
5976 (if (stringp dotime) dotime "")
5977 (and org-agenda-search-headline-for-time txt))))
5978 (time-of-day (and dotime (org-get-time-of-day ts)))
5979 stamp plain s0 s1 s2 rtn srp l
5980 duration thecategory)
5981 (and (derived-mode-p 'org-mode) buffer-file-name
5982 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5983 (when (and dotime time-of-day)
5984 ;; Extract starting and ending time and move them to prefix
5985 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5986 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5987 (setq s0 (match-string 0 ts)
5988 srp (and stamp (match-end 3))
5989 s1 (match-string (if plain 1 2) ts)
5990 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5992 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5993 ;; them, we might want to remove them there to avoid duplication.
5994 ;; The user can turn this off with a variable.
5995 (if (and org-prefix-has-time
5996 org-agenda-remove-times-when-in-prefix (or stamp plain)
5997 (string-match (concat (regexp-quote s0) " *") txt)
5998 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5999 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6000 (= (match-beginning 0) 0)
6002 (setq txt (replace-match "" nil nil txt))))
6003 ;; Normalize the time(s) to 24 hour
6004 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6005 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6007 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6008 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6009 (setq s2
6010 (org-minutes-to-hh:mm-string
6011 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6013 ;; Compute the duration
6014 (when s2
6015 (setq duration (- (org-hh:mm-string-to-minutes s2)
6016 (org-hh:mm-string-to-minutes s1)))))
6018 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6019 txt)
6020 ;; Tags are in the string
6021 (if (or (eq org-agenda-remove-tags t)
6022 (and org-agenda-remove-tags
6023 org-prefix-has-tag))
6024 (setq txt (replace-match "" t t txt))
6025 (setq txt (replace-match
6026 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6027 (match-string 2 txt))
6028 t t txt))))
6029 (when (derived-mode-p 'org-mode)
6030 (setq effort
6031 (condition-case nil
6032 (org-get-effort
6033 (or (get-text-property 0 'org-hd-marker txt)
6034 (get-text-property 0 'org-marker txt)))
6035 (error nil)))
6036 (when effort
6037 (setq neffort (org-duration-string-to-minutes effort)
6038 effort (setq effort (concat "[" effort "]")))))
6039 ;; prevent erroring out with %e format when there is no effort
6040 (or effort (setq effort ""))
6042 (when remove-re
6043 (while (string-match remove-re txt)
6044 (setq txt (replace-match "" t t txt))))
6046 ;; Set org-heading property on `txt' to mark the start of the
6047 ;; heading.
6048 (add-text-properties 0 (length txt) '(org-heading t) txt)
6050 ;; Prepare the variables needed in the eval of the compiled format
6051 (setq time (cond (s2 (concat
6052 (org-agenda-time-of-day-to-ampm-maybe s1)
6053 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6054 (if org-agenda-timegrid-use-ampm " ")))
6055 (s1 (concat
6056 (org-agenda-time-of-day-to-ampm-maybe s1)
6057 (if org-agenda-timegrid-use-ampm
6058 "........ "
6059 "......")))
6060 (t ""))
6061 extra (or (and (not habitp) extra) "")
6062 category (if (symbolp category) (symbol-name category) category)
6063 thecategory (copy-sequence category)
6064 level (or level ""))
6065 (if (string-match org-bracket-link-regexp category)
6066 (progn
6067 (setq l (if (match-end 3)
6068 (- (match-end 3) (match-beginning 3))
6069 (- (match-end 1) (match-beginning 1))))
6070 (when (< l (or org-prefix-category-length 0))
6071 (setq category (copy-sequence category))
6072 (org-add-props category nil
6073 'extra-space (make-string
6074 (- org-prefix-category-length l 1) ?\ ))))
6075 (if (and org-prefix-category-max-length
6076 (>= (length category) org-prefix-category-max-length))
6077 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6078 ;; Evaluate the compiled format
6079 (setq rtn (concat (eval formatter) txt))
6081 ;; And finally add the text properties
6082 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6083 (org-add-props rtn nil
6084 'org-category (if thecategory (downcase thecategory) category)
6085 'tags (mapcar 'org-downcase-keep-props tags)
6086 'org-highest-priority org-highest-priority
6087 'org-lowest-priority org-lowest-priority
6088 'time-of-day time-of-day
6089 'duration duration
6090 'effort effort
6091 'effort-minutes neffort
6092 'txt txt
6093 'level level
6094 'time time
6095 'extra extra
6096 'format org-prefix-format-compiled
6097 'dotime dotime)))))
6099 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6100 "Remove tags string from TXT, and add a modified list of tags.
6101 The modified list may contain inherited tags, and tags matched by
6102 `org-agenda-hide-tags-regexp' will be removed."
6103 (when (or add-inherited hide-re)
6104 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6105 (setq txt (substring txt 0 (match-beginning 0))))
6106 (setq tags
6107 (delq nil
6108 (mapcar (lambda (tg)
6109 (if (or (and hide-re (string-match hide-re tg))
6110 (and (not add-inherited)
6111 (get-text-property 0 'inherited tg)))
6113 tg))
6114 tags)))
6115 (when tags
6116 (let ((have-i (get-text-property 0 'inherited (car tags)))
6118 (setq txt (concat txt " :"
6119 (mapconcat
6120 (lambda (x)
6121 (setq i (get-text-property 0 'inherited x))
6122 (if (and have-i (not i))
6123 (progn
6124 (setq have-i nil)
6125 (concat ":" x))
6127 tags ":")
6128 (if have-i "::" ":"))))))
6129 txt)
6131 (defun org-downcase-keep-props (s)
6132 (let ((props (text-properties-at 0 s)))
6133 (setq s (downcase s))
6134 (add-text-properties 0 (length s) props s)
6137 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6138 (defvar org-agenda-sorting-strategy-selected nil)
6140 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6141 "Add a time-grid for agenda items which need it.
6143 LIST is the list of agenda items formatted by `org-agenda-list'.
6144 NDAYS is the span of the current agenda view.
6145 TODAYP is `t' when the current agenda view is on today."
6146 (catch 'exit
6147 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6148 ((and todayp (member 'today (car org-agenda-time-grid))))
6149 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6150 ((member 'weekly (car org-agenda-time-grid)))
6151 (t (throw 'exit list)))
6152 (let* ((have (delq nil (mapcar
6153 (lambda (x) (get-text-property 1 'time-of-day x))
6154 list)))
6155 (string (nth 1 org-agenda-time-grid))
6156 (gridtimes (nth 2 org-agenda-time-grid))
6157 (req (car org-agenda-time-grid))
6158 (remove (member 'remove-match req))
6159 new time)
6160 (if (and (member 'require-timed req) (not have))
6161 ;; don't show empty grid
6162 (throw 'exit list))
6163 (while (setq time (pop gridtimes))
6164 (unless (and remove (member time have))
6165 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6166 (push (org-agenda-format-item
6167 nil string nil "" nil
6168 (concat (substring time 0 -2) ":" (substring time -2)))
6169 new)
6170 (put-text-property
6171 2 (length (car new)) 'face 'org-time-grid (car new))))
6172 (when (and todayp org-agenda-show-current-time-in-grid)
6173 (push (org-agenda-format-item
6174 nil org-agenda-current-time-string nil "" nil
6175 (format-time-string "%H:%M "))
6176 new)
6177 (put-text-property
6178 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6180 (if (member 'time-up org-agenda-sorting-strategy-selected)
6181 (append new list)
6182 (append list new)))))
6184 (defun org-compile-prefix-format (key)
6185 "Compile the prefix format into a Lisp form that can be evaluated.
6186 The resulting form and associated variable bindings is returned
6187 and stored in the variable `org-prefix-format-compiled'."
6188 (setq org-prefix-has-time nil
6189 org-prefix-has-tag nil
6190 org-prefix-category-length nil
6191 org-prefix-has-effort nil)
6192 (let ((s (cond
6193 ((stringp org-agenda-prefix-format)
6194 org-agenda-prefix-format)
6195 ((assq key org-agenda-prefix-format)
6196 (cdr (assq key org-agenda-prefix-format)))
6197 (t " %-12:c%?-12t% s")))
6198 (start 0)
6199 varform vars var e c f opt)
6200 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6201 s start)
6202 (setq var (or (cdr (assoc (match-string 4 s)
6203 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6204 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6205 'eval)
6206 c (or (match-string 3 s) "")
6207 opt (match-beginning 1)
6208 start (1+ (match-beginning 0)))
6209 (if (equal var 'time) (setq org-prefix-has-time t))
6210 (if (equal var 'tag) (setq org-prefix-has-tag t))
6211 (if (equal var 'effort) (setq org-prefix-has-effort t))
6212 (setq f (concat "%" (match-string 2 s) "s"))
6213 (when (equal var 'category)
6214 (setq org-prefix-category-length
6215 (floor (abs (string-to-number (match-string 2 s)))))
6216 (setq org-prefix-category-max-length
6217 (let ((x (match-string 2 s)))
6218 (save-match-data
6219 (if (string-match "\\.[0-9]+" x)
6220 (string-to-number (substring (match-string 0 x) 1)))))))
6221 (if (eq var 'eval)
6222 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6223 (if opt
6224 (setq varform
6225 `(if (equal "" ,var)
6227 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6228 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6229 (setq s (replace-match "%s" t nil s))
6230 (push varform vars))
6231 (setq vars (nreverse vars))
6232 (with-current-buffer (or org-agenda-buffer (current-buffer))
6233 (setq org-prefix-format-compiled
6234 (list
6235 `((org-prefix-has-time ,org-prefix-has-time)
6236 (org-prefix-has-tag ,org-prefix-has-tag)
6237 (org-prefix-category-length ,org-prefix-category-length)
6238 (org-prefix-has-effort ,org-prefix-has-effort))
6239 `(format ,s ,@vars))))))
6241 (defun org-set-sorting-strategy (key)
6242 (if (symbolp (car org-agenda-sorting-strategy))
6243 ;; the old format
6244 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6245 (setq org-agenda-sorting-strategy-selected
6246 (or (cdr (assq key org-agenda-sorting-strategy))
6247 (cdr (assq 'agenda org-agenda-sorting-strategy))
6248 '(time-up category-keep priority-down)))))
6250 (defun org-get-time-of-day (s &optional string mod24)
6251 "Check string S for a time of day.
6252 If found, return it as a military time number between 0 and 2400.
6253 If not found, return nil.
6254 The optional STRING argument forces conversion into a 5 character wide string
6255 HH:MM."
6256 (save-match-data
6257 (when
6258 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6259 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6260 (let* ((h (string-to-number (match-string 1 s)))
6261 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6262 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6263 (am-p (equal ampm "am"))
6264 (h1 (cond ((not ampm) h)
6265 ((= h 12) (if am-p 0 12))
6266 (t (+ h (if am-p 0 12)))))
6267 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6268 (mod h1 24) h1))
6269 (t0 (+ (* 100 h2) m))
6270 (t1 (concat (if (>= h1 24) "+" " ")
6271 (if (and org-agenda-time-leading-zero
6272 (< t0 1000)) "0" "")
6273 (if (< t0 100) "0" "")
6274 (if (< t0 10) "0" "")
6275 (int-to-string t0))))
6276 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6278 (defvar org-agenda-before-sorting-filter-function nil
6279 "Function to be applied to agenda items prior to sorting.
6280 Prior to sorting also means just before they are inserted into the agenda.
6282 To aid sorting, you may revisit the original entries and add more text
6283 properties which will later be used by the sorting functions.
6285 The function should take a string argument, an agenda line.
6286 It has access to the text properties in that line, which contain among
6287 other things, the property `org-hd-marker' that points to the entry
6288 where the line comes from. Note that not all lines going into the agenda
6289 have this property, only most.
6291 The function should return the modified string. It is probably best
6292 to ONLY change text properties.
6294 You can also use this function as a filter, by returning nil for lines
6295 you don't want to have in the agenda at all. For this application, you
6296 could bind the variable in the options section of a custom command.")
6298 (defun org-agenda-finalize-entries (list &optional nosort)
6299 "Sort and concatenate the agenda items."
6300 (setq list (mapcar 'org-agenda-highlight-todo list))
6301 (if nosort
6302 list
6303 (when org-agenda-before-sorting-filter-function
6304 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6305 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6307 (defun org-agenda-highlight-todo (x)
6308 (let ((org-done-keywords org-done-keywords-for-agenda)
6309 (case-fold-search nil)
6311 (if (eq x 'line)
6312 (save-excursion
6313 (beginning-of-line 1)
6314 (setq re (org-get-at-bol 'org-todo-regexp))
6315 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6316 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6317 (add-text-properties (match-beginning 0) (match-end 1)
6318 (list 'face (org-get-todo-face 1)))
6319 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6320 (delete-region (match-beginning 1) (1- (match-end 0)))
6321 (goto-char (match-beginning 1))
6322 (insert (format org-agenda-todo-keyword-format s)))))
6323 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6324 (setq re (get-text-property 0 'org-todo-regexp x))
6325 (when (and re
6326 ;; Test `pl' because if there's no heading content,
6327 ;; there's no point matching to highlight. Note
6328 ;; that if we didn't test `pl' first, and there
6329 ;; happened to be no keyword from `org-todo-regexp'
6330 ;; on this heading line, then the `equal' comparison
6331 ;; afterwards would spuriously succeed in the case
6332 ;; where `pl' is nil -- causing an args-out-of-range
6333 ;; error when we try to add text properties to text
6334 ;; that isn't there.
6336 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6337 x pl) pl))
6338 (add-text-properties
6339 (or (match-end 1) (match-end 0)) (match-end 0)
6340 (list 'face (org-get-todo-face (match-string 2 x)))
6342 (when (match-end 1)
6343 (setq x (concat (substring x 0 (match-end 1))
6344 (format org-agenda-todo-keyword-format
6345 (match-string 2 x))
6346 (org-add-props " " (text-properties-at 0 x))
6347 (substring x (match-end 3)))))))
6348 x)))
6350 (defsubst org-cmp-priority (a b)
6351 "Compare the priorities of string A and B."
6352 (let ((pa (or (get-text-property 1 'priority a) 0))
6353 (pb (or (get-text-property 1 'priority b) 0)))
6354 (cond ((> pa pb) +1)
6355 ((< pa pb) -1))))
6357 (defsubst org-cmp-effort (a b)
6358 "Compare the effort values of string A and B."
6359 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6360 (ea (or (get-text-property 1 'effort-minutes a) def))
6361 (eb (or (get-text-property 1 'effort-minutes b) def)))
6362 (cond ((> ea eb) +1)
6363 ((< ea eb) -1))))
6365 (defsubst org-cmp-category (a b)
6366 "Compare the string values of categories of strings A and B."
6367 (let ((ca (or (get-text-property 1 'org-category a) ""))
6368 (cb (or (get-text-property 1 'org-category b) "")))
6369 (cond ((string-lessp ca cb) -1)
6370 ((string-lessp cb ca) +1))))
6372 (defsubst org-cmp-todo-state (a b)
6373 "Compare the todo states of strings A and B."
6374 (let* ((ma (or (get-text-property 1 'org-marker a)
6375 (get-text-property 1 'org-hd-marker a)))
6376 (mb (or (get-text-property 1 'org-marker b)
6377 (get-text-property 1 'org-hd-marker b)))
6378 (fa (and ma (marker-buffer ma)))
6379 (fb (and mb (marker-buffer mb)))
6380 (todo-kwds
6381 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6382 (and fb (with-current-buffer fb org-todo-keywords-1))))
6383 (ta (or (get-text-property 1 'todo-state a) ""))
6384 (tb (or (get-text-property 1 'todo-state b) ""))
6385 (la (- (length (member ta todo-kwds))))
6386 (lb (- (length (member tb todo-kwds))))
6387 (donepa (member ta org-done-keywords-for-agenda))
6388 (donepb (member tb org-done-keywords-for-agenda)))
6389 (cond ((and donepa (not donepb)) -1)
6390 ((and (not donepa) donepb) +1)
6391 ((< la lb) -1)
6392 ((< lb la) +1))))
6394 (defsubst org-cmp-alpha (a b)
6395 "Compare the headlines, alphabetically."
6396 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6397 (plb (text-property-any 0 (length b) 'org-heading t b))
6398 (ta (and pla (substring a pla)))
6399 (tb (and plb (substring b plb))))
6400 (when pla
6401 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6402 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6403 (setq ta (substring ta (match-end 0))))
6404 (setq ta (downcase ta)))
6405 (when plb
6406 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6407 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6408 (setq tb (substring tb (match-end 0))))
6409 (setq tb (downcase tb)))
6410 (cond ((not ta) +1)
6411 ((not tb) -1)
6412 ((string-lessp ta tb) -1)
6413 ((string-lessp tb ta) +1))))
6415 (defsubst org-cmp-tag (a b)
6416 "Compare the string values of the first tags of A and B."
6417 (let ((ta (car (last (get-text-property 1 'tags a))))
6418 (tb (car (last (get-text-property 1 'tags b)))))
6419 (cond ((not ta) +1)
6420 ((not tb) -1)
6421 ((string-lessp ta tb) -1)
6422 ((string-lessp tb ta) +1))))
6424 (defsubst org-cmp-time (a b)
6425 "Compare the time-of-day values of strings A and B."
6426 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6427 (ta (or (get-text-property 1 'time-of-day a) def))
6428 (tb (or (get-text-property 1 'time-of-day b) def)))
6429 (cond ((< ta tb) -1)
6430 ((< tb ta) +1))))
6432 (defsubst org-cmp-habit-p (a b)
6433 "Compare the todo states of strings A and B."
6434 (let ((ha (get-text-property 1 'org-habit-p a))
6435 (hb (get-text-property 1 'org-habit-p b)))
6436 (cond ((and ha (not hb)) -1)
6437 ((and (not ha) hb) +1))))
6439 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6441 (defun org-entries-lessp (a b)
6442 "Predicate for sorting agenda entries."
6443 ;; The following variables will be used when the form is evaluated.
6444 ;; So even though the compiler complains, keep them.
6445 (let* ((ss org-agenda-sorting-strategy-selected)
6446 (time-up (and (org-em 'time-up 'time-down ss)
6447 (org-cmp-time a b)))
6448 (time-down (if time-up (- time-up) nil))
6449 (priority-up (and (org-em 'priority-up 'priority-down ss)
6450 (org-cmp-priority a b)))
6451 (priority-down (if priority-up (- priority-up) nil))
6452 (effort-up (and (org-em 'effort-up 'effort-down ss)
6453 (org-cmp-effort a b)))
6454 (effort-down (if effort-up (- effort-up) nil))
6455 (category-up (and (or (org-em 'category-up 'category-down ss)
6456 (memq 'category-keep ss))
6457 (org-cmp-category a b)))
6458 (category-down (if category-up (- category-up) nil))
6459 (category-keep (if category-up +1 nil))
6460 (tag-up (and (org-em 'tag-up 'tag-down ss)
6461 (org-cmp-tag a b)))
6462 (tag-down (if tag-up (- tag-up) nil))
6463 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6464 (org-cmp-todo-state a b)))
6465 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6466 (habit-up (and (org-em 'habit-up 'habit-down ss)
6467 (org-cmp-habit-p a b)))
6468 (habit-down (if habit-up (- habit-up) nil))
6469 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6470 (org-cmp-alpha a b)))
6471 (alpha-down (if alpha-up (- alpha-up) nil))
6472 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6473 user-defined-up user-defined-down)
6474 (if (and need-user-cmp org-agenda-cmp-user-defined
6475 (functionp org-agenda-cmp-user-defined))
6476 (setq user-defined-up
6477 (funcall org-agenda-cmp-user-defined a b)
6478 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6479 (cdr (assoc
6480 (eval (cons 'or org-agenda-sorting-strategy-selected))
6481 '((-1 . t) (1 . nil) (nil . nil))))))
6483 ;;; Agenda restriction lock
6485 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6486 "Overlay to mark the headline to which agenda commands are restricted.")
6487 (overlay-put org-agenda-restriction-lock-overlay
6488 'face 'org-agenda-restriction-lock)
6489 (overlay-put org-agenda-restriction-lock-overlay
6490 'help-echo "Agendas are currently limited to this subtree.")
6491 (org-detach-overlay org-agenda-restriction-lock-overlay)
6493 (defun org-agenda-set-restriction-lock (&optional type)
6494 "Set restriction lock for agenda, to current subtree or file.
6495 Restriction will be the file if TYPE is `file', or if type is the
6496 universal prefix '(4), or if the cursor is before the first headline
6497 in the file. Otherwise, restriction will be to the current subtree."
6498 (interactive "P")
6499 (and (equal type '(4)) (setq type 'file))
6500 (setq type (cond
6501 (type type)
6502 ((org-at-heading-p) 'subtree)
6503 ((condition-case nil (org-back-to-heading t) (error nil))
6504 'subtree)
6505 (t 'file)))
6506 (if (eq type 'subtree)
6507 (progn
6508 (setq org-agenda-restrict t)
6509 (setq org-agenda-overriding-restriction 'subtree)
6510 (put 'org-agenda-files 'org-restrict
6511 (list (buffer-file-name (buffer-base-buffer))))
6512 (org-back-to-heading t)
6513 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6514 (move-marker org-agenda-restrict-begin (point))
6515 (move-marker org-agenda-restrict-end
6516 (save-excursion (org-end-of-subtree t)))
6517 (message "Locking agenda restriction to subtree"))
6518 (put 'org-agenda-files 'org-restrict
6519 (list (buffer-file-name (buffer-base-buffer))))
6520 (setq org-agenda-restrict nil)
6521 (setq org-agenda-overriding-restriction 'file)
6522 (move-marker org-agenda-restrict-begin nil)
6523 (move-marker org-agenda-restrict-end nil)
6524 (message "Locking agenda restriction to file"))
6525 (setq current-prefix-arg nil)
6526 (org-agenda-maybe-redo))
6528 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6529 "Remove the agenda restriction lock."
6530 (interactive "P")
6531 (org-detach-overlay org-agenda-restriction-lock-overlay)
6532 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6533 (setq org-agenda-overriding-restriction nil)
6534 (setq org-agenda-restrict nil)
6535 (put 'org-agenda-files 'org-restrict nil)
6536 (move-marker org-agenda-restrict-begin nil)
6537 (move-marker org-agenda-restrict-end nil)
6538 (setq current-prefix-arg nil)
6539 (message "Agenda restriction lock removed")
6540 (or noupdate (org-agenda-maybe-redo)))
6542 (defun org-agenda-maybe-redo ()
6543 "If there is any window showing the agenda view, update it."
6544 (let ((w (get-buffer-window org-agenda-buffer-name t))
6545 (w0 (selected-window)))
6546 (when w
6547 (select-window w)
6548 (org-agenda-redo)
6549 (select-window w0)
6550 (if org-agenda-overriding-restriction
6551 (message "Agenda view shifted to new %s restriction"
6552 org-agenda-overriding-restriction)
6553 (message "Agenda restriction lock removed")))))
6555 ;;; Agenda commands
6557 (defun org-agenda-check-type (error &rest types)
6558 "Check if agenda buffer is of allowed type.
6559 If ERROR is non-nil, throw an error, otherwise just return nil."
6560 (if (not org-agenda-type)
6561 (error "No Org agenda currently displayed")
6562 (if (memq org-agenda-type types)
6564 (if error
6565 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6566 nil))))
6568 (defun org-agenda-Quit (&optional arg)
6569 "Exit agenda by removing the window or the buffer."
6570 (interactive)
6571 (if org-agenda-columns-active
6572 (org-columns-quit)
6573 (let ((buf (current-buffer)))
6574 (if (eq org-agenda-window-setup 'other-frame)
6575 (progn
6576 (org-agenda-reset-markers)
6577 (kill-buffer buf)
6578 (org-columns-remove-overlays)
6579 (setq org-agenda-archives-mode nil)
6580 (delete-frame))
6581 (and (not (eq org-agenda-window-setup 'current-window))
6582 (not (one-window-p))
6583 (delete-window))
6584 (org-agenda-reset-markers)
6585 (kill-buffer buf)
6586 (org-columns-remove-overlays)
6587 (setq org-agenda-archives-mode nil)))
6588 ;; Maybe restore the pre-agenda window configuration.
6589 (and org-agenda-restore-windows-after-quit
6590 (not (eq org-agenda-window-setup 'other-frame))
6591 org-agenda-pre-window-conf
6592 (set-window-configuration org-agenda-pre-window-conf)
6593 (setq org-agenda-pre-window-conf nil))))
6595 (defun org-agenda-quit ()
6596 "Exit agenda by killing agenda buffer or burying it when
6597 `org-agenda-sticky' is non-NIL"
6598 (interactive)
6599 (if (and (eq org-indirect-buffer-display 'other-window)
6600 org-last-indirect-buffer)
6601 (delete-window (get-buffer-window org-last-indirect-buffer)))
6602 (if org-agenda-columns-active
6603 (org-columns-quit)
6604 (if org-agenda-sticky
6605 (let ((buf (current-buffer)))
6606 (if (eq org-agenda-window-setup 'other-frame)
6607 (progn
6608 (delete-frame))
6609 (and (not (eq org-agenda-window-setup 'current-window))
6610 (not (one-window-p))
6611 (delete-window)))
6612 (with-current-buffer buf
6613 (bury-buffer)
6614 ;; Maybe restore the pre-agenda window configuration.
6615 (and org-agenda-restore-windows-after-quit
6616 (not (eq org-agenda-window-setup 'other-frame))
6617 org-agenda-pre-window-conf
6618 (set-window-configuration org-agenda-pre-window-conf)
6619 (setq org-agenda-pre-window-conf nil))))
6620 (org-agenda-Quit))))
6622 (defun org-agenda-exit ()
6623 "Exit agenda by removing the window or the buffer.
6624 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6625 Org-mode buffers visited directly by the user will not be touched."
6626 (interactive)
6627 (org-release-buffers org-agenda-new-buffers)
6628 (setq org-agenda-new-buffers nil)
6629 (org-agenda-Quit))
6631 (defun org-agenda-kill-all-agenda-buffers ()
6632 "Kill all buffers in `org-agena-mode'.
6633 This is used when toggling sticky agendas. You can also explicitly invoke it
6634 with `C-c a C-k'."
6635 (interactive)
6636 (let (blist)
6637 (dolist (buf (buffer-list))
6638 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6639 (push buf blist)))
6640 (mapc 'kill-buffer blist)))
6642 (defun org-agenda-execute (arg)
6643 "Execute another agenda command, keeping same window.
6644 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6645 in the agenda."
6646 (interactive "P")
6647 (let ((org-agenda-window-setup 'current-window))
6648 (org-agenda arg)))
6650 (defun org-agenda-redo (&optional all)
6651 "Rebuild possibly ALL agenda view(s) in the current buffer."
6652 (interactive "P")
6653 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6654 (cpa (unless (eq all t) current-prefix-arg))
6655 (org-agenda-doing-sticky-redo org-agenda-sticky)
6656 (org-agenda-sticky nil)
6657 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6658 org-agenda-buffer-name))
6659 (org-agenda-keep-modes t)
6660 (tag-filter org-agenda-tag-filter)
6661 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6662 (top-cat-filter org-agenda-top-category-filter)
6663 (cat-filter org-agenda-category-filter)
6664 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6665 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6666 (cols org-agenda-columns-active)
6667 (line (org-current-line))
6668 (window-line (- line (org-current-line (window-start))))
6669 (lprops (get 'org-agenda-redo-command 'org-lprops))
6670 (redo-cmd (get-text-property p 'org-redo-cmd))
6671 (last-args (get-text-property p 'org-last-args))
6672 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6673 (org-agenda-overriding-cmd-arguments
6674 (unless (eq all t)
6675 (cond ((listp last-args)
6676 (cons (or cpa (car last-args)) (cdr last-args)))
6677 ((stringp last-args)
6678 last-args))))
6679 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6680 (put 'org-agenda-tag-filter :preset-filter nil)
6681 (put 'org-agenda-category-filter :preset-filter nil)
6682 (and cols (org-columns-quit))
6683 (message "Rebuilding agenda buffer...")
6684 (if serie-redo-cmd
6685 (eval serie-redo-cmd)
6686 (org-let lprops '(eval redo-cmd)))
6687 (setq org-agenda-undo-list nil
6688 org-agenda-pending-undo-list nil)
6689 (message "Rebuilding agenda buffer...done")
6690 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6691 (put 'org-agenda-category-filter :preset-filter cat-preset)
6692 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6693 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6694 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6695 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6696 (org-goto-line line)
6697 (recenter window-line)))
6699 (defvar org-global-tags-completion-table nil)
6700 (defvar org-agenda-filter-form nil)
6701 (defvar org-agenda-filtered-by-category nil)
6703 (defun org-agenda-filter-by-category (strip)
6704 "Keep only those lines in the agenda buffer that have a specific category.
6705 The category is that of the current line."
6706 (interactive "P")
6707 (if (and org-agenda-filtered-by-category
6708 org-agenda-category-filter)
6709 (org-agenda-filter-show-all-cat)
6710 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6711 (if cat (org-agenda-filter-apply
6712 (list (concat (if strip "-" "+") cat)) 'category)
6713 (error "No category at point")))))
6715 (defun org-find-top-category (&optional pos)
6716 (save-excursion
6717 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6718 (if pos (goto-char pos))
6719 ;; Skip up to the topmost parent
6720 (while (ignore-errors (outline-up-heading 1) t))
6721 (ignore-errors
6722 (nth 4 (org-heading-components))))))
6724 (defvar org-agenda-filtered-by-top-category nil)
6726 (defun org-agenda-filter-by-top-category (strip)
6727 "Keep only those lines in the agenda buffer that have a specific category.
6728 The category is that of the current line."
6729 (interactive "P")
6730 (if org-agenda-filtered-by-top-category
6731 (progn
6732 (setq org-agenda-filtered-by-top-category nil
6733 org-agenda-top-category-filter nil)
6734 (org-agenda-filter-show-all-cat))
6735 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6736 (if cat (org-agenda-filter-top-category-apply cat strip)
6737 (error "No top-level category at point")))))
6739 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6740 "Keep only those lines in the agenda buffer that have a specific tag.
6741 The tag is selected with its fast selection letter, as configured.
6742 With prefix argument STRIP, remove all lines that do have the tag.
6743 A lisp caller can specify CHAR. NARROW means that the new tag should be
6744 used to narrow the search - the interactive user can also press `-' or `+'
6745 to switch to narrowing."
6746 (interactive "P")
6747 (let* ((alist org-tag-alist-for-agenda)
6748 (tag-chars (mapconcat
6749 (lambda (x) (if (and (not (symbolp (car x)))
6750 (cdr x))
6751 (char-to-string (cdr x))
6752 ""))
6753 alist ""))
6754 (efforts (org-split-string
6755 (or (cdr (assoc (concat org-effort-property "_ALL")
6756 org-global-properties))
6757 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6758 "")))
6759 (effort-op org-agenda-filter-effort-default-operator)
6760 (effort-prompt "")
6761 (inhibit-read-only t)
6762 (current org-agenda-tag-filter)
6763 maybe-refresh a n tag)
6764 (unless char
6765 (message
6766 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6767 (if narrow "Narrow" "Filter") tag-chars
6768 (if org-agenda-auto-exclude-function "[RET], " ""))
6769 (setq char (read-char-exclusive)))
6770 (when (member char '(?+ ?-))
6771 ;; Narrowing down
6772 (cond ((equal char ?-) (setq strip t narrow t))
6773 ((equal char ?+) (setq strip nil narrow t)))
6774 (message
6775 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6776 (setq char (read-char-exclusive)))
6777 (when (member char '(?< ?> ?= ??))
6778 ;; An effort operator
6779 (setq effort-op (char-to-string char))
6780 (setq alist nil) ; to make sure it will be interpreted as effort.
6781 (unless (equal char ??)
6782 (loop for i from 0 to 9 do
6783 (setq effort-prompt
6784 (concat
6785 effort-prompt " ["
6786 (if (= i 9) "0" (int-to-string (1+ i)))
6787 "]" (nth i efforts))))
6788 (message "Effort%s: %s " effort-op effort-prompt)
6789 (setq char (read-char-exclusive))
6790 (when (or (< char ?0) (> char ?9))
6791 (error "Need 1-9,0 to select effort"))))
6792 (when (equal char ?\t)
6793 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6794 (org-set-local 'org-global-tags-completion-table
6795 (org-global-tags-completion-table)))
6796 (let ((completion-ignore-case t))
6797 (setq tag (org-icompleting-read
6798 "Tag: " org-global-tags-completion-table))))
6799 (cond
6800 ((equal char ?\r)
6801 (org-agenda-filter-show-all-tag)
6802 (when org-agenda-auto-exclude-function
6803 (setq org-agenda-tag-filter '())
6804 (dolist (tag (org-agenda-get-represented-tags))
6805 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6806 (if modifier
6807 (push modifier org-agenda-tag-filter))))
6808 (if (not (null org-agenda-tag-filter))
6809 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6810 (setq maybe-refresh t))
6811 ((equal char ?/)
6812 (org-agenda-filter-show-all-tag)
6813 (when (get 'org-agenda-tag-filter :preset-filter)
6814 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6815 (setq maybe-refresh t))
6816 ((equal char ?. )
6817 (setq org-agenda-tag-filter
6818 (mapcar (lambda(tag) (concat "+" tag))
6819 (org-get-at-bol 'tags)))
6820 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6821 (setq maybe-refresh t))
6822 ((or (equal char ?\ )
6823 (setq a (rassoc char alist))
6824 (and (>= char ?0) (<= char ?9)
6825 (setq n (if (= char ?0) 9 (- char ?0 1))
6826 tag (concat effort-op (nth n efforts))
6827 a (cons tag nil)))
6828 (and (= char ??)
6829 (setq tag "?eff")
6830 a (cons tag nil))
6831 (and tag (setq a (cons tag nil))))
6832 (org-agenda-filter-show-all-tag)
6833 (setq tag (car a))
6834 (setq org-agenda-tag-filter
6835 (cons (concat (if strip "-" "+") tag)
6836 (if narrow current nil)))
6837 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6838 (setq maybe-refresh t))
6839 (t (error "Invalid tag selection character %c" char)))
6840 (when (and maybe-refresh
6841 (eq org-agenda-clockreport-mode 'with-filter))
6842 (org-agenda-redo))))
6844 (defun org-agenda-get-represented-tags ()
6845 "Get a list of all tags currently represented in the agenda."
6846 (let (p tags)
6847 (save-excursion
6848 (goto-char (point-min))
6849 (while (setq p (next-single-property-change (point) 'tags))
6850 (goto-char p)
6851 (mapc (lambda (x) (add-to-list 'tags x))
6852 (get-text-property (point) 'tags))))
6853 tags))
6855 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6856 "Refine the current filter. See `org-agenda-filter-by-tag'."
6857 (interactive "P")
6858 (org-agenda-filter-by-tag strip char 'refine))
6860 (defun org-agenda-filter-make-matcher ()
6861 "Create the form that tests a line for agenda filter."
6862 (let (f f1)
6863 ;; first compute the tag-filter matcher
6864 (dolist (x (delete-dups
6865 (append (get 'org-agenda-tag-filter
6866 :preset-filter) org-agenda-tag-filter)))
6867 (if (member x '("-" "+"))
6868 (setq f1 (if (equal x "-") 'tags '(not tags)))
6869 (if (string-match "[<=>?]" x)
6870 (setq f1 (org-agenda-filter-effort-form x))
6871 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6872 (if (equal (string-to-char x) ?-)
6873 (setq f1 (list 'not f1))))
6874 (push f1 f))
6875 ;; then compute the category-filter matcher
6876 (dolist (x (delete-dups
6877 (append (get 'org-agenda-category-filter
6878 :preset-filter) org-agenda-category-filter)))
6879 (if (equal "-" (substring x 0 1))
6880 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6881 (setq f1 (list 'equal (substring x 1) 'cat)))
6882 (push f1 f))
6883 (cons 'and (nreverse f))))
6885 (defun org-agenda-filter-effort-form (e)
6886 "Return the form to compare the effort of the current line with what E says.
6887 E looks like \"+<2:25\"."
6888 (let (op)
6889 (setq e (substring e 1))
6890 (setq op (string-to-char e) e (substring e 1))
6891 (setq op (cond ((equal op ?<) '<=)
6892 ((equal op ?>) '>=)
6893 ((equal op ??) op)
6894 (t '=)))
6895 (list 'org-agenda-compare-effort (list 'quote op)
6896 (org-duration-string-to-minutes e))))
6898 (defun org-agenda-compare-effort (op value)
6899 "Compare the effort of the current line with VALUE, using OP.
6900 If the line does not have an effort defined, return nil."
6901 (let ((eff (org-get-at-bol 'effort-minutes)))
6902 (if (equal op ??)
6903 (not eff)
6904 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6905 value))))
6907 (defun org-agenda-filter-apply (filter type)
6908 "Set FILTER as the new agenda filter and apply it."
6909 (let (tags cat)
6910 (if (eq type 'tag)
6911 (setq org-agenda-tag-filter filter)
6912 (setq org-agenda-category-filter filter))
6913 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6914 (if (and (eq type 'category)
6915 (not (equal (substring (car filter) 0 1) "-")))
6916 ;; Only set `org-agenda-filtered-by-category' to t
6917 ;; when a unique category is used as the filter
6918 (setq org-agenda-filtered-by-category t))
6919 (org-agenda-set-mode-name)
6920 (save-excursion
6921 (goto-char (point-min))
6922 (while (not (eobp))
6923 (if (org-get-at-bol 'org-marker)
6924 (progn
6925 (setq tags (org-get-at-bol 'tags) ; used in eval
6926 cat (get-text-property (point) 'org-category))
6927 (if (not (eval org-agenda-filter-form))
6928 (org-agenda-filter-hide-line type))
6929 (beginning-of-line 2))
6930 (beginning-of-line 2))))
6931 (if (get-char-property (point) 'invisible)
6932 (ignore-errors (org-agenda-previous-line)))))
6934 (defun org-agenda-filter-top-category-apply (category &optional negative)
6935 "Set FILTER as the new agenda filter and apply it."
6936 (org-agenda-set-mode-name)
6937 (save-excursion
6938 (goto-char (point-min))
6939 (while (not (eobp))
6940 (let* ((pos (org-get-at-bol 'org-hd-marker))
6941 (topcat (and pos (org-find-top-category pos))))
6942 (if (and topcat (funcall (if negative 'identity 'not)
6943 (string= category topcat)))
6944 (org-agenda-filter-hide-line 'category)))
6945 (beginning-of-line 2)))
6946 (if (get-char-property (point) 'invisible)
6947 (org-agenda-previous-line))
6948 (setq org-agenda-top-category-filter category
6949 org-agenda-filtered-by-top-category t))
6951 (defun org-agenda-filter-hide-line (type)
6952 (let (ov)
6953 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6954 (point-at-eol)))
6955 (overlay-put ov 'invisible t)
6956 (overlay-put ov 'type type)
6957 (if (eq type 'tag)
6958 (push ov org-agenda-tag-filter-overlays)
6959 (push ov org-agenda-cat-filter-overlays))))
6961 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6962 (setq pos (or pos (point)))
6963 (save-excursion
6964 (dolist (ov (overlays-at pos))
6965 (when (and (overlay-get ov 'invisible)
6966 (eq (overlay-get ov 'type) 'tag))
6967 (goto-char pos)
6968 (if (< (overlay-start ov) (point-at-eol))
6969 (move-overlay ov (point-at-eol)
6970 (overlay-end ov)))))))
6972 (defun org-agenda-filter-show-all-tag nil
6973 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6974 (setq org-agenda-tag-filter-overlays nil
6975 org-agenda-tag-filter nil
6976 org-agenda-filter-form nil)
6977 (org-agenda-set-mode-name))
6979 (defun org-agenda-filter-show-all-cat nil
6980 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6981 (setq org-agenda-cat-filter-overlays nil
6982 org-agenda-filtered-by-category nil
6983 org-agenda-category-filter nil
6984 org-agenda-filter-form nil)
6985 (org-agenda-set-mode-name))
6987 (defun org-agenda-manipulate-query-add ()
6988 "Manipulate the query by adding a search term with positive selection.
6989 Positive selection means the term must be matched for selection of an entry."
6990 (interactive)
6991 (org-agenda-manipulate-query ?\[))
6992 (defun org-agenda-manipulate-query-subtract ()
6993 "Manipulate the query by adding a search term with negative selection.
6994 Negative selection means term must not be matched for selection of an entry."
6995 (interactive)
6996 (org-agenda-manipulate-query ?\]))
6997 (defun org-agenda-manipulate-query-add-re ()
6998 "Manipulate the query by adding a search regexp with positive selection.
6999 Positive selection means the regexp must match for selection of an entry."
7000 (interactive)
7001 (org-agenda-manipulate-query ?\{))
7002 (defun org-agenda-manipulate-query-subtract-re ()
7003 "Manipulate the query by adding a search regexp with negative selection.
7004 Negative selection means regexp must not match for selection of an entry."
7005 (interactive)
7006 (org-agenda-manipulate-query ?\}))
7007 (defun org-agenda-manipulate-query (char)
7008 (cond
7009 ((memq org-agenda-type '(timeline agenda))
7010 (let ((org-agenda-include-inactive-timestamps t))
7011 (org-agenda-redo))
7012 (message "Display now includes inactive timestamps as well"))
7013 ((eq org-agenda-type 'search)
7014 (org-add-to-string
7015 'org-agenda-query-string
7016 (if org-agenda-last-search-view-search-was-boolean
7017 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7018 (?\{ . " +{}") (?\} . " -{}"))))
7019 " "))
7020 (setq org-agenda-redo-command
7021 (list 'org-search-view
7022 (car (get-text-property (min (1- (point-max)) (point))
7023 'org-last-args))
7024 org-agenda-query-string
7025 (+ (length org-agenda-query-string)
7026 (if (member char '(?\{ ?\})) 0 1))))
7027 (set-register org-agenda-query-register org-agenda-query-string)
7028 (let ((org-agenda-overriding-arguments
7029 (cdr org-agenda-redo-command)))
7030 (org-agenda-redo)))
7031 (t (error "Cannot manipulate query for %s-type agenda buffers"
7032 org-agenda-type))))
7034 (defun org-add-to-string (var string)
7035 (set var (concat (symbol-value var) string)))
7037 (defun org-agenda-goto-date (span)
7038 "Jump to DATE in agenda."
7039 (interactive "P")
7040 (let* ((org-read-date-prefer-future
7041 (eval org-agenda-jump-prefer-future))
7042 (date (org-read-date))
7043 (org-agenda-sticky-orig org-agenda-sticky)
7044 (org-agenda-buffer-tmp-name (buffer-name))
7045 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7046 (0-arg (or current-prefix-arg (car args)))
7047 (2-arg (nth 2 args))
7048 (newcmd (list 'org-agenda-list 0-arg date
7049 (org-agenda-span-to-ndays 2-arg)))
7050 (newargs (cdr newcmd))
7051 (inhibit-read-only t)
7052 org-agenda-sticky)
7053 (if (not (org-agenda-check-type t 'agenda))
7054 (error "Not available in non-agenda blocks")
7055 (add-text-properties (point-min) (point-max)
7056 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7057 (org-agenda-redo)
7058 (setq org-agenda-sticky org-agenda-sticky-orig
7059 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7061 (defun org-agenda-goto-today ()
7062 "Go to today."
7063 (interactive)
7064 (org-agenda-check-type t 'timeline 'agenda)
7065 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7066 (curspan (nth 2 args))
7067 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7068 (cond
7069 (tdpos (goto-char tdpos))
7070 ((eq org-agenda-type 'agenda)
7071 (let* ((sd (org-agenda-compute-starting-span
7072 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7073 (org-agenda-overriding-arguments args))
7074 (setf (nth 1 org-agenda-overriding-arguments) sd)
7075 (org-agenda-redo)
7076 (org-agenda-find-same-or-today-or-agenda)))
7077 (t (error "Cannot find today")))))
7079 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7080 (goto-char
7081 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7082 (text-property-any (point-min) (point-max) 'org-today t)
7083 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7084 (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
7085 (org-agenda-goto-block-beginning))
7086 (point-min))))
7088 (defun org-agenda-goto-block-beginning ()
7089 "Go the agenda block beginning."
7090 (interactive)
7091 (if (not (derived-mode-p 'org-agenda-mode))
7092 (error "Cannot execute this command outside of org-agenda-mode buffers")
7093 (let (dest)
7094 (save-excursion
7095 (unless (looking-at "\\'")
7096 (forward-char))
7097 (let* ((prop 'org-agenda-structural-header)
7098 (p (previous-single-property-change (point) prop))
7099 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7100 (1- (point))) prop)))
7101 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7102 (if (not dest)
7103 (error "Cannot find the beginning of the blog")
7104 (goto-char dest)
7105 (move-beginning-of-line 1)))))
7107 (defun org-agenda-later (arg)
7108 "Go forward in time by thee current span.
7109 With prefix ARG, go forward that many times the current span."
7110 (interactive "p")
7111 (org-agenda-check-type t 'agenda)
7112 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7113 (span (or (nth 2 args) org-agenda-current-span))
7114 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7115 (greg (calendar-gregorian-from-absolute sd))
7116 (cnt (org-get-at-bol 'org-day-cnt))
7117 greg2)
7118 (cond
7119 ((numberp span)
7120 (setq sd (+ span sd)))
7121 ((eq span 'day)
7122 (setq sd (+ arg sd)))
7123 ((eq span 'week)
7124 (setq sd (+ (* 7 arg) sd)))
7125 ((eq span 'month)
7126 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7127 sd (calendar-absolute-from-gregorian greg2))
7128 (setcar greg2 (1+ (car greg2))))
7129 ((eq span 'year)
7130 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7131 sd (calendar-absolute-from-gregorian greg2))
7132 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7134 (setq sd (+ (* span arg) sd))))
7135 (let ((org-agenda-overriding-cmd
7136 ;; `cmd' may have been set by `org-agenda-run-series' which
7137 ;; uses `org-agenda-overriding-cmd' to decide whether
7138 ;; overriding is allowed for `cmd'
7139 (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
7140 (org-agenda-overriding-arguments
7141 (list (car args) sd span)))
7142 (org-agenda-redo)
7143 (org-agenda-find-same-or-today-or-agenda cnt))))
7145 (defun org-agenda-earlier (arg)
7146 "Go backward in time by the current span.
7147 With prefix ARG, go backward that many times the current span."
7148 (interactive "p")
7149 (org-agenda-later (- arg)))
7151 (defun org-agenda-view-mode-dispatch ()
7152 "Call one of the view mode commands."
7153 (interactive)
7154 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7155 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7156 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7157 (let ((a (read-char-exclusive)))
7158 (case a
7159 (?\ (call-interactively 'org-agenda-reset-view))
7160 (?d (call-interactively 'org-agenda-day-view))
7161 (?w (call-interactively 'org-agenda-week-view))
7162 (?m (call-interactively 'org-agenda-month-view))
7163 (?y (call-interactively 'org-agenda-year-view))
7164 (?l (call-interactively 'org-agenda-log-mode))
7165 (?L (org-agenda-log-mode '(4)))
7166 (?c (org-agenda-log-mode 'clockcheck))
7167 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7168 (?a (call-interactively 'org-agenda-archives-mode))
7169 (?A (org-agenda-archives-mode 'files))
7170 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7171 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7172 (?G (call-interactively 'org-agenda-toggle-time-grid))
7173 (?D (call-interactively 'org-agenda-toggle-diary))
7174 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7175 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7176 (org-agenda-check-type t 'timeline 'agenda)
7177 (org-agenda-redo))
7178 (message "Display now includes inactive timestamps as well"))
7179 (?q (message "Abort"))
7180 (otherwise (error "Invalid key" )))))
7182 (defun org-agenda-reset-view ()
7183 "Switch to default view for agenda."
7184 (interactive)
7185 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7186 (defun org-agenda-day-view (&optional day-of-year)
7187 "Switch to daily view for agenda.
7188 With argument DAY-OF-YEAR, switch to that day of the year."
7189 (interactive "P")
7190 (org-agenda-change-time-span 'day day-of-year))
7191 (defun org-agenda-week-view (&optional iso-week)
7192 "Switch to daily view for agenda.
7193 With argument ISO-WEEK, switch to the corresponding ISO week.
7194 If ISO-WEEK has more then 2 digits, only the last two encode the
7195 week. Any digits before this encode a year. So 200712 means
7196 week 12 of year 2007. Years in the range 1938-2037 can also be
7197 written as 2-digit years."
7198 (interactive "P")
7199 (org-agenda-change-time-span 'week iso-week))
7200 (defun org-agenda-month-view (&optional month)
7201 "Switch to monthly view for agenda.
7202 With argument MONTH, switch to that month."
7203 (interactive "P")
7204 (org-agenda-change-time-span 'month month))
7205 (defun org-agenda-year-view (&optional year)
7206 "Switch to yearly view for agenda.
7207 With argument YEAR, switch to that year.
7208 If MONTH has more then 2 digits, only the last two encode the
7209 month. Any digits before this encode a year. So 200712 means
7210 December year 2007. Years in the range 1938-2037 can also be
7211 written as 2-digit years."
7212 (interactive "P")
7213 (when year
7214 (setq year (org-small-year-to-year year)))
7215 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7216 (org-agenda-change-time-span 'year year)
7217 (error "Abort")))
7219 (defun org-agenda-change-time-span (span &optional n)
7220 "Change the agenda view to SPAN.
7221 SPAN may be `day', `week', `month', `year'."
7222 (org-agenda-check-type t 'agenda)
7223 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7224 (curspan (nth 2 args)))
7225 (if (and (not n) (equal curspan span))
7226 (error "Viewing span is already \"%s\"" span))
7227 (let* ((sd (or (org-get-at-bol 'day)
7228 (nth 1 args)
7229 org-starting-day))
7230 (sd (org-agenda-compute-starting-span sd span n))
7231 (org-agenda-overriding-cmd
7232 (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
7233 (org-agenda-overriding-arguments
7234 (list (car args) sd span)))
7235 (org-agenda-redo)
7236 (org-agenda-find-same-or-today-or-agenda))
7237 (org-agenda-set-mode-name)
7238 (message "Switched to %s view" span)))
7240 (defun org-agenda-compute-starting-span (sd span &optional n)
7241 "Compute starting date for agenda.
7242 SPAN may be `day', `week', `month', `year'. The return value
7243 is a cons cell with the starting date and the number of days,
7244 so that the date SD will be in that range."
7245 (let* ((greg (calendar-gregorian-from-absolute sd))
7246 (dg (nth 1 greg))
7247 (mg (car greg))
7248 (yg (nth 2 greg)))
7249 (cond
7250 ((eq span 'day)
7251 (when n
7252 (setq sd (+ (calendar-absolute-from-gregorian
7253 (list mg 1 yg))
7254 n -1))))
7255 ((eq span 'week)
7256 (let* ((nt (calendar-day-of-week
7257 (calendar-gregorian-from-absolute sd)))
7258 (d (if org-agenda-start-on-weekday
7259 (- nt org-agenda-start-on-weekday)
7262 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7263 (when n
7264 (require 'cal-iso)
7265 (when (> n 99)
7266 (setq y1 (org-small-year-to-year (/ n 100))
7267 n (mod n 100)))
7268 (setq sd
7269 (calendar-absolute-from-iso
7270 (list n 1
7271 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7272 ((eq span 'month)
7273 (let (y1)
7274 (when (and n (> n 99))
7275 (setq y1 (org-small-year-to-year (/ n 100))
7276 n (mod n 100)))
7277 (setq sd (calendar-absolute-from-gregorian
7278 (list (or n mg) 1 (or y1 yg))))))
7279 ((eq span 'year)
7280 (setq sd (calendar-absolute-from-gregorian
7281 (list 1 1 (or n yg))))))
7282 sd))
7284 (defun org-agenda-next-date-line (&optional arg)
7285 "Jump to the next line indicating a date in agenda buffer."
7286 (interactive "p")
7287 (org-agenda-check-type t 'agenda 'timeline)
7288 (beginning-of-line 1)
7289 ;; This does not work if user makes date format that starts with a blank
7290 (if (looking-at "^\\S-") (forward-char 1))
7291 (if (not (re-search-forward "^\\S-" nil t arg))
7292 (progn
7293 (backward-char 1)
7294 (error "No next date after this line in this buffer")))
7295 (goto-char (match-beginning 0)))
7297 (defun org-agenda-previous-date-line (&optional arg)
7298 "Jump to the previous line indicating a date in agenda buffer."
7299 (interactive "p")
7300 (org-agenda-check-type t 'agenda 'timeline)
7301 (beginning-of-line 1)
7302 (if (not (re-search-backward "^\\S-" nil t arg))
7303 (error "No previous date before this line in this buffer")))
7305 ;; Initialize the highlight
7306 (defvar org-hl (make-overlay 1 1))
7307 (overlay-put org-hl 'face 'highlight)
7309 (defun org-highlight (begin end &optional buffer)
7310 "Highlight a region with overlay."
7311 (move-overlay org-hl begin end (or buffer (current-buffer))))
7313 (defun org-unhighlight ()
7314 "Detach overlay INDEX."
7315 (org-detach-overlay org-hl))
7317 (defun org-unhighlight-once ()
7318 "Remove the highlight from its position, and this function from the hook."
7319 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7320 (org-unhighlight))
7322 (defvar org-agenda-pre-follow-window-conf nil)
7323 (defun org-agenda-follow-mode ()
7324 "Toggle follow mode in an agenda buffer."
7325 (interactive)
7326 (unless org-agenda-follow-mode
7327 (setq org-agenda-pre-follow-window-conf
7328 (current-window-configuration)))
7329 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7330 (unless org-agenda-follow-mode
7331 (set-window-configuration org-agenda-pre-follow-window-conf))
7332 (org-agenda-set-mode-name)
7333 (org-agenda-do-context-action)
7334 (message "Follow mode is %s"
7335 (if org-agenda-follow-mode "on" "off")))
7337 (defun org-agenda-entry-text-mode (&optional arg)
7338 "Toggle entry text mode in an agenda buffer."
7339 (interactive "P")
7340 (setq org-agenda-entry-text-mode (or (integerp arg)
7341 (not org-agenda-entry-text-mode)))
7342 (org-agenda-entry-text-hide)
7343 (and org-agenda-entry-text-mode
7344 (let ((org-agenda-entry-text-maxlines
7345 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7346 (org-agenda-entry-text-show)))
7347 (org-agenda-set-mode-name)
7348 (message "Entry text mode is %s. Maximum number of lines is %d"
7349 (if org-agenda-entry-text-mode "on" "off")
7350 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7352 (defun org-agenda-clockreport-mode (&optional with-filter)
7353 "Toggle clocktable mode in an agenda buffer.
7354 With prefix arg WITH-FILTER, make the clocktable respect the current
7355 agenda filter."
7356 (interactive "P")
7357 (org-agenda-check-type t 'agenda)
7358 (if with-filter
7359 (setq org-agenda-clockreport-mode 'with-filter)
7360 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7361 (org-agenda-set-mode-name)
7362 (org-agenda-redo)
7363 (message "Clocktable mode is %s"
7364 (if org-agenda-clockreport-mode "on" "off")))
7366 (defun org-agenda-log-mode (&optional special)
7367 "Toggle log mode in an agenda buffer.
7368 With argument SPECIAL, show all possible log items, not only the ones
7369 configured in `org-agenda-log-mode-items'.
7370 With a double `C-u' prefix arg, show *only* log items, nothing else."
7371 (interactive "P")
7372 (org-agenda-check-type t 'agenda 'timeline)
7373 (setq org-agenda-show-log
7374 (cond
7375 ((equal special '(16)) 'only)
7376 ((eq special 'clockcheck)
7377 (if (eq org-agenda-show-log 'clockcheck)
7378 nil 'clockcheck))
7379 (special '(closed clock state))
7380 (t (not org-agenda-show-log))))
7381 (org-agenda-set-mode-name)
7382 (org-agenda-redo)
7383 (message "Log mode is %s"
7384 (if org-agenda-show-log "on" "off")))
7386 (defun org-agenda-archives-mode (&optional with-files)
7387 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7388 When called with a prefix argument, include all archive files as well."
7389 (interactive "P")
7390 (setq org-agenda-archives-mode
7391 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7392 (org-agenda-set-mode-name)
7393 (org-agenda-redo)
7394 (message
7395 "%s"
7396 (cond
7397 ((eq org-agenda-archives-mode nil)
7398 "No archives are included")
7399 ((eq org-agenda-archives-mode 'trees)
7400 (format "Trees with :%s: tag are included" org-archive-tag))
7401 ((eq org-agenda-archives-mode t)
7402 (format "Trees with :%s: tag and all active archive files are included"
7403 org-archive-tag)))))
7405 (defun org-agenda-toggle-diary ()
7406 "Toggle diary inclusion in an agenda buffer."
7407 (interactive)
7408 (org-agenda-check-type t 'agenda)
7409 (setq org-agenda-include-diary (not org-agenda-include-diary))
7410 (org-agenda-redo)
7411 (org-agenda-set-mode-name)
7412 (message "Diary inclusion turned %s"
7413 (if org-agenda-include-diary "on" "off")))
7415 (defun org-agenda-toggle-deadlines ()
7416 "Toggle inclusion of entries with a deadline in an agenda buffer."
7417 (interactive)
7418 (org-agenda-check-type t 'agenda)
7419 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7420 (org-agenda-redo)
7421 (org-agenda-set-mode-name)
7422 (message "Deadlines inclusion turned %s"
7423 (if org-agenda-include-deadlines "on" "off")))
7425 (defun org-agenda-toggle-time-grid ()
7426 "Toggle time grid in an agenda buffer."
7427 (interactive)
7428 (org-agenda-check-type t 'agenda)
7429 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7430 (org-agenda-redo)
7431 (org-agenda-set-mode-name)
7432 (message "Time-grid turned %s"
7433 (if org-agenda-use-time-grid "on" "off")))
7435 (defun org-agenda-set-mode-name ()
7436 "Set the mode name to indicate all the small mode settings."
7437 (setq mode-name
7438 (list "Org-Agenda"
7439 (if (get 'org-agenda-files 'org-restrict) " []" "")
7441 '(:eval (org-agenda-span-name org-agenda-current-span))
7442 (if org-agenda-follow-mode " Follow" "")
7443 (if org-agenda-entry-text-mode " ETxt" "")
7444 (if org-agenda-include-diary " Diary" "")
7445 (if org-agenda-include-deadlines " Ddl" "")
7446 (if org-agenda-use-time-grid " Grid" "")
7447 (if (and (boundp 'org-habit-show-habits)
7448 org-habit-show-habits) " Habit" "")
7449 (cond
7450 ((consp org-agenda-show-log) " LogAll")
7451 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7452 (org-agenda-show-log " Log")
7453 (t ""))
7454 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7455 :preset-filter))
7456 '(:eval (org-propertize
7457 (concat " <"
7458 (mapconcat
7459 'identity
7460 (append
7461 (get 'org-agenda-category-filter :preset-filter)
7462 org-agenda-category-filter)
7464 ">")
7465 'face 'org-agenda-filter-category
7466 'help-echo "Category used in filtering"))
7468 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7469 :preset-filter))
7470 '(:eval (org-propertize
7471 (concat " {"
7472 (mapconcat
7473 'identity
7474 (append
7475 (get 'org-agenda-tag-filter :preset-filter)
7476 org-agenda-tag-filter)
7478 "}")
7479 'face 'org-agenda-filter-tags
7480 'help-echo "Tags used in filtering"))
7482 (if org-agenda-archives-mode
7483 (if (eq org-agenda-archives-mode t)
7484 " Archives"
7485 (format " :%s:" org-archive-tag))
7487 (if org-agenda-clockreport-mode
7488 (if (eq org-agenda-clockreport-mode 'with-filter)
7489 " Clock{}" " Clock")
7490 "")))
7491 (force-mode-line-update))
7493 (define-obsolete-function-alias
7494 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7496 (defun org-agenda-update-agenda-type ()
7497 "Update the agenda type after each command."
7498 (setq org-agenda-type
7499 (or (get-text-property (point) 'org-agenda-type)
7500 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7502 (defun org-agenda-next-line ()
7503 "Move cursor to the next line, and show if follow mode is active."
7504 (interactive)
7505 (call-interactively 'next-line)
7506 (org-agenda-do-context-action))
7508 (defun org-agenda-previous-line ()
7509 "Move cursor to the previous line, and show if follow-mode is active."
7510 (interactive)
7511 (call-interactively 'previous-line)
7512 (org-agenda-do-context-action))
7514 (defun org-agenda-next-item (n)
7515 "Move cursor to next agenda item."
7516 (interactive "p")
7517 (let ((col (current-column)))
7518 (dotimes (c n)
7519 (when (next-single-property-change (point-at-eol) 'org-marker)
7520 (move-end-of-line 1)
7521 (goto-char (next-single-property-change (point) 'org-marker))))
7522 (org-move-to-column col))
7523 (org-agenda-do-context-action))
7525 (defun org-agenda-previous-item (n)
7526 "Move cursor to next agenda item."
7527 (interactive "p")
7528 (dotimes (c n)
7529 (let ((col (current-column))
7530 (goto (save-excursion
7531 (move-end-of-line 0)
7532 (previous-single-property-change (point) 'org-marker))))
7533 (if goto (goto-char goto))
7534 (org-move-to-column col)))
7535 (org-agenda-do-context-action))
7537 (defun org-agenda-do-context-action ()
7538 "Show outline path and, maybe, follow mode window."
7539 (let ((m (org-get-at-bol 'org-marker)))
7540 (when (and (markerp m) (marker-buffer m))
7541 (and org-agenda-follow-mode
7542 (if org-agenda-follow-indirect
7543 (org-agenda-tree-to-indirect-buffer nil)
7544 (org-agenda-show)))
7545 (and org-agenda-show-outline-path
7546 (org-with-point-at m (org-display-outline-path t))))))
7548 (defun org-agenda-show-tags ()
7549 "Show the tags applicable to the current item."
7550 (interactive)
7551 (let* ((tags (org-get-at-bol 'tags)))
7552 (if tags
7553 (message "Tags are :%s:"
7554 (org-no-properties (mapconcat 'identity tags ":")))
7555 (message "No tags associated with this line"))))
7557 (defun org-agenda-goto (&optional highlight)
7558 "Go to the Org-mode file which contains the item at point."
7559 (interactive)
7560 (let* ((marker (or (org-get-at-bol 'org-marker)
7561 (org-agenda-error)))
7562 (buffer (marker-buffer marker))
7563 (pos (marker-position marker)))
7564 (switch-to-buffer-other-window buffer)
7565 (widen)
7566 (push-mark)
7567 (goto-char pos)
7568 (when (derived-mode-p 'org-mode)
7569 (org-show-context 'agenda)
7570 (save-excursion
7571 (and (outline-next-heading)
7572 (org-flag-heading nil)))) ; show the next heading
7573 (when (outline-invisible-p)
7574 (show-entry)) ; display invisible text
7575 (recenter (/ (window-height) 2))
7576 (run-hooks 'org-agenda-after-show-hook)
7577 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7579 (defvar org-agenda-after-show-hook nil
7580 "Normal hook run after an item has been shown from the agenda.
7581 Point is in the buffer where the item originated.")
7583 (defun org-agenda-kill ()
7584 "Kill the entry or subtree belonging to the current agenda entry."
7585 (interactive)
7586 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7587 (let* ((bufname-orig (buffer-name))
7588 (marker (or (org-get-at-bol 'org-marker)
7589 (org-agenda-error)))
7590 (buffer (marker-buffer marker))
7591 (pos (marker-position marker))
7592 (type (org-get-at-bol 'type))
7593 dbeg dend (n 0) conf)
7594 (org-with-remote-undo buffer
7595 (with-current-buffer buffer
7596 (save-excursion
7597 (goto-char pos)
7598 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7599 (setq dbeg (progn (org-back-to-heading t) (point))
7600 dend (org-end-of-subtree t t))
7601 (setq dbeg (point-at-bol)
7602 dend (min (point-max) (1+ (point-at-eol)))))
7603 (goto-char dbeg)
7604 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7605 (setq conf (or (eq t org-agenda-confirm-kill)
7606 (and (numberp org-agenda-confirm-kill)
7607 (> n org-agenda-confirm-kill))))
7608 (and conf
7609 (not (y-or-n-p
7610 (format "Delete entry with %d lines in buffer \"%s\"? "
7611 n (buffer-name buffer))))
7612 (error "Abort"))
7613 (let ((org-agenda-buffer-name bufname-orig))
7614 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7615 (with-current-buffer buffer (delete-region dbeg dend))
7616 (message "Agenda item and source killed"))))
7618 (defvar org-archive-default-command) ; defined in org-archive.el
7619 (defun org-agenda-archive-default ()
7620 "Archive the entry or subtree belonging to the current agenda entry."
7621 (interactive)
7622 (require 'org-archive)
7623 (org-agenda-archive-with org-archive-default-command))
7625 (defun org-agenda-archive-default-with-confirmation ()
7626 "Archive the entry or subtree belonging to the current agenda entry."
7627 (interactive)
7628 (require 'org-archive)
7629 (org-agenda-archive-with org-archive-default-command 'confirm))
7631 (defun org-agenda-archive ()
7632 "Archive the entry or subtree belonging to the current agenda entry."
7633 (interactive)
7634 (org-agenda-archive-with 'org-archive-subtree))
7636 (defun org-agenda-archive-to-archive-sibling ()
7637 "Move the entry to the archive sibling."
7638 (interactive)
7639 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7641 (defun org-agenda-archive-with (cmd &optional confirm)
7642 "Move the entry to the archive sibling."
7643 (interactive)
7644 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7645 (let* ((bufname-orig (buffer-name))
7646 (marker (or (org-get-at-bol 'org-marker)
7647 (org-agenda-error)))
7648 (buffer (marker-buffer marker))
7649 (pos (marker-position marker)))
7650 (org-with-remote-undo buffer
7651 (with-current-buffer buffer
7652 (if (derived-mode-p 'org-mode)
7653 (if (and confirm
7654 (not (y-or-n-p "Archive this subtree or entry? ")))
7655 (error "Abort")
7656 (save-excursion
7657 (goto-char pos)
7658 (let ((org-agenda-buffer-name bufname-orig))
7659 (org-remove-subtree-entries-from-agenda))
7660 (org-back-to-heading t)
7661 (funcall cmd)))
7662 (error "Archiving works only in Org-mode files"))))))
7664 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7665 "Remove all lines in the agenda that correspond to a given subtree.
7666 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7667 If this information is not given, the function uses the tree at point."
7668 (let ((buf (or buf (current-buffer))) m p)
7669 (save-excursion
7670 (unless (and beg end)
7671 (org-back-to-heading t)
7672 (setq beg (point))
7673 (org-end-of-subtree t)
7674 (setq end (point)))
7675 (set-buffer (get-buffer org-agenda-buffer-name))
7676 (save-excursion
7677 (goto-char (point-max))
7678 (beginning-of-line 1)
7679 (while (not (bobp))
7680 (when (and (setq m (org-get-at-bol 'org-marker))
7681 (equal buf (marker-buffer m))
7682 (setq p (marker-position m))
7683 (>= p beg)
7684 (< p end))
7685 (let ((inhibit-read-only t))
7686 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7687 (beginning-of-line 0))))))
7689 (defun org-agenda-refile (&optional goto rfloc no-update)
7690 "Refile the item at point."
7691 (interactive "P")
7692 (if (equal goto '(16))
7693 (org-refile-goto-last-stored)
7694 (let* ((buffer-orig (buffer-name))
7695 (marker (or (org-get-at-bol 'org-hd-marker)
7696 (org-agenda-error)))
7697 (buffer (marker-buffer marker))
7698 (pos (marker-position marker))
7699 (rfloc (or rfloc
7700 (org-refile-get-location
7701 (if goto "Goto" "Refile to") buffer
7702 org-refile-allow-creating-parent-nodes))))
7703 (with-current-buffer buffer
7704 (save-excursion
7705 (save-restriction
7706 (widen)
7707 (goto-char marker)
7708 (let ((org-agenda-buffer-name buffer-orig))
7709 (org-remove-subtree-entries-from-agenda))
7710 (org-refile goto buffer rfloc)))))
7711 (unless no-update (org-agenda-redo))))
7713 (defun org-agenda-open-link (&optional arg)
7714 "Follow the link in the current line, if any.
7715 This looks for a link in the displayed line in the agenda. It also looks
7716 at the text of the entry itself."
7717 (interactive "P")
7718 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7719 (org-get-at-bol 'org-marker)))
7720 (buffer (and marker (marker-buffer marker)))
7721 (prefix (buffer-substring
7722 (point-at-bol) (point-at-eol))))
7723 (cond
7724 (buffer
7725 (with-current-buffer buffer
7726 (save-excursion
7727 (save-restriction
7728 (widen)
7729 (goto-char marker)
7730 (org-offer-links-in-entry arg prefix)))))
7731 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7732 (save-excursion
7733 (beginning-of-line 1)
7734 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7735 (org-open-link-from-string (match-string 1)))
7736 (t (error "No link to open here")))))
7738 (defun org-agenda-copy-local-variable (var)
7739 "Get a variable from a referenced buffer and install it here."
7740 (let ((m (org-get-at-bol 'org-marker)))
7741 (when (and m (buffer-live-p (marker-buffer m)))
7742 (org-set-local var (with-current-buffer (marker-buffer m)
7743 (symbol-value var))))))
7745 (defun org-agenda-switch-to (&optional delete-other-windows)
7746 "Go to the Org-mode file which contains the item at point."
7747 (interactive)
7748 (if (and org-return-follows-link
7749 (not (org-get-at-bol 'org-marker))
7750 (org-in-regexp org-bracket-link-regexp))
7751 (org-open-link-from-string (match-string 0))
7752 (let* ((marker (or (org-get-at-bol 'org-marker)
7753 (org-agenda-error)))
7754 (buffer (marker-buffer marker))
7755 (pos (marker-position marker)))
7756 (org-pop-to-buffer-same-window buffer)
7757 (and delete-other-windows (delete-other-windows))
7758 (widen)
7759 (goto-char pos)
7760 (when (derived-mode-p 'org-mode)
7761 (org-show-context 'agenda)
7762 (save-excursion
7763 (and (outline-next-heading)
7764 (org-flag-heading nil))) ; show the next heading
7765 (when (outline-invisible-p)
7766 (show-entry)) ; display invisible text
7767 (run-hooks 'org-agenda-after-show-hook)))))
7769 (defun org-agenda-goto-mouse (ev)
7770 "Go to the Org-mode file which contains the item at the mouse click."
7771 (interactive "e")
7772 (mouse-set-point ev)
7773 (org-agenda-goto))
7775 (defun org-agenda-show (&optional full-entry)
7776 "Display the Org-mode file which contains the item at point.
7777 With prefix argument FULL-ENTRY, make the entire entry visible
7778 if it was hidden in the outline."
7779 (interactive "P")
7780 (let ((win (selected-window)))
7781 (if full-entry
7782 (let ((org-show-entry-below t))
7783 (org-agenda-goto t))
7784 (org-agenda-goto t))
7785 (select-window win)))
7787 (defvar org-agenda-show-window nil)
7788 (defun org-agenda-show-and-scroll-up (&optional arg)
7789 "Display the Org-mode file which contains the item at point.
7790 When called repeatedly, scroll the window that is displaying the buffer.
7791 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7792 `show-subtree' to display the item, so that drawers and logbooks stay
7793 folded."
7794 (interactive "P")
7795 (let ((win (selected-window)))
7796 (if (and (window-live-p org-agenda-show-window)
7797 (eq this-command last-command))
7798 (progn
7799 (select-window org-agenda-show-window)
7800 (ignore-errors (scroll-up)))
7801 (org-agenda-goto t)
7802 (if arg (org-show-entry) (show-subtree))
7803 (setq org-agenda-show-window (selected-window)))
7804 (select-window win)))
7806 (defun org-agenda-show-scroll-down ()
7807 "Scroll down the window showing the agenda."
7808 (interactive)
7809 (let ((win (selected-window)))
7810 (when (window-live-p org-agenda-show-window)
7811 (select-window org-agenda-show-window)
7812 (ignore-errors (scroll-down))
7813 (select-window win))))
7815 (defun org-agenda-show-1 (&optional more)
7816 "Display the Org-mode file which contains the item at point.
7817 The prefix arg selects the amount of information to display:
7819 0 hide the subtree
7820 1 just show the entry according to defaults.
7821 2 show the children view
7822 3 show the subtree view
7823 4 show the entire subtree and any LOGBOOK drawers
7824 5 show the entire subtree and any drawers
7825 With prefix argument FULL-ENTRY, make the entire entry visible
7826 if it was hidden in the outline."
7827 (interactive "p")
7828 (let ((win (selected-window)))
7829 (org-agenda-goto t)
7830 (org-recenter-heading 1)
7831 (cond
7832 ((= more 0)
7833 (hide-subtree)
7834 (save-excursion
7835 (org-back-to-heading)
7836 (run-hook-with-args 'org-cycle-hook 'folded))
7837 (message "Remote: FOLDED"))
7838 ((and (org-called-interactively-p 'any) (= more 1))
7839 (message "Remote: show with default settings"))
7840 ((= more 2)
7841 (show-entry)
7842 (show-children)
7843 (save-excursion
7844 (org-back-to-heading)
7845 (run-hook-with-args 'org-cycle-hook 'children))
7846 (message "Remote: CHILDREN"))
7847 ((= more 3)
7848 (show-subtree)
7849 (save-excursion
7850 (org-back-to-heading)
7851 (run-hook-with-args 'org-cycle-hook 'subtree))
7852 (message "Remote: SUBTREE"))
7853 ((= more 4)
7854 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7855 (org-drawer-regexp
7856 (concat "^[ \t]*:\\("
7857 (mapconcat 'regexp-quote org-drawers "\\|")
7858 "\\):[ \t]*$")))
7859 (show-subtree)
7860 (save-excursion
7861 (org-back-to-heading)
7862 (org-cycle-hide-drawers 'subtree)))
7863 (message "Remote: SUBTREE AND LOGBOOK"))
7864 ((> more 4)
7865 (show-subtree)
7866 (message "Remote: SUBTREE AND ALL DRAWERS")))
7867 (select-window win)))
7869 (defun org-recenter-heading (n)
7870 (save-excursion
7871 (org-back-to-heading)
7872 (recenter n)))
7874 (defvar org-agenda-cycle-counter nil)
7875 (defun org-agenda-cycle-show (&optional n)
7876 "Show the current entry in another window, with default settings.
7877 Default settings are taken from `org-show-hierarchy-above' and siblings.
7878 When use repeatedly in immediate succession, the remote entry will cycle
7879 through visibility
7881 children -> subtree -> folded
7883 When called with a numeric prefix arg, that arg will be passed through to
7884 `org-agenda-show-1'. For the interpretation of that argument, see the
7885 docstring of `org-agenda-show-1'."
7886 (interactive "P")
7887 (if (integerp n)
7888 (setq org-agenda-cycle-counter n)
7889 (if (not (eq last-command this-command))
7890 (setq org-agenda-cycle-counter 1)
7891 (if (equal org-agenda-cycle-counter 0)
7892 (setq org-agenda-cycle-counter 2)
7893 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7894 (if (> org-agenda-cycle-counter 3)
7895 (setq org-agenda-cycle-counter 0)))))
7896 (org-agenda-show-1 org-agenda-cycle-counter))
7898 (defun org-agenda-recenter (arg)
7899 "Display the Org-mode file which contains the item at point and recenter."
7900 (interactive "P")
7901 (let ((win (selected-window)))
7902 (org-agenda-goto t)
7903 (recenter arg)
7904 (select-window win)))
7906 (defun org-agenda-show-mouse (ev)
7907 "Display the Org-mode file which contains the item at the mouse click."
7908 (interactive "e")
7909 (mouse-set-point ev)
7910 (org-agenda-show))
7912 (defun org-agenda-check-no-diary ()
7913 "Check if the entry is a diary link and abort if yes."
7914 (if (org-get-at-bol 'org-agenda-diary-link)
7915 (org-agenda-error)))
7917 (defun org-agenda-error ()
7918 (error "Command not allowed in this line"))
7920 (defun org-agenda-tree-to-indirect-buffer (arg)
7921 "Show the subtree corresponding to the current entry in an indirect buffer.
7922 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
7924 With a numerical prefix ARG, go up to this level and then take that tree.
7925 With a negative numeric ARG, go up by this number of levels.
7926 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7927 use the dedicated frame)."
7928 (interactive "P")
7929 (if current-prefix-arg
7930 (org-agenda-do-tree-to-indirect-buffer arg)
7931 (let ((agenda-buffer (buffer-name))
7932 (agenda-window (selected-window))
7933 (indirect-window
7934 (and org-last-indirect-buffer
7935 (get-buffer-window org-last-indirect-buffer))))
7936 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
7937 (unless (or (eq org-indirect-buffer-display 'new-frame)
7938 (eq org-indirect-buffer-display 'dedicated-frame))
7939 (unwind-protect
7940 (unless (and indirect-window (window-live-p indirect-window))
7941 (setq indirect-window (split-window agenda-window)))
7942 (and indirect-window (select-window indirect-window))
7943 (switch-to-buffer org-last-indirect-buffer :norecord)
7944 (fit-window-to-buffer indirect-window)))
7945 (select-window (get-buffer-window agenda-buffer)))))
7947 (defun org-agenda-do-tree-to-indirect-buffer (arg)
7948 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7949 (org-agenda-check-no-diary)
7950 (let* ((marker (or (org-get-at-bol 'org-marker)
7951 (org-agenda-error)))
7952 (buffer (marker-buffer marker))
7953 (pos (marker-position marker)))
7954 (with-current-buffer buffer
7955 (save-excursion
7956 (goto-char pos)
7957 (funcall 'org-tree-to-indirect-buffer arg)))))
7959 (defvar org-last-heading-marker (make-marker)
7960 "Marker pointing to the headline that last changed its TODO state
7961 by a remote command from the agenda.")
7963 (defun org-agenda-todo-nextset ()
7964 "Switch TODO entry to next sequence."
7965 (interactive)
7966 (org-agenda-todo 'nextset))
7968 (defun org-agenda-todo-previousset ()
7969 "Switch TODO entry to previous sequence."
7970 (interactive)
7971 (org-agenda-todo 'previousset))
7973 (defun org-agenda-todo (&optional arg)
7974 "Cycle TODO state of line at point, also in Org-mode file.
7975 This changes the line at point, all other lines in the agenda referring to
7976 the same tree node, and the headline of the tree node in the Org-mode file."
7977 (interactive "P")
7978 (org-agenda-check-no-diary)
7979 (let* ((col (current-column))
7980 (marker (or (org-get-at-bol 'org-marker)
7981 (org-agenda-error)))
7982 (buffer (marker-buffer marker))
7983 (pos (marker-position marker))
7984 (hdmarker (org-get-at-bol 'org-hd-marker))
7985 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7986 (inhibit-read-only t)
7987 org-agenda-headline-snapshot-before-repeat newhead just-one)
7988 (org-with-remote-undo buffer
7989 (with-current-buffer buffer
7990 (widen)
7991 (goto-char pos)
7992 (org-show-context 'agenda)
7993 (save-excursion
7994 (and (outline-next-heading)
7995 (org-flag-heading nil))) ; show the next heading
7996 (let ((current-prefix-arg arg))
7997 (call-interactively 'org-todo))
7998 (and (bolp) (forward-char 1))
7999 (setq newhead (org-get-heading))
8000 (when (and (org-bound-and-true-p
8001 org-agenda-headline-snapshot-before-repeat)
8002 (not (equal org-agenda-headline-snapshot-before-repeat
8003 newhead))
8004 todayp)
8005 (setq newhead org-agenda-headline-snapshot-before-repeat
8006 just-one t))
8007 (save-excursion
8008 (org-back-to-heading)
8009 (move-marker org-last-heading-marker (point))))
8010 (beginning-of-line 1)
8011 (save-excursion
8012 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8013 (org-move-to-column col))))
8015 (defun org-agenda-add-note (&optional arg)
8016 "Add a time-stamped note to the entry at point."
8017 (interactive "P")
8018 (org-agenda-check-no-diary)
8019 (let* ((marker (or (org-get-at-bol 'org-marker)
8020 (org-agenda-error)))
8021 (buffer (marker-buffer marker))
8022 (pos (marker-position marker))
8023 (hdmarker (org-get-at-bol 'org-hd-marker))
8024 (inhibit-read-only t))
8025 (with-current-buffer buffer
8026 (widen)
8027 (goto-char pos)
8028 (org-show-context 'agenda)
8029 (save-excursion
8030 (and (outline-next-heading)
8031 (org-flag-heading nil))) ; show the next heading
8032 (org-add-note))))
8034 (defun org-agenda-change-all-lines (newhead hdmarker
8035 &optional fixface just-this)
8036 "Change all lines in the agenda buffer which match HDMARKER.
8037 The new content of the line will be NEWHEAD (as modified by
8038 `org-agenda-format-item'). HDMARKER is checked with
8039 `equal' against all `org-hd-marker' text properties in the file.
8040 If FIXFACE is non-nil, the face of each item is modified according to
8041 the new TODO state.
8042 If JUST-THIS is non-nil, change just the current line, not all.
8043 If FORCE-TAGS is non nil, the car of it returns the new tags."
8044 (let* ((inhibit-read-only t)
8045 (line (org-current-line))
8046 (org-agenda-buffer (current-buffer))
8047 (thetags (with-current-buffer (marker-buffer hdmarker)
8048 (save-excursion (save-restriction (widen)
8049 (goto-char hdmarker)
8050 (org-get-tags-at)))))
8051 props m pl undone-face done-face finish new dotime level cat tags)
8052 (save-excursion
8053 (goto-char (point-max))
8054 (beginning-of-line 1)
8055 (while (not finish)
8056 (setq finish (bobp))
8057 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8058 (or (not just-this) (= (org-current-line) line))
8059 (equal m hdmarker))
8060 (setq props (text-properties-at (point))
8061 dotime (org-get-at-bol 'dotime)
8062 cat (org-get-at-bol 'org-category)
8063 level (org-get-at-bol 'level)
8064 tags thetags
8066 (let ((org-prefix-format-compiled
8067 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8068 org-prefix-format-compiled))
8069 (extra (org-get-at-bol 'extra)))
8070 (with-current-buffer (marker-buffer hdmarker)
8071 (save-excursion
8072 (save-restriction
8073 (widen)
8074 (org-agenda-format-item extra newhead level cat tags dotime)))))
8075 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8076 undone-face (org-get-at-bol 'undone-face)
8077 done-face (org-get-at-bol 'done-face))
8078 (beginning-of-line 1)
8079 (cond
8080 ((equal new "")
8081 (and (looking-at ".*\n?") (replace-match "")))
8082 ((looking-at ".*")
8083 (replace-match new t t)
8084 (beginning-of-line 1)
8085 (add-text-properties (point-at-bol) (point-at-eol) props)
8086 (when fixface
8087 (add-text-properties
8088 (point-at-bol) (point-at-eol)
8089 (list 'face
8090 (if org-last-todo-state-is-todo
8091 undone-face done-face))))
8092 (org-agenda-highlight-todo 'line)
8093 (beginning-of-line 1))
8094 (t (error "Line update did not work")))
8095 (save-restriction
8096 (narrow-to-region (point-at-bol) (point-at-eol))
8097 (org-agenda-finalize)))
8098 (beginning-of-line 0)))))
8100 (defun org-agenda-align-tags (&optional line)
8101 "Align all tags in agenda items to `org-agenda-tags-column'."
8102 (let ((inhibit-read-only t) l c)
8103 (save-excursion
8104 (goto-char (if line (point-at-bol) (point-min)))
8105 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8106 (if line (point-at-eol) nil) t)
8107 (add-text-properties
8108 (match-beginning 2) (match-end 2)
8109 (list 'face (delq nil (let ((prop (get-text-property
8110 (match-beginning 2) 'face)))
8111 (or (listp prop) (setq prop (list prop)))
8112 (if (memq 'org-tag prop)
8113 prop
8114 (cons 'org-tag prop))))))
8115 (setq l (- (match-end 2) (match-beginning 2))
8116 c (if (< org-agenda-tags-column 0)
8117 (- (abs org-agenda-tags-column) l)
8118 org-agenda-tags-column))
8119 (delete-region (match-beginning 1) (match-end 1))
8120 (goto-char (match-beginning 1))
8121 (insert (org-add-props
8122 (make-string (max 1 (- c (current-column))) ?\ )
8123 (plist-put (copy-sequence (text-properties-at (point)))
8124 'face nil))))
8125 (goto-char (point-min))
8126 (org-font-lock-add-tag-faces (point-max)))))
8128 (defun org-agenda-priority-up ()
8129 "Increase the priority of line at point, also in Org-mode file."
8130 (interactive)
8131 (org-agenda-priority 'up))
8133 (defun org-agenda-priority-down ()
8134 "Decrease the priority of line at point, also in Org-mode file."
8135 (interactive)
8136 (org-agenda-priority 'down))
8138 (defun org-agenda-priority (&optional force-direction show)
8139 "Set the priority of line at point, also in Org-mode file.
8140 This changes the line at point, all other lines in the agenda referring to
8141 the same tree node, and the headline of the tree node in the Org-mode file."
8142 (interactive "P")
8143 (if (equal force-direction '(4)) (setq show t))
8144 (unless org-enable-priority-commands
8145 (error "Priority commands are disabled"))
8146 (org-agenda-check-no-diary)
8147 (let* ((marker (or (org-get-at-bol 'org-marker)
8148 (org-agenda-error)))
8149 (hdmarker (org-get-at-bol 'org-hd-marker))
8150 (buffer (marker-buffer hdmarker))
8151 (pos (marker-position hdmarker))
8152 (inhibit-read-only t)
8153 newhead)
8154 (org-with-remote-undo buffer
8155 (with-current-buffer buffer
8156 (widen)
8157 (goto-char pos)
8158 (org-show-context 'agenda)
8159 (save-excursion
8160 (and (outline-next-heading)
8161 (org-flag-heading nil))) ; show the next heading
8162 (funcall 'org-priority force-direction show)
8163 (end-of-line 1)
8164 (setq newhead (org-get-heading)))
8165 (org-agenda-change-all-lines newhead hdmarker)
8166 (beginning-of-line 1))))
8168 ;; FIXME: should fix the tags property of the agenda line.
8169 (defun org-agenda-set-tags (&optional tag onoff)
8170 "Set tags for the current headline."
8171 (interactive)
8172 (org-agenda-check-no-diary)
8173 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8174 (call-interactively 'org-change-tag-in-region)
8175 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8176 (org-agenda-error)))
8177 (buffer (marker-buffer hdmarker))
8178 (pos (marker-position hdmarker))
8179 (inhibit-read-only t)
8180 newhead)
8181 (org-with-remote-undo buffer
8182 (with-current-buffer buffer
8183 (widen)
8184 (goto-char pos)
8185 (save-excursion
8186 (org-show-context 'agenda))
8187 (save-excursion
8188 (and (outline-next-heading)
8189 (org-flag-heading nil))) ; show the next heading
8190 (goto-char pos)
8191 (if tag
8192 (org-toggle-tag tag onoff)
8193 (call-interactively 'org-set-tags))
8194 (end-of-line 1)
8195 (setq newhead (org-get-heading)))
8196 (org-agenda-change-all-lines newhead hdmarker)
8197 (beginning-of-line 1)))))
8199 (defun org-agenda-set-property ()
8200 "Set a property for the current headline."
8201 (interactive)
8202 (org-agenda-check-no-diary)
8203 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8204 (org-agenda-error)))
8205 (buffer (marker-buffer hdmarker))
8206 (pos (marker-position hdmarker))
8207 (inhibit-read-only t)
8208 newhead)
8209 (org-with-remote-undo buffer
8210 (with-current-buffer buffer
8211 (widen)
8212 (goto-char pos)
8213 (save-excursion
8214 (org-show-context 'agenda))
8215 (save-excursion
8216 (and (outline-next-heading)
8217 (org-flag-heading nil))) ; show the next heading
8218 (goto-char pos)
8219 (call-interactively 'org-set-property)))))
8221 (defun org-agenda-set-effort ()
8222 "Set the effort property for the current headline."
8223 (interactive)
8224 (org-agenda-check-no-diary)
8225 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8226 (org-agenda-error)))
8227 (buffer (marker-buffer hdmarker))
8228 (pos (marker-position hdmarker))
8229 (inhibit-read-only t)
8230 newhead)
8231 (org-with-remote-undo buffer
8232 (with-current-buffer buffer
8233 (widen)
8234 (goto-char pos)
8235 (save-excursion
8236 (org-show-context 'agenda))
8237 (save-excursion
8238 (and (outline-next-heading)
8239 (org-flag-heading nil))) ; show the next heading
8240 (goto-char pos)
8241 (call-interactively 'org-set-effort)
8242 (end-of-line 1)
8243 (setq newhead (org-get-heading)))
8244 (org-agenda-change-all-lines newhead hdmarker))))
8246 (defun org-agenda-toggle-archive-tag ()
8247 "Toggle the archive tag for the current entry."
8248 (interactive)
8249 (org-agenda-check-no-diary)
8250 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8251 (org-agenda-error)))
8252 (buffer (marker-buffer hdmarker))
8253 (pos (marker-position hdmarker))
8254 (inhibit-read-only t)
8255 newhead)
8256 (org-with-remote-undo buffer
8257 (with-current-buffer buffer
8258 (widen)
8259 (goto-char pos)
8260 (org-show-context 'agenda)
8261 (save-excursion
8262 (and (outline-next-heading)
8263 (org-flag-heading nil))) ; show the next heading
8264 (call-interactively 'org-toggle-archive-tag)
8265 (end-of-line 1)
8266 (setq newhead (org-get-heading)))
8267 (org-agenda-change-all-lines newhead hdmarker)
8268 (beginning-of-line 1))))
8270 (defun org-agenda-do-date-later (arg)
8271 (interactive "P")
8272 (cond
8273 ((or (equal arg '(16))
8274 (memq last-command
8275 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8276 (setq this-command 'org-agenda-date-later-minutes)
8277 (org-agenda-date-later-minutes 1))
8278 ((or (equal arg '(4))
8279 (memq last-command
8280 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8281 (setq this-command 'org-agenda-date-later-hours)
8282 (org-agenda-date-later-hours 1))
8284 (org-agenda-date-later (prefix-numeric-value arg)))))
8286 (defun org-agenda-do-date-earlier (arg)
8287 (interactive "P")
8288 (cond
8289 ((or (equal arg '(16))
8290 (memq last-command
8291 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8292 (setq this-command 'org-agenda-date-earlier-minutes)
8293 (org-agenda-date-earlier-minutes 1))
8294 ((or (equal arg '(4))
8295 (memq last-command
8296 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8297 (setq this-command 'org-agenda-date-earlier-hours)
8298 (org-agenda-date-earlier-hours 1))
8300 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8302 (defun org-agenda-date-later (arg &optional what)
8303 "Change the date of this item to ARG day(s) later."
8304 (interactive "p")
8305 (org-agenda-check-type t 'agenda 'timeline)
8306 (org-agenda-check-no-diary)
8307 (let* ((marker (or (org-get-at-bol 'org-marker)
8308 (org-agenda-error)))
8309 (buffer (marker-buffer marker))
8310 (pos (marker-position marker))
8311 cdate today)
8312 (org-with-remote-undo buffer
8313 (with-current-buffer buffer
8314 (widen)
8315 (goto-char pos)
8316 (if (not (org-at-timestamp-p))
8317 (error "Cannot find time stamp"))
8318 (when (and org-agenda-move-date-from-past-immediately-to-today
8319 (equal arg 1)
8320 (or (not what) (eq what 'day))
8321 (not (save-match-data (org-at-date-range-p))))
8322 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8323 cdate (calendar-absolute-from-gregorian
8324 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8325 today (org-today))
8326 (if (> today cdate)
8327 ;; immediately shift to today
8328 (setq arg (- today cdate))))
8329 (org-timestamp-change arg (or what 'day))
8330 (when (and (org-at-date-range-p)
8331 (re-search-backward org-tr-regexp-both (point-at-bol)))
8332 (let ((end org-last-changed-timestamp))
8333 (org-timestamp-change arg (or what 'day))
8334 (setq org-last-changed-timestamp
8335 (concat org-last-changed-timestamp "--" end)))))
8336 (org-agenda-show-new-time marker org-last-changed-timestamp))
8337 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8339 (defun org-agenda-date-earlier (arg &optional what)
8340 "Change the date of this item to ARG day(s) earlier."
8341 (interactive "p")
8342 (org-agenda-date-later (- arg) what))
8344 (defun org-agenda-date-later-minutes (arg)
8345 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8346 (interactive "p")
8347 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8348 (org-agenda-date-later arg 'minute))
8350 (defun org-agenda-date-earlier-minutes (arg)
8351 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8352 (interactive "p")
8353 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8354 (org-agenda-date-earlier arg 'minute))
8356 (defun org-agenda-date-later-hours (arg)
8357 "Change the time of this item, in hour steps."
8358 (interactive "p")
8359 (org-agenda-date-later arg 'hour))
8361 (defun org-agenda-date-earlier-hours (arg)
8362 "Change the time of this item, in hour steps."
8363 (interactive "p")
8364 (org-agenda-date-earlier arg 'hour))
8366 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8367 "Show new date stamp via text properties."
8368 ;; We use text properties to make this undoable
8369 (let ((inhibit-read-only t)
8370 (buffer-invisibility-spec))
8371 (setq stamp (concat " " prefix " => " stamp))
8372 (save-excursion
8373 (goto-char (point-max))
8374 (while (not (bobp))
8375 (when (equal marker (org-get-at-bol 'org-marker))
8376 (org-move-to-column (- (window-width) (length stamp)) t)
8377 (org-agenda-fix-tags-filter-overlays-at (point))
8378 (if (featurep 'xemacs)
8379 ;; Use `duplicable' property to trigger undo recording
8380 (let ((ex (make-extent nil nil))
8381 (gl (make-glyph stamp)))
8382 (set-glyph-face gl 'secondary-selection)
8383 (set-extent-properties
8384 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8385 (insert-extent ex (1- (point)) (point-at-eol)))
8386 (add-text-properties
8387 (1- (point)) (point-at-eol)
8388 (list 'display (org-add-props stamp nil
8389 'face 'secondary-selection))))
8390 (beginning-of-line 1))
8391 (beginning-of-line 0)))))
8393 (defun org-agenda-date-prompt (arg)
8394 "Change the date of this item. Date is prompted for, with default today.
8395 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8396 be used to request time specification in the time stamp."
8397 (interactive "P")
8398 (org-agenda-check-type t 'agenda 'timeline)
8399 (org-agenda-check-no-diary)
8400 (let* ((marker (or (org-get-at-bol 'org-marker)
8401 (org-agenda-error)))
8402 (buffer (marker-buffer marker))
8403 (pos (marker-position marker)))
8404 (org-with-remote-undo buffer
8405 (with-current-buffer buffer
8406 (widen)
8407 (goto-char pos)
8408 (if (not (org-at-timestamp-p t))
8409 (error "Cannot find time stamp"))
8410 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8411 (org-agenda-show-new-time marker org-last-changed-timestamp))
8412 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8414 (defun org-agenda-schedule (arg &optional time)
8415 "Schedule the item at point.
8416 ARG is passed through to `org-schedule'."
8417 (interactive "P")
8418 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8419 (org-agenda-check-no-diary)
8420 (let* ((marker (or (org-get-at-bol 'org-marker)
8421 (org-agenda-error)))
8422 (type (marker-insertion-type marker))
8423 (buffer (marker-buffer marker))
8424 (pos (marker-position marker))
8425 (org-insert-labeled-timestamps-at-point nil)
8427 (set-marker-insertion-type marker t)
8428 (org-with-remote-undo buffer
8429 (with-current-buffer buffer
8430 (widen)
8431 (goto-char pos)
8432 (setq ts (org-schedule arg time)))
8433 (org-agenda-show-new-time marker ts "S"))
8434 (message "Item scheduled for %s" ts)))
8436 (defun org-agenda-deadline (arg &optional time)
8437 "Schedule the item at point.
8438 ARG is passed through to `org-deadline'."
8439 (interactive "P")
8440 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8441 (org-agenda-check-no-diary)
8442 (let* ((marker (or (org-get-at-bol 'org-marker)
8443 (org-agenda-error)))
8444 (buffer (marker-buffer marker))
8445 (pos (marker-position marker))
8446 (org-insert-labeled-timestamps-at-point nil)
8448 (org-with-remote-undo buffer
8449 (with-current-buffer buffer
8450 (widen)
8451 (goto-char pos)
8452 (setq ts (org-deadline arg time)))
8453 (org-agenda-show-new-time marker ts "D"))
8454 (message "Deadline for this item set to %s" ts)))
8456 (defun org-agenda-clock-in (&optional arg)
8457 "Start the clock on the currently selected item."
8458 (interactive "P")
8459 (org-agenda-check-no-diary)
8460 (if (equal arg '(4))
8461 (org-clock-in arg)
8462 (let* ((marker (or (org-get-at-bol 'org-marker)
8463 (org-agenda-error)))
8464 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8465 marker))
8466 (pos (marker-position marker))
8467 newhead)
8468 (org-with-remote-undo (marker-buffer marker)
8469 (with-current-buffer (marker-buffer marker)
8470 (widen)
8471 (goto-char pos)
8472 (org-show-context 'agenda)
8473 (org-show-entry)
8474 (org-cycle-hide-drawers 'children)
8475 (org-clock-in arg)
8476 (setq newhead (org-get-heading)))
8477 (org-agenda-change-all-lines newhead hdmarker)))))
8479 (defun org-agenda-clock-out ()
8480 "Stop the currently running clock."
8481 (interactive)
8482 (unless (marker-buffer org-clock-marker)
8483 (error "No running clock"))
8484 (let ((marker (make-marker)) newhead)
8485 (org-with-remote-undo (marker-buffer org-clock-marker)
8486 (with-current-buffer (marker-buffer org-clock-marker)
8487 (save-excursion
8488 (save-restriction
8489 (widen)
8490 (goto-char org-clock-marker)
8491 (org-back-to-heading t)
8492 (move-marker marker (point))
8493 (org-clock-out)
8494 (setq newhead (org-get-heading))))))
8495 (org-agenda-change-all-lines newhead marker)
8496 (move-marker marker nil)))
8498 (defun org-agenda-clock-cancel (&optional arg)
8499 "Cancel the currently running clock."
8500 (interactive "P")
8501 (unless (marker-buffer org-clock-marker)
8502 (error "No running clock"))
8503 (org-with-remote-undo (marker-buffer org-clock-marker)
8504 (org-clock-cancel)))
8506 (defun org-agenda-clock-goto ()
8507 "Jump to the currently clocked in task within the agenda.
8508 If the currently clocked in task is not listed in the agenda
8509 buffer, display it in another window."
8510 (interactive)
8511 (let (pos)
8512 (mapc (lambda (o)
8513 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8514 (setq pos (overlay-start o))))
8515 (overlays-in (point-min) (point-max)))
8516 (cond (pos (goto-char pos))
8517 ;; If the currently clocked entry is not in the agenda
8518 ;; buffer, we visit it in another window:
8519 (org-clock-current-task
8520 (org-switch-to-buffer-other-window (org-clock-goto)))
8521 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8523 (defun org-agenda-diary-entry-in-org-file ()
8524 "Make a diary entry in the file `org-agenda-diary-file'."
8525 (let (d1 d2 char (text "") dp1 dp2)
8526 (if (equal (buffer-name) "*Calendar*")
8527 (setq d1 (calendar-cursor-to-date t)
8528 d2 (car calendar-mark-ring))
8529 (setq dp1 (get-text-property (point-at-bol) 'day))
8530 (unless dp1 (error "No date defined in current line"))
8531 (setq d1 (calendar-gregorian-from-absolute dp1)
8532 d2 (and (ignore-errors (mark))
8533 (save-excursion
8534 (goto-char (mark))
8535 (setq dp2 (get-text-property (point-at-bol) 'day)))
8536 (calendar-gregorian-from-absolute dp2))))
8537 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8538 (setq char (read-char-exclusive))
8539 (cond
8540 ((equal char ?d)
8541 (setq text (read-string "Day entry: "))
8542 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8543 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8544 ((equal char ?a)
8545 (setq d1 (list (car d1) (nth 1 d1)
8546 (read-number (format "Reference year [%d]: " (nth 2 d1))
8547 (nth 2 d1))))
8548 (setq text (read-string "Anniversary (use %d to show years): "))
8549 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8550 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8551 ((equal char ?b)
8552 (setq text (read-string "Block entry: "))
8553 (unless (and d1 d2 (not (equal d1 d2)))
8554 (error "No block of days selected"))
8555 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8556 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8557 ((equal char ?j)
8558 (org-switch-to-buffer-other-window
8559 (find-file-noselect org-agenda-diary-file))
8560 (require 'org-datetree)
8561 (org-datetree-find-date-create d1)
8562 (org-reveal t))
8563 (t (error "Invalid selection character `%c'" char)))))
8565 (defcustom org-agenda-insert-diary-strategy 'date-tree
8566 "Where in `org-agenda-diary-file' should new entries be added?
8567 Valid values:
8569 date-tree in the date tree, as child of the date
8570 top-level as top-level entries at the end of the file."
8571 :group 'org-agenda
8572 :type '(choice
8573 (const :tag "in a date tree" date-tree)
8574 (const :tag "as top level at end of file" top-level)))
8576 (defcustom org-agenda-insert-diary-extract-time nil
8577 "Non-nil means extract any time specification from the diary entry."
8578 :group 'org-agenda
8579 :version "24.1"
8580 :type 'boolean)
8582 (defcustom org-agenda-bulk-mark-char ">"
8583 "A single-character string to be used as the bulk mark."
8584 :group 'org-agenda
8585 :version "24.1"
8586 :type 'string)
8588 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8589 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8590 If TEXT is not empty, it will become the headline of the new entry, and
8591 the resulting entry will not be shown. When TEXT is empty, switch to
8592 `org-agenda-diary-file' and let the user finish the entry there."
8593 (let ((cw (current-window-configuration)))
8594 (org-switch-to-buffer-other-window
8595 (find-file-noselect org-agenda-diary-file))
8596 (widen)
8597 (goto-char (point-min))
8598 (cond
8599 ((eq type 'anniversary)
8600 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8601 (progn
8602 (or (org-at-heading-p t)
8603 (progn
8604 (outline-next-heading)
8605 (insert "* Anniversaries\n\n")
8606 (beginning-of-line -1)))))
8607 (outline-next-heading)
8608 (org-back-over-empty-lines)
8609 (backward-char 1)
8610 (insert "\n")
8611 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8612 (nth 2 d1) (car d1) (nth 1 d1) text)))
8613 ((eq type 'day)
8614 (let ((org-prefix-has-time t)
8615 (org-agenda-time-leading-zero t)
8616 fmt time time2)
8617 (if org-agenda-insert-diary-extract-time
8618 ;; Use org-agenda-format-item to parse text for a time-range and
8619 ;; remove it. FIXME: This is a hack, we should refactor
8620 ;; that function to make time extraction available separately
8621 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8622 time (get-text-property 0 'time fmt)
8623 time2 (if (> (length time) 0)
8624 ;; split-string removes trailing ...... if
8625 ;; no end time given. First space
8626 ;; separates time from date.
8627 (concat " " (car (split-string time "\\.")))
8628 nil)
8629 text (get-text-property 0 'txt fmt)))
8630 (if (eq org-agenda-insert-diary-strategy 'top-level)
8631 (org-agenda-insert-diary-as-top-level text)
8632 (require 'org-datetree)
8633 (org-datetree-find-date-create d1)
8634 (org-agenda-insert-diary-make-new-entry text))
8635 (org-insert-time-stamp (org-time-from-absolute
8636 (calendar-absolute-from-gregorian d1))
8637 nil nil nil nil time2))
8638 (end-of-line 0))
8639 ((eq type 'block)
8640 (if (> (calendar-absolute-from-gregorian d1)
8641 (calendar-absolute-from-gregorian d2))
8642 (setq d1 (prog1 d2 (setq d2 d1))))
8643 (if (eq org-agenda-insert-diary-strategy 'top-level)
8644 (org-agenda-insert-diary-as-top-level text)
8645 (require 'org-datetree)
8646 (org-datetree-find-date-create d1)
8647 (org-agenda-insert-diary-make-new-entry text))
8648 (org-insert-time-stamp (org-time-from-absolute
8649 (calendar-absolute-from-gregorian d1)))
8650 (insert "--")
8651 (org-insert-time-stamp (org-time-from-absolute
8652 (calendar-absolute-from-gregorian d2)))
8653 (end-of-line 0)))
8654 (if (string-match "\\S-" text)
8655 (progn
8656 (set-window-configuration cw)
8657 (message "%s entry added to %s"
8658 (capitalize (symbol-name type))
8659 (abbreviate-file-name org-agenda-diary-file)))
8660 (org-reveal t)
8661 (message "Please finish entry here"))))
8663 (defun org-agenda-insert-diary-as-top-level (text)
8664 "Make new entry as a top-level entry at the end of the file.
8665 Add TEXT as headline, and position the cursor in the second line so that
8666 a timestamp can be added there."
8667 (widen)
8668 (goto-char (point-max))
8669 (or (bolp) (insert "\n"))
8670 (insert "* " text "\n")
8671 (if org-adapt-indentation (org-indent-to-column 2)))
8673 (defun org-agenda-insert-diary-make-new-entry (text)
8674 "Make new entry as last child of current entry.
8675 Add TEXT as headline, and position the cursor in the second line so that
8676 a timestamp can be added there."
8677 (let ((org-show-following-heading t)
8678 (org-show-siblings t)
8679 (org-show-hierarchy-above t)
8680 (org-show-entry-below t)
8681 col)
8682 (outline-next-heading)
8683 (org-back-over-empty-lines)
8684 (or (looking-at "[ \t]*$")
8685 (progn (insert "\n") (backward-char 1)))
8686 (org-insert-heading nil t)
8687 (org-do-demote)
8688 (setq col (current-column))
8689 (insert text "\n")
8690 (if org-adapt-indentation (org-indent-to-column col))
8691 (let ((org-show-following-heading t)
8692 (org-show-siblings t)
8693 (org-show-hierarchy-above t)
8694 (org-show-entry-below t))
8695 (org-show-context))))
8697 (defun org-agenda-diary-entry ()
8698 "Make a diary entry, like the `i' command from the calendar.
8699 All the standard commands work: block, weekly etc.
8700 When `org-agenda-diary-file' points to a file,
8701 `org-agenda-diary-entry-in-org-file' is called instead to create
8702 entries in that Org-mode file."
8703 (interactive)
8704 (if (not (eq org-agenda-diary-file 'diary-file))
8705 (org-agenda-diary-entry-in-org-file)
8706 (require 'diary-lib)
8707 (let* ((char (progn
8708 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8709 (read-char-exclusive)))
8710 (cmd (cdr (assoc char
8711 '((?d . insert-diary-entry)
8712 (?w . insert-weekly-diary-entry)
8713 (?m . insert-monthly-diary-entry)
8714 (?y . insert-yearly-diary-entry)
8715 (?a . insert-anniversary-diary-entry)
8716 (?b . insert-block-diary-entry)
8717 (?c . insert-cyclic-diary-entry)))))
8718 (oldf (symbol-function 'calendar-cursor-to-date))
8719 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8720 (point (point))
8721 (mark (or (mark t) (point))))
8722 (unless cmd
8723 (error "No command associated with <%c>" char))
8724 (unless (and (get-text-property point 'day)
8725 (or (not (equal ?b char))
8726 (get-text-property mark 'day)))
8727 (error "Don't know which date to use for diary entry"))
8728 ;; We implement this by hacking the `calendar-cursor-to-date' function
8729 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8730 (let ((calendar-mark-ring
8731 (list (calendar-gregorian-from-absolute
8732 (or (get-text-property mark 'day)
8733 (get-text-property point 'day))))))
8734 (unwind-protect
8735 (progn
8736 (fset 'calendar-cursor-to-date
8737 (lambda (&optional error dummy)
8738 (calendar-gregorian-from-absolute
8739 (get-text-property point 'day))))
8740 (call-interactively cmd))
8741 (fset 'calendar-cursor-to-date oldf))))))
8743 (defun org-agenda-execute-calendar-command (cmd)
8744 "Execute a calendar command from the agenda with date from cursor."
8745 (org-agenda-check-type t 'agenda 'timeline)
8746 (require 'diary-lib)
8747 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
8748 (error "Don't know which date to use for the calendar command"))
8749 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8750 (point (point))
8751 (date (calendar-gregorian-from-absolute
8752 (get-text-property point 'day)))
8753 ;; the following 2 vars are needed in the calendar
8754 (displayed-month (car date))
8755 (displayed-year (nth 2 date)))
8756 (unwind-protect
8757 (progn
8758 (fset 'calendar-cursor-to-date
8759 (lambda (&optional error dummy)
8760 (calendar-gregorian-from-absolute
8761 (get-text-property point 'day))))
8762 (call-interactively cmd))
8763 (fset 'calendar-cursor-to-date oldf))))
8765 (defun org-agenda-phases-of-moon ()
8766 "Display the phases of the moon for the 3 months around the cursor date."
8767 (interactive)
8768 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8770 (defun org-agenda-holidays ()
8771 "Display the holidays for the 3 months around the cursor date."
8772 (interactive)
8773 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8775 (defvar calendar-longitude) ; defined in calendar.el
8776 (defvar calendar-latitude) ; defined in calendar.el
8777 (defvar calendar-location-name) ; defined in calendar.el
8779 (defun org-agenda-sunrise-sunset (arg)
8780 "Display sunrise and sunset for the cursor date.
8781 Latitude and longitude can be specified with the variables
8782 `calendar-latitude' and `calendar-longitude'. When called with prefix
8783 argument, latitude and longitude will be prompted for."
8784 (interactive "P")
8785 (require 'solar)
8786 (let ((calendar-longitude (if arg nil calendar-longitude))
8787 (calendar-latitude (if arg nil calendar-latitude))
8788 (calendar-location-name
8789 (if arg "the given coordinates" calendar-location-name)))
8790 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8792 (defun org-agenda-goto-calendar ()
8793 "Open the Emacs calendar with the date at the cursor."
8794 (interactive)
8795 (org-agenda-check-type t 'agenda 'timeline)
8796 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
8797 (error "Don't know which date to open in calendar")))
8798 (date (calendar-gregorian-from-absolute day))
8799 (calendar-move-hook nil)
8800 (calendar-view-holidays-initially-flag nil)
8801 (calendar-view-diary-initially-flag nil))
8802 (calendar)
8803 (calendar-goto-date date)))
8805 ;;;###autoload
8806 (defun org-calendar-goto-agenda ()
8807 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8808 This is a command that has to be installed in `calendar-mode-map'."
8809 (interactive)
8810 (org-agenda-list nil (calendar-absolute-from-gregorian
8811 (calendar-cursor-to-date))
8812 nil))
8814 (defun org-agenda-convert-date ()
8815 (interactive)
8816 (org-agenda-check-type t 'agenda 'timeline)
8817 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
8818 date s)
8819 (unless day
8820 (error "Don't know which date to convert"))
8821 (setq date (calendar-gregorian-from-absolute day))
8822 (setq s (concat
8823 "Gregorian: " (calendar-date-string date) "\n"
8824 "ISO: " (calendar-iso-date-string date) "\n"
8825 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8826 "Julian: " (calendar-julian-date-string date) "\n"
8827 "Astron. JD: " (calendar-astro-date-string date)
8828 " (Julian date number at noon UTC)\n"
8829 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8830 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8831 "French: " (calendar-french-date-string date) "\n"
8832 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8833 "Mayan: " (calendar-mayan-date-string date) "\n"
8834 "Coptic: " (calendar-coptic-date-string date) "\n"
8835 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8836 "Persian: " (calendar-persian-date-string date) "\n"
8837 "Chinese: " (calendar-chinese-date-string date) "\n"))
8838 (with-output-to-temp-buffer "*Dates*"
8839 (princ s))
8840 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8842 ;;; Bulk commands
8844 (defun org-agenda-bulk-marked-p ()
8845 (eq (get-char-property (point-at-bol) 'type)
8846 'org-marked-entry-overlay))
8848 (defun org-agenda-bulk-mark (&optional arg)
8849 "Mark the entry at point for future bulk action."
8850 (interactive "p")
8851 (dotimes (i (or arg 1))
8852 (unless (org-get-at-bol 'org-agenda-diary-link)
8853 (let* ((m (org-get-at-bol 'org-hd-marker))
8855 (unless (org-agenda-bulk-marked-p)
8856 (unless m (error "Nothing to mark at point"))
8857 (push m org-agenda-bulk-marked-entries)
8858 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8859 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8860 (org-get-todo-face "TODO")
8861 'evaporate)
8862 (overlay-put ov 'type 'org-marked-entry-overlay))
8863 (beginning-of-line 2)
8864 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8865 (beginning-of-line 2))
8866 (message "%d entries marked for bulk action"
8867 (length org-agenda-bulk-marked-entries))))))
8869 (defun org-agenda-bulk-mark-all ()
8870 "Mark all entries for future agenda bulk action."
8871 (interactive)
8872 (org-agenda-bulk-mark-regexp "."))
8874 (defun org-agenda-bulk-mark-regexp (regexp)
8875 "Mark entries matching REGEXP for future agenda bulk action."
8876 (interactive "sMark entries matching regexp: ")
8877 (let ((entries-marked 0))
8878 (save-excursion
8879 (goto-char (point-min))
8880 (goto-char (next-single-property-change (point) 'txt))
8881 (while (re-search-forward regexp nil t)
8882 (when (string-match regexp (get-text-property (point) 'txt))
8883 (setq entries-marked (1+ entries-marked))
8884 (call-interactively 'org-agenda-bulk-mark))))
8885 (if (not entries-marked)
8886 (message "No entry matching this regexp."))))
8888 (defun org-agenda-bulk-unmark (&optional arg)
8889 "Unmark the entry at point for future bulk action."
8890 (interactive "P")
8891 (if arg
8892 (org-agenda-bulk-unmark-all)
8893 (cond ((org-agenda-bulk-marked-p)
8894 (org-agenda-bulk-remove-overlays
8895 (point-at-bol) (+ 2 (point-at-bol)))
8896 (setq org-agenda-bulk-marked-entries
8897 (delete (org-get-at-bol 'org-hd-marker)
8898 org-agenda-bulk-marked-entries))
8899 (beginning-of-line 2)
8900 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8901 (beginning-of-line 2))
8902 (message "%d entries left marked for bulk action"
8903 (length org-agenda-bulk-marked-entries)))
8904 (t (message "No entry to unmark here")))))
8906 (defun org-agenda-bulk-toggle ()
8907 "Toggle marking the entry at point for bulk action."
8908 (interactive)
8909 (if (org-agenda-bulk-marked-p)
8910 (org-agenda-bulk-unmark)
8911 (org-agenda-bulk-mark)))
8913 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8914 "Remove the mark overlays between BEG and END in the agenda buffer.
8915 BEG and END default to the buffer limits.
8917 This only removes the overlays, it does not remove the markers
8918 from the list in `org-agenda-bulk-marked-entries'."
8919 (interactive)
8920 (mapc (lambda (ov)
8921 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8922 (delete-overlay ov)))
8923 (overlays-in (or beg (point-min)) (or end (point-max)))))
8925 (defun org-agenda-bulk-unmark-all ()
8926 "Remove all marks in the agenda buffer.
8927 This will remove the markers and the overlays."
8928 (interactive)
8929 (if (null org-agenda-bulk-marked-entries)
8930 (message "No entry to unmark")
8931 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8932 (setq org-agenda-bulk-marked-entries nil)
8933 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8935 (defcustom org-agenda-persistent-marks nil
8936 "Non-nil means marked items will stay marked after a bulk action.
8937 You can toggle this interactively by typing `p' when prompted for a
8938 bulk action."
8939 :group 'org-agenda
8940 :version "24.1"
8941 :type 'boolean)
8943 (defun org-agenda-bulk-action (&optional arg)
8944 "Execute an remote-editing action on all marked entries.
8945 The prefix arg is passed through to the command if possible."
8946 (interactive "P")
8947 ;; Make sure we have markers, and only valid ones
8948 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8949 (mapc
8950 (lambda (m)
8951 (unless (and (markerp m)
8952 (marker-buffer m)
8953 (buffer-live-p (marker-buffer m))
8954 (marker-position m))
8955 (error "Marker %s for bulk command is invalid" m)))
8956 org-agenda-bulk-marked-entries)
8958 ;; Prompt for the bulk command
8959 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8960 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
8961 "[S]catter [f]unction "
8962 (when org-agenda-bulk-custom-functions
8963 (concat " Custom: ["
8964 (mapconcat (lambda(f) (char-to-string (car f)))
8965 org-agenda-bulk-custom-functions "")
8966 "]"))))
8967 (catch 'exit
8968 (let* ((action (read-char-exclusive))
8969 (org-log-refile (if org-log-refile 'time nil))
8970 (entries (reverse org-agenda-bulk-marked-entries))
8971 (org-overriding-default-time
8972 (if (get-text-property (point) 'org-agenda-date-header)
8973 (org-get-cursor-date)))
8974 redo-at-end
8975 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8976 (cond
8977 ((equal action ?p)
8978 (let ((org-agenda-persistent-marks
8979 (not org-agenda-persistent-marks)))
8980 (org-agenda-bulk-action)
8981 (throw 'exit nil)))
8983 ((equal action ?$)
8984 (setq cmd '(org-agenda-archive)))
8986 ((equal action ?A)
8987 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8989 ((member action '(?r ?w))
8990 (setq rfloc (org-refile-get-location
8991 "Refile to"
8992 (marker-buffer (car entries))
8993 org-refile-allow-creating-parent-nodes))
8994 (if (nth 3 rfloc)
8995 (setcar (nthcdr 3 rfloc)
8996 (move-marker (make-marker) (nth 3 rfloc)
8997 (or (get-file-buffer (nth 1 rfloc))
8998 (find-buffer-visiting (nth 1 rfloc))
8999 (error "This should not happen")))))
9001 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9002 redo-at-end t))
9004 ((equal action ?t)
9005 (setq state (org-icompleting-read
9006 "Todo state: "
9007 (with-current-buffer (marker-buffer (car entries))
9008 (mapcar 'list org-todo-keywords-1))))
9009 (setq cmd `(let ((org-inhibit-blocking t)
9010 (org-inhibit-logging 'note))
9011 (org-agenda-todo ,state))))
9013 ((memq action '(?- ?+))
9014 (setq tag (org-icompleting-read
9015 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9016 (with-current-buffer (marker-buffer (car entries))
9017 (delq nil
9018 (mapcar (lambda (x)
9019 (if (stringp (car x)) x)) org-tag-alist)))))
9020 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9022 ((memq action '(?s ?d))
9023 (let* ((time
9024 (unless arg
9025 (org-read-date
9026 nil nil nil
9027 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9028 org-overriding-default-time)))
9029 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9030 (setq cmd `(eval '(,c1 arg ,time)))))
9032 ((equal action ?S)
9033 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9034 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9035 (let ((days (read-number
9036 (format "Scatter tasks across how many %sdays: "
9037 (if arg "week" "")) 7)))
9038 (setq cmd
9039 `(let ((distance (1+ (random ,days))))
9040 (if arg
9041 (let ((dist distance)
9042 (day-of-week
9043 (calendar-day-of-week
9044 (calendar-gregorian-from-absolute (org-today)))))
9045 (dotimes (i (1+ dist))
9046 (while (member day-of-week org-agenda-weekend-days)
9047 (incf distance)
9048 (incf day-of-week)
9049 (if (= day-of-week 7)
9050 (setq day-of-week 0)))
9051 (incf day-of-week)
9052 (if (= day-of-week 7)
9053 (setq day-of-week 0)))))
9054 ;; silently fail when try to replan a sexp entry
9055 (condition-case nil
9056 (let* ((date (calendar-gregorian-from-absolute
9057 (+ (org-today) distance)))
9058 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9059 (nth 2 date))))
9060 (org-agenda-schedule nil time))
9061 (error nil)))))))
9063 ((assoc action org-agenda-bulk-custom-functions)
9064 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9065 redo-at-end t))
9067 ((equal action ?f)
9068 (setq cmd (list (intern
9069 (org-icompleting-read "Function: "
9070 obarray 'fboundp t nil nil)))))
9072 (t (error "Invalid bulk action")))
9074 ;; Sort the markers, to make sure that parents are handled before children
9075 (setq entries (sort entries
9076 (lambda (a b)
9077 (cond
9078 ((equal (marker-buffer a) (marker-buffer b))
9079 (< (marker-position a) (marker-position b)))
9081 (string< (buffer-name (marker-buffer a))
9082 (buffer-name (marker-buffer b))))))))
9084 ;; Now loop over all markers and apply cmd
9085 (while (setq e (pop entries))
9086 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9087 (if (not pos)
9088 (progn (message "Skipping removed entry at %s" e)
9089 (setq cntskip (1+ cntskip)))
9090 (goto-char pos)
9091 (let (org-loop-over-headlines-in-active-region)
9092 (eval cmd))
9093 (setq cnt (1+ cnt))))
9094 (when redo-at-end (org-agenda-redo))
9095 (unless org-agenda-persistent-marks
9096 (org-agenda-bulk-unmark-all))
9097 (message "Acted on %d entries%s%s"
9099 (if (= cntskip 0)
9101 (format ", skipped %d (disappeared before their turn)"
9102 cntskip))
9103 (if (not org-agenda-persistent-marks)
9104 "" " (kept marked)"))))))
9106 (defun org-agenda-capture ()
9107 "Call `org-capture' with the date at point."
9108 (interactive)
9109 (if (not (eq major-mode 'org-agenda-mode))
9110 (error "You cannot do this outside of agenda buffers")
9111 (let ((org-overriding-default-time
9112 (org-get-cursor-date)))
9113 (call-interactively 'org-capture))))
9115 ;;; Flagging notes
9117 (defun org-agenda-show-the-flagging-note ()
9118 "Display the flagging note in the other window.
9119 When called a second time in direct sequence, offer to remove the FLAGGING
9120 tag and (if present) the flagging note."
9121 (interactive)
9122 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9123 (win (selected-window))
9124 note heading newhead)
9125 (unless hdmarker
9126 (error "No linked entry at point"))
9127 (if (and (eq this-command last-command)
9128 (y-or-n-p "Unflag and remove any flagging note? "))
9129 (progn
9130 (org-agenda-remove-flag hdmarker)
9131 (let ((win (get-buffer-window "*Flagging Note*")))
9132 (and win (delete-window win)))
9133 (message "Entry unflagged"))
9134 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9135 (unless note
9136 (error "No flagging note"))
9137 (org-kill-new note)
9138 (org-switch-to-buffer-other-window "*Flagging Note*")
9139 (erase-buffer)
9140 (insert note)
9141 (goto-char (point-min))
9142 (while (re-search-forward "\\\\n" nil t)
9143 (replace-match "\n" t t))
9144 (goto-char (point-min))
9145 (select-window win)
9146 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9148 (defun org-agenda-remove-flag (marker)
9149 "Remove the FLAGGED tag and any flagging note in the entry."
9150 (let (newhead)
9151 (org-with-point-at marker
9152 (org-toggle-tag "FLAGGED" 'off)
9153 (org-entry-delete nil "THEFLAGGINGNOTE")
9154 (setq newhead (org-get-heading)))
9155 (org-agenda-change-all-lines newhead marker)
9156 (message "Entry unflagged")))
9158 (defun org-agenda-get-any-marker (&optional pos)
9159 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9160 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9162 ;;; Appointment reminders
9164 (defvar appt-time-msg-list) ; defined in appt.el
9166 ;;;###autoload
9167 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9168 "Activate appointments found in `org-agenda-files'.
9169 With a \\[universal-argument] prefix, refresh the list of
9170 appointments.
9172 If FILTER is t, interactively prompt the user for a regular
9173 expression, and filter out entries that don't match it.
9175 If FILTER is a string, use this string as a regular expression
9176 for filtering entries out.
9178 If FILTER is a function, filter out entries against which
9179 calling the function returns nil. This function takes one
9180 argument: an entry from `org-agenda-get-day-entries'.
9182 FILTER can also be an alist with the car of each cell being
9183 either 'headline or 'category. For example:
9185 '((headline \"IMPORTANT\")
9186 (category \"Work\"))
9188 will only add headlines containing IMPORTANT or headlines
9189 belonging to the \"Work\" category.
9191 ARGS are symbols indicating what kind of entries to consider.
9192 By default `org-agenda-to-appt' will use :deadline, :scheduled
9193 and :timestamp entries. See the docstring of `org-diary' for
9194 details and examples.
9196 If an entry as a APPT_WARNTIME property, its value will be used
9197 to override `appt-message-warning-time'."
9198 (interactive "P")
9199 (if refresh (setq appt-time-msg-list nil))
9200 (if (eq filter t)
9201 (setq filter (read-from-minibuffer "Regexp filter: ")))
9202 (let* ((cnt 0) ; count added events
9203 (scope (or args '(:deadline :scheduled :timestamp)))
9204 (org-agenda-new-buffers nil)
9205 (org-deadline-warning-days 0)
9206 ;; Do not use `org-today' here because appt only takes
9207 ;; time and without date as argument, so it may pass wrong
9208 ;; information otherwise
9209 (today (org-date-to-gregorian
9210 (time-to-days (current-time))))
9211 (org-agenda-restrict nil)
9212 (files (org-agenda-files 'unrestricted)) entries file
9213 (org-agenda-buffer nil))
9214 ;; Get all entries which may contain an appt
9215 (org-agenda-prepare-buffers files)
9216 (while (setq file (pop files))
9217 (setq entries
9218 (delq nil
9219 (append entries
9220 (apply 'org-agenda-get-day-entries
9221 file today scope)))))
9222 ;; Map thru entries and find if we should filter them out
9223 (mapc
9224 (lambda(x)
9225 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9226 (cat (get-text-property 1 'org-category x))
9227 (tod (get-text-property 1 'time-of-day x))
9228 (ok (or (null filter)
9229 (and (stringp filter) (string-match filter evt))
9230 (and (functionp filter) (funcall filter x))
9231 (and (listp filter)
9232 (let ((cat-filter (cadr (assoc 'category filter)))
9233 (evt-filter (cadr (assoc 'headline filter))))
9234 (or (and (stringp cat-filter)
9235 (string-match cat-filter cat))
9236 (and (stringp evt-filter)
9237 (string-match evt-filter evt)))))))
9238 (wrn (get-text-property 1 'warntime x)))
9239 ;; FIXME: Shall we remove text-properties for the appt text?
9240 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9241 (when (and ok tod)
9242 (setq tod (concat "00" (number-to-string tod))
9243 tod (when (string-match
9244 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9245 (concat (match-string 1 tod) ":"
9246 (match-string 2 tod))))
9247 (if (version< emacs-version "23.3")
9248 (appt-add tod evt)
9249 (appt-add tod evt wrn))
9250 (setq cnt (1+ cnt))))) entries)
9251 (org-release-buffers org-agenda-new-buffers)
9252 (if (eq cnt 0)
9253 (message "No event to add")
9254 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9256 (defun org-agenda-todayp (date)
9257 "Does DATE mean today, when considering `org-extend-today-until'?"
9258 (let ((today (org-today))
9259 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9260 date)))
9261 (eq date today)))
9263 (defun org-agenda-todo-yesterday (&optional arg)
9264 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9265 (interactive "P")
9266 (let* ((hour (third (decode-time
9267 (org-current-time))))
9268 (org-extend-today-until (1+ hour)))
9269 (org-agenda-todo arg)))
9271 (provide 'org-agenda)
9273 ;;; org-agenda.el ends here