org-e-odt-preferred-output-format: Make string values safe
[org-mode.git] / lisp / org-agenda.el
blob0897f36f9ff576aa2d0aaf881083a41a1b36e94a
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))
87 (defvar calendar-mode-map) ; defined in calendar.el
88 (defvar org-clock-current-task nil) ; defined in org-clock.el
89 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
90 (defvar org-habit-show-habits) ; defined in org-habit.el
91 (defvar org-habit-show-habits-only-for-today)
92 (defvar org-habit-show-all-today nil)
94 ;; Defined somewhere in this file, but used before definition.
95 (defvar org-agenda-buffer-name "*Org Agenda*")
96 (defvar org-agenda-overriding-header nil)
97 (defvar org-agenda-title-append nil)
98 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
99 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
100 (defvar original-date) ; dynamically scoped, calendar.el does scope this
102 (defvar org-agenda-undo-list nil
103 "List of undoable operations in the agenda since last refresh.")
104 (defvar org-agenda-pending-undo-list nil
105 "In a series of undo commands, this is the list of remaining undo items.")
107 (defcustom org-agenda-confirm-kill 1
108 "When set, remote killing from the agenda buffer needs confirmation.
109 When t, a confirmation is always needed. When a number N, confirmation is
110 only needed when the text to be killed contains more than N non-white lines."
111 :group 'org-agenda
112 :type '(choice
113 (const :tag "Never" nil)
114 (const :tag "Always" t)
115 (integer :tag "When more than N lines")))
117 (defcustom org-agenda-compact-blocks nil
118 "Non-nil means make the block agenda more compact.
119 This is done globally by leaving out lines like the agenda span
120 name and week number or the separator lines."
121 :group 'org-agenda
122 :type 'boolean)
124 (defcustom org-agenda-block-separator ?=
125 "The separator between blocks in the agenda.
126 If this is a string, it will be used as the separator, with a newline added.
127 If it is a character, it will be repeated to fill the window width.
128 If nil the separator is disabled. In `org-agenda-custom-commands' this
129 addresses the separator between the current and the previous block."
130 :group 'org-agenda
131 :type '(choice
132 (const :tag "Disabled" nil)
133 (character)
134 (string)))
136 (defgroup org-agenda-export nil
137 "Options concerning exporting agenda views in Org-mode."
138 :tag "Org Agenda Export"
139 :group 'org-agenda)
141 (defcustom org-agenda-with-colors t
142 "Non-nil means use colors in agenda views."
143 :group 'org-agenda-export
144 :type 'boolean)
146 (defcustom org-agenda-exporter-settings nil
147 "Alist of variable/value pairs that should be active during agenda export.
148 This is a good place to set options for ps-print and for htmlize.
149 Note that the way this is implemented, the values will be evaluated
150 before assigned to the variables. So make sure to quote values you do
151 *not* want evaluated, for example
153 (setq org-agenda-exporter-settings
154 '((ps-print-color-p 'black-white)))"
155 :group 'org-agenda-export
156 :type '(repeat
157 (list
158 (variable)
159 (sexp :tag "Value"))))
161 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
162 "Hook run in temporary buffer before writing it to an export file.
163 A useful function is `org-agenda-add-entry-text'."
164 :group 'org-agenda-export
165 :type 'hook
166 :options '(org-agenda-add-entry-text))
168 (defcustom org-agenda-add-entry-text-maxlines 0
169 "Maximum number of entry text lines to be added to agenda.
170 This is only relevant when `org-agenda-add-entry-text' is part of
171 `org-agenda-before-write-hook', which it is by default.
172 When this is 0, nothing will happen. When it is greater than 0, it
173 specifies the maximum number of lines that will be added for each entry
174 that is listed in the agenda view.
176 Note that this variable is not used during display, only when exporting
177 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
178 and `org-agenda-entry-text-maxlines'."
179 :group 'org-agenda
180 :type 'integer)
182 (defcustom org-agenda-add-entry-text-descriptive-links t
183 "Non-nil means export org-links as descriptive links in agenda added text.
184 This variable applies to the text added to the agenda when
185 `org-agenda-add-entry-text-maxlines' is larger than 0.
186 When this variable nil, the URL will (also) be shown."
187 :group 'org-agenda
188 :type 'boolean)
190 (defcustom org-agenda-export-html-style ""
191 "The style specification for exported HTML Agenda files.
192 If this variable contains a string, it will replace the default <style>
193 section as produced by `htmlize'.
194 Since there are different ways of setting style information, this variable
195 needs to contain the full HTML structure to provide a style, including the
196 surrounding HTML tags. The style specifications should include definitions
197 the fonts used by the agenda, here is an example:
199 <style type=\"text/css\">
200 p { font-weight: normal; color: gray; }
201 .org-agenda-structure {
202 font-size: 110%;
203 color: #003399;
204 font-weight: 600;
206 .org-todo {
207 color: #cc6666;
208 font-weight: bold;
210 .org-agenda-done {
211 color: #339933;
213 .org-done {
214 color: #339933;
216 .title { text-align: center; }
217 .todo, .deadline { color: red; }
218 .done { color: green; }
219 </style>
221 or, if you want to keep the style in a file,
223 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
225 As the value of this option simply gets inserted into the HTML <head> header,
226 you can \"misuse\" it to also add other text to the header. However,
227 <style>...</style> is required, if not present the variable will be ignored."
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-tags-todo-honor-ignore-options nil
744 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
745 The variables
746 `org-agenda-todo-ignore-with-date',
747 `org-agenda-todo-ignore-timestamp',
748 `org-agenda-todo-ignore-scheduled',
749 `org-agenda-todo-ignore-deadlines'
750 make the global TODO list skip entries that have time stamps of certain
751 kinds. If this option is set, the same options will also apply for the
752 tags-todo search, which is the general tags/property matcher
753 restricted to unfinished TODO entries only."
754 :group 'org-agenda-skip
755 :group 'org-agenda-todo-list
756 :group 'org-agenda-match-view
757 :type 'boolean)
759 (defcustom org-agenda-skip-scheduled-if-done nil
760 "Non-nil means don't show scheduled items in agenda when they are done.
761 This is relevant for the daily/weekly agenda, not for the TODO list. And
762 it applies only to the actual date of the scheduling. Warnings about
763 an item with a past scheduling dates are always turned off when the item
764 is DONE."
765 :group 'org-agenda-skip
766 :group 'org-agenda-daily/weekly
767 :type 'boolean)
769 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
770 "Non-nil means skip scheduling line if same entry shows because of deadline.
771 In the agenda of today, an entry can show up multiple times because
772 it is both scheduled and has a nearby deadline, and maybe a plain time
773 stamp as well.
774 When this variable is t, then only the deadline is shown and the fact that
775 the entry is scheduled today or was scheduled previously is not shown.
776 When this variable is nil, the entry will be shown several times. When
777 the variable is the symbol `not-today', then skip scheduled previously,
778 but not scheduled today."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type '(choice
782 (const :tag "Never" nil)
783 (const :tag "Always" t)
784 (const :tag "Not when scheduled today" not-today)))
786 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
787 "Non-nil means skip timestamp line if same entry shows because of deadline.
788 In the agenda of today, an entry can show up multiple times
789 because it has both a plain timestamp and has a nearby deadline.
790 When this variable is t, then only the deadline is shown and the
791 fact that the entry has a timestamp for or including today is not
792 shown. When this variable is nil, the entry will be shown
793 several times."
794 :group 'org-agenda-skip
795 :group 'org-agenda-daily/weekly
796 :version "24.1"
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)))
801 (defcustom org-agenda-skip-deadline-if-done nil
802 "Non-nil means don't show deadlines when the corresponding item is done.
803 When nil, the deadline is still shown and should give you a happy feeling.
804 This is relevant for the daily/weekly agenda. And it applied only to the
805 actually date of the deadline. Warnings about approaching and past-due
806 deadlines are always turned off when the item is DONE."
807 :group 'org-agenda-skip
808 :group 'org-agenda-daily/weekly
809 :type 'boolean)
811 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
812 "Non-nil means skip deadline prewarning when entry is also scheduled.
813 This will apply on all days where a prewarning for the deadline would
814 be shown, but not at the day when the entry is actually due. On that day,
815 the deadline will be shown anyway.
816 This variable may be set to nil, t, or a number which will then give
817 the number of days before the actual deadline when the prewarnings
818 should resume.
819 This can be used in a workflow where the first showing of the deadline will
820 trigger you to schedule it, and then you don't want to be reminded of it
821 because you will take care of it on the day when scheduled."
822 :group 'org-agenda-skip
823 :group 'org-agenda-daily/weekly
824 :version "24.1"
825 :type '(choice
826 (const :tag "Alwas show prewarning" nil)
827 (const :tag "Remove prewarning if entry is scheduled" t)
828 (integer :tag "Restart prewarning N days before deadline")))
830 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
831 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
832 When non-nil, after the search for timestamps has matched once in an
833 entry, the rest of the entry will not be searched."
834 :group 'org-agenda-skip
835 :type 'boolean)
837 (defcustom org-agenda-skip-timestamp-if-done nil
838 "Non-nil means don't select item by timestamp or -range if it is DONE."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :type 'boolean)
843 (defcustom org-agenda-dim-blocked-tasks t
844 "Non-nil means dim blocked tasks in the agenda display.
845 This causes some overhead during agenda construction, but if you
846 have turned on `org-enforce-todo-dependencies',
847 `org-enforce-todo-checkbox-dependencies', or any other blocking
848 mechanism, this will create useful feedback in the agenda.
850 Instead of t, this variable can also have the value `invisible'.
851 Then blocked tasks will be invisible and only become visible when
852 they become unblocked. An exemption to this behavior is when a task is
853 blocked because of unchecked checkboxes below it. Since checkboxes do
854 not show up in the agenda views, making this task invisible you remove any
855 trace from agenda views that there is something to do. Therefore, a task
856 that is blocked because of checkboxes will never be made invisible, it
857 will only be dimmed."
858 :group 'org-agenda-daily/weekly
859 :group 'org-agenda-todo-list
860 :type '(choice
861 (const :tag "Do not dim" nil)
862 (const :tag "Dim to a gray face" t)
863 (const :tag "Make invisible" invisible)))
865 (defcustom org-timeline-show-empty-dates 3
866 "Non-nil means `org-timeline' also shows dates without an entry.
867 When nil, only the days which actually have entries are shown.
868 When t, all days between the first and the last date are shown.
869 When an integer, show also empty dates, but if there is a gap of more than
870 N days, just insert a special line indicating the size of the gap."
871 :group 'org-agenda-skip
872 :type '(choice
873 (const :tag "None" nil)
874 (const :tag "All" t)
875 (integer :tag "at most")))
877 (defgroup org-agenda-startup nil
878 "Options concerning initial settings in the Agenda in Org Mode."
879 :tag "Org Agenda Startup"
880 :group 'org-agenda)
882 (defcustom org-agenda-menu-show-matcher t
883 "Non-nil means show the match string in the agenda dispatcher menu.
884 When nil, the matcher string is not shown, but is put into the help-echo
885 property so than moving the mouse over the command shows it.
886 Setting it to nil is good if matcher strings are very long and/or if
887 you want to use two-columns display (see `org-agenda-menu-two-columns')."
888 :group 'org-agenda
889 :version "24.1"
890 :type 'boolean)
892 (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
894 (defcustom org-agenda-menu-two-columns nil
895 "Non-nil means, use two columns to show custom commands in the dispatcher.
896 If you use this, you probably want to set `org-agenda-menu-show-matcher'
897 to nil."
898 :group 'org-agenda
899 :version "24.1"
900 :type 'boolean)
902 (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
903 (defcustom org-agenda-finalize-hook nil
904 "Hook run just before displaying an agenda buffer."
905 :group 'org-agenda-startup
906 :type 'hook)
908 (defcustom org-agenda-mouse-1-follows-link nil
909 "Non-nil means mouse-1 on a link will follow the link in the agenda.
910 A longer mouse click will still set point. Does not work on XEmacs.
911 Needs to be set before org.el is loaded."
912 :group 'org-agenda-startup
913 :type 'boolean)
915 (defcustom org-agenda-start-with-follow-mode nil
916 "The initial value of follow mode in a newly created agenda window."
917 :group 'org-agenda-startup
918 :type 'boolean)
920 (defcustom org-agenda-follow-indirect nil
921 "Non-nil means `org-agenda-follow-mode' displays only the
922 current item's tree, in an indirect buffer."
923 :group 'org-agenda
924 :version "24.1"
925 :type 'boolean)
927 (defcustom org-agenda-show-outline-path t
928 "Non-nil means show outline path in echo area after line motion."
929 :group 'org-agenda-startup
930 :type 'boolean)
932 (defcustom org-agenda-start-with-entry-text-mode nil
933 "The initial value of entry-text-mode in a newly created agenda window."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-entry-text-maxlines 5
938 "Number of text lines to be added when `E' is pressed in the agenda.
940 Note that this variable only used during agenda display. Add add entry text
941 when exporting the agenda, configure the variable
942 `org-agenda-add-entry-ext-maxlines'."
943 :group 'org-agenda
944 :type 'integer)
946 (defcustom org-agenda-entry-text-exclude-regexps nil
947 "List of regular expressions to clean up entry text.
948 The complete matches of all regular expressions in this list will be
949 removed from entry text before it is shown in the agenda."
950 :group 'org-agenda
951 :type '(repeat (regexp)))
953 (defvar org-agenda-entry-text-cleanup-hook nil
954 "Hook that is run after basic cleanup of entry text to be shown in agenda.
955 This cleanup is done in a temporary buffer, so the function may inspect and
956 change the entire buffer.
957 Some default stuff like drawers and scheduling/deadline dates will already
958 have been removed when this is called, as will any matches for regular
959 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
961 (defvar org-agenda-include-inactive-timestamps nil
962 "Non-nil means include inactive time stamps in agenda and timeline.
963 Dynamically scoped.")
965 (defgroup org-agenda-windows nil
966 "Options concerning the windows used by the Agenda in Org Mode."
967 :tag "Org Agenda Windows"
968 :group 'org-agenda)
970 (defcustom org-agenda-window-setup 'reorganize-frame
971 "How the agenda buffer should be displayed.
972 Possible values for this option are:
974 current-window Show agenda in the current window, keeping all other windows.
975 other-window Use `switch-to-buffer-other-window' to display agenda.
976 reorganize-frame Show only two windows on the current frame, the current
977 window and the agenda.
978 other-frame Use `switch-to-buffer-other-frame' to display agenda.
979 Also, when exiting the agenda, kill that frame.
980 See also the variable `org-agenda-restore-windows-after-quit'."
981 :group 'org-agenda-windows
982 :type '(choice
983 (const current-window)
984 (const other-frame)
985 (const other-window)
986 (const reorganize-frame)))
988 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
989 "The min and max height of the agenda window as a fraction of frame height.
990 The value of the variable is a cons cell with two numbers between 0 and 1.
991 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
992 :group 'org-agenda-windows
993 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
995 (defcustom org-agenda-restore-windows-after-quit nil
996 "Non-nil means restore window configuration upon exiting agenda.
997 Before the window configuration is changed for displaying the agenda,
998 the current status is recorded. When the agenda is exited with
999 `q' or `x' and this option is set, the old state is restored. If
1000 `org-agenda-window-setup' is `other-frame', the value of this
1001 option will be ignored."
1002 :group 'org-agenda-windows
1003 :type 'boolean)
1005 (defcustom org-agenda-ndays nil
1006 "Number of days to include in overview display.
1007 Should be 1 or 7.
1008 Obsolete, see `org-agenda-span'."
1009 :group 'org-agenda-daily/weekly
1010 :type 'integer)
1012 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1014 (defcustom org-agenda-span 'week
1015 "Number of days to include in overview display.
1016 Can be day, week, month, year, or any number of days.
1017 Custom commands can set this variable in the options section."
1018 :group 'org-agenda-daily/weekly
1019 :type '(choice (const :tag "Day" day)
1020 (const :tag "Week" week)
1021 (const :tag "Month" month)
1022 (const :tag "Year" year)
1023 (integer :tag "Custom")))
1025 (defcustom org-agenda-start-on-weekday 1
1026 "Non-nil means start the overview always on the specified weekday.
1027 0 denotes Sunday, 1 denotes Monday etc.
1028 When nil, always start on the current day.
1029 Custom commands can set this variable in the options section."
1030 :group 'org-agenda-daily/weekly
1031 :type '(choice (const :tag "Today" nil)
1032 (integer :tag "Weekday No.")))
1034 (defcustom org-agenda-show-all-dates t
1035 "Non-nil means `org-agenda' shows every day in the selected range.
1036 When nil, only the days which actually have entries are shown."
1037 :group 'org-agenda-daily/weekly
1038 :type 'boolean)
1040 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1041 "Format string for displaying dates in the agenda.
1042 Used by the daily/weekly agenda and by the timeline. This should be
1043 a format string understood by `format-time-string', or a function returning
1044 the formatted date as a string. The function must take a single argument,
1045 a calendar-style date list like (month day year)."
1046 :group 'org-agenda-daily/weekly
1047 :type '(choice
1048 (string :tag "Format string")
1049 (function :tag "Function")))
1051 (defun org-agenda-format-date-aligned (date)
1052 "Format a date string for display in the daily/weekly agenda, or timeline.
1053 This function makes sure that dates are aligned for easy reading."
1054 (require 'cal-iso)
1055 (let* ((dayname (calendar-day-name date))
1056 (day (cadr date))
1057 (day-of-week (calendar-day-of-week date))
1058 (month (car date))
1059 (monthname (calendar-month-name month))
1060 (year (nth 2 date))
1061 (iso-week (org-days-to-iso-week
1062 (calendar-absolute-from-gregorian date)))
1063 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1064 (1- year))
1065 ((and (= month 12) (<= iso-week 1))
1066 (1+ year))
1067 (t year)))
1068 (weekstring (if (= day-of-week 1)
1069 (format " W%02d" iso-week)
1070 "")))
1071 (format "%-10s %2d %s %4d%s"
1072 dayname day monthname year weekstring)))
1074 (defcustom org-agenda-time-leading-zero nil
1075 "Non-nil means use leading zero for military times in agenda.
1076 For example, 9:30am would become 09:30 rather than 9:30."
1077 :group 'org-agenda-daily/weekly
1078 :version "24.1"
1079 :type 'boolean)
1081 (defcustom org-agenda-timegrid-use-ampm nil
1082 "When set, show AM/PM style timestamps on the timegrid."
1083 :group 'org-agenda
1084 :version "24.1"
1085 :type 'boolean)
1087 (defun org-agenda-time-of-day-to-ampm (time)
1088 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1089 (let* ((hour-number (string-to-number (substring time 0 -3)))
1090 (minute (substring time -2))
1091 (ampm "am"))
1092 (cond
1093 ((equal hour-number 12)
1094 (setq ampm "pm"))
1095 ((> hour-number 12)
1096 (setq ampm "pm")
1097 (setq hour-number (- hour-number 12))))
1098 (concat
1099 (if org-agenda-time-leading-zero
1100 (format "%02d" hour-number)
1101 (format "%02s" (number-to-string hour-number)))
1102 ":" minute ampm)))
1104 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1105 "Conditionally convert TIME to AM/PM format
1106 based on `org-agenda-timegrid-use-ampm'"
1107 (if org-agenda-timegrid-use-ampm
1108 (org-agenda-time-of-day-to-ampm time)
1109 time))
1111 (defcustom org-agenda-weekend-days '(6 0)
1112 "Which days are weekend?
1113 These days get the special face `org-agenda-date-weekend' in the agenda
1114 and timeline buffers."
1115 :group 'org-agenda-daily/weekly
1116 :type '(set :greedy t
1117 (const :tag "Monday" 1)
1118 (const :tag "Tuesday" 2)
1119 (const :tag "Wednesday" 3)
1120 (const :tag "Thursday" 4)
1121 (const :tag "Friday" 5)
1122 (const :tag "Saturday" 6)
1123 (const :tag "Sunday" 0)))
1125 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1126 "Non-nil means jump to today when moving a past date forward in time.
1127 When using S-right in the agenda to move a a date forward, and the date
1128 stamp currently points to the past, the first key press will move it
1129 to today. WHen nil, just move one day forward even if the date stays
1130 in the past."
1131 :group 'org-agenda-daily/weekly
1132 :version "24.1"
1133 :type 'boolean)
1135 (defcustom org-agenda-include-diary nil
1136 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1137 Custom commands can set this variable in the options section."
1138 :group 'org-agenda-daily/weekly
1139 :type 'boolean)
1141 (defcustom org-agenda-include-deadlines t
1142 "If non-nil, include entries within their deadline warning period.
1143 Custom commands can set this variable in the options section."
1144 :group 'org-agenda-daily/weekly
1145 :version "24.1"
1146 :type 'boolean)
1148 (defcustom org-agenda-repeating-timestamp-show-all t
1149 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1150 When set to a list of strings, only show occurrences of repeating
1151 stamps for these TODO keywords. When nil, only one occurrence is
1152 shown, either today or the nearest into the future."
1153 :group 'org-agenda-daily/weekly
1154 :type '(choice
1155 (const :tag "Show repeating stamps" t)
1156 (repeat :tag "Show repeating stamps for these TODO keywords"
1157 (string :tag "TODO Keyword"))
1158 (const :tag "Don't show repeating stamps" nil)))
1160 (defcustom org-scheduled-past-days 10000
1161 "No. of days to continue listing scheduled items that are not marked DONE.
1162 When an item is scheduled on a date, it shows up in the agenda on this
1163 day and will be listed until it is marked done for the number of days
1164 given here."
1165 :group 'org-agenda-daily/weekly
1166 :type 'integer)
1168 (defcustom org-agenda-log-mode-items '(closed clock)
1169 "List of items that should be shown in agenda log mode.
1170 This list may contain the following symbols:
1172 closed Show entries that have been closed on that day.
1173 clock Show entries that have received clocked time on that day.
1174 state Show all logged state changes.
1175 Note that instead of changing this variable, you can also press `C-u l' in
1176 the agenda to display all available LOG items temporarily."
1177 :group 'org-agenda-daily/weekly
1178 :type '(set :greedy t (const closed) (const clock) (const state)))
1180 (defcustom org-agenda-clock-consistency-checks
1181 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1182 :gap-ok-around ("4:00")
1183 :default-face ((:background "DarkRed") (:foreground "white"))
1184 :overlap-face nil :gap-face nil :no-end-time-face nil
1185 :long-face nil :short-face nil)
1186 "This is a property list, with the following keys:
1188 :max-duration Mark clocking chunks that are longer than this time.
1189 This is a time string like \"HH:MM\", or the number
1190 of minutes as an integer.
1192 :min-duration Mark clocking chunks that are shorter that this.
1193 This is a time string like \"HH:MM\", or the number
1194 of minutes as an integer.
1196 :max-gap Mark gaps between clocking chunks that are longer than
1197 this duration. A number of minutes, or a string
1198 like \"HH:MM\".
1200 :gap-ok-around List of times during the day which are usually not working
1201 times. When a gap is detected, but the gap contains any
1202 of these times, the gap is *not* reported. For example,
1203 if this is (\"4:00\" \"13:00\") then gaps that contain
1204 4:00 in the morning (i.e. the night) and 13:00
1205 (i.e. a typical lunch time) do not cause a warning.
1206 You should have at least one time during the night in this
1207 list, or otherwise the first task each morning will trigger
1208 a warning because it follows a long gap.
1210 Furthermore, the following properties can be used to define faces for
1211 issue display.
1213 :default-face the default face, if the specific face is undefined
1214 :overlap-face face for overlapping clocks
1215 :gap-face face for gaps between clocks
1216 :no-end-time-face face for incomplete clocks
1217 :long-face face for clock intervals that are too long
1218 :short-face face for clock intervals that are too short"
1219 :group 'org-agenda-daily/weekly
1220 :group 'org-clock
1221 :version "24.1"
1222 :type 'plist)
1224 (defcustom org-agenda-log-mode-add-notes t
1225 "Non-nil means add first line of notes to log entries in agenda views.
1226 If a log item like a state change or a clock entry is associated with
1227 notes, the first line of these notes will be added to the entry in the
1228 agenda display."
1229 :group 'org-agenda-daily/weekly
1230 :type 'boolean)
1232 (defcustom org-agenda-start-with-log-mode nil
1233 "The initial value of log-mode in a newly created agenda window.
1234 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1235 explanations on the possible values."
1236 :group 'org-agenda-startup
1237 :group 'org-agenda-daily/weekly
1238 :type '(choice (const :tag "Don't show log items" nil)
1239 (const :tag "Show only log items" 'only)
1240 (const :tag "Show all possible log items" 'clockcheck)
1241 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1242 (choice (const :tag "Show closed log items" 'closed)
1243 (const :tag "Show clocked log items" 'clock)
1244 (const :tag "Show all logged state changes" 'state)))))
1246 (defcustom org-agenda-start-with-clockreport-mode nil
1247 "The initial value of clockreport-mode in a newly created agenda window."
1248 :group 'org-agenda-startup
1249 :group 'org-agenda-daily/weekly
1250 :type 'boolean)
1252 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1253 "Property list with parameters for the clocktable in clockreport mode.
1254 This is the display mode that shows a clock table in the daily/weekly
1255 agenda, the properties for this dynamic block can be set here.
1256 The usual clocktable parameters are allowed here, but you cannot set
1257 the properties :name, :tstart, :tend, :block, and :scope - these will
1258 be overwritten to make sure the content accurately reflects the
1259 current display in the agenda."
1260 :group 'org-agenda-daily/weekly
1261 :type 'plist)
1263 (defcustom org-agenda-search-view-always-boolean nil
1264 "Non-nil means the search string is interpreted as individual parts.
1266 The search string for search view can either be interpreted as a phrase,
1267 or as a list of snippets that define a boolean search for a number of
1268 strings.
1270 When this is non-nil, the string will be split on whitespace, and each
1271 snippet will be searched individually, and all must match in order to
1272 select an entry. A snippet is then a single string of non-white
1273 characters, or a string in double quotes, or a regexp in {} braces.
1274 If a snippet is preceded by \"-\", the snippet must *not* match.
1275 \"+\" is syntactic sugar for positive selection. Each snippet may
1276 be found as a full word or a partial word, but see the variable
1277 `org-agenda-search-view-force-full-words'.
1279 When this is nil, search will look for the entire search phrase as one,
1280 with each space character matching any amount of whitespace, including
1281 line breaks.
1283 Even when this is nil, you can still switch to Boolean search dynamically
1284 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1285 is a regexp marked with braces like \"{abc}\", this will also switch to
1286 boolean search."
1287 :group 'org-agenda-search-view
1288 :version "24.1"
1289 :type 'boolean)
1291 (if (fboundp 'defvaralias)
1292 (defvaralias 'org-agenda-search-view-search-words-only
1293 'org-agenda-search-view-always-boolean))
1295 (defcustom org-agenda-search-view-force-full-words nil
1296 "Non-nil means, search words must be matches as complete words.
1297 When nil, they may also match part of a word."
1298 :group 'org-agenda-search-view
1299 :version "24.1"
1300 :type 'boolean)
1302 (defgroup org-agenda-time-grid nil
1303 "Options concerning the time grid in the Org-mode Agenda."
1304 :tag "Org Agenda Time Grid"
1305 :group 'org-agenda)
1307 (defcustom org-agenda-search-headline-for-time t
1308 "Non-nil means search headline for a time-of-day.
1309 If the headline contains a time-of-day in one format or another, it will
1310 be used to sort the entry into the time sequence of items for a day.
1311 Some people have time stamps in the headline that refer to the creation
1312 time or so, and then this produces an unwanted side effect. If this is
1313 the case for your, use this variable to turn off searching the headline
1314 for a time."
1315 :group 'org-agenda-time-grid
1316 :type 'boolean)
1318 (defcustom org-agenda-use-time-grid t
1319 "Non-nil means show a time grid in the agenda schedule.
1320 A time grid is a set of lines for specific times (like every two hours between
1321 8:00 and 20:00). The items scheduled for a day at specific times are
1322 sorted in between these lines.
1323 For details about when the grid will be shown, and what it will look like, see
1324 the variable `org-agenda-time-grid'."
1325 :group 'org-agenda-time-grid
1326 :type 'boolean)
1328 (defcustom org-agenda-time-grid
1329 '((daily today require-timed)
1330 "----------------"
1331 (800 1000 1200 1400 1600 1800 2000))
1333 "The settings for time grid for agenda display.
1334 This is a list of three items. The first item is again a list. It contains
1335 symbols specifying conditions when the grid should be displayed:
1337 daily if the agenda shows a single day
1338 weekly if the agenda shows an entire week
1339 today show grid on current date, independent of daily/weekly display
1340 require-timed show grid only if at least one item has a time specification
1342 The second item is a string which will be placed behind the grid time.
1344 The third item is a list of integers, indicating the times that should have
1345 a grid line."
1346 :group 'org-agenda-time-grid
1347 :type
1348 '(list
1349 (set :greedy t :tag "Grid Display Options"
1350 (const :tag "Show grid in single day agenda display" daily)
1351 (const :tag "Show grid in weekly agenda display" weekly)
1352 (const :tag "Always show grid for today" today)
1353 (const :tag "Show grid only if any timed entries are present"
1354 require-timed)
1355 (const :tag "Skip grid times already present in an entry"
1356 remove-match))
1357 (string :tag "Grid String")
1358 (repeat :tag "Grid Times" (integer :tag "Time"))))
1360 (defcustom org-agenda-show-current-time-in-grid t
1361 "Non-nil means show the current time in the time grid."
1362 :group 'org-agenda-time-grid
1363 :version "24.1"
1364 :type 'boolean)
1366 (defcustom org-agenda-current-time-string
1367 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1368 "The string for the current time marker in the agenda."
1369 :group 'org-agenda-time-grid
1370 :version "24.1"
1371 :type 'string)
1373 (defgroup org-agenda-sorting nil
1374 "Options concerning sorting in the Org-mode Agenda."
1375 :tag "Org Agenda Sorting"
1376 :group 'org-agenda)
1378 (defcustom org-agenda-sorting-strategy
1379 '((agenda habit-down time-up priority-down category-keep)
1380 (todo priority-down category-keep)
1381 (tags priority-down category-keep)
1382 (search category-keep))
1383 "Sorting structure for the agenda items of a single day.
1384 This is a list of symbols which will be used in sequence to determine
1385 if an entry should be listed before another entry. The following
1386 symbols are recognized:
1388 time-up Put entries with time-of-day indications first, early first
1389 time-down Put entries with time-of-day indications first, late first
1390 category-keep Keep the default order of categories, corresponding to the
1391 sequence in `org-agenda-files'.
1392 category-up Sort alphabetically by category, A-Z.
1393 category-down Sort alphabetically by category, Z-A.
1394 tag-up Sort alphabetically by last tag, A-Z.
1395 tag-down Sort alphabetically by last tag, Z-A.
1396 priority-up Sort numerically by priority, high priority last.
1397 priority-down Sort numerically by priority, high priority first.
1398 todo-state-up Sort by todo state, tasks that are done last.
1399 todo-state-down Sort by todo state, tasks that are done first.
1400 effort-up Sort numerically by estimated effort, high effort last.
1401 effort-down Sort numerically by estimated effort, high effort first.
1402 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1403 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1404 habit-up Put entries that are habits first
1405 habit-down Put entries that are habits last
1406 alpha-up Sort headlines alphabetically
1407 alpha-down Sort headlines alphabetically, reversed
1409 The different possibilities will be tried in sequence, and testing stops
1410 if one comparison returns a \"not-equal\". For example, the default
1411 '(time-up category-keep priority-down)
1412 means: Pull out all entries having a specified time of day and sort them,
1413 in order to make a time schedule for the current day the first thing in the
1414 agenda listing for the day. Of the entries without a time indication, keep
1415 the grouped in categories, don't sort the categories, but keep them in
1416 the sequence given in `org-agenda-files'. Within each category sort by
1417 priority.
1419 Leaving out `category-keep' would mean that items will be sorted across
1420 categories by priority.
1422 Instead of a single list, this can also be a set of list for specific
1423 contents, with a context symbol in the car of the list, any of
1424 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1426 Custom commands can bind this variable in the options section."
1427 :group 'org-agenda-sorting
1428 :type `(choice
1429 (repeat :tag "General" ,org-sorting-choice)
1430 (list :tag "Individually"
1431 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1432 (repeat ,org-sorting-choice))
1433 (cons (const :tag "Strategy for TODO lists" todo)
1434 (repeat ,org-sorting-choice))
1435 (cons (const :tag "Strategy for Tags matches" tags)
1436 (repeat ,org-sorting-choice))
1437 (cons (const :tag "Strategy for search matches" search)
1438 (repeat ,org-sorting-choice)))))
1440 (defcustom org-agenda-cmp-user-defined nil
1441 "A function to define the comparison `user-defined'.
1442 This function must receive two arguments, agenda entry a and b.
1443 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1444 the user comparison, return nil.
1445 When this is defined, you can make `user-defined-up' and `user-defined-down'
1446 part of an agenda sorting strategy."
1447 :group 'org-agenda-sorting
1448 :type 'symbol)
1450 (defcustom org-sort-agenda-notime-is-late t
1451 "Non-nil means items without time are considered late.
1452 This is only relevant for sorting. When t, items which have no explicit
1453 time like 15:30 will be considered as 99:01, i.e. later than any items which
1454 do have a time. When nil, the default time is before 0:00. You can use this
1455 option to decide if the schedule for today should come before or after timeless
1456 agenda entries."
1457 :group 'org-agenda-sorting
1458 :type 'boolean)
1460 (defcustom org-sort-agenda-noeffort-is-high t
1461 "Non-nil means items without effort estimate are sorted as high effort.
1462 This also applies when filtering an agenda view with respect to the
1463 < or > effort operator. Then, tasks with no effort defined will be treated
1464 as tasks with high effort.
1465 When nil, such items are sorted as 0 minutes effort."
1466 :group 'org-agenda-sorting
1467 :type 'boolean)
1469 (defgroup org-agenda-line-format nil
1470 "Options concerning the entry prefix in the Org-mode agenda display."
1471 :tag "Org Agenda Line Format"
1472 :group 'org-agenda)
1474 (defcustom org-agenda-prefix-format
1475 '((agenda . " %i %-12:c%?-12t% s")
1476 (timeline . " % s")
1477 (todo . " %i %-12:c")
1478 (tags . " %i %-12:c")
1479 (search . " %i %-12:c"))
1480 "Format specifications for the prefix of items in the agenda views.
1481 An alist with five entries, each for the different agenda types. The
1482 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1483 The values are format strings.
1485 This format works similar to a printf format, with the following meaning:
1487 %c the category of the item, \"Diary\" for entries from the diary,
1488 or as given by the CATEGORY keyword or derived from the file name
1489 %e the effort required by the item
1490 %i the icon category of the item, see `org-agenda-category-icon-alist'
1491 %T the last tag of the item (ignore inherited tags, which come first)
1492 %t the HH:MM time-of-day specification if one applies to the entry
1493 %s Scheduling/Deadline information, a short string
1494 %(expression) Eval EXPRESSION and replace the control string
1495 by the result
1497 All specifiers work basically like the standard `%s' of printf, but may
1498 contain two additional characters: a question mark just after the `%'
1499 and a whitespace/punctuation character just before the final letter.
1501 If the first character after `%' is a question mark, the entire field
1502 will only be included if the corresponding value applies to the current
1503 entry. This is useful for fields which should have fixed width when
1504 present, but zero width when absent. For example, \"%?-12t\" will
1505 result in a 12 character time field if a time of the day is specified,
1506 but will completely disappear in entries which do not contain a time.
1508 If there is punctuation or whitespace character just before the final
1509 format letter, this character will be appended to the field value if
1510 the value is not empty. For example, the format \"%-12:c\" leads to
1511 \"Diary: \" if the category is \"Diary\". If the category were be
1512 empty, no additional colon would be inserted.
1514 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1515 which means:
1517 - Indent the line with two space characters
1518 - Give the category a 12 chars wide field, padded with whitespace on
1519 the right (because of `-'). Append a colon if there is a category
1520 (because of `:').
1521 - If there is a time-of-day, put it into a 12 chars wide field. If no
1522 time, don't put in an empty field, just skip it (because of '?').
1523 - Finally, put the scheduling information.
1525 See also the variables `org-agenda-remove-times-when-in-prefix' and
1526 `org-agenda-remove-tags'.
1528 Custom commands can set this variable in the options section."
1529 :type '(choice
1530 (string :tag "General format")
1531 (list :greedy t :tag "View dependent"
1532 (cons (const agenda) (string :tag "Format"))
1533 (cons (const timeline) (string :tag "Format"))
1534 (cons (const todo) (string :tag "Format"))
1535 (cons (const tags) (string :tag "Format"))
1536 (cons (const search) (string :tag "Format"))))
1537 :group 'org-agenda-line-format)
1539 (defvar org-prefix-format-compiled nil
1540 "The compiled prefix format and associated variables.
1541 This is a list where first element is a list of variable bindings, and second
1542 element is the compiled format expression. See the variable
1543 `org-agenda-prefix-format'.")
1545 (defcustom org-agenda-todo-keyword-format "%-1s"
1546 "Format for the TODO keyword in agenda lines.
1547 Set this to something like \"%-12s\" if you want all TODO keywords
1548 to occupy a fixed space in the agenda display."
1549 :group 'org-agenda-line-format
1550 :type 'string)
1552 (defcustom org-agenda-diary-sexp-prefix nil
1553 "A regexp that matches part of a diary sexp entry
1554 which should be treated as scheduling/deadline information in
1555 `org-agenda'.
1557 For example, you can use this to extract the `diary-remind-message' from
1558 `diary-remind' entries."
1559 :group 'org-agenda-line-format
1560 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1562 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1563 "Text preceding timerange entries in the agenda view.
1564 This is a list with two strings. The first applies when the range
1565 is entirely on one day. The second applies if the range spans several days.
1566 The strings may have two \"%d\" format specifiers which will be filled
1567 with the sequence number of the days, and the total number of days in the
1568 range, respectively."
1569 :group 'org-agenda-line-format
1570 :type '(list
1571 (string :tag "Deadline today ")
1572 (choice :tag "Deadline relative"
1573 (string :tag "Format string")
1574 (function))))
1576 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1577 "Text preceding scheduled items in the agenda view.
1578 This is a list with two strings. The first applies when the item is
1579 scheduled on the current day. The second applies when it has been scheduled
1580 previously, it may contain a %d indicating that this is the nth time that
1581 this item is scheduled, due to automatic rescheduling of unfinished items
1582 for the following day. So this number is one larger than the number of days
1583 that passed since this item was scheduled first."
1584 :group 'org-agenda-line-format
1585 :type '(list
1586 (string :tag "Scheduled today ")
1587 (string :tag "Scheduled previously")))
1589 (defcustom org-agenda-inactive-leader "["
1590 "Text preceding item pulled into the agenda by inactive time stamps.
1591 These entries are added to the agenda when pressing \"[\"."
1592 :group 'org-agenda-line-format
1593 :version "24.1"
1594 :type '(list
1595 (string :tag "Scheduled today ")
1596 (string :tag "Scheduled previously")))
1598 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1599 "Text preceding deadline items in the agenda view.
1600 This is a list with two strings. The first applies when the item has its
1601 deadline on the current day. The second applies when it is in the past or
1602 in the future, it may contain %d to capture how many days away the deadline
1603 is (was)."
1604 :group 'org-agenda-line-format
1605 :type '(list
1606 (string :tag "Deadline today ")
1607 (choice :tag "Deadline relative"
1608 (string :tag "Format string")
1609 (function))))
1611 (defcustom org-agenda-remove-times-when-in-prefix t
1612 "Non-nil means remove duplicate time specifications in agenda items.
1613 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1614 time-of-day specification in a headline or diary entry is extracted and
1615 placed into the prefix. If this option is non-nil, the original specification
1616 \(a timestamp or -range, or just a plain time(range) specification like
1617 11:30-4pm) will be removed for agenda display. This makes the agenda less
1618 cluttered.
1619 The option can be t or nil. It may also be the symbol `beg', indicating
1620 that the time should only be removed when it is located at the beginning of
1621 the headline/diary entry."
1622 :group 'org-agenda-line-format
1623 :type '(choice
1624 (const :tag "Always" t)
1625 (const :tag "Never" nil)
1626 (const :tag "When at beginning of entry" beg)))
1628 (defcustom org-agenda-remove-timeranges-from-blocks nil
1629 "Non-nil means remove time ranges specifications in agenda
1630 items that span on several days."
1631 :group 'org-agenda-line-format
1632 :version "24.1"
1633 :type 'boolean)
1635 (defcustom org-agenda-default-appointment-duration nil
1636 "Default duration for appointments that only have a starting time.
1637 When nil, no duration is specified in such cases.
1638 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1639 :group 'org-agenda-line-format
1640 :type '(choice
1641 (integer :tag "Minutes")
1642 (const :tag "No default duration")))
1644 (defcustom org-agenda-show-inherited-tags t
1645 "Non-nil means show inherited tags in each agenda line."
1646 :group 'org-agenda-line-format
1647 :type 'boolean)
1649 (defcustom org-agenda-hide-tags-regexp nil
1650 "Regular expression used to filter away specific tags in agenda views.
1651 This means that these tags will be present, but not be shown in the agenda
1652 line. Secondary filtering will still work on the hidden tags.
1653 Nil means don't hide any tags."
1654 :group 'org-agenda-line-format
1655 :type '(choice
1656 (const :tag "Hide none" nil)
1657 (string :tag "Regexp ")))
1659 (defcustom org-agenda-remove-tags nil
1660 "Non-nil means remove the tags from the headline copy in the agenda.
1661 When this is the symbol `prefix', only remove tags when
1662 `org-agenda-prefix-format' contains a `%T' specifier."
1663 :group 'org-agenda-line-format
1664 :type '(choice
1665 (const :tag "Always" t)
1666 (const :tag "Never" nil)
1667 (const :tag "When prefix format contains %T" prefix)))
1669 (if (fboundp 'defvaralias)
1670 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1671 'org-agenda-remove-tags))
1673 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1674 "Shift tags in agenda items to this column.
1675 If this number is positive, it specifies the column. If it is negative,
1676 it means that the tags should be flushright to that column. For example,
1677 -80 works well for a normal 80 character screen."
1678 :group 'org-agenda-line-format
1679 :type 'integer)
1681 (if (fboundp 'defvaralias)
1682 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1684 (defcustom org-agenda-fontify-priorities 'cookies
1685 "Non-nil means highlight low and high priorities in agenda.
1686 When t, the highest priority entries are bold, lowest priority italic.
1687 However, settings in `org-priority-faces' will overrule these faces.
1688 When this variable is the symbol `cookies', only fontify the
1689 cookies, not the entire task.
1690 This may also be an association list of priority faces, whose
1691 keys are the character values of `org-highest-priority',
1692 `org-default-priority', and `org-lowest-priority' (the default values
1693 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1694 color as a string, or a list like `(:background \"Red\")'.
1695 If it is a color, the variable `org-faces-easy-properties'
1696 determines if it is a foreground or a background color."
1697 :group 'org-agenda-line-format
1698 :type '(choice
1699 (const :tag "Never" nil)
1700 (const :tag "Defaults" t)
1701 (const :tag "Cookies only" cookies)
1702 (repeat :tag "Specify"
1703 (list (character :tag "Priority" :value ?A)
1704 (choice :tag "Face "
1705 (string :tag "Color")
1706 (sexp :tag "Face"))))))
1708 (defcustom org-agenda-day-face-function nil
1709 "Function called to determine what face should be used to display a day.
1710 The only argument passed to that function is the day. It should
1711 returns a face, or nil if does not want to specify a face and let
1712 the normal rules apply."
1713 :group 'org-agenda-line-format
1714 :version "24.1"
1715 :type 'function)
1717 (defcustom org-agenda-category-icon-alist nil
1718 "Alist of category icon to be displayed in agenda views.
1720 Each entry should have the following format:
1722 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1724 Where CATEGORY-REGEXP is a regexp matching the categories where
1725 the icon should be displayed.
1726 FILE-OR-DATA either a file path or a string containing image data.
1728 The other fields can be omitted safely if not needed:
1729 TYPE indicates the image type.
1730 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1731 image data.
1732 PROPS are additional image attributes to assign to the image,
1733 like, e.g. `:ascent center'.
1735 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1737 If you want to set the display properties yourself, just put a
1738 list as second element:
1740 (CATEGORY-REGEXP (MY PROPERTY LIST))
1742 For example, to display a 16px horizontal space for Emacs
1743 category, you can use:
1745 (\"Emacs\" '(space . (:width (16))))"
1746 :group 'org-agenda-line-format
1747 :version "24.1"
1748 :type '(alist :key-type (string :tag "Regexp matching category")
1749 :value-type (choice (list :tag "Icon"
1750 (string :tag "File or data")
1751 (symbol :tag "Type")
1752 (boolean :tag "Data?")
1753 (repeat :tag "Extra image properties" :inline t symbol))
1754 (list :tag "Display properties" sexp))))
1756 (defgroup org-agenda-column-view nil
1757 "Options concerning column view in the agenda."
1758 :tag "Org Agenda Column View"
1759 :group 'org-agenda)
1761 (defcustom org-agenda-columns-show-summaries t
1762 "Non-nil means show summaries for columns displayed in the agenda view."
1763 :group 'org-agenda-column-view
1764 :type 'boolean)
1766 (defcustom org-agenda-columns-compute-summary-properties t
1767 "Non-nil means recompute all summary properties before column view.
1768 When column view in the agenda is listing properties that have a summary
1769 operator, it can go to all relevant buffers and recompute the summaries
1770 there. This can mean overhead for the agenda column view, but is necessary
1771 to have thing up to date.
1772 As a special case, a CLOCKSUM property also makes sure that the clock
1773 computations are current."
1774 :group 'org-agenda-column-view
1775 :type 'boolean)
1777 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1778 "Non-nil means the duration of an appointment will add to day effort.
1779 The property to which appointment durations will be added is the one given
1780 in the option `org-effort-property'. If an appointment does not have
1781 an end time, `org-agenda-default-appointment-duration' will be used. If that
1782 is not set, an appointment without end time will not contribute to the time
1783 estimate."
1784 :group 'org-agenda-column-view
1785 :type 'boolean)
1787 (defcustom org-agenda-auto-exclude-function nil
1788 "A function called with a tag to decide if it is filtered on '/ RET'.
1789 The sole argument to the function, which is called once for each
1790 possible tag, is a string giving the name of the tag. The
1791 function should return either nil if the tag should be included
1792 as normal, or \"-<TAG>\" to exclude the tag.
1793 Note that for the purpose of tag filtering, only the lower-case version of
1794 all tags will be considered, so that this function will only ever see
1795 the lower-case version of all tags."
1796 :group 'org-agenda
1797 :type 'function)
1799 (defcustom org-agenda-bulk-custom-functions nil
1800 "Alist of characters and custom functions for bulk actions.
1801 For example, this value makes those two functions available:
1803 '((?R set-category)
1804 (?C bulk-cut))
1806 With selected entries in an agenda buffer, `B R' will call
1807 the custom function `set-category' on the selected entries.
1808 Note that functions in this alist don't need to be quoted."
1809 :type 'alist
1810 :version "24.1"
1811 :group 'org-agenda)
1813 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1814 "Execute BODY with point at location given by `org-hd-marker' property.
1815 If STRING is non-nil, the text property will be fetched from position 0
1816 in that string. If STRING is nil, it will be fetched from the beginning
1817 of the current line."
1818 (org-with-gensyms (marker)
1819 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1820 'org-hd-marker ,string)))
1821 (with-current-buffer (marker-buffer ,marker)
1822 (save-excursion
1823 (goto-char ,marker)
1824 ,@body)))))
1825 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1827 (defun org-add-agenda-custom-command (entry)
1828 "Replace or add a command in `org-agenda-custom-commands'.
1829 This is mostly for hacking and trying a new command - once the command
1830 works you probably want to add it to `org-agenda-custom-commands' for good."
1831 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1832 (if ass
1833 (setcdr ass (cdr entry))
1834 (push entry org-agenda-custom-commands))))
1836 ;;; Define the org-agenda-mode
1838 (defvar org-agenda-mode-map (make-sparse-keymap)
1839 "Keymap for `org-agenda-mode'.")
1840 (if (fboundp 'defvaralias)
1841 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1843 (defvar org-agenda-menu) ; defined later in this file.
1844 (defvar org-agenda-restrict nil) ; defined later in this file.
1845 (defvar org-agenda-follow-mode nil)
1846 (defvar org-agenda-entry-text-mode nil)
1847 (defvar org-agenda-clockreport-mode nil)
1848 (defvar org-agenda-show-log nil)
1849 (defvar org-agenda-redo-command nil)
1850 (defvar org-agenda-query-string nil)
1851 (defvar org-agenda-mode-hook nil
1852 "Hook for `org-agenda-mode', run after the mode is turned on.")
1853 (defvar org-agenda-type nil)
1854 (defvar org-agenda-force-single-file nil)
1855 (defvar org-agenda-bulk-marked-entries nil
1856 "List of markers that refer to marked entries in the agenda.")
1858 ;;; Multiple agenda buffers support
1860 (defcustom org-agenda-sticky nil
1861 "Non-nil means agenda q key will bury agenda buffers.
1862 Agenda commands will then show existing buffer instead of generating new ones.
1863 When nil, `q' will kill the single agenda buffer."
1864 :group 'org-agenda
1865 :type 'boolean
1866 :set (lambda (var val)
1867 (if (boundp var)
1868 (org-toggle-sticky-agenda (if val 1 0))
1869 (set var val))))
1871 ;;;###autoload
1872 (defun org-toggle-sticky-agenda (&optional arg)
1873 "Toggle `org-agenda-sticky'."
1874 (interactive "P")
1875 (let ((new-value (if arg
1876 (> (prefix-numeric-value arg) 0)
1877 (not org-agenda-sticky))))
1878 (if (equal new-value org-agenda-sticky)
1879 (and (org-called-interactively-p 'interactive)
1880 (message "Sticky agenda was already %s"
1881 (if org-agenda-sticky "enabled" "disabled")))
1882 (setq org-agenda-sticky new-value)
1883 (org-agenda-kill-all-agenda-buffers)
1884 (and (org-called-interactively-p 'interactive)
1885 (message "Sticky agenda was %s"
1886 (if org-agenda-sticky "enabled" "disabled"))))))
1888 (defvar org-agenda-buffer nil
1889 "Agenda buffer currently being generated.")
1891 (defvar org-agenda-last-prefix-arg nil)
1892 (defvar org-agenda-this-buffer-name nil)
1893 (defvar org-agenda-doing-sticky-redo nil)
1894 (defvar org-agenda-this-buffer-is-sticky nil)
1896 (defconst org-agenda-local-vars
1897 '(org-agenda-this-buffer-name
1898 org-agenda-undo-list
1899 org-agenda-pending-undo-list
1900 org-agenda-follow-mode
1901 org-agenda-entry-text-mode
1902 org-agenda-clockreport-mode
1903 org-agenda-show-log
1904 org-agenda-redo-command
1905 org-agenda-query-string
1906 org-agenda-type
1907 org-agenda-bulk-marked-entries
1908 org-agenda-undo-has-started-in
1909 org-agenda-info
1910 org-agenda-tag-filter-overlays
1911 org-agenda-cat-filter-overlays
1912 org-agenda-pre-window-conf
1913 org-agenda-columns-active
1914 org-agenda-tag-filter
1915 org-agenda-category-filter
1916 org-agenda-markers
1917 org-agenda-last-search-view-search-was-boolean
1918 org-agenda-filtered-by-category
1919 org-agenda-filter-form
1920 org-agenda-show-window
1921 org-agenda-cycle-counter
1922 org-agenda-last-prefix-arg)
1923 "Variables that must be local in agenda buffers to allow multiple buffers.")
1925 (defun org-agenda-mode ()
1926 "Mode for time-sorted view on action items in Org-mode files.
1928 The following commands are available:
1930 \\{org-agenda-mode-map}"
1931 (interactive)
1932 (cond (org-agenda-doing-sticky-redo
1933 ;; Refreshing sticky agenda-buffer
1935 ;; Preserve the value of `org-agenda-local-vars' variables,
1936 ;; while letting `kill-all-local-variables' kill the rest
1937 (let ((save (buffer-local-variables)))
1938 (kill-all-local-variables)
1939 (mapc 'make-local-variable org-agenda-local-vars)
1940 (dolist (elem save)
1941 (let ((var (car elem))
1942 (val (cdr elem)))
1943 (when (and val
1944 (member var org-agenda-local-vars))
1945 (set var val)))))
1946 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1947 (org-agenda-sticky
1948 ;; Creating a sticky Agenda buffer for the first time
1949 (kill-all-local-variables)
1950 (mapc 'make-local-variable org-agenda-local-vars)
1951 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1953 ;; Creating a non-sticky agenda buffer
1954 (kill-all-local-variables)
1955 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1956 (setq org-agenda-undo-list nil
1957 org-agenda-pending-undo-list nil
1958 org-agenda-bulk-marked-entries nil)
1959 (setq major-mode 'org-agenda-mode)
1960 ;; Keep global-font-lock-mode from turning on font-lock-mode
1961 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1962 (setq mode-name "Org-Agenda")
1963 (use-local-map org-agenda-mode-map)
1964 (easy-menu-add org-agenda-menu)
1965 (if org-startup-truncated (setq truncate-lines t))
1966 (org-set-local 'line-move-visual nil)
1967 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1968 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1969 ;; Make sure properties are removed when copying text
1970 (make-local-variable 'filter-buffer-substring-functions)
1971 (add-hook 'filter-buffer-substring-functions
1972 (lambda (fun start end delete)
1973 (substring-no-properties (funcall fun start end delete))))
1974 (unless org-agenda-keep-modes
1975 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1976 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1977 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1978 org-agenda-show-log org-agenda-start-with-log-mode))
1980 (easy-menu-change
1981 '("Agenda") "Agenda Files"
1982 (append
1983 (list
1984 (vector
1985 (if (get 'org-agenda-files 'org-restrict)
1986 "Restricted to single file"
1987 "Edit File List")
1988 '(org-edit-agenda-file-list)
1989 (not (get 'org-agenda-files 'org-restrict)))
1990 "--")
1991 (mapcar 'org-file-menu-entry (org-agenda-files))))
1992 (org-agenda-set-mode-name)
1993 (apply
1994 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1995 (list 'org-agenda-mode-hook)))
1997 (substitute-key-definition 'undo 'org-agenda-undo
1998 org-agenda-mode-map global-map)
1999 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2000 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2001 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2002 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2003 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2004 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2005 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2006 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2007 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2008 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2009 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2010 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2011 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2012 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2013 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2014 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2015 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2016 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2017 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2018 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2019 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2020 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2021 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2022 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2023 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2024 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2025 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2026 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2027 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2028 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2029 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2030 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2031 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2032 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2033 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2034 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2035 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2036 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2037 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2038 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2039 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2040 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2041 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2042 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2043 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2044 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2046 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2047 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2048 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2049 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2050 (while l (org-defkey org-agenda-mode-map
2051 (int-to-string (pop l)) 'digit-argument)))
2053 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2054 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2055 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2056 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2057 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2058 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2059 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2060 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2061 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2062 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2063 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2064 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2065 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2066 'org-clock-modify-effort-estimate)
2067 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2068 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2069 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2070 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2071 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2072 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2073 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2074 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2075 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2076 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2077 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2078 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2079 (substitute-key-definition 'next-line 'org-agenda-next-line
2080 org-agenda-mode-map global-map)
2081 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2082 org-agenda-mode-map global-map)
2083 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2084 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2085 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2086 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2087 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2088 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2089 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2090 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2091 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2092 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2093 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2094 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2095 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2096 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2097 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2098 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2099 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2100 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2101 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2102 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2103 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2104 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2105 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2106 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2107 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2108 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2109 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2110 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2111 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2112 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2114 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2115 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2116 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2117 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2118 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2119 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2120 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2121 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2122 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2123 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2125 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2127 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2128 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2129 (when org-agenda-mouse-1-follows-link
2130 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2131 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2132 '("Agenda"
2133 ("Agenda Files")
2134 "--"
2135 ("Agenda Dates"
2136 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2137 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2138 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2139 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2140 "--"
2141 ("View"
2142 ["Day View" org-agenda-day-view
2143 :active (org-agenda-check-type nil 'agenda)
2144 :style radio :selected (eq org-agenda-current-span 'day)
2145 :keys "v d (or just d)"]
2146 ["Week View" org-agenda-week-view
2147 :active (org-agenda-check-type nil 'agenda)
2148 :style radio :selected (eq org-agenda-current-span 'week)
2149 :keys "v w (or just w)"]
2150 ["Month View" org-agenda-month-view
2151 :active (org-agenda-check-type nil 'agenda)
2152 :style radio :selected (eq org-agenda-current-span 'month)
2153 :keys "v m"]
2154 ["Year View" org-agenda-year-view
2155 :active (org-agenda-check-type nil 'agenda)
2156 :style radio :selected (eq org-agenda-current-span 'year)
2157 :keys "v y"]
2158 "--"
2159 ["Include Diary" org-agenda-toggle-diary
2160 :style toggle :selected org-agenda-include-diary
2161 :active (org-agenda-check-type nil 'agenda)]
2162 ["Include Deadlines" org-agenda-toggle-deadlines
2163 :style toggle :selected org-agenda-include-deadlines
2164 :active (org-agenda-check-type nil 'agenda)]
2165 ["Use Time Grid" org-agenda-toggle-time-grid
2166 :style toggle :selected org-agenda-use-time-grid
2167 :active (org-agenda-check-type nil 'agenda)]
2168 "--"
2169 ["Show clock report" org-agenda-clockreport-mode
2170 :style toggle :selected org-agenda-clockreport-mode
2171 :active (org-agenda-check-type nil 'agenda)]
2172 ["Show some entry text" org-agenda-entry-text-mode
2173 :style toggle :selected org-agenda-entry-text-mode
2174 :active t]
2175 "--"
2176 ["Show Logbook entries" org-agenda-log-mode
2177 :style toggle :selected org-agenda-show-log
2178 :active (org-agenda-check-type nil 'agenda 'timeline)
2179 :keys "v l (or just l)"]
2180 ["Include archived trees" org-agenda-archives-mode
2181 :style toggle :selected org-agenda-archives-mode :active t
2182 :keys "v a"]
2183 ["Include archive files" (org-agenda-archives-mode t)
2184 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2185 :keys "v A"]
2186 "--"
2187 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2188 ["Write view to file" org-agenda-write t]
2189 ["Rebuild buffer" org-agenda-redo t]
2190 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2191 "--"
2192 ["Show original entry" org-agenda-show t]
2193 ["Go To (other window)" org-agenda-goto t]
2194 ["Go To (this window)" org-agenda-switch-to t]
2195 ["Follow Mode" org-agenda-follow-mode
2196 :style toggle :selected org-agenda-follow-mode :active t]
2197 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2198 "--"
2199 ("TODO"
2200 ["Cycle TODO" org-agenda-todo t]
2201 ["Next TODO set" org-agenda-todo-nextset t]
2202 ["Previous TODO set" org-agenda-todo-previousset t]
2203 ["Add note" org-agenda-add-note t])
2204 ("Archive/Refile/Delete"
2205 ["Archive default" org-agenda-archive-default t]
2206 ["Archive default" org-agenda-archive-default-with-confirmation t]
2207 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2208 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2209 ["Archive subtree" org-agenda-archive t]
2210 "--"
2211 ["Refile" org-agenda-refile t]
2212 "--"
2213 ["Delete subtree" org-agenda-kill t])
2214 ("Bulk action"
2215 ["Mark entry" org-agenda-bulk-mark t]
2216 ["Mark all" org-agenda-bulk-mark-all t]
2217 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2218 ["Unmark entry" org-agenda-bulk-unmark t]
2219 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2220 ["Act on all marked" org-agenda-bulk-action t]
2221 "--"
2222 ("Tags and Properties"
2223 ["Show all Tags" org-agenda-show-tags t]
2224 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2225 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2226 "--"
2227 ["Column View" org-columns t])
2228 ("Deadline/Schedule"
2229 ["Schedule" org-agenda-schedule t]
2230 ["Set Deadline" org-agenda-deadline t]
2231 "--"
2232 ["Mark item" org-agenda-action :active t :keys "k m"]
2233 ["Show mark item" org-agenda-action :active t :keys "k v"]
2234 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2235 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2236 "--"
2237 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2238 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2239 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2240 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2241 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2242 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2243 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2244 ("Clock and Effort"
2245 ["Clock in" org-agenda-clock-in t]
2246 ["Clock out" org-agenda-clock-out t]
2247 ["Clock cancel" org-agenda-clock-cancel t]
2248 ["Goto running clock" org-clock-goto t]
2249 "--"
2250 ["Set Effort" org-agenda-set-effort t]
2251 ["Change clocked effort" org-clock-modify-effort-estimate
2252 (org-clock-is-active)])
2253 ("Priority"
2254 ["Set Priority" org-agenda-priority t]
2255 ["Increase Priority" org-agenda-priority-up t]
2256 ["Decrease Priority" org-agenda-priority-down t]
2257 ["Show Priority" org-agenda-show-priority t])
2258 ("Calendar/Diary"
2259 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2261 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2262 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2263 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2264 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2265 "--"
2266 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2267 "--"
2268 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2269 "--"
2270 ("MobileOrg"
2271 ["Push Files and Views" org-mobile-push t]
2272 ["Get Captured and Flagged" org-mobile-pull t]
2273 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2274 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2275 "--"
2276 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2277 "--"
2278 ["Quit" org-agenda-quit t]
2279 ["Exit and Release Buffers" org-agenda-exit t]
2282 ;;; Agenda undo
2284 (defvar org-agenda-allow-remote-undo t
2285 "Non-nil means allow remote undo from the agenda buffer.")
2286 (defvar org-agenda-undo-has-started-in nil
2287 "Buffers that have already seen `undo-start' in the current undo sequence.")
2289 (defun org-agenda-undo ()
2290 "Undo a remote editing step in the agenda.
2291 This undoes changes both in the agenda buffer and in the remote buffer
2292 that have been changed along."
2293 (interactive)
2294 (or org-agenda-allow-remote-undo
2295 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2296 (if (not (eq this-command last-command))
2297 (setq org-agenda-undo-has-started-in nil
2298 org-agenda-pending-undo-list org-agenda-undo-list))
2299 (if (not org-agenda-pending-undo-list)
2300 (error "No further undo information"))
2301 (let* ((entry (pop org-agenda-pending-undo-list))
2302 buf line cmd rembuf)
2303 (setq cmd (pop entry) line (pop entry))
2304 (setq rembuf (nth 2 entry))
2305 (org-with-remote-undo rembuf
2306 (while (bufferp (setq buf (pop entry)))
2307 (if (pop entry)
2308 (with-current-buffer buf
2309 (let ((last-undo-buffer buf)
2310 (inhibit-read-only t))
2311 (unless (memq buf org-agenda-undo-has-started-in)
2312 (push buf org-agenda-undo-has-started-in)
2313 (make-local-variable 'pending-undo-list)
2314 (undo-start))
2315 (while (and pending-undo-list
2316 (listp pending-undo-list)
2317 (not (car pending-undo-list)))
2318 (pop pending-undo-list))
2319 (undo-more 1))))))
2320 (org-goto-line line)
2321 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2323 (defun org-verify-change-for-undo (l1 l2)
2324 "Verify that a real change occurred between the undo lists L1 and L2."
2325 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2326 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2327 (not (eq l1 l2)))
2329 ;;; Agenda dispatch
2331 (defvar org-agenda-restrict-begin (make-marker))
2332 (defvar org-agenda-restrict-end (make-marker))
2333 (defvar org-agenda-last-dispatch-buffer nil)
2334 (defvar org-agenda-overriding-restriction nil)
2336 (defcustom org-agenda-custom-commands-contexts nil
2337 "Alist of custom agenda keys and contextual rules.
2339 For example, if you have a custom agenda command \"p\" and you
2340 want this command to be accessible only from plain text files,
2341 use this:
2343 '((\"p\" (in-file . \"\\.txt\")))
2345 Here are the available contexts definitions:
2347 in-file: command displayed only in matching files
2348 in-mode: command displayed only in matching modes
2349 not-in-file: command not displayed in matching files
2350 not-in-mode: command not displayed in matching modes
2351 [function]: a custom function taking no argument
2353 If you define several checks, the agenda command will be
2354 accessible if there is at least one valid check.
2356 You can also bind a key to another agenda custom command
2357 depending on contextual rules.
2359 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2361 Here it means: in .txt files, use \"p\" as the key for the
2362 agenda command otherwise associated with \"q\". (The command
2363 originally associated with \"q\" is not displayed to avoid
2364 duplicates.)"
2365 ;; :version "24.3"
2366 :group 'org-agenda-custom-commands
2367 :type '(repeat (list :tag "Rule"
2368 (string :tag " Agenda key")
2369 (string :tag "Replace by command")
2370 (repeat :tag "Available when"
2371 (choice
2372 (cons :tag "Condition"
2373 (choice
2374 (const :tag "In file" in-file)
2375 (const :tag "Not in file" not-in-file)
2376 (const :tag "In mode" in-mode)
2377 (const :tag "Not in mode" not-in-mode))
2378 (regexp))
2379 (function :tag "Custom function"))))))
2381 (defvar org-keys nil)
2382 (defvar org-match nil)
2383 ;;;###autoload
2384 (defun org-agenda (&optional arg org-keys restriction)
2385 "Dispatch agenda commands to collect entries to the agenda buffer.
2386 Prompts for a command to execute. Any prefix arg will be passed
2387 on to the selected command. The default selections are:
2389 a Call `org-agenda-list' to display the agenda for current day or week.
2390 t Call `org-todo-list' to display the global todo list.
2391 T Call `org-todo-list' to display the global todo list, select only
2392 entries with a specific TODO keyword (the user gets a prompt).
2393 m Call `org-tags-view' to display headlines with tags matching
2394 a condition (the user is prompted for the condition).
2395 M Like `m', but select only TODO entries, no ordinary headlines.
2396 L Create a timeline for the current buffer.
2397 e Export views to associated files.
2398 s Search entries for keywords.
2399 S Search entries for keywords, only with TODO keywords.
2400 / Multi occur across all agenda files and also files listed
2401 in `org-agenda-text-search-extra-files'.
2402 < Restrict agenda commands to buffer, subtree, or region.
2403 Press several times to get the desired effect.
2404 > Remove a previous restriction.
2405 # List \"stuck\" projects.
2406 ! Configure what \"stuck\" means.
2407 C Configure custom agenda commands.
2409 More commands can be added by configuring the variable
2410 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2411 searches can be pre-defined in this way.
2413 If the current buffer is in Org-mode and visiting a file, you can also
2414 first press `<' once to indicate that the agenda should be temporarily
2415 \(until the next use of \\[org-agenda]) restricted to the current file.
2416 Pressing `<' twice means to restrict to the current subtree or region
2417 \(if active)."
2418 (interactive "P")
2419 (catch 'exit
2420 (let* ((prefix-descriptions nil)
2421 (org-agenda-buffer-name org-agenda-buffer-name)
2422 (org-agenda-window-setup (if (equal (buffer-name)
2423 org-agenda-buffer-name)
2424 'current-window
2425 org-agenda-window-setup))
2426 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2427 (org-agenda-custom-commands
2428 ;; normalize different versions
2429 (delq nil
2430 (mapcar
2431 (lambda (x)
2432 (cond ((stringp (cdr x))
2433 (push x prefix-descriptions)
2434 nil)
2435 ((stringp (nth 1 x)) x)
2436 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2437 (t (cons (car x) (cons "" (cdr x))))))
2438 org-agenda-custom-commands)))
2439 (org-agenda-custom-commands
2440 (org-contextualize-keys
2441 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2442 (buf (current-buffer))
2443 (bfn (buffer-file-name (buffer-base-buffer)))
2444 entry key type org-match lprops ans)
2445 ;; Turn off restriction unless there is an overriding one,
2446 (unless org-agenda-overriding-restriction
2447 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2448 ;; There is a request to keep the file list in place
2449 (put 'org-agenda-files 'org-restrict nil))
2450 (setq org-agenda-restrict nil)
2451 (move-marker org-agenda-restrict-begin nil)
2452 (move-marker org-agenda-restrict-end nil))
2453 ;; Delete old local properties
2454 (put 'org-agenda-redo-command 'org-lprops nil)
2455 ;; Delete previously set last-arguments
2456 (put 'org-agenda-redo-command 'last-args nil)
2457 ;; Remember where this call originated
2458 (setq org-agenda-last-dispatch-buffer (current-buffer))
2459 (unless org-keys
2460 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2461 org-keys (car ans)
2462 restriction (cdr ans)))
2463 ;; If we have sticky agenda buffers, set a name for the buffer,
2464 ;; depending on the invoking keys. The user may still set this
2465 ;; as a command option, which will overwrite what we do here.
2466 (if org-agenda-sticky
2467 (setq org-agenda-buffer-name
2468 (format "*Org Agenda(%s)*" org-keys)))
2469 ;; Establish the restriction, if any
2470 (when (and (not org-agenda-overriding-restriction) restriction)
2471 (put 'org-agenda-files 'org-restrict (list bfn))
2472 (cond
2473 ((eq restriction 'region)
2474 (setq org-agenda-restrict t)
2475 (move-marker org-agenda-restrict-begin (region-beginning))
2476 (move-marker org-agenda-restrict-end (region-end)))
2477 ((eq restriction 'subtree)
2478 (save-excursion
2479 (setq org-agenda-restrict t)
2480 (org-back-to-heading t)
2481 (move-marker org-agenda-restrict-begin (point))
2482 (move-marker org-agenda-restrict-end
2483 (progn (org-end-of-subtree t)))))))
2485 ;; For example the todo list should not need it (but does...)
2486 (cond
2487 ((setq entry (assoc org-keys org-agenda-custom-commands))
2488 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2489 (progn
2490 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2491 lprops (nth 4 entry))
2492 (if org-agenda-sticky
2493 (setq org-agenda-buffer-name
2494 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2495 (format "*Org Agenda(%s)*" org-keys))))
2496 (put 'org-agenda-redo-command 'org-lprops lprops)
2497 (cond
2498 ((eq type 'agenda)
2499 (org-let lprops '(org-agenda-list current-prefix-arg)))
2500 ((eq type 'alltodo)
2501 (org-let lprops '(org-todo-list current-prefix-arg)))
2502 ((eq type 'search)
2503 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2504 ((eq type 'stuck)
2505 (org-let lprops '(org-agenda-list-stuck-projects
2506 current-prefix-arg)))
2507 ((eq type 'tags)
2508 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2509 ((eq type 'tags-todo)
2510 (org-let lprops '(org-tags-view '(4) org-match)))
2511 ((eq type 'todo)
2512 (org-let lprops '(org-todo-list org-match)))
2513 ((eq type 'tags-tree)
2514 (org-check-for-org-mode)
2515 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2516 ((eq type 'todo-tree)
2517 (org-check-for-org-mode)
2518 (org-let lprops
2519 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2520 (regexp-quote org-match) "\\>"))))
2521 ((eq type 'occur-tree)
2522 (org-check-for-org-mode)
2523 (org-let lprops '(org-occur org-match)))
2524 ((functionp type)
2525 (org-let lprops '(funcall type org-match)))
2526 ((fboundp type)
2527 (org-let lprops '(funcall type org-match)))
2528 (t (error "Invalid custom agenda command type %s" type))))
2529 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2530 ((equal org-keys "C")
2531 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2532 (customize-variable 'org-agenda-custom-commands))
2533 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2534 ((equal org-keys "s") (call-interactively 'org-search-view))
2535 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2536 ((equal org-keys "t") (call-interactively 'org-todo-list))
2537 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2538 ((equal org-keys "m") (call-interactively 'org-tags-view))
2539 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2540 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2541 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2542 (org-add-hook
2543 'post-command-hook
2544 (lambda ()
2545 (unless (current-message)
2546 (let* ((m (org-agenda-get-any-marker))
2547 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2548 (when note
2549 (message (concat
2550 "FLAGGING-NOTE ([?] for more info): "
2551 (org-add-props
2552 (replace-regexp-in-string
2553 "\\\\n" "//"
2554 (copy-sequence note))
2555 nil 'face 'org-warning)))))))
2556 t t))
2557 ((equal org-keys "L")
2558 (unless (derived-mode-p 'org-mode)
2559 (error "This is not an Org-mode file"))
2560 (unless restriction
2561 (put 'org-agenda-files 'org-restrict (list bfn))
2562 (org-call-with-arg 'org-timeline arg)))
2563 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2564 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2565 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2566 (t (error "Invalid agenda key"))))))
2568 (defun org-agenda-append-agenda ()
2569 "Append another agenda view to the current one.
2570 This function allows interactive building of block agendas.
2571 Agenda views are separated by `org-agenda-block-separator'."
2572 (interactive)
2573 (unless (derived-mode-p 'org-agenda-mode)
2574 (error "Can only append from within agenda buffer"))
2575 (let ((org-agenda-multi t))
2576 (org-agenda)
2577 (widen)
2578 (org-agenda-finalize)
2579 (org-agenda-fit-window-to-buffer)))
2581 (defun org-agenda-normalize-custom-commands (cmds)
2582 (delq nil
2583 (mapcar
2584 (lambda (x)
2585 (cond ((stringp (cdr x)) nil)
2586 ((stringp (nth 1 x)) x)
2587 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2588 (t (cons (car x) (cons "" (cdr x))))))
2589 cmds)))
2591 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2592 "The user interface for selecting an agenda command."
2593 (catch 'exit
2594 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2595 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2596 (region-p (org-region-active-p))
2597 (custom org-agenda-custom-commands)
2598 (selstring "")
2599 restriction second-time
2600 c entry key type match prefixes rmheader header-end custom1 desc
2601 line lines left right n n1)
2602 (save-window-excursion
2603 (delete-other-windows)
2604 (org-switch-to-buffer-other-window " *Agenda Commands*")
2605 (erase-buffer)
2606 (insert (eval-when-compile
2607 (let ((header
2608 "Press key for an agenda command: < Buffer, subtree/region restriction
2609 -------------------------------- > Remove restriction
2610 a Agenda for current week or day e Export agenda views
2611 t List of all TODO entries T Entries with special TODO kwd
2612 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2613 s Search for keywords S Like s, but only TODO entries
2614 L Timeline for current buffer # List stuck projects (!=configure)
2615 / Multi-occur C Configure custom agenda commands
2616 ? Find :FLAGGED: entries * Toggle sticky agenda views
2618 (start 0))
2619 (while (string-match
2620 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2621 header start)
2622 (setq start (match-end 0))
2623 (add-text-properties (match-beginning 2) (match-end 2)
2624 '(face bold) header))
2625 header)))
2626 (setq header-end (move-marker (make-marker) (point)))
2627 (while t
2628 (setq custom1 custom)
2629 (when (eq rmheader t)
2630 (org-goto-line 1)
2631 (re-search-forward ":" nil t)
2632 (delete-region (match-end 0) (point-at-eol))
2633 (forward-char 1)
2634 (looking-at "-+")
2635 (delete-region (match-end 0) (point-at-eol))
2636 (move-marker header-end (match-end 0)))
2637 (goto-char header-end)
2638 (delete-region (point) (point-max))
2640 ;; Produce all the lines that describe custom commands and prefixes
2641 (setq lines nil)
2642 (while (setq entry (pop custom1))
2643 (setq key (car entry) desc (nth 1 entry)
2644 type (nth 2 entry)
2645 match (nth 3 entry))
2646 (if (> (length key) 1)
2647 (add-to-list 'prefixes (string-to-char key))
2648 (setq line
2649 (format
2650 "%-4s%-14s"
2651 (org-add-props (copy-sequence key)
2652 '(face bold))
2653 (cond
2654 ((string-match "\\S-" desc) desc)
2655 ((eq type 'agenda) "Agenda for current week or day")
2656 ((eq type 'alltodo) "List of all TODO entries")
2657 ((eq type 'search) "Word search")
2658 ((eq type 'stuck) "List of stuck projects")
2659 ((eq type 'todo) "TODO keyword")
2660 ((eq type 'tags) "Tags query")
2661 ((eq type 'tags-todo) "Tags (TODO)")
2662 ((eq type 'tags-tree) "Tags tree")
2663 ((eq type 'todo-tree) "TODO kwd tree")
2664 ((eq type 'occur-tree) "Occur tree")
2665 ((functionp type) (if (symbolp type)
2666 (symbol-name type)
2667 "Lambda expression"))
2668 (t "???"))))
2669 (if org-agenda-menu-show-matcher
2670 (setq line
2671 (concat line ": "
2672 (cond
2673 ((stringp match)
2674 (setq match (copy-sequence match))
2675 (org-add-props match nil 'face 'org-warning))
2676 (match
2677 (format "set of %d commands" (length match)))
2678 (t ""))))
2679 (if (org-string-nw-p match)
2680 (add-text-properties
2681 0 (length line) (list 'help-echo
2682 (concat "Matcher: "match)) line)))
2683 (push line lines)))
2684 (setq lines (nreverse lines))
2685 (when prefixes
2686 (mapc (lambda (x)
2687 (push
2688 (format "%s %s"
2689 (org-add-props (char-to-string x)
2690 nil 'face 'bold)
2691 (or (cdr (assoc (concat selstring
2692 (char-to-string x))
2693 prefix-descriptions))
2694 "Prefix key"))
2695 lines))
2696 prefixes))
2698 ;; Check if we should display in two columns
2699 (if org-agenda-menu-two-columns
2700 (progn
2701 (setq n (length lines)
2702 n1 (+ (/ n 2) (mod n 2))
2703 right (nthcdr n1 lines)
2704 left (copy-sequence lines))
2705 (setcdr (nthcdr (1- n1) left) nil))
2706 (setq left lines right nil))
2707 (while left
2708 (insert "\n" (pop left))
2709 (when right
2710 (if (< (current-column) 40)
2711 (move-to-column 40 t)
2712 (insert " "))
2713 (insert (pop right))))
2715 ;; Make the window the right size
2716 (goto-char (point-min))
2717 (if second-time
2718 (if (not (pos-visible-in-window-p (point-max)))
2719 (org-fit-window-to-buffer))
2720 (setq second-time t)
2721 (org-fit-window-to-buffer))
2723 ;; Ask for selection
2724 (message "Press key for agenda command%s:"
2725 (if (or restrict-ok org-agenda-overriding-restriction)
2726 (if org-agenda-overriding-restriction
2727 " (restriction lock active)"
2728 (if restriction
2729 (format " (restricted to %s)" restriction)
2730 " (unrestricted)"))
2731 ""))
2732 (setq c (read-char-exclusive))
2733 (message "")
2734 (cond
2735 ((assoc (char-to-string c) custom)
2736 (setq selstring (concat selstring (char-to-string c)))
2737 (throw 'exit (cons selstring restriction)))
2738 ((memq c prefixes)
2739 (setq selstring (concat selstring (char-to-string c))
2740 prefixes nil
2741 rmheader (or rmheader t)
2742 custom (delq nil (mapcar
2743 (lambda (x)
2744 (if (or (= (length (car x)) 1)
2745 (/= (string-to-char (car x)) c))
2747 (cons (substring (car x) 1) (cdr x))))
2748 custom))))
2749 ((eq c ?*)
2750 (call-interactively 'org-toggle-sticky-agenda)
2751 (sit-for 2))
2752 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2753 (message "Restriction is only possible in Org-mode buffers")
2754 (ding) (sit-for 1))
2755 ((eq c ?1)
2756 (org-agenda-remove-restriction-lock 'noupdate)
2757 (setq restriction 'buffer))
2758 ((eq c ?0)
2759 (org-agenda-remove-restriction-lock 'noupdate)
2760 (setq restriction (if region-p 'region 'subtree)))
2761 ((eq c ?<)
2762 (org-agenda-remove-restriction-lock 'noupdate)
2763 (setq restriction
2764 (cond
2765 ((eq restriction 'buffer)
2766 (if region-p 'region 'subtree))
2767 ((memq restriction '(subtree region))
2768 nil)
2769 (t 'buffer))))
2770 ((eq c ?>)
2771 (org-agenda-remove-restriction-lock 'noupdate)
2772 (setq restriction nil))
2773 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2774 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2775 ((and (> (length selstring) 0) (eq c ?\d))
2776 (delete-window)
2777 (org-agenda-get-restriction-and-command prefix-descriptions))
2779 ((equal c ?q) (error "Abort"))
2780 (t (error "Invalid key %c" c))))))))
2782 (defun org-agenda-fit-window-to-buffer ()
2783 "Fit the window to the buffer size."
2784 (and (memq org-agenda-window-setup '(reorganize-frame))
2785 (fboundp 'fit-window-to-buffer)
2786 (org-fit-window-to-buffer
2788 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2789 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2791 (defvar org-cmd nil)
2792 (defvar org-agenda-overriding-cmd nil)
2793 (defvar org-agenda-overriding-arguments nil)
2794 (defvar org-agenda-overriding-cmd-arguments nil)
2795 (defun org-agenda-run-series (name series)
2796 (org-let (nth 1 series) '(org-agenda-prepare name))
2797 ;; We need to reset agenda markers here, because when constructing a
2798 ;; block agenda, the individual blocks do not do that.
2799 (org-agenda-reset-markers)
2800 (let* ((org-agenda-multi t)
2801 (redo (list 'org-agenda-run-series name (list 'quote series)))
2802 (cmds (car series))
2803 (gprops (nth 1 series))
2804 match ;; The byte compiler incorrectly complains about this. Keep it!
2805 org-cmd type lprops)
2806 (while (setq org-cmd (pop cmds))
2807 (setq type (car org-cmd)
2808 match (eval (nth 1 org-cmd))
2809 lprops (nth 2 org-cmd))
2810 (let ((org-agenda-overriding-arguments
2811 (if (eq org-agenda-overriding-cmd org-cmd)
2812 (or org-agenda-overriding-arguments
2813 org-agenda-overriding-cmd-arguments))))
2814 (cond
2815 ((eq type 'agenda)
2816 (org-let2 gprops lprops
2817 '(call-interactively 'org-agenda-list)))
2818 ((eq type 'alltodo)
2819 (org-let2 gprops lprops
2820 '(call-interactively 'org-todo-list)))
2821 ((eq type 'search)
2822 (org-let2 gprops lprops
2823 '(org-search-view current-prefix-arg match nil)))
2824 ((eq type 'stuck)
2825 (org-let2 gprops lprops
2826 '(call-interactively 'org-agenda-list-stuck-projects)))
2827 ((eq type 'tags)
2828 (org-let2 gprops lprops
2829 '(org-tags-view current-prefix-arg match)))
2830 ((eq type 'tags-todo)
2831 (org-let2 gprops lprops
2832 '(org-tags-view '(4) match)))
2833 ((eq type 'todo)
2834 (org-let2 gprops lprops
2835 '(org-todo-list match)))
2836 ((fboundp type)
2837 (org-let2 gprops lprops
2838 '(funcall type match)))
2839 (t (error "Invalid type in command series")))))
2840 (widen)
2841 (let ((inhibit-read-only t))
2842 (add-text-properties (point-min) (point-max)
2843 `(org-serie t org-serie-redo-cmd ,redo)))
2844 (setq org-agenda-redo-command redo)
2845 (goto-char (point-min)))
2846 (org-agenda-fit-window-to-buffer)
2847 (org-let (nth 1 series) '(org-agenda-finalize)))
2849 ;;;###autoload
2850 (defmacro org-batch-agenda (cmd-key &rest parameters)
2851 "Run an agenda command in batch mode and send the result to STDOUT.
2852 If CMD-KEY is a string of length 1, it is used as a key in
2853 `org-agenda-custom-commands' and triggers this command. If it is a
2854 longer string it is used as a tags/todo match string.
2855 Parameters are alternating variable names and values that will be bound
2856 before running the agenda command."
2857 (org-eval-in-environment (org-make-parameter-alist parameters)
2858 (if (> (length cmd-key) 2)
2859 (org-tags-view nil cmd-key)
2860 (org-agenda nil cmd-key)))
2861 (set-buffer org-agenda-buffer-name)
2862 (princ (buffer-string)))
2863 (def-edebug-spec org-batch-agenda (form &rest sexp))
2865 (defvar org-agenda-info nil)
2867 ;;;###autoload
2868 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2869 "Run an agenda command in batch mode and send the result to STDOUT.
2870 If CMD-KEY is a string of length 1, it is used as a key in
2871 `org-agenda-custom-commands' and triggers this command. If it is a
2872 longer string it is used as a tags/todo match string.
2873 Parameters are alternating variable names and values that will be bound
2874 before running the agenda command.
2876 The output gives a line for each selected agenda item. Each
2877 item is a list of comma-separated values, like this:
2879 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2881 category The category of the item
2882 head The headline, without TODO kwd, TAGS and PRIORITY
2883 type The type of the agenda entry, can be
2884 todo selected in TODO match
2885 tagsmatch selected in tags match
2886 diary imported from diary
2887 deadline a deadline on given date
2888 scheduled scheduled on given date
2889 timestamp entry has timestamp on given date
2890 closed entry was closed on given date
2891 upcoming-deadline warning about deadline
2892 past-scheduled forwarded scheduled item
2893 block entry has date block including g. date
2894 todo The todo keyword, if any
2895 tags All tags including inherited ones, separated by colons
2896 date The relevant date, like 2007-2-14
2897 time The time, like 15:00-16:50
2898 extra Sting with extra planning info
2899 priority-l The priority letter if any was given
2900 priority-n The computed numerical priority
2901 agenda-day The day in the agenda where this is listed"
2902 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2903 (org-make-parameter-alist parameters))
2904 (if (> (length cmd-key) 2)
2905 (org-tags-view nil cmd-key)
2906 (org-agenda nil cmd-key)))
2907 (set-buffer org-agenda-buffer-name)
2908 (let* ((lines (org-split-string (buffer-string) "\n"))
2909 line)
2910 (while (setq line (pop lines))
2911 (catch 'next
2912 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2913 (setq org-agenda-info
2914 (org-fix-agenda-info (text-properties-at 0 line)))
2915 (princ
2916 (mapconcat 'org-agenda-export-csv-mapper
2917 '(org-category txt type todo tags date time extra
2918 priority-letter priority agenda-day)
2919 ","))
2920 (princ "\n")))))
2921 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2923 (defun org-fix-agenda-info (props)
2924 "Make sure all properties on an agenda item have a canonical form.
2925 This ensures the export commands can easily use it."
2926 (let (tmp re)
2927 (when (setq tmp (plist-get props 'tags))
2928 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2929 (when (setq tmp (plist-get props 'date))
2930 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2931 (let ((calendar-date-display-form '(year "-" month "-" day)))
2932 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2934 (setq tmp (calendar-date-string tmp)))
2935 (setq props (plist-put props 'date tmp)))
2936 (when (setq tmp (plist-get props 'day))
2937 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2938 (let ((calendar-date-display-form '(year "-" month "-" day)))
2939 (setq tmp (calendar-date-string tmp)))
2940 (setq props (plist-put props 'day tmp))
2941 (setq props (plist-put props 'agenda-day tmp)))
2942 (when (setq tmp (plist-get props 'txt))
2943 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2944 (plist-put props 'priority-letter (match-string 1 tmp))
2945 (setq tmp (replace-match "" t t tmp)))
2946 (when (and (setq re (plist-get props 'org-todo-regexp))
2947 (setq re (concat "\\`\\.*" re " ?"))
2948 (string-match re tmp))
2949 (plist-put props 'todo (match-string 1 tmp))
2950 (setq tmp (replace-match "" t t tmp)))
2951 (plist-put props 'txt tmp)))
2952 props)
2954 (defun org-agenda-export-csv-mapper (prop)
2955 (let ((res (plist-get org-agenda-info prop)))
2956 (setq res
2957 (cond
2958 ((not res) "")
2959 ((stringp res) res)
2960 (t (prin1-to-string res))))
2961 (while (string-match "," res)
2962 (setq res (replace-match ";" t t res)))
2963 (org-trim res)))
2965 ;;;###autoload
2966 (defun org-store-agenda-views (&rest parameters)
2967 (interactive)
2968 (eval (list 'org-batch-store-agenda-views)))
2970 ;;;###autoload
2971 (defmacro org-batch-store-agenda-views (&rest parameters)
2972 "Run all custom agenda commands that have a file argument."
2973 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2974 (pop-up-frames nil)
2975 (dir default-directory)
2976 (pars (org-make-parameter-alist parameters))
2977 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
2978 (save-window-excursion
2979 (while cmds
2980 (setq cmd (pop cmds)
2981 thiscmdkey (car cmd)
2982 thiscmdcmd (cdr cmd)
2983 match (nth 2 thiscmdcmd)
2984 bufname (if org-agenda-sticky
2985 (or (and (stringp match)
2986 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
2987 (format "*Org Agenda(%s)*" thiscmdkey))
2988 org-agenda-buffer-name)
2989 cmd-or-set (nth 2 cmd)
2990 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2991 files (nth (if (listp cmd-or-set) 4 5) cmd))
2992 (if (stringp files) (setq files (list files)))
2993 (when files
2994 (org-eval-in-environment (append org-agenda-exporter-settings
2995 opts pars)
2996 (org-agenda nil thiscmdkey))
2997 (set-buffer bufname)
2998 (while files
2999 (org-eval-in-environment (append org-agenda-exporter-settings
3000 opts pars)
3001 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3002 (and (get-buffer bufname)
3003 (kill-buffer bufname)))))))
3004 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3006 (defvar org-agenda-current-span nil
3007 "The current span used in the agenda view.") ; local variable in the agenda buffer
3008 (defun org-agenda-mark-header-line (pos)
3009 "Mark the line at POS as an agenda structure header."
3010 (save-excursion
3011 (goto-char pos)
3012 (put-text-property (point-at-bol) (point-at-eol)
3013 'org-agenda-structural-header t)
3014 (when org-agenda-title-append
3015 (put-text-property (point-at-bol) (point-at-eol)
3016 'org-agenda-title-append org-agenda-title-append))))
3018 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3019 (defvar org-agenda-write-buffer-name "Agenda View")
3020 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3021 "Write the current buffer (an agenda view) as a file.
3022 Depending on the extension of the file name, plain text (.txt),
3023 HTML (.html or .htm) or Postscript (.ps) is produced.
3024 If the extension is .ics, run icalendar export over all files used
3025 to construct the agenda and limit the export to entries listed in the
3026 agenda now.
3027 With prefix argument OPEN, open the new file immediately.
3028 If NOSETTINGS is given, do not scope the settings of
3029 `org-agenda-exporter-settings' into the export commands. This is used when
3030 the settings have already been scoped and we do not wish to overrule other,
3031 higher priority settings.
3032 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3033 (interactive "FWrite agenda to file: \nP")
3034 (if (not (file-writable-p file))
3035 (error "Cannot write agenda to file %s" file))
3036 (org-let (if nosettings nil org-agenda-exporter-settings)
3037 '(save-excursion
3038 (save-window-excursion
3039 (org-agenda-mark-filtered-text)
3040 (let ((bs (copy-sequence (buffer-string))) beg)
3041 (org-agenda-unmark-filtered-text)
3042 (with-temp-buffer
3043 (rename-buffer org-agenda-write-buffer-name t)
3044 (set-buffer-modified-p nil)
3045 (insert bs)
3046 (org-agenda-remove-marked-text 'org-filtered)
3047 (while (setq beg (text-property-any (point-min) (point-max)
3048 'org-filtered t))
3049 (delete-region
3050 beg (or (next-single-property-change beg 'org-filtered)
3051 (point-max))))
3052 (run-hooks 'org-agenda-before-write-hook)
3053 (cond
3054 ((org-bound-and-true-p org-mobile-creating-agendas)
3055 (org-mobile-write-agenda-for-mobile file))
3056 ((string-match "\\.html?\\'" file)
3057 (require 'htmlize)
3058 (set-buffer (htmlize-buffer (current-buffer)))
3059 (when (and org-agenda-export-html-style
3060 (string-match "<style>" org-agenda-export-html-style))
3061 ;; replace <style> section with org-agenda-export-html-style
3062 (goto-char (point-min))
3063 (kill-region (- (search-forward "<style") 6)
3064 (search-forward "</style>"))
3065 (insert org-agenda-export-html-style))
3066 (write-file file)
3067 (kill-buffer (current-buffer))
3068 (message "HTML written to %s" file))
3069 ((string-match "\\.ps\\'" file)
3070 (require 'ps-print)
3071 (ps-print-buffer-with-faces file)
3072 (message "Postscript written to %s" file))
3073 ((string-match "\\.pdf\\'" file)
3074 (require 'ps-print)
3075 (ps-print-buffer-with-faces
3076 (concat (file-name-sans-extension file) ".ps"))
3077 (call-process "ps2pdf" nil nil nil
3078 (expand-file-name
3079 (concat (file-name-sans-extension file) ".ps"))
3080 (expand-file-name file))
3081 (delete-file (concat (file-name-sans-extension file) ".ps"))
3082 (message "PDF written to %s" file))
3083 ((string-match "\\.ics\\'" file)
3084 (require 'org-icalendar)
3085 (let ((org-agenda-marker-table
3086 (org-create-marker-find-array
3087 (org-agenda-collect-markers)))
3088 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3089 (org-combined-agenda-icalendar-file file))
3090 (apply 'org-export-icalendar 'combine
3091 (org-agenda-files nil 'ifmode))))
3093 (let ((bs (buffer-string)))
3094 (find-file file)
3095 (erase-buffer)
3096 (insert bs)
3097 (save-buffer 0)
3098 (kill-buffer (current-buffer))
3099 (message "Plain text written to %s" file))))))))
3100 (set-buffer (or agenda-bufname
3101 (and (called-interactively-p 'any) (buffer-name))
3102 org-agenda-buffer-name)))
3103 (when open (org-open-file file)))
3105 (defvar org-agenda-tag-filter-overlays nil)
3106 (defvar org-agenda-cat-filter-overlays nil)
3108 (defun org-agenda-mark-filtered-text ()
3109 "Mark all text hidden by filtering with a text property."
3110 (let ((inhibit-read-only t))
3111 (mapc
3112 (lambda (o)
3113 (when (equal (overlay-buffer o) (current-buffer))
3114 (put-text-property
3115 (overlay-start o) (overlay-end o)
3116 'org-filtered t)))
3117 (append org-agenda-tag-filter-overlays
3118 org-agenda-cat-filter-overlays))))
3120 (defun org-agenda-unmark-filtered-text ()
3121 "Remove the filtering text property."
3122 (let ((inhibit-read-only t))
3123 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3125 (defun org-agenda-remove-marked-text (property &optional value)
3126 "Delete all text marked with VALUE of PROPERTY.
3127 VALUE defaults to t."
3128 (let (beg)
3129 (setq value (or value t))
3130 (while (setq beg (text-property-any (point-min) (point-max)
3131 property value))
3132 (delete-region
3133 beg (or (next-single-property-change beg 'org-filtered)
3134 (point-max))))))
3136 (defun org-agenda-add-entry-text ()
3137 "Add entry text to agenda lines.
3138 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3139 entry text following headings shown in the agenda.
3140 Drawers will be excluded, also the line with scheduling/deadline info."
3141 (when (and (> org-agenda-add-entry-text-maxlines 0)
3142 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3143 (let (m txt)
3144 (goto-char (point-min))
3145 (while (not (eobp))
3146 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3147 (beginning-of-line 2)
3148 (setq txt (org-agenda-get-some-entry-text
3149 m org-agenda-add-entry-text-maxlines " > "))
3150 (end-of-line 1)
3151 (if (string-match "\\S-" txt)
3152 (insert "\n" txt)
3153 (or (eobp) (forward-char 1))))))))
3155 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3156 &rest keep)
3157 "Extract entry text from MARKER, at most N-LINES lines.
3158 This will ignore drawers etc, just get the text.
3159 If INDENT is given, prefix every line with this string. If KEEP is
3160 given, it is a list of symbols, defining stuff that should not be
3161 removed from the entry content. Currently only `planning' is allowed here."
3162 (let (txt drawer-re kwd-time-re ind)
3163 (save-excursion
3164 (with-current-buffer (marker-buffer marker)
3165 (if (not (derived-mode-p 'org-mode))
3166 (setq txt "")
3167 (save-excursion
3168 (save-restriction
3169 (widen)
3170 (goto-char marker)
3171 (end-of-line 1)
3172 (setq txt (buffer-substring
3173 (min (1+ (point)) (point-max))
3174 (progn (outline-next-heading) (point)))
3175 drawer-re org-drawer-regexp
3176 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3177 ".*\n?"))
3178 (with-temp-buffer
3179 (insert txt)
3180 (when org-agenda-add-entry-text-descriptive-links
3181 (goto-char (point-min))
3182 (while (org-activate-bracket-links (point-max))
3183 (add-text-properties (match-beginning 0) (match-end 0)
3184 '(face org-link))))
3185 (goto-char (point-min))
3186 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3187 (set-text-properties (match-beginning 0) (match-end 0)
3188 nil))
3189 (goto-char (point-min))
3190 (while (re-search-forward drawer-re nil t)
3191 (delete-region
3192 (match-beginning 0)
3193 (progn (re-search-forward
3194 "^[ \t]*:END:.*\n?" nil 'move)
3195 (point))))
3196 (unless (member 'planning keep)
3197 (goto-char (point-min))
3198 (while (re-search-forward kwd-time-re nil t)
3199 (replace-match "")))
3200 (goto-char (point-min))
3201 (when org-agenda-entry-text-exclude-regexps
3202 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3203 (while (setq re (pop re-list))
3204 (goto-char (point-min))
3205 (while (re-search-forward re nil t)
3206 (replace-match "")))))
3207 (goto-char (point-max))
3208 (skip-chars-backward " \t\n")
3209 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3211 ;; find and remove min common indentation
3212 (goto-char (point-min))
3213 (untabify (point-min) (point-max))
3214 (setq ind (org-get-indentation))
3215 (while (not (eobp))
3216 (unless (looking-at "[ \t]*$")
3217 (setq ind (min ind (org-get-indentation))))
3218 (beginning-of-line 2))
3219 (goto-char (point-min))
3220 (while (not (eobp))
3221 (unless (looking-at "[ \t]*$")
3222 (move-to-column ind)
3223 (delete-region (point-at-bol) (point)))
3224 (beginning-of-line 2))
3226 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3228 (goto-char (point-min))
3229 (when indent
3230 (while (and (not (eobp)) (re-search-forward "^" nil t))
3231 (replace-match indent t t)))
3232 (goto-char (point-min))
3233 (while (looking-at "[ \t]*\n") (replace-match ""))
3234 (goto-char (point-max))
3235 (when (> (org-current-line)
3236 n-lines)
3237 (org-goto-line (1+ n-lines))
3238 (backward-char 1))
3239 (setq txt (buffer-substring (point-min) (point)))))))))
3240 txt))
3242 (defun org-agenda-collect-markers ()
3243 "Collect the markers pointing to entries in the agenda buffer."
3244 (let (m markers)
3245 (save-excursion
3246 (goto-char (point-min))
3247 (while (not (eobp))
3248 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3249 (org-get-at-bol 'org-marker)))
3250 (push m markers))
3251 (beginning-of-line 2)))
3252 (nreverse markers)))
3254 (defun org-create-marker-find-array (marker-list)
3255 "Create a alist of files names with all marker positions in that file."
3256 (let (f tbl m a p)
3257 (while (setq m (pop marker-list))
3258 (setq p (marker-position m)
3259 f (buffer-file-name (or (buffer-base-buffer
3260 (marker-buffer m))
3261 (marker-buffer m))))
3262 (if (setq a (assoc f tbl))
3263 (push (marker-position m) (cdr a))
3264 (push (list f p) tbl)))
3265 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3266 tbl)))
3268 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3269 (defun org-check-agenda-marker-table ()
3270 "Check of the current entry is on the marker list."
3271 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3273 (and (setq a (assoc file org-agenda-marker-table))
3274 (save-match-data
3275 (save-excursion
3276 (org-back-to-heading t)
3277 (member (point) (cdr a)))))))
3279 (defun org-check-for-org-mode ()
3280 "Make sure current buffer is in org-mode. Error if not."
3281 (or (derived-mode-p 'org-mode)
3282 (error "Cannot execute org-mode agenda command on buffer in %s"
3283 major-mode)))
3285 ;;; Agenda prepare and finalize
3287 (defvar org-agenda-multi nil) ; dynamically scoped
3288 (defvar org-agenda-pre-window-conf nil)
3289 (defvar org-agenda-columns-active nil)
3290 (defvar org-agenda-name nil)
3291 (defvar org-agenda-tag-filter nil)
3292 (defvar org-agenda-category-filter nil)
3293 (defvar org-agenda-top-category-filter nil)
3294 (defvar org-agenda-tag-filter-while-redo nil)
3295 (defvar org-agenda-tag-filter-preset nil
3296 "A preset of the tags filter used for secondary agenda filtering.
3297 This must be a list of strings, each string must be a single tag preceded
3298 by \"+\" or \"-\".
3299 This variable should not be set directly, but agenda custom commands can
3300 bind it in the options section. The preset filter is a global property of
3301 the entire agenda view. In a block agenda, it will not work reliably to
3302 define a filter for one of the individual blocks. You need to set it in
3303 the global options and expect it to be applied to the entire view.")
3305 (defvar org-agenda-category-filter-preset nil
3306 "A preset of the category filter used for secondary agenda filtering.
3307 This must be a list of strings, each string must be a single category
3308 preceded by \"+\" or \"-\".
3309 This variable should not be set directly, but agenda custom commands can
3310 bind it in the options section. The preset filter is a global property of
3311 the entire agenda view. In a block agenda, it will not work reliably to
3312 define a filter for one of the individual blocks. You need to set it in
3313 the global options and expect it to be applied to the entire view.")
3316 (defun org-agenda-use-sticky-p ()
3317 "Return non-nil if an agenda buffer named
3318 `org-agenda-buffer-name' exists and should be shown instead of
3319 generating a new one."
3320 (and
3321 ;; turned off by user
3322 org-agenda-sticky
3323 ;; For multi-agenda buffer already exists
3324 (not org-agenda-multi)
3325 ;; buffer found
3326 (get-buffer org-agenda-buffer-name)
3327 ;; C-u parameter is same as last call
3328 (with-current-buffer (get-buffer org-agenda-buffer-name)
3329 (and
3330 (equal current-prefix-arg
3331 org-agenda-last-prefix-arg)
3332 ;; In case user turned stickiness on, while having existing
3333 ;; Agenda buffer active, don't reuse that buffer, because it
3334 ;; does not have org variables local
3335 org-agenda-this-buffer-is-sticky))))
3337 (defun org-agenda-prepare-window (abuf)
3338 "Setup agenda buffer in the window."
3339 (let* ((awin (get-buffer-window abuf))
3340 wconf)
3341 (cond
3342 ((equal (current-buffer) abuf) nil)
3343 (awin (select-window awin))
3344 ((not (setq wconf (current-window-configuration))))
3345 ((equal org-agenda-window-setup 'current-window)
3346 (org-pop-to-buffer-same-window abuf))
3347 ((equal org-agenda-window-setup 'other-window)
3348 (org-switch-to-buffer-other-window abuf))
3349 ((equal org-agenda-window-setup 'other-frame)
3350 (switch-to-buffer-other-frame abuf))
3351 ((equal org-agenda-window-setup 'reorganize-frame)
3352 (delete-other-windows)
3353 (org-switch-to-buffer-other-window abuf)))
3354 ;; additional test in case agenda is invoked from within agenda
3355 ;; buffer via elisp link
3356 (unless (equal (current-buffer) abuf)
3357 (org-pop-to-buffer-same-window abuf))
3358 (setq org-agenda-pre-window-conf
3359 (or org-agenda-pre-window-conf wconf))))
3361 (defun org-agenda-prepare (&optional name)
3362 (if (org-agenda-use-sticky-p)
3363 (progn
3364 ;; Popup existing buffer
3365 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3366 (message "Sticky Agenda buffer, use `r' to refresh")
3367 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3368 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3369 (setq org-todo-keywords-for-agenda nil)
3370 (setq org-drawers-for-agenda nil)
3371 (unless org-agenda-persistent-filter
3372 (setq org-agenda-tag-filter nil
3373 org-agenda-category-filter nil))
3374 (put 'org-agenda-tag-filter :preset-filter
3375 org-agenda-tag-filter-preset)
3376 (put 'org-agenda-category-filter :preset-filter
3377 org-agenda-category-filter-preset)
3378 (if org-agenda-multi
3379 (progn
3380 (setq buffer-read-only nil)
3381 (goto-char (point-max))
3382 (unless (or (bobp) org-agenda-compact-blocks
3383 (not org-agenda-block-separator))
3384 (insert "\n"
3385 (if (stringp org-agenda-block-separator)
3386 org-agenda-block-separator
3387 (make-string (window-width) org-agenda-block-separator))
3388 "\n"))
3389 (narrow-to-region (point) (point-max)))
3390 (setq org-done-keywords-for-agenda nil)
3392 ;; Setting any org variables that are in org-agenda-local-vars
3393 ;; list need to be done after the prepare call
3394 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3395 (setq buffer-read-only nil)
3396 (org-agenda-reset-markers)
3397 (let ((inhibit-read-only t)) (erase-buffer))
3398 (org-agenda-mode)
3399 (setq org-agenda-buffer (current-buffer))
3400 (setq org-agenda-contributing-files nil)
3401 (setq org-agenda-columns-active nil)
3402 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3403 (setq org-todo-keywords-for-agenda
3404 (org-uniquify org-todo-keywords-for-agenda))
3405 (setq org-done-keywords-for-agenda
3406 (org-uniquify org-done-keywords-for-agenda))
3407 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3408 (setq org-agenda-last-prefix-arg current-prefix-arg)
3409 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3410 (and name (not org-agenda-name)
3411 (org-set-local 'org-agenda-name name)))
3412 (setq buffer-read-only nil)))
3414 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3415 (defun org-agenda-finalize ()
3416 "Finishing touch for the agenda buffer, called just before displaying it."
3417 (unless org-agenda-multi
3418 (save-excursion
3419 (let ((inhibit-read-only t))
3420 (goto-char (point-min))
3421 (while (org-activate-bracket-links (point-max))
3422 (add-text-properties (match-beginning 0) (match-end 0)
3423 '(face org-link)))
3424 (org-agenda-align-tags)
3425 (unless org-agenda-with-colors
3426 (remove-text-properties (point-min) (point-max) '(face nil))))
3427 (if (and (boundp 'org-agenda-overriding-columns-format)
3428 org-agenda-overriding-columns-format)
3429 (org-set-local 'org-agenda-overriding-columns-format
3430 org-agenda-overriding-columns-format))
3431 (if (and (boundp 'org-agenda-view-columns-initially)
3432 org-agenda-view-columns-initially)
3433 (org-agenda-columns))
3434 (when org-agenda-fontify-priorities
3435 (org-agenda-fontify-priorities))
3436 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3437 (org-agenda-dim-blocked-tasks))
3438 (org-agenda-mark-clocking-task)
3439 (when org-agenda-entry-text-mode
3440 (org-agenda-entry-text-hide)
3441 (org-agenda-entry-text-show))
3442 (if (functionp 'org-habit-insert-consistency-graphs)
3443 (org-habit-insert-consistency-graphs))
3444 (run-hooks 'org-agenda-finalize-hook)
3445 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3446 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3447 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3448 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3449 (org-agenda-filter-apply org-agenda-category-filter 'category))
3450 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3453 (defun org-agenda-mark-clocking-task ()
3454 "Mark the current clock entry in the agenda if it is present."
3455 (mapc (lambda (o)
3456 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3457 (delete-overlay o)))
3458 (overlays-in (point-min) (point-max)))
3459 (when (marker-buffer org-clock-hd-marker)
3460 (save-excursion
3461 (goto-char (point-min))
3462 (let (s ov)
3463 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3464 (goto-char s)
3465 (when (equal (org-get-at-bol 'org-hd-marker)
3466 org-clock-hd-marker)
3467 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3468 (overlay-put ov 'type 'org-agenda-clocking)
3469 (overlay-put ov 'face 'org-agenda-clocking)
3470 (overlay-put ov 'help-echo
3471 "The clock is running in this item")))))))
3473 (defun org-agenda-fontify-priorities ()
3474 "Make highest priority lines bold, and lowest italic."
3475 (interactive)
3476 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3477 (delete-overlay o)))
3478 (overlays-in (point-min) (point-max)))
3479 (save-excursion
3480 (let ((inhibit-read-only t)
3481 b e p ov h l)
3482 (goto-char (point-min))
3483 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3484 (setq h (or (get-char-property (point) 'org-highest-priority)
3485 org-highest-priority)
3486 l (or (get-char-property (point) 'org-lowest-priority)
3487 org-lowest-priority)
3488 p (string-to-char (match-string 1))
3489 b (match-beginning 0)
3490 e (if (eq org-agenda-fontify-priorities 'cookies)
3491 (match-end 0)
3492 (point-at-eol))
3493 ov (make-overlay b e))
3494 (overlay-put
3495 ov 'face
3496 (cond ((org-face-from-face-or-color
3497 'priority nil
3498 (cdr (assoc p org-priority-faces))))
3499 ((and (listp org-agenda-fontify-priorities)
3500 (org-face-from-face-or-color
3501 'priority nil
3502 (cdr (assoc p org-agenda-fontify-priorities)))))
3503 ((equal p l) 'italic)
3504 ((equal p h) 'bold)))
3505 (overlay-put ov 'org-type 'org-priority)))))
3507 (defun org-agenda-dim-blocked-tasks ()
3508 "Dim currently blocked TODO's in the agenda display."
3509 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3510 (delete-overlay o)))
3511 (overlays-in (point-min) (point-max)))
3512 (save-excursion
3513 (let ((inhibit-read-only t)
3514 (org-depend-tag-blocked nil)
3515 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3516 org-blocked-by-checkboxes
3517 invis1 b e p ov h l)
3518 (goto-char (point-min))
3519 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3520 (and pos (goto-char (1+ pos))))
3521 (setq org-blocked-by-checkboxes nil invis1 invis)
3522 (let ((marker (org-get-at-bol 'org-hd-marker)))
3523 (when (and marker
3524 (with-current-buffer (marker-buffer marker)
3525 (save-excursion (goto-char marker)
3526 (org-entry-blocked-p))))
3527 (if org-blocked-by-checkboxes (setq invis1 nil))
3528 (setq b (if invis1
3529 (max (point-min) (1- (point-at-bol)))
3530 (point-at-bol))
3531 e (point-at-eol)
3532 ov (make-overlay b e))
3533 (if invis1
3534 (overlay-put ov 'invisible t)
3535 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3536 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3538 (defvar org-agenda-skip-function nil
3539 "Function to be called at each match during agenda construction.
3540 If this function returns nil, the current match should not be skipped.
3541 Otherwise, the function must return a position from where the search
3542 should be continued.
3543 This may also be a Lisp form, it will be evaluated.
3544 Never set this variable using `setq' or so, because then it will apply
3545 to all future agenda commands. If you do want a global skipping condition,
3546 use the option `org-agenda-skip-function-global' instead.
3547 The correct usage for `org-agenda-skip-function' is to bind it with
3548 `let' to scope it dynamically into the agenda-constructing command.
3549 A good way to set it is through options in `org-agenda-custom-commands'.")
3551 (defun org-agenda-skip ()
3552 "Throw to `:skip' in places that should be skipped.
3553 Also moves point to the end of the skipped region, so that search can
3554 continue from there."
3555 (let ((p (point-at-bol)) to)
3556 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3557 (get-text-property p :org-archived)
3558 (org-end-of-subtree t)
3559 (throw :skip t))
3560 (and org-agenda-skip-comment-trees
3561 (get-text-property p :org-comment)
3562 (org-end-of-subtree t)
3563 (throw :skip t))
3564 (if (equal (char-after p) ?#) (throw :skip t))
3565 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3566 (org-agenda-skip-eval org-agenda-skip-function)))
3567 (goto-char to)
3568 (throw :skip t))))
3570 (defun org-agenda-skip-eval (form)
3571 "If FORM is a function or a list, call (or eval) is and return result.
3572 `save-excursion' and `save-match-data' are wrapped around the call, so point
3573 and match data are returned to the previous state no matter what these
3574 functions do."
3575 (let (fp)
3576 (and form
3577 (or (setq fp (functionp form))
3578 (consp form))
3579 (save-excursion
3580 (save-match-data
3581 (if fp
3582 (funcall form)
3583 (eval form)))))))
3585 (defvar org-agenda-markers nil
3586 "List of all currently active markers created by `org-agenda'.")
3587 (defvar org-agenda-last-marker-time (org-float-time)
3588 "Creation time of the last agenda marker.")
3590 (defun org-agenda-new-marker (&optional pos)
3591 "Return a new agenda marker.
3592 Org-mode keeps a list of these markers and resets them when they are
3593 no longer in use."
3594 (let ((m (copy-marker (or pos (point)))))
3595 (setq org-agenda-last-marker-time (org-float-time))
3596 (if org-agenda-buffer
3597 (with-current-buffer org-agenda-buffer
3598 (push m org-agenda-markers))
3599 (push m org-agenda-markers))
3602 (defun org-agenda-reset-markers ()
3603 "Reset markers created by `org-agenda'."
3604 (while org-agenda-markers
3605 (move-marker (pop org-agenda-markers) nil)))
3607 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3608 "Save relative positions of markers in region.
3609 This check for agenda markers in all agenda buffers currently active."
3610 (dolist (buf (buffer-list))
3611 (with-current-buffer buf
3612 (when (eq major-mode 'org-agenda-mode)
3613 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3614 org-agenda-markers)))))
3616 ;;; Entry text mode
3618 (defun org-agenda-entry-text-show-here ()
3619 "Add some text from the entry as context to the current line."
3620 (let (m txt o)
3621 (setq m (org-get-at-bol 'org-hd-marker))
3622 (unless (marker-buffer m)
3623 (error "No marker points to an entry here"))
3624 (setq txt (concat "\n" (org-no-properties
3625 (org-agenda-get-some-entry-text
3626 m org-agenda-entry-text-maxlines " > "))))
3627 (when (string-match "\\S-" txt)
3628 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3629 (overlay-put o 'evaporate t)
3630 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3631 (overlay-put o 'after-string txt))))
3633 (defun org-agenda-entry-text-show ()
3634 "Add entry context for all agenda lines."
3635 (interactive)
3636 (save-excursion
3637 (goto-char (point-max))
3638 (beginning-of-line 1)
3639 (while (not (bobp))
3640 (when (org-get-at-bol 'org-hd-marker)
3641 (org-agenda-entry-text-show-here))
3642 (beginning-of-line 0))))
3644 (defun org-agenda-entry-text-hide ()
3645 "Remove any shown entry context."
3646 (delq nil
3647 (mapcar (lambda (o)
3648 (if (eq (overlay-get o 'org-overlay-type)
3649 'agenda-entry-content)
3650 (progn (delete-overlay o) t)))
3651 (overlays-in (point-min) (point-max)))))
3653 (defun org-agenda-get-day-face (date)
3654 "Return the face DATE should be displayed with."
3655 (or (and (functionp org-agenda-day-face-function)
3656 (funcall org-agenda-day-face-function date))
3657 (cond ((org-agenda-todayp date)
3658 'org-agenda-date-today)
3659 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3660 'org-agenda-date-weekend)
3661 (t 'org-agenda-date))))
3663 ;;; Agenda timeline
3665 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3667 (defun org-timeline (&optional dotodo)
3668 "Show a time-sorted view of the entries in the current org file.
3669 Only entries with a time stamp of today or later will be listed. With
3670 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3671 under the current date.
3672 If the buffer contains an active region, only check the region for
3673 dates."
3674 (interactive "P")
3675 (let* ((dopast t)
3676 (org-agenda-show-log-scoped org-agenda-show-log)
3677 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3678 (current-buffer))))
3679 (date (calendar-current-date))
3680 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3681 (end (if (org-region-active-p) (region-end) (point-max)))
3682 (day-numbers (org-get-all-dates
3683 beg end 'no-ranges
3684 t org-agenda-show-log-scoped ; always include today
3685 org-timeline-show-empty-dates))
3686 (org-deadline-warning-days 0)
3687 (org-agenda-only-exact-dates t)
3688 (today (org-today))
3689 (past t)
3690 args
3691 s e rtn d emptyp)
3692 (setq org-agenda-redo-command
3693 (list 'progn
3694 (list 'org-switch-to-buffer-other-window (current-buffer))
3695 (list 'org-timeline (list 'quote dotodo))))
3696 (if (not dopast)
3697 ;; Remove past dates from the list of dates.
3698 (setq day-numbers (delq nil (mapcar (lambda(x)
3699 (if (>= x today) x nil))
3700 day-numbers))))
3701 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3702 (org-compile-prefix-format 'timeline)
3703 (org-set-sorting-strategy 'timeline)
3704 (if org-agenda-show-log-scoped (push :closed args))
3705 (push :timestamp args)
3706 (push :deadline args)
3707 (push :scheduled args)
3708 (push :sexp args)
3709 (if dotodo (push :todo args))
3710 (insert "Timeline of file " entry "\n")
3711 (add-text-properties (point-min) (point)
3712 (list 'face 'org-agenda-structure))
3713 (org-agenda-mark-header-line (point-min))
3714 (while (setq d (pop day-numbers))
3715 (if (and (listp d) (eq (car d) :omitted))
3716 (progn
3717 (setq s (point))
3718 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3719 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3720 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3721 (if (and (>= d today)
3722 dopast
3723 past)
3724 (progn
3725 (setq past nil)
3726 (insert (make-string 79 ?-) "\n")))
3727 (setq date (calendar-gregorian-from-absolute d))
3728 (setq s (point))
3729 (setq rtn (and (not emptyp)
3730 (apply 'org-agenda-get-day-entries entry
3731 date args)))
3732 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3733 (progn
3734 (insert
3735 (if (stringp org-agenda-format-date)
3736 (format-time-string org-agenda-format-date
3737 (org-time-from-absolute date))
3738 (funcall org-agenda-format-date date))
3739 "\n")
3740 (put-text-property s (1- (point)) 'face
3741 (org-agenda-get-day-face date))
3742 (put-text-property s (1- (point)) 'org-date-line t)
3743 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3744 (if (equal d today)
3745 (put-text-property s (1- (point)) 'org-today t))
3746 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3747 (put-text-property s (1- (point)) 'day d)))))
3748 (goto-char (point-min))
3749 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3750 (point-min)))
3751 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3752 (org-agenda-finalize)
3753 (setq buffer-read-only t)))
3755 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3756 "Return a list of all relevant day numbers from BEG to END buffer positions.
3757 If NO-RANGES is non-nil, include only the start and end dates of a range,
3758 not every single day in the range. If FORCE-TODAY is non-nil, make
3759 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3760 inactive time stamps (those in square brackets) are included.
3761 When EMPTY is non-nil, also include days without any entries."
3762 (let ((re (concat
3763 (if pre-re pre-re "")
3764 (if inactive org-ts-regexp-both org-ts-regexp)))
3765 dates dates1 date day day1 day2 ts1 ts2 pos)
3766 (if force-today
3767 (setq dates (list (org-today))))
3768 (save-excursion
3769 (goto-char beg)
3770 (while (re-search-forward re end t)
3771 (setq day (time-to-days (org-time-string-to-time
3772 (substring (match-string 1) 0 10)
3773 (current-buffer) (match-beginning 0))))
3774 (or (memq day dates) (push day dates)))
3775 (unless no-ranges
3776 (goto-char beg)
3777 (while (re-search-forward org-tr-regexp end t)
3778 (setq pos (match-beginning 0))
3779 (setq ts1 (substring (match-string 1) 0 10)
3780 ts2 (substring (match-string 2) 0 10)
3781 day1 (time-to-days (org-time-string-to-time
3782 ts1 (current-buffer) pos))
3783 day2 (time-to-days (org-time-string-to-time
3784 ts2 (current-buffer) pos)))
3785 (while (< (setq day1 (1+ day1)) day2)
3786 (or (memq day1 dates) (push day1 dates)))))
3787 (setq dates (sort dates '<))
3788 (when empty
3789 (while (setq day (pop dates))
3790 (setq day2 (car dates))
3791 (push day dates1)
3792 (when (and day2 empty)
3793 (if (or (eq empty t)
3794 (and (numberp empty) (<= (- day2 day) empty)))
3795 (while (< (setq day (1+ day)) day2)
3796 (push (list day) dates1))
3797 (push (cons :omitted (- day2 day)) dates1))))
3798 (setq dates (nreverse dates1)))
3799 dates)))
3801 ;;; Agenda Daily/Weekly
3803 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3804 "Start day for the agenda view.
3805 Custom commands can set this variable in the options section.")
3806 (defvar org-starting-day nil) ; local variable in the agenda buffer
3807 (defvar org-arg-loc nil) ; local variable
3809 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3810 "List of types searched for when creating the daily/weekly agenda.
3811 This variable is a list of symbols that controls the types of
3812 items that appear in the daily/weekly agenda. Allowed symbols in this
3813 list are are
3815 :timestamp List items containing a date stamp or date range matching
3816 the selected date. This includes sexp entries in
3817 angular brackets.
3819 :sexp List entries resulting from plain diary-like sexps.
3821 :deadline List deadline due on that date. When the date is today,
3822 also list any deadlines past due, or due within
3823 `org-deadline-warning-days'. `:deadline' must appear before
3824 `:scheduled' if the setting of
3825 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3826 any effect.
3828 :scheduled List all items which are scheduled for the given date.
3829 The diary for *today* also contains items which were
3830 scheduled earlier and are not yet marked DONE.
3832 By default, all four types are turned on.
3834 Never set this variable globally using `setq', because then it
3835 will apply to all future agenda commands. Instead, bind it with
3836 `let' to scope it dynamically into the agenda-constructing
3837 command. A good way to set it is through options in
3838 `org-agenda-custom-commands'. For a more flexible (though
3839 somewhat less efficient) way of determining what is included in
3840 the daily/weekly agenda, see `org-agenda-skip-function'.")
3842 (defvar org-agenda-buffer-tmp-name nil)
3843 ;;;###autoload
3844 (defun org-agenda-list (&optional arg start-day span)
3845 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3846 The view will be for the current day or week, but from the overview buffer
3847 you will be able to go to other days/weeks.
3849 With a numeric prefix argument in an interactive call, the agenda will
3850 span ARG days. Lisp programs should instead specify SPAN to change
3851 the number of days. SPAN defaults to `org-agenda-span'.
3853 START-DAY defaults to TODAY, or to the most recent match for the weekday
3854 given in `org-agenda-start-on-weekday'."
3855 (interactive "P")
3856 (if org-agenda-overriding-arguments
3857 (setq arg (car org-agenda-overriding-arguments)
3858 start-day (nth 1 org-agenda-overriding-arguments)
3859 span (nth 2 org-agenda-overriding-arguments)))
3860 (if (and (integerp arg) (> arg 0))
3861 (setq span arg arg nil))
3862 (catch 'exit
3863 (setq org-agenda-buffer-name
3864 (or org-agenda-buffer-tmp-name
3865 (if org-agenda-sticky
3866 (cond ((and org-keys (stringp org-match))
3867 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3868 (org-keys
3869 (format "*Org Agenda(%s)*" org-keys))
3870 (t "*Org Agenda(a)*")))
3871 org-agenda-buffer-name))
3872 (org-agenda-prepare "Day/Week")
3873 (setq start-day (or start-day org-agenda-start-day))
3874 (if (stringp start-day)
3875 ;; Convert to an absolute day number
3876 (setq start-day (time-to-days (org-read-date nil t start-day))))
3877 (org-compile-prefix-format 'agenda)
3878 (org-set-sorting-strategy 'agenda)
3879 (let* ((span (org-agenda-ndays-to-span
3880 (or span org-agenda-ndays org-agenda-span)))
3881 (today (org-today))
3882 (sd (or start-day today))
3883 (ndays (org-agenda-span-to-ndays span sd))
3884 (org-agenda-start-on-weekday
3885 (if (eq ndays 7)
3886 org-agenda-start-on-weekday))
3887 (thefiles (org-agenda-files nil 'ifmode))
3888 (files thefiles)
3889 (start (if (or (null org-agenda-start-on-weekday)
3890 (< ndays 7))
3892 (let* ((nt (calendar-day-of-week
3893 (calendar-gregorian-from-absolute sd)))
3894 (n1 org-agenda-start-on-weekday)
3895 (d (- nt n1)))
3896 (- sd (+ (if (< d 0) 7 0) d)))))
3897 (day-numbers (list start))
3898 (day-cnt 0)
3899 (inhibit-redisplay (not debug-on-error))
3900 (org-agenda-show-log-scoped org-agenda-show-log)
3901 s e rtn rtnall file date d start-pos end-pos todayp
3902 clocktable-start clocktable-end filter)
3903 (setq org-agenda-redo-command
3904 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3905 (dotimes (n (1- ndays))
3906 (push (1+ (car day-numbers)) day-numbers))
3907 (setq day-numbers (nreverse day-numbers))
3908 (setq clocktable-start (car day-numbers)
3909 clocktable-end (1+ (or (org-last day-numbers) 0)))
3910 (org-set-local 'org-starting-day (car day-numbers))
3911 (org-set-local 'org-arg-loc arg)
3912 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3913 (unless org-agenda-compact-blocks
3914 (let* ((d1 (car day-numbers))
3915 (d2 (org-last day-numbers))
3916 (w1 (org-days-to-iso-week d1))
3917 (w2 (org-days-to-iso-week d2)))
3918 (setq s (point))
3919 (if org-agenda-overriding-header
3920 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3921 nil 'face 'org-agenda-structure) "\n")
3922 (insert (org-agenda-span-name span)
3923 "-agenda"
3924 (if (< (- d2 d1) 350)
3925 (if (= w1 w2)
3926 (format " (W%02d)" w1)
3927 (format " (W%02d-W%02d)" w1 w2))
3929 ":\n")))
3930 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3931 'org-date-line t))
3932 (org-agenda-mark-header-line s))
3933 (while (setq d (pop day-numbers))
3934 (setq date (calendar-gregorian-from-absolute d)
3935 s (point))
3936 (if (or (setq todayp (= d today))
3937 (and (not start-pos) (= d sd)))
3938 (setq start-pos (point))
3939 (if (and start-pos (not end-pos))
3940 (setq end-pos (point))))
3941 (setq files thefiles
3942 rtnall nil)
3943 (while (setq file (pop files))
3944 (catch 'nextfile
3945 (org-check-agenda-file file)
3946 (let ((org-agenda-entry-types org-agenda-entry-types))
3947 (unless org-agenda-include-deadlines
3948 (setq org-agenda-entry-types
3949 (delq :deadline org-agenda-entry-types)))
3950 (cond
3951 ((memq org-agenda-show-log-scoped '(only clockcheck))
3952 (setq rtn (org-agenda-get-day-entries
3953 file date :closed)))
3954 (org-agenda-show-log-scoped
3955 (setq rtn (apply 'org-agenda-get-day-entries
3956 file date
3957 (append '(:closed) org-agenda-entry-types))))
3959 (setq rtn (apply 'org-agenda-get-day-entries
3960 file date
3961 org-agenda-entry-types)))))
3962 (setq rtnall (append rtnall rtn)))) ;; all entries
3963 (if org-agenda-include-diary
3964 (let ((org-agenda-search-headline-for-time t))
3965 (require 'diary-lib)
3966 (setq rtn (org-get-entries-from-diary date))
3967 (setq rtnall (append rtnall rtn))))
3968 (if (or rtnall org-agenda-show-all-dates)
3969 (progn
3970 (setq day-cnt (1+ day-cnt))
3971 (insert
3972 (if (stringp org-agenda-format-date)
3973 (format-time-string org-agenda-format-date
3974 (org-time-from-absolute date))
3975 (funcall org-agenda-format-date date))
3976 "\n")
3977 (put-text-property s (1- (point)) 'face
3978 (org-agenda-get-day-face date))
3979 (put-text-property s (1- (point)) 'org-date-line t)
3980 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3981 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3982 (when todayp
3983 (put-text-property s (1- (point)) 'org-today t))
3984 (setq rtnall
3985 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3986 (if rtnall (insert ;; all entries
3987 (org-agenda-finalize-entries rtnall)
3988 "\n"))
3989 (put-text-property s (1- (point)) 'day d)
3990 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3991 (when (and org-agenda-clockreport-mode clocktable-start)
3992 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3993 ;; the above line is to ensure the restricted range!
3994 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3995 tbl)
3996 (setq p (org-plist-delete p :block))
3997 (setq p (plist-put p :tstart clocktable-start))
3998 (setq p (plist-put p :tend clocktable-end))
3999 (setq p (plist-put p :scope 'agenda))
4000 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4001 (setq filter (or org-agenda-tag-filter-while-redo
4002 (get 'org-agenda-tag-filter :preset-filter))))
4003 (setq p (plist-put p :tags (mapconcat (lambda (x)
4004 (if (string-match "[<>=]" x)
4007 filter ""))))
4008 (setq tbl (apply 'org-get-clocktable p))
4009 (insert tbl)))
4010 (goto-char (point-min))
4011 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4012 (unless (and (pos-visible-in-window-p (point-min))
4013 (pos-visible-in-window-p (point-max)))
4014 (goto-char (1- (point-max)))
4015 (recenter -1)
4016 (if (not (pos-visible-in-window-p (or start-pos 1)))
4017 (progn
4018 (goto-char (or start-pos 1))
4019 (recenter 1))))
4020 (goto-char (or start-pos 1))
4021 (add-text-properties (point-min) (point-max)
4022 `(org-agenda-type agenda
4023 org-last-args (,arg ,start-day ,span)
4024 org-redo-cmd ,org-agenda-redo-command
4025 org-serie-cmd ,org-cmd))
4026 (if (eq org-agenda-show-log-scoped 'clockcheck)
4027 (org-agenda-show-clocking-issues))
4028 (org-agenda-finalize)
4029 (setq buffer-read-only t)
4030 (message ""))))
4032 (defun org-agenda-ndays-to-span (n)
4033 "Return a span symbol for a span of N days, or N if none matches."
4034 (cond ((symbolp n) n)
4035 ((= n 1) 'day)
4036 ((= n 7) 'week)
4037 (t n)))
4039 (defun org-agenda-span-to-ndays (span &optional start-day)
4040 "Return ndays from SPAN, possibly starting at START-DAY."
4041 (cond ((numberp span) span)
4042 ((eq span 'day) 1)
4043 ((eq span 'week) 7)
4044 ((eq span 'month)
4045 (let ((date (calendar-gregorian-from-absolute start-day)))
4046 (calendar-last-day-of-month (car date) (caddr date))))
4047 ((eq span 'year)
4048 (let ((date (calendar-gregorian-from-absolute start-day)))
4049 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4051 (defun org-agenda-span-name (span)
4052 "Return a SPAN name."
4053 (if (null span)
4055 (if (symbolp span)
4056 (capitalize (symbol-name span))
4057 (format "%d days" span))))
4059 ;;; Agenda word search
4061 (defvar org-agenda-search-history nil)
4063 (defvar org-search-syntax-table nil
4064 "Special syntax table for org-mode search.
4065 In this table, we have single quotes not as word constituents, to
4066 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4068 (defvar org-mode-syntax-table) ; From org.el
4069 (defun org-search-syntax-table ()
4070 (unless org-search-syntax-table
4071 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4072 (modify-syntax-entry ?' "." org-search-syntax-table)
4073 (modify-syntax-entry ?` "." org-search-syntax-table))
4074 org-search-syntax-table)
4076 (defvar org-agenda-last-search-view-search-was-boolean nil)
4078 ;;;###autoload
4079 (defun org-search-view (&optional todo-only string edit-at)
4080 "Show all entries that contain a phrase or words or regular expressions.
4082 With optional prefix argument TODO-ONLY, only consider entries that are
4083 TODO entries. The argument STRING can be used to pass a default search
4084 string into this function. If EDIT-AT is non-nil, it means that the
4085 user should get a chance to edit this string, with cursor at position
4086 EDIT-AT.
4088 The search string can be viewed either as a phrase that should be found as
4089 is, or it can be broken into a number of snippets, each of which must match
4090 in a Boolean way to select an entry. The default depends on the variable
4091 `org-agenda-search-view-always-boolean'.
4092 Even if this is turned off (the default) you can always switch to
4093 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4095 The default is a direct search of the whole phrase, where each space in
4096 the search string can expand to an arbitrary amount of whitespace,
4097 including newlines.
4099 If using a Boolean search, the search string is split on whitespace and
4100 each snippet is searched separately, with logical AND to select an entry.
4101 Words prefixed with a minus must *not* occur in the entry. Words without
4102 a prefix or prefixed with a plus must occur in the entry. Matching is
4103 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4104 match whole words, not parts of a word) if
4105 `org-agenda-search-view-force-full-words' is set (default is nil).
4107 Boolean search snippets enclosed by curly braces are interpreted as
4108 regular expressions that must or (when preceded with \"-\") must not
4109 match in the entry. Snippets enclosed into double quotes will be taken
4110 as a whole, to include whitespace.
4112 - If the search string starts with an asterisk, search only in headlines.
4113 - If (possibly after the leading star) the search string starts with an
4114 exclamation mark, this also means to look at TODO entries only, an effect
4115 that can also be achieved with a prefix argument.
4116 - If (possibly after star and exclamation mark) the search string starts
4117 with a colon, this will mean that the (non-regexp) snippets of the
4118 Boolean search must match as full words.
4120 This command searches the agenda files, and in addition the files listed
4121 in `org-agenda-text-search-extra-files'."
4122 (interactive "P")
4123 (if org-agenda-overriding-arguments
4124 (setq todo-only (car org-agenda-overriding-arguments)
4125 string (nth 1 org-agenda-overriding-arguments)
4126 edit-at (nth 2 org-agenda-overriding-arguments)))
4127 (let* ((props (list 'face nil
4128 'done-face 'org-agenda-done
4129 'org-not-done-regexp org-not-done-regexp
4130 'org-todo-regexp org-todo-regexp
4131 'org-complex-heading-regexp org-complex-heading-regexp
4132 'mouse-face 'highlight
4133 'help-echo (format "mouse-2 or RET jump to location")))
4134 (full-words org-agenda-search-view-force-full-words)
4135 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4136 regexp rtn rtnall files file pos
4137 marker category category-pos tags c neg re boolean
4138 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4139 (unless (and (not edit-at)
4140 (stringp string)
4141 (string-match "\\S-" string))
4142 (setq string (read-string
4143 (if org-agenda-search-view-always-boolean
4144 "[+-]Word/{Regexp} ...: "
4145 "Phrase or [+-]Word/{Regexp} ...: ")
4146 (cond
4147 ((integerp edit-at) (cons string edit-at))
4148 (edit-at string))
4149 'org-agenda-search-history)))
4150 (catch 'exit
4151 (if org-agenda-sticky
4152 (setq org-agenda-buffer-name
4153 (if (stringp string)
4154 (format "*Org Agenda(%s:%s)*"
4155 (or org-keys (or (and todo-only "S") "s")) string)
4156 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4157 (org-agenda-prepare "SEARCH")
4158 (org-compile-prefix-format 'search)
4159 (org-set-sorting-strategy 'search)
4160 (setq org-agenda-redo-command
4161 (list 'org-search-view (if todo-only t nil)
4162 (list 'if 'current-prefix-arg nil string)))
4163 (setq org-agenda-query-string string)
4164 (if (equal (string-to-char string) ?*)
4165 (setq hdl-only t
4166 words (substring string 1))
4167 (setq words string))
4168 (when (equal (string-to-char words) ?!)
4169 (setq todo-only t
4170 words (substring words 1)))
4171 (when (equal (string-to-char words) ?:)
4172 (setq full-words t
4173 words (substring words 1)))
4174 (if (or org-agenda-search-view-always-boolean
4175 (member (string-to-char words) '(?- ?+ ?\{)))
4176 (setq boolean t))
4177 (setq words (org-split-string words))
4178 (let (www w)
4179 (while (setq w (pop words))
4180 (while (and (string-match "\\\\\\'" w) words)
4181 (setq w (concat (substring w 0 -1) " " (pop words))))
4182 (push w www))
4183 (setq words (nreverse www) www nil)
4184 (while (setq w (pop words))
4185 (when (and (string-match "\\`[-+]?{" w)
4186 (not (string-match "}\\'" w)))
4187 (while (and words (not (string-match "}\\'" (car words))))
4188 (setq w (concat w " " (pop words))))
4189 (setq w (concat w " " (pop words))))
4190 (push w www))
4191 (setq words (nreverse www)))
4192 (setq org-agenda-last-search-view-search-was-boolean boolean)
4193 (when boolean
4194 (let (wds w)
4195 (while (setq w (pop words))
4196 (if (or (equal (substring w 0 1) "\"")
4197 (and (> (length w) 1)
4198 (member (substring w 0 1) '("+" "-"))
4199 (equal (substring w 1 2) "\"")))
4200 (while (and words (not (equal (substring w -1) "\"")))
4201 (setq w (concat w " " (pop words)))))
4202 (and (string-match "\\`\\([-+]?\\)\"" w)
4203 (setq w (replace-match "\\1" nil nil w)))
4204 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4205 (push w wds))
4206 (setq words (nreverse wds))))
4207 (if boolean
4208 (mapc (lambda (w)
4209 (setq c (string-to-char w))
4210 (if (equal c ?-)
4211 (setq neg t w (substring w 1))
4212 (if (equal c ?+)
4213 (setq neg nil w (substring w 1))
4214 (setq neg nil)))
4215 (if (string-match "\\`{.*}\\'" w)
4216 (setq re (substring w 1 -1))
4217 (if full-words
4218 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4219 (setq re (regexp-quote (downcase w)))))
4220 (if neg (push re regexps-) (push re regexps+)))
4221 words)
4222 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4223 regexps+))
4224 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4225 (if (not regexps+)
4226 (setq regexp org-outline-regexp-bol)
4227 (setq regexp (pop regexps+))
4228 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4229 regexp))))
4230 (setq files (org-agenda-files nil 'ifmode))
4231 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4232 (pop org-agenda-text-search-extra-files)
4233 (setq files (org-add-archive-files files)))
4234 (setq files (append files org-agenda-text-search-extra-files)
4235 rtnall nil)
4236 (while (setq file (pop files))
4237 (setq ee nil)
4238 (catch 'nextfile
4239 (org-check-agenda-file file)
4240 (setq buffer (if (file-exists-p file)
4241 (org-get-agenda-file-buffer file)
4242 (error "No such file %s" file)))
4243 (if (not buffer)
4244 ;; If file does not exist, make sure an error message is sent
4245 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4246 file))))
4247 (with-current-buffer buffer
4248 (with-syntax-table (org-search-syntax-table)
4249 (unless (derived-mode-p 'org-mode)
4250 (error "Agenda file %s is not in `org-mode'" file))
4251 (let ((case-fold-search t))
4252 (save-excursion
4253 (save-restriction
4254 (if org-agenda-restrict
4255 (narrow-to-region org-agenda-restrict-begin
4256 org-agenda-restrict-end)
4257 (widen))
4258 (goto-char (point-min))
4259 (unless (or (org-at-heading-p)
4260 (outline-next-heading))
4261 (throw 'nextfile t))
4262 (goto-char (max (point-min) (1- (point))))
4263 (while (re-search-forward regexp nil t)
4264 (org-back-to-heading t)
4265 (skip-chars-forward "* ")
4266 (setq beg (point-at-bol)
4267 beg1 (point)
4268 end (progn (outline-next-heading) (point)))
4269 (catch :skip
4270 (goto-char beg)
4271 (org-agenda-skip)
4272 (setq str (buffer-substring-no-properties
4273 (point-at-bol)
4274 (if hdl-only (point-at-eol) end)))
4275 (mapc (lambda (wr) (when (string-match wr str)
4276 (goto-char (1- end))
4277 (throw :skip t)))
4278 regexps-)
4279 (mapc (lambda (wr) (unless (string-match wr str)
4280 (goto-char (1- end))
4281 (throw :skip t)))
4282 (if todo-only
4283 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4284 regexps+)
4285 regexps+))
4286 (goto-char beg)
4287 (setq marker (org-agenda-new-marker (point))
4288 category (org-get-category)
4289 category-pos (get-text-property (point) 'org-category-position)
4290 tags (org-get-tags-at (point))
4291 txt (org-agenda-format-item
4293 (buffer-substring-no-properties
4294 beg1 (point-at-eol))
4295 category tags))
4296 (org-add-props txt props
4297 'org-marker marker 'org-hd-marker marker
4298 'org-todo-regexp org-todo-regexp
4299 'org-complex-heading-regexp org-complex-heading-regexp
4300 'priority 1000 'org-category category
4301 'org-category-position category-pos
4302 'type "search")
4303 (push txt ee)
4304 (goto-char (1- end))))))))))
4305 (setq rtn (nreverse ee))
4306 (setq rtnall (append rtnall rtn)))
4307 (if org-agenda-overriding-header
4308 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4309 nil 'face 'org-agenda-structure) "\n")
4310 (insert "Search words: ")
4311 (add-text-properties (point-min) (1- (point))
4312 (list 'face 'org-agenda-structure))
4313 (setq pos (point))
4314 (insert string "\n")
4315 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4316 (setq pos (point))
4317 (unless org-agenda-multi
4318 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4319 (add-text-properties pos (1- (point))
4320 (list 'face 'org-agenda-structure))))
4321 (org-agenda-mark-header-line (point-min))
4322 (when rtnall
4323 (insert (org-agenda-finalize-entries rtnall) "\n"))
4324 (goto-char (point-min))
4325 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4326 (add-text-properties (point-min) (point-max)
4327 `(org-agenda-type search
4328 org-last-args (,todo-only ,string ,edit-at)
4329 org-redo-cmd ,org-agenda-redo-command
4330 org-serie-cmd ,org-cmd))
4331 (org-agenda-finalize)
4332 (setq buffer-read-only t))))
4334 ;;; Agenda TODO list
4336 (defvar org-select-this-todo-keyword nil)
4337 (defvar org-last-arg nil)
4339 ;;;###autoload
4340 (defun org-todo-list (&optional arg)
4341 "Show all (not done) TODO entries from all agenda file in a single list.
4342 The prefix arg can be used to select a specific TODO keyword and limit
4343 the list to these. When using \\[universal-argument], you will be prompted
4344 for a keyword. A numeric prefix directly selects the Nth keyword in
4345 `org-todo-keywords-1'."
4346 (interactive "P")
4347 (if org-agenda-overriding-arguments
4348 (setq arg org-agenda-overriding-arguments))
4349 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4350 (let* ((today (org-today))
4351 (date (calendar-gregorian-from-absolute today))
4352 (kwds org-todo-keywords-for-agenda)
4353 (completion-ignore-case t)
4354 (org-select-this-todo-keyword
4355 (if (stringp arg) arg
4356 (and arg (integerp arg) (> arg 0)
4357 (nth (1- arg) kwds))))
4358 rtn rtnall files file pos)
4359 (when (equal arg '(4))
4360 (setq org-select-this-todo-keyword
4361 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4362 (mapcar 'list kwds) nil nil)))
4363 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4364 (catch 'exit
4365 (if org-agenda-sticky
4366 (setq org-agenda-buffer-name
4367 (if (stringp org-select-this-todo-keyword)
4368 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4369 org-select-this-todo-keyword)
4370 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4371 (org-agenda-prepare "TODO")
4372 (org-compile-prefix-format 'todo)
4373 (org-set-sorting-strategy 'todo)
4374 (setq org-agenda-redo-command
4375 `(org-todo-list (or current-prefix-arg (quote ,arg))))
4376 (setq files (org-agenda-files nil 'ifmode)
4377 rtnall nil)
4378 (while (setq file (pop files))
4379 (catch 'nextfile
4380 (org-check-agenda-file file)
4381 (setq rtn (org-agenda-get-day-entries file date :todo))
4382 (setq rtnall (append rtnall rtn))))
4383 (if org-agenda-overriding-header
4384 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4385 nil 'face 'org-agenda-structure) "\n")
4386 (insert "Global list of TODO items of type: ")
4387 (add-text-properties (point-min) (1- (point))
4388 (list 'face 'org-agenda-structure
4389 'short-heading
4390 (concat "ToDo: "
4391 (or org-select-this-todo-keyword "ALL"))))
4392 (org-agenda-mark-header-line (point-min))
4393 (setq pos (point))
4394 (insert (or org-select-this-todo-keyword "ALL") "\n")
4395 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4396 (setq pos (point))
4397 (unless org-agenda-multi
4398 (insert "Available with `N r': (0)[ALL]")
4399 (let ((n 0) s)
4400 (mapc (lambda (x)
4401 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4402 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4403 (insert "\n "))
4404 (insert " " s))
4405 kwds))
4406 (insert "\n"))
4407 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4408 (org-agenda-mark-header-line (point-min))
4409 (when rtnall
4410 (insert (org-agenda-finalize-entries rtnall) "\n"))
4411 (goto-char (point-min))
4412 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4413 (add-text-properties (point-min) (point-max)
4414 `(org-agenda-type todo
4415 org-last-args ,arg
4416 org-redo-cmd ,org-agenda-redo-command
4417 org-serie-cmd ,org-cmd))
4418 (org-agenda-finalize)
4419 (setq buffer-read-only t))))
4421 ;;; Agenda tags match
4423 ;;;###autoload
4424 (defun org-tags-view (&optional todo-only match)
4425 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4426 The prefix arg TODO-ONLY limits the search to TODO entries."
4427 (interactive "P")
4428 (if org-agenda-overriding-arguments
4429 (setq todo-only (car org-agenda-overriding-arguments)
4430 match (nth 1 org-agenda-overriding-arguments)))
4431 (let* ((org-tags-match-list-sublevels
4432 org-tags-match-list-sublevels)
4433 (completion-ignore-case t)
4434 rtn rtnall files file pos matcher
4435 buffer)
4436 (when (and (stringp match) (not (string-match "\\S-" match)))
4437 (setq match nil))
4438 (setq matcher (org-make-tags-matcher match)
4439 match (car matcher) matcher (cdr matcher))
4440 (catch 'exit
4441 (if org-agenda-sticky
4442 (setq org-agenda-buffer-name
4443 (if (stringp match)
4444 (format "*Org Agenda(%s:%s)*"
4445 (or org-keys (or (and todo-only "M") "m")) match)
4446 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4447 (org-agenda-prepare (concat "TAGS " match))
4448 (org-compile-prefix-format 'tags)
4449 (org-set-sorting-strategy 'tags)
4450 (setq org-agenda-query-string match)
4451 (setq org-agenda-redo-command
4452 (list 'org-tags-view `(quote ,todo-only)
4453 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4454 (setq files (org-agenda-files nil 'ifmode)
4455 rtnall nil)
4456 (while (setq file (pop files))
4457 (catch 'nextfile
4458 (org-check-agenda-file file)
4459 (setq buffer (if (file-exists-p file)
4460 (org-get-agenda-file-buffer file)
4461 (error "No such file %s" file)))
4462 (if (not buffer)
4463 ;; If file does not exist, error message to agenda
4464 (setq rtn (list
4465 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4466 rtnall (append rtnall rtn))
4467 (with-current-buffer buffer
4468 (unless (derived-mode-p 'org-mode)
4469 (error "Agenda file %s is not in `org-mode'" file))
4470 (save-excursion
4471 (save-restriction
4472 (if org-agenda-restrict
4473 (narrow-to-region org-agenda-restrict-begin
4474 org-agenda-restrict-end)
4475 (widen))
4476 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4477 (setq rtnall (append rtnall rtn))))))))
4478 (if org-agenda-overriding-header
4479 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4480 nil 'face 'org-agenda-structure) "\n")
4481 (insert "Headlines with TAGS match: ")
4482 (add-text-properties (point-min) (1- (point))
4483 (list 'face 'org-agenda-structure
4484 'short-heading
4485 (concat "Match: " match)))
4486 (setq pos (point))
4487 (insert match "\n")
4488 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4489 (setq pos (point))
4490 (unless org-agenda-multi
4491 (insert "Press `C-u r' to search again with new search string\n"))
4492 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4493 (org-agenda-mark-header-line (point-min))
4494 (when rtnall
4495 (insert (org-agenda-finalize-entries rtnall) "\n"))
4496 (goto-char (point-min))
4497 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4498 (add-text-properties (point-min) (point-max)
4499 `(org-agenda-type tags
4500 org-last-args (,todo-only ,match)
4501 org-redo-cmd ,org-agenda-redo-command
4502 org-serie-cmd ,org-cmd))
4503 (org-agenda-finalize)
4504 (setq buffer-read-only t))))
4506 ;;; Agenda Finding stuck projects
4508 (defvar org-agenda-skip-regexp nil
4509 "Regular expression used in skipping subtrees for the agenda.
4510 This is basically a temporary global variable that can be set and then
4511 used by user-defined selections using `org-agenda-skip-function'.")
4513 (defvar org-agenda-overriding-header nil
4514 "When set during agenda, todo and tags searches it replaces the header.
4515 This variable should not be set directly, but custom commands can bind it
4516 in the options section.")
4518 (defun org-agenda-skip-entry-when-regexp-matches ()
4519 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4520 If yes, it returns the end position of this entry, causing agenda commands
4521 to skip the entry but continuing the search in the subtree. This is a
4522 function that can be put into `org-agenda-skip-function' for the duration
4523 of a command."
4524 (let ((end (save-excursion (org-end-of-subtree t)))
4525 skip)
4526 (save-excursion
4527 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4528 (and skip end)))
4530 (defun org-agenda-skip-subtree-when-regexp-matches ()
4531 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4532 If yes, it returns the end position of this tree, causing agenda commands
4533 to skip this subtree. This is a function that can be put into
4534 `org-agenda-skip-function' for the duration of a command."
4535 (let ((end (save-excursion (org-end-of-subtree t)))
4536 skip)
4537 (save-excursion
4538 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4539 (and skip end)))
4541 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4542 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4543 If yes, it returns the end position of the current entry (NOT the tree),
4544 causing agenda commands to skip the entry but continuing the search in
4545 the subtree. This is a function that can be put into
4546 `org-agenda-skip-function' for the duration of a command. An important
4547 use of this function is for the stuck project list."
4548 (let ((end (save-excursion (org-end-of-subtree t)))
4549 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4550 skip)
4551 (save-excursion
4552 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4553 (and skip entry-end)))
4555 (defun org-agenda-skip-entry-if (&rest conditions)
4556 "Skip entry if any of CONDITIONS is true.
4557 See `org-agenda-skip-if' for details."
4558 (org-agenda-skip-if nil conditions))
4560 (defun org-agenda-skip-subtree-if (&rest conditions)
4561 "Skip entry if any of CONDITIONS is true.
4562 See `org-agenda-skip-if' for details."
4563 (org-agenda-skip-if t conditions))
4565 (defun org-agenda-skip-if (subtree conditions)
4566 "Checks current entity for CONDITIONS.
4567 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4568 the entry (i.e. the text before the next heading) is checked.
4570 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4571 from different tests. Valid conditions are:
4573 scheduled Check if there is a scheduled cookie
4574 notscheduled Check if there is no scheduled cookie
4575 deadline Check if there is a deadline
4576 notdeadline Check if there is no deadline
4577 timestamp Check if there is a timestamp (also deadline or scheduled)
4578 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4579 regexp Check if regexp matches
4580 notregexp Check if regexp does not match.
4581 todo Check if TODO keyword matches
4582 nottodo Check if TODO keyword does not match
4584 The regexp is taken from the conditions list, it must come right after
4585 the `regexp' or `notregexp' element.
4587 `todo' and `nottodo' accept as an argument a list of todo
4588 keywords, which may include \"*\" to match any todo keyword.
4590 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4592 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4594 Instead of a list, a keyword class may be given. For example:
4596 (org-agenda-skip-entry-if 'nottodo 'done)
4598 would skip entries that haven't been marked with any of \"DONE\"
4599 keywords. Possible classes are: `todo', `done', `any'.
4601 If any of these conditions is met, this function returns the end point of
4602 the entity, causing the search to continue from there. This is a function
4603 that can be put into `org-agenda-skip-function' for the duration of a command."
4604 (let (beg end m)
4605 (org-back-to-heading t)
4606 (setq beg (point)
4607 end (if subtree
4608 (progn (org-end-of-subtree t) (point))
4609 (progn (outline-next-heading) (1- (point)))))
4610 (goto-char beg)
4611 (and
4613 (and (memq 'scheduled conditions)
4614 (re-search-forward org-scheduled-time-regexp end t))
4615 (and (memq 'notscheduled conditions)
4616 (not (re-search-forward org-scheduled-time-regexp end t)))
4617 (and (memq 'deadline conditions)
4618 (re-search-forward org-deadline-time-regexp end t))
4619 (and (memq 'notdeadline conditions)
4620 (not (re-search-forward org-deadline-time-regexp end t)))
4621 (and (memq 'timestamp conditions)
4622 (re-search-forward org-ts-regexp end t))
4623 (and (memq 'nottimestamp conditions)
4624 (not (re-search-forward org-ts-regexp end t)))
4625 (and (setq m (memq 'regexp conditions))
4626 (stringp (nth 1 m))
4627 (re-search-forward (nth 1 m) end t))
4628 (and (setq m (memq 'notregexp conditions))
4629 (stringp (nth 1 m))
4630 (not (re-search-forward (nth 1 m) end t)))
4631 (and (or
4632 (setq m (memq 'nottodo conditions))
4633 (setq m (memq 'todo-unblocked conditions))
4634 (setq m (memq 'nottodo-unblocked conditions))
4635 (setq m (memq 'todo conditions)))
4636 (org-agenda-skip-if-todo m end)))
4637 end)))
4639 (defun org-agenda-skip-if-todo (args end)
4640 "Helper function for `org-agenda-skip-if', do not use it directly.
4641 ARGS is a list with first element either `todo', `nottodo',
4642 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4643 a list of TODO keywords, or a state symbol `todo' or `done' or
4644 `any'."
4645 (let ((kw (car args))
4646 (arg (cadr args))
4647 todo-wds todo-re)
4648 (setq todo-wds
4649 (org-uniquify
4650 (cond
4651 ((listp arg) ;; list of keywords
4652 (if (member "*" arg)
4653 (mapcar 'substring-no-properties org-todo-keywords-1)
4654 arg))
4655 ((symbolp arg) ;; keyword class name
4656 (cond
4657 ((eq arg 'todo)
4658 (org-delete-all org-done-keywords
4659 (mapcar 'substring-no-properties
4660 org-todo-keywords-1)))
4661 ((eq arg 'done) org-done-keywords)
4662 ((eq arg 'any)
4663 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4664 (setq todo-re
4665 (concat "^\\*+[ \t]+\\<\\("
4666 (mapconcat 'identity todo-wds "\\|")
4667 "\\)\\>"))
4668 (cond
4669 ((eq kw 'todo) (re-search-forward todo-re end t))
4670 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4671 ((eq kw 'todo-unblocked)
4672 (catch 'unblocked
4673 (while (re-search-forward todo-re end t)
4674 (or (org-entry-blocked-p) (throw 'unblocked t)))
4675 nil))
4676 ((eq kw 'nottodo-unblocked)
4677 (catch 'unblocked
4678 (while (re-search-forward todo-re end t)
4679 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4683 ;;;###autoload
4684 (defun org-agenda-list-stuck-projects (&rest ignore)
4685 "Create agenda view for projects that are stuck.
4686 Stuck projects are project that have no next actions. For the definitions
4687 of what a project is and how to check if it stuck, customize the variable
4688 `org-stuck-projects'."
4689 (interactive)
4690 (let* ((org-agenda-skip-function
4691 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4692 ;; We could have used org-agenda-skip-if here.
4693 (org-agenda-overriding-header
4694 (or org-agenda-overriding-header "List of stuck projects: "))
4695 (matcher (nth 0 org-stuck-projects))
4696 (todo (nth 1 org-stuck-projects))
4697 (todo-wds (if (member "*" todo)
4698 (progn
4699 (org-agenda-prepare-buffers (org-agenda-files
4700 nil 'ifmode))
4701 (org-delete-all
4702 org-done-keywords-for-agenda
4703 (copy-sequence org-todo-keywords-for-agenda)))
4704 todo))
4705 (todo-re (concat "^\\*+[ \t]+\\("
4706 (mapconcat 'identity todo-wds "\\|")
4707 "\\)\\>"))
4708 (tags (nth 2 org-stuck-projects))
4709 (tags-re (if (member "*" tags)
4710 (concat org-outline-regexp-bol
4711 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4712 (if tags
4713 (concat org-outline-regexp-bol
4714 ".*:\\("
4715 (mapconcat 'identity tags "\\|")
4716 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4717 (gen-re (nth 3 org-stuck-projects))
4718 (re-list
4719 (delq nil
4720 (list
4721 (if todo todo-re)
4722 (if tags tags-re)
4723 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4724 gen-re)))))
4725 (setq org-agenda-skip-regexp
4726 (if re-list
4727 (mapconcat 'identity re-list "\\|")
4728 (error "No information how to identify unstuck projects")))
4729 (org-tags-view nil matcher)
4730 (with-current-buffer org-agenda-buffer-name
4731 (setq org-agenda-redo-command
4732 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4734 ;;; Diary integration
4736 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4737 (defvar diary-list-entries-hook)
4738 (defvar diary-time-regexp)
4739 (defun org-get-entries-from-diary (date)
4740 "Get the (Emacs Calendar) diary entries for DATE."
4741 (require 'diary-lib)
4742 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4743 (diary-display-hook '(fancy-diary-display))
4744 (diary-display-function 'fancy-diary-display)
4745 (pop-up-frames nil)
4746 (diary-list-entries-hook
4747 (cons 'org-diary-default-entry diary-list-entries-hook))
4748 (diary-file-name-prefix-function nil) ; turn this feature off
4749 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4750 entries
4751 (org-disable-agenda-to-diary t))
4752 (save-excursion
4753 (save-window-excursion
4754 (funcall (if (fboundp 'diary-list-entries)
4755 'diary-list-entries 'list-diary-entries)
4756 date 1)))
4757 (if (not (get-buffer diary-fancy-buffer))
4758 (setq entries nil)
4759 (with-current-buffer diary-fancy-buffer
4760 (setq buffer-read-only nil)
4761 (if (zerop (buffer-size))
4762 ;; No entries
4763 (setq entries nil)
4764 ;; Omit the date and other unnecessary stuff
4765 (org-agenda-cleanup-fancy-diary)
4766 ;; Add prefix to each line and extend the text properties
4767 (if (zerop (buffer-size))
4768 (setq entries nil)
4769 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4770 (setq entries
4771 (with-temp-buffer
4772 (insert entries) (goto-char (point-min))
4773 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4774 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4775 (replace-match (concat "; " (match-string 1)))))
4776 (buffer-string)))))
4777 (set-buffer-modified-p nil)
4778 (kill-buffer diary-fancy-buffer)))
4779 (when entries
4780 (setq entries (org-split-string entries "\n"))
4781 (setq entries
4782 (mapcar
4783 (lambda (x)
4784 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4785 ;; Extend the text properties to the beginning of the line
4786 (org-add-props x (text-properties-at (1- (length x)) x)
4787 'type "diary" 'date date 'face 'org-agenda-diary))
4788 entries)))))
4790 (defvar org-agenda-cleanup-fancy-diary-hook nil
4791 "Hook run when the fancy diary buffer is cleaned up.")
4793 (defun org-agenda-cleanup-fancy-diary ()
4794 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4795 This gets rid of the date, the underline under the date, and
4796 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4797 date. It also removes lines that contain only whitespace."
4798 (goto-char (point-min))
4799 (if (looking-at ".*?:[ \t]*")
4800 (progn
4801 (replace-match "")
4802 (re-search-forward "\n=+$" nil t)
4803 (replace-match "")
4804 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4805 (re-search-forward "\n=+$" nil t)
4806 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4807 (goto-char (point-min))
4808 (while (re-search-forward "^ +\n" nil t)
4809 (replace-match ""))
4810 (goto-char (point-min))
4811 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4812 (replace-match ""))
4813 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4815 ;; Make sure entries from the diary have the right text properties.
4816 (eval-after-load "diary-lib"
4817 '(if (boundp 'diary-modify-entry-list-string-function)
4818 ;; We can rely on the hook, nothing to do
4820 ;; Hook not available, must use advice to make this work
4821 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4822 "Make the position visible."
4823 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4824 (stringp string)
4825 buffer-file-name)
4826 (setq string (org-modify-diary-entry-string string))))))
4828 (defun org-modify-diary-entry-string (string)
4829 "Add text properties to string, allowing org-mode to act on it."
4830 (org-add-props string nil
4831 'mouse-face 'highlight
4832 'help-echo (if buffer-file-name
4833 (format "mouse-2 or RET jump to diary file %s"
4834 (abbreviate-file-name buffer-file-name))
4836 'org-agenda-diary-link t
4837 'org-marker (org-agenda-new-marker (point-at-bol))))
4839 (defun org-diary-default-entry ()
4840 "Add a dummy entry to the diary.
4841 Needed to avoid empty dates which mess up holiday display."
4842 ;; Catch the error if dealing with the new add-to-diary-alist
4843 (when org-disable-agenda-to-diary
4844 (condition-case nil
4845 (org-add-to-diary-list original-date "Org-mode dummy" "")
4846 (error
4847 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4849 (defun org-add-to-diary-list (&rest args)
4850 (if (fboundp 'diary-add-to-list)
4851 (apply 'diary-add-to-list args)
4852 (apply 'add-to-diary-list args)))
4854 (defvar org-diary-last-run-time nil)
4856 ;;;###autoload
4857 (defun org-diary (&rest args)
4858 "Return diary information from org files.
4859 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4860 It accesses org files and extracts information from those files to be
4861 listed in the diary. The function accepts arguments specifying what
4862 items should be listed. For a list of arguments allowed here, see the
4863 variable `org-agenda-entry-types'.
4865 The call in the diary file should look like this:
4867 &%%(org-diary) ~/path/to/some/orgfile.org
4869 Use a separate line for each org file to check. Or, if you omit the file name,
4870 all files listed in `org-agenda-files' will be checked automatically:
4872 &%%(org-diary)
4874 If you don't give any arguments (as in the example above), the default
4875 arguments (:deadline :scheduled :timestamp :sexp) are used.
4876 So the example above may also be written as
4878 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4880 The function expects the lisp variables `entry' and `date' to be provided
4881 by the caller, because this is how the calendar works. Don't use this
4882 function from a program - use `org-agenda-get-day-entries' instead."
4883 (when (> (- (org-float-time)
4884 org-agenda-last-marker-time)
4886 ;; I am not sure if this works with sticky agendas, because the marker
4887 ;; list is then no longer a global variable.
4888 (org-agenda-reset-markers))
4889 (org-compile-prefix-format 'agenda)
4890 (org-set-sorting-strategy 'agenda)
4891 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4892 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4893 (list entry)
4894 (org-agenda-files t)))
4895 (time (org-float-time))
4896 file rtn results)
4897 (when (or (not org-diary-last-run-time)
4898 (> (- time
4899 org-diary-last-run-time)
4901 (org-agenda-prepare-buffers files))
4902 (setq org-diary-last-run-time time)
4903 ;; If this is called during org-agenda, don't return any entries to
4904 ;; the calendar. Org Agenda will list these entries itself.
4905 (if org-disable-agenda-to-diary (setq files nil))
4906 (while (setq file (pop files))
4907 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4908 (setq results (append results rtn)))
4909 (if results
4910 (concat (org-agenda-finalize-entries results) "\n"))))
4912 ;;; Agenda entry finders
4914 (defun org-agenda-get-day-entries (file date &rest args)
4915 "Does the work for `org-diary' and `org-agenda'.
4916 FILE is the path to a file to be checked for entries. DATE is date like
4917 the one returned by `calendar-current-date'. ARGS are symbols indicating
4918 which kind of entries should be extracted. For details about these, see
4919 the documentation of `org-diary'."
4920 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4921 (let* ((org-startup-folded nil)
4922 (org-startup-align-all-tables nil)
4923 (buffer (if (file-exists-p file)
4924 (org-get-agenda-file-buffer file)
4925 (error "No such file %s" file)))
4926 arg results rtn deadline-results)
4927 (if (not buffer)
4928 ;; If file does not exist, make sure an error message ends up in diary
4929 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4930 (with-current-buffer buffer
4931 (unless (derived-mode-p 'org-mode)
4932 (error "Agenda file %s is not in `org-mode'" file))
4933 (setq org-agenda-buffer (or org-agenda-buffer buffer))
4934 (let ((case-fold-search nil))
4935 (save-excursion
4936 (save-restriction
4937 (if org-agenda-restrict
4938 (narrow-to-region org-agenda-restrict-begin
4939 org-agenda-restrict-end)
4940 (widen))
4941 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4942 (while (setq arg (pop args))
4943 (cond
4944 ((and (eq arg :todo)
4945 (equal date (calendar-gregorian-from-absolute
4946 (org-today))))
4947 (setq rtn (org-agenda-get-todos))
4948 (setq results (append results rtn)))
4949 ((eq arg :timestamp)
4950 (setq rtn (org-agenda-get-blocks))
4951 (setq results (append results rtn))
4952 (setq rtn (org-agenda-get-timestamps deadline-results))
4953 (setq results (append results rtn)))
4954 ((eq arg :sexp)
4955 (setq rtn (org-agenda-get-sexps))
4956 (setq results (append results rtn)))
4957 ((eq arg :scheduled)
4958 (setq rtn (org-agenda-get-scheduled deadline-results))
4959 (setq results (append results rtn)))
4960 ((eq arg :closed)
4961 (setq rtn (org-agenda-get-progress))
4962 (setq results (append results rtn)))
4963 ((eq arg :deadline)
4964 (setq rtn (org-agenda-get-deadlines))
4965 (setq deadline-results (copy-sequence rtn))
4966 (setq results (append results rtn))))))))
4967 results))))
4969 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4970 (defun org-agenda-get-todos ()
4971 "Return the TODO information for agenda display."
4972 (let* ((props (list 'face nil
4973 'done-face 'org-agenda-done
4974 'org-not-done-regexp org-not-done-regexp
4975 'org-todo-regexp org-todo-regexp
4976 'org-complex-heading-regexp org-complex-heading-regexp
4977 'mouse-face 'highlight
4978 'help-echo
4979 (format "mouse-2 or RET jump to org file %s"
4980 (abbreviate-file-name buffer-file-name))))
4981 (regexp (format org-heading-keyword-regexp-format
4982 (cond
4983 ((and org-select-this-todo-keyword
4984 (equal org-select-this-todo-keyword "*"))
4985 org-todo-regexp)
4986 (org-select-this-todo-keyword
4987 (concat "\\("
4988 (mapconcat 'identity
4989 (org-split-string
4990 org-select-this-todo-keyword
4991 "|")
4992 "\\|") "\\)"))
4993 (t org-not-done-regexp))))
4994 marker priority category category-pos tags todo-state
4995 ee txt beg end)
4996 (goto-char (point-min))
4997 (while (re-search-forward regexp nil t)
4998 (catch :skip
4999 (save-match-data
5000 (beginning-of-line)
5001 (org-agenda-skip)
5002 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5003 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5004 (goto-char (1+ beg))
5005 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5006 (throw :skip nil)))
5007 (goto-char (match-beginning 2))
5008 (setq marker (org-agenda-new-marker (match-beginning 0))
5009 category (org-get-category)
5010 category-pos (get-text-property (point) 'org-category-position)
5011 txt (org-trim
5012 (buffer-substring (match-beginning 2) (match-end 0)))
5013 tags (org-get-tags-at (point))
5014 txt (org-agenda-format-item "" txt category tags)
5015 priority (1+ (org-get-priority txt))
5016 todo-state (org-get-todo-state))
5017 (org-add-props txt props
5018 'org-marker marker 'org-hd-marker marker
5019 'priority priority 'org-category category
5020 'org-category-position category-pos
5021 'type "todo" 'todo-state todo-state)
5022 (push txt ee)
5023 (if org-agenda-todo-list-sublevels
5024 (goto-char (match-end 2))
5025 (org-end-of-subtree 'invisible))))
5026 (nreverse ee)))
5028 (defun org-agenda-todo-custom-ignore-p (time n)
5029 "Check whether timestamp is farther away then n number of days.
5030 This function is invoked if `org-agenda-todo-ignore-deadlines',
5031 `org-agenda-todo-ignore-scheduled' or
5032 `org-agenda-todo-ignore-timestamp' is set to an integer."
5033 (let ((days (org-days-to-time time)))
5034 (if (>= n 0)
5035 (>= days n)
5036 (<= days n))))
5038 ;;;###autoload
5039 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5040 (&optional end)
5041 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5042 (when (or org-agenda-todo-ignore-with-date
5043 org-agenda-todo-ignore-scheduled
5044 org-agenda-todo-ignore-deadlines
5045 org-agenda-todo-ignore-timestamp)
5046 (setq end (or end (save-excursion (outline-next-heading) (point))))
5047 (save-excursion
5048 (or (and org-agenda-todo-ignore-with-date
5049 (re-search-forward org-ts-regexp end t))
5050 (and org-agenda-todo-ignore-scheduled
5051 (re-search-forward org-scheduled-time-regexp end t)
5052 (cond
5053 ((eq org-agenda-todo-ignore-scheduled 'future)
5054 (> (org-days-to-time (match-string 1)) 0))
5055 ((eq org-agenda-todo-ignore-scheduled 'past)
5056 (<= (org-days-to-time (match-string 1)) 0))
5057 ((numberp org-agenda-todo-ignore-scheduled)
5058 (org-agenda-todo-custom-ignore-p
5059 (match-string 1) org-agenda-todo-ignore-scheduled))
5060 (t)))
5061 (and org-agenda-todo-ignore-deadlines
5062 (re-search-forward org-deadline-time-regexp end t)
5063 (cond
5064 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5065 ((eq org-agenda-todo-ignore-deadlines 'far)
5066 (not (org-deadline-close (match-string 1))))
5067 ((eq org-agenda-todo-ignore-deadlines 'future)
5068 (> (org-days-to-time (match-string 1)) 0))
5069 ((eq org-agenda-todo-ignore-deadlines 'past)
5070 (<= (org-days-to-time (match-string 1)) 0))
5071 ((numberp org-agenda-todo-ignore-deadlines)
5072 (org-agenda-todo-custom-ignore-p
5073 (match-string 1) org-agenda-todo-ignore-deadlines))
5074 (t (org-deadline-close (match-string 1)))))
5075 (and org-agenda-todo-ignore-timestamp
5076 (let ((buffer (current-buffer))
5077 (regexp
5078 (concat
5079 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5080 (start (point)))
5081 ;; Copy current buffer into a temporary one
5082 (with-temp-buffer
5083 (insert-buffer-substring buffer start end)
5084 (goto-char (point-min))
5085 ;; Delete SCHEDULED and DEADLINE items
5086 (while (re-search-forward regexp end t)
5087 (delete-region (match-beginning 0) (match-end 0)))
5088 (goto-char (point-min))
5089 ;; No search for timestamp left
5090 (when (re-search-forward org-ts-regexp nil t)
5091 (cond
5092 ((eq org-agenda-todo-ignore-timestamp 'future)
5093 (> (org-days-to-time (match-string 1)) 0))
5094 ((eq org-agenda-todo-ignore-timestamp 'past)
5095 (<= (org-days-to-time (match-string 1)) 0))
5096 ((numberp org-agenda-todo-ignore-timestamp)
5097 (org-agenda-todo-custom-ignore-p
5098 (match-string 1) org-agenda-todo-ignore-timestamp))
5099 (t))))))))))
5101 (defconst org-agenda-no-heading-message
5102 "No heading for this item in buffer or region.")
5104 (defun org-agenda-get-timestamps (&optional deadline-results)
5105 "Return the date stamp information for agenda display."
5106 (let* ((props (list 'face 'org-agenda-calendar-event
5107 'org-not-done-regexp org-not-done-regexp
5108 'org-todo-regexp org-todo-regexp
5109 'org-complex-heading-regexp org-complex-heading-regexp
5110 'mouse-face 'highlight
5111 'help-echo
5112 (format "mouse-2 or RET jump to org file %s"
5113 (abbreviate-file-name buffer-file-name))))
5114 (d1 (calendar-absolute-from-gregorian date))
5116 (deadline-position-alist
5117 (mapcar (lambda (a) (and (setq mm (get-text-property
5118 0 'org-hd-marker a))
5119 (cons (marker-position mm) a)))
5120 deadline-results))
5121 (remove-re org-ts-regexp)
5122 (regexp
5123 (concat
5124 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5125 (regexp-quote
5126 (substring
5127 (format-time-string
5128 (car org-time-stamp-formats)
5129 (apply 'encode-time ; DATE bound by calendar
5130 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5131 1 11))
5132 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5133 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5134 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5135 donep tmp priority category category-pos ee txt timestr tags
5136 b0 b3 e3 head todo-state end-of-match show-all warntime)
5137 (goto-char (point-min))
5138 (while (setq end-of-match (re-search-forward regexp nil t))
5139 (setq b0 (match-beginning 0)
5140 b3 (match-beginning 3) e3 (match-end 3)
5141 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5142 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5143 (member todo-state
5144 org-agenda-repeating-timestamp-show-all)))
5145 (catch :skip
5146 (and (org-at-date-range-p) (throw :skip nil))
5147 (org-agenda-skip)
5148 (if (and (match-end 1)
5149 (not (= d1 (org-time-string-to-absolute
5150 (match-string 1) d1 nil show-all
5151 (current-buffer) b0))))
5152 (throw :skip nil))
5153 (if (and e3
5154 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5155 (throw :skip nil))
5156 (setq tmp (buffer-substring (max (point-min)
5157 (- b0 org-ds-keyword-length))
5159 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5160 inactivep (= (char-after b0) ?\[)
5161 deadlinep (string-match org-deadline-regexp tmp)
5162 scheduledp (string-match org-scheduled-regexp tmp)
5163 closedp (and org-agenda-include-inactive-timestamps
5164 (string-match org-closed-string tmp))
5165 clockp (and org-agenda-include-inactive-timestamps
5166 (or (string-match org-clock-string tmp)
5167 (string-match "]-+\\'" tmp)))
5168 warntime (org-entry-get (point) "APPT_WARNTIME")
5169 donep (member todo-state org-done-keywords))
5170 (if (or scheduledp deadlinep closedp clockp
5171 (and donep org-agenda-skip-timestamp-if-done))
5172 (throw :skip t))
5173 (if (string-match ">" timestr)
5174 ;; substring should only run to end of time stamp
5175 (setq timestr (substring timestr 0 (match-end 0))))
5176 (setq marker (org-agenda-new-marker b0)
5177 category (org-get-category b0)
5178 category-pos (get-text-property b0 'org-category-position))
5179 (save-excursion
5180 (if (not (re-search-backward org-outline-regexp-bol nil t))
5181 (setq txt org-agenda-no-heading-message)
5182 (goto-char (match-beginning 0))
5183 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5184 (assoc (point) deadline-position-alist))
5185 (throw :skip nil))
5186 (setq hdmarker (org-agenda-new-marker)
5187 tags (org-get-tags-at))
5188 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5189 (setq head (or (match-string 1) ""))
5190 (setq txt (org-agenda-format-item
5191 (if inactivep org-agenda-inactive-leader nil)
5192 head category tags timestr
5193 remove-re)))
5194 (setq priority (org-get-priority txt))
5195 (org-add-props txt props
5196 'org-marker marker 'org-hd-marker hdmarker)
5197 (org-add-props txt nil 'priority priority
5198 'org-category category 'date date
5199 'org-category-position category-pos
5200 'todo-state todo-state
5201 'warntime warntime
5202 'type "timestamp")
5203 (push txt ee))
5204 (if org-agenda-skip-additional-timestamps-same-entry
5205 (outline-next-heading)
5206 (goto-char end-of-match))))
5207 (nreverse ee)))
5209 (defun org-agenda-get-sexps ()
5210 "Return the sexp information for agenda display."
5211 (require 'diary-lib)
5212 (let* ((props (list 'face 'org-agenda-calendar-sexp
5213 'mouse-face 'highlight
5214 'help-echo
5215 (format "mouse-2 or RET jump to org file %s"
5216 (abbreviate-file-name buffer-file-name))))
5217 (regexp "^&?%%(")
5218 marker category extra category-pos ee txt tags entry
5219 result beg b sexp sexp-entry todo-state warntime)
5220 (goto-char (point-min))
5221 (while (re-search-forward regexp nil t)
5222 (catch :skip
5223 (org-agenda-skip)
5224 (setq beg (match-beginning 0))
5225 (goto-char (1- (match-end 0)))
5226 (setq b (point))
5227 (forward-sexp 1)
5228 (setq sexp (buffer-substring b (point)))
5229 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5230 (org-trim (match-string 1))
5231 ""))
5232 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5233 (when result
5234 (setq marker (org-agenda-new-marker beg)
5235 category (org-get-category beg)
5236 category-pos (get-text-property beg 'org-category-position)
5237 tags (save-excursion (org-backward-heading-same-level 0)
5238 (org-get-tags-at))
5239 todo-state (org-get-todo-state)
5240 warntime (org-entry-get (point) "APPT_WARNTIME"))
5242 (dolist (r (if (stringp result)
5243 (list result)
5244 result)) ;; we expect a list here
5245 (when (and org-agenda-diary-sexp-prefix
5246 (string-match org-agenda-diary-sexp-prefix r))
5247 (setq extra (match-string 0 r)
5248 r (replace-match "" nil nil r)))
5249 (if (string-match "\\S-" r)
5250 (setq txt r)
5251 (setq txt "SEXP entry returned empty string"))
5253 (setq txt (org-agenda-format-item
5254 extra txt category tags 'time))
5255 (org-add-props txt props 'org-marker marker)
5256 (org-add-props txt nil
5257 'org-category category 'date date 'todo-state todo-state
5258 'org-category-position category-pos 'tags tags
5259 'type "sexp" 'warntime warntime)
5260 (push txt ee)))))
5261 (nreverse ee)))
5263 ;; Calendar sanity: define some functions that are independent of
5264 ;; `calendar-date-style'.
5265 ;; Normally I would like to use ISO format when calling the diary functions,
5266 ;; but to make sure we still have Emacs 22 compatibility we bind
5267 ;; also `european-calendar-style' and use european format
5268 (defun org-anniversary (year month day &optional mark)
5269 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5270 (org-no-warnings
5271 (let ((calendar-date-style 'european) (european-calendar-style t))
5272 (diary-anniversary day month year mark))))
5273 (defun org-cyclic (N year month day &optional mark)
5274 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5275 (org-no-warnings
5276 (let ((calendar-date-style 'european) (european-calendar-style t))
5277 (diary-cyclic N day month year mark))))
5278 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5279 "Like `diary-block', but with fixed (ISO) order of arguments."
5280 (org-no-warnings
5281 (let ((calendar-date-style 'european) (european-calendar-style t))
5282 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5283 (defun org-date (year month day &optional mark)
5284 "Like `diary-date', but with fixed (ISO) order of arguments."
5285 (org-no-warnings
5286 (let ((calendar-date-style 'european) (european-calendar-style t))
5287 (diary-date day month year mark))))
5288 (defalias 'org-float 'diary-float)
5290 ;; Define the` org-class' function
5291 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5292 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5293 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5294 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5295 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5296 `holidays', then any date that is known by the Emacs calendar to be a
5297 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5298 then those holidays will be skipped."
5299 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5300 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5301 (d (calendar-absolute-from-gregorian date))
5302 (h (when skip-weeks (calendar-check-holidays date))))
5303 (and
5304 (<= date1 d)
5305 (<= d date2)
5306 (= (calendar-day-of-week date) dayname)
5307 (or (not skip-weeks)
5308 (progn
5309 (require 'cal-iso)
5310 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5311 (not (or (and h (memq 'holidays skip-weeks))
5312 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5313 entry)))
5315 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5316 "Like `org-class', but honor `calendar-date-style'.
5317 The order of the first 2 times 3 arguments depends on the variable
5318 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5319 So for American calendars, give this as MONTH DAY YEAR, for European as
5320 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5321 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5322 is any number of ISO weeks in the block period for which the item should
5323 be skipped.
5325 This function is here only for backward compatibility and it is deprecated,
5326 please use `org-class' instead."
5327 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5328 (date2 (org-order-calendar-date-args m2 d2 y2)))
5329 (org-class
5330 (nth 2 date1) (car date1) (nth 1 date1)
5331 (nth 2 date2) (car date2) (nth 1 date2)
5332 dayname skip-weeks)))
5333 (make-obsolete 'org-diary-class 'org-class "")
5335 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5336 (defalias 'org-get-closed 'org-agenda-get-progress)
5337 (defun org-agenda-get-progress ()
5338 "Return the logged TODO entries for agenda display."
5339 (let* ((props (list 'mouse-face 'highlight
5340 'org-not-done-regexp org-not-done-regexp
5341 'org-todo-regexp org-todo-regexp
5342 'org-complex-heading-regexp org-complex-heading-regexp
5343 'help-echo
5344 (format "mouse-2 or RET jump to org file %s"
5345 (abbreviate-file-name buffer-file-name))))
5346 (items (if (consp org-agenda-show-log-scoped)
5347 org-agenda-show-log-scoped
5348 (if (eq org-agenda-show-log-scoped 'clockcheck)
5349 '(clock)
5350 org-agenda-log-mode-items)))
5351 (parts
5352 (delq nil
5353 (list
5354 (if (memq 'closed items) (concat "\\<" org-closed-string))
5355 (if (memq 'clock items) (concat "\\<" org-clock-string))
5356 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5357 (parts-re (if parts (mapconcat 'identity parts "\\|")
5358 (error "`org-agenda-log-mode-items' is empty")))
5359 (regexp (concat
5360 "\\(" parts-re "\\)"
5361 " *\\["
5362 (regexp-quote
5363 (substring
5364 (format-time-string
5365 (car org-time-stamp-formats)
5366 (apply 'encode-time ; DATE bound by calendar
5367 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5368 1 11))))
5369 (org-agenda-search-headline-for-time nil)
5370 marker hdmarker priority category category-pos tags closedp
5371 statep clockp state ee txt extra timestr rest clocked)
5372 (goto-char (point-min))
5373 (while (re-search-forward regexp nil t)
5374 (catch :skip
5375 (org-agenda-skip)
5376 (setq marker (org-agenda-new-marker (match-beginning 0))
5377 closedp (equal (match-string 1) org-closed-string)
5378 statep (equal (string-to-char (match-string 1)) ?-)
5379 clockp (not (or closedp statep))
5380 state (and statep (match-string 2))
5381 category (org-get-category (match-beginning 0))
5382 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5383 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5384 (when (string-match "\\]" timestr)
5385 ;; substring should only run to end of time stamp
5386 (setq rest (substring timestr (match-end 0))
5387 timestr (substring timestr 0 (match-end 0)))
5388 (if (and (not closedp) (not statep)
5389 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5390 rest))
5391 (progn (setq timestr (concat (substring timestr 0 -1)
5392 "-" (match-string 1 rest) "]"))
5393 (setq clocked (match-string 2 rest)))
5394 (setq clocked "-")))
5395 (save-excursion
5396 (setq extra
5397 (cond
5398 ((not org-agenda-log-mode-add-notes) nil)
5399 (statep
5400 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5401 (match-string 1)))
5402 (clockp
5403 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5404 (match-string 1)))))
5405 (if (not (re-search-backward org-outline-regexp-bol nil t))
5406 (setq txt org-agenda-no-heading-message)
5407 (goto-char (match-beginning 0))
5408 (setq hdmarker (org-agenda-new-marker)
5409 tags (org-get-tags-at))
5410 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5411 (setq txt (match-string 1))
5412 (when extra
5413 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5414 (setq txt (concat (substring txt 0 (match-beginning 1))
5415 " - " extra " " (match-string 2 txt)))
5416 (setq txt (concat txt " - " extra))))
5417 (setq txt (org-agenda-format-item
5418 (cond
5419 (closedp "Closed: ")
5420 (statep (concat "State: (" state ")"))
5421 (t (concat "Clocked: (" clocked ")")))
5422 txt category tags timestr)))
5423 (setq priority 100000)
5424 (org-add-props txt props
5425 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5426 'priority priority 'org-category category
5427 'org-category-position category-pos
5428 'type "closed" 'date date
5429 'undone-face 'org-warning 'done-face 'org-agenda-done)
5430 (push txt ee))
5431 (goto-char (point-at-eol))))
5432 (nreverse ee)))
5434 (defun org-agenda-show-clocking-issues ()
5435 "Add overlays, showing issues with clocking.
5436 See also the user option `org-agenda-clock-consistency-checks'."
5437 (interactive)
5438 (let* ((pl org-agenda-clock-consistency-checks)
5439 (re (concat "^[ \t]*"
5440 org-clock-string
5441 "[ \t]+"
5442 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5443 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5444 (tlstart 0.)
5445 (tlend 0.)
5446 (maxtime (org-hh:mm-string-to-minutes
5447 (or (plist-get pl :max-duration) "24:00")))
5448 (mintime (org-hh:mm-string-to-minutes
5449 (or (plist-get pl :min-duration) 0)))
5450 (maxgap (org-hh:mm-string-to-minutes
5451 ;; default 30:00 means never complain
5452 (or (plist-get pl :max-gap) "30:00")))
5453 (gapok (mapcar 'org-hh:mm-string-to-minutes
5454 (plist-get pl :gap-ok-around)))
5455 (def-face (or (plist-get pl :default-face)
5456 '((:background "DarkRed") (:foreground "white"))))
5457 issue face m te ts dt ov)
5458 (goto-char (point-min))
5459 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5460 (setq issue nil face def-face)
5461 (catch 'next
5462 (setq m (org-get-at-bol 'org-marker)
5463 te nil ts nil)
5464 (unless (and m (markerp m))
5465 (setq issue "No valid clock line") (throw 'next t))
5466 (org-with-point-at m
5467 (save-excursion
5468 (goto-char (point-at-bol))
5469 (unless (looking-at re)
5470 (error "No valid Clock line")
5471 (throw 'next t))
5472 (unless (match-end 3)
5473 (setq issue "No end time"
5474 face (or (plist-get pl :no-end-time-face) face))
5475 (throw 'next t))
5476 (setq ts (match-string 1)
5477 te (match-string 3)
5478 ts (org-float-time
5479 (apply 'encode-time (org-parse-time-string ts)))
5480 te (org-float-time
5481 (apply 'encode-time (org-parse-time-string te)))
5482 dt (- te ts))))
5483 (cond
5484 ((> dt (* 60 maxtime))
5485 ;; a very long clocking chunk
5486 (setq issue (format "Clocking interval is very long: %s"
5487 (org-minutes-to-hh:mm-string
5488 (floor (/ (float dt) 60.))))
5489 face (or (plist-get pl :long-face) face)))
5490 ((< dt (* 60 mintime))
5491 ;; a very short clocking chunk
5492 (setq issue (format "Clocking interval is very short: %s"
5493 (org-minutes-to-hh:mm-string
5494 (floor (/ (float dt) 60.))))
5495 face (or (plist-get pl :short-face) face)))
5496 ((and (> tlend 0) (< ts tlend))
5497 ;; Two clock entries are overlapping
5498 (setq issue (format "Clocking overlap: %d minutes"
5499 (/ (- tlend ts) 60))
5500 face (or (plist-get pl :overlap-face) face)))
5501 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5502 ;; There is a gap, lets see if we need to report it
5503 (unless (org-agenda-check-clock-gap tlend ts gapok)
5504 (setq issue (format "Clocking gap: %d minutes"
5505 (/ (- ts tlend) 60))
5506 face (or (plist-get pl :gap-face) face))))
5507 (t nil)))
5508 (setq tlend (or te tlend) tlstart (or ts tlstart))
5509 (when issue
5510 ;; OK, there was some issue, add an overlay to show the issue
5511 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5512 (overlay-put ov 'before-string
5513 (concat
5514 (org-add-props
5515 (format "%-43s" (concat " " issue))
5517 'face face)
5518 "\n"))
5519 (overlay-put ov 'evaporate t)))))
5521 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5522 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5523 (catch 'exit
5524 (unless ok-list
5525 ;; there are no OK times for gaps...
5526 (throw 'exit nil))
5527 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5528 ;; This is more than 24 hours, so it is OK.
5529 ;; because we have at least one OK time, that must be in the
5530 ;; 24 hour interval.
5531 (throw 'exit t))
5532 ;; We have a shorter gap.
5533 ;; Now we have to get the minute of the day when these times are
5534 (let* ((t1dec (decode-time (seconds-to-time t1)))
5535 (t2dec (decode-time (seconds-to-time t2)))
5536 ;; compute the minute on the day
5537 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5538 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5539 (when (< min2 min1)
5540 ;; if min2 is smaller than min1, this means it is on the next day.
5541 ;; Wrap it to after midnight.
5542 (setq min2 (+ min2 1440)))
5543 ;; Now check if any of the OK times is in the gap
5544 (mapc (lambda (x)
5545 ;; Wrap the time to after midnight if necessary
5546 (if (< x min1) (setq x (+ x 1440)))
5547 ;; Check if in interval
5548 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5549 ok-list)
5550 ;; Nope, this gap is not OK
5551 nil)))
5553 (defun org-agenda-get-deadlines ()
5554 "Return the deadline information for agenda display."
5555 (let* ((props (list 'mouse-face 'highlight
5556 'org-not-done-regexp org-not-done-regexp
5557 'org-todo-regexp org-todo-regexp
5558 'org-complex-heading-regexp org-complex-heading-regexp
5559 'help-echo
5560 (format "mouse-2 or RET jump to org file %s"
5561 (abbreviate-file-name buffer-file-name))))
5562 (regexp org-deadline-time-regexp)
5563 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5564 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5565 d2 diff dfrac wdays pos pos1 category category-pos
5566 tags suppress-prewarning ee txt head face s todo-state
5567 show-all upcomingp donep timestr warntime)
5568 (goto-char (point-min))
5569 (while (re-search-forward regexp nil t)
5570 (setq suppress-prewarning nil)
5571 (catch :skip
5572 (org-agenda-skip)
5573 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5574 (save-match-data
5575 (string-match org-scheduled-time-regexp
5576 (buffer-substring (point-at-bol)
5577 (point-at-eol)))))
5578 (setq suppress-prewarning
5579 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5580 org-agenda-skip-deadline-prewarning-if-scheduled
5581 0)))
5582 (setq s (match-string 1)
5583 txt nil
5584 pos (1- (match-beginning 1))
5585 todo-state (save-match-data (org-get-todo-state))
5586 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5587 (member todo-state
5588 org-agenda-repeating-timestamp-show-all))
5589 d2 (org-time-string-to-absolute
5590 (match-string 1) d1 'past show-all
5591 (current-buffer) pos)
5592 diff (- d2 d1)
5593 wdays (if suppress-prewarning
5594 (let ((org-deadline-warning-days suppress-prewarning))
5595 (org-get-wdays s))
5596 (org-get-wdays s))
5597 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5598 upcomingp (and todayp (> diff 0)))
5599 ;; When to show a deadline in the calendar:
5600 ;; If the expiration is within wdays warning time.
5601 ;; Past-due deadlines are only shown on the current date
5602 (if (and (or (and (<= diff wdays)
5603 (and todayp (not org-agenda-only-exact-dates)))
5604 (= diff 0)))
5605 (save-excursion
5606 ;; (setq todo-state (org-get-todo-state))
5607 (setq donep (member todo-state org-done-keywords))
5608 (if (and donep
5609 (or org-agenda-skip-deadline-if-done
5610 (not (= diff 0))))
5611 (setq txt nil)
5612 (setq category (org-get-category)
5613 warntime (org-entry-get (point) "APPT_WARNTIME")
5614 category-pos (get-text-property (point) 'org-category-position))
5615 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5616 (setq txt org-agenda-no-heading-message)
5617 (goto-char (match-end 0))
5618 (setq pos1 (match-beginning 0))
5619 (setq tags (org-get-tags-at pos1))
5620 (setq head (buffer-substring-no-properties
5621 (point)
5622 (progn (skip-chars-forward "^\r\n")
5623 (point))))
5624 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5625 (setq timestr
5626 (concat (substring s (match-beginning 1)) " "))
5627 (setq timestr 'time))
5628 (setq txt (org-agenda-format-item
5629 (if (= diff 0)
5630 (car org-agenda-deadline-leaders)
5631 (if (functionp
5632 (nth 1 org-agenda-deadline-leaders))
5633 (funcall
5634 (nth 1 org-agenda-deadline-leaders)
5635 diff date)
5636 (format (nth 1 org-agenda-deadline-leaders)
5637 diff)))
5638 head category tags
5639 (if (not (= diff 0)) nil timestr)))))
5640 (when txt
5641 (setq face (org-agenda-deadline-face dfrac))
5642 (org-add-props txt props
5643 'org-marker (org-agenda-new-marker pos)
5644 'warntime warntime
5645 'org-hd-marker (org-agenda-new-marker pos1)
5646 'priority (+ (- diff)
5647 (org-get-priority txt))
5648 'org-category category
5649 'org-category-position category-pos
5650 'todo-state todo-state
5651 'type (if upcomingp "upcoming-deadline" "deadline")
5652 'date (if upcomingp date d2)
5653 'face (if donep 'org-agenda-done face)
5654 'undone-face face 'done-face 'org-agenda-done)
5655 (push txt ee))))))
5656 (nreverse ee)))
5658 (defun org-agenda-deadline-face (fraction)
5659 "Return the face to displaying a deadline item.
5660 FRACTION is what fraction of the head-warning time has passed."
5661 (let ((faces org-agenda-deadline-faces) f)
5662 (catch 'exit
5663 (while (setq f (pop faces))
5664 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5666 (defun org-agenda-get-scheduled (&optional deadline-results)
5667 "Return the scheduled information for agenda display."
5668 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5669 'org-todo-regexp org-todo-regexp
5670 'org-complex-heading-regexp org-complex-heading-regexp
5671 'done-face 'org-agenda-done
5672 'mouse-face 'highlight
5673 'help-echo
5674 (format "mouse-2 or RET jump to org file %s"
5675 (abbreviate-file-name buffer-file-name))))
5676 (regexp org-scheduled-time-regexp)
5677 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5678 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5680 (deadline-position-alist
5681 (mapcar (lambda (a) (and (setq mm (get-text-property
5682 0 'org-hd-marker a))
5683 (cons (marker-position mm) a)))
5684 deadline-results))
5685 d2 diff pos pos1 category category-pos tags donep
5686 ee txt head pastschedp todo-state face timestr s habitp show-all
5687 did-habit-check-p warntime)
5688 (goto-char (point-min))
5689 (while (re-search-forward regexp nil t)
5690 (catch :skip
5691 (org-agenda-skip)
5692 (setq s (match-string 1)
5693 txt nil
5694 pos (1- (match-beginning 1))
5695 todo-state (save-match-data (org-get-todo-state))
5696 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5697 (member todo-state
5698 org-agenda-repeating-timestamp-show-all))
5699 d2 (org-time-string-to-absolute
5700 (match-string 1) d1 'past show-all
5701 (current-buffer) pos)
5702 diff (- d2 d1)
5703 warntime (org-entry-get (point) "APPT_WARNTIME"))
5704 (setq pastschedp (and todayp (< diff 0)))
5705 (setq did-habit-check-p nil)
5706 ;; When to show a scheduled item in the calendar:
5707 ;; If it is on or past the date.
5708 (when (or (and (< diff 0)
5709 (< (abs diff) org-scheduled-past-days)
5710 (and todayp (not org-agenda-only-exact-dates)))
5711 (= diff 0)
5712 ;; org-is-habit-p uses org-entry-get, which is expansive
5713 ;; so we go extra mile to only call it once
5714 (and todayp
5715 org-habit-show-all-today
5716 (setq did-habit-check-p t)
5717 (setq habitp (and (functionp 'org-is-habit-p)
5718 (org-is-habit-p)))))
5719 (save-excursion
5720 (setq donep (member todo-state org-done-keywords))
5721 (if (and donep
5722 (or org-agenda-skip-scheduled-if-done
5723 (not (= diff 0))
5724 (and (functionp 'org-is-habit-p)
5725 (org-is-habit-p))))
5726 (setq txt nil)
5727 (setq habitp (if did-habit-check-p habitp
5728 (and (functionp 'org-is-habit-p)
5729 (org-is-habit-p))))
5730 (setq category (org-get-category)
5731 category-pos (get-text-property (point) 'org-category-position))
5732 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5733 (setq txt org-agenda-no-heading-message)
5734 (goto-char (match-end 0))
5735 (setq pos1 (match-beginning 0))
5736 (if habitp
5737 (if (or (not org-habit-show-habits)
5738 (and (not todayp)
5739 org-habit-show-habits-only-for-today))
5740 (throw :skip nil))
5741 (if (and
5742 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5743 (and org-agenda-skip-scheduled-if-deadline-is-shown
5744 pastschedp))
5745 (setq mm (assoc pos1 deadline-position-alist)))
5746 (throw :skip nil)))
5747 (setq tags (org-get-tags-at))
5748 (setq head (buffer-substring-no-properties
5749 (point)
5750 (progn (skip-chars-forward "^\r\n") (point))))
5751 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5752 (setq timestr
5753 (concat (substring s (match-beginning 1)) " "))
5754 (setq timestr 'time))
5755 (setq txt (org-agenda-format-item
5756 (if (= diff 0)
5757 (car org-agenda-scheduled-leaders)
5758 (format (nth 1 org-agenda-scheduled-leaders)
5759 (- 1 diff)))
5760 head category tags
5761 (if (not (= diff 0)) nil timestr)
5762 nil habitp))))
5763 (when txt
5764 (setq face
5765 (cond
5766 ((and (not habitp) pastschedp)
5767 'org-scheduled-previously)
5768 (todayp 'org-scheduled-today)
5769 (t 'org-scheduled))
5770 habitp (and habitp (org-habit-parse-todo)))
5771 (org-add-props txt props
5772 'undone-face face
5773 'face (if donep 'org-agenda-done face)
5774 'org-marker (org-agenda-new-marker pos)
5775 'org-hd-marker (org-agenda-new-marker pos1)
5776 'type (if pastschedp "past-scheduled" "scheduled")
5777 'date (if pastschedp d2 date)
5778 'warntime warntime
5779 'priority (if habitp
5780 (org-habit-get-priority habitp)
5781 (+ 94 (- 5 diff) (org-get-priority txt)))
5782 'org-category category
5783 'category-position category-pos
5784 'org-habit-p habitp
5785 'todo-state todo-state)
5786 (push txt ee))))))
5787 (nreverse ee)))
5789 (defun org-agenda-get-blocks ()
5790 "Return the date-range information for agenda display."
5791 (let* ((props (list 'face nil
5792 'org-not-done-regexp org-not-done-regexp
5793 'org-todo-regexp org-todo-regexp
5794 'org-complex-heading-regexp org-complex-heading-regexp
5795 'mouse-face 'highlight
5796 'help-echo
5797 (format "mouse-2 or RET jump to org file %s"
5798 (abbreviate-file-name buffer-file-name))))
5799 (regexp org-tr-regexp)
5800 (d0 (calendar-absolute-from-gregorian date))
5801 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5802 todo-state tags pos head donep)
5803 (goto-char (point-min))
5804 (while (re-search-forward regexp nil t)
5805 (catch :skip
5806 (org-agenda-skip)
5807 (setq pos (point))
5808 (let ((start-time (match-string 1))
5809 (end-time (match-string 2)))
5810 (setq s1 (match-string 1)
5811 s2 (match-string 2)
5812 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5813 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5814 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5815 ;; Only allow days between the limits, because the normal
5816 ;; date stamps will catch the limits.
5817 (save-excursion
5818 (setq todo-state (org-get-todo-state))
5819 (setq donep (member todo-state org-done-keywords))
5820 (if (and donep org-agenda-skip-timestamp-if-done)
5821 (throw :skip t))
5822 (setq marker (org-agenda-new-marker (point)))
5823 (setq category (org-get-category)
5824 category-pos (get-text-property (point) 'org-category-position))
5825 (if (not (re-search-backward org-outline-regexp-bol nil t))
5826 (setq txt org-agenda-no-heading-message)
5827 (goto-char (match-beginning 0))
5828 (setq hdmarker (org-agenda-new-marker (point)))
5829 (setq tags (org-get-tags-at))
5830 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5831 (setq head (match-string 1))
5832 (let ((remove-re
5833 (if org-agenda-remove-timeranges-from-blocks
5834 (concat
5835 "<" (regexp-quote s1) ".*?>"
5836 "--"
5837 "<" (regexp-quote s2) ".*?>")
5838 nil)))
5839 (setq txt (org-agenda-format-item
5840 (format
5841 (nth (if (= d1 d2) 0 1)
5842 org-agenda-timerange-leaders)
5843 (1+ (- d0 d1)) (1+ (- d2 d1)))
5844 head category tags
5845 (cond ((and (= d1 d0) (= d2 d0))
5846 (concat "<" start-time ">--<" end-time ">"))
5847 ((= d1 d0)
5848 (concat "<" start-time ">"))
5849 ((= d2 d0)
5850 (concat "<" end-time ">")))
5851 remove-re))))
5852 (org-add-props txt props
5853 'org-marker marker 'org-hd-marker hdmarker
5854 'type "block" 'date date
5855 'todo-state todo-state
5856 'priority (org-get-priority txt) 'org-category category
5857 'org-category-position category-pos)
5858 (push txt ee))))
5859 (goto-char pos)))
5860 ;; Sort the entries by expiration date.
5861 (nreverse ee)))
5863 ;;; Agenda presentation and sorting
5865 (defvar org-prefix-has-time nil
5866 "A flag, set by `org-compile-prefix-format'.
5867 The flag is set if the currently compiled format contains a `%t'.")
5868 (defvar org-prefix-has-tag nil
5869 "A flag, set by `org-compile-prefix-format'.
5870 The flag is set if the currently compiled format contains a `%T'.")
5871 (defvar org-prefix-has-effort nil
5872 "A flag, set by `org-compile-prefix-format'.
5873 The flag is set if the currently compiled format contains a `%e'.")
5874 (defvar org-prefix-category-length nil
5875 "Used by `org-compile-prefix-format' to remember the category field width.")
5876 (defvar org-prefix-category-max-length nil
5877 "Used by `org-compile-prefix-format' to remember the category field width.")
5879 (defun org-agenda-get-category-icon (category)
5880 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5881 (dolist (entry org-agenda-category-icon-alist)
5882 (when (org-string-match-p (car entry) category)
5883 (if (listp (cadr entry))
5884 (return (cadr entry))
5885 (return (apply 'create-image (cdr entry)))))))
5887 (defun org-agenda-format-item (extra txt &optional category tags dotime
5888 remove-re habitp)
5889 "Format TXT to be inserted into the agenda buffer.
5890 In particular, it adds the prefix and corresponding text properties. EXTRA
5891 must be a string and replaces the `%s' specifier in the prefix format.
5892 CATEGORY (string, symbol or nil) may be used to overrule the default
5893 category taken from local variable or file name. It will replace the `%c'
5894 specifier in the format. DOTIME, when non-nil, indicates that a
5895 time-of-day should be extracted from TXT for sorting of this entry, and for
5896 the `%t' specifier in the format. When DOTIME is a string, this string is
5897 searched for a time before TXT is. TAGS can be the tags of the headline.
5898 Any match of REMOVE-RE will be removed from TXT."
5899 ;; We keep the org-prefix-* variable values along with a compiled
5900 ;; formatter, so that multiple agendas existing at the same time, do
5901 ;; not step on each other toes.
5903 ;; It was inconvenient to make these variables buffer local in
5904 ;; Agenda buffers, because this function expects to be called with
5905 ;; the buffer where item comes from being current, and not agenda
5906 ;; buffer
5907 (let* ((bindings (car org-prefix-format-compiled))
5908 (formatter (cadr org-prefix-format-compiled)))
5909 (loop for (var value) in bindings
5910 do (set var value))
5911 (save-match-data
5912 ;; Diary entries sometimes have extra whitespace at the beginning
5913 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5915 ;; Fix the tags part in txt
5916 (setq txt (org-agenda-fix-displayed-tags
5917 txt tags
5918 org-agenda-show-inherited-tags
5919 org-agenda-hide-tags-regexp))
5920 (let* ((category (or category
5921 (if (stringp org-category)
5922 org-category
5923 (and org-category (symbol-name org-category)))
5924 (if buffer-file-name
5925 (file-name-sans-extension
5926 (file-name-nondirectory buffer-file-name))
5927 "")))
5928 (category-icon (org-agenda-get-category-icon category))
5929 (category-icon (if category-icon
5930 (propertize " " 'display category-icon)
5931 ""))
5932 ;; time, tag, effort are needed for the eval of the prefix format
5933 (tag (if tags (nth (1- (length tags)) tags) ""))
5934 time effort neffort
5935 (ts (if dotime (concat
5936 (if (stringp dotime) dotime "")
5937 (and org-agenda-search-headline-for-time txt))))
5938 (time-of-day (and dotime (org-get-time-of-day ts)))
5939 stamp plain s0 s1 s2 rtn srp l
5940 duration thecategory)
5941 (and (derived-mode-p 'org-mode) buffer-file-name
5942 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5943 (when (and dotime time-of-day)
5944 ;; Extract starting and ending time and move them to prefix
5945 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5946 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5947 (setq s0 (match-string 0 ts)
5948 srp (and stamp (match-end 3))
5949 s1 (match-string (if plain 1 2) ts)
5950 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5952 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5953 ;; them, we might want to remove them there to avoid duplication.
5954 ;; The user can turn this off with a variable.
5955 (if (and org-prefix-has-time
5956 org-agenda-remove-times-when-in-prefix (or stamp plain)
5957 (string-match (concat (regexp-quote s0) " *") txt)
5958 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5959 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5960 (= (match-beginning 0) 0)
5962 (setq txt (replace-match "" nil nil txt))))
5963 ;; Normalize the time(s) to 24 hour
5964 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5965 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5967 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5968 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5969 (setq s2
5970 (org-minutes-to-hh:mm-string
5971 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5973 ;; Compute the duration
5974 (when s2
5975 (setq duration (- (org-hh:mm-string-to-minutes s2)
5976 (org-hh:mm-string-to-minutes s1)))))
5978 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5979 txt)
5980 ;; Tags are in the string
5981 (if (or (eq org-agenda-remove-tags t)
5982 (and org-agenda-remove-tags
5983 org-prefix-has-tag))
5984 (setq txt (replace-match "" t t txt))
5985 (setq txt (replace-match
5986 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5987 (match-string 2 txt))
5988 t t txt))))
5989 (when (derived-mode-p 'org-mode)
5990 (setq effort
5991 (condition-case nil
5992 (org-get-effort
5993 (or (get-text-property 0 'org-hd-marker txt)
5994 (get-text-property 0 'org-marker txt)))
5995 (error nil)))
5996 (when effort
5997 (setq neffort (org-duration-string-to-minutes effort)
5998 effort (setq effort (concat "[" effort "]")))))
5999 ;; prevent erroring out with %e format when there is no effort
6000 (or effort (setq effort ""))
6002 (when remove-re
6003 (while (string-match remove-re txt)
6004 (setq txt (replace-match "" t t txt))))
6006 ;; Set org-heading property on `txt' to mark the start of the
6007 ;; heading.
6008 (add-text-properties 0 (length txt) '(org-heading t) txt)
6010 ;; Prepare the variables needed in the eval of the compiled format
6011 (setq time (cond (s2 (concat
6012 (org-agenda-time-of-day-to-ampm-maybe s1)
6013 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6014 (if org-agenda-timegrid-use-ampm " ")))
6015 (s1 (concat
6016 (org-agenda-time-of-day-to-ampm-maybe s1)
6017 (if org-agenda-timegrid-use-ampm
6018 "........ "
6019 "......")))
6020 (t ""))
6021 extra (or (and (not habitp) extra) "")
6022 category (if (symbolp category) (symbol-name category) category)
6023 thecategory (copy-sequence category))
6024 (if (string-match org-bracket-link-regexp category)
6025 (progn
6026 (setq l (if (match-end 3)
6027 (- (match-end 3) (match-beginning 3))
6028 (- (match-end 1) (match-beginning 1))))
6029 (when (< l (or org-prefix-category-length 0))
6030 (setq category (copy-sequence category))
6031 (org-add-props category nil
6032 'extra-space (make-string
6033 (- org-prefix-category-length l 1) ?\ ))))
6034 (if (and org-prefix-category-max-length
6035 (>= (length category) org-prefix-category-max-length))
6036 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6037 ;; Evaluate the compiled format
6038 (setq rtn (concat (eval formatter) txt))
6040 ;; And finally add the text properties
6041 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6042 (org-add-props rtn nil
6043 'org-category (if thecategory (downcase thecategory) category)
6044 'tags (mapcar 'org-downcase-keep-props tags)
6045 'org-highest-priority org-highest-priority
6046 'org-lowest-priority org-lowest-priority
6047 'time-of-day time-of-day
6048 'duration duration
6049 'effort effort
6050 'effort-minutes neffort
6051 'txt txt
6052 'time time
6053 'extra extra
6054 'format org-prefix-format-compiled
6055 'dotime dotime)))))
6057 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6058 "Remove tags string from TXT, and add a modified list of tags.
6059 The modified list may contain inherited tags, and tags matched by
6060 `org-agenda-hide-tags-regexp' will be removed."
6061 (when (or add-inherited hide-re)
6062 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6063 (setq txt (substring txt 0 (match-beginning 0))))
6064 (setq tags
6065 (delq nil
6066 (mapcar (lambda (tg)
6067 (if (or (and hide-re (string-match hide-re tg))
6068 (and (not add-inherited)
6069 (get-text-property 0 'inherited tg)))
6071 tg))
6072 tags)))
6073 (when tags
6074 (let ((have-i (get-text-property 0 'inherited (car tags)))
6076 (setq txt (concat txt " :"
6077 (mapconcat
6078 (lambda (x)
6079 (setq i (get-text-property 0 'inherited x))
6080 (if (and have-i (not i))
6081 (progn
6082 (setq have-i nil)
6083 (concat ":" x))
6085 tags ":")
6086 (if have-i "::" ":"))))))
6087 txt)
6089 (defun org-downcase-keep-props (s)
6090 (let ((props (text-properties-at 0 s)))
6091 (setq s (downcase s))
6092 (add-text-properties 0 (length s) props s)
6095 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6096 (defvar org-agenda-sorting-strategy-selected nil)
6098 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6099 (catch 'exit
6100 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6101 ((and todayp (member 'today (car org-agenda-time-grid))))
6102 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6103 ((member 'weekly (car org-agenda-time-grid)))
6104 (t (throw 'exit list)))
6105 (let* ((have (delq nil (mapcar
6106 (lambda (x) (get-text-property 1 'time-of-day x))
6107 list)))
6108 (string (nth 1 org-agenda-time-grid))
6109 (gridtimes (nth 2 org-agenda-time-grid))
6110 (req (car org-agenda-time-grid))
6111 (remove (member 'remove-match req))
6112 new time)
6113 (if (and (member 'require-timed req) (not have))
6114 ;; don't show empty grid
6115 (throw 'exit list))
6116 (while (setq time (pop gridtimes))
6117 (unless (and remove (member time have))
6118 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6119 (push (org-agenda-format-item
6120 nil string "" nil
6121 (concat (substring time 0 -2) ":" (substring time -2)))
6122 new)
6123 (put-text-property
6124 2 (length (car new)) 'face 'org-time-grid (car new))))
6125 (when (and todayp org-agenda-show-current-time-in-grid)
6126 (push (org-agenda-format-item
6128 org-agenda-current-time-string
6129 "" nil
6130 (format-time-string "%H:%M "))
6131 new)
6132 (put-text-property
6133 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6135 (if (member 'time-up org-agenda-sorting-strategy-selected)
6136 (append new list)
6137 (append list new)))))
6139 (defun org-compile-prefix-format (key)
6140 "Compile the prefix format into a Lisp form that can be evaluated.
6141 The resulting form and associated variable bindings is returned
6142 and stored in the variable `org-prefix-format-compiled'."
6143 (setq org-prefix-has-time nil org-prefix-has-tag nil
6144 org-prefix-category-length nil
6145 org-prefix-has-effort nil)
6146 (let ((s (cond
6147 ((stringp org-agenda-prefix-format)
6148 org-agenda-prefix-format)
6149 ((assq key org-agenda-prefix-format)
6150 (cdr (assq key org-agenda-prefix-format)))
6151 (t " %-12:c%?-12t% s")))
6152 (start 0)
6153 varform vars var e c f opt)
6154 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6155 s start)
6156 (setq var (or (cdr (assoc (match-string 4 s)
6157 '(("c" . category) ("t" . time) ("s" . extra)
6158 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6159 'eval)
6160 c (or (match-string 3 s) "")
6161 opt (match-beginning 1)
6162 start (1+ (match-beginning 0)))
6163 (if (equal var 'time) (setq org-prefix-has-time t))
6164 (if (equal var 'tag) (setq org-prefix-has-tag t))
6165 (if (equal var 'effort) (setq org-prefix-has-effort t))
6166 (setq f (concat "%" (match-string 2 s) "s"))
6167 (when (equal var 'category)
6168 (setq org-prefix-category-length
6169 (floor (abs (string-to-number (match-string 2 s)))))
6170 (setq org-prefix-category-max-length
6171 (let ((x (match-string 2 s)))
6172 (save-match-data
6173 (if (string-match "\\.[0-9]+" x)
6174 (string-to-number (substring (match-string 0 x) 1)))))))
6175 (if (eq var 'eval)
6176 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6177 (if opt
6178 (setq varform
6179 `(if (equal "" ,var)
6181 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6182 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6183 (setq s (replace-match "%s" t nil s))
6184 (push varform vars))
6185 (setq vars (nreverse vars))
6186 (with-current-buffer (or org-agenda-buffer (current-buffer))
6187 (setq org-prefix-format-compiled
6188 (list
6189 `((org-prefix-has-time ,org-prefix-has-time)
6190 (org-prefix-has-tag ,org-prefix-has-tag)
6191 (org-prefix-category-length ,org-prefix-category-length)
6192 (org-prefix-has-effort ,org-prefix-has-effort))
6193 `(format ,s ,@vars))))))
6195 (defun org-set-sorting-strategy (key)
6196 (if (symbolp (car org-agenda-sorting-strategy))
6197 ;; the old format
6198 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6199 (setq org-agenda-sorting-strategy-selected
6200 (or (cdr (assq key org-agenda-sorting-strategy))
6201 (cdr (assq 'agenda org-agenda-sorting-strategy))
6202 '(time-up category-keep priority-down)))))
6204 (defun org-get-time-of-day (s &optional string mod24)
6205 "Check string S for a time of day.
6206 If found, return it as a military time number between 0 and 2400.
6207 If not found, return nil.
6208 The optional STRING argument forces conversion into a 5 character wide string
6209 HH:MM."
6210 (save-match-data
6211 (when
6212 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6213 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6214 (let* ((h (string-to-number (match-string 1 s)))
6215 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6216 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6217 (am-p (equal ampm "am"))
6218 (h1 (cond ((not ampm) h)
6219 ((= h 12) (if am-p 0 12))
6220 (t (+ h (if am-p 0 12)))))
6221 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6222 (mod h1 24) h1))
6223 (t0 (+ (* 100 h2) m))
6224 (t1 (concat (if (>= h1 24) "+" " ")
6225 (if (and org-agenda-time-leading-zero
6226 (< t0 1000)) "0" "")
6227 (if (< t0 100) "0" "")
6228 (if (< t0 10) "0" "")
6229 (int-to-string t0))))
6230 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6232 (defvar org-agenda-before-sorting-filter-function nil
6233 "Function to be applied to agenda items prior to sorting.
6234 Prior to sorting also means just before they are inserted into the agenda.
6236 To aid sorting, you may revisit the original entries and add more text
6237 properties which will later be used by the sorting functions.
6239 The function should take a string argument, an agenda line.
6240 It has access to the text properties in that line, which contain among
6241 other things, the property `org-hd-marker' that points to the entry
6242 where the line comes from. Note that not all lines going into the agenda
6243 have this property, only most.
6245 The function should return the modified string. It is probably best
6246 to ONLY change text properties.
6248 You can also use this function as a filter, by returning nil for lines
6249 you don't want to have in the agenda at all. For this application, you
6250 could bind the variable in the options section of a custom command.")
6252 (defun org-agenda-finalize-entries (list &optional nosort)
6253 "Sort and concatenate the agenda items."
6254 (setq list (mapcar 'org-agenda-highlight-todo list))
6255 (if nosort
6256 list
6257 (when org-agenda-before-sorting-filter-function
6258 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6259 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6261 (defun org-agenda-highlight-todo (x)
6262 (let ((org-done-keywords org-done-keywords-for-agenda)
6263 (case-fold-search nil)
6265 (if (eq x 'line)
6266 (save-excursion
6267 (beginning-of-line 1)
6268 (setq re (org-get-at-bol 'org-todo-regexp))
6269 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6270 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6271 (add-text-properties (match-beginning 0) (match-end 1)
6272 (list 'face (org-get-todo-face 1)))
6273 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6274 (delete-region (match-beginning 1) (1- (match-end 0)))
6275 (goto-char (match-beginning 1))
6276 (insert (format org-agenda-todo-keyword-format s)))))
6277 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6278 (setq re (get-text-property 0 'org-todo-regexp x))
6279 (when (and re
6280 ;; Test `pl' because if there's no heading content,
6281 ;; there's no point matching to highlight. Note
6282 ;; that if we didn't test `pl' first, and there
6283 ;; happened to be no keyword from `org-todo-regexp'
6284 ;; on this heading line, then the `equal' comparison
6285 ;; afterwards would spuriously succeed in the case
6286 ;; where `pl' is nil -- causing an args-out-of-range
6287 ;; error when we try to add text properties to text
6288 ;; that isn't there.
6290 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6291 x pl) pl))
6292 (add-text-properties
6293 (or (match-end 1) (match-end 0)) (match-end 0)
6294 (list 'face (org-get-todo-face (match-string 2 x)))
6296 (when (match-end 1)
6297 (setq x (concat (substring x 0 (match-end 1))
6298 (format org-agenda-todo-keyword-format
6299 (match-string 2 x))
6300 (org-add-props " " (text-properties-at 0 x))
6301 (substring x (match-end 3)))))))
6302 x)))
6304 (defsubst org-cmp-priority (a b)
6305 "Compare the priorities of string A and B."
6306 (let ((pa (or (get-text-property 1 'priority a) 0))
6307 (pb (or (get-text-property 1 'priority b) 0)))
6308 (cond ((> pa pb) +1)
6309 ((< pa pb) -1))))
6311 (defsubst org-cmp-effort (a b)
6312 "Compare the effort values of string A and B."
6313 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6314 (ea (or (get-text-property 1 'effort-minutes a) def))
6315 (eb (or (get-text-property 1 'effort-minutes b) def)))
6316 (cond ((> ea eb) +1)
6317 ((< ea eb) -1))))
6319 (defsubst org-cmp-category (a b)
6320 "Compare the string values of categories of strings A and B."
6321 (let ((ca (or (get-text-property 1 'org-category a) ""))
6322 (cb (or (get-text-property 1 'org-category b) "")))
6323 (cond ((string-lessp ca cb) -1)
6324 ((string-lessp cb ca) +1))))
6326 (defsubst org-cmp-todo-state (a b)
6327 "Compare the todo states of strings A and B."
6328 (let* ((ma (or (get-text-property 1 'org-marker a)
6329 (get-text-property 1 'org-hd-marker a)))
6330 (mb (or (get-text-property 1 'org-marker b)
6331 (get-text-property 1 'org-hd-marker b)))
6332 (fa (and ma (marker-buffer ma)))
6333 (fb (and mb (marker-buffer mb)))
6334 (todo-kwds
6335 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6336 (and fb (with-current-buffer fb org-todo-keywords-1))))
6337 (ta (or (get-text-property 1 'todo-state a) ""))
6338 (tb (or (get-text-property 1 'todo-state b) ""))
6339 (la (- (length (member ta todo-kwds))))
6340 (lb (- (length (member tb todo-kwds))))
6341 (donepa (member ta org-done-keywords-for-agenda))
6342 (donepb (member tb org-done-keywords-for-agenda)))
6343 (cond ((and donepa (not donepb)) -1)
6344 ((and (not donepa) donepb) +1)
6345 ((< la lb) -1)
6346 ((< lb la) +1))))
6348 (defsubst org-cmp-alpha (a b)
6349 "Compare the headlines, alphabetically."
6350 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6351 (plb (text-property-any 0 (length b) 'org-heading t b))
6352 (ta (and pla (substring a pla)))
6353 (tb (and plb (substring b plb))))
6354 (when pla
6355 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6356 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6357 (setq ta (substring ta (match-end 0))))
6358 (setq ta (downcase ta)))
6359 (when plb
6360 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6361 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6362 (setq tb (substring tb (match-end 0))))
6363 (setq tb (downcase tb)))
6364 (cond ((not ta) +1)
6365 ((not tb) -1)
6366 ((string-lessp ta tb) -1)
6367 ((string-lessp tb ta) +1))))
6369 (defsubst org-cmp-tag (a b)
6370 "Compare the string values of the first tags of A and B."
6371 (let ((ta (car (last (get-text-property 1 'tags a))))
6372 (tb (car (last (get-text-property 1 'tags b)))))
6373 (cond ((not ta) +1)
6374 ((not tb) -1)
6375 ((string-lessp ta tb) -1)
6376 ((string-lessp tb ta) +1))))
6378 (defsubst org-cmp-time (a b)
6379 "Compare the time-of-day values of strings A and B."
6380 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6381 (ta (or (get-text-property 1 'time-of-day a) def))
6382 (tb (or (get-text-property 1 'time-of-day b) def)))
6383 (cond ((< ta tb) -1)
6384 ((< tb ta) +1))))
6386 (defsubst org-cmp-habit-p (a b)
6387 "Compare the todo states of strings A and B."
6388 (let ((ha (get-text-property 1 'org-habit-p a))
6389 (hb (get-text-property 1 'org-habit-p b)))
6390 (cond ((and ha (not hb)) -1)
6391 ((and (not ha) hb) +1))))
6393 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6395 (defun org-entries-lessp (a b)
6396 "Predicate for sorting agenda entries."
6397 ;; The following variables will be used when the form is evaluated.
6398 ;; So even though the compiler complains, keep them.
6399 (let* ((ss org-agenda-sorting-strategy-selected)
6400 (time-up (and (org-em 'time-up 'time-down ss)
6401 (org-cmp-time a b)))
6402 (time-down (if time-up (- time-up) nil))
6403 (priority-up (and (org-em 'priority-up 'priority-down ss)
6404 (org-cmp-priority a b)))
6405 (priority-down (if priority-up (- priority-up) nil))
6406 (effort-up (and (org-em 'effort-up 'effort-down ss)
6407 (org-cmp-effort a b)))
6408 (effort-down (if effort-up (- effort-up) nil))
6409 (category-up (and (or (org-em 'category-up 'category-down ss)
6410 (memq 'category-keep ss))
6411 (org-cmp-category a b)))
6412 (category-down (if category-up (- category-up) nil))
6413 (category-keep (if category-up +1 nil))
6414 (tag-up (and (org-em 'tag-up 'tag-down ss)
6415 (org-cmp-tag a b)))
6416 (tag-down (if tag-up (- tag-up) nil))
6417 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6418 (org-cmp-todo-state a b)))
6419 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6420 (habit-up (and (org-em 'habit-up 'habit-down ss)
6421 (org-cmp-habit-p a b)))
6422 (habit-down (if habit-up (- habit-up) nil))
6423 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6424 (org-cmp-alpha a b)))
6425 (alpha-down (if alpha-up (- alpha-up) nil))
6426 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6427 user-defined-up user-defined-down)
6428 (if (and need-user-cmp org-agenda-cmp-user-defined
6429 (functionp org-agenda-cmp-user-defined))
6430 (setq user-defined-up
6431 (funcall org-agenda-cmp-user-defined a b)
6432 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6433 (cdr (assoc
6434 (eval (cons 'or org-agenda-sorting-strategy-selected))
6435 '((-1 . t) (1 . nil) (nil . nil))))))
6437 ;;; Agenda restriction lock
6439 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6440 "Overlay to mark the headline to which agenda commands are restricted.")
6441 (overlay-put org-agenda-restriction-lock-overlay
6442 'face 'org-agenda-restriction-lock)
6443 (overlay-put org-agenda-restriction-lock-overlay
6444 'help-echo "Agendas are currently limited to this subtree.")
6445 (org-detach-overlay org-agenda-restriction-lock-overlay)
6447 (defun org-agenda-set-restriction-lock (&optional type)
6448 "Set restriction lock for agenda, to current subtree or file.
6449 Restriction will be the file if TYPE is `file', or if type is the
6450 universal prefix '(4), or if the cursor is before the first headline
6451 in the file. Otherwise, restriction will be to the current subtree."
6452 (interactive "P")
6453 (and (equal type '(4)) (setq type 'file))
6454 (setq type (cond
6455 (type type)
6456 ((org-at-heading-p) 'subtree)
6457 ((condition-case nil (org-back-to-heading t) (error nil))
6458 'subtree)
6459 (t 'file)))
6460 (if (eq type 'subtree)
6461 (progn
6462 (setq org-agenda-restrict t)
6463 (setq org-agenda-overriding-restriction 'subtree)
6464 (put 'org-agenda-files 'org-restrict
6465 (list (buffer-file-name (buffer-base-buffer))))
6466 (org-back-to-heading t)
6467 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6468 (move-marker org-agenda-restrict-begin (point))
6469 (move-marker org-agenda-restrict-end
6470 (save-excursion (org-end-of-subtree t)))
6471 (message "Locking agenda restriction to subtree"))
6472 (put 'org-agenda-files 'org-restrict
6473 (list (buffer-file-name (buffer-base-buffer))))
6474 (setq org-agenda-restrict nil)
6475 (setq org-agenda-overriding-restriction 'file)
6476 (move-marker org-agenda-restrict-begin nil)
6477 (move-marker org-agenda-restrict-end nil)
6478 (message "Locking agenda restriction to file"))
6479 (setq current-prefix-arg nil)
6480 (org-agenda-maybe-redo))
6482 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6483 "Remove the agenda restriction lock."
6484 (interactive "P")
6485 (org-detach-overlay org-agenda-restriction-lock-overlay)
6486 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6487 (setq org-agenda-overriding-restriction nil)
6488 (setq org-agenda-restrict nil)
6489 (put 'org-agenda-files 'org-restrict nil)
6490 (move-marker org-agenda-restrict-begin nil)
6491 (move-marker org-agenda-restrict-end nil)
6492 (setq current-prefix-arg nil)
6493 (message "Agenda restriction lock removed")
6494 (or noupdate (org-agenda-maybe-redo)))
6496 (defun org-agenda-maybe-redo ()
6497 "If there is any window showing the agenda view, update it."
6498 (let ((w (get-buffer-window org-agenda-buffer-name t))
6499 (w0 (selected-window)))
6500 (when w
6501 (select-window w)
6502 (org-agenda-redo)
6503 (select-window w0)
6504 (if org-agenda-overriding-restriction
6505 (message "Agenda view shifted to new %s restriction"
6506 org-agenda-overriding-restriction)
6507 (message "Agenda restriction lock removed")))))
6509 ;;; Agenda commands
6511 (defun org-agenda-check-type (error &rest types)
6512 "Check if agenda buffer is of allowed type.
6513 If ERROR is non-nil, throw an error, otherwise just return nil."
6514 (if (not org-agenda-type)
6515 (error "No Org agenda currently displayed")
6516 (if (memq org-agenda-type types)
6518 (if error
6519 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6520 nil))))
6522 (defun org-agenda-Quit (&optional arg)
6523 "Exit agenda by removing the window or the buffer."
6524 (interactive)
6525 (if org-agenda-columns-active
6526 (org-columns-quit)
6527 (let ((buf (current-buffer)))
6528 (if (eq org-agenda-window-setup 'other-frame)
6529 (progn
6530 (org-agenda-reset-markers)
6531 (kill-buffer buf)
6532 (org-columns-remove-overlays)
6533 (setq org-agenda-archives-mode nil)
6534 (delete-frame))
6535 (and (not (eq org-agenda-window-setup 'current-window))
6536 (not (one-window-p))
6537 (delete-window))
6538 (org-agenda-reset-markers)
6539 (kill-buffer buf)
6540 (org-columns-remove-overlays)
6541 (setq org-agenda-archives-mode nil)))
6542 ;; Maybe restore the pre-agenda window configuration.
6543 (and org-agenda-restore-windows-after-quit
6544 (not (eq org-agenda-window-setup 'other-frame))
6545 org-agenda-pre-window-conf
6546 (set-window-configuration org-agenda-pre-window-conf)
6547 (setq org-agenda-pre-window-conf nil))))
6549 (defun org-agenda-quit ()
6550 "Exit agenda by killing agenda buffer or burying it when
6551 `org-agenda-sticky' is non-NIL"
6552 (interactive)
6553 (if org-agenda-columns-active
6554 (org-columns-quit)
6555 (if org-agenda-sticky
6556 (let ((buf (current-buffer)))
6557 (if (eq org-agenda-window-setup 'other-frame)
6558 (progn
6559 (delete-frame))
6560 (and (not (eq org-agenda-window-setup 'current-window))
6561 (not (one-window-p))
6562 (delete-window)))
6563 (with-current-buffer buf
6564 (bury-buffer)
6565 ;; Maybe restore the pre-agenda window configuration.
6566 (and org-agenda-restore-windows-after-quit
6567 (not (eq org-agenda-window-setup 'other-frame))
6568 org-agenda-pre-window-conf
6569 (set-window-configuration org-agenda-pre-window-conf)
6570 (setq org-agenda-pre-window-conf nil))))
6571 (org-agenda-Quit))))
6573 (defun org-agenda-exit ()
6574 "Exit agenda by removing the window or the buffer.
6575 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6576 Org-mode buffers visited directly by the user will not be touched."
6577 (interactive)
6578 (org-release-buffers org-agenda-new-buffers)
6579 (setq org-agenda-new-buffers nil)
6580 (org-agenda-Quit))
6582 (defun org-agenda-kill-all-agenda-buffers ()
6583 "Kill all buffers in `org-agena-mode'.
6584 This is used when toggling sticky agendas. You can also explicitly invoke it
6585 with `C-c a C-k'."
6586 (interactive)
6587 (let (blist)
6588 (dolist (buf (buffer-list))
6589 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6590 (push buf blist)))
6591 (mapc 'kill-buffer blist)))
6593 (defun org-agenda-execute (arg)
6594 "Execute another agenda command, keeping same window.
6595 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6596 in the agenda."
6597 (interactive "P")
6598 (let ((org-agenda-window-setup 'current-window))
6599 (org-agenda arg)))
6601 (defun org-agenda-redo (&optional all)
6602 "Rebuild possibly ALL agenda view(s) in the current buffer."
6603 (interactive "P")
6604 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6605 (cpa (unless (eq all t) current-prefix-arg))
6606 (org-agenda-doing-sticky-redo org-agenda-sticky)
6607 (org-agenda-sticky nil)
6608 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6609 org-agenda-buffer-name))
6610 (org-agenda-keep-modes t)
6611 (tag-filter org-agenda-tag-filter)
6612 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6613 (top-cat-filter org-agenda-top-category-filter)
6614 (cat-filter org-agenda-category-filter)
6615 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6616 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6617 (cols org-agenda-columns-active)
6618 (line (org-current-line))
6619 (window-line (- line (org-current-line (window-start))))
6620 (lprops (get 'org-agenda-redo-command 'org-lprops))
6621 (redo-cmd (get-text-property p 'org-redo-cmd))
6622 (last-args (get-text-property p 'org-last-args))
6623 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6624 (org-agenda-overriding-cmd-arguments
6625 (unless (eq all t)
6626 (cond ((listp last-args)
6627 (cons (or cpa (car last-args)) (cdr last-args)))
6628 ((stringp last-args)
6629 last-args))))
6630 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6631 (put 'org-agenda-tag-filter :preset-filter nil)
6632 (put 'org-agenda-category-filter :preset-filter nil)
6633 (and cols (org-columns-quit))
6634 (message "Rebuilding agenda buffer...")
6635 (if serie-redo-cmd
6636 (eval serie-redo-cmd)
6637 (org-let lprops '(eval redo-cmd)))
6638 (setq org-agenda-undo-list nil
6639 org-agenda-pending-undo-list nil)
6640 (message "Rebuilding agenda buffer...done")
6641 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6642 (put 'org-agenda-category-filter :preset-filter cat-preset)
6643 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6644 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6645 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6646 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6647 (org-goto-line line)
6648 (recenter window-line)))
6650 (defvar org-global-tags-completion-table nil)
6651 (defvar org-agenda-filter-form nil)
6652 (defvar org-agenda-filtered-by-category nil)
6654 (defun org-agenda-filter-by-category (strip)
6655 "Keep only those lines in the agenda buffer that have a specific category.
6656 The category is that of the current line."
6657 (interactive "P")
6658 (if (and org-agenda-filtered-by-category
6659 org-agenda-category-filter)
6660 (org-agenda-filter-show-all-cat)
6661 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6662 (if cat (org-agenda-filter-apply
6663 (list (concat (if strip "-" "+") cat)) 'category)
6664 (error "No category at point")))))
6666 (defun org-find-top-category (&optional pos)
6667 (save-excursion
6668 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6669 (if pos (goto-char pos))
6670 ;; Skip up to the topmost parent
6671 (while (ignore-errors (outline-up-heading 1) t))
6672 (ignore-errors
6673 (nth 4 (org-heading-components))))))
6675 (defvar org-agenda-filtered-by-top-category nil)
6677 (defun org-agenda-filter-by-top-category (strip)
6678 "Keep only those lines in the agenda buffer that have a specific category.
6679 The category is that of the current line."
6680 (interactive "P")
6681 (if org-agenda-filtered-by-top-category
6682 (progn
6683 (setq org-agenda-filtered-by-top-category nil
6684 org-agenda-top-category-filter nil)
6685 (org-agenda-filter-show-all-cat))
6686 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6687 (if cat (org-agenda-filter-top-category-apply cat strip)
6688 (error "No top-level category at point")))))
6690 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6691 "Keep only those lines in the agenda buffer that have a specific tag.
6692 The tag is selected with its fast selection letter, as configured.
6693 With prefix argument STRIP, remove all lines that do have the tag.
6694 A lisp caller can specify CHAR. NARROW means that the new tag should be
6695 used to narrow the search - the interactive user can also press `-' or `+'
6696 to switch to narrowing."
6697 (interactive "P")
6698 (let* ((alist org-tag-alist-for-agenda)
6699 (tag-chars (mapconcat
6700 (lambda (x) (if (and (not (symbolp (car x)))
6701 (cdr x))
6702 (char-to-string (cdr x))
6703 ""))
6704 alist ""))
6705 (efforts (org-split-string
6706 (or (cdr (assoc (concat org-effort-property "_ALL")
6707 org-global-properties))
6708 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6709 "")))
6710 (effort-op org-agenda-filter-effort-default-operator)
6711 (effort-prompt "")
6712 (inhibit-read-only t)
6713 (current org-agenda-tag-filter)
6714 maybe-refresh a n tag)
6715 (unless char
6716 (message
6717 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6718 (if narrow "Narrow" "Filter") tag-chars
6719 (if org-agenda-auto-exclude-function "[RET], " ""))
6720 (setq char (read-char-exclusive)))
6721 (when (member char '(?+ ?-))
6722 ;; Narrowing down
6723 (cond ((equal char ?-) (setq strip t narrow t))
6724 ((equal char ?+) (setq strip nil narrow t)))
6725 (message
6726 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6727 (setq char (read-char-exclusive)))
6728 (when (member char '(?< ?> ?= ??))
6729 ;; An effort operator
6730 (setq effort-op (char-to-string char))
6731 (setq alist nil) ; to make sure it will be interpreted as effort.
6732 (unless (equal char ??)
6733 (loop for i from 0 to 9 do
6734 (setq effort-prompt
6735 (concat
6736 effort-prompt " ["
6737 (if (= i 9) "0" (int-to-string (1+ i)))
6738 "]" (nth i efforts))))
6739 (message "Effort%s: %s " effort-op effort-prompt)
6740 (setq char (read-char-exclusive))
6741 (when (or (< char ?0) (> char ?9))
6742 (error "Need 1-9,0 to select effort"))))
6743 (when (equal char ?\t)
6744 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6745 (org-set-local 'org-global-tags-completion-table
6746 (org-global-tags-completion-table)))
6747 (let ((completion-ignore-case t))
6748 (setq tag (org-icompleting-read
6749 "Tag: " org-global-tags-completion-table))))
6750 (cond
6751 ((equal char ?\r)
6752 (org-agenda-filter-show-all-tag)
6753 (when org-agenda-auto-exclude-function
6754 (setq org-agenda-tag-filter '())
6755 (dolist (tag (org-agenda-get-represented-tags))
6756 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6757 (if modifier
6758 (push modifier org-agenda-tag-filter))))
6759 (if (not (null org-agenda-tag-filter))
6760 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6761 (setq maybe-refresh t))
6762 ((equal char ?/)
6763 (org-agenda-filter-show-all-tag)
6764 (when (get 'org-agenda-tag-filter :preset-filter)
6765 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6766 (setq maybe-refresh t))
6767 ((equal char ?. )
6768 (setq org-agenda-tag-filter
6769 (mapcar (lambda(tag) (concat "+" tag))
6770 (org-get-at-bol 'tags)))
6771 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6772 (setq maybe-refresh t))
6773 ((or (equal char ?\ )
6774 (setq a (rassoc char alist))
6775 (and (>= char ?0) (<= char ?9)
6776 (setq n (if (= char ?0) 9 (- char ?0 1))
6777 tag (concat effort-op (nth n efforts))
6778 a (cons tag nil)))
6779 (and (= char ??)
6780 (setq tag "?eff")
6781 a (cons tag nil))
6782 (and tag (setq a (cons tag nil))))
6783 (org-agenda-filter-show-all-tag)
6784 (setq tag (car a))
6785 (setq org-agenda-tag-filter
6786 (cons (concat (if strip "-" "+") tag)
6787 (if narrow current nil)))
6788 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6789 (setq maybe-refresh t))
6790 (t (error "Invalid tag selection character %c" char)))
6791 (when (and maybe-refresh
6792 (eq org-agenda-clockreport-mode 'with-filter))
6793 (org-agenda-redo))))
6795 (defun org-agenda-get-represented-tags ()
6796 "Get a list of all tags currently represented in the agenda."
6797 (let (p tags)
6798 (save-excursion
6799 (goto-char (point-min))
6800 (while (setq p (next-single-property-change (point) 'tags))
6801 (goto-char p)
6802 (mapc (lambda (x) (add-to-list 'tags x))
6803 (get-text-property (point) 'tags))))
6804 tags))
6806 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6807 "Refine the current filter. See `org-agenda-filter-by-tag'."
6808 (interactive "P")
6809 (org-agenda-filter-by-tag strip char 'refine))
6811 (defun org-agenda-filter-make-matcher ()
6812 "Create the form that tests a line for agenda filter."
6813 (let (f f1)
6814 ;; first compute the tag-filter matcher
6815 (dolist (x (delete-dups
6816 (append (get 'org-agenda-tag-filter
6817 :preset-filter) org-agenda-tag-filter)))
6818 (if (member x '("-" "+"))
6819 (setq f1 (if (equal x "-") 'tags '(not tags)))
6820 (if (string-match "[<=>?]" x)
6821 (setq f1 (org-agenda-filter-effort-form x))
6822 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6823 (if (equal (string-to-char x) ?-)
6824 (setq f1 (list 'not f1))))
6825 (push f1 f))
6826 ;; then compute the category-filter matcher
6827 (dolist (x (delete-dups
6828 (append (get 'org-agenda-category-filter
6829 :preset-filter) org-agenda-category-filter)))
6830 (if (equal "-" (substring x 0 1))
6831 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6832 (setq f1 (list 'equal (substring x 1) 'cat)))
6833 (push f1 f))
6834 (cons 'and (nreverse f))))
6836 (defun org-agenda-filter-effort-form (e)
6837 "Return the form to compare the effort of the current line with what E says.
6838 E looks like \"+<2:25\"."
6839 (let (op)
6840 (setq e (substring e 1))
6841 (setq op (string-to-char e) e (substring e 1))
6842 (setq op (cond ((equal op ?<) '<=)
6843 ((equal op ?>) '>=)
6844 ((equal op ??) op)
6845 (t '=)))
6846 (list 'org-agenda-compare-effort (list 'quote op)
6847 (org-duration-string-to-minutes e))))
6849 (defun org-agenda-compare-effort (op value)
6850 "Compare the effort of the current line with VALUE, using OP.
6851 If the line does not have an effort defined, return nil."
6852 (let ((eff (org-get-at-bol 'effort-minutes)))
6853 (if (equal op ??)
6854 (not eff)
6855 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6856 value))))
6858 (defun org-agenda-filter-apply (filter type)
6859 "Set FILTER as the new agenda filter and apply it."
6860 (let (tags cat)
6861 (if (eq type 'tag)
6862 (setq org-agenda-tag-filter filter)
6863 (setq org-agenda-category-filter filter))
6864 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6865 (if (and (eq type 'category)
6866 (not (equal (substring (car filter) 0 1) "-")))
6867 ;; Only set `org-agenda-filtered-by-category' to t
6868 ;; when a unique category is used as the filter
6869 (setq org-agenda-filtered-by-category t))
6870 (org-agenda-set-mode-name)
6871 (save-excursion
6872 (goto-char (point-min))
6873 (while (not (eobp))
6874 (if (org-get-at-bol 'org-marker)
6875 (progn
6876 (setq tags (org-get-at-bol 'tags) ; used in eval
6877 cat (get-text-property (point) 'org-category))
6878 (if (not (eval org-agenda-filter-form))
6879 (org-agenda-filter-hide-line type))
6880 (beginning-of-line 2))
6881 (beginning-of-line 2))))
6882 (if (get-char-property (point) 'invisible)
6883 (ignore-errors (org-agenda-previous-line)))))
6885 (defun org-agenda-filter-top-category-apply (category &optional negative)
6886 "Set FILTER as the new agenda filter and apply it."
6887 (org-agenda-set-mode-name)
6888 (save-excursion
6889 (goto-char (point-min))
6890 (while (not (eobp))
6891 (let* ((pos (org-get-at-bol 'org-hd-marker))
6892 (topcat (and pos (org-find-top-category pos))))
6893 (if (and topcat (funcall (if negative 'identity 'not)
6894 (string= category topcat)))
6895 (org-agenda-filter-hide-line 'category)))
6896 (beginning-of-line 2)))
6897 (if (get-char-property (point) 'invisible)
6898 (org-agenda-previous-line))
6899 (setq org-agenda-top-category-filter category
6900 org-agenda-filtered-by-top-category t))
6902 (defun org-agenda-filter-hide-line (type)
6903 (let (ov)
6904 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6905 (point-at-eol)))
6906 (overlay-put ov 'invisible t)
6907 (overlay-put ov 'type type)
6908 (if (eq type 'tag)
6909 (push ov org-agenda-tag-filter-overlays)
6910 (push ov org-agenda-cat-filter-overlays))))
6912 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6913 (setq pos (or pos (point)))
6914 (save-excursion
6915 (dolist (ov (overlays-at pos))
6916 (when (and (overlay-get ov 'invisible)
6917 (eq (overlay-get ov 'type) 'tag))
6918 (goto-char pos)
6919 (if (< (overlay-start ov) (point-at-eol))
6920 (move-overlay ov (point-at-eol)
6921 (overlay-end ov)))))))
6923 (defun org-agenda-filter-show-all-tag nil
6924 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6925 (setq org-agenda-tag-filter-overlays nil
6926 org-agenda-tag-filter nil
6927 org-agenda-filter-form nil)
6928 (org-agenda-set-mode-name))
6930 (defun org-agenda-filter-show-all-cat nil
6931 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6932 (setq org-agenda-cat-filter-overlays nil
6933 org-agenda-filtered-by-category nil
6934 org-agenda-category-filter nil
6935 org-agenda-filter-form nil)
6936 (org-agenda-set-mode-name))
6938 (defun org-agenda-manipulate-query-add ()
6939 "Manipulate the query by adding a search term with positive selection.
6940 Positive selection means the term must be matched for selection of an entry."
6941 (interactive)
6942 (org-agenda-manipulate-query ?\[))
6943 (defun org-agenda-manipulate-query-subtract ()
6944 "Manipulate the query by adding a search term with negative selection.
6945 Negative selection means term must not be matched for selection of an entry."
6946 (interactive)
6947 (org-agenda-manipulate-query ?\]))
6948 (defun org-agenda-manipulate-query-add-re ()
6949 "Manipulate the query by adding a search regexp with positive selection.
6950 Positive selection means the regexp must match for selection of an entry."
6951 (interactive)
6952 (org-agenda-manipulate-query ?\{))
6953 (defun org-agenda-manipulate-query-subtract-re ()
6954 "Manipulate the query by adding a search regexp with negative selection.
6955 Negative selection means regexp must not match for selection of an entry."
6956 (interactive)
6957 (org-agenda-manipulate-query ?\}))
6958 (defun org-agenda-manipulate-query (char)
6959 (cond
6960 ((memq org-agenda-type '(timeline agenda))
6961 (let ((org-agenda-include-inactive-timestamps t))
6962 (org-agenda-redo))
6963 (message "Display now includes inactive timestamps as well"))
6964 ((eq org-agenda-type 'search)
6965 (org-add-to-string
6966 'org-agenda-query-string
6967 (if org-agenda-last-search-view-search-was-boolean
6968 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6969 (?\{ . " +{}") (?\} . " -{}"))))
6970 " "))
6971 (setq org-agenda-redo-command
6972 (list 'org-search-view
6973 (car (get-text-property (point) 'org-last-args))
6974 org-agenda-query-string
6975 (+ (length org-agenda-query-string)
6976 (if (member char '(?\{ ?\})) 0 1))))
6977 (set-register org-agenda-query-register org-agenda-query-string)
6978 (let ((org-agenda-overriding-arguments
6979 (cdr org-agenda-redo-command)))
6980 (org-agenda-redo)))
6981 (t (error "Cannot manipulate query for %s-type agenda buffers"
6982 org-agenda-type))))
6984 (defun org-add-to-string (var string)
6985 (set var (concat (symbol-value var) string)))
6987 (defun org-agenda-goto-date (span)
6988 "Jump to DATE in agenda."
6989 (interactive "P")
6990 (let* ((org-read-date-prefer-future
6991 (eval org-agenda-jump-prefer-future))
6992 (date (org-read-date))
6993 (org-agenda-sticky-orig org-agenda-sticky)
6994 (org-agenda-buffer-tmp-name (buffer-name))
6995 (args (get-text-property (point) 'org-last-args))
6996 (0-arg (or current-prefix-arg (car args)))
6997 (2-arg (nth 2 args))
6998 (newcmd (list 'org-agenda-list 0-arg date
6999 (org-agenda-span-to-ndays 2-arg)))
7000 (newargs (cdr newcmd))
7001 (inhibit-read-only t)
7002 org-agenda-sticky)
7003 (if (not (org-agenda-check-type t 'agenda))
7004 (error "Not available in non-agenda blocks")
7005 (add-text-properties (point-min) (point-max)
7006 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7007 (org-agenda-redo)
7008 (setq org-agenda-sticky org-agenda-sticky-orig
7009 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7011 (defun org-agenda-goto-today ()
7012 "Go to today."
7013 (interactive)
7014 (org-agenda-check-type t 'timeline 'agenda)
7015 (let* ((args (get-text-property (point) 'org-last-args))
7016 (curspan (nth 2 args))
7017 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7018 (cond
7019 (tdpos (goto-char tdpos))
7020 ((eq org-agenda-type 'agenda)
7021 (let* ((sd (org-agenda-compute-starting-span
7022 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7023 (org-agenda-overriding-arguments args))
7024 (setf (nth 1 org-agenda-overriding-arguments) sd)
7025 (org-agenda-redo)
7026 (org-agenda-find-same-or-today-or-agenda)))
7027 (t (error "Cannot find today")))))
7029 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7030 (goto-char
7031 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7032 (text-property-any (point-min) (point-max) 'org-today t)
7033 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7034 (and (get-text-property (point) 'org-serie)
7035 (org-agenda-goto-block-beginning))
7036 (point-min))))
7038 (defun org-agenda-goto-block-beginning ()
7039 "Go the agenda block beginning."
7040 (interactive)
7041 (if (not (derived-mode-p 'org-agenda-mode))
7042 (error "Cannot execute this command outside of org-agenda-mode buffers")
7043 (let (dest)
7044 (save-excursion
7045 (unless (looking-at "\\'")
7046 (forward-char))
7047 (let* ((prop 'org-agenda-structural-header)
7048 (p (previous-single-property-change (point) prop))
7049 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7050 (1- (point))) prop)))
7051 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7052 (if (not dest)
7053 (error "Cannot find the beginning of the blog")
7054 (goto-char dest)
7055 (move-beginning-of-line 1)))))
7057 (defun org-agenda-later (arg)
7058 "Go forward in time by thee current span.
7059 With prefix ARG, go forward that many times the current span."
7060 (interactive "p")
7061 (org-agenda-check-type t 'agenda)
7062 (let* ((args (get-text-property (point) 'org-last-args))
7063 (span (or (nth 2 args) org-agenda-current-span))
7064 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7065 (greg (calendar-gregorian-from-absolute sd))
7066 (cnt (org-get-at-bol 'org-day-cnt))
7067 greg2)
7068 (cond
7069 ((numberp span)
7070 (setq sd (+ span sd)))
7071 ((eq span 'day)
7072 (setq sd (+ arg sd)))
7073 ((eq span 'week)
7074 (setq sd (+ (* 7 arg) sd)))
7075 ((eq span 'month)
7076 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7077 sd (calendar-absolute-from-gregorian greg2))
7078 (setcar greg2 (1+ (car greg2))))
7079 ((eq span 'year)
7080 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7081 sd (calendar-absolute-from-gregorian greg2))
7082 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7084 (setq sd (+ (* span arg) sd))))
7085 (let ((org-agenda-overriding-cmd
7086 ;; `cmd' may have been set by `org-agenda-run-series' which
7087 ;; uses `org-agenda-overriding-cmd' to decide whether
7088 ;; overriding is allowed for `cmd'
7089 (get-text-property (point) 'org-serie-cmd))
7090 (org-agenda-overriding-arguments
7091 (list (car args) sd span)))
7092 (org-agenda-redo)
7093 (org-agenda-find-same-or-today-or-agenda cnt))))
7095 (defun org-agenda-earlier (arg)
7096 "Go backward in time by the current span.
7097 With prefix ARG, go backward that many times the current span."
7098 (interactive "p")
7099 (org-agenda-later (- arg)))
7101 (defun org-agenda-view-mode-dispatch ()
7102 "Call one of the view mode commands."
7103 (interactive)
7104 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7105 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7106 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7107 (let ((a (read-char-exclusive)))
7108 (case a
7109 (?\ (call-interactively 'org-agenda-reset-view))
7110 (?d (call-interactively 'org-agenda-day-view))
7111 (?w (call-interactively 'org-agenda-week-view))
7112 (?m (call-interactively 'org-agenda-month-view))
7113 (?y (call-interactively 'org-agenda-year-view))
7114 (?l (call-interactively 'org-agenda-log-mode))
7115 (?L (org-agenda-log-mode '(4)))
7116 (?c (org-agenda-log-mode 'clockcheck))
7117 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7118 (?a (call-interactively 'org-agenda-archives-mode))
7119 (?A (org-agenda-archives-mode 'files))
7120 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7121 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7122 (?G (call-interactively 'org-agenda-toggle-time-grid))
7123 (?D (call-interactively 'org-agenda-toggle-diary))
7124 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7125 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7126 (org-agenda-check-type t 'timeline 'agenda)
7127 (org-agenda-redo))
7128 (message "Display now includes inactive timestamps as well"))
7129 (?q (message "Abort"))
7130 (otherwise (error "Invalid key" )))))
7132 (defun org-agenda-reset-view ()
7133 "Switch to default view for agenda."
7134 (interactive)
7135 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7136 (defun org-agenda-day-view (&optional day-of-year)
7137 "Switch to daily view for agenda.
7138 With argument DAY-OF-YEAR, switch to that day of the year."
7139 (interactive "P")
7140 (org-agenda-change-time-span 'day day-of-year))
7141 (defun org-agenda-week-view (&optional iso-week)
7142 "Switch to daily view for agenda.
7143 With argument ISO-WEEK, switch to the corresponding ISO week.
7144 If ISO-WEEK has more then 2 digits, only the last two encode the
7145 week. Any digits before this encode a year. So 200712 means
7146 week 12 of year 2007. Years in the range 1938-2037 can also be
7147 written as 2-digit years."
7148 (interactive "P")
7149 (org-agenda-change-time-span 'week iso-week))
7150 (defun org-agenda-month-view (&optional month)
7151 "Switch to monthly view for agenda.
7152 With argument MONTH, switch to that month."
7153 (interactive "P")
7154 (org-agenda-change-time-span 'month month))
7155 (defun org-agenda-year-view (&optional year)
7156 "Switch to yearly view for agenda.
7157 With argument YEAR, switch to that year.
7158 If MONTH has more then 2 digits, only the last two encode the
7159 month. Any digits before this encode a year. So 200712 means
7160 December year 2007. Years in the range 1938-2037 can also be
7161 written as 2-digit years."
7162 (interactive "P")
7163 (when year
7164 (setq year (org-small-year-to-year year)))
7165 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7166 (org-agenda-change-time-span 'year year)
7167 (error "Abort")))
7169 (defun org-agenda-change-time-span (span &optional n)
7170 "Change the agenda view to SPAN.
7171 SPAN may be `day', `week', `month', `year'."
7172 (org-agenda-check-type t 'agenda)
7173 (let* ((args (get-text-property (point) 'org-last-args))
7174 (curspan (nth 2 args)))
7175 (if (and (not n) (equal curspan span))
7176 (error "Viewing span is already \"%s\"" span))
7177 (let* ((sd (or (org-get-at-bol 'day)
7178 (nth 1 args)
7179 org-starting-day))
7180 (sd (org-agenda-compute-starting-span sd span n))
7181 (org-agenda-overriding-cmd
7182 (get-text-property (point) 'org-serie-cmd))
7183 (org-agenda-overriding-arguments
7184 (list (car args) sd span)))
7185 (org-agenda-redo)
7186 (org-agenda-find-same-or-today-or-agenda))
7187 (org-agenda-set-mode-name)
7188 (message "Switched to %s view" span)))
7190 (defun org-agenda-compute-starting-span (sd span &optional n)
7191 "Compute starting date for agenda.
7192 SPAN may be `day', `week', `month', `year'. The return value
7193 is a cons cell with the starting date and the number of days,
7194 so that the date SD will be in that range."
7195 (let* ((greg (calendar-gregorian-from-absolute sd))
7196 (dg (nth 1 greg))
7197 (mg (car greg))
7198 (yg (nth 2 greg)))
7199 (cond
7200 ((eq span 'day)
7201 (when n
7202 (setq sd (+ (calendar-absolute-from-gregorian
7203 (list mg 1 yg))
7204 n -1))))
7205 ((eq span 'week)
7206 (let* ((nt (calendar-day-of-week
7207 (calendar-gregorian-from-absolute sd)))
7208 (d (if org-agenda-start-on-weekday
7209 (- nt org-agenda-start-on-weekday)
7212 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7213 (when n
7214 (require 'cal-iso)
7215 (when (> n 99)
7216 (setq y1 (org-small-year-to-year (/ n 100))
7217 n (mod n 100)))
7218 (setq sd
7219 (calendar-absolute-from-iso
7220 (list n 1
7221 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7222 ((eq span 'month)
7223 (let (y1)
7224 (when (and n (> n 99))
7225 (setq y1 (org-small-year-to-year (/ n 100))
7226 n (mod n 100)))
7227 (setq sd (calendar-absolute-from-gregorian
7228 (list (or n mg) 1 (or y1 yg))))))
7229 ((eq span 'year)
7230 (setq sd (calendar-absolute-from-gregorian
7231 (list 1 1 (or n yg))))))
7232 sd))
7234 (defun org-agenda-next-date-line (&optional arg)
7235 "Jump to the next line indicating a date in agenda buffer."
7236 (interactive "p")
7237 (org-agenda-check-type t 'agenda 'timeline)
7238 (beginning-of-line 1)
7239 ;; This does not work if user makes date format that starts with a blank
7240 (if (looking-at "^\\S-") (forward-char 1))
7241 (if (not (re-search-forward "^\\S-" nil t arg))
7242 (progn
7243 (backward-char 1)
7244 (error "No next date after this line in this buffer")))
7245 (goto-char (match-beginning 0)))
7247 (defun org-agenda-previous-date-line (&optional arg)
7248 "Jump to the previous line indicating a date in agenda buffer."
7249 (interactive "p")
7250 (org-agenda-check-type t 'agenda 'timeline)
7251 (beginning-of-line 1)
7252 (if (not (re-search-backward "^\\S-" nil t arg))
7253 (error "No previous date before this line in this buffer")))
7255 ;; Initialize the highlight
7256 (defvar org-hl (make-overlay 1 1))
7257 (overlay-put org-hl 'face 'highlight)
7259 (defun org-highlight (begin end &optional buffer)
7260 "Highlight a region with overlay."
7261 (move-overlay org-hl begin end (or buffer (current-buffer))))
7263 (defun org-unhighlight ()
7264 "Detach overlay INDEX."
7265 (org-detach-overlay org-hl))
7267 (defun org-unhighlight-once ()
7268 "Remove the highlight from its position, and this function from the hook."
7269 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7270 (org-unhighlight))
7272 (defun org-agenda-follow-mode ()
7273 "Toggle follow mode in an agenda buffer."
7274 (interactive)
7275 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7276 (org-agenda-set-mode-name)
7277 (org-agenda-do-context-action)
7278 (message "Follow mode is %s"
7279 (if org-agenda-follow-mode "on" "off")))
7281 (defun org-agenda-entry-text-mode (&optional arg)
7282 "Toggle entry text mode in an agenda buffer."
7283 (interactive "P")
7284 (setq org-agenda-entry-text-mode (or (integerp arg)
7285 (not org-agenda-entry-text-mode)))
7286 (org-agenda-entry-text-hide)
7287 (and org-agenda-entry-text-mode
7288 (let ((org-agenda-entry-text-maxlines
7289 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7290 (org-agenda-entry-text-show)))
7291 (org-agenda-set-mode-name)
7292 (message "Entry text mode is %s. Maximum number of lines is %d"
7293 (if org-agenda-entry-text-mode "on" "off")
7294 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7296 (defun org-agenda-clockreport-mode (&optional with-filter)
7297 "Toggle clocktable mode in an agenda buffer.
7298 With prefix arg WITH-FILTER, make the clocktable respect the current
7299 agenda filter."
7300 (interactive "P")
7301 (org-agenda-check-type t 'agenda)
7302 (if with-filter
7303 (setq org-agenda-clockreport-mode 'with-filter)
7304 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7305 (org-agenda-set-mode-name)
7306 (org-agenda-redo)
7307 (message "Clocktable mode is %s"
7308 (if org-agenda-clockreport-mode "on" "off")))
7310 (defun org-agenda-log-mode (&optional special)
7311 "Toggle log mode in an agenda buffer.
7312 With argument SPECIAL, show all possible log items, not only the ones
7313 configured in `org-agenda-log-mode-items'.
7314 With a double `C-u' prefix arg, show *only* log items, nothing else."
7315 (interactive "P")
7316 (org-agenda-check-type t 'agenda 'timeline)
7317 (setq org-agenda-show-log
7318 (cond
7319 ((equal special '(16)) 'only)
7320 ((eq special 'clockcheck)
7321 (if (eq org-agenda-show-log 'clockcheck)
7322 nil 'clockcheck))
7323 (special '(closed clock state))
7324 (t (not org-agenda-show-log))))
7325 (org-agenda-set-mode-name)
7326 (org-agenda-redo)
7327 (message "Log mode is %s"
7328 (if org-agenda-show-log "on" "off")))
7330 (defun org-agenda-archives-mode (&optional with-files)
7331 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7332 When called with a prefix argument, include all archive files as well."
7333 (interactive "P")
7334 (setq org-agenda-archives-mode
7335 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7336 (org-agenda-set-mode-name)
7337 (org-agenda-redo)
7338 (message
7339 "%s"
7340 (cond
7341 ((eq org-agenda-archives-mode nil)
7342 "No archives are included")
7343 ((eq org-agenda-archives-mode 'trees)
7344 (format "Trees with :%s: tag are included" org-archive-tag))
7345 ((eq org-agenda-archives-mode t)
7346 (format "Trees with :%s: tag and all active archive files are included"
7347 org-archive-tag)))))
7349 (defun org-agenda-toggle-diary ()
7350 "Toggle diary inclusion in an agenda buffer."
7351 (interactive)
7352 (org-agenda-check-type t 'agenda)
7353 (setq org-agenda-include-diary (not org-agenda-include-diary))
7354 (org-agenda-redo)
7355 (org-agenda-set-mode-name)
7356 (message "Diary inclusion turned %s"
7357 (if org-agenda-include-diary "on" "off")))
7359 (defun org-agenda-toggle-deadlines ()
7360 "Toggle inclusion of entries with a deadline in an agenda buffer."
7361 (interactive)
7362 (org-agenda-check-type t 'agenda)
7363 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7364 (org-agenda-redo)
7365 (org-agenda-set-mode-name)
7366 (message "Deadlines inclusion turned %s"
7367 (if org-agenda-include-deadlines "on" "off")))
7369 (defun org-agenda-toggle-time-grid ()
7370 "Toggle time grid in an agenda buffer."
7371 (interactive)
7372 (org-agenda-check-type t 'agenda)
7373 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7374 (org-agenda-redo)
7375 (org-agenda-set-mode-name)
7376 (message "Time-grid turned %s"
7377 (if org-agenda-use-time-grid "on" "off")))
7379 (defun org-agenda-set-mode-name ()
7380 "Set the mode name to indicate all the small mode settings."
7381 (setq mode-name
7382 (list "Org-Agenda"
7383 (if (get 'org-agenda-files 'org-restrict) " []" "")
7385 '(:eval (org-agenda-span-name org-agenda-current-span))
7386 (if org-agenda-follow-mode " Follow" "")
7387 (if org-agenda-entry-text-mode " ETxt" "")
7388 (if org-agenda-include-diary " Diary" "")
7389 (if org-agenda-include-deadlines " Ddl" "")
7390 (if org-agenda-use-time-grid " Grid" "")
7391 (if (and (boundp 'org-habit-show-habits)
7392 org-habit-show-habits) " Habit" "")
7393 (cond
7394 ((consp org-agenda-show-log) " LogAll")
7395 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7396 (org-agenda-show-log " Log")
7397 (t ""))
7398 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7399 :preset-filter))
7400 '(:eval (org-propertize
7401 (concat " <"
7402 (mapconcat
7403 'identity
7404 (append
7405 (get 'org-agenda-category-filter :preset-filter)
7406 org-agenda-category-filter)
7408 ">")
7409 'face 'org-agenda-filter-category
7410 'help-echo "Category used in filtering"))
7412 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7413 :preset-filter))
7414 '(:eval (org-propertize
7415 (concat " {"
7416 (mapconcat
7417 'identity
7418 (append
7419 (get 'org-agenda-tag-filter :preset-filter)
7420 org-agenda-tag-filter)
7422 "}")
7423 'face 'org-agenda-filter-tags
7424 'help-echo "Tags used in filtering"))
7426 (if org-agenda-archives-mode
7427 (if (eq org-agenda-archives-mode t)
7428 " Archives"
7429 (format " :%s:" org-archive-tag))
7431 (if org-agenda-clockreport-mode
7432 (if (eq org-agenda-clockreport-mode 'with-filter)
7433 " Clock{}" " Clock")
7434 "")))
7435 (force-mode-line-update))
7437 (defun org-agenda-post-command-hook ()
7438 (setq org-agenda-type
7439 (or (get-text-property (point) 'org-agenda-type)
7440 (get-text-property (max (point-min) (1- (point)))
7441 'org-agenda-type))))
7443 (defun org-agenda-next-line ()
7444 "Move cursor to the next line, and show if follow mode is active."
7445 (interactive)
7446 (call-interactively 'next-line)
7447 (org-agenda-do-context-action))
7449 (defun org-agenda-previous-line ()
7450 "Move cursor to the previous line, and show if follow-mode is active."
7451 (interactive)
7452 (call-interactively 'previous-line)
7453 (org-agenda-do-context-action))
7455 (defun org-agenda-next-item (n)
7456 "Move cursor to next agenda item."
7457 (interactive "p")
7458 (let ((col (current-column)))
7459 (dotimes (c n)
7460 (when (next-single-property-change (point-at-eol) 'org-marker)
7461 (move-end-of-line 1)
7462 (goto-char (next-single-property-change (point) 'org-marker))))
7463 (org-move-to-column col))
7464 (org-agenda-do-context-action))
7466 (defun org-agenda-previous-item (n)
7467 "Move cursor to next agenda item."
7468 (interactive "p")
7469 (dotimes (c n)
7470 (let ((col (current-column))
7471 (goto (save-excursion
7472 (move-end-of-line 0)
7473 (previous-single-property-change (point) 'org-marker))))
7474 (if goto (goto-char goto))
7475 (org-move-to-column col)))
7476 (org-agenda-do-context-action))
7478 (defun org-agenda-do-context-action ()
7479 "Show outline path and, maybe, follow mode window."
7480 (let ((m (org-get-at-bol 'org-marker)))
7481 (when (and (markerp m) (marker-buffer m))
7482 (and org-agenda-follow-mode
7483 (if org-agenda-follow-indirect
7484 (org-agenda-tree-to-indirect-buffer)
7485 (org-agenda-show)))
7486 (and org-agenda-show-outline-path
7487 (org-with-point-at m (org-display-outline-path t))))))
7489 (defun org-agenda-show-priority ()
7490 "Show the priority of the current item.
7491 This priority is composed of the main priority given with the [#A] cookies,
7492 and by additional input from the age of a schedules or deadline entry."
7493 (interactive)
7494 (let* ((pri (org-get-at-bol 'priority)))
7495 (message "Priority is %d" (if pri pri -1000))))
7497 (defun org-agenda-show-tags ()
7498 "Show the tags applicable to the current item."
7499 (interactive)
7500 (let* ((tags (org-get-at-bol 'tags)))
7501 (if tags
7502 (message "Tags are :%s:"
7503 (org-no-properties (mapconcat 'identity tags ":")))
7504 (message "No tags associated with this line"))))
7506 (defun org-agenda-goto (&optional highlight)
7507 "Go to the Org-mode file which contains the item at point."
7508 (interactive)
7509 (let* ((marker (or (org-get-at-bol 'org-marker)
7510 (org-agenda-error)))
7511 (buffer (marker-buffer marker))
7512 (pos (marker-position marker)))
7513 (switch-to-buffer-other-window buffer)
7514 (widen)
7515 (push-mark)
7516 (goto-char pos)
7517 (when (derived-mode-p 'org-mode)
7518 (org-show-context 'agenda)
7519 (save-excursion
7520 (and (outline-next-heading)
7521 (org-flag-heading nil)))) ; show the next heading
7522 (when (outline-invisible-p)
7523 (show-entry)) ; display invisible text
7524 (recenter (/ (window-height) 2))
7525 (run-hooks 'org-agenda-after-show-hook)
7526 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7528 (defvar org-agenda-after-show-hook nil
7529 "Normal hook run after an item has been shown from the agenda.
7530 Point is in the buffer where the item originated.")
7532 (defun org-agenda-kill ()
7533 "Kill the entry or subtree belonging to the current agenda entry."
7534 (interactive)
7535 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7536 (let* ((bufname-orig (buffer-name))
7537 (marker (or (org-get-at-bol 'org-marker)
7538 (org-agenda-error)))
7539 (buffer (marker-buffer marker))
7540 (pos (marker-position marker))
7541 (type (org-get-at-bol 'type))
7542 dbeg dend (n 0) conf)
7543 (org-with-remote-undo buffer
7544 (with-current-buffer buffer
7545 (save-excursion
7546 (goto-char pos)
7547 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7548 (setq dbeg (progn (org-back-to-heading t) (point))
7549 dend (org-end-of-subtree t t))
7550 (setq dbeg (point-at-bol)
7551 dend (min (point-max) (1+ (point-at-eol)))))
7552 (goto-char dbeg)
7553 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7554 (setq conf (or (eq t org-agenda-confirm-kill)
7555 (and (numberp org-agenda-confirm-kill)
7556 (> n org-agenda-confirm-kill))))
7557 (and conf
7558 (not (y-or-n-p
7559 (format "Delete entry with %d lines in buffer \"%s\"? "
7560 n (buffer-name buffer))))
7561 (error "Abort"))
7562 (let ((org-agenda-buffer-name bufname-orig))
7563 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7564 (with-current-buffer buffer (delete-region dbeg dend))
7565 (message "Agenda item and source killed"))))
7567 (defvar org-archive-default-command) ; defined in org-archive.el
7568 (defun org-agenda-archive-default ()
7569 "Archive the entry or subtree belonging to the current agenda entry."
7570 (interactive)
7571 (require 'org-archive)
7572 (org-agenda-archive-with org-archive-default-command))
7574 (defun org-agenda-archive-default-with-confirmation ()
7575 "Archive the entry or subtree belonging to the current agenda entry."
7576 (interactive)
7577 (require 'org-archive)
7578 (org-agenda-archive-with org-archive-default-command 'confirm))
7580 (defun org-agenda-archive ()
7581 "Archive the entry or subtree belonging to the current agenda entry."
7582 (interactive)
7583 (org-agenda-archive-with 'org-archive-subtree))
7585 (defun org-agenda-archive-to-archive-sibling ()
7586 "Move the entry to the archive sibling."
7587 (interactive)
7588 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7590 (defun org-agenda-archive-with (cmd &optional confirm)
7591 "Move the entry to the archive sibling."
7592 (interactive)
7593 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7594 (let* ((bufname-orig (buffer-name))
7595 (marker (or (org-get-at-bol 'org-marker)
7596 (org-agenda-error)))
7597 (buffer (marker-buffer marker))
7598 (pos (marker-position marker)))
7599 (org-with-remote-undo buffer
7600 (with-current-buffer buffer
7601 (if (derived-mode-p 'org-mode)
7602 (if (and confirm
7603 (not (y-or-n-p "Archive this subtree or entry? ")))
7604 (error "Abort")
7605 (save-excursion
7606 (goto-char pos)
7607 (let ((org-agenda-buffer-name bufname-orig))
7608 (org-remove-subtree-entries-from-agenda))
7609 (org-back-to-heading t)
7610 (funcall cmd)))
7611 (error "Archiving works only in Org-mode files"))))))
7613 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7614 "Remove all lines in the agenda that correspond to a given subtree.
7615 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7616 If this information is not given, the function uses the tree at point."
7617 (let ((buf (or buf (current-buffer))) m p)
7618 (save-excursion
7619 (unless (and beg end)
7620 (org-back-to-heading t)
7621 (setq beg (point))
7622 (org-end-of-subtree t)
7623 (setq end (point)))
7624 (set-buffer (get-buffer org-agenda-buffer-name))
7625 (save-excursion
7626 (goto-char (point-max))
7627 (beginning-of-line 1)
7628 (while (not (bobp))
7629 (when (and (setq m (org-get-at-bol 'org-marker))
7630 (equal buf (marker-buffer m))
7631 (setq p (marker-position m))
7632 (>= p beg)
7633 (< p end))
7634 (let ((inhibit-read-only t))
7635 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7636 (beginning-of-line 0))))))
7638 (defun org-agenda-refile (&optional goto rfloc no-update)
7639 "Refile the item at point."
7640 (interactive "P")
7641 (if (equal goto '(16))
7642 (org-refile-goto-last-stored)
7643 (let* ((buffer-orig (buffer-name))
7644 (marker (or (org-get-at-bol 'org-hd-marker)
7645 (org-agenda-error)))
7646 (buffer (marker-buffer marker))
7647 (pos (marker-position marker))
7648 (rfloc (or rfloc
7649 (org-refile-get-location
7650 (if goto "Goto" "Refile to") buffer
7651 org-refile-allow-creating-parent-nodes))))
7652 (with-current-buffer buffer
7653 (save-excursion
7654 (save-restriction
7655 (widen)
7656 (goto-char marker)
7657 (let ((org-agenda-buffer-name buffer-orig))
7658 (org-remove-subtree-entries-from-agenda))
7659 (org-refile goto buffer rfloc)))))
7660 (unless no-update (org-agenda-redo))))
7662 (defun org-agenda-open-link (&optional arg)
7663 "Follow the link in the current line, if any.
7664 This looks for a link in the displayed line in the agenda. It also looks
7665 at the text of the entry itself."
7666 (interactive "P")
7667 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7668 (org-get-at-bol 'org-marker)))
7669 (buffer (and marker (marker-buffer marker)))
7670 (prefix (buffer-substring
7671 (point-at-bol) (point-at-eol))))
7672 (cond
7673 (buffer
7674 (with-current-buffer buffer
7675 (save-excursion
7676 (save-restriction
7677 (widen)
7678 (goto-char marker)
7679 (org-offer-links-in-entry arg prefix)))))
7680 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7681 (save-excursion
7682 (beginning-of-line 1)
7683 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7684 (org-open-link-from-string (match-string 1)))
7685 (t (error "No link to open here")))))
7687 (defun org-agenda-copy-local-variable (var)
7688 "Get a variable from a referenced buffer and install it here."
7689 (let ((m (org-get-at-bol 'org-marker)))
7690 (when (and m (buffer-live-p (marker-buffer m)))
7691 (org-set-local var (with-current-buffer (marker-buffer m)
7692 (symbol-value var))))))
7694 (defun org-agenda-switch-to (&optional delete-other-windows)
7695 "Go to the Org-mode file which contains the item at point."
7696 (interactive)
7697 (if (and org-return-follows-link
7698 (not (org-get-at-bol 'org-marker))
7699 (org-in-regexp org-bracket-link-regexp))
7700 (org-open-link-from-string (match-string 0))
7701 (let* ((marker (or (org-get-at-bol 'org-marker)
7702 (org-agenda-error)))
7703 (buffer (marker-buffer marker))
7704 (pos (marker-position marker)))
7705 (org-pop-to-buffer-same-window buffer)
7706 (and delete-other-windows (delete-other-windows))
7707 (widen)
7708 (goto-char pos)
7709 (when (derived-mode-p 'org-mode)
7710 (org-show-context 'agenda)
7711 (save-excursion
7712 (and (outline-next-heading)
7713 (org-flag-heading nil))) ; show the next heading
7714 (when (outline-invisible-p)
7715 (show-entry)) ; display invisible text
7716 (run-hooks 'org-agenda-after-show-hook)))))
7718 (defun org-agenda-goto-mouse (ev)
7719 "Go to the Org-mode file which contains the item at the mouse click."
7720 (interactive "e")
7721 (mouse-set-point ev)
7722 (org-agenda-goto))
7724 (defun org-agenda-show (&optional full-entry)
7725 "Display the Org-mode file which contains the item at point.
7726 With prefix argument FULL-ENTRY, make the entire entry visible
7727 if it was hidden in the outline."
7728 (interactive "P")
7729 (let ((win (selected-window)))
7730 (if full-entry
7731 (let ((org-show-entry-below t))
7732 (org-agenda-goto t))
7733 (org-agenda-goto t))
7734 (select-window win)))
7736 (defvar org-agenda-show-window nil)
7737 (defun org-agenda-show-and-scroll-up (&optional arg)
7738 "Display the Org-mode file which contains the item at point.
7739 When called repeatedly, scroll the window that is displaying the buffer.
7740 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7741 `show-subtree' to display the item, so that drawers and logbooks stay
7742 folded."
7743 (interactive "P")
7744 (let ((win (selected-window)))
7745 (if (and (window-live-p org-agenda-show-window)
7746 (eq this-command last-command))
7747 (progn
7748 (select-window org-agenda-show-window)
7749 (ignore-errors (scroll-up)))
7750 (org-agenda-goto t)
7751 (if arg (org-show-entry) (show-subtree))
7752 (setq org-agenda-show-window (selected-window)))
7753 (select-window win)))
7755 (defun org-agenda-show-scroll-down ()
7756 "Scroll down the window showing the agenda."
7757 (interactive)
7758 (let ((win (selected-window)))
7759 (when (window-live-p org-agenda-show-window)
7760 (select-window org-agenda-show-window)
7761 (ignore-errors (scroll-down))
7762 (select-window win))))
7764 (defun org-agenda-show-1 (&optional more)
7765 "Display the Org-mode file which contains the item at point.
7766 The prefix arg selects the amount of information to display:
7768 0 hide the subtree
7769 1 just show the entry according to defaults.
7770 2 show the children view
7771 3 show the subtree view
7772 4 show the entire subtree and any LOGBOOK drawers
7773 5 show the entire subtree and any drawers
7774 With prefix argument FULL-ENTRY, make the entire entry visible
7775 if it was hidden in the outline."
7776 (interactive "p")
7777 (let ((win (selected-window)))
7778 (org-agenda-goto t)
7779 (org-recenter-heading 1)
7780 (cond
7781 ((= more 0)
7782 (hide-subtree)
7783 (save-excursion
7784 (org-back-to-heading)
7785 (run-hook-with-args 'org-cycle-hook 'folded))
7786 (message "Remote: FOLDED"))
7787 ((and (org-called-interactively-p 'any) (= more 1))
7788 (message "Remote: show with default settings"))
7789 ((= more 2)
7790 (show-entry)
7791 (show-children)
7792 (save-excursion
7793 (org-back-to-heading)
7794 (run-hook-with-args 'org-cycle-hook 'children))
7795 (message "Remote: CHILDREN"))
7796 ((= more 3)
7797 (show-subtree)
7798 (save-excursion
7799 (org-back-to-heading)
7800 (run-hook-with-args 'org-cycle-hook 'subtree))
7801 (message "Remote: SUBTREE"))
7802 ((= more 4)
7803 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7804 (org-drawer-regexp
7805 (concat "^[ \t]*:\\("
7806 (mapconcat 'regexp-quote org-drawers "\\|")
7807 "\\):[ \t]*$")))
7808 (show-subtree)
7809 (save-excursion
7810 (org-back-to-heading)
7811 (org-cycle-hide-drawers 'subtree)))
7812 (message "Remote: SUBTREE AND LOGBOOK"))
7813 ((> more 4)
7814 (show-subtree)
7815 (message "Remote: SUBTREE AND ALL DRAWERS")))
7816 (select-window win)))
7818 (defun org-recenter-heading (n)
7819 (save-excursion
7820 (org-back-to-heading)
7821 (recenter n)))
7823 (defvar org-agenda-cycle-counter nil)
7824 (defun org-agenda-cycle-show (&optional n)
7825 "Show the current entry in another window, with default settings.
7826 Default settings are taken from `org-show-hierarchy-above' and siblings.
7827 When use repeatedly in immediate succession, the remote entry will cycle
7828 through visibility
7830 children -> subtree -> folded
7832 When called with a numeric prefix arg, that arg will be passed through to
7833 `org-agenda-show-1'. For the interpretation of that argument, see the
7834 docstring of `org-agenda-show-1'."
7835 (interactive "P")
7836 (if (integerp n)
7837 (setq org-agenda-cycle-counter n)
7838 (if (not (eq last-command this-command))
7839 (setq org-agenda-cycle-counter 1)
7840 (if (equal org-agenda-cycle-counter 0)
7841 (setq org-agenda-cycle-counter 2)
7842 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7843 (if (> org-agenda-cycle-counter 3)
7844 (setq org-agenda-cycle-counter 0)))))
7845 (org-agenda-show-1 org-agenda-cycle-counter))
7847 (defun org-agenda-recenter (arg)
7848 "Display the Org-mode file which contains the item at point and recenter."
7849 (interactive "P")
7850 (let ((win (selected-window)))
7851 (org-agenda-goto t)
7852 (recenter arg)
7853 (select-window win)))
7855 (defun org-agenda-show-mouse (ev)
7856 "Display the Org-mode file which contains the item at the mouse click."
7857 (interactive "e")
7858 (mouse-set-point ev)
7859 (org-agenda-show))
7861 (defun org-agenda-check-no-diary ()
7862 "Check if the entry is a diary link and abort if yes."
7863 (if (org-get-at-bol 'org-agenda-diary-link)
7864 (org-agenda-error)))
7866 (defun org-agenda-error ()
7867 (error "Command not allowed in this line"))
7869 (defun org-agenda-tree-to-indirect-buffer ()
7870 "Show the subtree corresponding to the current entry in an indirect buffer.
7871 This calls the command `org-tree-to-indirect-buffer' from the original
7872 Org-mode buffer.
7873 With numerical prefix arg ARG, go up to this level and then take that tree.
7874 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7875 use the dedicated frame)."
7876 (interactive)
7877 (if (and current-prefix-arg (listp current-prefix-arg))
7878 (org-agenda-do-tree-to-indirect-buffer)
7879 (let ((agenda-window (selected-window))
7880 (indirect-window
7881 (and org-last-indirect-buffer
7882 (get-buffer-window org-last-indirect-buffer))))
7883 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7884 (unwind-protect
7885 (progn
7886 (unless (and indirect-window (window-live-p indirect-window))
7887 (setq indirect-window (split-window agenda-window)))
7888 (select-window indirect-window)
7889 (switch-to-buffer org-last-indirect-buffer :norecord)
7890 (fit-window-to-buffer indirect-window))
7891 (select-window (get-buffer-window org-agenda-buffer-name))))))
7893 (defun org-agenda-do-tree-to-indirect-buffer ()
7894 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7895 (org-agenda-check-no-diary)
7896 (let* ((marker (or (org-get-at-bol 'org-marker)
7897 (org-agenda-error)))
7898 (buffer (marker-buffer marker))
7899 (pos (marker-position marker)))
7900 (with-current-buffer buffer
7901 (save-excursion
7902 (goto-char pos)
7903 (call-interactively 'org-tree-to-indirect-buffer)))))
7905 (defvar org-last-heading-marker (make-marker)
7906 "Marker pointing to the headline that last changed its TODO state
7907 by a remote command from the agenda.")
7909 (defun org-agenda-todo-nextset ()
7910 "Switch TODO entry to next sequence."
7911 (interactive)
7912 (org-agenda-todo 'nextset))
7914 (defun org-agenda-todo-previousset ()
7915 "Switch TODO entry to previous sequence."
7916 (interactive)
7917 (org-agenda-todo 'previousset))
7919 (defun org-agenda-todo (&optional arg)
7920 "Cycle TODO state of line at point, also in Org-mode file.
7921 This changes the line at point, all other lines in the agenda referring to
7922 the same tree node, and the headline of the tree node in the Org-mode file."
7923 (interactive "P")
7924 (org-agenda-check-no-diary)
7925 (let* ((col (current-column))
7926 (marker (or (org-get-at-bol 'org-marker)
7927 (org-agenda-error)))
7928 (buffer (marker-buffer marker))
7929 (pos (marker-position marker))
7930 (hdmarker (org-get-at-bol 'org-hd-marker))
7931 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7932 (inhibit-read-only t)
7933 org-agenda-headline-snapshot-before-repeat newhead just-one)
7934 (org-with-remote-undo buffer
7935 (with-current-buffer buffer
7936 (widen)
7937 (goto-char pos)
7938 (org-show-context 'agenda)
7939 (save-excursion
7940 (and (outline-next-heading)
7941 (org-flag-heading nil))) ; show the next heading
7942 (let ((current-prefix-arg arg))
7943 (call-interactively 'org-todo))
7944 (and (bolp) (forward-char 1))
7945 (setq newhead (org-get-heading))
7946 (when (and (org-bound-and-true-p
7947 org-agenda-headline-snapshot-before-repeat)
7948 (not (equal org-agenda-headline-snapshot-before-repeat
7949 newhead))
7950 todayp)
7951 (setq newhead org-agenda-headline-snapshot-before-repeat
7952 just-one t))
7953 (save-excursion
7954 (org-back-to-heading)
7955 (move-marker org-last-heading-marker (point))))
7956 (beginning-of-line 1)
7957 (save-excursion
7958 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7959 (org-move-to-column col))))
7961 (defun org-agenda-add-note (&optional arg)
7962 "Add a time-stamped note to the entry at point."
7963 (interactive "P")
7964 (org-agenda-check-no-diary)
7965 (let* ((marker (or (org-get-at-bol 'org-marker)
7966 (org-agenda-error)))
7967 (buffer (marker-buffer marker))
7968 (pos (marker-position marker))
7969 (hdmarker (org-get-at-bol 'org-hd-marker))
7970 (inhibit-read-only t))
7971 (with-current-buffer buffer
7972 (widen)
7973 (goto-char pos)
7974 (org-show-context 'agenda)
7975 (save-excursion
7976 (and (outline-next-heading)
7977 (org-flag-heading nil))) ; show the next heading
7978 (org-add-note))))
7980 (defun org-agenda-change-all-lines (newhead hdmarker
7981 &optional fixface just-this)
7982 "Change all lines in the agenda buffer which match HDMARKER.
7983 The new content of the line will be NEWHEAD (as modified by
7984 `org-agenda-format-item'). HDMARKER is checked with
7985 `equal' against all `org-hd-marker' text properties in the file.
7986 If FIXFACE is non-nil, the face of each item is modified according to
7987 the new TODO state.
7988 If JUST-THIS is non-nil, change just the current line, not all.
7989 If FORCE-TAGS is non nil, the car of it returns the new tags."
7990 (let* ((inhibit-read-only t)
7991 (line (org-current-line))
7992 (org-agenda-buffer (current-buffer))
7993 (thetags (with-current-buffer (marker-buffer hdmarker)
7994 (save-excursion (save-restriction (widen)
7995 (goto-char hdmarker)
7996 (org-get-tags-at)))))
7997 props m pl undone-face done-face finish new dotime cat tags)
7998 (save-excursion
7999 (goto-char (point-max))
8000 (beginning-of-line 1)
8001 (while (not finish)
8002 (setq finish (bobp))
8003 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8004 (or (not just-this) (= (org-current-line) line))
8005 (equal m hdmarker))
8006 (setq props (text-properties-at (point))
8007 dotime (org-get-at-bol 'dotime)
8008 cat (org-get-at-bol 'org-category)
8009 tags thetags
8011 (let ((org-prefix-format-compiled
8012 (or (get-text-property (point) 'format)
8013 org-prefix-format-compiled))
8014 (extra (org-get-at-bol 'extra)))
8015 (with-current-buffer (marker-buffer hdmarker)
8016 (save-excursion
8017 (save-restriction
8018 (widen)
8019 (org-agenda-format-item extra newhead cat tags dotime)))))
8020 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8021 undone-face (org-get-at-bol 'undone-face)
8022 done-face (org-get-at-bol 'done-face))
8023 (beginning-of-line 1)
8024 (cond
8025 ((equal new "")
8026 (and (looking-at ".*\n?") (replace-match "")))
8027 ((looking-at ".*")
8028 (replace-match new t t)
8029 (beginning-of-line 1)
8030 (add-text-properties (point-at-bol) (point-at-eol) props)
8031 (when fixface
8032 (add-text-properties
8033 (point-at-bol) (point-at-eol)
8034 (list 'face
8035 (if org-last-todo-state-is-todo
8036 undone-face done-face))))
8037 (org-agenda-highlight-todo 'line)
8038 (beginning-of-line 1))
8039 (t (error "Line update did not work"))))
8040 (beginning-of-line 0)))
8041 (org-agenda-finalize)))
8043 (defun org-agenda-align-tags (&optional line)
8044 "Align all tags in agenda items to `org-agenda-tags-column'."
8045 (let ((inhibit-read-only t) l c)
8046 (save-excursion
8047 (goto-char (if line (point-at-bol) (point-min)))
8048 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8049 (if line (point-at-eol) nil) t)
8050 (add-text-properties
8051 (match-beginning 2) (match-end 2)
8052 (list 'face (delq nil (let ((prop (get-text-property
8053 (match-beginning 2) 'face)))
8054 (or (listp prop) (setq prop (list prop)))
8055 (if (memq 'org-tag prop)
8056 prop
8057 (cons 'org-tag prop))))))
8058 (setq l (- (match-end 2) (match-beginning 2))
8059 c (if (< org-agenda-tags-column 0)
8060 (- (abs org-agenda-tags-column) l)
8061 org-agenda-tags-column))
8062 (delete-region (match-beginning 1) (match-end 1))
8063 (goto-char (match-beginning 1))
8064 (insert (org-add-props
8065 (make-string (max 1 (- c (current-column))) ?\ )
8066 (plist-put (copy-sequence (text-properties-at (point)))
8067 'face nil))))
8068 (goto-char (point-min))
8069 (org-font-lock-add-tag-faces (point-max)))))
8071 (defun org-agenda-priority-up ()
8072 "Increase the priority of line at point, also in Org-mode file."
8073 (interactive)
8074 (org-agenda-priority 'up))
8076 (defun org-agenda-priority-down ()
8077 "Decrease the priority of line at point, also in Org-mode file."
8078 (interactive)
8079 (org-agenda-priority 'down))
8081 (defun org-agenda-priority (&optional force-direction)
8082 "Set the priority of line at point, also in Org-mode file.
8083 This changes the line at point, all other lines in the agenda referring to
8084 the same tree node, and the headline of the tree node in the Org-mode file."
8085 (interactive)
8086 (unless org-enable-priority-commands
8087 (error "Priority commands are disabled"))
8088 (org-agenda-check-no-diary)
8089 (let* ((marker (or (org-get-at-bol 'org-marker)
8090 (org-agenda-error)))
8091 (hdmarker (org-get-at-bol 'org-hd-marker))
8092 (buffer (marker-buffer hdmarker))
8093 (pos (marker-position hdmarker))
8094 (inhibit-read-only t)
8095 newhead)
8096 (org-with-remote-undo buffer
8097 (with-current-buffer buffer
8098 (widen)
8099 (goto-char pos)
8100 (org-show-context 'agenda)
8101 (save-excursion
8102 (and (outline-next-heading)
8103 (org-flag-heading nil))) ; show the next heading
8104 (funcall 'org-priority force-direction)
8105 (end-of-line 1)
8106 (setq newhead (org-get-heading)))
8107 (org-agenda-change-all-lines newhead hdmarker)
8108 (beginning-of-line 1))))
8110 ;; FIXME: should fix the tags property of the agenda line.
8111 (defun org-agenda-set-tags (&optional tag onoff)
8112 "Set tags for the current headline."
8113 (interactive)
8114 (org-agenda-check-no-diary)
8115 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8116 (call-interactively 'org-change-tag-in-region)
8117 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8118 (org-agenda-error)))
8119 (buffer (marker-buffer hdmarker))
8120 (pos (marker-position hdmarker))
8121 (inhibit-read-only t)
8122 newhead)
8123 (org-with-remote-undo buffer
8124 (with-current-buffer buffer
8125 (widen)
8126 (goto-char pos)
8127 (save-excursion
8128 (org-show-context 'agenda))
8129 (save-excursion
8130 (and (outline-next-heading)
8131 (org-flag-heading nil))) ; show the next heading
8132 (goto-char pos)
8133 (if tag
8134 (org-toggle-tag tag onoff)
8135 (call-interactively 'org-set-tags))
8136 (end-of-line 1)
8137 (setq newhead (org-get-heading)))
8138 (org-agenda-change-all-lines newhead hdmarker)
8139 (beginning-of-line 1)))))
8141 (defun org-agenda-set-property ()
8142 "Set a property for the current headline."
8143 (interactive)
8144 (org-agenda-check-no-diary)
8145 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8146 (org-agenda-error)))
8147 (buffer (marker-buffer hdmarker))
8148 (pos (marker-position hdmarker))
8149 (inhibit-read-only t)
8150 newhead)
8151 (org-with-remote-undo buffer
8152 (with-current-buffer buffer
8153 (widen)
8154 (goto-char pos)
8155 (save-excursion
8156 (org-show-context 'agenda))
8157 (save-excursion
8158 (and (outline-next-heading)
8159 (org-flag-heading nil))) ; show the next heading
8160 (goto-char pos)
8161 (call-interactively 'org-set-property)))))
8163 (defun org-agenda-set-effort ()
8164 "Set the effort property for the current headline."
8165 (interactive)
8166 (org-agenda-check-no-diary)
8167 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8168 (org-agenda-error)))
8169 (buffer (marker-buffer hdmarker))
8170 (pos (marker-position hdmarker))
8171 (inhibit-read-only t)
8172 newhead)
8173 (org-with-remote-undo buffer
8174 (with-current-buffer buffer
8175 (widen)
8176 (goto-char pos)
8177 (save-excursion
8178 (org-show-context 'agenda))
8179 (save-excursion
8180 (and (outline-next-heading)
8181 (org-flag-heading nil))) ; show the next heading
8182 (goto-char pos)
8183 (call-interactively 'org-set-effort)
8184 (end-of-line 1)
8185 (setq newhead (org-get-heading)))
8186 (org-agenda-change-all-lines newhead hdmarker))))
8188 (defun org-agenda-toggle-archive-tag ()
8189 "Toggle the archive tag for the current entry."
8190 (interactive)
8191 (org-agenda-check-no-diary)
8192 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8193 (org-agenda-error)))
8194 (buffer (marker-buffer hdmarker))
8195 (pos (marker-position hdmarker))
8196 (inhibit-read-only t)
8197 newhead)
8198 (org-with-remote-undo buffer
8199 (with-current-buffer buffer
8200 (widen)
8201 (goto-char pos)
8202 (org-show-context 'agenda)
8203 (save-excursion
8204 (and (outline-next-heading)
8205 (org-flag-heading nil))) ; show the next heading
8206 (call-interactively 'org-toggle-archive-tag)
8207 (end-of-line 1)
8208 (setq newhead (org-get-heading)))
8209 (org-agenda-change-all-lines newhead hdmarker)
8210 (beginning-of-line 1))))
8212 (defun org-agenda-do-date-later (arg)
8213 (interactive "P")
8214 (cond
8215 ((or (equal arg '(16))
8216 (memq last-command
8217 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8218 (setq this-command 'org-agenda-date-later-minutes)
8219 (org-agenda-date-later-minutes 1))
8220 ((or (equal arg '(4))
8221 (memq last-command
8222 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8223 (setq this-command 'org-agenda-date-later-hours)
8224 (org-agenda-date-later-hours 1))
8226 (org-agenda-date-later (prefix-numeric-value arg)))))
8228 (defun org-agenda-do-date-earlier (arg)
8229 (interactive "P")
8230 (cond
8231 ((or (equal arg '(16))
8232 (memq last-command
8233 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8234 (setq this-command 'org-agenda-date-earlier-minutes)
8235 (org-agenda-date-earlier-minutes 1))
8236 ((or (equal arg '(4))
8237 (memq last-command
8238 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8239 (setq this-command 'org-agenda-date-earlier-hours)
8240 (org-agenda-date-earlier-hours 1))
8242 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8244 (defun org-agenda-date-later (arg &optional what)
8245 "Change the date of this item to ARG day(s) later."
8246 (interactive "p")
8247 (org-agenda-check-type t 'agenda 'timeline)
8248 (org-agenda-check-no-diary)
8249 (let* ((marker (or (org-get-at-bol 'org-marker)
8250 (org-agenda-error)))
8251 (buffer (marker-buffer marker))
8252 (pos (marker-position marker))
8253 cdate today)
8254 (org-with-remote-undo buffer
8255 (with-current-buffer buffer
8256 (widen)
8257 (goto-char pos)
8258 (if (not (org-at-timestamp-p))
8259 (error "Cannot find time stamp"))
8260 (when (and org-agenda-move-date-from-past-immediately-to-today
8261 (equal arg 1)
8262 (or (not what) (eq what 'day))
8263 (not (save-match-data (org-at-date-range-p))))
8264 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8265 cdate (calendar-absolute-from-gregorian
8266 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8267 today (org-today))
8268 (if (> today cdate)
8269 ;; immediately shift to today
8270 (setq arg (- today cdate))))
8271 (org-timestamp-change arg (or what 'day))
8272 (when (and (org-at-date-range-p)
8273 (re-search-backward org-tr-regexp-both (point-at-bol)))
8274 (let ((end org-last-changed-timestamp))
8275 (org-timestamp-change arg (or what 'day))
8276 (setq org-last-changed-timestamp
8277 (concat org-last-changed-timestamp "--" end)))))
8278 (org-agenda-show-new-time marker org-last-changed-timestamp))
8279 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8281 (defun org-agenda-date-earlier (arg &optional what)
8282 "Change the date of this item to ARG day(s) earlier."
8283 (interactive "p")
8284 (org-agenda-date-later (- arg) what))
8286 (defun org-agenda-date-later-minutes (arg)
8287 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8288 (interactive "p")
8289 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8290 (org-agenda-date-later arg 'minute))
8292 (defun org-agenda-date-earlier-minutes (arg)
8293 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8294 (interactive "p")
8295 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8296 (org-agenda-date-earlier arg 'minute))
8298 (defun org-agenda-date-later-hours (arg)
8299 "Change the time of this item, in hour steps."
8300 (interactive "p")
8301 (org-agenda-date-later arg 'hour))
8303 (defun org-agenda-date-earlier-hours (arg)
8304 "Change the time of this item, in hour steps."
8305 (interactive "p")
8306 (org-agenda-date-earlier arg 'hour))
8308 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8309 "Show new date stamp via text properties."
8310 ;; We use text properties to make this undoable
8311 (let ((inhibit-read-only t)
8312 (buffer-invisibility-spec))
8313 (setq stamp (concat " " prefix " => " stamp))
8314 (save-excursion
8315 (goto-char (point-max))
8316 (while (not (bobp))
8317 (when (equal marker (org-get-at-bol 'org-marker))
8318 (org-move-to-column (- (window-width) (length stamp)) t)
8319 (org-agenda-fix-tags-filter-overlays-at (point))
8320 (if (featurep 'xemacs)
8321 ;; Use `duplicable' property to trigger undo recording
8322 (let ((ex (make-extent nil nil))
8323 (gl (make-glyph stamp)))
8324 (set-glyph-face gl 'secondary-selection)
8325 (set-extent-properties
8326 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8327 (insert-extent ex (1- (point)) (point-at-eol)))
8328 (add-text-properties
8329 (1- (point)) (point-at-eol)
8330 (list 'display (org-add-props stamp nil
8331 'face 'secondary-selection))))
8332 (beginning-of-line 1))
8333 (beginning-of-line 0)))))
8335 (defun org-agenda-date-prompt (arg)
8336 "Change the date of this item. Date is prompted for, with default today.
8337 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8338 be used to request time specification in the time stamp."
8339 (interactive "P")
8340 (org-agenda-check-type t 'agenda 'timeline)
8341 (org-agenda-check-no-diary)
8342 (let* ((marker (or (org-get-at-bol 'org-marker)
8343 (org-agenda-error)))
8344 (buffer (marker-buffer marker))
8345 (pos (marker-position marker)))
8346 (org-with-remote-undo buffer
8347 (with-current-buffer buffer
8348 (widen)
8349 (goto-char pos)
8350 (if (not (org-at-timestamp-p t))
8351 (error "Cannot find time stamp"))
8352 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8353 (org-agenda-show-new-time marker org-last-changed-timestamp))
8354 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8356 (defun org-agenda-schedule (arg &optional time)
8357 "Schedule the item at point.
8358 ARG is passed through to `org-schedule'."
8359 (interactive "P")
8360 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8361 (org-agenda-check-no-diary)
8362 (let* ((marker (or (org-get-at-bol 'org-marker)
8363 (org-agenda-error)))
8364 (type (marker-insertion-type marker))
8365 (buffer (marker-buffer marker))
8366 (pos (marker-position marker))
8367 (org-insert-labeled-timestamps-at-point nil)
8369 (set-marker-insertion-type marker t)
8370 (org-with-remote-undo buffer
8371 (with-current-buffer buffer
8372 (widen)
8373 (goto-char pos)
8374 (setq ts (org-schedule arg time)))
8375 (org-agenda-show-new-time marker ts "S"))
8376 (message "Item scheduled for %s" ts)))
8378 (defun org-agenda-deadline (arg &optional time)
8379 "Schedule the item at point.
8380 ARG is passed through to `org-deadline'."
8381 (interactive "P")
8382 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8383 (org-agenda-check-no-diary)
8384 (let* ((marker (or (org-get-at-bol 'org-marker)
8385 (org-agenda-error)))
8386 (buffer (marker-buffer marker))
8387 (pos (marker-position marker))
8388 (org-insert-labeled-timestamps-at-point nil)
8390 (org-with-remote-undo buffer
8391 (with-current-buffer buffer
8392 (widen)
8393 (goto-char pos)
8394 (setq ts (org-deadline arg time)))
8395 (org-agenda-show-new-time marker ts "D"))
8396 (message "Deadline for this item set to %s" ts)))
8398 (defun org-agenda-action ()
8399 "Select entry for agenda action, or execute an agenda action.
8400 This command prompts for another letter. Valid inputs are:
8402 m Mark the entry at point for an agenda action
8403 s Schedule the marked entry to the date at the cursor
8404 d Set the deadline of the marked entry to the date at the cursor
8405 r Call `org-remember' with cursor date as the default date
8406 c Call `org-capture' with cursor date as the default date
8407 SPC Show marked entry in other window
8408 TAB Visit marked entry in other window
8410 The cursor may be at a date in the calendar, or in the Org agenda."
8411 (interactive)
8412 (let (ans)
8413 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8414 (setq ans (read-char-exclusive))
8415 (cond
8416 ((equal ans ?m)
8417 ;; Mark this entry
8418 (if (eq major-mode 'org-agenda-mode)
8419 (let ((m (or (org-get-at-bol 'org-hd-marker)
8420 (org-get-at-bol 'org-marker))))
8421 (if m
8422 (progn
8423 (move-marker org-agenda-action-marker
8424 (marker-position m) (marker-buffer m))
8425 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8426 (error "Don't know which entry to mark")))
8427 (error "This command works only in the agenda")))
8428 ((equal ans ?s)
8429 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8430 ((equal ans ?d)
8431 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8432 ((equal ans ?r)
8433 (org-agenda-do-action '(org-remember) t))
8434 ((equal ans ?c)
8435 (org-agenda-do-action '(org-capture) t))
8436 ((equal ans ?\ )
8437 (let ((cw (selected-window)))
8438 (org-switch-to-buffer-other-window
8439 (marker-buffer org-agenda-action-marker))
8440 (goto-char org-agenda-action-marker)
8441 (org-show-context 'agenda)
8442 (select-window cw)))
8443 ((equal ans ?\C-i)
8444 (org-switch-to-buffer-other-window
8445 (marker-buffer org-agenda-action-marker))
8446 (goto-char org-agenda-action-marker)
8447 (org-show-context 'agenda))
8448 (t (error "Invalid agenda action %c" ans)))))
8450 (defun org-agenda-do-action (form &optional current-buffer)
8451 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8452 (let ((org-overriding-default-time (org-get-cursor-date)))
8453 (if current-buffer
8454 (eval form)
8455 (if (not (marker-buffer org-agenda-action-marker))
8456 (error "No entry has been selected for agenda action")
8457 (with-current-buffer (marker-buffer org-agenda-action-marker)
8458 (save-excursion
8459 (save-restriction
8460 (widen)
8461 (goto-char org-agenda-action-marker)
8462 (eval form))))))))
8464 (defun org-agenda-clock-in (&optional arg)
8465 "Start the clock on the currently selected item."
8466 (interactive "P")
8467 (org-agenda-check-no-diary)
8468 (if (equal arg '(4))
8469 (org-clock-in arg)
8470 (let* ((marker (or (org-get-at-bol 'org-marker)
8471 (org-agenda-error)))
8472 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8473 marker))
8474 (pos (marker-position marker))
8475 newhead)
8476 (org-with-remote-undo (marker-buffer marker)
8477 (with-current-buffer (marker-buffer marker)
8478 (widen)
8479 (goto-char pos)
8480 (org-show-context 'agenda)
8481 (org-show-entry)
8482 (org-cycle-hide-drawers 'children)
8483 (org-clock-in arg)
8484 (setq newhead (org-get-heading)))
8485 (org-agenda-change-all-lines newhead hdmarker)))))
8487 (defun org-agenda-clock-out ()
8488 "Stop the currently running clock."
8489 (interactive)
8490 (unless (marker-buffer org-clock-marker)
8491 (error "No running clock"))
8492 (let ((marker (make-marker)) newhead)
8493 (org-with-remote-undo (marker-buffer org-clock-marker)
8494 (with-current-buffer (marker-buffer org-clock-marker)
8495 (save-excursion
8496 (save-restriction
8497 (widen)
8498 (goto-char org-clock-marker)
8499 (org-back-to-heading t)
8500 (move-marker marker (point))
8501 (org-clock-out)
8502 (setq newhead (org-get-heading))))))
8503 (org-agenda-change-all-lines newhead marker)
8504 (move-marker marker nil)))
8506 (defun org-agenda-clock-cancel (&optional arg)
8507 "Cancel the currently running clock."
8508 (interactive "P")
8509 (unless (marker-buffer org-clock-marker)
8510 (error "No running clock"))
8511 (org-with-remote-undo (marker-buffer org-clock-marker)
8512 (org-clock-cancel)))
8514 (defun org-agenda-clock-goto ()
8515 "Jump to the currently clocked in task within the agenda.
8516 If the currently clocked in task is not listed in the agenda
8517 buffer, display it in another window."
8518 (interactive)
8519 (let (pos)
8520 (mapc (lambda (o)
8521 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8522 (setq pos (overlay-start o))))
8523 (overlays-in (point-min) (point-max)))
8524 (cond (pos (goto-char pos))
8525 ;; If the currently clocked entry is not in the agenda
8526 ;; buffer, we visit it in another window:
8527 (org-clock-current-task
8528 (org-switch-to-buffer-other-window (org-clock-goto)))
8529 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8531 (defun org-agenda-diary-entry-in-org-file ()
8532 "Make a diary entry in the file `org-agenda-diary-file'."
8533 (let (d1 d2 char (text "") dp1 dp2)
8534 (if (equal (buffer-name) "*Calendar*")
8535 (setq d1 (calendar-cursor-to-date t)
8536 d2 (car calendar-mark-ring))
8537 (setq dp1 (get-text-property (point-at-bol) 'day))
8538 (unless dp1 (error "No date defined in current line"))
8539 (setq d1 (calendar-gregorian-from-absolute dp1)
8540 d2 (and (ignore-errors (mark))
8541 (save-excursion
8542 (goto-char (mark))
8543 (setq dp2 (get-text-property (point-at-bol) 'day)))
8544 (calendar-gregorian-from-absolute dp2))))
8545 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8546 (setq char (read-char-exclusive))
8547 (cond
8548 ((equal char ?d)
8549 (setq text (read-string "Day entry: "))
8550 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8551 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8552 ((equal char ?a)
8553 (setq d1 (list (car d1) (nth 1 d1)
8554 (read-number (format "Reference year [%d]: " (nth 2 d1))
8555 (nth 2 d1))))
8556 (setq text (read-string "Anniversary (use %d to show years): "))
8557 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8558 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8559 ((equal char ?b)
8560 (setq text (read-string "Block entry: "))
8561 (unless (and d1 d2 (not (equal d1 d2)))
8562 (error "No block of days selected"))
8563 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8564 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8565 ((equal char ?j)
8566 (org-switch-to-buffer-other-window
8567 (find-file-noselect org-agenda-diary-file))
8568 (require 'org-datetree)
8569 (org-datetree-find-date-create d1)
8570 (org-reveal t))
8571 (t (error "Invalid selection character `%c'" char)))))
8573 (defcustom org-agenda-insert-diary-strategy 'date-tree
8574 "Where in `org-agenda-diary-file' should new entries be added?
8575 Valid values:
8577 date-tree in the date tree, as child of the date
8578 top-level as top-level entries at the end of the file."
8579 :group 'org-agenda
8580 :type '(choice
8581 (const :tag "in a date tree" date-tree)
8582 (const :tag "as top level at end of file" top-level)))
8584 (defcustom org-agenda-insert-diary-extract-time nil
8585 "Non-nil means extract any time specification from the diary entry."
8586 :group 'org-agenda
8587 :version "24.1"
8588 :type 'boolean)
8590 (defcustom org-agenda-bulk-mark-char ">"
8591 "A single-character string to be used as the bulk mark."
8592 :group 'org-agenda
8593 :version "24.1"
8594 :type 'string)
8596 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8597 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8598 If TEXT is not empty, it will become the headline of the new entry, and
8599 the resulting entry will not be shown. When TEXT is empty, switch to
8600 `org-agenda-diary-file' and let the user finish the entry there."
8601 (let ((cw (current-window-configuration)))
8602 (org-switch-to-buffer-other-window
8603 (find-file-noselect org-agenda-diary-file))
8604 (widen)
8605 (goto-char (point-min))
8606 (cond
8607 ((eq type 'anniversary)
8608 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8609 (progn
8610 (or (org-at-heading-p t)
8611 (progn
8612 (outline-next-heading)
8613 (insert "* Anniversaries\n\n")
8614 (beginning-of-line -1)))))
8615 (outline-next-heading)
8616 (org-back-over-empty-lines)
8617 (backward-char 1)
8618 (insert "\n")
8619 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8620 (nth 2 d1) (car d1) (nth 1 d1) text)))
8621 ((eq type 'day)
8622 (let ((org-prefix-has-time t)
8623 (org-agenda-time-leading-zero t)
8624 fmt time time2)
8625 (if org-agenda-insert-diary-extract-time
8626 ;; Use org-agenda-format-item to parse text for a time-range and
8627 ;; remove it. FIXME: This is a hack, we should refactor
8628 ;; that function to make time extraction available separately
8629 (setq fmt (org-agenda-format-item nil text nil nil t)
8630 time (get-text-property 0 'time fmt)
8631 time2 (if (> (length time) 0)
8632 ;; split-string removes trailing ...... if
8633 ;; no end time given. First space
8634 ;; separates time from date.
8635 (concat " " (car (split-string time "\\.")))
8636 nil)
8637 text (get-text-property 0 'txt fmt)))
8638 (if (eq org-agenda-insert-diary-strategy 'top-level)
8639 (org-agenda-insert-diary-as-top-level text)
8640 (require 'org-datetree)
8641 (org-datetree-find-date-create d1)
8642 (org-agenda-insert-diary-make-new-entry text))
8643 (org-insert-time-stamp (org-time-from-absolute
8644 (calendar-absolute-from-gregorian d1))
8645 nil nil nil nil time2))
8646 (end-of-line 0))
8647 ((eq type 'block)
8648 (if (> (calendar-absolute-from-gregorian d1)
8649 (calendar-absolute-from-gregorian d2))
8650 (setq d1 (prog1 d2 (setq d2 d1))))
8651 (if (eq org-agenda-insert-diary-strategy 'top-level)
8652 (org-agenda-insert-diary-as-top-level text)
8653 (require 'org-datetree)
8654 (org-datetree-find-date-create d1)
8655 (org-agenda-insert-diary-make-new-entry text))
8656 (org-insert-time-stamp (org-time-from-absolute
8657 (calendar-absolute-from-gregorian d1)))
8658 (insert "--")
8659 (org-insert-time-stamp (org-time-from-absolute
8660 (calendar-absolute-from-gregorian d2)))
8661 (end-of-line 0)))
8662 (if (string-match "\\S-" text)
8663 (progn
8664 (set-window-configuration cw)
8665 (message "%s entry added to %s"
8666 (capitalize (symbol-name type))
8667 (abbreviate-file-name org-agenda-diary-file)))
8668 (org-reveal t)
8669 (message "Please finish entry here"))))
8671 (defun org-agenda-insert-diary-as-top-level (text)
8672 "Make new entry as a top-level entry at the end of the file.
8673 Add TEXT as headline, and position the cursor in the second line so that
8674 a timestamp can be added there."
8675 (widen)
8676 (goto-char (point-max))
8677 (or (bolp) (insert "\n"))
8678 (insert "* " text "\n")
8679 (if org-adapt-indentation (org-indent-to-column 2)))
8681 (defun org-agenda-insert-diary-make-new-entry (text)
8682 "Make new entry as last child of current entry.
8683 Add TEXT as headline, and position the cursor in the second line so that
8684 a timestamp can be added there."
8685 (let ((org-show-following-heading t)
8686 (org-show-siblings t)
8687 (org-show-hierarchy-above t)
8688 (org-show-entry-below t)
8689 col)
8690 (outline-next-heading)
8691 (org-back-over-empty-lines)
8692 (or (looking-at "[ \t]*$")
8693 (progn (insert "\n") (backward-char 1)))
8694 (org-insert-heading nil t)
8695 (org-do-demote)
8696 (setq col (current-column))
8697 (insert text "\n")
8698 (if org-adapt-indentation (org-indent-to-column col))
8699 (let ((org-show-following-heading t)
8700 (org-show-siblings t)
8701 (org-show-hierarchy-above t)
8702 (org-show-entry-below t))
8703 (org-show-context))))
8705 (defun org-agenda-diary-entry ()
8706 "Make a diary entry, like the `i' command from the calendar.
8707 All the standard commands work: block, weekly etc.
8708 When `org-agenda-diary-file' points to a file,
8709 `org-agenda-diary-entry-in-org-file' is called instead to create
8710 entries in that Org-mode file."
8711 (interactive)
8712 (org-agenda-check-type t 'agenda 'timeline)
8713 (if (not (eq org-agenda-diary-file 'diary-file))
8714 (org-agenda-diary-entry-in-org-file)
8715 (require 'diary-lib)
8716 (let* ((char (progn
8717 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8718 (read-char-exclusive)))
8719 (cmd (cdr (assoc char
8720 '((?d . insert-diary-entry)
8721 (?w . insert-weekly-diary-entry)
8722 (?m . insert-monthly-diary-entry)
8723 (?y . insert-yearly-diary-entry)
8724 (?a . insert-anniversary-diary-entry)
8725 (?b . insert-block-diary-entry)
8726 (?c . insert-cyclic-diary-entry)))))
8727 (oldf (symbol-function 'calendar-cursor-to-date))
8728 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8729 (point (point))
8730 (mark (or (mark t) (point))))
8731 (unless cmd
8732 (error "No command associated with <%c>" char))
8733 (unless (and (get-text-property point 'day)
8734 (or (not (equal ?b char))
8735 (get-text-property mark 'day)))
8736 (error "Don't know which date to use for diary entry"))
8737 ;; We implement this by hacking the `calendar-cursor-to-date' function
8738 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8739 (let ((calendar-mark-ring
8740 (list (calendar-gregorian-from-absolute
8741 (or (get-text-property mark 'day)
8742 (get-text-property point 'day))))))
8743 (unwind-protect
8744 (progn
8745 (fset 'calendar-cursor-to-date
8746 (lambda (&optional error dummy)
8747 (calendar-gregorian-from-absolute
8748 (get-text-property point 'day))))
8749 (call-interactively cmd))
8750 (fset 'calendar-cursor-to-date oldf))))))
8752 (defun org-agenda-execute-calendar-command (cmd)
8753 "Execute a calendar command from the agenda, with the date associated to
8754 the cursor position."
8755 (org-agenda-check-type t 'agenda 'timeline)
8756 (require 'diary-lib)
8757 (unless (get-text-property (point) 'day)
8758 (error "Don't know which date to use for calendar command"))
8759 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8760 (point (point))
8761 (date (calendar-gregorian-from-absolute
8762 (get-text-property point 'day)))
8763 ;; the following 2 vars are needed in the calendar
8764 (displayed-month (car date))
8765 (displayed-year (nth 2 date)))
8766 (unwind-protect
8767 (progn
8768 (fset 'calendar-cursor-to-date
8769 (lambda (&optional error dummy)
8770 (calendar-gregorian-from-absolute
8771 (get-text-property point 'day))))
8772 (call-interactively cmd))
8773 (fset 'calendar-cursor-to-date oldf))))
8775 (defun org-agenda-phases-of-moon ()
8776 "Display the phases of the moon for the 3 months around the cursor date."
8777 (interactive)
8778 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8780 (defun org-agenda-holidays ()
8781 "Display the holidays for the 3 months around the cursor date."
8782 (interactive)
8783 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8785 (defvar calendar-longitude) ; defined in calendar.el
8786 (defvar calendar-latitude) ; defined in calendar.el
8787 (defvar calendar-location-name) ; defined in calendar.el
8789 (defun org-agenda-sunrise-sunset (arg)
8790 "Display sunrise and sunset for the cursor date.
8791 Latitude and longitude can be specified with the variables
8792 `calendar-latitude' and `calendar-longitude'. When called with prefix
8793 argument, latitude and longitude will be prompted for."
8794 (interactive "P")
8795 (require 'solar)
8796 (let ((calendar-longitude (if arg nil calendar-longitude))
8797 (calendar-latitude (if arg nil calendar-latitude))
8798 (calendar-location-name
8799 (if arg "the given coordinates" calendar-location-name)))
8800 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8802 (defun org-agenda-goto-calendar ()
8803 "Open the Emacs calendar with the date at the cursor."
8804 (interactive)
8805 (org-agenda-check-type t 'agenda 'timeline)
8806 (let* ((day (or (get-text-property (point) 'day)
8807 (error "Don't know which date to open in calendar")))
8808 (date (calendar-gregorian-from-absolute day))
8809 (calendar-move-hook nil)
8810 (calendar-view-holidays-initially-flag nil)
8811 (calendar-view-diary-initially-flag nil))
8812 (calendar)
8813 (calendar-goto-date date)))
8815 ;;;###autoload
8816 (defun org-calendar-goto-agenda ()
8817 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8818 This is a command that has to be installed in `calendar-mode-map'."
8819 (interactive)
8820 (org-agenda-list nil (calendar-absolute-from-gregorian
8821 (calendar-cursor-to-date))
8822 nil))
8824 (defun org-agenda-convert-date ()
8825 (interactive)
8826 (org-agenda-check-type t 'agenda 'timeline)
8827 (let ((day (get-text-property (point) 'day))
8828 date s)
8829 (unless day
8830 (error "Don't know which date to convert"))
8831 (setq date (calendar-gregorian-from-absolute day))
8832 (setq s (concat
8833 "Gregorian: " (calendar-date-string date) "\n"
8834 "ISO: " (calendar-iso-date-string date) "\n"
8835 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8836 "Julian: " (calendar-julian-date-string date) "\n"
8837 "Astron. JD: " (calendar-astro-date-string date)
8838 " (Julian date number at noon UTC)\n"
8839 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8840 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8841 "French: " (calendar-french-date-string date) "\n"
8842 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8843 "Mayan: " (calendar-mayan-date-string date) "\n"
8844 "Coptic: " (calendar-coptic-date-string date) "\n"
8845 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8846 "Persian: " (calendar-persian-date-string date) "\n"
8847 "Chinese: " (calendar-chinese-date-string date) "\n"))
8848 (with-output-to-temp-buffer "*Dates*"
8849 (princ s))
8850 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8852 ;;; Bulk commands
8854 (defun org-agenda-bulk-marked-p ()
8855 (eq (get-char-property (point-at-bol) 'type)
8856 'org-marked-entry-overlay))
8858 (defun org-agenda-bulk-mark (&optional arg)
8859 "Mark the entry at point for future bulk action."
8860 (interactive "p")
8861 (dotimes (i (or arg 1))
8862 (unless (org-get-at-bol 'org-agenda-diary-link)
8863 (let* ((m (org-get-at-bol 'org-hd-marker))
8865 (unless (org-agenda-bulk-marked-p)
8866 (unless m (error "Nothing to mark at point"))
8867 (push m org-agenda-bulk-marked-entries)
8868 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8869 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8870 (org-get-todo-face "TODO")
8871 'evaporate)
8872 (overlay-put ov 'type 'org-marked-entry-overlay))
8873 (beginning-of-line 2)
8874 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8875 (beginning-of-line 2))
8876 (message "%d entries marked for bulk action"
8877 (length org-agenda-bulk-marked-entries))))))
8879 (defun org-agenda-bulk-mark-all ()
8880 "Mark all entries for future agenda bulk action."
8881 (interactive)
8882 (org-agenda-bulk-mark-regexp "."))
8884 (defun org-agenda-bulk-mark-regexp (regexp)
8885 "Mark entries matching REGEXP for future agenda bulk action."
8886 (interactive "sMark entries matching regexp: ")
8887 (let ((entries-marked 0))
8888 (save-excursion
8889 (goto-char (point-min))
8890 (goto-char (next-single-property-change (point) 'txt))
8891 (while (re-search-forward regexp nil t)
8892 (when (string-match regexp (get-text-property (point) 'txt))
8893 (setq entries-marked (1+ entries-marked))
8894 (call-interactively 'org-agenda-bulk-mark))))
8895 (if (not entries-marked)
8896 (message "No entry matching this regexp."))))
8898 (defun org-agenda-bulk-unmark (&optional arg)
8899 "Unmark the entry at point for future bulk action."
8900 (interactive "P")
8901 (if arg
8902 (org-agenda-bulk-unmark-all)
8903 (cond ((org-agenda-bulk-marked-p)
8904 (org-agenda-bulk-remove-overlays
8905 (point-at-bol) (+ 2 (point-at-bol)))
8906 (setq org-agenda-bulk-marked-entries
8907 (delete (org-get-at-bol 'org-hd-marker)
8908 org-agenda-bulk-marked-entries))
8909 (beginning-of-line 2)
8910 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8911 (beginning-of-line 2))
8912 (message "%d entries left marked for bulk action"
8913 (length org-agenda-bulk-marked-entries)))
8914 (t (message "No entry to unmark here")))))
8916 (defun org-agenda-bulk-toggle ()
8917 "Toggle marking the entry at point for bulk action."
8918 (interactive)
8919 (if (org-agenda-bulk-marked-p)
8920 (org-agenda-bulk-unmark)
8921 (org-agenda-bulk-mark)))
8923 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8924 "Remove the mark overlays between BEG and END in the agenda buffer.
8925 BEG and END default to the buffer limits.
8927 This only removes the overlays, it does not remove the markers
8928 from the list in `org-agenda-bulk-marked-entries'."
8929 (interactive)
8930 (mapc (lambda (ov)
8931 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8932 (delete-overlay ov)))
8933 (overlays-in (or beg (point-min)) (or end (point-max)))))
8935 (defun org-agenda-bulk-unmark-all ()
8936 "Remove all marks in the agenda buffer.
8937 This will remove the markers and the overlays."
8938 (interactive)
8939 (if (null org-agenda-bulk-marked-entries)
8940 (message "No entry to unmark")
8941 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8942 (setq org-agenda-bulk-marked-entries nil)
8943 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8945 (defcustom org-agenda-persistent-marks nil
8946 "Non-nil means marked items will stay marked after a bulk action.
8947 You can toggle this interactively by typing `p' when prompted for a
8948 bulk action."
8949 :group 'org-agenda
8950 :version "24.1"
8951 :type 'boolean)
8953 (defun org-agenda-bulk-action (&optional arg)
8954 "Execute an remote-editing action on all marked entries.
8955 The prefix arg is passed through to the command if possible."
8956 (interactive "P")
8957 ;; Make sure we have markers, and only valid ones
8958 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8959 (mapc
8960 (lambda (m)
8961 (unless (and (markerp m)
8962 (marker-buffer m)
8963 (buffer-live-p (marker-buffer m))
8964 (marker-position m))
8965 (error "Marker %s for bulk command is invalid" m)))
8966 org-agenda-bulk-marked-entries)
8968 ;; Prompt for the bulk command
8969 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8970 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8971 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8972 (when org-agenda-bulk-custom-functions
8973 (concat " Custom: ["
8974 (mapconcat (lambda(f) (char-to-string (car f)))
8975 org-agenda-bulk-custom-functions "")
8976 "]"))))
8977 (catch 'exit
8978 (let* ((action (read-char-exclusive))
8979 (org-log-refile (if org-log-refile 'time nil))
8980 (entries (reverse org-agenda-bulk-marked-entries))
8981 redo-at-end
8982 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8983 (cond
8984 ((equal action ?p)
8985 (let ((org-agenda-persistent-marks
8986 (not org-agenda-persistent-marks)))
8987 (org-agenda-bulk-action)
8988 (throw 'exit nil)))
8990 ((equal action ?$)
8991 (setq cmd '(org-agenda-archive)))
8993 ((equal action ?A)
8994 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8996 ((member action '(?r ?w))
8997 (setq rfloc (org-refile-get-location
8998 "Refile to"
8999 (marker-buffer (car org-agenda-bulk-marked-entries))
9000 org-refile-allow-creating-parent-nodes))
9001 (if (nth 3 rfloc)
9002 (setcar (nthcdr 3 rfloc)
9003 (move-marker (make-marker) (nth 3 rfloc)
9004 (or (get-file-buffer (nth 1 rfloc))
9005 (find-buffer-visiting (nth 1 rfloc))
9006 (error "This should not happen")))))
9008 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9009 redo-at-end t))
9011 ((equal action ?t)
9012 (setq state (org-icompleting-read
9013 "Todo state: "
9014 (with-current-buffer (marker-buffer (car entries))
9015 (mapcar 'list org-todo-keywords-1))))
9016 (setq cmd `(let ((org-inhibit-blocking t)
9017 (org-inhibit-logging 'note))
9018 (org-agenda-todo ,state))))
9020 ((memq action '(?- ?+))
9021 (setq tag (org-icompleting-read
9022 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9023 (with-current-buffer (marker-buffer (car entries))
9024 (delq nil
9025 (mapcar (lambda (x)
9026 (if (stringp (car x)) x)) org-tag-alist)))))
9027 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9029 ((memq action '(?s ?d))
9030 (let* ((date (unless arg
9031 (org-read-date
9032 nil nil nil
9033 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
9034 (ans (if arg nil org-read-date-final-answer))
9035 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9036 (setq cmd `(let* ((bound (fboundp 'read-string))
9037 (old (and bound (symbol-function 'read-string))))
9038 (unwind-protect
9039 (progn
9040 (fset 'read-string (lambda (&rest ignore) ,ans))
9041 (eval '(,c1 arg)))
9042 (if bound
9043 (fset 'read-string old)
9044 (fmakunbound 'read-string)))))))
9046 ((equal action ?S)
9047 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9048 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9049 (let ((days (read-number
9050 (format "Scatter tasks across how many %sdays: "
9051 (if arg "week" "")) 7)))
9052 (setq cmd
9053 `(let ((distance (1+ (random ,days))))
9054 (if arg
9055 (let ((dist distance)
9056 (day-of-week
9057 (calendar-day-of-week
9058 (calendar-gregorian-from-absolute (org-today)))))
9059 (dotimes (i (1+ dist))
9060 (while (member day-of-week org-agenda-weekend-days)
9061 (incf distance)
9062 (incf day-of-week)
9063 (if (= day-of-week 7)
9064 (setq day-of-week 0)))
9065 (incf day-of-week)
9066 (if (= day-of-week 7)
9067 (setq day-of-week 0)))))
9068 ;; silently fail when try to replan a sexp entry
9069 (condition-case nil
9070 (let* ((date (calendar-gregorian-from-absolute
9071 (+ (org-today) distance)))
9072 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9073 (nth 2 date))))
9074 (org-agenda-schedule nil time))
9075 (error nil)))))))
9077 ((assoc action org-agenda-bulk-custom-functions)
9078 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9079 redo-at-end t))
9081 ((equal action ?f)
9082 (setq cmd (list (intern
9083 (org-icompleting-read "Function: "
9084 obarray 'fboundp t nil nil)))))
9086 (t (error "Invalid bulk action")))
9088 ;; Sort the markers, to make sure that parents are handled before children
9089 (setq entries (sort entries
9090 (lambda (a b)
9091 (cond
9092 ((equal (marker-buffer a) (marker-buffer b))
9093 (< (marker-position a) (marker-position b)))
9095 (string< (buffer-name (marker-buffer a))
9096 (buffer-name (marker-buffer b))))))))
9098 ;; Now loop over all markers and apply cmd
9099 (while (setq e (pop entries))
9100 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9101 (if (not pos)
9102 (progn (message "Skipping removed entry at %s" e)
9103 (setq cntskip (1+ cntskip)))
9104 (goto-char pos)
9105 (let (org-loop-over-headlines-in-active-region)
9106 (eval cmd))
9107 (when (not org-agenda-persistent-marks)
9108 (setq org-agenda-bulk-marked-entries
9109 (delete e org-agenda-bulk-marked-entries)))
9110 (setq cnt (1+ cnt))))
9111 (when (not org-agenda-persistent-marks)
9112 (org-agenda-bulk-unmark-all))
9113 (when redo-at-end (org-agenda-redo))
9114 (message "Acted on %d entries%s%s"
9116 (if (= cntskip 0)
9118 (format ", skipped %d (disappeared before their turn)"
9119 cntskip))
9120 (if (not org-agenda-persistent-marks)
9121 "" " (kept marked)"))))))
9123 ;;; Flagging notes
9125 (defun org-agenda-show-the-flagging-note ()
9126 "Display the flagging note in the other window.
9127 When called a second time in direct sequence, offer to remove the FLAGGING
9128 tag and (if present) the flagging note."
9129 (interactive)
9130 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9131 (win (selected-window))
9132 note heading newhead)
9133 (unless hdmarker
9134 (error "No linked entry at point"))
9135 (if (and (eq this-command last-command)
9136 (y-or-n-p "Unflag and remove any flagging note? "))
9137 (progn
9138 (org-agenda-remove-flag hdmarker)
9139 (let ((win (get-buffer-window "*Flagging Note*")))
9140 (and win (delete-window win)))
9141 (message "Entry unflagged"))
9142 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9143 (unless note
9144 (error "No flagging note"))
9145 (org-kill-new note)
9146 (org-switch-to-buffer-other-window "*Flagging Note*")
9147 (erase-buffer)
9148 (insert note)
9149 (goto-char (point-min))
9150 (while (re-search-forward "\\\\n" nil t)
9151 (replace-match "\n" t t))
9152 (goto-char (point-min))
9153 (select-window win)
9154 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9156 (defun org-agenda-remove-flag (marker)
9157 "Remove the FLAGGED tag and any flagging note in the entry."
9158 (let (newhead)
9159 (org-with-point-at marker
9160 (org-toggle-tag "FLAGGED" 'off)
9161 (org-entry-delete nil "THEFLAGGINGNOTE")
9162 (setq newhead (org-get-heading)))
9163 (org-agenda-change-all-lines newhead marker)
9164 (message "Entry unflagged")))
9166 (defun org-agenda-get-any-marker (&optional pos)
9167 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9168 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9170 ;;; Appointment reminders
9172 (defvar appt-time-msg-list) ; defined in appt.el
9174 ;;;###autoload
9175 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9176 "Activate appointments found in `org-agenda-files'.
9177 With a \\[universal-argument] prefix, refresh the list of
9178 appointments.
9180 If FILTER is t, interactively prompt the user for a regular
9181 expression, and filter out entries that don't match it.
9183 If FILTER is a string, use this string as a regular expression
9184 for filtering entries out.
9186 If FILTER is a function, filter out entries against which
9187 calling the function returns nil. This function takes one
9188 argument: an entry from `org-agenda-get-day-entries'.
9190 FILTER can also be an alist with the car of each cell being
9191 either 'headline or 'category. For example:
9193 '((headline \"IMPORTANT\")
9194 (category \"Work\"))
9196 will only add headlines containing IMPORTANT or headlines
9197 belonging to the \"Work\" category.
9199 ARGS are symbols indicating what kind of entries to consider.
9200 By default `org-agenda-to-appt' will use :deadline, :scheduled
9201 and :timestamp entries. See the docstring of `org-diary' for
9202 details and examples.
9204 If an entry as a APPT_WARNTIME property, its value will be used
9205 to override `appt-message-warning-time'."
9206 (interactive "P")
9207 (if refresh (setq appt-time-msg-list nil))
9208 (if (eq filter t)
9209 (setq filter (read-from-minibuffer "Regexp filter: ")))
9210 (let* ((cnt 0) ; count added events
9211 (scope (or args '(:deadline :scheduled :timestamp)))
9212 (org-agenda-new-buffers nil)
9213 (org-deadline-warning-days 0)
9214 ;; Do not use `org-today' here because appt only takes
9215 ;; time and without date as argument, so it may pass wrong
9216 ;; information otherwise
9217 (today (org-date-to-gregorian
9218 (time-to-days (current-time))))
9219 (org-agenda-restrict nil)
9220 (files (org-agenda-files 'unrestricted)) entries file
9221 (org-agenda-buffer nil))
9222 ;; Get all entries which may contain an appt
9223 (org-agenda-prepare-buffers files)
9224 (while (setq file (pop files))
9225 (setq entries
9226 (delq nil
9227 (append entries
9228 (apply 'org-agenda-get-day-entries
9229 file today scope)))))
9230 ;; Map thru entries and find if we should filter them out
9231 (mapc
9232 (lambda(x)
9233 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9234 (cat (get-text-property 1 'org-category x))
9235 (tod (get-text-property 1 'time-of-day x))
9236 (ok (or (null filter)
9237 (and (stringp filter) (string-match filter evt))
9238 (and (functionp filter) (funcall filter x))
9239 (and (listp filter)
9240 (let ((cat-filter (cadr (assoc 'category filter)))
9241 (evt-filter (cadr (assoc 'headline filter))))
9242 (or (and (stringp cat-filter)
9243 (string-match cat-filter cat))
9244 (and (stringp evt-filter)
9245 (string-match evt-filter evt)))))))
9246 (wrn (get-text-property 1 'warntime x)))
9247 ;; FIXME: Shall we remove text-properties for the appt text?
9248 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9249 (when (and ok tod)
9250 (setq tod (concat "00" (number-to-string tod))
9251 tod (when (string-match
9252 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9253 (concat (match-string 1 tod) ":"
9254 (match-string 2 tod))))
9255 (if (version< emacs-version "23.3")
9256 (appt-add tod evt)
9257 (appt-add tod evt wrn))
9258 (setq cnt (1+ cnt))))) entries)
9259 (org-release-buffers org-agenda-new-buffers)
9260 (if (eq cnt 0)
9261 (message "No event to add")
9262 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9264 (defun org-agenda-todayp (date)
9265 "Does DATE mean today, when considering `org-extend-today-until'?"
9266 (let ((today (org-today))
9267 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9268 date)))
9269 (eq date today)))
9271 (defun org-agenda-todo-yesterday (&optional arg)
9272 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9273 (interactive "P")
9274 (let* ((hour (third (decode-time
9275 (org-current-time))))
9276 (org-extend-today-until (1+ hour)))
9277 (org-agenda-todo arg)))
9279 (provide 'org-agenda)
9281 ;;; org-agenda.el ends here