org-agenda.el (org-agenda-deadline-leaders): New formatting string for past deadlines
[org-mode.git] / lisp / org-agenda.el
blobc1fe4f3f51aea20f2f6578f2aaa608a1768cc8e7
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 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
847 "Non-nil means skip scheduled delay when entry also has a deadline.
848 This variable may be set to nil, t, the symbol `post-deadline',
849 or a number which will then give the number of days after the actual
850 scheduled date when the delay should expire. The symbol `post-deadline'
851 eliminates the schedule delay when the date is posterior to the deadline."
852 :group 'org-agenda-skip
853 :group 'org-agenda-daily/weekly
854 :version "24.4"
855 :package-version '(Org . "8.0")
856 :type '(choice
857 (const :tag "Always honor delay" nil)
858 (const :tag "Ignore delay if posterior to the deadline" post-deadline)
859 (const :tag "Ignore delay if entry has a deadline" t)
860 (integer :tag "Honor delay up until N days after the scheduled date")))
862 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
863 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
864 When non-nil, after the search for timestamps has matched once in an
865 entry, the rest of the entry will not be searched."
866 :group 'org-agenda-skip
867 :type 'boolean)
869 (defcustom org-agenda-skip-timestamp-if-done nil
870 "Non-nil means don't select item by timestamp or -range if it is DONE."
871 :group 'org-agenda-skip
872 :group 'org-agenda-daily/weekly
873 :type 'boolean)
875 (defcustom org-agenda-dim-blocked-tasks nil
876 "Non-nil means dim blocked tasks in the agenda display.
877 This causes some overhead during agenda construction, but if you
878 have turned on `org-enforce-todo-dependencies',
879 `org-enforce-todo-checkbox-dependencies', or any other blocking
880 mechanism, this will create useful feedback in the agenda.
882 Instead of t, this variable can also have the value `invisible'.
883 Then blocked tasks will be invisible and only become visible when
884 they become unblocked. An exemption to this behavior is when a task is
885 blocked because of unchecked checkboxes below it. Since checkboxes do
886 not show up in the agenda views, making this task invisible you remove any
887 trace from agenda views that there is something to do. Therefore, a task
888 that is blocked because of checkboxes will never be made invisible, it
889 will only be dimmed."
890 :group 'org-agenda-daily/weekly
891 :group 'org-agenda-todo-list
892 :version "24.3"
893 :type '(choice
894 (const :tag "Do not dim" nil)
895 (const :tag "Dim to a gray face" t)
896 (const :tag "Make invisible" invisible)))
898 (defcustom org-timeline-show-empty-dates 3
899 "Non-nil means `org-timeline' also shows dates without an entry.
900 When nil, only the days which actually have entries are shown.
901 When t, all days between the first and the last date are shown.
902 When an integer, show also empty dates, but if there is a gap of more than
903 N days, just insert a special line indicating the size of the gap."
904 :group 'org-agenda-skip
905 :type '(choice
906 (const :tag "None" nil)
907 (const :tag "All" t)
908 (integer :tag "at most")))
910 (defgroup org-agenda-startup nil
911 "Options concerning initial settings in the Agenda in Org Mode."
912 :tag "Org Agenda Startup"
913 :group 'org-agenda)
915 (defcustom org-agenda-menu-show-matcher t
916 "Non-nil means show the match string in the agenda dispatcher menu.
917 When nil, the matcher string is not shown, but is put into the help-echo
918 property so than moving the mouse over the command shows it.
919 Setting it to nil is good if matcher strings are very long and/or if
920 you want to use two-columns display (see `org-agenda-menu-two-columns')."
921 :group 'org-agenda
922 :version "24.1"
923 :type 'boolean)
925 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
927 (defcustom org-agenda-menu-two-columns nil
928 "Non-nil means, use two columns to show custom commands in the dispatcher.
929 If you use this, you probably want to set `org-agenda-menu-show-matcher'
930 to nil."
931 :group 'org-agenda
932 :version "24.1"
933 :type 'boolean)
935 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
936 (defcustom org-agenda-finalize-hook nil
937 "Hook run just before displaying an agenda buffer.
938 The buffer is still writable when the hook is called.
940 You can modify some of the buffer substrings but you should be
941 extra careful not to modify the text properties of the agenda
942 headlines as the agenda display heavily relies on them."
943 :group 'org-agenda-startup
944 :type 'hook)
946 (defcustom org-agenda-mouse-1-follows-link nil
947 "Non-nil means mouse-1 on a link will follow the link in the agenda.
948 A longer mouse click will still set point. Does not work on XEmacs.
949 Needs to be set before org.el is loaded."
950 :group 'org-agenda-startup
951 :type 'boolean)
953 (defcustom org-agenda-start-with-follow-mode nil
954 "The initial value of follow mode in a newly created agenda window."
955 :group 'org-agenda-startup
956 :type 'boolean)
958 (defcustom org-agenda-follow-indirect nil
959 "Non-nil means `org-agenda-follow-mode' displays only the
960 current item's tree, in an indirect buffer."
961 :group 'org-agenda
962 :version "24.1"
963 :type 'boolean)
965 (defcustom org-agenda-show-outline-path t
966 "Non-nil means show outline path in echo area after line motion."
967 :group 'org-agenda-startup
968 :type 'boolean)
970 (defcustom org-agenda-start-with-entry-text-mode nil
971 "The initial value of entry-text-mode in a newly created agenda window."
972 :group 'org-agenda-startup
973 :type 'boolean)
975 (defcustom org-agenda-entry-text-maxlines 5
976 "Number of text lines to be added when `E' is pressed in the agenda.
978 Note that this variable only used during agenda display. Add add entry text
979 when exporting the agenda, configure the variable
980 `org-agenda-add-entry-ext-maxlines'."
981 :group 'org-agenda
982 :type 'integer)
984 (defcustom org-agenda-entry-text-exclude-regexps nil
985 "List of regular expressions to clean up entry text.
986 The complete matches of all regular expressions in this list will be
987 removed from entry text before it is shown in the agenda."
988 :group 'org-agenda
989 :type '(repeat (regexp)))
991 (defvar org-agenda-entry-text-cleanup-hook nil
992 "Hook that is run after basic cleanup of entry text to be shown in agenda.
993 This cleanup is done in a temporary buffer, so the function may inspect and
994 change the entire buffer.
995 Some default stuff like drawers and scheduling/deadline dates will already
996 have been removed when this is called, as will any matches for regular
997 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
999 (defvar org-agenda-include-inactive-timestamps nil
1000 "Non-nil means include inactive time stamps in agenda and timeline.
1001 Dynamically scoped.")
1003 (defgroup org-agenda-windows nil
1004 "Options concerning the windows used by the Agenda in Org Mode."
1005 :tag "Org Agenda Windows"
1006 :group 'org-agenda)
1008 (defcustom org-agenda-window-setup 'reorganize-frame
1009 "How the agenda buffer should be displayed.
1010 Possible values for this option are:
1012 current-window Show agenda in the current window, keeping all other windows.
1013 other-window Use `switch-to-buffer-other-window' to display agenda.
1014 reorganize-frame Show only two windows on the current frame, the current
1015 window and the agenda.
1016 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1017 Also, when exiting the agenda, kill that frame.
1018 See also the variable `org-agenda-restore-windows-after-quit'."
1019 :group 'org-agenda-windows
1020 :type '(choice
1021 (const current-window)
1022 (const other-frame)
1023 (const other-window)
1024 (const reorganize-frame)))
1026 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1027 "The min and max height of the agenda window as a fraction of frame height.
1028 The value of the variable is a cons cell with two numbers between 0 and 1.
1029 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1030 :group 'org-agenda-windows
1031 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1033 (defcustom org-agenda-restore-windows-after-quit nil
1034 "Non-nil means restore window configuration upon exiting agenda.
1035 Before the window configuration is changed for displaying the agenda,
1036 the current status is recorded. When the agenda is exited with
1037 `q' or `x' and this option is set, the old state is restored. If
1038 `org-agenda-window-setup' is `other-frame', the value of this
1039 option will be ignored."
1040 :group 'org-agenda-windows
1041 :type 'boolean)
1043 (defcustom org-agenda-ndays nil
1044 "Number of days to include in overview display.
1045 Should be 1 or 7.
1046 Obsolete, see `org-agenda-span'."
1047 :group 'org-agenda-daily/weekly
1048 :type 'integer)
1050 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1052 (defcustom org-agenda-span 'week
1053 "Number of days to include in overview display.
1054 Can be day, week, month, year, or any number of days.
1055 Custom commands can set this variable in the options section."
1056 :group 'org-agenda-daily/weekly
1057 :type '(choice (const :tag "Day" day)
1058 (const :tag "Week" week)
1059 (const :tag "Month" month)
1060 (const :tag "Year" year)
1061 (integer :tag "Custom")))
1063 (defcustom org-agenda-start-on-weekday 1
1064 "Non-nil means start the overview always on the specified weekday.
1065 0 denotes Sunday, 1 denotes Monday etc.
1066 When nil, always start on the current day.
1067 Custom commands can set this variable in the options section."
1068 :group 'org-agenda-daily/weekly
1069 :type '(choice (const :tag "Today" nil)
1070 (integer :tag "Weekday No.")))
1072 (defcustom org-agenda-show-all-dates t
1073 "Non-nil means `org-agenda' shows every day in the selected range.
1074 When nil, only the days which actually have entries are shown."
1075 :group 'org-agenda-daily/weekly
1076 :type 'boolean)
1078 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1079 "Format string for displaying dates in the agenda.
1080 Used by the daily/weekly agenda and by the timeline. This should be
1081 a format string understood by `format-time-string', or a function returning
1082 the formatted date as a string. The function must take a single argument,
1083 a calendar-style date list like (month day year)."
1084 :group 'org-agenda-daily/weekly
1085 :type '(choice
1086 (string :tag "Format string")
1087 (function :tag "Function")))
1089 (defun org-agenda-format-date-aligned (date)
1090 "Format a date string for display in the daily/weekly agenda, or timeline.
1091 This function makes sure that dates are aligned for easy reading."
1092 (require 'cal-iso)
1093 (let* ((dayname (calendar-day-name date))
1094 (day (cadr date))
1095 (day-of-week (calendar-day-of-week date))
1096 (month (car date))
1097 (monthname (calendar-month-name month))
1098 (year (nth 2 date))
1099 (iso-week (org-days-to-iso-week
1100 (calendar-absolute-from-gregorian date)))
1101 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1102 (1- year))
1103 ((and (= month 12) (<= iso-week 1))
1104 (1+ year))
1105 (t year)))
1106 (weekstring (if (= day-of-week 1)
1107 (format " W%02d" iso-week)
1108 "")))
1109 (format "%-10s %2d %s %4d%s"
1110 dayname day monthname year weekstring)))
1112 (defcustom org-agenda-time-leading-zero nil
1113 "Non-nil means use leading zero for military times in agenda.
1114 For example, 9:30am would become 09:30 rather than 9:30."
1115 :group 'org-agenda-daily/weekly
1116 :version "24.1"
1117 :type 'boolean)
1119 (defcustom org-agenda-timegrid-use-ampm nil
1120 "When set, show AM/PM style timestamps on the timegrid."
1121 :group 'org-agenda
1122 :version "24.1"
1123 :type 'boolean)
1125 (defun org-agenda-time-of-day-to-ampm (time)
1126 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1127 (let* ((hour-number (string-to-number (substring time 0 -3)))
1128 (minute (substring time -2))
1129 (ampm "am"))
1130 (cond
1131 ((equal hour-number 12)
1132 (setq ampm "pm"))
1133 ((> hour-number 12)
1134 (setq ampm "pm")
1135 (setq hour-number (- hour-number 12))))
1136 (concat
1137 (if org-agenda-time-leading-zero
1138 (format "%02d" hour-number)
1139 (format "%02s" (number-to-string hour-number)))
1140 ":" minute ampm)))
1142 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1143 "Conditionally convert TIME to AM/PM format
1144 based on `org-agenda-timegrid-use-ampm'"
1145 (if org-agenda-timegrid-use-ampm
1146 (org-agenda-time-of-day-to-ampm time)
1147 time))
1149 (defcustom org-agenda-weekend-days '(6 0)
1150 "Which days are weekend?
1151 These days get the special face `org-agenda-date-weekend' in the agenda
1152 and timeline buffers."
1153 :group 'org-agenda-daily/weekly
1154 :type '(set :greedy t
1155 (const :tag "Monday" 1)
1156 (const :tag "Tuesday" 2)
1157 (const :tag "Wednesday" 3)
1158 (const :tag "Thursday" 4)
1159 (const :tag "Friday" 5)
1160 (const :tag "Saturday" 6)
1161 (const :tag "Sunday" 0)))
1163 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1164 "Non-nil means jump to today when moving a past date forward in time.
1165 When using S-right in the agenda to move a a date forward, and the date
1166 stamp currently points to the past, the first key press will move it
1167 to today. WHen nil, just move one day forward even if the date stays
1168 in the past."
1169 :group 'org-agenda-daily/weekly
1170 :version "24.1"
1171 :type 'boolean)
1173 (defcustom org-agenda-include-diary nil
1174 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1175 Custom commands can set this variable in the options section."
1176 :group 'org-agenda-daily/weekly
1177 :type 'boolean)
1179 (defcustom org-agenda-include-deadlines t
1180 "If non-nil, include entries within their deadline warning period.
1181 Custom commands can set this variable in the options section."
1182 :group 'org-agenda-daily/weekly
1183 :version "24.1"
1184 :type 'boolean)
1186 (defcustom org-agenda-repeating-timestamp-show-all t
1187 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1188 When set to a list of strings, only show occurrences of repeating
1189 stamps for these TODO keywords. When nil, only one occurrence is
1190 shown, either today or the nearest into the future."
1191 :group 'org-agenda-daily/weekly
1192 :type '(choice
1193 (const :tag "Show repeating stamps" t)
1194 (repeat :tag "Show repeating stamps for these TODO keywords"
1195 (string :tag "TODO Keyword"))
1196 (const :tag "Don't show repeating stamps" nil)))
1198 (defcustom org-scheduled-past-days 10000
1199 "No. of days to continue listing scheduled items that are not marked DONE.
1200 When an item is scheduled on a date, it shows up in the agenda on this
1201 day and will be listed until it is marked done for the number of days
1202 given here."
1203 :group 'org-agenda-daily/weekly
1204 :type 'integer)
1206 (defcustom org-agenda-log-mode-items '(closed clock)
1207 "List of items that should be shown in agenda log mode.
1208 This list may contain the following symbols:
1210 closed Show entries that have been closed on that day.
1211 clock Show entries that have received clocked time on that day.
1212 state Show all logged state changes.
1213 Note that instead of changing this variable, you can also press `C-u l' in
1214 the agenda to display all available LOG items temporarily."
1215 :group 'org-agenda-daily/weekly
1216 :type '(set :greedy t (const closed) (const clock) (const state)))
1218 (defcustom org-agenda-clock-consistency-checks
1219 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1220 :gap-ok-around ("4:00")
1221 :default-face ((:background "DarkRed") (:foreground "white"))
1222 :overlap-face nil :gap-face nil :no-end-time-face nil
1223 :long-face nil :short-face nil)
1224 "This is a property list, with the following keys:
1226 :max-duration Mark clocking chunks that are longer than this time.
1227 This is a time string like \"HH:MM\", or the number
1228 of minutes as an integer.
1230 :min-duration Mark clocking chunks that are shorter that this.
1231 This is a time string like \"HH:MM\", or the number
1232 of minutes as an integer.
1234 :max-gap Mark gaps between clocking chunks that are longer than
1235 this duration. A number of minutes, or a string
1236 like \"HH:MM\".
1238 :gap-ok-around List of times during the day which are usually not working
1239 times. When a gap is detected, but the gap contains any
1240 of these times, the gap is *not* reported. For example,
1241 if this is (\"4:00\" \"13:00\") then gaps that contain
1242 4:00 in the morning (i.e. the night) and 13:00
1243 (i.e. a typical lunch time) do not cause a warning.
1244 You should have at least one time during the night in this
1245 list, or otherwise the first task each morning will trigger
1246 a warning because it follows a long gap.
1248 Furthermore, the following properties can be used to define faces for
1249 issue display.
1251 :default-face the default face, if the specific face is undefined
1252 :overlap-face face for overlapping clocks
1253 :gap-face face for gaps between clocks
1254 :no-end-time-face face for incomplete clocks
1255 :long-face face for clock intervals that are too long
1256 :short-face face for clock intervals that are too short"
1257 :group 'org-agenda-daily/weekly
1258 :group 'org-clock
1259 :version "24.1"
1260 :type 'plist)
1262 (defcustom org-agenda-log-mode-add-notes t
1263 "Non-nil means add first line of notes to log entries in agenda views.
1264 If a log item like a state change or a clock entry is associated with
1265 notes, the first line of these notes will be added to the entry in the
1266 agenda display."
1267 :group 'org-agenda-daily/weekly
1268 :type 'boolean)
1270 (defcustom org-agenda-start-with-log-mode nil
1271 "The initial value of log-mode in a newly created agenda window.
1272 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1273 explanations on the possible values."
1274 :group 'org-agenda-startup
1275 :group 'org-agenda-daily/weekly
1276 :type '(choice (const :tag "Don't show log items" nil)
1277 (const :tag "Show only log items" 'only)
1278 (const :tag "Show all possible log items" 'clockcheck)
1279 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1280 (choice (const :tag "Show closed log items" 'closed)
1281 (const :tag "Show clocked log items" 'clock)
1282 (const :tag "Show all logged state changes" 'state)))))
1284 (defcustom org-agenda-start-with-clockreport-mode nil
1285 "The initial value of clockreport-mode in a newly created agenda window."
1286 :group 'org-agenda-startup
1287 :group 'org-agenda-daily/weekly
1288 :type 'boolean)
1290 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1291 "Property list with parameters for the clocktable in clockreport mode.
1292 This is the display mode that shows a clock table in the daily/weekly
1293 agenda, the properties for this dynamic block can be set here.
1294 The usual clocktable parameters are allowed here, but you cannot set
1295 the properties :name, :tstart, :tend, :block, and :scope - these will
1296 be overwritten to make sure the content accurately reflects the
1297 current display in the agenda."
1298 :group 'org-agenda-daily/weekly
1299 :type 'plist)
1301 (defcustom org-agenda-search-view-always-boolean nil
1302 "Non-nil means the search string is interpreted as individual parts.
1304 The search string for search view can either be interpreted as a phrase,
1305 or as a list of snippets that define a boolean search for a number of
1306 strings.
1308 When this is non-nil, the string will be split on whitespace, and each
1309 snippet will be searched individually, and all must match in order to
1310 select an entry. A snippet is then a single string of non-white
1311 characters, or a string in double quotes, or a regexp in {} braces.
1312 If a snippet is preceded by \"-\", the snippet must *not* match.
1313 \"+\" is syntactic sugar for positive selection. Each snippet may
1314 be found as a full word or a partial word, but see the variable
1315 `org-agenda-search-view-force-full-words'.
1317 When this is nil, search will look for the entire search phrase as one,
1318 with each space character matching any amount of whitespace, including
1319 line breaks.
1321 Even when this is nil, you can still switch to Boolean search dynamically
1322 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1323 is a regexp marked with braces like \"{abc}\", this will also switch to
1324 boolean search."
1325 :group 'org-agenda-search-view
1326 :version "24.1"
1327 :type 'boolean)
1329 (if (fboundp 'defvaralias)
1330 (defvaralias 'org-agenda-search-view-search-words-only
1331 'org-agenda-search-view-always-boolean))
1333 (defcustom org-agenda-search-view-force-full-words nil
1334 "Non-nil means, search words must be matches as complete words.
1335 When nil, they may also match part of a word."
1336 :group 'org-agenda-search-view
1337 :version "24.1"
1338 :type 'boolean)
1340 (defcustom org-agenda-search-view-max-outline-level nil
1341 "Maximum outline level to display in search view.
1342 E.g. when this is set to 1, the search view will only
1343 show headlines of level 1."
1344 :group 'org-agenda-search-view
1345 :version "24.4"
1346 :package-version '(Org . "8.0")
1347 :type 'integer)
1349 (defgroup org-agenda-time-grid nil
1350 "Options concerning the time grid in the Org-mode Agenda."
1351 :tag "Org Agenda Time Grid"
1352 :group 'org-agenda)
1354 (defcustom org-agenda-search-headline-for-time t
1355 "Non-nil means search headline for a time-of-day.
1356 If the headline contains a time-of-day in one format or another, it will
1357 be used to sort the entry into the time sequence of items for a day.
1358 Some people have time stamps in the headline that refer to the creation
1359 time or so, and then this produces an unwanted side effect. If this is
1360 the case for your, use this variable to turn off searching the headline
1361 for a time."
1362 :group 'org-agenda-time-grid
1363 :type 'boolean)
1365 (defcustom org-agenda-use-time-grid t
1366 "Non-nil means show a time grid in the agenda schedule.
1367 A time grid is a set of lines for specific times (like every two hours between
1368 8:00 and 20:00). The items scheduled for a day at specific times are
1369 sorted in between these lines.
1370 For details about when the grid will be shown, and what it will look like, see
1371 the variable `org-agenda-time-grid'."
1372 :group 'org-agenda-time-grid
1373 :type 'boolean)
1375 (defcustom org-agenda-time-grid
1376 '((daily today require-timed)
1377 "----------------"
1378 (800 1000 1200 1400 1600 1800 2000))
1380 "The settings for time grid for agenda display.
1381 This is a list of three items. The first item is again a list. It contains
1382 symbols specifying conditions when the grid should be displayed:
1384 daily if the agenda shows a single day
1385 weekly if the agenda shows an entire week
1386 today show grid on current date, independent of daily/weekly display
1387 require-timed show grid only if at least one item has a time specification
1389 The second item is a string which will be placed behind the grid time.
1391 The third item is a list of integers, indicating the times that should have
1392 a grid line."
1393 :group 'org-agenda-time-grid
1394 :type
1395 '(list
1396 (set :greedy t :tag "Grid Display Options"
1397 (const :tag "Show grid in single day agenda display" daily)
1398 (const :tag "Show grid in weekly agenda display" weekly)
1399 (const :tag "Always show grid for today" today)
1400 (const :tag "Show grid only if any timed entries are present"
1401 require-timed)
1402 (const :tag "Skip grid times already present in an entry"
1403 remove-match))
1404 (string :tag "Grid String")
1405 (repeat :tag "Grid Times" (integer :tag "Time"))))
1407 (defcustom org-agenda-show-current-time-in-grid t
1408 "Non-nil means show the current time in the time grid."
1409 :group 'org-agenda-time-grid
1410 :version "24.1"
1411 :type 'boolean)
1413 (defcustom org-agenda-current-time-string
1414 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1415 "The string for the current time marker in the agenda."
1416 :group 'org-agenda-time-grid
1417 :version "24.1"
1418 :type 'string)
1420 (defgroup org-agenda-sorting nil
1421 "Options concerning sorting in the Org-mode Agenda."
1422 :tag "Org Agenda Sorting"
1423 :group 'org-agenda)
1425 (defcustom org-agenda-sorting-strategy
1426 '((agenda habit-down time-up priority-down category-keep)
1427 (todo priority-down category-keep)
1428 (tags priority-down category-keep)
1429 (search category-keep))
1430 "Sorting structure for the agenda items of a single day.
1431 This is a list of symbols which will be used in sequence to determine
1432 if an entry should be listed before another entry. The following
1433 symbols are recognized:
1435 time-up Put entries with time-of-day indications first, early first
1436 time-down Put entries with time-of-day indications first, late first
1437 timestamp-up Sort by any timestamp, early first
1438 timestamp-down Sort by any timestamp, late first
1439 scheduled-up Sort by scheduled timestamp, early first
1440 scheduled-down Sort by scheduled timestamp, late first
1441 deadline-up Sort by deadline timestamp, early first
1442 deadline-down Sort by deadline timestamp, late first
1443 ts-up Sort by active timestamp, early first
1444 ts-down Sort by active timestamp, late first
1445 tsia-up Sort by inactive timestamp, early first
1446 tsia-down Sort by inactive timestamp, late first
1447 category-keep Keep the default order of categories, corresponding to the
1448 sequence in `org-agenda-files'.
1449 category-up Sort alphabetically by category, A-Z.
1450 category-down Sort alphabetically by category, Z-A.
1451 tag-up Sort alphabetically by last tag, A-Z.
1452 tag-down Sort alphabetically by last tag, Z-A.
1453 priority-up Sort numerically by priority, high priority last.
1454 priority-down Sort numerically by priority, high priority first.
1455 todo-state-up Sort by todo state, tasks that are done last.
1456 todo-state-down Sort by todo state, tasks that are done first.
1457 effort-up Sort numerically by estimated effort, high effort last.
1458 effort-down Sort numerically by estimated effort, high effort first.
1459 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1460 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1461 habit-up Put entries that are habits first
1462 habit-down Put entries that are habits last
1463 alpha-up Sort headlines alphabetically
1464 alpha-down Sort headlines alphabetically, reversed
1466 The different possibilities will be tried in sequence, and testing stops
1467 if one comparison returns a \"not-equal\". For example, the default
1468 '(time-up category-keep priority-down)
1469 means: Pull out all entries having a specified time of day and sort them,
1470 in order to make a time schedule for the current day the first thing in the
1471 agenda listing for the day. Of the entries without a time indication, keep
1472 the grouped in categories, don't sort the categories, but keep them in
1473 the sequence given in `org-agenda-files'. Within each category sort by
1474 priority.
1476 Leaving out `category-keep' would mean that items will be sorted across
1477 categories by priority.
1479 Instead of a single list, this can also be a set of list for specific
1480 contents, with a context symbol in the car of the list, any of
1481 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1483 Custom commands can bind this variable in the options section."
1484 :group 'org-agenda-sorting
1485 :type `(choice
1486 (repeat :tag "General" ,org-sorting-choice)
1487 (list :tag "Individually"
1488 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1489 (repeat ,org-sorting-choice))
1490 (cons (const :tag "Strategy for TODO lists" todo)
1491 (repeat ,org-sorting-choice))
1492 (cons (const :tag "Strategy for Tags matches" tags)
1493 (repeat ,org-sorting-choice))
1494 (cons (const :tag "Strategy for search matches" search)
1495 (repeat ,org-sorting-choice)))))
1497 (defcustom org-agenda-cmp-user-defined nil
1498 "A function to define the comparison `user-defined'.
1499 This function must receive two arguments, agenda entry a and b.
1500 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1501 the user comparison, return nil.
1502 When this is defined, you can make `user-defined-up' and `user-defined-down'
1503 part of an agenda sorting strategy."
1504 :group 'org-agenda-sorting
1505 :type 'symbol)
1507 (defcustom org-sort-agenda-notime-is-late t
1508 "Non-nil means items without time are considered late.
1509 This is only relevant for sorting. When t, items which have no explicit
1510 time like 15:30 will be considered as 99:01, i.e. later than any items which
1511 do have a time. When nil, the default time is before 0:00. You can use this
1512 option to decide if the schedule for today should come before or after timeless
1513 agenda entries."
1514 :group 'org-agenda-sorting
1515 :type 'boolean)
1517 (defcustom org-sort-agenda-noeffort-is-high t
1518 "Non-nil means items without effort estimate are sorted as high effort.
1519 This also applies when filtering an agenda view with respect to the
1520 < or > effort operator. Then, tasks with no effort defined will be treated
1521 as tasks with high effort.
1522 When nil, such items are sorted as 0 minutes effort."
1523 :group 'org-agenda-sorting
1524 :type 'boolean)
1526 (defgroup org-agenda-line-format nil
1527 "Options concerning the entry prefix in the Org-mode agenda display."
1528 :tag "Org Agenda Line Format"
1529 :group 'org-agenda)
1531 (defcustom org-agenda-prefix-format
1532 '((agenda . " %i %-12:c%?-12t% s")
1533 (timeline . " % s")
1534 (todo . " %i %-12:c")
1535 (tags . " %i %-12:c")
1536 (search . " %i %-12:c"))
1537 "Format specifications for the prefix of items in the agenda views.
1538 An alist with five entries, each for the different agenda types. The
1539 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1540 The values are format strings.
1542 This format works similar to a printf format, with the following meaning:
1544 %c the category of the item, \"Diary\" for entries from the diary,
1545 or as given by the CATEGORY keyword or derived from the file name
1546 %e the effort required by the item
1547 %l the level of the item (insert X space(s) if item is of level X)
1548 %i the icon category of the item, see `org-agenda-category-icon-alist'
1549 %T the last tag of the item (ignore inherited tags, which come first)
1550 %t the HH:MM time-of-day specification if one applies to the entry
1551 %s Scheduling/Deadline information, a short string
1552 %b show breadcrumbs, i.e., the names of the higher levels
1553 %(expression) Eval EXPRESSION and replace the control string
1554 by the result
1556 All specifiers work basically like the standard `%s' of printf, but may
1557 contain two additional characters: a question mark just after the `%'
1558 and a whitespace/punctuation character just before the final letter.
1560 If the first character after `%' is a question mark, the entire field
1561 will only be included if the corresponding value applies to the current
1562 entry. This is useful for fields which should have fixed width when
1563 present, but zero width when absent. For example, \"%?-12t\" will
1564 result in a 12 character time field if a time of the day is specified,
1565 but will completely disappear in entries which do not contain a time.
1567 If there is punctuation or whitespace character just before the
1568 final format letter, this character will be appended to the field
1569 value if the value is not empty. For example, the format
1570 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1571 the category is empty, no additional colon is inserted.
1573 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1574 which means:
1576 - Indent the line with two space characters
1577 - Give the category a 12 chars wide field, padded with whitespace on
1578 the right (because of `-'). Append a colon if there is a category
1579 (because of `:').
1580 - If there is a time-of-day, put it into a 12 chars wide field. If no
1581 time, don't put in an empty field, just skip it (because of '?').
1582 - Finally, put the scheduling information.
1584 See also the variables `org-agenda-remove-times-when-in-prefix' and
1585 `org-agenda-remove-tags'.
1587 Custom commands can set this variable in the options section."
1588 :type '(choice
1589 (string :tag "General format")
1590 (list :greedy t :tag "View dependent"
1591 (cons (const agenda) (string :tag "Format"))
1592 (cons (const timeline) (string :tag "Format"))
1593 (cons (const todo) (string :tag "Format"))
1594 (cons (const tags) (string :tag "Format"))
1595 (cons (const search) (string :tag "Format"))))
1596 :group 'org-agenda-line-format)
1598 (defvar org-prefix-format-compiled nil
1599 "The compiled prefix format and associated variables.
1600 This is a list where first element is a list of variable bindings, and second
1601 element is the compiled format expression. See the variable
1602 `org-agenda-prefix-format'.")
1604 (defcustom org-agenda-todo-keyword-format "%-1s"
1605 "Format for the TODO keyword in agenda lines.
1606 Set this to something like \"%-12s\" if you want all TODO keywords
1607 to occupy a fixed space in the agenda display."
1608 :group 'org-agenda-line-format
1609 :type 'string)
1611 (defcustom org-agenda-diary-sexp-prefix nil
1612 "A regexp that matches part of a diary sexp entry
1613 which should be treated as scheduling/deadline information in
1614 `org-agenda'.
1616 For example, you can use this to extract the `diary-remind-message' from
1617 `diary-remind' entries."
1618 :group 'org-agenda-line-format
1619 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1621 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1622 "Text preceding timerange entries in the agenda view.
1623 This is a list with two strings. The first applies when the range
1624 is entirely on one day. The second applies if the range spans several days.
1625 The strings may have two \"%d\" format specifiers which will be filled
1626 with the sequence number of the days, and the total number of days in the
1627 range, respectively."
1628 :group 'org-agenda-line-format
1629 :type '(list
1630 (string :tag "Deadline today ")
1631 (choice :tag "Deadline relative"
1632 (string :tag "Format string")
1633 (function))))
1635 (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
1636 "Text preceding scheduled items in the agenda view.
1637 This is a list with two strings. The first applies when the item is
1638 scheduled on the current day. The second applies when it has been scheduled
1639 previously, it may contain a %d indicating that this is the nth time that
1640 this item is scheduled, due to automatic rescheduling of unfinished items
1641 for the following day. So this number is one larger than the number of days
1642 that passed since this item was scheduled first."
1643 :group 'org-agenda-line-format
1644 :version "24.4"
1645 :package-version '(Org . "8.0")
1646 :type '(list
1647 (string :tag "Scheduled today ")
1648 (string :tag "Scheduled previously")))
1650 (defcustom org-agenda-inactive-leader "["
1651 "Text preceding item pulled into the agenda by inactive time stamps.
1652 These entries are added to the agenda when pressing \"[\"."
1653 :group 'org-agenda-line-format
1654 :version "24.1"
1655 :type '(list
1656 (string :tag "Scheduled today ")
1657 (string :tag "Scheduled previously")))
1659 (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
1660 "Text preceding deadline items in the agenda view.
1661 This is a list with three strings. The first applies when the item has its
1662 deadline on the current day. The second applies when the deadline is in the
1663 future, the third one when it is in the past. The strings may contain %d
1664 to capture the number of days."
1665 :group 'org-agenda-line-format
1666 :version "24.4"
1667 :package-version '(Org . "8.0")
1668 :type '(list
1669 (string :tag "Deadline today ")
1670 (choice :tag "Deadline relative"
1671 (string :tag "Format string")
1672 (function))))
1674 (defcustom org-agenda-remove-times-when-in-prefix t
1675 "Non-nil means remove duplicate time specifications in agenda items.
1676 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1677 time-of-day specification in a headline or diary entry is extracted and
1678 placed into the prefix. If this option is non-nil, the original specification
1679 \(a timestamp or -range, or just a plain time(range) specification like
1680 11:30-4pm) will be removed for agenda display. This makes the agenda less
1681 cluttered.
1682 The option can be t or nil. It may also be the symbol `beg', indicating
1683 that the time should only be removed when it is located at the beginning of
1684 the headline/diary entry."
1685 :group 'org-agenda-line-format
1686 :type '(choice
1687 (const :tag "Always" t)
1688 (const :tag "Never" nil)
1689 (const :tag "When at beginning of entry" beg)))
1691 (defcustom org-agenda-remove-timeranges-from-blocks nil
1692 "Non-nil means remove time ranges specifications in agenda
1693 items that span on several days."
1694 :group 'org-agenda-line-format
1695 :version "24.1"
1696 :type 'boolean)
1698 (defcustom org-agenda-default-appointment-duration nil
1699 "Default duration for appointments that only have a starting time.
1700 When nil, no duration is specified in such cases.
1701 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1702 :group 'org-agenda-line-format
1703 :type '(choice
1704 (integer :tag "Minutes")
1705 (const :tag "No default duration")))
1707 (defcustom org-agenda-show-inherited-tags t
1708 "Non-nil means show inherited tags in each agenda line.
1710 When this option is set to 'always, it take precedences over
1711 `org-agenda-use-tag-inheritance' and inherited tags are shown
1712 in every agenda.
1714 When this option is set to t (the default), inherited tags are
1715 shown when they are available, i.e. when the value of
1716 `org-agenda-use-tag-inheritance' has been taken into account.
1718 This can be set to a list of agenda types in which the agenda
1719 must display the inherited tags. Available types are 'todo,
1720 'agenda, 'search and 'timeline.
1722 When set to nil, never show inherited tags in agenda lines."
1723 :group 'org-agenda-line-format
1724 :group 'org-agenda
1725 :version "24.3"
1726 :type '(choice
1727 (const :tag "Show inherited tags when available" t)
1728 (const :tag "Always show inherited tags" 'always)
1729 (repeat :tag "Show inherited tags only in selected agenda types"
1730 (symbol :tag "Agenda type"))))
1732 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1733 "List of agenda view types where to use tag inheritance.
1735 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1736 controlled by `org-use-tag-inheritance'. In other agenda types,
1737 `org-use-tag-inheritance' is not used for the selection of the
1738 agenda entries. Still, you may want the agenda to be aware of
1739 the inherited tags anyway, e.g. for later tag filtering.
1741 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1743 This variable has no effect if `org-agenda-show-inherited-tags'
1744 is set to 'always. In that case, the agenda is aware of those
1745 tags.
1747 The default value sets tags in every agenda type. Setting this
1748 option to nil will speed up non-tags agenda view a lot."
1749 :group 'org-agenda
1750 :version "24.3"
1751 :type '(choice
1752 (const :tag "Use tag inheritance in all agenda types" t)
1753 (repeat :tag "Use tag inheritance in selected agenda types"
1754 (symbol :tag "Agenda type"))))
1756 (defcustom org-agenda-hide-tags-regexp nil
1757 "Regular expression used to filter away specific tags in agenda views.
1758 This means that these tags will be present, but not be shown in the agenda
1759 line. Secondary filtering will still work on the hidden tags.
1760 Nil means don't hide any tags."
1761 :group 'org-agenda-line-format
1762 :type '(choice
1763 (const :tag "Hide none" nil)
1764 (string :tag "Regexp ")))
1766 (defcustom org-agenda-remove-tags nil
1767 "Non-nil means remove the tags from the headline copy in the agenda.
1768 When this is the symbol `prefix', only remove tags when
1769 `org-agenda-prefix-format' contains a `%T' specifier."
1770 :group 'org-agenda-line-format
1771 :type '(choice
1772 (const :tag "Always" t)
1773 (const :tag "Never" nil)
1774 (const :tag "When prefix format contains %T" prefix)))
1776 (if (fboundp 'defvaralias)
1777 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1778 'org-agenda-remove-tags))
1780 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1781 "Shift tags in agenda items to this column.
1782 If this number is positive, it specifies the column. If it is negative,
1783 it means that the tags should be flushright to that column. For example,
1784 -80 works well for a normal 80 character screen."
1785 :group 'org-agenda-line-format
1786 :type 'integer)
1788 (if (fboundp 'defvaralias)
1789 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1791 (defcustom org-agenda-fontify-priorities 'cookies
1792 "Non-nil means highlight low and high priorities in agenda.
1793 When t, the highest priority entries are bold, lowest priority italic.
1794 However, settings in `org-priority-faces' will overrule these faces.
1795 When this variable is the symbol `cookies', only fontify the
1796 cookies, not the entire task.
1797 This may also be an association list of priority faces, whose
1798 keys are the character values of `org-highest-priority',
1799 `org-default-priority', and `org-lowest-priority' (the default values
1800 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1801 color as a string, or a list like `(:background \"Red\")'.
1802 If it is a color, the variable `org-faces-easy-properties'
1803 determines if it is a foreground or a background color."
1804 :group 'org-agenda-line-format
1805 :type '(choice
1806 (const :tag "Never" nil)
1807 (const :tag "Defaults" t)
1808 (const :tag "Cookies only" cookies)
1809 (repeat :tag "Specify"
1810 (list (character :tag "Priority" :value ?A)
1811 (choice :tag "Face "
1812 (string :tag "Color")
1813 (sexp :tag "Face"))))))
1815 (defcustom org-agenda-day-face-function nil
1816 "Function called to determine what face should be used to display a day.
1817 The only argument passed to that function is the day. It should
1818 returns a face, or nil if does not want to specify a face and let
1819 the normal rules apply."
1820 :group 'org-agenda-line-format
1821 :version "24.1"
1822 :type 'function)
1824 (defcustom org-agenda-category-icon-alist nil
1825 "Alist of category icon to be displayed in agenda views.
1827 Each entry should have the following format:
1829 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1831 Where CATEGORY-REGEXP is a regexp matching the categories where
1832 the icon should be displayed.
1833 FILE-OR-DATA either a file path or a string containing image data.
1835 The other fields can be omitted safely if not needed:
1836 TYPE indicates the image type.
1837 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1838 image data.
1839 PROPS are additional image attributes to assign to the image,
1840 like, e.g. `:ascent center'.
1842 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1844 If you want to set the display properties yourself, just put a
1845 list as second element:
1847 (CATEGORY-REGEXP (MY PROPERTY LIST))
1849 For example, to display a 16px horizontal space for Emacs
1850 category, you can use:
1852 (\"Emacs\" '(space . (:width (16))))"
1853 :group 'org-agenda-line-format
1854 :version "24.1"
1855 :type '(alist :key-type (string :tag "Regexp matching category")
1856 :value-type (choice (list :tag "Icon"
1857 (string :tag "File or data")
1858 (symbol :tag "Type")
1859 (boolean :tag "Data?")
1860 (repeat :tag "Extra image properties" :inline t symbol))
1861 (list :tag "Display properties" sexp))))
1863 (defgroup org-agenda-column-view nil
1864 "Options concerning column view in the agenda."
1865 :tag "Org Agenda Column View"
1866 :group 'org-agenda)
1868 (defcustom org-agenda-columns-show-summaries t
1869 "Non-nil means show summaries for columns displayed in the agenda view."
1870 :group 'org-agenda-column-view
1871 :type 'boolean)
1873 (defcustom org-agenda-columns-compute-summary-properties t
1874 "Non-nil means recompute all summary properties before column view.
1875 When column view in the agenda is listing properties that have a summary
1876 operator, it can go to all relevant buffers and recompute the summaries
1877 there. This can mean overhead for the agenda column view, but is necessary
1878 to have thing up to date.
1879 As a special case, a CLOCKSUM property also makes sure that the clock
1880 computations are current."
1881 :group 'org-agenda-column-view
1882 :type 'boolean)
1884 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1885 "Non-nil means the duration of an appointment will add to day effort.
1886 The property to which appointment durations will be added is the one given
1887 in the option `org-effort-property'. If an appointment does not have
1888 an end time, `org-agenda-default-appointment-duration' will be used. If that
1889 is not set, an appointment without end time will not contribute to the time
1890 estimate."
1891 :group 'org-agenda-column-view
1892 :type 'boolean)
1894 (defcustom org-agenda-auto-exclude-function nil
1895 "A function called with a tag to decide if it is filtered on '/ RET'.
1896 The sole argument to the function, which is called once for each
1897 possible tag, is a string giving the name of the tag. The
1898 function should return either nil if the tag should be included
1899 as normal, or \"-<TAG>\" to exclude the tag.
1900 Note that for the purpose of tag filtering, only the lower-case version of
1901 all tags will be considered, so that this function will only ever see
1902 the lower-case version of all tags."
1903 :group 'org-agenda
1904 :type 'function)
1906 (defcustom org-agenda-bulk-custom-functions nil
1907 "Alist of characters and custom functions for bulk actions.
1908 For example, this value makes those two functions available:
1910 '((?R set-category)
1911 (?C bulk-cut))
1913 With selected entries in an agenda buffer, `B R' will call
1914 the custom function `set-category' on the selected entries.
1915 Note that functions in this alist don't need to be quoted."
1916 :type 'alist
1917 :version "24.1"
1918 :group 'org-agenda)
1920 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1921 "Execute BODY with point at location given by `org-hd-marker' property.
1922 If STRING is non-nil, the text property will be fetched from position 0
1923 in that string. If STRING is nil, it will be fetched from the beginning
1924 of the current line."
1925 (org-with-gensyms (marker)
1926 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1927 'org-hd-marker ,string)))
1928 (with-current-buffer (marker-buffer ,marker)
1929 (save-excursion
1930 (goto-char ,marker)
1931 ,@body)))))
1932 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1934 (defun org-add-agenda-custom-command (entry)
1935 "Replace or add a command in `org-agenda-custom-commands'.
1936 This is mostly for hacking and trying a new command - once the command
1937 works you probably want to add it to `org-agenda-custom-commands' for good."
1938 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1939 (if ass
1940 (setcdr ass (cdr entry))
1941 (push entry org-agenda-custom-commands))))
1943 ;;; Define the org-agenda-mode
1945 (defvar org-agenda-mode-map (make-sparse-keymap)
1946 "Keymap for `org-agenda-mode'.")
1947 (if (fboundp 'defvaralias)
1948 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1950 (defvar org-agenda-menu) ; defined later in this file.
1951 (defvar org-agenda-restrict nil) ; defined later in this file.
1952 (defvar org-agenda-follow-mode nil)
1953 (defvar org-agenda-entry-text-mode nil)
1954 (defvar org-agenda-clockreport-mode nil)
1955 (defvar org-agenda-show-log nil)
1956 (defvar org-agenda-redo-command nil)
1957 (defvar org-agenda-query-string nil)
1958 (defvar org-agenda-mode-hook nil
1959 "Hook run after `org-agenda-mode' is turned on.
1960 The buffer is still writable when this hook is called.")
1961 (defvar org-agenda-type nil)
1962 (defvar org-agenda-force-single-file nil)
1963 (defvar org-agenda-bulk-marked-entries nil
1964 "List of markers that refer to marked entries in the agenda.")
1966 ;;; Multiple agenda buffers support
1968 (defcustom org-agenda-sticky nil
1969 "Non-nil means agenda q key will bury agenda buffers.
1970 Agenda commands will then show existing buffer instead of generating new ones.
1971 When nil, `q' will kill the single agenda buffer."
1972 :group 'org-agenda
1973 :version "24.3"
1974 :type 'boolean)
1977 ;;;###autoload
1978 (defun org-toggle-sticky-agenda (&optional arg)
1979 "Toggle `org-agenda-sticky'."
1980 (interactive "P")
1981 (let ((new-value (if arg
1982 (> (prefix-numeric-value arg) 0)
1983 (not org-agenda-sticky))))
1984 (if (equal new-value org-agenda-sticky)
1985 (and (org-called-interactively-p 'interactive)
1986 (message "Sticky agenda was already %s"
1987 (if org-agenda-sticky "enabled" "disabled")))
1988 (setq org-agenda-sticky new-value)
1989 (org-agenda-kill-all-agenda-buffers)
1990 (and (org-called-interactively-p 'interactive)
1991 (message "Sticky agenda was %s"
1992 (if org-agenda-sticky "enabled" "disabled"))))))
1994 (defvar org-agenda-buffer nil
1995 "Agenda buffer currently being generated.")
1997 (defvar org-agenda-last-prefix-arg nil)
1998 (defvar org-agenda-this-buffer-name nil)
1999 (defvar org-agenda-doing-sticky-redo nil)
2000 (defvar org-agenda-this-buffer-is-sticky nil)
2002 (defconst org-agenda-local-vars
2003 '(org-agenda-this-buffer-name
2004 org-agenda-undo-list
2005 org-agenda-pending-undo-list
2006 org-agenda-follow-mode
2007 org-agenda-entry-text-mode
2008 org-agenda-clockreport-mode
2009 org-agenda-show-log
2010 org-agenda-redo-command
2011 org-agenda-query-string
2012 org-agenda-type
2013 org-agenda-bulk-marked-entries
2014 org-agenda-undo-has-started-in
2015 org-agenda-info
2016 org-agenda-tag-filter-overlays
2017 org-agenda-cat-filter-overlays
2018 org-agenda-pre-window-conf
2019 org-agenda-columns-active
2020 org-agenda-tag-filter
2021 org-agenda-category-filter
2022 org-agenda-markers
2023 org-agenda-last-search-view-search-was-boolean
2024 org-agenda-filtered-by-category
2025 org-agenda-filter-form
2026 org-agenda-cycle-counter
2027 org-agenda-last-prefix-arg)
2028 "Variables that must be local in agenda buffers to allow multiple buffers.")
2030 (defun org-agenda-mode ()
2031 "Mode for time-sorted view on action items in Org-mode files.
2033 The following commands are available:
2035 \\{org-agenda-mode-map}"
2036 (interactive)
2037 (cond (org-agenda-doing-sticky-redo
2038 ;; Refreshing sticky agenda-buffer
2040 ;; Preserve the value of `org-agenda-local-vars' variables,
2041 ;; while letting `kill-all-local-variables' kill the rest
2042 (let ((save (buffer-local-variables)))
2043 (kill-all-local-variables)
2044 (mapc 'make-local-variable org-agenda-local-vars)
2045 (dolist (elem save)
2046 (let ((var (car elem))
2047 (val (cdr elem)))
2048 (when (and val
2049 (member var org-agenda-local-vars))
2050 (set var val)))))
2051 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2052 (org-agenda-sticky
2053 ;; Creating a sticky Agenda buffer for the first time
2054 (kill-all-local-variables)
2055 (mapc 'make-local-variable org-agenda-local-vars)
2056 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2058 ;; Creating a non-sticky agenda buffer
2059 (kill-all-local-variables)
2060 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2061 (setq org-agenda-undo-list nil
2062 org-agenda-pending-undo-list nil
2063 org-agenda-bulk-marked-entries nil)
2064 (setq major-mode 'org-agenda-mode)
2065 ;; Keep global-font-lock-mode from turning on font-lock-mode
2066 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2067 (setq mode-name "Org-Agenda")
2068 (use-local-map org-agenda-mode-map)
2069 (easy-menu-add org-agenda-menu)
2070 (if org-startup-truncated (setq truncate-lines t))
2071 (org-set-local 'line-move-visual nil)
2072 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2073 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2074 ;; Make sure properties are removed when copying text
2075 (make-local-variable 'filter-buffer-substring-functions)
2076 (add-hook 'filter-buffer-substring-functions
2077 (lambda (fun start end delete)
2078 (substring-no-properties (funcall fun start end delete))))
2079 (unless org-agenda-keep-modes
2080 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2081 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2082 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2083 org-agenda-show-log org-agenda-start-with-log-mode))
2085 (easy-menu-change
2086 '("Agenda") "Agenda Files"
2087 (append
2088 (list
2089 (vector
2090 (if (get 'org-agenda-files 'org-restrict)
2091 "Restricted to single file"
2092 "Edit File List")
2093 '(org-edit-agenda-file-list)
2094 (not (get 'org-agenda-files 'org-restrict)))
2095 "--")
2096 (mapcar 'org-file-menu-entry (org-agenda-files))))
2097 (org-agenda-set-mode-name)
2098 (apply
2099 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2100 (list 'org-agenda-mode-hook)))
2102 (substitute-key-definition 'undo 'org-agenda-undo
2103 org-agenda-mode-map global-map)
2104 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2105 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2106 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2107 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2108 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2109 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2110 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2111 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2112 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2113 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2114 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2115 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2116 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2117 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2119 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2120 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2121 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2122 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2123 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2124 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2125 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2126 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2127 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2128 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2129 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2130 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2131 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2132 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2133 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2134 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2135 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2136 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2137 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2138 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2139 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2140 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2141 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2142 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2143 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2144 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2145 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2146 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2147 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2148 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2149 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2151 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2152 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2153 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2154 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2155 (while l (org-defkey org-agenda-mode-map
2156 (int-to-string (pop l)) 'digit-argument)))
2158 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2159 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2160 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2161 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2162 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2163 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2164 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2165 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2166 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2167 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2168 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2169 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2170 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2171 'org-clock-modify-effort-estimate)
2172 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2173 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2174 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2175 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2176 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2177 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2178 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2179 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2180 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2181 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2182 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2183 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2184 (substitute-key-definition 'next-line 'org-agenda-next-line
2185 org-agenda-mode-map global-map)
2186 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2187 org-agenda-mode-map global-map)
2188 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2189 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2190 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2191 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2192 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2193 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2194 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2195 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2196 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2197 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2198 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2199 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2200 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2201 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2202 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2203 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2204 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2205 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2206 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2207 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2208 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2209 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2210 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2211 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2212 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2213 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2214 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2215 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2216 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2217 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2219 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2220 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2221 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2222 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2223 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2224 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2225 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2226 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2227 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2228 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2229 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2230 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2232 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2233 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2234 (when org-agenda-mouse-1-follows-link
2235 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2236 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2237 '("Agenda"
2238 ("Agenda Files")
2239 "--"
2240 ("Agenda Dates"
2241 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2242 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2243 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2244 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2245 "--"
2246 ("View"
2247 ["Day View" org-agenda-day-view
2248 :active (org-agenda-check-type nil 'agenda)
2249 :style radio :selected (eq org-agenda-current-span 'day)
2250 :keys "v d (or just d)"]
2251 ["Week View" org-agenda-week-view
2252 :active (org-agenda-check-type nil 'agenda)
2253 :style radio :selected (eq org-agenda-current-span 'week)
2254 :keys "v w (or just w)"]
2255 ["Month View" org-agenda-month-view
2256 :active (org-agenda-check-type nil 'agenda)
2257 :style radio :selected (eq org-agenda-current-span 'month)
2258 :keys "v m"]
2259 ["Year View" org-agenda-year-view
2260 :active (org-agenda-check-type nil 'agenda)
2261 :style radio :selected (eq org-agenda-current-span 'year)
2262 :keys "v y"]
2263 "--"
2264 ["Include Diary" org-agenda-toggle-diary
2265 :style toggle :selected org-agenda-include-diary
2266 :active (org-agenda-check-type nil 'agenda)]
2267 ["Include Deadlines" org-agenda-toggle-deadlines
2268 :style toggle :selected org-agenda-include-deadlines
2269 :active (org-agenda-check-type nil 'agenda)]
2270 ["Use Time Grid" org-agenda-toggle-time-grid
2271 :style toggle :selected org-agenda-use-time-grid
2272 :active (org-agenda-check-type nil 'agenda)]
2273 "--"
2274 ["Show clock report" org-agenda-clockreport-mode
2275 :style toggle :selected org-agenda-clockreport-mode
2276 :active (org-agenda-check-type nil 'agenda)]
2277 ["Show some entry text" org-agenda-entry-text-mode
2278 :style toggle :selected org-agenda-entry-text-mode
2279 :active t]
2280 "--"
2281 ["Show Logbook entries" org-agenda-log-mode
2282 :style toggle :selected org-agenda-show-log
2283 :active (org-agenda-check-type nil 'agenda 'timeline)
2284 :keys "v l (or just l)"]
2285 ["Include archived trees" org-agenda-archives-mode
2286 :style toggle :selected org-agenda-archives-mode :active t
2287 :keys "v a"]
2288 ["Include archive files" (org-agenda-archives-mode t)
2289 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2290 :keys "v A"]
2291 "--"
2292 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2293 ["Write view to file" org-agenda-write t]
2294 ["Rebuild buffer" org-agenda-redo t]
2295 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2296 "--"
2297 ["Show original entry" org-agenda-show t]
2298 ["Go To (other window)" org-agenda-goto t]
2299 ["Go To (this window)" org-agenda-switch-to t]
2300 ["Capture with cursor date" org-agenda-capture t]
2301 ["Follow Mode" org-agenda-follow-mode
2302 :style toggle :selected org-agenda-follow-mode :active t]
2303 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2304 "--"
2305 ("TODO"
2306 ["Cycle TODO" org-agenda-todo t]
2307 ["Next TODO set" org-agenda-todo-nextset t]
2308 ["Previous TODO set" org-agenda-todo-previousset t]
2309 ["Add note" org-agenda-add-note t])
2310 ("Archive/Refile/Delete"
2311 ["Archive default" org-agenda-archive-default t]
2312 ["Archive default" org-agenda-archive-default-with-confirmation t]
2313 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2314 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2315 ["Archive subtree" org-agenda-archive t]
2316 "--"
2317 ["Refile" org-agenda-refile t]
2318 "--"
2319 ["Delete subtree" org-agenda-kill t])
2320 ("Bulk action"
2321 ["Mark entry" org-agenda-bulk-mark t]
2322 ["Mark all" org-agenda-bulk-mark-all t]
2323 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2324 ["Unmark entry" org-agenda-bulk-unmark t]
2325 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2326 ["Act on all marked" org-agenda-bulk-action t]
2327 "--"
2328 ("Tags and Properties"
2329 ["Show all Tags" org-agenda-show-tags t]
2330 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2331 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2332 "--"
2333 ["Column View" org-columns t])
2334 ("Deadline/Schedule"
2335 ["Schedule" org-agenda-schedule t]
2336 ["Set Deadline" org-agenda-deadline t]
2337 "--"
2338 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2339 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2340 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2341 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2342 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2343 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2344 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2345 ("Clock and Effort"
2346 ["Clock in" org-agenda-clock-in t]
2347 ["Clock out" org-agenda-clock-out t]
2348 ["Clock cancel" org-agenda-clock-cancel t]
2349 ["Goto running clock" org-clock-goto t]
2350 "--"
2351 ["Set Effort" org-agenda-set-effort t]
2352 ["Change clocked effort" org-clock-modify-effort-estimate
2353 (org-clock-is-active)])
2354 ("Priority"
2355 ["Set Priority" org-agenda-priority t]
2356 ["Increase Priority" org-agenda-priority-up t]
2357 ["Decrease Priority" org-agenda-priority-down t]
2358 ["Show Priority" org-show-priority t])
2359 ("Calendar/Diary"
2360 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2361 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2362 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2363 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2364 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2365 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2366 "--"
2367 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2368 "--"
2369 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2370 "--"
2371 ("MobileOrg"
2372 ["Push Files and Views" org-mobile-push t]
2373 ["Get Captured and Flagged" org-mobile-pull t]
2374 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2375 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2376 "--"
2377 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2378 "--"
2379 ["Quit" org-agenda-quit t]
2380 ["Exit and Release Buffers" org-agenda-exit t]
2383 ;;; Agenda undo
2385 (defvar org-agenda-allow-remote-undo t
2386 "Non-nil means allow remote undo from the agenda buffer.")
2387 (defvar org-agenda-undo-has-started-in nil
2388 "Buffers that have already seen `undo-start' in the current undo sequence.")
2390 (defun org-agenda-undo ()
2391 "Undo a remote editing step in the agenda.
2392 This undoes changes both in the agenda buffer and in the remote buffer
2393 that have been changed along."
2394 (interactive)
2395 (or org-agenda-allow-remote-undo
2396 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2397 (if (not (eq this-command last-command))
2398 (setq org-agenda-undo-has-started-in nil
2399 org-agenda-pending-undo-list org-agenda-undo-list))
2400 (if (not org-agenda-pending-undo-list)
2401 (error "No further undo information"))
2402 (let* ((entry (pop org-agenda-pending-undo-list))
2403 buf line cmd rembuf)
2404 (setq cmd (pop entry) line (pop entry))
2405 (setq rembuf (nth 2 entry))
2406 (org-with-remote-undo rembuf
2407 (while (bufferp (setq buf (pop entry)))
2408 (if (pop entry)
2409 (with-current-buffer buf
2410 (let ((last-undo-buffer buf)
2411 (inhibit-read-only t))
2412 (unless (memq buf org-agenda-undo-has-started-in)
2413 (push buf org-agenda-undo-has-started-in)
2414 (make-local-variable 'pending-undo-list)
2415 (undo-start))
2416 (while (and pending-undo-list
2417 (listp pending-undo-list)
2418 (not (car pending-undo-list)))
2419 (pop pending-undo-list))
2420 (undo-more 1))))))
2421 (org-goto-line line)
2422 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2424 (defun org-verify-change-for-undo (l1 l2)
2425 "Verify that a real change occurred between the undo lists L1 and L2."
2426 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2427 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2428 (not (eq l1 l2)))
2430 ;;; Agenda dispatch
2432 (defvar org-agenda-restrict-begin (make-marker))
2433 (defvar org-agenda-restrict-end (make-marker))
2434 (defvar org-agenda-last-dispatch-buffer nil)
2435 (defvar org-agenda-overriding-restriction nil)
2437 (defcustom org-agenda-custom-commands-contexts nil
2438 "Alist of custom agenda keys and contextual rules.
2440 For example, if you have a custom agenda command \"p\" and you
2441 want this command to be accessible only from plain text files,
2442 use this:
2444 '((\"p\" ((in-file . \"\\.txt\"))))
2446 Here are the available contexts definitions:
2448 in-file: command displayed only in matching files
2449 in-mode: command displayed only in matching modes
2450 not-in-file: command not displayed in matching files
2451 not-in-mode: command not displayed in matching modes
2452 in-buffer: command displayed only in matching buffers
2453 not-in-buffer: command not displayed in matching buffers
2454 [function]: a custom function taking no argument
2456 If you define several checks, the agenda command will be
2457 accessible if there is at least one valid check.
2459 You can also bind a key to another agenda custom command
2460 depending on contextual rules.
2462 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2464 Here it means: in .txt files, use \"p\" as the key for the
2465 agenda command otherwise associated with \"q\". (The command
2466 originally associated with \"q\" is not displayed to avoid
2467 duplicates.)"
2468 :version "24.3"
2469 :group 'org-agenda-custom-commands
2470 :type '(repeat (list :tag "Rule"
2471 (string :tag " Agenda key")
2472 (string :tag "Replace by command")
2473 (repeat :tag "Available when"
2474 (choice
2475 (cons :tag "Condition"
2476 (choice
2477 (const :tag "In file" in-file)
2478 (const :tag "Not in file" not-in-file)
2479 (const :tag "In buffer" in-buffer)
2480 (const :tag "Not in buffer" not-in-buffer)
2481 (const :tag "In mode" in-mode)
2482 (const :tag "Not in mode" not-in-mode))
2483 (regexp))
2484 (function :tag "Custom function"))))))
2486 (defcustom org-agenda-max-entries nil
2487 "Maximum number of entries to display in an agenda.
2488 This can be nil (no limit) or an integer or an alist of agenda
2489 types with an associated number of entries to display in this
2490 type."
2491 :version "24.4"
2492 :package-version '(Org . "8.0")
2493 :group 'org-agenda-custom-commands
2494 :type '(choice (symbol :tag "No limit" nil)
2495 (integer :tag "Max number of entries")
2496 (repeat
2497 (cons (choice :tag "Agenda type"
2498 (const agenda)
2499 (const todo)
2500 (const tags)
2501 (const search)
2502 (const timeline))
2503 (integer :tag "Max number of entries")))))
2505 (defcustom org-agenda-max-todos nil
2506 "Maximum number of TODOs to display in an agenda.
2507 This can be nil (no limit) or an integer or an alist of agenda
2508 types with an associated number of entries to display in this
2509 type."
2510 :version "24.4"
2511 :package-version '(Org . "8.0")
2512 :group 'org-agenda-custom-commands
2513 :type '(choice (symbol :tag "No limit" nil)
2514 (integer :tag "Max number of entries")
2515 (repeat
2516 (cons (choice :tag "Agenda type"
2517 (const agenda)
2518 (const todo)
2519 (const tags)
2520 (const search)
2521 (const timeline))
2522 (integer :tag "Max number of entries")))))
2524 (defcustom org-agenda-max-tags nil
2525 "Maximum number of tagged entries to display in an agenda.
2526 This can be nil (no limit) or an integer or an alist of agenda
2527 types with an associated number of entries to display in this
2528 type."
2529 :version "24.4"
2530 :package-version '(Org . "8.0")
2531 :group 'org-agenda-custom-commands
2532 :type '(choice (symbol :tag "No limit" nil)
2533 (integer :tag "Max number of entries")
2534 (repeat
2535 (cons (choice :tag "Agenda type"
2536 (const agenda)
2537 (const todo)
2538 (const tags)
2539 (const search)
2540 (const timeline))
2541 (integer :tag "Max number of entries")))))
2543 (defcustom org-agenda-max-effort nil
2544 "Maximum cumulated effort duration for the agenda.
2545 This can be nil (no limit) or a number of minutes (as an integer)
2546 or an alist of agenda types with an associated number of minutes
2547 to limit entries to in this type."
2548 :version "24.4"
2549 :package-version '(Org . "8.0")
2550 :group 'org-agenda-custom-commands
2551 :type '(choice (symbol :tag "No limit" nil)
2552 (integer :tag "Max number of entries")
2553 (repeat
2554 (cons (choice :tag "Agenda type"
2555 (const agenda)
2556 (const todo)
2557 (const tags)
2558 (const search)
2559 (const timeline))
2560 (integer :tag "Max number of entries")))))
2562 (defvar org-keys nil)
2563 (defvar org-match nil)
2564 ;;;###autoload
2565 (defun org-agenda (&optional arg org-keys restriction)
2566 "Dispatch agenda commands to collect entries to the agenda buffer.
2567 Prompts for a command to execute. Any prefix arg will be passed
2568 on to the selected command. The default selections are:
2570 a Call `org-agenda-list' to display the agenda for current day or week.
2571 t Call `org-todo-list' to display the global todo list.
2572 T Call `org-todo-list' to display the global todo list, select only
2573 entries with a specific TODO keyword (the user gets a prompt).
2574 m Call `org-tags-view' to display headlines with tags matching
2575 a condition (the user is prompted for the condition).
2576 M Like `m', but select only TODO entries, no ordinary headlines.
2577 L Create a timeline for the current buffer.
2578 e Export views to associated files.
2579 s Search entries for keywords.
2580 S Search entries for keywords, only with TODO keywords.
2581 / Multi occur across all agenda files and also files listed
2582 in `org-agenda-text-search-extra-files'.
2583 < Restrict agenda commands to buffer, subtree, or region.
2584 Press several times to get the desired effect.
2585 > Remove a previous restriction.
2586 # List \"stuck\" projects.
2587 ! Configure what \"stuck\" means.
2588 C Configure custom agenda commands.
2590 More commands can be added by configuring the variable
2591 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2592 searches can be pre-defined in this way.
2594 If the current buffer is in Org-mode and visiting a file, you can also
2595 first press `<' once to indicate that the agenda should be temporarily
2596 \(until the next use of \\[org-agenda]) restricted to the current file.
2597 Pressing `<' twice means to restrict to the current subtree or region
2598 \(if active)."
2599 (interactive "P")
2600 (catch 'exit
2601 (let* ((prefix-descriptions nil)
2602 (org-agenda-buffer-name org-agenda-buffer-name)
2603 (org-agenda-window-setup (if (equal (buffer-name)
2604 org-agenda-buffer-name)
2605 'current-window
2606 org-agenda-window-setup))
2607 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2608 (org-agenda-custom-commands
2609 ;; normalize different versions
2610 (delq nil
2611 (mapcar
2612 (lambda (x)
2613 (cond ((stringp (cdr x))
2614 (push x prefix-descriptions)
2615 nil)
2616 ((stringp (nth 1 x)) x)
2617 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2618 (t (cons (car x) (cons "" (cdr x))))))
2619 org-agenda-custom-commands)))
2620 (org-agenda-custom-commands
2621 (org-contextualize-keys
2622 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2623 (buf (current-buffer))
2624 (bfn (buffer-file-name (buffer-base-buffer)))
2625 entry key type org-match lprops ans)
2626 ;; Turn off restriction unless there is an overriding one,
2627 (unless org-agenda-overriding-restriction
2628 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2629 ;; There is a request to keep the file list in place
2630 (put 'org-agenda-files 'org-restrict nil))
2631 (setq org-agenda-restrict nil)
2632 (move-marker org-agenda-restrict-begin nil)
2633 (move-marker org-agenda-restrict-end nil))
2634 ;; Delete old local properties
2635 (put 'org-agenda-redo-command 'org-lprops nil)
2636 ;; Delete previously set last-arguments
2637 (put 'org-agenda-redo-command 'last-args nil)
2638 ;; Remember where this call originated
2639 (setq org-agenda-last-dispatch-buffer (current-buffer))
2640 (unless org-keys
2641 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2642 org-keys (car ans)
2643 restriction (cdr ans)))
2644 ;; If we have sticky agenda buffers, set a name for the buffer,
2645 ;; depending on the invoking keys. The user may still set this
2646 ;; as a command option, which will overwrite what we do here.
2647 (if org-agenda-sticky
2648 (setq org-agenda-buffer-name
2649 (format "*Org Agenda(%s)*" org-keys)))
2650 ;; Establish the restriction, if any
2651 (when (and (not org-agenda-overriding-restriction) restriction)
2652 (put 'org-agenda-files 'org-restrict (list bfn))
2653 (cond
2654 ((eq restriction 'region)
2655 (setq org-agenda-restrict t)
2656 (move-marker org-agenda-restrict-begin (region-beginning))
2657 (move-marker org-agenda-restrict-end (region-end)))
2658 ((eq restriction 'subtree)
2659 (save-excursion
2660 (setq org-agenda-restrict t)
2661 (org-back-to-heading t)
2662 (move-marker org-agenda-restrict-begin (point))
2663 (move-marker org-agenda-restrict-end
2664 (progn (org-end-of-subtree t)))))))
2666 ;; For example the todo list should not need it (but does...)
2667 (cond
2668 ((setq entry (assoc org-keys org-agenda-custom-commands))
2669 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2670 (progn
2671 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2672 lprops (nth 4 entry))
2673 (if org-agenda-sticky
2674 (setq org-agenda-buffer-name
2675 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2676 (format "*Org Agenda(%s)*" org-keys))))
2677 (put 'org-agenda-redo-command 'org-lprops lprops)
2678 (cond
2679 ((eq type 'agenda)
2680 (org-let lprops '(org-agenda-list current-prefix-arg)))
2681 ((eq type 'alltodo)
2682 (org-let lprops '(org-todo-list current-prefix-arg)))
2683 ((eq type 'search)
2684 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2685 ((eq type 'stuck)
2686 (org-let lprops '(org-agenda-list-stuck-projects
2687 current-prefix-arg)))
2688 ((eq type 'tags)
2689 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2690 ((eq type 'tags-todo)
2691 (org-let lprops '(org-tags-view '(4) org-match)))
2692 ((eq type 'todo)
2693 (org-let lprops '(org-todo-list org-match)))
2694 ((eq type 'tags-tree)
2695 (org-check-for-org-mode)
2696 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2697 ((eq type 'todo-tree)
2698 (org-check-for-org-mode)
2699 (org-let lprops
2700 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2701 (regexp-quote org-match) "\\>"))))
2702 ((eq type 'occur-tree)
2703 (org-check-for-org-mode)
2704 (org-let lprops '(org-occur org-match)))
2705 ((functionp type)
2706 (org-let lprops '(funcall type org-match)))
2707 ((fboundp type)
2708 (org-let lprops '(funcall type org-match)))
2709 (t (error "Invalid custom agenda command type %s" type))))
2710 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2711 ((equal org-keys "C")
2712 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2713 (customize-variable 'org-agenda-custom-commands))
2714 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2715 ((equal org-keys "s") (call-interactively 'org-search-view))
2716 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2717 ((equal org-keys "t") (call-interactively 'org-todo-list))
2718 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2719 ((equal org-keys "m") (call-interactively 'org-tags-view))
2720 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2721 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2722 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2723 (org-add-hook
2724 'post-command-hook
2725 (lambda ()
2726 (unless (current-message)
2727 (let* ((m (org-agenda-get-any-marker))
2728 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2729 (when note
2730 (message (concat
2731 "FLAGGING-NOTE ([?] for more info): "
2732 (org-add-props
2733 (replace-regexp-in-string
2734 "\\\\n" "//"
2735 (copy-sequence note))
2736 nil 'face 'org-warning)))))))
2737 t t))
2738 ((equal org-keys "L")
2739 (unless (derived-mode-p 'org-mode)
2740 (error "This is not an Org-mode file"))
2741 (unless restriction
2742 (put 'org-agenda-files 'org-restrict (list bfn))
2743 (org-call-with-arg 'org-timeline arg)))
2744 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2745 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2746 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2747 (t (error "Invalid agenda key"))))))
2749 (defun org-agenda-append-agenda ()
2750 "Append another agenda view to the current one.
2751 This function allows interactive building of block agendas.
2752 Agenda views are separated by `org-agenda-block-separator'."
2753 (interactive)
2754 (unless (derived-mode-p 'org-agenda-mode)
2755 (error "Can only append from within agenda buffer"))
2756 (let ((org-agenda-multi t))
2757 (org-agenda)
2758 (widen)
2759 (org-agenda-finalize)
2760 (org-agenda-fit-window-to-buffer)))
2762 (defun org-agenda-normalize-custom-commands (cmds)
2763 (delq nil
2764 (mapcar
2765 (lambda (x)
2766 (cond ((stringp (cdr x)) nil)
2767 ((stringp (nth 1 x)) x)
2768 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2769 (t (cons (car x) (cons "" (cdr x))))))
2770 cmds)))
2772 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2773 "The user interface for selecting an agenda command."
2774 (catch 'exit
2775 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2776 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2777 (region-p (org-region-active-p))
2778 (custom org-agenda-custom-commands)
2779 (selstring "")
2780 restriction second-time
2781 c entry key type match prefixes rmheader header-end custom1 desc
2782 line lines left right n n1)
2783 (save-window-excursion
2784 (delete-other-windows)
2785 (org-switch-to-buffer-other-window " *Agenda Commands*")
2786 (erase-buffer)
2787 (insert (eval-when-compile
2788 (let ((header
2789 "Press key for an agenda command: < Buffer, subtree/region restriction
2790 -------------------------------- > Remove restriction
2791 a Agenda for current week or day e Export agenda views
2792 t List of all TODO entries T Entries with special TODO kwd
2793 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2794 s Search for keywords S Like s, but only TODO entries
2795 L Timeline for current buffer # List stuck projects (!=configure)
2796 / Multi-occur C Configure custom agenda commands
2797 ? Find :FLAGGED: entries * Toggle sticky agenda views
2799 (start 0))
2800 (while (string-match
2801 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2802 header start)
2803 (setq start (match-end 0))
2804 (add-text-properties (match-beginning 2) (match-end 2)
2805 '(face bold) header))
2806 header)))
2807 (setq header-end (point-marker))
2808 (while t
2809 (setq custom1 custom)
2810 (when (eq rmheader t)
2811 (org-goto-line 1)
2812 (re-search-forward ":" nil t)
2813 (delete-region (match-end 0) (point-at-eol))
2814 (forward-char 1)
2815 (looking-at "-+")
2816 (delete-region (match-end 0) (point-at-eol))
2817 (move-marker header-end (match-end 0)))
2818 (goto-char header-end)
2819 (delete-region (point) (point-max))
2821 ;; Produce all the lines that describe custom commands and prefixes
2822 (setq lines nil)
2823 (while (setq entry (pop custom1))
2824 (setq key (car entry) desc (nth 1 entry)
2825 type (nth 2 entry)
2826 match (nth 3 entry))
2827 (if (> (length key) 1)
2828 (add-to-list 'prefixes (string-to-char key))
2829 (setq line
2830 (format
2831 "%-4s%-14s"
2832 (org-add-props (copy-sequence key)
2833 '(face bold))
2834 (cond
2835 ((string-match "\\S-" desc) desc)
2836 ((eq type 'agenda) "Agenda for current week or day")
2837 ((eq type 'alltodo) "List of all TODO entries")
2838 ((eq type 'search) "Word search")
2839 ((eq type 'stuck) "List of stuck projects")
2840 ((eq type 'todo) "TODO keyword")
2841 ((eq type 'tags) "Tags query")
2842 ((eq type 'tags-todo) "Tags (TODO)")
2843 ((eq type 'tags-tree) "Tags tree")
2844 ((eq type 'todo-tree) "TODO kwd tree")
2845 ((eq type 'occur-tree) "Occur tree")
2846 ((functionp type) (if (symbolp type)
2847 (symbol-name type)
2848 "Lambda expression"))
2849 (t "???"))))
2850 (if org-agenda-menu-show-matcher
2851 (setq line
2852 (concat line ": "
2853 (cond
2854 ((stringp match)
2855 (setq match (copy-sequence match))
2856 (org-add-props match nil 'face 'org-warning))
2857 ((listp type)
2858 (format "set of %d commands" (length type))))))
2859 (if (org-string-nw-p match)
2860 (add-text-properties
2861 0 (length line) (list 'help-echo
2862 (concat "Matcher: " match)) line)))
2863 (push line lines)))
2864 (setq lines (nreverse lines))
2865 (when prefixes
2866 (mapc (lambda (x)
2867 (push
2868 (format "%s %s"
2869 (org-add-props (char-to-string x)
2870 nil 'face 'bold)
2871 (or (cdr (assoc (concat selstring
2872 (char-to-string x))
2873 prefix-descriptions))
2874 "Prefix key"))
2875 lines))
2876 prefixes))
2878 ;; Check if we should display in two columns
2879 (if org-agenda-menu-two-columns
2880 (progn
2881 (setq n (length lines)
2882 n1 (+ (/ n 2) (mod n 2))
2883 right (nthcdr n1 lines)
2884 left (copy-sequence lines))
2885 (setcdr (nthcdr (1- n1) left) nil))
2886 (setq left lines right nil))
2887 (while left
2888 (insert "\n" (pop left))
2889 (when right
2890 (if (< (current-column) 40)
2891 (move-to-column 40 t)
2892 (insert " "))
2893 (insert (pop right))))
2895 ;; Make the window the right size
2896 (goto-char (point-min))
2897 (if second-time
2898 (if (not (pos-visible-in-window-p (point-max)))
2899 (org-fit-window-to-buffer))
2900 (setq second-time t)
2901 (org-fit-window-to-buffer))
2903 ;; Ask for selection
2904 (message "Press key for agenda command%s:"
2905 (if (or restrict-ok org-agenda-overriding-restriction)
2906 (if org-agenda-overriding-restriction
2907 " (restriction lock active)"
2908 (if restriction
2909 (format " (restricted to %s)" restriction)
2910 " (unrestricted)"))
2911 ""))
2912 (setq c (read-char-exclusive))
2913 (message "")
2914 (cond
2915 ((assoc (char-to-string c) custom)
2916 (setq selstring (concat selstring (char-to-string c)))
2917 (throw 'exit (cons selstring restriction)))
2918 ((memq c prefixes)
2919 (setq selstring (concat selstring (char-to-string c))
2920 prefixes nil
2921 rmheader (or rmheader t)
2922 custom (delq nil (mapcar
2923 (lambda (x)
2924 (if (or (= (length (car x)) 1)
2925 (/= (string-to-char (car x)) c))
2927 (cons (substring (car x) 1) (cdr x))))
2928 custom))))
2929 ((eq c ?*)
2930 (call-interactively 'org-toggle-sticky-agenda)
2931 (sit-for 2))
2932 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2933 (message "Restriction is only possible in Org-mode buffers")
2934 (ding) (sit-for 1))
2935 ((eq c ?1)
2936 (org-agenda-remove-restriction-lock 'noupdate)
2937 (setq restriction 'buffer))
2938 ((eq c ?0)
2939 (org-agenda-remove-restriction-lock 'noupdate)
2940 (setq restriction (if region-p 'region 'subtree)))
2941 ((eq c ?<)
2942 (org-agenda-remove-restriction-lock 'noupdate)
2943 (setq restriction
2944 (cond
2945 ((eq restriction 'buffer)
2946 (if region-p 'region 'subtree))
2947 ((memq restriction '(subtree region))
2948 nil)
2949 (t 'buffer))))
2950 ((eq c ?>)
2951 (org-agenda-remove-restriction-lock 'noupdate)
2952 (setq restriction nil))
2953 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2954 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2955 ((and (> (length selstring) 0) (eq c ?\d))
2956 (delete-window)
2957 (org-agenda-get-restriction-and-command prefix-descriptions))
2959 ((equal c ?q) (error "Abort"))
2960 (t (error "Invalid key %c" c))))))))
2962 (defun org-agenda-fit-window-to-buffer ()
2963 "Fit the window to the buffer size."
2964 (and (memq org-agenda-window-setup '(reorganize-frame))
2965 (fboundp 'fit-window-to-buffer)
2966 (org-fit-window-to-buffer
2968 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2969 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2971 (defvar org-cmd nil)
2972 (defvar org-agenda-overriding-cmd nil)
2973 (defvar org-agenda-overriding-arguments nil)
2974 (defvar org-agenda-overriding-cmd-arguments nil)
2975 (defun org-agenda-run-series (name series)
2976 (org-let (nth 1 series) '(org-agenda-prepare name))
2977 ;; We need to reset agenda markers here, because when constructing a
2978 ;; block agenda, the individual blocks do not do that.
2979 (org-agenda-reset-markers)
2980 (let* ((org-agenda-multi t)
2981 (redo (list 'org-agenda-run-series name (list 'quote series)))
2982 (cmds (car series))
2983 (gprops (nth 1 series))
2984 match ;; The byte compiler incorrectly complains about this. Keep it!
2985 org-cmd type lprops)
2986 (while (setq org-cmd (pop cmds))
2987 (setq type (car org-cmd)
2988 match (eval (nth 1 org-cmd))
2989 lprops (nth 2 org-cmd))
2990 (let ((org-agenda-overriding-arguments
2991 (if (eq org-agenda-overriding-cmd org-cmd)
2992 (or org-agenda-overriding-arguments
2993 org-agenda-overriding-cmd-arguments))))
2994 (cond
2995 ((eq type 'agenda)
2996 (org-let2 gprops lprops
2997 '(call-interactively 'org-agenda-list)))
2998 ((eq type 'alltodo)
2999 (org-let2 gprops lprops
3000 '(call-interactively 'org-todo-list)))
3001 ((eq type 'search)
3002 (org-let2 gprops lprops
3003 '(org-search-view current-prefix-arg match nil)))
3004 ((eq type 'stuck)
3005 (org-let2 gprops lprops
3006 '(call-interactively 'org-agenda-list-stuck-projects)))
3007 ((eq type 'tags)
3008 (org-let2 gprops lprops
3009 '(org-tags-view current-prefix-arg match)))
3010 ((eq type 'tags-todo)
3011 (org-let2 gprops lprops
3012 '(org-tags-view '(4) match)))
3013 ((eq type 'todo)
3014 (org-let2 gprops lprops
3015 '(org-todo-list match)))
3016 ((fboundp type)
3017 (org-let2 gprops lprops
3018 '(funcall type match)))
3019 (t (error "Invalid type in command series")))))
3020 (widen)
3021 (let ((inhibit-read-only t))
3022 (add-text-properties (point-min) (point-max)
3023 `(org-series t org-series-redo-cmd ,redo)))
3024 (setq org-agenda-redo-command redo)
3025 (goto-char (point-min)))
3026 (org-agenda-fit-window-to-buffer)
3027 (org-let (nth 1 series) '(org-agenda-finalize)))
3029 ;;;###autoload
3030 (defmacro org-batch-agenda (cmd-key &rest parameters)
3031 "Run an agenda command in batch mode and send the result to STDOUT.
3032 If CMD-KEY is a string of length 1, it is used as a key in
3033 `org-agenda-custom-commands' and triggers this command. If it is a
3034 longer string it is used as a tags/todo match string.
3035 Parameters are alternating variable names and values that will be bound
3036 before running the agenda command."
3037 (org-eval-in-environment (org-make-parameter-alist parameters)
3038 (if (> (length cmd-key) 2)
3039 (org-tags-view nil cmd-key)
3040 (org-agenda nil cmd-key)))
3041 (set-buffer org-agenda-buffer-name)
3042 (princ (buffer-string)))
3044 (defvar org-agenda-info nil)
3046 ;;;###autoload
3047 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3048 "Run an agenda command in batch mode and send the result to STDOUT.
3049 If CMD-KEY is a string of length 1, it is used as a key in
3050 `org-agenda-custom-commands' and triggers this command. If it is a
3051 longer string it is used as a tags/todo match string.
3052 Parameters are alternating variable names and values that will be bound
3053 before running the agenda command.
3055 The output gives a line for each selected agenda item. Each
3056 item is a list of comma-separated values, like this:
3058 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3060 category The category of the item
3061 head The headline, without TODO kwd, TAGS and PRIORITY
3062 type The type of the agenda entry, can be
3063 todo selected in TODO match
3064 tagsmatch selected in tags match
3065 diary imported from diary
3066 deadline a deadline on given date
3067 scheduled scheduled on given date
3068 timestamp entry has timestamp on given date
3069 closed entry was closed on given date
3070 upcoming-deadline warning about deadline
3071 past-scheduled forwarded scheduled item
3072 block entry has date block including g. date
3073 todo The todo keyword, if any
3074 tags All tags including inherited ones, separated by colons
3075 date The relevant date, like 2007-2-14
3076 time The time, like 15:00-16:50
3077 extra Sting with extra planning info
3078 priority-l The priority letter if any was given
3079 priority-n The computed numerical priority
3080 agenda-day The day in the agenda where this is listed"
3081 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3082 (org-make-parameter-alist parameters))
3083 (if (> (length cmd-key) 2)
3084 (org-tags-view nil cmd-key)
3085 (org-agenda nil cmd-key)))
3086 (set-buffer org-agenda-buffer-name)
3087 (let* ((lines (org-split-string (buffer-string) "\n"))
3088 line)
3089 (while (setq line (pop lines))
3090 (catch 'next
3091 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3092 (setq org-agenda-info
3093 (org-fix-agenda-info (text-properties-at 0 line)))
3094 (princ
3095 (mapconcat 'org-agenda-export-csv-mapper
3096 '(org-category txt type todo tags date time extra
3097 priority-letter priority agenda-day)
3098 ","))
3099 (princ "\n")))))
3101 (defun org-fix-agenda-info (props)
3102 "Make sure all properties on an agenda item have a canonical form.
3103 This ensures the export commands can easily use it."
3104 (let (tmp re)
3105 (when (setq tmp (plist-get props 'tags))
3106 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3107 (when (setq tmp (plist-get props 'date))
3108 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3109 (let ((calendar-date-display-form '(year "-" month "-" day)))
3110 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3112 (setq tmp (calendar-date-string tmp)))
3113 (setq props (plist-put props 'date tmp)))
3114 (when (setq tmp (plist-get props 'day))
3115 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3116 (let ((calendar-date-display-form '(year "-" month "-" day)))
3117 (setq tmp (calendar-date-string tmp)))
3118 (setq props (plist-put props 'day tmp))
3119 (setq props (plist-put props 'agenda-day tmp)))
3120 (when (setq tmp (plist-get props 'txt))
3121 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3122 (plist-put props 'priority-letter (match-string 1 tmp))
3123 (setq tmp (replace-match "" t t tmp)))
3124 (when (and (setq re (plist-get props 'org-todo-regexp))
3125 (setq re (concat "\\`\\.*" re " ?"))
3126 (string-match re tmp))
3127 (plist-put props 'todo (match-string 1 tmp))
3128 (setq tmp (replace-match "" t t tmp)))
3129 (plist-put props 'txt tmp)))
3130 props)
3132 (defun org-agenda-export-csv-mapper (prop)
3133 (let ((res (plist-get org-agenda-info prop)))
3134 (setq res
3135 (cond
3136 ((not res) "")
3137 ((stringp res) res)
3138 (t (prin1-to-string res))))
3139 (while (string-match "," res)
3140 (setq res (replace-match ";" t t res)))
3141 (org-trim res)))
3143 ;;;###autoload
3144 (defun org-store-agenda-views (&rest parameters)
3145 (interactive)
3146 (eval (list 'org-batch-store-agenda-views)))
3148 ;;;###autoload
3149 (defmacro org-batch-store-agenda-views (&rest parameters)
3150 "Run all custom agenda commands that have a file argument."
3151 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3152 (pop-up-frames nil)
3153 (dir default-directory)
3154 (pars (org-make-parameter-alist parameters))
3155 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3156 (save-window-excursion
3157 (while cmds
3158 (setq cmd (pop cmds)
3159 thiscmdkey (car cmd)
3160 thiscmdcmd (cdr cmd)
3161 match (nth 2 thiscmdcmd)
3162 bufname (if org-agenda-sticky
3163 (or (and (stringp match)
3164 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3165 (format "*Org Agenda(%s)*" thiscmdkey))
3166 org-agenda-buffer-name)
3167 cmd-or-set (nth 2 cmd)
3168 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3169 files (nth (if (listp cmd-or-set) 4 5) cmd))
3170 (if (stringp files) (setq files (list files)))
3171 (when files
3172 (org-eval-in-environment (append org-agenda-exporter-settings
3173 opts pars)
3174 (org-agenda nil thiscmdkey))
3175 (set-buffer bufname)
3176 (while files
3177 (org-eval-in-environment (append org-agenda-exporter-settings
3178 opts pars)
3179 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3180 (and (get-buffer bufname)
3181 (kill-buffer bufname)))))))
3183 (defvar org-agenda-current-span nil
3184 "The current span used in the agenda view.") ; local variable in the agenda buffer
3185 (defun org-agenda-mark-header-line (pos)
3186 "Mark the line at POS as an agenda structure header."
3187 (save-excursion
3188 (goto-char pos)
3189 (put-text-property (point-at-bol) (point-at-eol)
3190 'org-agenda-structural-header t)
3191 (when org-agenda-title-append
3192 (put-text-property (point-at-bol) (point-at-eol)
3193 'org-agenda-title-append org-agenda-title-append))))
3195 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3196 (defvar org-agenda-write-buffer-name "Agenda View")
3197 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3198 "Write the current buffer (an agenda view) as a file.
3199 Depending on the extension of the file name, plain text (.txt),
3200 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3201 If the extension is .ics, run icalendar export over all files used
3202 to construct the agenda and limit the export to entries listed in the
3203 agenda now.
3204 If the extension is .org, collect all subtrees corresponding to the
3205 agenda entries and add them in an .org file.
3206 With prefix argument OPEN, open the new file immediately.
3207 If NOSETTINGS is given, do not scope the settings of
3208 `org-agenda-exporter-settings' into the export commands. This is used when
3209 the settings have already been scoped and we do not wish to overrule other,
3210 higher priority settings.
3211 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3212 (interactive "FWrite agenda to file: \nP")
3213 (if (not (file-writable-p file))
3214 (error "Cannot write agenda to file %s" file))
3215 (org-let (if nosettings nil org-agenda-exporter-settings)
3216 '(save-excursion
3217 (save-window-excursion
3218 (org-agenda-mark-filtered-text)
3219 (let ((bs (copy-sequence (buffer-string))) beg content)
3220 (org-agenda-unmark-filtered-text)
3221 (with-temp-buffer
3222 (rename-buffer org-agenda-write-buffer-name t)
3223 (set-buffer-modified-p nil)
3224 (insert bs)
3225 (org-agenda-remove-marked-text 'org-filtered)
3226 (while (setq beg (text-property-any (point-min) (point-max)
3227 'org-filtered t))
3228 (delete-region
3229 beg (or (next-single-property-change beg 'org-filtered)
3230 (point-max))))
3231 (run-hooks 'org-agenda-before-write-hook)
3232 (cond
3233 ((org-bound-and-true-p org-mobile-creating-agendas)
3234 (org-mobile-write-agenda-for-mobile file))
3235 ((string-match "\\.org\\'" file)
3236 (let (content p m message-log-max)
3237 (goto-char (point-min))
3238 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3239 (goto-char p)
3240 (setq m (get-text-property (point) 'org-hd-marker))
3241 (when m
3242 (push (save-excursion
3243 (set-buffer (marker-buffer m))
3244 (goto-char m)
3245 (org-copy-subtree 1 nil t t)
3246 org-subtree-clip)
3247 content)))
3248 (find-file file)
3249 (erase-buffer)
3250 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3251 (write-file file)
3252 (kill-buffer (current-buffer))
3253 (message "Org file written to %s" file)))
3254 ((string-match "\\.html?\\'" file)
3255 (require 'htmlize)
3256 (set-buffer (htmlize-buffer (current-buffer)))
3257 (when org-agenda-export-html-style
3258 ;; replace <style> section with org-agenda-export-html-style
3259 (goto-char (point-min))
3260 (kill-region (- (search-forward "<style") 6)
3261 (search-forward "</style>"))
3262 (insert org-agenda-export-html-style))
3263 (write-file file)
3264 (kill-buffer (current-buffer))
3265 (message "HTML written to %s" file))
3266 ((string-match "\\.ps\\'" file)
3267 (require 'ps-print)
3268 (ps-print-buffer-with-faces file)
3269 (message "Postscript written to %s" file))
3270 ((string-match "\\.pdf\\'" file)
3271 (require 'ps-print)
3272 (ps-print-buffer-with-faces
3273 (concat (file-name-sans-extension file) ".ps"))
3274 (call-process "ps2pdf" nil nil nil
3275 (expand-file-name
3276 (concat (file-name-sans-extension file) ".ps"))
3277 (expand-file-name file))
3278 (delete-file (concat (file-name-sans-extension file) ".ps"))
3279 (message "PDF written to %s" file))
3280 ((string-match "\\.ics\\'" file)
3281 (require 'ox-icalendar)
3282 (org-icalendar-export-current-agenda (expand-file-name file)))
3284 (let ((bs (buffer-string)))
3285 (find-file file)
3286 (erase-buffer)
3287 (insert bs)
3288 (save-buffer 0)
3289 (kill-buffer (current-buffer))
3290 (message "Plain text written to %s" file))))))))
3291 (set-buffer (or agenda-bufname
3292 (and (org-called-interactively-p 'any) (buffer-name))
3293 org-agenda-buffer-name)))
3294 (when open (org-open-file file)))
3296 (defvar org-agenda-tag-filter-overlays nil)
3297 (defvar org-agenda-cat-filter-overlays nil)
3299 (defun org-agenda-mark-filtered-text ()
3300 "Mark all text hidden by filtering with a text property."
3301 (let ((inhibit-read-only t))
3302 (mapc
3303 (lambda (o)
3304 (when (equal (overlay-buffer o) (current-buffer))
3305 (put-text-property
3306 (overlay-start o) (overlay-end o)
3307 'org-filtered t)))
3308 (append org-agenda-tag-filter-overlays
3309 org-agenda-cat-filter-overlays))))
3311 (defun org-agenda-unmark-filtered-text ()
3312 "Remove the filtering text property."
3313 (let ((inhibit-read-only t))
3314 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3316 (defun org-agenda-remove-marked-text (property &optional value)
3317 "Delete all text marked with VALUE of PROPERTY.
3318 VALUE defaults to t."
3319 (let (beg)
3320 (setq value (or value t))
3321 (while (setq beg (text-property-any (point-min) (point-max)
3322 property value))
3323 (delete-region
3324 beg (or (next-single-property-change beg 'org-filtered)
3325 (point-max))))))
3327 (defun org-agenda-add-entry-text ()
3328 "Add entry text to agenda lines.
3329 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3330 entry text following headings shown in the agenda.
3331 Drawers will be excluded, also the line with scheduling/deadline info."
3332 (when (and (> org-agenda-add-entry-text-maxlines 0)
3333 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3334 (let (m txt)
3335 (goto-char (point-min))
3336 (while (not (eobp))
3337 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3338 (beginning-of-line 2)
3339 (setq txt (org-agenda-get-some-entry-text
3340 m org-agenda-add-entry-text-maxlines " > "))
3341 (end-of-line 1)
3342 (if (string-match "\\S-" txt)
3343 (insert "\n" txt)
3344 (or (eobp) (forward-char 1))))))))
3346 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3347 &rest keep)
3348 "Extract entry text from MARKER, at most N-LINES lines.
3349 This will ignore drawers etc, just get the text.
3350 If INDENT is given, prefix every line with this string. If KEEP is
3351 given, it is a list of symbols, defining stuff that should not be
3352 removed from the entry content. Currently only `planning' is allowed here."
3353 (let (txt drawer-re kwd-time-re ind)
3354 (save-excursion
3355 (with-current-buffer (marker-buffer marker)
3356 (if (not (derived-mode-p 'org-mode))
3357 (setq txt "")
3358 (save-excursion
3359 (save-restriction
3360 (widen)
3361 (goto-char marker)
3362 (end-of-line 1)
3363 (setq txt (buffer-substring
3364 (min (1+ (point)) (point-max))
3365 (progn (outline-next-heading) (point)))
3366 drawer-re org-drawer-regexp
3367 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3368 ".*\n?"))
3369 (with-temp-buffer
3370 (insert txt)
3371 (when org-agenda-add-entry-text-descriptive-links
3372 (goto-char (point-min))
3373 (while (org-activate-bracket-links (point-max))
3374 (add-text-properties (match-beginning 0) (match-end 0)
3375 '(face org-link))))
3376 (goto-char (point-min))
3377 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3378 (set-text-properties (match-beginning 0) (match-end 0)
3379 nil))
3380 (goto-char (point-min))
3381 (while (re-search-forward drawer-re nil t)
3382 (delete-region
3383 (match-beginning 0)
3384 (progn (re-search-forward
3385 "^[ \t]*:END:.*\n?" nil 'move)
3386 (point))))
3387 (unless (member 'planning keep)
3388 (goto-char (point-min))
3389 (while (re-search-forward kwd-time-re nil t)
3390 (replace-match "")))
3391 (goto-char (point-min))
3392 (when org-agenda-entry-text-exclude-regexps
3393 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3394 (while (setq re (pop re-list))
3395 (goto-char (point-min))
3396 (while (re-search-forward re nil t)
3397 (replace-match "")))))
3398 (goto-char (point-max))
3399 (skip-chars-backward " \t\n")
3400 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3402 ;; find and remove min common indentation
3403 (goto-char (point-min))
3404 (untabify (point-min) (point-max))
3405 (setq ind (org-get-indentation))
3406 (while (not (eobp))
3407 (unless (looking-at "[ \t]*$")
3408 (setq ind (min ind (org-get-indentation))))
3409 (beginning-of-line 2))
3410 (goto-char (point-min))
3411 (while (not (eobp))
3412 (unless (looking-at "[ \t]*$")
3413 (move-to-column ind)
3414 (delete-region (point-at-bol) (point)))
3415 (beginning-of-line 2))
3417 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3419 (goto-char (point-min))
3420 (when indent
3421 (while (and (not (eobp)) (re-search-forward "^" nil t))
3422 (replace-match indent t t)))
3423 (goto-char (point-min))
3424 (while (looking-at "[ \t]*\n") (replace-match ""))
3425 (goto-char (point-max))
3426 (when (> (org-current-line)
3427 n-lines)
3428 (org-goto-line (1+ n-lines))
3429 (backward-char 1))
3430 (setq txt (buffer-substring (point-min) (point)))))))))
3431 txt))
3433 (defun org-agenda-collect-markers ()
3434 "Collect the markers pointing to entries in the agenda buffer."
3435 (let (m markers)
3436 (save-excursion
3437 (goto-char (point-min))
3438 (while (not (eobp))
3439 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3440 (org-get-at-bol 'org-marker)))
3441 (push m markers))
3442 (beginning-of-line 2)))
3443 (nreverse markers)))
3445 (defun org-create-marker-find-array (marker-list)
3446 "Create a alist of files names with all marker positions in that file."
3447 (let (f tbl m a p)
3448 (while (setq m (pop marker-list))
3449 (setq p (marker-position m)
3450 f (buffer-file-name (or (buffer-base-buffer
3451 (marker-buffer m))
3452 (marker-buffer m))))
3453 (if (setq a (assoc f tbl))
3454 (push (marker-position m) (cdr a))
3455 (push (list f p) tbl)))
3456 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3457 tbl)))
3459 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3460 (defun org-check-agenda-marker-table ()
3461 "Check of the current entry is on the marker list."
3462 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3464 (and (setq a (assoc file org-agenda-marker-table))
3465 (save-match-data
3466 (save-excursion
3467 (org-back-to-heading t)
3468 (member (point) (cdr a)))))))
3470 (defun org-check-for-org-mode ()
3471 "Make sure current buffer is in org-mode. Error if not."
3472 (or (derived-mode-p 'org-mode)
3473 (error "Cannot execute org-mode agenda command on buffer in %s"
3474 major-mode)))
3476 ;;; Agenda prepare and finalize
3478 (defvar org-agenda-multi nil) ; dynamically scoped
3479 (defvar org-agenda-pre-window-conf nil)
3480 (defvar org-agenda-columns-active nil)
3481 (defvar org-agenda-name nil)
3482 (defvar org-agenda-tag-filter nil)
3483 (defvar org-agenda-category-filter nil)
3484 (defvar org-agenda-top-category-filter nil)
3485 (defvar org-agenda-tag-filter-while-redo nil)
3486 (defvar org-agenda-tag-filter-preset nil
3487 "A preset of the tags filter used for secondary agenda filtering.
3488 This must be a list of strings, each string must be a single tag preceded
3489 by \"+\" or \"-\".
3490 This variable should not be set directly, but agenda custom commands can
3491 bind it in the options section. The preset filter is a global property of
3492 the entire agenda view. In a block agenda, it will not work reliably to
3493 define a filter for one of the individual blocks. You need to set it in
3494 the global options and expect it to be applied to the entire view.")
3496 (defvar org-agenda-category-filter-preset nil
3497 "A preset of the category filter used for secondary agenda filtering.
3498 This must be a list of strings, each string must be a single category
3499 preceded by \"+\" or \"-\".
3500 This variable should not be set directly, but agenda custom commands can
3501 bind it in the options section. The preset filter is a global property of
3502 the entire agenda view. In a block agenda, it will not work reliably to
3503 define a filter for one of the individual blocks. You need to set it in
3504 the global options and expect it to be applied to the entire view.")
3507 (defun org-agenda-use-sticky-p ()
3508 "Return non-nil if an agenda buffer named
3509 `org-agenda-buffer-name' exists and should be shown instead of
3510 generating a new one."
3511 (and
3512 ;; turned off by user
3513 org-agenda-sticky
3514 ;; For multi-agenda buffer already exists
3515 (not org-agenda-multi)
3516 ;; buffer found
3517 (get-buffer org-agenda-buffer-name)
3518 ;; C-u parameter is same as last call
3519 (with-current-buffer (get-buffer org-agenda-buffer-name)
3520 (and
3521 (equal current-prefix-arg
3522 org-agenda-last-prefix-arg)
3523 ;; In case user turned stickiness on, while having existing
3524 ;; Agenda buffer active, don't reuse that buffer, because it
3525 ;; does not have org variables local
3526 org-agenda-this-buffer-is-sticky))))
3528 (defun org-agenda-prepare-window (abuf)
3529 "Setup agenda buffer in the window."
3530 (let* ((awin (get-buffer-window abuf))
3531 wconf)
3532 (cond
3533 ((equal (current-buffer) abuf) nil)
3534 (awin (select-window awin))
3535 ((not (setq wconf (current-window-configuration))))
3536 ((equal org-agenda-window-setup 'current-window)
3537 (org-pop-to-buffer-same-window abuf))
3538 ((equal org-agenda-window-setup 'other-window)
3539 (org-switch-to-buffer-other-window abuf))
3540 ((equal org-agenda-window-setup 'other-frame)
3541 (switch-to-buffer-other-frame abuf))
3542 ((equal org-agenda-window-setup 'reorganize-frame)
3543 (delete-other-windows)
3544 (org-switch-to-buffer-other-window abuf)))
3545 ;; additional test in case agenda is invoked from within agenda
3546 ;; buffer via elisp link
3547 (unless (equal (current-buffer) abuf)
3548 (org-pop-to-buffer-same-window abuf))
3549 (setq org-agenda-pre-window-conf
3550 (or org-agenda-pre-window-conf wconf))))
3552 (defun org-agenda-prepare (&optional name)
3553 (if (org-agenda-use-sticky-p)
3554 (progn
3555 ;; Popup existing buffer
3556 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3557 (message "Sticky Agenda buffer, use `r' to refresh")
3558 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3559 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3560 (setq org-todo-keywords-for-agenda nil)
3561 (setq org-drawers-for-agenda nil)
3562 (unless org-agenda-persistent-filter
3563 (setq org-agenda-tag-filter nil
3564 org-agenda-category-filter nil))
3565 (put 'org-agenda-tag-filter :preset-filter
3566 org-agenda-tag-filter-preset)
3567 (put 'org-agenda-category-filter :preset-filter
3568 org-agenda-category-filter-preset)
3569 (if org-agenda-multi
3570 (progn
3571 (setq buffer-read-only nil)
3572 (goto-char (point-max))
3573 (unless (or (bobp) org-agenda-compact-blocks
3574 (not org-agenda-block-separator))
3575 (insert "\n"
3576 (if (stringp org-agenda-block-separator)
3577 org-agenda-block-separator
3578 (make-string (window-width) org-agenda-block-separator))
3579 "\n"))
3580 (narrow-to-region (point) (point-max)))
3581 (setq org-done-keywords-for-agenda nil)
3583 ;; Setting any org variables that are in org-agenda-local-vars
3584 ;; list need to be done after the prepare call
3585 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3586 (setq buffer-read-only nil)
3587 (org-agenda-reset-markers)
3588 (let ((inhibit-read-only t)) (erase-buffer))
3589 (org-agenda-mode)
3590 (setq org-agenda-buffer (current-buffer))
3591 (setq org-agenda-contributing-files nil)
3592 (setq org-agenda-columns-active nil)
3593 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3594 (setq org-todo-keywords-for-agenda
3595 (org-uniquify org-todo-keywords-for-agenda))
3596 (setq org-done-keywords-for-agenda
3597 (org-uniquify org-done-keywords-for-agenda))
3598 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3599 (setq org-agenda-last-prefix-arg current-prefix-arg)
3600 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3601 (and name (not org-agenda-name)
3602 (org-set-local 'org-agenda-name name)))
3603 (setq buffer-read-only nil)))
3605 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3606 (defun org-agenda-finalize ()
3607 "Finishing touch for the agenda buffer, called just before displaying it."
3608 (unless org-agenda-multi
3609 (save-excursion
3610 (let ((inhibit-read-only t))
3611 (goto-char (point-min))
3612 (save-excursion
3613 (while (org-activate-bracket-links (point-max))
3614 (add-text-properties (match-beginning 0) (match-end 0)
3615 '(face org-link))))
3616 (save-excursion
3617 (while (org-activate-plain-links (point-max))
3618 (add-text-properties (match-beginning 0) (match-end 0)
3619 '(face org-link))))
3620 (unless (eq org-agenda-remove-tags t)
3621 (org-agenda-align-tags))
3622 (unless org-agenda-with-colors
3623 (remove-text-properties (point-min) (point-max) '(face nil)))
3624 (if (and (boundp 'org-agenda-overriding-columns-format)
3625 org-agenda-overriding-columns-format)
3626 (org-set-local 'org-agenda-overriding-columns-format
3627 org-agenda-overriding-columns-format))
3628 (if (and (boundp 'org-agenda-view-columns-initially)
3629 org-agenda-view-columns-initially)
3630 (org-agenda-columns))
3631 (when org-agenda-fontify-priorities
3632 (org-agenda-fontify-priorities))
3633 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3634 (org-agenda-dim-blocked-tasks))
3635 ;; We need to widen when `org-agenda-finalize' is called from
3636 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3637 (when org-clock-current-task
3638 (save-restriction
3639 (widen)
3640 (org-agenda-mark-clocking-task)))
3641 (when org-agenda-entry-text-mode
3642 (org-agenda-entry-text-hide)
3643 (org-agenda-entry-text-show))
3644 (if (and (functionp 'org-habit-insert-consistency-graphs)
3645 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3646 (org-habit-insert-consistency-graphs))
3647 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3648 (unless (or (eq org-agenda-show-inherited-tags 'always)
3649 (and (listp org-agenda-show-inherited-tags)
3650 (memq org-agenda-type org-agenda-show-inherited-tags))
3651 (and (eq org-agenda-show-inherited-tags t)
3652 (or (eq org-agenda-use-tag-inheritance t)
3653 (and (listp org-agenda-use-tag-inheritance)
3654 (not (memq org-agenda-type
3655 org-agenda-use-tag-inheritance))))))
3656 (let (mrk)
3657 (save-excursion
3658 (goto-char (point-min))
3659 (while (equal (forward-line) 0)
3660 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3661 (get-text-property (point) 'org-hd-marker)))
3662 (put-text-property (point-at-bol) (point-at-eol)
3663 'tags (org-with-point-at mrk
3664 (delete-dups
3665 (mapcar 'downcase (org-get-tags-at))))))))))
3666 (run-hooks 'org-agenda-finalize-hook)
3667 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3668 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3669 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3670 (org-agenda-filter-apply org-agenda-category-filter 'category))
3671 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3673 (defun org-agenda-mark-clocking-task ()
3674 "Mark the current clock entry in the agenda if it is present."
3675 (org-agenda-unmark-clocking-task)
3676 (when (marker-buffer org-clock-hd-marker)
3677 (save-excursion
3678 (goto-char (point-min))
3679 (let (s ov)
3680 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3681 (goto-char s)
3682 (when (equal (org-get-at-bol 'org-hd-marker)
3683 org-clock-hd-marker)
3684 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3685 (overlay-put ov 'type 'org-agenda-clocking)
3686 (overlay-put ov 'face 'org-agenda-clocking)
3687 (overlay-put ov 'help-echo
3688 "The clock is running in this item")))))))
3690 (defun org-agenda-unmark-clocking-task ()
3691 "Unmark the current clocking task."
3692 (mapc (lambda (o)
3693 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3694 (delete-overlay o)))
3695 (overlays-in (point-min) (point-max))))
3697 (defun org-agenda-fontify-priorities ()
3698 "Make highest priority lines bold, and lowest italic."
3699 (interactive)
3700 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3701 (delete-overlay o)))
3702 (overlays-in (point-min) (point-max)))
3703 (save-excursion
3704 (let (b e p ov h l)
3705 (goto-char (point-min))
3706 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3707 (setq h (or (get-char-property (point) 'org-highest-priority)
3708 org-highest-priority)
3709 l (or (get-char-property (point) 'org-lowest-priority)
3710 org-lowest-priority)
3711 p (string-to-char (match-string 1))
3712 b (match-beginning 0)
3713 e (if (eq org-agenda-fontify-priorities 'cookies)
3714 (match-end 0)
3715 (point-at-eol))
3716 ov (make-overlay b e))
3717 (overlay-put
3718 ov 'face
3719 (cons (cond ((org-face-from-face-or-color
3720 'priority nil
3721 (cdr (assoc p org-priority-faces))))
3722 ((and (listp org-agenda-fontify-priorities)
3723 (org-face-from-face-or-color
3724 'priority nil
3725 (cdr (assoc p org-agenda-fontify-priorities)))))
3726 ((equal p l) 'italic)
3727 ((equal p h) 'bold))
3728 'org-priority))
3729 (overlay-put ov 'org-type 'org-priority)))))
3731 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3732 (interactive "P")
3733 "Dim currently blocked TODO's in the agenda display."
3734 (message "Dim or hide blocked tasks...")
3735 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3736 (delete-overlay o)))
3737 (overlays-in (point-min) (point-max)))
3738 (save-excursion
3739 (let ((inhibit-read-only t)
3740 (org-depend-tag-blocked nil)
3741 (invis (or (not (null invisible))
3742 (eq org-agenda-dim-blocked-tasks 'invisible)))
3743 org-blocked-by-checkboxes
3744 invis1 b e p ov h l)
3745 (goto-char (point-min))
3746 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3747 (and pos (goto-char (1+ pos))))
3748 (setq org-blocked-by-checkboxes nil invis1 invis)
3749 (let ((marker (org-get-at-bol 'org-hd-marker)))
3750 (when (and marker
3751 (with-current-buffer (marker-buffer marker)
3752 (save-excursion (goto-char marker)
3753 (org-entry-blocked-p))))
3754 (if org-blocked-by-checkboxes (setq invis1 nil))
3755 (setq b (if invis1
3756 (max (point-min) (1- (point-at-bol)))
3757 (point-at-bol))
3758 e (point-at-eol)
3759 ov (make-overlay b e))
3760 (if invis1
3761 (overlay-put ov 'invisible t)
3762 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3763 (overlay-put ov 'org-type 'org-blocked-todo))))))
3764 (message "Dim or hide blocked tasks...done"))
3766 (defvar org-agenda-skip-function nil
3767 "Function to be called at each match during agenda construction.
3768 If this function returns nil, the current match should not be skipped.
3769 Otherwise, the function must return a position from where the search
3770 should be continued.
3771 This may also be a Lisp form, it will be evaluated.
3772 Never set this variable using `setq' or so, because then it will apply
3773 to all future agenda commands. If you do want a global skipping condition,
3774 use the option `org-agenda-skip-function-global' instead.
3775 The correct usage for `org-agenda-skip-function' is to bind it with
3776 `let' to scope it dynamically into the agenda-constructing command.
3777 A good way to set it is through options in `org-agenda-custom-commands'.")
3779 (defun org-agenda-skip ()
3780 "Throw to `:skip' in places that should be skipped.
3781 Also moves point to the end of the skipped region, so that search can
3782 continue from there."
3783 (let ((p (point-at-bol)) to)
3784 (when (or
3785 (save-excursion (goto-char p) (looking-at comment-start-skip))
3786 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3787 (get-text-property p :org-archived)
3788 (org-end-of-subtree t))
3789 (and org-agenda-skip-comment-trees
3790 (get-text-property p :org-comment)
3791 (org-end-of-subtree t))
3792 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3793 (org-agenda-skip-eval org-agenda-skip-function)))
3794 (goto-char to))
3795 (org-in-src-block-p t))
3796 (throw :skip t))))
3798 (defun org-agenda-skip-eval (form)
3799 "If FORM is a function or a list, call (or eval) is and return result.
3800 `save-excursion' and `save-match-data' are wrapped around the call, so point
3801 and match data are returned to the previous state no matter what these
3802 functions do."
3803 (let (fp)
3804 (and form
3805 (or (setq fp (functionp form))
3806 (consp form))
3807 (save-excursion
3808 (save-match-data
3809 (if fp
3810 (funcall form)
3811 (eval form)))))))
3813 (defvar org-agenda-markers nil
3814 "List of all currently active markers created by `org-agenda'.")
3815 (defvar org-agenda-last-marker-time (org-float-time)
3816 "Creation time of the last agenda marker.")
3818 (defun org-agenda-new-marker (&optional pos)
3819 "Return a new agenda marker.
3820 Org-mode keeps a list of these markers and resets them when they are
3821 no longer in use."
3822 (let ((m (copy-marker (or pos (point)))))
3823 (setq org-agenda-last-marker-time (org-float-time))
3824 (if org-agenda-buffer
3825 (with-current-buffer org-agenda-buffer
3826 (push m org-agenda-markers))
3827 (push m org-agenda-markers))
3830 (defun org-agenda-reset-markers ()
3831 "Reset markers created by `org-agenda'."
3832 (while org-agenda-markers
3833 (move-marker (pop org-agenda-markers) nil)))
3835 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3836 "Save relative positions of markers in region.
3837 This check for agenda markers in all agenda buffers currently active."
3838 (dolist (buf (buffer-list))
3839 (with-current-buffer buf
3840 (when (eq major-mode 'org-agenda-mode)
3841 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3842 org-agenda-markers)))))
3844 ;;; Entry text mode
3846 (defun org-agenda-entry-text-show-here ()
3847 "Add some text from the entry as context to the current line."
3848 (let (m txt o)
3849 (setq m (org-get-at-bol 'org-hd-marker))
3850 (unless (marker-buffer m)
3851 (error "No marker points to an entry here"))
3852 (setq txt (concat "\n" (org-no-properties
3853 (org-agenda-get-some-entry-text
3854 m org-agenda-entry-text-maxlines " > "))))
3855 (when (string-match "\\S-" txt)
3856 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3857 (overlay-put o 'evaporate t)
3858 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3859 (overlay-put o 'after-string txt))))
3861 (defun org-agenda-entry-text-show ()
3862 "Add entry context for all agenda lines."
3863 (interactive)
3864 (save-excursion
3865 (goto-char (point-max))
3866 (beginning-of-line 1)
3867 (while (not (bobp))
3868 (when (org-get-at-bol 'org-hd-marker)
3869 (org-agenda-entry-text-show-here))
3870 (beginning-of-line 0))))
3872 (defun org-agenda-entry-text-hide ()
3873 "Remove any shown entry context."
3874 (delq nil
3875 (mapcar (lambda (o)
3876 (if (eq (overlay-get o 'org-overlay-type)
3877 'agenda-entry-content)
3878 (progn (delete-overlay o) t)))
3879 (overlays-in (point-min) (point-max)))))
3881 (defun org-agenda-get-day-face (date)
3882 "Return the face DATE should be displayed with."
3883 (or (and (functionp org-agenda-day-face-function)
3884 (funcall org-agenda-day-face-function date))
3885 (cond ((org-agenda-todayp date)
3886 'org-agenda-date-today)
3887 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3888 'org-agenda-date-weekend)
3889 (t 'org-agenda-date))))
3891 ;;; Agenda timeline
3893 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3895 (defun org-timeline (&optional dotodo)
3896 "Show a time-sorted view of the entries in the current org file.
3897 Only entries with a time stamp of today or later will be listed. With
3898 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3899 under the current date.
3900 If the buffer contains an active region, only check the region for
3901 dates."
3902 (interactive "P")
3903 (let* ((dopast t)
3904 (org-agenda-show-log-scoped org-agenda-show-log)
3905 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3906 (current-buffer))))
3907 (date (calendar-current-date))
3908 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3909 (end (if (org-region-active-p) (region-end) (point-max)))
3910 (day-numbers (org-get-all-dates
3911 beg end 'no-ranges
3912 t org-agenda-show-log-scoped ; always include today
3913 org-timeline-show-empty-dates))
3914 (org-deadline-warning-days 0)
3915 (org-agenda-only-exact-dates t)
3916 (today (org-today))
3917 (past t)
3918 args
3919 s e rtn d emptyp)
3920 (setq org-agenda-redo-command
3921 (list 'progn
3922 (list 'org-switch-to-buffer-other-window (current-buffer))
3923 (list 'org-timeline (list 'quote dotodo))))
3924 (if (not dopast)
3925 ;; Remove past dates from the list of dates.
3926 (setq day-numbers (delq nil (mapcar (lambda(x)
3927 (if (>= x today) x nil))
3928 day-numbers))))
3929 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3930 (org-compile-prefix-format 'timeline)
3931 (org-set-sorting-strategy 'timeline)
3932 (if org-agenda-show-log-scoped (push :closed args))
3933 (push :timestamp args)
3934 (push :deadline args)
3935 (push :scheduled args)
3936 (push :sexp args)
3937 (if dotodo (push :todo args))
3938 (insert "Timeline of file " entry "\n")
3939 (add-text-properties (point-min) (point)
3940 (list 'face 'org-agenda-structure))
3941 (org-agenda-mark-header-line (point-min))
3942 (while (setq d (pop day-numbers))
3943 (if (and (listp d) (eq (car d) :omitted))
3944 (progn
3945 (setq s (point))
3946 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3947 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3948 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3949 (if (and (>= d today)
3950 dopast
3951 past)
3952 (progn
3953 (setq past nil)
3954 (insert (make-string 79 ?-) "\n")))
3955 (setq date (calendar-gregorian-from-absolute d))
3956 (setq s (point))
3957 (setq rtn (and (not emptyp)
3958 (apply 'org-agenda-get-day-entries entry
3959 date args)))
3960 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3961 (progn
3962 (insert
3963 (if (stringp org-agenda-format-date)
3964 (format-time-string org-agenda-format-date
3965 (org-time-from-absolute date))
3966 (funcall org-agenda-format-date date))
3967 "\n")
3968 (put-text-property s (1- (point)) 'face
3969 (org-agenda-get-day-face date))
3970 (put-text-property s (1- (point)) 'org-date-line t)
3971 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3972 (if (equal d today)
3973 (put-text-property s (1- (point)) 'org-today t))
3974 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
3975 (put-text-property s (1- (point)) 'day d)))))
3976 (goto-char (point-min))
3977 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3978 (point-min)))
3979 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3980 (org-agenda-finalize)
3981 (setq buffer-read-only t)))
3983 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3984 "Return a list of all relevant day numbers from BEG to END buffer positions.
3985 If NO-RANGES is non-nil, include only the start and end dates of a range,
3986 not every single day in the range. If FORCE-TODAY is non-nil, make
3987 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3988 inactive time stamps (those in square brackets) are included.
3989 When EMPTY is non-nil, also include days without any entries."
3990 (let ((re (concat
3991 (if pre-re pre-re "")
3992 (if inactive org-ts-regexp-both org-ts-regexp)))
3993 dates dates1 date day day1 day2 ts1 ts2 pos)
3994 (if force-today
3995 (setq dates (list (org-today))))
3996 (save-excursion
3997 (goto-char beg)
3998 (while (re-search-forward re end t)
3999 (setq day (time-to-days (org-time-string-to-time
4000 (substring (match-string 1) 0 10)
4001 (current-buffer) (match-beginning 0))))
4002 (or (memq day dates) (push day dates)))
4003 (unless no-ranges
4004 (goto-char beg)
4005 (while (re-search-forward org-tr-regexp end t)
4006 (setq pos (match-beginning 0))
4007 (setq ts1 (substring (match-string 1) 0 10)
4008 ts2 (substring (match-string 2) 0 10)
4009 day1 (time-to-days (org-time-string-to-time
4010 ts1 (current-buffer) pos))
4011 day2 (time-to-days (org-time-string-to-time
4012 ts2 (current-buffer) pos)))
4013 (while (< (setq day1 (1+ day1)) day2)
4014 (or (memq day1 dates) (push day1 dates)))))
4015 (setq dates (sort dates '<))
4016 (when empty
4017 (while (setq day (pop dates))
4018 (setq day2 (car dates))
4019 (push day dates1)
4020 (when (and day2 empty)
4021 (if (or (eq empty t)
4022 (and (numberp empty) (<= (- day2 day) empty)))
4023 (while (< (setq day (1+ day)) day2)
4024 (push (list day) dates1))
4025 (push (cons :omitted (- day2 day)) dates1))))
4026 (setq dates (nreverse dates1)))
4027 dates)))
4029 ;;; Agenda Daily/Weekly
4031 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4032 "Start day for the agenda view.
4033 Custom commands can set this variable in the options section.
4034 See the docstring of `org-read-date' on allowed values.")
4035 (defvar org-starting-day nil) ; local variable in the agenda buffer
4036 (defvar org-arg-loc nil) ; local variable
4038 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4039 "List of types searched for when creating the daily/weekly agenda.
4040 This variable is a list of symbols that controls the types of
4041 items that appear in the daily/weekly agenda. Allowed symbols in this
4042 list are are
4044 :timestamp List items containing a date stamp or date range matching
4045 the selected date. This includes sexp entries in
4046 angular brackets.
4048 :sexp List entries resulting from plain diary-like sexps.
4050 :deadline List deadline due on that date. When the date is today,
4051 also list any deadlines past due, or due within
4052 `org-deadline-warning-days'. `:deadline' must appear before
4053 `:scheduled' if the setting of
4054 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4055 any effect.
4057 :scheduled List all items which are scheduled for the given date.
4058 The diary for *today* also contains items which were
4059 scheduled earlier and are not yet marked DONE.
4061 By default, all four types are turned on.
4063 Never set this variable globally using `setq', because then it
4064 will apply to all future agenda commands. Instead, bind it with
4065 `let' to scope it dynamically into the agenda-constructing
4066 command. A good way to set it is through options in
4067 `org-agenda-custom-commands'. For a more flexible (though
4068 somewhat less efficient) way of determining what is included in
4069 the daily/weekly agenda, see `org-agenda-skip-function'.")
4071 (defvar org-agenda-buffer-tmp-name nil)
4072 ;;;###autoload
4073 (defun org-agenda-list (&optional arg start-day span)
4074 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4075 The view will be for the current day or week, but from the overview buffer
4076 you will be able to go to other days/weeks.
4078 With a numeric prefix argument in an interactive call, the agenda will
4079 span ARG days. Lisp programs should instead specify SPAN to change
4080 the number of days. SPAN defaults to `org-agenda-span'.
4082 START-DAY defaults to TODAY, or to the most recent match for the weekday
4083 given in `org-agenda-start-on-weekday'."
4084 (interactive "P")
4085 (if org-agenda-overriding-arguments
4086 (setq arg (car org-agenda-overriding-arguments)
4087 start-day (nth 1 org-agenda-overriding-arguments)
4088 span (nth 2 org-agenda-overriding-arguments)))
4089 (if (and (integerp arg) (> arg 0))
4090 (setq span arg arg nil))
4091 (catch 'exit
4092 (setq org-agenda-buffer-name
4093 (or org-agenda-buffer-tmp-name
4094 (if org-agenda-sticky
4095 (cond ((and org-keys (stringp org-match))
4096 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4097 (org-keys
4098 (format "*Org Agenda(%s)*" org-keys))
4099 (t "*Org Agenda(a)*")))
4100 org-agenda-buffer-name))
4101 (org-agenda-prepare "Day/Week")
4102 (setq start-day (or start-day org-agenda-start-day))
4103 (if (stringp start-day)
4104 ;; Convert to an absolute day number
4105 (setq start-day (time-to-days (org-read-date nil t start-day))))
4106 (org-compile-prefix-format 'agenda)
4107 (org-set-sorting-strategy 'agenda)
4108 (let* ((span (org-agenda-ndays-to-span
4109 (or span org-agenda-ndays org-agenda-span)))
4110 (today (org-today))
4111 (sd (or start-day today))
4112 (ndays (org-agenda-span-to-ndays span sd))
4113 (org-agenda-start-on-weekday
4114 (if (eq ndays 7)
4115 org-agenda-start-on-weekday))
4116 (thefiles (org-agenda-files nil 'ifmode))
4117 (files thefiles)
4118 (start (if (or (null org-agenda-start-on-weekday)
4119 (< ndays 7))
4121 (let* ((nt (calendar-day-of-week
4122 (calendar-gregorian-from-absolute sd)))
4123 (n1 org-agenda-start-on-weekday)
4124 (d (- nt n1)))
4125 (- sd (+ (if (< d 0) 7 0) d)))))
4126 (day-numbers (list start))
4127 (day-cnt 0)
4128 (inhibit-redisplay (not debug-on-error))
4129 (org-agenda-show-log-scoped org-agenda-show-log)
4130 s e rtn rtnall file date d start-pos end-pos todayp
4131 clocktable-start clocktable-end filter)
4132 (setq org-agenda-redo-command
4133 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4134 (dotimes (n (1- ndays))
4135 (push (1+ (car day-numbers)) day-numbers))
4136 (setq day-numbers (nreverse day-numbers))
4137 (setq clocktable-start (car day-numbers)
4138 clocktable-end (1+ (or (org-last day-numbers) 0)))
4139 (org-set-local 'org-starting-day (car day-numbers))
4140 (org-set-local 'org-arg-loc arg)
4141 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4142 (unless org-agenda-compact-blocks
4143 (let* ((d1 (car day-numbers))
4144 (d2 (org-last day-numbers))
4145 (w1 (org-days-to-iso-week d1))
4146 (w2 (org-days-to-iso-week d2)))
4147 (setq s (point))
4148 (if org-agenda-overriding-header
4149 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4150 nil 'face 'org-agenda-structure) "\n")
4151 (insert (org-agenda-span-name span)
4152 "-agenda"
4153 (if (< (- d2 d1) 350)
4154 (if (= w1 w2)
4155 (format " (W%02d)" w1)
4156 (format " (W%02d-W%02d)" w1 w2))
4158 ":\n")))
4159 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4160 'org-date-line t))
4161 (org-agenda-mark-header-line s))
4162 (while (setq d (pop day-numbers))
4163 (setq date (calendar-gregorian-from-absolute d)
4164 s (point))
4165 (if (or (setq todayp (= d today))
4166 (and (not start-pos) (= d sd)))
4167 (setq start-pos (point))
4168 (if (and start-pos (not end-pos))
4169 (setq end-pos (point))))
4170 (setq files thefiles
4171 rtnall nil)
4172 (while (setq file (pop files))
4173 (catch 'nextfile
4174 (org-check-agenda-file file)
4175 (let ((org-agenda-entry-types org-agenda-entry-types))
4176 (unless org-agenda-include-deadlines
4177 (setq org-agenda-entry-types
4178 (delq :deadline org-agenda-entry-types)))
4179 (cond
4180 ((memq org-agenda-show-log-scoped '(only clockcheck))
4181 (setq rtn (org-agenda-get-day-entries
4182 file date :closed)))
4183 (org-agenda-show-log-scoped
4184 (setq rtn (apply 'org-agenda-get-day-entries
4185 file date
4186 (append '(:closed) org-agenda-entry-types))))
4188 (setq rtn (apply 'org-agenda-get-day-entries
4189 file date
4190 org-agenda-entry-types)))))
4191 (setq rtnall (append rtnall rtn)))) ;; all entries
4192 (if org-agenda-include-diary
4193 (let ((org-agenda-search-headline-for-time t))
4194 (require 'diary-lib)
4195 (setq rtn (org-get-entries-from-diary date))
4196 (setq rtnall (append rtnall rtn))))
4197 (if (or rtnall org-agenda-show-all-dates)
4198 (progn
4199 (setq day-cnt (1+ day-cnt))
4200 (insert
4201 (if (stringp org-agenda-format-date)
4202 (format-time-string org-agenda-format-date
4203 (org-time-from-absolute date))
4204 (funcall org-agenda-format-date date))
4205 "\n")
4206 (put-text-property s (1- (point)) 'face
4207 (org-agenda-get-day-face date))
4208 (put-text-property s (1- (point)) 'org-date-line t)
4209 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4210 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4211 (when todayp
4212 (put-text-property s (1- (point)) 'org-today t))
4213 (setq rtnall
4214 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4215 (if rtnall (insert ;; all entries
4216 (org-agenda-finalize-entries rtnall 'agenda)
4217 "\n"))
4218 (put-text-property s (1- (point)) 'day d)
4219 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4220 (when (and org-agenda-clockreport-mode clocktable-start)
4221 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4222 ;; the above line is to ensure the restricted range!
4223 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4224 tbl)
4225 (setq p (org-plist-delete p :block))
4226 (setq p (plist-put p :tstart clocktable-start))
4227 (setq p (plist-put p :tend clocktable-end))
4228 (setq p (plist-put p :scope 'agenda))
4229 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4230 (setq filter (or org-agenda-tag-filter-while-redo
4231 (get 'org-agenda-tag-filter :preset-filter))))
4232 (setq p (plist-put p :tags (mapconcat (lambda (x)
4233 (if (string-match "[<>=]" x)
4236 filter ""))))
4237 (setq tbl (apply 'org-clock-get-clocktable p))
4238 (insert tbl)))
4239 (goto-char (point-min))
4240 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4241 (unless (and (pos-visible-in-window-p (point-min))
4242 (pos-visible-in-window-p (point-max)))
4243 (goto-char (1- (point-max)))
4244 (recenter -1)
4245 (if (not (pos-visible-in-window-p (or start-pos 1)))
4246 (progn
4247 (goto-char (or start-pos 1))
4248 (recenter 1))))
4249 (goto-char (or start-pos 1))
4250 (add-text-properties (point-min) (point-max)
4251 `(org-agenda-type agenda
4252 org-last-args (,arg ,start-day ,span)
4253 org-redo-cmd ,org-agenda-redo-command
4254 org-series-cmd ,org-cmd))
4255 (if (eq org-agenda-show-log-scoped 'clockcheck)
4256 (org-agenda-show-clocking-issues))
4257 (org-agenda-finalize)
4258 (setq buffer-read-only t)
4259 (message ""))))
4261 (defun org-agenda-ndays-to-span (n)
4262 "Return a span symbol for a span of N days, or N if none matches."
4263 (cond ((symbolp n) n)
4264 ((= n 1) 'day)
4265 ((= n 7) 'week)
4266 (t n)))
4268 (defun org-agenda-span-to-ndays (span &optional start-day)
4269 "Return ndays from SPAN, possibly starting at START-DAY."
4270 (cond ((numberp span) span)
4271 ((eq span 'day) 1)
4272 ((eq span 'week) 7)
4273 ((eq span 'month)
4274 (let ((date (calendar-gregorian-from-absolute start-day)))
4275 (calendar-last-day-of-month (car date) (caddr date))))
4276 ((eq span 'year)
4277 (let ((date (calendar-gregorian-from-absolute start-day)))
4278 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4280 (defun org-agenda-span-name (span)
4281 "Return a SPAN name."
4282 (if (null span)
4284 (if (symbolp span)
4285 (capitalize (symbol-name span))
4286 (format "%d days" span))))
4288 ;;; Agenda word search
4290 (defvar org-agenda-search-history nil)
4292 (defvar org-search-syntax-table nil
4293 "Special syntax table for org-mode search.
4294 In this table, we have single quotes not as word constituents, to
4295 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4297 (defvar org-mode-syntax-table) ; From org.el
4298 (defun org-search-syntax-table ()
4299 (unless org-search-syntax-table
4300 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4301 (modify-syntax-entry ?' "." org-search-syntax-table)
4302 (modify-syntax-entry ?` "." org-search-syntax-table))
4303 org-search-syntax-table)
4305 (defvar org-agenda-last-search-view-search-was-boolean nil)
4307 ;;;###autoload
4308 (defun org-search-view (&optional todo-only string edit-at)
4309 "Show all entries that contain a phrase or words or regular expressions.
4311 With optional prefix argument TODO-ONLY, only consider entries that are
4312 TODO entries. The argument STRING can be used to pass a default search
4313 string into this function. If EDIT-AT is non-nil, it means that the
4314 user should get a chance to edit this string, with cursor at position
4315 EDIT-AT.
4317 The search string can be viewed either as a phrase that should be found as
4318 is, or it can be broken into a number of snippets, each of which must match
4319 in a Boolean way to select an entry. The default depends on the variable
4320 `org-agenda-search-view-always-boolean'.
4321 Even if this is turned off (the default) you can always switch to
4322 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4324 The default is a direct search of the whole phrase, where each space in
4325 the search string can expand to an arbitrary amount of whitespace,
4326 including newlines.
4328 If using a Boolean search, the search string is split on whitespace and
4329 each snippet is searched separately, with logical AND to select an entry.
4330 Words prefixed with a minus must *not* occur in the entry. Words without
4331 a prefix or prefixed with a plus must occur in the entry. Matching is
4332 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4333 match whole words, not parts of a word) if
4334 `org-agenda-search-view-force-full-words' is set (default is nil).
4336 Boolean search snippets enclosed by curly braces are interpreted as
4337 regular expressions that must or (when preceded with \"-\") must not
4338 match in the entry. Snippets enclosed into double quotes will be taken
4339 as a whole, to include whitespace.
4341 - If the search string starts with an asterisk, search only in headlines.
4342 - If (possibly after the leading star) the search string starts with an
4343 exclamation mark, this also means to look at TODO entries only, an effect
4344 that can also be achieved with a prefix argument.
4345 - If (possibly after star and exclamation mark) the search string starts
4346 with a colon, this will mean that the (non-regexp) snippets of the
4347 Boolean search must match as full words.
4349 This command searches the agenda files, and in addition the files listed
4350 in `org-agenda-text-search-extra-files'."
4351 (interactive "P")
4352 (if org-agenda-overriding-arguments
4353 (setq todo-only (car org-agenda-overriding-arguments)
4354 string (nth 1 org-agenda-overriding-arguments)
4355 edit-at (nth 2 org-agenda-overriding-arguments)))
4356 (let* ((props (list 'face nil
4357 'done-face 'org-agenda-done
4358 'org-not-done-regexp org-not-done-regexp
4359 'org-todo-regexp org-todo-regexp
4360 'org-complex-heading-regexp org-complex-heading-regexp
4361 'mouse-face 'highlight
4362 'help-echo (format "mouse-2 or RET jump to location")))
4363 (full-words org-agenda-search-view-force-full-words)
4364 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4365 regexp rtn rtnall files file pos inherited-tags
4366 marker category category-pos level tags c neg re boolean
4367 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4368 (unless (and (not edit-at)
4369 (stringp string)
4370 (string-match "\\S-" string))
4371 (setq string (read-string
4372 (if org-agenda-search-view-always-boolean
4373 "[+-]Word/{Regexp} ...: "
4374 "Phrase or [+-]Word/{Regexp} ...: ")
4375 (cond
4376 ((integerp edit-at) (cons string edit-at))
4377 (edit-at string))
4378 'org-agenda-search-history)))
4379 (catch 'exit
4380 (if org-agenda-sticky
4381 (setq org-agenda-buffer-name
4382 (if (stringp string)
4383 (format "*Org Agenda(%s:%s)*"
4384 (or org-keys (or (and todo-only "S") "s")) string)
4385 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4386 (org-agenda-prepare "SEARCH")
4387 (org-compile-prefix-format 'search)
4388 (org-set-sorting-strategy 'search)
4389 (setq org-agenda-redo-command
4390 (list 'org-search-view (if todo-only t nil)
4391 (list 'if 'current-prefix-arg nil string)))
4392 (setq org-agenda-query-string string)
4393 (if (equal (string-to-char string) ?*)
4394 (setq hdl-only t
4395 words (substring string 1))
4396 (setq words string))
4397 (when (equal (string-to-char words) ?!)
4398 (setq todo-only t
4399 words (substring words 1)))
4400 (when (equal (string-to-char words) ?:)
4401 (setq full-words t
4402 words (substring words 1)))
4403 (if (or org-agenda-search-view-always-boolean
4404 (member (string-to-char words) '(?- ?+ ?\{)))
4405 (setq boolean t))
4406 (setq words (org-split-string words))
4407 (let (www w)
4408 (while (setq w (pop words))
4409 (while (and (string-match "\\\\\\'" w) words)
4410 (setq w (concat (substring w 0 -1) " " (pop words))))
4411 (push w www))
4412 (setq words (nreverse www) www nil)
4413 (while (setq w (pop words))
4414 (when (and (string-match "\\`[-+]?{" w)
4415 (not (string-match "}\\'" w)))
4416 (while (and words (not (string-match "}\\'" (car words))))
4417 (setq w (concat w " " (pop words))))
4418 (setq w (concat w " " (pop words))))
4419 (push w www))
4420 (setq words (nreverse www)))
4421 (setq org-agenda-last-search-view-search-was-boolean boolean)
4422 (when boolean
4423 (let (wds w)
4424 (while (setq w (pop words))
4425 (if (or (equal (substring w 0 1) "\"")
4426 (and (> (length w) 1)
4427 (member (substring w 0 1) '("+" "-"))
4428 (equal (substring w 1 2) "\"")))
4429 (while (and words (not (equal (substring w -1) "\"")))
4430 (setq w (concat w " " (pop words)))))
4431 (and (string-match "\\`\\([-+]?\\)\"" w)
4432 (setq w (replace-match "\\1" nil nil w)))
4433 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4434 (push w wds))
4435 (setq words (nreverse wds))))
4436 (if boolean
4437 (mapc (lambda (w)
4438 (setq c (string-to-char w))
4439 (if (equal c ?-)
4440 (setq neg t w (substring w 1))
4441 (if (equal c ?+)
4442 (setq neg nil w (substring w 1))
4443 (setq neg nil)))
4444 (if (string-match "\\`{.*}\\'" w)
4445 (setq re (substring w 1 -1))
4446 (if full-words
4447 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4448 (setq re (regexp-quote (downcase w)))))
4449 (if neg (push re regexps-) (push re regexps+)))
4450 words)
4451 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4452 regexps+))
4453 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4454 (if (not regexps+)
4455 (setq regexp org-outline-regexp-bol)
4456 (setq regexp (pop regexps+))
4457 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4458 regexp))))
4459 (setq files (org-agenda-files nil 'ifmode))
4460 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4461 (pop org-agenda-text-search-extra-files)
4462 (setq files (org-add-archive-files files)))
4463 (setq files (append files org-agenda-text-search-extra-files)
4464 rtnall nil)
4465 (while (setq file (pop files))
4466 (setq ee nil)
4467 (catch 'nextfile
4468 (org-check-agenda-file file)
4469 (setq buffer (if (file-exists-p file)
4470 (org-get-agenda-file-buffer file)
4471 (error "No such file %s" file)))
4472 (if (not buffer)
4473 ;; If file does not exist, make sure an error message is sent
4474 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4475 file))))
4476 (with-current-buffer buffer
4477 (with-syntax-table (org-search-syntax-table)
4478 (unless (derived-mode-p 'org-mode)
4479 (error "Agenda file %s is not in `org-mode'" file))
4480 (let ((case-fold-search t))
4481 (save-excursion
4482 (save-restriction
4483 (if org-agenda-restrict
4484 (narrow-to-region org-agenda-restrict-begin
4485 org-agenda-restrict-end)
4486 (widen))
4487 (goto-char (point-min))
4488 (unless (or (org-at-heading-p)
4489 (outline-next-heading))
4490 (throw 'nextfile t))
4491 (goto-char (max (point-min) (1- (point))))
4492 (while (re-search-forward regexp nil t)
4493 (org-back-to-heading t)
4494 (while (and org-agenda-search-view-max-outline-level
4495 (> (org-reduced-level (org-outline-level))
4496 org-agenda-search-view-max-outline-level)
4497 (forward-line -1)
4498 (outline-back-to-heading t)))
4499 (skip-chars-forward "* ")
4500 (setq beg (point-at-bol)
4501 beg1 (point)
4502 end (progn
4503 (outline-next-heading)
4504 (while (and org-agenda-search-view-max-outline-level
4505 (> (org-reduced-level (org-outline-level))
4506 org-agenda-search-view-max-outline-level)
4507 (forward-line 1)
4508 (outline-next-heading)))
4509 (point)))
4511 (catch :skip
4512 (goto-char beg)
4513 (org-agenda-skip)
4514 (setq str (buffer-substring-no-properties
4515 (point-at-bol)
4516 (if hdl-only (point-at-eol) end)))
4517 (mapc (lambda (wr) (when (string-match wr str)
4518 (goto-char (1- end))
4519 (throw :skip t)))
4520 regexps-)
4521 (mapc (lambda (wr) (unless (string-match wr str)
4522 (goto-char (1- end))
4523 (throw :skip t)))
4524 (if todo-only
4525 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4526 regexps+)
4527 regexps+))
4528 (goto-char beg)
4529 (setq marker (org-agenda-new-marker (point))
4530 category (org-get-category)
4531 level (make-string (org-reduced-level (org-outline-level)) ? )
4532 category-pos (get-text-property (point) 'org-category-position)
4533 inherited-tags
4534 (or (eq org-agenda-show-inherited-tags 'always)
4535 (and (listp org-agenda-show-inherited-tags)
4536 (memq 'todo org-agenda-show-inherited-tags))
4537 (and (eq org-agenda-show-inherited-tags t)
4538 (or (eq org-agenda-use-tag-inheritance t)
4539 (memq 'todo org-agenda-use-tag-inheritance))))
4540 tags (org-get-tags-at nil (not inherited-tags))
4541 txt (org-agenda-format-item
4543 (buffer-substring-no-properties
4544 beg1 (point-at-eol))
4545 level category tags t))
4546 (org-add-props txt props
4547 'org-marker marker 'org-hd-marker marker
4548 'org-todo-regexp org-todo-regexp
4549 'level level
4550 'org-complex-heading-regexp org-complex-heading-regexp
4551 'priority 1000 'org-category category
4552 'org-category-position category-pos
4553 'type "search")
4554 (push txt ee)
4555 (goto-char (1- end))))))))))
4556 (setq rtn (nreverse ee))
4557 (setq rtnall (append rtnall rtn)))
4558 (if org-agenda-overriding-header
4559 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4560 nil 'face 'org-agenda-structure) "\n")
4561 (insert "Search words: ")
4562 (add-text-properties (point-min) (1- (point))
4563 (list 'face 'org-agenda-structure))
4564 (setq pos (point))
4565 (insert string "\n")
4566 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4567 (setq pos (point))
4568 (unless org-agenda-multi
4569 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4570 (add-text-properties pos (1- (point))
4571 (list 'face 'org-agenda-structure))))
4572 (org-agenda-mark-header-line (point-min))
4573 (when rtnall
4574 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4575 (goto-char (point-min))
4576 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4577 (add-text-properties (point-min) (point-max)
4578 `(org-agenda-type search
4579 org-last-args (,todo-only ,string ,edit-at)
4580 org-redo-cmd ,org-agenda-redo-command
4581 org-series-cmd ,org-cmd))
4582 (org-agenda-finalize)
4583 (setq buffer-read-only t))))
4585 ;;; Agenda TODO list
4587 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4588 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4589 (concat
4590 (if (or (equal keywords "ALL") (not keywords))
4591 (propertize "ALL" 'face 'warning)
4592 (mapconcat
4593 (lambda (kw)
4594 (propertize kw 'face (org-get-todo-face kw)))
4595 (org-split-string keywords "|")
4596 "|"))
4597 "\n"))
4599 (defvar org-select-this-todo-keyword nil)
4600 (defvar org-last-arg nil)
4602 ;;;###autoload
4603 (defun org-todo-list (&optional arg)
4604 "Show all (not done) TODO entries from all agenda file in a single list.
4605 The prefix arg can be used to select a specific TODO keyword and limit
4606 the list to these. When using \\[universal-argument], you will be prompted
4607 for a keyword. A numeric prefix directly selects the Nth keyword in
4608 `org-todo-keywords-1'."
4609 (interactive "P")
4610 (if org-agenda-overriding-arguments
4611 (setq arg org-agenda-overriding-arguments))
4612 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4613 (let* ((today (org-today))
4614 (date (calendar-gregorian-from-absolute today))
4615 (kwds org-todo-keywords-for-agenda)
4616 (completion-ignore-case t)
4617 (org-select-this-todo-keyword
4618 (if (stringp arg) arg
4619 (and arg (integerp arg) (> arg 0)
4620 (nth (1- arg) kwds))))
4621 rtn rtnall files file pos)
4622 (when (equal arg '(4))
4623 (setq org-select-this-todo-keyword
4624 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4625 (mapcar 'list kwds) nil nil)))
4626 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4627 (catch 'exit
4628 (if org-agenda-sticky
4629 (setq org-agenda-buffer-name
4630 (if (stringp org-select-this-todo-keyword)
4631 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4632 org-select-this-todo-keyword)
4633 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4634 (org-agenda-prepare "TODO")
4635 (org-compile-prefix-format 'todo)
4636 (org-set-sorting-strategy 'todo)
4637 (setq org-agenda-redo-command
4638 `(org-todo-list (or (and (numberp current-prefix-arg)
4639 current-prefix-arg)
4640 ,org-select-this-todo-keyword
4641 current-prefix-arg ,arg)))
4642 (setq files (org-agenda-files nil 'ifmode)
4643 rtnall nil)
4644 (while (setq file (pop files))
4645 (catch 'nextfile
4646 (org-check-agenda-file file)
4647 (setq rtn (org-agenda-get-day-entries file date :todo))
4648 (setq rtnall (append rtnall rtn))))
4649 (if org-agenda-overriding-header
4650 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4651 nil 'face 'org-agenda-structure) "\n")
4652 (insert "Global list of TODO items of type: ")
4653 (add-text-properties (point-min) (1- (point))
4654 (list 'face 'org-agenda-structure
4655 'short-heading
4656 (concat "ToDo: "
4657 (or org-select-this-todo-keyword "ALL"))))
4658 (org-agenda-mark-header-line (point-min))
4659 (insert (org-agenda-propertize-selected-todo-keywords
4660 org-select-this-todo-keyword))
4661 (setq pos (point))
4662 (unless org-agenda-multi
4663 (insert "Available with `N r': (0)[ALL]")
4664 (let ((n 0) s)
4665 (mapc (lambda (x)
4666 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4667 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4668 (insert "\n "))
4669 (insert " " s))
4670 kwds))
4671 (insert "\n"))
4672 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4673 (org-agenda-mark-header-line (point-min))
4674 (when rtnall
4675 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4676 (goto-char (point-min))
4677 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4678 (add-text-properties (point-min) (point-max)
4679 `(org-agenda-type todo
4680 org-last-args ,arg
4681 org-redo-cmd ,org-agenda-redo-command
4682 org-series-cmd ,org-cmd))
4683 (org-agenda-finalize)
4684 (setq buffer-read-only t))))
4686 ;;; Agenda tags match
4688 ;;;###autoload
4689 (defun org-tags-view (&optional todo-only match)
4690 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4691 The prefix arg TODO-ONLY limits the search to TODO entries."
4692 (interactive "P")
4693 (if org-agenda-overriding-arguments
4694 (setq todo-only (car org-agenda-overriding-arguments)
4695 match (nth 1 org-agenda-overriding-arguments)))
4696 (let* ((org-tags-match-list-sublevels
4697 org-tags-match-list-sublevels)
4698 (completion-ignore-case t)
4699 rtn rtnall files file pos matcher
4700 buffer)
4701 (when (and (stringp match) (not (string-match "\\S-" match)))
4702 (setq match nil))
4703 (setq matcher (org-make-tags-matcher match)
4704 match (car matcher) matcher (cdr matcher))
4705 (catch 'exit
4706 (if org-agenda-sticky
4707 (setq org-agenda-buffer-name
4708 (if (stringp match)
4709 (format "*Org Agenda(%s:%s)*"
4710 (or org-keys (or (and todo-only "M") "m")) match)
4711 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4712 (org-agenda-prepare (concat "TAGS " match))
4713 (org-compile-prefix-format 'tags)
4714 (org-set-sorting-strategy 'tags)
4715 (setq org-agenda-query-string match)
4716 (setq org-agenda-redo-command
4717 (list 'org-tags-view `(quote ,todo-only)
4718 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4719 (setq files (org-agenda-files nil 'ifmode)
4720 rtnall nil)
4721 (while (setq file (pop files))
4722 (catch 'nextfile
4723 (org-check-agenda-file file)
4724 (setq buffer (if (file-exists-p file)
4725 (org-get-agenda-file-buffer file)
4726 (error "No such file %s" file)))
4727 (if (not buffer)
4728 ;; If file does not exist, error message to agenda
4729 (setq rtn (list
4730 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4731 rtnall (append rtnall rtn))
4732 (with-current-buffer buffer
4733 (unless (derived-mode-p 'org-mode)
4734 (error "Agenda file %s is not in `org-mode'" file))
4735 (save-excursion
4736 (save-restriction
4737 (if org-agenda-restrict
4738 (narrow-to-region org-agenda-restrict-begin
4739 org-agenda-restrict-end)
4740 (widen))
4741 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4742 (setq rtnall (append rtnall rtn))))))))
4743 (if org-agenda-overriding-header
4744 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4745 nil 'face 'org-agenda-structure) "\n")
4746 (insert "Headlines with TAGS match: ")
4747 (add-text-properties (point-min) (1- (point))
4748 (list 'face 'org-agenda-structure
4749 'short-heading
4750 (concat "Match: " match)))
4751 (setq pos (point))
4752 (insert match "\n")
4753 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4754 (setq pos (point))
4755 (unless org-agenda-multi
4756 (insert "Press `C-u r' to search again with new search string\n"))
4757 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4758 (org-agenda-mark-header-line (point-min))
4759 (when rtnall
4760 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4761 (goto-char (point-min))
4762 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4763 (add-text-properties (point-min) (point-max)
4764 `(org-agenda-type tags
4765 org-last-args (,todo-only ,match)
4766 org-redo-cmd ,org-agenda-redo-command
4767 org-series-cmd ,org-cmd))
4768 (org-agenda-finalize)
4769 (setq buffer-read-only t))))
4771 ;;; Agenda Finding stuck projects
4773 (defvar org-agenda-skip-regexp nil
4774 "Regular expression used in skipping subtrees for the agenda.
4775 This is basically a temporary global variable that can be set and then
4776 used by user-defined selections using `org-agenda-skip-function'.")
4778 (defvar org-agenda-overriding-header nil
4779 "When set during agenda, todo and tags searches it replaces the header.
4780 This variable should not be set directly, but custom commands can bind it
4781 in the options section.")
4783 (defun org-agenda-skip-entry-when-regexp-matches ()
4784 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4785 If yes, it returns the end position of this entry, causing agenda commands
4786 to skip the entry but continuing the search in the subtree. This is a
4787 function that can be put into `org-agenda-skip-function' for the duration
4788 of a command."
4789 (let ((end (save-excursion (org-end-of-subtree t)))
4790 skip)
4791 (save-excursion
4792 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4793 (and skip end)))
4795 (defun org-agenda-skip-subtree-when-regexp-matches ()
4796 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4797 If yes, it returns the end position of this tree, causing agenda commands
4798 to skip this subtree. This is a function that can be put into
4799 `org-agenda-skip-function' for the duration of a command."
4800 (let ((end (save-excursion (org-end-of-subtree t)))
4801 skip)
4802 (save-excursion
4803 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4804 (and skip end)))
4806 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4807 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4808 If yes, it returns the end position of the current entry (NOT the tree),
4809 causing agenda commands to skip the entry but continuing the search in
4810 the subtree. This is a function that can be put into
4811 `org-agenda-skip-function' for the duration of a command. An important
4812 use of this function is for the stuck project list."
4813 (let ((end (save-excursion (org-end-of-subtree t)))
4814 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4815 skip)
4816 (save-excursion
4817 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4818 (and skip entry-end)))
4820 (defun org-agenda-skip-entry-if (&rest conditions)
4821 "Skip entry if any of CONDITIONS is true.
4822 See `org-agenda-skip-if' for details."
4823 (org-agenda-skip-if nil conditions))
4825 (defun org-agenda-skip-subtree-if (&rest conditions)
4826 "Skip entry if any of CONDITIONS is true.
4827 See `org-agenda-skip-if' for details."
4828 (org-agenda-skip-if t conditions))
4830 (defun org-agenda-skip-if (subtree conditions)
4831 "Checks current entity for CONDITIONS.
4832 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4833 the entry (i.e. the text before the next heading) is checked.
4835 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4836 from different tests. Valid conditions are:
4838 scheduled Check if there is a scheduled cookie
4839 notscheduled Check if there is no scheduled cookie
4840 deadline Check if there is a deadline
4841 notdeadline Check if there is no deadline
4842 timestamp Check if there is a timestamp (also deadline or scheduled)
4843 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4844 regexp Check if regexp matches
4845 notregexp Check if regexp does not match.
4846 todo Check if TODO keyword matches
4847 nottodo Check if TODO keyword does not match
4849 The regexp is taken from the conditions list, it must come right after
4850 the `regexp' or `notregexp' element.
4852 `todo' and `nottodo' accept as an argument a list of todo
4853 keywords, which may include \"*\" to match any todo keyword.
4855 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4857 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4859 Instead of a list, a keyword class may be given. For example:
4861 (org-agenda-skip-entry-if 'nottodo 'done)
4863 would skip entries that haven't been marked with any of \"DONE\"
4864 keywords. Possible classes are: `todo', `done', `any'.
4866 If any of these conditions is met, this function returns the end point of
4867 the entity, causing the search to continue from there. This is a function
4868 that can be put into `org-agenda-skip-function' for the duration of a command."
4869 (let (beg end m)
4870 (org-back-to-heading t)
4871 (setq beg (point)
4872 end (if subtree
4873 (progn (org-end-of-subtree t) (point))
4874 (progn (outline-next-heading) (1- (point)))))
4875 (goto-char beg)
4876 (and
4878 (and (memq 'scheduled conditions)
4879 (re-search-forward org-scheduled-time-regexp end t))
4880 (and (memq 'notscheduled conditions)
4881 (not (re-search-forward org-scheduled-time-regexp end t)))
4882 (and (memq 'deadline conditions)
4883 (re-search-forward org-deadline-time-regexp end t))
4884 (and (memq 'notdeadline conditions)
4885 (not (re-search-forward org-deadline-time-regexp end t)))
4886 (and (memq 'timestamp conditions)
4887 (re-search-forward org-ts-regexp end t))
4888 (and (memq 'nottimestamp conditions)
4889 (not (re-search-forward org-ts-regexp end t)))
4890 (and (setq m (memq 'regexp conditions))
4891 (stringp (nth 1 m))
4892 (re-search-forward (nth 1 m) end t))
4893 (and (setq m (memq 'notregexp conditions))
4894 (stringp (nth 1 m))
4895 (not (re-search-forward (nth 1 m) end t)))
4896 (and (or
4897 (setq m (memq 'nottodo conditions))
4898 (setq m (memq 'todo-unblocked conditions))
4899 (setq m (memq 'nottodo-unblocked conditions))
4900 (setq m (memq 'todo conditions)))
4901 (org-agenda-skip-if-todo m end)))
4902 end)))
4904 (defun org-agenda-skip-if-todo (args end)
4905 "Helper function for `org-agenda-skip-if', do not use it directly.
4906 ARGS is a list with first element either `todo', `nottodo',
4907 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4908 a list of TODO keywords, or a state symbol `todo' or `done' or
4909 `any'."
4910 (let ((kw (car args))
4911 (arg (cadr args))
4912 todo-wds todo-re)
4913 (setq todo-wds
4914 (org-uniquify
4915 (cond
4916 ((listp arg) ;; list of keywords
4917 (if (member "*" arg)
4918 (mapcar 'substring-no-properties org-todo-keywords-1)
4919 arg))
4920 ((symbolp arg) ;; keyword class name
4921 (cond
4922 ((eq arg 'todo)
4923 (org-delete-all org-done-keywords
4924 (mapcar 'substring-no-properties
4925 org-todo-keywords-1)))
4926 ((eq arg 'done) org-done-keywords)
4927 ((eq arg 'any)
4928 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4929 (setq todo-re
4930 (concat "^\\*+[ \t]+\\<\\("
4931 (mapconcat 'identity todo-wds "\\|")
4932 "\\)\\>"))
4933 (cond
4934 ((eq kw 'todo) (re-search-forward todo-re end t))
4935 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4936 ((eq kw 'todo-unblocked)
4937 (catch 'unblocked
4938 (while (re-search-forward todo-re end t)
4939 (or (org-entry-blocked-p) (throw 'unblocked t)))
4940 nil))
4941 ((eq kw 'nottodo-unblocked)
4942 (catch 'unblocked
4943 (while (re-search-forward todo-re end t)
4944 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4948 ;;;###autoload
4949 (defun org-agenda-list-stuck-projects (&rest ignore)
4950 "Create agenda view for projects that are stuck.
4951 Stuck projects are project that have no next actions. For the definitions
4952 of what a project is and how to check if it stuck, customize the variable
4953 `org-stuck-projects'."
4954 (interactive)
4955 (let* ((org-agenda-skip-function
4956 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4957 ;; We could have used org-agenda-skip-if here.
4958 (org-agenda-overriding-header
4959 (or org-agenda-overriding-header "List of stuck projects: "))
4960 (matcher (nth 0 org-stuck-projects))
4961 (todo (nth 1 org-stuck-projects))
4962 (todo-wds (if (member "*" todo)
4963 (progn
4964 (org-agenda-prepare-buffers (org-agenda-files
4965 nil 'ifmode))
4966 (org-delete-all
4967 org-done-keywords-for-agenda
4968 (copy-sequence org-todo-keywords-for-agenda)))
4969 todo))
4970 (todo-re (concat "^\\*+[ \t]+\\("
4971 (mapconcat 'identity todo-wds "\\|")
4972 "\\)\\>"))
4973 (tags (nth 2 org-stuck-projects))
4974 (tags-re (if (member "*" tags)
4975 (concat org-outline-regexp-bol
4976 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4977 (if tags
4978 (concat org-outline-regexp-bol
4979 ".*:\\("
4980 (mapconcat 'identity tags "\\|")
4981 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4982 (gen-re (nth 3 org-stuck-projects))
4983 (re-list
4984 (delq nil
4985 (list
4986 (if todo todo-re)
4987 (if tags tags-re)
4988 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4989 gen-re)))))
4990 (setq org-agenda-skip-regexp
4991 (if re-list
4992 (mapconcat 'identity re-list "\\|")
4993 (error "No information how to identify unstuck projects")))
4994 (org-tags-view nil matcher)
4995 (with-current-buffer org-agenda-buffer-name
4996 (setq org-agenda-redo-command
4997 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4999 ;;; Diary integration
5001 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5002 (defvar diary-list-entries-hook)
5003 (defvar diary-time-regexp)
5004 (defun org-get-entries-from-diary (date)
5005 "Get the (Emacs Calendar) diary entries for DATE."
5006 (require 'diary-lib)
5007 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5008 (diary-display-hook '(fancy-diary-display))
5009 (diary-display-function 'fancy-diary-display)
5010 (pop-up-frames nil)
5011 (diary-list-entries-hook
5012 (cons 'org-diary-default-entry diary-list-entries-hook))
5013 (diary-file-name-prefix nil) ; turn this feature off
5014 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5015 entries
5016 (org-disable-agenda-to-diary t))
5017 (save-excursion
5018 (save-window-excursion
5019 (funcall (if (fboundp 'diary-list-entries)
5020 'diary-list-entries 'list-diary-entries)
5021 date 1)))
5022 (if (not (get-buffer diary-fancy-buffer))
5023 (setq entries nil)
5024 (with-current-buffer diary-fancy-buffer
5025 (setq buffer-read-only nil)
5026 (if (zerop (buffer-size))
5027 ;; No entries
5028 (setq entries nil)
5029 ;; Omit the date and other unnecessary stuff
5030 (org-agenda-cleanup-fancy-diary)
5031 ;; Add prefix to each line and extend the text properties
5032 (if (zerop (buffer-size))
5033 (setq entries nil)
5034 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5035 (setq entries
5036 (with-temp-buffer
5037 (insert entries) (goto-char (point-min))
5038 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5039 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5040 (replace-match (concat "; " (match-string 1)))))
5041 (buffer-string)))))
5042 (set-buffer-modified-p nil)
5043 (kill-buffer diary-fancy-buffer)))
5044 (when entries
5045 (setq entries (org-split-string entries "\n"))
5046 (setq entries
5047 (mapcar
5048 (lambda (x)
5049 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5050 ;; Extend the text properties to the beginning of the line
5051 (org-add-props x (text-properties-at (1- (length x)) x)
5052 'type "diary" 'date date 'face 'org-agenda-diary))
5053 entries)))))
5055 (defvar org-agenda-cleanup-fancy-diary-hook nil
5056 "Hook run when the fancy diary buffer is cleaned up.")
5058 (defun org-agenda-cleanup-fancy-diary ()
5059 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5060 This gets rid of the date, the underline under the date, and
5061 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5062 date. It also removes lines that contain only whitespace."
5063 (goto-char (point-min))
5064 (if (looking-at ".*?:[ \t]*")
5065 (progn
5066 (replace-match "")
5067 (re-search-forward "\n=+$" nil t)
5068 (replace-match "")
5069 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5070 (re-search-forward "\n=+$" nil t)
5071 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5072 (goto-char (point-min))
5073 (while (re-search-forward "^ +\n" nil t)
5074 (replace-match ""))
5075 (goto-char (point-min))
5076 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5077 (replace-match ""))
5078 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5080 ;; Make sure entries from the diary have the right text properties.
5081 (eval-after-load "diary-lib"
5082 '(if (boundp 'diary-modify-entry-list-string-function)
5083 ;; We can rely on the hook, nothing to do
5085 ;; Hook not available, must use advice to make this work
5086 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5087 "Make the position visible."
5088 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5089 (stringp string)
5090 buffer-file-name)
5091 (setq string (org-modify-diary-entry-string string))))))
5093 (defun org-modify-diary-entry-string (string)
5094 "Add text properties to string, allowing org-mode to act on it."
5095 (org-add-props string nil
5096 'mouse-face 'highlight
5097 'help-echo (if buffer-file-name
5098 (format "mouse-2 or RET jump to diary file %s"
5099 (abbreviate-file-name buffer-file-name))
5101 'org-agenda-diary-link t
5102 'org-marker (org-agenda-new-marker (point-at-bol))))
5104 (defun org-diary-default-entry ()
5105 "Add a dummy entry to the diary.
5106 Needed to avoid empty dates which mess up holiday display."
5107 ;; Catch the error if dealing with the new add-to-diary-alist
5108 (when org-disable-agenda-to-diary
5109 (condition-case nil
5110 (org-add-to-diary-list original-date "Org-mode dummy" "")
5111 (error
5112 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5114 (defun org-add-to-diary-list (&rest args)
5115 (if (fboundp 'diary-add-to-list)
5116 (apply 'diary-add-to-list args)
5117 (apply 'add-to-diary-list args)))
5119 (defvar org-diary-last-run-time nil)
5121 ;;;###autoload
5122 (defun org-diary (&rest args)
5123 "Return diary information from org files.
5124 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5125 It accesses org files and extracts information from those files to be
5126 listed in the diary. The function accepts arguments specifying what
5127 items should be listed. For a list of arguments allowed here, see the
5128 variable `org-agenda-entry-types'.
5130 The call in the diary file should look like this:
5132 &%%(org-diary) ~/path/to/some/orgfile.org
5134 Use a separate line for each org file to check. Or, if you omit the file name,
5135 all files listed in `org-agenda-files' will be checked automatically:
5137 &%%(org-diary)
5139 If you don't give any arguments (as in the example above), the default
5140 arguments (:deadline :scheduled :timestamp :sexp) are used.
5141 So the example above may also be written as
5143 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5145 The function expects the lisp variables `entry' and `date' to be provided
5146 by the caller, because this is how the calendar works. Don't use this
5147 function from a program - use `org-agenda-get-day-entries' instead."
5148 (when (> (- (org-float-time)
5149 org-agenda-last-marker-time)
5151 ;; I am not sure if this works with sticky agendas, because the marker
5152 ;; list is then no longer a global variable.
5153 (org-agenda-reset-markers))
5154 (org-compile-prefix-format 'agenda)
5155 (org-set-sorting-strategy 'agenda)
5156 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5157 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5158 (list entry)
5159 (org-agenda-files t)))
5160 (time (org-float-time))
5161 file rtn results)
5162 (when (or (not org-diary-last-run-time)
5163 (> (- time
5164 org-diary-last-run-time)
5166 (org-agenda-prepare-buffers files))
5167 (setq org-diary-last-run-time time)
5168 ;; If this is called during org-agenda, don't return any entries to
5169 ;; the calendar. Org Agenda will list these entries itself.
5170 (if org-disable-agenda-to-diary (setq files nil))
5171 (while (setq file (pop files))
5172 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5173 (setq results (append results rtn)))
5174 (when results
5175 (setq results
5176 (mapcar (lambda (i) (replace-regexp-in-string
5177 org-bracket-link-regexp "\\3" i)) results))
5178 (concat (org-agenda-finalize-entries results) "\n"))))
5180 ;;; Agenda entry finders
5182 (defun org-agenda-get-day-entries (file date &rest args)
5183 "Does the work for `org-diary' and `org-agenda'.
5184 FILE is the path to a file to be checked for entries. DATE is date like
5185 the one returned by `calendar-current-date'. ARGS are symbols indicating
5186 which kind of entries should be extracted. For details about these, see
5187 the documentation of `org-diary'."
5188 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5189 (let* ((org-startup-folded nil)
5190 (org-startup-align-all-tables nil)
5191 (buffer (if (file-exists-p file)
5192 (org-get-agenda-file-buffer file)
5193 (error "No such file %s" file)))
5194 arg results rtn deadline-results)
5195 (if (not buffer)
5196 ;; If file does not exist, make sure an error message ends up in diary
5197 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5198 (with-current-buffer buffer
5199 (unless (derived-mode-p 'org-mode)
5200 (error "Agenda file %s is not in `org-mode'" file))
5201 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5202 (let ((case-fold-search nil))
5203 (save-excursion
5204 (save-restriction
5205 (if org-agenda-restrict
5206 (narrow-to-region org-agenda-restrict-begin
5207 org-agenda-restrict-end)
5208 (widen))
5209 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5210 (while (setq arg (pop args))
5211 (cond
5212 ((and (eq arg :todo)
5213 (equal date (calendar-gregorian-from-absolute
5214 (org-today))))
5215 (setq rtn (org-agenda-get-todos))
5216 (setq results (append results rtn)))
5217 ((eq arg :timestamp)
5218 (setq rtn (org-agenda-get-blocks))
5219 (setq results (append results rtn))
5220 (setq rtn (org-agenda-get-timestamps deadline-results))
5221 (setq results (append results rtn)))
5222 ((eq arg :sexp)
5223 (setq rtn (org-agenda-get-sexps))
5224 (setq results (append results rtn)))
5225 ((eq arg :scheduled)
5226 (setq rtn (org-agenda-get-scheduled deadline-results))
5227 (setq results (append results rtn)))
5228 ((eq arg :closed)
5229 (setq rtn (org-agenda-get-progress))
5230 (setq results (append results rtn)))
5231 ((eq arg :deadline)
5232 (setq rtn (org-agenda-get-deadlines))
5233 (setq deadline-results (copy-sequence rtn))
5234 (setq results (append results rtn))))))))
5235 results))))
5237 (defsubst org-em (x y list)
5238 "Is X or Y a member of LIST?"
5239 (or (memq x list) (memq y list)))
5241 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5242 (defvar org-agenda-sorting-strategy-selected nil)
5244 (defun org-agenda-get-todos ()
5245 "Return the TODO information for agenda display."
5246 (let* ((props (list 'face nil
5247 'done-face 'org-agenda-done
5248 'org-not-done-regexp org-not-done-regexp
5249 'org-todo-regexp org-todo-regexp
5250 'org-complex-heading-regexp org-complex-heading-regexp
5251 'mouse-face 'highlight
5252 'help-echo
5253 (format "mouse-2 or RET jump to org file %s"
5254 (abbreviate-file-name buffer-file-name))))
5255 (regexp (format org-heading-keyword-regexp-format
5256 (cond
5257 ((and org-select-this-todo-keyword
5258 (equal org-select-this-todo-keyword "*"))
5259 org-todo-regexp)
5260 (org-select-this-todo-keyword
5261 (concat "\\("
5262 (mapconcat 'identity
5263 (org-split-string
5264 org-select-this-todo-keyword
5265 "|")
5266 "\\|") "\\)"))
5267 (t org-not-done-regexp))))
5268 marker priority category category-pos level tags todo-state ts-date ts-date-type
5269 ee txt beg end inherited-tags)
5270 (goto-char (point-min))
5271 (while (re-search-forward regexp nil t)
5272 (catch :skip
5273 (save-match-data
5274 (beginning-of-line)
5275 (org-agenda-skip)
5276 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5277 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5278 (goto-char (1+ beg))
5279 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5280 (throw :skip nil)))
5281 (goto-char (match-beginning 2))
5282 (setq marker (org-agenda-new-marker (match-beginning 0))
5283 category (org-get-category)
5284 ts-date (let (ts)
5285 (save-match-data
5286 (cond ((org-em 'scheduled-up 'scheduled-down
5287 org-agenda-sorting-strategy-selected)
5288 (setq ts (org-entry-get (point) "SCHEDULED")
5289 ts-date-type " scheduled"))
5290 ((org-em 'deadline-up 'deadline-down
5291 org-agenda-sorting-strategy-selected)
5292 (setq ts (org-entry-get (point) "DEADLINE")
5293 ts-date-type " deadline"))
5294 ((org-em 'ts-up 'ts-down
5295 org-agenda-sorting-strategy-selected)
5296 (setq ts (org-entry-get (point) "TIMESTAMP")
5297 ts-date-type " timestamp"))
5298 ((org-em 'tsia-up 'tsia-down
5299 org-agenda-sorting-strategy-selected)
5300 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5301 ts-date-type " timestamp_ia"))
5302 ((org-em 'timestamp-up 'timestamp-down
5303 org-agenda-sorting-strategy-selected)
5304 (setq ts (or (org-entry-get (point) "SCHEDULED")
5305 (org-entry-get (point) "DEADLINE")
5306 (org-entry-get (point) "TIMESTAMP")
5307 (org-entry-get (point) "TIMESTAMP_IA"))
5308 ts-date-type ""))
5309 (t (setq ts-date-type "")))
5310 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5311 category-pos (get-text-property (point) 'org-category-position)
5312 txt (org-trim
5313 (buffer-substring (match-beginning 2) (match-end 0)))
5314 inherited-tags
5315 (or (eq org-agenda-show-inherited-tags 'always)
5316 (and (listp org-agenda-show-inherited-tags)
5317 (memq 'todo org-agenda-show-inherited-tags))
5318 (and (eq org-agenda-show-inherited-tags t)
5319 (or (eq org-agenda-use-tag-inheritance t)
5320 (memq 'todo org-agenda-use-tag-inheritance))))
5321 tags (org-get-tags-at nil (not inherited-tags))
5322 level (make-string (org-reduced-level (org-outline-level)) ? )
5323 txt (org-agenda-format-item "" txt level category tags t)
5324 priority (1+ (org-get-priority txt))
5325 todo-state (org-get-todo-state))
5326 (org-add-props txt props
5327 'org-marker marker 'org-hd-marker marker
5328 'priority priority 'org-category category
5329 'level level
5330 'ts-date ts-date
5331 'org-category-position category-pos
5332 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5333 (push txt ee)
5334 (if org-agenda-todo-list-sublevels
5335 (goto-char (match-end 2))
5336 (org-end-of-subtree 'invisible))))
5337 (nreverse ee)))
5339 (defun org-agenda-todo-custom-ignore-p (time n)
5340 "Check whether timestamp is farther away than n number of days.
5341 This function is invoked if `org-agenda-todo-ignore-deadlines',
5342 `org-agenda-todo-ignore-scheduled' or
5343 `org-agenda-todo-ignore-timestamp' is set to an integer."
5344 (let ((days (org-time-stamp-to-now
5345 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5346 (if (>= n 0)
5347 (>= days n)
5348 (<= days n))))
5350 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5351 (&optional end)
5352 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5353 (when (or org-agenda-todo-ignore-with-date
5354 org-agenda-todo-ignore-scheduled
5355 org-agenda-todo-ignore-deadlines
5356 org-agenda-todo-ignore-timestamp)
5357 (setq end (or end (save-excursion (outline-next-heading) (point))))
5358 (save-excursion
5359 (or (and org-agenda-todo-ignore-with-date
5360 (re-search-forward org-ts-regexp end t))
5361 (and org-agenda-todo-ignore-scheduled
5362 (re-search-forward org-scheduled-time-regexp end t)
5363 (cond
5364 ((eq org-agenda-todo-ignore-scheduled 'future)
5365 (> (org-time-stamp-to-now
5366 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5367 ((eq org-agenda-todo-ignore-scheduled 'past)
5368 (<= (org-time-stamp-to-now
5369 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5370 ((numberp org-agenda-todo-ignore-scheduled)
5371 (org-agenda-todo-custom-ignore-p
5372 (match-string 1) org-agenda-todo-ignore-scheduled))
5373 (t)))
5374 (and org-agenda-todo-ignore-deadlines
5375 (re-search-forward org-deadline-time-regexp end t)
5376 (cond
5377 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5378 ((eq org-agenda-todo-ignore-deadlines 'far)
5379 (not (org-deadline-close (match-string 1))))
5380 ((eq org-agenda-todo-ignore-deadlines 'future)
5381 (> (org-time-stamp-to-now
5382 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5383 ((eq org-agenda-todo-ignore-deadlines 'past)
5384 (<= (org-time-stamp-to-now
5385 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5386 ((numberp org-agenda-todo-ignore-deadlines)
5387 (org-agenda-todo-custom-ignore-p
5388 (match-string 1) org-agenda-todo-ignore-deadlines))
5389 (t (org-deadline-close (match-string 1)))))
5390 (and org-agenda-todo-ignore-timestamp
5391 (let ((buffer (current-buffer))
5392 (regexp
5393 (concat
5394 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5395 (start (point)))
5396 ;; Copy current buffer into a temporary one
5397 (with-temp-buffer
5398 (insert-buffer-substring buffer start end)
5399 (goto-char (point-min))
5400 ;; Delete SCHEDULED and DEADLINE items
5401 (while (re-search-forward regexp end t)
5402 (delete-region (match-beginning 0) (match-end 0)))
5403 (goto-char (point-min))
5404 ;; No search for timestamp left
5405 (when (re-search-forward org-ts-regexp nil t)
5406 (cond
5407 ((eq org-agenda-todo-ignore-timestamp 'future)
5408 (> (org-time-stamp-to-now
5409 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5410 ((eq org-agenda-todo-ignore-timestamp 'past)
5411 (<= (org-time-stamp-to-now
5412 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5413 ((numberp org-agenda-todo-ignore-timestamp)
5414 (org-agenda-todo-custom-ignore-p
5415 (match-string 1) org-agenda-todo-ignore-timestamp))
5416 (t))))))))))
5418 (defun org-agenda-get-timestamps (&optional deadline-results)
5419 "Return the date stamp information for agenda display."
5420 (let* ((props (list 'face 'org-agenda-calendar-event
5421 'org-not-done-regexp org-not-done-regexp
5422 'org-todo-regexp org-todo-regexp
5423 'org-complex-heading-regexp org-complex-heading-regexp
5424 'mouse-face 'highlight
5425 'help-echo
5426 (format "mouse-2 or RET jump to org file %s"
5427 (abbreviate-file-name buffer-file-name))))
5428 (d1 (calendar-absolute-from-gregorian date))
5430 (deadline-position-alist
5431 (mapcar (lambda (a) (and (setq mm (get-text-property
5432 0 'org-hd-marker a))
5433 (cons (marker-position mm) a)))
5434 deadline-results))
5435 (remove-re org-ts-regexp)
5436 (regexp
5437 (concat
5438 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5439 (regexp-quote
5440 (substring
5441 (format-time-string
5442 (car org-time-stamp-formats)
5443 (apply 'encode-time ; DATE bound by calendar
5444 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5445 1 11))
5446 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5447 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5448 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5449 donep tmp priority category category-pos level ee txt timestr tags
5450 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5451 inherited-tags ts-date)
5452 (goto-char (point-min))
5453 (while (setq end-of-match (re-search-forward regexp nil t))
5454 (setq b0 (match-beginning 0)
5455 b3 (match-beginning 3) e3 (match-end 3)
5456 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5457 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5458 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5459 (member todo-state
5460 org-agenda-repeating-timestamp-show-all)))
5461 (catch :skip
5462 (and (org-at-date-range-p) (throw :skip nil))
5463 (org-agenda-skip)
5464 (if (and (match-end 1)
5465 (not (= d1 (org-time-string-to-absolute
5466 (match-string 1) d1 nil show-all
5467 (current-buffer) b0))))
5468 (throw :skip nil))
5469 (if (and e3
5470 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5471 (throw :skip nil))
5472 (setq tmp (buffer-substring (max (point-min)
5473 (- b0 org-ds-keyword-length))
5475 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5476 inactivep (= (char-after b0) ?\[)
5477 deadlinep (string-match org-deadline-regexp tmp)
5478 scheduledp (string-match org-scheduled-regexp tmp)
5479 closedp (and org-agenda-include-inactive-timestamps
5480 (string-match org-closed-string tmp))
5481 clockp (and org-agenda-include-inactive-timestamps
5482 (or (string-match org-clock-string tmp)
5483 (string-match "]-+\\'" tmp)))
5484 warntime (get-text-property (point) 'org-appt-warntime)
5485 donep (member todo-state org-done-keywords))
5486 (if (or scheduledp deadlinep closedp clockp
5487 (and donep org-agenda-skip-timestamp-if-done))
5488 (throw :skip t))
5489 (if (string-match ">" timestr)
5490 ;; substring should only run to end of time stamp
5491 (setq timestr (substring timestr 0 (match-end 0))))
5492 (setq marker (org-agenda-new-marker b0)
5493 category (org-get-category b0)
5494 category-pos (get-text-property b0 'org-category-position))
5495 (save-excursion
5496 (if (not (re-search-backward org-outline-regexp-bol nil t))
5497 (throw :skip nil)
5498 (goto-char (match-beginning 0))
5499 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5500 (assoc (point) deadline-position-alist))
5501 (throw :skip nil))
5502 (setq hdmarker (org-agenda-new-marker)
5503 inherited-tags
5504 (or (eq org-agenda-show-inherited-tags 'always)
5505 (and (listp org-agenda-show-inherited-tags)
5506 (memq 'agenda org-agenda-show-inherited-tags))
5507 (and (eq org-agenda-show-inherited-tags t)
5508 (or (eq org-agenda-use-tag-inheritance t)
5509 (memq 'agenda org-agenda-use-tag-inheritance))))
5510 tags (org-get-tags-at nil (not inherited-tags))
5511 level (make-string (org-reduced-level (org-outline-level)) ? ))
5512 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5513 (setq head (or (match-string 1) ""))
5514 (setq txt (org-agenda-format-item
5515 (if inactivep org-agenda-inactive-leader nil)
5516 head level category tags timestr
5517 remove-re habitp)))
5518 (setq priority (org-get-priority txt))
5519 (org-add-props txt props 'priority priority
5520 'org-marker marker 'org-hd-marker hdmarker
5521 'org-category category 'date date
5522 'level level
5523 'ts-date
5524 (ignore-errors (org-time-string-to-absolute timestr))
5525 'org-category-position category-pos
5526 'todo-state todo-state
5527 'warntime warntime
5528 'type "timestamp")
5529 (push txt ee))
5530 (if org-agenda-skip-additional-timestamps-same-entry
5531 (outline-next-heading)
5532 (goto-char end-of-match))))
5533 (nreverse ee)))
5535 (defun org-agenda-get-sexps ()
5536 "Return the sexp information for agenda display."
5537 (require 'diary-lib)
5538 (let* ((props (list 'face 'org-agenda-calendar-sexp
5539 'mouse-face 'highlight
5540 'help-echo
5541 (format "mouse-2 or RET jump to org file %s"
5542 (abbreviate-file-name buffer-file-name))))
5543 (regexp "^&?%%(")
5544 marker category extra category-pos level ee txt tags entry
5545 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5546 (goto-char (point-min))
5547 (while (re-search-forward regexp nil t)
5548 (catch :skip
5549 (org-agenda-skip)
5550 (setq beg (match-beginning 0))
5551 (goto-char (1- (match-end 0)))
5552 (setq b (point))
5553 (forward-sexp 1)
5554 (setq sexp (buffer-substring b (point)))
5555 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5556 (org-trim (match-string 1))
5557 ""))
5558 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5559 (when result
5560 (setq marker (org-agenda-new-marker beg)
5561 level (make-string (org-reduced-level (org-outline-level)) ? )
5562 category (org-get-category beg)
5563 category-pos (get-text-property beg 'org-category-position)
5564 inherited-tags
5565 (or (eq org-agenda-show-inherited-tags 'always)
5566 (and (listp org-agenda-show-inherited-tags)
5567 (memq 'agenda org-agenda-show-inherited-tags))
5568 (and (eq org-agenda-show-inherited-tags t)
5569 (or (eq org-agenda-use-tag-inheritance t)
5570 (memq 'agenda org-agenda-use-tag-inheritance))))
5571 tags (org-get-tags-at nil (not inherited-tags))
5572 todo-state (org-get-todo-state)
5573 warntime (get-text-property (point) 'org-appt-warntime)
5574 extra nil)
5576 (dolist (r (if (stringp result)
5577 (list result)
5578 result)) ;; we expect a list here
5579 (when (and org-agenda-diary-sexp-prefix
5580 (string-match org-agenda-diary-sexp-prefix r))
5581 (setq extra (match-string 0 r)
5582 r (replace-match "" nil nil r)))
5583 (if (string-match "\\S-" r)
5584 (setq txt r)
5585 (setq txt "SEXP entry returned empty string"))
5586 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5587 (org-add-props txt props 'org-marker marker
5588 'org-category category 'date date 'todo-state todo-state
5589 'org-category-position category-pos 'tags tags
5590 'level level
5591 'type "sexp" 'warntime warntime)
5592 (push txt ee)))))
5593 (nreverse ee)))
5595 ;; Calendar sanity: define some functions that are independent of
5596 ;; `calendar-date-style'.
5597 ;; Normally I would like to use ISO format when calling the diary functions,
5598 ;; but to make sure we still have Emacs 22 compatibility we bind
5599 ;; also `european-calendar-style' and use european format
5600 (defun org-anniversary (year month day &optional mark)
5601 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5602 (org-no-warnings
5603 (let ((calendar-date-style 'european) (european-calendar-style t))
5604 (diary-anniversary day month year mark))))
5605 (defun org-cyclic (N year month day &optional mark)
5606 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5607 (org-no-warnings
5608 (let ((calendar-date-style 'european) (european-calendar-style t))
5609 (diary-cyclic N day month year mark))))
5610 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5611 "Like `diary-block', but with fixed (ISO) order of arguments."
5612 (org-no-warnings
5613 (let ((calendar-date-style 'european) (european-calendar-style t))
5614 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5615 (defun org-date (year month day &optional mark)
5616 "Like `diary-date', but with fixed (ISO) order of arguments."
5617 (org-no-warnings
5618 (let ((calendar-date-style 'european) (european-calendar-style t))
5619 (diary-date day month year mark))))
5621 ;; Define the` org-class' function
5622 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5623 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5624 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5625 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5626 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5627 `holidays', then any date that is known by the Emacs calendar to be a
5628 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5629 then those holidays will be skipped."
5630 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5631 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5632 (d (calendar-absolute-from-gregorian date))
5633 (h (when skip-weeks (calendar-check-holidays date))))
5634 (and
5635 (<= date1 d)
5636 (<= d date2)
5637 (= (calendar-day-of-week date) dayname)
5638 (or (not skip-weeks)
5639 (progn
5640 (require 'cal-iso)
5641 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5642 (not (or (and h (memq 'holidays skip-weeks))
5643 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5644 entry)))
5646 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5647 "Like `org-class', but honor `calendar-date-style'.
5648 The order of the first 2 times 3 arguments depends on the variable
5649 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5650 So for American calendars, give this as MONTH DAY YEAR, for European as
5651 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5652 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5653 is any number of ISO weeks in the block period for which the item should
5654 be skipped.
5656 This function is here only for backward compatibility and it is deprecated,
5657 please use `org-class' instead."
5658 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5659 (date2 (org-order-calendar-date-args m2 d2 y2)))
5660 (org-class
5661 (nth 2 date1) (car date1) (nth 1 date1)
5662 (nth 2 date2) (car date2) (nth 1 date2)
5663 dayname skip-weeks)))
5664 (make-obsolete 'org-diary-class 'org-class "")
5666 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5667 (defalias 'org-get-closed 'org-agenda-get-progress)
5668 (defun org-agenda-get-progress ()
5669 "Return the logged TODO entries for agenda display."
5670 (let* ((props (list 'mouse-face 'highlight
5671 'org-not-done-regexp org-not-done-regexp
5672 'org-todo-regexp org-todo-regexp
5673 'org-complex-heading-regexp org-complex-heading-regexp
5674 'help-echo
5675 (format "mouse-2 or RET jump to org file %s"
5676 (abbreviate-file-name buffer-file-name))))
5677 (items (if (consp org-agenda-show-log-scoped)
5678 org-agenda-show-log-scoped
5679 (if (eq org-agenda-show-log-scoped 'clockcheck)
5680 '(clock)
5681 org-agenda-log-mode-items)))
5682 (parts
5683 (delq nil
5684 (list
5685 (if (memq 'closed items) (concat "\\<" org-closed-string))
5686 (if (memq 'clock items) (concat "\\<" org-clock-string))
5687 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5688 (parts-re (if parts (mapconcat 'identity parts "\\|")
5689 (error "`org-agenda-log-mode-items' is empty")))
5690 (regexp (concat
5691 "\\(" parts-re "\\)"
5692 " *\\["
5693 (regexp-quote
5694 (substring
5695 (format-time-string
5696 (car org-time-stamp-formats)
5697 (apply 'encode-time ; DATE bound by calendar
5698 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5699 1 11))))
5700 (org-agenda-search-headline-for-time nil)
5701 marker hdmarker priority category category-pos level tags closedp
5702 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5703 (goto-char (point-min))
5704 (while (re-search-forward regexp nil t)
5705 (catch :skip
5706 (org-agenda-skip)
5707 (setq marker (org-agenda-new-marker (match-beginning 0))
5708 closedp (equal (match-string 1) org-closed-string)
5709 statep (equal (string-to-char (match-string 1)) ?-)
5710 clockp (not (or closedp statep))
5711 state (and statep (match-string 2))
5712 category (org-get-category (match-beginning 0))
5713 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5714 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5715 (when (string-match "\\]" timestr)
5716 ;; substring should only run to end of time stamp
5717 (setq rest (substring timestr (match-end 0))
5718 timestr (substring timestr 0 (match-end 0)))
5719 (if (and (not closedp) (not statep)
5720 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5721 rest))
5722 (progn (setq timestr (concat (substring timestr 0 -1)
5723 "-" (match-string 1 rest) "]"))
5724 (setq clocked (match-string 2 rest)))
5725 (setq clocked "-")))
5726 (save-excursion
5727 (setq extra
5728 (cond
5729 ((not org-agenda-log-mode-add-notes) nil)
5730 (statep
5731 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5732 (match-string 1)))
5733 (clockp
5734 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5735 (match-string 1)))))
5736 (if (not (re-search-backward org-outline-regexp-bol nil t))
5737 (throw :skip nil)
5738 (goto-char (match-beginning 0))
5739 (setq hdmarker (org-agenda-new-marker)
5740 inherited-tags
5741 (or (eq org-agenda-show-inherited-tags 'always)
5742 (and (listp org-agenda-show-inherited-tags)
5743 (memq 'todo org-agenda-show-inherited-tags))
5744 (and (eq org-agenda-show-inherited-tags t)
5745 (or (eq org-agenda-use-tag-inheritance t)
5746 (memq 'todo org-agenda-use-tag-inheritance))))
5747 tags (org-get-tags-at nil (not inherited-tags))
5748 level (make-string (org-reduced-level (org-outline-level)) ? ))
5749 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5750 (setq txt (match-string 1))
5751 (when extra
5752 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5753 (setq txt (concat (substring txt 0 (match-beginning 1))
5754 " - " extra " " (match-string 2 txt)))
5755 (setq txt (concat txt " - " extra))))
5756 (setq txt (org-agenda-format-item
5757 (cond
5758 (closedp "Closed: ")
5759 (statep (concat "State: (" state ")"))
5760 (t (concat "Clocked: (" clocked ")")))
5761 txt level category tags timestr)))
5762 (setq priority 100000)
5763 (org-add-props txt props
5764 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5765 'priority priority 'org-category category
5766 'org-category-position category-pos
5767 'level level
5768 'type "closed" 'date date
5769 'undone-face 'org-warning 'done-face 'org-agenda-done)
5770 (push txt ee))
5771 (goto-char (point-at-eol))))
5772 (nreverse ee)))
5774 (defun org-agenda-show-clocking-issues ()
5775 "Add overlays, showing issues with clocking.
5776 See also the user option `org-agenda-clock-consistency-checks'."
5777 (interactive)
5778 (let* ((org-time-clocksum-use-effort-durations nil)
5779 (pl org-agenda-clock-consistency-checks)
5780 (re (concat "^[ \t]*"
5781 org-clock-string
5782 "[ \t]+"
5783 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5784 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5785 (tlstart 0.)
5786 (tlend 0.)
5787 (maxtime (org-hh:mm-string-to-minutes
5788 (or (plist-get pl :max-duration) "24:00")))
5789 (mintime (org-hh:mm-string-to-minutes
5790 (or (plist-get pl :min-duration) 0)))
5791 (maxgap (org-hh:mm-string-to-minutes
5792 ;; default 30:00 means never complain
5793 (or (plist-get pl :max-gap) "30:00")))
5794 (gapok (mapcar 'org-hh:mm-string-to-minutes
5795 (plist-get pl :gap-ok-around)))
5796 (def-face (or (plist-get pl :default-face)
5797 '((:background "DarkRed") (:foreground "white"))))
5798 issue face m te ts dt ov)
5799 (goto-char (point-min))
5800 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5801 (setq issue nil face def-face)
5802 (catch 'next
5803 (setq m (org-get-at-bol 'org-marker)
5804 te nil ts nil)
5805 (unless (and m (markerp m))
5806 (setq issue "No valid clock line") (throw 'next t))
5807 (org-with-point-at m
5808 (save-excursion
5809 (goto-char (point-at-bol))
5810 (unless (looking-at re)
5811 (error "No valid Clock line")
5812 (throw 'next t))
5813 (unless (match-end 3)
5814 (setq issue "No end time"
5815 face (or (plist-get pl :no-end-time-face) face))
5816 (throw 'next t))
5817 (setq ts (match-string 1)
5818 te (match-string 3)
5819 ts (org-float-time
5820 (apply 'encode-time (org-parse-time-string ts)))
5821 te (org-float-time
5822 (apply 'encode-time (org-parse-time-string te)))
5823 dt (- te ts))))
5824 (cond
5825 ((> dt (* 60 maxtime))
5826 ;; a very long clocking chunk
5827 (setq issue (format "Clocking interval is very long: %s"
5828 (org-minutes-to-clocksum-string
5829 (floor (/ (float dt) 60.))))
5830 face (or (plist-get pl :long-face) face)))
5831 ((< dt (* 60 mintime))
5832 ;; a very short clocking chunk
5833 (setq issue (format "Clocking interval is very short: %s"
5834 (org-minutes-to-clocksum-string
5835 (floor (/ (float dt) 60.))))
5836 face (or (plist-get pl :short-face) face)))
5837 ((and (> tlend 0) (< ts tlend))
5838 ;; Two clock entries are overlapping
5839 (setq issue (format "Clocking overlap: %d minutes"
5840 (/ (- tlend ts) 60))
5841 face (or (plist-get pl :overlap-face) face)))
5842 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5843 ;; There is a gap, lets see if we need to report it
5844 (unless (org-agenda-check-clock-gap tlend ts gapok)
5845 (setq issue (format "Clocking gap: %d minutes"
5846 (/ (- ts tlend) 60))
5847 face (or (plist-get pl :gap-face) face))))
5848 (t nil)))
5849 (setq tlend (or te tlend) tlstart (or ts tlstart))
5850 (when issue
5851 ;; OK, there was some issue, add an overlay to show the issue
5852 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5853 (overlay-put ov 'before-string
5854 (concat
5855 (org-add-props
5856 (format "%-43s" (concat " " issue))
5858 'face face)
5859 "\n"))
5860 (overlay-put ov 'evaporate t)))))
5862 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5863 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5864 (catch 'exit
5865 (unless ok-list
5866 ;; there are no OK times for gaps...
5867 (throw 'exit nil))
5868 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5869 ;; This is more than 24 hours, so it is OK.
5870 ;; because we have at least one OK time, that must be in the
5871 ;; 24 hour interval.
5872 (throw 'exit t))
5873 ;; We have a shorter gap.
5874 ;; Now we have to get the minute of the day when these times are
5875 (let* ((t1dec (decode-time (seconds-to-time t1)))
5876 (t2dec (decode-time (seconds-to-time t2)))
5877 ;; compute the minute on the day
5878 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5879 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5880 (when (< min2 min1)
5881 ;; if min2 is smaller than min1, this means it is on the next day.
5882 ;; Wrap it to after midnight.
5883 (setq min2 (+ min2 1440)))
5884 ;; Now check if any of the OK times is in the gap
5885 (mapc (lambda (x)
5886 ;; Wrap the time to after midnight if necessary
5887 (if (< x min1) (setq x (+ x 1440)))
5888 ;; Check if in interval
5889 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5890 ok-list)
5891 ;; Nope, this gap is not OK
5892 nil)))
5894 (defun org-agenda-get-deadlines ()
5895 "Return the deadline information for agenda display."
5896 (let* ((props (list 'mouse-face 'highlight
5897 'org-not-done-regexp org-not-done-regexp
5898 'org-todo-regexp org-todo-regexp
5899 'org-complex-heading-regexp org-complex-heading-regexp
5900 'help-echo
5901 (format "mouse-2 or RET jump to org file %s"
5902 (abbreviate-file-name buffer-file-name))))
5903 (regexp org-deadline-time-regexp)
5904 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5905 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5906 (dl0 (car org-agenda-deadline-leaders))
5907 (dl1 (nth 1 org-agenda-deadline-leaders))
5908 (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
5909 d2 diff dfrac wdays pos pos1 category category-pos level
5910 tags suppress-prewarning ee txt head face s todo-state
5911 show-all upcomingp donep timestr warntime inherited-tags ts-date)
5912 (goto-char (point-min))
5913 (while (re-search-forward regexp nil t)
5914 (catch :skip
5915 (org-agenda-skip)
5916 (setq s (match-string 1)
5917 txt nil
5918 pos (1- (match-beginning 1))
5919 todo-state (save-match-data (org-get-todo-state))
5920 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5921 (member todo-state
5922 org-agenda-repeating-timestamp-show-all))
5923 d2 (org-time-string-to-absolute
5924 s d1 'past show-all (current-buffer) pos)
5925 diff (- d2 d1))
5926 (setq suppress-prewarning
5927 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5928 (let ((item (buffer-substring (point-at-bol)
5929 (point-at-eol))))
5930 (save-match-data
5931 (and (string-match
5932 org-scheduled-time-regexp item)
5933 (match-string 1 item)))))))
5934 (cond
5935 ((not ds) nil)
5936 ;; The current item has a scheduled date (in ds), so
5937 ;; evaluate its prewarning lead time.
5938 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5939 ;; Use global prewarning-restart lead time.
5940 org-agenda-skip-deadline-prewarning-if-scheduled)
5941 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5942 'pre-scheduled)
5943 ;; Set prewarning to no earlier than scheduled.
5944 (min (- d2 (org-time-string-to-absolute
5945 ds d1 'past show-all (current-buffer) pos))
5946 org-deadline-warning-days))
5947 ;; Set prewarning to deadline.
5948 (t 0))))
5949 (setq wdays (if suppress-prewarning
5950 (let ((org-deadline-warning-days suppress-prewarning))
5951 (org-get-wdays s))
5952 (org-get-wdays s))
5953 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5954 upcomingp (and todayp (> diff 0)))
5955 ;; When to show a deadline in the calendar:
5956 ;; If the expiration is within wdays warning time.
5957 ;; Past-due deadlines are only shown on the current date
5958 (if (and (or (and (<= diff wdays)
5959 (and todayp (not org-agenda-only-exact-dates)))
5960 (= diff 0)))
5961 (save-excursion
5962 ;; (setq todo-state (org-get-todo-state))
5963 (setq donep (member todo-state org-done-keywords))
5964 (if (and donep
5965 (or org-agenda-skip-deadline-if-done
5966 (not (= diff 0))))
5967 (setq txt nil)
5968 (setq category (org-get-category)
5969 warntime (get-text-property (point) 'org-appt-warntime)
5970 category-pos (get-text-property (point) 'org-category-position))
5971 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5972 (throw :skip nil)
5973 (goto-char (match-end 0))
5974 (setq pos1 (match-beginning 0))
5975 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5976 (setq inherited-tags
5977 (or (eq org-agenda-show-inherited-tags 'always)
5978 (and (listp org-agenda-show-inherited-tags)
5979 (memq 'agenda org-agenda-show-inherited-tags))
5980 (and (eq org-agenda-show-inherited-tags t)
5981 (or (eq org-agenda-use-tag-inheritance t)
5982 (memq 'agenda org-agenda-use-tag-inheritance))))
5983 tags (org-get-tags-at pos1 (not inherited-tags)))
5984 (setq head (buffer-substring
5985 (point)
5986 (progn (skip-chars-forward "^\r\n")
5987 (point))))
5988 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5989 (setq timestr
5990 (concat (substring s (match-beginning 1)) " "))
5991 (setq timestr 'time))
5992 (setq txt (org-agenda-format-item
5993 (cond ((= diff 0) dl0)
5994 ((> diff 0)
5995 (if (functionp dl1)
5996 (funcall dl1 diff date)
5997 (format dl1 diff)))
5999 (if (functionp dl2)
6000 (funcall dl2 diff date)
6001 (format dl2 (if (string= dl2 dl1)
6002 diff (abs diff))))))
6003 head level category tags
6004 (if (not (= diff 0)) nil timestr)))))
6005 (when txt
6006 (setq face (org-agenda-deadline-face dfrac))
6007 (org-add-props txt props
6008 'org-marker (org-agenda-new-marker pos)
6009 'warntime warntime
6010 'level level
6011 'ts-date d2
6012 'org-hd-marker (org-agenda-new-marker pos1)
6013 'priority (+ (- diff)
6014 (org-get-priority txt))
6015 'org-category category
6016 'org-category-position category-pos
6017 'todo-state todo-state
6018 'type (if upcomingp "upcoming-deadline" "deadline")
6019 'date (if upcomingp date d2)
6020 'face (if donep 'org-agenda-done face)
6021 'undone-face face 'done-face 'org-agenda-done)
6022 (push txt ee))))))
6023 (nreverse ee)))
6025 (defun org-agenda-deadline-face (fraction)
6026 "Return the face to displaying a deadline item.
6027 FRACTION is what fraction of the head-warning time has passed."
6028 (let ((faces org-agenda-deadline-faces) f)
6029 (catch 'exit
6030 (while (setq f (pop faces))
6031 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6033 (defun org-agenda-get-scheduled (&optional deadline-results)
6034 "Return the scheduled information for agenda display."
6035 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6036 'org-todo-regexp org-todo-regexp
6037 'org-complex-heading-regexp org-complex-heading-regexp
6038 'done-face 'org-agenda-done
6039 'mouse-face 'highlight
6040 'help-echo
6041 (format "mouse-2 or RET jump to org file %s"
6042 (abbreviate-file-name buffer-file-name))))
6043 (regexp org-scheduled-time-regexp)
6044 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6045 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6047 (deadline-position-alist
6048 (mapcar (lambda (a) (and (setq mm (get-text-property
6049 0 'org-hd-marker a))
6050 (cons (marker-position mm) a)))
6051 deadline-results))
6052 d2 diff pos pos1 category category-pos level tags donep
6053 ee txt head pastschedp todo-state face timestr s habitp show-all
6054 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6055 ddays)
6056 (goto-char (point-min))
6057 (while (re-search-forward regexp nil t)
6058 (catch :skip
6059 (org-agenda-skip)
6060 (setq s (match-string 1)
6061 txt nil
6062 pos (1- (match-beginning 1))
6063 todo-state (save-match-data (org-get-todo-state))
6064 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6065 (member todo-state
6066 org-agenda-repeating-timestamp-show-all))
6067 d2 (org-time-string-to-absolute
6068 s d1 'past show-all (current-buffer) pos)
6069 diff (- d2 d1)
6070 warntime (get-text-property (point) 'org-appt-warntime))
6071 (setq pastschedp (and todayp (< diff 0)))
6072 (setq did-habit-check-p nil)
6073 (setq suppress-delay
6074 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6075 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6076 (save-match-data
6077 (and (string-match
6078 org-deadline-time-regexp item)
6079 (match-string 1 item)))))))
6080 (cond
6081 ((not ds) nil)
6082 ;; The current item has a deadline date (in ds), so
6083 ;; evaluate its delay time.
6084 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6085 ;; Use global delay time.
6086 (- org-agenda-skip-scheduled-delay-if-deadline))
6087 ((eq org-agenda-skip-scheduled-delay-if-deadline
6088 'post-deadline)
6089 ;; Set delay to no later than deadline.
6090 (min (- d2 (org-time-string-to-absolute
6091 ds d1 'past show-all (current-buffer) pos))
6092 org-scheduled-delay-days))
6093 (t 0))))
6094 (setq ddays (if suppress-delay
6095 (let ((org-scheduled-delay-days suppress-delay))
6096 (org-get-wdays s t t))
6097 (org-get-wdays s t)))
6098 ;; Use a delay of 0 when there is a repeater and the delay is
6099 ;; of the form --3d
6100 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6101 (< (org-time-string-to-absolute s)
6102 (org-time-string-to-absolute
6103 s d2 'past nil (current-buffer) pos)))
6104 (setq ddays 0))
6105 ;; When to show a scheduled item in the calendar:
6106 ;; If it is on or past the date.
6107 (when (or (and (> ddays 0) (= diff (- ddays)))
6108 (and (zerop ddays) (= diff 0))
6109 (and (< (+ diff ddays) 0)
6110 (< (abs diff) org-scheduled-past-days)
6111 (and todayp (not org-agenda-only-exact-dates)))
6112 ;; org-is-habit-p uses org-entry-get, which is expansive
6113 ;; so we go extra mile to only call it once
6114 (and todayp
6115 (boundp 'org-habit-show-all-today)
6116 org-habit-show-all-today
6117 (setq did-habit-check-p t)
6118 (setq habitp (and (functionp 'org-is-habit-p)
6119 (org-is-habit-p)))))
6120 (save-excursion
6121 (setq donep (member todo-state org-done-keywords))
6122 (if (and donep
6123 (or org-agenda-skip-scheduled-if-done
6124 (not (= diff 0))
6125 (and (functionp 'org-is-habit-p)
6126 (org-is-habit-p))))
6127 (setq txt nil)
6128 (setq habitp (if did-habit-check-p habitp
6129 (and (functionp 'org-is-habit-p)
6130 (org-is-habit-p))))
6131 (setq category (org-get-category)
6132 category-pos (get-text-property (point) 'org-category-position))
6133 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6134 (throw :skip nil)
6135 (goto-char (match-end 0))
6136 (setq pos1 (match-beginning 0))
6137 (if habitp
6138 (if (or (not org-habit-show-habits)
6139 (and (not todayp)
6140 (boundp 'org-habit-show-habits-only-for-today)
6141 org-habit-show-habits-only-for-today))
6142 (throw :skip nil))
6143 (if (and
6144 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6145 (and org-agenda-skip-scheduled-if-deadline-is-shown
6146 pastschedp))
6147 (setq mm (assoc pos1 deadline-position-alist)))
6148 (throw :skip nil)))
6149 (setq inherited-tags
6150 (or (eq org-agenda-show-inherited-tags 'always)
6151 (and (listp org-agenda-show-inherited-tags)
6152 (memq 'agenda org-agenda-show-inherited-tags))
6153 (and (eq org-agenda-show-inherited-tags t)
6154 (or (eq org-agenda-use-tag-inheritance t)
6155 (memq 'agenda org-agenda-use-tag-inheritance))))
6157 tags (org-get-tags-at nil (not inherited-tags)))
6158 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6159 (setq head (buffer-substring
6160 (point)
6161 (progn (skip-chars-forward "^\r\n") (point))))
6162 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6163 (setq timestr
6164 (concat (substring s (match-beginning 1)) " "))
6165 (setq timestr 'time))
6166 (setq txt (org-agenda-format-item
6167 (if (= diff 0)
6168 (car org-agenda-scheduled-leaders)
6169 (format (nth 1 org-agenda-scheduled-leaders)
6170 (- 1 diff)))
6171 head level category tags
6172 (if (not (= diff 0)) nil timestr)
6173 nil habitp))))
6174 (when txt
6175 (setq face
6176 (cond
6177 ((and (not habitp) pastschedp)
6178 'org-scheduled-previously)
6179 (todayp 'org-scheduled-today)
6180 (t 'org-scheduled))
6181 habitp (and habitp (org-habit-parse-todo)))
6182 (org-add-props txt props
6183 'undone-face face
6184 'face (if donep 'org-agenda-done face)
6185 'org-marker (org-agenda-new-marker pos)
6186 'org-hd-marker (org-agenda-new-marker pos1)
6187 'type (if pastschedp "past-scheduled" "scheduled")
6188 'date (if pastschedp d2 date)
6189 'ts-date d2
6190 'warntime warntime
6191 'level level
6192 'priority (if habitp
6193 (org-habit-get-priority habitp)
6194 (+ 94 (- 5 diff) (org-get-priority txt)))
6195 'org-category category
6196 'category-position category-pos
6197 'org-habit-p habitp
6198 'todo-state todo-state)
6199 (push txt ee))))))
6200 (nreverse ee)))
6202 (defun org-agenda-get-blocks ()
6203 "Return the date-range information for agenda display."
6204 (let* ((props (list 'face nil
6205 'org-not-done-regexp org-not-done-regexp
6206 'org-todo-regexp org-todo-regexp
6207 'org-complex-heading-regexp org-complex-heading-regexp
6208 'mouse-face 'highlight
6209 'help-echo
6210 (format "mouse-2 or RET jump to org file %s"
6211 (abbreviate-file-name buffer-file-name))))
6212 (regexp org-tr-regexp)
6213 (d0 (calendar-absolute-from-gregorian date))
6214 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6215 level todo-state tags pos head donep inherited-tags)
6216 (goto-char (point-min))
6217 (while (re-search-forward regexp nil t)
6218 (catch :skip
6219 (org-agenda-skip)
6220 (setq pos (point))
6221 (let ((start-time (match-string 1))
6222 (end-time (match-string 2)))
6223 (setq s1 (match-string 1)
6224 s2 (match-string 2)
6225 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6226 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6227 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6228 ;; Only allow days between the limits, because the normal
6229 ;; date stamps will catch the limits.
6230 (save-excursion
6231 (setq todo-state (org-get-todo-state))
6232 (setq donep (member todo-state org-done-keywords))
6233 (if (and donep org-agenda-skip-timestamp-if-done)
6234 (throw :skip t))
6235 (setq marker (org-agenda-new-marker (point)))
6236 (setq category (org-get-category)
6237 category-pos (get-text-property (point) 'org-category-position))
6238 (if (not (re-search-backward org-outline-regexp-bol nil t))
6239 (throw :skip nil)
6240 (goto-char (match-beginning 0))
6241 (setq hdmarker (org-agenda-new-marker (point))
6242 inherited-tags
6243 (or (eq org-agenda-show-inherited-tags 'always)
6244 (and (listp org-agenda-show-inherited-tags)
6245 (memq 'agenda org-agenda-show-inherited-tags))
6246 (and (eq org-agenda-show-inherited-tags t)
6247 (or (eq org-agenda-use-tag-inheritance t)
6248 (memq 'agenda org-agenda-use-tag-inheritance))))
6250 tags (org-get-tags-at nil (not inherited-tags)))
6251 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6252 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6253 (setq head (match-string 1))
6254 (let ((remove-re
6255 (if org-agenda-remove-timeranges-from-blocks
6256 (concat
6257 "<" (regexp-quote s1) ".*?>"
6258 "--"
6259 "<" (regexp-quote s2) ".*?>")
6260 nil)))
6261 (setq txt (org-agenda-format-item
6262 (format
6263 (nth (if (= d1 d2) 0 1)
6264 org-agenda-timerange-leaders)
6265 (1+ (- d0 d1)) (1+ (- d2 d1)))
6266 head level category tags
6267 (cond ((and (= d1 d0) (= d2 d0))
6268 (concat "<" start-time ">--<" end-time ">"))
6269 ((= d1 d0)
6270 (concat "<" start-time ">"))
6271 ((= d2 d0)
6272 (concat "<" end-time ">")))
6273 remove-re))))
6274 (org-add-props txt props
6275 'org-marker marker 'org-hd-marker hdmarker
6276 'type "block" 'date date
6277 'level level
6278 'todo-state todo-state
6279 'priority (org-get-priority txt) 'org-category category
6280 'org-category-position category-pos)
6281 (push txt ee))))
6282 (goto-char pos)))
6283 ;; Sort the entries by expiration date.
6284 (nreverse ee)))
6286 ;;; Agenda presentation and sorting
6288 (defvar org-prefix-has-time nil
6289 "A flag, set by `org-compile-prefix-format'.
6290 The flag is set if the currently compiled format contains a `%t'.")
6291 (defvar org-prefix-has-tag nil
6292 "A flag, set by `org-compile-prefix-format'.
6293 The flag is set if the currently compiled format contains a `%T'.")
6294 (defvar org-prefix-has-effort nil
6295 "A flag, set by `org-compile-prefix-format'.
6296 The flag is set if the currently compiled format contains a `%e'.")
6297 (defvar org-prefix-has-breadcrumbs nil
6298 "A flag, set by `org-compile-prefix-format'.
6299 The flag is set if the currently compiled format contains a `%b'.")
6300 (defvar org-prefix-category-length nil
6301 "Used by `org-compile-prefix-format' to remember the category field width.")
6302 (defvar org-prefix-category-max-length nil
6303 "Used by `org-compile-prefix-format' to remember the category field width.")
6305 (defun org-agenda-get-category-icon (category)
6306 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6307 (dolist (entry org-agenda-category-icon-alist)
6308 (when (org-string-match-p (car entry) category)
6309 (if (listp (cadr entry))
6310 (return (cadr entry))
6311 (return (apply 'create-image (cdr entry)))))))
6313 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6314 remove-re habitp)
6315 "Format TXT to be inserted into the agenda buffer.
6316 In particular, add the prefix and corresponding text properties.
6318 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6319 LEVEL may be a string to replace the `%l' specifier.
6320 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6321 category taken from local variable or file name. It will replace the `%c'
6322 specifier in the format.
6323 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6324 TXT for sorting of this entry, and for the `%t' specifier in the format.
6325 When DOTIME is a string, this string is searched for a time before TXT is.
6326 TAGS can be the tags of the headline.
6327 Any match of REMOVE-RE will be removed from TXT."
6328 ;; We keep the org-prefix-* variable values along with a compiled
6329 ;; formatter, so that multiple agendas existing at the same time do
6330 ;; not step on each other toes.
6332 ;; It was inconvenient to make these variables buffer local in
6333 ;; Agenda buffers, because this function expects to be called with
6334 ;; the buffer where item comes from being current, and not agenda
6335 ;; buffer
6336 (let* ((bindings (car org-prefix-format-compiled))
6337 (formatter (cadr org-prefix-format-compiled)))
6338 (loop for (var value) in bindings
6339 do (set var value))
6340 (save-match-data
6341 ;; Diary entries sometimes have extra whitespace at the beginning
6342 (setq txt (org-trim txt))
6344 ;; Fix the tags part in txt
6345 (setq txt (org-agenda-fix-displayed-tags
6346 txt tags
6347 org-agenda-show-inherited-tags
6348 org-agenda-hide-tags-regexp))
6350 (let* ((category (or category
6351 (if (stringp org-category)
6352 org-category
6353 (and org-category (symbol-name org-category)))
6354 (if buffer-file-name
6355 (file-name-sans-extension
6356 (file-name-nondirectory buffer-file-name))
6357 "")))
6358 (category-icon (org-agenda-get-category-icon category))
6359 (category-icon (if category-icon
6360 (propertize " " 'display category-icon)
6361 ""))
6362 ;; time, tag, effort are needed for the eval of the prefix format
6363 (tag (if tags (nth (1- (length tags)) tags) ""))
6364 time effort neffort
6365 (ts (if dotime (concat
6366 (if (stringp dotime) dotime "")
6367 (and org-agenda-search-headline-for-time txt))))
6368 (time-of-day (and dotime (org-get-time-of-day ts)))
6369 stamp plain s0 s1 s2 rtn srp l
6370 duration thecategory breadcrumbs)
6371 (and (derived-mode-p 'org-mode) buffer-file-name
6372 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6373 (when (and dotime time-of-day)
6374 ;; Extract starting and ending time and move them to prefix
6375 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6376 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6377 (setq s0 (match-string 0 ts)
6378 srp (and stamp (match-end 3))
6379 s1 (match-string (if plain 1 2) ts)
6380 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6382 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6383 ;; them, we might want to remove them there to avoid duplication.
6384 ;; The user can turn this off with a variable.
6385 (if (and org-prefix-has-time
6386 org-agenda-remove-times-when-in-prefix (or stamp plain)
6387 (string-match (concat (regexp-quote s0) " *") txt)
6388 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6389 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6390 (= (match-beginning 0) 0)
6392 (setq txt (replace-match "" nil nil txt))))
6393 ;; Normalize the time(s) to 24 hour
6394 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6395 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6397 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6398 (let (org-time-clocksum-use-effort-durations)
6399 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6400 (setq s2
6401 (org-minutes-to-clocksum-string
6402 (+ (org-hh:mm-string-to-minutes s1)
6403 org-agenda-default-appointment-duration)))))
6405 ;; Compute the duration
6406 (when s2
6407 (setq duration (- (org-hh:mm-string-to-minutes s2)
6408 (org-hh:mm-string-to-minutes s1)))))
6410 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6411 txt)
6412 ;; Tags are in the string
6413 (if (or (eq org-agenda-remove-tags t)
6414 (and org-agenda-remove-tags
6415 org-prefix-has-tag))
6416 (setq txt (replace-match "" t t txt))
6417 (setq txt (replace-match
6418 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6419 (match-string 2 txt))
6420 t t txt))))
6421 (when (derived-mode-p 'org-mode)
6422 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6423 (if effort
6424 (setq neffort (org-duration-string-to-minutes effort)
6425 effort (setq effort (concat "[" effort "]")))
6426 ;; prevent erroring out with %e format when there is no effort
6427 (setq effort "")))
6429 (when remove-re
6430 (while (string-match remove-re txt)
6431 (setq txt (replace-match "" t t txt))))
6433 ;; Set org-heading property on `txt' to mark the start of the
6434 ;; heading.
6435 (add-text-properties 0 (length txt) '(org-heading t) txt)
6437 ;; Prepare the variables needed in the eval of the compiled format
6438 (if org-prefix-has-breadcrumbs
6439 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6440 (let ((s (org-display-outline-path nil nil "->" t)))
6441 (if (eq "" s) "" (concat s "->"))))))
6442 (setq time (cond (s2 (concat
6443 (org-agenda-time-of-day-to-ampm-maybe s1)
6444 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6445 (if org-agenda-timegrid-use-ampm " ")))
6446 (s1 (concat
6447 (org-agenda-time-of-day-to-ampm-maybe s1)
6448 (if org-agenda-timegrid-use-ampm
6449 "........ "
6450 "......")))
6451 (t ""))
6452 extra (or (and (not habitp) extra) "")
6453 category (if (symbolp category) (symbol-name category) category)
6454 thecategory (copy-sequence category)
6455 level (or level ""))
6456 (if (string-match org-bracket-link-regexp category)
6457 (progn
6458 (setq l (if (match-end 3)
6459 (- (match-end 3) (match-beginning 3))
6460 (- (match-end 1) (match-beginning 1))))
6461 (when (< l (or org-prefix-category-length 0))
6462 (setq category (copy-sequence category))
6463 (org-add-props category nil
6464 'extra-space (make-string
6465 (- org-prefix-category-length l 1) ?\ ))))
6466 (if (and org-prefix-category-max-length
6467 (>= (length category) org-prefix-category-max-length))
6468 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6469 ;; Evaluate the compiled format
6470 (setq rtn (concat (eval formatter) txt))
6472 ;; And finally add the text properties
6473 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6474 (org-add-props rtn nil
6475 'org-category (if thecategory (downcase thecategory) category)
6476 'tags (mapcar 'org-downcase-keep-props tags)
6477 'org-highest-priority org-highest-priority
6478 'org-lowest-priority org-lowest-priority
6479 'time-of-day time-of-day
6480 'duration duration
6481 'effort effort
6482 'effort-minutes neffort
6483 'breadcrumbs breadcrumbs
6484 'txt txt
6485 'level level
6486 'time time
6487 'extra extra
6488 'format org-prefix-format-compiled
6489 'dotime dotime)))))
6491 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6492 "Remove tags string from TXT, and add a modified list of tags.
6493 The modified list may contain inherited tags, and tags matched by
6494 `org-agenda-hide-tags-regexp' will be removed."
6495 (when (or add-inherited hide-re)
6496 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6497 (setq txt (substring txt 0 (match-beginning 0))))
6498 (setq tags
6499 (delq nil
6500 (mapcar (lambda (tg)
6501 (if (or (and hide-re (string-match hide-re tg))
6502 (and (not add-inherited)
6503 (get-text-property 0 'inherited tg)))
6505 tg))
6506 tags)))
6507 (when tags
6508 (let ((have-i (get-text-property 0 'inherited (car tags)))
6510 (setq txt (concat txt " :"
6511 (mapconcat
6512 (lambda (x)
6513 (setq i (get-text-property 0 'inherited x))
6514 (if (and have-i (not i))
6515 (progn
6516 (setq have-i nil)
6517 (concat ":" x))
6519 tags ":")
6520 (if have-i "::" ":"))))))
6521 txt)
6523 (defun org-downcase-keep-props (s)
6524 (let ((props (text-properties-at 0 s)))
6525 (setq s (downcase s))
6526 (add-text-properties 0 (length s) props s)
6529 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6531 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6532 "Add a time-grid for agenda items which need it.
6534 LIST is the list of agenda items formatted by `org-agenda-list'.
6535 NDAYS is the span of the current agenda view.
6536 TODAYP is `t' when the current agenda view is on today."
6537 (catch 'exit
6538 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6539 ((and todayp (member 'today (car org-agenda-time-grid))))
6540 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6541 ((member 'weekly (car org-agenda-time-grid)))
6542 (t (throw 'exit list)))
6543 (let* ((have (delq nil (mapcar
6544 (lambda (x) (get-text-property 1 'time-of-day x))
6545 list)))
6546 (string (nth 1 org-agenda-time-grid))
6547 (gridtimes (nth 2 org-agenda-time-grid))
6548 (req (car org-agenda-time-grid))
6549 (remove (member 'remove-match req))
6550 new time)
6551 (if (and (member 'require-timed req) (not have))
6552 ;; don't show empty grid
6553 (throw 'exit list))
6554 (while (setq time (pop gridtimes))
6555 (unless (and remove (member time have))
6556 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6557 (push (org-agenda-format-item
6558 nil string nil "" nil
6559 (concat (substring time 0 -2) ":" (substring time -2)))
6560 new)
6561 (put-text-property
6562 2 (length (car new)) 'face 'org-time-grid (car new))))
6563 (when (and todayp org-agenda-show-current-time-in-grid)
6564 (push (org-agenda-format-item
6565 nil org-agenda-current-time-string nil "" nil
6566 (format-time-string "%H:%M "))
6567 new)
6568 (put-text-property
6569 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6571 (if (member 'time-up org-agenda-sorting-strategy-selected)
6572 (append new list)
6573 (append list new)))))
6575 (defun org-compile-prefix-format (key)
6576 "Compile the prefix format into a Lisp form that can be evaluated.
6577 The resulting form and associated variable bindings is returned
6578 and stored in the variable `org-prefix-format-compiled'."
6579 (setq org-prefix-has-time nil
6580 org-prefix-has-tag nil
6581 org-prefix-category-length nil
6582 org-prefix-has-effort nil
6583 org-prefix-has-breadcrumbs nil)
6584 (let ((s (cond
6585 ((stringp org-agenda-prefix-format)
6586 org-agenda-prefix-format)
6587 ((assq key org-agenda-prefix-format)
6588 (cdr (assq key org-agenda-prefix-format)))
6589 (t " %-12:c%?-12t% s")))
6590 (start 0)
6591 varform vars var e c f opt)
6592 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6593 s start)
6594 (setq var (or (cdr (assoc (match-string 4 s)
6595 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6596 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6597 'eval)
6598 c (or (match-string 3 s) "")
6599 opt (match-beginning 1)
6600 start (1+ (match-beginning 0)))
6601 (if (equal var 'time) (setq org-prefix-has-time t))
6602 (if (equal var 'tag) (setq org-prefix-has-tag t))
6603 (if (equal var 'effort) (setq org-prefix-has-effort t))
6604 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6605 (setq f (concat "%" (match-string 2 s) "s"))
6606 (when (equal var 'category)
6607 (setq org-prefix-category-length
6608 (floor (abs (string-to-number (match-string 2 s)))))
6609 (setq org-prefix-category-max-length
6610 (let ((x (match-string 2 s)))
6611 (save-match-data
6612 (if (string-match "\\.[0-9]+" x)
6613 (string-to-number (substring (match-string 0 x) 1)))))))
6614 (if (eq var 'eval)
6615 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6616 (if opt
6617 (setq varform
6618 `(if (equal "" ,var)
6620 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6621 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6622 (setq s (replace-match "%s" t nil s))
6623 (push varform vars))
6624 (setq vars (nreverse vars))
6625 (with-current-buffer (or org-agenda-buffer (current-buffer))
6626 (setq org-prefix-format-compiled
6627 (list
6628 `((org-prefix-has-time ,org-prefix-has-time)
6629 (org-prefix-has-tag ,org-prefix-has-tag)
6630 (org-prefix-category-length ,org-prefix-category-length)
6631 (org-prefix-has-effort ,org-prefix-has-effort)
6632 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6633 `(format ,s ,@vars))))))
6635 (defun org-set-sorting-strategy (key)
6636 (if (symbolp (car org-agenda-sorting-strategy))
6637 ;; the old format
6638 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6639 (setq org-agenda-sorting-strategy-selected
6640 (or (cdr (assq key org-agenda-sorting-strategy))
6641 (cdr (assq 'agenda org-agenda-sorting-strategy))
6642 '(time-up category-keep priority-down)))))
6644 (defun org-get-time-of-day (s &optional string mod24)
6645 "Check string S for a time of day.
6646 If found, return it as a military time number between 0 and 2400.
6647 If not found, return nil.
6648 The optional STRING argument forces conversion into a 5 character wide string
6649 HH:MM."
6650 (save-match-data
6651 (when
6652 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6653 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6654 (let* ((h (string-to-number (match-string 1 s)))
6655 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6656 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6657 (am-p (equal ampm "am"))
6658 (h1 (cond ((not ampm) h)
6659 ((= h 12) (if am-p 0 12))
6660 (t (+ h (if am-p 0 12)))))
6661 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6662 (mod h1 24) h1))
6663 (t0 (+ (* 100 h2) m))
6664 (t1 (concat (if (>= h1 24) "+" " ")
6665 (if (and org-agenda-time-leading-zero
6666 (< t0 1000)) "0" "")
6667 (if (< t0 100) "0" "")
6668 (if (< t0 10) "0" "")
6669 (int-to-string t0))))
6670 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6672 (defvar org-agenda-before-sorting-filter-function nil
6673 "Function to be applied to agenda items prior to sorting.
6674 Prior to sorting also means just before they are inserted into the agenda.
6676 To aid sorting, you may revisit the original entries and add more text
6677 properties which will later be used by the sorting functions.
6679 The function should take a string argument, an agenda line.
6680 It has access to the text properties in that line, which contain among
6681 other things, the property `org-hd-marker' that points to the entry
6682 where the line comes from. Note that not all lines going into the agenda
6683 have this property, only most.
6685 The function should return the modified string. It is probably best
6686 to ONLY change text properties.
6688 You can also use this function as a filter, by returning nil for lines
6689 you don't want to have in the agenda at all. For this application, you
6690 could bind the variable in the options section of a custom command.")
6692 (defun org-agenda-finalize-entries (list &optional type)
6693 "Sort, limit and concatenate the LIST of agenda items.
6694 The optional argument TYPE tells the agenda type."
6695 (let ((max-effort (cond ((listp org-agenda-max-effort)
6696 (cdr (assoc type org-agenda-max-effort)))
6697 (t org-agenda-max-effort)))
6698 (max-todo (cond ((listp org-agenda-max-todos)
6699 (cdr (assoc type org-agenda-max-todos)))
6700 (t org-agenda-max-todos)))
6701 (max-tags (cond ((listp org-agenda-max-tags)
6702 (cdr (assoc type org-agenda-max-tags)))
6703 (t org-agenda-max-tags)))
6704 (max-entries (cond ((listp org-agenda-max-entries)
6705 (cdr (assoc type org-agenda-max-entries)))
6706 (t org-agenda-max-entries))) l)
6707 (when org-agenda-before-sorting-filter-function
6708 (setq list
6709 (delq nil
6710 (mapcar
6711 org-agenda-before-sorting-filter-function list))))
6712 (setq list (mapcar 'org-agenda-highlight-todo list)
6713 list (mapcar 'identity (sort list 'org-entries-lessp))
6714 list (org-agenda-limit-entries
6715 list 'effort-minutes max-effort 'identity)
6716 list (org-agenda-limit-entries list 'todo-state max-todo)
6717 list (org-agenda-limit-entries list 'tags max-tags)
6718 list (org-agenda-limit-entries list 'org-hd-marker max-entries)
6719 list (mapconcat 'identity list "\n"))))
6721 (defun org-agenda-limit-entries (list prop limit &optional fn)
6722 "Limit the number of agenda entries."
6723 (if limit
6724 (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
6725 (delq nil
6726 (mapcar
6727 (lambda (e)
6728 (let ((pval (funcall f (get-text-property 1 prop e))))
6729 (if pval (setq lim (+ lim pval)))
6730 (if (or (not pval) (<= lim limit)) e)))
6731 list)))
6732 list))
6734 (defun org-agenda-highlight-todo (x)
6735 (let ((org-done-keywords org-done-keywords-for-agenda)
6736 (case-fold-search nil)
6738 (if (eq x 'line)
6739 (save-excursion
6740 (beginning-of-line 1)
6741 (setq re (org-get-at-bol 'org-todo-regexp))
6742 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6743 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6744 (add-text-properties (match-beginning 0) (match-end 1)
6745 (list 'face (org-get-todo-face 1)))
6746 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6747 (delete-region (match-beginning 1) (1- (match-end 0)))
6748 (goto-char (match-beginning 1))
6749 (insert (format org-agenda-todo-keyword-format s)))))
6750 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6751 (setq re (get-text-property 0 'org-todo-regexp x))
6752 (when (and re
6753 ;; Test `pl' because if there's no heading content,
6754 ;; there's no point matching to highlight. Note
6755 ;; that if we didn't test `pl' first, and there
6756 ;; happened to be no keyword from `org-todo-regexp'
6757 ;; on this heading line, then the `equal' comparison
6758 ;; afterwards would spuriously succeed in the case
6759 ;; where `pl' is nil -- causing an args-out-of-range
6760 ;; error when we try to add text properties to text
6761 ;; that isn't there.
6763 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6764 x pl) pl))
6765 (add-text-properties
6766 (or (match-end 1) (match-end 0)) (match-end 0)
6767 (list 'face (org-get-todo-face (match-string 2 x)))
6769 (when (match-end 1)
6770 (setq x (concat (substring x 0 (match-end 1))
6771 (format org-agenda-todo-keyword-format
6772 (match-string 2 x))
6773 (org-add-props " " (text-properties-at 0 x))
6774 (substring x (match-end 3)))))))
6775 x)))
6777 (defsubst org-cmp-priority (a b)
6778 "Compare the priorities of string A and B."
6779 (let ((pa (or (get-text-property 1 'priority a) 0))
6780 (pb (or (get-text-property 1 'priority b) 0)))
6781 (cond ((> pa pb) +1)
6782 ((< pa pb) -1))))
6784 (defsubst org-cmp-effort (a b)
6785 "Compare the effort values of string A and B."
6786 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6787 (ea (or (get-text-property 1 'effort-minutes a) def))
6788 (eb (or (get-text-property 1 'effort-minutes b) def)))
6789 (cond ((> ea eb) +1)
6790 ((< ea eb) -1))))
6792 (defsubst org-cmp-category (a b)
6793 "Compare the string values of categories of strings A and B."
6794 (let ((ca (or (get-text-property 1 'org-category a) ""))
6795 (cb (or (get-text-property 1 'org-category b) "")))
6796 (cond ((string-lessp ca cb) -1)
6797 ((string-lessp cb ca) +1))))
6799 (defsubst org-cmp-todo-state (a b)
6800 "Compare the todo states of strings A and B."
6801 (let* ((ma (or (get-text-property 1 'org-marker a)
6802 (get-text-property 1 'org-hd-marker a)))
6803 (mb (or (get-text-property 1 'org-marker b)
6804 (get-text-property 1 'org-hd-marker b)))
6805 (fa (and ma (marker-buffer ma)))
6806 (fb (and mb (marker-buffer mb)))
6807 (todo-kwds
6808 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6809 (and fb (with-current-buffer fb org-todo-keywords-1))))
6810 (ta (or (get-text-property 1 'todo-state a) ""))
6811 (tb (or (get-text-property 1 'todo-state b) ""))
6812 (la (- (length (member ta todo-kwds))))
6813 (lb (- (length (member tb todo-kwds))))
6814 (donepa (member ta org-done-keywords-for-agenda))
6815 (donepb (member tb org-done-keywords-for-agenda)))
6816 (cond ((and donepa (not donepb)) -1)
6817 ((and (not donepa) donepb) +1)
6818 ((< la lb) -1)
6819 ((< lb la) +1))))
6821 (defsubst org-cmp-alpha (a b)
6822 "Compare the headlines, alphabetically."
6823 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6824 (plb (text-property-any 0 (length b) 'org-heading t b))
6825 (ta (and pla (substring a pla)))
6826 (tb (and plb (substring b plb))))
6827 (when pla
6828 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6829 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6830 (setq ta (substring ta (match-end 0))))
6831 (setq ta (downcase ta)))
6832 (when plb
6833 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6834 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6835 (setq tb (substring tb (match-end 0))))
6836 (setq tb (downcase tb)))
6837 (cond ((not ta) +1)
6838 ((not tb) -1)
6839 ((string-lessp ta tb) -1)
6840 ((string-lessp tb ta) +1))))
6842 (defsubst org-cmp-tag (a b)
6843 "Compare the string values of the first tags of A and B."
6844 (let ((ta (car (last (get-text-property 1 'tags a))))
6845 (tb (car (last (get-text-property 1 'tags b)))))
6846 (cond ((not ta) +1)
6847 ((not tb) -1)
6848 ((string-lessp ta tb) -1)
6849 ((string-lessp tb ta) +1))))
6851 (defsubst org-cmp-time (a b)
6852 "Compare the time-of-day values of strings A and B."
6853 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6854 (ta (or (get-text-property 1 'time-of-day a) def))
6855 (tb (or (get-text-property 1 'time-of-day b) def)))
6856 (cond ((< ta tb) -1)
6857 ((< tb ta) +1))))
6859 (defsubst org-cmp-ts (a b &optional type)
6860 "Compare the timestamps values of entries A and B.
6861 When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
6862 or \"timestamp_ia\", compare within each of these type.
6863 When TYPE is the empty string, compare all timestamps
6864 without respect of their type."
6865 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6866 (ta (or (and (string-match type (get-text-property 1 'type a))
6867 (get-text-property 1 'ts-date a)) def))
6868 (tb (or (and (string-match type (get-text-property 1 'type b))
6869 (get-text-property 1 'ts-date b)) def)))
6870 (cond ((< ta tb) -1)
6871 ((< tb ta) +1))))
6873 (defsubst org-cmp-habit-p (a b)
6874 "Compare the todo states of strings A and B."
6875 (let ((ha (get-text-property 1 'org-habit-p a))
6876 (hb (get-text-property 1 'org-habit-p b)))
6877 (cond ((and ha (not hb)) -1)
6878 ((and (not ha) hb) +1))))
6880 (defun org-entries-lessp (a b)
6881 "Predicate for sorting agenda entries."
6882 ;; The following variables will be used when the form is evaluated.
6883 ;; So even though the compiler complains, keep them.
6884 (let* ((ss org-agenda-sorting-strategy-selected)
6885 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
6886 (org-cmp-ts a b "")))
6887 (timestamp-down (if timestamp-up (- timestamp-up) nil))
6888 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
6889 (org-cmp-ts a b "scheduled")))
6890 (scheduled-down (if scheduled-up (- scheduled-up) nil))
6891 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
6892 (org-cmp-ts a b "deadline")))
6893 (deadline-down (if deadline-up (- deadline-up) nil))
6894 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
6895 (org-cmp-ts a b "iatimestamp_ia")))
6896 (tsia-down (if tsia-up (- tsia-up) nil))
6897 (ts-up (and (org-em 'ts-up 'ts-down ss)
6898 (org-cmp-ts a b "timestamp")))
6899 (ts-down (if ts-up (- ts-up) nil))
6900 (time-up (and (org-em 'time-up 'time-down ss)
6901 (org-cmp-time a b)))
6902 (time-down (if time-up (- time-up) nil))
6903 (priority-up (and (org-em 'priority-up 'priority-down ss)
6904 (org-cmp-priority a b)))
6905 (priority-down (if priority-up (- priority-up) nil))
6906 (effort-up (and (org-em 'effort-up 'effort-down ss)
6907 (org-cmp-effort a b)))
6908 (effort-down (if effort-up (- effort-up) nil))
6909 (category-up (and (or (org-em 'category-up 'category-down ss)
6910 (memq 'category-keep ss))
6911 (org-cmp-category a b)))
6912 (category-down (if category-up (- category-up) nil))
6913 (category-keep (if category-up +1 nil))
6914 (tag-up (and (org-em 'tag-up 'tag-down ss)
6915 (org-cmp-tag a b)))
6916 (tag-down (if tag-up (- tag-up) nil))
6917 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6918 (org-cmp-todo-state a b)))
6919 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6920 (habit-up (and (org-em 'habit-up 'habit-down ss)
6921 (org-cmp-habit-p a b)))
6922 (habit-down (if habit-up (- habit-up) nil))
6923 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6924 (org-cmp-alpha a b)))
6925 (alpha-down (if alpha-up (- alpha-up) nil))
6926 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6927 user-defined-up user-defined-down)
6928 (if (and need-user-cmp org-agenda-cmp-user-defined
6929 (functionp org-agenda-cmp-user-defined))
6930 (setq user-defined-up
6931 (funcall org-agenda-cmp-user-defined a b)
6932 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6933 (cdr (assoc
6934 (eval (cons 'or org-agenda-sorting-strategy-selected))
6935 '((-1 . t) (1 . nil) (nil . nil))))))
6937 ;;; Agenda restriction lock
6939 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6940 "Overlay to mark the headline to which agenda commands are restricted.")
6941 (overlay-put org-agenda-restriction-lock-overlay
6942 'face 'org-agenda-restriction-lock)
6943 (overlay-put org-agenda-restriction-lock-overlay
6944 'help-echo "Agendas are currently limited to this subtree.")
6945 (org-detach-overlay org-agenda-restriction-lock-overlay)
6947 (defun org-agenda-set-restriction-lock (&optional type)
6948 "Set restriction lock for agenda, to current subtree or file.
6949 Restriction will be the file if TYPE is `file', or if type is the
6950 universal prefix '(4), or if the cursor is before the first headline
6951 in the file. Otherwise, restriction will be to the current subtree."
6952 (interactive "P")
6953 (and (equal type '(4)) (setq type 'file))
6954 (setq type (cond
6955 (type type)
6956 ((org-at-heading-p) 'subtree)
6957 ((condition-case nil (org-back-to-heading t) (error nil))
6958 'subtree)
6959 (t 'file)))
6960 (if (eq type 'subtree)
6961 (progn
6962 (setq org-agenda-restrict t)
6963 (setq org-agenda-overriding-restriction 'subtree)
6964 (put 'org-agenda-files 'org-restrict
6965 (list (buffer-file-name (buffer-base-buffer))))
6966 (org-back-to-heading t)
6967 (move-overlay org-agenda-restriction-lock-overlay
6968 (point) (save-excursion (org-end-of-subtree t t) (point)))
6969 (move-marker org-agenda-restrict-begin (point))
6970 (move-marker org-agenda-restrict-end
6971 (save-excursion (org-end-of-subtree t t)))
6972 (message "Locking agenda restriction to subtree"))
6973 (put 'org-agenda-files 'org-restrict
6974 (list (buffer-file-name (buffer-base-buffer))))
6975 (setq org-agenda-restrict nil)
6976 (setq org-agenda-overriding-restriction 'file)
6977 (move-marker org-agenda-restrict-begin nil)
6978 (move-marker org-agenda-restrict-end nil)
6979 (message "Locking agenda restriction to file"))
6980 (setq current-prefix-arg nil)
6981 (org-agenda-maybe-redo))
6983 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6984 "Remove the agenda restriction lock."
6985 (interactive "P")
6986 (org-detach-overlay org-agenda-restriction-lock-overlay)
6987 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6988 (setq org-agenda-overriding-restriction nil)
6989 (setq org-agenda-restrict nil)
6990 (put 'org-agenda-files 'org-restrict nil)
6991 (move-marker org-agenda-restrict-begin nil)
6992 (move-marker org-agenda-restrict-end nil)
6993 (setq current-prefix-arg nil)
6994 (message "Agenda restriction lock removed")
6995 (or noupdate (org-agenda-maybe-redo)))
6997 (defun org-agenda-maybe-redo ()
6998 "If there is any window showing the agenda view, update it."
6999 (let ((w (get-buffer-window org-agenda-buffer-name t))
7000 (w0 (selected-window)))
7001 (when w
7002 (select-window w)
7003 (org-agenda-redo)
7004 (select-window w0)
7005 (if org-agenda-overriding-restriction
7006 (message "Agenda view shifted to new %s restriction"
7007 org-agenda-overriding-restriction)
7008 (message "Agenda restriction lock removed")))))
7010 ;;; Agenda commands
7012 (defun org-agenda-check-type (error &rest types)
7013 "Check if agenda buffer is of allowed type.
7014 If ERROR is non-nil, throw an error, otherwise just return nil.
7015 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
7016 (if (not org-agenda-type)
7017 (error "No Org agenda currently displayed")
7018 (if (memq org-agenda-type types)
7020 (if error
7021 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7022 nil))))
7024 (defun org-agenda-Quit ()
7025 "Exit the agenda and kill buffers loaded by `org-agenda'.
7026 Also restore the window configuration."
7027 (interactive)
7028 (if org-agenda-columns-active
7029 (org-columns-quit)
7030 (let ((buf (current-buffer)))
7031 (if (eq org-agenda-window-setup 'other-frame)
7032 (progn
7033 (org-agenda-reset-markers)
7034 (kill-buffer buf)
7035 (org-columns-remove-overlays)
7036 (setq org-agenda-archives-mode nil)
7037 (delete-frame))
7038 (and (not (eq org-agenda-window-setup 'current-window))
7039 (not (one-window-p))
7040 (delete-window))
7041 (org-agenda-reset-markers)
7042 (kill-buffer buf)
7043 (org-columns-remove-overlays)
7044 (setq org-agenda-archives-mode nil)))
7045 ;; Maybe restore the pre-agenda window configuration.
7046 (and org-agenda-restore-windows-after-quit
7047 (not (eq org-agenda-window-setup 'other-frame))
7048 org-agenda-pre-window-conf
7049 (set-window-configuration org-agenda-pre-window-conf)
7050 (setq org-agenda-pre-window-conf nil))))
7052 (defun org-agenda-quit ()
7053 "Exit the agenda and restore the window configuration.
7054 When `org-agenda-sticky' is non-nil, only bury the agenda."
7055 (interactive)
7056 (if (and (eq org-indirect-buffer-display 'other-window)
7057 org-last-indirect-buffer)
7058 (let ((org-last-indirect-window
7059 (get-buffer-window org-last-indirect-buffer)))
7060 (if org-last-indirect-window
7061 (delete-window org-last-indirect-window))))
7062 (if org-agenda-columns-active
7063 (org-columns-quit)
7064 (if org-agenda-sticky
7065 (let ((buf (current-buffer)))
7066 (if (eq org-agenda-window-setup 'other-frame)
7067 (progn
7068 (delete-frame))
7069 (and (not (eq org-agenda-window-setup 'current-window))
7070 (not (one-window-p))
7071 (delete-window)))
7072 (with-current-buffer buf
7073 (bury-buffer)
7074 ;; Maybe restore the pre-agenda window configuration.
7075 (and org-agenda-restore-windows-after-quit
7076 (not (eq org-agenda-window-setup 'other-frame))
7077 org-agenda-pre-window-conf
7078 (set-window-configuration org-agenda-pre-window-conf)
7079 (setq org-agenda-pre-window-conf nil))))
7080 (org-agenda-Quit))))
7082 (defun org-agenda-exit ()
7083 "Exit the agenda and restore the window configuration.
7084 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7085 buffers visited directly by the user will not be touched."
7086 (interactive)
7087 (org-release-buffers org-agenda-new-buffers)
7088 (setq org-agenda-new-buffers nil)
7089 (org-agenda-Quit))
7091 (defun org-agenda-kill-all-agenda-buffers ()
7092 "Kill all buffers in `org-agenda-mode'.
7093 This is used when toggling sticky agendas.
7094 You can also explicitly invoke it with `C-c a C-k'."
7095 (interactive)
7096 (let (blist)
7097 (dolist (buf (buffer-list))
7098 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7099 (push buf blist)))
7100 (mapc 'kill-buffer blist)))
7102 (defun org-agenda-execute (arg)
7103 "Execute another agenda command, keeping same window.
7104 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7105 in the agenda."
7106 (interactive "P")
7107 (let ((org-agenda-window-setup 'current-window))
7108 (org-agenda arg)))
7110 (defun org-agenda-redo (&optional all)
7111 "Rebuild possibly ALL agenda view(s) in the current buffer."
7112 (interactive "P")
7113 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7114 (cpa (unless (eq all t) current-prefix-arg))
7115 (org-agenda-doing-sticky-redo org-agenda-sticky)
7116 (org-agenda-sticky nil)
7117 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7118 org-agenda-buffer-name))
7119 (org-agenda-keep-modes t)
7120 (tag-filter org-agenda-tag-filter)
7121 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7122 (top-cat-filter org-agenda-top-category-filter)
7123 (cat-filter org-agenda-category-filter)
7124 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7125 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7126 (cols org-agenda-columns-active)
7127 (line (org-current-line))
7128 (window-line (- line (org-current-line (window-start))))
7129 (lprops (get 'org-agenda-redo-command 'org-lprops))
7130 (redo-cmd (get-text-property p 'org-redo-cmd))
7131 (last-args (get-text-property p 'org-last-args))
7132 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7133 (org-agenda-overriding-cmd-arguments
7134 (unless (eq all t)
7135 (cond ((listp last-args)
7136 (cons (or cpa (car last-args)) (cdr last-args)))
7137 ((stringp last-args)
7138 last-args))))
7139 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7140 (put 'org-agenda-tag-filter :preset-filter nil)
7141 (put 'org-agenda-category-filter :preset-filter nil)
7142 (and cols (org-columns-quit))
7143 (message "Rebuilding agenda buffer...")
7144 (if series-redo-cmd
7145 (eval series-redo-cmd)
7146 (org-let lprops '(eval redo-cmd)))
7147 (setq org-agenda-undo-list nil
7148 org-agenda-pending-undo-list nil)
7149 (message "Rebuilding agenda buffer...done")
7150 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7151 (put 'org-agenda-category-filter :preset-filter cat-preset)
7152 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7153 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7154 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7155 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7156 (org-goto-line line)
7157 (recenter window-line)))
7159 (defvar org-global-tags-completion-table nil)
7160 (defvar org-agenda-filter-form nil)
7161 (defvar org-agenda-filtered-by-category nil)
7163 (defun org-agenda-filter-by-category (strip)
7164 "Keep only those lines in the agenda buffer that have a specific category.
7165 The category is that of the current line."
7166 (interactive "P")
7167 (if (and org-agenda-filtered-by-category
7168 org-agenda-category-filter)
7169 (org-agenda-filter-show-all-cat)
7170 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7171 (if cat (org-agenda-filter-apply
7172 (list (concat (if strip "-" "+") cat)) 'category)
7173 (error "No category at point")))))
7175 (defun org-find-top-category (&optional pos)
7176 (save-excursion
7177 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7178 (if pos (goto-char pos))
7179 ;; Skip up to the topmost parent
7180 (while (ignore-errors (outline-up-heading 1) t))
7181 (ignore-errors
7182 (nth 4 (org-heading-components))))))
7184 (defvar org-agenda-filtered-by-top-category nil)
7186 (defun org-agenda-filter-by-top-category (strip)
7187 "Keep only those lines in the agenda buffer that have a specific category.
7188 The category is that of the current line."
7189 (interactive "P")
7190 (if org-agenda-filtered-by-top-category
7191 (progn
7192 (setq org-agenda-filtered-by-top-category nil
7193 org-agenda-top-category-filter nil)
7194 (org-agenda-filter-show-all-cat))
7195 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7196 (if cat (org-agenda-filter-top-category-apply cat strip)
7197 (error "No top-level category at point")))))
7199 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7200 "Keep only those lines in the agenda buffer that have a specific tag.
7201 The tag is selected with its fast selection letter, as configured.
7202 With prefix argument STRIP, remove all lines that do have the tag.
7203 A lisp caller can specify CHAR. NARROW means that the new tag should be
7204 used to narrow the search - the interactive user can also press `-' or `+'
7205 to switch to narrowing."
7206 (interactive "P")
7207 (let* ((alist org-tag-alist-for-agenda)
7208 (tag-chars (mapconcat
7209 (lambda (x) (if (and (not (symbolp (car x)))
7210 (cdr x))
7211 (char-to-string (cdr x))
7212 ""))
7213 alist ""))
7214 (efforts (org-split-string
7215 (or (cdr (assoc (concat org-effort-property "_ALL")
7216 org-global-properties))
7217 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7218 "")))
7219 (effort-op org-agenda-filter-effort-default-operator)
7220 (effort-prompt "")
7221 (inhibit-read-only t)
7222 (current org-agenda-tag-filter)
7223 maybe-refresh a n tag)
7224 (unless char
7225 (message
7226 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7227 (if narrow "Narrow" "Filter") tag-chars
7228 (if org-agenda-auto-exclude-function "[RET], " ""))
7229 (setq char (read-char-exclusive)))
7230 (when (member char '(?+ ?-))
7231 ;; Narrowing down
7232 (cond ((equal char ?-) (setq strip t narrow t))
7233 ((equal char ?+) (setq strip nil narrow t)))
7234 (message
7235 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7236 (setq char (read-char-exclusive)))
7237 (when (member char '(?< ?> ?= ??))
7238 ;; An effort operator
7239 (setq effort-op (char-to-string char))
7240 (setq alist nil) ; to make sure it will be interpreted as effort.
7241 (unless (equal char ??)
7242 (loop for i from 0 to 9 do
7243 (setq effort-prompt
7244 (concat
7245 effort-prompt " ["
7246 (if (= i 9) "0" (int-to-string (1+ i)))
7247 "]" (nth i efforts))))
7248 (message "Effort%s: %s " effort-op effort-prompt)
7249 (setq char (read-char-exclusive))
7250 (when (or (< char ?0) (> char ?9))
7251 (error "Need 1-9,0 to select effort"))))
7252 (when (equal char ?\t)
7253 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7254 (org-set-local 'org-global-tags-completion-table
7255 (org-global-tags-completion-table)))
7256 (let ((completion-ignore-case t))
7257 (setq tag (org-icompleting-read
7258 "Tag: " org-global-tags-completion-table))))
7259 (cond
7260 ((equal char ?\r)
7261 (org-agenda-filter-show-all-tag)
7262 (when org-agenda-auto-exclude-function
7263 (setq org-agenda-tag-filter '())
7264 (dolist (tag (org-agenda-get-represented-tags))
7265 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7266 (if modifier
7267 (push modifier org-agenda-tag-filter))))
7268 (if (not (null org-agenda-tag-filter))
7269 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7270 (setq maybe-refresh t))
7271 ((equal char ?/)
7272 (org-agenda-filter-show-all-tag)
7273 (when (get 'org-agenda-tag-filter :preset-filter)
7274 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7275 (setq maybe-refresh t))
7276 ((equal char ?. )
7277 (setq org-agenda-tag-filter
7278 (mapcar (lambda(tag) (concat "+" tag))
7279 (org-get-at-bol 'tags)))
7280 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7281 (setq maybe-refresh t))
7282 ((or (equal char ?\ )
7283 (setq a (rassoc char alist))
7284 (and (>= char ?0) (<= char ?9)
7285 (setq n (if (= char ?0) 9 (- char ?0 1))
7286 tag (concat effort-op (nth n efforts))
7287 a (cons tag nil)))
7288 (and (= char ??)
7289 (setq tag "?eff")
7290 a (cons tag nil))
7291 (and tag (setq a (cons tag nil))))
7292 (org-agenda-filter-show-all-tag)
7293 (setq tag (car a))
7294 (setq org-agenda-tag-filter
7295 (cons (concat (if strip "-" "+") tag)
7296 (if narrow current nil)))
7297 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7298 (setq maybe-refresh t))
7299 (t (error "Invalid tag selection character %c" char)))
7300 (when (and maybe-refresh
7301 (eq org-agenda-clockreport-mode 'with-filter))
7302 (org-agenda-redo))))
7304 (defun org-agenda-get-represented-tags ()
7305 "Get a list of all tags currently represented in the agenda."
7306 (let (p tags)
7307 (save-excursion
7308 (goto-char (point-min))
7309 (while (setq p (next-single-property-change (point) 'tags))
7310 (goto-char p)
7311 (mapc (lambda (x) (add-to-list 'tags x))
7312 (get-text-property (point) 'tags))))
7313 tags))
7315 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7316 "Refine the current filter. See `org-agenda-filter-by-tag'."
7317 (interactive "P")
7318 (org-agenda-filter-by-tag strip char 'refine))
7320 (defun org-agenda-filter-make-matcher ()
7321 "Create the form that tests a line for agenda filter."
7322 (let (f f1)
7323 ;; first compute the tag-filter matcher
7324 (dolist (x (delete-dups
7325 (append (get 'org-agenda-tag-filter
7326 :preset-filter) org-agenda-tag-filter)))
7327 (if (member x '("-" "+"))
7328 (setq f1 (if (equal x "-") 'tags '(not tags)))
7329 (if (string-match "[<=>?]" x)
7330 (setq f1 (org-agenda-filter-effort-form x))
7331 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7332 (if (equal (string-to-char x) ?-)
7333 (setq f1 (list 'not f1))))
7334 (push f1 f))
7335 ;; then compute the category-filter matcher
7336 (dolist (x (delete-dups
7337 (append (get 'org-agenda-category-filter
7338 :preset-filter) org-agenda-category-filter)))
7339 (if (equal "-" (substring x 0 1))
7340 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7341 (setq f1 (list 'equal (substring x 1) 'cat)))
7342 (push f1 f))
7343 (cons 'and (nreverse f))))
7345 (defun org-agenda-filter-effort-form (e)
7346 "Return the form to compare the effort of the current line with what E says.
7347 E looks like \"+<2:25\"."
7348 (let (op)
7349 (setq e (substring e 1))
7350 (setq op (string-to-char e) e (substring e 1))
7351 (setq op (cond ((equal op ?<) '<=)
7352 ((equal op ?>) '>=)
7353 ((equal op ??) op)
7354 (t '=)))
7355 (list 'org-agenda-compare-effort (list 'quote op)
7356 (org-duration-string-to-minutes e))))
7358 (defun org-agenda-compare-effort (op value)
7359 "Compare the effort of the current line with VALUE, using OP.
7360 If the line does not have an effort defined, return nil."
7361 (let ((eff (org-get-at-bol 'effort-minutes)))
7362 (if (equal op ??)
7363 (not eff)
7364 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7365 value))))
7367 (defun org-agenda-filter-apply (filter type)
7368 "Set FILTER as the new agenda filter and apply it."
7369 (let (tags cat)
7370 (if (eq type 'tag)
7371 (setq org-agenda-tag-filter filter)
7372 (setq org-agenda-category-filter filter))
7373 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7374 (if (and (eq type 'category)
7375 (not (equal (substring (car filter) 0 1) "-")))
7376 ;; Only set `org-agenda-filtered-by-category' to t
7377 ;; when a unique category is used as the filter
7378 (setq org-agenda-filtered-by-category t))
7379 (org-agenda-set-mode-name)
7380 (save-excursion
7381 (goto-char (point-min))
7382 (while (not (eobp))
7383 (if (org-get-at-bol 'org-marker)
7384 (progn
7385 (setq tags (org-get-at-bol 'tags) ; used in eval
7386 cat (get-text-property (point) 'org-category))
7387 (if (not (eval org-agenda-filter-form))
7388 (org-agenda-filter-hide-line type))
7389 (beginning-of-line 2))
7390 (beginning-of-line 2))))
7391 (if (get-char-property (point) 'invisible)
7392 (ignore-errors (org-agenda-previous-line)))))
7394 (defun org-agenda-filter-top-category-apply (category &optional negative)
7395 "Set FILTER as the new agenda filter and apply it."
7396 (org-agenda-set-mode-name)
7397 (save-excursion
7398 (goto-char (point-min))
7399 (while (not (eobp))
7400 (let* ((pos (org-get-at-bol 'org-hd-marker))
7401 (topcat (and pos (org-find-top-category pos))))
7402 (if (and topcat (funcall (if negative 'identity 'not)
7403 (string= category topcat)))
7404 (org-agenda-filter-hide-line 'category)))
7405 (beginning-of-line 2)))
7406 (if (get-char-property (point) 'invisible)
7407 (org-agenda-previous-line))
7408 (setq org-agenda-top-category-filter category
7409 org-agenda-filtered-by-top-category t))
7411 (defun org-agenda-filter-hide-line (type)
7412 (let (ov)
7413 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7414 (point-at-eol)))
7415 (overlay-put ov 'invisible t)
7416 (overlay-put ov 'type type)
7417 (if (eq type 'tag)
7418 (push ov org-agenda-tag-filter-overlays)
7419 (push ov org-agenda-cat-filter-overlays))))
7421 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7422 (setq pos (or pos (point)))
7423 (save-excursion
7424 (dolist (ov (overlays-at pos))
7425 (when (and (overlay-get ov 'invisible)
7426 (eq (overlay-get ov 'type) 'tag))
7427 (goto-char pos)
7428 (if (< (overlay-start ov) (point-at-eol))
7429 (move-overlay ov (point-at-eol)
7430 (overlay-end ov)))))))
7432 (defun org-agenda-filter-show-all-tag nil
7433 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7434 (setq org-agenda-tag-filter-overlays nil
7435 org-agenda-tag-filter nil
7436 org-agenda-filter-form nil)
7437 (org-agenda-set-mode-name))
7439 (defun org-agenda-filter-show-all-cat nil
7440 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7441 (setq org-agenda-cat-filter-overlays nil
7442 org-agenda-filtered-by-category nil
7443 org-agenda-category-filter nil
7444 org-agenda-filter-form nil)
7445 (org-agenda-set-mode-name))
7447 (defun org-agenda-manipulate-query-add ()
7448 "Manipulate the query by adding a search term with positive selection.
7449 Positive selection means the term must be matched for selection of an entry."
7450 (interactive)
7451 (org-agenda-manipulate-query ?\[))
7452 (defun org-agenda-manipulate-query-subtract ()
7453 "Manipulate the query by adding a search term with negative selection.
7454 Negative selection means term must not be matched for selection of an entry."
7455 (interactive)
7456 (org-agenda-manipulate-query ?\]))
7457 (defun org-agenda-manipulate-query-add-re ()
7458 "Manipulate the query by adding a search regexp with positive selection.
7459 Positive selection means the regexp must match for selection of an entry."
7460 (interactive)
7461 (org-agenda-manipulate-query ?\{))
7462 (defun org-agenda-manipulate-query-subtract-re ()
7463 "Manipulate the query by adding a search regexp with negative selection.
7464 Negative selection means regexp must not match for selection of an entry."
7465 (interactive)
7466 (org-agenda-manipulate-query ?\}))
7467 (defun org-agenda-manipulate-query (char)
7468 (cond
7469 ((memq org-agenda-type '(timeline agenda))
7470 (let ((org-agenda-include-inactive-timestamps t))
7471 (org-agenda-redo))
7472 (message "Display now includes inactive timestamps as well"))
7473 ((eq org-agenda-type 'search)
7474 (org-add-to-string
7475 'org-agenda-query-string
7476 (if org-agenda-last-search-view-search-was-boolean
7477 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7478 (?\{ . " +{}") (?\} . " -{}"))))
7479 " "))
7480 (setq org-agenda-redo-command
7481 (list 'org-search-view
7482 (car (get-text-property (min (1- (point-max)) (point))
7483 'org-last-args))
7484 org-agenda-query-string
7485 (+ (length org-agenda-query-string)
7486 (if (member char '(?\{ ?\})) 0 1))))
7487 (set-register org-agenda-query-register org-agenda-query-string)
7488 (let ((org-agenda-overriding-arguments
7489 (cdr org-agenda-redo-command)))
7490 (org-agenda-redo)))
7491 (t (error "Cannot manipulate query for %s-type agenda buffers"
7492 org-agenda-type))))
7494 (defun org-add-to-string (var string)
7495 (set var (concat (symbol-value var) string)))
7497 (defun org-agenda-goto-date (span)
7498 "Jump to DATE in agenda."
7499 (interactive "P")
7500 (let* ((org-read-date-prefer-future
7501 (eval org-agenda-jump-prefer-future))
7502 (date (org-read-date))
7503 (org-agenda-sticky-orig org-agenda-sticky)
7504 (org-agenda-buffer-tmp-name (buffer-name))
7505 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7506 (0-arg (or current-prefix-arg (car args)))
7507 (2-arg (nth 2 args))
7508 (newcmd (list 'org-agenda-list 0-arg date
7509 (org-agenda-span-to-ndays 2-arg)))
7510 (newargs (cdr newcmd))
7511 (inhibit-read-only t)
7512 org-agenda-sticky)
7513 (if (not (org-agenda-check-type t 'agenda))
7514 (error "Not available in non-agenda blocks")
7515 (add-text-properties (point-min) (point-max)
7516 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7517 (org-agenda-redo)
7518 (setq org-agenda-sticky org-agenda-sticky-orig
7519 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7521 (defun org-agenda-goto-today ()
7522 "Go to today."
7523 (interactive)
7524 (org-agenda-check-type t 'timeline 'agenda)
7525 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7526 (curspan (nth 2 args))
7527 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7528 (cond
7529 (tdpos (goto-char tdpos))
7530 ((eq org-agenda-type 'agenda)
7531 (let* ((sd (org-agenda-compute-starting-span
7532 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7533 (org-agenda-overriding-arguments args))
7534 (setf (nth 1 org-agenda-overriding-arguments) sd)
7535 (org-agenda-redo)
7536 (org-agenda-find-same-or-today-or-agenda)))
7537 (t (error "Cannot find today")))))
7539 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7540 (goto-char
7541 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7542 (text-property-any (point-min) (point-max) 'org-today t)
7543 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7544 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7545 (org-agenda-goto-block-beginning))
7546 (point-min))))
7548 (defun org-agenda-goto-block-beginning ()
7549 "Go the agenda block beginning."
7550 (interactive)
7551 (if (not (derived-mode-p 'org-agenda-mode))
7552 (error "Cannot execute this command outside of org-agenda-mode buffers")
7553 (let (dest)
7554 (save-excursion
7555 (unless (looking-at "\\'")
7556 (forward-char))
7557 (let* ((prop 'org-agenda-structural-header)
7558 (p (previous-single-property-change (point) prop))
7559 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7560 (1- (point))) prop)))
7561 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7562 (if (not dest)
7563 (error "Cannot find the beginning of the blog")
7564 (goto-char dest)
7565 (move-beginning-of-line 1)))))
7567 (defun org-agenda-later (arg)
7568 "Go forward in time by the current span.
7569 With prefix ARG, go forward that many times the current span."
7570 (interactive "p")
7571 (org-agenda-check-type t 'agenda)
7572 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7573 (span (or (nth 2 args) org-agenda-current-span))
7574 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7575 (greg (calendar-gregorian-from-absolute sd))
7576 (cnt (org-get-at-bol 'org-day-cnt))
7577 greg2)
7578 (cond
7579 ((numberp span)
7580 (setq sd (+ (* span arg) sd)))
7581 ((eq span 'day)
7582 (setq sd (+ arg sd)))
7583 ((eq span 'week)
7584 (setq sd (+ (* 7 arg) sd)))
7585 ((eq span 'month)
7586 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7587 sd (calendar-absolute-from-gregorian greg2))
7588 (setcar greg2 (1+ (car greg2))))
7589 ((eq span 'year)
7590 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7591 sd (calendar-absolute-from-gregorian greg2))
7592 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7594 (setq sd (+ (* span arg) sd))))
7595 (let ((org-agenda-overriding-cmd
7596 ;; `cmd' may have been set by `org-agenda-run-series' which
7597 ;; uses `org-agenda-overriding-cmd' to decide whether
7598 ;; overriding is allowed for `cmd'
7599 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7600 (org-agenda-overriding-arguments
7601 (list (car args) sd span)))
7602 (org-agenda-redo)
7603 (org-agenda-find-same-or-today-or-agenda cnt))))
7605 (defun org-agenda-earlier (arg)
7606 "Go backward in time by the current span.
7607 With prefix ARG, go backward that many times the current span."
7608 (interactive "p")
7609 (org-agenda-later (- arg)))
7611 (defun org-agenda-view-mode-dispatch ()
7612 "Call one of the view mode commands."
7613 (interactive)
7614 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7615 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7616 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7617 (let ((a (read-char-exclusive)))
7618 (case a
7619 (?\ (call-interactively 'org-agenda-reset-view))
7620 (?d (call-interactively 'org-agenda-day-view))
7621 (?w (call-interactively 'org-agenda-week-view))
7622 (?m (call-interactively 'org-agenda-month-view))
7623 (?y (call-interactively 'org-agenda-year-view))
7624 (?l (call-interactively 'org-agenda-log-mode))
7625 (?L (org-agenda-log-mode '(4)))
7626 (?c (org-agenda-log-mode 'clockcheck))
7627 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7628 (?a (call-interactively 'org-agenda-archives-mode))
7629 (?A (org-agenda-archives-mode 'files))
7630 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7631 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7632 (?G (call-interactively 'org-agenda-toggle-time-grid))
7633 (?D (call-interactively 'org-agenda-toggle-diary))
7634 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7635 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7636 (org-agenda-check-type t 'timeline 'agenda)
7637 (org-agenda-redo))
7638 (message "Display now includes inactive timestamps as well"))
7639 (?q (message "Abort"))
7640 (otherwise (error "Invalid key" )))))
7642 (defun org-agenda-reset-view ()
7643 "Switch to default view for agenda."
7644 (interactive)
7645 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7646 (defun org-agenda-day-view (&optional day-of-year)
7647 "Switch to daily view for agenda.
7648 With argument DAY-OF-YEAR, switch to that day of the year."
7649 (interactive "P")
7650 (org-agenda-change-time-span 'day day-of-year))
7651 (defun org-agenda-week-view (&optional iso-week)
7652 "Switch to daily view for agenda.
7653 With argument ISO-WEEK, switch to the corresponding ISO week.
7654 If ISO-WEEK has more then 2 digits, only the last two encode the
7655 week. Any digits before this encode a year. So 200712 means
7656 week 12 of year 2007. Years in the range 1938-2037 can also be
7657 written as 2-digit years."
7658 (interactive "P")
7659 (org-agenda-change-time-span 'week iso-week))
7660 (defun org-agenda-month-view (&optional month)
7661 "Switch to monthly view for agenda.
7662 With argument MONTH, switch to that month."
7663 (interactive "P")
7664 (org-agenda-change-time-span 'month month))
7665 (defun org-agenda-year-view (&optional year)
7666 "Switch to yearly view for agenda.
7667 With argument YEAR, switch to that year.
7668 If MONTH has more then 2 digits, only the last two encode the
7669 month. Any digits before this encode a year. So 200712 means
7670 December year 2007. Years in the range 1938-2037 can also be
7671 written as 2-digit years."
7672 (interactive "P")
7673 (when year
7674 (setq year (org-small-year-to-year year)))
7675 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7676 (org-agenda-change-time-span 'year year)
7677 (error "Abort")))
7679 (defun org-agenda-change-time-span (span &optional n)
7680 "Change the agenda view to SPAN.
7681 SPAN may be `day', `week', `month', `year'."
7682 (org-agenda-check-type t 'agenda)
7683 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7684 (curspan (nth 2 args)))
7685 (if (and (not n) (equal curspan span))
7686 (error "Viewing span is already \"%s\"" span))
7687 (let* ((sd (or (org-get-at-bol 'day)
7688 (nth 1 args)
7689 org-starting-day))
7690 (sd (org-agenda-compute-starting-span sd span n))
7691 (org-agenda-overriding-cmd
7692 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7693 (org-agenda-overriding-arguments
7694 (list (car args) sd span)))
7695 (org-agenda-redo)
7696 (org-agenda-find-same-or-today-or-agenda))
7697 (org-agenda-set-mode-name)
7698 (message "Switched to %s view" span)))
7700 (defun org-agenda-compute-starting-span (sd span &optional n)
7701 "Compute starting date for agenda.
7702 SPAN may be `day', `week', `month', `year'. The return value
7703 is a cons cell with the starting date and the number of days,
7704 so that the date SD will be in that range."
7705 (let* ((greg (calendar-gregorian-from-absolute sd))
7706 (dg (nth 1 greg))
7707 (mg (car greg))
7708 (yg (nth 2 greg)))
7709 (cond
7710 ((eq span 'day)
7711 (when n
7712 (setq sd (+ (calendar-absolute-from-gregorian
7713 (list mg 1 yg))
7714 n -1))))
7715 ((eq span 'week)
7716 (let* ((nt (calendar-day-of-week
7717 (calendar-gregorian-from-absolute sd)))
7718 (d (if org-agenda-start-on-weekday
7719 (- nt org-agenda-start-on-weekday)
7722 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7723 (when n
7724 (require 'cal-iso)
7725 (when (> n 99)
7726 (setq y1 (org-small-year-to-year (/ n 100))
7727 n (mod n 100)))
7728 (setq sd
7729 (calendar-absolute-from-iso
7730 (list n 1
7731 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7732 ((eq span 'month)
7733 (let (y1)
7734 (when (and n (> n 99))
7735 (setq y1 (org-small-year-to-year (/ n 100))
7736 n (mod n 100)))
7737 (setq sd (calendar-absolute-from-gregorian
7738 (list (or n mg) 1 (or y1 yg))))))
7739 ((eq span 'year)
7740 (setq sd (calendar-absolute-from-gregorian
7741 (list 1 1 (or n yg))))))
7742 sd))
7744 (defun org-agenda-next-date-line (&optional arg)
7745 "Jump to the next line indicating a date in agenda buffer."
7746 (interactive "p")
7747 (org-agenda-check-type t 'agenda 'timeline)
7748 (beginning-of-line 1)
7749 ;; This does not work if user makes date format that starts with a blank
7750 (if (looking-at "^\\S-") (forward-char 1))
7751 (if (not (re-search-forward "^\\S-" nil t arg))
7752 (progn
7753 (backward-char 1)
7754 (error "No next date after this line in this buffer")))
7755 (goto-char (match-beginning 0)))
7757 (defun org-agenda-previous-date-line (&optional arg)
7758 "Jump to the previous line indicating a date in agenda buffer."
7759 (interactive "p")
7760 (org-agenda-check-type t 'agenda 'timeline)
7761 (beginning-of-line 1)
7762 (if (not (re-search-backward "^\\S-" nil t arg))
7763 (error "No previous date before this line in this buffer")))
7765 ;; Initialize the highlight
7766 (defvar org-hl (make-overlay 1 1))
7767 (overlay-put org-hl 'face 'highlight)
7769 (defun org-highlight (begin end &optional buffer)
7770 "Highlight a region with overlay."
7771 (move-overlay org-hl begin end (or buffer (current-buffer))))
7773 (defun org-unhighlight ()
7774 "Detach overlay INDEX."
7775 (org-detach-overlay org-hl))
7777 (defun org-unhighlight-once ()
7778 "Remove the highlight from its position, and this function from the hook."
7779 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7780 (org-unhighlight))
7782 (defvar org-agenda-pre-follow-window-conf nil)
7783 (defun org-agenda-follow-mode ()
7784 "Toggle follow mode in an agenda buffer."
7785 (interactive)
7786 (unless org-agenda-follow-mode
7787 (setq org-agenda-pre-follow-window-conf
7788 (current-window-configuration)))
7789 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7790 (unless org-agenda-follow-mode
7791 (set-window-configuration org-agenda-pre-follow-window-conf))
7792 (org-agenda-set-mode-name)
7793 (org-agenda-do-context-action)
7794 (message "Follow mode is %s"
7795 (if org-agenda-follow-mode "on" "off")))
7797 (defun org-agenda-entry-text-mode (&optional arg)
7798 "Toggle entry text mode in an agenda buffer."
7799 (interactive "P")
7800 (setq org-agenda-entry-text-mode (or (integerp arg)
7801 (not org-agenda-entry-text-mode)))
7802 (org-agenda-entry-text-hide)
7803 (and org-agenda-entry-text-mode
7804 (let ((org-agenda-entry-text-maxlines
7805 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7806 (org-agenda-entry-text-show)))
7807 (org-agenda-set-mode-name)
7808 (message "Entry text mode is %s. Maximum number of lines is %d"
7809 (if org-agenda-entry-text-mode "on" "off")
7810 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7812 (defun org-agenda-clockreport-mode (&optional with-filter)
7813 "Toggle clocktable mode in an agenda buffer.
7814 With prefix arg WITH-FILTER, make the clocktable respect the current
7815 agenda filter."
7816 (interactive "P")
7817 (org-agenda-check-type t 'agenda)
7818 (if with-filter
7819 (setq org-agenda-clockreport-mode 'with-filter)
7820 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7821 (org-agenda-set-mode-name)
7822 (org-agenda-redo)
7823 (message "Clocktable mode is %s"
7824 (if org-agenda-clockreport-mode "on" "off")))
7826 (defun org-agenda-log-mode (&optional special)
7827 "Toggle log mode in an agenda buffer.
7828 With argument SPECIAL, show all possible log items, not only the ones
7829 configured in `org-agenda-log-mode-items'.
7830 With a double `C-u' prefix arg, show *only* log items, nothing else."
7831 (interactive "P")
7832 (org-agenda-check-type t 'agenda 'timeline)
7833 (setq org-agenda-show-log
7834 (cond
7835 ((equal special '(16)) 'only)
7836 ((eq special 'clockcheck)
7837 (if (eq org-agenda-show-log 'clockcheck)
7838 nil 'clockcheck))
7839 (special '(closed clock state))
7840 (t (not org-agenda-show-log))))
7841 (org-agenda-set-mode-name)
7842 (org-agenda-redo)
7843 (message "Log mode is %s"
7844 (if org-agenda-show-log "on" "off")))
7846 (defun org-agenda-archives-mode (&optional with-files)
7847 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7848 When called with a prefix argument, include all archive files as well."
7849 (interactive "P")
7850 (setq org-agenda-archives-mode
7851 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7852 (org-agenda-set-mode-name)
7853 (org-agenda-redo)
7854 (message
7855 "%s"
7856 (cond
7857 ((eq org-agenda-archives-mode nil)
7858 "No archives are included")
7859 ((eq org-agenda-archives-mode 'trees)
7860 (format "Trees with :%s: tag are included" org-archive-tag))
7861 ((eq org-agenda-archives-mode t)
7862 (format "Trees with :%s: tag and all active archive files are included"
7863 org-archive-tag)))))
7865 (defun org-agenda-toggle-diary ()
7866 "Toggle diary inclusion in an agenda buffer."
7867 (interactive)
7868 (org-agenda-check-type t 'agenda)
7869 (setq org-agenda-include-diary (not org-agenda-include-diary))
7870 (org-agenda-redo)
7871 (org-agenda-set-mode-name)
7872 (message "Diary inclusion turned %s"
7873 (if org-agenda-include-diary "on" "off")))
7875 (defun org-agenda-toggle-deadlines ()
7876 "Toggle inclusion of entries with a deadline in an agenda buffer."
7877 (interactive)
7878 (org-agenda-check-type t 'agenda)
7879 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7880 (org-agenda-redo)
7881 (org-agenda-set-mode-name)
7882 (message "Deadlines inclusion turned %s"
7883 (if org-agenda-include-deadlines "on" "off")))
7885 (defun org-agenda-toggle-time-grid ()
7886 "Toggle time grid in an agenda buffer."
7887 (interactive)
7888 (org-agenda-check-type t 'agenda)
7889 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7890 (org-agenda-redo)
7891 (org-agenda-set-mode-name)
7892 (message "Time-grid turned %s"
7893 (if org-agenda-use-time-grid "on" "off")))
7895 (defun org-agenda-set-mode-name ()
7896 "Set the mode name to indicate all the small mode settings."
7897 (setq mode-name
7898 (list "Org-Agenda"
7899 (if (get 'org-agenda-files 'org-restrict) " []" "")
7901 '(:eval (org-agenda-span-name org-agenda-current-span))
7902 (if org-agenda-follow-mode " Follow" "")
7903 (if org-agenda-entry-text-mode " ETxt" "")
7904 (if org-agenda-include-diary " Diary" "")
7905 (if org-agenda-include-deadlines " Ddl" "")
7906 (if org-agenda-use-time-grid " Grid" "")
7907 (if (and (boundp 'org-habit-show-habits)
7908 org-habit-show-habits) " Habit" "")
7909 (cond
7910 ((consp org-agenda-show-log) " LogAll")
7911 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7912 (org-agenda-show-log " Log")
7913 (t ""))
7914 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7915 :preset-filter))
7916 '(:eval (org-propertize
7917 (concat " <"
7918 (mapconcat
7919 'identity
7920 (append
7921 (get 'org-agenda-category-filter :preset-filter)
7922 org-agenda-category-filter)
7924 ">")
7925 'face 'org-agenda-filter-category
7926 'help-echo "Category used in filtering"))
7928 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7929 :preset-filter))
7930 '(:eval (org-propertize
7931 (concat " {"
7932 (mapconcat
7933 'identity
7934 (append
7935 (get 'org-agenda-tag-filter :preset-filter)
7936 org-agenda-tag-filter)
7938 "}")
7939 'face 'org-agenda-filter-tags
7940 'help-echo "Tags used in filtering"))
7942 (if org-agenda-archives-mode
7943 (if (eq org-agenda-archives-mode t)
7944 " Archives"
7945 (format " :%s:" org-archive-tag))
7947 (if org-agenda-clockreport-mode
7948 (if (eq org-agenda-clockreport-mode 'with-filter)
7949 " Clock{}" " Clock")
7950 "")))
7951 (force-mode-line-update))
7953 (define-obsolete-function-alias
7954 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7956 (defun org-agenda-update-agenda-type ()
7957 "Update the agenda type after each command."
7958 (setq org-agenda-type
7959 (or (get-text-property (point) 'org-agenda-type)
7960 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7962 (defun org-agenda-next-line ()
7963 "Move cursor to the next line, and show if follow mode is active."
7964 (interactive)
7965 (call-interactively 'next-line)
7966 (org-agenda-do-context-action))
7968 (defun org-agenda-previous-line ()
7969 "Move cursor to the previous line, and show if follow-mode is active."
7970 (interactive)
7971 (call-interactively 'previous-line)
7972 (org-agenda-do-context-action))
7974 (defun org-agenda-next-item (n)
7975 "Move cursor to next agenda item."
7976 (interactive "p")
7977 (let ((col (current-column)))
7978 (dotimes (c n)
7979 (when (next-single-property-change (point-at-eol) 'org-marker)
7980 (move-end-of-line 1)
7981 (goto-char (next-single-property-change (point) 'org-marker))))
7982 (org-move-to-column col))
7983 (org-agenda-do-context-action))
7985 (defun org-agenda-previous-item (n)
7986 "Move cursor to next agenda item."
7987 (interactive "p")
7988 (dotimes (c n)
7989 (let ((col (current-column))
7990 (goto (save-excursion
7991 (move-end-of-line 0)
7992 (previous-single-property-change (point) 'org-marker))))
7993 (if goto (goto-char goto))
7994 (org-move-to-column col)))
7995 (org-agenda-do-context-action))
7997 (defun org-agenda-do-context-action ()
7998 "Show outline path and, maybe, follow mode window."
7999 (let ((m (org-get-at-bol 'org-marker)))
8000 (when (and (markerp m) (marker-buffer m))
8001 (and org-agenda-follow-mode
8002 (if org-agenda-follow-indirect
8003 (org-agenda-tree-to-indirect-buffer nil)
8004 (org-agenda-show)))
8005 (and org-agenda-show-outline-path
8006 (org-with-point-at m (org-display-outline-path t))))))
8008 (defun org-agenda-show-tags ()
8009 "Show the tags applicable to the current item."
8010 (interactive)
8011 (let* ((tags (org-get-at-bol 'tags)))
8012 (if tags
8013 (message "Tags are :%s:"
8014 (org-no-properties (mapconcat 'identity tags ":")))
8015 (message "No tags associated with this line"))))
8017 (defun org-agenda-goto (&optional highlight)
8018 "Go to the Org-mode file which contains the item at point."
8019 (interactive)
8020 (let* ((marker (or (org-get-at-bol 'org-marker)
8021 (org-agenda-error)))
8022 (buffer (marker-buffer marker))
8023 (pos (marker-position marker)))
8024 (switch-to-buffer-other-window buffer)
8025 (widen)
8026 (push-mark)
8027 (goto-char pos)
8028 (when (derived-mode-p 'org-mode)
8029 (org-show-context 'agenda)
8030 (save-excursion
8031 (and (outline-next-heading)
8032 (org-flag-heading nil)))) ; show the next heading
8033 (when (outline-invisible-p)
8034 (show-entry)) ; display invisible text
8035 (recenter (/ (window-height) 2))
8036 (run-hooks 'org-agenda-after-show-hook)
8037 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8039 (defvar org-agenda-after-show-hook nil
8040 "Normal hook run after an item has been shown from the agenda.
8041 Point is in the buffer where the item originated.")
8043 (defun org-agenda-kill ()
8044 "Kill the entry or subtree belonging to the current agenda entry."
8045 (interactive)
8046 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8047 (let* ((bufname-orig (buffer-name))
8048 (marker (or (org-get-at-bol 'org-marker)
8049 (org-agenda-error)))
8050 (buffer (marker-buffer marker))
8051 (pos (marker-position marker))
8052 (type (org-get-at-bol 'type))
8053 dbeg dend (n 0) conf)
8054 (org-with-remote-undo buffer
8055 (with-current-buffer buffer
8056 (save-excursion
8057 (goto-char pos)
8058 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8059 (setq dbeg (progn (org-back-to-heading t) (point))
8060 dend (org-end-of-subtree t t))
8061 (setq dbeg (point-at-bol)
8062 dend (min (point-max) (1+ (point-at-eol)))))
8063 (goto-char dbeg)
8064 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8065 (setq conf (or (eq t org-agenda-confirm-kill)
8066 (and (numberp org-agenda-confirm-kill)
8067 (> n org-agenda-confirm-kill))))
8068 (and conf
8069 (not (y-or-n-p
8070 (format "Delete entry with %d lines in buffer \"%s\"? "
8071 n (buffer-name buffer))))
8072 (error "Abort"))
8073 (let ((org-agenda-buffer-name bufname-orig))
8074 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8075 (with-current-buffer buffer (delete-region dbeg dend))
8076 (message "Agenda item and source killed"))))
8078 (defvar org-archive-default-command) ; defined in org-archive.el
8079 (defun org-agenda-archive-default ()
8080 "Archive the entry or subtree belonging to the current agenda entry."
8081 (interactive)
8082 (require 'org-archive)
8083 (org-agenda-archive-with org-archive-default-command))
8085 (defun org-agenda-archive-default-with-confirmation ()
8086 "Archive the entry or subtree belonging to the current agenda entry."
8087 (interactive)
8088 (require 'org-archive)
8089 (org-agenda-archive-with org-archive-default-command 'confirm))
8091 (defun org-agenda-archive ()
8092 "Archive the entry or subtree belonging to the current agenda entry."
8093 (interactive)
8094 (org-agenda-archive-with 'org-archive-subtree))
8096 (defun org-agenda-archive-to-archive-sibling ()
8097 "Move the entry to the archive sibling."
8098 (interactive)
8099 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8101 (defun org-agenda-archive-with (cmd &optional confirm)
8102 "Move the entry to the archive sibling."
8103 (interactive)
8104 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8105 (let* ((bufname-orig (buffer-name))
8106 (marker (or (org-get-at-bol 'org-marker)
8107 (org-agenda-error)))
8108 (buffer (marker-buffer marker))
8109 (pos (marker-position marker)))
8110 (org-with-remote-undo buffer
8111 (with-current-buffer buffer
8112 (if (derived-mode-p 'org-mode)
8113 (if (and confirm
8114 (not (y-or-n-p "Archive this subtree or entry? ")))
8115 (error "Abort")
8116 (save-excursion
8117 (goto-char pos)
8118 (let ((org-agenda-buffer-name bufname-orig))
8119 (org-remove-subtree-entries-from-agenda))
8120 (org-back-to-heading t)
8121 (funcall cmd)))
8122 (error "Archiving works only in Org-mode files"))))))
8124 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8125 "Remove all lines in the agenda that correspond to a given subtree.
8126 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8127 If this information is not given, the function uses the tree at point."
8128 (let ((buf (or buf (current-buffer))) m p)
8129 (save-excursion
8130 (unless (and beg end)
8131 (org-back-to-heading t)
8132 (setq beg (point))
8133 (org-end-of-subtree t)
8134 (setq end (point)))
8135 (set-buffer (get-buffer org-agenda-buffer-name))
8136 (save-excursion
8137 (goto-char (point-max))
8138 (beginning-of-line 1)
8139 (while (not (bobp))
8140 (when (and (setq m (org-get-at-bol 'org-marker))
8141 (equal buf (marker-buffer m))
8142 (setq p (marker-position m))
8143 (>= p beg)
8144 (< p end))
8145 (let ((inhibit-read-only t))
8146 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8147 (beginning-of-line 0))))))
8149 (defun org-agenda-refile (&optional goto rfloc no-update)
8150 "Refile the item at point."
8151 (interactive "P")
8152 (if (equal goto '(16))
8153 (org-refile-goto-last-stored)
8154 (let* ((buffer-orig (buffer-name))
8155 (marker (or (org-get-at-bol 'org-hd-marker)
8156 (org-agenda-error)))
8157 (buffer (marker-buffer marker))
8158 (pos (marker-position marker))
8159 (rfloc (or rfloc
8160 (org-refile-get-location
8161 (if goto "Goto" "Refile to") buffer
8162 org-refile-allow-creating-parent-nodes))))
8163 (with-current-buffer buffer
8164 (save-excursion
8165 (save-restriction
8166 (widen)
8167 (goto-char marker)
8168 (let ((org-agenda-buffer-name buffer-orig))
8169 (org-remove-subtree-entries-from-agenda))
8170 (org-refile goto buffer rfloc)))))
8171 (unless no-update (org-agenda-redo))))
8173 (defun org-agenda-open-link (&optional arg)
8174 "Open the link(s) in the current entry, if any.
8175 This looks for a link in the displayed line in the agenda.
8176 It also looks at the text of the entry itself."
8177 (interactive "P")
8178 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8179 (org-get-at-bol 'org-marker)))
8180 (buffer (and marker (marker-buffer marker)))
8181 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8182 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8183 (lk0 (car lkall))
8184 (lk (if (stringp lk0) (list lk0) lk0))
8185 (lkend (cdr lkall))
8186 trg)
8187 (cond
8188 ((and buffer lk)
8189 (mapcar (lambda(l)
8190 (with-current-buffer buffer
8191 (setq trg (and (string-match org-bracket-link-regexp l)
8192 (match-string 1 l)))
8193 (if (or (not trg) (string-match org-any-link-re trg))
8194 (save-excursion
8195 (save-restriction
8196 (widen)
8197 (goto-char marker)
8198 (when (search-forward l nil lkend)
8199 (goto-char (match-beginning 0))
8200 (org-open-at-point))))
8201 ;; This is an internal link, widen the buffer
8202 (switch-to-buffer-other-window buffer)
8203 (widen)
8204 (goto-char marker)
8205 (when (search-forward l nil lkend)
8206 (goto-char (match-beginning 0))
8207 (org-open-at-point)))))
8208 lk))
8209 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8210 (save-excursion
8211 (beginning-of-line 1)
8212 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8213 (org-open-link-from-string (match-string 1)))
8214 (t (message "No link to open here")))))
8216 (defun org-agenda-copy-local-variable (var)
8217 "Get a variable from a referenced buffer and install it here."
8218 (let ((m (org-get-at-bol 'org-marker)))
8219 (when (and m (buffer-live-p (marker-buffer m)))
8220 (org-set-local var (with-current-buffer (marker-buffer m)
8221 (symbol-value var))))))
8223 (defun org-agenda-switch-to (&optional delete-other-windows)
8224 "Go to the Org-mode file which contains the item at point."
8225 (interactive)
8226 (if (and org-return-follows-link
8227 (not (org-get-at-bol 'org-marker))
8228 (org-in-regexp org-bracket-link-regexp))
8229 (org-open-link-from-string (match-string 0))
8230 (let* ((marker (or (org-get-at-bol 'org-marker)
8231 (org-agenda-error)))
8232 (buffer (marker-buffer marker))
8233 (pos (marker-position marker)))
8234 (org-pop-to-buffer-same-window buffer)
8235 (and delete-other-windows (delete-other-windows))
8236 (widen)
8237 (goto-char pos)
8238 (when (derived-mode-p 'org-mode)
8239 (org-show-context 'agenda)
8240 (save-excursion
8241 (and (outline-next-heading)
8242 (org-flag-heading nil))) ; show the next heading
8243 (when (outline-invisible-p)
8244 (show-entry)) ; display invisible text
8245 (run-hooks 'org-agenda-after-show-hook)))))
8247 (defun org-agenda-goto-mouse (ev)
8248 "Go to the Org-mode file which contains the item at the mouse click."
8249 (interactive "e")
8250 (mouse-set-point ev)
8251 (org-agenda-goto))
8253 (defun org-agenda-show (&optional full-entry)
8254 "Display the Org-mode file which contains the item at point.
8255 With prefix argument FULL-ENTRY, make the entire entry visible
8256 if it was hidden in the outline."
8257 (interactive "P")
8258 (let ((win (selected-window)))
8259 (if full-entry
8260 (let ((org-show-entry-below t))
8261 (org-agenda-goto t))
8262 (org-agenda-goto t))
8263 (select-window win)))
8265 (defvar org-agenda-show-window nil)
8266 (defun org-agenda-show-and-scroll-up (&optional arg)
8267 "Display the Org-mode file which contains the item at point.
8268 When called repeatedly, scroll the window that is displaying the buffer.
8269 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8270 `show-subtree' to display the item, so that drawers and logbooks stay
8271 folded."
8272 (interactive "P")
8273 (let ((win (selected-window)))
8274 (if (and (window-live-p org-agenda-show-window)
8275 (eq this-command last-command))
8276 (progn
8277 (select-window org-agenda-show-window)
8278 (ignore-errors (scroll-up)))
8279 (org-agenda-goto t)
8280 (if arg (org-show-entry) (show-subtree))
8281 (setq org-agenda-show-window (selected-window)))
8282 (select-window win)))
8284 (defun org-agenda-show-scroll-down ()
8285 "Scroll down the window showing the agenda."
8286 (interactive)
8287 (let ((win (selected-window)))
8288 (when (window-live-p org-agenda-show-window)
8289 (select-window org-agenda-show-window)
8290 (ignore-errors (scroll-down))
8291 (select-window win))))
8293 (defun org-agenda-show-1 (&optional more)
8294 "Display the Org-mode file which contains the item at point.
8295 The prefix arg selects the amount of information to display:
8297 0 hide the subtree
8298 1 just show the entry according to defaults.
8299 2 show the children view
8300 3 show the subtree view
8301 4 show the entire subtree and any LOGBOOK drawers
8302 5 show the entire subtree and any drawers
8303 With prefix argument FULL-ENTRY, make the entire entry visible
8304 if it was hidden in the outline."
8305 (interactive "p")
8306 (let ((win (selected-window)))
8307 (org-agenda-goto t)
8308 (org-recenter-heading 1)
8309 (cond
8310 ((= more 0)
8311 (hide-subtree)
8312 (save-excursion
8313 (org-back-to-heading)
8314 (run-hook-with-args 'org-cycle-hook 'folded))
8315 (message "Remote: FOLDED"))
8316 ((and (org-called-interactively-p 'any) (= more 1))
8317 (message "Remote: show with default settings"))
8318 ((= more 2)
8319 (show-entry)
8320 (show-children)
8321 (save-excursion
8322 (org-back-to-heading)
8323 (run-hook-with-args 'org-cycle-hook 'children))
8324 (message "Remote: CHILDREN"))
8325 ((= more 3)
8326 (show-subtree)
8327 (save-excursion
8328 (org-back-to-heading)
8329 (run-hook-with-args 'org-cycle-hook 'subtree))
8330 (message "Remote: SUBTREE"))
8331 ((= more 4)
8332 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8333 (org-drawer-regexp
8334 (concat "^[ \t]*:\\("
8335 (mapconcat 'regexp-quote org-drawers "\\|")
8336 "\\):[ \t]*$")))
8337 (show-subtree)
8338 (save-excursion
8339 (org-back-to-heading)
8340 (org-cycle-hide-drawers 'subtree)))
8341 (message "Remote: SUBTREE AND LOGBOOK"))
8342 ((> more 4)
8343 (show-subtree)
8344 (message "Remote: SUBTREE AND ALL DRAWERS")))
8345 (select-window win)))
8347 (defun org-recenter-heading (n)
8348 (save-excursion
8349 (org-back-to-heading)
8350 (recenter n)))
8352 (defvar org-agenda-cycle-counter nil)
8353 (defun org-agenda-cycle-show (&optional n)
8354 "Show the current entry in another window, with default settings.
8355 Default settings are taken from `org-show-hierarchy-above' and siblings.
8356 When use repeatedly in immediate succession, the remote entry will cycle
8357 through visibility
8359 children -> subtree -> folded
8361 When called with a numeric prefix arg, that arg will be passed through to
8362 `org-agenda-show-1'. For the interpretation of that argument, see the
8363 docstring of `org-agenda-show-1'."
8364 (interactive "P")
8365 (if (integerp n)
8366 (setq org-agenda-cycle-counter n)
8367 (if (not (eq last-command this-command))
8368 (setq org-agenda-cycle-counter 1)
8369 (if (equal org-agenda-cycle-counter 0)
8370 (setq org-agenda-cycle-counter 2)
8371 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8372 (if (> org-agenda-cycle-counter 3)
8373 (setq org-agenda-cycle-counter 0)))))
8374 (org-agenda-show-1 org-agenda-cycle-counter))
8376 (defun org-agenda-recenter (arg)
8377 "Display the Org-mode file which contains the item at point and recenter."
8378 (interactive "P")
8379 (let ((win (selected-window)))
8380 (org-agenda-goto t)
8381 (recenter arg)
8382 (select-window win)))
8384 (defun org-agenda-show-mouse (ev)
8385 "Display the Org-mode file which contains the item at the mouse click."
8386 (interactive "e")
8387 (mouse-set-point ev)
8388 (org-agenda-show))
8390 (defun org-agenda-check-no-diary ()
8391 "Check if the entry is a diary link and abort if yes."
8392 (if (org-get-at-bol 'org-agenda-diary-link)
8393 (org-agenda-error)))
8395 (defun org-agenda-error ()
8396 (error "Command not allowed in this line"))
8398 (defun org-agenda-tree-to-indirect-buffer (arg)
8399 "Show the subtree corresponding to the current entry in an indirect buffer.
8400 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8402 With a numerical prefix ARG, go up to this level and then take that tree.
8403 With a negative numeric ARG, go up by this number of levels.
8404 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8405 use the dedicated frame)."
8406 (interactive "P")
8407 (if current-prefix-arg
8408 (org-agenda-do-tree-to-indirect-buffer arg)
8409 (let ((agenda-buffer (buffer-name))
8410 (agenda-window (selected-window))
8411 (indirect-window
8412 (and org-last-indirect-buffer
8413 (get-buffer-window org-last-indirect-buffer))))
8414 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8415 (unless (or (eq org-indirect-buffer-display 'new-frame)
8416 (eq org-indirect-buffer-display 'dedicated-frame))
8417 (unwind-protect
8418 (unless (and indirect-window (window-live-p indirect-window))
8419 (setq indirect-window (split-window agenda-window)))
8420 (and indirect-window (select-window indirect-window))
8421 (switch-to-buffer org-last-indirect-buffer :norecord)
8422 (fit-window-to-buffer indirect-window)))
8423 (select-window (get-buffer-window agenda-buffer)))))
8425 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8426 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8427 (org-agenda-check-no-diary)
8428 (let* ((marker (or (org-get-at-bol 'org-marker)
8429 (org-agenda-error)))
8430 (buffer (marker-buffer marker))
8431 (pos (marker-position marker)))
8432 (with-current-buffer buffer
8433 (save-excursion
8434 (goto-char pos)
8435 (funcall 'org-tree-to-indirect-buffer arg)))))
8437 (defvar org-last-heading-marker (make-marker)
8438 "Marker pointing to the headline that last changed its TODO state
8439 by a remote command from the agenda.")
8441 (defun org-agenda-todo-nextset ()
8442 "Switch TODO entry to next sequence."
8443 (interactive)
8444 (org-agenda-todo 'nextset))
8446 (defun org-agenda-todo-previousset ()
8447 "Switch TODO entry to previous sequence."
8448 (interactive)
8449 (org-agenda-todo 'previousset))
8451 (defun org-agenda-todo (&optional arg)
8452 "Cycle TODO state of line at point, also in Org-mode file.
8453 This changes the line at point, all other lines in the agenda referring to
8454 the same tree node, and the headline of the tree node in the Org-mode file."
8455 (interactive "P")
8456 (org-agenda-check-no-diary)
8457 (let* ((col (current-column))
8458 (marker (or (org-get-at-bol 'org-marker)
8459 (org-agenda-error)))
8460 (buffer (marker-buffer marker))
8461 (pos (marker-position marker))
8462 (hdmarker (org-get-at-bol 'org-hd-marker))
8463 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8464 (inhibit-read-only t)
8465 org-agenda-headline-snapshot-before-repeat newhead just-one)
8466 (org-with-remote-undo buffer
8467 (with-current-buffer buffer
8468 (widen)
8469 (goto-char pos)
8470 (org-show-context 'agenda)
8471 (save-excursion
8472 (and (outline-next-heading)
8473 (org-flag-heading nil))) ; show the next heading
8474 (let ((current-prefix-arg arg))
8475 (call-interactively 'org-todo))
8476 (and (bolp) (forward-char 1))
8477 (setq newhead (org-get-heading))
8478 (when (and (org-bound-and-true-p
8479 org-agenda-headline-snapshot-before-repeat)
8480 (not (equal org-agenda-headline-snapshot-before-repeat
8481 newhead))
8482 todayp)
8483 (setq newhead org-agenda-headline-snapshot-before-repeat
8484 just-one t))
8485 (save-excursion
8486 (org-back-to-heading)
8487 (move-marker org-last-heading-marker (point))))
8488 (beginning-of-line 1)
8489 (save-excursion
8490 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8491 (org-move-to-column col))))
8493 (defun org-agenda-add-note (&optional arg)
8494 "Add a time-stamped note to the entry at point."
8495 (interactive "P")
8496 (org-agenda-check-no-diary)
8497 (let* ((marker (or (org-get-at-bol 'org-marker)
8498 (org-agenda-error)))
8499 (buffer (marker-buffer marker))
8500 (pos (marker-position marker))
8501 (hdmarker (org-get-at-bol 'org-hd-marker))
8502 (inhibit-read-only t))
8503 (with-current-buffer buffer
8504 (widen)
8505 (goto-char pos)
8506 (org-show-context 'agenda)
8507 (save-excursion
8508 (and (outline-next-heading)
8509 (org-flag-heading nil))) ; show the next heading
8510 (org-add-note))))
8512 (defun org-agenda-change-all-lines (newhead hdmarker
8513 &optional fixface just-this)
8514 "Change all lines in the agenda buffer which match HDMARKER.
8515 The new content of the line will be NEWHEAD (as modified by
8516 `org-agenda-format-item'). HDMARKER is checked with
8517 `equal' against all `org-hd-marker' text properties in the file.
8518 If FIXFACE is non-nil, the face of each item is modified according to
8519 the new TODO state.
8520 If JUST-THIS is non-nil, change just the current line, not all.
8521 If FORCE-TAGS is non nil, the car of it returns the new tags."
8522 (let* ((inhibit-read-only t)
8523 (line (org-current-line))
8524 (org-agenda-buffer (current-buffer))
8525 (thetags (with-current-buffer (marker-buffer hdmarker)
8526 (save-excursion (save-restriction (widen)
8527 (goto-char hdmarker)
8528 (org-get-tags-at)))))
8529 props m pl undone-face done-face finish new dotime level cat tags)
8530 (save-excursion
8531 (goto-char (point-max))
8532 (beginning-of-line 1)
8533 (while (not finish)
8534 (setq finish (bobp))
8535 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8536 (or (not just-this) (= (org-current-line) line))
8537 (equal m hdmarker))
8538 (setq props (text-properties-at (point))
8539 dotime (org-get-at-bol 'dotime)
8540 cat (org-get-at-bol 'org-category)
8541 level (org-get-at-bol 'level)
8542 tags thetags
8544 (let ((org-prefix-format-compiled
8545 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8546 org-prefix-format-compiled))
8547 (extra (org-get-at-bol 'extra)))
8548 (with-current-buffer (marker-buffer hdmarker)
8549 (save-excursion
8550 (save-restriction
8551 (widen)
8552 (org-agenda-format-item extra newhead level cat tags dotime)))))
8553 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8554 undone-face (org-get-at-bol 'undone-face)
8555 done-face (org-get-at-bol 'done-face))
8556 (beginning-of-line 1)
8557 (cond
8558 ((equal new "")
8559 (and (looking-at ".*\n?") (replace-match "")))
8560 ((looking-at ".*")
8561 (replace-match new t t)
8562 (beginning-of-line 1)
8563 (add-text-properties (point-at-bol) (point-at-eol) props)
8564 (when fixface
8565 (add-text-properties
8566 (point-at-bol) (point-at-eol)
8567 (list 'face
8568 (if org-last-todo-state-is-todo
8569 undone-face done-face))))
8570 (org-agenda-highlight-todo 'line)
8571 (beginning-of-line 1))
8572 (t (error "Line update did not work")))
8573 (save-restriction
8574 (narrow-to-region (point-at-bol) (point-at-eol))
8575 (org-agenda-finalize)))
8576 (beginning-of-line 0)))))
8578 (defun org-agenda-align-tags (&optional line)
8579 "Align all tags in agenda items to `org-agenda-tags-column'."
8580 (let ((inhibit-read-only t) l c)
8581 (save-excursion
8582 (goto-char (if line (point-at-bol) (point-min)))
8583 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8584 (if line (point-at-eol) nil) t)
8585 (add-text-properties
8586 (match-beginning 2) (match-end 2)
8587 (list 'face (delq nil (let ((prop (get-text-property
8588 (match-beginning 2) 'face)))
8589 (or (listp prop) (setq prop (list prop)))
8590 (if (memq 'org-tag prop)
8591 prop
8592 (cons 'org-tag prop))))))
8593 (setq l (- (match-end 2) (match-beginning 2))
8594 c (if (< org-agenda-tags-column 0)
8595 (- (abs org-agenda-tags-column) l)
8596 org-agenda-tags-column))
8597 (delete-region (match-beginning 1) (match-end 1))
8598 (goto-char (match-beginning 1))
8599 (insert (org-add-props
8600 (make-string (max 1 (- c (current-column))) ?\ )
8601 (plist-put (copy-sequence (text-properties-at (point)))
8602 'face nil))))
8603 (goto-char (point-min))
8604 (org-font-lock-add-tag-faces (point-max)))))
8606 (defun org-agenda-priority-up ()
8607 "Increase the priority of line at point, also in Org-mode file."
8608 (interactive)
8609 (org-agenda-priority 'up))
8611 (defun org-agenda-priority-down ()
8612 "Decrease the priority of line at point, also in Org-mode file."
8613 (interactive)
8614 (org-agenda-priority 'down))
8616 (defun org-agenda-priority (&optional force-direction)
8617 "Set the priority of line at point, also in Org-mode file.
8618 This changes the line at point, all other lines in the agenda referring to
8619 the same tree node, and the headline of the tree node in the Org-mode file.
8620 Called with a universal prefix arg, show the priority instead of setting it."
8621 (interactive "P")
8622 (if (equal force-direction '(4))
8623 (org-show-priority)
8624 (unless org-enable-priority-commands
8625 (error "Priority commands are disabled"))
8626 (org-agenda-check-no-diary)
8627 (let* ((marker (or (org-get-at-bol 'org-marker)
8628 (org-agenda-error)))
8629 (hdmarker (org-get-at-bol 'org-hd-marker))
8630 (buffer (marker-buffer hdmarker))
8631 (pos (marker-position hdmarker))
8632 (inhibit-read-only t)
8633 newhead)
8634 (org-with-remote-undo buffer
8635 (with-current-buffer buffer
8636 (widen)
8637 (goto-char pos)
8638 (org-show-context 'agenda)
8639 (save-excursion
8640 (and (outline-next-heading)
8641 (org-flag-heading nil))) ; show the next heading
8642 (funcall 'org-priority force-direction)
8643 (end-of-line 1)
8644 (setq newhead (org-get-heading)))
8645 (org-agenda-change-all-lines newhead hdmarker)
8646 (beginning-of-line 1)))))
8648 ;; FIXME: should fix the tags property of the agenda line.
8649 (defun org-agenda-set-tags (&optional tag onoff)
8650 "Set tags for the current headline."
8651 (interactive)
8652 (org-agenda-check-no-diary)
8653 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8654 (call-interactively 'org-change-tag-in-region)
8655 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8656 (org-agenda-error)))
8657 (buffer (marker-buffer hdmarker))
8658 (pos (marker-position hdmarker))
8659 (inhibit-read-only t)
8660 newhead)
8661 (org-with-remote-undo buffer
8662 (with-current-buffer buffer
8663 (widen)
8664 (goto-char pos)
8665 (save-excursion
8666 (org-show-context 'agenda))
8667 (save-excursion
8668 (and (outline-next-heading)
8669 (org-flag-heading nil))) ; show the next heading
8670 (goto-char pos)
8671 (if tag
8672 (org-toggle-tag tag onoff)
8673 (call-interactively 'org-set-tags))
8674 (end-of-line 1)
8675 (setq newhead (org-get-heading)))
8676 (org-agenda-change-all-lines newhead hdmarker)
8677 (beginning-of-line 1)))))
8679 (defun org-agenda-set-property ()
8680 "Set a property for the current headline."
8681 (interactive)
8682 (org-agenda-check-no-diary)
8683 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8684 (org-agenda-error)))
8685 (buffer (marker-buffer hdmarker))
8686 (pos (marker-position hdmarker))
8687 (inhibit-read-only t)
8688 newhead)
8689 (org-with-remote-undo buffer
8690 (with-current-buffer buffer
8691 (widen)
8692 (goto-char pos)
8693 (save-excursion
8694 (org-show-context 'agenda))
8695 (save-excursion
8696 (and (outline-next-heading)
8697 (org-flag-heading nil))) ; show the next heading
8698 (goto-char pos)
8699 (call-interactively 'org-set-property)))))
8701 (defun org-agenda-set-effort ()
8702 "Set the effort property for the current headline."
8703 (interactive)
8704 (org-agenda-check-no-diary)
8705 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8706 (org-agenda-error)))
8707 (buffer (marker-buffer hdmarker))
8708 (pos (marker-position hdmarker))
8709 (inhibit-read-only t)
8710 newhead)
8711 (org-with-remote-undo buffer
8712 (with-current-buffer buffer
8713 (widen)
8714 (goto-char pos)
8715 (save-excursion
8716 (org-show-context 'agenda))
8717 (save-excursion
8718 (and (outline-next-heading)
8719 (org-flag-heading nil))) ; show the next heading
8720 (goto-char pos)
8721 (call-interactively 'org-set-effort)
8722 (end-of-line 1)
8723 (setq newhead (org-get-heading)))
8724 (org-agenda-change-all-lines newhead hdmarker))))
8726 (defun org-agenda-toggle-archive-tag ()
8727 "Toggle the archive tag for the current entry."
8728 (interactive)
8729 (org-agenda-check-no-diary)
8730 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8731 (org-agenda-error)))
8732 (buffer (marker-buffer hdmarker))
8733 (pos (marker-position hdmarker))
8734 (inhibit-read-only t)
8735 newhead)
8736 (org-with-remote-undo buffer
8737 (with-current-buffer buffer
8738 (widen)
8739 (goto-char pos)
8740 (org-show-context 'agenda)
8741 (save-excursion
8742 (and (outline-next-heading)
8743 (org-flag-heading nil))) ; show the next heading
8744 (call-interactively 'org-toggle-archive-tag)
8745 (end-of-line 1)
8746 (setq newhead (org-get-heading)))
8747 (org-agenda-change-all-lines newhead hdmarker)
8748 (beginning-of-line 1))))
8750 (defun org-agenda-do-date-later (arg)
8751 (interactive "P")
8752 (cond
8753 ((or (equal arg '(16))
8754 (memq last-command
8755 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8756 (setq this-command 'org-agenda-date-later-minutes)
8757 (org-agenda-date-later-minutes 1))
8758 ((or (equal arg '(4))
8759 (memq last-command
8760 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8761 (setq this-command 'org-agenda-date-later-hours)
8762 (org-agenda-date-later-hours 1))
8764 (org-agenda-date-later (prefix-numeric-value arg)))))
8766 (defun org-agenda-do-date-earlier (arg)
8767 (interactive "P")
8768 (cond
8769 ((or (equal arg '(16))
8770 (memq last-command
8771 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8772 (setq this-command 'org-agenda-date-earlier-minutes)
8773 (org-agenda-date-earlier-minutes 1))
8774 ((or (equal arg '(4))
8775 (memq last-command
8776 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8777 (setq this-command 'org-agenda-date-earlier-hours)
8778 (org-agenda-date-earlier-hours 1))
8780 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8782 (defun org-agenda-date-later (arg &optional what)
8783 "Change the date of this item to ARG day(s) later."
8784 (interactive "p")
8785 (org-agenda-check-type t 'agenda 'timeline)
8786 (org-agenda-check-no-diary)
8787 (let* ((marker (or (org-get-at-bol 'org-marker)
8788 (org-agenda-error)))
8789 (buffer (marker-buffer marker))
8790 (pos (marker-position marker))
8791 cdate today)
8792 (org-with-remote-undo buffer
8793 (with-current-buffer buffer
8794 (widen)
8795 (goto-char pos)
8796 (if (not (org-at-timestamp-p))
8797 (error "Cannot find time stamp"))
8798 (when (and org-agenda-move-date-from-past-immediately-to-today
8799 (equal arg 1)
8800 (or (not what) (eq what 'day))
8801 (not (save-match-data (org-at-date-range-p))))
8802 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8803 cdate (calendar-absolute-from-gregorian
8804 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8805 today (org-today))
8806 (if (> today cdate)
8807 ;; immediately shift to today
8808 (setq arg (- today cdate))))
8809 (org-timestamp-change arg (or what 'day))
8810 (when (and (org-at-date-range-p)
8811 (re-search-backward org-tr-regexp-both (point-at-bol)))
8812 (let ((end org-last-changed-timestamp))
8813 (org-timestamp-change arg (or what 'day))
8814 (setq org-last-changed-timestamp
8815 (concat org-last-changed-timestamp "--" end)))))
8816 (org-agenda-show-new-time marker org-last-changed-timestamp))
8817 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8819 (defun org-agenda-date-earlier (arg &optional what)
8820 "Change the date of this item to ARG day(s) earlier."
8821 (interactive "p")
8822 (org-agenda-date-later (- arg) what))
8824 (defun org-agenda-date-later-minutes (arg)
8825 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8826 (interactive "p")
8827 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8828 (org-agenda-date-later arg 'minute))
8830 (defun org-agenda-date-earlier-minutes (arg)
8831 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8832 (interactive "p")
8833 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8834 (org-agenda-date-earlier arg 'minute))
8836 (defun org-agenda-date-later-hours (arg)
8837 "Change the time of this item, in hour steps."
8838 (interactive "p")
8839 (org-agenda-date-later arg 'hour))
8841 (defun org-agenda-date-earlier-hours (arg)
8842 "Change the time of this item, in hour steps."
8843 (interactive "p")
8844 (org-agenda-date-earlier arg 'hour))
8846 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8847 "Show new date stamp via text properties."
8848 ;; We use text properties to make this undoable
8849 (let ((inhibit-read-only t))
8850 (setq stamp (concat prefix " => " stamp " "))
8851 (save-excursion
8852 (goto-char (point-max))
8853 (while (not (bobp))
8854 (when (equal marker (org-get-at-bol 'org-marker))
8855 (org-move-to-column (- (window-width) (length stamp)) t)
8856 (org-agenda-fix-tags-filter-overlays-at (point))
8857 (if (featurep 'xemacs)
8858 ;; Use `duplicable' property to trigger undo recording
8859 (let ((ex (make-extent nil nil))
8860 (gl (make-glyph stamp)))
8861 (set-glyph-face gl 'secondary-selection)
8862 (set-extent-properties
8863 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8864 (insert-extent ex (1- (point)) (point-at-eol)))
8865 (add-text-properties
8866 (1- (point)) (point-at-eol)
8867 (list 'display (org-add-props stamp nil
8868 'face 'secondary-selection))))
8869 (beginning-of-line 1))
8870 (beginning-of-line 0)))))
8872 (defun org-agenda-date-prompt (arg)
8873 "Change the date of this item. Date is prompted for, with default today.
8874 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8875 be used to request time specification in the time stamp."
8876 (interactive "P")
8877 (org-agenda-check-type t 'agenda 'timeline)
8878 (org-agenda-check-no-diary)
8879 (let* ((marker (or (org-get-at-bol 'org-marker)
8880 (org-agenda-error)))
8881 (buffer (marker-buffer marker))
8882 (pos (marker-position marker)))
8883 (org-with-remote-undo buffer
8884 (with-current-buffer buffer
8885 (widen)
8886 (goto-char pos)
8887 (if (not (org-at-timestamp-p t))
8888 (error "Cannot find time stamp"))
8889 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8890 (org-agenda-show-new-time marker org-last-changed-timestamp))
8891 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8893 (defun org-agenda-schedule (arg &optional time)
8894 "Schedule the item at point.
8895 ARG is passed through to `org-schedule'."
8896 (interactive "P")
8897 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8898 (org-agenda-check-no-diary)
8899 (let* ((marker (or (org-get-at-bol 'org-marker)
8900 (org-agenda-error)))
8901 (type (marker-insertion-type marker))
8902 (buffer (marker-buffer marker))
8903 (pos (marker-position marker))
8904 (org-insert-labeled-timestamps-at-point nil)
8906 (set-marker-insertion-type marker t)
8907 (org-with-remote-undo buffer
8908 (with-current-buffer buffer
8909 (widen)
8910 (goto-char pos)
8911 (setq ts (org-schedule arg time)))
8912 (org-agenda-show-new-time marker ts " S"))
8913 (message "%s" ts)))
8915 (defun org-agenda-deadline (arg &optional time)
8916 "Schedule the item at point.
8917 ARG is passed through to `org-deadline'."
8918 (interactive "P")
8919 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8920 (org-agenda-check-no-diary)
8921 (let* ((marker (or (org-get-at-bol 'org-marker)
8922 (org-agenda-error)))
8923 (buffer (marker-buffer marker))
8924 (pos (marker-position marker))
8925 (org-insert-labeled-timestamps-at-point nil)
8927 (org-with-remote-undo buffer
8928 (with-current-buffer buffer
8929 (widen)
8930 (goto-char pos)
8931 (setq ts (org-deadline arg time)))
8932 (org-agenda-show-new-time marker ts " D"))
8933 (message "%s" ts)))
8935 (defun org-agenda-clock-in (&optional arg)
8936 "Start the clock on the currently selected item."
8937 (interactive "P")
8938 (org-agenda-check-no-diary)
8939 (if (equal arg '(4))
8940 (org-clock-in arg)
8941 (let* ((marker (or (org-get-at-bol 'org-marker)
8942 (org-agenda-error)))
8943 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
8944 (pos (marker-position marker))
8945 (col (current-column))
8946 newhead)
8947 (org-with-remote-undo (marker-buffer marker)
8948 (with-current-buffer (marker-buffer marker)
8949 (widen)
8950 (goto-char pos)
8951 (org-show-context 'agenda)
8952 (org-show-entry)
8953 (org-cycle-hide-drawers 'children)
8954 (org-clock-in arg)
8955 (setq newhead (org-get-heading)))
8956 (org-agenda-change-all-lines newhead hdmarker))
8957 (org-move-to-column col))))
8959 (defun org-agenda-clock-out ()
8960 "Stop the currently running clock."
8961 (interactive)
8962 (unless (marker-buffer org-clock-marker)
8963 (error "No running clock"))
8964 (let ((marker (make-marker)) (col (current-column)) newhead)
8965 (org-with-remote-undo (marker-buffer org-clock-marker)
8966 (with-current-buffer (marker-buffer org-clock-marker)
8967 (save-excursion
8968 (save-restriction
8969 (widen)
8970 (goto-char org-clock-marker)
8971 (org-back-to-heading t)
8972 (move-marker marker (point))
8973 (org-clock-out)
8974 (setq newhead (org-get-heading))))))
8975 (org-agenda-change-all-lines newhead marker)
8976 (move-marker marker nil)
8977 (org-move-to-column col)
8978 (org-agenda-unmark-clocking-task)))
8980 (defun org-agenda-clock-cancel (&optional arg)
8981 "Cancel the currently running clock."
8982 (interactive "P")
8983 (unless (marker-buffer org-clock-marker)
8984 (error "No running clock"))
8985 (org-with-remote-undo (marker-buffer org-clock-marker)
8986 (org-clock-cancel)))
8988 (defun org-agenda-clock-goto ()
8989 "Jump to the currently clocked in task within the agenda.
8990 If the currently clocked in task is not listed in the agenda
8991 buffer, display it in another window."
8992 (interactive)
8993 (let (pos)
8994 (mapc (lambda (o)
8995 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8996 (setq pos (overlay-start o))))
8997 (overlays-in (point-min) (point-max)))
8998 (cond (pos (goto-char pos))
8999 ;; If the currently clocked entry is not in the agenda
9000 ;; buffer, we visit it in another window:
9001 (org-clock-current-task
9002 (org-switch-to-buffer-other-window (org-clock-goto)))
9003 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9005 (defun org-agenda-diary-entry-in-org-file ()
9006 "Make a diary entry in the file `org-agenda-diary-file'."
9007 (let (d1 d2 char (text "") dp1 dp2)
9008 (if (equal (buffer-name) "*Calendar*")
9009 (setq d1 (calendar-cursor-to-date t)
9010 d2 (car calendar-mark-ring))
9011 (setq dp1 (get-text-property (point-at-bol) 'day))
9012 (unless dp1 (error "No date defined in current line"))
9013 (setq d1 (calendar-gregorian-from-absolute dp1)
9014 d2 (and (ignore-errors (mark))
9015 (save-excursion
9016 (goto-char (mark))
9017 (setq dp2 (get-text-property (point-at-bol) 'day)))
9018 (calendar-gregorian-from-absolute dp2))))
9019 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9020 (setq char (read-char-exclusive))
9021 (cond
9022 ((equal char ?d)
9023 (setq text (read-string "Day entry: "))
9024 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9025 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9026 ((equal char ?a)
9027 (setq d1 (list (car d1) (nth 1 d1)
9028 (read-number (format "Reference year [%d]: " (nth 2 d1))
9029 (nth 2 d1))))
9030 (setq text (read-string "Anniversary (use %d to show years): "))
9031 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9032 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9033 ((equal char ?b)
9034 (setq text (read-string "Block entry: "))
9035 (unless (and d1 d2 (not (equal d1 d2)))
9036 (error "No block of days selected"))
9037 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9038 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9039 ((equal char ?j)
9040 (org-switch-to-buffer-other-window
9041 (find-file-noselect org-agenda-diary-file))
9042 (require 'org-datetree)
9043 (org-datetree-find-date-create d1)
9044 (org-reveal t))
9045 (t (error "Invalid selection character `%c'" char)))))
9047 (defcustom org-agenda-insert-diary-strategy 'date-tree
9048 "Where in `org-agenda-diary-file' should new entries be added?
9049 Valid values:
9051 date-tree in the date tree, as child of the date
9052 top-level as top-level entries at the end of the file."
9053 :group 'org-agenda
9054 :type '(choice
9055 (const :tag "in a date tree" date-tree)
9056 (const :tag "as top level at end of file" top-level)))
9058 (defcustom org-agenda-insert-diary-extract-time nil
9059 "Non-nil means extract any time specification from the diary entry."
9060 :group 'org-agenda
9061 :version "24.1"
9062 :type 'boolean)
9064 (defcustom org-agenda-bulk-mark-char ">"
9065 "A single-character string to be used as the bulk mark."
9066 :group 'org-agenda
9067 :version "24.1"
9068 :type 'string)
9070 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9071 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9072 If TEXT is not empty, it will become the headline of the new entry, and
9073 the resulting entry will not be shown. When TEXT is empty, switch to
9074 `org-agenda-diary-file' and let the user finish the entry there."
9075 (let ((cw (current-window-configuration)))
9076 (org-switch-to-buffer-other-window
9077 (find-file-noselect org-agenda-diary-file))
9078 (widen)
9079 (goto-char (point-min))
9080 (cond
9081 ((eq type 'anniversary)
9082 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9083 (progn
9084 (or (org-at-heading-p t)
9085 (progn
9086 (outline-next-heading)
9087 (insert "* Anniversaries\n\n")
9088 (beginning-of-line -1)))))
9089 (outline-next-heading)
9090 (org-back-over-empty-lines)
9091 (backward-char 1)
9092 (insert "\n")
9093 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9094 (nth 2 d1) (car d1) (nth 1 d1) text)))
9095 ((eq type 'day)
9096 (let ((org-prefix-has-time t)
9097 (org-agenda-time-leading-zero t)
9098 fmt time time2)
9099 (if org-agenda-insert-diary-extract-time
9100 ;; Use org-agenda-format-item to parse text for a time-range and
9101 ;; remove it. FIXME: This is a hack, we should refactor
9102 ;; that function to make time extraction available separately
9103 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9104 time (get-text-property 0 'time fmt)
9105 time2 (if (> (length time) 0)
9106 ;; split-string removes trailing ...... if
9107 ;; no end time given. First space
9108 ;; separates time from date.
9109 (concat " " (car (split-string time "\\.")))
9110 nil)
9111 text (get-text-property 0 'txt fmt)))
9112 (if (eq org-agenda-insert-diary-strategy 'top-level)
9113 (org-agenda-insert-diary-as-top-level text)
9114 (require 'org-datetree)
9115 (org-datetree-find-date-create d1)
9116 (org-agenda-insert-diary-make-new-entry text))
9117 (org-insert-time-stamp (org-time-from-absolute
9118 (calendar-absolute-from-gregorian d1))
9119 nil nil nil nil time2))
9120 (end-of-line 0))
9121 ((eq type 'block)
9122 (if (> (calendar-absolute-from-gregorian d1)
9123 (calendar-absolute-from-gregorian d2))
9124 (setq d1 (prog1 d2 (setq d2 d1))))
9125 (if (eq org-agenda-insert-diary-strategy 'top-level)
9126 (org-agenda-insert-diary-as-top-level text)
9127 (require 'org-datetree)
9128 (org-datetree-find-date-create d1)
9129 (org-agenda-insert-diary-make-new-entry text))
9130 (org-insert-time-stamp (org-time-from-absolute
9131 (calendar-absolute-from-gregorian d1)))
9132 (insert "--")
9133 (org-insert-time-stamp (org-time-from-absolute
9134 (calendar-absolute-from-gregorian d2)))
9135 (end-of-line 0)))
9136 (if (string-match "\\S-" text)
9137 (progn
9138 (set-window-configuration cw)
9139 (message "%s entry added to %s"
9140 (capitalize (symbol-name type))
9141 (abbreviate-file-name org-agenda-diary-file)))
9142 (org-reveal t)
9143 (message "Please finish entry here"))))
9145 (defun org-agenda-insert-diary-as-top-level (text)
9146 "Make new entry as a top-level entry at the end of the file.
9147 Add TEXT as headline, and position the cursor in the second line so that
9148 a timestamp can be added there."
9149 (widen)
9150 (goto-char (point-max))
9151 (or (bolp) (insert "\n"))
9152 (insert "* " text "\n")
9153 (if org-adapt-indentation (org-indent-to-column 2)))
9155 (defun org-agenda-insert-diary-make-new-entry (text)
9156 "Make new entry as last child of current entry.
9157 Add TEXT as headline, and position the cursor in the second line so that
9158 a timestamp can be added there."
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 col)
9164 (outline-next-heading)
9165 (org-back-over-empty-lines)
9166 (or (looking-at "[ \t]*$")
9167 (progn (insert "\n") (backward-char 1)))
9168 (org-insert-heading nil t)
9169 (org-do-demote)
9170 (setq col (current-column))
9171 (insert text "\n")
9172 (if org-adapt-indentation (org-indent-to-column col))
9173 (let ((org-show-following-heading t)
9174 (org-show-siblings t)
9175 (org-show-hierarchy-above t)
9176 (org-show-entry-below t))
9177 (org-show-context))))
9179 (defun org-agenda-diary-entry ()
9180 "Make a diary entry, like the `i' command from the calendar.
9181 All the standard commands work: block, weekly etc.
9182 When `org-agenda-diary-file' points to a file,
9183 `org-agenda-diary-entry-in-org-file' is called instead to create
9184 entries in that Org-mode file."
9185 (interactive)
9186 (if (not (eq org-agenda-diary-file 'diary-file))
9187 (org-agenda-diary-entry-in-org-file)
9188 (require 'diary-lib)
9189 (let* ((char (progn
9190 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9191 (read-char-exclusive)))
9192 (cmd (cdr (assoc char
9193 '((?d . insert-diary-entry)
9194 (?w . insert-weekly-diary-entry)
9195 (?m . insert-monthly-diary-entry)
9196 (?y . insert-yearly-diary-entry)
9197 (?a . insert-anniversary-diary-entry)
9198 (?b . insert-block-diary-entry)
9199 (?c . insert-cyclic-diary-entry)))))
9200 (oldf (symbol-function 'calendar-cursor-to-date))
9201 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9202 (point (point))
9203 (mark (or (mark t) (point))))
9204 (unless cmd
9205 (error "No command associated with <%c>" char))
9206 (unless (and (get-text-property point 'day)
9207 (or (not (equal ?b char))
9208 (get-text-property mark 'day)))
9209 (error "Don't know which date to use for diary entry"))
9210 ;; We implement this by hacking the `calendar-cursor-to-date' function
9211 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9212 (let ((calendar-mark-ring
9213 (list (calendar-gregorian-from-absolute
9214 (or (get-text-property mark 'day)
9215 (get-text-property point 'day))))))
9216 (unwind-protect
9217 (progn
9218 (fset 'calendar-cursor-to-date
9219 (lambda (&optional error dummy)
9220 (calendar-gregorian-from-absolute
9221 (get-text-property point 'day))))
9222 (call-interactively cmd))
9223 (fset 'calendar-cursor-to-date oldf))))))
9225 (defun org-agenda-execute-calendar-command (cmd)
9226 "Execute a calendar command from the agenda with date from cursor."
9227 (org-agenda-check-type t 'agenda 'timeline)
9228 (require 'diary-lib)
9229 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9230 (error "Don't know which date to use for the calendar command"))
9231 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9232 (point (point))
9233 (date (calendar-gregorian-from-absolute
9234 (get-text-property point 'day)))
9235 ;; the following 2 vars are needed in the calendar
9236 (displayed-month (car date))
9237 (displayed-year (nth 2 date)))
9238 (unwind-protect
9239 (progn
9240 (fset 'calendar-cursor-to-date
9241 (lambda (&optional error dummy)
9242 (calendar-gregorian-from-absolute
9243 (get-text-property point 'day))))
9244 (call-interactively cmd))
9245 (fset 'calendar-cursor-to-date oldf))))
9247 (defun org-agenda-phases-of-moon ()
9248 "Display the phases of the moon for the 3 months around the cursor date."
9249 (interactive)
9250 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9252 (defun org-agenda-holidays ()
9253 "Display the holidays for the 3 months around the cursor date."
9254 (interactive)
9255 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9257 (defvar calendar-longitude) ; defined in calendar.el
9258 (defvar calendar-latitude) ; defined in calendar.el
9259 (defvar calendar-location-name) ; defined in calendar.el
9261 (defun org-agenda-sunrise-sunset (arg)
9262 "Display sunrise and sunset for the cursor date.
9263 Latitude and longitude can be specified with the variables
9264 `calendar-latitude' and `calendar-longitude'. When called with prefix
9265 argument, latitude and longitude will be prompted for."
9266 (interactive "P")
9267 (require 'solar)
9268 (let ((calendar-longitude (if arg nil calendar-longitude))
9269 (calendar-latitude (if arg nil calendar-latitude))
9270 (calendar-location-name
9271 (if arg "the given coordinates" calendar-location-name)))
9272 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9274 (defun org-agenda-goto-calendar ()
9275 "Open the Emacs calendar with the date at the cursor."
9276 (interactive)
9277 (org-agenda-check-type t 'agenda 'timeline)
9278 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9279 (error "Don't know which date to open in calendar")))
9280 (date (calendar-gregorian-from-absolute day))
9281 (calendar-move-hook nil)
9282 (calendar-view-holidays-initially-flag nil)
9283 (calendar-view-diary-initially-flag nil))
9284 (calendar)
9285 (calendar-goto-date date)))
9287 ;;;###autoload
9288 (defun org-calendar-goto-agenda ()
9289 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9290 This is a command that has to be installed in `calendar-mode-map'."
9291 (interactive)
9292 (org-agenda-list nil (calendar-absolute-from-gregorian
9293 (calendar-cursor-to-date))
9294 nil))
9296 (defun org-agenda-convert-date ()
9297 (interactive)
9298 (org-agenda-check-type t 'agenda 'timeline)
9299 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9300 date s)
9301 (unless day
9302 (error "Don't know which date to convert"))
9303 (setq date (calendar-gregorian-from-absolute day))
9304 (setq s (concat
9305 "Gregorian: " (calendar-date-string date) "\n"
9306 "ISO: " (calendar-iso-date-string date) "\n"
9307 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9308 "Julian: " (calendar-julian-date-string date) "\n"
9309 "Astron. JD: " (calendar-astro-date-string date)
9310 " (Julian date number at noon UTC)\n"
9311 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9312 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9313 "French: " (calendar-french-date-string date) "\n"
9314 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9315 "Mayan: " (calendar-mayan-date-string date) "\n"
9316 "Coptic: " (calendar-coptic-date-string date) "\n"
9317 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9318 "Persian: " (calendar-persian-date-string date) "\n"
9319 "Chinese: " (calendar-chinese-date-string date) "\n"))
9320 (with-output-to-temp-buffer "*Dates*"
9321 (princ s))
9322 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9324 ;;; Bulk commands
9326 (defun org-agenda-bulk-marked-p ()
9327 (eq (get-char-property (point-at-bol) 'type)
9328 'org-marked-entry-overlay))
9330 (defun org-agenda-bulk-mark (&optional arg)
9331 "Mark the entry at point for future bulk action."
9332 (interactive "p")
9333 (dotimes (i (or arg 1))
9334 (unless (org-get-at-bol 'org-agenda-diary-link)
9335 (let* ((m (org-get-at-bol 'org-hd-marker))
9337 (unless (org-agenda-bulk-marked-p)
9338 (unless m (error "Nothing to mark at point"))
9339 (push m org-agenda-bulk-marked-entries)
9340 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9341 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9342 (org-get-todo-face "TODO")
9343 'evaporate)
9344 (overlay-put ov 'type 'org-marked-entry-overlay))
9345 (beginning-of-line 2)
9346 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9347 (beginning-of-line 2))
9348 (message "%d entries marked for bulk action"
9349 (length org-agenda-bulk-marked-entries))))))
9351 (defun org-agenda-bulk-mark-all ()
9352 "Mark all entries for future agenda bulk action."
9353 (interactive)
9354 (org-agenda-bulk-mark-regexp "."))
9356 (defun org-agenda-bulk-mark-regexp (regexp)
9357 "Mark entries matching REGEXP for future agenda bulk action."
9358 (interactive "sMark entries matching regexp: ")
9359 (let ((entries-marked 0))
9360 (save-excursion
9361 (goto-char (point-min))
9362 (goto-char (next-single-property-change (point) 'txt))
9363 (while (re-search-forward regexp nil t)
9364 (when (string-match regexp (get-text-property (point) 'txt))
9365 (setq entries-marked (1+ entries-marked))
9366 (call-interactively 'org-agenda-bulk-mark))))
9367 (if (not entries-marked)
9368 (message "No entry matching this regexp."))))
9370 (defun org-agenda-bulk-unmark (&optional arg)
9371 "Unmark the entry at point for future bulk action."
9372 (interactive "P")
9373 (if arg
9374 (org-agenda-bulk-unmark-all)
9375 (cond ((org-agenda-bulk-marked-p)
9376 (org-agenda-bulk-remove-overlays
9377 (point-at-bol) (+ 2 (point-at-bol)))
9378 (setq org-agenda-bulk-marked-entries
9379 (delete (org-get-at-bol 'org-hd-marker)
9380 org-agenda-bulk-marked-entries))
9381 (beginning-of-line 2)
9382 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9383 (beginning-of-line 2))
9384 (message "%d entries left marked for bulk action"
9385 (length org-agenda-bulk-marked-entries)))
9386 (t (message "No entry to unmark here")))))
9388 (defun org-agenda-bulk-toggle ()
9389 "Toggle marking the entry at point for bulk action."
9390 (interactive)
9391 (if (org-agenda-bulk-marked-p)
9392 (org-agenda-bulk-unmark)
9393 (org-agenda-bulk-mark)))
9395 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9396 "Remove the mark overlays between BEG and END in the agenda buffer.
9397 BEG and END default to the buffer limits.
9399 This only removes the overlays, it does not remove the markers
9400 from the list in `org-agenda-bulk-marked-entries'."
9401 (interactive)
9402 (mapc (lambda (ov)
9403 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9404 (delete-overlay ov)))
9405 (overlays-in (or beg (point-min)) (or end (point-max)))))
9407 (defun org-agenda-bulk-unmark-all ()
9408 "Remove all marks in the agenda buffer.
9409 This will remove the markers and the overlays."
9410 (interactive)
9411 (if (null org-agenda-bulk-marked-entries)
9412 (message "No entry to unmark")
9413 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9414 (setq org-agenda-bulk-marked-entries nil)
9415 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9417 (defcustom org-agenda-persistent-marks nil
9418 "Non-nil means marked items will stay marked after a bulk action.
9419 You can toggle this interactively by typing `p' when prompted for a
9420 bulk action."
9421 :group 'org-agenda
9422 :version "24.1"
9423 :type 'boolean)
9425 (defun org-agenda-bulk-action (&optional arg)
9426 "Execute an remote-editing action on all marked entries.
9427 The prefix arg is passed through to the command if possible."
9428 (interactive "P")
9429 ;; Make sure we have markers, and only valid ones
9430 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9431 (mapc
9432 (lambda (m)
9433 (unless (and (markerp m)
9434 (marker-buffer m)
9435 (buffer-live-p (marker-buffer m))
9436 (marker-position m))
9437 (error "Marker %s for bulk command is invalid" m)))
9438 org-agenda-bulk-marked-entries)
9440 ;; Prompt for the bulk command
9441 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9442 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9443 "[S]catter [f]unction "
9444 (when org-agenda-bulk-custom-functions
9445 (concat " Custom: ["
9446 (mapconcat (lambda(f) (char-to-string (car f)))
9447 org-agenda-bulk-custom-functions "")
9448 "]"))))
9449 (catch 'exit
9450 (let* ((action (read-char-exclusive))
9451 (org-log-refile (if org-log-refile 'time nil))
9452 (entries (reverse org-agenda-bulk-marked-entries))
9453 (org-overriding-default-time
9454 (if (get-text-property (point) 'org-agenda-date-header)
9455 (org-get-cursor-date)))
9456 redo-at-end
9457 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9458 (cond
9459 ((equal action ?p)
9460 (let ((org-agenda-persistent-marks
9461 (not org-agenda-persistent-marks)))
9462 (org-agenda-bulk-action)
9463 (throw 'exit nil)))
9465 ((equal action ?$)
9466 (setq cmd '(org-agenda-archive)))
9468 ((equal action ?A)
9469 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9471 ((member action '(?r ?w))
9472 (setq rfloc (org-refile-get-location
9473 "Refile to"
9474 (marker-buffer (car entries))
9475 org-refile-allow-creating-parent-nodes))
9476 (if (nth 3 rfloc)
9477 (setcar (nthcdr 3 rfloc)
9478 (move-marker (make-marker) (nth 3 rfloc)
9479 (or (get-file-buffer (nth 1 rfloc))
9480 (find-buffer-visiting (nth 1 rfloc))
9481 (error "This should not happen")))))
9483 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9484 redo-at-end t))
9486 ((equal action ?t)
9487 (setq state (org-icompleting-read
9488 "Todo state: "
9489 (with-current-buffer (marker-buffer (car entries))
9490 (mapcar 'list org-todo-keywords-1))))
9491 (setq cmd `(let ((org-inhibit-blocking t)
9492 (org-inhibit-logging 'note))
9493 (org-agenda-todo ,state))))
9495 ((memq action '(?- ?+))
9496 (setq tag (org-icompleting-read
9497 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9498 (with-current-buffer (marker-buffer (car entries))
9499 (delq nil
9500 (mapcar (lambda (x)
9501 (if (stringp (car x)) x)) org-tag-alist)))))
9502 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9504 ((memq action '(?s ?d))
9505 (let* ((time
9506 (unless arg
9507 (org-read-date
9508 nil nil nil
9509 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9510 org-overriding-default-time)))
9511 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9512 (setq cmd `(eval '(,c1 arg ,time)))))
9514 ((equal action ?S)
9515 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9516 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9517 (let ((days (read-number
9518 (format "Scatter tasks across how many %sdays: "
9519 (if arg "week" "")) 7)))
9520 (setq cmd
9521 `(let ((distance (1+ (random ,days))))
9522 (if arg
9523 (let ((dist distance)
9524 (day-of-week
9525 (calendar-day-of-week
9526 (calendar-gregorian-from-absolute (org-today)))))
9527 (dotimes (i (1+ dist))
9528 (while (member day-of-week org-agenda-weekend-days)
9529 (incf distance)
9530 (incf day-of-week)
9531 (if (= day-of-week 7)
9532 (setq day-of-week 0)))
9533 (incf day-of-week)
9534 (if (= day-of-week 7)
9535 (setq day-of-week 0)))))
9536 ;; silently fail when try to replan a sexp entry
9537 (condition-case nil
9538 (let* ((date (calendar-gregorian-from-absolute
9539 (+ (org-today) distance)))
9540 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9541 (nth 2 date))))
9542 (org-agenda-schedule nil time))
9543 (error nil)))))))
9545 ((assoc action org-agenda-bulk-custom-functions)
9546 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9547 redo-at-end t))
9549 ((equal action ?f)
9550 (setq cmd (list (intern
9551 (org-icompleting-read "Function: "
9552 obarray 'fboundp t nil nil)))))
9554 (t (error "Invalid bulk action")))
9556 ;; Sort the markers, to make sure that parents are handled before children
9557 (setq entries (sort entries
9558 (lambda (a b)
9559 (cond
9560 ((equal (marker-buffer a) (marker-buffer b))
9561 (< (marker-position a) (marker-position b)))
9563 (string< (buffer-name (marker-buffer a))
9564 (buffer-name (marker-buffer b))))))))
9566 ;; Now loop over all markers and apply cmd
9567 (while (setq e (pop entries))
9568 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9569 (if (not pos)
9570 (progn (message "Skipping removed entry at %s" e)
9571 (setq cntskip (1+ cntskip)))
9572 (goto-char pos)
9573 (let (org-loop-over-headlines-in-active-region)
9574 (eval cmd))
9575 (setq cnt (1+ cnt))))
9576 (when redo-at-end (org-agenda-redo))
9577 (unless org-agenda-persistent-marks
9578 (org-agenda-bulk-unmark-all))
9579 (message "Acted on %d entries%s%s"
9581 (if (= cntskip 0)
9583 (format ", skipped %d (disappeared before their turn)"
9584 cntskip))
9585 (if (not org-agenda-persistent-marks)
9586 "" " (kept marked)"))))))
9588 (defun org-agenda-capture (&optional with-time)
9589 "Call `org-capture' with the date at point.
9590 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9591 current HH:MM time."
9592 (interactive "P")
9593 (if (not (eq major-mode 'org-agenda-mode))
9594 (user-error "You cannot do this outside of agenda buffers")
9595 (let ((org-overriding-default-time
9596 (org-get-cursor-date (equal with-time 1))))
9597 (call-interactively 'org-capture))))
9599 ;;; Flagging notes
9601 (defun org-agenda-show-the-flagging-note ()
9602 "Display the flagging note in the other window.
9603 When called a second time in direct sequence, offer to remove the FLAGGING
9604 tag and (if present) the flagging note."
9605 (interactive)
9606 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9607 (win (selected-window))
9608 note heading newhead)
9609 (unless hdmarker
9610 (error "No linked entry at point"))
9611 (if (and (eq this-command last-command)
9612 (y-or-n-p "Unflag and remove any flagging note? "))
9613 (progn
9614 (org-agenda-remove-flag hdmarker)
9615 (let ((win (get-buffer-window "*Flagging Note*")))
9616 (and win (delete-window win)))
9617 (message "Entry unflagged"))
9618 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9619 (unless note
9620 (error "No flagging note"))
9621 (org-kill-new note)
9622 (org-switch-to-buffer-other-window "*Flagging Note*")
9623 (erase-buffer)
9624 (insert note)
9625 (goto-char (point-min))
9626 (while (re-search-forward "\\\\n" nil t)
9627 (replace-match "\n" t t))
9628 (goto-char (point-min))
9629 (select-window win)
9630 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9632 (defun org-agenda-remove-flag (marker)
9633 "Remove the FLAGGED tag and any flagging note in the entry."
9634 (let (newhead)
9635 (org-with-point-at marker
9636 (org-toggle-tag "FLAGGED" 'off)
9637 (org-entry-delete nil "THEFLAGGINGNOTE")
9638 (setq newhead (org-get-heading)))
9639 (org-agenda-change-all-lines newhead marker)
9640 (message "Entry unflagged")))
9642 (defun org-agenda-get-any-marker (&optional pos)
9643 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9644 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9646 ;;; Appointment reminders
9648 (defvar appt-time-msg-list) ; defined in appt.el
9650 ;;;###autoload
9651 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9652 "Activate appointments found in `org-agenda-files'.
9653 With a \\[universal-argument] prefix, refresh the list of
9654 appointments.
9656 If FILTER is t, interactively prompt the user for a regular
9657 expression, and filter out entries that don't match it.
9659 If FILTER is a string, use this string as a regular expression
9660 for filtering entries out.
9662 If FILTER is a function, filter out entries against which
9663 calling the function returns nil. This function takes one
9664 argument: an entry from `org-agenda-get-day-entries'.
9666 FILTER can also be an alist with the car of each cell being
9667 either 'headline or 'category. For example:
9669 '((headline \"IMPORTANT\")
9670 (category \"Work\"))
9672 will only add headlines containing IMPORTANT or headlines
9673 belonging to the \"Work\" category.
9675 ARGS are symbols indicating what kind of entries to consider.
9676 By default `org-agenda-to-appt' will use :deadline, :scheduled
9677 and :timestamp entries. See the docstring of `org-diary' for
9678 details and examples.
9680 If an entry has a APPT_WARNTIME property, its value will be used
9681 to override `appt-message-warning-time'."
9682 (interactive "P")
9683 (if refresh (setq appt-time-msg-list nil))
9684 (if (eq filter t)
9685 (setq filter (read-from-minibuffer "Regexp filter: ")))
9686 (let* ((cnt 0) ; count added events
9687 (scope (or args '(:deadline :scheduled :timestamp)))
9688 (org-agenda-new-buffers nil)
9689 (org-deadline-warning-days 0)
9690 ;; Do not use `org-today' here because appt only takes
9691 ;; time and without date as argument, so it may pass wrong
9692 ;; information otherwise
9693 (today (org-date-to-gregorian
9694 (time-to-days (current-time))))
9695 (org-agenda-restrict nil)
9696 (files (org-agenda-files 'unrestricted)) entries file
9697 (org-agenda-buffer nil))
9698 ;; Get all entries which may contain an appt
9699 (org-agenda-prepare-buffers files)
9700 (while (setq file (pop files))
9701 (setq entries
9702 (delq nil
9703 (append entries
9704 (apply 'org-agenda-get-day-entries
9705 file today scope)))))
9706 ;; Map thru entries and find if we should filter them out
9707 (mapc
9708 (lambda(x)
9709 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9710 (cat (get-text-property 1 'org-category x))
9711 (tod (get-text-property 1 'time-of-day x))
9712 (ok (or (null filter)
9713 (and (stringp filter) (string-match filter evt))
9714 (and (functionp filter) (funcall filter x))
9715 (and (listp filter)
9716 (let ((cat-filter (cadr (assoc 'category filter)))
9717 (evt-filter (cadr (assoc 'headline filter))))
9718 (or (and (stringp cat-filter)
9719 (string-match cat-filter cat))
9720 (and (stringp evt-filter)
9721 (string-match evt-filter evt)))))))
9722 (wrn (get-text-property 1 'warntime x)))
9723 ;; FIXME: Shall we remove text-properties for the appt text?
9724 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9725 (when (and ok tod)
9726 (setq tod (concat "00" (number-to-string tod))
9727 tod (when (string-match
9728 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9729 (concat (match-string 1 tod) ":"
9730 (match-string 2 tod))))
9731 (if (version< emacs-version "23.3")
9732 (appt-add tod evt)
9733 (appt-add tod evt wrn))
9734 (setq cnt (1+ cnt))))) entries)
9735 (org-release-buffers org-agenda-new-buffers)
9736 (if (eq cnt 0)
9737 (message "No event to add")
9738 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9740 (defun org-agenda-todayp (date)
9741 "Does DATE mean today, when considering `org-extend-today-until'?"
9742 (let ((today (org-today))
9743 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9744 date)))
9745 (eq date today)))
9747 (defun org-agenda-todo-yesterday (&optional arg)
9748 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9749 (interactive "P")
9750 (let* ((hour (third (decode-time
9751 (org-current-time))))
9752 (org-extend-today-until (1+ hour)))
9753 (org-agenda-todo arg)))
9755 (provide 'org-agenda)
9757 ;;; org-agenda.el ends here