Revert `org-agenda-dim-blocked-tasks' and `org-agenda-inhibit-startup' to their previ...
[org-mode.git] / lisp / org-agenda.el
blob30202137998c31024b44b3ed6c2e9261c4c775ee
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags do not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :version "24.4"
754 :package-version '(Org . "8.0")
755 :type '(choice
756 (const :tag "Compare time with days" nil)
757 (const :tag "Compare time with seconds" t)))
759 (defcustom org-agenda-tags-todo-honor-ignore-options nil
760 "Non-nil means honor todo-list ignores options also in tags-todo search.
761 The variables
762 `org-agenda-todo-ignore-with-date',
763 `org-agenda-todo-ignore-timestamp',
764 `org-agenda-todo-ignore-scheduled',
765 `org-agenda-todo-ignore-deadlines'
766 make the global TODO list skip entries that have time stamps of certain
767 kinds. If this option is set, the same options will also apply for the
768 tags-todo search, which is the general tags/property matcher
769 restricted to unfinished TODO entries only."
770 :group 'org-agenda-skip
771 :group 'org-agenda-todo-list
772 :group 'org-agenda-match-view
773 :type 'boolean)
775 (defcustom org-agenda-skip-scheduled-if-done nil
776 "Non-nil means don't show scheduled items in agenda when they are done.
777 This is relevant for the daily/weekly agenda, not for the TODO list. And
778 it applies only to the actual date of the scheduling. Warnings about
779 an item with a past scheduling dates are always turned off when the item
780 is DONE."
781 :group 'org-agenda-skip
782 :group 'org-agenda-daily/weekly
783 :type 'boolean)
785 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
786 "Non-nil means skip scheduling line if same entry shows because of deadline.
787 In the agenda of today, an entry can show up multiple times because
788 it is both scheduled and has a nearby deadline, and maybe a plain time
789 stamp as well.
790 When this variable is t, then only the deadline is shown and the fact that
791 the entry is scheduled today or was scheduled previously is not shown.
792 When this variable is nil, the entry will be shown several times. When
793 the variable is the symbol `not-today', then skip scheduled previously,
794 but not scheduled today."
795 :group 'org-agenda-skip
796 :group 'org-agenda-daily/weekly
797 :type '(choice
798 (const :tag "Never" nil)
799 (const :tag "Always" t)
800 (const :tag "Not when scheduled today" not-today)))
802 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
803 "Non-nil means skip timestamp line if same entry shows because of deadline.
804 In the agenda of today, an entry can show up multiple times
805 because it has both a plain timestamp and has a nearby deadline.
806 When this variable is t, then only the deadline is shown and the
807 fact that the entry has a timestamp for or including today is not
808 shown. When this variable is nil, the entry will be shown
809 several times."
810 :group 'org-agenda-skip
811 :group 'org-agenda-daily/weekly
812 :version "24.1"
813 :type '(choice
814 (const :tag "Never" nil)
815 (const :tag "Always" t)))
817 (defcustom org-agenda-skip-deadline-if-done nil
818 "Non-nil means don't show deadlines when the corresponding item is done.
819 When nil, the deadline is still shown and should give you a happy feeling.
820 This is relevant for the daily/weekly agenda. And it applied only to the
821 actually date of the deadline. Warnings about approaching and past-due
822 deadlines are always turned off when the item is DONE."
823 :group 'org-agenda-skip
824 :group 'org-agenda-daily/weekly
825 :type 'boolean)
827 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
828 "Non-nil means skip deadline prewarning when entry is also scheduled.
829 This will apply on all days where a prewarning for the deadline would
830 be shown, but not at the day when the entry is actually due. On that day,
831 the deadline will be shown anyway.
832 This variable may be set to nil, t, the symbol `pre-scheduled',
833 or a number which will then give the number of days before the actual
834 deadline when the prewarnings should resume. The symbol `pre-scheduled'
835 eliminates the deadline prewarning only prior to the scheduled date.
836 This can be used in a workflow where the first showing of the deadline will
837 trigger you to schedule it, and then you don't want to be reminded of it
838 because you will take care of it on the day when scheduled."
839 :group 'org-agenda-skip
840 :group 'org-agenda-daily/weekly
841 :version "24.1"
842 :type '(choice
843 (const :tag "Always show prewarning" nil)
844 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
845 (const :tag "Remove prewarning if entry is scheduled" t)
846 (integer :tag "Restart prewarning N days before deadline")))
848 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
849 "Non-nil means skip scheduled delay when entry also has a deadline.
850 This variable may be set to nil, t, the symbol `post-deadline',
851 or a number which will then give the number of days after the actual
852 scheduled date when the delay should expire. The symbol `post-deadline'
853 eliminates the schedule delay when the date is posterior to the deadline."
854 :group 'org-agenda-skip
855 :group 'org-agenda-daily/weekly
856 :version "24.4"
857 :package-version '(Org . "8.0")
858 :type '(choice
859 (const :tag "Always honor delay" nil)
860 (const :tag "Ignore delay if posterior to the deadline" post-deadline)
861 (const :tag "Ignore delay if entry has a deadline" t)
862 (integer :tag "Honor delay up until N days after the scheduled date")))
864 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
865 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
866 When non-nil, after the search for timestamps has matched once in an
867 entry, the rest of the entry will not be searched."
868 :group 'org-agenda-skip
869 :type 'boolean)
871 (defcustom org-agenda-skip-timestamp-if-done nil
872 "Non-nil means don't select item by timestamp or -range if it is DONE."
873 :group 'org-agenda-skip
874 :group 'org-agenda-daily/weekly
875 :type 'boolean)
877 (defcustom org-agenda-dim-blocked-tasks t
878 "Non-nil means dim blocked tasks in the agenda display.
879 This causes some overhead during agenda construction, but if you
880 have turned on `org-enforce-todo-dependencies',
881 `org-enforce-todo-checkbox-dependencies', or any other blocking
882 mechanism, this will create useful feedback in the agenda.
884 Instead of t, this variable can also have the value `invisible'.
885 Then blocked tasks will be invisible and only become visible when
886 they become unblocked. An exemption to this behavior is when a task is
887 blocked because of unchecked checkboxes below it. Since checkboxes do
888 not show up in the agenda views, making this task invisible you remove any
889 trace from agenda views that there is something to do. Therefore, a task
890 that is blocked because of checkboxes will never be made invisible, it
891 will only be dimmed."
892 :group 'org-agenda-daily/weekly
893 :group 'org-agenda-todo-list
894 :version "24.3"
895 :type '(choice
896 (const :tag "Do not dim" nil)
897 (const :tag "Dim to a gray face" t)
898 (const :tag "Make invisible" invisible)))
900 (defcustom org-timeline-show-empty-dates 3
901 "Non-nil means `org-timeline' also shows dates without an entry.
902 When nil, only the days which actually have entries are shown.
903 When t, all days between the first and the last date are shown.
904 When an integer, show also empty dates, but if there is a gap of more than
905 N days, just insert a special line indicating the size of the gap."
906 :group 'org-agenda-skip
907 :type '(choice
908 (const :tag "None" nil)
909 (const :tag "All" t)
910 (integer :tag "at most")))
912 (defgroup org-agenda-startup nil
913 "Options concerning initial settings in the Agenda in Org Mode."
914 :tag "Org Agenda Startup"
915 :group 'org-agenda)
917 (defcustom org-agenda-menu-show-matcher t
918 "Non-nil means show the match string in the agenda dispatcher menu.
919 When nil, the matcher string is not shown, but is put into the help-echo
920 property so than moving the mouse over the command shows it.
921 Setting it to nil is good if matcher strings are very long and/or if
922 you want to use two-columns display (see `org-agenda-menu-two-columns')."
923 :group 'org-agenda
924 :version "24.1"
925 :type 'boolean)
927 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
929 (defcustom org-agenda-menu-two-columns nil
930 "Non-nil means, use two columns to show custom commands in the dispatcher.
931 If you use this, you probably want to set `org-agenda-menu-show-matcher'
932 to nil."
933 :group 'org-agenda
934 :version "24.1"
935 :type 'boolean)
937 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
938 (defcustom org-agenda-finalize-hook nil
939 "Hook run just before displaying an agenda buffer.
940 The buffer is still writable when the hook is called.
942 You can modify some of the buffer substrings but you should be
943 extra careful not to modify the text properties of the agenda
944 headlines as the agenda display heavily relies on them."
945 :group 'org-agenda-startup
946 :type 'hook)
948 (defcustom org-agenda-mouse-1-follows-link nil
949 "Non-nil means mouse-1 on a link will follow the link in the agenda.
950 A longer mouse click will still set point. Does not work on XEmacs.
951 Needs to be set before org.el is loaded."
952 :group 'org-agenda-startup
953 :type 'boolean)
955 (defcustom org-agenda-start-with-follow-mode nil
956 "The initial value of follow mode in a newly created agenda window."
957 :group 'org-agenda-startup
958 :type 'boolean)
960 (defcustom org-agenda-follow-indirect nil
961 "Non-nil means `org-agenda-follow-mode' displays only the
962 current item's tree, in an indirect buffer."
963 :group 'org-agenda
964 :version "24.1"
965 :type 'boolean)
967 (defcustom org-agenda-show-outline-path t
968 "Non-nil means show outline path in echo area after line motion."
969 :group 'org-agenda-startup
970 :type 'boolean)
972 (defcustom org-agenda-start-with-entry-text-mode nil
973 "The initial value of entry-text-mode in a newly created agenda window."
974 :group 'org-agenda-startup
975 :type 'boolean)
977 (defcustom org-agenda-entry-text-maxlines 5
978 "Number of text lines to be added when `E' is pressed in the agenda.
980 Note that this variable only used during agenda display. Add add entry text
981 when exporting the agenda, configure the variable
982 `org-agenda-add-entry-ext-maxlines'."
983 :group 'org-agenda
984 :type 'integer)
986 (defcustom org-agenda-entry-text-exclude-regexps nil
987 "List of regular expressions to clean up entry text.
988 The complete matches of all regular expressions in this list will be
989 removed from entry text before it is shown in the agenda."
990 :group 'org-agenda
991 :type '(repeat (regexp)))
993 (defcustom org-agenda-entry-text-leaders " > "
994 "Text prepended to the entry text in agenda buffers."
995 :version "24.4"
996 :package-version '(Org . "8.0")
997 :group 'org-agenda
998 :type 'string)
1000 (defvar org-agenda-entry-text-cleanup-hook nil
1001 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1002 This cleanup is done in a temporary buffer, so the function may inspect and
1003 change the entire buffer.
1004 Some default stuff like drawers and scheduling/deadline dates will already
1005 have been removed when this is called, as will any matches for regular
1006 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1008 (defvar org-agenda-include-inactive-timestamps nil
1009 "Non-nil means include inactive time stamps in agenda and timeline.
1010 Dynamically scoped.")
1012 (defgroup org-agenda-windows nil
1013 "Options concerning the windows used by the Agenda in Org Mode."
1014 :tag "Org Agenda Windows"
1015 :group 'org-agenda)
1017 (defcustom org-agenda-window-setup 'reorganize-frame
1018 "How the agenda buffer should be displayed.
1019 Possible values for this option are:
1021 current-window Show agenda in the current window, keeping all other windows.
1022 other-window Use `switch-to-buffer-other-window' to display agenda.
1023 reorganize-frame Show only two windows on the current frame, the current
1024 window and the agenda.
1025 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1026 Also, when exiting the agenda, kill that frame.
1027 See also the variable `org-agenda-restore-windows-after-quit'."
1028 :group 'org-agenda-windows
1029 :type '(choice
1030 (const current-window)
1031 (const other-frame)
1032 (const other-window)
1033 (const reorganize-frame)))
1035 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1036 "The min and max height of the agenda window as a fraction of frame height.
1037 The value of the variable is a cons cell with two numbers between 0 and 1.
1038 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1039 :group 'org-agenda-windows
1040 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1042 (defcustom org-agenda-restore-windows-after-quit nil
1043 "Non-nil means restore window configuration upon exiting agenda.
1044 Before the window configuration is changed for displaying the agenda,
1045 the current status is recorded. When the agenda is exited with
1046 `q' or `x' and this option is set, the old state is restored. If
1047 `org-agenda-window-setup' is `other-frame', the value of this
1048 option will be ignored."
1049 :group 'org-agenda-windows
1050 :type 'boolean)
1052 (defcustom org-agenda-ndays nil
1053 "Number of days to include in overview display.
1054 Should be 1 or 7.
1055 Obsolete, see `org-agenda-span'."
1056 :group 'org-agenda-daily/weekly
1057 :type 'integer)
1059 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1061 (defcustom org-agenda-span 'week
1062 "Number of days to include in overview display.
1063 Can be day, week, month, year, or any number of days.
1064 Custom commands can set this variable in the options section."
1065 :group 'org-agenda-daily/weekly
1066 :type '(choice (const :tag "Day" day)
1067 (const :tag "Week" week)
1068 (const :tag "Month" month)
1069 (const :tag "Year" year)
1070 (integer :tag "Custom")))
1072 (defcustom org-agenda-start-on-weekday 1
1073 "Non-nil means start the overview always on the specified weekday.
1074 0 denotes Sunday, 1 denotes Monday etc.
1075 When nil, always start on the current day.
1076 Custom commands can set this variable in the options section."
1077 :group 'org-agenda-daily/weekly
1078 :type '(choice (const :tag "Today" nil)
1079 (integer :tag "Weekday No.")))
1081 (defcustom org-agenda-show-all-dates t
1082 "Non-nil means `org-agenda' shows every day in the selected range.
1083 When nil, only the days which actually have entries are shown."
1084 :group 'org-agenda-daily/weekly
1085 :type 'boolean)
1087 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1088 "Format string for displaying dates in the agenda.
1089 Used by the daily/weekly agenda and by the timeline. This should be
1090 a format string understood by `format-time-string', or a function returning
1091 the formatted date as a string. The function must take a single argument,
1092 a calendar-style date list like (month day year)."
1093 :group 'org-agenda-daily/weekly
1094 :type '(choice
1095 (string :tag "Format string")
1096 (function :tag "Function")))
1098 (defun org-agenda-format-date-aligned (date)
1099 "Format a DATE string for display in the daily/weekly agenda, or timeline.
1100 This function makes sure that dates are aligned for easy reading."
1101 (require 'cal-iso)
1102 (let* ((dayname (calendar-day-name date))
1103 (day (cadr date))
1104 (day-of-week (calendar-day-of-week date))
1105 (month (car date))
1106 (monthname (calendar-month-name month))
1107 (year (nth 2 date))
1108 (iso-week (org-days-to-iso-week
1109 (calendar-absolute-from-gregorian date)))
1110 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1111 (1- year))
1112 ((and (= month 12) (<= iso-week 1))
1113 (1+ year))
1114 (t year)))
1115 (weekstring (if (= day-of-week 1)
1116 (format " W%02d" iso-week)
1117 "")))
1118 (format "%-10s %2d %s %4d%s"
1119 dayname day monthname year weekstring)))
1121 (defcustom org-agenda-time-leading-zero nil
1122 "Non-nil means use leading zero for military times in agenda.
1123 For example, 9:30am would become 09:30 rather than 9:30."
1124 :group 'org-agenda-daily/weekly
1125 :version "24.1"
1126 :type 'boolean)
1128 (defcustom org-agenda-timegrid-use-ampm nil
1129 "When set, show AM/PM style timestamps on the timegrid."
1130 :group 'org-agenda
1131 :version "24.1"
1132 :type 'boolean)
1134 (defun org-agenda-time-of-day-to-ampm (time)
1135 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1136 (let* ((hour-number (string-to-number (substring time 0 -3)))
1137 (minute (substring time -2))
1138 (ampm "am"))
1139 (cond
1140 ((equal hour-number 12)
1141 (setq ampm "pm"))
1142 ((> hour-number 12)
1143 (setq ampm "pm")
1144 (setq hour-number (- hour-number 12))))
1145 (concat
1146 (if org-agenda-time-leading-zero
1147 (format "%02d" hour-number)
1148 (format "%02s" (number-to-string hour-number)))
1149 ":" minute ampm)))
1151 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1152 "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
1153 (if org-agenda-timegrid-use-ampm
1154 (org-agenda-time-of-day-to-ampm time)
1155 time))
1157 (defcustom org-agenda-weekend-days '(6 0)
1158 "Which days are weekend?
1159 These days get the special face `org-agenda-date-weekend' in the agenda
1160 and timeline buffers."
1161 :group 'org-agenda-daily/weekly
1162 :type '(set :greedy t
1163 (const :tag "Monday" 1)
1164 (const :tag "Tuesday" 2)
1165 (const :tag "Wednesday" 3)
1166 (const :tag "Thursday" 4)
1167 (const :tag "Friday" 5)
1168 (const :tag "Saturday" 6)
1169 (const :tag "Sunday" 0)))
1171 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1172 "Non-nil means jump to today when moving a past date forward in time.
1173 When using S-right in the agenda to move a a date forward, and the date
1174 stamp currently points to the past, the first key press will move it
1175 to today. WHen nil, just move one day forward even if the date stays
1176 in the past."
1177 :group 'org-agenda-daily/weekly
1178 :version "24.1"
1179 :type 'boolean)
1181 (defcustom org-agenda-include-diary nil
1182 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1183 Custom commands can set this variable in the options section."
1184 :group 'org-agenda-daily/weekly
1185 :type 'boolean)
1187 (defcustom org-agenda-include-deadlines t
1188 "If non-nil, include entries within their deadline warning period.
1189 Custom commands can set this variable in the options section."
1190 :group 'org-agenda-daily/weekly
1191 :version "24.1"
1192 :type 'boolean)
1194 (defcustom org-agenda-repeating-timestamp-show-all t
1195 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1196 When set to a list of strings, only show occurrences of repeating
1197 stamps for these TODO keywords. When nil, only one occurrence is
1198 shown, either today or the nearest into the future."
1199 :group 'org-agenda-daily/weekly
1200 :type '(choice
1201 (const :tag "Show repeating stamps" t)
1202 (repeat :tag "Show repeating stamps for these TODO keywords"
1203 (string :tag "TODO Keyword"))
1204 (const :tag "Don't show repeating stamps" nil)))
1206 (defcustom org-scheduled-past-days 10000
1207 "Number of days to continue listing scheduled items not marked DONE.
1208 When an item is scheduled on a date, it shows up in the agenda on this
1209 day and will be listed until it is marked done for the number of days
1210 given here."
1211 :group 'org-agenda-daily/weekly
1212 :type 'integer)
1214 (defcustom org-agenda-log-mode-items '(closed clock)
1215 "List of items that should be shown in agenda log mode.
1216 This list may contain the following symbols:
1218 closed Show entries that have been closed on that day.
1219 clock Show entries that have received clocked time on that day.
1220 state Show all logged state changes.
1221 Note that instead of changing this variable, you can also press `C-u l' in
1222 the agenda to display all available LOG items temporarily."
1223 :group 'org-agenda-daily/weekly
1224 :type '(set :greedy t (const closed) (const clock) (const state)))
1226 (defcustom org-agenda-clock-consistency-checks
1227 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1228 :gap-ok-around ("4:00")
1229 :default-face ((:background "DarkRed") (:foreground "white"))
1230 :overlap-face nil :gap-face nil :no-end-time-face nil
1231 :long-face nil :short-face nil)
1232 "This is a property list, with the following keys:
1234 :max-duration Mark clocking chunks that are longer than this time.
1235 This is a time string like \"HH:MM\", or the number
1236 of minutes as an integer.
1238 :min-duration Mark clocking chunks that are shorter that this.
1239 This is a time string like \"HH:MM\", or the number
1240 of minutes as an integer.
1242 :max-gap Mark gaps between clocking chunks that are longer than
1243 this duration. A number of minutes, or a string
1244 like \"HH:MM\".
1246 :gap-ok-around List of times during the day which are usually not working
1247 times. When a gap is detected, but the gap contains any
1248 of these times, the gap is *not* reported. For example,
1249 if this is (\"4:00\" \"13:00\") then gaps that contain
1250 4:00 in the morning (i.e. the night) and 13:00
1251 (i.e. a typical lunch time) do not cause a warning.
1252 You should have at least one time during the night in this
1253 list, or otherwise the first task each morning will trigger
1254 a warning because it follows a long gap.
1256 Furthermore, the following properties can be used to define faces for
1257 issue display.
1259 :default-face the default face, if the specific face is undefined
1260 :overlap-face face for overlapping clocks
1261 :gap-face face for gaps between clocks
1262 :no-end-time-face face for incomplete clocks
1263 :long-face face for clock intervals that are too long
1264 :short-face face for clock intervals that are too short"
1265 :group 'org-agenda-daily/weekly
1266 :group 'org-clock
1267 :version "24.1"
1268 :type 'plist)
1270 (defcustom org-agenda-log-mode-add-notes t
1271 "Non-nil means add first line of notes to log entries in agenda views.
1272 If a log item like a state change or a clock entry is associated with
1273 notes, the first line of these notes will be added to the entry in the
1274 agenda display."
1275 :group 'org-agenda-daily/weekly
1276 :type 'boolean)
1278 (defcustom org-agenda-start-with-log-mode nil
1279 "The initial value of log-mode in a newly created agenda window.
1280 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1281 explanations on the possible values."
1282 :group 'org-agenda-startup
1283 :group 'org-agenda-daily/weekly
1284 :type '(choice (const :tag "Don't show log items" nil)
1285 (const :tag "Show only log items" 'only)
1286 (const :tag "Show all possible log items" 'clockcheck)
1287 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1288 (choice (const :tag "Show closed log items" 'closed)
1289 (const :tag "Show clocked log items" 'clock)
1290 (const :tag "Show all logged state changes" 'state)))))
1292 (defcustom org-agenda-start-with-clockreport-mode nil
1293 "The initial value of clockreport-mode in a newly created agenda window."
1294 :group 'org-agenda-startup
1295 :group 'org-agenda-daily/weekly
1296 :type 'boolean)
1298 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1299 "Property list with parameters for the clocktable in clockreport mode.
1300 This is the display mode that shows a clock table in the daily/weekly
1301 agenda, the properties for this dynamic block can be set here.
1302 The usual clocktable parameters are allowed here, but you cannot set
1303 the properties :name, :tstart, :tend, :block, and :scope - these will
1304 be overwritten to make sure the content accurately reflects the
1305 current display in the agenda."
1306 :group 'org-agenda-daily/weekly
1307 :type 'plist)
1309 (defcustom org-agenda-search-view-always-boolean nil
1310 "Non-nil means the search string is interpreted as individual parts.
1312 The search string for search view can either be interpreted as a phrase,
1313 or as a list of snippets that define a boolean search for a number of
1314 strings.
1316 When this is non-nil, the string will be split on whitespace, and each
1317 snippet will be searched individually, and all must match in order to
1318 select an entry. A snippet is then a single string of non-white
1319 characters, or a string in double quotes, or a regexp in {} braces.
1320 If a snippet is preceded by \"-\", the snippet must *not* match.
1321 \"+\" is syntactic sugar for positive selection. Each snippet may
1322 be found as a full word or a partial word, but see the variable
1323 `org-agenda-search-view-force-full-words'.
1325 When this is nil, search will look for the entire search phrase as one,
1326 with each space character matching any amount of whitespace, including
1327 line breaks.
1329 Even when this is nil, you can still switch to Boolean search dynamically
1330 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1331 is a regexp marked with braces like \"{abc}\", this will also switch to
1332 boolean search."
1333 :group 'org-agenda-search-view
1334 :version "24.1"
1335 :type 'boolean)
1337 (if (fboundp 'defvaralias)
1338 (defvaralias 'org-agenda-search-view-search-words-only
1339 'org-agenda-search-view-always-boolean))
1341 (defcustom org-agenda-search-view-force-full-words nil
1342 "Non-nil means, search words must be matches as complete words.
1343 When nil, they may also match part of a word."
1344 :group 'org-agenda-search-view
1345 :version "24.1"
1346 :type 'boolean)
1348 (defcustom org-agenda-search-view-max-outline-level nil
1349 "Maximum outline level to display in search view.
1350 E.g. when this is set to 1, the search view will only
1351 show headlines of level 1."
1352 :group 'org-agenda-search-view
1353 :version "24.4"
1354 :package-version '(Org . "8.0")
1355 :type 'integer)
1357 (defgroup org-agenda-time-grid nil
1358 "Options concerning the time grid in the Org-mode Agenda."
1359 :tag "Org Agenda Time Grid"
1360 :group 'org-agenda)
1362 (defcustom org-agenda-search-headline-for-time t
1363 "Non-nil means search headline for a time-of-day.
1364 If the headline contains a time-of-day in one format or another, it will
1365 be used to sort the entry into the time sequence of items for a day.
1366 Some people have time stamps in the headline that refer to the creation
1367 time or so, and then this produces an unwanted side effect. If this is
1368 the case for your, use this variable to turn off searching the headline
1369 for a time."
1370 :group 'org-agenda-time-grid
1371 :type 'boolean)
1373 (defcustom org-agenda-use-time-grid t
1374 "Non-nil means show a time grid in the agenda schedule.
1375 A time grid is a set of lines for specific times (like every two hours between
1376 8:00 and 20:00). The items scheduled for a day at specific times are
1377 sorted in between these lines.
1378 For details about when the grid will be shown, and what it will look like, see
1379 the variable `org-agenda-time-grid'."
1380 :group 'org-agenda-time-grid
1381 :type 'boolean)
1383 (defcustom org-agenda-time-grid
1384 '((daily today require-timed)
1385 "----------------"
1386 (800 1000 1200 1400 1600 1800 2000))
1388 "The settings for time grid for agenda display.
1389 This is a list of three items. The first item is again a list. It contains
1390 symbols specifying conditions when the grid should be displayed:
1392 daily if the agenda shows a single day
1393 weekly if the agenda shows an entire week
1394 today show grid on current date, independent of daily/weekly display
1395 require-timed show grid only if at least one item has a time specification
1397 The second item is a string which will be placed behind the grid time.
1399 The third item is a list of integers, indicating the times that should have
1400 a grid line."
1401 :group 'org-agenda-time-grid
1402 :type
1403 '(list
1404 (set :greedy t :tag "Grid Display Options"
1405 (const :tag "Show grid in single day agenda display" daily)
1406 (const :tag "Show grid in weekly agenda display" weekly)
1407 (const :tag "Always show grid for today" today)
1408 (const :tag "Show grid only if any timed entries are present"
1409 require-timed)
1410 (const :tag "Skip grid times already present in an entry"
1411 remove-match))
1412 (string :tag "Grid String")
1413 (repeat :tag "Grid Times" (integer :tag "Time"))))
1415 (defcustom org-agenda-show-current-time-in-grid t
1416 "Non-nil means show the current time in the time grid."
1417 :group 'org-agenda-time-grid
1418 :version "24.1"
1419 :type 'boolean)
1421 (defcustom org-agenda-current-time-string
1422 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1423 "The string for the current time marker in the agenda."
1424 :group 'org-agenda-time-grid
1425 :version "24.1"
1426 :type 'string)
1428 (defgroup org-agenda-sorting nil
1429 "Options concerning sorting in the Org-mode Agenda."
1430 :tag "Org Agenda Sorting"
1431 :group 'org-agenda)
1433 (defcustom org-agenda-sorting-strategy
1434 '((agenda habit-down time-up priority-down category-keep)
1435 (todo priority-down category-keep)
1436 (tags priority-down category-keep)
1437 (search category-keep))
1438 "Sorting structure for the agenda items of a single day.
1439 This is a list of symbols which will be used in sequence to determine
1440 if an entry should be listed before another entry. The following
1441 symbols are recognized:
1443 time-up Put entries with time-of-day indications first, early first
1444 time-down Put entries with time-of-day indications first, late first
1445 timestamp-up Sort by any timestamp, early first
1446 timestamp-down Sort by any timestamp, late first
1447 scheduled-up Sort by scheduled timestamp, early first
1448 scheduled-down Sort by scheduled timestamp, late first
1449 deadline-up Sort by deadline timestamp, early first
1450 deadline-down Sort by deadline timestamp, late first
1451 ts-up Sort by active timestamp, early first
1452 ts-down Sort by active timestamp, late first
1453 tsia-up Sort by inactive timestamp, early first
1454 tsia-down Sort by inactive timestamp, late first
1455 category-keep Keep the default order of categories, corresponding to the
1456 sequence in `org-agenda-files'.
1457 category-up Sort alphabetically by category, A-Z.
1458 category-down Sort alphabetically by category, Z-A.
1459 tag-up Sort alphabetically by last tag, A-Z.
1460 tag-down Sort alphabetically by last tag, Z-A.
1461 priority-up Sort numerically by priority, high priority last.
1462 priority-down Sort numerically by priority, high priority first.
1463 todo-state-up Sort by todo state, tasks that are done last.
1464 todo-state-down Sort by todo state, tasks that are done first.
1465 effort-up Sort numerically by estimated effort, high effort last.
1466 effort-down Sort numerically by estimated effort, high effort first.
1467 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1468 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1469 habit-up Put entries that are habits first
1470 habit-down Put entries that are habits last
1471 alpha-up Sort headlines alphabetically
1472 alpha-down Sort headlines alphabetically, reversed
1474 The different possibilities will be tried in sequence, and testing stops
1475 if one comparison returns a \"not-equal\". For example, the default
1476 '(time-up category-keep priority-down)
1477 means: Pull out all entries having a specified time of day and sort them,
1478 in order to make a time schedule for the current day the first thing in the
1479 agenda listing for the day. Of the entries without a time indication, keep
1480 the grouped in categories, don't sort the categories, but keep them in
1481 the sequence given in `org-agenda-files'. Within each category sort by
1482 priority.
1484 Leaving out `category-keep' would mean that items will be sorted across
1485 categories by priority.
1487 Instead of a single list, this can also be a set of list for specific
1488 contents, with a context symbol in the car of the list, any of
1489 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1491 Custom commands can bind this variable in the options section."
1492 :group 'org-agenda-sorting
1493 :type `(choice
1494 (repeat :tag "General" ,org-sorting-choice)
1495 (list :tag "Individually"
1496 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1497 (repeat ,org-sorting-choice))
1498 (cons (const :tag "Strategy for TODO lists" todo)
1499 (repeat ,org-sorting-choice))
1500 (cons (const :tag "Strategy for Tags matches" tags)
1501 (repeat ,org-sorting-choice))
1502 (cons (const :tag "Strategy for search matches" search)
1503 (repeat ,org-sorting-choice)))))
1505 (defcustom org-agenda-cmp-user-defined nil
1506 "A function to define the comparison `user-defined'.
1507 This function must receive two arguments, agenda entry a and b.
1508 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1509 the user comparison, return nil.
1510 When this is defined, you can make `user-defined-up' and `user-defined-down'
1511 part of an agenda sorting strategy."
1512 :group 'org-agenda-sorting
1513 :type 'symbol)
1515 (defcustom org-sort-agenda-notime-is-late t
1516 "Non-nil means items without time are considered late.
1517 This is only relevant for sorting. When t, items which have no explicit
1518 time like 15:30 will be considered as 99:01, i.e. later than any items which
1519 do have a time. When nil, the default time is before 0:00. You can use this
1520 option to decide if the schedule for today should come before or after timeless
1521 agenda entries."
1522 :group 'org-agenda-sorting
1523 :type 'boolean)
1525 (defcustom org-sort-agenda-noeffort-is-high t
1526 "Non-nil means items without effort estimate are sorted as high effort.
1527 This also applies when filtering an agenda view with respect to the
1528 < or > effort operator. Then, tasks with no effort defined will be treated
1529 as tasks with high effort.
1530 When nil, such items are sorted as 0 minutes effort."
1531 :group 'org-agenda-sorting
1532 :type 'boolean)
1534 (defgroup org-agenda-line-format nil
1535 "Options concerning the entry prefix in the Org-mode agenda display."
1536 :tag "Org Agenda Line Format"
1537 :group 'org-agenda)
1539 (defcustom org-agenda-prefix-format
1540 '((agenda . " %i %-12:c%?-12t% s")
1541 (timeline . " % s")
1542 (todo . " %i %-12:c")
1543 (tags . " %i %-12:c")
1544 (search . " %i %-12:c"))
1545 "Format specifications for the prefix of items in the agenda views.
1546 An alist with five entries, each for the different agenda types. The
1547 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1548 The values are format strings.
1550 This format works similar to a printf format, with the following meaning:
1552 %c the category of the item, \"Diary\" for entries from the diary,
1553 or as given by the CATEGORY keyword or derived from the file name
1554 %e the effort required by the item
1555 %l the level of the item (insert X space(s) if item is of level X)
1556 %i the icon category of the item, see `org-agenda-category-icon-alist'
1557 %T the last tag of the item (ignore inherited tags, which come first)
1558 %t the HH:MM time-of-day specification if one applies to the entry
1559 %s Scheduling/Deadline information, a short string
1560 %b show breadcrumbs, i.e., the names of the higher levels
1561 %(expression) Eval EXPRESSION and replace the control string
1562 by the result
1564 All specifiers work basically like the standard `%s' of printf, but may
1565 contain two additional characters: a question mark just after the `%'
1566 and a whitespace/punctuation character just before the final letter.
1568 If the first character after `%' is a question mark, the entire field
1569 will only be included if the corresponding value applies to the current
1570 entry. This is useful for fields which should have fixed width when
1571 present, but zero width when absent. For example, \"%?-12t\" will
1572 result in a 12 character time field if a time of the day is specified,
1573 but will completely disappear in entries which do not contain a time.
1575 If there is punctuation or whitespace character just before the
1576 final format letter, this character will be appended to the field
1577 value if the value is not empty. For example, the format
1578 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1579 the category is empty, no additional colon is inserted.
1581 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1582 which means:
1584 - Indent the line with two space characters
1585 - Give the category a 12 chars wide field, padded with whitespace on
1586 the right (because of `-'). Append a colon if there is a category
1587 (because of `:').
1588 - If there is a time-of-day, put it into a 12 chars wide field. If no
1589 time, don't put in an empty field, just skip it (because of '?').
1590 - Finally, put the scheduling information.
1592 See also the variables `org-agenda-remove-times-when-in-prefix' and
1593 `org-agenda-remove-tags'.
1595 Custom commands can set this variable in the options section."
1596 :type '(choice
1597 (string :tag "General format")
1598 (list :greedy t :tag "View dependent"
1599 (cons (const agenda) (string :tag "Format"))
1600 (cons (const timeline) (string :tag "Format"))
1601 (cons (const todo) (string :tag "Format"))
1602 (cons (const tags) (string :tag "Format"))
1603 (cons (const search) (string :tag "Format"))))
1604 :group 'org-agenda-line-format)
1606 (defvar org-prefix-format-compiled nil
1607 "The compiled prefix format and associated variables.
1608 This is a list where first element is a list of variable bindings, and second
1609 element is the compiled format expression. See the variable
1610 `org-agenda-prefix-format'.")
1612 (defcustom org-agenda-todo-keyword-format "%-1s"
1613 "Format for the TODO keyword in agenda lines.
1614 Set this to something like \"%-12s\" if you want all TODO keywords
1615 to occupy a fixed space in the agenda display."
1616 :group 'org-agenda-line-format
1617 :type 'string)
1619 (defcustom org-agenda-diary-sexp-prefix nil
1620 "A regexp that matches part of a diary sexp entry
1621 which should be treated as scheduling/deadline information in
1622 `org-agenda'.
1624 For example, you can use this to extract the `diary-remind-message' from
1625 `diary-remind' entries."
1626 :group 'org-agenda-line-format
1627 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1629 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1630 "Text preceding timerange entries in the agenda view.
1631 This is a list with two strings. The first applies when the range
1632 is entirely on one day. The second applies if the range spans several days.
1633 The strings may have two \"%d\" format specifiers which will be filled
1634 with the sequence number of the days, and the total number of days in the
1635 range, respectively."
1636 :group 'org-agenda-line-format
1637 :type '(list
1638 (string :tag "Deadline today ")
1639 (choice :tag "Deadline relative"
1640 (string :tag "Format string")
1641 (function))))
1643 (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
1644 "Text preceding scheduled items in the agenda view.
1645 This is a list with two strings. The first applies when the item is
1646 scheduled on the current day. The second applies when it has been scheduled
1647 previously, it may contain a %d indicating that this is the nth time that
1648 this item is scheduled, due to automatic rescheduling of unfinished items
1649 for the following day. So this number is one larger than the number of days
1650 that passed since this item was scheduled first."
1651 :group 'org-agenda-line-format
1652 :version "24.4"
1653 :package-version '(Org . "8.0")
1654 :type '(list
1655 (string :tag "Scheduled today ")
1656 (string :tag "Scheduled previously")))
1658 (defcustom org-agenda-inactive-leader "["
1659 "Text preceding item pulled into the agenda by inactive time stamps.
1660 These entries are added to the agenda when pressing \"[\"."
1661 :group 'org-agenda-line-format
1662 :version "24.1"
1663 :type '(list
1664 (string :tag "Scheduled today ")
1665 (string :tag "Scheduled previously")))
1667 (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
1668 "Text preceding deadline items in the agenda view.
1669 This is a list with three strings. The first applies when the item has its
1670 deadline on the current day. The second applies when the deadline is in the
1671 future, the third one when it is in the past. The strings may contain %d
1672 to capture the number of days."
1673 :group 'org-agenda-line-format
1674 :version "24.4"
1675 :package-version '(Org . "8.0")
1676 :type '(list
1677 (string :tag "Deadline today ")
1678 (choice :tag "Deadline relative"
1679 (string :tag "Format string")
1680 (function))))
1682 (defcustom org-agenda-remove-times-when-in-prefix t
1683 "Non-nil means remove duplicate time specifications in agenda items.
1684 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1685 time-of-day specification in a headline or diary entry is extracted and
1686 placed into the prefix. If this option is non-nil, the original specification
1687 \(a timestamp or -range, or just a plain time(range) specification like
1688 11:30-4pm) will be removed for agenda display. This makes the agenda less
1689 cluttered.
1690 The option can be t or nil. It may also be the symbol `beg', indicating
1691 that the time should only be removed when it is located at the beginning of
1692 the headline/diary entry."
1693 :group 'org-agenda-line-format
1694 :type '(choice
1695 (const :tag "Always" t)
1696 (const :tag "Never" nil)
1697 (const :tag "When at beginning of entry" beg)))
1699 (defcustom org-agenda-remove-timeranges-from-blocks nil
1700 "Non-nil means remove time ranges specifications in agenda
1701 items that span on several days."
1702 :group 'org-agenda-line-format
1703 :version "24.1"
1704 :type 'boolean)
1706 (defcustom org-agenda-default-appointment-duration nil
1707 "Default duration for appointments that only have a starting time.
1708 When nil, no duration is specified in such cases.
1709 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1710 :group 'org-agenda-line-format
1711 :type '(choice
1712 (integer :tag "Minutes")
1713 (const :tag "No default duration")))
1715 (defcustom org-agenda-show-inherited-tags t
1716 "Non-nil means show inherited tags in each agenda line.
1718 When this option is set to 'always, it take precedences over
1719 `org-agenda-use-tag-inheritance' and inherited tags are shown
1720 in every agenda.
1722 When this option is set to t (the default), inherited tags are
1723 shown when they are available, i.e. when the value of
1724 `org-agenda-use-tag-inheritance' has been taken into account.
1726 This can be set to a list of agenda types in which the agenda
1727 must display the inherited tags. Available types are 'todo,
1728 'agenda, 'search and 'timeline.
1730 When set to nil, never show inherited tags in agenda lines."
1731 :group 'org-agenda-line-format
1732 :group 'org-agenda
1733 :version "24.3"
1734 :type '(choice
1735 (const :tag "Show inherited tags when available" t)
1736 (const :tag "Always show inherited tags" 'always)
1737 (repeat :tag "Show inherited tags only in selected agenda types"
1738 (symbol :tag "Agenda type"))))
1740 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1741 "List of agenda view types where to use tag inheritance.
1743 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1744 controlled by `org-use-tag-inheritance'. In other agenda types,
1745 `org-use-tag-inheritance' is not used for the selection of the
1746 agenda entries. Still, you may want the agenda to be aware of
1747 the inherited tags anyway, e.g. for later tag filtering.
1749 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1751 This variable has no effect if `org-agenda-show-inherited-tags'
1752 is set to 'always. In that case, the agenda is aware of those
1753 tags.
1755 The default value sets tags in every agenda type. Setting this
1756 option to nil will speed up non-tags agenda view a lot."
1757 :group 'org-agenda
1758 :version "24.3"
1759 :type '(choice
1760 (const :tag "Use tag inheritance in all agenda types" t)
1761 (repeat :tag "Use tag inheritance in selected agenda types"
1762 (symbol :tag "Agenda type"))))
1764 (defcustom org-agenda-hide-tags-regexp nil
1765 "Regular expression used to filter away specific tags in agenda views.
1766 This means that these tags will be present, but not be shown in the agenda
1767 line. Secondary filtering will still work on the hidden tags.
1768 Nil means don't hide any tags."
1769 :group 'org-agenda-line-format
1770 :type '(choice
1771 (const :tag "Hide none" nil)
1772 (string :tag "Regexp ")))
1774 (defcustom org-agenda-remove-tags nil
1775 "Non-nil means remove the tags from the headline copy in the agenda.
1776 When this is the symbol `prefix', only remove tags when
1777 `org-agenda-prefix-format' contains a `%T' specifier."
1778 :group 'org-agenda-line-format
1779 :type '(choice
1780 (const :tag "Always" t)
1781 (const :tag "Never" nil)
1782 (const :tag "When prefix format contains %T" prefix)))
1784 (if (fboundp 'defvaralias)
1785 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1786 'org-agenda-remove-tags))
1788 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1789 "Shift tags in agenda items to this column.
1790 If this number is positive, it specifies the column. If it is negative,
1791 it means that the tags should be flushright to that column. For example,
1792 -80 works well for a normal 80 character screen."
1793 :group 'org-agenda-line-format
1794 :type 'integer)
1796 (if (fboundp 'defvaralias)
1797 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1799 (defcustom org-agenda-fontify-priorities 'cookies
1800 "Non-nil means highlight low and high priorities in agenda.
1801 When t, the highest priority entries are bold, lowest priority italic.
1802 However, settings in `org-priority-faces' will overrule these faces.
1803 When this variable is the symbol `cookies', only fontify the
1804 cookies, not the entire task.
1805 This may also be an association list of priority faces, whose
1806 keys are the character values of `org-highest-priority',
1807 `org-default-priority', and `org-lowest-priority' (the default values
1808 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1809 color as a string, or a list like `(:background \"Red\")'.
1810 If it is a color, the variable `org-faces-easy-properties'
1811 determines if it is a foreground or a background color."
1812 :group 'org-agenda-line-format
1813 :type '(choice
1814 (const :tag "Never" nil)
1815 (const :tag "Defaults" t)
1816 (const :tag "Cookies only" cookies)
1817 (repeat :tag "Specify"
1818 (list (character :tag "Priority" :value ?A)
1819 (choice :tag "Face "
1820 (string :tag "Color")
1821 (sexp :tag "Face"))))))
1823 (defcustom org-agenda-day-face-function nil
1824 "Function called to determine what face should be used to display a day.
1825 The only argument passed to that function is the day. It should
1826 returns a face, or nil if does not want to specify a face and let
1827 the normal rules apply."
1828 :group 'org-agenda-line-format
1829 :version "24.1"
1830 :type 'function)
1832 (defcustom org-agenda-category-icon-alist nil
1833 "Alist of category icon to be displayed in agenda views.
1835 Each entry should have the following format:
1837 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1839 Where CATEGORY-REGEXP is a regexp matching the categories where
1840 the icon should be displayed.
1841 FILE-OR-DATA either a file path or a string containing image data.
1843 The other fields can be omitted safely if not needed:
1844 TYPE indicates the image type.
1845 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1846 image data.
1847 PROPS are additional image attributes to assign to the image,
1848 like, e.g. `:ascent center'.
1850 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1852 If you want to set the display properties yourself, just put a
1853 list as second element:
1855 (CATEGORY-REGEXP (MY PROPERTY LIST))
1857 For example, to display a 16px horizontal space for Emacs
1858 category, you can use:
1860 (\"Emacs\" '(space . (:width (16))))"
1861 :group 'org-agenda-line-format
1862 :version "24.1"
1863 :type '(alist :key-type (string :tag "Regexp matching category")
1864 :value-type (choice (list :tag "Icon"
1865 (string :tag "File or data")
1866 (symbol :tag "Type")
1867 (boolean :tag "Data?")
1868 (repeat :tag "Extra image properties" :inline t symbol))
1869 (list :tag "Display properties" sexp))))
1871 (defgroup org-agenda-column-view nil
1872 "Options concerning column view in the agenda."
1873 :tag "Org Agenda Column View"
1874 :group 'org-agenda)
1876 (defcustom org-agenda-columns-show-summaries t
1877 "Non-nil means show summaries for columns displayed in the agenda view."
1878 :group 'org-agenda-column-view
1879 :type 'boolean)
1881 (defcustom org-agenda-columns-compute-summary-properties t
1882 "Non-nil means recompute all summary properties before column view.
1883 When column view in the agenda is listing properties that have a summary
1884 operator, it can go to all relevant buffers and recompute the summaries
1885 there. This can mean overhead for the agenda column view, but is necessary
1886 to have thing up to date.
1887 As a special case, a CLOCKSUM property also makes sure that the clock
1888 computations are current."
1889 :group 'org-agenda-column-view
1890 :type 'boolean)
1892 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1893 "Non-nil means the duration of an appointment will add to day effort.
1894 The property to which appointment durations will be added is the one given
1895 in the option `org-effort-property'. If an appointment does not have
1896 an end time, `org-agenda-default-appointment-duration' will be used. If that
1897 is not set, an appointment without end time will not contribute to the time
1898 estimate."
1899 :group 'org-agenda-column-view
1900 :type 'boolean)
1902 (defcustom org-agenda-auto-exclude-function nil
1903 "A function called with a tag to decide if it is filtered on '/ RET'.
1904 The sole argument to the function, which is called once for each
1905 possible tag, is a string giving the name of the tag. The
1906 function should return either nil if the tag should be included
1907 as normal, or \"-<TAG>\" to exclude the tag.
1908 Note that for the purpose of tag filtering, only the lower-case version of
1909 all tags will be considered, so that this function will only ever see
1910 the lower-case version of all tags."
1911 :group 'org-agenda
1912 :type 'function)
1914 (defcustom org-agenda-bulk-custom-functions nil
1915 "Alist of characters and custom functions for bulk actions.
1916 For example, this value makes those two functions available:
1918 '((?R set-category)
1919 (?C bulk-cut))
1921 With selected entries in an agenda buffer, `B R' will call
1922 the custom function `set-category' on the selected entries.
1923 Note that functions in this alist don't need to be quoted."
1924 :type 'alist
1925 :version "24.1"
1926 :group 'org-agenda)
1928 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1929 "Execute BODY with point at location given by `org-hd-marker' property.
1930 If STRING is non-nil, the text property will be fetched from position 0
1931 in that string. If STRING is nil, it will be fetched from the beginning
1932 of the current line."
1933 (org-with-gensyms (marker)
1934 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1935 'org-hd-marker ,string)))
1936 (with-current-buffer (marker-buffer ,marker)
1937 (save-excursion
1938 (goto-char ,marker)
1939 ,@body)))))
1940 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1942 (defun org-add-agenda-custom-command (entry)
1943 "Replace or add a command in `org-agenda-custom-commands'.
1944 This is mostly for hacking and trying a new command - once the command
1945 works you probably want to add it to `org-agenda-custom-commands' for good."
1946 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1947 (if ass
1948 (setcdr ass (cdr entry))
1949 (push entry org-agenda-custom-commands))))
1951 ;;; Define the org-agenda-mode
1953 (defvar org-agenda-mode-map (make-sparse-keymap)
1954 "Keymap for `org-agenda-mode'.")
1955 (if (fboundp 'defvaralias)
1956 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1958 (defvar org-agenda-menu) ; defined later in this file.
1959 (defvar org-agenda-restrict nil) ; defined later in this file.
1960 (defvar org-agenda-follow-mode nil)
1961 (defvar org-agenda-entry-text-mode nil)
1962 (defvar org-agenda-clockreport-mode nil)
1963 (defvar org-agenda-show-log nil)
1964 (defvar org-agenda-redo-command nil)
1965 (defvar org-agenda-query-string nil)
1966 (defvar org-agenda-mode-hook nil
1967 "Hook run after `org-agenda-mode' is turned on.
1968 The buffer is still writable when this hook is called.")
1969 (defvar org-agenda-type nil)
1970 (defvar org-agenda-force-single-file nil)
1971 (defvar org-agenda-bulk-marked-entries nil
1972 "List of markers that refer to marked entries in the agenda.")
1974 ;;; Multiple agenda buffers support
1976 (defcustom org-agenda-sticky nil
1977 "Non-nil means agenda q key will bury agenda buffers.
1978 Agenda commands will then show existing buffer instead of generating new ones.
1979 When nil, `q' will kill the single agenda buffer."
1980 :group 'org-agenda
1981 :version "24.3"
1982 :type 'boolean)
1985 ;;;###autoload
1986 (defun org-toggle-sticky-agenda (&optional arg)
1987 "Toggle `org-agenda-sticky'."
1988 (interactive "P")
1989 (let ((new-value (if arg
1990 (> (prefix-numeric-value arg) 0)
1991 (not org-agenda-sticky))))
1992 (if (equal new-value org-agenda-sticky)
1993 (and (org-called-interactively-p 'interactive)
1994 (message "Sticky agenda was already %s"
1995 (if org-agenda-sticky "enabled" "disabled")))
1996 (setq org-agenda-sticky new-value)
1997 (org-agenda-kill-all-agenda-buffers)
1998 (and (org-called-interactively-p 'interactive)
1999 (message "Sticky agenda was %s"
2000 (if org-agenda-sticky "enabled" "disabled"))))))
2002 (defvar org-agenda-buffer nil
2003 "Agenda buffer currently being generated.")
2005 (defvar org-agenda-last-prefix-arg nil)
2006 (defvar org-agenda-this-buffer-name nil)
2007 (defvar org-agenda-doing-sticky-redo nil)
2008 (defvar org-agenda-this-buffer-is-sticky nil)
2010 (defconst org-agenda-local-vars
2011 '(org-agenda-this-buffer-name
2012 org-agenda-undo-list
2013 org-agenda-pending-undo-list
2014 org-agenda-follow-mode
2015 org-agenda-entry-text-mode
2016 org-agenda-clockreport-mode
2017 org-agenda-show-log
2018 org-agenda-redo-command
2019 org-agenda-query-string
2020 org-agenda-type
2021 org-agenda-bulk-marked-entries
2022 org-agenda-undo-has-started-in
2023 org-agenda-info
2024 org-agenda-tag-filter-overlays
2025 org-agenda-cat-filter-overlays
2026 org-agenda-pre-window-conf
2027 org-agenda-columns-active
2028 org-agenda-tag-filter
2029 org-agenda-category-filter
2030 org-agenda-markers
2031 org-agenda-last-search-view-search-was-boolean
2032 org-agenda-filtered-by-category
2033 org-agenda-filter-form
2034 org-agenda-cycle-counter
2035 org-agenda-last-prefix-arg)
2036 "Variables that must be local in agenda buffers to allow multiple buffers.")
2038 (defun org-agenda-mode ()
2039 "Mode for time-sorted view on action items in Org-mode files.
2041 The following commands are available:
2043 \\{org-agenda-mode-map}"
2044 (interactive)
2045 (cond (org-agenda-doing-sticky-redo
2046 ;; Refreshing sticky agenda-buffer
2048 ;; Preserve the value of `org-agenda-local-vars' variables,
2049 ;; while letting `kill-all-local-variables' kill the rest
2050 (let ((save (buffer-local-variables)))
2051 (kill-all-local-variables)
2052 (mapc 'make-local-variable org-agenda-local-vars)
2053 (dolist (elem save)
2054 (let ((var (car elem))
2055 (val (cdr elem)))
2056 (when (and val
2057 (member var org-agenda-local-vars))
2058 (set var val)))))
2059 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2060 (org-agenda-sticky
2061 ;; Creating a sticky Agenda buffer for the first time
2062 (kill-all-local-variables)
2063 (mapc 'make-local-variable org-agenda-local-vars)
2064 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2066 ;; Creating a non-sticky agenda buffer
2067 (kill-all-local-variables)
2068 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2069 (setq org-agenda-undo-list nil
2070 org-agenda-pending-undo-list nil
2071 org-agenda-bulk-marked-entries nil)
2072 (setq major-mode 'org-agenda-mode)
2073 ;; Keep global-font-lock-mode from turning on font-lock-mode
2074 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2075 (setq mode-name "Org-Agenda")
2076 (use-local-map org-agenda-mode-map)
2077 (easy-menu-add org-agenda-menu)
2078 (if org-startup-truncated (setq truncate-lines t))
2079 (org-set-local 'line-move-visual nil)
2080 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2081 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2082 ;; Make sure properties are removed when copying text
2083 (make-local-variable 'filter-buffer-substring-functions)
2084 (add-hook 'filter-buffer-substring-functions
2085 (lambda (fun start end delete)
2086 (substring-no-properties (funcall fun start end delete))))
2087 (unless org-agenda-keep-modes
2088 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2089 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2090 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2091 org-agenda-show-log org-agenda-start-with-log-mode))
2093 (easy-menu-change
2094 '("Agenda") "Agenda Files"
2095 (append
2096 (list
2097 (vector
2098 (if (get 'org-agenda-files 'org-restrict)
2099 "Restricted to single file"
2100 "Edit File List")
2101 '(org-edit-agenda-file-list)
2102 (not (get 'org-agenda-files 'org-restrict)))
2103 "--")
2104 (mapcar 'org-file-menu-entry (org-agenda-files))))
2105 (org-agenda-set-mode-name)
2106 (apply
2107 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2108 (list 'org-agenda-mode-hook)))
2110 (substitute-key-definition 'undo 'org-agenda-undo
2111 org-agenda-mode-map global-map)
2112 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2113 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2114 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2115 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2116 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2117 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2118 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2119 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2120 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2121 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2122 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2123 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2124 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2125 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2127 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2128 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2129 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2131 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2132 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2133 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2134 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2135 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2136 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2137 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2138 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2139 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2140 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2141 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2142 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2143 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2144 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2145 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2146 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2147 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2148 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2149 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2150 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2151 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2152 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2153 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2154 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2155 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2156 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2157 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2159 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2160 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2161 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2162 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2163 (while l (org-defkey org-agenda-mode-map
2164 (int-to-string (pop l)) 'digit-argument)))
2166 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2167 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2168 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2169 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2170 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2171 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2172 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2173 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2174 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2175 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2176 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2177 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2178 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2179 'org-clock-modify-effort-estimate)
2180 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2181 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2182 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2183 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2184 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2185 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2186 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2187 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2188 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2189 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2190 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2191 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2192 (substitute-key-definition 'next-line 'org-agenda-next-line
2193 org-agenda-mode-map global-map)
2194 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2195 org-agenda-mode-map global-map)
2196 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2197 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2198 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2199 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2200 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2201 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2202 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2203 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2204 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2205 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2206 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2207 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2208 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2209 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2210 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2211 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2212 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2213 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2214 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2215 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2216 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2217 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2218 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2219 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2220 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2221 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2222 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2223 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2224 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2225 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2227 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2228 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2229 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2230 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2231 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2232 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2233 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2234 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2235 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2236 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2237 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2238 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2240 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2241 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2242 (when org-agenda-mouse-1-follows-link
2243 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2244 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2245 '("Agenda"
2246 ("Agenda Files")
2247 "--"
2248 ("Agenda Dates"
2249 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2250 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2251 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2252 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2253 "--"
2254 ("View"
2255 ["Day View" org-agenda-day-view
2256 :active (org-agenda-check-type nil 'agenda)
2257 :style radio :selected (eq org-agenda-current-span 'day)
2258 :keys "v d (or just d)"]
2259 ["Week View" org-agenda-week-view
2260 :active (org-agenda-check-type nil 'agenda)
2261 :style radio :selected (eq org-agenda-current-span 'week)
2262 :keys "v w (or just w)"]
2263 ["Month View" org-agenda-month-view
2264 :active (org-agenda-check-type nil 'agenda)
2265 :style radio :selected (eq org-agenda-current-span 'month)
2266 :keys "v m"]
2267 ["Year View" org-agenda-year-view
2268 :active (org-agenda-check-type nil 'agenda)
2269 :style radio :selected (eq org-agenda-current-span 'year)
2270 :keys "v y"]
2271 "--"
2272 ["Include Diary" org-agenda-toggle-diary
2273 :style toggle :selected org-agenda-include-diary
2274 :active (org-agenda-check-type nil 'agenda)]
2275 ["Include Deadlines" org-agenda-toggle-deadlines
2276 :style toggle :selected org-agenda-include-deadlines
2277 :active (org-agenda-check-type nil 'agenda)]
2278 ["Use Time Grid" org-agenda-toggle-time-grid
2279 :style toggle :selected org-agenda-use-time-grid
2280 :active (org-agenda-check-type nil 'agenda)]
2281 "--"
2282 ["Show clock report" org-agenda-clockreport-mode
2283 :style toggle :selected org-agenda-clockreport-mode
2284 :active (org-agenda-check-type nil 'agenda)]
2285 ["Show some entry text" org-agenda-entry-text-mode
2286 :style toggle :selected org-agenda-entry-text-mode
2287 :active t]
2288 "--"
2289 ["Show Logbook entries" org-agenda-log-mode
2290 :style toggle :selected org-agenda-show-log
2291 :active (org-agenda-check-type nil 'agenda 'timeline)
2292 :keys "v l (or just l)"]
2293 ["Include archived trees" org-agenda-archives-mode
2294 :style toggle :selected org-agenda-archives-mode :active t
2295 :keys "v a"]
2296 ["Include archive files" (org-agenda-archives-mode t)
2297 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2298 :keys "v A"]
2299 "--"
2300 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2301 ["Write view to file" org-agenda-write t]
2302 ["Rebuild buffer" org-agenda-redo t]
2303 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2304 "--"
2305 ["Show original entry" org-agenda-show t]
2306 ["Go To (other window)" org-agenda-goto t]
2307 ["Go To (this window)" org-agenda-switch-to t]
2308 ["Capture with cursor date" org-agenda-capture t]
2309 ["Follow Mode" org-agenda-follow-mode
2310 :style toggle :selected org-agenda-follow-mode :active t]
2311 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2312 "--"
2313 ("TODO"
2314 ["Cycle TODO" org-agenda-todo t]
2315 ["Next TODO set" org-agenda-todo-nextset t]
2316 ["Previous TODO set" org-agenda-todo-previousset t]
2317 ["Add note" org-agenda-add-note t])
2318 ("Archive/Refile/Delete"
2319 ["Archive default" org-agenda-archive-default t]
2320 ["Archive default" org-agenda-archive-default-with-confirmation t]
2321 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2322 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2323 ["Archive subtree" org-agenda-archive t]
2324 "--"
2325 ["Refile" org-agenda-refile t]
2326 "--"
2327 ["Delete subtree" org-agenda-kill t])
2328 ("Bulk action"
2329 ["Mark entry" org-agenda-bulk-mark t]
2330 ["Mark all" org-agenda-bulk-mark-all t]
2331 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2332 ["Unmark entry" org-agenda-bulk-unmark t]
2333 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2334 ["Act on all marked" org-agenda-bulk-action t]
2335 "--"
2336 ("Tags and Properties"
2337 ["Show all Tags" org-agenda-show-tags t]
2338 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2339 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2340 "--"
2341 ["Column View" org-columns t])
2342 ("Deadline/Schedule"
2343 ["Schedule" org-agenda-schedule t]
2344 ["Set Deadline" org-agenda-deadline t]
2345 "--"
2346 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2347 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2348 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2349 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2350 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2351 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2352 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2353 ("Clock and Effort"
2354 ["Clock in" org-agenda-clock-in t]
2355 ["Clock out" org-agenda-clock-out t]
2356 ["Clock cancel" org-agenda-clock-cancel t]
2357 ["Goto running clock" org-clock-goto t]
2358 "--"
2359 ["Set Effort" org-agenda-set-effort t]
2360 ["Change clocked effort" org-clock-modify-effort-estimate
2361 (org-clock-is-active)])
2362 ("Priority"
2363 ["Set Priority" org-agenda-priority t]
2364 ["Increase Priority" org-agenda-priority-up t]
2365 ["Decrease Priority" org-agenda-priority-down t]
2366 ["Show Priority" org-show-priority t])
2367 ("Calendar/Diary"
2368 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2369 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2370 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2371 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2372 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2373 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2374 "--"
2375 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2376 "--"
2377 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2378 "--"
2379 ("MobileOrg"
2380 ["Push Files and Views" org-mobile-push t]
2381 ["Get Captured and Flagged" org-mobile-pull t]
2382 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2383 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2384 "--"
2385 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2386 "--"
2387 ["Quit" org-agenda-quit t]
2388 ["Exit and Release Buffers" org-agenda-exit t]
2391 ;;; Agenda undo
2393 (defvar org-agenda-allow-remote-undo t
2394 "Non-nil means allow remote undo from the agenda buffer.")
2395 (defvar org-agenda-undo-has-started-in nil
2396 "Buffers that have already seen `undo-start' in the current undo sequence.")
2398 (defun org-agenda-undo ()
2399 "Undo a remote editing step in the agenda.
2400 This undoes changes both in the agenda buffer and in the remote buffer
2401 that have been changed along."
2402 (interactive)
2403 (or org-agenda-allow-remote-undo
2404 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2405 (if (not (eq this-command last-command))
2406 (setq org-agenda-undo-has-started-in nil
2407 org-agenda-pending-undo-list org-agenda-undo-list))
2408 (if (not org-agenda-pending-undo-list)
2409 (error "No further undo information"))
2410 (let* ((entry (pop org-agenda-pending-undo-list))
2411 buf line cmd rembuf)
2412 (setq cmd (pop entry) line (pop entry))
2413 (setq rembuf (nth 2 entry))
2414 (org-with-remote-undo rembuf
2415 (while (bufferp (setq buf (pop entry)))
2416 (if (pop entry)
2417 (with-current-buffer buf
2418 (let ((last-undo-buffer buf)
2419 (inhibit-read-only t))
2420 (unless (memq buf org-agenda-undo-has-started-in)
2421 (push buf org-agenda-undo-has-started-in)
2422 (make-local-variable 'pending-undo-list)
2423 (undo-start))
2424 (while (and pending-undo-list
2425 (listp pending-undo-list)
2426 (not (car pending-undo-list)))
2427 (pop pending-undo-list))
2428 (undo-more 1))))))
2429 (org-goto-line line)
2430 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2432 (defun org-verify-change-for-undo (l1 l2)
2433 "Verify that a real change occurred between the undo lists L1 and L2."
2434 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2435 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2436 (not (eq l1 l2)))
2438 ;;; Agenda dispatch
2440 (defvar org-agenda-restrict-begin (make-marker))
2441 (defvar org-agenda-restrict-end (make-marker))
2442 (defvar org-agenda-last-dispatch-buffer nil)
2443 (defvar org-agenda-overriding-restriction nil)
2445 (defcustom org-agenda-custom-commands-contexts nil
2446 "Alist of custom agenda keys and contextual rules.
2448 For example, if you have a custom agenda command \"p\" and you
2449 want this command to be accessible only from plain text files,
2450 use this:
2452 '((\"p\" ((in-file . \"\\.txt\"))))
2454 Here are the available contexts definitions:
2456 in-file: command displayed only in matching files
2457 in-mode: command displayed only in matching modes
2458 not-in-file: command not displayed in matching files
2459 not-in-mode: command not displayed in matching modes
2460 in-buffer: command displayed only in matching buffers
2461 not-in-buffer: command not displayed in matching buffers
2462 [function]: a custom function taking no argument
2464 If you define several checks, the agenda command will be
2465 accessible if there is at least one valid check.
2467 You can also bind a key to another agenda custom command
2468 depending on contextual rules.
2470 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2472 Here it means: in .txt files, use \"p\" as the key for the
2473 agenda command otherwise associated with \"q\". (The command
2474 originally associated with \"q\" is not displayed to avoid
2475 duplicates.)"
2476 :version "24.3"
2477 :group 'org-agenda-custom-commands
2478 :type '(repeat (list :tag "Rule"
2479 (string :tag " Agenda key")
2480 (string :tag "Replace by command")
2481 (repeat :tag "Available when"
2482 (choice
2483 (cons :tag "Condition"
2484 (choice
2485 (const :tag "In file" in-file)
2486 (const :tag "Not in file" not-in-file)
2487 (const :tag "In buffer" in-buffer)
2488 (const :tag "Not in buffer" not-in-buffer)
2489 (const :tag "In mode" in-mode)
2490 (const :tag "Not in mode" not-in-mode))
2491 (regexp))
2492 (function :tag "Custom function"))))))
2494 (defcustom org-agenda-max-entries nil
2495 "Maximum number of entries to display in an agenda.
2496 This can be nil (no limit) or an integer or an alist of agenda
2497 types with an associated number of entries to display in this
2498 type."
2499 :version "24.4"
2500 :package-version '(Org . "8.0")
2501 :group 'org-agenda-custom-commands
2502 :type '(choice (symbol :tag "No limit" nil)
2503 (integer :tag "Max number of entries")
2504 (repeat
2505 (cons (choice :tag "Agenda type"
2506 (const agenda)
2507 (const todo)
2508 (const tags)
2509 (const search)
2510 (const timeline))
2511 (integer :tag "Max number of entries")))))
2513 (defcustom org-agenda-max-todos nil
2514 "Maximum number of TODOs to display in an agenda.
2515 This can be nil (no limit) or an integer or an alist of agenda
2516 types with an associated number of entries to display in this
2517 type."
2518 :version "24.4"
2519 :package-version '(Org . "8.0")
2520 :group 'org-agenda-custom-commands
2521 :type '(choice (symbol :tag "No limit" nil)
2522 (integer :tag "Max number of entries")
2523 (repeat
2524 (cons (choice :tag "Agenda type"
2525 (const agenda)
2526 (const todo)
2527 (const tags)
2528 (const search)
2529 (const timeline))
2530 (integer :tag "Max number of entries")))))
2532 (defcustom org-agenda-max-tags nil
2533 "Maximum number of tagged entries to display in an agenda.
2534 This can be nil (no limit) or an integer or an alist of agenda
2535 types with an associated number of entries to display in this
2536 type."
2537 :version "24.4"
2538 :package-version '(Org . "8.0")
2539 :group 'org-agenda-custom-commands
2540 :type '(choice (symbol :tag "No limit" nil)
2541 (integer :tag "Max number of entries")
2542 (repeat
2543 (cons (choice :tag "Agenda type"
2544 (const agenda)
2545 (const todo)
2546 (const tags)
2547 (const search)
2548 (const timeline))
2549 (integer :tag "Max number of entries")))))
2551 (defcustom org-agenda-max-effort nil
2552 "Maximum cumulated effort duration for the agenda.
2553 This can be nil (no limit) or a number of minutes (as an integer)
2554 or an alist of agenda types with an associated number of minutes
2555 to limit entries to in this type."
2556 :version "24.4"
2557 :package-version '(Org . "8.0")
2558 :group 'org-agenda-custom-commands
2559 :type '(choice (symbol :tag "No limit" nil)
2560 (integer :tag "Max number of entries")
2561 (repeat
2562 (cons (choice :tag "Agenda type"
2563 (const agenda)
2564 (const todo)
2565 (const tags)
2566 (const search)
2567 (const timeline))
2568 (integer :tag "Max number of entries")))))
2570 (defvar org-keys nil)
2571 (defvar org-match nil)
2572 ;;;###autoload
2573 (defun org-agenda (&optional arg org-keys restriction)
2574 "Dispatch agenda commands to collect entries to the agenda buffer.
2575 Prompts for a command to execute. Any prefix arg will be passed
2576 on to the selected command. The default selections are:
2578 a Call `org-agenda-list' to display the agenda for current day or week.
2579 t Call `org-todo-list' to display the global todo list.
2580 T Call `org-todo-list' to display the global todo list, select only
2581 entries with a specific TODO keyword (the user gets a prompt).
2582 m Call `org-tags-view' to display headlines with tags matching
2583 a condition (the user is prompted for the condition).
2584 M Like `m', but select only TODO entries, no ordinary headlines.
2585 L Create a timeline for the current buffer.
2586 e Export views to associated files.
2587 s Search entries for keywords.
2588 S Search entries for keywords, only with TODO keywords.
2589 / Multi occur across all agenda files and also files listed
2590 in `org-agenda-text-search-extra-files'.
2591 < Restrict agenda commands to buffer, subtree, or region.
2592 Press several times to get the desired effect.
2593 > Remove a previous restriction.
2594 # List \"stuck\" projects.
2595 ! Configure what \"stuck\" means.
2596 C Configure custom agenda commands.
2598 More commands can be added by configuring the variable
2599 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2600 searches can be pre-defined in this way.
2602 If the current buffer is in Org-mode and visiting a file, you can also
2603 first press `<' once to indicate that the agenda should be temporarily
2604 \(until the next use of \\[org-agenda]) restricted to the current file.
2605 Pressing `<' twice means to restrict to the current subtree or region
2606 \(if active)."
2607 (interactive "P")
2608 (catch 'exit
2609 (let* ((prefix-descriptions nil)
2610 (org-agenda-buffer-name org-agenda-buffer-name)
2611 (org-agenda-window-setup (if (equal (buffer-name)
2612 org-agenda-buffer-name)
2613 'current-window
2614 org-agenda-window-setup))
2615 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2616 (org-agenda-custom-commands
2617 ;; normalize different versions
2618 (delq nil
2619 (mapcar
2620 (lambda (x)
2621 (cond ((stringp (cdr x))
2622 (push x prefix-descriptions)
2623 nil)
2624 ((stringp (nth 1 x)) x)
2625 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2626 (t (cons (car x) (cons "" (cdr x))))))
2627 org-agenda-custom-commands)))
2628 (org-agenda-custom-commands
2629 (org-contextualize-keys
2630 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2631 (buf (current-buffer))
2632 (bfn (buffer-file-name (buffer-base-buffer)))
2633 entry key type org-match lprops ans)
2634 ;; Turn off restriction unless there is an overriding one,
2635 (unless org-agenda-overriding-restriction
2636 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2637 ;; There is a request to keep the file list in place
2638 (put 'org-agenda-files 'org-restrict nil))
2639 (setq org-agenda-restrict nil)
2640 (move-marker org-agenda-restrict-begin nil)
2641 (move-marker org-agenda-restrict-end nil))
2642 ;; Delete old local properties
2643 (put 'org-agenda-redo-command 'org-lprops nil)
2644 ;; Delete previously set last-arguments
2645 (put 'org-agenda-redo-command 'last-args nil)
2646 ;; Remember where this call originated
2647 (setq org-agenda-last-dispatch-buffer (current-buffer))
2648 (unless org-keys
2649 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2650 org-keys (car ans)
2651 restriction (cdr ans)))
2652 ;; If we have sticky agenda buffers, set a name for the buffer,
2653 ;; depending on the invoking keys. The user may still set this
2654 ;; as a command option, which will overwrite what we do here.
2655 (if org-agenda-sticky
2656 (setq org-agenda-buffer-name
2657 (format "*Org Agenda(%s)*" org-keys)))
2658 ;; Establish the restriction, if any
2659 (when (and (not org-agenda-overriding-restriction) restriction)
2660 (put 'org-agenda-files 'org-restrict (list bfn))
2661 (cond
2662 ((eq restriction 'region)
2663 (setq org-agenda-restrict t)
2664 (move-marker org-agenda-restrict-begin (region-beginning))
2665 (move-marker org-agenda-restrict-end (region-end)))
2666 ((eq restriction 'subtree)
2667 (save-excursion
2668 (setq org-agenda-restrict t)
2669 (org-back-to-heading t)
2670 (move-marker org-agenda-restrict-begin (point))
2671 (move-marker org-agenda-restrict-end
2672 (progn (org-end-of-subtree t)))))))
2674 ;; For example the todo list should not need it (but does...)
2675 (cond
2676 ((setq entry (assoc org-keys org-agenda-custom-commands))
2677 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2678 (progn
2679 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2680 lprops (nth 4 entry))
2681 (if org-agenda-sticky
2682 (setq org-agenda-buffer-name
2683 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2684 (format "*Org Agenda(%s)*" org-keys))))
2685 (put 'org-agenda-redo-command 'org-lprops lprops)
2686 (cond
2687 ((eq type 'agenda)
2688 (org-let lprops '(org-agenda-list current-prefix-arg)))
2689 ((eq type 'alltodo)
2690 (org-let lprops '(org-todo-list current-prefix-arg)))
2691 ((eq type 'search)
2692 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2693 ((eq type 'stuck)
2694 (org-let lprops '(org-agenda-list-stuck-projects
2695 current-prefix-arg)))
2696 ((eq type 'tags)
2697 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2698 ((eq type 'tags-todo)
2699 (org-let lprops '(org-tags-view '(4) org-match)))
2700 ((eq type 'todo)
2701 (org-let lprops '(org-todo-list org-match)))
2702 ((eq type 'tags-tree)
2703 (org-check-for-org-mode)
2704 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2705 ((eq type 'todo-tree)
2706 (org-check-for-org-mode)
2707 (org-let lprops
2708 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2709 (regexp-quote org-match) "\\>"))))
2710 ((eq type 'occur-tree)
2711 (org-check-for-org-mode)
2712 (org-let lprops '(org-occur org-match)))
2713 ((functionp type)
2714 (org-let lprops '(funcall type org-match)))
2715 ((fboundp type)
2716 (org-let lprops '(funcall type org-match)))
2717 (t (error "Invalid custom agenda command type %s" type))))
2718 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2719 ((equal org-keys "C")
2720 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2721 (customize-variable 'org-agenda-custom-commands))
2722 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2723 ((equal org-keys "s") (call-interactively 'org-search-view))
2724 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2725 ((equal org-keys "t") (call-interactively 'org-todo-list))
2726 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2727 ((equal org-keys "m") (call-interactively 'org-tags-view))
2728 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2729 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2730 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2731 (org-add-hook
2732 'post-command-hook
2733 (lambda ()
2734 (unless (current-message)
2735 (let* ((m (org-agenda-get-any-marker))
2736 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2737 (when note
2738 (message (concat
2739 "FLAGGING-NOTE ([?] for more info): "
2740 (org-add-props
2741 (replace-regexp-in-string
2742 "\\\\n" "//"
2743 (copy-sequence note))
2744 nil 'face 'org-warning)))))))
2745 t t))
2746 ((equal org-keys "L")
2747 (unless (derived-mode-p 'org-mode)
2748 (error "This is not an Org-mode file"))
2749 (unless restriction
2750 (put 'org-agenda-files 'org-restrict (list bfn))
2751 (org-call-with-arg 'org-timeline arg)))
2752 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2753 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2754 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2755 (t (error "Invalid agenda key"))))))
2757 (defun org-agenda-append-agenda ()
2758 "Append another agenda view to the current one.
2759 This function allows interactive building of block agendas.
2760 Agenda views are separated by `org-agenda-block-separator'."
2761 (interactive)
2762 (unless (derived-mode-p 'org-agenda-mode)
2763 (error "Can only append from within agenda buffer"))
2764 (let ((org-agenda-multi t))
2765 (org-agenda)
2766 (widen)
2767 (org-agenda-finalize)
2768 (org-agenda-fit-window-to-buffer)))
2770 (defun org-agenda-normalize-custom-commands (cmds)
2771 "Normalize custom commands CMDS."
2772 (delq nil
2773 (mapcar
2774 (lambda (x)
2775 (cond ((stringp (cdr x)) nil)
2776 ((stringp (nth 1 x)) x)
2777 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2778 (t (cons (car x) (cons "" (cdr x))))))
2779 cmds)))
2781 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2782 "The user interface for selecting an agenda command."
2783 (catch 'exit
2784 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2785 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2786 (region-p (org-region-active-p))
2787 (custom org-agenda-custom-commands)
2788 (selstring "")
2789 restriction second-time
2790 c entry key type match prefixes rmheader header-end custom1 desc
2791 line lines left right n n1)
2792 (save-window-excursion
2793 (delete-other-windows)
2794 (org-switch-to-buffer-other-window " *Agenda Commands*")
2795 (erase-buffer)
2796 (insert (eval-when-compile
2797 (let ((header
2798 "Press key for an agenda command: < Buffer, subtree/region restriction
2799 -------------------------------- > Remove restriction
2800 a Agenda for current week or day e Export agenda views
2801 t List of all TODO entries T Entries with special TODO kwd
2802 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2803 s Search for keywords S Like s, but only TODO entries
2804 L Timeline for current buffer # List stuck projects (!=configure)
2805 / Multi-occur C Configure custom agenda commands
2806 ? Find :FLAGGED: entries * Toggle sticky agenda views
2808 (start 0))
2809 (while (string-match
2810 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2811 header start)
2812 (setq start (match-end 0))
2813 (add-text-properties (match-beginning 2) (match-end 2)
2814 '(face bold) header))
2815 header)))
2816 (setq header-end (point-marker))
2817 (while t
2818 (setq custom1 custom)
2819 (when (eq rmheader t)
2820 (org-goto-line 1)
2821 (re-search-forward ":" nil t)
2822 (delete-region (match-end 0) (point-at-eol))
2823 (forward-char 1)
2824 (looking-at "-+")
2825 (delete-region (match-end 0) (point-at-eol))
2826 (move-marker header-end (match-end 0)))
2827 (goto-char header-end)
2828 (delete-region (point) (point-max))
2830 ;; Produce all the lines that describe custom commands and prefixes
2831 (setq lines nil)
2832 (while (setq entry (pop custom1))
2833 (setq key (car entry) desc (nth 1 entry)
2834 type (nth 2 entry)
2835 match (nth 3 entry))
2836 (if (> (length key) 1)
2837 (add-to-list 'prefixes (string-to-char key))
2838 (setq line
2839 (format
2840 "%-4s%-14s"
2841 (org-add-props (copy-sequence key)
2842 '(face bold))
2843 (cond
2844 ((string-match "\\S-" desc) desc)
2845 ((eq type 'agenda) "Agenda for current week or day")
2846 ((eq type 'alltodo) "List of all TODO entries")
2847 ((eq type 'search) "Word search")
2848 ((eq type 'stuck) "List of stuck projects")
2849 ((eq type 'todo) "TODO keyword")
2850 ((eq type 'tags) "Tags query")
2851 ((eq type 'tags-todo) "Tags (TODO)")
2852 ((eq type 'tags-tree) "Tags tree")
2853 ((eq type 'todo-tree) "TODO kwd tree")
2854 ((eq type 'occur-tree) "Occur tree")
2855 ((functionp type) (if (symbolp type)
2856 (symbol-name type)
2857 "Lambda expression"))
2858 (t "???"))))
2859 (if org-agenda-menu-show-matcher
2860 (setq line
2861 (concat line ": "
2862 (cond
2863 ((stringp match)
2864 (setq match (copy-sequence match))
2865 (org-add-props match nil 'face 'org-warning))
2866 ((listp type)
2867 (format "set of %d commands" (length type))))))
2868 (if (org-string-nw-p match)
2869 (add-text-properties
2870 0 (length line) (list 'help-echo
2871 (concat "Matcher: " match)) line)))
2872 (push line lines)))
2873 (setq lines (nreverse lines))
2874 (when prefixes
2875 (mapc (lambda (x)
2876 (push
2877 (format "%s %s"
2878 (org-add-props (char-to-string x)
2879 nil 'face 'bold)
2880 (or (cdr (assoc (concat selstring
2881 (char-to-string x))
2882 prefix-descriptions))
2883 "Prefix key"))
2884 lines))
2885 prefixes))
2887 ;; Check if we should display in two columns
2888 (if org-agenda-menu-two-columns
2889 (progn
2890 (setq n (length lines)
2891 n1 (+ (/ n 2) (mod n 2))
2892 right (nthcdr n1 lines)
2893 left (copy-sequence lines))
2894 (setcdr (nthcdr (1- n1) left) nil))
2895 (setq left lines right nil))
2896 (while left
2897 (insert "\n" (pop left))
2898 (when right
2899 (if (< (current-column) 40)
2900 (move-to-column 40 t)
2901 (insert " "))
2902 (insert (pop right))))
2904 ;; Make the window the right size
2905 (goto-char (point-min))
2906 (if second-time
2907 (if (not (pos-visible-in-window-p (point-max)))
2908 (org-fit-window-to-buffer))
2909 (setq second-time t)
2910 (org-fit-window-to-buffer))
2912 ;; Ask for selection
2913 (message "Press key for agenda command%s:"
2914 (if (or restrict-ok org-agenda-overriding-restriction)
2915 (if org-agenda-overriding-restriction
2916 " (restriction lock active)"
2917 (if restriction
2918 (format " (restricted to %s)" restriction)
2919 " (unrestricted)"))
2920 ""))
2921 (setq c (read-char-exclusive))
2922 (message "")
2923 (cond
2924 ((assoc (char-to-string c) custom)
2925 (setq selstring (concat selstring (char-to-string c)))
2926 (throw 'exit (cons selstring restriction)))
2927 ((memq c prefixes)
2928 (setq selstring (concat selstring (char-to-string c))
2929 prefixes nil
2930 rmheader (or rmheader t)
2931 custom (delq nil (mapcar
2932 (lambda (x)
2933 (if (or (= (length (car x)) 1)
2934 (/= (string-to-char (car x)) c))
2936 (cons (substring (car x) 1) (cdr x))))
2937 custom))))
2938 ((eq c ?*)
2939 (call-interactively 'org-toggle-sticky-agenda)
2940 (sit-for 2))
2941 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2942 (message "Restriction is only possible in Org-mode buffers")
2943 (ding) (sit-for 1))
2944 ((eq c ?1)
2945 (org-agenda-remove-restriction-lock 'noupdate)
2946 (setq restriction 'buffer))
2947 ((eq c ?0)
2948 (org-agenda-remove-restriction-lock 'noupdate)
2949 (setq restriction (if region-p 'region 'subtree)))
2950 ((eq c ?<)
2951 (org-agenda-remove-restriction-lock 'noupdate)
2952 (setq restriction
2953 (cond
2954 ((eq restriction 'buffer)
2955 (if region-p 'region 'subtree))
2956 ((memq restriction '(subtree region))
2957 nil)
2958 (t 'buffer))))
2959 ((eq c ?>)
2960 (org-agenda-remove-restriction-lock 'noupdate)
2961 (setq restriction nil))
2962 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2963 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2964 ((and (> (length selstring) 0) (eq c ?\d))
2965 (delete-window)
2966 (org-agenda-get-restriction-and-command prefix-descriptions))
2968 ((equal c ?q) (error "Abort"))
2969 (t (error "Invalid key %c" c))))))))
2971 (defun org-agenda-fit-window-to-buffer ()
2972 "Fit the window to the buffer size."
2973 (and (memq org-agenda-window-setup '(reorganize-frame))
2974 (fboundp 'fit-window-to-buffer)
2975 (org-fit-window-to-buffer
2977 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2978 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2980 (defvar org-cmd nil)
2981 (defvar org-agenda-overriding-cmd nil)
2982 (defvar org-agenda-overriding-arguments nil)
2983 (defvar org-agenda-overriding-cmd-arguments nil)
2984 (defun org-agenda-run-series (name series)
2985 "Run agenda NAME as a SERIES of agenda commands."
2986 (org-let (nth 1 series) '(org-agenda-prepare name))
2987 ;; We need to reset agenda markers here, because when constructing a
2988 ;; block agenda, the individual blocks do not do that.
2989 (org-agenda-reset-markers)
2990 (let* ((org-agenda-multi t)
2991 (redo (list 'org-agenda-run-series name (list 'quote series)))
2992 (cmds (car series))
2993 (gprops (nth 1 series))
2994 match ;; The byte compiler incorrectly complains about this. Keep it!
2995 org-cmd type lprops)
2996 (while (setq org-cmd (pop cmds))
2997 (setq type (car org-cmd)
2998 match (eval (nth 1 org-cmd))
2999 lprops (nth 2 org-cmd))
3000 (let ((org-agenda-overriding-arguments
3001 (if (eq org-agenda-overriding-cmd org-cmd)
3002 (or org-agenda-overriding-arguments
3003 org-agenda-overriding-cmd-arguments))))
3004 (cond
3005 ((eq type 'agenda)
3006 (org-let2 gprops lprops
3007 '(call-interactively 'org-agenda-list)))
3008 ((eq type 'alltodo)
3009 (org-let2 gprops lprops
3010 '(call-interactively 'org-todo-list)))
3011 ((eq type 'search)
3012 (org-let2 gprops lprops
3013 '(org-search-view current-prefix-arg match nil)))
3014 ((eq type 'stuck)
3015 (org-let2 gprops lprops
3016 '(call-interactively 'org-agenda-list-stuck-projects)))
3017 ((eq type 'tags)
3018 (org-let2 gprops lprops
3019 '(org-tags-view current-prefix-arg match)))
3020 ((eq type 'tags-todo)
3021 (org-let2 gprops lprops
3022 '(org-tags-view '(4) match)))
3023 ((eq type 'todo)
3024 (org-let2 gprops lprops
3025 '(org-todo-list match)))
3026 ((fboundp type)
3027 (org-let2 gprops lprops
3028 '(funcall type match)))
3029 (t (error "Invalid type in command series")))))
3030 (widen)
3031 (let ((inhibit-read-only t))
3032 (add-text-properties (point-min) (point-max)
3033 `(org-series t org-series-redo-cmd ,redo)))
3034 (setq org-agenda-redo-command redo)
3035 (goto-char (point-min)))
3036 (org-agenda-fit-window-to-buffer)
3037 (org-let (nth 1 series) '(org-agenda-finalize)))
3039 ;;;###autoload
3040 (defmacro org-batch-agenda (cmd-key &rest parameters)
3041 "Run an agenda command in batch mode and send the result to STDOUT.
3042 If CMD-KEY is a string of length 1, it is used as a key in
3043 `org-agenda-custom-commands' and triggers this command. If it is a
3044 longer string it is used as a tags/todo match string.
3045 Parameters are alternating variable names and values that will be bound
3046 before running the agenda command."
3047 (org-eval-in-environment (org-make-parameter-alist parameters)
3048 (if (> (length cmd-key) 2)
3049 (org-tags-view nil cmd-key)
3050 (org-agenda nil cmd-key)))
3051 (set-buffer org-agenda-buffer-name)
3052 (princ (buffer-string)))
3054 (defvar org-agenda-info nil)
3056 ;;;###autoload
3057 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3058 "Run an agenda command in batch mode and send the result to STDOUT.
3059 If CMD-KEY is a string of length 1, it is used as a key in
3060 `org-agenda-custom-commands' and triggers this command. If it is a
3061 longer string it is used as a tags/todo match string.
3062 Parameters are alternating variable names and values that will be bound
3063 before running the agenda command.
3065 The output gives a line for each selected agenda item. Each
3066 item is a list of comma-separated values, like this:
3068 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3070 category The category of the item
3071 head The headline, without TODO kwd, TAGS and PRIORITY
3072 type The type of the agenda entry, can be
3073 todo selected in TODO match
3074 tagsmatch selected in tags match
3075 diary imported from diary
3076 deadline a deadline on given date
3077 scheduled scheduled on given date
3078 timestamp entry has timestamp on given date
3079 closed entry was closed on given date
3080 upcoming-deadline warning about deadline
3081 past-scheduled forwarded scheduled item
3082 block entry has date block including g. date
3083 todo The todo keyword, if any
3084 tags All tags including inherited ones, separated by colons
3085 date The relevant date, like 2007-2-14
3086 time The time, like 15:00-16:50
3087 extra Sting with extra planning info
3088 priority-l The priority letter if any was given
3089 priority-n The computed numerical priority
3090 agenda-day The day in the agenda where this is listed"
3091 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3092 (org-make-parameter-alist parameters))
3093 (if (> (length cmd-key) 2)
3094 (org-tags-view nil cmd-key)
3095 (org-agenda nil cmd-key)))
3096 (set-buffer org-agenda-buffer-name)
3097 (let* ((lines (org-split-string (buffer-string) "\n"))
3098 line)
3099 (while (setq line (pop lines))
3100 (catch 'next
3101 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3102 (setq org-agenda-info
3103 (org-fix-agenda-info (text-properties-at 0 line)))
3104 (princ
3105 (mapconcat 'org-agenda-export-csv-mapper
3106 '(org-category txt type todo tags date time extra
3107 priority-letter priority agenda-day)
3108 ","))
3109 (princ "\n")))))
3111 (defun org-fix-agenda-info (props)
3112 "Make sure all properties on an agenda item have a canonical form.
3113 This ensures the export commands can easily use it."
3114 (let (tmp re)
3115 (when (setq tmp (plist-get props 'tags))
3116 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3117 (when (setq tmp (plist-get props 'date))
3118 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3119 (let ((calendar-date-display-form '(year "-" month "-" day)))
3120 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3122 (setq tmp (calendar-date-string tmp)))
3123 (setq props (plist-put props 'date tmp)))
3124 (when (setq tmp (plist-get props 'day))
3125 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3126 (let ((calendar-date-display-form '(year "-" month "-" day)))
3127 (setq tmp (calendar-date-string tmp)))
3128 (setq props (plist-put props 'day tmp))
3129 (setq props (plist-put props 'agenda-day tmp)))
3130 (when (setq tmp (plist-get props 'txt))
3131 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3132 (plist-put props 'priority-letter (match-string 1 tmp))
3133 (setq tmp (replace-match "" t t tmp)))
3134 (when (and (setq re (plist-get props 'org-todo-regexp))
3135 (setq re (concat "\\`\\.*" re " ?"))
3136 (string-match re tmp))
3137 (plist-put props 'todo (match-string 1 tmp))
3138 (setq tmp (replace-match "" t t tmp)))
3139 (plist-put props 'txt tmp)))
3140 props)
3142 (defun org-agenda-export-csv-mapper (prop)
3143 (let ((res (plist-get org-agenda-info prop)))
3144 (setq res
3145 (cond
3146 ((not res) "")
3147 ((stringp res) res)
3148 (t (prin1-to-string res))))
3149 (while (string-match "," res)
3150 (setq res (replace-match ";" t t res)))
3151 (org-trim res)))
3153 ;;;###autoload
3154 (defun org-store-agenda-views (&rest parameters)
3155 "Store agenda views."
3156 (interactive)
3157 (eval (list 'org-batch-store-agenda-views)))
3159 ;;;###autoload
3160 (defmacro org-batch-store-agenda-views (&rest parameters)
3161 "Run all custom agenda commands that have a file argument."
3162 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3163 (pop-up-frames nil)
3164 (dir default-directory)
3165 (pars (org-make-parameter-alist parameters))
3166 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3167 (save-window-excursion
3168 (while cmds
3169 (setq cmd (pop cmds)
3170 thiscmdkey (car cmd)
3171 thiscmdcmd (cdr cmd)
3172 match (nth 2 thiscmdcmd)
3173 bufname (if org-agenda-sticky
3174 (or (and (stringp match)
3175 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3176 (format "*Org Agenda(%s)*" thiscmdkey))
3177 org-agenda-buffer-name)
3178 cmd-or-set (nth 2 cmd)
3179 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3180 files (nth (if (listp cmd-or-set) 4 5) cmd))
3181 (if (stringp files) (setq files (list files)))
3182 (when files
3183 (org-eval-in-environment (append org-agenda-exporter-settings
3184 opts pars)
3185 (org-agenda nil thiscmdkey))
3186 (set-buffer bufname)
3187 (while files
3188 (org-eval-in-environment (append org-agenda-exporter-settings
3189 opts pars)
3190 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3191 (and (get-buffer bufname)
3192 (kill-buffer bufname)))))))
3194 (defvar org-agenda-current-span nil
3195 "The current span used in the agenda view.") ; local variable in the agenda buffer
3196 (defun org-agenda-mark-header-line (pos)
3197 "Mark the line at POS as an agenda structure header."
3198 (save-excursion
3199 (goto-char pos)
3200 (put-text-property (point-at-bol) (point-at-eol)
3201 'org-agenda-structural-header t)
3202 (when org-agenda-title-append
3203 (put-text-property (point-at-bol) (point-at-eol)
3204 'org-agenda-title-append org-agenda-title-append))))
3206 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3207 (defvar org-agenda-write-buffer-name "Agenda View")
3208 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3209 "Write the current buffer (an agenda view) as a file.
3210 Depending on the extension of the file name, plain text (.txt),
3211 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3212 If the extension is .ics, run icalendar export over all files used
3213 to construct the agenda and limit the export to entries listed in the
3214 agenda now.
3215 If the extension is .org, collect all subtrees corresponding to the
3216 agenda entries and add them in an .org file.
3217 With prefix argument OPEN, open the new file immediately.
3218 If NOSETTINGS is given, do not scope the settings of
3219 `org-agenda-exporter-settings' into the export commands. This is used when
3220 the settings have already been scoped and we do not wish to overrule other,
3221 higher priority settings.
3222 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3223 (interactive "FWrite agenda to file: \nP")
3224 (if (or (not (file-writable-p file))
3225 (and (file-exists-p file)
3226 (if (called-interactively-p 'any)
3227 (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
3228 (error "Cannot write agenda to file %s" file))
3229 (org-let (if nosettings nil org-agenda-exporter-settings)
3230 '(save-excursion
3231 (save-window-excursion
3232 (org-agenda-mark-filtered-text)
3233 (let ((bs (copy-sequence (buffer-string))) beg content)
3234 (org-agenda-unmark-filtered-text)
3235 (with-temp-buffer
3236 (rename-buffer org-agenda-write-buffer-name t)
3237 (set-buffer-modified-p nil)
3238 (insert bs)
3239 (org-agenda-remove-marked-text 'org-filtered)
3240 (while (setq beg (text-property-any (point-min) (point-max)
3241 'org-filtered t))
3242 (delete-region
3243 beg (or (next-single-property-change beg 'org-filtered)
3244 (point-max))))
3245 (run-hooks 'org-agenda-before-write-hook)
3246 (cond
3247 ((org-bound-and-true-p org-mobile-creating-agendas)
3248 (org-mobile-write-agenda-for-mobile file))
3249 ((string-match "\\.org\\'" file)
3250 (let (content p m message-log-max)
3251 (goto-char (point-min))
3252 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3253 (goto-char p)
3254 (setq m (get-text-property (point) 'org-hd-marker))
3255 (when m
3256 (push (save-excursion
3257 (set-buffer (marker-buffer m))
3258 (goto-char m)
3259 (org-copy-subtree 1 nil t t)
3260 org-subtree-clip)
3261 content)))
3262 (find-file file)
3263 (erase-buffer)
3264 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3265 (write-file file)
3266 (kill-buffer (current-buffer))
3267 (message "Org file written to %s" file)))
3268 ((string-match "\\.html?\\'" file)
3269 (require 'htmlize)
3270 (set-buffer (htmlize-buffer (current-buffer)))
3271 (when org-agenda-export-html-style
3272 ;; replace <style> section with org-agenda-export-html-style
3273 (goto-char (point-min))
3274 (kill-region (- (search-forward "<style") 6)
3275 (search-forward "</style>"))
3276 (insert org-agenda-export-html-style))
3277 (write-file file)
3278 (kill-buffer (current-buffer))
3279 (message "HTML written to %s" file))
3280 ((string-match "\\.ps\\'" file)
3281 (require 'ps-print)
3282 (ps-print-buffer-with-faces file)
3283 (message "Postscript written to %s" file))
3284 ((string-match "\\.pdf\\'" file)
3285 (require 'ps-print)
3286 (ps-print-buffer-with-faces
3287 (concat (file-name-sans-extension file) ".ps"))
3288 (call-process "ps2pdf" nil nil nil
3289 (expand-file-name
3290 (concat (file-name-sans-extension file) ".ps"))
3291 (expand-file-name file))
3292 (delete-file (concat (file-name-sans-extension file) ".ps"))
3293 (message "PDF written to %s" file))
3294 ((string-match "\\.ics\\'" file)
3295 (require 'ox-icalendar)
3296 (org-icalendar-export-current-agenda (expand-file-name file)))
3298 (let ((bs (buffer-string)))
3299 (find-file file)
3300 (erase-buffer)
3301 (insert bs)
3302 (save-buffer 0)
3303 (kill-buffer (current-buffer))
3304 (message "Plain text written to %s" file))))))))
3305 (set-buffer (or agenda-bufname
3306 (and (org-called-interactively-p 'any) (buffer-name))
3307 org-agenda-buffer-name)))
3308 (when open (org-open-file file)))
3310 (defvar org-agenda-tag-filter-overlays nil)
3311 (defvar org-agenda-cat-filter-overlays nil)
3313 (defun org-agenda-mark-filtered-text ()
3314 "Mark all text hidden by filtering with a text property."
3315 (let ((inhibit-read-only t))
3316 (mapc
3317 (lambda (o)
3318 (when (equal (overlay-buffer o) (current-buffer))
3319 (put-text-property
3320 (overlay-start o) (overlay-end o)
3321 'org-filtered t)))
3322 (append org-agenda-tag-filter-overlays
3323 org-agenda-cat-filter-overlays))))
3325 (defun org-agenda-unmark-filtered-text ()
3326 "Remove the filtering text property."
3327 (let ((inhibit-read-only t))
3328 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3330 (defun org-agenda-remove-marked-text (property &optional value)
3331 "Delete all text marked with VALUE of PROPERTY.
3332 VALUE defaults to t."
3333 (let (beg)
3334 (setq value (or value t))
3335 (while (setq beg (text-property-any (point-min) (point-max)
3336 property value))
3337 (delete-region
3338 beg (or (next-single-property-change beg 'org-filtered)
3339 (point-max))))))
3341 (defun org-agenda-add-entry-text ()
3342 "Add entry text to agenda lines.
3343 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3344 entry text following headings shown in the agenda.
3345 Drawers will be excluded, also the line with scheduling/deadline info."
3346 (when (and (> org-agenda-add-entry-text-maxlines 0)
3347 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3348 (let (m txt)
3349 (goto-char (point-min))
3350 (while (not (eobp))
3351 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3352 (beginning-of-line 2)
3353 (setq txt (org-agenda-get-some-entry-text
3354 m org-agenda-add-entry-text-maxlines " > "))
3355 (end-of-line 1)
3356 (if (string-match "\\S-" txt)
3357 (insert "\n" txt)
3358 (or (eobp) (forward-char 1))))))))
3360 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3361 &rest keep)
3362 "Extract entry text from MARKER, at most N-LINES lines.
3363 This will ignore drawers etc, just get the text.
3364 If INDENT is given, prefix every line with this string. If KEEP is
3365 given, it is a list of symbols, defining stuff that should not be
3366 removed from the entry content. Currently only `planning' is allowed here."
3367 (let (txt drawer-re kwd-time-re ind)
3368 (save-excursion
3369 (with-current-buffer (marker-buffer marker)
3370 (if (not (derived-mode-p 'org-mode))
3371 (setq txt "")
3372 (save-excursion
3373 (save-restriction
3374 (widen)
3375 (goto-char marker)
3376 (end-of-line 1)
3377 (setq txt (buffer-substring
3378 (min (1+ (point)) (point-max))
3379 (progn (outline-next-heading) (point)))
3380 drawer-re org-drawer-regexp
3381 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3382 ".*\n?"))
3383 (with-temp-buffer
3384 (insert txt)
3385 (when org-agenda-add-entry-text-descriptive-links
3386 (goto-char (point-min))
3387 (while (org-activate-bracket-links (point-max))
3388 (add-text-properties (match-beginning 0) (match-end 0)
3389 '(face org-link))))
3390 (goto-char (point-min))
3391 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3392 (set-text-properties (match-beginning 0) (match-end 0)
3393 nil))
3394 (goto-char (point-min))
3395 (while (re-search-forward drawer-re nil t)
3396 (delete-region
3397 (match-beginning 0)
3398 (progn (re-search-forward
3399 "^[ \t]*:END:.*\n?" nil 'move)
3400 (point))))
3401 (unless (member 'planning keep)
3402 (goto-char (point-min))
3403 (while (re-search-forward kwd-time-re nil t)
3404 (replace-match "")))
3405 (goto-char (point-min))
3406 (when org-agenda-entry-text-exclude-regexps
3407 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3408 (while (setq re (pop re-list))
3409 (goto-char (point-min))
3410 (while (re-search-forward re nil t)
3411 (replace-match "")))))
3412 (goto-char (point-max))
3413 (skip-chars-backward " \t\n")
3414 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3416 ;; find and remove min common indentation
3417 (goto-char (point-min))
3418 (untabify (point-min) (point-max))
3419 (setq ind (org-get-indentation))
3420 (while (not (eobp))
3421 (unless (looking-at "[ \t]*$")
3422 (setq ind (min ind (org-get-indentation))))
3423 (beginning-of-line 2))
3424 (goto-char (point-min))
3425 (while (not (eobp))
3426 (unless (looking-at "[ \t]*$")
3427 (move-to-column ind)
3428 (delete-region (point-at-bol) (point)))
3429 (beginning-of-line 2))
3431 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3433 (goto-char (point-min))
3434 (when indent
3435 (while (and (not (eobp)) (re-search-forward "^" nil t))
3436 (replace-match indent t t)))
3437 (goto-char (point-min))
3438 (while (looking-at "[ \t]*\n") (replace-match ""))
3439 (goto-char (point-max))
3440 (when (> (org-current-line)
3441 n-lines)
3442 (org-goto-line (1+ n-lines))
3443 (backward-char 1))
3444 (setq txt (buffer-substring (point-min) (point)))))))))
3445 txt))
3447 (defun org-check-for-org-mode ()
3448 "Make sure current buffer is in org-mode. Error if not."
3449 (or (derived-mode-p 'org-mode)
3450 (error "Cannot execute org-mode agenda command on buffer in %s"
3451 major-mode)))
3453 ;;; Agenda prepare and finalize
3455 (defvar org-agenda-multi nil) ; dynamically scoped
3456 (defvar org-agenda-pre-window-conf nil)
3457 (defvar org-agenda-columns-active nil)
3458 (defvar org-agenda-name nil)
3459 (defvar org-agenda-tag-filter nil)
3460 (defvar org-agenda-category-filter nil)
3461 (defvar org-agenda-top-category-filter nil)
3462 (defvar org-agenda-tag-filter-while-redo nil)
3463 (defvar org-agenda-tag-filter-preset nil
3464 "A preset of the tags filter used for secondary agenda filtering.
3465 This must be a list of strings, each string must be a single tag preceded
3466 by \"+\" or \"-\".
3467 This variable should not be set directly, but agenda custom commands can
3468 bind it in the options section. The preset filter is a global property of
3469 the entire agenda view. In a block agenda, it will not work reliably to
3470 define a filter for one of the individual blocks. You need to set it in
3471 the global options and expect it to be applied to the entire view.")
3473 (defvar org-agenda-category-filter-preset nil
3474 "A preset of the category filter used for secondary agenda filtering.
3475 This must be a list of strings, each string must be a single category
3476 preceded by \"+\" or \"-\".
3477 This variable should not be set directly, but agenda custom commands can
3478 bind it in the options section. The preset filter is a global property of
3479 the entire agenda view. In a block agenda, it will not work reliably to
3480 define a filter for one of the individual blocks. You need to set it in
3481 the global options and expect it to be applied to the entire view.")
3484 (defun org-agenda-use-sticky-p ()
3485 "Return non-nil if an agenda buffer named
3486 `org-agenda-buffer-name' exists and should be shown instead of
3487 generating a new one."
3488 (and
3489 ;; turned off by user
3490 org-agenda-sticky
3491 ;; For multi-agenda buffer already exists
3492 (not org-agenda-multi)
3493 ;; buffer found
3494 (get-buffer org-agenda-buffer-name)
3495 ;; C-u parameter is same as last call
3496 (with-current-buffer (get-buffer org-agenda-buffer-name)
3497 (and
3498 (equal current-prefix-arg
3499 org-agenda-last-prefix-arg)
3500 ;; In case user turned stickiness on, while having existing
3501 ;; Agenda buffer active, don't reuse that buffer, because it
3502 ;; does not have org variables local
3503 org-agenda-this-buffer-is-sticky))))
3505 (defun org-agenda-prepare-window (abuf)
3506 "Setup agenda buffer in the window."
3507 (let* ((awin (get-buffer-window abuf))
3508 wconf)
3509 (cond
3510 ((equal (current-buffer) abuf) nil)
3511 (awin (select-window awin))
3512 ((not (setq wconf (current-window-configuration))))
3513 ((equal org-agenda-window-setup 'current-window)
3514 (org-pop-to-buffer-same-window abuf))
3515 ((equal org-agenda-window-setup 'other-window)
3516 (org-switch-to-buffer-other-window abuf))
3517 ((equal org-agenda-window-setup 'other-frame)
3518 (switch-to-buffer-other-frame abuf))
3519 ((equal org-agenda-window-setup 'reorganize-frame)
3520 (delete-other-windows)
3521 (org-switch-to-buffer-other-window abuf)))
3522 ;; additional test in case agenda is invoked from within agenda
3523 ;; buffer via elisp link
3524 (unless (equal (current-buffer) abuf)
3525 (org-pop-to-buffer-same-window abuf))
3526 (setq org-agenda-pre-window-conf
3527 (or org-agenda-pre-window-conf wconf))))
3529 (defun org-agenda-prepare (&optional name)
3530 (if (org-agenda-use-sticky-p)
3531 (progn
3532 ;; Popup existing buffer
3533 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3534 (message "Sticky Agenda buffer, use `r' to refresh")
3535 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3536 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3537 (setq org-todo-keywords-for-agenda nil)
3538 (setq org-drawers-for-agenda nil)
3539 (unless org-agenda-persistent-filter
3540 (setq org-agenda-tag-filter nil
3541 org-agenda-category-filter nil))
3542 (put 'org-agenda-tag-filter :preset-filter
3543 org-agenda-tag-filter-preset)
3544 (put 'org-agenda-category-filter :preset-filter
3545 org-agenda-category-filter-preset)
3546 (if org-agenda-multi
3547 (progn
3548 (setq buffer-read-only nil)
3549 (goto-char (point-max))
3550 (unless (or (bobp) org-agenda-compact-blocks
3551 (not org-agenda-block-separator))
3552 (insert "\n"
3553 (if (stringp org-agenda-block-separator)
3554 org-agenda-block-separator
3555 (make-string (window-width) org-agenda-block-separator))
3556 "\n"))
3557 (narrow-to-region (point) (point-max)))
3558 (setq org-done-keywords-for-agenda nil)
3560 ;; Setting any org variables that are in org-agenda-local-vars
3561 ;; list need to be done after the prepare call
3562 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3563 (setq buffer-read-only nil)
3564 (org-agenda-reset-markers)
3565 (let ((inhibit-read-only t)) (erase-buffer))
3566 (org-agenda-mode)
3567 (setq org-agenda-buffer (current-buffer))
3568 (setq org-agenda-contributing-files nil)
3569 (setq org-agenda-columns-active nil)
3570 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3571 (setq org-todo-keywords-for-agenda
3572 (org-uniquify org-todo-keywords-for-agenda))
3573 (setq org-done-keywords-for-agenda
3574 (org-uniquify org-done-keywords-for-agenda))
3575 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3576 (setq org-agenda-last-prefix-arg current-prefix-arg)
3577 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3578 (and name (not org-agenda-name)
3579 (org-set-local 'org-agenda-name name)))
3580 (setq buffer-read-only nil)))
3582 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3583 (defun org-agenda-finalize ()
3584 "Finishing touch for the agenda buffer, called just before displaying it."
3585 (unless org-agenda-multi
3586 (save-excursion
3587 (let ((inhibit-read-only t))
3588 (goto-char (point-min))
3589 (save-excursion
3590 (while (org-activate-bracket-links (point-max))
3591 (add-text-properties (match-beginning 0) (match-end 0)
3592 '(face org-link))))
3593 (save-excursion
3594 (while (org-activate-plain-links (point-max))
3595 (add-text-properties (match-beginning 0) (match-end 0)
3596 '(face org-link))))
3597 (unless (eq org-agenda-remove-tags t)
3598 (org-agenda-align-tags))
3599 (unless org-agenda-with-colors
3600 (remove-text-properties (point-min) (point-max) '(face nil)))
3601 (if (and (boundp 'org-agenda-overriding-columns-format)
3602 org-agenda-overriding-columns-format)
3603 (org-set-local 'org-agenda-overriding-columns-format
3604 org-agenda-overriding-columns-format))
3605 (if (and (boundp 'org-agenda-view-columns-initially)
3606 org-agenda-view-columns-initially)
3607 (org-agenda-columns))
3608 (when org-agenda-fontify-priorities
3609 (org-agenda-fontify-priorities))
3610 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3611 (org-agenda-dim-blocked-tasks))
3612 ;; We need to widen when `org-agenda-finalize' is called from
3613 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3614 (when org-clock-current-task
3615 (save-restriction
3616 (widen)
3617 (org-agenda-mark-clocking-task)))
3618 (when org-agenda-entry-text-mode
3619 (org-agenda-entry-text-hide)
3620 (org-agenda-entry-text-show))
3621 (if (and (functionp 'org-habit-insert-consistency-graphs)
3622 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3623 (org-habit-insert-consistency-graphs))
3624 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3625 (unless (or (eq org-agenda-show-inherited-tags 'always)
3626 (and (listp org-agenda-show-inherited-tags)
3627 (memq org-agenda-type org-agenda-show-inherited-tags))
3628 (and (eq org-agenda-show-inherited-tags t)
3629 (or (eq org-agenda-use-tag-inheritance t)
3630 (and (listp org-agenda-use-tag-inheritance)
3631 (not (memq org-agenda-type
3632 org-agenda-use-tag-inheritance))))))
3633 (let (mrk)
3634 (save-excursion
3635 (goto-char (point-min))
3636 (while (equal (forward-line) 0)
3637 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3638 (get-text-property (point) 'org-hd-marker)))
3639 (put-text-property (point-at-bol) (point-at-eol)
3640 'tags (org-with-point-at mrk
3641 (delete-dups
3642 (mapcar 'downcase (org-get-tags-at))))))))))
3643 (run-hooks 'org-agenda-finalize-hook)
3644 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3645 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3646 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3647 (org-agenda-filter-apply org-agenda-category-filter 'category))
3648 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3650 (defun org-agenda-mark-clocking-task ()
3651 "Mark the current clock entry in the agenda if it is present."
3652 (org-agenda-unmark-clocking-task)
3653 (when (marker-buffer org-clock-hd-marker)
3654 (save-excursion
3655 (goto-char (point-min))
3656 (let (s ov)
3657 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3658 (goto-char s)
3659 (when (equal (org-get-at-bol 'org-hd-marker)
3660 org-clock-hd-marker)
3661 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3662 (overlay-put ov 'type 'org-agenda-clocking)
3663 (overlay-put ov 'face 'org-agenda-clocking)
3664 (overlay-put ov 'help-echo
3665 "The clock is running in this item")))))))
3667 (defun org-agenda-unmark-clocking-task ()
3668 "Unmark the current clocking task."
3669 (mapc (lambda (o)
3670 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3671 (delete-overlay o)))
3672 (overlays-in (point-min) (point-max))))
3674 (defun org-agenda-fontify-priorities ()
3675 "Make highest priority lines bold, and lowest italic."
3676 (interactive)
3677 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3678 (delete-overlay o)))
3679 (overlays-in (point-min) (point-max)))
3680 (save-excursion
3681 (let (b e p ov h l)
3682 (goto-char (point-min))
3683 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3684 (setq h (or (get-char-property (point) 'org-highest-priority)
3685 org-highest-priority)
3686 l (or (get-char-property (point) 'org-lowest-priority)
3687 org-lowest-priority)
3688 p (string-to-char (match-string 1))
3689 b (match-beginning 0)
3690 e (if (eq org-agenda-fontify-priorities 'cookies)
3691 (match-end 0)
3692 (point-at-eol))
3693 ov (make-overlay b e))
3694 (overlay-put
3695 ov 'face
3696 (cons (cond ((org-face-from-face-or-color
3697 'priority nil
3698 (cdr (assoc p org-priority-faces))))
3699 ((and (listp org-agenda-fontify-priorities)
3700 (org-face-from-face-or-color
3701 'priority nil
3702 (cdr (assoc p org-agenda-fontify-priorities)))))
3703 ((equal p l) 'italic)
3704 ((equal p h) 'bold))
3705 'org-priority))
3706 (overlay-put ov 'org-type 'org-priority)))))
3708 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3709 (interactive "P")
3710 "Dim currently blocked TODO's in the agenda display."
3711 (message "Dim or hide blocked tasks...")
3712 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3713 (delete-overlay o)))
3714 (overlays-in (point-min) (point-max)))
3715 (save-excursion
3716 (let ((inhibit-read-only t)
3717 (org-depend-tag-blocked nil)
3718 (invis (or (not (null invisible))
3719 (eq org-agenda-dim-blocked-tasks 'invisible)))
3720 org-blocked-by-checkboxes
3721 invis1 b e p ov h l)
3722 (goto-char (point-min))
3723 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3724 (and pos (goto-char (1+ pos))))
3725 (setq org-blocked-by-checkboxes nil invis1 invis)
3726 (let ((marker (org-get-at-bol 'org-hd-marker)))
3727 (when (and marker
3728 (with-current-buffer (marker-buffer marker)
3729 (save-excursion (goto-char marker)
3730 (org-entry-blocked-p))))
3731 (if org-blocked-by-checkboxes (setq invis1 nil))
3732 (setq b (if invis1
3733 (max (point-min) (1- (point-at-bol)))
3734 (point-at-bol))
3735 e (point-at-eol)
3736 ov (make-overlay b e))
3737 (if invis1
3738 (overlay-put ov 'invisible t)
3739 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3740 (overlay-put ov 'org-type 'org-blocked-todo))))))
3741 (message "Dim or hide blocked tasks...done"))
3743 (defvar org-agenda-skip-function nil
3744 "Function to be called at each match during agenda construction.
3745 If this function returns nil, the current match should not be skipped.
3746 Otherwise, the function must return a position from where the search
3747 should be continued.
3748 This may also be a Lisp form, it will be evaluated.
3749 Never set this variable using `setq' or so, because then it will apply
3750 to all future agenda commands. If you do want a global skipping condition,
3751 use the option `org-agenda-skip-function-global' instead.
3752 The correct usage for `org-agenda-skip-function' is to bind it with
3753 `let' to scope it dynamically into the agenda-constructing command.
3754 A good way to set it is through options in `org-agenda-custom-commands'.")
3756 (defun org-agenda-skip ()
3757 "Throw to `:skip' in places that should be skipped.
3758 Also moves point to the end of the skipped region, so that search can
3759 continue from there."
3760 (let ((p (point-at-bol)) to)
3761 (when (or
3762 (save-excursion (goto-char p) (looking-at comment-start-skip))
3763 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3764 (get-text-property p :org-archived)
3765 (org-end-of-subtree t))
3766 (and org-agenda-skip-comment-trees
3767 (get-text-property p :org-comment)
3768 (org-end-of-subtree t))
3769 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3770 (org-agenda-skip-eval org-agenda-skip-function)))
3771 (goto-char to))
3772 (org-in-src-block-p t))
3773 (throw :skip t))))
3775 (defun org-agenda-skip-eval (form)
3776 "If FORM is a function or a list, call (or eval) is and return result.
3777 `save-excursion' and `save-match-data' are wrapped around the call, so point
3778 and match data are returned to the previous state no matter what these
3779 functions do."
3780 (let (fp)
3781 (and form
3782 (or (setq fp (functionp form))
3783 (consp form))
3784 (save-excursion
3785 (save-match-data
3786 (if fp
3787 (funcall form)
3788 (eval form)))))))
3790 (defvar org-agenda-markers nil
3791 "List of all currently active markers created by `org-agenda'.")
3792 (defvar org-agenda-last-marker-time (org-float-time)
3793 "Creation time of the last agenda marker.")
3795 (defun org-agenda-new-marker (&optional pos)
3796 "Return a new agenda marker.
3797 Org-mode keeps a list of these markers and resets them when they are
3798 no longer in use."
3799 (let ((m (copy-marker (or pos (point)))))
3800 (setq org-agenda-last-marker-time (org-float-time))
3801 (if org-agenda-buffer
3802 (with-current-buffer org-agenda-buffer
3803 (push m org-agenda-markers))
3804 (push m org-agenda-markers))
3807 (defun org-agenda-reset-markers ()
3808 "Reset markers created by `org-agenda'."
3809 (while org-agenda-markers
3810 (move-marker (pop org-agenda-markers) nil)))
3812 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3813 "Save relative positions of markers in region.
3814 This check for agenda markers in all agenda buffers currently active."
3815 (dolist (buf (buffer-list))
3816 (with-current-buffer buf
3817 (when (eq major-mode 'org-agenda-mode)
3818 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3819 org-agenda-markers)))))
3821 ;;; Entry text mode
3823 (defun org-agenda-entry-text-show-here ()
3824 "Add some text from the entry as context to the current line."
3825 (let (m txt o)
3826 (setq m (org-get-at-bol 'org-hd-marker))
3827 (unless (marker-buffer m)
3828 (error "No marker points to an entry here"))
3829 (setq txt (concat "\n" (org-no-properties
3830 (org-agenda-get-some-entry-text
3831 m org-agenda-entry-text-maxlines
3832 org-agenda-entry-text-leaders))))
3833 (when (string-match "\\S-" txt)
3834 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3835 (overlay-put o 'evaporate t)
3836 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3837 (overlay-put o 'after-string txt))))
3839 (defun org-agenda-entry-text-show ()
3840 "Add entry context for all agenda lines."
3841 (interactive)
3842 (save-excursion
3843 (goto-char (point-max))
3844 (beginning-of-line 1)
3845 (while (not (bobp))
3846 (when (org-get-at-bol 'org-hd-marker)
3847 (org-agenda-entry-text-show-here))
3848 (beginning-of-line 0))))
3850 (defun org-agenda-entry-text-hide ()
3851 "Remove any shown entry context."
3852 (delq nil
3853 (mapcar (lambda (o)
3854 (if (eq (overlay-get o 'org-overlay-type)
3855 'agenda-entry-content)
3856 (progn (delete-overlay o) t)))
3857 (overlays-in (point-min) (point-max)))))
3859 (defun org-agenda-get-day-face (date)
3860 "Return the face DATE should be displayed with."
3861 (or (and (functionp org-agenda-day-face-function)
3862 (funcall org-agenda-day-face-function date))
3863 (cond ((org-agenda-todayp date)
3864 'org-agenda-date-today)
3865 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3866 'org-agenda-date-weekend)
3867 (t 'org-agenda-date))))
3869 ;;; Agenda timeline
3871 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3873 (defun org-timeline (&optional dotodo)
3874 "Show a time-sorted view of the entries in the current org file.
3875 Only entries with a time stamp of today or later will be listed. With
3876 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3877 under the current date.
3878 If the buffer contains an active region, only check the region for
3879 dates."
3880 (interactive "P")
3881 (let* ((dopast t)
3882 (org-agenda-show-log-scoped org-agenda-show-log)
3883 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3884 (current-buffer))))
3885 (date (calendar-current-date))
3886 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3887 (end (if (org-region-active-p) (region-end) (point-max)))
3888 (day-numbers (org-get-all-dates
3889 beg end 'no-ranges
3890 t org-agenda-show-log-scoped ; always include today
3891 org-timeline-show-empty-dates))
3892 (org-deadline-warning-days 0)
3893 (org-agenda-only-exact-dates t)
3894 (today (org-today))
3895 (past t)
3896 args
3897 s e rtn d emptyp)
3898 (setq org-agenda-redo-command
3899 (list 'progn
3900 (list 'org-switch-to-buffer-other-window (current-buffer))
3901 (list 'org-timeline (list 'quote dotodo))))
3902 (if (not dopast)
3903 ;; Remove past dates from the list of dates.
3904 (setq day-numbers (delq nil (mapcar (lambda(x)
3905 (if (>= x today) x nil))
3906 day-numbers))))
3907 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3908 (org-compile-prefix-format 'timeline)
3909 (org-set-sorting-strategy 'timeline)
3910 (if org-agenda-show-log-scoped (push :closed args))
3911 (push :timestamp args)
3912 (push :deadline args)
3913 (push :scheduled args)
3914 (push :sexp args)
3915 (if dotodo (push :todo args))
3916 (insert "Timeline of file " entry "\n")
3917 (add-text-properties (point-min) (point)
3918 (list 'face 'org-agenda-structure))
3919 (org-agenda-mark-header-line (point-min))
3920 (while (setq d (pop day-numbers))
3921 (if (and (listp d) (eq (car d) :omitted))
3922 (progn
3923 (setq s (point))
3924 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3925 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3926 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3927 (if (and (>= d today)
3928 dopast
3929 past)
3930 (progn
3931 (setq past nil)
3932 (insert (make-string 79 ?-) "\n")))
3933 (setq date (calendar-gregorian-from-absolute d))
3934 (setq s (point))
3935 (setq rtn (and (not emptyp)
3936 (apply 'org-agenda-get-day-entries entry
3937 date args)))
3938 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3939 (progn
3940 (insert
3941 (if (stringp org-agenda-format-date)
3942 (format-time-string org-agenda-format-date
3943 (org-time-from-absolute date))
3944 (funcall org-agenda-format-date date))
3945 "\n")
3946 (put-text-property s (1- (point)) 'face
3947 (org-agenda-get-day-face date))
3948 (put-text-property s (1- (point)) 'org-date-line t)
3949 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3950 (if (equal d today)
3951 (put-text-property s (1- (point)) 'org-today t))
3952 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
3953 (put-text-property s (1- (point)) 'day d)))))
3954 (goto-char (point-min))
3955 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3956 (point-min)))
3957 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3958 (org-agenda-finalize)
3959 (setq buffer-read-only t)))
3961 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3962 "Return a list of all relevant day numbers from BEG to END buffer positions.
3963 If NO-RANGES is non-nil, include only the start and end dates of a range,
3964 not every single day in the range. If FORCE-TODAY is non-nil, make
3965 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3966 inactive time stamps (those in square brackets) are included.
3967 When EMPTY is non-nil, also include days without any entries."
3968 (let ((re (concat
3969 (if pre-re pre-re "")
3970 (if inactive org-ts-regexp-both org-ts-regexp)))
3971 dates dates1 date day day1 day2 ts1 ts2 pos)
3972 (if force-today
3973 (setq dates (list (org-today))))
3974 (save-excursion
3975 (goto-char beg)
3976 (while (re-search-forward re end t)
3977 (setq day (time-to-days (org-time-string-to-time
3978 (substring (match-string 1) 0 10)
3979 (current-buffer) (match-beginning 0))))
3980 (or (memq day dates) (push day dates)))
3981 (unless no-ranges
3982 (goto-char beg)
3983 (while (re-search-forward org-tr-regexp end t)
3984 (setq pos (match-beginning 0))
3985 (setq ts1 (substring (match-string 1) 0 10)
3986 ts2 (substring (match-string 2) 0 10)
3987 day1 (time-to-days (org-time-string-to-time
3988 ts1 (current-buffer) pos))
3989 day2 (time-to-days (org-time-string-to-time
3990 ts2 (current-buffer) pos)))
3991 (while (< (setq day1 (1+ day1)) day2)
3992 (or (memq day1 dates) (push day1 dates)))))
3993 (setq dates (sort dates '<))
3994 (when empty
3995 (while (setq day (pop dates))
3996 (setq day2 (car dates))
3997 (push day dates1)
3998 (when (and day2 empty)
3999 (if (or (eq empty t)
4000 (and (numberp empty) (<= (- day2 day) empty)))
4001 (while (< (setq day (1+ day)) day2)
4002 (push (list day) dates1))
4003 (push (cons :omitted (- day2 day)) dates1))))
4004 (setq dates (nreverse dates1)))
4005 dates)))
4007 ;;; Agenda Daily/Weekly
4009 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4010 "Start day for the agenda view.
4011 Custom commands can set this variable in the options section.
4012 See the docstring of `org-read-date' on allowed values.")
4013 (defvar org-starting-day nil) ; local variable in the agenda buffer
4014 (defvar org-arg-loc nil) ; local variable
4016 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4017 "List of types searched for when creating the daily/weekly agenda.
4018 This variable is a list of symbols that controls the types of
4019 items that appear in the daily/weekly agenda. Allowed symbols in this
4020 list are are
4022 :timestamp List items containing a date stamp or date range matching
4023 the selected date. This includes sexp entries in
4024 angular brackets.
4026 :sexp List entries resulting from plain diary-like sexps.
4028 :deadline List deadline due on that date. When the date is today,
4029 also list any deadlines past due, or due within
4030 `org-deadline-warning-days'. `:deadline' must appear before
4031 `:scheduled' if the setting of
4032 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4033 any effect.
4035 :scheduled List all items which are scheduled for the given date.
4036 The diary for *today* also contains items which were
4037 scheduled earlier and are not yet marked DONE.
4039 By default, all four types are turned on.
4041 Never set this variable globally using `setq', because then it
4042 will apply to all future agenda commands. Instead, bind it with
4043 `let' to scope it dynamically into the agenda-constructing
4044 command. A good way to set it is through options in
4045 `org-agenda-custom-commands'. For a more flexible (though
4046 somewhat less efficient) way of determining what is included in
4047 the daily/weekly agenda, see `org-agenda-skip-function'.")
4049 (defvar org-agenda-buffer-tmp-name nil)
4050 ;;;###autoload
4051 (defun org-agenda-list (&optional arg start-day span)
4052 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4053 The view will be for the current day or week, but from the overview buffer
4054 you will be able to go to other days/weeks.
4056 With a numeric prefix argument in an interactive call, the agenda will
4057 span ARG days. Lisp programs should instead specify SPAN to change
4058 the number of days. SPAN defaults to `org-agenda-span'.
4060 START-DAY defaults to TODAY, or to the most recent match for the weekday
4061 given in `org-agenda-start-on-weekday'."
4062 (interactive "P")
4063 (if org-agenda-overriding-arguments
4064 (setq arg (car org-agenda-overriding-arguments)
4065 start-day (nth 1 org-agenda-overriding-arguments)
4066 span (nth 2 org-agenda-overriding-arguments)))
4067 (if (and (integerp arg) (> arg 0))
4068 (setq span arg arg nil))
4069 (catch 'exit
4070 (setq org-agenda-buffer-name
4071 (or org-agenda-buffer-tmp-name
4072 (if org-agenda-sticky
4073 (cond ((and org-keys (stringp org-match))
4074 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4075 (org-keys
4076 (format "*Org Agenda(%s)*" org-keys))
4077 (t "*Org Agenda(a)*")))
4078 org-agenda-buffer-name))
4079 (org-agenda-prepare "Day/Week")
4080 (setq start-day (or start-day org-agenda-start-day))
4081 (if (stringp start-day)
4082 ;; Convert to an absolute day number
4083 (setq start-day (time-to-days (org-read-date nil t start-day))))
4084 (org-compile-prefix-format 'agenda)
4085 (org-set-sorting-strategy 'agenda)
4086 (let* ((span (org-agenda-ndays-to-span
4087 (or span org-agenda-ndays org-agenda-span)))
4088 (today (org-today))
4089 (sd (or start-day today))
4090 (ndays (org-agenda-span-to-ndays span sd))
4091 (org-agenda-start-on-weekday
4092 (if (eq ndays 7)
4093 org-agenda-start-on-weekday))
4094 (thefiles (org-agenda-files nil 'ifmode))
4095 (files thefiles)
4096 (start (if (or (null org-agenda-start-on-weekday)
4097 (< ndays 7))
4099 (let* ((nt (calendar-day-of-week
4100 (calendar-gregorian-from-absolute sd)))
4101 (n1 org-agenda-start-on-weekday)
4102 (d (- nt n1)))
4103 (- sd (+ (if (< d 0) 7 0) d)))))
4104 (day-numbers (list start))
4105 (day-cnt 0)
4106 (inhibit-redisplay (not debug-on-error))
4107 (org-agenda-show-log-scoped org-agenda-show-log)
4108 s e rtn rtnall file date d start-pos end-pos todayp
4109 clocktable-start clocktable-end filter)
4110 (setq org-agenda-redo-command
4111 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4112 (dotimes (n (1- ndays))
4113 (push (1+ (car day-numbers)) day-numbers))
4114 (setq day-numbers (nreverse day-numbers))
4115 (setq clocktable-start (car day-numbers)
4116 clocktable-end (1+ (or (org-last day-numbers) 0)))
4117 (org-set-local 'org-starting-day (car day-numbers))
4118 (org-set-local 'org-arg-loc arg)
4119 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4120 (unless org-agenda-compact-blocks
4121 (let* ((d1 (car day-numbers))
4122 (d2 (org-last day-numbers))
4123 (w1 (org-days-to-iso-week d1))
4124 (w2 (org-days-to-iso-week d2)))
4125 (setq s (point))
4126 (if org-agenda-overriding-header
4127 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4128 nil 'face 'org-agenda-structure) "\n")
4129 (insert (org-agenda-span-name span)
4130 "-agenda"
4131 (if (< (- d2 d1) 350)
4132 (if (= w1 w2)
4133 (format " (W%02d)" w1)
4134 (format " (W%02d-W%02d)" w1 w2))
4136 ":\n")))
4137 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4138 'org-date-line t))
4139 (org-agenda-mark-header-line s))
4140 (while (setq d (pop day-numbers))
4141 (setq date (calendar-gregorian-from-absolute d)
4142 s (point))
4143 (if (or (setq todayp (= d today))
4144 (and (not start-pos) (= d sd)))
4145 (setq start-pos (point))
4146 (if (and start-pos (not end-pos))
4147 (setq end-pos (point))))
4148 (setq files thefiles
4149 rtnall nil)
4150 (while (setq file (pop files))
4151 (catch 'nextfile
4152 (org-check-agenda-file file)
4153 (let ((org-agenda-entry-types org-agenda-entry-types))
4154 (unless org-agenda-include-deadlines
4155 (setq org-agenda-entry-types
4156 (delq :deadline org-agenda-entry-types)))
4157 (cond
4158 ((memq org-agenda-show-log-scoped '(only clockcheck))
4159 (setq rtn (org-agenda-get-day-entries
4160 file date :closed)))
4161 (org-agenda-show-log-scoped
4162 (setq rtn (apply 'org-agenda-get-day-entries
4163 file date
4164 (append '(:closed) org-agenda-entry-types))))
4166 (setq rtn (apply 'org-agenda-get-day-entries
4167 file date
4168 org-agenda-entry-types)))))
4169 (setq rtnall (append rtnall rtn)))) ;; all entries
4170 (if org-agenda-include-diary
4171 (let ((org-agenda-search-headline-for-time t))
4172 (require 'diary-lib)
4173 (setq rtn (org-get-entries-from-diary date))
4174 (setq rtnall (append rtnall rtn))))
4175 (if (or rtnall org-agenda-show-all-dates)
4176 (progn
4177 (setq day-cnt (1+ day-cnt))
4178 (insert
4179 (if (stringp org-agenda-format-date)
4180 (format-time-string org-agenda-format-date
4181 (org-time-from-absolute date))
4182 (funcall org-agenda-format-date date))
4183 "\n")
4184 (put-text-property s (1- (point)) 'face
4185 (org-agenda-get-day-face date))
4186 (put-text-property s (1- (point)) 'org-date-line t)
4187 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4188 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4189 (when todayp
4190 (put-text-property s (1- (point)) 'org-today t))
4191 (setq rtnall
4192 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4193 (if rtnall (insert ;; all entries
4194 (org-agenda-finalize-entries rtnall 'agenda)
4195 "\n"))
4196 (put-text-property s (1- (point)) 'day d)
4197 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4198 (when (and org-agenda-clockreport-mode clocktable-start)
4199 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4200 ;; the above line is to ensure the restricted range!
4201 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4202 tbl)
4203 (setq p (org-plist-delete p :block))
4204 (setq p (plist-put p :tstart clocktable-start))
4205 (setq p (plist-put p :tend clocktable-end))
4206 (setq p (plist-put p :scope 'agenda))
4207 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4208 (setq filter (or org-agenda-tag-filter-while-redo
4209 (get 'org-agenda-tag-filter :preset-filter))))
4210 (setq p (plist-put p :tags (mapconcat (lambda (x)
4211 (if (string-match "[<>=]" x)
4214 filter ""))))
4215 (setq tbl (apply 'org-clock-get-clocktable p))
4216 (insert tbl)))
4217 (goto-char (point-min))
4218 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4219 (unless (and (pos-visible-in-window-p (point-min))
4220 (pos-visible-in-window-p (point-max)))
4221 (goto-char (1- (point-max)))
4222 (recenter -1)
4223 (if (not (pos-visible-in-window-p (or start-pos 1)))
4224 (progn
4225 (goto-char (or start-pos 1))
4226 (recenter 1))))
4227 (goto-char (or start-pos 1))
4228 (add-text-properties (point-min) (point-max)
4229 `(org-agenda-type agenda
4230 org-last-args (,arg ,start-day ,span)
4231 org-redo-cmd ,org-agenda-redo-command
4232 org-series-cmd ,org-cmd))
4233 (if (eq org-agenda-show-log-scoped 'clockcheck)
4234 (org-agenda-show-clocking-issues))
4235 (org-agenda-finalize)
4236 (setq buffer-read-only t)
4237 (message ""))))
4239 (defun org-agenda-ndays-to-span (n)
4240 "Return a span symbol for a span of N days, or N if none matches."
4241 (cond ((symbolp n) n)
4242 ((= n 1) 'day)
4243 ((= n 7) 'week)
4244 (t n)))
4246 (defun org-agenda-span-to-ndays (span &optional start-day)
4247 "Return ndays from SPAN, possibly starting at START-DAY."
4248 (cond ((numberp span) span)
4249 ((eq span 'day) 1)
4250 ((eq span 'week) 7)
4251 ((eq span 'month)
4252 (let ((date (calendar-gregorian-from-absolute start-day)))
4253 (calendar-last-day-of-month (car date) (caddr date))))
4254 ((eq span 'year)
4255 (let ((date (calendar-gregorian-from-absolute start-day)))
4256 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4258 (defun org-agenda-span-name (span)
4259 "Return a SPAN name."
4260 (if (null span)
4262 (if (symbolp span)
4263 (capitalize (symbol-name span))
4264 (format "%d days" span))))
4266 ;;; Agenda word search
4268 (defvar org-agenda-search-history nil)
4270 (defvar org-search-syntax-table nil
4271 "Special syntax table for org-mode search.
4272 In this table, we have single quotes not as word constituents, to
4273 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4275 (defvar org-mode-syntax-table) ; From org.el
4276 (defun org-search-syntax-table ()
4277 (unless org-search-syntax-table
4278 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4279 (modify-syntax-entry ?' "." org-search-syntax-table)
4280 (modify-syntax-entry ?` "." org-search-syntax-table))
4281 org-search-syntax-table)
4283 (defvar org-agenda-last-search-view-search-was-boolean nil)
4285 ;;;###autoload
4286 (defun org-search-view (&optional todo-only string edit-at)
4287 "Show all entries that contain a phrase or words or regular expressions.
4289 With optional prefix argument TODO-ONLY, only consider entries that are
4290 TODO entries. The argument STRING can be used to pass a default search
4291 string into this function. If EDIT-AT is non-nil, it means that the
4292 user should get a chance to edit this string, with cursor at position
4293 EDIT-AT.
4295 The search string can be viewed either as a phrase that should be found as
4296 is, or it can be broken into a number of snippets, each of which must match
4297 in a Boolean way to select an entry. The default depends on the variable
4298 `org-agenda-search-view-always-boolean'.
4299 Even if this is turned off (the default) you can always switch to
4300 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4302 The default is a direct search of the whole phrase, where each space in
4303 the search string can expand to an arbitrary amount of whitespace,
4304 including newlines.
4306 If using a Boolean search, the search string is split on whitespace and
4307 each snippet is searched separately, with logical AND to select an entry.
4308 Words prefixed with a minus must *not* occur in the entry. Words without
4309 a prefix or prefixed with a plus must occur in the entry. Matching is
4310 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4311 match whole words, not parts of a word) if
4312 `org-agenda-search-view-force-full-words' is set (default is nil).
4314 Boolean search snippets enclosed by curly braces are interpreted as
4315 regular expressions that must or (when preceded with \"-\") must not
4316 match in the entry. Snippets enclosed into double quotes will be taken
4317 as a whole, to include whitespace.
4319 - If the search string starts with an asterisk, search only in headlines.
4320 - If (possibly after the leading star) the search string starts with an
4321 exclamation mark, this also means to look at TODO entries only, an effect
4322 that can also be achieved with a prefix argument.
4323 - If (possibly after star and exclamation mark) the search string starts
4324 with a colon, this will mean that the (non-regexp) snippets of the
4325 Boolean search must match as full words.
4327 This command searches the agenda files, and in addition the files listed
4328 in `org-agenda-text-search-extra-files'."
4329 (interactive "P")
4330 (if org-agenda-overriding-arguments
4331 (setq todo-only (car org-agenda-overriding-arguments)
4332 string (nth 1 org-agenda-overriding-arguments)
4333 edit-at (nth 2 org-agenda-overriding-arguments)))
4334 (let* ((props (list 'face nil
4335 'done-face 'org-agenda-done
4336 'org-not-done-regexp org-not-done-regexp
4337 'org-todo-regexp org-todo-regexp
4338 'org-complex-heading-regexp org-complex-heading-regexp
4339 'mouse-face 'highlight
4340 'help-echo (format "mouse-2 or RET jump to location")))
4341 (full-words org-agenda-search-view-force-full-words)
4342 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4343 regexp rtn rtnall files file pos inherited-tags
4344 marker category category-pos level tags c neg re boolean
4345 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4346 (unless (and (not edit-at)
4347 (stringp string)
4348 (string-match "\\S-" string))
4349 (setq string (read-string
4350 (if org-agenda-search-view-always-boolean
4351 "[+-]Word/{Regexp} ...: "
4352 "Phrase or [+-]Word/{Regexp} ...: ")
4353 (cond
4354 ((integerp edit-at) (cons string edit-at))
4355 (edit-at string))
4356 'org-agenda-search-history)))
4357 (catch 'exit
4358 (if org-agenda-sticky
4359 (setq org-agenda-buffer-name
4360 (if (stringp string)
4361 (format "*Org Agenda(%s:%s)*"
4362 (or org-keys (or (and todo-only "S") "s")) string)
4363 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4364 (org-agenda-prepare "SEARCH")
4365 (org-compile-prefix-format 'search)
4366 (org-set-sorting-strategy 'search)
4367 (setq org-agenda-redo-command
4368 (list 'org-search-view (if todo-only t nil)
4369 (list 'if 'current-prefix-arg nil string)))
4370 (setq org-agenda-query-string string)
4371 (if (equal (string-to-char string) ?*)
4372 (setq hdl-only t
4373 words (substring string 1))
4374 (setq words string))
4375 (when (equal (string-to-char words) ?!)
4376 (setq todo-only t
4377 words (substring words 1)))
4378 (when (equal (string-to-char words) ?:)
4379 (setq full-words t
4380 words (substring words 1)))
4381 (if (or org-agenda-search-view-always-boolean
4382 (member (string-to-char words) '(?- ?+ ?\{)))
4383 (setq boolean t))
4384 (setq words (org-split-string words))
4385 (let (www w)
4386 (while (setq w (pop words))
4387 (while (and (string-match "\\\\\\'" w) words)
4388 (setq w (concat (substring w 0 -1) " " (pop words))))
4389 (push w www))
4390 (setq words (nreverse www) www nil)
4391 (while (setq w (pop words))
4392 (when (and (string-match "\\`[-+]?{" w)
4393 (not (string-match "}\\'" w)))
4394 (while (and words (not (string-match "}\\'" (car words))))
4395 (setq w (concat w " " (pop words))))
4396 (setq w (concat w " " (pop words))))
4397 (push w www))
4398 (setq words (nreverse www)))
4399 (setq org-agenda-last-search-view-search-was-boolean boolean)
4400 (when boolean
4401 (let (wds w)
4402 (while (setq w (pop words))
4403 (if (or (equal (substring w 0 1) "\"")
4404 (and (> (length w) 1)
4405 (member (substring w 0 1) '("+" "-"))
4406 (equal (substring w 1 2) "\"")))
4407 (while (and words (not (equal (substring w -1) "\"")))
4408 (setq w (concat w " " (pop words)))))
4409 (and (string-match "\\`\\([-+]?\\)\"" w)
4410 (setq w (replace-match "\\1" nil nil w)))
4411 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4412 (push w wds))
4413 (setq words (nreverse wds))))
4414 (if boolean
4415 (mapc (lambda (w)
4416 (setq c (string-to-char w))
4417 (if (equal c ?-)
4418 (setq neg t w (substring w 1))
4419 (if (equal c ?+)
4420 (setq neg nil w (substring w 1))
4421 (setq neg nil)))
4422 (if (string-match "\\`{.*}\\'" w)
4423 (setq re (substring w 1 -1))
4424 (if full-words
4425 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4426 (setq re (regexp-quote (downcase w)))))
4427 (if neg (push re regexps-) (push re regexps+)))
4428 words)
4429 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4430 regexps+))
4431 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4432 (if (not regexps+)
4433 (setq regexp org-outline-regexp-bol)
4434 (setq regexp (pop regexps+))
4435 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4436 regexp))))
4437 (setq files (org-agenda-files nil 'ifmode))
4438 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4439 (pop org-agenda-text-search-extra-files)
4440 (setq files (org-add-archive-files files)))
4441 (setq files (append files org-agenda-text-search-extra-files)
4442 rtnall nil)
4443 (while (setq file (pop files))
4444 (setq ee nil)
4445 (catch 'nextfile
4446 (org-check-agenda-file file)
4447 (setq buffer (if (file-exists-p file)
4448 (org-get-agenda-file-buffer file)
4449 (error "No such file %s" file)))
4450 (if (not buffer)
4451 ;; If file does not exist, make sure an error message is sent
4452 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4453 file))))
4454 (with-current-buffer buffer
4455 (with-syntax-table (org-search-syntax-table)
4456 (unless (derived-mode-p 'org-mode)
4457 (error "Agenda file %s is not in `org-mode'" file))
4458 (let ((case-fold-search t))
4459 (save-excursion
4460 (save-restriction
4461 (if org-agenda-restrict
4462 (narrow-to-region org-agenda-restrict-begin
4463 org-agenda-restrict-end)
4464 (widen))
4465 (goto-char (point-min))
4466 (unless (or (org-at-heading-p)
4467 (outline-next-heading))
4468 (throw 'nextfile t))
4469 (goto-char (max (point-min) (1- (point))))
4470 (while (re-search-forward regexp nil t)
4471 (org-back-to-heading t)
4472 (while (and org-agenda-search-view-max-outline-level
4473 (> (org-reduced-level (org-outline-level))
4474 org-agenda-search-view-max-outline-level)
4475 (forward-line -1)
4476 (outline-back-to-heading t)))
4477 (skip-chars-forward "* ")
4478 (setq beg (point-at-bol)
4479 beg1 (point)
4480 end (progn
4481 (outline-next-heading)
4482 (while (and org-agenda-search-view-max-outline-level
4483 (> (org-reduced-level (org-outline-level))
4484 org-agenda-search-view-max-outline-level)
4485 (forward-line 1)
4486 (outline-next-heading)))
4487 (point)))
4489 (catch :skip
4490 (goto-char beg)
4491 (org-agenda-skip)
4492 (setq str (buffer-substring-no-properties
4493 (point-at-bol)
4494 (if hdl-only (point-at-eol) end)))
4495 (mapc (lambda (wr) (when (string-match wr str)
4496 (goto-char (1- end))
4497 (throw :skip t)))
4498 regexps-)
4499 (mapc (lambda (wr) (unless (string-match wr str)
4500 (goto-char (1- end))
4501 (throw :skip t)))
4502 (if todo-only
4503 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4504 regexps+)
4505 regexps+))
4506 (goto-char beg)
4507 (setq marker (org-agenda-new-marker (point))
4508 category (org-get-category)
4509 level (make-string (org-reduced-level (org-outline-level)) ? )
4510 category-pos (get-text-property (point) 'org-category-position)
4511 inherited-tags
4512 (or (eq org-agenda-show-inherited-tags 'always)
4513 (and (listp org-agenda-show-inherited-tags)
4514 (memq 'todo org-agenda-show-inherited-tags))
4515 (and (eq org-agenda-show-inherited-tags t)
4516 (or (eq org-agenda-use-tag-inheritance t)
4517 (memq 'todo org-agenda-use-tag-inheritance))))
4518 tags (org-get-tags-at nil (not inherited-tags))
4519 txt (org-agenda-format-item
4521 (buffer-substring-no-properties
4522 beg1 (point-at-eol))
4523 level category tags t))
4524 (org-add-props txt props
4525 'org-marker marker 'org-hd-marker marker
4526 'org-todo-regexp org-todo-regexp
4527 'level level
4528 'org-complex-heading-regexp org-complex-heading-regexp
4529 'priority 1000 'org-category category
4530 'org-category-position category-pos
4531 'type "search")
4532 (push txt ee)
4533 (goto-char (1- end))))))))))
4534 (setq rtn (nreverse ee))
4535 (setq rtnall (append rtnall rtn)))
4536 (if org-agenda-overriding-header
4537 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4538 nil 'face 'org-agenda-structure) "\n")
4539 (insert "Search words: ")
4540 (add-text-properties (point-min) (1- (point))
4541 (list 'face 'org-agenda-structure))
4542 (setq pos (point))
4543 (insert string "\n")
4544 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4545 (setq pos (point))
4546 (unless org-agenda-multi
4547 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4548 (add-text-properties pos (1- (point))
4549 (list 'face 'org-agenda-structure))))
4550 (org-agenda-mark-header-line (point-min))
4551 (when rtnall
4552 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4553 (goto-char (point-min))
4554 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4555 (add-text-properties (point-min) (point-max)
4556 `(org-agenda-type search
4557 org-last-args (,todo-only ,string ,edit-at)
4558 org-redo-cmd ,org-agenda-redo-command
4559 org-series-cmd ,org-cmd))
4560 (org-agenda-finalize)
4561 (setq buffer-read-only t))))
4563 ;;; Agenda TODO list
4565 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4566 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4567 (concat
4568 (if (or (equal keywords "ALL") (not keywords))
4569 (propertize "ALL" 'face 'warning)
4570 (mapconcat
4571 (lambda (kw)
4572 (propertize kw 'face (org-get-todo-face kw)))
4573 (org-split-string keywords "|")
4574 "|"))
4575 "\n"))
4577 (defvar org-select-this-todo-keyword nil)
4578 (defvar org-last-arg nil)
4580 ;;;###autoload
4581 (defun org-todo-list (&optional arg)
4582 "Show all (not done) TODO entries from all agenda file in a single list.
4583 The prefix arg can be used to select a specific TODO keyword and limit
4584 the list to these. When using \\[universal-argument], you will be prompted
4585 for a keyword. A numeric prefix directly selects the Nth keyword in
4586 `org-todo-keywords-1'."
4587 (interactive "P")
4588 (if org-agenda-overriding-arguments
4589 (setq arg org-agenda-overriding-arguments))
4590 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4591 (let* ((today (org-today))
4592 (date (calendar-gregorian-from-absolute today))
4593 (kwds org-todo-keywords-for-agenda)
4594 (completion-ignore-case t)
4595 (org-select-this-todo-keyword
4596 (if (stringp arg) arg
4597 (and arg (integerp arg) (> arg 0)
4598 (nth (1- arg) kwds))))
4599 rtn rtnall files file pos)
4600 (when (equal arg '(4))
4601 (setq org-select-this-todo-keyword
4602 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4603 (mapcar 'list kwds) nil nil)))
4604 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4605 (catch 'exit
4606 (if org-agenda-sticky
4607 (setq org-agenda-buffer-name
4608 (if (stringp org-select-this-todo-keyword)
4609 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4610 org-select-this-todo-keyword)
4611 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4612 (org-agenda-prepare "TODO")
4613 (org-compile-prefix-format 'todo)
4614 (org-set-sorting-strategy 'todo)
4615 (setq org-agenda-redo-command
4616 `(org-todo-list (or (and (numberp current-prefix-arg)
4617 current-prefix-arg)
4618 ,org-select-this-todo-keyword
4619 current-prefix-arg ,arg)))
4620 (setq files (org-agenda-files nil 'ifmode)
4621 rtnall nil)
4622 (while (setq file (pop files))
4623 (catch 'nextfile
4624 (org-check-agenda-file file)
4625 (setq rtn (org-agenda-get-day-entries file date :todo))
4626 (setq rtnall (append rtnall rtn))))
4627 (if org-agenda-overriding-header
4628 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4629 nil 'face 'org-agenda-structure) "\n")
4630 (insert "Global list of TODO items of type: ")
4631 (add-text-properties (point-min) (1- (point))
4632 (list 'face 'org-agenda-structure
4633 'short-heading
4634 (concat "ToDo: "
4635 (or org-select-this-todo-keyword "ALL"))))
4636 (org-agenda-mark-header-line (point-min))
4637 (insert (org-agenda-propertize-selected-todo-keywords
4638 org-select-this-todo-keyword))
4639 (setq pos (point))
4640 (unless org-agenda-multi
4641 (insert "Available with `N r': (0)[ALL]")
4642 (let ((n 0) s)
4643 (mapc (lambda (x)
4644 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4645 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4646 (insert "\n "))
4647 (insert " " s))
4648 kwds))
4649 (insert "\n"))
4650 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4651 (org-agenda-mark-header-line (point-min))
4652 (when rtnall
4653 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4654 (goto-char (point-min))
4655 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4656 (add-text-properties (point-min) (point-max)
4657 `(org-agenda-type todo
4658 org-last-args ,arg
4659 org-redo-cmd ,org-agenda-redo-command
4660 org-series-cmd ,org-cmd))
4661 (org-agenda-finalize)
4662 (setq buffer-read-only t))))
4664 ;;; Agenda tags match
4666 ;;;###autoload
4667 (defun org-tags-view (&optional todo-only match)
4668 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4669 The prefix arg TODO-ONLY limits the search to TODO entries."
4670 (interactive "P")
4671 (if org-agenda-overriding-arguments
4672 (setq todo-only (car org-agenda-overriding-arguments)
4673 match (nth 1 org-agenda-overriding-arguments)))
4674 (let* ((org-tags-match-list-sublevels
4675 org-tags-match-list-sublevels)
4676 (completion-ignore-case t)
4677 rtn rtnall files file pos matcher
4678 buffer)
4679 (when (and (stringp match) (not (string-match "\\S-" match)))
4680 (setq match nil))
4681 (setq matcher (org-make-tags-matcher match)
4682 match (car matcher) matcher (cdr matcher))
4683 (catch 'exit
4684 (if org-agenda-sticky
4685 (setq org-agenda-buffer-name
4686 (if (stringp match)
4687 (format "*Org Agenda(%s:%s)*"
4688 (or org-keys (or (and todo-only "M") "m")) match)
4689 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4690 (org-agenda-prepare (concat "TAGS " match))
4691 (org-compile-prefix-format 'tags)
4692 (org-set-sorting-strategy 'tags)
4693 (setq org-agenda-query-string match)
4694 (setq org-agenda-redo-command
4695 (list 'org-tags-view `(quote ,todo-only)
4696 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4697 (setq files (org-agenda-files nil 'ifmode)
4698 rtnall nil)
4699 (while (setq file (pop files))
4700 (catch 'nextfile
4701 (org-check-agenda-file file)
4702 (setq buffer (if (file-exists-p file)
4703 (org-get-agenda-file-buffer file)
4704 (error "No such file %s" file)))
4705 (if (not buffer)
4706 ;; If file does not exist, error message to agenda
4707 (setq rtn (list
4708 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4709 rtnall (append rtnall rtn))
4710 (with-current-buffer buffer
4711 (unless (derived-mode-p 'org-mode)
4712 (error "Agenda file %s is not in `org-mode'" file))
4713 (save-excursion
4714 (save-restriction
4715 (if org-agenda-restrict
4716 (narrow-to-region org-agenda-restrict-begin
4717 org-agenda-restrict-end)
4718 (widen))
4719 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4720 (setq rtnall (append rtnall rtn))))))))
4721 (if org-agenda-overriding-header
4722 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4723 nil 'face 'org-agenda-structure) "\n")
4724 (insert "Headlines with TAGS match: ")
4725 (add-text-properties (point-min) (1- (point))
4726 (list 'face 'org-agenda-structure
4727 'short-heading
4728 (concat "Match: " match)))
4729 (setq pos (point))
4730 (insert match "\n")
4731 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4732 (setq pos (point))
4733 (unless org-agenda-multi
4734 (insert "Press `C-u r' to search again with new search string\n"))
4735 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4736 (org-agenda-mark-header-line (point-min))
4737 (when rtnall
4738 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4739 (goto-char (point-min))
4740 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4741 (add-text-properties (point-min) (point-max)
4742 `(org-agenda-type tags
4743 org-last-args (,todo-only ,match)
4744 org-redo-cmd ,org-agenda-redo-command
4745 org-series-cmd ,org-cmd))
4746 (org-agenda-finalize)
4747 (setq buffer-read-only t))))
4749 ;;; Agenda Finding stuck projects
4751 (defvar org-agenda-skip-regexp nil
4752 "Regular expression used in skipping subtrees for the agenda.
4753 This is basically a temporary global variable that can be set and then
4754 used by user-defined selections using `org-agenda-skip-function'.")
4756 (defvar org-agenda-overriding-header nil
4757 "When set during agenda, todo and tags searches it replaces the header.
4758 This variable should not be set directly, but custom commands can bind it
4759 in the options section.")
4761 (defun org-agenda-skip-entry-when-regexp-matches ()
4762 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4763 If yes, it returns the end position of this entry, causing agenda commands
4764 to skip the entry but continuing the search in the subtree. This is a
4765 function that can be put into `org-agenda-skip-function' for the duration
4766 of a command."
4767 (let ((end (save-excursion (org-end-of-subtree t)))
4768 skip)
4769 (save-excursion
4770 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4771 (and skip end)))
4773 (defun org-agenda-skip-subtree-when-regexp-matches ()
4774 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4775 If yes, it returns the end position of this tree, causing agenda commands
4776 to skip this subtree. This is a function that can be put into
4777 `org-agenda-skip-function' for the duration of a command."
4778 (let ((end (save-excursion (org-end-of-subtree t)))
4779 skip)
4780 (save-excursion
4781 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4782 (and skip end)))
4784 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4785 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4786 If yes, it returns the end position of the current entry (NOT the tree),
4787 causing agenda commands to skip the entry but continuing the search in
4788 the subtree. This is a function that can be put into
4789 `org-agenda-skip-function' for the duration of a command. An important
4790 use of this function is for the stuck project list."
4791 (let ((end (save-excursion (org-end-of-subtree t)))
4792 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4793 skip)
4794 (save-excursion
4795 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4796 (and skip entry-end)))
4798 (defun org-agenda-skip-entry-if (&rest conditions)
4799 "Skip entry if any of CONDITIONS is true.
4800 See `org-agenda-skip-if' for details."
4801 (org-agenda-skip-if nil conditions))
4803 (defun org-agenda-skip-subtree-if (&rest conditions)
4804 "Skip entry if any of CONDITIONS is true.
4805 See `org-agenda-skip-if' for details."
4806 (org-agenda-skip-if t conditions))
4808 (defun org-agenda-skip-if (subtree conditions)
4809 "Checks current entity for CONDITIONS.
4810 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4811 the entry (i.e. the text before the next heading) is checked.
4813 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4814 from different tests. Valid conditions are:
4816 scheduled Check if there is a scheduled cookie
4817 notscheduled Check if there is no scheduled cookie
4818 deadline Check if there is a deadline
4819 notdeadline Check if there is no deadline
4820 timestamp Check if there is a timestamp (also deadline or scheduled)
4821 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4822 regexp Check if regexp matches
4823 notregexp Check if regexp does not match.
4824 todo Check if TODO keyword matches
4825 nottodo Check if TODO keyword does not match
4827 The regexp is taken from the conditions list, it must come right after
4828 the `regexp' or `notregexp' element.
4830 `todo' and `nottodo' accept as an argument a list of todo
4831 keywords, which may include \"*\" to match any todo keyword.
4833 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4835 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4837 Instead of a list, a keyword class may be given. For example:
4839 (org-agenda-skip-entry-if 'nottodo 'done)
4841 would skip entries that haven't been marked with any of \"DONE\"
4842 keywords. Possible classes are: `todo', `done', `any'.
4844 If any of these conditions is met, this function returns the end point of
4845 the entity, causing the search to continue from there. This is a function
4846 that can be put into `org-agenda-skip-function' for the duration of a command."
4847 (let (beg end m)
4848 (org-back-to-heading t)
4849 (setq beg (point)
4850 end (if subtree
4851 (progn (org-end-of-subtree t) (point))
4852 (progn (outline-next-heading) (1- (point)))))
4853 (goto-char beg)
4854 (and
4856 (and (memq 'scheduled conditions)
4857 (re-search-forward org-scheduled-time-regexp end t))
4858 (and (memq 'notscheduled conditions)
4859 (not (re-search-forward org-scheduled-time-regexp end t)))
4860 (and (memq 'deadline conditions)
4861 (re-search-forward org-deadline-time-regexp end t))
4862 (and (memq 'notdeadline conditions)
4863 (not (re-search-forward org-deadline-time-regexp end t)))
4864 (and (memq 'timestamp conditions)
4865 (re-search-forward org-ts-regexp end t))
4866 (and (memq 'nottimestamp conditions)
4867 (not (re-search-forward org-ts-regexp end t)))
4868 (and (setq m (memq 'regexp conditions))
4869 (stringp (nth 1 m))
4870 (re-search-forward (nth 1 m) end t))
4871 (and (setq m (memq 'notregexp conditions))
4872 (stringp (nth 1 m))
4873 (not (re-search-forward (nth 1 m) end t)))
4874 (and (or
4875 (setq m (memq 'nottodo conditions))
4876 (setq m (memq 'todo-unblocked conditions))
4877 (setq m (memq 'nottodo-unblocked conditions))
4878 (setq m (memq 'todo conditions)))
4879 (org-agenda-skip-if-todo m end)))
4880 end)))
4882 (defun org-agenda-skip-if-todo (args end)
4883 "Helper function for `org-agenda-skip-if', do not use it directly.
4884 ARGS is a list with first element either `todo', `nottodo',
4885 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4886 a list of TODO keywords, or a state symbol `todo' or `done' or
4887 `any'."
4888 (let ((kw (car args))
4889 (arg (cadr args))
4890 todo-wds todo-re)
4891 (setq todo-wds
4892 (org-uniquify
4893 (cond
4894 ((listp arg) ;; list of keywords
4895 (if (member "*" arg)
4896 (mapcar 'substring-no-properties org-todo-keywords-1)
4897 arg))
4898 ((symbolp arg) ;; keyword class name
4899 (cond
4900 ((eq arg 'todo)
4901 (org-delete-all org-done-keywords
4902 (mapcar 'substring-no-properties
4903 org-todo-keywords-1)))
4904 ((eq arg 'done) org-done-keywords)
4905 ((eq arg 'any)
4906 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4907 (setq todo-re
4908 (concat "^\\*+[ \t]+\\<\\("
4909 (mapconcat 'identity todo-wds "\\|")
4910 "\\)\\>"))
4911 (cond
4912 ((eq kw 'todo) (re-search-forward todo-re end t))
4913 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4914 ((eq kw 'todo-unblocked)
4915 (catch 'unblocked
4916 (while (re-search-forward todo-re end t)
4917 (or (org-entry-blocked-p) (throw 'unblocked t)))
4918 nil))
4919 ((eq kw 'nottodo-unblocked)
4920 (catch 'unblocked
4921 (while (re-search-forward todo-re end t)
4922 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4926 ;;;###autoload
4927 (defun org-agenda-list-stuck-projects (&rest ignore)
4928 "Create agenda view for projects that are stuck.
4929 Stuck projects are project that have no next actions. For the definitions
4930 of what a project is and how to check if it stuck, customize the variable
4931 `org-stuck-projects'."
4932 (interactive)
4933 (let* ((org-agenda-skip-function
4934 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4935 ;; We could have used org-agenda-skip-if here.
4936 (org-agenda-overriding-header
4937 (or org-agenda-overriding-header "List of stuck projects: "))
4938 (matcher (nth 0 org-stuck-projects))
4939 (todo (nth 1 org-stuck-projects))
4940 (todo-wds (if (member "*" todo)
4941 (progn
4942 (org-agenda-prepare-buffers (org-agenda-files
4943 nil 'ifmode))
4944 (org-delete-all
4945 org-done-keywords-for-agenda
4946 (copy-sequence org-todo-keywords-for-agenda)))
4947 todo))
4948 (todo-re (concat "^\\*+[ \t]+\\("
4949 (mapconcat 'identity todo-wds "\\|")
4950 "\\)\\>"))
4951 (tags (nth 2 org-stuck-projects))
4952 (tags-re (if (member "*" tags)
4953 (concat org-outline-regexp-bol
4954 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4955 (if tags
4956 (concat org-outline-regexp-bol
4957 ".*:\\("
4958 (mapconcat 'identity tags "\\|")
4959 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4960 (gen-re (nth 3 org-stuck-projects))
4961 (re-list
4962 (delq nil
4963 (list
4964 (if todo todo-re)
4965 (if tags tags-re)
4966 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4967 gen-re)))))
4968 (setq org-agenda-skip-regexp
4969 (if re-list
4970 (mapconcat 'identity re-list "\\|")
4971 (error "No information how to identify unstuck projects")))
4972 (org-tags-view nil matcher)
4973 (with-current-buffer org-agenda-buffer-name
4974 (setq org-agenda-redo-command
4975 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4977 ;;; Diary integration
4979 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4980 (defvar diary-list-entries-hook)
4981 (defvar diary-time-regexp)
4982 (defun org-get-entries-from-diary (date)
4983 "Get the (Emacs Calendar) diary entries for DATE."
4984 (require 'diary-lib)
4985 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4986 (diary-display-hook '(fancy-diary-display))
4987 (diary-display-function 'fancy-diary-display)
4988 (pop-up-frames nil)
4989 (diary-list-entries-hook
4990 (cons 'org-diary-default-entry diary-list-entries-hook))
4991 (diary-file-name-prefix nil) ; turn this feature off
4992 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4993 entries
4994 (org-disable-agenda-to-diary t))
4995 (save-excursion
4996 (save-window-excursion
4997 (funcall (if (fboundp 'diary-list-entries)
4998 'diary-list-entries 'list-diary-entries)
4999 date 1)))
5000 (if (not (get-buffer diary-fancy-buffer))
5001 (setq entries nil)
5002 (with-current-buffer diary-fancy-buffer
5003 (setq buffer-read-only nil)
5004 (if (zerop (buffer-size))
5005 ;; No entries
5006 (setq entries nil)
5007 ;; Omit the date and other unnecessary stuff
5008 (org-agenda-cleanup-fancy-diary)
5009 ;; Add prefix to each line and extend the text properties
5010 (if (zerop (buffer-size))
5011 (setq entries nil)
5012 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5013 (setq entries
5014 (with-temp-buffer
5015 (insert entries) (goto-char (point-min))
5016 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5017 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5018 (replace-match (concat "; " (match-string 1)))))
5019 (buffer-string)))))
5020 (set-buffer-modified-p nil)
5021 (kill-buffer diary-fancy-buffer)))
5022 (when entries
5023 (setq entries (org-split-string entries "\n"))
5024 (setq entries
5025 (mapcar
5026 (lambda (x)
5027 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5028 ;; Extend the text properties to the beginning of the line
5029 (org-add-props x (text-properties-at (1- (length x)) x)
5030 'type "diary" 'date date 'face 'org-agenda-diary))
5031 entries)))))
5033 (defvar org-agenda-cleanup-fancy-diary-hook nil
5034 "Hook run when the fancy diary buffer is cleaned up.")
5036 (defun org-agenda-cleanup-fancy-diary ()
5037 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5038 This gets rid of the date, the underline under the date, and
5039 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5040 date. It also removes lines that contain only whitespace."
5041 (goto-char (point-min))
5042 (if (looking-at ".*?:[ \t]*")
5043 (progn
5044 (replace-match "")
5045 (re-search-forward "\n=+$" nil t)
5046 (replace-match "")
5047 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5048 (re-search-forward "\n=+$" nil t)
5049 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5050 (goto-char (point-min))
5051 (while (re-search-forward "^ +\n" nil t)
5052 (replace-match ""))
5053 (goto-char (point-min))
5054 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5055 (replace-match ""))
5056 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5058 ;; Make sure entries from the diary have the right text properties.
5059 (eval-after-load "diary-lib"
5060 '(if (boundp 'diary-modify-entry-list-string-function)
5061 ;; We can rely on the hook, nothing to do
5063 ;; Hook not available, must use advice to make this work
5064 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5065 "Make the position visible."
5066 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5067 (stringp string)
5068 buffer-file-name)
5069 (setq string (org-modify-diary-entry-string string))))))
5071 (defun org-modify-diary-entry-string (string)
5072 "Add text properties to string, allowing org-mode to act on it."
5073 (org-add-props string nil
5074 'mouse-face 'highlight
5075 'help-echo (if buffer-file-name
5076 (format "mouse-2 or RET jump to diary file %s"
5077 (abbreviate-file-name buffer-file-name))
5079 'org-agenda-diary-link t
5080 'org-marker (org-agenda-new-marker (point-at-bol))))
5082 (defun org-diary-default-entry ()
5083 "Add a dummy entry to the diary.
5084 Needed to avoid empty dates which mess up holiday display."
5085 ;; Catch the error if dealing with the new add-to-diary-alist
5086 (when org-disable-agenda-to-diary
5087 (condition-case nil
5088 (org-add-to-diary-list original-date "Org-mode dummy" "")
5089 (error
5090 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5092 (defun org-add-to-diary-list (&rest args)
5093 (if (fboundp 'diary-add-to-list)
5094 (apply 'diary-add-to-list args)
5095 (apply 'add-to-diary-list args)))
5097 (defvar org-diary-last-run-time nil)
5099 ;;;###autoload
5100 (defun org-diary (&rest args)
5101 "Return diary information from org files.
5102 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5103 It accesses org files and extracts information from those files to be
5104 listed in the diary. The function accepts arguments specifying what
5105 items should be listed. For a list of arguments allowed here, see the
5106 variable `org-agenda-entry-types'.
5108 The call in the diary file should look like this:
5110 &%%(org-diary) ~/path/to/some/orgfile.org
5112 Use a separate line for each org file to check. Or, if you omit the file name,
5113 all files listed in `org-agenda-files' will be checked automatically:
5115 &%%(org-diary)
5117 If you don't give any arguments (as in the example above), the default
5118 arguments (:deadline :scheduled :timestamp :sexp) are used.
5119 So the example above may also be written as
5121 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5123 The function expects the lisp variables `entry' and `date' to be provided
5124 by the caller, because this is how the calendar works. Don't use this
5125 function from a program - use `org-agenda-get-day-entries' instead."
5126 (when (> (- (org-float-time)
5127 org-agenda-last-marker-time)
5129 ;; I am not sure if this works with sticky agendas, because the marker
5130 ;; list is then no longer a global variable.
5131 (org-agenda-reset-markers))
5132 (org-compile-prefix-format 'agenda)
5133 (org-set-sorting-strategy 'agenda)
5134 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5135 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5136 (list entry)
5137 (org-agenda-files t)))
5138 (time (org-float-time))
5139 file rtn results)
5140 (when (or (not org-diary-last-run-time)
5141 (> (- time
5142 org-diary-last-run-time)
5144 (org-agenda-prepare-buffers files))
5145 (setq org-diary-last-run-time time)
5146 ;; If this is called during org-agenda, don't return any entries to
5147 ;; the calendar. Org Agenda will list these entries itself.
5148 (if org-disable-agenda-to-diary (setq files nil))
5149 (while (setq file (pop files))
5150 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5151 (setq results (append results rtn)))
5152 (when results
5153 (setq results
5154 (mapcar (lambda (i) (replace-regexp-in-string
5155 org-bracket-link-regexp "\\3" i)) results))
5156 (concat (org-agenda-finalize-entries results) "\n"))))
5158 ;;; Agenda entry finders
5160 (defun org-agenda-get-day-entries (file date &rest args)
5161 "Does the work for `org-diary' and `org-agenda'.
5162 FILE is the path to a file to be checked for entries. DATE is date like
5163 the one returned by `calendar-current-date'. ARGS are symbols indicating
5164 which kind of entries should be extracted. For details about these, see
5165 the documentation of `org-diary'."
5166 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5167 (let* ((org-startup-folded nil)
5168 (org-startup-align-all-tables nil)
5169 (buffer (if (file-exists-p file)
5170 (org-get-agenda-file-buffer file)
5171 (error "No such file %s" file)))
5172 arg results rtn deadline-results)
5173 (if (not buffer)
5174 ;; If file does not exist, make sure an error message ends up in diary
5175 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5176 (with-current-buffer buffer
5177 (unless (derived-mode-p 'org-mode)
5178 (error "Agenda file %s is not in `org-mode'" file))
5179 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5180 (let ((case-fold-search nil))
5181 (save-excursion
5182 (save-restriction
5183 (if org-agenda-restrict
5184 (narrow-to-region org-agenda-restrict-begin
5185 org-agenda-restrict-end)
5186 (widen))
5187 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5188 (while (setq arg (pop args))
5189 (cond
5190 ((and (eq arg :todo)
5191 (equal date (calendar-gregorian-from-absolute
5192 (org-today))))
5193 (setq rtn (org-agenda-get-todos))
5194 (setq results (append results rtn)))
5195 ((eq arg :timestamp)
5196 (setq rtn (org-agenda-get-blocks))
5197 (setq results (append results rtn))
5198 (setq rtn (org-agenda-get-timestamps deadline-results))
5199 (setq results (append results rtn)))
5200 ((eq arg :sexp)
5201 (setq rtn (org-agenda-get-sexps))
5202 (setq results (append results rtn)))
5203 ((eq arg :scheduled)
5204 (setq rtn (org-agenda-get-scheduled deadline-results))
5205 (setq results (append results rtn)))
5206 ((eq arg :closed)
5207 (setq rtn (org-agenda-get-progress))
5208 (setq results (append results rtn)))
5209 ((eq arg :deadline)
5210 (setq rtn (org-agenda-get-deadlines))
5211 (setq deadline-results (copy-sequence rtn))
5212 (setq results (append results rtn))))))))
5213 results))))
5215 (defsubst org-em (x y list)
5216 "Is X or Y a member of LIST?"
5217 (or (memq x list) (memq y list)))
5219 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5220 (defvar org-agenda-sorting-strategy-selected nil)
5222 (defun org-agenda-get-todos ()
5223 "Return the TODO information for agenda display."
5224 (let* ((props (list 'face nil
5225 'done-face 'org-agenda-done
5226 'org-not-done-regexp org-not-done-regexp
5227 'org-todo-regexp org-todo-regexp
5228 'org-complex-heading-regexp org-complex-heading-regexp
5229 'mouse-face 'highlight
5230 'help-echo
5231 (format "mouse-2 or RET jump to org file %s"
5232 (abbreviate-file-name buffer-file-name))))
5233 (regexp (format org-heading-keyword-regexp-format
5234 (cond
5235 ((and org-select-this-todo-keyword
5236 (equal org-select-this-todo-keyword "*"))
5237 org-todo-regexp)
5238 (org-select-this-todo-keyword
5239 (concat "\\("
5240 (mapconcat 'identity
5241 (org-split-string
5242 org-select-this-todo-keyword
5243 "|")
5244 "\\|") "\\)"))
5245 (t org-not-done-regexp))))
5246 marker priority category category-pos level tags todo-state ts-date ts-date-type
5247 ee txt beg end inherited-tags)
5248 (goto-char (point-min))
5249 (while (re-search-forward regexp nil t)
5250 (catch :skip
5251 (save-match-data
5252 (beginning-of-line)
5253 (org-agenda-skip)
5254 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5255 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5256 (goto-char (1+ beg))
5257 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5258 (throw :skip nil)))
5259 (goto-char (match-beginning 2))
5260 (setq marker (org-agenda-new-marker (match-beginning 0))
5261 category (org-get-category)
5262 ts-date (let (ts)
5263 (save-match-data
5264 (cond ((org-em 'scheduled-up 'scheduled-down
5265 org-agenda-sorting-strategy-selected)
5266 (setq ts (org-entry-get (point) "SCHEDULED")
5267 ts-date-type " scheduled"))
5268 ((org-em 'deadline-up 'deadline-down
5269 org-agenda-sorting-strategy-selected)
5270 (setq ts (org-entry-get (point) "DEADLINE")
5271 ts-date-type " deadline"))
5272 ((org-em 'ts-up 'ts-down
5273 org-agenda-sorting-strategy-selected)
5274 (setq ts (org-entry-get (point) "TIMESTAMP")
5275 ts-date-type " timestamp"))
5276 ((org-em 'tsia-up 'tsia-down
5277 org-agenda-sorting-strategy-selected)
5278 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5279 ts-date-type " timestamp_ia"))
5280 ((org-em 'timestamp-up 'timestamp-down
5281 org-agenda-sorting-strategy-selected)
5282 (setq ts (or (org-entry-get (point) "SCHEDULED")
5283 (org-entry-get (point) "DEADLINE")
5284 (org-entry-get (point) "TIMESTAMP")
5285 (org-entry-get (point) "TIMESTAMP_IA"))
5286 ts-date-type ""))
5287 (t (setq ts-date-type "")))
5288 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5289 category-pos (get-text-property (point) 'org-category-position)
5290 txt (org-trim
5291 (buffer-substring (match-beginning 2) (match-end 0)))
5292 inherited-tags
5293 (or (eq org-agenda-show-inherited-tags 'always)
5294 (and (listp org-agenda-show-inherited-tags)
5295 (memq 'todo org-agenda-show-inherited-tags))
5296 (and (eq org-agenda-show-inherited-tags t)
5297 (or (eq org-agenda-use-tag-inheritance t)
5298 (memq 'todo org-agenda-use-tag-inheritance))))
5299 tags (org-get-tags-at nil (not inherited-tags))
5300 level (make-string (org-reduced-level (org-outline-level)) ? )
5301 txt (org-agenda-format-item "" txt level category tags t)
5302 priority (1+ (org-get-priority txt))
5303 todo-state (org-get-todo-state))
5304 (org-add-props txt props
5305 'org-marker marker 'org-hd-marker marker
5306 'priority priority 'org-category category
5307 'level level
5308 'ts-date ts-date
5309 'org-category-position category-pos
5310 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5311 (push txt ee)
5312 (if org-agenda-todo-list-sublevels
5313 (goto-char (match-end 2))
5314 (org-end-of-subtree 'invisible))))
5315 (nreverse ee)))
5317 (defun org-agenda-todo-custom-ignore-p (time n)
5318 "Check whether timestamp is farther away than n number of days.
5319 This function is invoked if `org-agenda-todo-ignore-deadlines',
5320 `org-agenda-todo-ignore-scheduled' or
5321 `org-agenda-todo-ignore-timestamp' is set to an integer."
5322 (let ((days (org-time-stamp-to-now
5323 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5324 (if (>= n 0)
5325 (>= days n)
5326 (<= days n))))
5328 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5329 (&optional end)
5330 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5331 (when (or org-agenda-todo-ignore-with-date
5332 org-agenda-todo-ignore-scheduled
5333 org-agenda-todo-ignore-deadlines
5334 org-agenda-todo-ignore-timestamp)
5335 (setq end (or end (save-excursion (outline-next-heading) (point))))
5336 (save-excursion
5337 (or (and org-agenda-todo-ignore-with-date
5338 (re-search-forward org-ts-regexp end t))
5339 (and org-agenda-todo-ignore-scheduled
5340 (re-search-forward org-scheduled-time-regexp end t)
5341 (cond
5342 ((eq org-agenda-todo-ignore-scheduled 'future)
5343 (> (org-time-stamp-to-now
5344 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5345 ((eq org-agenda-todo-ignore-scheduled 'past)
5346 (<= (org-time-stamp-to-now
5347 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5348 ((numberp org-agenda-todo-ignore-scheduled)
5349 (org-agenda-todo-custom-ignore-p
5350 (match-string 1) org-agenda-todo-ignore-scheduled))
5351 (t)))
5352 (and org-agenda-todo-ignore-deadlines
5353 (re-search-forward org-deadline-time-regexp end t)
5354 (cond
5355 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5356 ((eq org-agenda-todo-ignore-deadlines 'far)
5357 (not (org-deadline-close (match-string 1))))
5358 ((eq org-agenda-todo-ignore-deadlines 'future)
5359 (> (org-time-stamp-to-now
5360 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5361 ((eq org-agenda-todo-ignore-deadlines 'past)
5362 (<= (org-time-stamp-to-now
5363 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5364 ((numberp org-agenda-todo-ignore-deadlines)
5365 (org-agenda-todo-custom-ignore-p
5366 (match-string 1) org-agenda-todo-ignore-deadlines))
5367 (t (org-deadline-close (match-string 1)))))
5368 (and org-agenda-todo-ignore-timestamp
5369 (let ((buffer (current-buffer))
5370 (regexp
5371 (concat
5372 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5373 (start (point)))
5374 ;; Copy current buffer into a temporary one
5375 (with-temp-buffer
5376 (insert-buffer-substring buffer start end)
5377 (goto-char (point-min))
5378 ;; Delete SCHEDULED and DEADLINE items
5379 (while (re-search-forward regexp end t)
5380 (delete-region (match-beginning 0) (match-end 0)))
5381 (goto-char (point-min))
5382 ;; No search for timestamp left
5383 (when (re-search-forward org-ts-regexp nil t)
5384 (cond
5385 ((eq org-agenda-todo-ignore-timestamp 'future)
5386 (> (org-time-stamp-to-now
5387 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5388 ((eq org-agenda-todo-ignore-timestamp 'past)
5389 (<= (org-time-stamp-to-now
5390 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5391 ((numberp org-agenda-todo-ignore-timestamp)
5392 (org-agenda-todo-custom-ignore-p
5393 (match-string 1) org-agenda-todo-ignore-timestamp))
5394 (t))))))))))
5396 (defun org-agenda-get-timestamps (&optional deadline-results)
5397 "Return the date stamp information for agenda display."
5398 (let* ((props (list 'face 'org-agenda-calendar-event
5399 'org-not-done-regexp org-not-done-regexp
5400 'org-todo-regexp org-todo-regexp
5401 'org-complex-heading-regexp org-complex-heading-regexp
5402 'mouse-face 'highlight
5403 'help-echo
5404 (format "mouse-2 or RET jump to org file %s"
5405 (abbreviate-file-name buffer-file-name))))
5406 (d1 (calendar-absolute-from-gregorian date))
5408 (deadline-position-alist
5409 (mapcar (lambda (a) (and (setq mm (get-text-property
5410 0 'org-hd-marker a))
5411 (cons (marker-position mm) a)))
5412 deadline-results))
5413 (remove-re org-ts-regexp)
5414 (regexp
5415 (concat
5416 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5417 (regexp-quote
5418 (substring
5419 (format-time-string
5420 (car org-time-stamp-formats)
5421 (apply 'encode-time ; DATE bound by calendar
5422 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5423 1 11))
5424 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5425 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5426 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5427 donep tmp priority category category-pos level ee txt timestr tags
5428 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5429 inherited-tags ts-date)
5430 (goto-char (point-min))
5431 (while (setq end-of-match (re-search-forward regexp nil t))
5432 (setq b0 (match-beginning 0)
5433 b3 (match-beginning 3) e3 (match-end 3)
5434 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5435 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5436 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5437 (member todo-state
5438 org-agenda-repeating-timestamp-show-all)))
5439 (catch :skip
5440 (and (org-at-date-range-p) (throw :skip nil))
5441 (org-agenda-skip)
5442 (if (and (match-end 1)
5443 (not (= d1 (org-time-string-to-absolute
5444 (match-string 1) d1 nil show-all
5445 (current-buffer) b0))))
5446 (throw :skip nil))
5447 (if (and e3
5448 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5449 (throw :skip nil))
5450 (setq tmp (buffer-substring (max (point-min)
5451 (- b0 org-ds-keyword-length))
5453 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5454 inactivep (= (char-after b0) ?\[)
5455 deadlinep (string-match org-deadline-regexp tmp)
5456 scheduledp (string-match org-scheduled-regexp tmp)
5457 closedp (and org-agenda-include-inactive-timestamps
5458 (string-match org-closed-string tmp))
5459 clockp (and org-agenda-include-inactive-timestamps
5460 (or (string-match org-clock-string tmp)
5461 (string-match "]-+\\'" tmp)))
5462 warntime (get-text-property (point) 'org-appt-warntime)
5463 donep (member todo-state org-done-keywords))
5464 (if (or scheduledp deadlinep closedp clockp
5465 (and donep org-agenda-skip-timestamp-if-done))
5466 (throw :skip t))
5467 (if (string-match ">" timestr)
5468 ;; substring should only run to end of time stamp
5469 (setq timestr (substring timestr 0 (match-end 0))))
5470 (setq marker (org-agenda-new-marker b0)
5471 category (org-get-category b0)
5472 category-pos (get-text-property b0 'org-category-position))
5473 (save-excursion
5474 (if (not (re-search-backward org-outline-regexp-bol nil t))
5475 (throw :skip nil)
5476 (goto-char (match-beginning 0))
5477 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5478 (assoc (point) deadline-position-alist))
5479 (throw :skip nil))
5480 (setq hdmarker (org-agenda-new-marker)
5481 inherited-tags
5482 (or (eq org-agenda-show-inherited-tags 'always)
5483 (and (listp org-agenda-show-inherited-tags)
5484 (memq 'agenda org-agenda-show-inherited-tags))
5485 (and (eq org-agenda-show-inherited-tags t)
5486 (or (eq org-agenda-use-tag-inheritance t)
5487 (memq 'agenda org-agenda-use-tag-inheritance))))
5488 tags (org-get-tags-at nil (not inherited-tags))
5489 level (make-string (org-reduced-level (org-outline-level)) ? ))
5490 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5491 (setq head (or (match-string 1) ""))
5492 (setq txt (org-agenda-format-item
5493 (if inactivep org-agenda-inactive-leader nil)
5494 head level category tags timestr
5495 remove-re habitp)))
5496 (setq priority (org-get-priority txt))
5497 (org-add-props txt props 'priority priority
5498 'org-marker marker 'org-hd-marker hdmarker
5499 'org-category category 'date date
5500 'level level
5501 'ts-date
5502 (ignore-errors (org-time-string-to-absolute timestr))
5503 'org-category-position category-pos
5504 'todo-state todo-state
5505 'warntime warntime
5506 'type "timestamp")
5507 (push txt ee))
5508 (if org-agenda-skip-additional-timestamps-same-entry
5509 (outline-next-heading)
5510 (goto-char end-of-match))))
5511 (nreverse ee)))
5513 (defun org-agenda-get-sexps ()
5514 "Return the sexp information for agenda display."
5515 (require 'diary-lib)
5516 (let* ((props (list 'face 'org-agenda-calendar-sexp
5517 'mouse-face 'highlight
5518 'help-echo
5519 (format "mouse-2 or RET jump to org file %s"
5520 (abbreviate-file-name buffer-file-name))))
5521 (regexp "^&?%%(")
5522 marker category extra category-pos level ee txt tags entry
5523 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5524 (goto-char (point-min))
5525 (while (re-search-forward regexp nil t)
5526 (catch :skip
5527 (org-agenda-skip)
5528 (setq beg (match-beginning 0))
5529 (goto-char (1- (match-end 0)))
5530 (setq b (point))
5531 (forward-sexp 1)
5532 (setq sexp (buffer-substring b (point)))
5533 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5534 (org-trim (match-string 1))
5535 ""))
5536 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5537 (when result
5538 (setq marker (org-agenda-new-marker beg)
5539 level (make-string (org-reduced-level (org-outline-level)) ? )
5540 category (org-get-category beg)
5541 category-pos (get-text-property beg 'org-category-position)
5542 inherited-tags
5543 (or (eq org-agenda-show-inherited-tags 'always)
5544 (and (listp org-agenda-show-inherited-tags)
5545 (memq 'agenda org-agenda-show-inherited-tags))
5546 (and (eq org-agenda-show-inherited-tags t)
5547 (or (eq org-agenda-use-tag-inheritance t)
5548 (memq 'agenda org-agenda-use-tag-inheritance))))
5549 tags (org-get-tags-at nil (not inherited-tags))
5550 todo-state (org-get-todo-state)
5551 warntime (get-text-property (point) 'org-appt-warntime)
5552 extra nil)
5554 (dolist (r (if (stringp result)
5555 (list result)
5556 result)) ;; we expect a list here
5557 (when (and org-agenda-diary-sexp-prefix
5558 (string-match org-agenda-diary-sexp-prefix r))
5559 (setq extra (match-string 0 r)
5560 r (replace-match "" nil nil r)))
5561 (if (string-match "\\S-" r)
5562 (setq txt r)
5563 (setq txt "SEXP entry returned empty string"))
5564 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5565 (org-add-props txt props 'org-marker marker
5566 'org-category category 'date date 'todo-state todo-state
5567 'org-category-position category-pos 'tags tags
5568 'level level
5569 'type "sexp" 'warntime warntime)
5570 (push txt ee)))))
5571 (nreverse ee)))
5573 ;; Calendar sanity: define some functions that are independent of
5574 ;; `calendar-date-style'.
5575 ;; Normally I would like to use ISO format when calling the diary functions,
5576 ;; but to make sure we still have Emacs 22 compatibility we bind
5577 ;; also `european-calendar-style' and use european format
5578 (defun org-anniversary (year month day &optional mark)
5579 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5580 (org-no-warnings
5581 (let ((calendar-date-style 'european) (european-calendar-style t))
5582 (diary-anniversary day month year mark))))
5583 (defun org-cyclic (N year month day &optional mark)
5584 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5585 (org-no-warnings
5586 (let ((calendar-date-style 'european) (european-calendar-style t))
5587 (diary-cyclic N day month year mark))))
5588 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5589 "Like `diary-block', but with fixed (ISO) order of arguments."
5590 (org-no-warnings
5591 (let ((calendar-date-style 'european) (european-calendar-style t))
5592 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5593 (defun org-date (year month day &optional mark)
5594 "Like `diary-date', but with fixed (ISO) order of arguments."
5595 (org-no-warnings
5596 (let ((calendar-date-style 'european) (european-calendar-style t))
5597 (diary-date day month year mark))))
5599 ;; Define the` org-class' function
5600 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5601 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5602 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5603 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5604 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5605 `holidays', then any date that is known by the Emacs calendar to be a
5606 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5607 then those holidays will be skipped."
5608 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5609 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5610 (d (calendar-absolute-from-gregorian date))
5611 (h (when skip-weeks (calendar-check-holidays date))))
5612 (and
5613 (<= date1 d)
5614 (<= d date2)
5615 (= (calendar-day-of-week date) dayname)
5616 (or (not skip-weeks)
5617 (progn
5618 (require 'cal-iso)
5619 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5620 (not (or (and h (memq 'holidays skip-weeks))
5621 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5622 entry)))
5624 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5625 "Like `org-class', but honor `calendar-date-style'.
5626 The order of the first 2 times 3 arguments depends on the variable
5627 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5628 So for American calendars, give this as MONTH DAY YEAR, for European as
5629 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5630 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5631 is any number of ISO weeks in the block period for which the item should
5632 be skipped.
5634 This function is here only for backward compatibility and it is deprecated,
5635 please use `org-class' instead."
5636 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5637 (date2 (org-order-calendar-date-args m2 d2 y2)))
5638 (org-class
5639 (nth 2 date1) (car date1) (nth 1 date1)
5640 (nth 2 date2) (car date2) (nth 1 date2)
5641 dayname skip-weeks)))
5642 (make-obsolete 'org-diary-class 'org-class "")
5644 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5645 (defalias 'org-get-closed 'org-agenda-get-progress)
5646 (defun org-agenda-get-progress ()
5647 "Return the logged TODO entries for agenda display."
5648 (let* ((props (list 'mouse-face 'highlight
5649 'org-not-done-regexp org-not-done-regexp
5650 'org-todo-regexp org-todo-regexp
5651 'org-complex-heading-regexp org-complex-heading-regexp
5652 'help-echo
5653 (format "mouse-2 or RET jump to org file %s"
5654 (abbreviate-file-name buffer-file-name))))
5655 (items (if (consp org-agenda-show-log-scoped)
5656 org-agenda-show-log-scoped
5657 (if (eq org-agenda-show-log-scoped 'clockcheck)
5658 '(clock)
5659 org-agenda-log-mode-items)))
5660 (parts
5661 (delq nil
5662 (list
5663 (if (memq 'closed items) (concat "\\<" org-closed-string))
5664 (if (memq 'clock items) (concat "\\<" org-clock-string))
5665 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5666 (parts-re (if parts (mapconcat 'identity parts "\\|")
5667 (error "`org-agenda-log-mode-items' is empty")))
5668 (regexp (concat
5669 "\\(" parts-re "\\)"
5670 " *\\["
5671 (regexp-quote
5672 (substring
5673 (format-time-string
5674 (car org-time-stamp-formats)
5675 (apply 'encode-time ; DATE bound by calendar
5676 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5677 1 11))))
5678 (org-agenda-search-headline-for-time nil)
5679 marker hdmarker priority category category-pos level tags closedp
5680 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5681 (goto-char (point-min))
5682 (while (re-search-forward regexp nil t)
5683 (catch :skip
5684 (org-agenda-skip)
5685 (setq marker (org-agenda-new-marker (match-beginning 0))
5686 closedp (equal (match-string 1) org-closed-string)
5687 statep (equal (string-to-char (match-string 1)) ?-)
5688 clockp (not (or closedp statep))
5689 state (and statep (match-string 2))
5690 category (org-get-category (match-beginning 0))
5691 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5692 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5693 (when (string-match "\\]" timestr)
5694 ;; substring should only run to end of time stamp
5695 (setq rest (substring timestr (match-end 0))
5696 timestr (substring timestr 0 (match-end 0)))
5697 (if (and (not closedp) (not statep)
5698 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5699 rest))
5700 (progn (setq timestr (concat (substring timestr 0 -1)
5701 "-" (match-string 1 rest) "]"))
5702 (setq clocked (match-string 2 rest)))
5703 (setq clocked "-")))
5704 (save-excursion
5705 (setq extra
5706 (cond
5707 ((not org-agenda-log-mode-add-notes) nil)
5708 (statep
5709 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5710 (match-string 1)))
5711 (clockp
5712 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5713 (match-string 1)))))
5714 (if (not (re-search-backward org-outline-regexp-bol nil t))
5715 (throw :skip nil)
5716 (goto-char (match-beginning 0))
5717 (setq hdmarker (org-agenda-new-marker)
5718 inherited-tags
5719 (or (eq org-agenda-show-inherited-tags 'always)
5720 (and (listp org-agenda-show-inherited-tags)
5721 (memq 'todo org-agenda-show-inherited-tags))
5722 (and (eq org-agenda-show-inherited-tags t)
5723 (or (eq org-agenda-use-tag-inheritance t)
5724 (memq 'todo org-agenda-use-tag-inheritance))))
5725 tags (org-get-tags-at nil (not inherited-tags))
5726 level (make-string (org-reduced-level (org-outline-level)) ? ))
5727 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5728 (setq txt (match-string 1))
5729 (when extra
5730 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5731 (setq txt (concat (substring txt 0 (match-beginning 1))
5732 " - " extra " " (match-string 2 txt)))
5733 (setq txt (concat txt " - " extra))))
5734 (setq txt (org-agenda-format-item
5735 (cond
5736 (closedp "Closed: ")
5737 (statep (concat "State: (" state ")"))
5738 (t (concat "Clocked: (" clocked ")")))
5739 txt level category tags timestr)))
5740 (setq priority 100000)
5741 (org-add-props txt props
5742 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5743 'priority priority 'org-category category
5744 'org-category-position category-pos
5745 'level level
5746 'type "closed" 'date date
5747 'undone-face 'org-warning 'done-face 'org-agenda-done)
5748 (push txt ee))
5749 (goto-char (point-at-eol))))
5750 (nreverse ee)))
5752 (defun org-agenda-show-clocking-issues ()
5753 "Add overlays, showing issues with clocking.
5754 See also the user option `org-agenda-clock-consistency-checks'."
5755 (interactive)
5756 (let* ((org-time-clocksum-use-effort-durations nil)
5757 (pl org-agenda-clock-consistency-checks)
5758 (re (concat "^[ \t]*"
5759 org-clock-string
5760 "[ \t]+"
5761 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5762 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5763 (tlstart 0.)
5764 (tlend 0.)
5765 (maxtime (org-hh:mm-string-to-minutes
5766 (or (plist-get pl :max-duration) "24:00")))
5767 (mintime (org-hh:mm-string-to-minutes
5768 (or (plist-get pl :min-duration) 0)))
5769 (maxgap (org-hh:mm-string-to-minutes
5770 ;; default 30:00 means never complain
5771 (or (plist-get pl :max-gap) "30:00")))
5772 (gapok (mapcar 'org-hh:mm-string-to-minutes
5773 (plist-get pl :gap-ok-around)))
5774 (def-face (or (plist-get pl :default-face)
5775 '((:background "DarkRed") (:foreground "white"))))
5776 issue face m te ts dt ov)
5777 (goto-char (point-min))
5778 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5779 (setq issue nil face def-face)
5780 (catch 'next
5781 (setq m (org-get-at-bol 'org-marker)
5782 te nil ts nil)
5783 (unless (and m (markerp m))
5784 (setq issue "No valid clock line") (throw 'next t))
5785 (org-with-point-at m
5786 (save-excursion
5787 (goto-char (point-at-bol))
5788 (unless (looking-at re)
5789 (error "No valid Clock line")
5790 (throw 'next t))
5791 (unless (match-end 3)
5792 (setq issue "No end time"
5793 face (or (plist-get pl :no-end-time-face) face))
5794 (throw 'next t))
5795 (setq ts (match-string 1)
5796 te (match-string 3)
5797 ts (org-float-time
5798 (apply 'encode-time (org-parse-time-string ts)))
5799 te (org-float-time
5800 (apply 'encode-time (org-parse-time-string te)))
5801 dt (- te ts))))
5802 (cond
5803 ((> dt (* 60 maxtime))
5804 ;; a very long clocking chunk
5805 (setq issue (format "Clocking interval is very long: %s"
5806 (org-minutes-to-clocksum-string
5807 (floor (/ (float dt) 60.))))
5808 face (or (plist-get pl :long-face) face)))
5809 ((< dt (* 60 mintime))
5810 ;; a very short clocking chunk
5811 (setq issue (format "Clocking interval is very short: %s"
5812 (org-minutes-to-clocksum-string
5813 (floor (/ (float dt) 60.))))
5814 face (or (plist-get pl :short-face) face)))
5815 ((and (> tlend 0) (< ts tlend))
5816 ;; Two clock entries are overlapping
5817 (setq issue (format "Clocking overlap: %d minutes"
5818 (/ (- tlend ts) 60))
5819 face (or (plist-get pl :overlap-face) face)))
5820 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5821 ;; There is a gap, lets see if we need to report it
5822 (unless (org-agenda-check-clock-gap tlend ts gapok)
5823 (setq issue (format "Clocking gap: %d minutes"
5824 (/ (- ts tlend) 60))
5825 face (or (plist-get pl :gap-face) face))))
5826 (t nil)))
5827 (setq tlend (or te tlend) tlstart (or ts tlstart))
5828 (when issue
5829 ;; OK, there was some issue, add an overlay to show the issue
5830 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5831 (overlay-put ov 'before-string
5832 (concat
5833 (org-add-props
5834 (format "%-43s" (concat " " issue))
5836 'face face)
5837 "\n"))
5838 (overlay-put ov 'evaporate t)))))
5840 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5841 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5842 (catch 'exit
5843 (unless ok-list
5844 ;; there are no OK times for gaps...
5845 (throw 'exit nil))
5846 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5847 ;; This is more than 24 hours, so it is OK.
5848 ;; because we have at least one OK time, that must be in the
5849 ;; 24 hour interval.
5850 (throw 'exit t))
5851 ;; We have a shorter gap.
5852 ;; Now we have to get the minute of the day when these times are
5853 (let* ((t1dec (decode-time (seconds-to-time t1)))
5854 (t2dec (decode-time (seconds-to-time t2)))
5855 ;; compute the minute on the day
5856 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5857 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5858 (when (< min2 min1)
5859 ;; if min2 is smaller than min1, this means it is on the next day.
5860 ;; Wrap it to after midnight.
5861 (setq min2 (+ min2 1440)))
5862 ;; Now check if any of the OK times is in the gap
5863 (mapc (lambda (x)
5864 ;; Wrap the time to after midnight if necessary
5865 (if (< x min1) (setq x (+ x 1440)))
5866 ;; Check if in interval
5867 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5868 ok-list)
5869 ;; Nope, this gap is not OK
5870 nil)))
5872 (defun org-agenda-get-deadlines ()
5873 "Return the deadline information for agenda display."
5874 (let* ((props (list 'mouse-face 'highlight
5875 'org-not-done-regexp org-not-done-regexp
5876 'org-todo-regexp org-todo-regexp
5877 'org-complex-heading-regexp org-complex-heading-regexp
5878 'help-echo
5879 (format "mouse-2 or RET jump to org file %s"
5880 (abbreviate-file-name buffer-file-name))))
5881 (regexp org-deadline-time-regexp)
5882 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5883 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5884 (dl0 (car org-agenda-deadline-leaders))
5885 (dl1 (nth 1 org-agenda-deadline-leaders))
5886 (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
5887 d2 diff dfrac wdays pos pos1 category category-pos level
5888 tags suppress-prewarning ee txt head face s todo-state
5889 show-all upcomingp donep timestr warntime inherited-tags ts-date)
5890 (goto-char (point-min))
5891 (while (re-search-forward regexp nil t)
5892 (catch :skip
5893 (org-agenda-skip)
5894 (setq s (match-string 1)
5895 txt nil
5896 pos (1- (match-beginning 1))
5897 todo-state (save-match-data (org-get-todo-state))
5898 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5899 (member todo-state
5900 org-agenda-repeating-timestamp-show-all))
5901 d2 (org-time-string-to-absolute
5902 s d1 'past show-all (current-buffer) pos)
5903 diff (- d2 d1))
5904 (setq suppress-prewarning
5905 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5906 (let ((item (buffer-substring (point-at-bol)
5907 (point-at-eol))))
5908 (save-match-data
5909 (and (string-match
5910 org-scheduled-time-regexp item)
5911 (match-string 1 item)))))))
5912 (cond
5913 ((not ds) nil)
5914 ;; The current item has a scheduled date (in ds), so
5915 ;; evaluate its prewarning lead time.
5916 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5917 ;; Use global prewarning-restart lead time.
5918 org-agenda-skip-deadline-prewarning-if-scheduled)
5919 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5920 'pre-scheduled)
5921 ;; Set prewarning to no earlier than scheduled.
5922 (min (- d2 (org-time-string-to-absolute
5923 ds d1 'past show-all (current-buffer) pos))
5924 org-deadline-warning-days))
5925 ;; Set prewarning to deadline.
5926 (t 0))))
5927 (setq wdays (if suppress-prewarning
5928 (let ((org-deadline-warning-days suppress-prewarning))
5929 (org-get-wdays s))
5930 (org-get-wdays s))
5931 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5932 upcomingp (and todayp (> diff 0)))
5933 ;; When to show a deadline in the calendar:
5934 ;; If the expiration is within wdays warning time.
5935 ;; Past-due deadlines are only shown on the current date
5936 (if (and (or (and (<= diff wdays)
5937 (and todayp (not org-agenda-only-exact-dates)))
5938 (= diff 0)))
5939 (save-excursion
5940 ;; (setq todo-state (org-get-todo-state))
5941 (setq donep (member todo-state org-done-keywords))
5942 (if (and donep
5943 (or org-agenda-skip-deadline-if-done
5944 (not (= diff 0))))
5945 (setq txt nil)
5946 (setq category (org-get-category)
5947 warntime (get-text-property (point) 'org-appt-warntime)
5948 category-pos (get-text-property (point) 'org-category-position))
5949 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5950 (throw :skip nil)
5951 (goto-char (match-end 0))
5952 (setq pos1 (match-beginning 0))
5953 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5954 (setq inherited-tags
5955 (or (eq org-agenda-show-inherited-tags 'always)
5956 (and (listp org-agenda-show-inherited-tags)
5957 (memq 'agenda org-agenda-show-inherited-tags))
5958 (and (eq org-agenda-show-inherited-tags t)
5959 (or (eq org-agenda-use-tag-inheritance t)
5960 (memq 'agenda org-agenda-use-tag-inheritance))))
5961 tags (org-get-tags-at pos1 (not inherited-tags)))
5962 (setq head (buffer-substring
5963 (point)
5964 (progn (skip-chars-forward "^\r\n")
5965 (point))))
5966 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5967 (setq timestr
5968 (concat (substring s (match-beginning 1)) " "))
5969 (setq timestr 'time))
5970 (setq txt (org-agenda-format-item
5971 (cond ((= diff 0) dl0)
5972 ((> diff 0)
5973 (if (functionp dl1)
5974 (funcall dl1 diff date)
5975 (format dl1 diff)))
5977 (if (functionp dl2)
5978 (funcall dl2 diff date)
5979 (format dl2 (if (string= dl2 dl1)
5980 diff (abs diff))))))
5981 head level category tags
5982 (if (not (= diff 0)) nil timestr)))))
5983 (when txt
5984 (setq face (org-agenda-deadline-face dfrac))
5985 (org-add-props txt props
5986 'org-marker (org-agenda-new-marker pos)
5987 'warntime warntime
5988 'level level
5989 'ts-date d2
5990 'org-hd-marker (org-agenda-new-marker pos1)
5991 'priority (+ (- diff)
5992 (org-get-priority txt))
5993 'org-category category
5994 'org-category-position category-pos
5995 'todo-state todo-state
5996 'type (if upcomingp "upcoming-deadline" "deadline")
5997 'date (if upcomingp date d2)
5998 'face (if donep 'org-agenda-done face)
5999 'undone-face face 'done-face 'org-agenda-done)
6000 (push txt ee))))))
6001 (nreverse ee)))
6003 (defun org-agenda-deadline-face (fraction)
6004 "Return the face to displaying a deadline item.
6005 FRACTION is what fraction of the head-warning time has passed."
6006 (let ((faces org-agenda-deadline-faces) f)
6007 (catch 'exit
6008 (while (setq f (pop faces))
6009 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6011 (defun org-agenda-get-scheduled (&optional deadline-results)
6012 "Return the scheduled information for agenda display."
6013 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6014 'org-todo-regexp org-todo-regexp
6015 'org-complex-heading-regexp org-complex-heading-regexp
6016 'done-face 'org-agenda-done
6017 'mouse-face 'highlight
6018 'help-echo
6019 (format "mouse-2 or RET jump to org file %s"
6020 (abbreviate-file-name buffer-file-name))))
6021 (regexp org-scheduled-time-regexp)
6022 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6023 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6025 (deadline-position-alist
6026 (mapcar (lambda (a) (and (setq mm (get-text-property
6027 0 'org-hd-marker a))
6028 (cons (marker-position mm) a)))
6029 deadline-results))
6030 d2 diff pos pos1 category category-pos level tags donep
6031 ee txt head pastschedp todo-state face timestr s habitp show-all
6032 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6033 ddays)
6034 (goto-char (point-min))
6035 (while (re-search-forward regexp nil t)
6036 (catch :skip
6037 (org-agenda-skip)
6038 (setq s (match-string 1)
6039 txt nil
6040 pos (1- (match-beginning 1))
6041 todo-state (save-match-data (org-get-todo-state))
6042 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6043 (member todo-state
6044 org-agenda-repeating-timestamp-show-all))
6045 d2 (org-time-string-to-absolute
6046 s d1 'past show-all (current-buffer) pos)
6047 diff (- d2 d1)
6048 warntime (get-text-property (point) 'org-appt-warntime))
6049 (setq pastschedp (and todayp (< diff 0)))
6050 (setq did-habit-check-p nil)
6051 (setq suppress-delay
6052 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6053 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6054 (save-match-data
6055 (and (string-match
6056 org-deadline-time-regexp item)
6057 (match-string 1 item)))))))
6058 (cond
6059 ((not ds) nil)
6060 ;; The current item has a deadline date (in ds), so
6061 ;; evaluate its delay time.
6062 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6063 ;; Use global delay time.
6064 (- org-agenda-skip-scheduled-delay-if-deadline))
6065 ((eq org-agenda-skip-scheduled-delay-if-deadline
6066 'post-deadline)
6067 ;; Set delay to no later than deadline.
6068 (min (- d2 (org-time-string-to-absolute
6069 ds d1 'past show-all (current-buffer) pos))
6070 org-scheduled-delay-days))
6071 (t 0))))
6072 (setq ddays (if suppress-delay
6073 (let ((org-scheduled-delay-days suppress-delay))
6074 (org-get-wdays s t t))
6075 (org-get-wdays s t)))
6076 ;; Use a delay of 0 when there is a repeater and the delay is
6077 ;; of the form --3d
6078 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6079 (< (org-time-string-to-absolute s)
6080 (org-time-string-to-absolute
6081 s d2 'past nil (current-buffer) pos)))
6082 (setq ddays 0))
6083 ;; When to show a scheduled item in the calendar:
6084 ;; If it is on or past the date.
6085 (when (or (and (> ddays 0) (= diff (- ddays)))
6086 (and (zerop ddays) (= diff 0))
6087 (and (< (+ diff ddays) 0)
6088 (< (abs diff) org-scheduled-past-days)
6089 (and todayp (not org-agenda-only-exact-dates)))
6090 ;; org-is-habit-p uses org-entry-get, which is expansive
6091 ;; so we go extra mile to only call it once
6092 (and todayp
6093 (boundp 'org-habit-show-all-today)
6094 org-habit-show-all-today
6095 (setq did-habit-check-p t)
6096 (setq habitp (and (functionp 'org-is-habit-p)
6097 (org-is-habit-p)))))
6098 (save-excursion
6099 (setq donep (member todo-state org-done-keywords))
6100 (if (and donep
6101 (or org-agenda-skip-scheduled-if-done
6102 (not (= diff 0))
6103 (and (functionp 'org-is-habit-p)
6104 (org-is-habit-p))))
6105 (setq txt nil)
6106 (setq habitp (if did-habit-check-p habitp
6107 (and (functionp 'org-is-habit-p)
6108 (org-is-habit-p))))
6109 (setq category (org-get-category)
6110 category-pos (get-text-property (point) 'org-category-position))
6111 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6112 (throw :skip nil)
6113 (goto-char (match-end 0))
6114 (setq pos1 (match-beginning 0))
6115 (if habitp
6116 (if (or (not org-habit-show-habits)
6117 (and (not todayp)
6118 (boundp 'org-habit-show-habits-only-for-today)
6119 org-habit-show-habits-only-for-today))
6120 (throw :skip nil))
6121 (if (and
6122 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6123 (and org-agenda-skip-scheduled-if-deadline-is-shown
6124 pastschedp))
6125 (setq mm (assoc pos1 deadline-position-alist)))
6126 (throw :skip nil)))
6127 (setq inherited-tags
6128 (or (eq org-agenda-show-inherited-tags 'always)
6129 (and (listp org-agenda-show-inherited-tags)
6130 (memq 'agenda org-agenda-show-inherited-tags))
6131 (and (eq org-agenda-show-inherited-tags t)
6132 (or (eq org-agenda-use-tag-inheritance t)
6133 (memq 'agenda org-agenda-use-tag-inheritance))))
6135 tags (org-get-tags-at nil (not inherited-tags)))
6136 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6137 (setq head (buffer-substring
6138 (point)
6139 (progn (skip-chars-forward "^\r\n") (point))))
6140 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6141 (setq timestr
6142 (concat (substring s (match-beginning 1)) " "))
6143 (setq timestr 'time))
6144 (setq txt (org-agenda-format-item
6145 (if (= diff 0)
6146 (car org-agenda-scheduled-leaders)
6147 (format (nth 1 org-agenda-scheduled-leaders)
6148 (- 1 diff)))
6149 head level category tags
6150 (if (not (= diff 0)) nil timestr)
6151 nil habitp))))
6152 (when txt
6153 (setq face
6154 (cond
6155 ((and (not habitp) pastschedp)
6156 'org-scheduled-previously)
6157 (todayp 'org-scheduled-today)
6158 (t 'org-scheduled))
6159 habitp (and habitp (org-habit-parse-todo)))
6160 (org-add-props txt props
6161 'undone-face face
6162 'face (if donep 'org-agenda-done face)
6163 'org-marker (org-agenda-new-marker pos)
6164 'org-hd-marker (org-agenda-new-marker pos1)
6165 'type (if pastschedp "past-scheduled" "scheduled")
6166 'date (if pastschedp d2 date)
6167 'ts-date d2
6168 'warntime warntime
6169 'level level
6170 'priority (if habitp
6171 (org-habit-get-priority habitp)
6172 (+ 94 (- 5 diff) (org-get-priority txt)))
6173 'org-category category
6174 'category-position category-pos
6175 'org-habit-p habitp
6176 'todo-state todo-state)
6177 (push txt ee))))))
6178 (nreverse ee)))
6180 (defun org-agenda-get-blocks ()
6181 "Return the date-range information for agenda display."
6182 (let* ((props (list 'face nil
6183 'org-not-done-regexp org-not-done-regexp
6184 'org-todo-regexp org-todo-regexp
6185 'org-complex-heading-regexp org-complex-heading-regexp
6186 'mouse-face 'highlight
6187 'help-echo
6188 (format "mouse-2 or RET jump to org file %s"
6189 (abbreviate-file-name buffer-file-name))))
6190 (regexp org-tr-regexp)
6191 (d0 (calendar-absolute-from-gregorian date))
6192 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6193 level todo-state tags pos head donep inherited-tags)
6194 (goto-char (point-min))
6195 (while (re-search-forward regexp nil t)
6196 (catch :skip
6197 (org-agenda-skip)
6198 (setq pos (point))
6199 (let ((start-time (match-string 1))
6200 (end-time (match-string 2)))
6201 (setq s1 (match-string 1)
6202 s2 (match-string 2)
6203 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6204 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6205 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6206 ;; Only allow days between the limits, because the normal
6207 ;; date stamps will catch the limits.
6208 (save-excursion
6209 (setq todo-state (org-get-todo-state))
6210 (setq donep (member todo-state org-done-keywords))
6211 (if (and donep org-agenda-skip-timestamp-if-done)
6212 (throw :skip t))
6213 (setq marker (org-agenda-new-marker (point)))
6214 (setq category (org-get-category)
6215 category-pos (get-text-property (point) 'org-category-position))
6216 (if (not (re-search-backward org-outline-regexp-bol nil t))
6217 (throw :skip nil)
6218 (goto-char (match-beginning 0))
6219 (setq hdmarker (org-agenda-new-marker (point))
6220 inherited-tags
6221 (or (eq org-agenda-show-inherited-tags 'always)
6222 (and (listp org-agenda-show-inherited-tags)
6223 (memq 'agenda org-agenda-show-inherited-tags))
6224 (and (eq org-agenda-show-inherited-tags t)
6225 (or (eq org-agenda-use-tag-inheritance t)
6226 (memq 'agenda org-agenda-use-tag-inheritance))))
6228 tags (org-get-tags-at nil (not inherited-tags)))
6229 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6230 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6231 (setq head (match-string 1))
6232 (let ((remove-re
6233 (if org-agenda-remove-timeranges-from-blocks
6234 (concat
6235 "<" (regexp-quote s1) ".*?>"
6236 "--"
6237 "<" (regexp-quote s2) ".*?>")
6238 nil)))
6239 (setq txt (org-agenda-format-item
6240 (format
6241 (nth (if (= d1 d2) 0 1)
6242 org-agenda-timerange-leaders)
6243 (1+ (- d0 d1)) (1+ (- d2 d1)))
6244 head level category tags
6245 (cond ((and (= d1 d0) (= d2 d0))
6246 (concat "<" start-time ">--<" end-time ">"))
6247 ((= d1 d0)
6248 (concat "<" start-time ">"))
6249 ((= d2 d0)
6250 (concat "<" end-time ">")))
6251 remove-re))))
6252 (org-add-props txt props
6253 'org-marker marker 'org-hd-marker hdmarker
6254 'type "block" 'date date
6255 'level level
6256 'todo-state todo-state
6257 'priority (org-get-priority txt) 'org-category category
6258 'org-category-position category-pos)
6259 (push txt ee))))
6260 (goto-char pos)))
6261 ;; Sort the entries by expiration date.
6262 (nreverse ee)))
6264 ;;; Agenda presentation and sorting
6266 (defvar org-prefix-has-time nil
6267 "A flag, set by `org-compile-prefix-format'.
6268 The flag is set if the currently compiled format contains a `%t'.")
6269 (defvar org-prefix-has-tag nil
6270 "A flag, set by `org-compile-prefix-format'.
6271 The flag is set if the currently compiled format contains a `%T'.")
6272 (defvar org-prefix-has-effort nil
6273 "A flag, set by `org-compile-prefix-format'.
6274 The flag is set if the currently compiled format contains a `%e'.")
6275 (defvar org-prefix-has-breadcrumbs nil
6276 "A flag, set by `org-compile-prefix-format'.
6277 The flag is set if the currently compiled format contains a `%b'.")
6278 (defvar org-prefix-category-length nil
6279 "Used by `org-compile-prefix-format' to remember the category field width.")
6280 (defvar org-prefix-category-max-length nil
6281 "Used by `org-compile-prefix-format' to remember the category field width.")
6283 (defun org-agenda-get-category-icon (category)
6284 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6285 (dolist (entry org-agenda-category-icon-alist)
6286 (when (org-string-match-p (car entry) category)
6287 (if (listp (cadr entry))
6288 (return (cadr entry))
6289 (return (apply 'create-image (cdr entry)))))))
6291 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6292 remove-re habitp)
6293 "Format TXT to be inserted into the agenda buffer.
6294 In particular, add the prefix and corresponding text properties.
6296 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6297 LEVEL may be a string to replace the `%l' specifier.
6298 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6299 category taken from local variable or file name. It will replace the `%c'
6300 specifier in the format.
6301 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6302 TXT for sorting of this entry, and for the `%t' specifier in the format.
6303 When DOTIME is a string, this string is searched for a time before TXT is.
6304 TAGS can be the tags of the headline.
6305 Any match of REMOVE-RE will be removed from TXT."
6306 ;; We keep the org-prefix-* variable values along with a compiled
6307 ;; formatter, so that multiple agendas existing at the same time do
6308 ;; not step on each other toes.
6310 ;; It was inconvenient to make these variables buffer local in
6311 ;; Agenda buffers, because this function expects to be called with
6312 ;; the buffer where item comes from being current, and not agenda
6313 ;; buffer
6314 (let* ((bindings (car org-prefix-format-compiled))
6315 (formatter (cadr org-prefix-format-compiled)))
6316 (loop for (var value) in bindings
6317 do (set var value))
6318 (save-match-data
6319 ;; Diary entries sometimes have extra whitespace at the beginning
6320 (setq txt (org-trim txt))
6322 ;; Fix the tags part in txt
6323 (setq txt (org-agenda-fix-displayed-tags
6324 txt tags
6325 org-agenda-show-inherited-tags
6326 org-agenda-hide-tags-regexp))
6328 (let* ((category (or category
6329 (if (stringp org-category)
6330 org-category
6331 (and org-category (symbol-name org-category)))
6332 (if buffer-file-name
6333 (file-name-sans-extension
6334 (file-name-nondirectory buffer-file-name))
6335 "")))
6336 (category-icon (org-agenda-get-category-icon category))
6337 (category-icon (if category-icon
6338 (propertize " " 'display category-icon)
6339 ""))
6340 ;; time, tag, effort are needed for the eval of the prefix format
6341 (tag (if tags (nth (1- (length tags)) tags) ""))
6342 time effort neffort
6343 (ts (if dotime (concat
6344 (if (stringp dotime) dotime "")
6345 (and org-agenda-search-headline-for-time txt))))
6346 (time-of-day (and dotime (org-get-time-of-day ts)))
6347 stamp plain s0 s1 s2 rtn srp l
6348 duration thecategory breadcrumbs)
6349 (and (derived-mode-p 'org-mode) buffer-file-name
6350 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6351 (when (and dotime time-of-day)
6352 ;; Extract starting and ending time and move them to prefix
6353 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6354 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6355 (setq s0 (match-string 0 ts)
6356 srp (and stamp (match-end 3))
6357 s1 (match-string (if plain 1 2) ts)
6358 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6360 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6361 ;; them, we might want to remove them there to avoid duplication.
6362 ;; The user can turn this off with a variable.
6363 (if (and org-prefix-has-time
6364 org-agenda-remove-times-when-in-prefix (or stamp plain)
6365 (string-match (concat (regexp-quote s0) " *") txt)
6366 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6367 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6368 (= (match-beginning 0) 0)
6370 (setq txt (replace-match "" nil nil txt))))
6371 ;; Normalize the time(s) to 24 hour
6372 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6373 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6375 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6376 (let (org-time-clocksum-use-effort-durations)
6377 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6378 (setq s2
6379 (org-minutes-to-clocksum-string
6380 (+ (org-hh:mm-string-to-minutes s1)
6381 org-agenda-default-appointment-duration)))))
6383 ;; Compute the duration
6384 (when s2
6385 (setq duration (- (org-hh:mm-string-to-minutes s2)
6386 (org-hh:mm-string-to-minutes s1)))))
6388 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6389 txt)
6390 ;; Tags are in the string
6391 (if (or (eq org-agenda-remove-tags t)
6392 (and org-agenda-remove-tags
6393 org-prefix-has-tag))
6394 (setq txt (replace-match "" t t txt))
6395 (setq txt (replace-match
6396 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6397 (match-string 2 txt))
6398 t t txt))))
6399 (when (derived-mode-p 'org-mode)
6400 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6401 (if effort
6402 (setq neffort (org-duration-string-to-minutes effort)
6403 effort (setq effort (concat "[" effort "]")))
6404 ;; prevent erroring out with %e format when there is no effort
6405 (setq effort "")))
6407 (when remove-re
6408 (while (string-match remove-re txt)
6409 (setq txt (replace-match "" t t txt))))
6411 ;; Set org-heading property on `txt' to mark the start of the
6412 ;; heading.
6413 (add-text-properties 0 (length txt) '(org-heading t) txt)
6415 ;; Prepare the variables needed in the eval of the compiled format
6416 (if org-prefix-has-breadcrumbs
6417 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6418 (let ((s (org-display-outline-path nil nil "->" t)))
6419 (if (eq "" s) "" (concat s "->"))))))
6420 (setq time (cond (s2 (concat
6421 (org-agenda-time-of-day-to-ampm-maybe s1)
6422 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6423 (if org-agenda-timegrid-use-ampm " ")))
6424 (s1 (concat
6425 (org-agenda-time-of-day-to-ampm-maybe s1)
6426 (if org-agenda-timegrid-use-ampm
6427 "........ "
6428 "......")))
6429 (t ""))
6430 extra (or (and (not habitp) extra) "")
6431 category (if (symbolp category) (symbol-name category) category)
6432 thecategory (copy-sequence category)
6433 level (or level ""))
6434 (if (string-match org-bracket-link-regexp category)
6435 (progn
6436 (setq l (if (match-end 3)
6437 (- (match-end 3) (match-beginning 3))
6438 (- (match-end 1) (match-beginning 1))))
6439 (when (< l (or org-prefix-category-length 0))
6440 (setq category (copy-sequence category))
6441 (org-add-props category nil
6442 'extra-space (make-string
6443 (- org-prefix-category-length l 1) ?\ ))))
6444 (if (and org-prefix-category-max-length
6445 (>= (length category) org-prefix-category-max-length))
6446 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6447 ;; Evaluate the compiled format
6448 (setq rtn (concat (eval formatter) txt))
6450 ;; And finally add the text properties
6451 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6452 (org-add-props rtn nil
6453 'org-category (if thecategory (downcase thecategory) category)
6454 'tags (mapcar 'org-downcase-keep-props tags)
6455 'org-highest-priority org-highest-priority
6456 'org-lowest-priority org-lowest-priority
6457 'time-of-day time-of-day
6458 'duration duration
6459 'effort effort
6460 'effort-minutes neffort
6461 'breadcrumbs breadcrumbs
6462 'txt txt
6463 'level level
6464 'time time
6465 'extra extra
6466 'format org-prefix-format-compiled
6467 'dotime dotime)))))
6469 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6470 "Remove tags string from TXT, and add a modified list of tags.
6471 The modified list may contain inherited tags, and tags matched by
6472 `org-agenda-hide-tags-regexp' will be removed."
6473 (when (or add-inherited hide-re)
6474 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6475 (setq txt (substring txt 0 (match-beginning 0))))
6476 (setq tags
6477 (delq nil
6478 (mapcar (lambda (tg)
6479 (if (or (and hide-re (string-match hide-re tg))
6480 (and (not add-inherited)
6481 (get-text-property 0 'inherited tg)))
6483 tg))
6484 tags)))
6485 (when tags
6486 (let ((have-i (get-text-property 0 'inherited (car tags)))
6488 (setq txt (concat txt " :"
6489 (mapconcat
6490 (lambda (x)
6491 (setq i (get-text-property 0 'inherited x))
6492 (if (and have-i (not i))
6493 (progn
6494 (setq have-i nil)
6495 (concat ":" x))
6497 tags ":")
6498 (if have-i "::" ":"))))))
6499 txt)
6501 (defun org-downcase-keep-props (s)
6502 (let ((props (text-properties-at 0 s)))
6503 (setq s (downcase s))
6504 (add-text-properties 0 (length s) props s)
6507 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6509 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6510 "Add a time-grid for agenda items which need it.
6512 LIST is the list of agenda items formatted by `org-agenda-list'.
6513 NDAYS is the span of the current agenda view.
6514 TODAYP is `t' when the current agenda view is on today."
6515 (catch 'exit
6516 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6517 ((and todayp (member 'today (car org-agenda-time-grid))))
6518 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6519 ((member 'weekly (car org-agenda-time-grid)))
6520 (t (throw 'exit list)))
6521 (let* ((have (delq nil (mapcar
6522 (lambda (x) (get-text-property 1 'time-of-day x))
6523 list)))
6524 (string (nth 1 org-agenda-time-grid))
6525 (gridtimes (nth 2 org-agenda-time-grid))
6526 (req (car org-agenda-time-grid))
6527 (remove (member 'remove-match req))
6528 new time)
6529 (if (and (member 'require-timed req) (not have))
6530 ;; don't show empty grid
6531 (throw 'exit list))
6532 (while (setq time (pop gridtimes))
6533 (unless (and remove (member time have))
6534 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6535 (push (org-agenda-format-item
6536 nil string nil "" nil
6537 (concat (substring time 0 -2) ":" (substring time -2)))
6538 new)
6539 (put-text-property
6540 2 (length (car new)) 'face 'org-time-grid (car new))))
6541 (when (and todayp org-agenda-show-current-time-in-grid)
6542 (push (org-agenda-format-item
6543 nil org-agenda-current-time-string nil "" nil
6544 (format-time-string "%H:%M "))
6545 new)
6546 (put-text-property
6547 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6549 (if (member 'time-up org-agenda-sorting-strategy-selected)
6550 (append new list)
6551 (append list new)))))
6553 (defun org-compile-prefix-format (key)
6554 "Compile the prefix format into a Lisp form that can be evaluated.
6555 The resulting form and associated variable bindings is returned
6556 and stored in the variable `org-prefix-format-compiled'."
6557 (setq org-prefix-has-time nil
6558 org-prefix-has-tag nil
6559 org-prefix-category-length nil
6560 org-prefix-has-effort nil
6561 org-prefix-has-breadcrumbs nil)
6562 (let ((s (cond
6563 ((stringp org-agenda-prefix-format)
6564 org-agenda-prefix-format)
6565 ((assq key org-agenda-prefix-format)
6566 (cdr (assq key org-agenda-prefix-format)))
6567 (t " %-12:c%?-12t% s")))
6568 (start 0)
6569 varform vars var e c f opt)
6570 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6571 s start)
6572 (setq var (or (cdr (assoc (match-string 4 s)
6573 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6574 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6575 'eval)
6576 c (or (match-string 3 s) "")
6577 opt (match-beginning 1)
6578 start (1+ (match-beginning 0)))
6579 (if (equal var 'time) (setq org-prefix-has-time t))
6580 (if (equal var 'tag) (setq org-prefix-has-tag t))
6581 (if (equal var 'effort) (setq org-prefix-has-effort t))
6582 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6583 (setq f (concat "%" (match-string 2 s) "s"))
6584 (when (equal var 'category)
6585 (setq org-prefix-category-length
6586 (floor (abs (string-to-number (match-string 2 s)))))
6587 (setq org-prefix-category-max-length
6588 (let ((x (match-string 2 s)))
6589 (save-match-data
6590 (if (string-match "\\.[0-9]+" x)
6591 (string-to-number (substring (match-string 0 x) 1)))))))
6592 (if (eq var 'eval)
6593 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6594 (if opt
6595 (setq varform
6596 `(if (equal "" ,var)
6598 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6599 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6600 (setq s (replace-match "%s" t nil s))
6601 (push varform vars))
6602 (setq vars (nreverse vars))
6603 (with-current-buffer (or org-agenda-buffer (current-buffer))
6604 (setq org-prefix-format-compiled
6605 (list
6606 `((org-prefix-has-time ,org-prefix-has-time)
6607 (org-prefix-has-tag ,org-prefix-has-tag)
6608 (org-prefix-category-length ,org-prefix-category-length)
6609 (org-prefix-has-effort ,org-prefix-has-effort)
6610 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6611 `(format ,s ,@vars))))))
6613 (defun org-set-sorting-strategy (key)
6614 (if (symbolp (car org-agenda-sorting-strategy))
6615 ;; the old format
6616 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6617 (setq org-agenda-sorting-strategy-selected
6618 (or (cdr (assq key org-agenda-sorting-strategy))
6619 (cdr (assq 'agenda org-agenda-sorting-strategy))
6620 '(time-up category-keep priority-down)))))
6622 (defun org-get-time-of-day (s &optional string mod24)
6623 "Check string S for a time of day.
6624 If found, return it as a military time number between 0 and 2400.
6625 If not found, return nil.
6626 The optional STRING argument forces conversion into a 5 character wide string
6627 HH:MM."
6628 (save-match-data
6629 (when
6630 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6631 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6632 (let* ((h (string-to-number (match-string 1 s)))
6633 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6634 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6635 (am-p (equal ampm "am"))
6636 (h1 (cond ((not ampm) h)
6637 ((= h 12) (if am-p 0 12))
6638 (t (+ h (if am-p 0 12)))))
6639 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6640 (mod h1 24) h1))
6641 (t0 (+ (* 100 h2) m))
6642 (t1 (concat (if (>= h1 24) "+" " ")
6643 (if (and org-agenda-time-leading-zero
6644 (< t0 1000)) "0" "")
6645 (if (< t0 100) "0" "")
6646 (if (< t0 10) "0" "")
6647 (int-to-string t0))))
6648 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6650 (defvar org-agenda-before-sorting-filter-function nil
6651 "Function to be applied to agenda items prior to sorting.
6652 Prior to sorting also means just before they are inserted into the agenda.
6654 To aid sorting, you may revisit the original entries and add more text
6655 properties which will later be used by the sorting functions.
6657 The function should take a string argument, an agenda line.
6658 It has access to the text properties in that line, which contain among
6659 other things, the property `org-hd-marker' that points to the entry
6660 where the line comes from. Note that not all lines going into the agenda
6661 have this property, only most.
6663 The function should return the modified string. It is probably best
6664 to ONLY change text properties.
6666 You can also use this function as a filter, by returning nil for lines
6667 you don't want to have in the agenda at all. For this application, you
6668 could bind the variable in the options section of a custom command.")
6670 (defun org-agenda-finalize-entries (list &optional type)
6671 "Sort, limit and concatenate the LIST of agenda items.
6672 The optional argument TYPE tells the agenda type."
6673 (let ((max-effort (cond ((listp org-agenda-max-effort)
6674 (cdr (assoc type org-agenda-max-effort)))
6675 (t org-agenda-max-effort)))
6676 (max-todo (cond ((listp org-agenda-max-todos)
6677 (cdr (assoc type org-agenda-max-todos)))
6678 (t org-agenda-max-todos)))
6679 (max-tags (cond ((listp org-agenda-max-tags)
6680 (cdr (assoc type org-agenda-max-tags)))
6681 (t org-agenda-max-tags)))
6682 (max-entries (cond ((listp org-agenda-max-entries)
6683 (cdr (assoc type org-agenda-max-entries)))
6684 (t org-agenda-max-entries))) l)
6685 (when org-agenda-before-sorting-filter-function
6686 (setq list
6687 (delq nil
6688 (mapcar
6689 org-agenda-before-sorting-filter-function list))))
6690 (setq list (mapcar 'org-agenda-highlight-todo list)
6691 list (mapcar 'identity (sort list 'org-entries-lessp))
6692 list (org-agenda-limit-entries
6693 list 'effort-minutes max-effort 'identity)
6694 list (org-agenda-limit-entries list 'todo-state max-todo)
6695 list (org-agenda-limit-entries list 'tags max-tags)
6696 list (org-agenda-limit-entries list 'org-hd-marker max-entries)
6697 list (mapconcat 'identity list "\n"))))
6699 (defun org-agenda-limit-entries (list prop limit &optional fn)
6700 "Limit the number of agenda entries."
6701 (if limit
6702 (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
6703 (delq nil
6704 (mapcar
6705 (lambda (e)
6706 (let ((pval (funcall f (get-text-property 1 prop e))))
6707 (if pval (setq lim (+ lim pval)))
6708 (if (or (not pval) (<= lim limit)) e)))
6709 list)))
6710 list))
6712 (defun org-agenda-highlight-todo (x)
6713 (let ((org-done-keywords org-done-keywords-for-agenda)
6714 (case-fold-search nil)
6716 (if (eq x 'line)
6717 (save-excursion
6718 (beginning-of-line 1)
6719 (setq re (org-get-at-bol 'org-todo-regexp))
6720 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6721 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6722 (add-text-properties (match-beginning 0) (match-end 1)
6723 (list 'face (org-get-todo-face 1)))
6724 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6725 (delete-region (match-beginning 1) (1- (match-end 0)))
6726 (goto-char (match-beginning 1))
6727 (insert (format org-agenda-todo-keyword-format s)))))
6728 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6729 (setq re (get-text-property 0 'org-todo-regexp x))
6730 (when (and re
6731 ;; Test `pl' because if there's no heading content,
6732 ;; there's no point matching to highlight. Note
6733 ;; that if we didn't test `pl' first, and there
6734 ;; happened to be no keyword from `org-todo-regexp'
6735 ;; on this heading line, then the `equal' comparison
6736 ;; afterwards would spuriously succeed in the case
6737 ;; where `pl' is nil -- causing an args-out-of-range
6738 ;; error when we try to add text properties to text
6739 ;; that isn't there.
6741 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6742 x pl) pl))
6743 (add-text-properties
6744 (or (match-end 1) (match-end 0)) (match-end 0)
6745 (list 'face (org-get-todo-face (match-string 2 x)))
6747 (when (match-end 1)
6748 (setq x (concat (substring x 0 (match-end 1))
6749 (format org-agenda-todo-keyword-format
6750 (match-string 2 x))
6751 (org-add-props " " (text-properties-at 0 x))
6752 (substring x (match-end 3)))))))
6753 x)))
6755 (defsubst org-cmp-priority (a b)
6756 "Compare the priorities of string A and B."
6757 (let ((pa (or (get-text-property 1 'priority a) 0))
6758 (pb (or (get-text-property 1 'priority b) 0)))
6759 (cond ((> pa pb) +1)
6760 ((< pa pb) -1))))
6762 (defsubst org-cmp-effort (a b)
6763 "Compare the effort values of string A and B."
6764 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6765 (ea (or (get-text-property 1 'effort-minutes a) def))
6766 (eb (or (get-text-property 1 'effort-minutes b) def)))
6767 (cond ((> ea eb) +1)
6768 ((< ea eb) -1))))
6770 (defsubst org-cmp-category (a b)
6771 "Compare the string values of categories of strings A and B."
6772 (let ((ca (or (get-text-property 1 'org-category a) ""))
6773 (cb (or (get-text-property 1 'org-category b) "")))
6774 (cond ((string-lessp ca cb) -1)
6775 ((string-lessp cb ca) +1))))
6777 (defsubst org-cmp-todo-state (a b)
6778 "Compare the todo states of strings A and B."
6779 (let* ((ma (or (get-text-property 1 'org-marker a)
6780 (get-text-property 1 'org-hd-marker a)))
6781 (mb (or (get-text-property 1 'org-marker b)
6782 (get-text-property 1 'org-hd-marker b)))
6783 (fa (and ma (marker-buffer ma)))
6784 (fb (and mb (marker-buffer mb)))
6785 (todo-kwds
6786 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6787 (and fb (with-current-buffer fb org-todo-keywords-1))))
6788 (ta (or (get-text-property 1 'todo-state a) ""))
6789 (tb (or (get-text-property 1 'todo-state b) ""))
6790 (la (- (length (member ta todo-kwds))))
6791 (lb (- (length (member tb todo-kwds))))
6792 (donepa (member ta org-done-keywords-for-agenda))
6793 (donepb (member tb org-done-keywords-for-agenda)))
6794 (cond ((and donepa (not donepb)) -1)
6795 ((and (not donepa) donepb) +1)
6796 ((< la lb) -1)
6797 ((< lb la) +1))))
6799 (defsubst org-cmp-alpha (a b)
6800 "Compare the headlines, alphabetically."
6801 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6802 (plb (text-property-any 0 (length b) 'org-heading t b))
6803 (ta (and pla (substring a pla)))
6804 (tb (and plb (substring b plb))))
6805 (when pla
6806 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6807 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6808 (setq ta (substring ta (match-end 0))))
6809 (setq ta (downcase ta)))
6810 (when plb
6811 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6812 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6813 (setq tb (substring tb (match-end 0))))
6814 (setq tb (downcase tb)))
6815 (cond ((not ta) +1)
6816 ((not tb) -1)
6817 ((string-lessp ta tb) -1)
6818 ((string-lessp tb ta) +1))))
6820 (defsubst org-cmp-tag (a b)
6821 "Compare the string values of the first tags of A and B."
6822 (let ((ta (car (last (get-text-property 1 'tags a))))
6823 (tb (car (last (get-text-property 1 'tags b)))))
6824 (cond ((not ta) +1)
6825 ((not tb) -1)
6826 ((string-lessp ta tb) -1)
6827 ((string-lessp tb ta) +1))))
6829 (defsubst org-cmp-time (a b)
6830 "Compare the time-of-day values of strings A and B."
6831 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6832 (ta (or (get-text-property 1 'time-of-day a) def))
6833 (tb (or (get-text-property 1 'time-of-day b) def)))
6834 (cond ((< ta tb) -1)
6835 ((< tb ta) +1))))
6837 (defsubst org-cmp-ts (a b &optional type)
6838 "Compare the timestamps values of entries A and B.
6839 When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
6840 or \"timestamp_ia\", compare within each of these type.
6841 When TYPE is the empty string, compare all timestamps
6842 without respect of their type."
6843 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6844 (ta (or (and (string-match type (get-text-property 1 'type a))
6845 (get-text-property 1 'ts-date a)) def))
6846 (tb (or (and (string-match type (get-text-property 1 'type b))
6847 (get-text-property 1 'ts-date b)) def)))
6848 (cond ((< ta tb) -1)
6849 ((< tb ta) +1))))
6851 (defsubst org-cmp-habit-p (a b)
6852 "Compare the todo states of strings A and B."
6853 (let ((ha (get-text-property 1 'org-habit-p a))
6854 (hb (get-text-property 1 'org-habit-p b)))
6855 (cond ((and ha (not hb)) -1)
6856 ((and (not ha) hb) +1))))
6858 (defun org-entries-lessp (a b)
6859 "Predicate for sorting agenda entries."
6860 ;; The following variables will be used when the form is evaluated.
6861 ;; So even though the compiler complains, keep them.
6862 (let* ((ss org-agenda-sorting-strategy-selected)
6863 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
6864 (org-cmp-ts a b "")))
6865 (timestamp-down (if timestamp-up (- timestamp-up) nil))
6866 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
6867 (org-cmp-ts a b "scheduled")))
6868 (scheduled-down (if scheduled-up (- scheduled-up) nil))
6869 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
6870 (org-cmp-ts a b "deadline")))
6871 (deadline-down (if deadline-up (- deadline-up) nil))
6872 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
6873 (org-cmp-ts a b "iatimestamp_ia")))
6874 (tsia-down (if tsia-up (- tsia-up) nil))
6875 (ts-up (and (org-em 'ts-up 'ts-down ss)
6876 (org-cmp-ts a b "timestamp")))
6877 (ts-down (if ts-up (- ts-up) nil))
6878 (time-up (and (org-em 'time-up 'time-down ss)
6879 (org-cmp-time a b)))
6880 (time-down (if time-up (- time-up) nil))
6881 (priority-up (and (org-em 'priority-up 'priority-down ss)
6882 (org-cmp-priority a b)))
6883 (priority-down (if priority-up (- priority-up) nil))
6884 (effort-up (and (org-em 'effort-up 'effort-down ss)
6885 (org-cmp-effort a b)))
6886 (effort-down (if effort-up (- effort-up) nil))
6887 (category-up (and (or (org-em 'category-up 'category-down ss)
6888 (memq 'category-keep ss))
6889 (org-cmp-category a b)))
6890 (category-down (if category-up (- category-up) nil))
6891 (category-keep (if category-up +1 nil))
6892 (tag-up (and (org-em 'tag-up 'tag-down ss)
6893 (org-cmp-tag a b)))
6894 (tag-down (if tag-up (- tag-up) nil))
6895 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6896 (org-cmp-todo-state a b)))
6897 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6898 (habit-up (and (org-em 'habit-up 'habit-down ss)
6899 (org-cmp-habit-p a b)))
6900 (habit-down (if habit-up (- habit-up) nil))
6901 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6902 (org-cmp-alpha a b)))
6903 (alpha-down (if alpha-up (- alpha-up) nil))
6904 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6905 user-defined-up user-defined-down)
6906 (if (and need-user-cmp org-agenda-cmp-user-defined
6907 (functionp org-agenda-cmp-user-defined))
6908 (setq user-defined-up
6909 (funcall org-agenda-cmp-user-defined a b)
6910 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6911 (cdr (assoc
6912 (eval (cons 'or org-agenda-sorting-strategy-selected))
6913 '((-1 . t) (1 . nil) (nil . nil))))))
6915 ;;; Agenda restriction lock
6917 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6918 "Overlay to mark the headline to which agenda commands are restricted.")
6919 (overlay-put org-agenda-restriction-lock-overlay
6920 'face 'org-agenda-restriction-lock)
6921 (overlay-put org-agenda-restriction-lock-overlay
6922 'help-echo "Agendas are currently limited to this subtree.")
6923 (org-detach-overlay org-agenda-restriction-lock-overlay)
6925 (defun org-agenda-set-restriction-lock (&optional type)
6926 "Set restriction lock for agenda, to current subtree or file.
6927 Restriction will be the file if TYPE is `file', or if type is the
6928 universal prefix '(4), or if the cursor is before the first headline
6929 in the file. Otherwise, restriction will be to the current subtree."
6930 (interactive "P")
6931 (and (equal type '(4)) (setq type 'file))
6932 (setq type (cond
6933 (type type)
6934 ((org-at-heading-p) 'subtree)
6935 ((condition-case nil (org-back-to-heading t) (error nil))
6936 'subtree)
6937 (t 'file)))
6938 (if (eq type 'subtree)
6939 (progn
6940 (setq org-agenda-restrict t)
6941 (setq org-agenda-overriding-restriction 'subtree)
6942 (put 'org-agenda-files 'org-restrict
6943 (list (buffer-file-name (buffer-base-buffer))))
6944 (org-back-to-heading t)
6945 (move-overlay org-agenda-restriction-lock-overlay
6946 (point) (save-excursion (org-end-of-subtree t t) (point)))
6947 (move-marker org-agenda-restrict-begin (point))
6948 (move-marker org-agenda-restrict-end
6949 (save-excursion (org-end-of-subtree t t)))
6950 (message "Locking agenda restriction to subtree"))
6951 (put 'org-agenda-files 'org-restrict
6952 (list (buffer-file-name (buffer-base-buffer))))
6953 (setq org-agenda-restrict nil)
6954 (setq org-agenda-overriding-restriction 'file)
6955 (move-marker org-agenda-restrict-begin nil)
6956 (move-marker org-agenda-restrict-end nil)
6957 (message "Locking agenda restriction to file"))
6958 (setq current-prefix-arg nil)
6959 (org-agenda-maybe-redo))
6961 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6962 "Remove the agenda restriction lock."
6963 (interactive "P")
6964 (org-detach-overlay org-agenda-restriction-lock-overlay)
6965 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6966 (setq org-agenda-overriding-restriction nil)
6967 (setq org-agenda-restrict nil)
6968 (put 'org-agenda-files 'org-restrict nil)
6969 (move-marker org-agenda-restrict-begin nil)
6970 (move-marker org-agenda-restrict-end nil)
6971 (setq current-prefix-arg nil)
6972 (message "Agenda restriction lock removed")
6973 (or noupdate (org-agenda-maybe-redo)))
6975 (defun org-agenda-maybe-redo ()
6976 "If there is any window showing the agenda view, update it."
6977 (let ((w (get-buffer-window org-agenda-buffer-name t))
6978 (w0 (selected-window)))
6979 (when w
6980 (select-window w)
6981 (org-agenda-redo)
6982 (select-window w0)
6983 (if org-agenda-overriding-restriction
6984 (message "Agenda view shifted to new %s restriction"
6985 org-agenda-overriding-restriction)
6986 (message "Agenda restriction lock removed")))))
6988 ;;; Agenda commands
6990 (defun org-agenda-check-type (error &rest types)
6991 "Check if agenda buffer is of allowed type.
6992 If ERROR is non-nil, throw an error, otherwise just return nil.
6993 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6994 (if (not org-agenda-type)
6995 (error "No Org agenda currently displayed")
6996 (if (memq org-agenda-type types)
6998 (if error
6999 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7000 nil))))
7002 (defun org-agenda-Quit ()
7003 "Exit the agenda and kill buffers loaded by `org-agenda'.
7004 Also restore the window configuration."
7005 (interactive)
7006 (if org-agenda-columns-active
7007 (org-columns-quit)
7008 (let ((buf (current-buffer)))
7009 (if (eq org-agenda-window-setup 'other-frame)
7010 (progn
7011 (org-agenda-reset-markers)
7012 (kill-buffer buf)
7013 (org-columns-remove-overlays)
7014 (setq org-agenda-archives-mode nil)
7015 (delete-frame))
7016 (and (not (eq org-agenda-window-setup 'current-window))
7017 (not (one-window-p))
7018 (delete-window))
7019 (org-agenda-reset-markers)
7020 (kill-buffer buf)
7021 (org-columns-remove-overlays)
7022 (setq org-agenda-archives-mode nil)))
7023 ;; Maybe restore the pre-agenda window configuration.
7024 (and org-agenda-restore-windows-after-quit
7025 (not (eq org-agenda-window-setup 'other-frame))
7026 org-agenda-pre-window-conf
7027 (set-window-configuration org-agenda-pre-window-conf)
7028 (setq org-agenda-pre-window-conf nil))))
7030 (defun org-agenda-quit ()
7031 "Exit the agenda and restore the window configuration.
7032 When `org-agenda-sticky' is non-nil, only bury the agenda."
7033 (interactive)
7034 (if (and (eq org-indirect-buffer-display 'other-window)
7035 org-last-indirect-buffer)
7036 (let ((org-last-indirect-window
7037 (get-buffer-window org-last-indirect-buffer)))
7038 (if org-last-indirect-window
7039 (delete-window org-last-indirect-window))))
7040 (if org-agenda-columns-active
7041 (org-columns-quit)
7042 (if org-agenda-sticky
7043 (let ((buf (current-buffer)))
7044 (if (eq org-agenda-window-setup 'other-frame)
7045 (progn
7046 (delete-frame))
7047 (and (not (eq org-agenda-window-setup 'current-window))
7048 (not (one-window-p))
7049 (delete-window)))
7050 (with-current-buffer buf
7051 (bury-buffer)
7052 ;; Maybe restore the pre-agenda window configuration.
7053 (and org-agenda-restore-windows-after-quit
7054 (not (eq org-agenda-window-setup 'other-frame))
7055 org-agenda-pre-window-conf
7056 (set-window-configuration org-agenda-pre-window-conf)
7057 (setq org-agenda-pre-window-conf nil))))
7058 (org-agenda-Quit))))
7060 (defun org-agenda-exit ()
7061 "Exit the agenda and restore the window configuration.
7062 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7063 buffers visited directly by the user will not be touched."
7064 (interactive)
7065 (org-release-buffers org-agenda-new-buffers)
7066 (setq org-agenda-new-buffers nil)
7067 (org-agenda-Quit))
7069 (defun org-agenda-kill-all-agenda-buffers ()
7070 "Kill all buffers in `org-agenda-mode'.
7071 This is used when toggling sticky agendas.
7072 You can also explicitly invoke it with `C-c a C-k'."
7073 (interactive)
7074 (let (blist)
7075 (dolist (buf (buffer-list))
7076 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7077 (push buf blist)))
7078 (mapc 'kill-buffer blist)))
7080 (defun org-agenda-execute (arg)
7081 "Execute another agenda command, keeping same window.
7082 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7083 in the agenda."
7084 (interactive "P")
7085 (let ((org-agenda-window-setup 'current-window))
7086 (org-agenda arg)))
7088 (defun org-agenda-redo (&optional all)
7089 "Rebuild possibly ALL agenda view(s) in the current buffer."
7090 (interactive "P")
7091 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7092 (cpa (unless (eq all t) current-prefix-arg))
7093 (org-agenda-doing-sticky-redo org-agenda-sticky)
7094 (org-agenda-sticky nil)
7095 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7096 org-agenda-buffer-name))
7097 (org-agenda-keep-modes t)
7098 (tag-filter org-agenda-tag-filter)
7099 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7100 (top-cat-filter org-agenda-top-category-filter)
7101 (cat-filter org-agenda-category-filter)
7102 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7103 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7104 (cols org-agenda-columns-active)
7105 (line (org-current-line))
7106 (window-line (- line (org-current-line (window-start))))
7107 (lprops (get 'org-agenda-redo-command 'org-lprops))
7108 (redo-cmd (get-text-property p 'org-redo-cmd))
7109 (last-args (get-text-property p 'org-last-args))
7110 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7111 (org-agenda-overriding-cmd-arguments
7112 (unless (eq all t)
7113 (cond ((listp last-args)
7114 (cons (or cpa (car last-args)) (cdr last-args)))
7115 ((stringp last-args)
7116 last-args))))
7117 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7118 (put 'org-agenda-tag-filter :preset-filter nil)
7119 (put 'org-agenda-category-filter :preset-filter nil)
7120 (and cols (org-columns-quit))
7121 (message "Rebuilding agenda buffer...")
7122 (if series-redo-cmd
7123 (eval series-redo-cmd)
7124 (org-let lprops '(eval redo-cmd)))
7125 (setq org-agenda-undo-list nil
7126 org-agenda-pending-undo-list nil)
7127 (message "Rebuilding agenda buffer...done")
7128 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7129 (put 'org-agenda-category-filter :preset-filter cat-preset)
7130 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7131 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7132 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7133 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7134 (org-goto-line line)
7135 (recenter window-line)))
7137 (defvar org-global-tags-completion-table nil)
7138 (defvar org-agenda-filter-form nil)
7139 (defvar org-agenda-filtered-by-category nil)
7141 (defun org-agenda-filter-by-category (strip)
7142 "Keep only those lines in the agenda buffer that have a specific category.
7143 The category is that of the current line."
7144 (interactive "P")
7145 (if (and org-agenda-filtered-by-category
7146 org-agenda-category-filter)
7147 (org-agenda-filter-show-all-cat)
7148 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7149 (if cat (org-agenda-filter-apply
7150 (list (concat (if strip "-" "+") cat)) 'category)
7151 (error "No category at point")))))
7153 (defun org-find-top-category (&optional pos)
7154 (save-excursion
7155 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7156 (if pos (goto-char pos))
7157 ;; Skip up to the topmost parent
7158 (while (ignore-errors (outline-up-heading 1) t))
7159 (ignore-errors
7160 (nth 4 (org-heading-components))))))
7162 (defvar org-agenda-filtered-by-top-category nil)
7164 (defun org-agenda-filter-by-top-category (strip)
7165 "Keep only those lines in the agenda buffer that have a specific category.
7166 The category is that of the current line."
7167 (interactive "P")
7168 (if org-agenda-filtered-by-top-category
7169 (progn
7170 (setq org-agenda-filtered-by-top-category nil
7171 org-agenda-top-category-filter nil)
7172 (org-agenda-filter-show-all-cat))
7173 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7174 (if cat (org-agenda-filter-top-category-apply cat strip)
7175 (error "No top-level category at point")))))
7177 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7178 "Keep only those lines in the agenda buffer that have a specific tag.
7179 The tag is selected with its fast selection letter, as configured.
7180 With prefix argument STRIP, remove all lines that do have the tag.
7181 A lisp caller can specify CHAR. NARROW means that the new tag should be
7182 used to narrow the search - the interactive user can also press `-' or `+'
7183 to switch to narrowing."
7184 (interactive "P")
7185 (let* ((alist org-tag-alist-for-agenda)
7186 (tag-chars (mapconcat
7187 (lambda (x) (if (and (not (symbolp (car x)))
7188 (cdr x))
7189 (char-to-string (cdr x))
7190 ""))
7191 alist ""))
7192 (efforts (org-split-string
7193 (or (cdr (assoc (concat org-effort-property "_ALL")
7194 org-global-properties))
7195 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7196 "")))
7197 (effort-op org-agenda-filter-effort-default-operator)
7198 (effort-prompt "")
7199 (inhibit-read-only t)
7200 (current org-agenda-tag-filter)
7201 maybe-refresh a n tag)
7202 (unless char
7203 (message
7204 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7205 (if narrow "Narrow" "Filter") tag-chars
7206 (if org-agenda-auto-exclude-function "[RET], " ""))
7207 (setq char (read-char-exclusive)))
7208 (when (member char '(?+ ?-))
7209 ;; Narrowing down
7210 (cond ((equal char ?-) (setq strip t narrow t))
7211 ((equal char ?+) (setq strip nil narrow t)))
7212 (message
7213 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7214 (setq char (read-char-exclusive)))
7215 (when (member char '(?< ?> ?= ??))
7216 ;; An effort operator
7217 (setq effort-op (char-to-string char))
7218 (setq alist nil) ; to make sure it will be interpreted as effort.
7219 (unless (equal char ??)
7220 (loop for i from 0 to 9 do
7221 (setq effort-prompt
7222 (concat
7223 effort-prompt " ["
7224 (if (= i 9) "0" (int-to-string (1+ i)))
7225 "]" (nth i efforts))))
7226 (message "Effort%s: %s " effort-op effort-prompt)
7227 (setq char (read-char-exclusive))
7228 (when (or (< char ?0) (> char ?9))
7229 (error "Need 1-9,0 to select effort"))))
7230 (when (equal char ?\t)
7231 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7232 (org-set-local 'org-global-tags-completion-table
7233 (org-global-tags-completion-table)))
7234 (let ((completion-ignore-case t))
7235 (setq tag (org-icompleting-read
7236 "Tag: " org-global-tags-completion-table))))
7237 (cond
7238 ((equal char ?\r)
7239 (org-agenda-filter-show-all-tag)
7240 (when org-agenda-auto-exclude-function
7241 (setq org-agenda-tag-filter '())
7242 (dolist (tag (org-agenda-get-represented-tags))
7243 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7244 (if modifier
7245 (push modifier org-agenda-tag-filter))))
7246 (if (not (null org-agenda-tag-filter))
7247 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7248 (setq maybe-refresh t))
7249 ((equal char ?/)
7250 (org-agenda-filter-show-all-tag)
7251 (when (get 'org-agenda-tag-filter :preset-filter)
7252 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7253 (setq maybe-refresh t))
7254 ((equal char ?. )
7255 (setq org-agenda-tag-filter
7256 (mapcar (lambda(tag) (concat "+" tag))
7257 (org-get-at-bol 'tags)))
7258 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7259 (setq maybe-refresh t))
7260 ((or (equal char ?\ )
7261 (setq a (rassoc char alist))
7262 (and (>= char ?0) (<= char ?9)
7263 (setq n (if (= char ?0) 9 (- char ?0 1))
7264 tag (concat effort-op (nth n efforts))
7265 a (cons tag nil)))
7266 (and (= char ??)
7267 (setq tag "?eff")
7268 a (cons tag nil))
7269 (and tag (setq a (cons tag nil))))
7270 (org-agenda-filter-show-all-tag)
7271 (setq tag (car a))
7272 (setq org-agenda-tag-filter
7273 (cons (concat (if strip "-" "+") tag)
7274 (if narrow current nil)))
7275 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7276 (setq maybe-refresh t))
7277 (t (error "Invalid tag selection character %c" char)))
7278 (when (and maybe-refresh
7279 (eq org-agenda-clockreport-mode 'with-filter))
7280 (org-agenda-redo))))
7282 (defun org-agenda-get-represented-tags ()
7283 "Get a list of all tags currently represented in the agenda."
7284 (let (p tags)
7285 (save-excursion
7286 (goto-char (point-min))
7287 (while (setq p (next-single-property-change (point) 'tags))
7288 (goto-char p)
7289 (mapc (lambda (x) (add-to-list 'tags x))
7290 (get-text-property (point) 'tags))))
7291 tags))
7293 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7294 "Refine the current filter. See `org-agenda-filter-by-tag'."
7295 (interactive "P")
7296 (org-agenda-filter-by-tag strip char 'refine))
7298 (defun org-agenda-filter-make-matcher ()
7299 "Create the form that tests a line for agenda filter."
7300 (let (f f1)
7301 ;; first compute the tag-filter matcher
7302 (dolist (x (delete-dups
7303 (append (get 'org-agenda-tag-filter
7304 :preset-filter) org-agenda-tag-filter)))
7305 (if (member x '("-" "+"))
7306 (setq f1 (if (equal x "-") 'tags '(not tags)))
7307 (if (string-match "[<=>?]" x)
7308 (setq f1 (org-agenda-filter-effort-form x))
7309 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7310 (if (equal (string-to-char x) ?-)
7311 (setq f1 (list 'not f1))))
7312 (push f1 f))
7313 ;; then compute the category-filter matcher
7314 (dolist (x (delete-dups
7315 (append (get 'org-agenda-category-filter
7316 :preset-filter) org-agenda-category-filter)))
7317 (if (equal "-" (substring x 0 1))
7318 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7319 (setq f1 (list 'equal (substring x 1) 'cat)))
7320 (push f1 f))
7321 (cons 'and (nreverse f))))
7323 (defun org-agenda-filter-effort-form (e)
7324 "Return the form to compare the effort of the current line with what E says.
7325 E looks like \"+<2:25\"."
7326 (let (op)
7327 (setq e (substring e 1))
7328 (setq op (string-to-char e) e (substring e 1))
7329 (setq op (cond ((equal op ?<) '<=)
7330 ((equal op ?>) '>=)
7331 ((equal op ??) op)
7332 (t '=)))
7333 (list 'org-agenda-compare-effort (list 'quote op)
7334 (org-duration-string-to-minutes e))))
7336 (defun org-agenda-compare-effort (op value)
7337 "Compare the effort of the current line with VALUE, using OP.
7338 If the line does not have an effort defined, return nil."
7339 (let ((eff (org-get-at-bol 'effort-minutes)))
7340 (if (equal op ??)
7341 (not eff)
7342 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7343 value))))
7345 (defun org-agenda-filter-apply (filter type)
7346 "Set FILTER as the new agenda filter and apply it."
7347 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7348 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7349 (let (tags cat)
7350 (if (eq type 'tag)
7351 (setq org-agenda-tag-filter filter)
7352 (setq org-agenda-category-filter filter))
7353 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7354 (if (and (eq type 'category)
7355 (not (equal (substring (car filter) 0 1) "-")))
7356 ;; Only set `org-agenda-filtered-by-category' to t
7357 ;; when a unique category is used as the filter
7358 (setq org-agenda-filtered-by-category t))
7359 (org-agenda-set-mode-name)
7360 (save-excursion
7361 (goto-char (point-min))
7362 (while (not (eobp))
7363 (if (org-get-at-bol 'org-marker)
7364 (progn
7365 (setq tags (org-get-at-bol 'tags) ; used in eval
7366 cat (get-text-property (point) 'org-category))
7367 (if (not (eval org-agenda-filter-form))
7368 (org-agenda-filter-hide-line type))
7369 (beginning-of-line 2))
7370 (beginning-of-line 2))))
7371 (if (get-char-property (point) 'invisible)
7372 (ignore-errors (org-agenda-previous-line)))))
7374 (defun org-agenda-filter-top-category-apply (category &optional negative)
7375 "Set FILTER as the new agenda filter and apply it."
7376 (org-agenda-set-mode-name)
7377 (save-excursion
7378 (goto-char (point-min))
7379 (while (not (eobp))
7380 (let* ((pos (org-get-at-bol 'org-hd-marker))
7381 (topcat (and pos (org-find-top-category pos))))
7382 (if (and topcat (funcall (if negative 'identity 'not)
7383 (string= category topcat)))
7384 (org-agenda-filter-hide-line 'category)))
7385 (beginning-of-line 2)))
7386 (if (get-char-property (point) 'invisible)
7387 (org-agenda-previous-line))
7388 (setq org-agenda-top-category-filter category
7389 org-agenda-filtered-by-top-category t))
7391 (defun org-agenda-filter-hide-line (type)
7392 (let (ov)
7393 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7394 (point-at-eol)))
7395 (overlay-put ov 'invisible t)
7396 (overlay-put ov 'type type)
7397 (if (eq type 'tag)
7398 (push ov org-agenda-tag-filter-overlays)
7399 (push ov org-agenda-cat-filter-overlays))))
7401 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7402 (setq pos (or pos (point)))
7403 (save-excursion
7404 (dolist (ov (overlays-at pos))
7405 (when (and (overlay-get ov 'invisible)
7406 (eq (overlay-get ov 'type) 'tag))
7407 (goto-char pos)
7408 (if (< (overlay-start ov) (point-at-eol))
7409 (move-overlay ov (point-at-eol)
7410 (overlay-end ov)))))))
7412 (defun org-agenda-filter-show-all-tag nil
7413 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7414 (setq org-agenda-tag-filter-overlays nil
7415 org-agenda-tag-filter nil
7416 org-agenda-filter-form nil)
7417 (org-agenda-set-mode-name))
7419 (defun org-agenda-filter-show-all-cat nil
7420 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7421 (setq org-agenda-cat-filter-overlays nil
7422 org-agenda-filtered-by-category nil
7423 org-agenda-category-filter nil
7424 org-agenda-filter-form nil)
7425 (org-agenda-set-mode-name))
7427 (defun org-agenda-manipulate-query-add ()
7428 "Manipulate the query by adding a search term with positive selection.
7429 Positive selection means the term must be matched for selection of an entry."
7430 (interactive)
7431 (org-agenda-manipulate-query ?\[))
7432 (defun org-agenda-manipulate-query-subtract ()
7433 "Manipulate the query by adding a search term with negative selection.
7434 Negative selection means term must not be matched for selection of an entry."
7435 (interactive)
7436 (org-agenda-manipulate-query ?\]))
7437 (defun org-agenda-manipulate-query-add-re ()
7438 "Manipulate the query by adding a search regexp with positive selection.
7439 Positive selection means the regexp must match for selection of an entry."
7440 (interactive)
7441 (org-agenda-manipulate-query ?\{))
7442 (defun org-agenda-manipulate-query-subtract-re ()
7443 "Manipulate the query by adding a search regexp with negative selection.
7444 Negative selection means regexp must not match for selection of an entry."
7445 (interactive)
7446 (org-agenda-manipulate-query ?\}))
7447 (defun org-agenda-manipulate-query (char)
7448 (cond
7449 ((memq org-agenda-type '(timeline agenda))
7450 (let ((org-agenda-include-inactive-timestamps t))
7451 (org-agenda-redo))
7452 (message "Display now includes inactive timestamps as well"))
7453 ((eq org-agenda-type 'search)
7454 (org-add-to-string
7455 'org-agenda-query-string
7456 (if org-agenda-last-search-view-search-was-boolean
7457 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7458 (?\{ . " +{}") (?\} . " -{}"))))
7459 " "))
7460 (setq org-agenda-redo-command
7461 (list 'org-search-view
7462 (car (get-text-property (min (1- (point-max)) (point))
7463 'org-last-args))
7464 org-agenda-query-string
7465 (+ (length org-agenda-query-string)
7466 (if (member char '(?\{ ?\})) 0 1))))
7467 (set-register org-agenda-query-register org-agenda-query-string)
7468 (let ((org-agenda-overriding-arguments
7469 (cdr org-agenda-redo-command)))
7470 (org-agenda-redo)))
7471 (t (error "Cannot manipulate query for %s-type agenda buffers"
7472 org-agenda-type))))
7474 (defun org-add-to-string (var string)
7475 (set var (concat (symbol-value var) string)))
7477 (defun org-agenda-goto-date (span)
7478 "Jump to DATE in agenda."
7479 (interactive "P")
7480 (let* ((org-read-date-prefer-future
7481 (eval org-agenda-jump-prefer-future))
7482 (date (org-read-date))
7483 (org-agenda-sticky-orig org-agenda-sticky)
7484 (org-agenda-buffer-tmp-name (buffer-name))
7485 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7486 (0-arg (or current-prefix-arg (car args)))
7487 (2-arg (nth 2 args))
7488 (newcmd (list 'org-agenda-list 0-arg date
7489 (org-agenda-span-to-ndays 2-arg)))
7490 (newargs (cdr newcmd))
7491 (inhibit-read-only t)
7492 org-agenda-sticky)
7493 (if (not (org-agenda-check-type t 'agenda))
7494 (error "Not available in non-agenda blocks")
7495 (add-text-properties (point-min) (point-max)
7496 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7497 (org-agenda-redo)
7498 (setq org-agenda-sticky org-agenda-sticky-orig
7499 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7501 (defun org-agenda-goto-today ()
7502 "Go to today."
7503 (interactive)
7504 (org-agenda-check-type t 'timeline 'agenda)
7505 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7506 (curspan (nth 2 args))
7507 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7508 (cond
7509 (tdpos (goto-char tdpos))
7510 ((eq org-agenda-type 'agenda)
7511 (let* ((sd (org-agenda-compute-starting-span
7512 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7513 (org-agenda-overriding-arguments args))
7514 (setf (nth 1 org-agenda-overriding-arguments) sd)
7515 (org-agenda-redo)
7516 (org-agenda-find-same-or-today-or-agenda)))
7517 (t (error "Cannot find today")))))
7519 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7520 (goto-char
7521 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7522 (text-property-any (point-min) (point-max) 'org-today t)
7523 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7524 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7525 (org-agenda-goto-block-beginning))
7526 (point-min))))
7528 (defun org-agenda-goto-block-beginning ()
7529 "Go the agenda block beginning."
7530 (interactive)
7531 (if (not (derived-mode-p 'org-agenda-mode))
7532 (error "Cannot execute this command outside of org-agenda-mode buffers")
7533 (let (dest)
7534 (save-excursion
7535 (unless (looking-at "\\'")
7536 (forward-char))
7537 (let* ((prop 'org-agenda-structural-header)
7538 (p (previous-single-property-change (point) prop))
7539 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7540 (1- (point))) prop)))
7541 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7542 (if (not dest)
7543 (error "Cannot find the beginning of the blog")
7544 (goto-char dest)
7545 (move-beginning-of-line 1)))))
7547 (defun org-agenda-later (arg)
7548 "Go forward in time by the current span.
7549 With prefix ARG, go forward that many times the current span."
7550 (interactive "p")
7551 (org-agenda-check-type t 'agenda)
7552 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7553 (span (or (nth 2 args) org-agenda-current-span))
7554 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7555 (greg (calendar-gregorian-from-absolute sd))
7556 (cnt (org-get-at-bol 'org-day-cnt))
7557 greg2)
7558 (cond
7559 ((numberp span)
7560 (setq sd (+ (* span arg) sd)))
7561 ((eq span 'day)
7562 (setq sd (+ arg sd)))
7563 ((eq span 'week)
7564 (setq sd (+ (* 7 arg) sd)))
7565 ((eq span 'month)
7566 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7567 sd (calendar-absolute-from-gregorian greg2))
7568 (setcar greg2 (1+ (car greg2))))
7569 ((eq span 'year)
7570 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7571 sd (calendar-absolute-from-gregorian greg2))
7572 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7574 (setq sd (+ (* span arg) sd))))
7575 (let ((org-agenda-overriding-cmd
7576 ;; `cmd' may have been set by `org-agenda-run-series' which
7577 ;; uses `org-agenda-overriding-cmd' to decide whether
7578 ;; overriding is allowed for `cmd'
7579 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7580 (org-agenda-overriding-arguments
7581 (list (car args) sd span)))
7582 (org-agenda-redo)
7583 (org-agenda-find-same-or-today-or-agenda cnt))))
7585 (defun org-agenda-earlier (arg)
7586 "Go backward in time by the current span.
7587 With prefix ARG, go backward that many times the current span."
7588 (interactive "p")
7589 (org-agenda-later (- arg)))
7591 (defun org-agenda-view-mode-dispatch ()
7592 "Call one of the view mode commands."
7593 (interactive)
7594 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7595 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7596 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7597 (let ((a (read-char-exclusive)))
7598 (case a
7599 (?\ (call-interactively 'org-agenda-reset-view))
7600 (?d (call-interactively 'org-agenda-day-view))
7601 (?w (call-interactively 'org-agenda-week-view))
7602 (?m (call-interactively 'org-agenda-month-view))
7603 (?y (call-interactively 'org-agenda-year-view))
7604 (?l (call-interactively 'org-agenda-log-mode))
7605 (?L (org-agenda-log-mode '(4)))
7606 (?c (org-agenda-log-mode 'clockcheck))
7607 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7608 (?a (call-interactively 'org-agenda-archives-mode))
7609 (?A (org-agenda-archives-mode 'files))
7610 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7611 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7612 (?G (call-interactively 'org-agenda-toggle-time-grid))
7613 (?D (call-interactively 'org-agenda-toggle-diary))
7614 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7615 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7616 (org-agenda-check-type t 'timeline 'agenda)
7617 (org-agenda-redo))
7618 (message "Display now includes inactive timestamps as well"))
7619 (?q (message "Abort"))
7620 (otherwise (error "Invalid key" )))))
7622 (defun org-agenda-reset-view ()
7623 "Switch to default view for agenda."
7624 (interactive)
7625 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7626 (defun org-agenda-day-view (&optional day-of-year)
7627 "Switch to daily view for agenda.
7628 With argument DAY-OF-YEAR, switch to that day of the year."
7629 (interactive "P")
7630 (org-agenda-change-time-span 'day day-of-year))
7631 (defun org-agenda-week-view (&optional iso-week)
7632 "Switch to daily view for agenda.
7633 With argument ISO-WEEK, switch to the corresponding ISO week.
7634 If ISO-WEEK has more then 2 digits, only the last two encode the
7635 week. Any digits before this encode a year. So 200712 means
7636 week 12 of year 2007. Years in the range 1938-2037 can also be
7637 written as 2-digit years."
7638 (interactive "P")
7639 (org-agenda-change-time-span 'week iso-week))
7640 (defun org-agenda-month-view (&optional month)
7641 "Switch to monthly view for agenda.
7642 With argument MONTH, switch to that month."
7643 (interactive "P")
7644 (org-agenda-change-time-span 'month month))
7645 (defun org-agenda-year-view (&optional year)
7646 "Switch to yearly view for agenda.
7647 With argument YEAR, switch to that year.
7648 If MONTH has more then 2 digits, only the last two encode the
7649 month. Any digits before this encode a year. So 200712 means
7650 December year 2007. Years in the range 1938-2037 can also be
7651 written as 2-digit years."
7652 (interactive "P")
7653 (when year
7654 (setq year (org-small-year-to-year year)))
7655 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7656 (org-agenda-change-time-span 'year year)
7657 (error "Abort")))
7659 (defun org-agenda-change-time-span (span &optional n)
7660 "Change the agenda view to SPAN.
7661 SPAN may be `day', `week', `month', `year'."
7662 (org-agenda-check-type t 'agenda)
7663 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7664 (curspan (nth 2 args)))
7665 (if (and (not n) (equal curspan span))
7666 (error "Viewing span is already \"%s\"" span))
7667 (let* ((sd (or (org-get-at-bol 'day)
7668 (nth 1 args)
7669 org-starting-day))
7670 (sd (org-agenda-compute-starting-span sd span n))
7671 (org-agenda-overriding-cmd
7672 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7673 (org-agenda-overriding-arguments
7674 (list (car args) sd span)))
7675 (org-agenda-redo)
7676 (org-agenda-find-same-or-today-or-agenda))
7677 (org-agenda-set-mode-name)
7678 (message "Switched to %s view" span)))
7680 (defun org-agenda-compute-starting-span (sd span &optional n)
7681 "Compute starting date for agenda.
7682 SPAN may be `day', `week', `month', `year'. The return value
7683 is a cons cell with the starting date and the number of days,
7684 so that the date SD will be in that range."
7685 (let* ((greg (calendar-gregorian-from-absolute sd))
7686 (dg (nth 1 greg))
7687 (mg (car greg))
7688 (yg (nth 2 greg)))
7689 (cond
7690 ((eq span 'day)
7691 (when n
7692 (setq sd (+ (calendar-absolute-from-gregorian
7693 (list mg 1 yg))
7694 n -1))))
7695 ((eq span 'week)
7696 (let* ((nt (calendar-day-of-week
7697 (calendar-gregorian-from-absolute sd)))
7698 (d (if org-agenda-start-on-weekday
7699 (- nt org-agenda-start-on-weekday)
7702 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7703 (when n
7704 (require 'cal-iso)
7705 (when (> n 99)
7706 (setq y1 (org-small-year-to-year (/ n 100))
7707 n (mod n 100)))
7708 (setq sd
7709 (calendar-absolute-from-iso
7710 (list n 1
7711 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7712 ((eq span 'month)
7713 (let (y1)
7714 (when (and n (> n 99))
7715 (setq y1 (org-small-year-to-year (/ n 100))
7716 n (mod n 100)))
7717 (setq sd (calendar-absolute-from-gregorian
7718 (list (or n mg) 1 (or y1 yg))))))
7719 ((eq span 'year)
7720 (setq sd (calendar-absolute-from-gregorian
7721 (list 1 1 (or n yg))))))
7722 sd))
7724 (defun org-agenda-next-date-line (&optional arg)
7725 "Jump to the next line indicating a date in agenda buffer."
7726 (interactive "p")
7727 (org-agenda-check-type t 'agenda 'timeline)
7728 (beginning-of-line 1)
7729 ;; This does not work if user makes date format that starts with a blank
7730 (if (looking-at "^\\S-") (forward-char 1))
7731 (if (not (re-search-forward "^\\S-" nil t arg))
7732 (progn
7733 (backward-char 1)
7734 (error "No next date after this line in this buffer")))
7735 (goto-char (match-beginning 0)))
7737 (defun org-agenda-previous-date-line (&optional arg)
7738 "Jump to the previous line indicating a date in agenda buffer."
7739 (interactive "p")
7740 (org-agenda-check-type t 'agenda 'timeline)
7741 (beginning-of-line 1)
7742 (if (not (re-search-backward "^\\S-" nil t arg))
7743 (error "No previous date before this line in this buffer")))
7745 ;; Initialize the highlight
7746 (defvar org-hl (make-overlay 1 1))
7747 (overlay-put org-hl 'face 'highlight)
7749 (defun org-highlight (begin end &optional buffer)
7750 "Highlight a region with overlay."
7751 (move-overlay org-hl begin end (or buffer (current-buffer))))
7753 (defun org-unhighlight ()
7754 "Detach overlay INDEX."
7755 (org-detach-overlay org-hl))
7757 (defun org-unhighlight-once ()
7758 "Remove the highlight from its position, and this function from the hook."
7759 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7760 (org-unhighlight))
7762 (defvar org-agenda-pre-follow-window-conf nil)
7763 (defun org-agenda-follow-mode ()
7764 "Toggle follow mode in an agenda buffer."
7765 (interactive)
7766 (unless org-agenda-follow-mode
7767 (setq org-agenda-pre-follow-window-conf
7768 (current-window-configuration)))
7769 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7770 (unless org-agenda-follow-mode
7771 (set-window-configuration org-agenda-pre-follow-window-conf))
7772 (org-agenda-set-mode-name)
7773 (org-agenda-do-context-action)
7774 (message "Follow mode is %s"
7775 (if org-agenda-follow-mode "on" "off")))
7777 (defun org-agenda-entry-text-mode (&optional arg)
7778 "Toggle entry text mode in an agenda buffer."
7779 (interactive "P")
7780 (if (or org-agenda-tag-filter
7781 org-agenda-category-filter
7782 org-agenda-top-category-filter)
7783 (user-error "Can't show entry text in filtered views")
7784 (setq org-agenda-entry-text-mode (or (integerp arg)
7785 (not org-agenda-entry-text-mode)))
7786 (org-agenda-entry-text-hide)
7787 (and org-agenda-entry-text-mode
7788 (let ((org-agenda-entry-text-maxlines
7789 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7790 (org-agenda-entry-text-show)))
7791 (org-agenda-set-mode-name)
7792 (message "Entry text mode is %s%s"
7793 (if org-agenda-entry-text-mode "on" "off")
7794 (if (not org-agenda-entry-text-mode) ""
7795 (format " (maximum number of lines is %d)"
7796 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
7798 (defun org-agenda-clockreport-mode (&optional with-filter)
7799 "Toggle clocktable mode in an agenda buffer.
7800 With prefix arg WITH-FILTER, make the clocktable respect the current
7801 agenda filter."
7802 (interactive "P")
7803 (org-agenda-check-type t 'agenda)
7804 (if with-filter
7805 (setq org-agenda-clockreport-mode 'with-filter)
7806 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7807 (org-agenda-set-mode-name)
7808 (org-agenda-redo)
7809 (message "Clocktable mode is %s"
7810 (if org-agenda-clockreport-mode "on" "off")))
7812 (defun org-agenda-log-mode (&optional special)
7813 "Toggle log mode in an agenda buffer.
7814 With argument SPECIAL, show all possible log items, not only the ones
7815 configured in `org-agenda-log-mode-items'.
7816 With a double `C-u' prefix arg, show *only* log items, nothing else."
7817 (interactive "P")
7818 (org-agenda-check-type t 'agenda 'timeline)
7819 (setq org-agenda-show-log
7820 (cond
7821 ((equal special '(16)) 'only)
7822 ((eq special 'clockcheck)
7823 (if (eq org-agenda-show-log 'clockcheck)
7824 nil 'clockcheck))
7825 (special '(closed clock state))
7826 (t (not org-agenda-show-log))))
7827 (org-agenda-set-mode-name)
7828 (org-agenda-redo)
7829 (message "Log mode is %s"
7830 (if org-agenda-show-log "on" "off")))
7832 (defun org-agenda-archives-mode (&optional with-files)
7833 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7834 When called with a prefix argument, include all archive files as well."
7835 (interactive "P")
7836 (setq org-agenda-archives-mode
7837 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7838 (org-agenda-set-mode-name)
7839 (org-agenda-redo)
7840 (message
7841 "%s"
7842 (cond
7843 ((eq org-agenda-archives-mode nil)
7844 "No archives are included")
7845 ((eq org-agenda-archives-mode 'trees)
7846 (format "Trees with :%s: tag are included" org-archive-tag))
7847 ((eq org-agenda-archives-mode t)
7848 (format "Trees with :%s: tag and all active archive files are included"
7849 org-archive-tag)))))
7851 (defun org-agenda-toggle-diary ()
7852 "Toggle diary inclusion in an agenda buffer."
7853 (interactive)
7854 (org-agenda-check-type t 'agenda)
7855 (setq org-agenda-include-diary (not org-agenda-include-diary))
7856 (org-agenda-redo)
7857 (org-agenda-set-mode-name)
7858 (message "Diary inclusion turned %s"
7859 (if org-agenda-include-diary "on" "off")))
7861 (defun org-agenda-toggle-deadlines ()
7862 "Toggle inclusion of entries with a deadline in an agenda buffer."
7863 (interactive)
7864 (org-agenda-check-type t 'agenda)
7865 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7866 (org-agenda-redo)
7867 (org-agenda-set-mode-name)
7868 (message "Deadlines inclusion turned %s"
7869 (if org-agenda-include-deadlines "on" "off")))
7871 (defun org-agenda-toggle-time-grid ()
7872 "Toggle time grid in an agenda buffer."
7873 (interactive)
7874 (org-agenda-check-type t 'agenda)
7875 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7876 (org-agenda-redo)
7877 (org-agenda-set-mode-name)
7878 (message "Time-grid turned %s"
7879 (if org-agenda-use-time-grid "on" "off")))
7881 (defun org-agenda-set-mode-name ()
7882 "Set the mode name to indicate all the small mode settings."
7883 (setq mode-name
7884 (list "Org-Agenda"
7885 (if (get 'org-agenda-files 'org-restrict) " []" "")
7887 '(:eval (org-agenda-span-name org-agenda-current-span))
7888 (if org-agenda-follow-mode " Follow" "")
7889 (if org-agenda-entry-text-mode " ETxt" "")
7890 (if org-agenda-include-diary " Diary" "")
7891 (if org-agenda-include-deadlines " Ddl" "")
7892 (if org-agenda-use-time-grid " Grid" "")
7893 (if (and (boundp 'org-habit-show-habits)
7894 org-habit-show-habits) " Habit" "")
7895 (cond
7896 ((consp org-agenda-show-log) " LogAll")
7897 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7898 (org-agenda-show-log " Log")
7899 (t ""))
7900 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7901 :preset-filter))
7902 '(:eval (org-propertize
7903 (concat " <"
7904 (mapconcat
7905 'identity
7906 (append
7907 (get 'org-agenda-category-filter :preset-filter)
7908 org-agenda-category-filter)
7910 ">")
7911 'face 'org-agenda-filter-category
7912 'help-echo "Category used in filtering"))
7914 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7915 :preset-filter))
7916 '(:eval (org-propertize
7917 (concat " {"
7918 (mapconcat
7919 'identity
7920 (append
7921 (get 'org-agenda-tag-filter :preset-filter)
7922 org-agenda-tag-filter)
7924 "}")
7925 'face 'org-agenda-filter-tags
7926 'help-echo "Tags used in filtering"))
7928 (if org-agenda-archives-mode
7929 (if (eq org-agenda-archives-mode t)
7930 " Archives"
7931 (format " :%s:" org-archive-tag))
7933 (if org-agenda-clockreport-mode
7934 (if (eq org-agenda-clockreport-mode 'with-filter)
7935 " Clock{}" " Clock")
7936 "")))
7937 (force-mode-line-update))
7939 (define-obsolete-function-alias
7940 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7942 (defun org-agenda-update-agenda-type ()
7943 "Update the agenda type after each command."
7944 (setq org-agenda-type
7945 (or (get-text-property (point) 'org-agenda-type)
7946 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7948 (defun org-agenda-next-line ()
7949 "Move cursor to the next line, and show if follow mode is active."
7950 (interactive)
7951 (call-interactively 'next-line)
7952 (org-agenda-do-context-action))
7954 (defun org-agenda-previous-line ()
7955 "Move cursor to the previous line, and show if follow-mode is active."
7956 (interactive)
7957 (call-interactively 'previous-line)
7958 (org-agenda-do-context-action))
7960 (defun org-agenda-next-item (n)
7961 "Move cursor to next agenda item."
7962 (interactive "p")
7963 (let ((col (current-column)))
7964 (dotimes (c n)
7965 (when (next-single-property-change (point-at-eol) 'org-marker)
7966 (move-end-of-line 1)
7967 (goto-char (next-single-property-change (point) 'org-marker))))
7968 (org-move-to-column col))
7969 (org-agenda-do-context-action))
7971 (defun org-agenda-previous-item (n)
7972 "Move cursor to next agenda item."
7973 (interactive "p")
7974 (dotimes (c n)
7975 (let ((col (current-column))
7976 (goto (save-excursion
7977 (move-end-of-line 0)
7978 (previous-single-property-change (point) 'org-marker))))
7979 (if goto (goto-char goto))
7980 (org-move-to-column col)))
7981 (org-agenda-do-context-action))
7983 (defun org-agenda-do-context-action ()
7984 "Show outline path and, maybe, follow mode window."
7985 (let ((m (org-get-at-bol 'org-marker)))
7986 (when (and (markerp m) (marker-buffer m))
7987 (and org-agenda-follow-mode
7988 (if org-agenda-follow-indirect
7989 (org-agenda-tree-to-indirect-buffer nil)
7990 (org-agenda-show)))
7991 (and org-agenda-show-outline-path
7992 (org-with-point-at m (org-display-outline-path t))))))
7994 (defun org-agenda-show-tags ()
7995 "Show the tags applicable to the current item."
7996 (interactive)
7997 (let* ((tags (org-get-at-bol 'tags)))
7998 (if tags
7999 (message "Tags are :%s:"
8000 (org-no-properties (mapconcat 'identity tags ":")))
8001 (message "No tags associated with this line"))))
8003 (defun org-agenda-goto (&optional highlight)
8004 "Go to the Org-mode file which contains the item at point."
8005 (interactive)
8006 (let* ((marker (or (org-get-at-bol 'org-marker)
8007 (org-agenda-error)))
8008 (buffer (marker-buffer marker))
8009 (pos (marker-position marker)))
8010 (switch-to-buffer-other-window buffer)
8011 (widen)
8012 (push-mark)
8013 (goto-char pos)
8014 (when (derived-mode-p 'org-mode)
8015 (org-show-context 'agenda)
8016 (save-excursion
8017 (and (outline-next-heading)
8018 (org-flag-heading nil)))) ; show the next heading
8019 (when (outline-invisible-p)
8020 (show-entry)) ; display invisible text
8021 (recenter (/ (window-height) 2))
8022 (run-hooks 'org-agenda-after-show-hook)
8023 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8025 (defvar org-agenda-after-show-hook nil
8026 "Normal hook run after an item has been shown from the agenda.
8027 Point is in the buffer where the item originated.")
8029 (defun org-agenda-kill ()
8030 "Kill the entry or subtree belonging to the current agenda entry."
8031 (interactive)
8032 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8033 (let* ((bufname-orig (buffer-name))
8034 (marker (or (org-get-at-bol 'org-marker)
8035 (org-agenda-error)))
8036 (buffer (marker-buffer marker))
8037 (pos (marker-position marker))
8038 (type (org-get-at-bol 'type))
8039 dbeg dend (n 0) conf)
8040 (org-with-remote-undo buffer
8041 (with-current-buffer buffer
8042 (save-excursion
8043 (goto-char pos)
8044 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8045 (setq dbeg (progn (org-back-to-heading t) (point))
8046 dend (org-end-of-subtree t t))
8047 (setq dbeg (point-at-bol)
8048 dend (min (point-max) (1+ (point-at-eol)))))
8049 (goto-char dbeg)
8050 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8051 (setq conf (or (eq t org-agenda-confirm-kill)
8052 (and (numberp org-agenda-confirm-kill)
8053 (> n org-agenda-confirm-kill))))
8054 (and conf
8055 (not (y-or-n-p
8056 (format "Delete entry with %d lines in buffer \"%s\"? "
8057 n (buffer-name buffer))))
8058 (error "Abort"))
8059 (let ((org-agenda-buffer-name bufname-orig))
8060 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8061 (with-current-buffer buffer (delete-region dbeg dend))
8062 (message "Agenda item and source killed"))))
8064 (defvar org-archive-default-command) ; defined in org-archive.el
8065 (defun org-agenda-archive-default ()
8066 "Archive the entry or subtree belonging to the current agenda entry."
8067 (interactive)
8068 (require 'org-archive)
8069 (org-agenda-archive-with org-archive-default-command))
8071 (defun org-agenda-archive-default-with-confirmation ()
8072 "Archive the entry or subtree belonging to the current agenda entry."
8073 (interactive)
8074 (require 'org-archive)
8075 (org-agenda-archive-with org-archive-default-command 'confirm))
8077 (defun org-agenda-archive ()
8078 "Archive the entry or subtree belonging to the current agenda entry."
8079 (interactive)
8080 (org-agenda-archive-with 'org-archive-subtree))
8082 (defun org-agenda-archive-to-archive-sibling ()
8083 "Move the entry to the archive sibling."
8084 (interactive)
8085 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8087 (defun org-agenda-archive-with (cmd &optional confirm)
8088 "Move the entry to the archive sibling."
8089 (interactive)
8090 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8091 (let* ((bufname-orig (buffer-name))
8092 (marker (or (org-get-at-bol 'org-marker)
8093 (org-agenda-error)))
8094 (buffer (marker-buffer marker))
8095 (pos (marker-position marker)))
8096 (org-with-remote-undo buffer
8097 (with-current-buffer buffer
8098 (if (derived-mode-p 'org-mode)
8099 (if (and confirm
8100 (not (y-or-n-p "Archive this subtree or entry? ")))
8101 (error "Abort")
8102 (save-excursion
8103 (goto-char pos)
8104 (let ((org-agenda-buffer-name bufname-orig))
8105 (org-remove-subtree-entries-from-agenda))
8106 (org-back-to-heading t)
8107 (funcall cmd)))
8108 (error "Archiving works only in Org-mode files"))))))
8110 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8111 "Remove all lines in the agenda that correspond to a given subtree.
8112 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8113 If this information is not given, the function uses the tree at point."
8114 (let ((buf (or buf (current-buffer))) m p)
8115 (save-excursion
8116 (unless (and beg end)
8117 (org-back-to-heading t)
8118 (setq beg (point))
8119 (org-end-of-subtree t)
8120 (setq end (point)))
8121 (set-buffer (get-buffer org-agenda-buffer-name))
8122 (save-excursion
8123 (goto-char (point-max))
8124 (beginning-of-line 1)
8125 (while (not (bobp))
8126 (when (and (setq m (org-get-at-bol 'org-marker))
8127 (equal buf (marker-buffer m))
8128 (setq p (marker-position m))
8129 (>= p beg)
8130 (< p end))
8131 (let ((inhibit-read-only t))
8132 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8133 (beginning-of-line 0))))))
8135 (defun org-agenda-refile (&optional goto rfloc no-update)
8136 "Refile the item at point."
8137 (interactive "P")
8138 (if (equal goto '(16))
8139 (org-refile-goto-last-stored)
8140 (let* ((buffer-orig (buffer-name))
8141 (marker (or (org-get-at-bol 'org-hd-marker)
8142 (org-agenda-error)))
8143 (buffer (marker-buffer marker))
8144 (pos (marker-position marker))
8145 (rfloc (or rfloc
8146 (org-refile-get-location
8147 (if goto "Goto" "Refile to") buffer
8148 org-refile-allow-creating-parent-nodes))))
8149 (with-current-buffer buffer
8150 (save-excursion
8151 (save-restriction
8152 (widen)
8153 (goto-char marker)
8154 (let ((org-agenda-buffer-name buffer-orig))
8155 (org-remove-subtree-entries-from-agenda))
8156 (org-refile goto buffer rfloc)))))
8157 (unless no-update (org-agenda-redo))))
8159 (defun org-agenda-open-link (&optional arg)
8160 "Open the link(s) in the current entry, if any.
8161 This looks for a link in the displayed line in the agenda.
8162 It also looks at the text of the entry itself."
8163 (interactive "P")
8164 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8165 (org-get-at-bol 'org-marker)))
8166 (buffer (and marker (marker-buffer marker)))
8167 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8168 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8169 (lk0 (car lkall))
8170 (lk (if (stringp lk0) (list lk0) lk0))
8171 (lkend (cdr lkall))
8172 trg)
8173 (cond
8174 ((and buffer lk)
8175 (mapcar (lambda(l)
8176 (with-current-buffer buffer
8177 (setq trg (and (string-match org-bracket-link-regexp l)
8178 (match-string 1 l)))
8179 (if (or (not trg) (string-match org-any-link-re trg))
8180 (save-excursion
8181 (save-restriction
8182 (widen)
8183 (goto-char marker)
8184 (when (search-forward l nil lkend)
8185 (goto-char (match-beginning 0))
8186 (org-open-at-point))))
8187 ;; This is an internal link, widen the buffer
8188 (switch-to-buffer-other-window buffer)
8189 (widen)
8190 (goto-char marker)
8191 (when (search-forward l nil lkend)
8192 (goto-char (match-beginning 0))
8193 (org-open-at-point)))))
8194 lk))
8195 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8196 (save-excursion
8197 (beginning-of-line 1)
8198 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8199 (org-open-link-from-string (match-string 1)))
8200 (t (message "No link to open here")))))
8202 (defun org-agenda-copy-local-variable (var)
8203 "Get a variable from a referenced buffer and install it here."
8204 (let ((m (org-get-at-bol 'org-marker)))
8205 (when (and m (buffer-live-p (marker-buffer m)))
8206 (org-set-local var (with-current-buffer (marker-buffer m)
8207 (symbol-value var))))))
8209 (defun org-agenda-switch-to (&optional delete-other-windows)
8210 "Go to the Org-mode file which contains the item at point."
8211 (interactive)
8212 (if (and org-return-follows-link
8213 (not (org-get-at-bol 'org-marker))
8214 (org-in-regexp org-bracket-link-regexp))
8215 (org-open-link-from-string (match-string 0))
8216 (let* ((marker (or (org-get-at-bol 'org-marker)
8217 (org-agenda-error)))
8218 (buffer (marker-buffer marker))
8219 (pos (marker-position marker)))
8220 (org-pop-to-buffer-same-window buffer)
8221 (and delete-other-windows (delete-other-windows))
8222 (widen)
8223 (goto-char pos)
8224 (when (derived-mode-p 'org-mode)
8225 (org-show-context 'agenda)
8226 (save-excursion
8227 (and (outline-next-heading)
8228 (org-flag-heading nil))) ; show the next heading
8229 (when (outline-invisible-p)
8230 (show-entry)) ; display invisible text
8231 (run-hooks 'org-agenda-after-show-hook)))))
8233 (defun org-agenda-goto-mouse (ev)
8234 "Go to the Org-mode file which contains the item at the mouse click."
8235 (interactive "e")
8236 (mouse-set-point ev)
8237 (org-agenda-goto))
8239 (defun org-agenda-show (&optional full-entry)
8240 "Display the Org-mode file which contains the item at point.
8241 With prefix argument FULL-ENTRY, make the entire entry visible
8242 if it was hidden in the outline."
8243 (interactive "P")
8244 (let ((win (selected-window)))
8245 (if full-entry
8246 (let ((org-show-entry-below t))
8247 (org-agenda-goto t))
8248 (org-agenda-goto t))
8249 (select-window win)))
8251 (defvar org-agenda-show-window nil)
8252 (defun org-agenda-show-and-scroll-up (&optional arg)
8253 "Display the Org-mode file which contains the item at point.
8254 When called repeatedly, scroll the window that is displaying the buffer.
8255 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8256 `show-subtree' to display the item, so that drawers and logbooks stay
8257 folded."
8258 (interactive "P")
8259 (let ((win (selected-window)))
8260 (if (and (window-live-p org-agenda-show-window)
8261 (eq this-command last-command))
8262 (progn
8263 (select-window org-agenda-show-window)
8264 (ignore-errors (scroll-up)))
8265 (org-agenda-goto t)
8266 (if arg (org-show-entry) (show-subtree))
8267 (setq org-agenda-show-window (selected-window)))
8268 (select-window win)))
8270 (defun org-agenda-show-scroll-down ()
8271 "Scroll down the window showing the agenda."
8272 (interactive)
8273 (let ((win (selected-window)))
8274 (when (window-live-p org-agenda-show-window)
8275 (select-window org-agenda-show-window)
8276 (ignore-errors (scroll-down))
8277 (select-window win))))
8279 (defun org-agenda-show-1 (&optional more)
8280 "Display the Org-mode file which contains the item at point.
8281 The prefix arg selects the amount of information to display:
8283 0 hide the subtree
8284 1 just show the entry according to defaults.
8285 2 show the children view
8286 3 show the subtree view
8287 4 show the entire subtree and any LOGBOOK drawers
8288 5 show the entire subtree and any drawers
8289 With prefix argument FULL-ENTRY, make the entire entry visible
8290 if it was hidden in the outline."
8291 (interactive "p")
8292 (let ((win (selected-window)))
8293 (org-agenda-goto t)
8294 (org-recenter-heading 1)
8295 (cond
8296 ((= more 0)
8297 (hide-subtree)
8298 (save-excursion
8299 (org-back-to-heading)
8300 (run-hook-with-args 'org-cycle-hook 'folded))
8301 (message "Remote: FOLDED"))
8302 ((and (org-called-interactively-p 'any) (= more 1))
8303 (message "Remote: show with default settings"))
8304 ((= more 2)
8305 (show-entry)
8306 (show-children)
8307 (save-excursion
8308 (org-back-to-heading)
8309 (run-hook-with-args 'org-cycle-hook 'children))
8310 (message "Remote: CHILDREN"))
8311 ((= more 3)
8312 (show-subtree)
8313 (save-excursion
8314 (org-back-to-heading)
8315 (run-hook-with-args 'org-cycle-hook 'subtree))
8316 (message "Remote: SUBTREE"))
8317 ((= more 4)
8318 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8319 (org-drawer-regexp
8320 (concat "^[ \t]*:\\("
8321 (mapconcat 'regexp-quote org-drawers "\\|")
8322 "\\):[ \t]*$")))
8323 (show-subtree)
8324 (save-excursion
8325 (org-back-to-heading)
8326 (org-cycle-hide-drawers 'subtree)))
8327 (message "Remote: SUBTREE AND LOGBOOK"))
8328 ((> more 4)
8329 (show-subtree)
8330 (message "Remote: SUBTREE AND ALL DRAWERS")))
8331 (select-window win)))
8333 (defun org-recenter-heading (n)
8334 (save-excursion
8335 (org-back-to-heading)
8336 (recenter n)))
8338 (defvar org-agenda-cycle-counter nil)
8339 (defun org-agenda-cycle-show (&optional n)
8340 "Show the current entry in another window, with default settings.
8341 Default settings are taken from `org-show-hierarchy-above' and siblings.
8342 When use repeatedly in immediate succession, the remote entry will cycle
8343 through visibility
8345 children -> subtree -> folded
8347 When called with a numeric prefix arg, that arg will be passed through to
8348 `org-agenda-show-1'. For the interpretation of that argument, see the
8349 docstring of `org-agenda-show-1'."
8350 (interactive "P")
8351 (if (integerp n)
8352 (setq org-agenda-cycle-counter n)
8353 (if (not (eq last-command this-command))
8354 (setq org-agenda-cycle-counter 1)
8355 (if (equal org-agenda-cycle-counter 0)
8356 (setq org-agenda-cycle-counter 2)
8357 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8358 (if (> org-agenda-cycle-counter 3)
8359 (setq org-agenda-cycle-counter 0)))))
8360 (org-agenda-show-1 org-agenda-cycle-counter))
8362 (defun org-agenda-recenter (arg)
8363 "Display the Org-mode file which contains the item at point and recenter."
8364 (interactive "P")
8365 (let ((win (selected-window)))
8366 (org-agenda-goto t)
8367 (recenter arg)
8368 (select-window win)))
8370 (defun org-agenda-show-mouse (ev)
8371 "Display the Org-mode file which contains the item at the mouse click."
8372 (interactive "e")
8373 (mouse-set-point ev)
8374 (org-agenda-show))
8376 (defun org-agenda-check-no-diary ()
8377 "Check if the entry is a diary link and abort if yes."
8378 (if (org-get-at-bol 'org-agenda-diary-link)
8379 (org-agenda-error)))
8381 (defun org-agenda-error ()
8382 (error "Command not allowed in this line"))
8384 (defun org-agenda-tree-to-indirect-buffer (arg)
8385 "Show the subtree corresponding to the current entry in an indirect buffer.
8386 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8388 With a numerical prefix ARG, go up to this level and then take that tree.
8389 With a negative numeric ARG, go up by this number of levels.
8390 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8391 use the dedicated frame)."
8392 (interactive "P")
8393 (if current-prefix-arg
8394 (org-agenda-do-tree-to-indirect-buffer arg)
8395 (let ((agenda-buffer (buffer-name))
8396 (agenda-window (selected-window))
8397 (indirect-window
8398 (and org-last-indirect-buffer
8399 (get-buffer-window org-last-indirect-buffer))))
8400 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8401 (unless (or (eq org-indirect-buffer-display 'new-frame)
8402 (eq org-indirect-buffer-display 'dedicated-frame))
8403 (unwind-protect
8404 (unless (and indirect-window (window-live-p indirect-window))
8405 (setq indirect-window (split-window agenda-window)))
8406 (and indirect-window (select-window indirect-window))
8407 (switch-to-buffer org-last-indirect-buffer :norecord)
8408 (fit-window-to-buffer indirect-window)))
8409 (select-window (get-buffer-window agenda-buffer)))))
8411 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8412 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8413 (org-agenda-check-no-diary)
8414 (let* ((marker (or (org-get-at-bol 'org-marker)
8415 (org-agenda-error)))
8416 (buffer (marker-buffer marker))
8417 (pos (marker-position marker)))
8418 (with-current-buffer buffer
8419 (save-excursion
8420 (goto-char pos)
8421 (funcall 'org-tree-to-indirect-buffer arg)))))
8423 (defvar org-last-heading-marker (make-marker)
8424 "Marker pointing to the headline that last changed its TODO state
8425 by a remote command from the agenda.")
8427 (defun org-agenda-todo-nextset ()
8428 "Switch TODO entry to next sequence."
8429 (interactive)
8430 (org-agenda-todo 'nextset))
8432 (defun org-agenda-todo-previousset ()
8433 "Switch TODO entry to previous sequence."
8434 (interactive)
8435 (org-agenda-todo 'previousset))
8437 (defun org-agenda-todo (&optional arg)
8438 "Cycle TODO state of line at point, also in Org-mode file.
8439 This changes the line at point, all other lines in the agenda referring to
8440 the same tree node, and the headline of the tree node in the Org-mode file."
8441 (interactive "P")
8442 (org-agenda-check-no-diary)
8443 (let* ((col (current-column))
8444 (marker (or (org-get-at-bol 'org-marker)
8445 (org-agenda-error)))
8446 (buffer (marker-buffer marker))
8447 (pos (marker-position marker))
8448 (hdmarker (org-get-at-bol 'org-hd-marker))
8449 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8450 (inhibit-read-only t)
8451 org-agenda-headline-snapshot-before-repeat newhead just-one)
8452 (org-with-remote-undo buffer
8453 (with-current-buffer buffer
8454 (widen)
8455 (goto-char pos)
8456 (org-show-context 'agenda)
8457 (save-excursion
8458 (and (outline-next-heading)
8459 (org-flag-heading nil))) ; show the next heading
8460 (let ((current-prefix-arg arg))
8461 (call-interactively 'org-todo))
8462 (and (bolp) (forward-char 1))
8463 (setq newhead (org-get-heading))
8464 (when (and (org-bound-and-true-p
8465 org-agenda-headline-snapshot-before-repeat)
8466 (not (equal org-agenda-headline-snapshot-before-repeat
8467 newhead))
8468 todayp)
8469 (setq newhead org-agenda-headline-snapshot-before-repeat
8470 just-one t))
8471 (save-excursion
8472 (org-back-to-heading)
8473 (move-marker org-last-heading-marker (point))))
8474 (beginning-of-line 1)
8475 (save-excursion
8476 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8477 (org-move-to-column col))))
8479 (defun org-agenda-add-note (&optional arg)
8480 "Add a time-stamped note to the entry at point."
8481 (interactive "P")
8482 (org-agenda-check-no-diary)
8483 (let* ((marker (or (org-get-at-bol 'org-marker)
8484 (org-agenda-error)))
8485 (buffer (marker-buffer marker))
8486 (pos (marker-position marker))
8487 (hdmarker (org-get-at-bol 'org-hd-marker))
8488 (inhibit-read-only t))
8489 (with-current-buffer buffer
8490 (widen)
8491 (goto-char pos)
8492 (org-show-context 'agenda)
8493 (save-excursion
8494 (and (outline-next-heading)
8495 (org-flag-heading nil))) ; show the next heading
8496 (org-add-note))))
8498 (defun org-agenda-change-all-lines (newhead hdmarker
8499 &optional fixface just-this)
8500 "Change all lines in the agenda buffer which match HDMARKER.
8501 The new content of the line will be NEWHEAD (as modified by
8502 `org-agenda-format-item'). HDMARKER is checked with
8503 `equal' against all `org-hd-marker' text properties in the file.
8504 If FIXFACE is non-nil, the face of each item is modified according to
8505 the new TODO state.
8506 If JUST-THIS is non-nil, change just the current line, not all.
8507 If FORCE-TAGS is non nil, the car of it returns the new tags."
8508 (let* ((inhibit-read-only t)
8509 (line (org-current-line))
8510 (org-agenda-buffer (current-buffer))
8511 (thetags (with-current-buffer (marker-buffer hdmarker)
8512 (save-excursion (save-restriction (widen)
8513 (goto-char hdmarker)
8514 (org-get-tags-at)))))
8515 props m pl undone-face done-face finish new dotime level cat tags)
8516 (save-excursion
8517 (goto-char (point-max))
8518 (beginning-of-line 1)
8519 (while (not finish)
8520 (setq finish (bobp))
8521 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8522 (or (not just-this) (= (org-current-line) line))
8523 (equal m hdmarker))
8524 (setq props (text-properties-at (point))
8525 dotime (org-get-at-bol 'dotime)
8526 cat (org-get-at-bol 'org-category)
8527 level (org-get-at-bol 'level)
8528 tags thetags
8530 (let ((org-prefix-format-compiled
8531 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8532 org-prefix-format-compiled))
8533 (extra (org-get-at-bol 'extra)))
8534 (with-current-buffer (marker-buffer hdmarker)
8535 (save-excursion
8536 (save-restriction
8537 (widen)
8538 (org-agenda-format-item extra newhead level cat tags dotime)))))
8539 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8540 undone-face (org-get-at-bol 'undone-face)
8541 done-face (org-get-at-bol 'done-face))
8542 (beginning-of-line 1)
8543 (cond
8544 ((equal new "")
8545 (and (looking-at ".*\n?") (replace-match "")))
8546 ((looking-at ".*")
8547 (replace-match new t t)
8548 (beginning-of-line 1)
8549 (add-text-properties (point-at-bol) (point-at-eol) props)
8550 (when fixface
8551 (add-text-properties
8552 (point-at-bol) (point-at-eol)
8553 (list 'face
8554 (if org-last-todo-state-is-todo
8555 undone-face done-face))))
8556 (org-agenda-highlight-todo 'line)
8557 (beginning-of-line 1))
8558 (t (error "Line update did not work")))
8559 (save-restriction
8560 (narrow-to-region (point-at-bol) (point-at-eol))
8561 (org-agenda-finalize)))
8562 (beginning-of-line 0)))))
8564 (defun org-agenda-align-tags (&optional line)
8565 "Align all tags in agenda items to `org-agenda-tags-column'."
8566 (let ((inhibit-read-only t) l c)
8567 (save-excursion
8568 (goto-char (if line (point-at-bol) (point-min)))
8569 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8570 (if line (point-at-eol) nil) t)
8571 (add-text-properties
8572 (match-beginning 2) (match-end 2)
8573 (list 'face (delq nil (let ((prop (get-text-property
8574 (match-beginning 2) 'face)))
8575 (or (listp prop) (setq prop (list prop)))
8576 (if (memq 'org-tag prop)
8577 prop
8578 (cons 'org-tag prop))))))
8579 (setq l (- (match-end 2) (match-beginning 2))
8580 c (if (< org-agenda-tags-column 0)
8581 (- (abs org-agenda-tags-column) l)
8582 org-agenda-tags-column))
8583 (delete-region (match-beginning 1) (match-end 1))
8584 (goto-char (match-beginning 1))
8585 (insert (org-add-props
8586 (make-string (max 1 (- c (current-column))) ?\ )
8587 (plist-put (copy-sequence (text-properties-at (point)))
8588 'face nil))))
8589 (goto-char (point-min))
8590 (org-font-lock-add-tag-faces (point-max)))))
8592 (defun org-agenda-priority-up ()
8593 "Increase the priority of line at point, also in Org-mode file."
8594 (interactive)
8595 (org-agenda-priority 'up))
8597 (defun org-agenda-priority-down ()
8598 "Decrease the priority of line at point, also in Org-mode file."
8599 (interactive)
8600 (org-agenda-priority 'down))
8602 (defun org-agenda-priority (&optional force-direction)
8603 "Set the priority of line at point, also in Org-mode file.
8604 This changes the line at point, all other lines in the agenda referring to
8605 the same tree node, and the headline of the tree node in the Org-mode file.
8606 Called with a universal prefix arg, show the priority instead of setting it."
8607 (interactive "P")
8608 (if (equal force-direction '(4))
8609 (org-show-priority)
8610 (unless org-enable-priority-commands
8611 (error "Priority commands are disabled"))
8612 (org-agenda-check-no-diary)
8613 (let* ((marker (or (org-get-at-bol 'org-marker)
8614 (org-agenda-error)))
8615 (hdmarker (org-get-at-bol 'org-hd-marker))
8616 (buffer (marker-buffer hdmarker))
8617 (pos (marker-position hdmarker))
8618 (inhibit-read-only t)
8619 newhead)
8620 (org-with-remote-undo buffer
8621 (with-current-buffer buffer
8622 (widen)
8623 (goto-char pos)
8624 (org-show-context 'agenda)
8625 (save-excursion
8626 (and (outline-next-heading)
8627 (org-flag-heading nil))) ; show the next heading
8628 (funcall 'org-priority force-direction)
8629 (end-of-line 1)
8630 (setq newhead (org-get-heading)))
8631 (org-agenda-change-all-lines newhead hdmarker)
8632 (beginning-of-line 1)))))
8634 ;; FIXME: should fix the tags property of the agenda line.
8635 (defun org-agenda-set-tags (&optional tag onoff)
8636 "Set tags for the current headline."
8637 (interactive)
8638 (org-agenda-check-no-diary)
8639 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8640 (call-interactively 'org-change-tag-in-region)
8641 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8642 (org-agenda-error)))
8643 (buffer (marker-buffer hdmarker))
8644 (pos (marker-position hdmarker))
8645 (inhibit-read-only t)
8646 newhead)
8647 (org-with-remote-undo buffer
8648 (with-current-buffer buffer
8649 (widen)
8650 (goto-char pos)
8651 (save-excursion
8652 (org-show-context 'agenda))
8653 (save-excursion
8654 (and (outline-next-heading)
8655 (org-flag-heading nil))) ; show the next heading
8656 (goto-char pos)
8657 (if tag
8658 (org-toggle-tag tag onoff)
8659 (call-interactively 'org-set-tags))
8660 (end-of-line 1)
8661 (setq newhead (org-get-heading)))
8662 (org-agenda-change-all-lines newhead hdmarker)
8663 (beginning-of-line 1)))))
8665 (defun org-agenda-set-property ()
8666 "Set a property for the current headline."
8667 (interactive)
8668 (org-agenda-check-no-diary)
8669 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8670 (org-agenda-error)))
8671 (buffer (marker-buffer hdmarker))
8672 (pos (marker-position hdmarker))
8673 (inhibit-read-only t)
8674 newhead)
8675 (org-with-remote-undo buffer
8676 (with-current-buffer buffer
8677 (widen)
8678 (goto-char pos)
8679 (save-excursion
8680 (org-show-context 'agenda))
8681 (save-excursion
8682 (and (outline-next-heading)
8683 (org-flag-heading nil))) ; show the next heading
8684 (goto-char pos)
8685 (call-interactively 'org-set-property)))))
8687 (defun org-agenda-set-effort ()
8688 "Set the effort property for the current headline."
8689 (interactive)
8690 (org-agenda-check-no-diary)
8691 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8692 (org-agenda-error)))
8693 (buffer (marker-buffer hdmarker))
8694 (pos (marker-position hdmarker))
8695 (inhibit-read-only t)
8696 newhead)
8697 (org-with-remote-undo buffer
8698 (with-current-buffer buffer
8699 (widen)
8700 (goto-char pos)
8701 (save-excursion
8702 (org-show-context 'agenda))
8703 (save-excursion
8704 (and (outline-next-heading)
8705 (org-flag-heading nil))) ; show the next heading
8706 (goto-char pos)
8707 (call-interactively 'org-set-effort)
8708 (end-of-line 1)
8709 (setq newhead (org-get-heading)))
8710 (org-agenda-change-all-lines newhead hdmarker))))
8712 (defun org-agenda-toggle-archive-tag ()
8713 "Toggle the archive tag for the current entry."
8714 (interactive)
8715 (org-agenda-check-no-diary)
8716 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8717 (org-agenda-error)))
8718 (buffer (marker-buffer hdmarker))
8719 (pos (marker-position hdmarker))
8720 (inhibit-read-only t)
8721 newhead)
8722 (org-with-remote-undo buffer
8723 (with-current-buffer buffer
8724 (widen)
8725 (goto-char pos)
8726 (org-show-context 'agenda)
8727 (save-excursion
8728 (and (outline-next-heading)
8729 (org-flag-heading nil))) ; show the next heading
8730 (call-interactively 'org-toggle-archive-tag)
8731 (end-of-line 1)
8732 (setq newhead (org-get-heading)))
8733 (org-agenda-change-all-lines newhead hdmarker)
8734 (beginning-of-line 1))))
8736 (defun org-agenda-do-date-later (arg)
8737 (interactive "P")
8738 (cond
8739 ((or (equal arg '(16))
8740 (memq last-command
8741 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8742 (setq this-command 'org-agenda-date-later-minutes)
8743 (org-agenda-date-later-minutes 1))
8744 ((or (equal arg '(4))
8745 (memq last-command
8746 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8747 (setq this-command 'org-agenda-date-later-hours)
8748 (org-agenda-date-later-hours 1))
8750 (org-agenda-date-later (prefix-numeric-value arg)))))
8752 (defun org-agenda-do-date-earlier (arg)
8753 (interactive "P")
8754 (cond
8755 ((or (equal arg '(16))
8756 (memq last-command
8757 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8758 (setq this-command 'org-agenda-date-earlier-minutes)
8759 (org-agenda-date-earlier-minutes 1))
8760 ((or (equal arg '(4))
8761 (memq last-command
8762 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8763 (setq this-command 'org-agenda-date-earlier-hours)
8764 (org-agenda-date-earlier-hours 1))
8766 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8768 (defun org-agenda-date-later (arg &optional what)
8769 "Change the date of this item to ARG day(s) later."
8770 (interactive "p")
8771 (org-agenda-check-type t 'agenda 'timeline)
8772 (org-agenda-check-no-diary)
8773 (let* ((marker (or (org-get-at-bol 'org-marker)
8774 (org-agenda-error)))
8775 (buffer (marker-buffer marker))
8776 (pos (marker-position marker))
8777 cdate today)
8778 (org-with-remote-undo buffer
8779 (with-current-buffer buffer
8780 (widen)
8781 (goto-char pos)
8782 (if (not (org-at-timestamp-p))
8783 (error "Cannot find time stamp"))
8784 (when (and org-agenda-move-date-from-past-immediately-to-today
8785 (equal arg 1)
8786 (or (not what) (eq what 'day))
8787 (not (save-match-data (org-at-date-range-p))))
8788 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8789 cdate (calendar-absolute-from-gregorian
8790 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8791 today (org-today))
8792 (if (> today cdate)
8793 ;; immediately shift to today
8794 (setq arg (- today cdate))))
8795 (org-timestamp-change arg (or what 'day))
8796 (when (and (org-at-date-range-p)
8797 (re-search-backward org-tr-regexp-both (point-at-bol)))
8798 (let ((end org-last-changed-timestamp))
8799 (org-timestamp-change arg (or what 'day))
8800 (setq org-last-changed-timestamp
8801 (concat org-last-changed-timestamp "--" end)))))
8802 (org-agenda-show-new-time marker org-last-changed-timestamp))
8803 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8805 (defun org-agenda-date-earlier (arg &optional what)
8806 "Change the date of this item to ARG day(s) earlier."
8807 (interactive "p")
8808 (org-agenda-date-later (- arg) what))
8810 (defun org-agenda-date-later-minutes (arg)
8811 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8812 (interactive "p")
8813 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8814 (org-agenda-date-later arg 'minute))
8816 (defun org-agenda-date-earlier-minutes (arg)
8817 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8818 (interactive "p")
8819 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8820 (org-agenda-date-earlier arg 'minute))
8822 (defun org-agenda-date-later-hours (arg)
8823 "Change the time of this item, in hour steps."
8824 (interactive "p")
8825 (org-agenda-date-later arg 'hour))
8827 (defun org-agenda-date-earlier-hours (arg)
8828 "Change the time of this item, in hour steps."
8829 (interactive "p")
8830 (org-agenda-date-earlier arg 'hour))
8832 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8833 "Show new date stamp via text properties."
8834 ;; We use text properties to make this undoable
8835 (let ((inhibit-read-only t))
8836 (setq stamp (concat prefix " => " stamp " "))
8837 (save-excursion
8838 (goto-char (point-max))
8839 (while (not (bobp))
8840 (when (equal marker (org-get-at-bol 'org-marker))
8841 (org-move-to-column (- (window-width) (length stamp)) t)
8842 (org-agenda-fix-tags-filter-overlays-at (point))
8843 (if (featurep 'xemacs)
8844 ;; Use `duplicable' property to trigger undo recording
8845 (let ((ex (make-extent nil nil))
8846 (gl (make-glyph stamp)))
8847 (set-glyph-face gl 'secondary-selection)
8848 (set-extent-properties
8849 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8850 (insert-extent ex (1- (point)) (point-at-eol)))
8851 (add-text-properties
8852 (1- (point)) (point-at-eol)
8853 (list 'display (org-add-props stamp nil
8854 'face 'secondary-selection))))
8855 (beginning-of-line 1))
8856 (beginning-of-line 0)))))
8858 (defun org-agenda-date-prompt (arg)
8859 "Change the date of this item. Date is prompted for, with default today.
8860 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8861 be used to request time specification in the time stamp."
8862 (interactive "P")
8863 (org-agenda-check-type t 'agenda 'timeline)
8864 (org-agenda-check-no-diary)
8865 (let* ((marker (or (org-get-at-bol 'org-marker)
8866 (org-agenda-error)))
8867 (buffer (marker-buffer marker))
8868 (pos (marker-position marker)))
8869 (org-with-remote-undo buffer
8870 (with-current-buffer buffer
8871 (widen)
8872 (goto-char pos)
8873 (if (not (org-at-timestamp-p t))
8874 (error "Cannot find time stamp"))
8875 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8876 (org-agenda-show-new-time marker org-last-changed-timestamp))
8877 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8879 (defun org-agenda-schedule (arg &optional time)
8880 "Schedule the item at point.
8881 ARG is passed through to `org-schedule'."
8882 (interactive "P")
8883 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8884 (org-agenda-check-no-diary)
8885 (let* ((marker (or (org-get-at-bol 'org-marker)
8886 (org-agenda-error)))
8887 (type (marker-insertion-type marker))
8888 (buffer (marker-buffer marker))
8889 (pos (marker-position marker))
8890 (org-insert-labeled-timestamps-at-point nil)
8892 (set-marker-insertion-type marker t)
8893 (org-with-remote-undo buffer
8894 (with-current-buffer buffer
8895 (widen)
8896 (goto-char pos)
8897 (setq ts (org-schedule arg time)))
8898 (org-agenda-show-new-time marker ts " S"))
8899 (message "%s" ts)))
8901 (defun org-agenda-deadline (arg &optional time)
8902 "Schedule the item at point.
8903 ARG is passed through to `org-deadline'."
8904 (interactive "P")
8905 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8906 (org-agenda-check-no-diary)
8907 (let* ((marker (or (org-get-at-bol 'org-marker)
8908 (org-agenda-error)))
8909 (buffer (marker-buffer marker))
8910 (pos (marker-position marker))
8911 (org-insert-labeled-timestamps-at-point nil)
8913 (org-with-remote-undo buffer
8914 (with-current-buffer buffer
8915 (widen)
8916 (goto-char pos)
8917 (setq ts (org-deadline arg time)))
8918 (org-agenda-show-new-time marker ts " D"))
8919 (message "%s" ts)))
8921 (defun org-agenda-clock-in (&optional arg)
8922 "Start the clock on the currently selected item."
8923 (interactive "P")
8924 (org-agenda-check-no-diary)
8925 (if (equal arg '(4))
8926 (org-clock-in arg)
8927 (let* ((marker (or (org-get-at-bol 'org-marker)
8928 (org-agenda-error)))
8929 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
8930 (pos (marker-position marker))
8931 (col (current-column))
8932 newhead)
8933 (org-with-remote-undo (marker-buffer marker)
8934 (with-current-buffer (marker-buffer marker)
8935 (widen)
8936 (goto-char pos)
8937 (org-show-context 'agenda)
8938 (org-show-entry)
8939 (org-cycle-hide-drawers 'children)
8940 (org-clock-in arg)
8941 (setq newhead (org-get-heading)))
8942 (org-agenda-change-all-lines newhead hdmarker))
8943 (org-move-to-column col))))
8945 (defun org-agenda-clock-out ()
8946 "Stop the currently running clock."
8947 (interactive)
8948 (unless (marker-buffer org-clock-marker)
8949 (error "No running clock"))
8950 (let ((marker (make-marker)) (col (current-column)) newhead)
8951 (org-with-remote-undo (marker-buffer org-clock-marker)
8952 (with-current-buffer (marker-buffer org-clock-marker)
8953 (save-excursion
8954 (save-restriction
8955 (widen)
8956 (goto-char org-clock-marker)
8957 (org-back-to-heading t)
8958 (move-marker marker (point))
8959 (org-clock-out)
8960 (setq newhead (org-get-heading))))))
8961 (org-agenda-change-all-lines newhead marker)
8962 (move-marker marker nil)
8963 (org-move-to-column col)
8964 (org-agenda-unmark-clocking-task)))
8966 (defun org-agenda-clock-cancel (&optional arg)
8967 "Cancel the currently running clock."
8968 (interactive "P")
8969 (unless (marker-buffer org-clock-marker)
8970 (error "No running clock"))
8971 (org-with-remote-undo (marker-buffer org-clock-marker)
8972 (org-clock-cancel)))
8974 (defun org-agenda-clock-goto ()
8975 "Jump to the currently clocked in task within the agenda.
8976 If the currently clocked in task is not listed in the agenda
8977 buffer, display it in another window."
8978 (interactive)
8979 (let (pos)
8980 (mapc (lambda (o)
8981 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8982 (setq pos (overlay-start o))))
8983 (overlays-in (point-min) (point-max)))
8984 (cond (pos (goto-char pos))
8985 ;; If the currently clocked entry is not in the agenda
8986 ;; buffer, we visit it in another window:
8987 (org-clock-current-task
8988 (org-switch-to-buffer-other-window (org-clock-goto)))
8989 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8991 (defun org-agenda-diary-entry-in-org-file ()
8992 "Make a diary entry in the file `org-agenda-diary-file'."
8993 (let (d1 d2 char (text "") dp1 dp2)
8994 (if (equal (buffer-name) "*Calendar*")
8995 (setq d1 (calendar-cursor-to-date t)
8996 d2 (car calendar-mark-ring))
8997 (setq dp1 (get-text-property (point-at-bol) 'day))
8998 (unless dp1 (error "No date defined in current line"))
8999 (setq d1 (calendar-gregorian-from-absolute dp1)
9000 d2 (and (ignore-errors (mark))
9001 (save-excursion
9002 (goto-char (mark))
9003 (setq dp2 (get-text-property (point-at-bol) 'day)))
9004 (calendar-gregorian-from-absolute dp2))))
9005 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9006 (setq char (read-char-exclusive))
9007 (cond
9008 ((equal char ?d)
9009 (setq text (read-string "Day entry: "))
9010 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9011 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9012 ((equal char ?a)
9013 (setq d1 (list (car d1) (nth 1 d1)
9014 (read-number (format "Reference year [%d]: " (nth 2 d1))
9015 (nth 2 d1))))
9016 (setq text (read-string "Anniversary (use %d to show years): "))
9017 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9018 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9019 ((equal char ?b)
9020 (setq text (read-string "Block entry: "))
9021 (unless (and d1 d2 (not (equal d1 d2)))
9022 (error "No block of days selected"))
9023 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9024 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9025 ((equal char ?j)
9026 (org-switch-to-buffer-other-window
9027 (find-file-noselect org-agenda-diary-file))
9028 (require 'org-datetree)
9029 (org-datetree-find-date-create d1)
9030 (org-reveal t))
9031 (t (error "Invalid selection character `%c'" char)))))
9033 (defcustom org-agenda-insert-diary-strategy 'date-tree
9034 "Where in `org-agenda-diary-file' should new entries be added?
9035 Valid values:
9037 date-tree in the date tree, as child of the date
9038 top-level as top-level entries at the end of the file."
9039 :group 'org-agenda
9040 :type '(choice
9041 (const :tag "in a date tree" date-tree)
9042 (const :tag "as top level at end of file" top-level)))
9044 (defcustom org-agenda-insert-diary-extract-time nil
9045 "Non-nil means extract any time specification from the diary entry."
9046 :group 'org-agenda
9047 :version "24.1"
9048 :type 'boolean)
9050 (defcustom org-agenda-bulk-mark-char ">"
9051 "A single-character string to be used as the bulk mark."
9052 :group 'org-agenda
9053 :version "24.1"
9054 :type 'string)
9056 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9057 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9058 If TEXT is not empty, it will become the headline of the new entry, and
9059 the resulting entry will not be shown. When TEXT is empty, switch to
9060 `org-agenda-diary-file' and let the user finish the entry there."
9061 (let ((cw (current-window-configuration)))
9062 (org-switch-to-buffer-other-window
9063 (find-file-noselect org-agenda-diary-file))
9064 (widen)
9065 (goto-char (point-min))
9066 (cond
9067 ((eq type 'anniversary)
9068 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9069 (progn
9070 (or (org-at-heading-p t)
9071 (progn
9072 (outline-next-heading)
9073 (insert "* Anniversaries\n\n")
9074 (beginning-of-line -1)))))
9075 (outline-next-heading)
9076 (org-back-over-empty-lines)
9077 (backward-char 1)
9078 (insert "\n")
9079 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9080 (nth 2 d1) (car d1) (nth 1 d1) text)))
9081 ((eq type 'day)
9082 (let ((org-prefix-has-time t)
9083 (org-agenda-time-leading-zero t)
9084 fmt time time2)
9085 (if org-agenda-insert-diary-extract-time
9086 ;; Use org-agenda-format-item to parse text for a time-range and
9087 ;; remove it. FIXME: This is a hack, we should refactor
9088 ;; that function to make time extraction available separately
9089 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9090 time (get-text-property 0 'time fmt)
9091 time2 (if (> (length time) 0)
9092 ;; split-string removes trailing ...... if
9093 ;; no end time given. First space
9094 ;; separates time from date.
9095 (concat " " (car (split-string time "\\.")))
9096 nil)
9097 text (get-text-property 0 'txt fmt)))
9098 (if (eq org-agenda-insert-diary-strategy 'top-level)
9099 (org-agenda-insert-diary-as-top-level text)
9100 (require 'org-datetree)
9101 (org-datetree-find-date-create d1)
9102 (org-agenda-insert-diary-make-new-entry text))
9103 (org-insert-time-stamp (org-time-from-absolute
9104 (calendar-absolute-from-gregorian d1))
9105 nil nil nil nil time2))
9106 (end-of-line 0))
9107 ((eq type 'block)
9108 (if (> (calendar-absolute-from-gregorian d1)
9109 (calendar-absolute-from-gregorian d2))
9110 (setq d1 (prog1 d2 (setq d2 d1))))
9111 (if (eq org-agenda-insert-diary-strategy 'top-level)
9112 (org-agenda-insert-diary-as-top-level text)
9113 (require 'org-datetree)
9114 (org-datetree-find-date-create d1)
9115 (org-agenda-insert-diary-make-new-entry text))
9116 (org-insert-time-stamp (org-time-from-absolute
9117 (calendar-absolute-from-gregorian d1)))
9118 (insert "--")
9119 (org-insert-time-stamp (org-time-from-absolute
9120 (calendar-absolute-from-gregorian d2)))
9121 (end-of-line 0)))
9122 (if (string-match "\\S-" text)
9123 (progn
9124 (set-window-configuration cw)
9125 (message "%s entry added to %s"
9126 (capitalize (symbol-name type))
9127 (abbreviate-file-name org-agenda-diary-file)))
9128 (org-reveal t)
9129 (message "Please finish entry here"))))
9131 (defun org-agenda-insert-diary-as-top-level (text)
9132 "Make new entry as a top-level entry at the end of the file.
9133 Add TEXT as headline, and position the cursor in the second line so that
9134 a timestamp can be added there."
9135 (widen)
9136 (goto-char (point-max))
9137 (or (bolp) (insert "\n"))
9138 (insert "* " text "\n")
9139 (if org-adapt-indentation (org-indent-to-column 2)))
9141 (defun org-agenda-insert-diary-make-new-entry (text)
9142 "Make new entry as last child of current entry.
9143 Add TEXT as headline, and position the cursor in the second line so that
9144 a timestamp can be added there."
9145 (let ((org-show-following-heading t)
9146 (org-show-siblings t)
9147 (org-show-hierarchy-above t)
9148 (org-show-entry-below t)
9149 col)
9150 (outline-next-heading)
9151 (org-back-over-empty-lines)
9152 (or (looking-at "[ \t]*$")
9153 (progn (insert "\n") (backward-char 1)))
9154 (org-insert-heading nil t)
9155 (org-do-demote)
9156 (setq col (current-column))
9157 (insert text "\n")
9158 (if org-adapt-indentation (org-indent-to-column col))
9159 (let ((org-show-following-heading t)
9160 (org-show-siblings t)
9161 (org-show-hierarchy-above t)
9162 (org-show-entry-below t))
9163 (org-show-context))))
9165 (defun org-agenda-diary-entry ()
9166 "Make a diary entry, like the `i' command from the calendar.
9167 All the standard commands work: block, weekly etc.
9168 When `org-agenda-diary-file' points to a file,
9169 `org-agenda-diary-entry-in-org-file' is called instead to create
9170 entries in that Org-mode file."
9171 (interactive)
9172 (if (not (eq org-agenda-diary-file 'diary-file))
9173 (org-agenda-diary-entry-in-org-file)
9174 (require 'diary-lib)
9175 (let* ((char (progn
9176 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9177 (read-char-exclusive)))
9178 (cmd (cdr (assoc char
9179 '((?d . insert-diary-entry)
9180 (?w . insert-weekly-diary-entry)
9181 (?m . insert-monthly-diary-entry)
9182 (?y . insert-yearly-diary-entry)
9183 (?a . insert-anniversary-diary-entry)
9184 (?b . insert-block-diary-entry)
9185 (?c . insert-cyclic-diary-entry)))))
9186 (oldf (symbol-function 'calendar-cursor-to-date))
9187 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9188 (point (point))
9189 (mark (or (mark t) (point))))
9190 (unless cmd
9191 (error "No command associated with <%c>" char))
9192 (unless (and (get-text-property point 'day)
9193 (or (not (equal ?b char))
9194 (get-text-property mark 'day)))
9195 (error "Don't know which date to use for diary entry"))
9196 ;; We implement this by hacking the `calendar-cursor-to-date' function
9197 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9198 (let ((calendar-mark-ring
9199 (list (calendar-gregorian-from-absolute
9200 (or (get-text-property mark 'day)
9201 (get-text-property point 'day))))))
9202 (unwind-protect
9203 (progn
9204 (fset 'calendar-cursor-to-date
9205 (lambda (&optional error dummy)
9206 (calendar-gregorian-from-absolute
9207 (get-text-property point 'day))))
9208 (call-interactively cmd))
9209 (fset 'calendar-cursor-to-date oldf))))))
9211 (defun org-agenda-execute-calendar-command (cmd)
9212 "Execute a calendar command from the agenda with date from cursor."
9213 (org-agenda-check-type t 'agenda 'timeline)
9214 (require 'diary-lib)
9215 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9216 (error "Don't know which date to use for the calendar command"))
9217 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9218 (point (point))
9219 (date (calendar-gregorian-from-absolute
9220 (get-text-property point 'day)))
9221 ;; the following 2 vars are needed in the calendar
9222 (displayed-month (car date))
9223 (displayed-year (nth 2 date)))
9224 (unwind-protect
9225 (progn
9226 (fset 'calendar-cursor-to-date
9227 (lambda (&optional error dummy)
9228 (calendar-gregorian-from-absolute
9229 (get-text-property point 'day))))
9230 (call-interactively cmd))
9231 (fset 'calendar-cursor-to-date oldf))))
9233 (defun org-agenda-phases-of-moon ()
9234 "Display the phases of the moon for the 3 months around the cursor date."
9235 (interactive)
9236 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9238 (defun org-agenda-holidays ()
9239 "Display the holidays for the 3 months around the cursor date."
9240 (interactive)
9241 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9243 (defvar calendar-longitude) ; defined in calendar.el
9244 (defvar calendar-latitude) ; defined in calendar.el
9245 (defvar calendar-location-name) ; defined in calendar.el
9247 (defun org-agenda-sunrise-sunset (arg)
9248 "Display sunrise and sunset for the cursor date.
9249 Latitude and longitude can be specified with the variables
9250 `calendar-latitude' and `calendar-longitude'. When called with prefix
9251 argument, latitude and longitude will be prompted for."
9252 (interactive "P")
9253 (require 'solar)
9254 (let ((calendar-longitude (if arg nil calendar-longitude))
9255 (calendar-latitude (if arg nil calendar-latitude))
9256 (calendar-location-name
9257 (if arg "the given coordinates" calendar-location-name)))
9258 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9260 (defun org-agenda-goto-calendar ()
9261 "Open the Emacs calendar with the date at the cursor."
9262 (interactive)
9263 (org-agenda-check-type t 'agenda 'timeline)
9264 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9265 (error "Don't know which date to open in calendar")))
9266 (date (calendar-gregorian-from-absolute day))
9267 (calendar-move-hook nil)
9268 (calendar-view-holidays-initially-flag nil)
9269 (calendar-view-diary-initially-flag nil))
9270 (calendar)
9271 (calendar-goto-date date)))
9273 ;;;###autoload
9274 (defun org-calendar-goto-agenda ()
9275 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9276 This is a command that has to be installed in `calendar-mode-map'."
9277 (interactive)
9278 (org-agenda-list nil (calendar-absolute-from-gregorian
9279 (calendar-cursor-to-date))
9280 nil))
9282 (defun org-agenda-convert-date ()
9283 (interactive)
9284 (org-agenda-check-type t 'agenda 'timeline)
9285 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9286 date s)
9287 (unless day
9288 (error "Don't know which date to convert"))
9289 (setq date (calendar-gregorian-from-absolute day))
9290 (setq s (concat
9291 "Gregorian: " (calendar-date-string date) "\n"
9292 "ISO: " (calendar-iso-date-string date) "\n"
9293 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9294 "Julian: " (calendar-julian-date-string date) "\n"
9295 "Astron. JD: " (calendar-astro-date-string date)
9296 " (Julian date number at noon UTC)\n"
9297 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9298 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9299 "French: " (calendar-french-date-string date) "\n"
9300 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9301 "Mayan: " (calendar-mayan-date-string date) "\n"
9302 "Coptic: " (calendar-coptic-date-string date) "\n"
9303 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9304 "Persian: " (calendar-persian-date-string date) "\n"
9305 "Chinese: " (calendar-chinese-date-string date) "\n"))
9306 (with-output-to-temp-buffer "*Dates*"
9307 (princ s))
9308 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9310 ;;; Bulk commands
9312 (defun org-agenda-bulk-marked-p ()
9313 (eq (get-char-property (point-at-bol) 'type)
9314 'org-marked-entry-overlay))
9316 (defun org-agenda-bulk-mark (&optional arg)
9317 "Mark the entry at point for future bulk action."
9318 (interactive "p")
9319 (dotimes (i (or arg 1))
9320 (unless (org-get-at-bol 'org-agenda-diary-link)
9321 (let* ((m (org-get-at-bol 'org-hd-marker))
9323 (unless (org-agenda-bulk-marked-p)
9324 (unless m (error "Nothing to mark at point"))
9325 (push m org-agenda-bulk-marked-entries)
9326 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9327 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9328 (org-get-todo-face "TODO")
9329 'evaporate)
9330 (overlay-put ov 'type 'org-marked-entry-overlay))
9331 (beginning-of-line 2)
9332 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9333 (beginning-of-line 2))
9334 (message "%d entries marked for bulk action"
9335 (length org-agenda-bulk-marked-entries))))))
9337 (defun org-agenda-bulk-mark-all ()
9338 "Mark all entries for future agenda bulk action."
9339 (interactive)
9340 (org-agenda-bulk-mark-regexp "."))
9342 (defun org-agenda-bulk-mark-regexp (regexp)
9343 "Mark entries matching REGEXP for future agenda bulk action."
9344 (interactive "sMark entries matching regexp: ")
9345 (let ((entries-marked 0))
9346 (save-excursion
9347 (goto-char (point-min))
9348 (goto-char (next-single-property-change (point) 'txt))
9349 (while (re-search-forward regexp nil t)
9350 (when (string-match regexp (get-text-property (point) 'txt))
9351 (setq entries-marked (1+ entries-marked))
9352 (call-interactively 'org-agenda-bulk-mark))))
9353 (if (not entries-marked)
9354 (message "No entry matching this regexp."))))
9356 (defun org-agenda-bulk-unmark (&optional arg)
9357 "Unmark the entry at point for future bulk action."
9358 (interactive "P")
9359 (if arg
9360 (org-agenda-bulk-unmark-all)
9361 (cond ((org-agenda-bulk-marked-p)
9362 (org-agenda-bulk-remove-overlays
9363 (point-at-bol) (+ 2 (point-at-bol)))
9364 (setq org-agenda-bulk-marked-entries
9365 (delete (org-get-at-bol 'org-hd-marker)
9366 org-agenda-bulk-marked-entries))
9367 (beginning-of-line 2)
9368 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9369 (beginning-of-line 2))
9370 (message "%d entries left marked for bulk action"
9371 (length org-agenda-bulk-marked-entries)))
9372 (t (message "No entry to unmark here")))))
9374 (defun org-agenda-bulk-toggle ()
9375 "Toggle marking the entry at point for bulk action."
9376 (interactive)
9377 (if (org-agenda-bulk-marked-p)
9378 (org-agenda-bulk-unmark)
9379 (org-agenda-bulk-mark)))
9381 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9382 "Remove the mark overlays between BEG and END in the agenda buffer.
9383 BEG and END default to the buffer limits.
9385 This only removes the overlays, it does not remove the markers
9386 from the list in `org-agenda-bulk-marked-entries'."
9387 (interactive)
9388 (mapc (lambda (ov)
9389 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9390 (delete-overlay ov)))
9391 (overlays-in (or beg (point-min)) (or end (point-max)))))
9393 (defun org-agenda-bulk-unmark-all ()
9394 "Remove all marks in the agenda buffer.
9395 This will remove the markers and the overlays."
9396 (interactive)
9397 (if (null org-agenda-bulk-marked-entries)
9398 (message "No entry to unmark")
9399 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9400 (setq org-agenda-bulk-marked-entries nil)
9401 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9403 (defcustom org-agenda-persistent-marks nil
9404 "Non-nil means marked items will stay marked after a bulk action.
9405 You can toggle this interactively by typing `p' when prompted for a
9406 bulk action."
9407 :group 'org-agenda
9408 :version "24.1"
9409 :type 'boolean)
9411 (defun org-agenda-bulk-action (&optional arg)
9412 "Execute an remote-editing action on all marked entries.
9413 The prefix arg is passed through to the command if possible."
9414 (interactive "P")
9415 ;; Make sure we have markers, and only valid ones
9416 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9417 (mapc
9418 (lambda (m)
9419 (unless (and (markerp m)
9420 (marker-buffer m)
9421 (buffer-live-p (marker-buffer m))
9422 (marker-position m))
9423 (error "Marker %s for bulk command is invalid" m)))
9424 org-agenda-bulk-marked-entries)
9426 ;; Prompt for the bulk command
9427 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9428 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9429 "[S]catter [f]unction "
9430 (when org-agenda-bulk-custom-functions
9431 (concat " Custom: ["
9432 (mapconcat (lambda(f) (char-to-string (car f)))
9433 org-agenda-bulk-custom-functions "")
9434 "]"))))
9435 (catch 'exit
9436 (let* ((action (read-char-exclusive))
9437 (org-log-refile (if org-log-refile 'time nil))
9438 (entries (reverse org-agenda-bulk-marked-entries))
9439 (org-overriding-default-time
9440 (if (get-text-property (point) 'org-agenda-date-header)
9441 (org-get-cursor-date)))
9442 redo-at-end
9443 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9444 (cond
9445 ((equal action ?p)
9446 (let ((org-agenda-persistent-marks
9447 (not org-agenda-persistent-marks)))
9448 (org-agenda-bulk-action)
9449 (throw 'exit nil)))
9451 ((equal action ?$)
9452 (setq cmd '(org-agenda-archive)))
9454 ((equal action ?A)
9455 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9457 ((member action '(?r ?w))
9458 (setq rfloc (org-refile-get-location
9459 "Refile to"
9460 (marker-buffer (car entries))
9461 org-refile-allow-creating-parent-nodes))
9462 (if (nth 3 rfloc)
9463 (setcar (nthcdr 3 rfloc)
9464 (move-marker (make-marker) (nth 3 rfloc)
9465 (or (get-file-buffer (nth 1 rfloc))
9466 (find-buffer-visiting (nth 1 rfloc))
9467 (error "This should not happen")))))
9469 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9470 redo-at-end t))
9472 ((equal action ?t)
9473 (setq state (org-icompleting-read
9474 "Todo state: "
9475 (with-current-buffer (marker-buffer (car entries))
9476 (mapcar 'list org-todo-keywords-1))))
9477 (setq cmd `(let ((org-inhibit-blocking t)
9478 (org-inhibit-logging 'note))
9479 (org-agenda-todo ,state))))
9481 ((memq action '(?- ?+))
9482 (setq tag (org-icompleting-read
9483 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9484 (with-current-buffer (marker-buffer (car entries))
9485 (delq nil
9486 (mapcar (lambda (x)
9487 (if (stringp (car x)) x)) org-tag-alist)))))
9488 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9490 ((memq action '(?s ?d))
9491 (let* ((time
9492 (unless arg
9493 (org-read-date
9494 nil nil nil
9495 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9496 org-overriding-default-time)))
9497 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9498 (setq cmd `(eval '(,c1 arg ,time)))))
9500 ((equal action ?S)
9501 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9502 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9503 (let ((days (read-number
9504 (format "Scatter tasks across how many %sdays: "
9505 (if arg "week" "")) 7)))
9506 (setq cmd
9507 `(let ((distance (1+ (random ,days))))
9508 (if arg
9509 (let ((dist distance)
9510 (day-of-week
9511 (calendar-day-of-week
9512 (calendar-gregorian-from-absolute (org-today)))))
9513 (dotimes (i (1+ dist))
9514 (while (member day-of-week org-agenda-weekend-days)
9515 (incf distance)
9516 (incf day-of-week)
9517 (if (= day-of-week 7)
9518 (setq day-of-week 0)))
9519 (incf day-of-week)
9520 (if (= day-of-week 7)
9521 (setq day-of-week 0)))))
9522 ;; silently fail when try to replan a sexp entry
9523 (condition-case nil
9524 (let* ((date (calendar-gregorian-from-absolute
9525 (+ (org-today) distance)))
9526 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9527 (nth 2 date))))
9528 (org-agenda-schedule nil time))
9529 (error nil)))))))
9531 ((assoc action org-agenda-bulk-custom-functions)
9532 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9533 redo-at-end t))
9535 ((equal action ?f)
9536 (setq cmd (list (intern
9537 (org-icompleting-read "Function: "
9538 obarray 'fboundp t nil nil)))))
9540 (t (error "Invalid bulk action")))
9542 ;; Sort the markers, to make sure that parents are handled before children
9543 (setq entries (sort entries
9544 (lambda (a b)
9545 (cond
9546 ((equal (marker-buffer a) (marker-buffer b))
9547 (< (marker-position a) (marker-position b)))
9549 (string< (buffer-name (marker-buffer a))
9550 (buffer-name (marker-buffer b))))))))
9552 ;; Now loop over all markers and apply cmd
9553 (while (setq e (pop entries))
9554 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9555 (if (not pos)
9556 (progn (message "Skipping removed entry at %s" e)
9557 (setq cntskip (1+ cntskip)))
9558 (goto-char pos)
9559 (let (org-loop-over-headlines-in-active-region)
9560 (eval cmd))
9561 (setq cnt (1+ cnt))))
9562 (when redo-at-end (org-agenda-redo))
9563 (unless org-agenda-persistent-marks
9564 (org-agenda-bulk-unmark-all))
9565 (message "Acted on %d entries%s%s"
9567 (if (= cntskip 0)
9569 (format ", skipped %d (disappeared before their turn)"
9570 cntskip))
9571 (if (not org-agenda-persistent-marks)
9572 "" " (kept marked)"))))))
9574 (defun org-agenda-capture (&optional with-time)
9575 "Call `org-capture' with the date at point.
9576 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9577 current HH:MM time."
9578 (interactive "P")
9579 (if (not (eq major-mode 'org-agenda-mode))
9580 (user-error "You cannot do this outside of agenda buffers")
9581 (let ((org-overriding-default-time
9582 (org-get-cursor-date (equal with-time 1))))
9583 (call-interactively 'org-capture))))
9585 ;;; Flagging notes
9587 (defun org-agenda-show-the-flagging-note ()
9588 "Display the flagging note in the other window.
9589 When called a second time in direct sequence, offer to remove the FLAGGING
9590 tag and (if present) the flagging note."
9591 (interactive)
9592 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9593 (win (selected-window))
9594 note heading newhead)
9595 (unless hdmarker
9596 (error "No linked entry at point"))
9597 (if (and (eq this-command last-command)
9598 (y-or-n-p "Unflag and remove any flagging note? "))
9599 (progn
9600 (org-agenda-remove-flag hdmarker)
9601 (let ((win (get-buffer-window "*Flagging Note*")))
9602 (and win (delete-window win)))
9603 (message "Entry unflagged"))
9604 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9605 (unless note
9606 (error "No flagging note"))
9607 (org-kill-new note)
9608 (org-switch-to-buffer-other-window "*Flagging Note*")
9609 (erase-buffer)
9610 (insert note)
9611 (goto-char (point-min))
9612 (while (re-search-forward "\\\\n" nil t)
9613 (replace-match "\n" t t))
9614 (goto-char (point-min))
9615 (select-window win)
9616 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9618 (defun org-agenda-remove-flag (marker)
9619 "Remove the FLAGGED tag and any flagging note in the entry."
9620 (let (newhead)
9621 (org-with-point-at marker
9622 (org-toggle-tag "FLAGGED" 'off)
9623 (org-entry-delete nil "THEFLAGGINGNOTE")
9624 (setq newhead (org-get-heading)))
9625 (org-agenda-change-all-lines newhead marker)
9626 (message "Entry unflagged")))
9628 (defun org-agenda-get-any-marker (&optional pos)
9629 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9630 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9632 ;;; Appointment reminders
9634 (defvar appt-time-msg-list) ; defined in appt.el
9636 ;;;###autoload
9637 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9638 "Activate appointments found in `org-agenda-files'.
9639 With a \\[universal-argument] prefix, refresh the list of
9640 appointments.
9642 If FILTER is t, interactively prompt the user for a regular
9643 expression, and filter out entries that don't match it.
9645 If FILTER is a string, use this string as a regular expression
9646 for filtering entries out.
9648 If FILTER is a function, filter out entries against which
9649 calling the function returns nil. This function takes one
9650 argument: an entry from `org-agenda-get-day-entries'.
9652 FILTER can also be an alist with the car of each cell being
9653 either 'headline or 'category. For example:
9655 '((headline \"IMPORTANT\")
9656 (category \"Work\"))
9658 will only add headlines containing IMPORTANT or headlines
9659 belonging to the \"Work\" category.
9661 ARGS are symbols indicating what kind of entries to consider.
9662 By default `org-agenda-to-appt' will use :deadline, :scheduled
9663 and :timestamp entries. See the docstring of `org-diary' for
9664 details and examples.
9666 If an entry has a APPT_WARNTIME property, its value will be used
9667 to override `appt-message-warning-time'."
9668 (interactive "P")
9669 (if refresh (setq appt-time-msg-list nil))
9670 (if (eq filter t)
9671 (setq filter (read-from-minibuffer "Regexp filter: ")))
9672 (let* ((cnt 0) ; count added events
9673 (scope (or args '(:deadline :scheduled :timestamp)))
9674 (org-agenda-new-buffers nil)
9675 (org-deadline-warning-days 0)
9676 ;; Do not use `org-today' here because appt only takes
9677 ;; time and without date as argument, so it may pass wrong
9678 ;; information otherwise
9679 (today (org-date-to-gregorian
9680 (time-to-days (current-time))))
9681 (org-agenda-restrict nil)
9682 (files (org-agenda-files 'unrestricted)) entries file
9683 (org-agenda-buffer nil))
9684 ;; Get all entries which may contain an appt
9685 (org-agenda-prepare-buffers files)
9686 (while (setq file (pop files))
9687 (setq entries
9688 (delq nil
9689 (append entries
9690 (apply 'org-agenda-get-day-entries
9691 file today scope)))))
9692 ;; Map thru entries and find if we should filter them out
9693 (mapc
9694 (lambda(x)
9695 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9696 (cat (get-text-property 1 'org-category x))
9697 (tod (get-text-property 1 'time-of-day x))
9698 (ok (or (null filter)
9699 (and (stringp filter) (string-match filter evt))
9700 (and (functionp filter) (funcall filter x))
9701 (and (listp filter)
9702 (let ((cat-filter (cadr (assoc 'category filter)))
9703 (evt-filter (cadr (assoc 'headline filter))))
9704 (or (and (stringp cat-filter)
9705 (string-match cat-filter cat))
9706 (and (stringp evt-filter)
9707 (string-match evt-filter evt)))))))
9708 (wrn (get-text-property 1 'warntime x)))
9709 ;; FIXME: Shall we remove text-properties for the appt text?
9710 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9711 (when (and ok tod)
9712 (setq tod (concat "00" (number-to-string tod))
9713 tod (when (string-match
9714 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9715 (concat (match-string 1 tod) ":"
9716 (match-string 2 tod))))
9717 (if (version< emacs-version "23.3")
9718 (appt-add tod evt)
9719 (appt-add tod evt wrn))
9720 (setq cnt (1+ cnt))))) entries)
9721 (org-release-buffers org-agenda-new-buffers)
9722 (if (eq cnt 0)
9723 (message "No event to add")
9724 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9726 (defun org-agenda-todayp (date)
9727 "Does DATE mean today, when considering `org-extend-today-until'?"
9728 (let ((today (org-today))
9729 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9730 date)))
9731 (eq date today)))
9733 (defun org-agenda-todo-yesterday (&optional arg)
9734 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9735 (interactive "P")
9736 (let* ((hour (third (decode-time
9737 (org-current-time))))
9738 (org-extend-today-until (1+ hour)))
9739 (org-agenda-todo arg)))
9741 (provide 'org-agenda)
9743 ;;; org-agenda.el ends here