Merge branch 'maint'
[org-mode.git] / lisp / org-agenda.el
blob414fd2b833cf035b2204054eda531c1465d18101
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 (defcustom org-agenda-entry-text-leaders " > "
992 "Text prepended to the entry text in agenda buffers."
993 :version "24.4"
994 :package-version '(Org . "8.0")
995 :group 'org-agenda
996 :type 'string)
998 (defvar org-agenda-entry-text-cleanup-hook nil
999 "Hook that is run after basic cleanup of entry text to be shown in agenda.
1000 This cleanup is done in a temporary buffer, so the function may inspect and
1001 change the entire buffer.
1002 Some default stuff like drawers and scheduling/deadline dates will already
1003 have been removed when this is called, as will any matches for regular
1004 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
1006 (defvar org-agenda-include-inactive-timestamps nil
1007 "Non-nil means include inactive time stamps in agenda and timeline.
1008 Dynamically scoped.")
1010 (defgroup org-agenda-windows nil
1011 "Options concerning the windows used by the Agenda in Org Mode."
1012 :tag "Org Agenda Windows"
1013 :group 'org-agenda)
1015 (defcustom org-agenda-window-setup 'reorganize-frame
1016 "How the agenda buffer should be displayed.
1017 Possible values for this option are:
1019 current-window Show agenda in the current window, keeping all other windows.
1020 other-window Use `switch-to-buffer-other-window' to display agenda.
1021 reorganize-frame Show only two windows on the current frame, the current
1022 window and the agenda.
1023 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1024 Also, when exiting the agenda, kill that frame.
1025 See also the variable `org-agenda-restore-windows-after-quit'."
1026 :group 'org-agenda-windows
1027 :type '(choice
1028 (const current-window)
1029 (const other-frame)
1030 (const other-window)
1031 (const reorganize-frame)))
1033 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1034 "The min and max height of the agenda window as a fraction of frame height.
1035 The value of the variable is a cons cell with two numbers between 0 and 1.
1036 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1037 :group 'org-agenda-windows
1038 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1040 (defcustom org-agenda-restore-windows-after-quit nil
1041 "Non-nil means restore window configuration upon exiting agenda.
1042 Before the window configuration is changed for displaying the agenda,
1043 the current status is recorded. When the agenda is exited with
1044 `q' or `x' and this option is set, the old state is restored. If
1045 `org-agenda-window-setup' is `other-frame', the value of this
1046 option will be ignored."
1047 :group 'org-agenda-windows
1048 :type 'boolean)
1050 (defcustom org-agenda-ndays nil
1051 "Number of days to include in overview display.
1052 Should be 1 or 7.
1053 Obsolete, see `org-agenda-span'."
1054 :group 'org-agenda-daily/weekly
1055 :type 'integer)
1057 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1059 (defcustom org-agenda-span 'week
1060 "Number of days to include in overview display.
1061 Can be day, week, month, year, or any number of days.
1062 Custom commands can set this variable in the options section."
1063 :group 'org-agenda-daily/weekly
1064 :type '(choice (const :tag "Day" day)
1065 (const :tag "Week" week)
1066 (const :tag "Month" month)
1067 (const :tag "Year" year)
1068 (integer :tag "Custom")))
1070 (defcustom org-agenda-start-on-weekday 1
1071 "Non-nil means start the overview always on the specified weekday.
1072 0 denotes Sunday, 1 denotes Monday etc.
1073 When nil, always start on the current day.
1074 Custom commands can set this variable in the options section."
1075 :group 'org-agenda-daily/weekly
1076 :type '(choice (const :tag "Today" nil)
1077 (integer :tag "Weekday No.")))
1079 (defcustom org-agenda-show-all-dates t
1080 "Non-nil means `org-agenda' shows every day in the selected range.
1081 When nil, only the days which actually have entries are shown."
1082 :group 'org-agenda-daily/weekly
1083 :type 'boolean)
1085 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1086 "Format string for displaying dates in the agenda.
1087 Used by the daily/weekly agenda and by the timeline. This should be
1088 a format string understood by `format-time-string', or a function returning
1089 the formatted date as a string. The function must take a single argument,
1090 a calendar-style date list like (month day year)."
1091 :group 'org-agenda-daily/weekly
1092 :type '(choice
1093 (string :tag "Format string")
1094 (function :tag "Function")))
1096 (defun org-agenda-format-date-aligned (date)
1097 "Format a date string for display in the daily/weekly agenda, or timeline.
1098 This function makes sure that dates are aligned for easy reading."
1099 (require 'cal-iso)
1100 (let* ((dayname (calendar-day-name date))
1101 (day (cadr date))
1102 (day-of-week (calendar-day-of-week date))
1103 (month (car date))
1104 (monthname (calendar-month-name month))
1105 (year (nth 2 date))
1106 (iso-week (org-days-to-iso-week
1107 (calendar-absolute-from-gregorian date)))
1108 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1109 (1- year))
1110 ((and (= month 12) (<= iso-week 1))
1111 (1+ year))
1112 (t year)))
1113 (weekstring (if (= day-of-week 1)
1114 (format " W%02d" iso-week)
1115 "")))
1116 (format "%-10s %2d %s %4d%s"
1117 dayname day monthname year weekstring)))
1119 (defcustom org-agenda-time-leading-zero nil
1120 "Non-nil means use leading zero for military times in agenda.
1121 For example, 9:30am would become 09:30 rather than 9:30."
1122 :group 'org-agenda-daily/weekly
1123 :version "24.1"
1124 :type 'boolean)
1126 (defcustom org-agenda-timegrid-use-ampm nil
1127 "When set, show AM/PM style timestamps on the timegrid."
1128 :group 'org-agenda
1129 :version "24.1"
1130 :type 'boolean)
1132 (defun org-agenda-time-of-day-to-ampm (time)
1133 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1134 (let* ((hour-number (string-to-number (substring time 0 -3)))
1135 (minute (substring time -2))
1136 (ampm "am"))
1137 (cond
1138 ((equal hour-number 12)
1139 (setq ampm "pm"))
1140 ((> hour-number 12)
1141 (setq ampm "pm")
1142 (setq hour-number (- hour-number 12))))
1143 (concat
1144 (if org-agenda-time-leading-zero
1145 (format "%02d" hour-number)
1146 (format "%02s" (number-to-string hour-number)))
1147 ":" minute ampm)))
1149 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1150 "Conditionally convert TIME to AM/PM format
1151 based on `org-agenda-timegrid-use-ampm'"
1152 (if org-agenda-timegrid-use-ampm
1153 (org-agenda-time-of-day-to-ampm time)
1154 time))
1156 (defcustom org-agenda-weekend-days '(6 0)
1157 "Which days are weekend?
1158 These days get the special face `org-agenda-date-weekend' in the agenda
1159 and timeline buffers."
1160 :group 'org-agenda-daily/weekly
1161 :type '(set :greedy t
1162 (const :tag "Monday" 1)
1163 (const :tag "Tuesday" 2)
1164 (const :tag "Wednesday" 3)
1165 (const :tag "Thursday" 4)
1166 (const :tag "Friday" 5)
1167 (const :tag "Saturday" 6)
1168 (const :tag "Sunday" 0)))
1170 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1171 "Non-nil means jump to today when moving a past date forward in time.
1172 When using S-right in the agenda to move a a date forward, and the date
1173 stamp currently points to the past, the first key press will move it
1174 to today. WHen nil, just move one day forward even if the date stays
1175 in the past."
1176 :group 'org-agenda-daily/weekly
1177 :version "24.1"
1178 :type 'boolean)
1180 (defcustom org-agenda-include-diary nil
1181 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1182 Custom commands can set this variable in the options section."
1183 :group 'org-agenda-daily/weekly
1184 :type 'boolean)
1186 (defcustom org-agenda-include-deadlines t
1187 "If non-nil, include entries within their deadline warning period.
1188 Custom commands can set this variable in the options section."
1189 :group 'org-agenda-daily/weekly
1190 :version "24.1"
1191 :type 'boolean)
1193 (defcustom org-agenda-repeating-timestamp-show-all t
1194 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1195 When set to a list of strings, only show occurrences of repeating
1196 stamps for these TODO keywords. When nil, only one occurrence is
1197 shown, either today or the nearest into the future."
1198 :group 'org-agenda-daily/weekly
1199 :type '(choice
1200 (const :tag "Show repeating stamps" t)
1201 (repeat :tag "Show repeating stamps for these TODO keywords"
1202 (string :tag "TODO Keyword"))
1203 (const :tag "Don't show repeating stamps" nil)))
1205 (defcustom org-scheduled-past-days 10000
1206 "No. of days to continue listing scheduled items that are not marked DONE.
1207 When an item is scheduled on a date, it shows up in the agenda on this
1208 day and will be listed until it is marked done for the number of days
1209 given here."
1210 :group 'org-agenda-daily/weekly
1211 :type 'integer)
1213 (defcustom org-agenda-log-mode-items '(closed clock)
1214 "List of items that should be shown in agenda log mode.
1215 This list may contain the following symbols:
1217 closed Show entries that have been closed on that day.
1218 clock Show entries that have received clocked time on that day.
1219 state Show all logged state changes.
1220 Note that instead of changing this variable, you can also press `C-u l' in
1221 the agenda to display all available LOG items temporarily."
1222 :group 'org-agenda-daily/weekly
1223 :type '(set :greedy t (const closed) (const clock) (const state)))
1225 (defcustom org-agenda-clock-consistency-checks
1226 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1227 :gap-ok-around ("4:00")
1228 :default-face ((:background "DarkRed") (:foreground "white"))
1229 :overlap-face nil :gap-face nil :no-end-time-face nil
1230 :long-face nil :short-face nil)
1231 "This is a property list, with the following keys:
1233 :max-duration Mark clocking chunks that are longer than this time.
1234 This is a time string like \"HH:MM\", or the number
1235 of minutes as an integer.
1237 :min-duration Mark clocking chunks that are shorter that this.
1238 This is a time string like \"HH:MM\", or the number
1239 of minutes as an integer.
1241 :max-gap Mark gaps between clocking chunks that are longer than
1242 this duration. A number of minutes, or a string
1243 like \"HH:MM\".
1245 :gap-ok-around List of times during the day which are usually not working
1246 times. When a gap is detected, but the gap contains any
1247 of these times, the gap is *not* reported. For example,
1248 if this is (\"4:00\" \"13:00\") then gaps that contain
1249 4:00 in the morning (i.e. the night) and 13:00
1250 (i.e. a typical lunch time) do not cause a warning.
1251 You should have at least one time during the night in this
1252 list, or otherwise the first task each morning will trigger
1253 a warning because it follows a long gap.
1255 Furthermore, the following properties can be used to define faces for
1256 issue display.
1258 :default-face the default face, if the specific face is undefined
1259 :overlap-face face for overlapping clocks
1260 :gap-face face for gaps between clocks
1261 :no-end-time-face face for incomplete clocks
1262 :long-face face for clock intervals that are too long
1263 :short-face face for clock intervals that are too short"
1264 :group 'org-agenda-daily/weekly
1265 :group 'org-clock
1266 :version "24.1"
1267 :type 'plist)
1269 (defcustom org-agenda-log-mode-add-notes t
1270 "Non-nil means add first line of notes to log entries in agenda views.
1271 If a log item like a state change or a clock entry is associated with
1272 notes, the first line of these notes will be added to the entry in the
1273 agenda display."
1274 :group 'org-agenda-daily/weekly
1275 :type 'boolean)
1277 (defcustom org-agenda-start-with-log-mode nil
1278 "The initial value of log-mode in a newly created agenda window.
1279 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1280 explanations on the possible values."
1281 :group 'org-agenda-startup
1282 :group 'org-agenda-daily/weekly
1283 :type '(choice (const :tag "Don't show log items" nil)
1284 (const :tag "Show only log items" 'only)
1285 (const :tag "Show all possible log items" 'clockcheck)
1286 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1287 (choice (const :tag "Show closed log items" 'closed)
1288 (const :tag "Show clocked log items" 'clock)
1289 (const :tag "Show all logged state changes" 'state)))))
1291 (defcustom org-agenda-start-with-clockreport-mode nil
1292 "The initial value of clockreport-mode in a newly created agenda window."
1293 :group 'org-agenda-startup
1294 :group 'org-agenda-daily/weekly
1295 :type 'boolean)
1297 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1298 "Property list with parameters for the clocktable in clockreport mode.
1299 This is the display mode that shows a clock table in the daily/weekly
1300 agenda, the properties for this dynamic block can be set here.
1301 The usual clocktable parameters are allowed here, but you cannot set
1302 the properties :name, :tstart, :tend, :block, and :scope - these will
1303 be overwritten to make sure the content accurately reflects the
1304 current display in the agenda."
1305 :group 'org-agenda-daily/weekly
1306 :type 'plist)
1308 (defcustom org-agenda-search-view-always-boolean nil
1309 "Non-nil means the search string is interpreted as individual parts.
1311 The search string for search view can either be interpreted as a phrase,
1312 or as a list of snippets that define a boolean search for a number of
1313 strings.
1315 When this is non-nil, the string will be split on whitespace, and each
1316 snippet will be searched individually, and all must match in order to
1317 select an entry. A snippet is then a single string of non-white
1318 characters, or a string in double quotes, or a regexp in {} braces.
1319 If a snippet is preceded by \"-\", the snippet must *not* match.
1320 \"+\" is syntactic sugar for positive selection. Each snippet may
1321 be found as a full word or a partial word, but see the variable
1322 `org-agenda-search-view-force-full-words'.
1324 When this is nil, search will look for the entire search phrase as one,
1325 with each space character matching any amount of whitespace, including
1326 line breaks.
1328 Even when this is nil, you can still switch to Boolean search dynamically
1329 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1330 is a regexp marked with braces like \"{abc}\", this will also switch to
1331 boolean search."
1332 :group 'org-agenda-search-view
1333 :version "24.1"
1334 :type 'boolean)
1336 (if (fboundp 'defvaralias)
1337 (defvaralias 'org-agenda-search-view-search-words-only
1338 'org-agenda-search-view-always-boolean))
1340 (defcustom org-agenda-search-view-force-full-words nil
1341 "Non-nil means, search words must be matches as complete words.
1342 When nil, they may also match part of a word."
1343 :group 'org-agenda-search-view
1344 :version "24.1"
1345 :type 'boolean)
1347 (defcustom org-agenda-search-view-max-outline-level nil
1348 "Maximum outline level to display in search view.
1349 E.g. when this is set to 1, the search view will only
1350 show headlines of level 1."
1351 :group 'org-agenda-search-view
1352 :version "24.4"
1353 :package-version '(Org . "8.0")
1354 :type 'integer)
1356 (defgroup org-agenda-time-grid nil
1357 "Options concerning the time grid in the Org-mode Agenda."
1358 :tag "Org Agenda Time Grid"
1359 :group 'org-agenda)
1361 (defcustom org-agenda-search-headline-for-time t
1362 "Non-nil means search headline for a time-of-day.
1363 If the headline contains a time-of-day in one format or another, it will
1364 be used to sort the entry into the time sequence of items for a day.
1365 Some people have time stamps in the headline that refer to the creation
1366 time or so, and then this produces an unwanted side effect. If this is
1367 the case for your, use this variable to turn off searching the headline
1368 for a time."
1369 :group 'org-agenda-time-grid
1370 :type 'boolean)
1372 (defcustom org-agenda-use-time-grid t
1373 "Non-nil means show a time grid in the agenda schedule.
1374 A time grid is a set of lines for specific times (like every two hours between
1375 8:00 and 20:00). The items scheduled for a day at specific times are
1376 sorted in between these lines.
1377 For details about when the grid will be shown, and what it will look like, see
1378 the variable `org-agenda-time-grid'."
1379 :group 'org-agenda-time-grid
1380 :type 'boolean)
1382 (defcustom org-agenda-time-grid
1383 '((daily today require-timed)
1384 "----------------"
1385 (800 1000 1200 1400 1600 1800 2000))
1387 "The settings for time grid for agenda display.
1388 This is a list of three items. The first item is again a list. It contains
1389 symbols specifying conditions when the grid should be displayed:
1391 daily if the agenda shows a single day
1392 weekly if the agenda shows an entire week
1393 today show grid on current date, independent of daily/weekly display
1394 require-timed show grid only if at least one item has a time specification
1396 The second item is a string which will be placed behind the grid time.
1398 The third item is a list of integers, indicating the times that should have
1399 a grid line."
1400 :group 'org-agenda-time-grid
1401 :type
1402 '(list
1403 (set :greedy t :tag "Grid Display Options"
1404 (const :tag "Show grid in single day agenda display" daily)
1405 (const :tag "Show grid in weekly agenda display" weekly)
1406 (const :tag "Always show grid for today" today)
1407 (const :tag "Show grid only if any timed entries are present"
1408 require-timed)
1409 (const :tag "Skip grid times already present in an entry"
1410 remove-match))
1411 (string :tag "Grid String")
1412 (repeat :tag "Grid Times" (integer :tag "Time"))))
1414 (defcustom org-agenda-show-current-time-in-grid t
1415 "Non-nil means show the current time in the time grid."
1416 :group 'org-agenda-time-grid
1417 :version "24.1"
1418 :type 'boolean)
1420 (defcustom org-agenda-current-time-string
1421 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1422 "The string for the current time marker in the agenda."
1423 :group 'org-agenda-time-grid
1424 :version "24.1"
1425 :type 'string)
1427 (defgroup org-agenda-sorting nil
1428 "Options concerning sorting in the Org-mode Agenda."
1429 :tag "Org Agenda Sorting"
1430 :group 'org-agenda)
1432 (defcustom org-agenda-sorting-strategy
1433 '((agenda habit-down time-up priority-down category-keep)
1434 (todo priority-down category-keep)
1435 (tags priority-down category-keep)
1436 (search category-keep))
1437 "Sorting structure for the agenda items of a single day.
1438 This is a list of symbols which will be used in sequence to determine
1439 if an entry should be listed before another entry. The following
1440 symbols are recognized:
1442 time-up Put entries with time-of-day indications first, early first
1443 time-down Put entries with time-of-day indications first, late first
1444 timestamp-up Sort by any timestamp, early first
1445 timestamp-down Sort by any timestamp, late first
1446 scheduled-up Sort by scheduled timestamp, early first
1447 scheduled-down Sort by scheduled timestamp, late first
1448 deadline-up Sort by deadline timestamp, early first
1449 deadline-down Sort by deadline timestamp, late first
1450 ts-up Sort by active timestamp, early first
1451 ts-down Sort by active timestamp, late first
1452 tsia-up Sort by inactive timestamp, early first
1453 tsia-down Sort by inactive timestamp, late first
1454 category-keep Keep the default order of categories, corresponding to the
1455 sequence in `org-agenda-files'.
1456 category-up Sort alphabetically by category, A-Z.
1457 category-down Sort alphabetically by category, Z-A.
1458 tag-up Sort alphabetically by last tag, A-Z.
1459 tag-down Sort alphabetically by last tag, Z-A.
1460 priority-up Sort numerically by priority, high priority last.
1461 priority-down Sort numerically by priority, high priority first.
1462 todo-state-up Sort by todo state, tasks that are done last.
1463 todo-state-down Sort by todo state, tasks that are done first.
1464 effort-up Sort numerically by estimated effort, high effort last.
1465 effort-down Sort numerically by estimated effort, high effort first.
1466 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1467 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1468 habit-up Put entries that are habits first
1469 habit-down Put entries that are habits last
1470 alpha-up Sort headlines alphabetically
1471 alpha-down Sort headlines alphabetically, reversed
1473 The different possibilities will be tried in sequence, and testing stops
1474 if one comparison returns a \"not-equal\". For example, the default
1475 '(time-up category-keep priority-down)
1476 means: Pull out all entries having a specified time of day and sort them,
1477 in order to make a time schedule for the current day the first thing in the
1478 agenda listing for the day. Of the entries without a time indication, keep
1479 the grouped in categories, don't sort the categories, but keep them in
1480 the sequence given in `org-agenda-files'. Within each category sort by
1481 priority.
1483 Leaving out `category-keep' would mean that items will be sorted across
1484 categories by priority.
1486 Instead of a single list, this can also be a set of list for specific
1487 contents, with a context symbol in the car of the list, any of
1488 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1490 Custom commands can bind this variable in the options section."
1491 :group 'org-agenda-sorting
1492 :type `(choice
1493 (repeat :tag "General" ,org-sorting-choice)
1494 (list :tag "Individually"
1495 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1496 (repeat ,org-sorting-choice))
1497 (cons (const :tag "Strategy for TODO lists" todo)
1498 (repeat ,org-sorting-choice))
1499 (cons (const :tag "Strategy for Tags matches" tags)
1500 (repeat ,org-sorting-choice))
1501 (cons (const :tag "Strategy for search matches" search)
1502 (repeat ,org-sorting-choice)))))
1504 (defcustom org-agenda-cmp-user-defined nil
1505 "A function to define the comparison `user-defined'.
1506 This function must receive two arguments, agenda entry a and b.
1507 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1508 the user comparison, return nil.
1509 When this is defined, you can make `user-defined-up' and `user-defined-down'
1510 part of an agenda sorting strategy."
1511 :group 'org-agenda-sorting
1512 :type 'symbol)
1514 (defcustom org-sort-agenda-notime-is-late t
1515 "Non-nil means items without time are considered late.
1516 This is only relevant for sorting. When t, items which have no explicit
1517 time like 15:30 will be considered as 99:01, i.e. later than any items which
1518 do have a time. When nil, the default time is before 0:00. You can use this
1519 option to decide if the schedule for today should come before or after timeless
1520 agenda entries."
1521 :group 'org-agenda-sorting
1522 :type 'boolean)
1524 (defcustom org-sort-agenda-noeffort-is-high t
1525 "Non-nil means items without effort estimate are sorted as high effort.
1526 This also applies when filtering an agenda view with respect to the
1527 < or > effort operator. Then, tasks with no effort defined will be treated
1528 as tasks with high effort.
1529 When nil, such items are sorted as 0 minutes effort."
1530 :group 'org-agenda-sorting
1531 :type 'boolean)
1533 (defgroup org-agenda-line-format nil
1534 "Options concerning the entry prefix in the Org-mode agenda display."
1535 :tag "Org Agenda Line Format"
1536 :group 'org-agenda)
1538 (defcustom org-agenda-prefix-format
1539 '((agenda . " %i %-12:c%?-12t% s")
1540 (timeline . " % s")
1541 (todo . " %i %-12:c")
1542 (tags . " %i %-12:c")
1543 (search . " %i %-12:c"))
1544 "Format specifications for the prefix of items in the agenda views.
1545 An alist with five entries, each for the different agenda types. The
1546 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1547 The values are format strings.
1549 This format works similar to a printf format, with the following meaning:
1551 %c the category of the item, \"Diary\" for entries from the diary,
1552 or as given by the CATEGORY keyword or derived from the file name
1553 %e the effort required by the item
1554 %l the level of the item (insert X space(s) if item is of level X)
1555 %i the icon category of the item, see `org-agenda-category-icon-alist'
1556 %T the last tag of the item (ignore inherited tags, which come first)
1557 %t the HH:MM time-of-day specification if one applies to the entry
1558 %s Scheduling/Deadline information, a short string
1559 %b show breadcrumbs, i.e., the names of the higher levels
1560 %(expression) Eval EXPRESSION and replace the control string
1561 by the result
1563 All specifiers work basically like the standard `%s' of printf, but may
1564 contain two additional characters: a question mark just after the `%'
1565 and a whitespace/punctuation character just before the final letter.
1567 If the first character after `%' is a question mark, the entire field
1568 will only be included if the corresponding value applies to the current
1569 entry. This is useful for fields which should have fixed width when
1570 present, but zero width when absent. For example, \"%?-12t\" will
1571 result in a 12 character time field if a time of the day is specified,
1572 but will completely disappear in entries which do not contain a time.
1574 If there is punctuation or whitespace character just before the
1575 final format letter, this character will be appended to the field
1576 value if the value is not empty. For example, the format
1577 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1578 the category is empty, no additional colon is inserted.
1580 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1581 which means:
1583 - Indent the line with two space characters
1584 - Give the category a 12 chars wide field, padded with whitespace on
1585 the right (because of `-'). Append a colon if there is a category
1586 (because of `:').
1587 - If there is a time-of-day, put it into a 12 chars wide field. If no
1588 time, don't put in an empty field, just skip it (because of '?').
1589 - Finally, put the scheduling information.
1591 See also the variables `org-agenda-remove-times-when-in-prefix' and
1592 `org-agenda-remove-tags'.
1594 Custom commands can set this variable in the options section."
1595 :type '(choice
1596 (string :tag "General format")
1597 (list :greedy t :tag "View dependent"
1598 (cons (const agenda) (string :tag "Format"))
1599 (cons (const timeline) (string :tag "Format"))
1600 (cons (const todo) (string :tag "Format"))
1601 (cons (const tags) (string :tag "Format"))
1602 (cons (const search) (string :tag "Format"))))
1603 :group 'org-agenda-line-format)
1605 (defvar org-prefix-format-compiled nil
1606 "The compiled prefix format and associated variables.
1607 This is a list where first element is a list of variable bindings, and second
1608 element is the compiled format expression. See the variable
1609 `org-agenda-prefix-format'.")
1611 (defcustom org-agenda-todo-keyword-format "%-1s"
1612 "Format for the TODO keyword in agenda lines.
1613 Set this to something like \"%-12s\" if you want all TODO keywords
1614 to occupy a fixed space in the agenda display."
1615 :group 'org-agenda-line-format
1616 :type 'string)
1618 (defcustom org-agenda-diary-sexp-prefix nil
1619 "A regexp that matches part of a diary sexp entry
1620 which should be treated as scheduling/deadline information in
1621 `org-agenda'.
1623 For example, you can use this to extract the `diary-remind-message' from
1624 `diary-remind' entries."
1625 :group 'org-agenda-line-format
1626 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1628 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1629 "Text preceding timerange entries in the agenda view.
1630 This is a list with two strings. The first applies when the range
1631 is entirely on one day. The second applies if the range spans several days.
1632 The strings may have two \"%d\" format specifiers which will be filled
1633 with the sequence number of the days, and the total number of days in the
1634 range, respectively."
1635 :group 'org-agenda-line-format
1636 :type '(list
1637 (string :tag "Deadline today ")
1638 (choice :tag "Deadline relative"
1639 (string :tag "Format string")
1640 (function))))
1642 (defcustom org-agenda-scheduled-leaders '(" Scheduled: " "Sched.%3dx: ")
1643 "Text preceding scheduled items in the agenda view.
1644 This is a list with two strings. The first applies when the item is
1645 scheduled on the current day. The second applies when it has been scheduled
1646 previously, it may contain a %d indicating that this is the nth time that
1647 this item is scheduled, due to automatic rescheduling of unfinished items
1648 for the following day. So this number is one larger than the number of days
1649 that passed since this item was scheduled first."
1650 :group 'org-agenda-line-format
1651 :version "24.4"
1652 :package-version '(Org . "8.0")
1653 :type '(list
1654 (string :tag "Scheduled today ")
1655 (string :tag "Scheduled previously")))
1657 (defcustom org-agenda-inactive-leader "["
1658 "Text preceding item pulled into the agenda by inactive time stamps.
1659 These entries are added to the agenda when pressing \"[\"."
1660 :group 'org-agenda-line-format
1661 :version "24.1"
1662 :type '(list
1663 (string :tag "Scheduled today ")
1664 (string :tag "Scheduled previously")))
1666 (defcustom org-agenda-deadline-leaders '(" Deadline: " " In %3d d.: " "%3d d. ago: ")
1667 "Text preceding deadline items in the agenda view.
1668 This is a list with three strings. The first applies when the item has its
1669 deadline on the current day. The second applies when the deadline is in the
1670 future, the third one when it is in the past. The strings may contain %d
1671 to capture the number of days."
1672 :group 'org-agenda-line-format
1673 :version "24.4"
1674 :package-version '(Org . "8.0")
1675 :type '(list
1676 (string :tag "Deadline today ")
1677 (choice :tag "Deadline relative"
1678 (string :tag "Format string")
1679 (function))))
1681 (defcustom org-agenda-remove-times-when-in-prefix t
1682 "Non-nil means remove duplicate time specifications in agenda items.
1683 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1684 time-of-day specification in a headline or diary entry is extracted and
1685 placed into the prefix. If this option is non-nil, the original specification
1686 \(a timestamp or -range, or just a plain time(range) specification like
1687 11:30-4pm) will be removed for agenda display. This makes the agenda less
1688 cluttered.
1689 The option can be t or nil. It may also be the symbol `beg', indicating
1690 that the time should only be removed when it is located at the beginning of
1691 the headline/diary entry."
1692 :group 'org-agenda-line-format
1693 :type '(choice
1694 (const :tag "Always" t)
1695 (const :tag "Never" nil)
1696 (const :tag "When at beginning of entry" beg)))
1698 (defcustom org-agenda-remove-timeranges-from-blocks nil
1699 "Non-nil means remove time ranges specifications in agenda
1700 items that span on several days."
1701 :group 'org-agenda-line-format
1702 :version "24.1"
1703 :type 'boolean)
1705 (defcustom org-agenda-default-appointment-duration nil
1706 "Default duration for appointments that only have a starting time.
1707 When nil, no duration is specified in such cases.
1708 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1709 :group 'org-agenda-line-format
1710 :type '(choice
1711 (integer :tag "Minutes")
1712 (const :tag "No default duration")))
1714 (defcustom org-agenda-show-inherited-tags t
1715 "Non-nil means show inherited tags in each agenda line.
1717 When this option is set to 'always, it take precedences over
1718 `org-agenda-use-tag-inheritance' and inherited tags are shown
1719 in every agenda.
1721 When this option is set to t (the default), inherited tags are
1722 shown when they are available, i.e. when the value of
1723 `org-agenda-use-tag-inheritance' has been taken into account.
1725 This can be set to a list of agenda types in which the agenda
1726 must display the inherited tags. Available types are 'todo,
1727 'agenda, 'search and 'timeline.
1729 When set to nil, never show inherited tags in agenda lines."
1730 :group 'org-agenda-line-format
1731 :group 'org-agenda
1732 :version "24.3"
1733 :type '(choice
1734 (const :tag "Show inherited tags when available" t)
1735 (const :tag "Always show inherited tags" 'always)
1736 (repeat :tag "Show inherited tags only in selected agenda types"
1737 (symbol :tag "Agenda type"))))
1739 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1740 "List of agenda view types where to use tag inheritance.
1742 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1743 controlled by `org-use-tag-inheritance'. In other agenda types,
1744 `org-use-tag-inheritance' is not used for the selection of the
1745 agenda entries. Still, you may want the agenda to be aware of
1746 the inherited tags anyway, e.g. for later tag filtering.
1748 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1750 This variable has no effect if `org-agenda-show-inherited-tags'
1751 is set to 'always. In that case, the agenda is aware of those
1752 tags.
1754 The default value sets tags in every agenda type. Setting this
1755 option to nil will speed up non-tags agenda view a lot."
1756 :group 'org-agenda
1757 :version "24.3"
1758 :type '(choice
1759 (const :tag "Use tag inheritance in all agenda types" t)
1760 (repeat :tag "Use tag inheritance in selected agenda types"
1761 (symbol :tag "Agenda type"))))
1763 (defcustom org-agenda-hide-tags-regexp nil
1764 "Regular expression used to filter away specific tags in agenda views.
1765 This means that these tags will be present, but not be shown in the agenda
1766 line. Secondary filtering will still work on the hidden tags.
1767 Nil means don't hide any tags."
1768 :group 'org-agenda-line-format
1769 :type '(choice
1770 (const :tag "Hide none" nil)
1771 (string :tag "Regexp ")))
1773 (defcustom org-agenda-remove-tags nil
1774 "Non-nil means remove the tags from the headline copy in the agenda.
1775 When this is the symbol `prefix', only remove tags when
1776 `org-agenda-prefix-format' contains a `%T' specifier."
1777 :group 'org-agenda-line-format
1778 :type '(choice
1779 (const :tag "Always" t)
1780 (const :tag "Never" nil)
1781 (const :tag "When prefix format contains %T" prefix)))
1783 (if (fboundp 'defvaralias)
1784 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1785 'org-agenda-remove-tags))
1787 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1788 "Shift tags in agenda items to this column.
1789 If this number is positive, it specifies the column. If it is negative,
1790 it means that the tags should be flushright to that column. For example,
1791 -80 works well for a normal 80 character screen."
1792 :group 'org-agenda-line-format
1793 :type 'integer)
1795 (if (fboundp 'defvaralias)
1796 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1798 (defcustom org-agenda-fontify-priorities 'cookies
1799 "Non-nil means highlight low and high priorities in agenda.
1800 When t, the highest priority entries are bold, lowest priority italic.
1801 However, settings in `org-priority-faces' will overrule these faces.
1802 When this variable is the symbol `cookies', only fontify the
1803 cookies, not the entire task.
1804 This may also be an association list of priority faces, whose
1805 keys are the character values of `org-highest-priority',
1806 `org-default-priority', and `org-lowest-priority' (the default values
1807 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1808 color as a string, or a list like `(:background \"Red\")'.
1809 If it is a color, the variable `org-faces-easy-properties'
1810 determines if it is a foreground or a background color."
1811 :group 'org-agenda-line-format
1812 :type '(choice
1813 (const :tag "Never" nil)
1814 (const :tag "Defaults" t)
1815 (const :tag "Cookies only" cookies)
1816 (repeat :tag "Specify"
1817 (list (character :tag "Priority" :value ?A)
1818 (choice :tag "Face "
1819 (string :tag "Color")
1820 (sexp :tag "Face"))))))
1822 (defcustom org-agenda-day-face-function nil
1823 "Function called to determine what face should be used to display a day.
1824 The only argument passed to that function is the day. It should
1825 returns a face, or nil if does not want to specify a face and let
1826 the normal rules apply."
1827 :group 'org-agenda-line-format
1828 :version "24.1"
1829 :type 'function)
1831 (defcustom org-agenda-category-icon-alist nil
1832 "Alist of category icon to be displayed in agenda views.
1834 Each entry should have the following format:
1836 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1838 Where CATEGORY-REGEXP is a regexp matching the categories where
1839 the icon should be displayed.
1840 FILE-OR-DATA either a file path or a string containing image data.
1842 The other fields can be omitted safely if not needed:
1843 TYPE indicates the image type.
1844 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1845 image data.
1846 PROPS are additional image attributes to assign to the image,
1847 like, e.g. `:ascent center'.
1849 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1851 If you want to set the display properties yourself, just put a
1852 list as second element:
1854 (CATEGORY-REGEXP (MY PROPERTY LIST))
1856 For example, to display a 16px horizontal space for Emacs
1857 category, you can use:
1859 (\"Emacs\" '(space . (:width (16))))"
1860 :group 'org-agenda-line-format
1861 :version "24.1"
1862 :type '(alist :key-type (string :tag "Regexp matching category")
1863 :value-type (choice (list :tag "Icon"
1864 (string :tag "File or data")
1865 (symbol :tag "Type")
1866 (boolean :tag "Data?")
1867 (repeat :tag "Extra image properties" :inline t symbol))
1868 (list :tag "Display properties" sexp))))
1870 (defgroup org-agenda-column-view nil
1871 "Options concerning column view in the agenda."
1872 :tag "Org Agenda Column View"
1873 :group 'org-agenda)
1875 (defcustom org-agenda-columns-show-summaries t
1876 "Non-nil means show summaries for columns displayed in the agenda view."
1877 :group 'org-agenda-column-view
1878 :type 'boolean)
1880 (defcustom org-agenda-columns-compute-summary-properties t
1881 "Non-nil means recompute all summary properties before column view.
1882 When column view in the agenda is listing properties that have a summary
1883 operator, it can go to all relevant buffers and recompute the summaries
1884 there. This can mean overhead for the agenda column view, but is necessary
1885 to have thing up to date.
1886 As a special case, a CLOCKSUM property also makes sure that the clock
1887 computations are current."
1888 :group 'org-agenda-column-view
1889 :type 'boolean)
1891 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1892 "Non-nil means the duration of an appointment will add to day effort.
1893 The property to which appointment durations will be added is the one given
1894 in the option `org-effort-property'. If an appointment does not have
1895 an end time, `org-agenda-default-appointment-duration' will be used. If that
1896 is not set, an appointment without end time will not contribute to the time
1897 estimate."
1898 :group 'org-agenda-column-view
1899 :type 'boolean)
1901 (defcustom org-agenda-auto-exclude-function nil
1902 "A function called with a tag to decide if it is filtered on '/ RET'.
1903 The sole argument to the function, which is called once for each
1904 possible tag, is a string giving the name of the tag. The
1905 function should return either nil if the tag should be included
1906 as normal, or \"-<TAG>\" to exclude the tag.
1907 Note that for the purpose of tag filtering, only the lower-case version of
1908 all tags will be considered, so that this function will only ever see
1909 the lower-case version of all tags."
1910 :group 'org-agenda
1911 :type 'function)
1913 (defcustom org-agenda-bulk-custom-functions nil
1914 "Alist of characters and custom functions for bulk actions.
1915 For example, this value makes those two functions available:
1917 '((?R set-category)
1918 (?C bulk-cut))
1920 With selected entries in an agenda buffer, `B R' will call
1921 the custom function `set-category' on the selected entries.
1922 Note that functions in this alist don't need to be quoted."
1923 :type 'alist
1924 :version "24.1"
1925 :group 'org-agenda)
1927 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1928 "Execute BODY with point at location given by `org-hd-marker' property.
1929 If STRING is non-nil, the text property will be fetched from position 0
1930 in that string. If STRING is nil, it will be fetched from the beginning
1931 of the current line."
1932 (org-with-gensyms (marker)
1933 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1934 'org-hd-marker ,string)))
1935 (with-current-buffer (marker-buffer ,marker)
1936 (save-excursion
1937 (goto-char ,marker)
1938 ,@body)))))
1939 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1941 (defun org-add-agenda-custom-command (entry)
1942 "Replace or add a command in `org-agenda-custom-commands'.
1943 This is mostly for hacking and trying a new command - once the command
1944 works you probably want to add it to `org-agenda-custom-commands' for good."
1945 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1946 (if ass
1947 (setcdr ass (cdr entry))
1948 (push entry org-agenda-custom-commands))))
1950 ;;; Define the org-agenda-mode
1952 (defvar org-agenda-mode-map (make-sparse-keymap)
1953 "Keymap for `org-agenda-mode'.")
1954 (if (fboundp 'defvaralias)
1955 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1957 (defvar org-agenda-menu) ; defined later in this file.
1958 (defvar org-agenda-restrict nil) ; defined later in this file.
1959 (defvar org-agenda-follow-mode nil)
1960 (defvar org-agenda-entry-text-mode nil)
1961 (defvar org-agenda-clockreport-mode nil)
1962 (defvar org-agenda-show-log nil)
1963 (defvar org-agenda-redo-command nil)
1964 (defvar org-agenda-query-string nil)
1965 (defvar org-agenda-mode-hook nil
1966 "Hook run after `org-agenda-mode' is turned on.
1967 The buffer is still writable when this hook is called.")
1968 (defvar org-agenda-type nil)
1969 (defvar org-agenda-force-single-file nil)
1970 (defvar org-agenda-bulk-marked-entries nil
1971 "List of markers that refer to marked entries in the agenda.")
1973 ;;; Multiple agenda buffers support
1975 (defcustom org-agenda-sticky nil
1976 "Non-nil means agenda q key will bury agenda buffers.
1977 Agenda commands will then show existing buffer instead of generating new ones.
1978 When nil, `q' will kill the single agenda buffer."
1979 :group 'org-agenda
1980 :version "24.3"
1981 :type 'boolean)
1984 ;;;###autoload
1985 (defun org-toggle-sticky-agenda (&optional arg)
1986 "Toggle `org-agenda-sticky'."
1987 (interactive "P")
1988 (let ((new-value (if arg
1989 (> (prefix-numeric-value arg) 0)
1990 (not org-agenda-sticky))))
1991 (if (equal new-value org-agenda-sticky)
1992 (and (org-called-interactively-p 'interactive)
1993 (message "Sticky agenda was already %s"
1994 (if org-agenda-sticky "enabled" "disabled")))
1995 (setq org-agenda-sticky new-value)
1996 (org-agenda-kill-all-agenda-buffers)
1997 (and (org-called-interactively-p 'interactive)
1998 (message "Sticky agenda was %s"
1999 (if org-agenda-sticky "enabled" "disabled"))))))
2001 (defvar org-agenda-buffer nil
2002 "Agenda buffer currently being generated.")
2004 (defvar org-agenda-last-prefix-arg nil)
2005 (defvar org-agenda-this-buffer-name nil)
2006 (defvar org-agenda-doing-sticky-redo nil)
2007 (defvar org-agenda-this-buffer-is-sticky nil)
2009 (defconst org-agenda-local-vars
2010 '(org-agenda-this-buffer-name
2011 org-agenda-undo-list
2012 org-agenda-pending-undo-list
2013 org-agenda-follow-mode
2014 org-agenda-entry-text-mode
2015 org-agenda-clockreport-mode
2016 org-agenda-show-log
2017 org-agenda-redo-command
2018 org-agenda-query-string
2019 org-agenda-type
2020 org-agenda-bulk-marked-entries
2021 org-agenda-undo-has-started-in
2022 org-agenda-info
2023 org-agenda-tag-filter-overlays
2024 org-agenda-cat-filter-overlays
2025 org-agenda-pre-window-conf
2026 org-agenda-columns-active
2027 org-agenda-tag-filter
2028 org-agenda-category-filter
2029 org-agenda-markers
2030 org-agenda-last-search-view-search-was-boolean
2031 org-agenda-filtered-by-category
2032 org-agenda-filter-form
2033 org-agenda-cycle-counter
2034 org-agenda-last-prefix-arg)
2035 "Variables that must be local in agenda buffers to allow multiple buffers.")
2037 (defun org-agenda-mode ()
2038 "Mode for time-sorted view on action items in Org-mode files.
2040 The following commands are available:
2042 \\{org-agenda-mode-map}"
2043 (interactive)
2044 (cond (org-agenda-doing-sticky-redo
2045 ;; Refreshing sticky agenda-buffer
2047 ;; Preserve the value of `org-agenda-local-vars' variables,
2048 ;; while letting `kill-all-local-variables' kill the rest
2049 (let ((save (buffer-local-variables)))
2050 (kill-all-local-variables)
2051 (mapc 'make-local-variable org-agenda-local-vars)
2052 (dolist (elem save)
2053 (let ((var (car elem))
2054 (val (cdr elem)))
2055 (when (and val
2056 (member var org-agenda-local-vars))
2057 (set var val)))))
2058 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2059 (org-agenda-sticky
2060 ;; Creating a sticky Agenda buffer for the first time
2061 (kill-all-local-variables)
2062 (mapc 'make-local-variable org-agenda-local-vars)
2063 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2065 ;; Creating a non-sticky agenda buffer
2066 (kill-all-local-variables)
2067 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2068 (setq org-agenda-undo-list nil
2069 org-agenda-pending-undo-list nil
2070 org-agenda-bulk-marked-entries nil)
2071 (setq major-mode 'org-agenda-mode)
2072 ;; Keep global-font-lock-mode from turning on font-lock-mode
2073 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2074 (setq mode-name "Org-Agenda")
2075 (use-local-map org-agenda-mode-map)
2076 (easy-menu-add org-agenda-menu)
2077 (if org-startup-truncated (setq truncate-lines t))
2078 (org-set-local 'line-move-visual nil)
2079 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2080 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2081 ;; Make sure properties are removed when copying text
2082 (make-local-variable 'filter-buffer-substring-functions)
2083 (add-hook 'filter-buffer-substring-functions
2084 (lambda (fun start end delete)
2085 (substring-no-properties (funcall fun start end delete))))
2086 (unless org-agenda-keep-modes
2087 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2088 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2089 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2090 org-agenda-show-log org-agenda-start-with-log-mode))
2092 (easy-menu-change
2093 '("Agenda") "Agenda Files"
2094 (append
2095 (list
2096 (vector
2097 (if (get 'org-agenda-files 'org-restrict)
2098 "Restricted to single file"
2099 "Edit File List")
2100 '(org-edit-agenda-file-list)
2101 (not (get 'org-agenda-files 'org-restrict)))
2102 "--")
2103 (mapcar 'org-file-menu-entry (org-agenda-files))))
2104 (org-agenda-set-mode-name)
2105 (apply
2106 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2107 (list 'org-agenda-mode-hook)))
2109 (substitute-key-definition 'undo 'org-agenda-undo
2110 org-agenda-mode-map global-map)
2111 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2112 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2113 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2114 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2115 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2116 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2117 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2118 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2119 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2120 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2121 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2122 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2123 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2124 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2125 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2126 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2127 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2128 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2129 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2130 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2131 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2132 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2133 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2134 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2135 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2136 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2137 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2138 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2139 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2140 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2141 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2142 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2143 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2144 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2145 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2146 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2147 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2148 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2149 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2150 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2151 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2152 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2153 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2154 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2155 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2156 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2158 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2159 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2160 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2161 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2162 (while l (org-defkey org-agenda-mode-map
2163 (int-to-string (pop l)) 'digit-argument)))
2165 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2166 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2167 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2168 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2169 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2170 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2171 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2172 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2173 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2174 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2175 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2176 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2177 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2178 'org-clock-modify-effort-estimate)
2179 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2180 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2181 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2182 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2183 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2184 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2185 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2186 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2187 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2188 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2189 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2190 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2191 (substitute-key-definition 'next-line 'org-agenda-next-line
2192 org-agenda-mode-map global-map)
2193 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2194 org-agenda-mode-map global-map)
2195 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2196 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2197 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2198 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2199 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2200 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2201 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2202 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2203 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2204 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2205 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2206 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2207 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2208 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2209 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2210 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2211 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2212 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2213 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2214 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2215 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2216 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2217 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2218 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2219 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2220 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2221 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2222 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2223 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2224 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2226 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2227 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2228 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2229 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2230 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2231 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2232 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2233 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2234 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2235 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2236 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2237 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2239 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2240 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2241 (when org-agenda-mouse-1-follows-link
2242 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2243 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2244 '("Agenda"
2245 ("Agenda Files")
2246 "--"
2247 ("Agenda Dates"
2248 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2249 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2250 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2251 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2252 "--"
2253 ("View"
2254 ["Day View" org-agenda-day-view
2255 :active (org-agenda-check-type nil 'agenda)
2256 :style radio :selected (eq org-agenda-current-span 'day)
2257 :keys "v d (or just d)"]
2258 ["Week View" org-agenda-week-view
2259 :active (org-agenda-check-type nil 'agenda)
2260 :style radio :selected (eq org-agenda-current-span 'week)
2261 :keys "v w (or just w)"]
2262 ["Month View" org-agenda-month-view
2263 :active (org-agenda-check-type nil 'agenda)
2264 :style radio :selected (eq org-agenda-current-span 'month)
2265 :keys "v m"]
2266 ["Year View" org-agenda-year-view
2267 :active (org-agenda-check-type nil 'agenda)
2268 :style radio :selected (eq org-agenda-current-span 'year)
2269 :keys "v y"]
2270 "--"
2271 ["Include Diary" org-agenda-toggle-diary
2272 :style toggle :selected org-agenda-include-diary
2273 :active (org-agenda-check-type nil 'agenda)]
2274 ["Include Deadlines" org-agenda-toggle-deadlines
2275 :style toggle :selected org-agenda-include-deadlines
2276 :active (org-agenda-check-type nil 'agenda)]
2277 ["Use Time Grid" org-agenda-toggle-time-grid
2278 :style toggle :selected org-agenda-use-time-grid
2279 :active (org-agenda-check-type nil 'agenda)]
2280 "--"
2281 ["Show clock report" org-agenda-clockreport-mode
2282 :style toggle :selected org-agenda-clockreport-mode
2283 :active (org-agenda-check-type nil 'agenda)]
2284 ["Show some entry text" org-agenda-entry-text-mode
2285 :style toggle :selected org-agenda-entry-text-mode
2286 :active t]
2287 "--"
2288 ["Show Logbook entries" org-agenda-log-mode
2289 :style toggle :selected org-agenda-show-log
2290 :active (org-agenda-check-type nil 'agenda 'timeline)
2291 :keys "v l (or just l)"]
2292 ["Include archived trees" org-agenda-archives-mode
2293 :style toggle :selected org-agenda-archives-mode :active t
2294 :keys "v a"]
2295 ["Include archive files" (org-agenda-archives-mode t)
2296 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2297 :keys "v A"]
2298 "--"
2299 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2300 ["Write view to file" org-agenda-write t]
2301 ["Rebuild buffer" org-agenda-redo t]
2302 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2303 "--"
2304 ["Show original entry" org-agenda-show t]
2305 ["Go To (other window)" org-agenda-goto t]
2306 ["Go To (this window)" org-agenda-switch-to t]
2307 ["Capture with cursor date" org-agenda-capture t]
2308 ["Follow Mode" org-agenda-follow-mode
2309 :style toggle :selected org-agenda-follow-mode :active t]
2310 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2311 "--"
2312 ("TODO"
2313 ["Cycle TODO" org-agenda-todo t]
2314 ["Next TODO set" org-agenda-todo-nextset t]
2315 ["Previous TODO set" org-agenda-todo-previousset t]
2316 ["Add note" org-agenda-add-note t])
2317 ("Archive/Refile/Delete"
2318 ["Archive default" org-agenda-archive-default t]
2319 ["Archive default" org-agenda-archive-default-with-confirmation t]
2320 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2321 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2322 ["Archive subtree" org-agenda-archive t]
2323 "--"
2324 ["Refile" org-agenda-refile t]
2325 "--"
2326 ["Delete subtree" org-agenda-kill t])
2327 ("Bulk action"
2328 ["Mark entry" org-agenda-bulk-mark t]
2329 ["Mark all" org-agenda-bulk-mark-all t]
2330 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2331 ["Unmark entry" org-agenda-bulk-unmark t]
2332 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2333 ["Act on all marked" org-agenda-bulk-action t]
2334 "--"
2335 ("Tags and Properties"
2336 ["Show all Tags" org-agenda-show-tags t]
2337 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2338 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2339 "--"
2340 ["Column View" org-columns t])
2341 ("Deadline/Schedule"
2342 ["Schedule" org-agenda-schedule t]
2343 ["Set Deadline" org-agenda-deadline t]
2344 "--"
2345 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2346 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2347 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2348 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2349 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2350 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2351 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2352 ("Clock and Effort"
2353 ["Clock in" org-agenda-clock-in t]
2354 ["Clock out" org-agenda-clock-out t]
2355 ["Clock cancel" org-agenda-clock-cancel t]
2356 ["Goto running clock" org-clock-goto t]
2357 "--"
2358 ["Set Effort" org-agenda-set-effort t]
2359 ["Change clocked effort" org-clock-modify-effort-estimate
2360 (org-clock-is-active)])
2361 ("Priority"
2362 ["Set Priority" org-agenda-priority t]
2363 ["Increase Priority" org-agenda-priority-up t]
2364 ["Decrease Priority" org-agenda-priority-down t]
2365 ["Show Priority" org-show-priority t])
2366 ("Calendar/Diary"
2367 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2368 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2369 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2370 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2371 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2372 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2373 "--"
2374 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2375 "--"
2376 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2377 "--"
2378 ("MobileOrg"
2379 ["Push Files and Views" org-mobile-push t]
2380 ["Get Captured and Flagged" org-mobile-pull t]
2381 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2382 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2383 "--"
2384 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2385 "--"
2386 ["Quit" org-agenda-quit t]
2387 ["Exit and Release Buffers" org-agenda-exit t]
2390 ;;; Agenda undo
2392 (defvar org-agenda-allow-remote-undo t
2393 "Non-nil means allow remote undo from the agenda buffer.")
2394 (defvar org-agenda-undo-has-started-in nil
2395 "Buffers that have already seen `undo-start' in the current undo sequence.")
2397 (defun org-agenda-undo ()
2398 "Undo a remote editing step in the agenda.
2399 This undoes changes both in the agenda buffer and in the remote buffer
2400 that have been changed along."
2401 (interactive)
2402 (or org-agenda-allow-remote-undo
2403 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2404 (if (not (eq this-command last-command))
2405 (setq org-agenda-undo-has-started-in nil
2406 org-agenda-pending-undo-list org-agenda-undo-list))
2407 (if (not org-agenda-pending-undo-list)
2408 (error "No further undo information"))
2409 (let* ((entry (pop org-agenda-pending-undo-list))
2410 buf line cmd rembuf)
2411 (setq cmd (pop entry) line (pop entry))
2412 (setq rembuf (nth 2 entry))
2413 (org-with-remote-undo rembuf
2414 (while (bufferp (setq buf (pop entry)))
2415 (if (pop entry)
2416 (with-current-buffer buf
2417 (let ((last-undo-buffer buf)
2418 (inhibit-read-only t))
2419 (unless (memq buf org-agenda-undo-has-started-in)
2420 (push buf org-agenda-undo-has-started-in)
2421 (make-local-variable 'pending-undo-list)
2422 (undo-start))
2423 (while (and pending-undo-list
2424 (listp pending-undo-list)
2425 (not (car pending-undo-list)))
2426 (pop pending-undo-list))
2427 (undo-more 1))))))
2428 (org-goto-line line)
2429 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2431 (defun org-verify-change-for-undo (l1 l2)
2432 "Verify that a real change occurred between the undo lists L1 and L2."
2433 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2434 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2435 (not (eq l1 l2)))
2437 ;;; Agenda dispatch
2439 (defvar org-agenda-restrict-begin (make-marker))
2440 (defvar org-agenda-restrict-end (make-marker))
2441 (defvar org-agenda-last-dispatch-buffer nil)
2442 (defvar org-agenda-overriding-restriction nil)
2444 (defcustom org-agenda-custom-commands-contexts nil
2445 "Alist of custom agenda keys and contextual rules.
2447 For example, if you have a custom agenda command \"p\" and you
2448 want this command to be accessible only from plain text files,
2449 use this:
2451 '((\"p\" ((in-file . \"\\.txt\"))))
2453 Here are the available contexts definitions:
2455 in-file: command displayed only in matching files
2456 in-mode: command displayed only in matching modes
2457 not-in-file: command not displayed in matching files
2458 not-in-mode: command not displayed in matching modes
2459 in-buffer: command displayed only in matching buffers
2460 not-in-buffer: command not displayed in matching buffers
2461 [function]: a custom function taking no argument
2463 If you define several checks, the agenda command will be
2464 accessible if there is at least one valid check.
2466 You can also bind a key to another agenda custom command
2467 depending on contextual rules.
2469 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2471 Here it means: in .txt files, use \"p\" as the key for the
2472 agenda command otherwise associated with \"q\". (The command
2473 originally associated with \"q\" is not displayed to avoid
2474 duplicates.)"
2475 :version "24.3"
2476 :group 'org-agenda-custom-commands
2477 :type '(repeat (list :tag "Rule"
2478 (string :tag " Agenda key")
2479 (string :tag "Replace by command")
2480 (repeat :tag "Available when"
2481 (choice
2482 (cons :tag "Condition"
2483 (choice
2484 (const :tag "In file" in-file)
2485 (const :tag "Not in file" not-in-file)
2486 (const :tag "In buffer" in-buffer)
2487 (const :tag "Not in buffer" not-in-buffer)
2488 (const :tag "In mode" in-mode)
2489 (const :tag "Not in mode" not-in-mode))
2490 (regexp))
2491 (function :tag "Custom function"))))))
2493 (defcustom org-agenda-max-entries nil
2494 "Maximum number of entries to display in an agenda.
2495 This can be nil (no limit) or an integer or an alist of agenda
2496 types with an associated number of entries to display in this
2497 type."
2498 :version "24.4"
2499 :package-version '(Org . "8.0")
2500 :group 'org-agenda-custom-commands
2501 :type '(choice (symbol :tag "No limit" nil)
2502 (integer :tag "Max number of entries")
2503 (repeat
2504 (cons (choice :tag "Agenda type"
2505 (const agenda)
2506 (const todo)
2507 (const tags)
2508 (const search)
2509 (const timeline))
2510 (integer :tag "Max number of entries")))))
2512 (defcustom org-agenda-max-todos nil
2513 "Maximum number of TODOs to display in an agenda.
2514 This can be nil (no limit) or an integer or an alist of agenda
2515 types with an associated number of entries to display in this
2516 type."
2517 :version "24.4"
2518 :package-version '(Org . "8.0")
2519 :group 'org-agenda-custom-commands
2520 :type '(choice (symbol :tag "No limit" nil)
2521 (integer :tag "Max number of entries")
2522 (repeat
2523 (cons (choice :tag "Agenda type"
2524 (const agenda)
2525 (const todo)
2526 (const tags)
2527 (const search)
2528 (const timeline))
2529 (integer :tag "Max number of entries")))))
2531 (defcustom org-agenda-max-tags nil
2532 "Maximum number of tagged entries to display in an agenda.
2533 This can be nil (no limit) or an integer or an alist of agenda
2534 types with an associated number of entries to display in this
2535 type."
2536 :version "24.4"
2537 :package-version '(Org . "8.0")
2538 :group 'org-agenda-custom-commands
2539 :type '(choice (symbol :tag "No limit" nil)
2540 (integer :tag "Max number of entries")
2541 (repeat
2542 (cons (choice :tag "Agenda type"
2543 (const agenda)
2544 (const todo)
2545 (const tags)
2546 (const search)
2547 (const timeline))
2548 (integer :tag "Max number of entries")))))
2550 (defcustom org-agenda-max-effort nil
2551 "Maximum cumulated effort duration for the agenda.
2552 This can be nil (no limit) or a number of minutes (as an integer)
2553 or an alist of agenda types with an associated number of minutes
2554 to limit entries to in this type."
2555 :version "24.4"
2556 :package-version '(Org . "8.0")
2557 :group 'org-agenda-custom-commands
2558 :type '(choice (symbol :tag "No limit" nil)
2559 (integer :tag "Max number of entries")
2560 (repeat
2561 (cons (choice :tag "Agenda type"
2562 (const agenda)
2563 (const todo)
2564 (const tags)
2565 (const search)
2566 (const timeline))
2567 (integer :tag "Max number of entries")))))
2569 (defvar org-keys nil)
2570 (defvar org-match nil)
2571 ;;;###autoload
2572 (defun org-agenda (&optional arg org-keys restriction)
2573 "Dispatch agenda commands to collect entries to the agenda buffer.
2574 Prompts for a command to execute. Any prefix arg will be passed
2575 on to the selected command. The default selections are:
2577 a Call `org-agenda-list' to display the agenda for current day or week.
2578 t Call `org-todo-list' to display the global todo list.
2579 T Call `org-todo-list' to display the global todo list, select only
2580 entries with a specific TODO keyword (the user gets a prompt).
2581 m Call `org-tags-view' to display headlines with tags matching
2582 a condition (the user is prompted for the condition).
2583 M Like `m', but select only TODO entries, no ordinary headlines.
2584 L Create a timeline for the current buffer.
2585 e Export views to associated files.
2586 s Search entries for keywords.
2587 S Search entries for keywords, only with TODO keywords.
2588 / Multi occur across all agenda files and also files listed
2589 in `org-agenda-text-search-extra-files'.
2590 < Restrict agenda commands to buffer, subtree, or region.
2591 Press several times to get the desired effect.
2592 > Remove a previous restriction.
2593 # List \"stuck\" projects.
2594 ! Configure what \"stuck\" means.
2595 C Configure custom agenda commands.
2597 More commands can be added by configuring the variable
2598 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2599 searches can be pre-defined in this way.
2601 If the current buffer is in Org-mode and visiting a file, you can also
2602 first press `<' once to indicate that the agenda should be temporarily
2603 \(until the next use of \\[org-agenda]) restricted to the current file.
2604 Pressing `<' twice means to restrict to the current subtree or region
2605 \(if active)."
2606 (interactive "P")
2607 (catch 'exit
2608 (let* ((prefix-descriptions nil)
2609 (org-agenda-buffer-name org-agenda-buffer-name)
2610 (org-agenda-window-setup (if (equal (buffer-name)
2611 org-agenda-buffer-name)
2612 'current-window
2613 org-agenda-window-setup))
2614 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2615 (org-agenda-custom-commands
2616 ;; normalize different versions
2617 (delq nil
2618 (mapcar
2619 (lambda (x)
2620 (cond ((stringp (cdr x))
2621 (push x prefix-descriptions)
2622 nil)
2623 ((stringp (nth 1 x)) x)
2624 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2625 (t (cons (car x) (cons "" (cdr x))))))
2626 org-agenda-custom-commands)))
2627 (org-agenda-custom-commands
2628 (org-contextualize-keys
2629 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2630 (buf (current-buffer))
2631 (bfn (buffer-file-name (buffer-base-buffer)))
2632 entry key type org-match lprops ans)
2633 ;; Turn off restriction unless there is an overriding one,
2634 (unless org-agenda-overriding-restriction
2635 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2636 ;; There is a request to keep the file list in place
2637 (put 'org-agenda-files 'org-restrict nil))
2638 (setq org-agenda-restrict nil)
2639 (move-marker org-agenda-restrict-begin nil)
2640 (move-marker org-agenda-restrict-end nil))
2641 ;; Delete old local properties
2642 (put 'org-agenda-redo-command 'org-lprops nil)
2643 ;; Delete previously set last-arguments
2644 (put 'org-agenda-redo-command 'last-args nil)
2645 ;; Remember where this call originated
2646 (setq org-agenda-last-dispatch-buffer (current-buffer))
2647 (unless org-keys
2648 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2649 org-keys (car ans)
2650 restriction (cdr ans)))
2651 ;; If we have sticky agenda buffers, set a name for the buffer,
2652 ;; depending on the invoking keys. The user may still set this
2653 ;; as a command option, which will overwrite what we do here.
2654 (if org-agenda-sticky
2655 (setq org-agenda-buffer-name
2656 (format "*Org Agenda(%s)*" org-keys)))
2657 ;; Establish the restriction, if any
2658 (when (and (not org-agenda-overriding-restriction) restriction)
2659 (put 'org-agenda-files 'org-restrict (list bfn))
2660 (cond
2661 ((eq restriction 'region)
2662 (setq org-agenda-restrict t)
2663 (move-marker org-agenda-restrict-begin (region-beginning))
2664 (move-marker org-agenda-restrict-end (region-end)))
2665 ((eq restriction 'subtree)
2666 (save-excursion
2667 (setq org-agenda-restrict t)
2668 (org-back-to-heading t)
2669 (move-marker org-agenda-restrict-begin (point))
2670 (move-marker org-agenda-restrict-end
2671 (progn (org-end-of-subtree t)))))))
2673 ;; For example the todo list should not need it (but does...)
2674 (cond
2675 ((setq entry (assoc org-keys org-agenda-custom-commands))
2676 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2677 (progn
2678 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2679 lprops (nth 4 entry))
2680 (if org-agenda-sticky
2681 (setq org-agenda-buffer-name
2682 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2683 (format "*Org Agenda(%s)*" org-keys))))
2684 (put 'org-agenda-redo-command 'org-lprops lprops)
2685 (cond
2686 ((eq type 'agenda)
2687 (org-let lprops '(org-agenda-list current-prefix-arg)))
2688 ((eq type 'alltodo)
2689 (org-let lprops '(org-todo-list current-prefix-arg)))
2690 ((eq type 'search)
2691 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2692 ((eq type 'stuck)
2693 (org-let lprops '(org-agenda-list-stuck-projects
2694 current-prefix-arg)))
2695 ((eq type 'tags)
2696 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2697 ((eq type 'tags-todo)
2698 (org-let lprops '(org-tags-view '(4) org-match)))
2699 ((eq type 'todo)
2700 (org-let lprops '(org-todo-list org-match)))
2701 ((eq type 'tags-tree)
2702 (org-check-for-org-mode)
2703 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2704 ((eq type 'todo-tree)
2705 (org-check-for-org-mode)
2706 (org-let lprops
2707 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2708 (regexp-quote org-match) "\\>"))))
2709 ((eq type 'occur-tree)
2710 (org-check-for-org-mode)
2711 (org-let lprops '(org-occur org-match)))
2712 ((functionp type)
2713 (org-let lprops '(funcall type org-match)))
2714 ((fboundp type)
2715 (org-let lprops '(funcall type org-match)))
2716 (t (error "Invalid custom agenda command type %s" type))))
2717 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2718 ((equal org-keys "C")
2719 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2720 (customize-variable 'org-agenda-custom-commands))
2721 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2722 ((equal org-keys "s") (call-interactively 'org-search-view))
2723 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2724 ((equal org-keys "t") (call-interactively 'org-todo-list))
2725 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2726 ((equal org-keys "m") (call-interactively 'org-tags-view))
2727 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2728 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2729 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2730 (org-add-hook
2731 'post-command-hook
2732 (lambda ()
2733 (unless (current-message)
2734 (let* ((m (org-agenda-get-any-marker))
2735 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2736 (when note
2737 (message (concat
2738 "FLAGGING-NOTE ([?] for more info): "
2739 (org-add-props
2740 (replace-regexp-in-string
2741 "\\\\n" "//"
2742 (copy-sequence note))
2743 nil 'face 'org-warning)))))))
2744 t t))
2745 ((equal org-keys "L")
2746 (unless (derived-mode-p 'org-mode)
2747 (error "This is not an Org-mode file"))
2748 (unless restriction
2749 (put 'org-agenda-files 'org-restrict (list bfn))
2750 (org-call-with-arg 'org-timeline arg)))
2751 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2752 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2753 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2754 (t (error "Invalid agenda key"))))))
2756 (defun org-agenda-append-agenda ()
2757 "Append another agenda view to the current one.
2758 This function allows interactive building of block agendas.
2759 Agenda views are separated by `org-agenda-block-separator'."
2760 (interactive)
2761 (unless (derived-mode-p 'org-agenda-mode)
2762 (error "Can only append from within agenda buffer"))
2763 (let ((org-agenda-multi t))
2764 (org-agenda)
2765 (widen)
2766 (org-agenda-finalize)
2767 (org-agenda-fit-window-to-buffer)))
2769 (defun org-agenda-normalize-custom-commands (cmds)
2770 (delq nil
2771 (mapcar
2772 (lambda (x)
2773 (cond ((stringp (cdr x)) nil)
2774 ((stringp (nth 1 x)) x)
2775 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2776 (t (cons (car x) (cons "" (cdr x))))))
2777 cmds)))
2779 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2780 "The user interface for selecting an agenda command."
2781 (catch 'exit
2782 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2783 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2784 (region-p (org-region-active-p))
2785 (custom org-agenda-custom-commands)
2786 (selstring "")
2787 restriction second-time
2788 c entry key type match prefixes rmheader header-end custom1 desc
2789 line lines left right n n1)
2790 (save-window-excursion
2791 (delete-other-windows)
2792 (org-switch-to-buffer-other-window " *Agenda Commands*")
2793 (erase-buffer)
2794 (insert (eval-when-compile
2795 (let ((header
2796 "Press key for an agenda command: < Buffer, subtree/region restriction
2797 -------------------------------- > Remove restriction
2798 a Agenda for current week or day e Export agenda views
2799 t List of all TODO entries T Entries with special TODO kwd
2800 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2801 s Search for keywords S Like s, but only TODO entries
2802 L Timeline for current buffer # List stuck projects (!=configure)
2803 / Multi-occur C Configure custom agenda commands
2804 ? Find :FLAGGED: entries * Toggle sticky agenda views
2806 (start 0))
2807 (while (string-match
2808 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2809 header start)
2810 (setq start (match-end 0))
2811 (add-text-properties (match-beginning 2) (match-end 2)
2812 '(face bold) header))
2813 header)))
2814 (setq header-end (point-marker))
2815 (while t
2816 (setq custom1 custom)
2817 (when (eq rmheader t)
2818 (org-goto-line 1)
2819 (re-search-forward ":" nil t)
2820 (delete-region (match-end 0) (point-at-eol))
2821 (forward-char 1)
2822 (looking-at "-+")
2823 (delete-region (match-end 0) (point-at-eol))
2824 (move-marker header-end (match-end 0)))
2825 (goto-char header-end)
2826 (delete-region (point) (point-max))
2828 ;; Produce all the lines that describe custom commands and prefixes
2829 (setq lines nil)
2830 (while (setq entry (pop custom1))
2831 (setq key (car entry) desc (nth 1 entry)
2832 type (nth 2 entry)
2833 match (nth 3 entry))
2834 (if (> (length key) 1)
2835 (add-to-list 'prefixes (string-to-char key))
2836 (setq line
2837 (format
2838 "%-4s%-14s"
2839 (org-add-props (copy-sequence key)
2840 '(face bold))
2841 (cond
2842 ((string-match "\\S-" desc) desc)
2843 ((eq type 'agenda) "Agenda for current week or day")
2844 ((eq type 'alltodo) "List of all TODO entries")
2845 ((eq type 'search) "Word search")
2846 ((eq type 'stuck) "List of stuck projects")
2847 ((eq type 'todo) "TODO keyword")
2848 ((eq type 'tags) "Tags query")
2849 ((eq type 'tags-todo) "Tags (TODO)")
2850 ((eq type 'tags-tree) "Tags tree")
2851 ((eq type 'todo-tree) "TODO kwd tree")
2852 ((eq type 'occur-tree) "Occur tree")
2853 ((functionp type) (if (symbolp type)
2854 (symbol-name type)
2855 "Lambda expression"))
2856 (t "???"))))
2857 (if org-agenda-menu-show-matcher
2858 (setq line
2859 (concat line ": "
2860 (cond
2861 ((stringp match)
2862 (setq match (copy-sequence match))
2863 (org-add-props match nil 'face 'org-warning))
2864 ((listp type)
2865 (format "set of %d commands" (length type))))))
2866 (if (org-string-nw-p match)
2867 (add-text-properties
2868 0 (length line) (list 'help-echo
2869 (concat "Matcher: " match)) line)))
2870 (push line lines)))
2871 (setq lines (nreverse lines))
2872 (when prefixes
2873 (mapc (lambda (x)
2874 (push
2875 (format "%s %s"
2876 (org-add-props (char-to-string x)
2877 nil 'face 'bold)
2878 (or (cdr (assoc (concat selstring
2879 (char-to-string x))
2880 prefix-descriptions))
2881 "Prefix key"))
2882 lines))
2883 prefixes))
2885 ;; Check if we should display in two columns
2886 (if org-agenda-menu-two-columns
2887 (progn
2888 (setq n (length lines)
2889 n1 (+ (/ n 2) (mod n 2))
2890 right (nthcdr n1 lines)
2891 left (copy-sequence lines))
2892 (setcdr (nthcdr (1- n1) left) nil))
2893 (setq left lines right nil))
2894 (while left
2895 (insert "\n" (pop left))
2896 (when right
2897 (if (< (current-column) 40)
2898 (move-to-column 40 t)
2899 (insert " "))
2900 (insert (pop right))))
2902 ;; Make the window the right size
2903 (goto-char (point-min))
2904 (if second-time
2905 (if (not (pos-visible-in-window-p (point-max)))
2906 (org-fit-window-to-buffer))
2907 (setq second-time t)
2908 (org-fit-window-to-buffer))
2910 ;; Ask for selection
2911 (message "Press key for agenda command%s:"
2912 (if (or restrict-ok org-agenda-overriding-restriction)
2913 (if org-agenda-overriding-restriction
2914 " (restriction lock active)"
2915 (if restriction
2916 (format " (restricted to %s)" restriction)
2917 " (unrestricted)"))
2918 ""))
2919 (setq c (read-char-exclusive))
2920 (message "")
2921 (cond
2922 ((assoc (char-to-string c) custom)
2923 (setq selstring (concat selstring (char-to-string c)))
2924 (throw 'exit (cons selstring restriction)))
2925 ((memq c prefixes)
2926 (setq selstring (concat selstring (char-to-string c))
2927 prefixes nil
2928 rmheader (or rmheader t)
2929 custom (delq nil (mapcar
2930 (lambda (x)
2931 (if (or (= (length (car x)) 1)
2932 (/= (string-to-char (car x)) c))
2934 (cons (substring (car x) 1) (cdr x))))
2935 custom))))
2936 ((eq c ?*)
2937 (call-interactively 'org-toggle-sticky-agenda)
2938 (sit-for 2))
2939 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2940 (message "Restriction is only possible in Org-mode buffers")
2941 (ding) (sit-for 1))
2942 ((eq c ?1)
2943 (org-agenda-remove-restriction-lock 'noupdate)
2944 (setq restriction 'buffer))
2945 ((eq c ?0)
2946 (org-agenda-remove-restriction-lock 'noupdate)
2947 (setq restriction (if region-p 'region 'subtree)))
2948 ((eq c ?<)
2949 (org-agenda-remove-restriction-lock 'noupdate)
2950 (setq restriction
2951 (cond
2952 ((eq restriction 'buffer)
2953 (if region-p 'region 'subtree))
2954 ((memq restriction '(subtree region))
2955 nil)
2956 (t 'buffer))))
2957 ((eq c ?>)
2958 (org-agenda-remove-restriction-lock 'noupdate)
2959 (setq restriction nil))
2960 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2961 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2962 ((and (> (length selstring) 0) (eq c ?\d))
2963 (delete-window)
2964 (org-agenda-get-restriction-and-command prefix-descriptions))
2966 ((equal c ?q) (error "Abort"))
2967 (t (error "Invalid key %c" c))))))))
2969 (defun org-agenda-fit-window-to-buffer ()
2970 "Fit the window to the buffer size."
2971 (and (memq org-agenda-window-setup '(reorganize-frame))
2972 (fboundp 'fit-window-to-buffer)
2973 (org-fit-window-to-buffer
2975 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2976 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2978 (defvar org-cmd nil)
2979 (defvar org-agenda-overriding-cmd nil)
2980 (defvar org-agenda-overriding-arguments nil)
2981 (defvar org-agenda-overriding-cmd-arguments nil)
2982 (defun org-agenda-run-series (name series)
2983 (org-let (nth 1 series) '(org-agenda-prepare name))
2984 ;; We need to reset agenda markers here, because when constructing a
2985 ;; block agenda, the individual blocks do not do that.
2986 (org-agenda-reset-markers)
2987 (let* ((org-agenda-multi t)
2988 (redo (list 'org-agenda-run-series name (list 'quote series)))
2989 (cmds (car series))
2990 (gprops (nth 1 series))
2991 match ;; The byte compiler incorrectly complains about this. Keep it!
2992 org-cmd type lprops)
2993 (while (setq org-cmd (pop cmds))
2994 (setq type (car org-cmd)
2995 match (eval (nth 1 org-cmd))
2996 lprops (nth 2 org-cmd))
2997 (let ((org-agenda-overriding-arguments
2998 (if (eq org-agenda-overriding-cmd org-cmd)
2999 (or org-agenda-overriding-arguments
3000 org-agenda-overriding-cmd-arguments))))
3001 (cond
3002 ((eq type 'agenda)
3003 (org-let2 gprops lprops
3004 '(call-interactively 'org-agenda-list)))
3005 ((eq type 'alltodo)
3006 (org-let2 gprops lprops
3007 '(call-interactively 'org-todo-list)))
3008 ((eq type 'search)
3009 (org-let2 gprops lprops
3010 '(org-search-view current-prefix-arg match nil)))
3011 ((eq type 'stuck)
3012 (org-let2 gprops lprops
3013 '(call-interactively 'org-agenda-list-stuck-projects)))
3014 ((eq type 'tags)
3015 (org-let2 gprops lprops
3016 '(org-tags-view current-prefix-arg match)))
3017 ((eq type 'tags-todo)
3018 (org-let2 gprops lprops
3019 '(org-tags-view '(4) match)))
3020 ((eq type 'todo)
3021 (org-let2 gprops lprops
3022 '(org-todo-list match)))
3023 ((fboundp type)
3024 (org-let2 gprops lprops
3025 '(funcall type match)))
3026 (t (error "Invalid type in command series")))))
3027 (widen)
3028 (let ((inhibit-read-only t))
3029 (add-text-properties (point-min) (point-max)
3030 `(org-series t org-series-redo-cmd ,redo)))
3031 (setq org-agenda-redo-command redo)
3032 (goto-char (point-min)))
3033 (org-agenda-fit-window-to-buffer)
3034 (org-let (nth 1 series) '(org-agenda-finalize)))
3036 ;;;###autoload
3037 (defmacro org-batch-agenda (cmd-key &rest parameters)
3038 "Run an agenda command in batch mode and send the result to STDOUT.
3039 If CMD-KEY is a string of length 1, it is used as a key in
3040 `org-agenda-custom-commands' and triggers this command. If it is a
3041 longer string it is used as a tags/todo match string.
3042 Parameters are alternating variable names and values that will be bound
3043 before running the agenda command."
3044 (org-eval-in-environment (org-make-parameter-alist parameters)
3045 (if (> (length cmd-key) 2)
3046 (org-tags-view nil cmd-key)
3047 (org-agenda nil cmd-key)))
3048 (set-buffer org-agenda-buffer-name)
3049 (princ (buffer-string)))
3051 (defvar org-agenda-info nil)
3053 ;;;###autoload
3054 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3055 "Run an agenda command in batch mode and send the result to STDOUT.
3056 If CMD-KEY is a string of length 1, it is used as a key in
3057 `org-agenda-custom-commands' and triggers this command. If it is a
3058 longer string it is used as a tags/todo match string.
3059 Parameters are alternating variable names and values that will be bound
3060 before running the agenda command.
3062 The output gives a line for each selected agenda item. Each
3063 item is a list of comma-separated values, like this:
3065 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3067 category The category of the item
3068 head The headline, without TODO kwd, TAGS and PRIORITY
3069 type The type of the agenda entry, can be
3070 todo selected in TODO match
3071 tagsmatch selected in tags match
3072 diary imported from diary
3073 deadline a deadline on given date
3074 scheduled scheduled on given date
3075 timestamp entry has timestamp on given date
3076 closed entry was closed on given date
3077 upcoming-deadline warning about deadline
3078 past-scheduled forwarded scheduled item
3079 block entry has date block including g. date
3080 todo The todo keyword, if any
3081 tags All tags including inherited ones, separated by colons
3082 date The relevant date, like 2007-2-14
3083 time The time, like 15:00-16:50
3084 extra Sting with extra planning info
3085 priority-l The priority letter if any was given
3086 priority-n The computed numerical priority
3087 agenda-day The day in the agenda where this is listed"
3088 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3089 (org-make-parameter-alist parameters))
3090 (if (> (length cmd-key) 2)
3091 (org-tags-view nil cmd-key)
3092 (org-agenda nil cmd-key)))
3093 (set-buffer org-agenda-buffer-name)
3094 (let* ((lines (org-split-string (buffer-string) "\n"))
3095 line)
3096 (while (setq line (pop lines))
3097 (catch 'next
3098 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3099 (setq org-agenda-info
3100 (org-fix-agenda-info (text-properties-at 0 line)))
3101 (princ
3102 (mapconcat 'org-agenda-export-csv-mapper
3103 '(org-category txt type todo tags date time extra
3104 priority-letter priority agenda-day)
3105 ","))
3106 (princ "\n")))))
3108 (defun org-fix-agenda-info (props)
3109 "Make sure all properties on an agenda item have a canonical form.
3110 This ensures the export commands can easily use it."
3111 (let (tmp re)
3112 (when (setq tmp (plist-get props 'tags))
3113 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3114 (when (setq tmp (plist-get props 'date))
3115 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3116 (let ((calendar-date-display-form '(year "-" month "-" day)))
3117 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3119 (setq tmp (calendar-date-string tmp)))
3120 (setq props (plist-put props 'date tmp)))
3121 (when (setq tmp (plist-get props 'day))
3122 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3123 (let ((calendar-date-display-form '(year "-" month "-" day)))
3124 (setq tmp (calendar-date-string tmp)))
3125 (setq props (plist-put props 'day tmp))
3126 (setq props (plist-put props 'agenda-day tmp)))
3127 (when (setq tmp (plist-get props 'txt))
3128 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3129 (plist-put props 'priority-letter (match-string 1 tmp))
3130 (setq tmp (replace-match "" t t tmp)))
3131 (when (and (setq re (plist-get props 'org-todo-regexp))
3132 (setq re (concat "\\`\\.*" re " ?"))
3133 (string-match re tmp))
3134 (plist-put props 'todo (match-string 1 tmp))
3135 (setq tmp (replace-match "" t t tmp)))
3136 (plist-put props 'txt tmp)))
3137 props)
3139 (defun org-agenda-export-csv-mapper (prop)
3140 (let ((res (plist-get org-agenda-info prop)))
3141 (setq res
3142 (cond
3143 ((not res) "")
3144 ((stringp res) res)
3145 (t (prin1-to-string res))))
3146 (while (string-match "," res)
3147 (setq res (replace-match ";" t t res)))
3148 (org-trim res)))
3150 ;;;###autoload
3151 (defun org-store-agenda-views (&rest parameters)
3152 (interactive)
3153 (eval (list 'org-batch-store-agenda-views)))
3155 ;;;###autoload
3156 (defmacro org-batch-store-agenda-views (&rest parameters)
3157 "Run all custom agenda commands that have a file argument."
3158 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3159 (pop-up-frames nil)
3160 (dir default-directory)
3161 (pars (org-make-parameter-alist parameters))
3162 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3163 (save-window-excursion
3164 (while cmds
3165 (setq cmd (pop cmds)
3166 thiscmdkey (car cmd)
3167 thiscmdcmd (cdr cmd)
3168 match (nth 2 thiscmdcmd)
3169 bufname (if org-agenda-sticky
3170 (or (and (stringp match)
3171 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3172 (format "*Org Agenda(%s)*" thiscmdkey))
3173 org-agenda-buffer-name)
3174 cmd-or-set (nth 2 cmd)
3175 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3176 files (nth (if (listp cmd-or-set) 4 5) cmd))
3177 (if (stringp files) (setq files (list files)))
3178 (when files
3179 (org-eval-in-environment (append org-agenda-exporter-settings
3180 opts pars)
3181 (org-agenda nil thiscmdkey))
3182 (set-buffer bufname)
3183 (while files
3184 (org-eval-in-environment (append org-agenda-exporter-settings
3185 opts pars)
3186 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3187 (and (get-buffer bufname)
3188 (kill-buffer bufname)))))))
3190 (defvar org-agenda-current-span nil
3191 "The current span used in the agenda view.") ; local variable in the agenda buffer
3192 (defun org-agenda-mark-header-line (pos)
3193 "Mark the line at POS as an agenda structure header."
3194 (save-excursion
3195 (goto-char pos)
3196 (put-text-property (point-at-bol) (point-at-eol)
3197 'org-agenda-structural-header t)
3198 (when org-agenda-title-append
3199 (put-text-property (point-at-bol) (point-at-eol)
3200 'org-agenda-title-append org-agenda-title-append))))
3202 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3203 (defvar org-agenda-write-buffer-name "Agenda View")
3204 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3205 "Write the current buffer (an agenda view) as a file.
3206 Depending on the extension of the file name, plain text (.txt),
3207 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3208 If the extension is .ics, run icalendar export over all files used
3209 to construct the agenda and limit the export to entries listed in the
3210 agenda now.
3211 If the extension is .org, collect all subtrees corresponding to the
3212 agenda entries and add them in an .org file.
3213 With prefix argument OPEN, open the new file immediately.
3214 If NOSETTINGS is given, do not scope the settings of
3215 `org-agenda-exporter-settings' into the export commands. This is used when
3216 the settings have already been scoped and we do not wish to overrule other,
3217 higher priority settings.
3218 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3219 (interactive "FWrite agenda to file: \nP")
3220 (if (or (not (file-writable-p file))
3221 (and (file-exists-p file)
3222 (not (y-or-n-p (format "Overwrite existing file %s? " file)))))
3223 (error "Cannot write agenda to file %s" file))
3224 (org-let (if nosettings nil org-agenda-exporter-settings)
3225 '(save-excursion
3226 (save-window-excursion
3227 (org-agenda-mark-filtered-text)
3228 (let ((bs (copy-sequence (buffer-string))) beg content)
3229 (org-agenda-unmark-filtered-text)
3230 (with-temp-buffer
3231 (rename-buffer org-agenda-write-buffer-name t)
3232 (set-buffer-modified-p nil)
3233 (insert bs)
3234 (org-agenda-remove-marked-text 'org-filtered)
3235 (while (setq beg (text-property-any (point-min) (point-max)
3236 'org-filtered t))
3237 (delete-region
3238 beg (or (next-single-property-change beg 'org-filtered)
3239 (point-max))))
3240 (run-hooks 'org-agenda-before-write-hook)
3241 (cond
3242 ((org-bound-and-true-p org-mobile-creating-agendas)
3243 (org-mobile-write-agenda-for-mobile file))
3244 ((string-match "\\.org\\'" file)
3245 (let (content p m message-log-max)
3246 (goto-char (point-min))
3247 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3248 (goto-char p)
3249 (setq m (get-text-property (point) 'org-hd-marker))
3250 (when m
3251 (push (save-excursion
3252 (set-buffer (marker-buffer m))
3253 (goto-char m)
3254 (org-copy-subtree 1 nil t t)
3255 org-subtree-clip)
3256 content)))
3257 (find-file file)
3258 (erase-buffer)
3259 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3260 (write-file file)
3261 (kill-buffer (current-buffer))
3262 (message "Org file written to %s" file)))
3263 ((string-match "\\.html?\\'" file)
3264 (require 'htmlize)
3265 (set-buffer (htmlize-buffer (current-buffer)))
3266 (when org-agenda-export-html-style
3267 ;; replace <style> section with org-agenda-export-html-style
3268 (goto-char (point-min))
3269 (kill-region (- (search-forward "<style") 6)
3270 (search-forward "</style>"))
3271 (insert org-agenda-export-html-style))
3272 (write-file file)
3273 (kill-buffer (current-buffer))
3274 (message "HTML written to %s" file))
3275 ((string-match "\\.ps\\'" file)
3276 (require 'ps-print)
3277 (ps-print-buffer-with-faces file)
3278 (message "Postscript written to %s" file))
3279 ((string-match "\\.pdf\\'" file)
3280 (require 'ps-print)
3281 (ps-print-buffer-with-faces
3282 (concat (file-name-sans-extension file) ".ps"))
3283 (call-process "ps2pdf" nil nil nil
3284 (expand-file-name
3285 (concat (file-name-sans-extension file) ".ps"))
3286 (expand-file-name file))
3287 (delete-file (concat (file-name-sans-extension file) ".ps"))
3288 (message "PDF written to %s" file))
3289 ((string-match "\\.ics\\'" file)
3290 (require 'ox-icalendar)
3291 (org-icalendar-export-current-agenda (expand-file-name file)))
3293 (let ((bs (buffer-string)))
3294 (find-file file)
3295 (erase-buffer)
3296 (insert bs)
3297 (save-buffer 0)
3298 (kill-buffer (current-buffer))
3299 (message "Plain text written to %s" file))))))))
3300 (set-buffer (or agenda-bufname
3301 (and (org-called-interactively-p 'any) (buffer-name))
3302 org-agenda-buffer-name)))
3303 (when open (org-open-file file)))
3305 (defvar org-agenda-tag-filter-overlays nil)
3306 (defvar org-agenda-cat-filter-overlays nil)
3308 (defun org-agenda-mark-filtered-text ()
3309 "Mark all text hidden by filtering with a text property."
3310 (let ((inhibit-read-only t))
3311 (mapc
3312 (lambda (o)
3313 (when (equal (overlay-buffer o) (current-buffer))
3314 (put-text-property
3315 (overlay-start o) (overlay-end o)
3316 'org-filtered t)))
3317 (append org-agenda-tag-filter-overlays
3318 org-agenda-cat-filter-overlays))))
3320 (defun org-agenda-unmark-filtered-text ()
3321 "Remove the filtering text property."
3322 (let ((inhibit-read-only t))
3323 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3325 (defun org-agenda-remove-marked-text (property &optional value)
3326 "Delete all text marked with VALUE of PROPERTY.
3327 VALUE defaults to t."
3328 (let (beg)
3329 (setq value (or value t))
3330 (while (setq beg (text-property-any (point-min) (point-max)
3331 property value))
3332 (delete-region
3333 beg (or (next-single-property-change beg 'org-filtered)
3334 (point-max))))))
3336 (defun org-agenda-add-entry-text ()
3337 "Add entry text to agenda lines.
3338 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3339 entry text following headings shown in the agenda.
3340 Drawers will be excluded, also the line with scheduling/deadline info."
3341 (when (and (> org-agenda-add-entry-text-maxlines 0)
3342 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3343 (let (m txt)
3344 (goto-char (point-min))
3345 (while (not (eobp))
3346 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3347 (beginning-of-line 2)
3348 (setq txt (org-agenda-get-some-entry-text
3349 m org-agenda-add-entry-text-maxlines " > "))
3350 (end-of-line 1)
3351 (if (string-match "\\S-" txt)
3352 (insert "\n" txt)
3353 (or (eobp) (forward-char 1))))))))
3355 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3356 &rest keep)
3357 "Extract entry text from MARKER, at most N-LINES lines.
3358 This will ignore drawers etc, just get the text.
3359 If INDENT is given, prefix every line with this string. If KEEP is
3360 given, it is a list of symbols, defining stuff that should not be
3361 removed from the entry content. Currently only `planning' is allowed here."
3362 (let (txt drawer-re kwd-time-re ind)
3363 (save-excursion
3364 (with-current-buffer (marker-buffer marker)
3365 (if (not (derived-mode-p 'org-mode))
3366 (setq txt "")
3367 (save-excursion
3368 (save-restriction
3369 (widen)
3370 (goto-char marker)
3371 (end-of-line 1)
3372 (setq txt (buffer-substring
3373 (min (1+ (point)) (point-max))
3374 (progn (outline-next-heading) (point)))
3375 drawer-re org-drawer-regexp
3376 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3377 ".*\n?"))
3378 (with-temp-buffer
3379 (insert txt)
3380 (when org-agenda-add-entry-text-descriptive-links
3381 (goto-char (point-min))
3382 (while (org-activate-bracket-links (point-max))
3383 (add-text-properties (match-beginning 0) (match-end 0)
3384 '(face org-link))))
3385 (goto-char (point-min))
3386 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3387 (set-text-properties (match-beginning 0) (match-end 0)
3388 nil))
3389 (goto-char (point-min))
3390 (while (re-search-forward drawer-re nil t)
3391 (delete-region
3392 (match-beginning 0)
3393 (progn (re-search-forward
3394 "^[ \t]*:END:.*\n?" nil 'move)
3395 (point))))
3396 (unless (member 'planning keep)
3397 (goto-char (point-min))
3398 (while (re-search-forward kwd-time-re nil t)
3399 (replace-match "")))
3400 (goto-char (point-min))
3401 (when org-agenda-entry-text-exclude-regexps
3402 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3403 (while (setq re (pop re-list))
3404 (goto-char (point-min))
3405 (while (re-search-forward re nil t)
3406 (replace-match "")))))
3407 (goto-char (point-max))
3408 (skip-chars-backward " \t\n")
3409 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3411 ;; find and remove min common indentation
3412 (goto-char (point-min))
3413 (untabify (point-min) (point-max))
3414 (setq ind (org-get-indentation))
3415 (while (not (eobp))
3416 (unless (looking-at "[ \t]*$")
3417 (setq ind (min ind (org-get-indentation))))
3418 (beginning-of-line 2))
3419 (goto-char (point-min))
3420 (while (not (eobp))
3421 (unless (looking-at "[ \t]*$")
3422 (move-to-column ind)
3423 (delete-region (point-at-bol) (point)))
3424 (beginning-of-line 2))
3426 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3428 (goto-char (point-min))
3429 (when indent
3430 (while (and (not (eobp)) (re-search-forward "^" nil t))
3431 (replace-match indent t t)))
3432 (goto-char (point-min))
3433 (while (looking-at "[ \t]*\n") (replace-match ""))
3434 (goto-char (point-max))
3435 (when (> (org-current-line)
3436 n-lines)
3437 (org-goto-line (1+ n-lines))
3438 (backward-char 1))
3439 (setq txt (buffer-substring (point-min) (point)))))))))
3440 txt))
3442 (defun org-check-for-org-mode ()
3443 "Make sure current buffer is in org-mode. Error if not."
3444 (or (derived-mode-p 'org-mode)
3445 (error "Cannot execute org-mode agenda command on buffer in %s"
3446 major-mode)))
3448 ;;; Agenda prepare and finalize
3450 (defvar org-agenda-multi nil) ; dynamically scoped
3451 (defvar org-agenda-pre-window-conf nil)
3452 (defvar org-agenda-columns-active nil)
3453 (defvar org-agenda-name nil)
3454 (defvar org-agenda-tag-filter nil)
3455 (defvar org-agenda-category-filter nil)
3456 (defvar org-agenda-top-category-filter nil)
3457 (defvar org-agenda-tag-filter-while-redo nil)
3458 (defvar org-agenda-tag-filter-preset nil
3459 "A preset of the tags filter used for secondary agenda filtering.
3460 This must be a list of strings, each string must be a single tag preceded
3461 by \"+\" or \"-\".
3462 This variable should not be set directly, but agenda custom commands can
3463 bind it in the options section. The preset filter is a global property of
3464 the entire agenda view. In a block agenda, it will not work reliably to
3465 define a filter for one of the individual blocks. You need to set it in
3466 the global options and expect it to be applied to the entire view.")
3468 (defvar org-agenda-category-filter-preset nil
3469 "A preset of the category filter used for secondary agenda filtering.
3470 This must be a list of strings, each string must be a single category
3471 preceded by \"+\" or \"-\".
3472 This variable should not be set directly, but agenda custom commands can
3473 bind it in the options section. The preset filter is a global property of
3474 the entire agenda view. In a block agenda, it will not work reliably to
3475 define a filter for one of the individual blocks. You need to set it in
3476 the global options and expect it to be applied to the entire view.")
3479 (defun org-agenda-use-sticky-p ()
3480 "Return non-nil if an agenda buffer named
3481 `org-agenda-buffer-name' exists and should be shown instead of
3482 generating a new one."
3483 (and
3484 ;; turned off by user
3485 org-agenda-sticky
3486 ;; For multi-agenda buffer already exists
3487 (not org-agenda-multi)
3488 ;; buffer found
3489 (get-buffer org-agenda-buffer-name)
3490 ;; C-u parameter is same as last call
3491 (with-current-buffer (get-buffer org-agenda-buffer-name)
3492 (and
3493 (equal current-prefix-arg
3494 org-agenda-last-prefix-arg)
3495 ;; In case user turned stickiness on, while having existing
3496 ;; Agenda buffer active, don't reuse that buffer, because it
3497 ;; does not have org variables local
3498 org-agenda-this-buffer-is-sticky))))
3500 (defun org-agenda-prepare-window (abuf)
3501 "Setup agenda buffer in the window."
3502 (let* ((awin (get-buffer-window abuf))
3503 wconf)
3504 (cond
3505 ((equal (current-buffer) abuf) nil)
3506 (awin (select-window awin))
3507 ((not (setq wconf (current-window-configuration))))
3508 ((equal org-agenda-window-setup 'current-window)
3509 (org-pop-to-buffer-same-window abuf))
3510 ((equal org-agenda-window-setup 'other-window)
3511 (org-switch-to-buffer-other-window abuf))
3512 ((equal org-agenda-window-setup 'other-frame)
3513 (switch-to-buffer-other-frame abuf))
3514 ((equal org-agenda-window-setup 'reorganize-frame)
3515 (delete-other-windows)
3516 (org-switch-to-buffer-other-window abuf)))
3517 ;; additional test in case agenda is invoked from within agenda
3518 ;; buffer via elisp link
3519 (unless (equal (current-buffer) abuf)
3520 (org-pop-to-buffer-same-window abuf))
3521 (setq org-agenda-pre-window-conf
3522 (or org-agenda-pre-window-conf wconf))))
3524 (defun org-agenda-prepare (&optional name)
3525 (if (org-agenda-use-sticky-p)
3526 (progn
3527 ;; Popup existing buffer
3528 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3529 (message "Sticky Agenda buffer, use `r' to refresh")
3530 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3531 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3532 (setq org-todo-keywords-for-agenda nil)
3533 (setq org-drawers-for-agenda nil)
3534 (unless org-agenda-persistent-filter
3535 (setq org-agenda-tag-filter nil
3536 org-agenda-category-filter nil))
3537 (put 'org-agenda-tag-filter :preset-filter
3538 org-agenda-tag-filter-preset)
3539 (put 'org-agenda-category-filter :preset-filter
3540 org-agenda-category-filter-preset)
3541 (if org-agenda-multi
3542 (progn
3543 (setq buffer-read-only nil)
3544 (goto-char (point-max))
3545 (unless (or (bobp) org-agenda-compact-blocks
3546 (not org-agenda-block-separator))
3547 (insert "\n"
3548 (if (stringp org-agenda-block-separator)
3549 org-agenda-block-separator
3550 (make-string (window-width) org-agenda-block-separator))
3551 "\n"))
3552 (narrow-to-region (point) (point-max)))
3553 (setq org-done-keywords-for-agenda nil)
3555 ;; Setting any org variables that are in org-agenda-local-vars
3556 ;; list need to be done after the prepare call
3557 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3558 (setq buffer-read-only nil)
3559 (org-agenda-reset-markers)
3560 (let ((inhibit-read-only t)) (erase-buffer))
3561 (org-agenda-mode)
3562 (setq org-agenda-buffer (current-buffer))
3563 (setq org-agenda-contributing-files nil)
3564 (setq org-agenda-columns-active nil)
3565 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3566 (setq org-todo-keywords-for-agenda
3567 (org-uniquify org-todo-keywords-for-agenda))
3568 (setq org-done-keywords-for-agenda
3569 (org-uniquify org-done-keywords-for-agenda))
3570 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3571 (setq org-agenda-last-prefix-arg current-prefix-arg)
3572 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3573 (and name (not org-agenda-name)
3574 (org-set-local 'org-agenda-name name)))
3575 (setq buffer-read-only nil)))
3577 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3578 (defun org-agenda-finalize ()
3579 "Finishing touch for the agenda buffer, called just before displaying it."
3580 (unless org-agenda-multi
3581 (save-excursion
3582 (let ((inhibit-read-only t))
3583 (goto-char (point-min))
3584 (save-excursion
3585 (while (org-activate-bracket-links (point-max))
3586 (add-text-properties (match-beginning 0) (match-end 0)
3587 '(face org-link))))
3588 (save-excursion
3589 (while (org-activate-plain-links (point-max))
3590 (add-text-properties (match-beginning 0) (match-end 0)
3591 '(face org-link))))
3592 (unless (eq org-agenda-remove-tags t)
3593 (org-agenda-align-tags))
3594 (unless org-agenda-with-colors
3595 (remove-text-properties (point-min) (point-max) '(face nil)))
3596 (if (and (boundp 'org-agenda-overriding-columns-format)
3597 org-agenda-overriding-columns-format)
3598 (org-set-local 'org-agenda-overriding-columns-format
3599 org-agenda-overriding-columns-format))
3600 (if (and (boundp 'org-agenda-view-columns-initially)
3601 org-agenda-view-columns-initially)
3602 (org-agenda-columns))
3603 (when org-agenda-fontify-priorities
3604 (org-agenda-fontify-priorities))
3605 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3606 (org-agenda-dim-blocked-tasks))
3607 ;; We need to widen when `org-agenda-finalize' is called from
3608 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3609 (when org-clock-current-task
3610 (save-restriction
3611 (widen)
3612 (org-agenda-mark-clocking-task)))
3613 (when org-agenda-entry-text-mode
3614 (org-agenda-entry-text-hide)
3615 (org-agenda-entry-text-show))
3616 (if (and (functionp 'org-habit-insert-consistency-graphs)
3617 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3618 (org-habit-insert-consistency-graphs))
3619 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3620 (unless (or (eq org-agenda-show-inherited-tags 'always)
3621 (and (listp org-agenda-show-inherited-tags)
3622 (memq org-agenda-type org-agenda-show-inherited-tags))
3623 (and (eq org-agenda-show-inherited-tags t)
3624 (or (eq org-agenda-use-tag-inheritance t)
3625 (and (listp org-agenda-use-tag-inheritance)
3626 (not (memq org-agenda-type
3627 org-agenda-use-tag-inheritance))))))
3628 (let (mrk)
3629 (save-excursion
3630 (goto-char (point-min))
3631 (while (equal (forward-line) 0)
3632 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3633 (get-text-property (point) 'org-hd-marker)))
3634 (put-text-property (point-at-bol) (point-at-eol)
3635 'tags (org-with-point-at mrk
3636 (delete-dups
3637 (mapcar 'downcase (org-get-tags-at))))))))))
3638 (run-hooks 'org-agenda-finalize-hook)
3639 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3640 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3641 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3642 (org-agenda-filter-apply org-agenda-category-filter 'category))
3643 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3645 (defun org-agenda-mark-clocking-task ()
3646 "Mark the current clock entry in the agenda if it is present."
3647 (org-agenda-unmark-clocking-task)
3648 (when (marker-buffer org-clock-hd-marker)
3649 (save-excursion
3650 (goto-char (point-min))
3651 (let (s ov)
3652 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3653 (goto-char s)
3654 (when (equal (org-get-at-bol 'org-hd-marker)
3655 org-clock-hd-marker)
3656 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3657 (overlay-put ov 'type 'org-agenda-clocking)
3658 (overlay-put ov 'face 'org-agenda-clocking)
3659 (overlay-put ov 'help-echo
3660 "The clock is running in this item")))))))
3662 (defun org-agenda-unmark-clocking-task ()
3663 "Unmark the current clocking task."
3664 (mapc (lambda (o)
3665 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3666 (delete-overlay o)))
3667 (overlays-in (point-min) (point-max))))
3669 (defun org-agenda-fontify-priorities ()
3670 "Make highest priority lines bold, and lowest italic."
3671 (interactive)
3672 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3673 (delete-overlay o)))
3674 (overlays-in (point-min) (point-max)))
3675 (save-excursion
3676 (let (b e p ov h l)
3677 (goto-char (point-min))
3678 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3679 (setq h (or (get-char-property (point) 'org-highest-priority)
3680 org-highest-priority)
3681 l (or (get-char-property (point) 'org-lowest-priority)
3682 org-lowest-priority)
3683 p (string-to-char (match-string 1))
3684 b (match-beginning 0)
3685 e (if (eq org-agenda-fontify-priorities 'cookies)
3686 (match-end 0)
3687 (point-at-eol))
3688 ov (make-overlay b e))
3689 (overlay-put
3690 ov 'face
3691 (cons (cond ((org-face-from-face-or-color
3692 'priority nil
3693 (cdr (assoc p org-priority-faces))))
3694 ((and (listp org-agenda-fontify-priorities)
3695 (org-face-from-face-or-color
3696 'priority nil
3697 (cdr (assoc p org-agenda-fontify-priorities)))))
3698 ((equal p l) 'italic)
3699 ((equal p h) 'bold))
3700 'org-priority))
3701 (overlay-put ov 'org-type 'org-priority)))))
3703 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3704 (interactive "P")
3705 "Dim currently blocked TODO's in the agenda display."
3706 (message "Dim or hide blocked tasks...")
3707 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3708 (delete-overlay o)))
3709 (overlays-in (point-min) (point-max)))
3710 (save-excursion
3711 (let ((inhibit-read-only t)
3712 (org-depend-tag-blocked nil)
3713 (invis (or (not (null invisible))
3714 (eq org-agenda-dim-blocked-tasks 'invisible)))
3715 org-blocked-by-checkboxes
3716 invis1 b e p ov h l)
3717 (goto-char (point-min))
3718 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3719 (and pos (goto-char (1+ pos))))
3720 (setq org-blocked-by-checkboxes nil invis1 invis)
3721 (let ((marker (org-get-at-bol 'org-hd-marker)))
3722 (when (and marker
3723 (with-current-buffer (marker-buffer marker)
3724 (save-excursion (goto-char marker)
3725 (org-entry-blocked-p))))
3726 (if org-blocked-by-checkboxes (setq invis1 nil))
3727 (setq b (if invis1
3728 (max (point-min) (1- (point-at-bol)))
3729 (point-at-bol))
3730 e (point-at-eol)
3731 ov (make-overlay b e))
3732 (if invis1
3733 (overlay-put ov 'invisible t)
3734 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3735 (overlay-put ov 'org-type 'org-blocked-todo))))))
3736 (message "Dim or hide blocked tasks...done"))
3738 (defvar org-agenda-skip-function nil
3739 "Function to be called at each match during agenda construction.
3740 If this function returns nil, the current match should not be skipped.
3741 Otherwise, the function must return a position from where the search
3742 should be continued.
3743 This may also be a Lisp form, it will be evaluated.
3744 Never set this variable using `setq' or so, because then it will apply
3745 to all future agenda commands. If you do want a global skipping condition,
3746 use the option `org-agenda-skip-function-global' instead.
3747 The correct usage for `org-agenda-skip-function' is to bind it with
3748 `let' to scope it dynamically into the agenda-constructing command.
3749 A good way to set it is through options in `org-agenda-custom-commands'.")
3751 (defun org-agenda-skip ()
3752 "Throw to `:skip' in places that should be skipped.
3753 Also moves point to the end of the skipped region, so that search can
3754 continue from there."
3755 (let ((p (point-at-bol)) to)
3756 (when (or
3757 (save-excursion (goto-char p) (looking-at comment-start-skip))
3758 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3759 (get-text-property p :org-archived)
3760 (org-end-of-subtree t))
3761 (and org-agenda-skip-comment-trees
3762 (get-text-property p :org-comment)
3763 (org-end-of-subtree t))
3764 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3765 (org-agenda-skip-eval org-agenda-skip-function)))
3766 (goto-char to))
3767 (org-in-src-block-p t))
3768 (throw :skip t))))
3770 (defun org-agenda-skip-eval (form)
3771 "If FORM is a function or a list, call (or eval) is and return result.
3772 `save-excursion' and `save-match-data' are wrapped around the call, so point
3773 and match data are returned to the previous state no matter what these
3774 functions do."
3775 (let (fp)
3776 (and form
3777 (or (setq fp (functionp form))
3778 (consp form))
3779 (save-excursion
3780 (save-match-data
3781 (if fp
3782 (funcall form)
3783 (eval form)))))))
3785 (defvar org-agenda-markers nil
3786 "List of all currently active markers created by `org-agenda'.")
3787 (defvar org-agenda-last-marker-time (org-float-time)
3788 "Creation time of the last agenda marker.")
3790 (defun org-agenda-new-marker (&optional pos)
3791 "Return a new agenda marker.
3792 Org-mode keeps a list of these markers and resets them when they are
3793 no longer in use."
3794 (let ((m (copy-marker (or pos (point)))))
3795 (setq org-agenda-last-marker-time (org-float-time))
3796 (if org-agenda-buffer
3797 (with-current-buffer org-agenda-buffer
3798 (push m org-agenda-markers))
3799 (push m org-agenda-markers))
3802 (defun org-agenda-reset-markers ()
3803 "Reset markers created by `org-agenda'."
3804 (while org-agenda-markers
3805 (move-marker (pop org-agenda-markers) nil)))
3807 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3808 "Save relative positions of markers in region.
3809 This check for agenda markers in all agenda buffers currently active."
3810 (dolist (buf (buffer-list))
3811 (with-current-buffer buf
3812 (when (eq major-mode 'org-agenda-mode)
3813 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3814 org-agenda-markers)))))
3816 ;;; Entry text mode
3818 (defun org-agenda-entry-text-show-here ()
3819 "Add some text from the entry as context to the current line."
3820 (let (m txt o)
3821 (setq m (org-get-at-bol 'org-hd-marker))
3822 (unless (marker-buffer m)
3823 (error "No marker points to an entry here"))
3824 (setq txt (concat "\n" (org-no-properties
3825 (org-agenda-get-some-entry-text
3826 m org-agenda-entry-text-maxlines
3827 org-agenda-entry-text-leaders))))
3828 (when (string-match "\\S-" txt)
3829 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3830 (overlay-put o 'evaporate t)
3831 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3832 (overlay-put o 'after-string txt))))
3834 (defun org-agenda-entry-text-show ()
3835 "Add entry context for all agenda lines."
3836 (interactive)
3837 (save-excursion
3838 (goto-char (point-max))
3839 (beginning-of-line 1)
3840 (while (not (bobp))
3841 (when (org-get-at-bol 'org-hd-marker)
3842 (org-agenda-entry-text-show-here))
3843 (beginning-of-line 0))))
3845 (defun org-agenda-entry-text-hide ()
3846 "Remove any shown entry context."
3847 (delq nil
3848 (mapcar (lambda (o)
3849 (if (eq (overlay-get o 'org-overlay-type)
3850 'agenda-entry-content)
3851 (progn (delete-overlay o) t)))
3852 (overlays-in (point-min) (point-max)))))
3854 (defun org-agenda-get-day-face (date)
3855 "Return the face DATE should be displayed with."
3856 (or (and (functionp org-agenda-day-face-function)
3857 (funcall org-agenda-day-face-function date))
3858 (cond ((org-agenda-todayp date)
3859 'org-agenda-date-today)
3860 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3861 'org-agenda-date-weekend)
3862 (t 'org-agenda-date))))
3864 ;;; Agenda timeline
3866 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3868 (defun org-timeline (&optional dotodo)
3869 "Show a time-sorted view of the entries in the current org file.
3870 Only entries with a time stamp of today or later will be listed. With
3871 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3872 under the current date.
3873 If the buffer contains an active region, only check the region for
3874 dates."
3875 (interactive "P")
3876 (let* ((dopast t)
3877 (org-agenda-show-log-scoped org-agenda-show-log)
3878 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3879 (current-buffer))))
3880 (date (calendar-current-date))
3881 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3882 (end (if (org-region-active-p) (region-end) (point-max)))
3883 (day-numbers (org-get-all-dates
3884 beg end 'no-ranges
3885 t org-agenda-show-log-scoped ; always include today
3886 org-timeline-show-empty-dates))
3887 (org-deadline-warning-days 0)
3888 (org-agenda-only-exact-dates t)
3889 (today (org-today))
3890 (past t)
3891 args
3892 s e rtn d emptyp)
3893 (setq org-agenda-redo-command
3894 (list 'progn
3895 (list 'org-switch-to-buffer-other-window (current-buffer))
3896 (list 'org-timeline (list 'quote dotodo))))
3897 (if (not dopast)
3898 ;; Remove past dates from the list of dates.
3899 (setq day-numbers (delq nil (mapcar (lambda(x)
3900 (if (>= x today) x nil))
3901 day-numbers))))
3902 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3903 (org-compile-prefix-format 'timeline)
3904 (org-set-sorting-strategy 'timeline)
3905 (if org-agenda-show-log-scoped (push :closed args))
3906 (push :timestamp args)
3907 (push :deadline args)
3908 (push :scheduled args)
3909 (push :sexp args)
3910 (if dotodo (push :todo args))
3911 (insert "Timeline of file " entry "\n")
3912 (add-text-properties (point-min) (point)
3913 (list 'face 'org-agenda-structure))
3914 (org-agenda-mark-header-line (point-min))
3915 (while (setq d (pop day-numbers))
3916 (if (and (listp d) (eq (car d) :omitted))
3917 (progn
3918 (setq s (point))
3919 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3920 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3921 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3922 (if (and (>= d today)
3923 dopast
3924 past)
3925 (progn
3926 (setq past nil)
3927 (insert (make-string 79 ?-) "\n")))
3928 (setq date (calendar-gregorian-from-absolute d))
3929 (setq s (point))
3930 (setq rtn (and (not emptyp)
3931 (apply 'org-agenda-get-day-entries entry
3932 date args)))
3933 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3934 (progn
3935 (insert
3936 (if (stringp org-agenda-format-date)
3937 (format-time-string org-agenda-format-date
3938 (org-time-from-absolute date))
3939 (funcall org-agenda-format-date date))
3940 "\n")
3941 (put-text-property s (1- (point)) 'face
3942 (org-agenda-get-day-face date))
3943 (put-text-property s (1- (point)) 'org-date-line t)
3944 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3945 (if (equal d today)
3946 (put-text-property s (1- (point)) 'org-today t))
3947 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
3948 (put-text-property s (1- (point)) 'day d)))))
3949 (goto-char (point-min))
3950 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3951 (point-min)))
3952 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3953 (org-agenda-finalize)
3954 (setq buffer-read-only t)))
3956 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3957 "Return a list of all relevant day numbers from BEG to END buffer positions.
3958 If NO-RANGES is non-nil, include only the start and end dates of a range,
3959 not every single day in the range. If FORCE-TODAY is non-nil, make
3960 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3961 inactive time stamps (those in square brackets) are included.
3962 When EMPTY is non-nil, also include days without any entries."
3963 (let ((re (concat
3964 (if pre-re pre-re "")
3965 (if inactive org-ts-regexp-both org-ts-regexp)))
3966 dates dates1 date day day1 day2 ts1 ts2 pos)
3967 (if force-today
3968 (setq dates (list (org-today))))
3969 (save-excursion
3970 (goto-char beg)
3971 (while (re-search-forward re end t)
3972 (setq day (time-to-days (org-time-string-to-time
3973 (substring (match-string 1) 0 10)
3974 (current-buffer) (match-beginning 0))))
3975 (or (memq day dates) (push day dates)))
3976 (unless no-ranges
3977 (goto-char beg)
3978 (while (re-search-forward org-tr-regexp end t)
3979 (setq pos (match-beginning 0))
3980 (setq ts1 (substring (match-string 1) 0 10)
3981 ts2 (substring (match-string 2) 0 10)
3982 day1 (time-to-days (org-time-string-to-time
3983 ts1 (current-buffer) pos))
3984 day2 (time-to-days (org-time-string-to-time
3985 ts2 (current-buffer) pos)))
3986 (while (< (setq day1 (1+ day1)) day2)
3987 (or (memq day1 dates) (push day1 dates)))))
3988 (setq dates (sort dates '<))
3989 (when empty
3990 (while (setq day (pop dates))
3991 (setq day2 (car dates))
3992 (push day dates1)
3993 (when (and day2 empty)
3994 (if (or (eq empty t)
3995 (and (numberp empty) (<= (- day2 day) empty)))
3996 (while (< (setq day (1+ day)) day2)
3997 (push (list day) dates1))
3998 (push (cons :omitted (- day2 day)) dates1))))
3999 (setq dates (nreverse dates1)))
4000 dates)))
4002 ;;; Agenda Daily/Weekly
4004 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4005 "Start day for the agenda view.
4006 Custom commands can set this variable in the options section.
4007 See the docstring of `org-read-date' on allowed values.")
4008 (defvar org-starting-day nil) ; local variable in the agenda buffer
4009 (defvar org-arg-loc nil) ; local variable
4011 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4012 "List of types searched for when creating the daily/weekly agenda.
4013 This variable is a list of symbols that controls the types of
4014 items that appear in the daily/weekly agenda. Allowed symbols in this
4015 list are are
4017 :timestamp List items containing a date stamp or date range matching
4018 the selected date. This includes sexp entries in
4019 angular brackets.
4021 :sexp List entries resulting from plain diary-like sexps.
4023 :deadline List deadline due on that date. When the date is today,
4024 also list any deadlines past due, or due within
4025 `org-deadline-warning-days'. `:deadline' must appear before
4026 `:scheduled' if the setting of
4027 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4028 any effect.
4030 :scheduled List all items which are scheduled for the given date.
4031 The diary for *today* also contains items which were
4032 scheduled earlier and are not yet marked DONE.
4034 By default, all four types are turned on.
4036 Never set this variable globally using `setq', because then it
4037 will apply to all future agenda commands. Instead, bind it with
4038 `let' to scope it dynamically into the agenda-constructing
4039 command. A good way to set it is through options in
4040 `org-agenda-custom-commands'. For a more flexible (though
4041 somewhat less efficient) way of determining what is included in
4042 the daily/weekly agenda, see `org-agenda-skip-function'.")
4044 (defvar org-agenda-buffer-tmp-name nil)
4045 ;;;###autoload
4046 (defun org-agenda-list (&optional arg start-day span)
4047 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4048 The view will be for the current day or week, but from the overview buffer
4049 you will be able to go to other days/weeks.
4051 With a numeric prefix argument in an interactive call, the agenda will
4052 span ARG days. Lisp programs should instead specify SPAN to change
4053 the number of days. SPAN defaults to `org-agenda-span'.
4055 START-DAY defaults to TODAY, or to the most recent match for the weekday
4056 given in `org-agenda-start-on-weekday'."
4057 (interactive "P")
4058 (if org-agenda-overriding-arguments
4059 (setq arg (car org-agenda-overriding-arguments)
4060 start-day (nth 1 org-agenda-overriding-arguments)
4061 span (nth 2 org-agenda-overriding-arguments)))
4062 (if (and (integerp arg) (> arg 0))
4063 (setq span arg arg nil))
4064 (catch 'exit
4065 (setq org-agenda-buffer-name
4066 (or org-agenda-buffer-tmp-name
4067 (if org-agenda-sticky
4068 (cond ((and org-keys (stringp org-match))
4069 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4070 (org-keys
4071 (format "*Org Agenda(%s)*" org-keys))
4072 (t "*Org Agenda(a)*")))
4073 org-agenda-buffer-name))
4074 (org-agenda-prepare "Day/Week")
4075 (setq start-day (or start-day org-agenda-start-day))
4076 (if (stringp start-day)
4077 ;; Convert to an absolute day number
4078 (setq start-day (time-to-days (org-read-date nil t start-day))))
4079 (org-compile-prefix-format 'agenda)
4080 (org-set-sorting-strategy 'agenda)
4081 (let* ((span (org-agenda-ndays-to-span
4082 (or span org-agenda-ndays org-agenda-span)))
4083 (today (org-today))
4084 (sd (or start-day today))
4085 (ndays (org-agenda-span-to-ndays span sd))
4086 (org-agenda-start-on-weekday
4087 (if (eq ndays 7)
4088 org-agenda-start-on-weekday))
4089 (thefiles (org-agenda-files nil 'ifmode))
4090 (files thefiles)
4091 (start (if (or (null org-agenda-start-on-weekday)
4092 (< ndays 7))
4094 (let* ((nt (calendar-day-of-week
4095 (calendar-gregorian-from-absolute sd)))
4096 (n1 org-agenda-start-on-weekday)
4097 (d (- nt n1)))
4098 (- sd (+ (if (< d 0) 7 0) d)))))
4099 (day-numbers (list start))
4100 (day-cnt 0)
4101 (inhibit-redisplay (not debug-on-error))
4102 (org-agenda-show-log-scoped org-agenda-show-log)
4103 s e rtn rtnall file date d start-pos end-pos todayp
4104 clocktable-start clocktable-end filter)
4105 (setq org-agenda-redo-command
4106 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4107 (dotimes (n (1- ndays))
4108 (push (1+ (car day-numbers)) day-numbers))
4109 (setq day-numbers (nreverse day-numbers))
4110 (setq clocktable-start (car day-numbers)
4111 clocktable-end (1+ (or (org-last day-numbers) 0)))
4112 (org-set-local 'org-starting-day (car day-numbers))
4113 (org-set-local 'org-arg-loc arg)
4114 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4115 (unless org-agenda-compact-blocks
4116 (let* ((d1 (car day-numbers))
4117 (d2 (org-last day-numbers))
4118 (w1 (org-days-to-iso-week d1))
4119 (w2 (org-days-to-iso-week d2)))
4120 (setq s (point))
4121 (if org-agenda-overriding-header
4122 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4123 nil 'face 'org-agenda-structure) "\n")
4124 (insert (org-agenda-span-name span)
4125 "-agenda"
4126 (if (< (- d2 d1) 350)
4127 (if (= w1 w2)
4128 (format " (W%02d)" w1)
4129 (format " (W%02d-W%02d)" w1 w2))
4131 ":\n")))
4132 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4133 'org-date-line t))
4134 (org-agenda-mark-header-line s))
4135 (while (setq d (pop day-numbers))
4136 (setq date (calendar-gregorian-from-absolute d)
4137 s (point))
4138 (if (or (setq todayp (= d today))
4139 (and (not start-pos) (= d sd)))
4140 (setq start-pos (point))
4141 (if (and start-pos (not end-pos))
4142 (setq end-pos (point))))
4143 (setq files thefiles
4144 rtnall nil)
4145 (while (setq file (pop files))
4146 (catch 'nextfile
4147 (org-check-agenda-file file)
4148 (let ((org-agenda-entry-types org-agenda-entry-types))
4149 (unless org-agenda-include-deadlines
4150 (setq org-agenda-entry-types
4151 (delq :deadline org-agenda-entry-types)))
4152 (cond
4153 ((memq org-agenda-show-log-scoped '(only clockcheck))
4154 (setq rtn (org-agenda-get-day-entries
4155 file date :closed)))
4156 (org-agenda-show-log-scoped
4157 (setq rtn (apply 'org-agenda-get-day-entries
4158 file date
4159 (append '(:closed) org-agenda-entry-types))))
4161 (setq rtn (apply 'org-agenda-get-day-entries
4162 file date
4163 org-agenda-entry-types)))))
4164 (setq rtnall (append rtnall rtn)))) ;; all entries
4165 (if org-agenda-include-diary
4166 (let ((org-agenda-search-headline-for-time t))
4167 (require 'diary-lib)
4168 (setq rtn (org-get-entries-from-diary date))
4169 (setq rtnall (append rtnall rtn))))
4170 (if (or rtnall org-agenda-show-all-dates)
4171 (progn
4172 (setq day-cnt (1+ day-cnt))
4173 (insert
4174 (if (stringp org-agenda-format-date)
4175 (format-time-string org-agenda-format-date
4176 (org-time-from-absolute date))
4177 (funcall org-agenda-format-date date))
4178 "\n")
4179 (put-text-property s (1- (point)) 'face
4180 (org-agenda-get-day-face date))
4181 (put-text-property s (1- (point)) 'org-date-line t)
4182 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4183 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4184 (when todayp
4185 (put-text-property s (1- (point)) 'org-today t))
4186 (setq rtnall
4187 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4188 (if rtnall (insert ;; all entries
4189 (org-agenda-finalize-entries rtnall 'agenda)
4190 "\n"))
4191 (put-text-property s (1- (point)) 'day d)
4192 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4193 (when (and org-agenda-clockreport-mode clocktable-start)
4194 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4195 ;; the above line is to ensure the restricted range!
4196 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4197 tbl)
4198 (setq p (org-plist-delete p :block))
4199 (setq p (plist-put p :tstart clocktable-start))
4200 (setq p (plist-put p :tend clocktable-end))
4201 (setq p (plist-put p :scope 'agenda))
4202 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4203 (setq filter (or org-agenda-tag-filter-while-redo
4204 (get 'org-agenda-tag-filter :preset-filter))))
4205 (setq p (plist-put p :tags (mapconcat (lambda (x)
4206 (if (string-match "[<>=]" x)
4209 filter ""))))
4210 (setq tbl (apply 'org-clock-get-clocktable p))
4211 (insert tbl)))
4212 (goto-char (point-min))
4213 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4214 (unless (and (pos-visible-in-window-p (point-min))
4215 (pos-visible-in-window-p (point-max)))
4216 (goto-char (1- (point-max)))
4217 (recenter -1)
4218 (if (not (pos-visible-in-window-p (or start-pos 1)))
4219 (progn
4220 (goto-char (or start-pos 1))
4221 (recenter 1))))
4222 (goto-char (or start-pos 1))
4223 (add-text-properties (point-min) (point-max)
4224 `(org-agenda-type agenda
4225 org-last-args (,arg ,start-day ,span)
4226 org-redo-cmd ,org-agenda-redo-command
4227 org-series-cmd ,org-cmd))
4228 (if (eq org-agenda-show-log-scoped 'clockcheck)
4229 (org-agenda-show-clocking-issues))
4230 (org-agenda-finalize)
4231 (setq buffer-read-only t)
4232 (message ""))))
4234 (defun org-agenda-ndays-to-span (n)
4235 "Return a span symbol for a span of N days, or N if none matches."
4236 (cond ((symbolp n) n)
4237 ((= n 1) 'day)
4238 ((= n 7) 'week)
4239 (t n)))
4241 (defun org-agenda-span-to-ndays (span &optional start-day)
4242 "Return ndays from SPAN, possibly starting at START-DAY."
4243 (cond ((numberp span) span)
4244 ((eq span 'day) 1)
4245 ((eq span 'week) 7)
4246 ((eq span 'month)
4247 (let ((date (calendar-gregorian-from-absolute start-day)))
4248 (calendar-last-day-of-month (car date) (caddr date))))
4249 ((eq span 'year)
4250 (let ((date (calendar-gregorian-from-absolute start-day)))
4251 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4253 (defun org-agenda-span-name (span)
4254 "Return a SPAN name."
4255 (if (null span)
4257 (if (symbolp span)
4258 (capitalize (symbol-name span))
4259 (format "%d days" span))))
4261 ;;; Agenda word search
4263 (defvar org-agenda-search-history nil)
4265 (defvar org-search-syntax-table nil
4266 "Special syntax table for org-mode search.
4267 In this table, we have single quotes not as word constituents, to
4268 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4270 (defvar org-mode-syntax-table) ; From org.el
4271 (defun org-search-syntax-table ()
4272 (unless org-search-syntax-table
4273 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4274 (modify-syntax-entry ?' "." org-search-syntax-table)
4275 (modify-syntax-entry ?` "." org-search-syntax-table))
4276 org-search-syntax-table)
4278 (defvar org-agenda-last-search-view-search-was-boolean nil)
4280 ;;;###autoload
4281 (defun org-search-view (&optional todo-only string edit-at)
4282 "Show all entries that contain a phrase or words or regular expressions.
4284 With optional prefix argument TODO-ONLY, only consider entries that are
4285 TODO entries. The argument STRING can be used to pass a default search
4286 string into this function. If EDIT-AT is non-nil, it means that the
4287 user should get a chance to edit this string, with cursor at position
4288 EDIT-AT.
4290 The search string can be viewed either as a phrase that should be found as
4291 is, or it can be broken into a number of snippets, each of which must match
4292 in a Boolean way to select an entry. The default depends on the variable
4293 `org-agenda-search-view-always-boolean'.
4294 Even if this is turned off (the default) you can always switch to
4295 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4297 The default is a direct search of the whole phrase, where each space in
4298 the search string can expand to an arbitrary amount of whitespace,
4299 including newlines.
4301 If using a Boolean search, the search string is split on whitespace and
4302 each snippet is searched separately, with logical AND to select an entry.
4303 Words prefixed with a minus must *not* occur in the entry. Words without
4304 a prefix or prefixed with a plus must occur in the entry. Matching is
4305 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4306 match whole words, not parts of a word) if
4307 `org-agenda-search-view-force-full-words' is set (default is nil).
4309 Boolean search snippets enclosed by curly braces are interpreted as
4310 regular expressions that must or (when preceded with \"-\") must not
4311 match in the entry. Snippets enclosed into double quotes will be taken
4312 as a whole, to include whitespace.
4314 - If the search string starts with an asterisk, search only in headlines.
4315 - If (possibly after the leading star) the search string starts with an
4316 exclamation mark, this also means to look at TODO entries only, an effect
4317 that can also be achieved with a prefix argument.
4318 - If (possibly after star and exclamation mark) the search string starts
4319 with a colon, this will mean that the (non-regexp) snippets of the
4320 Boolean search must match as full words.
4322 This command searches the agenda files, and in addition the files listed
4323 in `org-agenda-text-search-extra-files'."
4324 (interactive "P")
4325 (if org-agenda-overriding-arguments
4326 (setq todo-only (car org-agenda-overriding-arguments)
4327 string (nth 1 org-agenda-overriding-arguments)
4328 edit-at (nth 2 org-agenda-overriding-arguments)))
4329 (let* ((props (list 'face nil
4330 'done-face 'org-agenda-done
4331 'org-not-done-regexp org-not-done-regexp
4332 'org-todo-regexp org-todo-regexp
4333 'org-complex-heading-regexp org-complex-heading-regexp
4334 'mouse-face 'highlight
4335 'help-echo (format "mouse-2 or RET jump to location")))
4336 (full-words org-agenda-search-view-force-full-words)
4337 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4338 regexp rtn rtnall files file pos inherited-tags
4339 marker category category-pos level tags c neg re boolean
4340 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4341 (unless (and (not edit-at)
4342 (stringp string)
4343 (string-match "\\S-" string))
4344 (setq string (read-string
4345 (if org-agenda-search-view-always-boolean
4346 "[+-]Word/{Regexp} ...: "
4347 "Phrase or [+-]Word/{Regexp} ...: ")
4348 (cond
4349 ((integerp edit-at) (cons string edit-at))
4350 (edit-at string))
4351 'org-agenda-search-history)))
4352 (catch 'exit
4353 (if org-agenda-sticky
4354 (setq org-agenda-buffer-name
4355 (if (stringp string)
4356 (format "*Org Agenda(%s:%s)*"
4357 (or org-keys (or (and todo-only "S") "s")) string)
4358 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4359 (org-agenda-prepare "SEARCH")
4360 (org-compile-prefix-format 'search)
4361 (org-set-sorting-strategy 'search)
4362 (setq org-agenda-redo-command
4363 (list 'org-search-view (if todo-only t nil)
4364 (list 'if 'current-prefix-arg nil string)))
4365 (setq org-agenda-query-string string)
4366 (if (equal (string-to-char string) ?*)
4367 (setq hdl-only t
4368 words (substring string 1))
4369 (setq words string))
4370 (when (equal (string-to-char words) ?!)
4371 (setq todo-only t
4372 words (substring words 1)))
4373 (when (equal (string-to-char words) ?:)
4374 (setq full-words t
4375 words (substring words 1)))
4376 (if (or org-agenda-search-view-always-boolean
4377 (member (string-to-char words) '(?- ?+ ?\{)))
4378 (setq boolean t))
4379 (setq words (org-split-string words))
4380 (let (www w)
4381 (while (setq w (pop words))
4382 (while (and (string-match "\\\\\\'" w) words)
4383 (setq w (concat (substring w 0 -1) " " (pop words))))
4384 (push w www))
4385 (setq words (nreverse www) www nil)
4386 (while (setq w (pop words))
4387 (when (and (string-match "\\`[-+]?{" w)
4388 (not (string-match "}\\'" w)))
4389 (while (and words (not (string-match "}\\'" (car words))))
4390 (setq w (concat w " " (pop words))))
4391 (setq w (concat w " " (pop words))))
4392 (push w www))
4393 (setq words (nreverse www)))
4394 (setq org-agenda-last-search-view-search-was-boolean boolean)
4395 (when boolean
4396 (let (wds w)
4397 (while (setq w (pop words))
4398 (if (or (equal (substring w 0 1) "\"")
4399 (and (> (length w) 1)
4400 (member (substring w 0 1) '("+" "-"))
4401 (equal (substring w 1 2) "\"")))
4402 (while (and words (not (equal (substring w -1) "\"")))
4403 (setq w (concat w " " (pop words)))))
4404 (and (string-match "\\`\\([-+]?\\)\"" w)
4405 (setq w (replace-match "\\1" nil nil w)))
4406 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4407 (push w wds))
4408 (setq words (nreverse wds))))
4409 (if boolean
4410 (mapc (lambda (w)
4411 (setq c (string-to-char w))
4412 (if (equal c ?-)
4413 (setq neg t w (substring w 1))
4414 (if (equal c ?+)
4415 (setq neg nil w (substring w 1))
4416 (setq neg nil)))
4417 (if (string-match "\\`{.*}\\'" w)
4418 (setq re (substring w 1 -1))
4419 (if full-words
4420 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4421 (setq re (regexp-quote (downcase w)))))
4422 (if neg (push re regexps-) (push re regexps+)))
4423 words)
4424 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4425 regexps+))
4426 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4427 (if (not regexps+)
4428 (setq regexp org-outline-regexp-bol)
4429 (setq regexp (pop regexps+))
4430 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4431 regexp))))
4432 (setq files (org-agenda-files nil 'ifmode))
4433 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4434 (pop org-agenda-text-search-extra-files)
4435 (setq files (org-add-archive-files files)))
4436 (setq files (append files org-agenda-text-search-extra-files)
4437 rtnall nil)
4438 (while (setq file (pop files))
4439 (setq ee nil)
4440 (catch 'nextfile
4441 (org-check-agenda-file file)
4442 (setq buffer (if (file-exists-p file)
4443 (org-get-agenda-file-buffer file)
4444 (error "No such file %s" file)))
4445 (if (not buffer)
4446 ;; If file does not exist, make sure an error message is sent
4447 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4448 file))))
4449 (with-current-buffer buffer
4450 (with-syntax-table (org-search-syntax-table)
4451 (unless (derived-mode-p 'org-mode)
4452 (error "Agenda file %s is not in `org-mode'" file))
4453 (let ((case-fold-search t))
4454 (save-excursion
4455 (save-restriction
4456 (if org-agenda-restrict
4457 (narrow-to-region org-agenda-restrict-begin
4458 org-agenda-restrict-end)
4459 (widen))
4460 (goto-char (point-min))
4461 (unless (or (org-at-heading-p)
4462 (outline-next-heading))
4463 (throw 'nextfile t))
4464 (goto-char (max (point-min) (1- (point))))
4465 (while (re-search-forward regexp nil t)
4466 (org-back-to-heading t)
4467 (while (and org-agenda-search-view-max-outline-level
4468 (> (org-reduced-level (org-outline-level))
4469 org-agenda-search-view-max-outline-level)
4470 (forward-line -1)
4471 (outline-back-to-heading t)))
4472 (skip-chars-forward "* ")
4473 (setq beg (point-at-bol)
4474 beg1 (point)
4475 end (progn
4476 (outline-next-heading)
4477 (while (and org-agenda-search-view-max-outline-level
4478 (> (org-reduced-level (org-outline-level))
4479 org-agenda-search-view-max-outline-level)
4480 (forward-line 1)
4481 (outline-next-heading)))
4482 (point)))
4484 (catch :skip
4485 (goto-char beg)
4486 (org-agenda-skip)
4487 (setq str (buffer-substring-no-properties
4488 (point-at-bol)
4489 (if hdl-only (point-at-eol) end)))
4490 (mapc (lambda (wr) (when (string-match wr str)
4491 (goto-char (1- end))
4492 (throw :skip t)))
4493 regexps-)
4494 (mapc (lambda (wr) (unless (string-match wr str)
4495 (goto-char (1- end))
4496 (throw :skip t)))
4497 (if todo-only
4498 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4499 regexps+)
4500 regexps+))
4501 (goto-char beg)
4502 (setq marker (org-agenda-new-marker (point))
4503 category (org-get-category)
4504 level (make-string (org-reduced-level (org-outline-level)) ? )
4505 category-pos (get-text-property (point) 'org-category-position)
4506 inherited-tags
4507 (or (eq org-agenda-show-inherited-tags 'always)
4508 (and (listp org-agenda-show-inherited-tags)
4509 (memq 'todo org-agenda-show-inherited-tags))
4510 (and (eq org-agenda-show-inherited-tags t)
4511 (or (eq org-agenda-use-tag-inheritance t)
4512 (memq 'todo org-agenda-use-tag-inheritance))))
4513 tags (org-get-tags-at nil (not inherited-tags))
4514 txt (org-agenda-format-item
4516 (buffer-substring-no-properties
4517 beg1 (point-at-eol))
4518 level category tags t))
4519 (org-add-props txt props
4520 'org-marker marker 'org-hd-marker marker
4521 'org-todo-regexp org-todo-regexp
4522 'level level
4523 'org-complex-heading-regexp org-complex-heading-regexp
4524 'priority 1000 'org-category category
4525 'org-category-position category-pos
4526 'type "search")
4527 (push txt ee)
4528 (goto-char (1- end))))))))))
4529 (setq rtn (nreverse ee))
4530 (setq rtnall (append rtnall rtn)))
4531 (if org-agenda-overriding-header
4532 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4533 nil 'face 'org-agenda-structure) "\n")
4534 (insert "Search words: ")
4535 (add-text-properties (point-min) (1- (point))
4536 (list 'face 'org-agenda-structure))
4537 (setq pos (point))
4538 (insert string "\n")
4539 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4540 (setq pos (point))
4541 (unless org-agenda-multi
4542 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4543 (add-text-properties pos (1- (point))
4544 (list 'face 'org-agenda-structure))))
4545 (org-agenda-mark-header-line (point-min))
4546 (when rtnall
4547 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4548 (goto-char (point-min))
4549 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4550 (add-text-properties (point-min) (point-max)
4551 `(org-agenda-type search
4552 org-last-args (,todo-only ,string ,edit-at)
4553 org-redo-cmd ,org-agenda-redo-command
4554 org-series-cmd ,org-cmd))
4555 (org-agenda-finalize)
4556 (setq buffer-read-only t))))
4558 ;;; Agenda TODO list
4560 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4561 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4562 (concat
4563 (if (or (equal keywords "ALL") (not keywords))
4564 (propertize "ALL" 'face 'warning)
4565 (mapconcat
4566 (lambda (kw)
4567 (propertize kw 'face (org-get-todo-face kw)))
4568 (org-split-string keywords "|")
4569 "|"))
4570 "\n"))
4572 (defvar org-select-this-todo-keyword nil)
4573 (defvar org-last-arg nil)
4575 ;;;###autoload
4576 (defun org-todo-list (&optional arg)
4577 "Show all (not done) TODO entries from all agenda file in a single list.
4578 The prefix arg can be used to select a specific TODO keyword and limit
4579 the list to these. When using \\[universal-argument], you will be prompted
4580 for a keyword. A numeric prefix directly selects the Nth keyword in
4581 `org-todo-keywords-1'."
4582 (interactive "P")
4583 (if org-agenda-overriding-arguments
4584 (setq arg org-agenda-overriding-arguments))
4585 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4586 (let* ((today (org-today))
4587 (date (calendar-gregorian-from-absolute today))
4588 (kwds org-todo-keywords-for-agenda)
4589 (completion-ignore-case t)
4590 (org-select-this-todo-keyword
4591 (if (stringp arg) arg
4592 (and arg (integerp arg) (> arg 0)
4593 (nth (1- arg) kwds))))
4594 rtn rtnall files file pos)
4595 (when (equal arg '(4))
4596 (setq org-select-this-todo-keyword
4597 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4598 (mapcar 'list kwds) nil nil)))
4599 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4600 (catch 'exit
4601 (if org-agenda-sticky
4602 (setq org-agenda-buffer-name
4603 (if (stringp org-select-this-todo-keyword)
4604 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4605 org-select-this-todo-keyword)
4606 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4607 (org-agenda-prepare "TODO")
4608 (org-compile-prefix-format 'todo)
4609 (org-set-sorting-strategy 'todo)
4610 (setq org-agenda-redo-command
4611 `(org-todo-list (or (and (numberp current-prefix-arg)
4612 current-prefix-arg)
4613 ,org-select-this-todo-keyword
4614 current-prefix-arg ,arg)))
4615 (setq files (org-agenda-files nil 'ifmode)
4616 rtnall nil)
4617 (while (setq file (pop files))
4618 (catch 'nextfile
4619 (org-check-agenda-file file)
4620 (setq rtn (org-agenda-get-day-entries file date :todo))
4621 (setq rtnall (append rtnall rtn))))
4622 (if org-agenda-overriding-header
4623 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4624 nil 'face 'org-agenda-structure) "\n")
4625 (insert "Global list of TODO items of type: ")
4626 (add-text-properties (point-min) (1- (point))
4627 (list 'face 'org-agenda-structure
4628 'short-heading
4629 (concat "ToDo: "
4630 (or org-select-this-todo-keyword "ALL"))))
4631 (org-agenda-mark-header-line (point-min))
4632 (insert (org-agenda-propertize-selected-todo-keywords
4633 org-select-this-todo-keyword))
4634 (setq pos (point))
4635 (unless org-agenda-multi
4636 (insert "Available with `N r': (0)[ALL]")
4637 (let ((n 0) s)
4638 (mapc (lambda (x)
4639 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4640 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4641 (insert "\n "))
4642 (insert " " s))
4643 kwds))
4644 (insert "\n"))
4645 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4646 (org-agenda-mark-header-line (point-min))
4647 (when rtnall
4648 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4649 (goto-char (point-min))
4650 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4651 (add-text-properties (point-min) (point-max)
4652 `(org-agenda-type todo
4653 org-last-args ,arg
4654 org-redo-cmd ,org-agenda-redo-command
4655 org-series-cmd ,org-cmd))
4656 (org-agenda-finalize)
4657 (setq buffer-read-only t))))
4659 ;;; Agenda tags match
4661 ;;;###autoload
4662 (defun org-tags-view (&optional todo-only match)
4663 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4664 The prefix arg TODO-ONLY limits the search to TODO entries."
4665 (interactive "P")
4666 (if org-agenda-overriding-arguments
4667 (setq todo-only (car org-agenda-overriding-arguments)
4668 match (nth 1 org-agenda-overriding-arguments)))
4669 (let* ((org-tags-match-list-sublevels
4670 org-tags-match-list-sublevels)
4671 (completion-ignore-case t)
4672 rtn rtnall files file pos matcher
4673 buffer)
4674 (when (and (stringp match) (not (string-match "\\S-" match)))
4675 (setq match nil))
4676 (setq matcher (org-make-tags-matcher match)
4677 match (car matcher) matcher (cdr matcher))
4678 (catch 'exit
4679 (if org-agenda-sticky
4680 (setq org-agenda-buffer-name
4681 (if (stringp match)
4682 (format "*Org Agenda(%s:%s)*"
4683 (or org-keys (or (and todo-only "M") "m")) match)
4684 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4685 (org-agenda-prepare (concat "TAGS " match))
4686 (org-compile-prefix-format 'tags)
4687 (org-set-sorting-strategy 'tags)
4688 (setq org-agenda-query-string match)
4689 (setq org-agenda-redo-command
4690 (list 'org-tags-view `(quote ,todo-only)
4691 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4692 (setq files (org-agenda-files nil 'ifmode)
4693 rtnall nil)
4694 (while (setq file (pop files))
4695 (catch 'nextfile
4696 (org-check-agenda-file file)
4697 (setq buffer (if (file-exists-p file)
4698 (org-get-agenda-file-buffer file)
4699 (error "No such file %s" file)))
4700 (if (not buffer)
4701 ;; If file does not exist, error message to agenda
4702 (setq rtn (list
4703 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4704 rtnall (append rtnall rtn))
4705 (with-current-buffer buffer
4706 (unless (derived-mode-p 'org-mode)
4707 (error "Agenda file %s is not in `org-mode'" file))
4708 (save-excursion
4709 (save-restriction
4710 (if org-agenda-restrict
4711 (narrow-to-region org-agenda-restrict-begin
4712 org-agenda-restrict-end)
4713 (widen))
4714 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4715 (setq rtnall (append rtnall rtn))))))))
4716 (if org-agenda-overriding-header
4717 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4718 nil 'face 'org-agenda-structure) "\n")
4719 (insert "Headlines with TAGS match: ")
4720 (add-text-properties (point-min) (1- (point))
4721 (list 'face 'org-agenda-structure
4722 'short-heading
4723 (concat "Match: " match)))
4724 (setq pos (point))
4725 (insert match "\n")
4726 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4727 (setq pos (point))
4728 (unless org-agenda-multi
4729 (insert "Press `C-u r' to search again with new search string\n"))
4730 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4731 (org-agenda-mark-header-line (point-min))
4732 (when rtnall
4733 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4734 (goto-char (point-min))
4735 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4736 (add-text-properties (point-min) (point-max)
4737 `(org-agenda-type tags
4738 org-last-args (,todo-only ,match)
4739 org-redo-cmd ,org-agenda-redo-command
4740 org-series-cmd ,org-cmd))
4741 (org-agenda-finalize)
4742 (setq buffer-read-only t))))
4744 ;;; Agenda Finding stuck projects
4746 (defvar org-agenda-skip-regexp nil
4747 "Regular expression used in skipping subtrees for the agenda.
4748 This is basically a temporary global variable that can be set and then
4749 used by user-defined selections using `org-agenda-skip-function'.")
4751 (defvar org-agenda-overriding-header nil
4752 "When set during agenda, todo and tags searches it replaces the header.
4753 This variable should not be set directly, but custom commands can bind it
4754 in the options section.")
4756 (defun org-agenda-skip-entry-when-regexp-matches ()
4757 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4758 If yes, it returns the end position of this entry, causing agenda commands
4759 to skip the entry but continuing the search in the subtree. This is a
4760 function that can be put into `org-agenda-skip-function' for the duration
4761 of a command."
4762 (let ((end (save-excursion (org-end-of-subtree t)))
4763 skip)
4764 (save-excursion
4765 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4766 (and skip end)))
4768 (defun org-agenda-skip-subtree-when-regexp-matches ()
4769 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4770 If yes, it returns the end position of this tree, causing agenda commands
4771 to skip this subtree. This is a function that can be put into
4772 `org-agenda-skip-function' for the duration of a command."
4773 (let ((end (save-excursion (org-end-of-subtree t)))
4774 skip)
4775 (save-excursion
4776 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4777 (and skip end)))
4779 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4780 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4781 If yes, it returns the end position of the current entry (NOT the tree),
4782 causing agenda commands to skip the entry but continuing the search in
4783 the subtree. This is a function that can be put into
4784 `org-agenda-skip-function' for the duration of a command. An important
4785 use of this function is for the stuck project list."
4786 (let ((end (save-excursion (org-end-of-subtree t)))
4787 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4788 skip)
4789 (save-excursion
4790 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4791 (and skip entry-end)))
4793 (defun org-agenda-skip-entry-if (&rest conditions)
4794 "Skip entry if any of CONDITIONS is true.
4795 See `org-agenda-skip-if' for details."
4796 (org-agenda-skip-if nil conditions))
4798 (defun org-agenda-skip-subtree-if (&rest conditions)
4799 "Skip entry if any of CONDITIONS is true.
4800 See `org-agenda-skip-if' for details."
4801 (org-agenda-skip-if t conditions))
4803 (defun org-agenda-skip-if (subtree conditions)
4804 "Checks current entity for CONDITIONS.
4805 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4806 the entry (i.e. the text before the next heading) is checked.
4808 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4809 from different tests. Valid conditions are:
4811 scheduled Check if there is a scheduled cookie
4812 notscheduled Check if there is no scheduled cookie
4813 deadline Check if there is a deadline
4814 notdeadline Check if there is no deadline
4815 timestamp Check if there is a timestamp (also deadline or scheduled)
4816 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4817 regexp Check if regexp matches
4818 notregexp Check if regexp does not match.
4819 todo Check if TODO keyword matches
4820 nottodo Check if TODO keyword does not match
4822 The regexp is taken from the conditions list, it must come right after
4823 the `regexp' or `notregexp' element.
4825 `todo' and `nottodo' accept as an argument a list of todo
4826 keywords, which may include \"*\" to match any todo keyword.
4828 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4830 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4832 Instead of a list, a keyword class may be given. For example:
4834 (org-agenda-skip-entry-if 'nottodo 'done)
4836 would skip entries that haven't been marked with any of \"DONE\"
4837 keywords. Possible classes are: `todo', `done', `any'.
4839 If any of these conditions is met, this function returns the end point of
4840 the entity, causing the search to continue from there. This is a function
4841 that can be put into `org-agenda-skip-function' for the duration of a command."
4842 (let (beg end m)
4843 (org-back-to-heading t)
4844 (setq beg (point)
4845 end (if subtree
4846 (progn (org-end-of-subtree t) (point))
4847 (progn (outline-next-heading) (1- (point)))))
4848 (goto-char beg)
4849 (and
4851 (and (memq 'scheduled conditions)
4852 (re-search-forward org-scheduled-time-regexp end t))
4853 (and (memq 'notscheduled conditions)
4854 (not (re-search-forward org-scheduled-time-regexp end t)))
4855 (and (memq 'deadline conditions)
4856 (re-search-forward org-deadline-time-regexp end t))
4857 (and (memq 'notdeadline conditions)
4858 (not (re-search-forward org-deadline-time-regexp end t)))
4859 (and (memq 'timestamp conditions)
4860 (re-search-forward org-ts-regexp end t))
4861 (and (memq 'nottimestamp conditions)
4862 (not (re-search-forward org-ts-regexp end t)))
4863 (and (setq m (memq 'regexp conditions))
4864 (stringp (nth 1 m))
4865 (re-search-forward (nth 1 m) end t))
4866 (and (setq m (memq 'notregexp conditions))
4867 (stringp (nth 1 m))
4868 (not (re-search-forward (nth 1 m) end t)))
4869 (and (or
4870 (setq m (memq 'nottodo conditions))
4871 (setq m (memq 'todo-unblocked conditions))
4872 (setq m (memq 'nottodo-unblocked conditions))
4873 (setq m (memq 'todo conditions)))
4874 (org-agenda-skip-if-todo m end)))
4875 end)))
4877 (defun org-agenda-skip-if-todo (args end)
4878 "Helper function for `org-agenda-skip-if', do not use it directly.
4879 ARGS is a list with first element either `todo', `nottodo',
4880 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4881 a list of TODO keywords, or a state symbol `todo' or `done' or
4882 `any'."
4883 (let ((kw (car args))
4884 (arg (cadr args))
4885 todo-wds todo-re)
4886 (setq todo-wds
4887 (org-uniquify
4888 (cond
4889 ((listp arg) ;; list of keywords
4890 (if (member "*" arg)
4891 (mapcar 'substring-no-properties org-todo-keywords-1)
4892 arg))
4893 ((symbolp arg) ;; keyword class name
4894 (cond
4895 ((eq arg 'todo)
4896 (org-delete-all org-done-keywords
4897 (mapcar 'substring-no-properties
4898 org-todo-keywords-1)))
4899 ((eq arg 'done) org-done-keywords)
4900 ((eq arg 'any)
4901 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4902 (setq todo-re
4903 (concat "^\\*+[ \t]+\\<\\("
4904 (mapconcat 'identity todo-wds "\\|")
4905 "\\)\\>"))
4906 (cond
4907 ((eq kw 'todo) (re-search-forward todo-re end t))
4908 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4909 ((eq kw 'todo-unblocked)
4910 (catch 'unblocked
4911 (while (re-search-forward todo-re end t)
4912 (or (org-entry-blocked-p) (throw 'unblocked t)))
4913 nil))
4914 ((eq kw 'nottodo-unblocked)
4915 (catch 'unblocked
4916 (while (re-search-forward todo-re end t)
4917 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4921 ;;;###autoload
4922 (defun org-agenda-list-stuck-projects (&rest ignore)
4923 "Create agenda view for projects that are stuck.
4924 Stuck projects are project that have no next actions. For the definitions
4925 of what a project is and how to check if it stuck, customize the variable
4926 `org-stuck-projects'."
4927 (interactive)
4928 (let* ((org-agenda-skip-function
4929 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4930 ;; We could have used org-agenda-skip-if here.
4931 (org-agenda-overriding-header
4932 (or org-agenda-overriding-header "List of stuck projects: "))
4933 (matcher (nth 0 org-stuck-projects))
4934 (todo (nth 1 org-stuck-projects))
4935 (todo-wds (if (member "*" todo)
4936 (progn
4937 (org-agenda-prepare-buffers (org-agenda-files
4938 nil 'ifmode))
4939 (org-delete-all
4940 org-done-keywords-for-agenda
4941 (copy-sequence org-todo-keywords-for-agenda)))
4942 todo))
4943 (todo-re (concat "^\\*+[ \t]+\\("
4944 (mapconcat 'identity todo-wds "\\|")
4945 "\\)\\>"))
4946 (tags (nth 2 org-stuck-projects))
4947 (tags-re (if (member "*" tags)
4948 (concat org-outline-regexp-bol
4949 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4950 (if tags
4951 (concat org-outline-regexp-bol
4952 ".*:\\("
4953 (mapconcat 'identity tags "\\|")
4954 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4955 (gen-re (nth 3 org-stuck-projects))
4956 (re-list
4957 (delq nil
4958 (list
4959 (if todo todo-re)
4960 (if tags tags-re)
4961 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4962 gen-re)))))
4963 (setq org-agenda-skip-regexp
4964 (if re-list
4965 (mapconcat 'identity re-list "\\|")
4966 (error "No information how to identify unstuck projects")))
4967 (org-tags-view nil matcher)
4968 (with-current-buffer org-agenda-buffer-name
4969 (setq org-agenda-redo-command
4970 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4972 ;;; Diary integration
4974 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4975 (defvar diary-list-entries-hook)
4976 (defvar diary-time-regexp)
4977 (defun org-get-entries-from-diary (date)
4978 "Get the (Emacs Calendar) diary entries for DATE."
4979 (require 'diary-lib)
4980 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4981 (diary-display-hook '(fancy-diary-display))
4982 (diary-display-function 'fancy-diary-display)
4983 (pop-up-frames nil)
4984 (diary-list-entries-hook
4985 (cons 'org-diary-default-entry diary-list-entries-hook))
4986 (diary-file-name-prefix nil) ; turn this feature off
4987 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4988 entries
4989 (org-disable-agenda-to-diary t))
4990 (save-excursion
4991 (save-window-excursion
4992 (funcall (if (fboundp 'diary-list-entries)
4993 'diary-list-entries 'list-diary-entries)
4994 date 1)))
4995 (if (not (get-buffer diary-fancy-buffer))
4996 (setq entries nil)
4997 (with-current-buffer diary-fancy-buffer
4998 (setq buffer-read-only nil)
4999 (if (zerop (buffer-size))
5000 ;; No entries
5001 (setq entries nil)
5002 ;; Omit the date and other unnecessary stuff
5003 (org-agenda-cleanup-fancy-diary)
5004 ;; Add prefix to each line and extend the text properties
5005 (if (zerop (buffer-size))
5006 (setq entries nil)
5007 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5008 (setq entries
5009 (with-temp-buffer
5010 (insert entries) (goto-char (point-min))
5011 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5012 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5013 (replace-match (concat "; " (match-string 1)))))
5014 (buffer-string)))))
5015 (set-buffer-modified-p nil)
5016 (kill-buffer diary-fancy-buffer)))
5017 (when entries
5018 (setq entries (org-split-string entries "\n"))
5019 (setq entries
5020 (mapcar
5021 (lambda (x)
5022 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5023 ;; Extend the text properties to the beginning of the line
5024 (org-add-props x (text-properties-at (1- (length x)) x)
5025 'type "diary" 'date date 'face 'org-agenda-diary))
5026 entries)))))
5028 (defvar org-agenda-cleanup-fancy-diary-hook nil
5029 "Hook run when the fancy diary buffer is cleaned up.")
5031 (defun org-agenda-cleanup-fancy-diary ()
5032 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5033 This gets rid of the date, the underline under the date, and
5034 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5035 date. It also removes lines that contain only whitespace."
5036 (goto-char (point-min))
5037 (if (looking-at ".*?:[ \t]*")
5038 (progn
5039 (replace-match "")
5040 (re-search-forward "\n=+$" nil t)
5041 (replace-match "")
5042 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5043 (re-search-forward "\n=+$" nil t)
5044 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5045 (goto-char (point-min))
5046 (while (re-search-forward "^ +\n" nil t)
5047 (replace-match ""))
5048 (goto-char (point-min))
5049 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5050 (replace-match ""))
5051 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5053 ;; Make sure entries from the diary have the right text properties.
5054 (eval-after-load "diary-lib"
5055 '(if (boundp 'diary-modify-entry-list-string-function)
5056 ;; We can rely on the hook, nothing to do
5058 ;; Hook not available, must use advice to make this work
5059 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5060 "Make the position visible."
5061 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5062 (stringp string)
5063 buffer-file-name)
5064 (setq string (org-modify-diary-entry-string string))))))
5066 (defun org-modify-diary-entry-string (string)
5067 "Add text properties to string, allowing org-mode to act on it."
5068 (org-add-props string nil
5069 'mouse-face 'highlight
5070 'help-echo (if buffer-file-name
5071 (format "mouse-2 or RET jump to diary file %s"
5072 (abbreviate-file-name buffer-file-name))
5074 'org-agenda-diary-link t
5075 'org-marker (org-agenda-new-marker (point-at-bol))))
5077 (defun org-diary-default-entry ()
5078 "Add a dummy entry to the diary.
5079 Needed to avoid empty dates which mess up holiday display."
5080 ;; Catch the error if dealing with the new add-to-diary-alist
5081 (when org-disable-agenda-to-diary
5082 (condition-case nil
5083 (org-add-to-diary-list original-date "Org-mode dummy" "")
5084 (error
5085 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5087 (defun org-add-to-diary-list (&rest args)
5088 (if (fboundp 'diary-add-to-list)
5089 (apply 'diary-add-to-list args)
5090 (apply 'add-to-diary-list args)))
5092 (defvar org-diary-last-run-time nil)
5094 ;;;###autoload
5095 (defun org-diary (&rest args)
5096 "Return diary information from org files.
5097 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5098 It accesses org files and extracts information from those files to be
5099 listed in the diary. The function accepts arguments specifying what
5100 items should be listed. For a list of arguments allowed here, see the
5101 variable `org-agenda-entry-types'.
5103 The call in the diary file should look like this:
5105 &%%(org-diary) ~/path/to/some/orgfile.org
5107 Use a separate line for each org file to check. Or, if you omit the file name,
5108 all files listed in `org-agenda-files' will be checked automatically:
5110 &%%(org-diary)
5112 If you don't give any arguments (as in the example above), the default
5113 arguments (:deadline :scheduled :timestamp :sexp) are used.
5114 So the example above may also be written as
5116 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5118 The function expects the lisp variables `entry' and `date' to be provided
5119 by the caller, because this is how the calendar works. Don't use this
5120 function from a program - use `org-agenda-get-day-entries' instead."
5121 (when (> (- (org-float-time)
5122 org-agenda-last-marker-time)
5124 ;; I am not sure if this works with sticky agendas, because the marker
5125 ;; list is then no longer a global variable.
5126 (org-agenda-reset-markers))
5127 (org-compile-prefix-format 'agenda)
5128 (org-set-sorting-strategy 'agenda)
5129 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5130 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5131 (list entry)
5132 (org-agenda-files t)))
5133 (time (org-float-time))
5134 file rtn results)
5135 (when (or (not org-diary-last-run-time)
5136 (> (- time
5137 org-diary-last-run-time)
5139 (org-agenda-prepare-buffers files))
5140 (setq org-diary-last-run-time time)
5141 ;; If this is called during org-agenda, don't return any entries to
5142 ;; the calendar. Org Agenda will list these entries itself.
5143 (if org-disable-agenda-to-diary (setq files nil))
5144 (while (setq file (pop files))
5145 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5146 (setq results (append results rtn)))
5147 (when results
5148 (setq results
5149 (mapcar (lambda (i) (replace-regexp-in-string
5150 org-bracket-link-regexp "\\3" i)) results))
5151 (concat (org-agenda-finalize-entries results) "\n"))))
5153 ;;; Agenda entry finders
5155 (defun org-agenda-get-day-entries (file date &rest args)
5156 "Does the work for `org-diary' and `org-agenda'.
5157 FILE is the path to a file to be checked for entries. DATE is date like
5158 the one returned by `calendar-current-date'. ARGS are symbols indicating
5159 which kind of entries should be extracted. For details about these, see
5160 the documentation of `org-diary'."
5161 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5162 (let* ((org-startup-folded nil)
5163 (org-startup-align-all-tables nil)
5164 (buffer (if (file-exists-p file)
5165 (org-get-agenda-file-buffer file)
5166 (error "No such file %s" file)))
5167 arg results rtn deadline-results)
5168 (if (not buffer)
5169 ;; If file does not exist, make sure an error message ends up in diary
5170 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5171 (with-current-buffer buffer
5172 (unless (derived-mode-p 'org-mode)
5173 (error "Agenda file %s is not in `org-mode'" file))
5174 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5175 (let ((case-fold-search nil))
5176 (save-excursion
5177 (save-restriction
5178 (if org-agenda-restrict
5179 (narrow-to-region org-agenda-restrict-begin
5180 org-agenda-restrict-end)
5181 (widen))
5182 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5183 (while (setq arg (pop args))
5184 (cond
5185 ((and (eq arg :todo)
5186 (equal date (calendar-gregorian-from-absolute
5187 (org-today))))
5188 (setq rtn (org-agenda-get-todos))
5189 (setq results (append results rtn)))
5190 ((eq arg :timestamp)
5191 (setq rtn (org-agenda-get-blocks))
5192 (setq results (append results rtn))
5193 (setq rtn (org-agenda-get-timestamps deadline-results))
5194 (setq results (append results rtn)))
5195 ((eq arg :sexp)
5196 (setq rtn (org-agenda-get-sexps))
5197 (setq results (append results rtn)))
5198 ((eq arg :scheduled)
5199 (setq rtn (org-agenda-get-scheduled deadline-results))
5200 (setq results (append results rtn)))
5201 ((eq arg :closed)
5202 (setq rtn (org-agenda-get-progress))
5203 (setq results (append results rtn)))
5204 ((eq arg :deadline)
5205 (setq rtn (org-agenda-get-deadlines))
5206 (setq deadline-results (copy-sequence rtn))
5207 (setq results (append results rtn))))))))
5208 results))))
5210 (defsubst org-em (x y list)
5211 "Is X or Y a member of LIST?"
5212 (or (memq x list) (memq y list)))
5214 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5215 (defvar org-agenda-sorting-strategy-selected nil)
5217 (defun org-agenda-get-todos ()
5218 "Return the TODO information for agenda display."
5219 (let* ((props (list 'face nil
5220 'done-face 'org-agenda-done
5221 'org-not-done-regexp org-not-done-regexp
5222 'org-todo-regexp org-todo-regexp
5223 'org-complex-heading-regexp org-complex-heading-regexp
5224 'mouse-face 'highlight
5225 'help-echo
5226 (format "mouse-2 or RET jump to org file %s"
5227 (abbreviate-file-name buffer-file-name))))
5228 (regexp (format org-heading-keyword-regexp-format
5229 (cond
5230 ((and org-select-this-todo-keyword
5231 (equal org-select-this-todo-keyword "*"))
5232 org-todo-regexp)
5233 (org-select-this-todo-keyword
5234 (concat "\\("
5235 (mapconcat 'identity
5236 (org-split-string
5237 org-select-this-todo-keyword
5238 "|")
5239 "\\|") "\\)"))
5240 (t org-not-done-regexp))))
5241 marker priority category category-pos level tags todo-state ts-date ts-date-type
5242 ee txt beg end inherited-tags)
5243 (goto-char (point-min))
5244 (while (re-search-forward regexp nil t)
5245 (catch :skip
5246 (save-match-data
5247 (beginning-of-line)
5248 (org-agenda-skip)
5249 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5250 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5251 (goto-char (1+ beg))
5252 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5253 (throw :skip nil)))
5254 (goto-char (match-beginning 2))
5255 (setq marker (org-agenda-new-marker (match-beginning 0))
5256 category (org-get-category)
5257 ts-date (let (ts)
5258 (save-match-data
5259 (cond ((org-em 'scheduled-up 'scheduled-down
5260 org-agenda-sorting-strategy-selected)
5261 (setq ts (org-entry-get (point) "SCHEDULED")
5262 ts-date-type " scheduled"))
5263 ((org-em 'deadline-up 'deadline-down
5264 org-agenda-sorting-strategy-selected)
5265 (setq ts (org-entry-get (point) "DEADLINE")
5266 ts-date-type " deadline"))
5267 ((org-em 'ts-up 'ts-down
5268 org-agenda-sorting-strategy-selected)
5269 (setq ts (org-entry-get (point) "TIMESTAMP")
5270 ts-date-type " timestamp"))
5271 ((org-em 'tsia-up 'tsia-down
5272 org-agenda-sorting-strategy-selected)
5273 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5274 ts-date-type " timestamp_ia"))
5275 ((org-em 'timestamp-up 'timestamp-down
5276 org-agenda-sorting-strategy-selected)
5277 (setq ts (or (org-entry-get (point) "SCHEDULED")
5278 (org-entry-get (point) "DEADLINE")
5279 (org-entry-get (point) "TIMESTAMP")
5280 (org-entry-get (point) "TIMESTAMP_IA"))
5281 ts-date-type ""))
5282 (t (setq ts-date-type "")))
5283 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5284 category-pos (get-text-property (point) 'org-category-position)
5285 txt (org-trim
5286 (buffer-substring (match-beginning 2) (match-end 0)))
5287 inherited-tags
5288 (or (eq org-agenda-show-inherited-tags 'always)
5289 (and (listp org-agenda-show-inherited-tags)
5290 (memq 'todo org-agenda-show-inherited-tags))
5291 (and (eq org-agenda-show-inherited-tags t)
5292 (or (eq org-agenda-use-tag-inheritance t)
5293 (memq 'todo org-agenda-use-tag-inheritance))))
5294 tags (org-get-tags-at nil (not inherited-tags))
5295 level (make-string (org-reduced-level (org-outline-level)) ? )
5296 txt (org-agenda-format-item "" txt level category tags t)
5297 priority (1+ (org-get-priority txt))
5298 todo-state (org-get-todo-state))
5299 (org-add-props txt props
5300 'org-marker marker 'org-hd-marker marker
5301 'priority priority 'org-category category
5302 'level level
5303 'ts-date ts-date
5304 'org-category-position category-pos
5305 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5306 (push txt ee)
5307 (if org-agenda-todo-list-sublevels
5308 (goto-char (match-end 2))
5309 (org-end-of-subtree 'invisible))))
5310 (nreverse ee)))
5312 (defun org-agenda-todo-custom-ignore-p (time n)
5313 "Check whether timestamp is farther away than n number of days.
5314 This function is invoked if `org-agenda-todo-ignore-deadlines',
5315 `org-agenda-todo-ignore-scheduled' or
5316 `org-agenda-todo-ignore-timestamp' is set to an integer."
5317 (let ((days (org-time-stamp-to-now
5318 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5319 (if (>= n 0)
5320 (>= days n)
5321 (<= days n))))
5323 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5324 (&optional end)
5325 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5326 (when (or org-agenda-todo-ignore-with-date
5327 org-agenda-todo-ignore-scheduled
5328 org-agenda-todo-ignore-deadlines
5329 org-agenda-todo-ignore-timestamp)
5330 (setq end (or end (save-excursion (outline-next-heading) (point))))
5331 (save-excursion
5332 (or (and org-agenda-todo-ignore-with-date
5333 (re-search-forward org-ts-regexp end t))
5334 (and org-agenda-todo-ignore-scheduled
5335 (re-search-forward org-scheduled-time-regexp end t)
5336 (cond
5337 ((eq org-agenda-todo-ignore-scheduled 'future)
5338 (> (org-time-stamp-to-now
5339 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5340 ((eq org-agenda-todo-ignore-scheduled 'past)
5341 (<= (org-time-stamp-to-now
5342 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5343 ((numberp org-agenda-todo-ignore-scheduled)
5344 (org-agenda-todo-custom-ignore-p
5345 (match-string 1) org-agenda-todo-ignore-scheduled))
5346 (t)))
5347 (and org-agenda-todo-ignore-deadlines
5348 (re-search-forward org-deadline-time-regexp end t)
5349 (cond
5350 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5351 ((eq org-agenda-todo-ignore-deadlines 'far)
5352 (not (org-deadline-close (match-string 1))))
5353 ((eq org-agenda-todo-ignore-deadlines 'future)
5354 (> (org-time-stamp-to-now
5355 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5356 ((eq org-agenda-todo-ignore-deadlines 'past)
5357 (<= (org-time-stamp-to-now
5358 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5359 ((numberp org-agenda-todo-ignore-deadlines)
5360 (org-agenda-todo-custom-ignore-p
5361 (match-string 1) org-agenda-todo-ignore-deadlines))
5362 (t (org-deadline-close (match-string 1)))))
5363 (and org-agenda-todo-ignore-timestamp
5364 (let ((buffer (current-buffer))
5365 (regexp
5366 (concat
5367 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5368 (start (point)))
5369 ;; Copy current buffer into a temporary one
5370 (with-temp-buffer
5371 (insert-buffer-substring buffer start end)
5372 (goto-char (point-min))
5373 ;; Delete SCHEDULED and DEADLINE items
5374 (while (re-search-forward regexp end t)
5375 (delete-region (match-beginning 0) (match-end 0)))
5376 (goto-char (point-min))
5377 ;; No search for timestamp left
5378 (when (re-search-forward org-ts-regexp nil t)
5379 (cond
5380 ((eq org-agenda-todo-ignore-timestamp '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-timestamp '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-timestamp)
5387 (org-agenda-todo-custom-ignore-p
5388 (match-string 1) org-agenda-todo-ignore-timestamp))
5389 (t))))))))))
5391 (defun org-agenda-get-timestamps (&optional deadline-results)
5392 "Return the date stamp information for agenda display."
5393 (let* ((props (list 'face 'org-agenda-calendar-event
5394 'org-not-done-regexp org-not-done-regexp
5395 'org-todo-regexp org-todo-regexp
5396 'org-complex-heading-regexp org-complex-heading-regexp
5397 'mouse-face 'highlight
5398 'help-echo
5399 (format "mouse-2 or RET jump to org file %s"
5400 (abbreviate-file-name buffer-file-name))))
5401 (d1 (calendar-absolute-from-gregorian date))
5403 (deadline-position-alist
5404 (mapcar (lambda (a) (and (setq mm (get-text-property
5405 0 'org-hd-marker a))
5406 (cons (marker-position mm) a)))
5407 deadline-results))
5408 (remove-re org-ts-regexp)
5409 (regexp
5410 (concat
5411 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5412 (regexp-quote
5413 (substring
5414 (format-time-string
5415 (car org-time-stamp-formats)
5416 (apply 'encode-time ; DATE bound by calendar
5417 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5418 1 11))
5419 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5420 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5421 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5422 donep tmp priority category category-pos level ee txt timestr tags
5423 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5424 inherited-tags ts-date)
5425 (goto-char (point-min))
5426 (while (setq end-of-match (re-search-forward regexp nil t))
5427 (setq b0 (match-beginning 0)
5428 b3 (match-beginning 3) e3 (match-end 3)
5429 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5430 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5431 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5432 (member todo-state
5433 org-agenda-repeating-timestamp-show-all)))
5434 (catch :skip
5435 (and (org-at-date-range-p) (throw :skip nil))
5436 (org-agenda-skip)
5437 (if (and (match-end 1)
5438 (not (= d1 (org-time-string-to-absolute
5439 (match-string 1) d1 nil show-all
5440 (current-buffer) b0))))
5441 (throw :skip nil))
5442 (if (and e3
5443 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5444 (throw :skip nil))
5445 (setq tmp (buffer-substring (max (point-min)
5446 (- b0 org-ds-keyword-length))
5448 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5449 inactivep (= (char-after b0) ?\[)
5450 deadlinep (string-match org-deadline-regexp tmp)
5451 scheduledp (string-match org-scheduled-regexp tmp)
5452 closedp (and org-agenda-include-inactive-timestamps
5453 (string-match org-closed-string tmp))
5454 clockp (and org-agenda-include-inactive-timestamps
5455 (or (string-match org-clock-string tmp)
5456 (string-match "]-+\\'" tmp)))
5457 warntime (get-text-property (point) 'org-appt-warntime)
5458 donep (member todo-state org-done-keywords))
5459 (if (or scheduledp deadlinep closedp clockp
5460 (and donep org-agenda-skip-timestamp-if-done))
5461 (throw :skip t))
5462 (if (string-match ">" timestr)
5463 ;; substring should only run to end of time stamp
5464 (setq timestr (substring timestr 0 (match-end 0))))
5465 (setq marker (org-agenda-new-marker b0)
5466 category (org-get-category b0)
5467 category-pos (get-text-property b0 'org-category-position))
5468 (save-excursion
5469 (if (not (re-search-backward org-outline-regexp-bol nil t))
5470 (throw :skip nil)
5471 (goto-char (match-beginning 0))
5472 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5473 (assoc (point) deadline-position-alist))
5474 (throw :skip nil))
5475 (setq hdmarker (org-agenda-new-marker)
5476 inherited-tags
5477 (or (eq org-agenda-show-inherited-tags 'always)
5478 (and (listp org-agenda-show-inherited-tags)
5479 (memq 'agenda org-agenda-show-inherited-tags))
5480 (and (eq org-agenda-show-inherited-tags t)
5481 (or (eq org-agenda-use-tag-inheritance t)
5482 (memq 'agenda org-agenda-use-tag-inheritance))))
5483 tags (org-get-tags-at nil (not inherited-tags))
5484 level (make-string (org-reduced-level (org-outline-level)) ? ))
5485 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5486 (setq head (or (match-string 1) ""))
5487 (setq txt (org-agenda-format-item
5488 (if inactivep org-agenda-inactive-leader nil)
5489 head level category tags timestr
5490 remove-re habitp)))
5491 (setq priority (org-get-priority txt))
5492 (org-add-props txt props 'priority priority
5493 'org-marker marker 'org-hd-marker hdmarker
5494 'org-category category 'date date
5495 'level level
5496 'ts-date
5497 (ignore-errors (org-time-string-to-absolute timestr))
5498 'org-category-position category-pos
5499 'todo-state todo-state
5500 'warntime warntime
5501 'type "timestamp")
5502 (push txt ee))
5503 (if org-agenda-skip-additional-timestamps-same-entry
5504 (outline-next-heading)
5505 (goto-char end-of-match))))
5506 (nreverse ee)))
5508 (defun org-agenda-get-sexps ()
5509 "Return the sexp information for agenda display."
5510 (require 'diary-lib)
5511 (let* ((props (list 'face 'org-agenda-calendar-sexp
5512 'mouse-face 'highlight
5513 'help-echo
5514 (format "mouse-2 or RET jump to org file %s"
5515 (abbreviate-file-name buffer-file-name))))
5516 (regexp "^&?%%(")
5517 marker category extra category-pos level ee txt tags entry
5518 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5519 (goto-char (point-min))
5520 (while (re-search-forward regexp nil t)
5521 (catch :skip
5522 (org-agenda-skip)
5523 (setq beg (match-beginning 0))
5524 (goto-char (1- (match-end 0)))
5525 (setq b (point))
5526 (forward-sexp 1)
5527 (setq sexp (buffer-substring b (point)))
5528 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5529 (org-trim (match-string 1))
5530 ""))
5531 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5532 (when result
5533 (setq marker (org-agenda-new-marker beg)
5534 level (make-string (org-reduced-level (org-outline-level)) ? )
5535 category (org-get-category beg)
5536 category-pos (get-text-property beg 'org-category-position)
5537 inherited-tags
5538 (or (eq org-agenda-show-inherited-tags 'always)
5539 (and (listp org-agenda-show-inherited-tags)
5540 (memq 'agenda org-agenda-show-inherited-tags))
5541 (and (eq org-agenda-show-inherited-tags t)
5542 (or (eq org-agenda-use-tag-inheritance t)
5543 (memq 'agenda org-agenda-use-tag-inheritance))))
5544 tags (org-get-tags-at nil (not inherited-tags))
5545 todo-state (org-get-todo-state)
5546 warntime (get-text-property (point) 'org-appt-warntime)
5547 extra nil)
5549 (dolist (r (if (stringp result)
5550 (list result)
5551 result)) ;; we expect a list here
5552 (when (and org-agenda-diary-sexp-prefix
5553 (string-match org-agenda-diary-sexp-prefix r))
5554 (setq extra (match-string 0 r)
5555 r (replace-match "" nil nil r)))
5556 (if (string-match "\\S-" r)
5557 (setq txt r)
5558 (setq txt "SEXP entry returned empty string"))
5559 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5560 (org-add-props txt props 'org-marker marker
5561 'org-category category 'date date 'todo-state todo-state
5562 'org-category-position category-pos 'tags tags
5563 'level level
5564 'type "sexp" 'warntime warntime)
5565 (push txt ee)))))
5566 (nreverse ee)))
5568 ;; Calendar sanity: define some functions that are independent of
5569 ;; `calendar-date-style'.
5570 ;; Normally I would like to use ISO format when calling the diary functions,
5571 ;; but to make sure we still have Emacs 22 compatibility we bind
5572 ;; also `european-calendar-style' and use european format
5573 (defun org-anniversary (year month day &optional mark)
5574 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5575 (org-no-warnings
5576 (let ((calendar-date-style 'european) (european-calendar-style t))
5577 (diary-anniversary day month year mark))))
5578 (defun org-cyclic (N year month day &optional mark)
5579 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5580 (org-no-warnings
5581 (let ((calendar-date-style 'european) (european-calendar-style t))
5582 (diary-cyclic N day month year mark))))
5583 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5584 "Like `diary-block', but with fixed (ISO) order of arguments."
5585 (org-no-warnings
5586 (let ((calendar-date-style 'european) (european-calendar-style t))
5587 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5588 (defun org-date (year month day &optional mark)
5589 "Like `diary-date', but with fixed (ISO) order of arguments."
5590 (org-no-warnings
5591 (let ((calendar-date-style 'european) (european-calendar-style t))
5592 (diary-date day month year mark))))
5594 ;; Define the` org-class' function
5595 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5596 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5597 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5598 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5599 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5600 `holidays', then any date that is known by the Emacs calendar to be a
5601 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5602 then those holidays will be skipped."
5603 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5604 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5605 (d (calendar-absolute-from-gregorian date))
5606 (h (when skip-weeks (calendar-check-holidays date))))
5607 (and
5608 (<= date1 d)
5609 (<= d date2)
5610 (= (calendar-day-of-week date) dayname)
5611 (or (not skip-weeks)
5612 (progn
5613 (require 'cal-iso)
5614 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5615 (not (or (and h (memq 'holidays skip-weeks))
5616 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5617 entry)))
5619 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5620 "Like `org-class', but honor `calendar-date-style'.
5621 The order of the first 2 times 3 arguments depends on the variable
5622 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5623 So for American calendars, give this as MONTH DAY YEAR, for European as
5624 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5625 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5626 is any number of ISO weeks in the block period for which the item should
5627 be skipped.
5629 This function is here only for backward compatibility and it is deprecated,
5630 please use `org-class' instead."
5631 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5632 (date2 (org-order-calendar-date-args m2 d2 y2)))
5633 (org-class
5634 (nth 2 date1) (car date1) (nth 1 date1)
5635 (nth 2 date2) (car date2) (nth 1 date2)
5636 dayname skip-weeks)))
5637 (make-obsolete 'org-diary-class 'org-class "")
5639 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5640 (defalias 'org-get-closed 'org-agenda-get-progress)
5641 (defun org-agenda-get-progress ()
5642 "Return the logged TODO entries for agenda display."
5643 (let* ((props (list 'mouse-face 'highlight
5644 'org-not-done-regexp org-not-done-regexp
5645 'org-todo-regexp org-todo-regexp
5646 'org-complex-heading-regexp org-complex-heading-regexp
5647 'help-echo
5648 (format "mouse-2 or RET jump to org file %s"
5649 (abbreviate-file-name buffer-file-name))))
5650 (items (if (consp org-agenda-show-log-scoped)
5651 org-agenda-show-log-scoped
5652 (if (eq org-agenda-show-log-scoped 'clockcheck)
5653 '(clock)
5654 org-agenda-log-mode-items)))
5655 (parts
5656 (delq nil
5657 (list
5658 (if (memq 'closed items) (concat "\\<" org-closed-string))
5659 (if (memq 'clock items) (concat "\\<" org-clock-string))
5660 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5661 (parts-re (if parts (mapconcat 'identity parts "\\|")
5662 (error "`org-agenda-log-mode-items' is empty")))
5663 (regexp (concat
5664 "\\(" parts-re "\\)"
5665 " *\\["
5666 (regexp-quote
5667 (substring
5668 (format-time-string
5669 (car org-time-stamp-formats)
5670 (apply 'encode-time ; DATE bound by calendar
5671 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5672 1 11))))
5673 (org-agenda-search-headline-for-time nil)
5674 marker hdmarker priority category category-pos level tags closedp
5675 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5676 (goto-char (point-min))
5677 (while (re-search-forward regexp nil t)
5678 (catch :skip
5679 (org-agenda-skip)
5680 (setq marker (org-agenda-new-marker (match-beginning 0))
5681 closedp (equal (match-string 1) org-closed-string)
5682 statep (equal (string-to-char (match-string 1)) ?-)
5683 clockp (not (or closedp statep))
5684 state (and statep (match-string 2))
5685 category (org-get-category (match-beginning 0))
5686 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5687 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5688 (when (string-match "\\]" timestr)
5689 ;; substring should only run to end of time stamp
5690 (setq rest (substring timestr (match-end 0))
5691 timestr (substring timestr 0 (match-end 0)))
5692 (if (and (not closedp) (not statep)
5693 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5694 rest))
5695 (progn (setq timestr (concat (substring timestr 0 -1)
5696 "-" (match-string 1 rest) "]"))
5697 (setq clocked (match-string 2 rest)))
5698 (setq clocked "-")))
5699 (save-excursion
5700 (setq extra
5701 (cond
5702 ((not org-agenda-log-mode-add-notes) nil)
5703 (statep
5704 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5705 (match-string 1)))
5706 (clockp
5707 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5708 (match-string 1)))))
5709 (if (not (re-search-backward org-outline-regexp-bol nil t))
5710 (throw :skip nil)
5711 (goto-char (match-beginning 0))
5712 (setq hdmarker (org-agenda-new-marker)
5713 inherited-tags
5714 (or (eq org-agenda-show-inherited-tags 'always)
5715 (and (listp org-agenda-show-inherited-tags)
5716 (memq 'todo org-agenda-show-inherited-tags))
5717 (and (eq org-agenda-show-inherited-tags t)
5718 (or (eq org-agenda-use-tag-inheritance t)
5719 (memq 'todo org-agenda-use-tag-inheritance))))
5720 tags (org-get-tags-at nil (not inherited-tags))
5721 level (make-string (org-reduced-level (org-outline-level)) ? ))
5722 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5723 (setq txt (match-string 1))
5724 (when extra
5725 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5726 (setq txt (concat (substring txt 0 (match-beginning 1))
5727 " - " extra " " (match-string 2 txt)))
5728 (setq txt (concat txt " - " extra))))
5729 (setq txt (org-agenda-format-item
5730 (cond
5731 (closedp "Closed: ")
5732 (statep (concat "State: (" state ")"))
5733 (t (concat "Clocked: (" clocked ")")))
5734 txt level category tags timestr)))
5735 (setq priority 100000)
5736 (org-add-props txt props
5737 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5738 'priority priority 'org-category category
5739 'org-category-position category-pos
5740 'level level
5741 'type "closed" 'date date
5742 'undone-face 'org-warning 'done-face 'org-agenda-done)
5743 (push txt ee))
5744 (goto-char (point-at-eol))))
5745 (nreverse ee)))
5747 (defun org-agenda-show-clocking-issues ()
5748 "Add overlays, showing issues with clocking.
5749 See also the user option `org-agenda-clock-consistency-checks'."
5750 (interactive)
5751 (let* ((org-time-clocksum-use-effort-durations nil)
5752 (pl org-agenda-clock-consistency-checks)
5753 (re (concat "^[ \t]*"
5754 org-clock-string
5755 "[ \t]+"
5756 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5757 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5758 (tlstart 0.)
5759 (tlend 0.)
5760 (maxtime (org-hh:mm-string-to-minutes
5761 (or (plist-get pl :max-duration) "24:00")))
5762 (mintime (org-hh:mm-string-to-minutes
5763 (or (plist-get pl :min-duration) 0)))
5764 (maxgap (org-hh:mm-string-to-minutes
5765 ;; default 30:00 means never complain
5766 (or (plist-get pl :max-gap) "30:00")))
5767 (gapok (mapcar 'org-hh:mm-string-to-minutes
5768 (plist-get pl :gap-ok-around)))
5769 (def-face (or (plist-get pl :default-face)
5770 '((:background "DarkRed") (:foreground "white"))))
5771 issue face m te ts dt ov)
5772 (goto-char (point-min))
5773 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5774 (setq issue nil face def-face)
5775 (catch 'next
5776 (setq m (org-get-at-bol 'org-marker)
5777 te nil ts nil)
5778 (unless (and m (markerp m))
5779 (setq issue "No valid clock line") (throw 'next t))
5780 (org-with-point-at m
5781 (save-excursion
5782 (goto-char (point-at-bol))
5783 (unless (looking-at re)
5784 (error "No valid Clock line")
5785 (throw 'next t))
5786 (unless (match-end 3)
5787 (setq issue "No end time"
5788 face (or (plist-get pl :no-end-time-face) face))
5789 (throw 'next t))
5790 (setq ts (match-string 1)
5791 te (match-string 3)
5792 ts (org-float-time
5793 (apply 'encode-time (org-parse-time-string ts)))
5794 te (org-float-time
5795 (apply 'encode-time (org-parse-time-string te)))
5796 dt (- te ts))))
5797 (cond
5798 ((> dt (* 60 maxtime))
5799 ;; a very long clocking chunk
5800 (setq issue (format "Clocking interval is very long: %s"
5801 (org-minutes-to-clocksum-string
5802 (floor (/ (float dt) 60.))))
5803 face (or (plist-get pl :long-face) face)))
5804 ((< dt (* 60 mintime))
5805 ;; a very short clocking chunk
5806 (setq issue (format "Clocking interval is very short: %s"
5807 (org-minutes-to-clocksum-string
5808 (floor (/ (float dt) 60.))))
5809 face (or (plist-get pl :short-face) face)))
5810 ((and (> tlend 0) (< ts tlend))
5811 ;; Two clock entries are overlapping
5812 (setq issue (format "Clocking overlap: %d minutes"
5813 (/ (- tlend ts) 60))
5814 face (or (plist-get pl :overlap-face) face)))
5815 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5816 ;; There is a gap, lets see if we need to report it
5817 (unless (org-agenda-check-clock-gap tlend ts gapok)
5818 (setq issue (format "Clocking gap: %d minutes"
5819 (/ (- ts tlend) 60))
5820 face (or (plist-get pl :gap-face) face))))
5821 (t nil)))
5822 (setq tlend (or te tlend) tlstart (or ts tlstart))
5823 (when issue
5824 ;; OK, there was some issue, add an overlay to show the issue
5825 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5826 (overlay-put ov 'before-string
5827 (concat
5828 (org-add-props
5829 (format "%-43s" (concat " " issue))
5831 'face face)
5832 "\n"))
5833 (overlay-put ov 'evaporate t)))))
5835 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5836 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5837 (catch 'exit
5838 (unless ok-list
5839 ;; there are no OK times for gaps...
5840 (throw 'exit nil))
5841 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5842 ;; This is more than 24 hours, so it is OK.
5843 ;; because we have at least one OK time, that must be in the
5844 ;; 24 hour interval.
5845 (throw 'exit t))
5846 ;; We have a shorter gap.
5847 ;; Now we have to get the minute of the day when these times are
5848 (let* ((t1dec (decode-time (seconds-to-time t1)))
5849 (t2dec (decode-time (seconds-to-time t2)))
5850 ;; compute the minute on the day
5851 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5852 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5853 (when (< min2 min1)
5854 ;; if min2 is smaller than min1, this means it is on the next day.
5855 ;; Wrap it to after midnight.
5856 (setq min2 (+ min2 1440)))
5857 ;; Now check if any of the OK times is in the gap
5858 (mapc (lambda (x)
5859 ;; Wrap the time to after midnight if necessary
5860 (if (< x min1) (setq x (+ x 1440)))
5861 ;; Check if in interval
5862 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5863 ok-list)
5864 ;; Nope, this gap is not OK
5865 nil)))
5867 (defun org-agenda-get-deadlines ()
5868 "Return the deadline information for agenda display."
5869 (let* ((props (list 'mouse-face 'highlight
5870 'org-not-done-regexp org-not-done-regexp
5871 'org-todo-regexp org-todo-regexp
5872 'org-complex-heading-regexp org-complex-heading-regexp
5873 'help-echo
5874 (format "mouse-2 or RET jump to org file %s"
5875 (abbreviate-file-name buffer-file-name))))
5876 (regexp org-deadline-time-regexp)
5877 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5878 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5879 (dl0 (car org-agenda-deadline-leaders))
5880 (dl1 (nth 1 org-agenda-deadline-leaders))
5881 (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
5882 d2 diff dfrac wdays pos pos1 category category-pos level
5883 tags suppress-prewarning ee txt head face s todo-state
5884 show-all upcomingp donep timestr warntime inherited-tags ts-date)
5885 (goto-char (point-min))
5886 (while (re-search-forward regexp nil t)
5887 (catch :skip
5888 (org-agenda-skip)
5889 (setq s (match-string 1)
5890 txt nil
5891 pos (1- (match-beginning 1))
5892 todo-state (save-match-data (org-get-todo-state))
5893 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5894 (member todo-state
5895 org-agenda-repeating-timestamp-show-all))
5896 d2 (org-time-string-to-absolute
5897 s d1 'past show-all (current-buffer) pos)
5898 diff (- d2 d1))
5899 (setq suppress-prewarning
5900 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5901 (let ((item (buffer-substring (point-at-bol)
5902 (point-at-eol))))
5903 (save-match-data
5904 (and (string-match
5905 org-scheduled-time-regexp item)
5906 (match-string 1 item)))))))
5907 (cond
5908 ((not ds) nil)
5909 ;; The current item has a scheduled date (in ds), so
5910 ;; evaluate its prewarning lead time.
5911 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5912 ;; Use global prewarning-restart lead time.
5913 org-agenda-skip-deadline-prewarning-if-scheduled)
5914 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5915 'pre-scheduled)
5916 ;; Set prewarning to no earlier than scheduled.
5917 (min (- d2 (org-time-string-to-absolute
5918 ds d1 'past show-all (current-buffer) pos))
5919 org-deadline-warning-days))
5920 ;; Set prewarning to deadline.
5921 (t 0))))
5922 (setq wdays (if suppress-prewarning
5923 (let ((org-deadline-warning-days suppress-prewarning))
5924 (org-get-wdays s))
5925 (org-get-wdays s))
5926 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5927 upcomingp (and todayp (> diff 0)))
5928 ;; When to show a deadline in the calendar:
5929 ;; If the expiration is within wdays warning time.
5930 ;; Past-due deadlines are only shown on the current date
5931 (if (and (or (and (<= diff wdays)
5932 (and todayp (not org-agenda-only-exact-dates)))
5933 (= diff 0)))
5934 (save-excursion
5935 ;; (setq todo-state (org-get-todo-state))
5936 (setq donep (member todo-state org-done-keywords))
5937 (if (and donep
5938 (or org-agenda-skip-deadline-if-done
5939 (not (= diff 0))))
5940 (setq txt nil)
5941 (setq category (org-get-category)
5942 warntime (get-text-property (point) 'org-appt-warntime)
5943 category-pos (get-text-property (point) 'org-category-position))
5944 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5945 (throw :skip nil)
5946 (goto-char (match-end 0))
5947 (setq pos1 (match-beginning 0))
5948 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5949 (setq inherited-tags
5950 (or (eq org-agenda-show-inherited-tags 'always)
5951 (and (listp org-agenda-show-inherited-tags)
5952 (memq 'agenda org-agenda-show-inherited-tags))
5953 (and (eq org-agenda-show-inherited-tags t)
5954 (or (eq org-agenda-use-tag-inheritance t)
5955 (memq 'agenda org-agenda-use-tag-inheritance))))
5956 tags (org-get-tags-at pos1 (not inherited-tags)))
5957 (setq head (buffer-substring
5958 (point)
5959 (progn (skip-chars-forward "^\r\n")
5960 (point))))
5961 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5962 (setq timestr
5963 (concat (substring s (match-beginning 1)) " "))
5964 (setq timestr 'time))
5965 (setq txt (org-agenda-format-item
5966 (cond ((= diff 0) dl0)
5967 ((> diff 0)
5968 (if (functionp dl1)
5969 (funcall dl1 diff date)
5970 (format dl1 diff)))
5972 (if (functionp dl2)
5973 (funcall dl2 diff date)
5974 (format dl2 (if (string= dl2 dl1)
5975 diff (abs diff))))))
5976 head level category tags
5977 (if (not (= diff 0)) nil timestr)))))
5978 (when txt
5979 (setq face (org-agenda-deadline-face dfrac))
5980 (org-add-props txt props
5981 'org-marker (org-agenda-new-marker pos)
5982 'warntime warntime
5983 'level level
5984 'ts-date d2
5985 'org-hd-marker (org-agenda-new-marker pos1)
5986 'priority (+ (- diff)
5987 (org-get-priority txt))
5988 'org-category category
5989 'org-category-position category-pos
5990 'todo-state todo-state
5991 'type (if upcomingp "upcoming-deadline" "deadline")
5992 'date (if upcomingp date d2)
5993 'face (if donep 'org-agenda-done face)
5994 'undone-face face 'done-face 'org-agenda-done)
5995 (push txt ee))))))
5996 (nreverse ee)))
5998 (defun org-agenda-deadline-face (fraction)
5999 "Return the face to displaying a deadline item.
6000 FRACTION is what fraction of the head-warning time has passed."
6001 (let ((faces org-agenda-deadline-faces) f)
6002 (catch 'exit
6003 (while (setq f (pop faces))
6004 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6006 (defun org-agenda-get-scheduled (&optional deadline-results)
6007 "Return the scheduled information for agenda display."
6008 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6009 'org-todo-regexp org-todo-regexp
6010 'org-complex-heading-regexp org-complex-heading-regexp
6011 'done-face 'org-agenda-done
6012 'mouse-face 'highlight
6013 'help-echo
6014 (format "mouse-2 or RET jump to org file %s"
6015 (abbreviate-file-name buffer-file-name))))
6016 (regexp org-scheduled-time-regexp)
6017 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6018 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6020 (deadline-position-alist
6021 (mapcar (lambda (a) (and (setq mm (get-text-property
6022 0 'org-hd-marker a))
6023 (cons (marker-position mm) a)))
6024 deadline-results))
6025 d2 diff pos pos1 category category-pos level tags donep
6026 ee txt head pastschedp todo-state face timestr s habitp show-all
6027 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6028 ddays)
6029 (goto-char (point-min))
6030 (while (re-search-forward regexp nil t)
6031 (catch :skip
6032 (org-agenda-skip)
6033 (setq s (match-string 1)
6034 txt nil
6035 pos (1- (match-beginning 1))
6036 todo-state (save-match-data (org-get-todo-state))
6037 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6038 (member todo-state
6039 org-agenda-repeating-timestamp-show-all))
6040 d2 (org-time-string-to-absolute
6041 s d1 'past show-all (current-buffer) pos)
6042 diff (- d2 d1)
6043 warntime (get-text-property (point) 'org-appt-warntime))
6044 (setq pastschedp (and todayp (< diff 0)))
6045 (setq did-habit-check-p nil)
6046 (setq suppress-delay
6047 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6048 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6049 (save-match-data
6050 (and (string-match
6051 org-deadline-time-regexp item)
6052 (match-string 1 item)))))))
6053 (cond
6054 ((not ds) nil)
6055 ;; The current item has a deadline date (in ds), so
6056 ;; evaluate its delay time.
6057 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6058 ;; Use global delay time.
6059 (- org-agenda-skip-scheduled-delay-if-deadline))
6060 ((eq org-agenda-skip-scheduled-delay-if-deadline
6061 'post-deadline)
6062 ;; Set delay to no later than deadline.
6063 (min (- d2 (org-time-string-to-absolute
6064 ds d1 'past show-all (current-buffer) pos))
6065 org-scheduled-delay-days))
6066 (t 0))))
6067 (setq ddays (if suppress-delay
6068 (let ((org-scheduled-delay-days suppress-delay))
6069 (org-get-wdays s t t))
6070 (org-get-wdays s t)))
6071 ;; Use a delay of 0 when there is a repeater and the delay is
6072 ;; of the form --3d
6073 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6074 (< (org-time-string-to-absolute s)
6075 (org-time-string-to-absolute
6076 s d2 'past nil (current-buffer) pos)))
6077 (setq ddays 0))
6078 ;; When to show a scheduled item in the calendar:
6079 ;; If it is on or past the date.
6080 (when (or (and (> ddays 0) (= diff (- ddays)))
6081 (and (zerop ddays) (= diff 0))
6082 (and (< (+ diff ddays) 0)
6083 (< (abs diff) org-scheduled-past-days)
6084 (and todayp (not org-agenda-only-exact-dates)))
6085 ;; org-is-habit-p uses org-entry-get, which is expansive
6086 ;; so we go extra mile to only call it once
6087 (and todayp
6088 (boundp 'org-habit-show-all-today)
6089 org-habit-show-all-today
6090 (setq did-habit-check-p t)
6091 (setq habitp (and (functionp 'org-is-habit-p)
6092 (org-is-habit-p)))))
6093 (save-excursion
6094 (setq donep (member todo-state org-done-keywords))
6095 (if (and donep
6096 (or org-agenda-skip-scheduled-if-done
6097 (not (= diff 0))
6098 (and (functionp 'org-is-habit-p)
6099 (org-is-habit-p))))
6100 (setq txt nil)
6101 (setq habitp (if did-habit-check-p habitp
6102 (and (functionp 'org-is-habit-p)
6103 (org-is-habit-p))))
6104 (setq category (org-get-category)
6105 category-pos (get-text-property (point) 'org-category-position))
6106 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6107 (throw :skip nil)
6108 (goto-char (match-end 0))
6109 (setq pos1 (match-beginning 0))
6110 (if habitp
6111 (if (or (not org-habit-show-habits)
6112 (and (not todayp)
6113 (boundp 'org-habit-show-habits-only-for-today)
6114 org-habit-show-habits-only-for-today))
6115 (throw :skip nil))
6116 (if (and
6117 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6118 (and org-agenda-skip-scheduled-if-deadline-is-shown
6119 pastschedp))
6120 (setq mm (assoc pos1 deadline-position-alist)))
6121 (throw :skip nil)))
6122 (setq inherited-tags
6123 (or (eq org-agenda-show-inherited-tags 'always)
6124 (and (listp org-agenda-show-inherited-tags)
6125 (memq 'agenda org-agenda-show-inherited-tags))
6126 (and (eq org-agenda-show-inherited-tags t)
6127 (or (eq org-agenda-use-tag-inheritance t)
6128 (memq 'agenda org-agenda-use-tag-inheritance))))
6130 tags (org-get-tags-at nil (not inherited-tags)))
6131 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6132 (setq head (buffer-substring
6133 (point)
6134 (progn (skip-chars-forward "^\r\n") (point))))
6135 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6136 (setq timestr
6137 (concat (substring s (match-beginning 1)) " "))
6138 (setq timestr 'time))
6139 (setq txt (org-agenda-format-item
6140 (if (= diff 0)
6141 (car org-agenda-scheduled-leaders)
6142 (format (nth 1 org-agenda-scheduled-leaders)
6143 (- 1 diff)))
6144 head level category tags
6145 (if (not (= diff 0)) nil timestr)
6146 nil habitp))))
6147 (when txt
6148 (setq face
6149 (cond
6150 ((and (not habitp) pastschedp)
6151 'org-scheduled-previously)
6152 (todayp 'org-scheduled-today)
6153 (t 'org-scheduled))
6154 habitp (and habitp (org-habit-parse-todo)))
6155 (org-add-props txt props
6156 'undone-face face
6157 'face (if donep 'org-agenda-done face)
6158 'org-marker (org-agenda-new-marker pos)
6159 'org-hd-marker (org-agenda-new-marker pos1)
6160 'type (if pastschedp "past-scheduled" "scheduled")
6161 'date (if pastschedp d2 date)
6162 'ts-date d2
6163 'warntime warntime
6164 'level level
6165 'priority (if habitp
6166 (org-habit-get-priority habitp)
6167 (+ 94 (- 5 diff) (org-get-priority txt)))
6168 'org-category category
6169 'category-position category-pos
6170 'org-habit-p habitp
6171 'todo-state todo-state)
6172 (push txt ee))))))
6173 (nreverse ee)))
6175 (defun org-agenda-get-blocks ()
6176 "Return the date-range information for agenda display."
6177 (let* ((props (list 'face nil
6178 'org-not-done-regexp org-not-done-regexp
6179 'org-todo-regexp org-todo-regexp
6180 'org-complex-heading-regexp org-complex-heading-regexp
6181 'mouse-face 'highlight
6182 'help-echo
6183 (format "mouse-2 or RET jump to org file %s"
6184 (abbreviate-file-name buffer-file-name))))
6185 (regexp org-tr-regexp)
6186 (d0 (calendar-absolute-from-gregorian date))
6187 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6188 level todo-state tags pos head donep inherited-tags)
6189 (goto-char (point-min))
6190 (while (re-search-forward regexp nil t)
6191 (catch :skip
6192 (org-agenda-skip)
6193 (setq pos (point))
6194 (let ((start-time (match-string 1))
6195 (end-time (match-string 2)))
6196 (setq s1 (match-string 1)
6197 s2 (match-string 2)
6198 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6199 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6200 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6201 ;; Only allow days between the limits, because the normal
6202 ;; date stamps will catch the limits.
6203 (save-excursion
6204 (setq todo-state (org-get-todo-state))
6205 (setq donep (member todo-state org-done-keywords))
6206 (if (and donep org-agenda-skip-timestamp-if-done)
6207 (throw :skip t))
6208 (setq marker (org-agenda-new-marker (point)))
6209 (setq category (org-get-category)
6210 category-pos (get-text-property (point) 'org-category-position))
6211 (if (not (re-search-backward org-outline-regexp-bol nil t))
6212 (throw :skip nil)
6213 (goto-char (match-beginning 0))
6214 (setq hdmarker (org-agenda-new-marker (point))
6215 inherited-tags
6216 (or (eq org-agenda-show-inherited-tags 'always)
6217 (and (listp org-agenda-show-inherited-tags)
6218 (memq 'agenda org-agenda-show-inherited-tags))
6219 (and (eq org-agenda-show-inherited-tags t)
6220 (or (eq org-agenda-use-tag-inheritance t)
6221 (memq 'agenda org-agenda-use-tag-inheritance))))
6223 tags (org-get-tags-at nil (not inherited-tags)))
6224 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6225 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6226 (setq head (match-string 1))
6227 (let ((remove-re
6228 (if org-agenda-remove-timeranges-from-blocks
6229 (concat
6230 "<" (regexp-quote s1) ".*?>"
6231 "--"
6232 "<" (regexp-quote s2) ".*?>")
6233 nil)))
6234 (setq txt (org-agenda-format-item
6235 (format
6236 (nth (if (= d1 d2) 0 1)
6237 org-agenda-timerange-leaders)
6238 (1+ (- d0 d1)) (1+ (- d2 d1)))
6239 head level category tags
6240 (cond ((and (= d1 d0) (= d2 d0))
6241 (concat "<" start-time ">--<" end-time ">"))
6242 ((= d1 d0)
6243 (concat "<" start-time ">"))
6244 ((= d2 d0)
6245 (concat "<" end-time ">")))
6246 remove-re))))
6247 (org-add-props txt props
6248 'org-marker marker 'org-hd-marker hdmarker
6249 'type "block" 'date date
6250 'level level
6251 'todo-state todo-state
6252 'priority (org-get-priority txt) 'org-category category
6253 'org-category-position category-pos)
6254 (push txt ee))))
6255 (goto-char pos)))
6256 ;; Sort the entries by expiration date.
6257 (nreverse ee)))
6259 ;;; Agenda presentation and sorting
6261 (defvar org-prefix-has-time nil
6262 "A flag, set by `org-compile-prefix-format'.
6263 The flag is set if the currently compiled format contains a `%t'.")
6264 (defvar org-prefix-has-tag nil
6265 "A flag, set by `org-compile-prefix-format'.
6266 The flag is set if the currently compiled format contains a `%T'.")
6267 (defvar org-prefix-has-effort nil
6268 "A flag, set by `org-compile-prefix-format'.
6269 The flag is set if the currently compiled format contains a `%e'.")
6270 (defvar org-prefix-has-breadcrumbs nil
6271 "A flag, set by `org-compile-prefix-format'.
6272 The flag is set if the currently compiled format contains a `%b'.")
6273 (defvar org-prefix-category-length nil
6274 "Used by `org-compile-prefix-format' to remember the category field width.")
6275 (defvar org-prefix-category-max-length nil
6276 "Used by `org-compile-prefix-format' to remember the category field width.")
6278 (defun org-agenda-get-category-icon (category)
6279 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6280 (dolist (entry org-agenda-category-icon-alist)
6281 (when (org-string-match-p (car entry) category)
6282 (if (listp (cadr entry))
6283 (return (cadr entry))
6284 (return (apply 'create-image (cdr entry)))))))
6286 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6287 remove-re habitp)
6288 "Format TXT to be inserted into the agenda buffer.
6289 In particular, add the prefix and corresponding text properties.
6291 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6292 LEVEL may be a string to replace the `%l' specifier.
6293 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6294 category taken from local variable or file name. It will replace the `%c'
6295 specifier in the format.
6296 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6297 TXT for sorting of this entry, and for the `%t' specifier in the format.
6298 When DOTIME is a string, this string is searched for a time before TXT is.
6299 TAGS can be the tags of the headline.
6300 Any match of REMOVE-RE will be removed from TXT."
6301 ;; We keep the org-prefix-* variable values along with a compiled
6302 ;; formatter, so that multiple agendas existing at the same time do
6303 ;; not step on each other toes.
6305 ;; It was inconvenient to make these variables buffer local in
6306 ;; Agenda buffers, because this function expects to be called with
6307 ;; the buffer where item comes from being current, and not agenda
6308 ;; buffer
6309 (let* ((bindings (car org-prefix-format-compiled))
6310 (formatter (cadr org-prefix-format-compiled)))
6311 (loop for (var value) in bindings
6312 do (set var value))
6313 (save-match-data
6314 ;; Diary entries sometimes have extra whitespace at the beginning
6315 (setq txt (org-trim txt))
6317 ;; Fix the tags part in txt
6318 (setq txt (org-agenda-fix-displayed-tags
6319 txt tags
6320 org-agenda-show-inherited-tags
6321 org-agenda-hide-tags-regexp))
6323 (let* ((category (or category
6324 (if (stringp org-category)
6325 org-category
6326 (and org-category (symbol-name org-category)))
6327 (if buffer-file-name
6328 (file-name-sans-extension
6329 (file-name-nondirectory buffer-file-name))
6330 "")))
6331 (category-icon (org-agenda-get-category-icon category))
6332 (category-icon (if category-icon
6333 (propertize " " 'display category-icon)
6334 ""))
6335 ;; time, tag, effort are needed for the eval of the prefix format
6336 (tag (if tags (nth (1- (length tags)) tags) ""))
6337 time effort neffort
6338 (ts (if dotime (concat
6339 (if (stringp dotime) dotime "")
6340 (and org-agenda-search-headline-for-time txt))))
6341 (time-of-day (and dotime (org-get-time-of-day ts)))
6342 stamp plain s0 s1 s2 rtn srp l
6343 duration thecategory breadcrumbs)
6344 (and (derived-mode-p 'org-mode) buffer-file-name
6345 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6346 (when (and dotime time-of-day)
6347 ;; Extract starting and ending time and move them to prefix
6348 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6349 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6350 (setq s0 (match-string 0 ts)
6351 srp (and stamp (match-end 3))
6352 s1 (match-string (if plain 1 2) ts)
6353 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6355 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6356 ;; them, we might want to remove them there to avoid duplication.
6357 ;; The user can turn this off with a variable.
6358 (if (and org-prefix-has-time
6359 org-agenda-remove-times-when-in-prefix (or stamp plain)
6360 (string-match (concat (regexp-quote s0) " *") txt)
6361 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6362 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6363 (= (match-beginning 0) 0)
6365 (setq txt (replace-match "" nil nil txt))))
6366 ;; Normalize the time(s) to 24 hour
6367 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6368 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6370 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6371 (let (org-time-clocksum-use-effort-durations)
6372 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6373 (setq s2
6374 (org-minutes-to-clocksum-string
6375 (+ (org-hh:mm-string-to-minutes s1)
6376 org-agenda-default-appointment-duration)))))
6378 ;; Compute the duration
6379 (when s2
6380 (setq duration (- (org-hh:mm-string-to-minutes s2)
6381 (org-hh:mm-string-to-minutes s1)))))
6383 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6384 txt)
6385 ;; Tags are in the string
6386 (if (or (eq org-agenda-remove-tags t)
6387 (and org-agenda-remove-tags
6388 org-prefix-has-tag))
6389 (setq txt (replace-match "" t t txt))
6390 (setq txt (replace-match
6391 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6392 (match-string 2 txt))
6393 t t txt))))
6394 (when (derived-mode-p 'org-mode)
6395 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6396 (if effort
6397 (setq neffort (org-duration-string-to-minutes effort)
6398 effort (setq effort (concat "[" effort "]")))
6399 ;; prevent erroring out with %e format when there is no effort
6400 (setq effort "")))
6402 (when remove-re
6403 (while (string-match remove-re txt)
6404 (setq txt (replace-match "" t t txt))))
6406 ;; Set org-heading property on `txt' to mark the start of the
6407 ;; heading.
6408 (add-text-properties 0 (length txt) '(org-heading t) txt)
6410 ;; Prepare the variables needed in the eval of the compiled format
6411 (if org-prefix-has-breadcrumbs
6412 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6413 (let ((s (org-display-outline-path nil nil "->" t)))
6414 (if (eq "" s) "" (concat s "->"))))))
6415 (setq time (cond (s2 (concat
6416 (org-agenda-time-of-day-to-ampm-maybe s1)
6417 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6418 (if org-agenda-timegrid-use-ampm " ")))
6419 (s1 (concat
6420 (org-agenda-time-of-day-to-ampm-maybe s1)
6421 (if org-agenda-timegrid-use-ampm
6422 "........ "
6423 "......")))
6424 (t ""))
6425 extra (or (and (not habitp) extra) "")
6426 category (if (symbolp category) (symbol-name category) category)
6427 thecategory (copy-sequence category)
6428 level (or level ""))
6429 (if (string-match org-bracket-link-regexp category)
6430 (progn
6431 (setq l (if (match-end 3)
6432 (- (match-end 3) (match-beginning 3))
6433 (- (match-end 1) (match-beginning 1))))
6434 (when (< l (or org-prefix-category-length 0))
6435 (setq category (copy-sequence category))
6436 (org-add-props category nil
6437 'extra-space (make-string
6438 (- org-prefix-category-length l 1) ?\ ))))
6439 (if (and org-prefix-category-max-length
6440 (>= (length category) org-prefix-category-max-length))
6441 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6442 ;; Evaluate the compiled format
6443 (setq rtn (concat (eval formatter) txt))
6445 ;; And finally add the text properties
6446 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6447 (org-add-props rtn nil
6448 'org-category (if thecategory (downcase thecategory) category)
6449 'tags (mapcar 'org-downcase-keep-props tags)
6450 'org-highest-priority org-highest-priority
6451 'org-lowest-priority org-lowest-priority
6452 'time-of-day time-of-day
6453 'duration duration
6454 'effort effort
6455 'effort-minutes neffort
6456 'breadcrumbs breadcrumbs
6457 'txt txt
6458 'level level
6459 'time time
6460 'extra extra
6461 'format org-prefix-format-compiled
6462 'dotime dotime)))))
6464 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6465 "Remove tags string from TXT, and add a modified list of tags.
6466 The modified list may contain inherited tags, and tags matched by
6467 `org-agenda-hide-tags-regexp' will be removed."
6468 (when (or add-inherited hide-re)
6469 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6470 (setq txt (substring txt 0 (match-beginning 0))))
6471 (setq tags
6472 (delq nil
6473 (mapcar (lambda (tg)
6474 (if (or (and hide-re (string-match hide-re tg))
6475 (and (not add-inherited)
6476 (get-text-property 0 'inherited tg)))
6478 tg))
6479 tags)))
6480 (when tags
6481 (let ((have-i (get-text-property 0 'inherited (car tags)))
6483 (setq txt (concat txt " :"
6484 (mapconcat
6485 (lambda (x)
6486 (setq i (get-text-property 0 'inherited x))
6487 (if (and have-i (not i))
6488 (progn
6489 (setq have-i nil)
6490 (concat ":" x))
6492 tags ":")
6493 (if have-i "::" ":"))))))
6494 txt)
6496 (defun org-downcase-keep-props (s)
6497 (let ((props (text-properties-at 0 s)))
6498 (setq s (downcase s))
6499 (add-text-properties 0 (length s) props s)
6502 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6504 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6505 "Add a time-grid for agenda items which need it.
6507 LIST is the list of agenda items formatted by `org-agenda-list'.
6508 NDAYS is the span of the current agenda view.
6509 TODAYP is `t' when the current agenda view is on today."
6510 (catch 'exit
6511 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6512 ((and todayp (member 'today (car org-agenda-time-grid))))
6513 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6514 ((member 'weekly (car org-agenda-time-grid)))
6515 (t (throw 'exit list)))
6516 (let* ((have (delq nil (mapcar
6517 (lambda (x) (get-text-property 1 'time-of-day x))
6518 list)))
6519 (string (nth 1 org-agenda-time-grid))
6520 (gridtimes (nth 2 org-agenda-time-grid))
6521 (req (car org-agenda-time-grid))
6522 (remove (member 'remove-match req))
6523 new time)
6524 (if (and (member 'require-timed req) (not have))
6525 ;; don't show empty grid
6526 (throw 'exit list))
6527 (while (setq time (pop gridtimes))
6528 (unless (and remove (member time have))
6529 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6530 (push (org-agenda-format-item
6531 nil string nil "" nil
6532 (concat (substring time 0 -2) ":" (substring time -2)))
6533 new)
6534 (put-text-property
6535 2 (length (car new)) 'face 'org-time-grid (car new))))
6536 (when (and todayp org-agenda-show-current-time-in-grid)
6537 (push (org-agenda-format-item
6538 nil org-agenda-current-time-string nil "" nil
6539 (format-time-string "%H:%M "))
6540 new)
6541 (put-text-property
6542 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6544 (if (member 'time-up org-agenda-sorting-strategy-selected)
6545 (append new list)
6546 (append list new)))))
6548 (defun org-compile-prefix-format (key)
6549 "Compile the prefix format into a Lisp form that can be evaluated.
6550 The resulting form and associated variable bindings is returned
6551 and stored in the variable `org-prefix-format-compiled'."
6552 (setq org-prefix-has-time nil
6553 org-prefix-has-tag nil
6554 org-prefix-category-length nil
6555 org-prefix-has-effort nil
6556 org-prefix-has-breadcrumbs nil)
6557 (let ((s (cond
6558 ((stringp org-agenda-prefix-format)
6559 org-agenda-prefix-format)
6560 ((assq key org-agenda-prefix-format)
6561 (cdr (assq key org-agenda-prefix-format)))
6562 (t " %-12:c%?-12t% s")))
6563 (start 0)
6564 varform vars var e c f opt)
6565 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6566 s start)
6567 (setq var (or (cdr (assoc (match-string 4 s)
6568 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6569 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6570 'eval)
6571 c (or (match-string 3 s) "")
6572 opt (match-beginning 1)
6573 start (1+ (match-beginning 0)))
6574 (if (equal var 'time) (setq org-prefix-has-time t))
6575 (if (equal var 'tag) (setq org-prefix-has-tag t))
6576 (if (equal var 'effort) (setq org-prefix-has-effort t))
6577 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6578 (setq f (concat "%" (match-string 2 s) "s"))
6579 (when (equal var 'category)
6580 (setq org-prefix-category-length
6581 (floor (abs (string-to-number (match-string 2 s)))))
6582 (setq org-prefix-category-max-length
6583 (let ((x (match-string 2 s)))
6584 (save-match-data
6585 (if (string-match "\\.[0-9]+" x)
6586 (string-to-number (substring (match-string 0 x) 1)))))))
6587 (if (eq var 'eval)
6588 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6589 (if opt
6590 (setq varform
6591 `(if (equal "" ,var)
6593 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6594 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6595 (setq s (replace-match "%s" t nil s))
6596 (push varform vars))
6597 (setq vars (nreverse vars))
6598 (with-current-buffer (or org-agenda-buffer (current-buffer))
6599 (setq org-prefix-format-compiled
6600 (list
6601 `((org-prefix-has-time ,org-prefix-has-time)
6602 (org-prefix-has-tag ,org-prefix-has-tag)
6603 (org-prefix-category-length ,org-prefix-category-length)
6604 (org-prefix-has-effort ,org-prefix-has-effort)
6605 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6606 `(format ,s ,@vars))))))
6608 (defun org-set-sorting-strategy (key)
6609 (if (symbolp (car org-agenda-sorting-strategy))
6610 ;; the old format
6611 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6612 (setq org-agenda-sorting-strategy-selected
6613 (or (cdr (assq key org-agenda-sorting-strategy))
6614 (cdr (assq 'agenda org-agenda-sorting-strategy))
6615 '(time-up category-keep priority-down)))))
6617 (defun org-get-time-of-day (s &optional string mod24)
6618 "Check string S for a time of day.
6619 If found, return it as a military time number between 0 and 2400.
6620 If not found, return nil.
6621 The optional STRING argument forces conversion into a 5 character wide string
6622 HH:MM."
6623 (save-match-data
6624 (when
6625 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6626 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6627 (let* ((h (string-to-number (match-string 1 s)))
6628 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6629 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6630 (am-p (equal ampm "am"))
6631 (h1 (cond ((not ampm) h)
6632 ((= h 12) (if am-p 0 12))
6633 (t (+ h (if am-p 0 12)))))
6634 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6635 (mod h1 24) h1))
6636 (t0 (+ (* 100 h2) m))
6637 (t1 (concat (if (>= h1 24) "+" " ")
6638 (if (and org-agenda-time-leading-zero
6639 (< t0 1000)) "0" "")
6640 (if (< t0 100) "0" "")
6641 (if (< t0 10) "0" "")
6642 (int-to-string t0))))
6643 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6645 (defvar org-agenda-before-sorting-filter-function nil
6646 "Function to be applied to agenda items prior to sorting.
6647 Prior to sorting also means just before they are inserted into the agenda.
6649 To aid sorting, you may revisit the original entries and add more text
6650 properties which will later be used by the sorting functions.
6652 The function should take a string argument, an agenda line.
6653 It has access to the text properties in that line, which contain among
6654 other things, the property `org-hd-marker' that points to the entry
6655 where the line comes from. Note that not all lines going into the agenda
6656 have this property, only most.
6658 The function should return the modified string. It is probably best
6659 to ONLY change text properties.
6661 You can also use this function as a filter, by returning nil for lines
6662 you don't want to have in the agenda at all. For this application, you
6663 could bind the variable in the options section of a custom command.")
6665 (defun org-agenda-finalize-entries (list &optional type)
6666 "Sort, limit and concatenate the LIST of agenda items.
6667 The optional argument TYPE tells the agenda type."
6668 (let ((max-effort (cond ((listp org-agenda-max-effort)
6669 (cdr (assoc type org-agenda-max-effort)))
6670 (t org-agenda-max-effort)))
6671 (max-todo (cond ((listp org-agenda-max-todos)
6672 (cdr (assoc type org-agenda-max-todos)))
6673 (t org-agenda-max-todos)))
6674 (max-tags (cond ((listp org-agenda-max-tags)
6675 (cdr (assoc type org-agenda-max-tags)))
6676 (t org-agenda-max-tags)))
6677 (max-entries (cond ((listp org-agenda-max-entries)
6678 (cdr (assoc type org-agenda-max-entries)))
6679 (t org-agenda-max-entries))) l)
6680 (when org-agenda-before-sorting-filter-function
6681 (setq list
6682 (delq nil
6683 (mapcar
6684 org-agenda-before-sorting-filter-function list))))
6685 (setq list (mapcar 'org-agenda-highlight-todo list)
6686 list (mapcar 'identity (sort list 'org-entries-lessp))
6687 list (org-agenda-limit-entries
6688 list 'effort-minutes max-effort 'identity)
6689 list (org-agenda-limit-entries list 'todo-state max-todo)
6690 list (org-agenda-limit-entries list 'tags max-tags)
6691 list (org-agenda-limit-entries list 'org-hd-marker max-entries)
6692 list (mapconcat 'identity list "\n"))))
6694 (defun org-agenda-limit-entries (list prop limit &optional fn)
6695 "Limit the number of agenda entries."
6696 (if limit
6697 (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
6698 (delq nil
6699 (mapcar
6700 (lambda (e)
6701 (let ((pval (funcall f (get-text-property 1 prop e))))
6702 (if pval (setq lim (+ lim pval)))
6703 (if (or (not pval) (<= lim limit)) e)))
6704 list)))
6705 list))
6707 (defun org-agenda-highlight-todo (x)
6708 (let ((org-done-keywords org-done-keywords-for-agenda)
6709 (case-fold-search nil)
6711 (if (eq x 'line)
6712 (save-excursion
6713 (beginning-of-line 1)
6714 (setq re (org-get-at-bol 'org-todo-regexp))
6715 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6716 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6717 (add-text-properties (match-beginning 0) (match-end 1)
6718 (list 'face (org-get-todo-face 1)))
6719 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6720 (delete-region (match-beginning 1) (1- (match-end 0)))
6721 (goto-char (match-beginning 1))
6722 (insert (format org-agenda-todo-keyword-format s)))))
6723 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6724 (setq re (get-text-property 0 'org-todo-regexp x))
6725 (when (and re
6726 ;; Test `pl' because if there's no heading content,
6727 ;; there's no point matching to highlight. Note
6728 ;; that if we didn't test `pl' first, and there
6729 ;; happened to be no keyword from `org-todo-regexp'
6730 ;; on this heading line, then the `equal' comparison
6731 ;; afterwards would spuriously succeed in the case
6732 ;; where `pl' is nil -- causing an args-out-of-range
6733 ;; error when we try to add text properties to text
6734 ;; that isn't there.
6736 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6737 x pl) pl))
6738 (add-text-properties
6739 (or (match-end 1) (match-end 0)) (match-end 0)
6740 (list 'face (org-get-todo-face (match-string 2 x)))
6742 (when (match-end 1)
6743 (setq x (concat (substring x 0 (match-end 1))
6744 (format org-agenda-todo-keyword-format
6745 (match-string 2 x))
6746 (org-add-props " " (text-properties-at 0 x))
6747 (substring x (match-end 3)))))))
6748 x)))
6750 (defsubst org-cmp-priority (a b)
6751 "Compare the priorities of string A and B."
6752 (let ((pa (or (get-text-property 1 'priority a) 0))
6753 (pb (or (get-text-property 1 'priority b) 0)))
6754 (cond ((> pa pb) +1)
6755 ((< pa pb) -1))))
6757 (defsubst org-cmp-effort (a b)
6758 "Compare the effort values of string A and B."
6759 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6760 (ea (or (get-text-property 1 'effort-minutes a) def))
6761 (eb (or (get-text-property 1 'effort-minutes b) def)))
6762 (cond ((> ea eb) +1)
6763 ((< ea eb) -1))))
6765 (defsubst org-cmp-category (a b)
6766 "Compare the string values of categories of strings A and B."
6767 (let ((ca (or (get-text-property 1 'org-category a) ""))
6768 (cb (or (get-text-property 1 'org-category b) "")))
6769 (cond ((string-lessp ca cb) -1)
6770 ((string-lessp cb ca) +1))))
6772 (defsubst org-cmp-todo-state (a b)
6773 "Compare the todo states of strings A and B."
6774 (let* ((ma (or (get-text-property 1 'org-marker a)
6775 (get-text-property 1 'org-hd-marker a)))
6776 (mb (or (get-text-property 1 'org-marker b)
6777 (get-text-property 1 'org-hd-marker b)))
6778 (fa (and ma (marker-buffer ma)))
6779 (fb (and mb (marker-buffer mb)))
6780 (todo-kwds
6781 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6782 (and fb (with-current-buffer fb org-todo-keywords-1))))
6783 (ta (or (get-text-property 1 'todo-state a) ""))
6784 (tb (or (get-text-property 1 'todo-state b) ""))
6785 (la (- (length (member ta todo-kwds))))
6786 (lb (- (length (member tb todo-kwds))))
6787 (donepa (member ta org-done-keywords-for-agenda))
6788 (donepb (member tb org-done-keywords-for-agenda)))
6789 (cond ((and donepa (not donepb)) -1)
6790 ((and (not donepa) donepb) +1)
6791 ((< la lb) -1)
6792 ((< lb la) +1))))
6794 (defsubst org-cmp-alpha (a b)
6795 "Compare the headlines, alphabetically."
6796 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6797 (plb (text-property-any 0 (length b) 'org-heading t b))
6798 (ta (and pla (substring a pla)))
6799 (tb (and plb (substring b plb))))
6800 (when pla
6801 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6802 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6803 (setq ta (substring ta (match-end 0))))
6804 (setq ta (downcase ta)))
6805 (when plb
6806 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6807 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6808 (setq tb (substring tb (match-end 0))))
6809 (setq tb (downcase tb)))
6810 (cond ((not ta) +1)
6811 ((not tb) -1)
6812 ((string-lessp ta tb) -1)
6813 ((string-lessp tb ta) +1))))
6815 (defsubst org-cmp-tag (a b)
6816 "Compare the string values of the first tags of A and B."
6817 (let ((ta (car (last (get-text-property 1 'tags a))))
6818 (tb (car (last (get-text-property 1 'tags b)))))
6819 (cond ((not ta) +1)
6820 ((not tb) -1)
6821 ((string-lessp ta tb) -1)
6822 ((string-lessp tb ta) +1))))
6824 (defsubst org-cmp-time (a b)
6825 "Compare the time-of-day values of strings A and B."
6826 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6827 (ta (or (get-text-property 1 'time-of-day a) def))
6828 (tb (or (get-text-property 1 'time-of-day b) def)))
6829 (cond ((< ta tb) -1)
6830 ((< tb ta) +1))))
6832 (defsubst org-cmp-ts (a b &optional type)
6833 "Compare the timestamps values of entries A and B.
6834 When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
6835 or \"timestamp_ia\", compare within each of these type.
6836 When TYPE is the empty string, compare all timestamps
6837 without respect of their type."
6838 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6839 (ta (or (and (string-match type (get-text-property 1 'type a))
6840 (get-text-property 1 'ts-date a)) def))
6841 (tb (or (and (string-match type (get-text-property 1 'type b))
6842 (get-text-property 1 'ts-date b)) def)))
6843 (cond ((< ta tb) -1)
6844 ((< tb ta) +1))))
6846 (defsubst org-cmp-habit-p (a b)
6847 "Compare the todo states of strings A and B."
6848 (let ((ha (get-text-property 1 'org-habit-p a))
6849 (hb (get-text-property 1 'org-habit-p b)))
6850 (cond ((and ha (not hb)) -1)
6851 ((and (not ha) hb) +1))))
6853 (defun org-entries-lessp (a b)
6854 "Predicate for sorting agenda entries."
6855 ;; The following variables will be used when the form is evaluated.
6856 ;; So even though the compiler complains, keep them.
6857 (let* ((ss org-agenda-sorting-strategy-selected)
6858 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
6859 (org-cmp-ts a b "")))
6860 (timestamp-down (if timestamp-up (- timestamp-up) nil))
6861 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
6862 (org-cmp-ts a b "scheduled")))
6863 (scheduled-down (if scheduled-up (- scheduled-up) nil))
6864 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
6865 (org-cmp-ts a b "deadline")))
6866 (deadline-down (if deadline-up (- deadline-up) nil))
6867 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
6868 (org-cmp-ts a b "iatimestamp_ia")))
6869 (tsia-down (if tsia-up (- tsia-up) nil))
6870 (ts-up (and (org-em 'ts-up 'ts-down ss)
6871 (org-cmp-ts a b "timestamp")))
6872 (ts-down (if ts-up (- ts-up) nil))
6873 (time-up (and (org-em 'time-up 'time-down ss)
6874 (org-cmp-time a b)))
6875 (time-down (if time-up (- time-up) nil))
6876 (priority-up (and (org-em 'priority-up 'priority-down ss)
6877 (org-cmp-priority a b)))
6878 (priority-down (if priority-up (- priority-up) nil))
6879 (effort-up (and (org-em 'effort-up 'effort-down ss)
6880 (org-cmp-effort a b)))
6881 (effort-down (if effort-up (- effort-up) nil))
6882 (category-up (and (or (org-em 'category-up 'category-down ss)
6883 (memq 'category-keep ss))
6884 (org-cmp-category a b)))
6885 (category-down (if category-up (- category-up) nil))
6886 (category-keep (if category-up +1 nil))
6887 (tag-up (and (org-em 'tag-up 'tag-down ss)
6888 (org-cmp-tag a b)))
6889 (tag-down (if tag-up (- tag-up) nil))
6890 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6891 (org-cmp-todo-state a b)))
6892 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6893 (habit-up (and (org-em 'habit-up 'habit-down ss)
6894 (org-cmp-habit-p a b)))
6895 (habit-down (if habit-up (- habit-up) nil))
6896 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6897 (org-cmp-alpha a b)))
6898 (alpha-down (if alpha-up (- alpha-up) nil))
6899 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6900 user-defined-up user-defined-down)
6901 (if (and need-user-cmp org-agenda-cmp-user-defined
6902 (functionp org-agenda-cmp-user-defined))
6903 (setq user-defined-up
6904 (funcall org-agenda-cmp-user-defined a b)
6905 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6906 (cdr (assoc
6907 (eval (cons 'or org-agenda-sorting-strategy-selected))
6908 '((-1 . t) (1 . nil) (nil . nil))))))
6910 ;;; Agenda restriction lock
6912 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6913 "Overlay to mark the headline to which agenda commands are restricted.")
6914 (overlay-put org-agenda-restriction-lock-overlay
6915 'face 'org-agenda-restriction-lock)
6916 (overlay-put org-agenda-restriction-lock-overlay
6917 'help-echo "Agendas are currently limited to this subtree.")
6918 (org-detach-overlay org-agenda-restriction-lock-overlay)
6920 (defun org-agenda-set-restriction-lock (&optional type)
6921 "Set restriction lock for agenda, to current subtree or file.
6922 Restriction will be the file if TYPE is `file', or if type is the
6923 universal prefix '(4), or if the cursor is before the first headline
6924 in the file. Otherwise, restriction will be to the current subtree."
6925 (interactive "P")
6926 (and (equal type '(4)) (setq type 'file))
6927 (setq type (cond
6928 (type type)
6929 ((org-at-heading-p) 'subtree)
6930 ((condition-case nil (org-back-to-heading t) (error nil))
6931 'subtree)
6932 (t 'file)))
6933 (if (eq type 'subtree)
6934 (progn
6935 (setq org-agenda-restrict t)
6936 (setq org-agenda-overriding-restriction 'subtree)
6937 (put 'org-agenda-files 'org-restrict
6938 (list (buffer-file-name (buffer-base-buffer))))
6939 (org-back-to-heading t)
6940 (move-overlay org-agenda-restriction-lock-overlay
6941 (point) (save-excursion (org-end-of-subtree t t) (point)))
6942 (move-marker org-agenda-restrict-begin (point))
6943 (move-marker org-agenda-restrict-end
6944 (save-excursion (org-end-of-subtree t t)))
6945 (message "Locking agenda restriction to subtree"))
6946 (put 'org-agenda-files 'org-restrict
6947 (list (buffer-file-name (buffer-base-buffer))))
6948 (setq org-agenda-restrict nil)
6949 (setq org-agenda-overriding-restriction 'file)
6950 (move-marker org-agenda-restrict-begin nil)
6951 (move-marker org-agenda-restrict-end nil)
6952 (message "Locking agenda restriction to file"))
6953 (setq current-prefix-arg nil)
6954 (org-agenda-maybe-redo))
6956 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6957 "Remove the agenda restriction lock."
6958 (interactive "P")
6959 (org-detach-overlay org-agenda-restriction-lock-overlay)
6960 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6961 (setq org-agenda-overriding-restriction nil)
6962 (setq org-agenda-restrict nil)
6963 (put 'org-agenda-files 'org-restrict nil)
6964 (move-marker org-agenda-restrict-begin nil)
6965 (move-marker org-agenda-restrict-end nil)
6966 (setq current-prefix-arg nil)
6967 (message "Agenda restriction lock removed")
6968 (or noupdate (org-agenda-maybe-redo)))
6970 (defun org-agenda-maybe-redo ()
6971 "If there is any window showing the agenda view, update it."
6972 (let ((w (get-buffer-window org-agenda-buffer-name t))
6973 (w0 (selected-window)))
6974 (when w
6975 (select-window w)
6976 (org-agenda-redo)
6977 (select-window w0)
6978 (if org-agenda-overriding-restriction
6979 (message "Agenda view shifted to new %s restriction"
6980 org-agenda-overriding-restriction)
6981 (message "Agenda restriction lock removed")))))
6983 ;;; Agenda commands
6985 (defun org-agenda-check-type (error &rest types)
6986 "Check if agenda buffer is of allowed type.
6987 If ERROR is non-nil, throw an error, otherwise just return nil.
6988 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6989 (if (not org-agenda-type)
6990 (error "No Org agenda currently displayed")
6991 (if (memq org-agenda-type types)
6993 (if error
6994 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6995 nil))))
6997 (defun org-agenda-Quit ()
6998 "Exit the agenda and kill buffers loaded by `org-agenda'.
6999 Also restore the window configuration."
7000 (interactive)
7001 (if org-agenda-columns-active
7002 (org-columns-quit)
7003 (let ((buf (current-buffer)))
7004 (if (eq org-agenda-window-setup 'other-frame)
7005 (progn
7006 (org-agenda-reset-markers)
7007 (kill-buffer buf)
7008 (org-columns-remove-overlays)
7009 (setq org-agenda-archives-mode nil)
7010 (delete-frame))
7011 (and (not (eq org-agenda-window-setup 'current-window))
7012 (not (one-window-p))
7013 (delete-window))
7014 (org-agenda-reset-markers)
7015 (kill-buffer buf)
7016 (org-columns-remove-overlays)
7017 (setq org-agenda-archives-mode nil)))
7018 ;; Maybe restore the pre-agenda window configuration.
7019 (and org-agenda-restore-windows-after-quit
7020 (not (eq org-agenda-window-setup 'other-frame))
7021 org-agenda-pre-window-conf
7022 (set-window-configuration org-agenda-pre-window-conf)
7023 (setq org-agenda-pre-window-conf nil))))
7025 (defun org-agenda-quit ()
7026 "Exit the agenda and restore the window configuration.
7027 When `org-agenda-sticky' is non-nil, only bury the agenda."
7028 (interactive)
7029 (if (and (eq org-indirect-buffer-display 'other-window)
7030 org-last-indirect-buffer)
7031 (let ((org-last-indirect-window
7032 (get-buffer-window org-last-indirect-buffer)))
7033 (if org-last-indirect-window
7034 (delete-window org-last-indirect-window))))
7035 (if org-agenda-columns-active
7036 (org-columns-quit)
7037 (if org-agenda-sticky
7038 (let ((buf (current-buffer)))
7039 (if (eq org-agenda-window-setup 'other-frame)
7040 (progn
7041 (delete-frame))
7042 (and (not (eq org-agenda-window-setup 'current-window))
7043 (not (one-window-p))
7044 (delete-window)))
7045 (with-current-buffer buf
7046 (bury-buffer)
7047 ;; Maybe restore the pre-agenda window configuration.
7048 (and org-agenda-restore-windows-after-quit
7049 (not (eq org-agenda-window-setup 'other-frame))
7050 org-agenda-pre-window-conf
7051 (set-window-configuration org-agenda-pre-window-conf)
7052 (setq org-agenda-pre-window-conf nil))))
7053 (org-agenda-Quit))))
7055 (defun org-agenda-exit ()
7056 "Exit the agenda and restore the window configuration.
7057 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7058 buffers visited directly by the user will not be touched."
7059 (interactive)
7060 (org-release-buffers org-agenda-new-buffers)
7061 (setq org-agenda-new-buffers nil)
7062 (org-agenda-Quit))
7064 (defun org-agenda-kill-all-agenda-buffers ()
7065 "Kill all buffers in `org-agenda-mode'.
7066 This is used when toggling sticky agendas.
7067 You can also explicitly invoke it with `C-c a C-k'."
7068 (interactive)
7069 (let (blist)
7070 (dolist (buf (buffer-list))
7071 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7072 (push buf blist)))
7073 (mapc 'kill-buffer blist)))
7075 (defun org-agenda-execute (arg)
7076 "Execute another agenda command, keeping same window.
7077 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7078 in the agenda."
7079 (interactive "P")
7080 (let ((org-agenda-window-setup 'current-window))
7081 (org-agenda arg)))
7083 (defun org-agenda-redo (&optional all)
7084 "Rebuild possibly ALL agenda view(s) in the current buffer."
7085 (interactive "P")
7086 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7087 (cpa (unless (eq all t) current-prefix-arg))
7088 (org-agenda-doing-sticky-redo org-agenda-sticky)
7089 (org-agenda-sticky nil)
7090 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7091 org-agenda-buffer-name))
7092 (org-agenda-keep-modes t)
7093 (tag-filter org-agenda-tag-filter)
7094 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7095 (top-cat-filter org-agenda-top-category-filter)
7096 (cat-filter org-agenda-category-filter)
7097 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7098 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7099 (cols org-agenda-columns-active)
7100 (line (org-current-line))
7101 (window-line (- line (org-current-line (window-start))))
7102 (lprops (get 'org-agenda-redo-command 'org-lprops))
7103 (redo-cmd (get-text-property p 'org-redo-cmd))
7104 (last-args (get-text-property p 'org-last-args))
7105 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7106 (org-agenda-overriding-cmd-arguments
7107 (unless (eq all t)
7108 (cond ((listp last-args)
7109 (cons (or cpa (car last-args)) (cdr last-args)))
7110 ((stringp last-args)
7111 last-args))))
7112 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7113 (put 'org-agenda-tag-filter :preset-filter nil)
7114 (put 'org-agenda-category-filter :preset-filter nil)
7115 (and cols (org-columns-quit))
7116 (message "Rebuilding agenda buffer...")
7117 (if series-redo-cmd
7118 (eval series-redo-cmd)
7119 (org-let lprops '(eval redo-cmd)))
7120 (setq org-agenda-undo-list nil
7121 org-agenda-pending-undo-list nil)
7122 (message "Rebuilding agenda buffer...done")
7123 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7124 (put 'org-agenda-category-filter :preset-filter cat-preset)
7125 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7126 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7127 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7128 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7129 (org-goto-line line)
7130 (recenter window-line)))
7132 (defvar org-global-tags-completion-table nil)
7133 (defvar org-agenda-filter-form nil)
7134 (defvar org-agenda-filtered-by-category nil)
7136 (defun org-agenda-filter-by-category (strip)
7137 "Keep only those lines in the agenda buffer that have a specific category.
7138 The category is that of the current line."
7139 (interactive "P")
7140 (if (and org-agenda-filtered-by-category
7141 org-agenda-category-filter)
7142 (org-agenda-filter-show-all-cat)
7143 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7144 (if cat (org-agenda-filter-apply
7145 (list (concat (if strip "-" "+") cat)) 'category)
7146 (error "No category at point")))))
7148 (defun org-find-top-category (&optional pos)
7149 (save-excursion
7150 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7151 (if pos (goto-char pos))
7152 ;; Skip up to the topmost parent
7153 (while (ignore-errors (outline-up-heading 1) t))
7154 (ignore-errors
7155 (nth 4 (org-heading-components))))))
7157 (defvar org-agenda-filtered-by-top-category nil)
7159 (defun org-agenda-filter-by-top-category (strip)
7160 "Keep only those lines in the agenda buffer that have a specific category.
7161 The category is that of the current line."
7162 (interactive "P")
7163 (if org-agenda-filtered-by-top-category
7164 (progn
7165 (setq org-agenda-filtered-by-top-category nil
7166 org-agenda-top-category-filter nil)
7167 (org-agenda-filter-show-all-cat))
7168 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7169 (if cat (org-agenda-filter-top-category-apply cat strip)
7170 (error "No top-level category at point")))))
7172 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7173 "Keep only those lines in the agenda buffer that have a specific tag.
7174 The tag is selected with its fast selection letter, as configured.
7175 With prefix argument STRIP, remove all lines that do have the tag.
7176 A lisp caller can specify CHAR. NARROW means that the new tag should be
7177 used to narrow the search - the interactive user can also press `-' or `+'
7178 to switch to narrowing."
7179 (interactive "P")
7180 (let* ((alist org-tag-alist-for-agenda)
7181 (tag-chars (mapconcat
7182 (lambda (x) (if (and (not (symbolp (car x)))
7183 (cdr x))
7184 (char-to-string (cdr x))
7185 ""))
7186 alist ""))
7187 (efforts (org-split-string
7188 (or (cdr (assoc (concat org-effort-property "_ALL")
7189 org-global-properties))
7190 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7191 "")))
7192 (effort-op org-agenda-filter-effort-default-operator)
7193 (effort-prompt "")
7194 (inhibit-read-only t)
7195 (current org-agenda-tag-filter)
7196 maybe-refresh a n tag)
7197 (unless char
7198 (message
7199 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7200 (if narrow "Narrow" "Filter") tag-chars
7201 (if org-agenda-auto-exclude-function "[RET], " ""))
7202 (setq char (read-char-exclusive)))
7203 (when (member char '(?+ ?-))
7204 ;; Narrowing down
7205 (cond ((equal char ?-) (setq strip t narrow t))
7206 ((equal char ?+) (setq strip nil narrow t)))
7207 (message
7208 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7209 (setq char (read-char-exclusive)))
7210 (when (member char '(?< ?> ?= ??))
7211 ;; An effort operator
7212 (setq effort-op (char-to-string char))
7213 (setq alist nil) ; to make sure it will be interpreted as effort.
7214 (unless (equal char ??)
7215 (loop for i from 0 to 9 do
7216 (setq effort-prompt
7217 (concat
7218 effort-prompt " ["
7219 (if (= i 9) "0" (int-to-string (1+ i)))
7220 "]" (nth i efforts))))
7221 (message "Effort%s: %s " effort-op effort-prompt)
7222 (setq char (read-char-exclusive))
7223 (when (or (< char ?0) (> char ?9))
7224 (error "Need 1-9,0 to select effort"))))
7225 (when (equal char ?\t)
7226 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7227 (org-set-local 'org-global-tags-completion-table
7228 (org-global-tags-completion-table)))
7229 (let ((completion-ignore-case t))
7230 (setq tag (org-icompleting-read
7231 "Tag: " org-global-tags-completion-table))))
7232 (cond
7233 ((equal char ?\r)
7234 (org-agenda-filter-show-all-tag)
7235 (when org-agenda-auto-exclude-function
7236 (setq org-agenda-tag-filter '())
7237 (dolist (tag (org-agenda-get-represented-tags))
7238 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7239 (if modifier
7240 (push modifier org-agenda-tag-filter))))
7241 (if (not (null org-agenda-tag-filter))
7242 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7243 (setq maybe-refresh t))
7244 ((equal char ?/)
7245 (org-agenda-filter-show-all-tag)
7246 (when (get 'org-agenda-tag-filter :preset-filter)
7247 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7248 (setq maybe-refresh t))
7249 ((equal char ?. )
7250 (setq org-agenda-tag-filter
7251 (mapcar (lambda(tag) (concat "+" tag))
7252 (org-get-at-bol 'tags)))
7253 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7254 (setq maybe-refresh t))
7255 ((or (equal char ?\ )
7256 (setq a (rassoc char alist))
7257 (and (>= char ?0) (<= char ?9)
7258 (setq n (if (= char ?0) 9 (- char ?0 1))
7259 tag (concat effort-op (nth n efforts))
7260 a (cons tag nil)))
7261 (and (= char ??)
7262 (setq tag "?eff")
7263 a (cons tag nil))
7264 (and tag (setq a (cons tag nil))))
7265 (org-agenda-filter-show-all-tag)
7266 (setq tag (car a))
7267 (setq org-agenda-tag-filter
7268 (cons (concat (if strip "-" "+") tag)
7269 (if narrow current nil)))
7270 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7271 (setq maybe-refresh t))
7272 (t (error "Invalid tag selection character %c" char)))
7273 (when (and maybe-refresh
7274 (eq org-agenda-clockreport-mode 'with-filter))
7275 (org-agenda-redo))))
7277 (defun org-agenda-get-represented-tags ()
7278 "Get a list of all tags currently represented in the agenda."
7279 (let (p tags)
7280 (save-excursion
7281 (goto-char (point-min))
7282 (while (setq p (next-single-property-change (point) 'tags))
7283 (goto-char p)
7284 (mapc (lambda (x) (add-to-list 'tags x))
7285 (get-text-property (point) 'tags))))
7286 tags))
7288 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7289 "Refine the current filter. See `org-agenda-filter-by-tag'."
7290 (interactive "P")
7291 (org-agenda-filter-by-tag strip char 'refine))
7293 (defun org-agenda-filter-make-matcher ()
7294 "Create the form that tests a line for agenda filter."
7295 (let (f f1)
7296 ;; first compute the tag-filter matcher
7297 (dolist (x (delete-dups
7298 (append (get 'org-agenda-tag-filter
7299 :preset-filter) org-agenda-tag-filter)))
7300 (if (member x '("-" "+"))
7301 (setq f1 (if (equal x "-") 'tags '(not tags)))
7302 (if (string-match "[<=>?]" x)
7303 (setq f1 (org-agenda-filter-effort-form x))
7304 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7305 (if (equal (string-to-char x) ?-)
7306 (setq f1 (list 'not f1))))
7307 (push f1 f))
7308 ;; then compute the category-filter matcher
7309 (dolist (x (delete-dups
7310 (append (get 'org-agenda-category-filter
7311 :preset-filter) org-agenda-category-filter)))
7312 (if (equal "-" (substring x 0 1))
7313 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7314 (setq f1 (list 'equal (substring x 1) 'cat)))
7315 (push f1 f))
7316 (cons 'and (nreverse f))))
7318 (defun org-agenda-filter-effort-form (e)
7319 "Return the form to compare the effort of the current line with what E says.
7320 E looks like \"+<2:25\"."
7321 (let (op)
7322 (setq e (substring e 1))
7323 (setq op (string-to-char e) e (substring e 1))
7324 (setq op (cond ((equal op ?<) '<=)
7325 ((equal op ?>) '>=)
7326 ((equal op ??) op)
7327 (t '=)))
7328 (list 'org-agenda-compare-effort (list 'quote op)
7329 (org-duration-string-to-minutes e))))
7331 (defun org-agenda-compare-effort (op value)
7332 "Compare the effort of the current line with VALUE, using OP.
7333 If the line does not have an effort defined, return nil."
7334 (let ((eff (org-get-at-bol 'effort-minutes)))
7335 (if (equal op ??)
7336 (not eff)
7337 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7338 value))))
7340 (defun org-agenda-filter-apply (filter type)
7341 "Set FILTER as the new agenda filter and apply it."
7342 ;; Deactivate `org-agenda-entry-text-mode' when filtering
7343 (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
7344 (let (tags cat)
7345 (if (eq type 'tag)
7346 (setq org-agenda-tag-filter filter)
7347 (setq org-agenda-category-filter filter))
7348 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7349 (if (and (eq type 'category)
7350 (not (equal (substring (car filter) 0 1) "-")))
7351 ;; Only set `org-agenda-filtered-by-category' to t
7352 ;; when a unique category is used as the filter
7353 (setq org-agenda-filtered-by-category t))
7354 (org-agenda-set-mode-name)
7355 (save-excursion
7356 (goto-char (point-min))
7357 (while (not (eobp))
7358 (if (org-get-at-bol 'org-marker)
7359 (progn
7360 (setq tags (org-get-at-bol 'tags) ; used in eval
7361 cat (get-text-property (point) 'org-category))
7362 (if (not (eval org-agenda-filter-form))
7363 (org-agenda-filter-hide-line type))
7364 (beginning-of-line 2))
7365 (beginning-of-line 2))))
7366 (if (get-char-property (point) 'invisible)
7367 (ignore-errors (org-agenda-previous-line)))))
7369 (defun org-agenda-filter-top-category-apply (category &optional negative)
7370 "Set FILTER as the new agenda filter and apply it."
7371 (org-agenda-set-mode-name)
7372 (save-excursion
7373 (goto-char (point-min))
7374 (while (not (eobp))
7375 (let* ((pos (org-get-at-bol 'org-hd-marker))
7376 (topcat (and pos (org-find-top-category pos))))
7377 (if (and topcat (funcall (if negative 'identity 'not)
7378 (string= category topcat)))
7379 (org-agenda-filter-hide-line 'category)))
7380 (beginning-of-line 2)))
7381 (if (get-char-property (point) 'invisible)
7382 (org-agenda-previous-line))
7383 (setq org-agenda-top-category-filter category
7384 org-agenda-filtered-by-top-category t))
7386 (defun org-agenda-filter-hide-line (type)
7387 (let (ov)
7388 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7389 (point-at-eol)))
7390 (overlay-put ov 'invisible t)
7391 (overlay-put ov 'type type)
7392 (if (eq type 'tag)
7393 (push ov org-agenda-tag-filter-overlays)
7394 (push ov org-agenda-cat-filter-overlays))))
7396 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7397 (setq pos (or pos (point)))
7398 (save-excursion
7399 (dolist (ov (overlays-at pos))
7400 (when (and (overlay-get ov 'invisible)
7401 (eq (overlay-get ov 'type) 'tag))
7402 (goto-char pos)
7403 (if (< (overlay-start ov) (point-at-eol))
7404 (move-overlay ov (point-at-eol)
7405 (overlay-end ov)))))))
7407 (defun org-agenda-filter-show-all-tag nil
7408 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7409 (setq org-agenda-tag-filter-overlays nil
7410 org-agenda-tag-filter nil
7411 org-agenda-filter-form nil)
7412 (org-agenda-set-mode-name))
7414 (defun org-agenda-filter-show-all-cat nil
7415 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7416 (setq org-agenda-cat-filter-overlays nil
7417 org-agenda-filtered-by-category nil
7418 org-agenda-category-filter nil
7419 org-agenda-filter-form nil)
7420 (org-agenda-set-mode-name))
7422 (defun org-agenda-manipulate-query-add ()
7423 "Manipulate the query by adding a search term with positive selection.
7424 Positive selection means the term must be matched for selection of an entry."
7425 (interactive)
7426 (org-agenda-manipulate-query ?\[))
7427 (defun org-agenda-manipulate-query-subtract ()
7428 "Manipulate the query by adding a search term with negative selection.
7429 Negative selection means term must not be matched for selection of an entry."
7430 (interactive)
7431 (org-agenda-manipulate-query ?\]))
7432 (defun org-agenda-manipulate-query-add-re ()
7433 "Manipulate the query by adding a search regexp with positive selection.
7434 Positive selection means the regexp must match for selection of an entry."
7435 (interactive)
7436 (org-agenda-manipulate-query ?\{))
7437 (defun org-agenda-manipulate-query-subtract-re ()
7438 "Manipulate the query by adding a search regexp with negative selection.
7439 Negative selection means regexp must not match for selection of an entry."
7440 (interactive)
7441 (org-agenda-manipulate-query ?\}))
7442 (defun org-agenda-manipulate-query (char)
7443 (cond
7444 ((memq org-agenda-type '(timeline agenda))
7445 (let ((org-agenda-include-inactive-timestamps t))
7446 (org-agenda-redo))
7447 (message "Display now includes inactive timestamps as well"))
7448 ((eq org-agenda-type 'search)
7449 (org-add-to-string
7450 'org-agenda-query-string
7451 (if org-agenda-last-search-view-search-was-boolean
7452 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7453 (?\{ . " +{}") (?\} . " -{}"))))
7454 " "))
7455 (setq org-agenda-redo-command
7456 (list 'org-search-view
7457 (car (get-text-property (min (1- (point-max)) (point))
7458 'org-last-args))
7459 org-agenda-query-string
7460 (+ (length org-agenda-query-string)
7461 (if (member char '(?\{ ?\})) 0 1))))
7462 (set-register org-agenda-query-register org-agenda-query-string)
7463 (let ((org-agenda-overriding-arguments
7464 (cdr org-agenda-redo-command)))
7465 (org-agenda-redo)))
7466 (t (error "Cannot manipulate query for %s-type agenda buffers"
7467 org-agenda-type))))
7469 (defun org-add-to-string (var string)
7470 (set var (concat (symbol-value var) string)))
7472 (defun org-agenda-goto-date (span)
7473 "Jump to DATE in agenda."
7474 (interactive "P")
7475 (let* ((org-read-date-prefer-future
7476 (eval org-agenda-jump-prefer-future))
7477 (date (org-read-date))
7478 (org-agenda-sticky-orig org-agenda-sticky)
7479 (org-agenda-buffer-tmp-name (buffer-name))
7480 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7481 (0-arg (or current-prefix-arg (car args)))
7482 (2-arg (nth 2 args))
7483 (newcmd (list 'org-agenda-list 0-arg date
7484 (org-agenda-span-to-ndays 2-arg)))
7485 (newargs (cdr newcmd))
7486 (inhibit-read-only t)
7487 org-agenda-sticky)
7488 (if (not (org-agenda-check-type t 'agenda))
7489 (error "Not available in non-agenda blocks")
7490 (add-text-properties (point-min) (point-max)
7491 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7492 (org-agenda-redo)
7493 (setq org-agenda-sticky org-agenda-sticky-orig
7494 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7496 (defun org-agenda-goto-today ()
7497 "Go to today."
7498 (interactive)
7499 (org-agenda-check-type t 'timeline 'agenda)
7500 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7501 (curspan (nth 2 args))
7502 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7503 (cond
7504 (tdpos (goto-char tdpos))
7505 ((eq org-agenda-type 'agenda)
7506 (let* ((sd (org-agenda-compute-starting-span
7507 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7508 (org-agenda-overriding-arguments args))
7509 (setf (nth 1 org-agenda-overriding-arguments) sd)
7510 (org-agenda-redo)
7511 (org-agenda-find-same-or-today-or-agenda)))
7512 (t (error "Cannot find today")))))
7514 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7515 (goto-char
7516 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7517 (text-property-any (point-min) (point-max) 'org-today t)
7518 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7519 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7520 (org-agenda-goto-block-beginning))
7521 (point-min))))
7523 (defun org-agenda-goto-block-beginning ()
7524 "Go the agenda block beginning."
7525 (interactive)
7526 (if (not (derived-mode-p 'org-agenda-mode))
7527 (error "Cannot execute this command outside of org-agenda-mode buffers")
7528 (let (dest)
7529 (save-excursion
7530 (unless (looking-at "\\'")
7531 (forward-char))
7532 (let* ((prop 'org-agenda-structural-header)
7533 (p (previous-single-property-change (point) prop))
7534 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7535 (1- (point))) prop)))
7536 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7537 (if (not dest)
7538 (error "Cannot find the beginning of the blog")
7539 (goto-char dest)
7540 (move-beginning-of-line 1)))))
7542 (defun org-agenda-later (arg)
7543 "Go forward in time by the current span.
7544 With prefix ARG, go forward that many times the current span."
7545 (interactive "p")
7546 (org-agenda-check-type t 'agenda)
7547 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7548 (span (or (nth 2 args) org-agenda-current-span))
7549 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7550 (greg (calendar-gregorian-from-absolute sd))
7551 (cnt (org-get-at-bol 'org-day-cnt))
7552 greg2)
7553 (cond
7554 ((numberp span)
7555 (setq sd (+ (* span arg) sd)))
7556 ((eq span 'day)
7557 (setq sd (+ arg sd)))
7558 ((eq span 'week)
7559 (setq sd (+ (* 7 arg) sd)))
7560 ((eq span 'month)
7561 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7562 sd (calendar-absolute-from-gregorian greg2))
7563 (setcar greg2 (1+ (car greg2))))
7564 ((eq span 'year)
7565 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7566 sd (calendar-absolute-from-gregorian greg2))
7567 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7569 (setq sd (+ (* span arg) sd))))
7570 (let ((org-agenda-overriding-cmd
7571 ;; `cmd' may have been set by `org-agenda-run-series' which
7572 ;; uses `org-agenda-overriding-cmd' to decide whether
7573 ;; overriding is allowed for `cmd'
7574 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7575 (org-agenda-overriding-arguments
7576 (list (car args) sd span)))
7577 (org-agenda-redo)
7578 (org-agenda-find-same-or-today-or-agenda cnt))))
7580 (defun org-agenda-earlier (arg)
7581 "Go backward in time by the current span.
7582 With prefix ARG, go backward that many times the current span."
7583 (interactive "p")
7584 (org-agenda-later (- arg)))
7586 (defun org-agenda-view-mode-dispatch ()
7587 "Call one of the view mode commands."
7588 (interactive)
7589 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7590 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7591 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7592 (let ((a (read-char-exclusive)))
7593 (case a
7594 (?\ (call-interactively 'org-agenda-reset-view))
7595 (?d (call-interactively 'org-agenda-day-view))
7596 (?w (call-interactively 'org-agenda-week-view))
7597 (?m (call-interactively 'org-agenda-month-view))
7598 (?y (call-interactively 'org-agenda-year-view))
7599 (?l (call-interactively 'org-agenda-log-mode))
7600 (?L (org-agenda-log-mode '(4)))
7601 (?c (org-agenda-log-mode 'clockcheck))
7602 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7603 (?a (call-interactively 'org-agenda-archives-mode))
7604 (?A (org-agenda-archives-mode 'files))
7605 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7606 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7607 (?G (call-interactively 'org-agenda-toggle-time-grid))
7608 (?D (call-interactively 'org-agenda-toggle-diary))
7609 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7610 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7611 (org-agenda-check-type t 'timeline 'agenda)
7612 (org-agenda-redo))
7613 (message "Display now includes inactive timestamps as well"))
7614 (?q (message "Abort"))
7615 (otherwise (error "Invalid key" )))))
7617 (defun org-agenda-reset-view ()
7618 "Switch to default view for agenda."
7619 (interactive)
7620 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7621 (defun org-agenda-day-view (&optional day-of-year)
7622 "Switch to daily view for agenda.
7623 With argument DAY-OF-YEAR, switch to that day of the year."
7624 (interactive "P")
7625 (org-agenda-change-time-span 'day day-of-year))
7626 (defun org-agenda-week-view (&optional iso-week)
7627 "Switch to daily view for agenda.
7628 With argument ISO-WEEK, switch to the corresponding ISO week.
7629 If ISO-WEEK has more then 2 digits, only the last two encode the
7630 week. Any digits before this encode a year. So 200712 means
7631 week 12 of year 2007. Years in the range 1938-2037 can also be
7632 written as 2-digit years."
7633 (interactive "P")
7634 (org-agenda-change-time-span 'week iso-week))
7635 (defun org-agenda-month-view (&optional month)
7636 "Switch to monthly view for agenda.
7637 With argument MONTH, switch to that month."
7638 (interactive "P")
7639 (org-agenda-change-time-span 'month month))
7640 (defun org-agenda-year-view (&optional year)
7641 "Switch to yearly view for agenda.
7642 With argument YEAR, switch to that year.
7643 If MONTH has more then 2 digits, only the last two encode the
7644 month. Any digits before this encode a year. So 200712 means
7645 December year 2007. Years in the range 1938-2037 can also be
7646 written as 2-digit years."
7647 (interactive "P")
7648 (when year
7649 (setq year (org-small-year-to-year year)))
7650 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7651 (org-agenda-change-time-span 'year year)
7652 (error "Abort")))
7654 (defun org-agenda-change-time-span (span &optional n)
7655 "Change the agenda view to SPAN.
7656 SPAN may be `day', `week', `month', `year'."
7657 (org-agenda-check-type t 'agenda)
7658 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7659 (curspan (nth 2 args)))
7660 (if (and (not n) (equal curspan span))
7661 (error "Viewing span is already \"%s\"" span))
7662 (let* ((sd (or (org-get-at-bol 'day)
7663 (nth 1 args)
7664 org-starting-day))
7665 (sd (org-agenda-compute-starting-span sd span n))
7666 (org-agenda-overriding-cmd
7667 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7668 (org-agenda-overriding-arguments
7669 (list (car args) sd span)))
7670 (org-agenda-redo)
7671 (org-agenda-find-same-or-today-or-agenda))
7672 (org-agenda-set-mode-name)
7673 (message "Switched to %s view" span)))
7675 (defun org-agenda-compute-starting-span (sd span &optional n)
7676 "Compute starting date for agenda.
7677 SPAN may be `day', `week', `month', `year'. The return value
7678 is a cons cell with the starting date and the number of days,
7679 so that the date SD will be in that range."
7680 (let* ((greg (calendar-gregorian-from-absolute sd))
7681 (dg (nth 1 greg))
7682 (mg (car greg))
7683 (yg (nth 2 greg)))
7684 (cond
7685 ((eq span 'day)
7686 (when n
7687 (setq sd (+ (calendar-absolute-from-gregorian
7688 (list mg 1 yg))
7689 n -1))))
7690 ((eq span 'week)
7691 (let* ((nt (calendar-day-of-week
7692 (calendar-gregorian-from-absolute sd)))
7693 (d (if org-agenda-start-on-weekday
7694 (- nt org-agenda-start-on-weekday)
7697 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7698 (when n
7699 (require 'cal-iso)
7700 (when (> n 99)
7701 (setq y1 (org-small-year-to-year (/ n 100))
7702 n (mod n 100)))
7703 (setq sd
7704 (calendar-absolute-from-iso
7705 (list n 1
7706 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7707 ((eq span 'month)
7708 (let (y1)
7709 (when (and n (> n 99))
7710 (setq y1 (org-small-year-to-year (/ n 100))
7711 n (mod n 100)))
7712 (setq sd (calendar-absolute-from-gregorian
7713 (list (or n mg) 1 (or y1 yg))))))
7714 ((eq span 'year)
7715 (setq sd (calendar-absolute-from-gregorian
7716 (list 1 1 (or n yg))))))
7717 sd))
7719 (defun org-agenda-next-date-line (&optional arg)
7720 "Jump to the next line indicating a date in agenda buffer."
7721 (interactive "p")
7722 (org-agenda-check-type t 'agenda 'timeline)
7723 (beginning-of-line 1)
7724 ;; This does not work if user makes date format that starts with a blank
7725 (if (looking-at "^\\S-") (forward-char 1))
7726 (if (not (re-search-forward "^\\S-" nil t arg))
7727 (progn
7728 (backward-char 1)
7729 (error "No next date after this line in this buffer")))
7730 (goto-char (match-beginning 0)))
7732 (defun org-agenda-previous-date-line (&optional arg)
7733 "Jump to the previous line indicating a date in agenda buffer."
7734 (interactive "p")
7735 (org-agenda-check-type t 'agenda 'timeline)
7736 (beginning-of-line 1)
7737 (if (not (re-search-backward "^\\S-" nil t arg))
7738 (error "No previous date before this line in this buffer")))
7740 ;; Initialize the highlight
7741 (defvar org-hl (make-overlay 1 1))
7742 (overlay-put org-hl 'face 'highlight)
7744 (defun org-highlight (begin end &optional buffer)
7745 "Highlight a region with overlay."
7746 (move-overlay org-hl begin end (or buffer (current-buffer))))
7748 (defun org-unhighlight ()
7749 "Detach overlay INDEX."
7750 (org-detach-overlay org-hl))
7752 (defun org-unhighlight-once ()
7753 "Remove the highlight from its position, and this function from the hook."
7754 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7755 (org-unhighlight))
7757 (defvar org-agenda-pre-follow-window-conf nil)
7758 (defun org-agenda-follow-mode ()
7759 "Toggle follow mode in an agenda buffer."
7760 (interactive)
7761 (unless org-agenda-follow-mode
7762 (setq org-agenda-pre-follow-window-conf
7763 (current-window-configuration)))
7764 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7765 (unless org-agenda-follow-mode
7766 (set-window-configuration org-agenda-pre-follow-window-conf))
7767 (org-agenda-set-mode-name)
7768 (org-agenda-do-context-action)
7769 (message "Follow mode is %s"
7770 (if org-agenda-follow-mode "on" "off")))
7772 (defun org-agenda-entry-text-mode (&optional arg)
7773 "Toggle entry text mode in an agenda buffer."
7774 (interactive "P")
7775 (if (or org-agenda-tag-filter
7776 org-agenda-category-filter
7777 org-agenda-top-category-filter)
7778 (user-error "Can't show entry text in filtered views")
7779 (setq org-agenda-entry-text-mode (or (integerp arg)
7780 (not org-agenda-entry-text-mode)))
7781 (org-agenda-entry-text-hide)
7782 (and org-agenda-entry-text-mode
7783 (let ((org-agenda-entry-text-maxlines
7784 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7785 (org-agenda-entry-text-show)))
7786 (org-agenda-set-mode-name)
7787 (message "Entry text mode is %s%s"
7788 (if org-agenda-entry-text-mode "on" "off")
7789 (if (not org-agenda-entry-text-mode) ""
7790 (format " (maximum number of lines is %d)"
7791 (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
7793 (defun org-agenda-clockreport-mode (&optional with-filter)
7794 "Toggle clocktable mode in an agenda buffer.
7795 With prefix arg WITH-FILTER, make the clocktable respect the current
7796 agenda filter."
7797 (interactive "P")
7798 (org-agenda-check-type t 'agenda)
7799 (if with-filter
7800 (setq org-agenda-clockreport-mode 'with-filter)
7801 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7802 (org-agenda-set-mode-name)
7803 (org-agenda-redo)
7804 (message "Clocktable mode is %s"
7805 (if org-agenda-clockreport-mode "on" "off")))
7807 (defun org-agenda-log-mode (&optional special)
7808 "Toggle log mode in an agenda buffer.
7809 With argument SPECIAL, show all possible log items, not only the ones
7810 configured in `org-agenda-log-mode-items'.
7811 With a double `C-u' prefix arg, show *only* log items, nothing else."
7812 (interactive "P")
7813 (org-agenda-check-type t 'agenda 'timeline)
7814 (setq org-agenda-show-log
7815 (cond
7816 ((equal special '(16)) 'only)
7817 ((eq special 'clockcheck)
7818 (if (eq org-agenda-show-log 'clockcheck)
7819 nil 'clockcheck))
7820 (special '(closed clock state))
7821 (t (not org-agenda-show-log))))
7822 (org-agenda-set-mode-name)
7823 (org-agenda-redo)
7824 (message "Log mode is %s"
7825 (if org-agenda-show-log "on" "off")))
7827 (defun org-agenda-archives-mode (&optional with-files)
7828 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7829 When called with a prefix argument, include all archive files as well."
7830 (interactive "P")
7831 (setq org-agenda-archives-mode
7832 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7833 (org-agenda-set-mode-name)
7834 (org-agenda-redo)
7835 (message
7836 "%s"
7837 (cond
7838 ((eq org-agenda-archives-mode nil)
7839 "No archives are included")
7840 ((eq org-agenda-archives-mode 'trees)
7841 (format "Trees with :%s: tag are included" org-archive-tag))
7842 ((eq org-agenda-archives-mode t)
7843 (format "Trees with :%s: tag and all active archive files are included"
7844 org-archive-tag)))))
7846 (defun org-agenda-toggle-diary ()
7847 "Toggle diary inclusion in an agenda buffer."
7848 (interactive)
7849 (org-agenda-check-type t 'agenda)
7850 (setq org-agenda-include-diary (not org-agenda-include-diary))
7851 (org-agenda-redo)
7852 (org-agenda-set-mode-name)
7853 (message "Diary inclusion turned %s"
7854 (if org-agenda-include-diary "on" "off")))
7856 (defun org-agenda-toggle-deadlines ()
7857 "Toggle inclusion of entries with a deadline in an agenda buffer."
7858 (interactive)
7859 (org-agenda-check-type t 'agenda)
7860 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7861 (org-agenda-redo)
7862 (org-agenda-set-mode-name)
7863 (message "Deadlines inclusion turned %s"
7864 (if org-agenda-include-deadlines "on" "off")))
7866 (defun org-agenda-toggle-time-grid ()
7867 "Toggle time grid in an agenda buffer."
7868 (interactive)
7869 (org-agenda-check-type t 'agenda)
7870 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7871 (org-agenda-redo)
7872 (org-agenda-set-mode-name)
7873 (message "Time-grid turned %s"
7874 (if org-agenda-use-time-grid "on" "off")))
7876 (defun org-agenda-set-mode-name ()
7877 "Set the mode name to indicate all the small mode settings."
7878 (setq mode-name
7879 (list "Org-Agenda"
7880 (if (get 'org-agenda-files 'org-restrict) " []" "")
7882 '(:eval (org-agenda-span-name org-agenda-current-span))
7883 (if org-agenda-follow-mode " Follow" "")
7884 (if org-agenda-entry-text-mode " ETxt" "")
7885 (if org-agenda-include-diary " Diary" "")
7886 (if org-agenda-include-deadlines " Ddl" "")
7887 (if org-agenda-use-time-grid " Grid" "")
7888 (if (and (boundp 'org-habit-show-habits)
7889 org-habit-show-habits) " Habit" "")
7890 (cond
7891 ((consp org-agenda-show-log) " LogAll")
7892 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7893 (org-agenda-show-log " Log")
7894 (t ""))
7895 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7896 :preset-filter))
7897 '(:eval (org-propertize
7898 (concat " <"
7899 (mapconcat
7900 'identity
7901 (append
7902 (get 'org-agenda-category-filter :preset-filter)
7903 org-agenda-category-filter)
7905 ">")
7906 'face 'org-agenda-filter-category
7907 'help-echo "Category used in filtering"))
7909 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7910 :preset-filter))
7911 '(:eval (org-propertize
7912 (concat " {"
7913 (mapconcat
7914 'identity
7915 (append
7916 (get 'org-agenda-tag-filter :preset-filter)
7917 org-agenda-tag-filter)
7919 "}")
7920 'face 'org-agenda-filter-tags
7921 'help-echo "Tags used in filtering"))
7923 (if org-agenda-archives-mode
7924 (if (eq org-agenda-archives-mode t)
7925 " Archives"
7926 (format " :%s:" org-archive-tag))
7928 (if org-agenda-clockreport-mode
7929 (if (eq org-agenda-clockreport-mode 'with-filter)
7930 " Clock{}" " Clock")
7931 "")))
7932 (force-mode-line-update))
7934 (define-obsolete-function-alias
7935 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7937 (defun org-agenda-update-agenda-type ()
7938 "Update the agenda type after each command."
7939 (setq org-agenda-type
7940 (or (get-text-property (point) 'org-agenda-type)
7941 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7943 (defun org-agenda-next-line ()
7944 "Move cursor to the next line, and show if follow mode is active."
7945 (interactive)
7946 (call-interactively 'next-line)
7947 (org-agenda-do-context-action))
7949 (defun org-agenda-previous-line ()
7950 "Move cursor to the previous line, and show if follow-mode is active."
7951 (interactive)
7952 (call-interactively 'previous-line)
7953 (org-agenda-do-context-action))
7955 (defun org-agenda-next-item (n)
7956 "Move cursor to next agenda item."
7957 (interactive "p")
7958 (let ((col (current-column)))
7959 (dotimes (c n)
7960 (when (next-single-property-change (point-at-eol) 'org-marker)
7961 (move-end-of-line 1)
7962 (goto-char (next-single-property-change (point) 'org-marker))))
7963 (org-move-to-column col))
7964 (org-agenda-do-context-action))
7966 (defun org-agenda-previous-item (n)
7967 "Move cursor to next agenda item."
7968 (interactive "p")
7969 (dotimes (c n)
7970 (let ((col (current-column))
7971 (goto (save-excursion
7972 (move-end-of-line 0)
7973 (previous-single-property-change (point) 'org-marker))))
7974 (if goto (goto-char goto))
7975 (org-move-to-column col)))
7976 (org-agenda-do-context-action))
7978 (defun org-agenda-do-context-action ()
7979 "Show outline path and, maybe, follow mode window."
7980 (let ((m (org-get-at-bol 'org-marker)))
7981 (when (and (markerp m) (marker-buffer m))
7982 (and org-agenda-follow-mode
7983 (if org-agenda-follow-indirect
7984 (org-agenda-tree-to-indirect-buffer nil)
7985 (org-agenda-show)))
7986 (and org-agenda-show-outline-path
7987 (org-with-point-at m (org-display-outline-path t))))))
7989 (defun org-agenda-show-tags ()
7990 "Show the tags applicable to the current item."
7991 (interactive)
7992 (let* ((tags (org-get-at-bol 'tags)))
7993 (if tags
7994 (message "Tags are :%s:"
7995 (org-no-properties (mapconcat 'identity tags ":")))
7996 (message "No tags associated with this line"))))
7998 (defun org-agenda-goto (&optional highlight)
7999 "Go to the Org-mode file which contains the item at point."
8000 (interactive)
8001 (let* ((marker (or (org-get-at-bol 'org-marker)
8002 (org-agenda-error)))
8003 (buffer (marker-buffer marker))
8004 (pos (marker-position marker)))
8005 (switch-to-buffer-other-window buffer)
8006 (widen)
8007 (push-mark)
8008 (goto-char pos)
8009 (when (derived-mode-p 'org-mode)
8010 (org-show-context 'agenda)
8011 (save-excursion
8012 (and (outline-next-heading)
8013 (org-flag-heading nil)))) ; show the next heading
8014 (when (outline-invisible-p)
8015 (show-entry)) ; display invisible text
8016 (recenter (/ (window-height) 2))
8017 (run-hooks 'org-agenda-after-show-hook)
8018 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8020 (defvar org-agenda-after-show-hook nil
8021 "Normal hook run after an item has been shown from the agenda.
8022 Point is in the buffer where the item originated.")
8024 (defun org-agenda-kill ()
8025 "Kill the entry or subtree belonging to the current agenda entry."
8026 (interactive)
8027 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8028 (let* ((bufname-orig (buffer-name))
8029 (marker (or (org-get-at-bol 'org-marker)
8030 (org-agenda-error)))
8031 (buffer (marker-buffer marker))
8032 (pos (marker-position marker))
8033 (type (org-get-at-bol 'type))
8034 dbeg dend (n 0) conf)
8035 (org-with-remote-undo buffer
8036 (with-current-buffer buffer
8037 (save-excursion
8038 (goto-char pos)
8039 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8040 (setq dbeg (progn (org-back-to-heading t) (point))
8041 dend (org-end-of-subtree t t))
8042 (setq dbeg (point-at-bol)
8043 dend (min (point-max) (1+ (point-at-eol)))))
8044 (goto-char dbeg)
8045 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8046 (setq conf (or (eq t org-agenda-confirm-kill)
8047 (and (numberp org-agenda-confirm-kill)
8048 (> n org-agenda-confirm-kill))))
8049 (and conf
8050 (not (y-or-n-p
8051 (format "Delete entry with %d lines in buffer \"%s\"? "
8052 n (buffer-name buffer))))
8053 (error "Abort"))
8054 (let ((org-agenda-buffer-name bufname-orig))
8055 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8056 (with-current-buffer buffer (delete-region dbeg dend))
8057 (message "Agenda item and source killed"))))
8059 (defvar org-archive-default-command) ; defined in org-archive.el
8060 (defun org-agenda-archive-default ()
8061 "Archive the entry or subtree belonging to the current agenda entry."
8062 (interactive)
8063 (require 'org-archive)
8064 (org-agenda-archive-with org-archive-default-command))
8066 (defun org-agenda-archive-default-with-confirmation ()
8067 "Archive the entry or subtree belonging to the current agenda entry."
8068 (interactive)
8069 (require 'org-archive)
8070 (org-agenda-archive-with org-archive-default-command 'confirm))
8072 (defun org-agenda-archive ()
8073 "Archive the entry or subtree belonging to the current agenda entry."
8074 (interactive)
8075 (org-agenda-archive-with 'org-archive-subtree))
8077 (defun org-agenda-archive-to-archive-sibling ()
8078 "Move the entry to the archive sibling."
8079 (interactive)
8080 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8082 (defun org-agenda-archive-with (cmd &optional confirm)
8083 "Move the entry to the archive sibling."
8084 (interactive)
8085 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8086 (let* ((bufname-orig (buffer-name))
8087 (marker (or (org-get-at-bol 'org-marker)
8088 (org-agenda-error)))
8089 (buffer (marker-buffer marker))
8090 (pos (marker-position marker)))
8091 (org-with-remote-undo buffer
8092 (with-current-buffer buffer
8093 (if (derived-mode-p 'org-mode)
8094 (if (and confirm
8095 (not (y-or-n-p "Archive this subtree or entry? ")))
8096 (error "Abort")
8097 (save-excursion
8098 (goto-char pos)
8099 (let ((org-agenda-buffer-name bufname-orig))
8100 (org-remove-subtree-entries-from-agenda))
8101 (org-back-to-heading t)
8102 (funcall cmd)))
8103 (error "Archiving works only in Org-mode files"))))))
8105 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8106 "Remove all lines in the agenda that correspond to a given subtree.
8107 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8108 If this information is not given, the function uses the tree at point."
8109 (let ((buf (or buf (current-buffer))) m p)
8110 (save-excursion
8111 (unless (and beg end)
8112 (org-back-to-heading t)
8113 (setq beg (point))
8114 (org-end-of-subtree t)
8115 (setq end (point)))
8116 (set-buffer (get-buffer org-agenda-buffer-name))
8117 (save-excursion
8118 (goto-char (point-max))
8119 (beginning-of-line 1)
8120 (while (not (bobp))
8121 (when (and (setq m (org-get-at-bol 'org-marker))
8122 (equal buf (marker-buffer m))
8123 (setq p (marker-position m))
8124 (>= p beg)
8125 (< p end))
8126 (let ((inhibit-read-only t))
8127 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8128 (beginning-of-line 0))))))
8130 (defun org-agenda-refile (&optional goto rfloc no-update)
8131 "Refile the item at point."
8132 (interactive "P")
8133 (if (equal goto '(16))
8134 (org-refile-goto-last-stored)
8135 (let* ((buffer-orig (buffer-name))
8136 (marker (or (org-get-at-bol 'org-hd-marker)
8137 (org-agenda-error)))
8138 (buffer (marker-buffer marker))
8139 (pos (marker-position marker))
8140 (rfloc (or rfloc
8141 (org-refile-get-location
8142 (if goto "Goto" "Refile to") buffer
8143 org-refile-allow-creating-parent-nodes))))
8144 (with-current-buffer buffer
8145 (save-excursion
8146 (save-restriction
8147 (widen)
8148 (goto-char marker)
8149 (let ((org-agenda-buffer-name buffer-orig))
8150 (org-remove-subtree-entries-from-agenda))
8151 (org-refile goto buffer rfloc)))))
8152 (unless no-update (org-agenda-redo))))
8154 (defun org-agenda-open-link (&optional arg)
8155 "Open the link(s) in the current entry, if any.
8156 This looks for a link in the displayed line in the agenda.
8157 It also looks at the text of the entry itself."
8158 (interactive "P")
8159 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8160 (org-get-at-bol 'org-marker)))
8161 (buffer (and marker (marker-buffer marker)))
8162 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8163 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8164 (lk0 (car lkall))
8165 (lk (if (stringp lk0) (list lk0) lk0))
8166 (lkend (cdr lkall))
8167 trg)
8168 (cond
8169 ((and buffer lk)
8170 (mapcar (lambda(l)
8171 (with-current-buffer buffer
8172 (setq trg (and (string-match org-bracket-link-regexp l)
8173 (match-string 1 l)))
8174 (if (or (not trg) (string-match org-any-link-re trg))
8175 (save-excursion
8176 (save-restriction
8177 (widen)
8178 (goto-char marker)
8179 (when (search-forward l nil lkend)
8180 (goto-char (match-beginning 0))
8181 (org-open-at-point))))
8182 ;; This is an internal link, widen the buffer
8183 (switch-to-buffer-other-window buffer)
8184 (widen)
8185 (goto-char marker)
8186 (when (search-forward l nil lkend)
8187 (goto-char (match-beginning 0))
8188 (org-open-at-point)))))
8189 lk))
8190 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8191 (save-excursion
8192 (beginning-of-line 1)
8193 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8194 (org-open-link-from-string (match-string 1)))
8195 (t (message "No link to open here")))))
8197 (defun org-agenda-copy-local-variable (var)
8198 "Get a variable from a referenced buffer and install it here."
8199 (let ((m (org-get-at-bol 'org-marker)))
8200 (when (and m (buffer-live-p (marker-buffer m)))
8201 (org-set-local var (with-current-buffer (marker-buffer m)
8202 (symbol-value var))))))
8204 (defun org-agenda-switch-to (&optional delete-other-windows)
8205 "Go to the Org-mode file which contains the item at point."
8206 (interactive)
8207 (if (and org-return-follows-link
8208 (not (org-get-at-bol 'org-marker))
8209 (org-in-regexp org-bracket-link-regexp))
8210 (org-open-link-from-string (match-string 0))
8211 (let* ((marker (or (org-get-at-bol 'org-marker)
8212 (org-agenda-error)))
8213 (buffer (marker-buffer marker))
8214 (pos (marker-position marker)))
8215 (org-pop-to-buffer-same-window buffer)
8216 (and delete-other-windows (delete-other-windows))
8217 (widen)
8218 (goto-char pos)
8219 (when (derived-mode-p 'org-mode)
8220 (org-show-context 'agenda)
8221 (save-excursion
8222 (and (outline-next-heading)
8223 (org-flag-heading nil))) ; show the next heading
8224 (when (outline-invisible-p)
8225 (show-entry)) ; display invisible text
8226 (run-hooks 'org-agenda-after-show-hook)))))
8228 (defun org-agenda-goto-mouse (ev)
8229 "Go to the Org-mode file which contains the item at the mouse click."
8230 (interactive "e")
8231 (mouse-set-point ev)
8232 (org-agenda-goto))
8234 (defun org-agenda-show (&optional full-entry)
8235 "Display the Org-mode file which contains the item at point.
8236 With prefix argument FULL-ENTRY, make the entire entry visible
8237 if it was hidden in the outline."
8238 (interactive "P")
8239 (let ((win (selected-window)))
8240 (if full-entry
8241 (let ((org-show-entry-below t))
8242 (org-agenda-goto t))
8243 (org-agenda-goto t))
8244 (select-window win)))
8246 (defvar org-agenda-show-window nil)
8247 (defun org-agenda-show-and-scroll-up (&optional arg)
8248 "Display the Org-mode file which contains the item at point.
8249 When called repeatedly, scroll the window that is displaying the buffer.
8250 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8251 `show-subtree' to display the item, so that drawers and logbooks stay
8252 folded."
8253 (interactive "P")
8254 (let ((win (selected-window)))
8255 (if (and (window-live-p org-agenda-show-window)
8256 (eq this-command last-command))
8257 (progn
8258 (select-window org-agenda-show-window)
8259 (ignore-errors (scroll-up)))
8260 (org-agenda-goto t)
8261 (if arg (org-show-entry) (show-subtree))
8262 (setq org-agenda-show-window (selected-window)))
8263 (select-window win)))
8265 (defun org-agenda-show-scroll-down ()
8266 "Scroll down the window showing the agenda."
8267 (interactive)
8268 (let ((win (selected-window)))
8269 (when (window-live-p org-agenda-show-window)
8270 (select-window org-agenda-show-window)
8271 (ignore-errors (scroll-down))
8272 (select-window win))))
8274 (defun org-agenda-show-1 (&optional more)
8275 "Display the Org-mode file which contains the item at point.
8276 The prefix arg selects the amount of information to display:
8278 0 hide the subtree
8279 1 just show the entry according to defaults.
8280 2 show the children view
8281 3 show the subtree view
8282 4 show the entire subtree and any LOGBOOK drawers
8283 5 show the entire subtree and any drawers
8284 With prefix argument FULL-ENTRY, make the entire entry visible
8285 if it was hidden in the outline."
8286 (interactive "p")
8287 (let ((win (selected-window)))
8288 (org-agenda-goto t)
8289 (org-recenter-heading 1)
8290 (cond
8291 ((= more 0)
8292 (hide-subtree)
8293 (save-excursion
8294 (org-back-to-heading)
8295 (run-hook-with-args 'org-cycle-hook 'folded))
8296 (message "Remote: FOLDED"))
8297 ((and (org-called-interactively-p 'any) (= more 1))
8298 (message "Remote: show with default settings"))
8299 ((= more 2)
8300 (show-entry)
8301 (show-children)
8302 (save-excursion
8303 (org-back-to-heading)
8304 (run-hook-with-args 'org-cycle-hook 'children))
8305 (message "Remote: CHILDREN"))
8306 ((= more 3)
8307 (show-subtree)
8308 (save-excursion
8309 (org-back-to-heading)
8310 (run-hook-with-args 'org-cycle-hook 'subtree))
8311 (message "Remote: SUBTREE"))
8312 ((= more 4)
8313 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8314 (org-drawer-regexp
8315 (concat "^[ \t]*:\\("
8316 (mapconcat 'regexp-quote org-drawers "\\|")
8317 "\\):[ \t]*$")))
8318 (show-subtree)
8319 (save-excursion
8320 (org-back-to-heading)
8321 (org-cycle-hide-drawers 'subtree)))
8322 (message "Remote: SUBTREE AND LOGBOOK"))
8323 ((> more 4)
8324 (show-subtree)
8325 (message "Remote: SUBTREE AND ALL DRAWERS")))
8326 (select-window win)))
8328 (defun org-recenter-heading (n)
8329 (save-excursion
8330 (org-back-to-heading)
8331 (recenter n)))
8333 (defvar org-agenda-cycle-counter nil)
8334 (defun org-agenda-cycle-show (&optional n)
8335 "Show the current entry in another window, with default settings.
8336 Default settings are taken from `org-show-hierarchy-above' and siblings.
8337 When use repeatedly in immediate succession, the remote entry will cycle
8338 through visibility
8340 children -> subtree -> folded
8342 When called with a numeric prefix arg, that arg will be passed through to
8343 `org-agenda-show-1'. For the interpretation of that argument, see the
8344 docstring of `org-agenda-show-1'."
8345 (interactive "P")
8346 (if (integerp n)
8347 (setq org-agenda-cycle-counter n)
8348 (if (not (eq last-command this-command))
8349 (setq org-agenda-cycle-counter 1)
8350 (if (equal org-agenda-cycle-counter 0)
8351 (setq org-agenda-cycle-counter 2)
8352 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8353 (if (> org-agenda-cycle-counter 3)
8354 (setq org-agenda-cycle-counter 0)))))
8355 (org-agenda-show-1 org-agenda-cycle-counter))
8357 (defun org-agenda-recenter (arg)
8358 "Display the Org-mode file which contains the item at point and recenter."
8359 (interactive "P")
8360 (let ((win (selected-window)))
8361 (org-agenda-goto t)
8362 (recenter arg)
8363 (select-window win)))
8365 (defun org-agenda-show-mouse (ev)
8366 "Display the Org-mode file which contains the item at the mouse click."
8367 (interactive "e")
8368 (mouse-set-point ev)
8369 (org-agenda-show))
8371 (defun org-agenda-check-no-diary ()
8372 "Check if the entry is a diary link and abort if yes."
8373 (if (org-get-at-bol 'org-agenda-diary-link)
8374 (org-agenda-error)))
8376 (defun org-agenda-error ()
8377 (error "Command not allowed in this line"))
8379 (defun org-agenda-tree-to-indirect-buffer (arg)
8380 "Show the subtree corresponding to the current entry in an indirect buffer.
8381 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8383 With a numerical prefix ARG, go up to this level and then take that tree.
8384 With a negative numeric ARG, go up by this number of levels.
8385 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8386 use the dedicated frame)."
8387 (interactive "P")
8388 (if current-prefix-arg
8389 (org-agenda-do-tree-to-indirect-buffer arg)
8390 (let ((agenda-buffer (buffer-name))
8391 (agenda-window (selected-window))
8392 (indirect-window
8393 (and org-last-indirect-buffer
8394 (get-buffer-window org-last-indirect-buffer))))
8395 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8396 (unless (or (eq org-indirect-buffer-display 'new-frame)
8397 (eq org-indirect-buffer-display 'dedicated-frame))
8398 (unwind-protect
8399 (unless (and indirect-window (window-live-p indirect-window))
8400 (setq indirect-window (split-window agenda-window)))
8401 (and indirect-window (select-window indirect-window))
8402 (switch-to-buffer org-last-indirect-buffer :norecord)
8403 (fit-window-to-buffer indirect-window)))
8404 (select-window (get-buffer-window agenda-buffer)))))
8406 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8407 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8408 (org-agenda-check-no-diary)
8409 (let* ((marker (or (org-get-at-bol 'org-marker)
8410 (org-agenda-error)))
8411 (buffer (marker-buffer marker))
8412 (pos (marker-position marker)))
8413 (with-current-buffer buffer
8414 (save-excursion
8415 (goto-char pos)
8416 (funcall 'org-tree-to-indirect-buffer arg)))))
8418 (defvar org-last-heading-marker (make-marker)
8419 "Marker pointing to the headline that last changed its TODO state
8420 by a remote command from the agenda.")
8422 (defun org-agenda-todo-nextset ()
8423 "Switch TODO entry to next sequence."
8424 (interactive)
8425 (org-agenda-todo 'nextset))
8427 (defun org-agenda-todo-previousset ()
8428 "Switch TODO entry to previous sequence."
8429 (interactive)
8430 (org-agenda-todo 'previousset))
8432 (defun org-agenda-todo (&optional arg)
8433 "Cycle TODO state of line at point, also in Org-mode file.
8434 This changes the line at point, all other lines in the agenda referring to
8435 the same tree node, and the headline of the tree node in the Org-mode file."
8436 (interactive "P")
8437 (org-agenda-check-no-diary)
8438 (let* ((col (current-column))
8439 (marker (or (org-get-at-bol 'org-marker)
8440 (org-agenda-error)))
8441 (buffer (marker-buffer marker))
8442 (pos (marker-position marker))
8443 (hdmarker (org-get-at-bol 'org-hd-marker))
8444 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8445 (inhibit-read-only t)
8446 org-agenda-headline-snapshot-before-repeat newhead just-one)
8447 (org-with-remote-undo buffer
8448 (with-current-buffer buffer
8449 (widen)
8450 (goto-char pos)
8451 (org-show-context 'agenda)
8452 (save-excursion
8453 (and (outline-next-heading)
8454 (org-flag-heading nil))) ; show the next heading
8455 (let ((current-prefix-arg arg))
8456 (call-interactively 'org-todo))
8457 (and (bolp) (forward-char 1))
8458 (setq newhead (org-get-heading))
8459 (when (and (org-bound-and-true-p
8460 org-agenda-headline-snapshot-before-repeat)
8461 (not (equal org-agenda-headline-snapshot-before-repeat
8462 newhead))
8463 todayp)
8464 (setq newhead org-agenda-headline-snapshot-before-repeat
8465 just-one t))
8466 (save-excursion
8467 (org-back-to-heading)
8468 (move-marker org-last-heading-marker (point))))
8469 (beginning-of-line 1)
8470 (save-excursion
8471 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8472 (org-move-to-column col))))
8474 (defun org-agenda-add-note (&optional arg)
8475 "Add a time-stamped note to the entry at point."
8476 (interactive "P")
8477 (org-agenda-check-no-diary)
8478 (let* ((marker (or (org-get-at-bol 'org-marker)
8479 (org-agenda-error)))
8480 (buffer (marker-buffer marker))
8481 (pos (marker-position marker))
8482 (hdmarker (org-get-at-bol 'org-hd-marker))
8483 (inhibit-read-only t))
8484 (with-current-buffer buffer
8485 (widen)
8486 (goto-char pos)
8487 (org-show-context 'agenda)
8488 (save-excursion
8489 (and (outline-next-heading)
8490 (org-flag-heading nil))) ; show the next heading
8491 (org-add-note))))
8493 (defun org-agenda-change-all-lines (newhead hdmarker
8494 &optional fixface just-this)
8495 "Change all lines in the agenda buffer which match HDMARKER.
8496 The new content of the line will be NEWHEAD (as modified by
8497 `org-agenda-format-item'). HDMARKER is checked with
8498 `equal' against all `org-hd-marker' text properties in the file.
8499 If FIXFACE is non-nil, the face of each item is modified according to
8500 the new TODO state.
8501 If JUST-THIS is non-nil, change just the current line, not all.
8502 If FORCE-TAGS is non nil, the car of it returns the new tags."
8503 (let* ((inhibit-read-only t)
8504 (line (org-current-line))
8505 (org-agenda-buffer (current-buffer))
8506 (thetags (with-current-buffer (marker-buffer hdmarker)
8507 (save-excursion (save-restriction (widen)
8508 (goto-char hdmarker)
8509 (org-get-tags-at)))))
8510 props m pl undone-face done-face finish new dotime level cat tags)
8511 (save-excursion
8512 (goto-char (point-max))
8513 (beginning-of-line 1)
8514 (while (not finish)
8515 (setq finish (bobp))
8516 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8517 (or (not just-this) (= (org-current-line) line))
8518 (equal m hdmarker))
8519 (setq props (text-properties-at (point))
8520 dotime (org-get-at-bol 'dotime)
8521 cat (org-get-at-bol 'org-category)
8522 level (org-get-at-bol 'level)
8523 tags thetags
8525 (let ((org-prefix-format-compiled
8526 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8527 org-prefix-format-compiled))
8528 (extra (org-get-at-bol 'extra)))
8529 (with-current-buffer (marker-buffer hdmarker)
8530 (save-excursion
8531 (save-restriction
8532 (widen)
8533 (org-agenda-format-item extra newhead level cat tags dotime)))))
8534 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8535 undone-face (org-get-at-bol 'undone-face)
8536 done-face (org-get-at-bol 'done-face))
8537 (beginning-of-line 1)
8538 (cond
8539 ((equal new "")
8540 (and (looking-at ".*\n?") (replace-match "")))
8541 ((looking-at ".*")
8542 (replace-match new t t)
8543 (beginning-of-line 1)
8544 (add-text-properties (point-at-bol) (point-at-eol) props)
8545 (when fixface
8546 (add-text-properties
8547 (point-at-bol) (point-at-eol)
8548 (list 'face
8549 (if org-last-todo-state-is-todo
8550 undone-face done-face))))
8551 (org-agenda-highlight-todo 'line)
8552 (beginning-of-line 1))
8553 (t (error "Line update did not work")))
8554 (save-restriction
8555 (narrow-to-region (point-at-bol) (point-at-eol))
8556 (org-agenda-finalize)))
8557 (beginning-of-line 0)))))
8559 (defun org-agenda-align-tags (&optional line)
8560 "Align all tags in agenda items to `org-agenda-tags-column'."
8561 (let ((inhibit-read-only t) l c)
8562 (save-excursion
8563 (goto-char (if line (point-at-bol) (point-min)))
8564 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8565 (if line (point-at-eol) nil) t)
8566 (add-text-properties
8567 (match-beginning 2) (match-end 2)
8568 (list 'face (delq nil (let ((prop (get-text-property
8569 (match-beginning 2) 'face)))
8570 (or (listp prop) (setq prop (list prop)))
8571 (if (memq 'org-tag prop)
8572 prop
8573 (cons 'org-tag prop))))))
8574 (setq l (- (match-end 2) (match-beginning 2))
8575 c (if (< org-agenda-tags-column 0)
8576 (- (abs org-agenda-tags-column) l)
8577 org-agenda-tags-column))
8578 (delete-region (match-beginning 1) (match-end 1))
8579 (goto-char (match-beginning 1))
8580 (insert (org-add-props
8581 (make-string (max 1 (- c (current-column))) ?\ )
8582 (plist-put (copy-sequence (text-properties-at (point)))
8583 'face nil))))
8584 (goto-char (point-min))
8585 (org-font-lock-add-tag-faces (point-max)))))
8587 (defun org-agenda-priority-up ()
8588 "Increase the priority of line at point, also in Org-mode file."
8589 (interactive)
8590 (org-agenda-priority 'up))
8592 (defun org-agenda-priority-down ()
8593 "Decrease the priority of line at point, also in Org-mode file."
8594 (interactive)
8595 (org-agenda-priority 'down))
8597 (defun org-agenda-priority (&optional force-direction)
8598 "Set the priority of line at point, also in Org-mode file.
8599 This changes the line at point, all other lines in the agenda referring to
8600 the same tree node, and the headline of the tree node in the Org-mode file.
8601 Called with a universal prefix arg, show the priority instead of setting it."
8602 (interactive "P")
8603 (if (equal force-direction '(4))
8604 (org-show-priority)
8605 (unless org-enable-priority-commands
8606 (error "Priority commands are disabled"))
8607 (org-agenda-check-no-diary)
8608 (let* ((marker (or (org-get-at-bol 'org-marker)
8609 (org-agenda-error)))
8610 (hdmarker (org-get-at-bol 'org-hd-marker))
8611 (buffer (marker-buffer hdmarker))
8612 (pos (marker-position hdmarker))
8613 (inhibit-read-only t)
8614 newhead)
8615 (org-with-remote-undo buffer
8616 (with-current-buffer buffer
8617 (widen)
8618 (goto-char pos)
8619 (org-show-context 'agenda)
8620 (save-excursion
8621 (and (outline-next-heading)
8622 (org-flag-heading nil))) ; show the next heading
8623 (funcall 'org-priority force-direction)
8624 (end-of-line 1)
8625 (setq newhead (org-get-heading)))
8626 (org-agenda-change-all-lines newhead hdmarker)
8627 (beginning-of-line 1)))))
8629 ;; FIXME: should fix the tags property of the agenda line.
8630 (defun org-agenda-set-tags (&optional tag onoff)
8631 "Set tags for the current headline."
8632 (interactive)
8633 (org-agenda-check-no-diary)
8634 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8635 (call-interactively 'org-change-tag-in-region)
8636 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8637 (org-agenda-error)))
8638 (buffer (marker-buffer hdmarker))
8639 (pos (marker-position hdmarker))
8640 (inhibit-read-only t)
8641 newhead)
8642 (org-with-remote-undo buffer
8643 (with-current-buffer buffer
8644 (widen)
8645 (goto-char pos)
8646 (save-excursion
8647 (org-show-context 'agenda))
8648 (save-excursion
8649 (and (outline-next-heading)
8650 (org-flag-heading nil))) ; show the next heading
8651 (goto-char pos)
8652 (if tag
8653 (org-toggle-tag tag onoff)
8654 (call-interactively 'org-set-tags))
8655 (end-of-line 1)
8656 (setq newhead (org-get-heading)))
8657 (org-agenda-change-all-lines newhead hdmarker)
8658 (beginning-of-line 1)))))
8660 (defun org-agenda-set-property ()
8661 "Set a property for the current headline."
8662 (interactive)
8663 (org-agenda-check-no-diary)
8664 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8665 (org-agenda-error)))
8666 (buffer (marker-buffer hdmarker))
8667 (pos (marker-position hdmarker))
8668 (inhibit-read-only t)
8669 newhead)
8670 (org-with-remote-undo buffer
8671 (with-current-buffer buffer
8672 (widen)
8673 (goto-char pos)
8674 (save-excursion
8675 (org-show-context 'agenda))
8676 (save-excursion
8677 (and (outline-next-heading)
8678 (org-flag-heading nil))) ; show the next heading
8679 (goto-char pos)
8680 (call-interactively 'org-set-property)))))
8682 (defun org-agenda-set-effort ()
8683 "Set the effort property for the current headline."
8684 (interactive)
8685 (org-agenda-check-no-diary)
8686 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8687 (org-agenda-error)))
8688 (buffer (marker-buffer hdmarker))
8689 (pos (marker-position hdmarker))
8690 (inhibit-read-only t)
8691 newhead)
8692 (org-with-remote-undo buffer
8693 (with-current-buffer buffer
8694 (widen)
8695 (goto-char pos)
8696 (save-excursion
8697 (org-show-context 'agenda))
8698 (save-excursion
8699 (and (outline-next-heading)
8700 (org-flag-heading nil))) ; show the next heading
8701 (goto-char pos)
8702 (call-interactively 'org-set-effort)
8703 (end-of-line 1)
8704 (setq newhead (org-get-heading)))
8705 (org-agenda-change-all-lines newhead hdmarker))))
8707 (defun org-agenda-toggle-archive-tag ()
8708 "Toggle the archive tag for the current entry."
8709 (interactive)
8710 (org-agenda-check-no-diary)
8711 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8712 (org-agenda-error)))
8713 (buffer (marker-buffer hdmarker))
8714 (pos (marker-position hdmarker))
8715 (inhibit-read-only t)
8716 newhead)
8717 (org-with-remote-undo buffer
8718 (with-current-buffer buffer
8719 (widen)
8720 (goto-char pos)
8721 (org-show-context 'agenda)
8722 (save-excursion
8723 (and (outline-next-heading)
8724 (org-flag-heading nil))) ; show the next heading
8725 (call-interactively 'org-toggle-archive-tag)
8726 (end-of-line 1)
8727 (setq newhead (org-get-heading)))
8728 (org-agenda-change-all-lines newhead hdmarker)
8729 (beginning-of-line 1))))
8731 (defun org-agenda-do-date-later (arg)
8732 (interactive "P")
8733 (cond
8734 ((or (equal arg '(16))
8735 (memq last-command
8736 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8737 (setq this-command 'org-agenda-date-later-minutes)
8738 (org-agenda-date-later-minutes 1))
8739 ((or (equal arg '(4))
8740 (memq last-command
8741 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8742 (setq this-command 'org-agenda-date-later-hours)
8743 (org-agenda-date-later-hours 1))
8745 (org-agenda-date-later (prefix-numeric-value arg)))))
8747 (defun org-agenda-do-date-earlier (arg)
8748 (interactive "P")
8749 (cond
8750 ((or (equal arg '(16))
8751 (memq last-command
8752 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8753 (setq this-command 'org-agenda-date-earlier-minutes)
8754 (org-agenda-date-earlier-minutes 1))
8755 ((or (equal arg '(4))
8756 (memq last-command
8757 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8758 (setq this-command 'org-agenda-date-earlier-hours)
8759 (org-agenda-date-earlier-hours 1))
8761 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8763 (defun org-agenda-date-later (arg &optional what)
8764 "Change the date of this item to ARG day(s) later."
8765 (interactive "p")
8766 (org-agenda-check-type t 'agenda 'timeline)
8767 (org-agenda-check-no-diary)
8768 (let* ((marker (or (org-get-at-bol 'org-marker)
8769 (org-agenda-error)))
8770 (buffer (marker-buffer marker))
8771 (pos (marker-position marker))
8772 cdate today)
8773 (org-with-remote-undo buffer
8774 (with-current-buffer buffer
8775 (widen)
8776 (goto-char pos)
8777 (if (not (org-at-timestamp-p))
8778 (error "Cannot find time stamp"))
8779 (when (and org-agenda-move-date-from-past-immediately-to-today
8780 (equal arg 1)
8781 (or (not what) (eq what 'day))
8782 (not (save-match-data (org-at-date-range-p))))
8783 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8784 cdate (calendar-absolute-from-gregorian
8785 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8786 today (org-today))
8787 (if (> today cdate)
8788 ;; immediately shift to today
8789 (setq arg (- today cdate))))
8790 (org-timestamp-change arg (or what 'day))
8791 (when (and (org-at-date-range-p)
8792 (re-search-backward org-tr-regexp-both (point-at-bol)))
8793 (let ((end org-last-changed-timestamp))
8794 (org-timestamp-change arg (or what 'day))
8795 (setq org-last-changed-timestamp
8796 (concat org-last-changed-timestamp "--" end)))))
8797 (org-agenda-show-new-time marker org-last-changed-timestamp))
8798 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8800 (defun org-agenda-date-earlier (arg &optional what)
8801 "Change the date of this item to ARG day(s) earlier."
8802 (interactive "p")
8803 (org-agenda-date-later (- arg) what))
8805 (defun org-agenda-date-later-minutes (arg)
8806 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8807 (interactive "p")
8808 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8809 (org-agenda-date-later arg 'minute))
8811 (defun org-agenda-date-earlier-minutes (arg)
8812 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8813 (interactive "p")
8814 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8815 (org-agenda-date-earlier arg 'minute))
8817 (defun org-agenda-date-later-hours (arg)
8818 "Change the time of this item, in hour steps."
8819 (interactive "p")
8820 (org-agenda-date-later arg 'hour))
8822 (defun org-agenda-date-earlier-hours (arg)
8823 "Change the time of this item, in hour steps."
8824 (interactive "p")
8825 (org-agenda-date-earlier arg 'hour))
8827 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8828 "Show new date stamp via text properties."
8829 ;; We use text properties to make this undoable
8830 (let ((inhibit-read-only t))
8831 (setq stamp (concat prefix " => " stamp " "))
8832 (save-excursion
8833 (goto-char (point-max))
8834 (while (not (bobp))
8835 (when (equal marker (org-get-at-bol 'org-marker))
8836 (org-move-to-column (- (window-width) (length stamp)) t)
8837 (org-agenda-fix-tags-filter-overlays-at (point))
8838 (if (featurep 'xemacs)
8839 ;; Use `duplicable' property to trigger undo recording
8840 (let ((ex (make-extent nil nil))
8841 (gl (make-glyph stamp)))
8842 (set-glyph-face gl 'secondary-selection)
8843 (set-extent-properties
8844 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8845 (insert-extent ex (1- (point)) (point-at-eol)))
8846 (add-text-properties
8847 (1- (point)) (point-at-eol)
8848 (list 'display (org-add-props stamp nil
8849 'face 'secondary-selection))))
8850 (beginning-of-line 1))
8851 (beginning-of-line 0)))))
8853 (defun org-agenda-date-prompt (arg)
8854 "Change the date of this item. Date is prompted for, with default today.
8855 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8856 be used to request time specification in the time stamp."
8857 (interactive "P")
8858 (org-agenda-check-type t 'agenda 'timeline)
8859 (org-agenda-check-no-diary)
8860 (let* ((marker (or (org-get-at-bol 'org-marker)
8861 (org-agenda-error)))
8862 (buffer (marker-buffer marker))
8863 (pos (marker-position marker)))
8864 (org-with-remote-undo buffer
8865 (with-current-buffer buffer
8866 (widen)
8867 (goto-char pos)
8868 (if (not (org-at-timestamp-p t))
8869 (error "Cannot find time stamp"))
8870 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8871 (org-agenda-show-new-time marker org-last-changed-timestamp))
8872 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8874 (defun org-agenda-schedule (arg &optional time)
8875 "Schedule the item at point.
8876 ARG is passed through to `org-schedule'."
8877 (interactive "P")
8878 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8879 (org-agenda-check-no-diary)
8880 (let* ((marker (or (org-get-at-bol 'org-marker)
8881 (org-agenda-error)))
8882 (type (marker-insertion-type marker))
8883 (buffer (marker-buffer marker))
8884 (pos (marker-position marker))
8885 (org-insert-labeled-timestamps-at-point nil)
8887 (set-marker-insertion-type marker t)
8888 (org-with-remote-undo buffer
8889 (with-current-buffer buffer
8890 (widen)
8891 (goto-char pos)
8892 (setq ts (org-schedule arg time)))
8893 (org-agenda-show-new-time marker ts " S"))
8894 (message "%s" ts)))
8896 (defun org-agenda-deadline (arg &optional time)
8897 "Schedule the item at point.
8898 ARG is passed through to `org-deadline'."
8899 (interactive "P")
8900 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8901 (org-agenda-check-no-diary)
8902 (let* ((marker (or (org-get-at-bol 'org-marker)
8903 (org-agenda-error)))
8904 (buffer (marker-buffer marker))
8905 (pos (marker-position marker))
8906 (org-insert-labeled-timestamps-at-point nil)
8908 (org-with-remote-undo buffer
8909 (with-current-buffer buffer
8910 (widen)
8911 (goto-char pos)
8912 (setq ts (org-deadline arg time)))
8913 (org-agenda-show-new-time marker ts " D"))
8914 (message "%s" ts)))
8916 (defun org-agenda-clock-in (&optional arg)
8917 "Start the clock on the currently selected item."
8918 (interactive "P")
8919 (org-agenda-check-no-diary)
8920 (if (equal arg '(4))
8921 (org-clock-in arg)
8922 (let* ((marker (or (org-get-at-bol 'org-marker)
8923 (org-agenda-error)))
8924 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
8925 (pos (marker-position marker))
8926 (col (current-column))
8927 newhead)
8928 (org-with-remote-undo (marker-buffer marker)
8929 (with-current-buffer (marker-buffer marker)
8930 (widen)
8931 (goto-char pos)
8932 (org-show-context 'agenda)
8933 (org-show-entry)
8934 (org-cycle-hide-drawers 'children)
8935 (org-clock-in arg)
8936 (setq newhead (org-get-heading)))
8937 (org-agenda-change-all-lines newhead hdmarker))
8938 (org-move-to-column col))))
8940 (defun org-agenda-clock-out ()
8941 "Stop the currently running clock."
8942 (interactive)
8943 (unless (marker-buffer org-clock-marker)
8944 (error "No running clock"))
8945 (let ((marker (make-marker)) (col (current-column)) newhead)
8946 (org-with-remote-undo (marker-buffer org-clock-marker)
8947 (with-current-buffer (marker-buffer org-clock-marker)
8948 (save-excursion
8949 (save-restriction
8950 (widen)
8951 (goto-char org-clock-marker)
8952 (org-back-to-heading t)
8953 (move-marker marker (point))
8954 (org-clock-out)
8955 (setq newhead (org-get-heading))))))
8956 (org-agenda-change-all-lines newhead marker)
8957 (move-marker marker nil)
8958 (org-move-to-column col)
8959 (org-agenda-unmark-clocking-task)))
8961 (defun org-agenda-clock-cancel (&optional arg)
8962 "Cancel the currently running clock."
8963 (interactive "P")
8964 (unless (marker-buffer org-clock-marker)
8965 (error "No running clock"))
8966 (org-with-remote-undo (marker-buffer org-clock-marker)
8967 (org-clock-cancel)))
8969 (defun org-agenda-clock-goto ()
8970 "Jump to the currently clocked in task within the agenda.
8971 If the currently clocked in task is not listed in the agenda
8972 buffer, display it in another window."
8973 (interactive)
8974 (let (pos)
8975 (mapc (lambda (o)
8976 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8977 (setq pos (overlay-start o))))
8978 (overlays-in (point-min) (point-max)))
8979 (cond (pos (goto-char pos))
8980 ;; If the currently clocked entry is not in the agenda
8981 ;; buffer, we visit it in another window:
8982 (org-clock-current-task
8983 (org-switch-to-buffer-other-window (org-clock-goto)))
8984 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8986 (defun org-agenda-diary-entry-in-org-file ()
8987 "Make a diary entry in the file `org-agenda-diary-file'."
8988 (let (d1 d2 char (text "") dp1 dp2)
8989 (if (equal (buffer-name) "*Calendar*")
8990 (setq d1 (calendar-cursor-to-date t)
8991 d2 (car calendar-mark-ring))
8992 (setq dp1 (get-text-property (point-at-bol) 'day))
8993 (unless dp1 (error "No date defined in current line"))
8994 (setq d1 (calendar-gregorian-from-absolute dp1)
8995 d2 (and (ignore-errors (mark))
8996 (save-excursion
8997 (goto-char (mark))
8998 (setq dp2 (get-text-property (point-at-bol) 'day)))
8999 (calendar-gregorian-from-absolute dp2))))
9000 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9001 (setq char (read-char-exclusive))
9002 (cond
9003 ((equal char ?d)
9004 (setq text (read-string "Day entry: "))
9005 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9006 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9007 ((equal char ?a)
9008 (setq d1 (list (car d1) (nth 1 d1)
9009 (read-number (format "Reference year [%d]: " (nth 2 d1))
9010 (nth 2 d1))))
9011 (setq text (read-string "Anniversary (use %d to show years): "))
9012 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9013 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9014 ((equal char ?b)
9015 (setq text (read-string "Block entry: "))
9016 (unless (and d1 d2 (not (equal d1 d2)))
9017 (error "No block of days selected"))
9018 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9019 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9020 ((equal char ?j)
9021 (org-switch-to-buffer-other-window
9022 (find-file-noselect org-agenda-diary-file))
9023 (require 'org-datetree)
9024 (org-datetree-find-date-create d1)
9025 (org-reveal t))
9026 (t (error "Invalid selection character `%c'" char)))))
9028 (defcustom org-agenda-insert-diary-strategy 'date-tree
9029 "Where in `org-agenda-diary-file' should new entries be added?
9030 Valid values:
9032 date-tree in the date tree, as child of the date
9033 top-level as top-level entries at the end of the file."
9034 :group 'org-agenda
9035 :type '(choice
9036 (const :tag "in a date tree" date-tree)
9037 (const :tag "as top level at end of file" top-level)))
9039 (defcustom org-agenda-insert-diary-extract-time nil
9040 "Non-nil means extract any time specification from the diary entry."
9041 :group 'org-agenda
9042 :version "24.1"
9043 :type 'boolean)
9045 (defcustom org-agenda-bulk-mark-char ">"
9046 "A single-character string to be used as the bulk mark."
9047 :group 'org-agenda
9048 :version "24.1"
9049 :type 'string)
9051 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9052 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9053 If TEXT is not empty, it will become the headline of the new entry, and
9054 the resulting entry will not be shown. When TEXT is empty, switch to
9055 `org-agenda-diary-file' and let the user finish the entry there."
9056 (let ((cw (current-window-configuration)))
9057 (org-switch-to-buffer-other-window
9058 (find-file-noselect org-agenda-diary-file))
9059 (widen)
9060 (goto-char (point-min))
9061 (cond
9062 ((eq type 'anniversary)
9063 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9064 (progn
9065 (or (org-at-heading-p t)
9066 (progn
9067 (outline-next-heading)
9068 (insert "* Anniversaries\n\n")
9069 (beginning-of-line -1)))))
9070 (outline-next-heading)
9071 (org-back-over-empty-lines)
9072 (backward-char 1)
9073 (insert "\n")
9074 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9075 (nth 2 d1) (car d1) (nth 1 d1) text)))
9076 ((eq type 'day)
9077 (let ((org-prefix-has-time t)
9078 (org-agenda-time-leading-zero t)
9079 fmt time time2)
9080 (if org-agenda-insert-diary-extract-time
9081 ;; Use org-agenda-format-item to parse text for a time-range and
9082 ;; remove it. FIXME: This is a hack, we should refactor
9083 ;; that function to make time extraction available separately
9084 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9085 time (get-text-property 0 'time fmt)
9086 time2 (if (> (length time) 0)
9087 ;; split-string removes trailing ...... if
9088 ;; no end time given. First space
9089 ;; separates time from date.
9090 (concat " " (car (split-string time "\\.")))
9091 nil)
9092 text (get-text-property 0 'txt fmt)))
9093 (if (eq org-agenda-insert-diary-strategy 'top-level)
9094 (org-agenda-insert-diary-as-top-level text)
9095 (require 'org-datetree)
9096 (org-datetree-find-date-create d1)
9097 (org-agenda-insert-diary-make-new-entry text))
9098 (org-insert-time-stamp (org-time-from-absolute
9099 (calendar-absolute-from-gregorian d1))
9100 nil nil nil nil time2))
9101 (end-of-line 0))
9102 ((eq type 'block)
9103 (if (> (calendar-absolute-from-gregorian d1)
9104 (calendar-absolute-from-gregorian d2))
9105 (setq d1 (prog1 d2 (setq d2 d1))))
9106 (if (eq org-agenda-insert-diary-strategy 'top-level)
9107 (org-agenda-insert-diary-as-top-level text)
9108 (require 'org-datetree)
9109 (org-datetree-find-date-create d1)
9110 (org-agenda-insert-diary-make-new-entry text))
9111 (org-insert-time-stamp (org-time-from-absolute
9112 (calendar-absolute-from-gregorian d1)))
9113 (insert "--")
9114 (org-insert-time-stamp (org-time-from-absolute
9115 (calendar-absolute-from-gregorian d2)))
9116 (end-of-line 0)))
9117 (if (string-match "\\S-" text)
9118 (progn
9119 (set-window-configuration cw)
9120 (message "%s entry added to %s"
9121 (capitalize (symbol-name type))
9122 (abbreviate-file-name org-agenda-diary-file)))
9123 (org-reveal t)
9124 (message "Please finish entry here"))))
9126 (defun org-agenda-insert-diary-as-top-level (text)
9127 "Make new entry as a top-level entry at the end of the file.
9128 Add TEXT as headline, and position the cursor in the second line so that
9129 a timestamp can be added there."
9130 (widen)
9131 (goto-char (point-max))
9132 (or (bolp) (insert "\n"))
9133 (insert "* " text "\n")
9134 (if org-adapt-indentation (org-indent-to-column 2)))
9136 (defun org-agenda-insert-diary-make-new-entry (text)
9137 "Make new entry as last child of current entry.
9138 Add TEXT as headline, and position the cursor in the second line so that
9139 a timestamp can be added there."
9140 (let ((org-show-following-heading t)
9141 (org-show-siblings t)
9142 (org-show-hierarchy-above t)
9143 (org-show-entry-below t)
9144 col)
9145 (outline-next-heading)
9146 (org-back-over-empty-lines)
9147 (or (looking-at "[ \t]*$")
9148 (progn (insert "\n") (backward-char 1)))
9149 (org-insert-heading nil t)
9150 (org-do-demote)
9151 (setq col (current-column))
9152 (insert text "\n")
9153 (if org-adapt-indentation (org-indent-to-column col))
9154 (let ((org-show-following-heading t)
9155 (org-show-siblings t)
9156 (org-show-hierarchy-above t)
9157 (org-show-entry-below t))
9158 (org-show-context))))
9160 (defun org-agenda-diary-entry ()
9161 "Make a diary entry, like the `i' command from the calendar.
9162 All the standard commands work: block, weekly etc.
9163 When `org-agenda-diary-file' points to a file,
9164 `org-agenda-diary-entry-in-org-file' is called instead to create
9165 entries in that Org-mode file."
9166 (interactive)
9167 (if (not (eq org-agenda-diary-file 'diary-file))
9168 (org-agenda-diary-entry-in-org-file)
9169 (require 'diary-lib)
9170 (let* ((char (progn
9171 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9172 (read-char-exclusive)))
9173 (cmd (cdr (assoc char
9174 '((?d . insert-diary-entry)
9175 (?w . insert-weekly-diary-entry)
9176 (?m . insert-monthly-diary-entry)
9177 (?y . insert-yearly-diary-entry)
9178 (?a . insert-anniversary-diary-entry)
9179 (?b . insert-block-diary-entry)
9180 (?c . insert-cyclic-diary-entry)))))
9181 (oldf (symbol-function 'calendar-cursor-to-date))
9182 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9183 (point (point))
9184 (mark (or (mark t) (point))))
9185 (unless cmd
9186 (error "No command associated with <%c>" char))
9187 (unless (and (get-text-property point 'day)
9188 (or (not (equal ?b char))
9189 (get-text-property mark 'day)))
9190 (error "Don't know which date to use for diary entry"))
9191 ;; We implement this by hacking the `calendar-cursor-to-date' function
9192 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9193 (let ((calendar-mark-ring
9194 (list (calendar-gregorian-from-absolute
9195 (or (get-text-property mark 'day)
9196 (get-text-property point 'day))))))
9197 (unwind-protect
9198 (progn
9199 (fset 'calendar-cursor-to-date
9200 (lambda (&optional error dummy)
9201 (calendar-gregorian-from-absolute
9202 (get-text-property point 'day))))
9203 (call-interactively cmd))
9204 (fset 'calendar-cursor-to-date oldf))))))
9206 (defun org-agenda-execute-calendar-command (cmd)
9207 "Execute a calendar command from the agenda with date from cursor."
9208 (org-agenda-check-type t 'agenda 'timeline)
9209 (require 'diary-lib)
9210 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9211 (error "Don't know which date to use for the calendar command"))
9212 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9213 (point (point))
9214 (date (calendar-gregorian-from-absolute
9215 (get-text-property point 'day)))
9216 ;; the following 2 vars are needed in the calendar
9217 (displayed-month (car date))
9218 (displayed-year (nth 2 date)))
9219 (unwind-protect
9220 (progn
9221 (fset 'calendar-cursor-to-date
9222 (lambda (&optional error dummy)
9223 (calendar-gregorian-from-absolute
9224 (get-text-property point 'day))))
9225 (call-interactively cmd))
9226 (fset 'calendar-cursor-to-date oldf))))
9228 (defun org-agenda-phases-of-moon ()
9229 "Display the phases of the moon for the 3 months around the cursor date."
9230 (interactive)
9231 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9233 (defun org-agenda-holidays ()
9234 "Display the holidays for the 3 months around the cursor date."
9235 (interactive)
9236 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9238 (defvar calendar-longitude) ; defined in calendar.el
9239 (defvar calendar-latitude) ; defined in calendar.el
9240 (defvar calendar-location-name) ; defined in calendar.el
9242 (defun org-agenda-sunrise-sunset (arg)
9243 "Display sunrise and sunset for the cursor date.
9244 Latitude and longitude can be specified with the variables
9245 `calendar-latitude' and `calendar-longitude'. When called with prefix
9246 argument, latitude and longitude will be prompted for."
9247 (interactive "P")
9248 (require 'solar)
9249 (let ((calendar-longitude (if arg nil calendar-longitude))
9250 (calendar-latitude (if arg nil calendar-latitude))
9251 (calendar-location-name
9252 (if arg "the given coordinates" calendar-location-name)))
9253 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9255 (defun org-agenda-goto-calendar ()
9256 "Open the Emacs calendar with the date at the cursor."
9257 (interactive)
9258 (org-agenda-check-type t 'agenda 'timeline)
9259 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9260 (error "Don't know which date to open in calendar")))
9261 (date (calendar-gregorian-from-absolute day))
9262 (calendar-move-hook nil)
9263 (calendar-view-holidays-initially-flag nil)
9264 (calendar-view-diary-initially-flag nil))
9265 (calendar)
9266 (calendar-goto-date date)))
9268 ;;;###autoload
9269 (defun org-calendar-goto-agenda ()
9270 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9271 This is a command that has to be installed in `calendar-mode-map'."
9272 (interactive)
9273 (org-agenda-list nil (calendar-absolute-from-gregorian
9274 (calendar-cursor-to-date))
9275 nil))
9277 (defun org-agenda-convert-date ()
9278 (interactive)
9279 (org-agenda-check-type t 'agenda 'timeline)
9280 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9281 date s)
9282 (unless day
9283 (error "Don't know which date to convert"))
9284 (setq date (calendar-gregorian-from-absolute day))
9285 (setq s (concat
9286 "Gregorian: " (calendar-date-string date) "\n"
9287 "ISO: " (calendar-iso-date-string date) "\n"
9288 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9289 "Julian: " (calendar-julian-date-string date) "\n"
9290 "Astron. JD: " (calendar-astro-date-string date)
9291 " (Julian date number at noon UTC)\n"
9292 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9293 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9294 "French: " (calendar-french-date-string date) "\n"
9295 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9296 "Mayan: " (calendar-mayan-date-string date) "\n"
9297 "Coptic: " (calendar-coptic-date-string date) "\n"
9298 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9299 "Persian: " (calendar-persian-date-string date) "\n"
9300 "Chinese: " (calendar-chinese-date-string date) "\n"))
9301 (with-output-to-temp-buffer "*Dates*"
9302 (princ s))
9303 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9305 ;;; Bulk commands
9307 (defun org-agenda-bulk-marked-p ()
9308 (eq (get-char-property (point-at-bol) 'type)
9309 'org-marked-entry-overlay))
9311 (defun org-agenda-bulk-mark (&optional arg)
9312 "Mark the entry at point for future bulk action."
9313 (interactive "p")
9314 (dotimes (i (or arg 1))
9315 (unless (org-get-at-bol 'org-agenda-diary-link)
9316 (let* ((m (org-get-at-bol 'org-hd-marker))
9318 (unless (org-agenda-bulk-marked-p)
9319 (unless m (error "Nothing to mark at point"))
9320 (push m org-agenda-bulk-marked-entries)
9321 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9322 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9323 (org-get-todo-face "TODO")
9324 'evaporate)
9325 (overlay-put ov 'type 'org-marked-entry-overlay))
9326 (beginning-of-line 2)
9327 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9328 (beginning-of-line 2))
9329 (message "%d entries marked for bulk action"
9330 (length org-agenda-bulk-marked-entries))))))
9332 (defun org-agenda-bulk-mark-all ()
9333 "Mark all entries for future agenda bulk action."
9334 (interactive)
9335 (org-agenda-bulk-mark-regexp "."))
9337 (defun org-agenda-bulk-mark-regexp (regexp)
9338 "Mark entries matching REGEXP for future agenda bulk action."
9339 (interactive "sMark entries matching regexp: ")
9340 (let ((entries-marked 0))
9341 (save-excursion
9342 (goto-char (point-min))
9343 (goto-char (next-single-property-change (point) 'txt))
9344 (while (re-search-forward regexp nil t)
9345 (when (string-match regexp (get-text-property (point) 'txt))
9346 (setq entries-marked (1+ entries-marked))
9347 (call-interactively 'org-agenda-bulk-mark))))
9348 (if (not entries-marked)
9349 (message "No entry matching this regexp."))))
9351 (defun org-agenda-bulk-unmark (&optional arg)
9352 "Unmark the entry at point for future bulk action."
9353 (interactive "P")
9354 (if arg
9355 (org-agenda-bulk-unmark-all)
9356 (cond ((org-agenda-bulk-marked-p)
9357 (org-agenda-bulk-remove-overlays
9358 (point-at-bol) (+ 2 (point-at-bol)))
9359 (setq org-agenda-bulk-marked-entries
9360 (delete (org-get-at-bol 'org-hd-marker)
9361 org-agenda-bulk-marked-entries))
9362 (beginning-of-line 2)
9363 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9364 (beginning-of-line 2))
9365 (message "%d entries left marked for bulk action"
9366 (length org-agenda-bulk-marked-entries)))
9367 (t (message "No entry to unmark here")))))
9369 (defun org-agenda-bulk-toggle ()
9370 "Toggle marking the entry at point for bulk action."
9371 (interactive)
9372 (if (org-agenda-bulk-marked-p)
9373 (org-agenda-bulk-unmark)
9374 (org-agenda-bulk-mark)))
9376 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9377 "Remove the mark overlays between BEG and END in the agenda buffer.
9378 BEG and END default to the buffer limits.
9380 This only removes the overlays, it does not remove the markers
9381 from the list in `org-agenda-bulk-marked-entries'."
9382 (interactive)
9383 (mapc (lambda (ov)
9384 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9385 (delete-overlay ov)))
9386 (overlays-in (or beg (point-min)) (or end (point-max)))))
9388 (defun org-agenda-bulk-unmark-all ()
9389 "Remove all marks in the agenda buffer.
9390 This will remove the markers and the overlays."
9391 (interactive)
9392 (if (null org-agenda-bulk-marked-entries)
9393 (message "No entry to unmark")
9394 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9395 (setq org-agenda-bulk-marked-entries nil)
9396 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9398 (defcustom org-agenda-persistent-marks nil
9399 "Non-nil means marked items will stay marked after a bulk action.
9400 You can toggle this interactively by typing `p' when prompted for a
9401 bulk action."
9402 :group 'org-agenda
9403 :version "24.1"
9404 :type 'boolean)
9406 (defun org-agenda-bulk-action (&optional arg)
9407 "Execute an remote-editing action on all marked entries.
9408 The prefix arg is passed through to the command if possible."
9409 (interactive "P")
9410 ;; Make sure we have markers, and only valid ones
9411 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9412 (mapc
9413 (lambda (m)
9414 (unless (and (markerp m)
9415 (marker-buffer m)
9416 (buffer-live-p (marker-buffer m))
9417 (marker-position m))
9418 (error "Marker %s for bulk command is invalid" m)))
9419 org-agenda-bulk-marked-entries)
9421 ;; Prompt for the bulk command
9422 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9423 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9424 "[S]catter [f]unction "
9425 (when org-agenda-bulk-custom-functions
9426 (concat " Custom: ["
9427 (mapconcat (lambda(f) (char-to-string (car f)))
9428 org-agenda-bulk-custom-functions "")
9429 "]"))))
9430 (catch 'exit
9431 (let* ((action (read-char-exclusive))
9432 (org-log-refile (if org-log-refile 'time nil))
9433 (entries (reverse org-agenda-bulk-marked-entries))
9434 (org-overriding-default-time
9435 (if (get-text-property (point) 'org-agenda-date-header)
9436 (org-get-cursor-date)))
9437 redo-at-end
9438 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9439 (cond
9440 ((equal action ?p)
9441 (let ((org-agenda-persistent-marks
9442 (not org-agenda-persistent-marks)))
9443 (org-agenda-bulk-action)
9444 (throw 'exit nil)))
9446 ((equal action ?$)
9447 (setq cmd '(org-agenda-archive)))
9449 ((equal action ?A)
9450 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9452 ((member action '(?r ?w))
9453 (setq rfloc (org-refile-get-location
9454 "Refile to"
9455 (marker-buffer (car entries))
9456 org-refile-allow-creating-parent-nodes))
9457 (if (nth 3 rfloc)
9458 (setcar (nthcdr 3 rfloc)
9459 (move-marker (make-marker) (nth 3 rfloc)
9460 (or (get-file-buffer (nth 1 rfloc))
9461 (find-buffer-visiting (nth 1 rfloc))
9462 (error "This should not happen")))))
9464 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9465 redo-at-end t))
9467 ((equal action ?t)
9468 (setq state (org-icompleting-read
9469 "Todo state: "
9470 (with-current-buffer (marker-buffer (car entries))
9471 (mapcar 'list org-todo-keywords-1))))
9472 (setq cmd `(let ((org-inhibit-blocking t)
9473 (org-inhibit-logging 'note))
9474 (org-agenda-todo ,state))))
9476 ((memq action '(?- ?+))
9477 (setq tag (org-icompleting-read
9478 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9479 (with-current-buffer (marker-buffer (car entries))
9480 (delq nil
9481 (mapcar (lambda (x)
9482 (if (stringp (car x)) x)) org-tag-alist)))))
9483 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9485 ((memq action '(?s ?d))
9486 (let* ((time
9487 (unless arg
9488 (org-read-date
9489 nil nil nil
9490 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9491 org-overriding-default-time)))
9492 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9493 (setq cmd `(eval '(,c1 arg ,time)))))
9495 ((equal action ?S)
9496 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9497 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9498 (let ((days (read-number
9499 (format "Scatter tasks across how many %sdays: "
9500 (if arg "week" "")) 7)))
9501 (setq cmd
9502 `(let ((distance (1+ (random ,days))))
9503 (if arg
9504 (let ((dist distance)
9505 (day-of-week
9506 (calendar-day-of-week
9507 (calendar-gregorian-from-absolute (org-today)))))
9508 (dotimes (i (1+ dist))
9509 (while (member day-of-week org-agenda-weekend-days)
9510 (incf distance)
9511 (incf day-of-week)
9512 (if (= day-of-week 7)
9513 (setq day-of-week 0)))
9514 (incf day-of-week)
9515 (if (= day-of-week 7)
9516 (setq day-of-week 0)))))
9517 ;; silently fail when try to replan a sexp entry
9518 (condition-case nil
9519 (let* ((date (calendar-gregorian-from-absolute
9520 (+ (org-today) distance)))
9521 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9522 (nth 2 date))))
9523 (org-agenda-schedule nil time))
9524 (error nil)))))))
9526 ((assoc action org-agenda-bulk-custom-functions)
9527 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9528 redo-at-end t))
9530 ((equal action ?f)
9531 (setq cmd (list (intern
9532 (org-icompleting-read "Function: "
9533 obarray 'fboundp t nil nil)))))
9535 (t (error "Invalid bulk action")))
9537 ;; Sort the markers, to make sure that parents are handled before children
9538 (setq entries (sort entries
9539 (lambda (a b)
9540 (cond
9541 ((equal (marker-buffer a) (marker-buffer b))
9542 (< (marker-position a) (marker-position b)))
9544 (string< (buffer-name (marker-buffer a))
9545 (buffer-name (marker-buffer b))))))))
9547 ;; Now loop over all markers and apply cmd
9548 (while (setq e (pop entries))
9549 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9550 (if (not pos)
9551 (progn (message "Skipping removed entry at %s" e)
9552 (setq cntskip (1+ cntskip)))
9553 (goto-char pos)
9554 (let (org-loop-over-headlines-in-active-region)
9555 (eval cmd))
9556 (setq cnt (1+ cnt))))
9557 (when redo-at-end (org-agenda-redo))
9558 (unless org-agenda-persistent-marks
9559 (org-agenda-bulk-unmark-all))
9560 (message "Acted on %d entries%s%s"
9562 (if (= cntskip 0)
9564 (format ", skipped %d (disappeared before their turn)"
9565 cntskip))
9566 (if (not org-agenda-persistent-marks)
9567 "" " (kept marked)"))))))
9569 (defun org-agenda-capture (&optional with-time)
9570 "Call `org-capture' with the date at point.
9571 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9572 current HH:MM time."
9573 (interactive "P")
9574 (if (not (eq major-mode 'org-agenda-mode))
9575 (user-error "You cannot do this outside of agenda buffers")
9576 (let ((org-overriding-default-time
9577 (org-get-cursor-date (equal with-time 1))))
9578 (call-interactively 'org-capture))))
9580 ;;; Flagging notes
9582 (defun org-agenda-show-the-flagging-note ()
9583 "Display the flagging note in the other window.
9584 When called a second time in direct sequence, offer to remove the FLAGGING
9585 tag and (if present) the flagging note."
9586 (interactive)
9587 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9588 (win (selected-window))
9589 note heading newhead)
9590 (unless hdmarker
9591 (error "No linked entry at point"))
9592 (if (and (eq this-command last-command)
9593 (y-or-n-p "Unflag and remove any flagging note? "))
9594 (progn
9595 (org-agenda-remove-flag hdmarker)
9596 (let ((win (get-buffer-window "*Flagging Note*")))
9597 (and win (delete-window win)))
9598 (message "Entry unflagged"))
9599 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9600 (unless note
9601 (error "No flagging note"))
9602 (org-kill-new note)
9603 (org-switch-to-buffer-other-window "*Flagging Note*")
9604 (erase-buffer)
9605 (insert note)
9606 (goto-char (point-min))
9607 (while (re-search-forward "\\\\n" nil t)
9608 (replace-match "\n" t t))
9609 (goto-char (point-min))
9610 (select-window win)
9611 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9613 (defun org-agenda-remove-flag (marker)
9614 "Remove the FLAGGED tag and any flagging note in the entry."
9615 (let (newhead)
9616 (org-with-point-at marker
9617 (org-toggle-tag "FLAGGED" 'off)
9618 (org-entry-delete nil "THEFLAGGINGNOTE")
9619 (setq newhead (org-get-heading)))
9620 (org-agenda-change-all-lines newhead marker)
9621 (message "Entry unflagged")))
9623 (defun org-agenda-get-any-marker (&optional pos)
9624 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9625 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9627 ;;; Appointment reminders
9629 (defvar appt-time-msg-list) ; defined in appt.el
9631 ;;;###autoload
9632 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9633 "Activate appointments found in `org-agenda-files'.
9634 With a \\[universal-argument] prefix, refresh the list of
9635 appointments.
9637 If FILTER is t, interactively prompt the user for a regular
9638 expression, and filter out entries that don't match it.
9640 If FILTER is a string, use this string as a regular expression
9641 for filtering entries out.
9643 If FILTER is a function, filter out entries against which
9644 calling the function returns nil. This function takes one
9645 argument: an entry from `org-agenda-get-day-entries'.
9647 FILTER can also be an alist with the car of each cell being
9648 either 'headline or 'category. For example:
9650 '((headline \"IMPORTANT\")
9651 (category \"Work\"))
9653 will only add headlines containing IMPORTANT or headlines
9654 belonging to the \"Work\" category.
9656 ARGS are symbols indicating what kind of entries to consider.
9657 By default `org-agenda-to-appt' will use :deadline, :scheduled
9658 and :timestamp entries. See the docstring of `org-diary' for
9659 details and examples.
9661 If an entry has a APPT_WARNTIME property, its value will be used
9662 to override `appt-message-warning-time'."
9663 (interactive "P")
9664 (if refresh (setq appt-time-msg-list nil))
9665 (if (eq filter t)
9666 (setq filter (read-from-minibuffer "Regexp filter: ")))
9667 (let* ((cnt 0) ; count added events
9668 (scope (or args '(:deadline :scheduled :timestamp)))
9669 (org-agenda-new-buffers nil)
9670 (org-deadline-warning-days 0)
9671 ;; Do not use `org-today' here because appt only takes
9672 ;; time and without date as argument, so it may pass wrong
9673 ;; information otherwise
9674 (today (org-date-to-gregorian
9675 (time-to-days (current-time))))
9676 (org-agenda-restrict nil)
9677 (files (org-agenda-files 'unrestricted)) entries file
9678 (org-agenda-buffer nil))
9679 ;; Get all entries which may contain an appt
9680 (org-agenda-prepare-buffers files)
9681 (while (setq file (pop files))
9682 (setq entries
9683 (delq nil
9684 (append entries
9685 (apply 'org-agenda-get-day-entries
9686 file today scope)))))
9687 ;; Map thru entries and find if we should filter them out
9688 (mapc
9689 (lambda(x)
9690 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9691 (cat (get-text-property 1 'org-category x))
9692 (tod (get-text-property 1 'time-of-day x))
9693 (ok (or (null filter)
9694 (and (stringp filter) (string-match filter evt))
9695 (and (functionp filter) (funcall filter x))
9696 (and (listp filter)
9697 (let ((cat-filter (cadr (assoc 'category filter)))
9698 (evt-filter (cadr (assoc 'headline filter))))
9699 (or (and (stringp cat-filter)
9700 (string-match cat-filter cat))
9701 (and (stringp evt-filter)
9702 (string-match evt-filter evt)))))))
9703 (wrn (get-text-property 1 'warntime x)))
9704 ;; FIXME: Shall we remove text-properties for the appt text?
9705 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9706 (when (and ok tod)
9707 (setq tod (concat "00" (number-to-string tod))
9708 tod (when (string-match
9709 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9710 (concat (match-string 1 tod) ":"
9711 (match-string 2 tod))))
9712 (if (version< emacs-version "23.3")
9713 (appt-add tod evt)
9714 (appt-add tod evt wrn))
9715 (setq cnt (1+ cnt))))) entries)
9716 (org-release-buffers org-agenda-new-buffers)
9717 (if (eq cnt 0)
9718 (message "No event to add")
9719 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9721 (defun org-agenda-todayp (date)
9722 "Does DATE mean today, when considering `org-extend-today-until'?"
9723 (let ((today (org-today))
9724 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9725 date)))
9726 (eq date today)))
9728 (defun org-agenda-todo-yesterday (&optional arg)
9729 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9730 (interactive "P")
9731 (let* ((hour (third (decode-time
9732 (org-current-time))))
9733 (org-extend-today-until (1+ hour)))
9734 (org-agenda-todo arg)))
9736 (provide 'org-agenda)
9738 ;;; org-agenda.el ends here