Export back-ends: add entry in `org-export-dispatch' when loaded
[org-mode.git] / lisp / org-agenda.el
blob8a5a0cc8db1a70ea5b638af24380d5b1694cbd0e
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today nil)
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 temporary buffer before writing it to an export file.
164 A useful function 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 it is by 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 ""
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. However,
228 <style>...</style> is required, if not present the variable will be ignored."
229 :group 'org-agenda-export
230 :group 'org-export-html
231 :type 'string)
233 (defcustom org-agenda-persistent-filter nil
234 "When set, keep filters from one agenda view to the next."
235 :group 'org-agenda
236 :type 'boolean)
238 (defgroup org-agenda-custom-commands nil
239 "Options concerning agenda views in Org-mode."
240 :tag "Org Agenda Custom Commands"
241 :group 'org-agenda)
243 (defconst org-sorting-choice
244 '(choice
245 (const time-up) (const time-down)
246 (const category-keep) (const category-up) (const category-down)
247 (const tag-down) (const tag-up)
248 (const priority-up) (const priority-down)
249 (const todo-state-up) (const todo-state-down)
250 (const effort-up) (const effort-down)
251 (const habit-up) (const habit-down)
252 (const alpha-up) (const alpha-down)
253 (const user-defined-up) (const user-defined-down))
254 "Sorting choices.")
256 ;; Keep custom values for `org-agenda-filter-preset' compatible with
257 ;; the new variable `org-agenda-tag-filter-preset'.
258 (if (fboundp 'defvaralias)
259 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
260 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
262 (defconst org-agenda-custom-commands-local-options
263 `(repeat :tag "Local settings for this command. Remember to quote values"
264 (choice :tag "Setting"
265 (list :tag "Heading for this block"
266 (const org-agenda-overriding-header)
267 (string :tag "Headline"))
268 (list :tag "Files to be searched"
269 (const org-agenda-files)
270 (list
271 (const :format "" quote)
272 (repeat (file))))
273 (list :tag "Sorting strategy"
274 (const org-agenda-sorting-strategy)
275 (list
276 (const :format "" quote)
277 (repeat
278 ,org-sorting-choice)))
279 (list :tag "Prefix format"
280 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
281 (string))
282 (list :tag "Number of days in agenda"
283 (const org-agenda-span)
284 (choice (const :tag "Day" 'day)
285 (const :tag "Week" 'week)
286 (const :tag "Month" 'month)
287 (const :tag "Year" 'year)
288 (integer :tag "Custom")))
289 (list :tag "Fixed starting date"
290 (const org-agenda-start-day)
291 (string :value "2007-11-01"))
292 (list :tag "Start on day of week"
293 (const org-agenda-start-on-weekday)
294 (choice :value 1
295 (const :tag "Today" nil)
296 (integer :tag "Weekday No.")))
297 (list :tag "Include data from diary"
298 (const org-agenda-include-diary)
299 (boolean))
300 (list :tag "Deadline Warning days"
301 (const org-deadline-warning-days)
302 (integer :value 1))
303 (list :tag "Category filter preset"
304 (const org-agenda-category-filter-preset)
305 (list
306 (const :format "" quote)
307 (repeat
308 (string :tag "+category or -category"))))
309 (list :tag "Tags filter preset"
310 (const org-agenda-tag-filter-preset)
311 (list
312 (const :format "" quote)
313 (repeat
314 (string :tag "+tag or -tag"))))
315 (list :tag "Set daily/weekly entry types"
316 (const org-agenda-entry-types)
317 (list
318 (const :format "" quote)
319 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
320 (const :deadline)
321 (const :scheduled)
322 (const :timestamp)
323 (const :sexp))))
324 (list :tag "Standard skipping condition"
325 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
326 (const org-agenda-skip-function)
327 (list
328 (const :format "" quote)
329 (list
330 (choice
331 :tag "Skipping range"
332 (const :tag "Skip entry" org-agenda-skip-entry-if)
333 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
334 (repeat :inline t :tag "Conditions for skipping"
335 (choice
336 :tag "Condition type"
337 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
338 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
339 (list :tag "TODO state is" :inline t
340 (const 'todo)
341 (choice
342 (const :tag "any not-done state" 'todo)
343 (const :tag "any done state" 'done)
344 (const :tag "any state" 'any)
345 (list :tag "Keyword list"
346 (const :format "" quote)
347 (repeat (string :tag "Keyword")))))
348 (list :tag "TODO state is not" :inline t
349 (const 'nottodo)
350 (choice
351 (const :tag "any not-done state" 'todo)
352 (const :tag "any done state" 'done)
353 (const :tag "any state" 'any)
354 (list :tag "Keyword list"
355 (const :format "" quote)
356 (repeat (string :tag "Keyword")))))
357 (const :tag "scheduled" 'scheduled)
358 (const :tag "not scheduled" 'notscheduled)
359 (const :tag "deadline" 'deadline)
360 (const :tag "no deadline" 'notdeadline)
361 (const :tag "timestamp" 'timestamp)
362 (const :tag "no timestamp" 'nottimestamp))))))
363 (list :tag "Non-standard skipping condition"
364 :value (org-agenda-skip-function)
365 (const org-agenda-skip-function)
366 (sexp :tag "Function or form (quoted!)"))
367 (list :tag "Any variable"
368 (variable :tag "Variable")
369 (sexp :tag "Value (sexp)"))))
370 "Selection of examples for agenda command settings.
371 This will be spliced into the custom type of
372 `org-agenda-custom-commands'.")
375 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
376 ((agenda "") (alltodo))))
377 "Custom commands for the agenda.
378 These commands will be offered on the splash screen displayed by the
379 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
381 (key desc type match settings files)
383 key The key (one or more characters as a string) to be associated
384 with the command.
385 desc A description of the command, when omitted or nil, a default
386 description is built using MATCH.
387 type The command type, any of the following symbols:
388 agenda The daily/weekly agenda.
389 todo Entries with a specific TODO keyword, in all agenda files.
390 search Entries containing search words entry or headline.
391 tags Tags/Property/TODO match in all agenda files.
392 tags-todo Tags/P/T match in all agenda files, TODO entries only.
393 todo-tree Sparse tree of specific TODO keyword in *current* file.
394 tags-tree Sparse tree with all tags matches in *current* file.
395 occur-tree Occur sparse tree for *current* file.
396 ... A user-defined function.
397 match What to search for:
398 - a single keyword for TODO keyword searches
399 - a tags match expression for tags searches
400 - a word search expression for text searches.
401 - a regular expression for occur searches
402 For all other commands, this should be the empty string.
403 settings A list of option settings, similar to that in a let form, so like
404 this: ((opt1 val1) (opt2 val2) ...). The values will be
405 evaluated at the moment of execution, so quote them when needed.
406 files A list of files file to write the produced agenda buffer to
407 with the command `org-store-agenda-views'.
408 If a file name ends in \".html\", an HTML version of the buffer
409 is written out. If it ends in \".ps\", a postscript version is
410 produced. Otherwise, only the plain text is written to the file.
412 You can also define a set of commands, to create a composite agenda buffer.
413 In this case, an entry looks like this:
415 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
417 where
419 desc A description string to be displayed in the dispatcher menu.
420 cmd An agenda command, similar to the above. However, tree commands
421 are not allowed, but instead you can get agenda and global todo list.
422 So valid commands for a set are:
423 (agenda \"\" settings)
424 (alltodo \"\" settings)
425 (stuck \"\" settings)
426 (todo \"match\" settings files)
427 (search \"match\" settings files)
428 (tags \"match\" settings files)
429 (tags-todo \"match\" settings files)
431 Each command can carry a list of options, and another set of options can be
432 given for the whole set of commands. Individual command options take
433 precedence over the general options.
435 When using several characters as key to a command, the first characters
436 are prefix commands. For the dispatcher to display useful information, you
437 should provide a description for the prefix, like
439 (setq org-agenda-custom-commands
440 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
441 (\"hl\" tags \"+HOME+Lisa\")
442 (\"hp\" tags \"+HOME+Peter\")
443 (\"hk\" tags \"+HOME+Kim\")))"
444 :group 'org-agenda-custom-commands
445 :type `(repeat
446 (choice :value ("x" "Describe command here" tags "" nil)
447 (list :tag "Single command"
448 (string :tag "Access Key(s) ")
449 (option (string :tag "Description"))
450 (choice
451 (const :tag "Agenda" agenda)
452 (const :tag "TODO list" alltodo)
453 (const :tag "Search words" search)
454 (const :tag "Stuck projects" stuck)
455 (const :tag "Tags/Property match (all agenda files)" tags)
456 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
457 (const :tag "TODO keyword search (all agenda files)" todo)
458 (const :tag "Tags sparse tree (current buffer)" tags-tree)
459 (const :tag "TODO keyword tree (current buffer)" todo-tree)
460 (const :tag "Occur tree (current buffer)" occur-tree)
461 (sexp :tag "Other, user-defined function"))
462 (string :tag "Match (only for some commands)")
463 ,org-agenda-custom-commands-local-options
464 (option (repeat :tag "Export" (file :tag "Export to"))))
465 (list :tag "Command series, all agenda files"
466 (string :tag "Access Key(s)")
467 (string :tag "Description ")
468 (repeat :tag "Component"
469 (choice
470 (list :tag "Agenda"
471 (const :format "" agenda)
472 (const :tag "" :format "" "")
473 ,org-agenda-custom-commands-local-options)
474 (list :tag "TODO list (all keywords)"
475 (const :format "" alltodo)
476 (const :tag "" :format "" "")
477 ,org-agenda-custom-commands-local-options)
478 (list :tag "Search words"
479 (const :format "" search)
480 (string :tag "Match")
481 ,org-agenda-custom-commands-local-options)
482 (list :tag "Stuck projects"
483 (const :format "" stuck)
484 (const :tag "" :format "" "")
485 ,org-agenda-custom-commands-local-options)
486 (list :tag "Tags search"
487 (const :format "" tags)
488 (string :tag "Match")
489 ,org-agenda-custom-commands-local-options)
490 (list :tag "Tags search, TODO entries only"
491 (const :format "" tags-todo)
492 (string :tag "Match")
493 ,org-agenda-custom-commands-local-options)
494 (list :tag "TODO keyword search"
495 (const :format "" todo)
496 (string :tag "Match")
497 ,org-agenda-custom-commands-local-options)
498 (list :tag "Other, user-defined function"
499 (symbol :tag "function")
500 (string :tag "Match")
501 ,org-agenda-custom-commands-local-options)))
503 (repeat :tag "Settings for entire command set"
504 (list (variable :tag "Any variable")
505 (sexp :tag "Value")))
506 (option (repeat :tag "Export" (file :tag "Export to"))))
507 (cons :tag "Prefix key documentation"
508 (string :tag "Access Key(s)")
509 (string :tag "Description ")))))
511 (defcustom org-agenda-query-register ?o
512 "The register holding the current query string.
513 The purpose of this is that if you construct a query string interactively,
514 you can then use it to define a custom command."
515 :group 'org-agenda-custom-commands
516 :type 'character)
518 (defcustom org-stuck-projects
519 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
520 "How to identify stuck projects.
521 This is a list of four items:
522 1. A tags/todo/property matcher string that is used to identify a project.
523 See the manual for a description of tag and property searches.
524 The entire tree below a headline matched by this is considered one project.
525 2. A list of TODO keywords identifying non-stuck projects.
526 If the project subtree contains any headline with one of these todo
527 keywords, the project is considered to be not stuck. If you specify
528 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
529 3. A list of tags identifying non-stuck projects.
530 If the project subtree contains any headline with one of these tags,
531 the project is considered to be not stuck. If you specify \"*\" as
532 a tag, any tag will mark the project unstuck. Note that this is about
533 the explicit presence of a tag somewhere in the subtree, inherited
534 tags to not count here. If inherited tags make a project not stuck,
535 use \"-TAG\" in the tags part of the matcher under (1.) above.
536 4. An arbitrary regular expression matching non-stuck projects.
538 If the project turns out to be not stuck, search continues also in the
539 subtree to see if any of the subtasks have project status.
541 See also the variable `org-tags-match-list-sublevels' which applies
542 to projects matched by this search as well.
544 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
545 or `C-c a #' to produce the list."
546 :group 'org-agenda-custom-commands
547 :type '(list
548 (string :tag "Tags/TODO match to identify a project")
549 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
550 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
551 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
553 (defcustom org-agenda-filter-effort-default-operator "<"
554 "The default operator for effort estimate filtering.
555 If you select an effort estimate limit without first pressing an operator,
556 this one will be used."
557 :group 'org-agenda-custom-commands
558 :type '(choice (const :tag "less or equal" "<")
559 (const :tag "greater or equal"">")
560 (const :tag "equal" "=")))
562 (defgroup org-agenda-skip nil
563 "Options concerning skipping parts of agenda files."
564 :tag "Org Agenda Skip"
565 :group 'org-agenda)
567 (defcustom org-agenda-skip-function-global nil
568 "Function to be called at each match during agenda construction.
569 If this function returns nil, the current match should not be skipped.
570 If the function decided to skip an agenda match, is must return the
571 buffer position from which the search should be continued.
572 This may also be a Lisp form, which will be evaluated.
574 This variable will be applied to every agenda match, including
575 tags/property searches and TODO lists. So try to make the test function
576 do its checking as efficiently as possible. To implement a skipping
577 condition just for specific agenda commands, use the variable
578 `org-agenda-skip-function' which can be set in the options section
579 of custom agenda commands."
580 :group 'org-agenda-skip
581 :type 'sexp)
583 (defgroup org-agenda-daily/weekly nil
584 "Options concerning the daily/weekly agenda."
585 :tag "Org Agenda Daily/Weekly"
586 :group 'org-agenda)
587 (defgroup org-agenda-todo-list nil
588 "Options concerning the global todo list agenda view."
589 :tag "Org Agenda Todo List"
590 :group 'org-agenda)
591 (defgroup org-agenda-match-view nil
592 "Options concerning the general tags/property/todo match agenda view."
593 :tag "Org Agenda Match View"
594 :group 'org-agenda)
595 (defgroup org-agenda-search-view nil
596 "Options concerning the general tags/property/todo match agenda view."
597 :tag "Org Agenda Match View"
598 :group 'org-agenda)
600 (defvar org-agenda-archives-mode nil
601 "Non-nil means the agenda will include archived items.
602 If this is the symbol `trees', trees in the selected agenda scope
603 that are marked with the ARCHIVE tag will be included anyway. When this is
604 t, also all archive files associated with the current selection of agenda
605 files will be included.")
607 (defcustom org-agenda-skip-comment-trees t
608 "Non-nil means skip trees that start with the COMMENT keyword.
609 When nil, these trees are also scanned by agenda commands."
610 :group 'org-agenda-skip
611 :type 'boolean)
613 (defcustom org-agenda-todo-list-sublevels t
614 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
615 When nil, the sublevels of a TODO entry are not checked, resulting in
616 potentially much shorter TODO lists."
617 :group 'org-agenda-skip
618 :group 'org-agenda-todo-list
619 :type 'boolean)
621 (defcustom org-agenda-todo-ignore-with-date nil
622 "Non-nil means don't show entries with a date in the global todo list.
623 You can use this if you prefer to mark mere appointments with a TODO keyword,
624 but don't want them to show up in the TODO list.
625 When this is set, it also covers deadlines and scheduled items, the settings
626 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
627 will be ignored.
628 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
629 :group 'org-agenda-skip
630 :group 'org-agenda-todo-list
631 :type 'boolean)
633 (defcustom org-agenda-todo-ignore-timestamp nil
634 "Non-nil means don't show entries with a timestamp.
635 This applies when creating the global todo list.
636 Valid values are:
638 past Don't show entries for today or in the past.
640 future Don't show entries with a timestamp in the future.
641 The idea behind this is that if it has a future
642 timestamp, you don't want to think about it until the
643 date.
645 all Don't show any entries with a timestamp in the global todo list.
646 The idea behind this is that by setting a timestamp, you
647 have already \"taken care\" of this item.
649 This variable can also have an integer as a value. If positive (N),
650 todos with a timestamp N or more days in the future will be ignored. If
651 negative (-N), todos with a timestamp N or more days in the past will be
652 ignored. If 0, todos with a timestamp either today or in the future will
653 be ignored. For example, a value of -1 will exclude todos with a
654 timestamp in the past (yesterday or earlier), while a value of 7 will
655 exclude todos with a timestamp a week or more in the future.
657 See also `org-agenda-todo-ignore-with-date'.
658 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
659 to make his option also apply to the tags-todo list."
660 :group 'org-agenda-skip
661 :group 'org-agenda-todo-list
662 :version "24.1"
663 :type '(choice
664 (const :tag "Ignore future timestamp todos" future)
665 (const :tag "Ignore past or present timestamp todos" past)
666 (const :tag "Ignore all timestamp todos" all)
667 (const :tag "Show timestamp todos" nil)
668 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
670 (defcustom org-agenda-todo-ignore-scheduled nil
671 "Non-nil means, ignore some scheduled TODO items when making TODO list.
672 This applies when creating the global todo list.
673 Valid values are:
675 past Don't show entries scheduled today or in the past.
677 future Don't show entries scheduled in the future.
678 The idea behind this is that by scheduling it, you don't want to
679 think about it until the scheduled date.
681 all Don't show any scheduled entries in the global todo list.
682 The idea behind this is that by scheduling it, you have already
683 \"taken care\" of this item.
685 t Same as `all', for backward compatibility.
687 This variable can also have an integer as a value. See
688 `org-agenda-todo-ignore-timestamp' for more details.
690 See also `org-agenda-todo-ignore-with-date'.
691 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
692 to make his option also apply to the tags-todo list."
693 :group 'org-agenda-skip
694 :group 'org-agenda-todo-list
695 :type '(choice
696 (const :tag "Ignore future-scheduled todos" future)
697 (const :tag "Ignore past- or present-scheduled todos" past)
698 (const :tag "Ignore all scheduled todos" all)
699 (const :tag "Ignore all scheduled todos (compatibility)" t)
700 (const :tag "Show scheduled todos" nil)
701 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
703 (defcustom org-agenda-todo-ignore-deadlines nil
704 "Non-nil means ignore some deadlined TODO items when making TODO list.
705 There are different motivations for using different values, please think
706 carefully when configuring this variable.
708 This applies when creating the global todo list.
709 Valid values are:
711 near Don't show near deadline entries. A deadline is near when it is
712 closer than `org-deadline-warning-days' days. The idea behind this
713 is that such items will appear in the agenda anyway.
715 far Don't show TODO entries where a deadline has been defined, but
716 the deadline is not near. This is useful if you don't want to
717 use the todo list to figure out what to do now.
719 past Don't show entries with a deadline timestamp for today or in the past.
721 future Don't show entries with a deadline timestamp in the future, not even
722 when they become `near' ones. Use it with caution.
724 all Ignore all TODO entries that do have a deadline.
726 t Same as `near', for backward compatibility.
728 This variable can also have an integer as a value. See
729 `org-agenda-todo-ignore-timestamp' for more details.
731 See also `org-agenda-todo-ignore-with-date'.
732 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
733 to make his option also apply to the tags-todo list."
734 :group 'org-agenda-skip
735 :group 'org-agenda-todo-list
736 :type '(choice
737 (const :tag "Ignore near deadlines" near)
738 (const :tag "Ignore near deadlines (compatibility)" t)
739 (const :tag "Ignore far deadlines" far)
740 (const :tag "Ignore all TODOs with a deadlines" all)
741 (const :tag "Show all TODOs, even if they have a deadline" nil)
742 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
744 (defcustom org-agenda-tags-todo-honor-ignore-options nil
745 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
746 The variables
747 `org-agenda-todo-ignore-with-date',
748 `org-agenda-todo-ignore-timestamp',
749 `org-agenda-todo-ignore-scheduled',
750 `org-agenda-todo-ignore-deadlines'
751 make the global TODO list skip entries that have time stamps of certain
752 kinds. If this option is set, the same options will also apply for the
753 tags-todo search, which is the general tags/property matcher
754 restricted to unfinished TODO entries only."
755 :group 'org-agenda-skip
756 :group 'org-agenda-todo-list
757 :group 'org-agenda-match-view
758 :type 'boolean)
760 (defcustom org-agenda-skip-scheduled-if-done nil
761 "Non-nil means don't show scheduled items in agenda when they are done.
762 This is relevant for the daily/weekly agenda, not for the TODO list. And
763 it applies only to the actual date of the scheduling. Warnings about
764 an item with a past scheduling dates are always turned off when the item
765 is DONE."
766 :group 'org-agenda-skip
767 :group 'org-agenda-daily/weekly
768 :type 'boolean)
770 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
771 "Non-nil means skip scheduling line if same entry shows because of deadline.
772 In the agenda of today, an entry can show up multiple times because
773 it is both scheduled and has a nearby deadline, and maybe a plain time
774 stamp as well.
775 When this variable is t, then only the deadline is shown and the fact that
776 the entry is scheduled today or was scheduled previously is not shown.
777 When this variable is nil, the entry will be shown several times. When
778 the variable is the symbol `not-today', then skip scheduled previously,
779 but not scheduled today."
780 :group 'org-agenda-skip
781 :group 'org-agenda-daily/weekly
782 :type '(choice
783 (const :tag "Never" nil)
784 (const :tag "Always" t)
785 (const :tag "Not when scheduled today" not-today)))
787 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
788 "Non-nil means skip timestamp line if same entry shows because of deadline.
789 In the agenda of today, an entry can show up multiple times
790 because it has both a plain timestamp and has a nearby deadline.
791 When this variable is t, then only the deadline is shown and the
792 fact that the entry has a timestamp for or including today is not
793 shown. When this variable is nil, the entry will be shown
794 several times."
795 :group 'org-agenda-skip
796 :group 'org-agenda-daily/weekly
797 :version "24.1"
798 :type '(choice
799 (const :tag "Never" nil)
800 (const :tag "Always" t)))
802 (defcustom org-agenda-skip-deadline-if-done nil
803 "Non-nil means don't show deadlines when the corresponding item is done.
804 When nil, the deadline is still shown and should give you a happy feeling.
805 This is relevant for the daily/weekly agenda. And it applied only to the
806 actually date of the deadline. Warnings about approaching and past-due
807 deadlines are always turned off when the item is DONE."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :type 'boolean)
812 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
813 "Non-nil means skip deadline prewarning when entry is also scheduled.
814 This will apply on all days where a prewarning for the deadline would
815 be shown, but not at the day when the entry is actually due. On that day,
816 the deadline will be shown anyway.
817 This variable may be set to nil, t, or a number which will then give
818 the number of days before the actual deadline when the prewarnings
819 should resume.
820 This can be used in a workflow where the first showing of the deadline will
821 trigger you to schedule it, and then you don't want to be reminded of it
822 because you will take care of it on the day when scheduled."
823 :group 'org-agenda-skip
824 :group 'org-agenda-daily/weekly
825 :version "24.1"
826 :type '(choice
827 (const :tag "Alwas show prewarning" nil)
828 (const :tag "Remove prewarning if entry is scheduled" t)
829 (integer :tag "Restart prewarning N days before deadline")))
831 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
832 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
833 When non-nil, after the search for timestamps has matched once in an
834 entry, the rest of the entry will not be searched."
835 :group 'org-agenda-skip
836 :type 'boolean)
838 (defcustom org-agenda-skip-timestamp-if-done nil
839 "Non-nil means don't select item by timestamp or -range if it is DONE."
840 :group 'org-agenda-skip
841 :group 'org-agenda-daily/weekly
842 :type 'boolean)
844 (defcustom org-agenda-dim-blocked-tasks t
845 "Non-nil means dim blocked tasks in the agenda display.
846 This causes some overhead during agenda construction, but if you
847 have turned on `org-enforce-todo-dependencies',
848 `org-enforce-todo-checkbox-dependencies', or any other blocking
849 mechanism, this will create useful feedback in the agenda.
851 Instead of t, this variable can also have the value `invisible'.
852 Then blocked tasks will be invisible and only become visible when
853 they become unblocked. An exemption to this behavior is when a task is
854 blocked because of unchecked checkboxes below it. Since checkboxes do
855 not show up in the agenda views, making this task invisible you remove any
856 trace from agenda views that there is something to do. Therefore, a task
857 that is blocked because of checkboxes will never be made invisible, it
858 will only be dimmed."
859 :group 'org-agenda-daily/weekly
860 :group 'org-agenda-todo-list
861 :type '(choice
862 (const :tag "Do not dim" nil)
863 (const :tag "Dim to a gray face" t)
864 (const :tag "Make invisible" invisible)))
866 (defcustom org-timeline-show-empty-dates 3
867 "Non-nil means `org-timeline' also shows dates without an entry.
868 When nil, only the days which actually have entries are shown.
869 When t, all days between the first and the last date are shown.
870 When an integer, show also empty dates, but if there is a gap of more than
871 N days, just insert a special line indicating the size of the gap."
872 :group 'org-agenda-skip
873 :type '(choice
874 (const :tag "None" nil)
875 (const :tag "All" t)
876 (integer :tag "at most")))
878 (defgroup org-agenda-startup nil
879 "Options concerning initial settings in the Agenda in Org Mode."
880 :tag "Org Agenda Startup"
881 :group 'org-agenda)
883 (defcustom org-agenda-menu-show-matcher t
884 "Non-nil means show the match string in the agenda dispatcher menu.
885 When nil, the matcher string is not shown, but is put into the help-echo
886 property so than moving the mouse over the command shows it.
887 Setting it to nil is good if matcher strings are very long and/or if
888 you want to use two-columns display (see `org-agenda-menu-two-columns')."
889 :group 'org-agenda
890 :version "24.1"
891 :type 'boolean)
893 (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
895 (defcustom org-agenda-menu-two-columns nil
896 "Non-nil means, use two columns to show custom commands in the dispatcher.
897 If you use this, you probably want to set `org-agenda-menu-show-matcher'
898 to nil."
899 :group 'org-agenda
900 :version "24.1"
901 :type 'boolean)
903 (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
904 (defcustom org-agenda-finalize-hook nil
905 "Hook run just before displaying an agenda buffer."
906 :group 'org-agenda-startup
907 :type 'hook)
909 (defcustom org-agenda-mouse-1-follows-link nil
910 "Non-nil means mouse-1 on a link will follow the link in the agenda.
911 A longer mouse click will still set point. Does not work on XEmacs.
912 Needs to be set before org.el is loaded."
913 :group 'org-agenda-startup
914 :type 'boolean)
916 (defcustom org-agenda-start-with-follow-mode nil
917 "The initial value of follow mode in a newly created agenda window."
918 :group 'org-agenda-startup
919 :type 'boolean)
921 (defcustom org-agenda-follow-indirect nil
922 "Non-nil means `org-agenda-follow-mode' displays only the
923 current item's tree, in an indirect buffer."
924 :group 'org-agenda
925 :version "24.1"
926 :type 'boolean)
928 (defcustom org-agenda-show-outline-path t
929 "Non-nil means show outline path in echo area after line motion."
930 :group 'org-agenda-startup
931 :type 'boolean)
933 (defcustom org-agenda-start-with-entry-text-mode nil
934 "The initial value of entry-text-mode in a newly created agenda window."
935 :group 'org-agenda-startup
936 :type 'boolean)
938 (defcustom org-agenda-entry-text-maxlines 5
939 "Number of text lines to be added when `E' is pressed in the agenda.
941 Note that this variable only used during agenda display. Add add entry text
942 when exporting the agenda, configure the variable
943 `org-agenda-add-entry-ext-maxlines'."
944 :group 'org-agenda
945 :type 'integer)
947 (defcustom org-agenda-entry-text-exclude-regexps nil
948 "List of regular expressions to clean up entry text.
949 The complete matches of all regular expressions in this list will be
950 removed from entry text before it is shown in the agenda."
951 :group 'org-agenda
952 :type '(repeat (regexp)))
954 (defvar org-agenda-entry-text-cleanup-hook nil
955 "Hook that is run after basic cleanup of entry text to be shown in agenda.
956 This cleanup is done in a temporary buffer, so the function may inspect and
957 change the entire buffer.
958 Some default stuff like drawers and scheduling/deadline dates will already
959 have been removed when this is called, as will any matches for regular
960 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
962 (defvar org-agenda-include-inactive-timestamps nil
963 "Non-nil means include inactive time stamps in agenda and timeline.
964 Dynamically scoped.")
966 (defgroup org-agenda-windows nil
967 "Options concerning the windows used by the Agenda in Org Mode."
968 :tag "Org Agenda Windows"
969 :group 'org-agenda)
971 (defcustom org-agenda-window-setup 'reorganize-frame
972 "How the agenda buffer should be displayed.
973 Possible values for this option are:
975 current-window Show agenda in the current window, keeping all other windows.
976 other-window Use `switch-to-buffer-other-window' to display agenda.
977 reorganize-frame Show only two windows on the current frame, the current
978 window and the agenda.
979 other-frame Use `switch-to-buffer-other-frame' to display agenda.
980 Also, when exiting the agenda, kill that frame.
981 See also the variable `org-agenda-restore-windows-after-quit'."
982 :group 'org-agenda-windows
983 :type '(choice
984 (const current-window)
985 (const other-frame)
986 (const other-window)
987 (const reorganize-frame)))
989 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
990 "The min and max height of the agenda window as a fraction of frame height.
991 The value of the variable is a cons cell with two numbers between 0 and 1.
992 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
993 :group 'org-agenda-windows
994 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
996 (defcustom org-agenda-restore-windows-after-quit nil
997 "Non-nil means restore window configuration upon exiting agenda.
998 Before the window configuration is changed for displaying the agenda,
999 the current status is recorded. When the agenda is exited with
1000 `q' or `x' and this option is set, the old state is restored. If
1001 `org-agenda-window-setup' is `other-frame', the value of this
1002 option will be ignored."
1003 :group 'org-agenda-windows
1004 :type 'boolean)
1006 (defcustom org-agenda-ndays nil
1007 "Number of days to include in overview display.
1008 Should be 1 or 7.
1009 Obsolete, see `org-agenda-span'."
1010 :group 'org-agenda-daily/weekly
1011 :type 'integer)
1013 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1015 (defcustom org-agenda-span 'week
1016 "Number of days to include in overview display.
1017 Can be day, week, month, year, or any number of days.
1018 Custom commands can set this variable in the options section."
1019 :group 'org-agenda-daily/weekly
1020 :type '(choice (const :tag "Day" day)
1021 (const :tag "Week" week)
1022 (const :tag "Month" month)
1023 (const :tag "Year" year)
1024 (integer :tag "Custom")))
1026 (defcustom org-agenda-start-on-weekday 1
1027 "Non-nil means start the overview always on the specified weekday.
1028 0 denotes Sunday, 1 denotes Monday etc.
1029 When nil, always start on the current day.
1030 Custom commands can set this variable in the options section."
1031 :group 'org-agenda-daily/weekly
1032 :type '(choice (const :tag "Today" nil)
1033 (integer :tag "Weekday No.")))
1035 (defcustom org-agenda-show-all-dates t
1036 "Non-nil means `org-agenda' shows every day in the selected range.
1037 When nil, only the days which actually have entries are shown."
1038 :group 'org-agenda-daily/weekly
1039 :type 'boolean)
1041 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1042 "Format string for displaying dates in the agenda.
1043 Used by the daily/weekly agenda and by the timeline. This should be
1044 a format string understood by `format-time-string', or a function returning
1045 the formatted date as a string. The function must take a single argument,
1046 a calendar-style date list like (month day year)."
1047 :group 'org-agenda-daily/weekly
1048 :type '(choice
1049 (string :tag "Format string")
1050 (function :tag "Function")))
1052 (defun org-agenda-format-date-aligned (date)
1053 "Format a date string for display in the daily/weekly agenda, or timeline.
1054 This function makes sure that dates are aligned for easy reading."
1055 (require 'cal-iso)
1056 (let* ((dayname (calendar-day-name date))
1057 (day (cadr date))
1058 (day-of-week (calendar-day-of-week date))
1059 (month (car date))
1060 (monthname (calendar-month-name month))
1061 (year (nth 2 date))
1062 (iso-week (org-days-to-iso-week
1063 (calendar-absolute-from-gregorian date)))
1064 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1065 (1- year))
1066 ((and (= month 12) (<= iso-week 1))
1067 (1+ year))
1068 (t year)))
1069 (weekstring (if (= day-of-week 1)
1070 (format " W%02d" iso-week)
1071 "")))
1072 (format "%-10s %2d %s %4d%s"
1073 dayname day monthname year weekstring)))
1075 (defcustom org-agenda-time-leading-zero nil
1076 "Non-nil means use leading zero for military times in agenda.
1077 For example, 9:30am would become 09:30 rather than 9:30."
1078 :group 'org-agenda-daily/weekly
1079 :version "24.1"
1080 :type 'boolean)
1082 (defcustom org-agenda-timegrid-use-ampm nil
1083 "When set, show AM/PM style timestamps on the timegrid."
1084 :group 'org-agenda
1085 :version "24.1"
1086 :type 'boolean)
1088 (defun org-agenda-time-of-day-to-ampm (time)
1089 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1090 (let* ((hour-number (string-to-number (substring time 0 -3)))
1091 (minute (substring time -2))
1092 (ampm "am"))
1093 (cond
1094 ((equal hour-number 12)
1095 (setq ampm "pm"))
1096 ((> hour-number 12)
1097 (setq ampm "pm")
1098 (setq hour-number (- hour-number 12))))
1099 (concat
1100 (if org-agenda-time-leading-zero
1101 (format "%02d" hour-number)
1102 (format "%02s" (number-to-string hour-number)))
1103 ":" minute ampm)))
1105 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1106 "Conditionally convert TIME to AM/PM format
1107 based on `org-agenda-timegrid-use-ampm'"
1108 (if org-agenda-timegrid-use-ampm
1109 (org-agenda-time-of-day-to-ampm time)
1110 time))
1112 (defcustom org-agenda-weekend-days '(6 0)
1113 "Which days are weekend?
1114 These days get the special face `org-agenda-date-weekend' in the agenda
1115 and timeline buffers."
1116 :group 'org-agenda-daily/weekly
1117 :type '(set :greedy t
1118 (const :tag "Monday" 1)
1119 (const :tag "Tuesday" 2)
1120 (const :tag "Wednesday" 3)
1121 (const :tag "Thursday" 4)
1122 (const :tag "Friday" 5)
1123 (const :tag "Saturday" 6)
1124 (const :tag "Sunday" 0)))
1126 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1127 "Non-nil means jump to today when moving a past date forward in time.
1128 When using S-right in the agenda to move a a date forward, and the date
1129 stamp currently points to the past, the first key press will move it
1130 to today. WHen nil, just move one day forward even if the date stays
1131 in the past."
1132 :group 'org-agenda-daily/weekly
1133 :version "24.1"
1134 :type 'boolean)
1136 (defcustom org-agenda-include-diary nil
1137 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1138 Custom commands can set this variable in the options section."
1139 :group 'org-agenda-daily/weekly
1140 :type 'boolean)
1142 (defcustom org-agenda-include-deadlines t
1143 "If non-nil, include entries within their deadline warning period.
1144 Custom commands can set this variable in the options section."
1145 :group 'org-agenda-daily/weekly
1146 :version "24.1"
1147 :type 'boolean)
1149 (defcustom org-agenda-repeating-timestamp-show-all t
1150 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1151 When set to a list of strings, only show occurrences of repeating
1152 stamps for these TODO keywords. When nil, only one occurrence is
1153 shown, either today or the nearest into the future."
1154 :group 'org-agenda-daily/weekly
1155 :type '(choice
1156 (const :tag "Show repeating stamps" t)
1157 (repeat :tag "Show repeating stamps for these TODO keywords"
1158 (string :tag "TODO Keyword"))
1159 (const :tag "Don't show repeating stamps" nil)))
1161 (defcustom org-scheduled-past-days 10000
1162 "No. of days to continue listing scheduled items that are not marked DONE.
1163 When an item is scheduled on a date, it shows up in the agenda on this
1164 day and will be listed until it is marked done for the number of days
1165 given here."
1166 :group 'org-agenda-daily/weekly
1167 :type 'integer)
1169 (defcustom org-agenda-log-mode-items '(closed clock)
1170 "List of items that should be shown in agenda log mode.
1171 This list may contain the following symbols:
1173 closed Show entries that have been closed on that day.
1174 clock Show entries that have received clocked time on that day.
1175 state Show all logged state changes.
1176 Note that instead of changing this variable, you can also press `C-u l' in
1177 the agenda to display all available LOG items temporarily."
1178 :group 'org-agenda-daily/weekly
1179 :type '(set :greedy t (const closed) (const clock) (const state)))
1181 (defcustom org-agenda-clock-consistency-checks
1182 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1183 :gap-ok-around ("4:00")
1184 :default-face ((:background "DarkRed") (:foreground "white"))
1185 :overlap-face nil :gap-face nil :no-end-time-face nil
1186 :long-face nil :short-face nil)
1187 "This is a property list, with the following keys:
1189 :max-duration Mark clocking chunks that are longer than this time.
1190 This is a time string like \"HH:MM\", or the number
1191 of minutes as an integer.
1193 :min-duration Mark clocking chunks that are shorter that this.
1194 This is a time string like \"HH:MM\", or the number
1195 of minutes as an integer.
1197 :max-gap Mark gaps between clocking chunks that are longer than
1198 this duration. A number of minutes, or a string
1199 like \"HH:MM\".
1201 :gap-ok-around List of times during the day which are usually not working
1202 times. When a gap is detected, but the gap contains any
1203 of these times, the gap is *not* reported. For example,
1204 if this is (\"4:00\" \"13:00\") then gaps that contain
1205 4:00 in the morning (i.e. the night) and 13:00
1206 (i.e. a typical lunch time) do not cause a warning.
1207 You should have at least one time during the night in this
1208 list, or otherwise the first task each morning will trigger
1209 a warning because it follows a long gap.
1211 Furthermore, the following properties can be used to define faces for
1212 issue display.
1214 :default-face the default face, if the specific face is undefined
1215 :overlap-face face for overlapping clocks
1216 :gap-face face for gaps between clocks
1217 :no-end-time-face face for incomplete clocks
1218 :long-face face for clock intervals that are too long
1219 :short-face face for clock intervals that are too short"
1220 :group 'org-agenda-daily/weekly
1221 :group 'org-clock
1222 :version "24.1"
1223 :type 'plist)
1225 (defcustom org-agenda-log-mode-add-notes t
1226 "Non-nil means add first line of notes to log entries in agenda views.
1227 If a log item like a state change or a clock entry is associated with
1228 notes, the first line of these notes will be added to the entry in the
1229 agenda display."
1230 :group 'org-agenda-daily/weekly
1231 :type 'boolean)
1233 (defcustom org-agenda-start-with-log-mode nil
1234 "The initial value of log-mode in a newly created agenda window.
1235 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1236 explanations on the possible values."
1237 :group 'org-agenda-startup
1238 :group 'org-agenda-daily/weekly
1239 :type '(choice (const :tag "Don't show log items" nil)
1240 (const :tag "Show only log items" 'only)
1241 (const :tag "Show all possible log items" 'clockcheck)
1242 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1243 (choice (const :tag "Show closed log items" 'closed)
1244 (const :tag "Show clocked log items" 'clock)
1245 (const :tag "Show all logged state changes" 'state)))))
1247 (defcustom org-agenda-start-with-clockreport-mode nil
1248 "The initial value of clockreport-mode in a newly created agenda window."
1249 :group 'org-agenda-startup
1250 :group 'org-agenda-daily/weekly
1251 :type 'boolean)
1253 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1254 "Property list with parameters for the clocktable in clockreport mode.
1255 This is the display mode that shows a clock table in the daily/weekly
1256 agenda, the properties for this dynamic block can be set here.
1257 The usual clocktable parameters are allowed here, but you cannot set
1258 the properties :name, :tstart, :tend, :block, and :scope - these will
1259 be overwritten to make sure the content accurately reflects the
1260 current display in the agenda."
1261 :group 'org-agenda-daily/weekly
1262 :type 'plist)
1264 (defcustom org-agenda-search-view-always-boolean nil
1265 "Non-nil means the search string is interpreted as individual parts.
1267 The search string for search view can either be interpreted as a phrase,
1268 or as a list of snippets that define a boolean search for a number of
1269 strings.
1271 When this is non-nil, the string will be split on whitespace, and each
1272 snippet will be searched individually, and all must match in order to
1273 select an entry. A snippet is then a single string of non-white
1274 characters, or a string in double quotes, or a regexp in {} braces.
1275 If a snippet is preceded by \"-\", the snippet must *not* match.
1276 \"+\" is syntactic sugar for positive selection. Each snippet may
1277 be found as a full word or a partial word, but see the variable
1278 `org-agenda-search-view-force-full-words'.
1280 When this is nil, search will look for the entire search phrase as one,
1281 with each space character matching any amount of whitespace, including
1282 line breaks.
1284 Even when this is nil, you can still switch to Boolean search dynamically
1285 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1286 is a regexp marked with braces like \"{abc}\", this will also switch to
1287 boolean search."
1288 :group 'org-agenda-search-view
1289 :version "24.1"
1290 :type 'boolean)
1292 (if (fboundp 'defvaralias)
1293 (defvaralias 'org-agenda-search-view-search-words-only
1294 'org-agenda-search-view-always-boolean))
1296 (defcustom org-agenda-search-view-force-full-words nil
1297 "Non-nil means, search words must be matches as complete words.
1298 When nil, they may also match part of a word."
1299 :group 'org-agenda-search-view
1300 :version "24.1"
1301 :type 'boolean)
1303 (defgroup org-agenda-time-grid nil
1304 "Options concerning the time grid in the Org-mode Agenda."
1305 :tag "Org Agenda Time Grid"
1306 :group 'org-agenda)
1308 (defcustom org-agenda-search-headline-for-time t
1309 "Non-nil means search headline for a time-of-day.
1310 If the headline contains a time-of-day in one format or another, it will
1311 be used to sort the entry into the time sequence of items for a day.
1312 Some people have time stamps in the headline that refer to the creation
1313 time or so, and then this produces an unwanted side effect. If this is
1314 the case for your, use this variable to turn off searching the headline
1315 for a time."
1316 :group 'org-agenda-time-grid
1317 :type 'boolean)
1319 (defcustom org-agenda-use-time-grid t
1320 "Non-nil means show a time grid in the agenda schedule.
1321 A time grid is a set of lines for specific times (like every two hours between
1322 8:00 and 20:00). The items scheduled for a day at specific times are
1323 sorted in between these lines.
1324 For details about when the grid will be shown, and what it will look like, see
1325 the variable `org-agenda-time-grid'."
1326 :group 'org-agenda-time-grid
1327 :type 'boolean)
1329 (defcustom org-agenda-time-grid
1330 '((daily today require-timed)
1331 "----------------"
1332 (800 1000 1200 1400 1600 1800 2000))
1334 "The settings for time grid for agenda display.
1335 This is a list of three items. The first item is again a list. It contains
1336 symbols specifying conditions when the grid should be displayed:
1338 daily if the agenda shows a single day
1339 weekly if the agenda shows an entire week
1340 today show grid on current date, independent of daily/weekly display
1341 require-timed show grid only if at least one item has a time specification
1343 The second item is a string which will be placed behind the grid time.
1345 The third item is a list of integers, indicating the times that should have
1346 a grid line."
1347 :group 'org-agenda-time-grid
1348 :type
1349 '(list
1350 (set :greedy t :tag "Grid Display Options"
1351 (const :tag "Show grid in single day agenda display" daily)
1352 (const :tag "Show grid in weekly agenda display" weekly)
1353 (const :tag "Always show grid for today" today)
1354 (const :tag "Show grid only if any timed entries are present"
1355 require-timed)
1356 (const :tag "Skip grid times already present in an entry"
1357 remove-match))
1358 (string :tag "Grid String")
1359 (repeat :tag "Grid Times" (integer :tag "Time"))))
1361 (defcustom org-agenda-show-current-time-in-grid t
1362 "Non-nil means show the current time in the time grid."
1363 :group 'org-agenda-time-grid
1364 :version "24.1"
1365 :type 'boolean)
1367 (defcustom org-agenda-current-time-string
1368 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1369 "The string for the current time marker in the agenda."
1370 :group 'org-agenda-time-grid
1371 :version "24.1"
1372 :type 'string)
1374 (defgroup org-agenda-sorting nil
1375 "Options concerning sorting in the Org-mode Agenda."
1376 :tag "Org Agenda Sorting"
1377 :group 'org-agenda)
1379 (defcustom org-agenda-sorting-strategy
1380 '((agenda habit-down time-up priority-down category-keep)
1381 (todo priority-down category-keep)
1382 (tags priority-down category-keep)
1383 (search category-keep))
1384 "Sorting structure for the agenda items of a single day.
1385 This is a list of symbols which will be used in sequence to determine
1386 if an entry should be listed before another entry. The following
1387 symbols are recognized:
1389 time-up Put entries with time-of-day indications first, early first
1390 time-down Put entries with time-of-day indications first, late first
1391 category-keep Keep the default order of categories, corresponding to the
1392 sequence in `org-agenda-files'.
1393 category-up Sort alphabetically by category, A-Z.
1394 category-down Sort alphabetically by category, Z-A.
1395 tag-up Sort alphabetically by last tag, A-Z.
1396 tag-down Sort alphabetically by last tag, Z-A.
1397 priority-up Sort numerically by priority, high priority last.
1398 priority-down Sort numerically by priority, high priority first.
1399 todo-state-up Sort by todo state, tasks that are done last.
1400 todo-state-down Sort by todo state, tasks that are done first.
1401 effort-up Sort numerically by estimated effort, high effort last.
1402 effort-down Sort numerically by estimated effort, high effort first.
1403 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1404 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1405 habit-up Put entries that are habits first
1406 habit-down Put entries that are habits last
1407 alpha-up Sort headlines alphabetically
1408 alpha-down Sort headlines alphabetically, reversed
1410 The different possibilities will be tried in sequence, and testing stops
1411 if one comparison returns a \"not-equal\". For example, the default
1412 '(time-up category-keep priority-down)
1413 means: Pull out all entries having a specified time of day and sort them,
1414 in order to make a time schedule for the current day the first thing in the
1415 agenda listing for the day. Of the entries without a time indication, keep
1416 the grouped in categories, don't sort the categories, but keep them in
1417 the sequence given in `org-agenda-files'. Within each category sort by
1418 priority.
1420 Leaving out `category-keep' would mean that items will be sorted across
1421 categories by priority.
1423 Instead of a single list, this can also be a set of list for specific
1424 contents, with a context symbol in the car of the list, any of
1425 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1427 Custom commands can bind this variable in the options section."
1428 :group 'org-agenda-sorting
1429 :type `(choice
1430 (repeat :tag "General" ,org-sorting-choice)
1431 (list :tag "Individually"
1432 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1433 (repeat ,org-sorting-choice))
1434 (cons (const :tag "Strategy for TODO lists" todo)
1435 (repeat ,org-sorting-choice))
1436 (cons (const :tag "Strategy for Tags matches" tags)
1437 (repeat ,org-sorting-choice))
1438 (cons (const :tag "Strategy for search matches" search)
1439 (repeat ,org-sorting-choice)))))
1441 (defcustom org-agenda-cmp-user-defined nil
1442 "A function to define the comparison `user-defined'.
1443 This function must receive two arguments, agenda entry a and b.
1444 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1445 the user comparison, return nil.
1446 When this is defined, you can make `user-defined-up' and `user-defined-down'
1447 part of an agenda sorting strategy."
1448 :group 'org-agenda-sorting
1449 :type 'symbol)
1451 (defcustom org-sort-agenda-notime-is-late t
1452 "Non-nil means items without time are considered late.
1453 This is only relevant for sorting. When t, items which have no explicit
1454 time like 15:30 will be considered as 99:01, i.e. later than any items which
1455 do have a time. When nil, the default time is before 0:00. You can use this
1456 option to decide if the schedule for today should come before or after timeless
1457 agenda entries."
1458 :group 'org-agenda-sorting
1459 :type 'boolean)
1461 (defcustom org-sort-agenda-noeffort-is-high t
1462 "Non-nil means items without effort estimate are sorted as high effort.
1463 This also applies when filtering an agenda view with respect to the
1464 < or > effort operator. Then, tasks with no effort defined will be treated
1465 as tasks with high effort.
1466 When nil, such items are sorted as 0 minutes effort."
1467 :group 'org-agenda-sorting
1468 :type 'boolean)
1470 (defgroup org-agenda-line-format nil
1471 "Options concerning the entry prefix in the Org-mode agenda display."
1472 :tag "Org Agenda Line Format"
1473 :group 'org-agenda)
1475 (defcustom org-agenda-prefix-format
1476 '((agenda . " %i %-12:c%?-12t% s")
1477 (timeline . " % s")
1478 (todo . " %i %-12:c")
1479 (tags . " %i %-12:c")
1480 (search . " %i %-12:c"))
1481 "Format specifications for the prefix of items in the agenda views.
1482 An alist with five entries, each for the different agenda types. The
1483 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1484 The values are format strings.
1486 This format works similar to a printf format, with the following meaning:
1488 %c the category of the item, \"Diary\" for entries from the diary,
1489 or as given by the CATEGORY keyword or derived from the file name
1490 %e the effort required by the item
1491 %i the icon category of the item, see `org-agenda-category-icon-alist'
1492 %T the last tag of the item (ignore inherited tags, which come first)
1493 %t the HH:MM time-of-day specification if one applies to the entry
1494 %s Scheduling/Deadline information, a short string
1495 %(expression) Eval EXPRESSION and replace the control string
1496 by the result
1498 All specifiers work basically like the standard `%s' of printf, but may
1499 contain two additional characters: a question mark just after the `%'
1500 and a whitespace/punctuation character just before the final letter.
1502 If the first character after `%' is a question mark, the entire field
1503 will only be included if the corresponding value applies to the current
1504 entry. This is useful for fields which should have fixed width when
1505 present, but zero width when absent. For example, \"%?-12t\" will
1506 result in a 12 character time field if a time of the day is specified,
1507 but will completely disappear in entries which do not contain a time.
1509 If there is punctuation or whitespace character just before the final
1510 format letter, this character will be appended to the field value if
1511 the value is not empty. For example, the format \"%-12:c\" leads to
1512 \"Diary: \" if the category is \"Diary\". If the category were be
1513 empty, no additional colon would be inserted.
1515 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1516 which means:
1518 - Indent the line with two space characters
1519 - Give the category a 12 chars wide field, padded with whitespace on
1520 the right (because of `-'). Append a colon if there is a category
1521 (because of `:').
1522 - If there is a time-of-day, put it into a 12 chars wide field. If no
1523 time, don't put in an empty field, just skip it (because of '?').
1524 - Finally, put the scheduling information.
1526 See also the variables `org-agenda-remove-times-when-in-prefix' and
1527 `org-agenda-remove-tags'.
1529 Custom commands can set this variable in the options section."
1530 :type '(choice
1531 (string :tag "General format")
1532 (list :greedy t :tag "View dependent"
1533 (cons (const agenda) (string :tag "Format"))
1534 (cons (const timeline) (string :tag "Format"))
1535 (cons (const todo) (string :tag "Format"))
1536 (cons (const tags) (string :tag "Format"))
1537 (cons (const search) (string :tag "Format"))))
1538 :group 'org-agenda-line-format)
1540 (defvar org-prefix-format-compiled nil
1541 "The compiled prefix format and associated variables.
1542 This is a list where first element is a list of variable bindings, and second
1543 element is the compiled format expression. See the variable
1544 `org-agenda-prefix-format'.")
1546 (defcustom org-agenda-todo-keyword-format "%-1s"
1547 "Format for the TODO keyword in agenda lines.
1548 Set this to something like \"%-12s\" if you want all TODO keywords
1549 to occupy a fixed space in the agenda display."
1550 :group 'org-agenda-line-format
1551 :type 'string)
1553 (defcustom org-agenda-diary-sexp-prefix nil
1554 "A regexp that matches part of a diary sexp entry
1555 which should be treated as scheduling/deadline information in
1556 `org-agenda'.
1558 For example, you can use this to extract the `diary-remind-message' from
1559 `diary-remind' entries."
1560 :group 'org-agenda-line-format
1561 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1563 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1564 "Text preceding timerange entries in the agenda view.
1565 This is a list with two strings. The first applies when the range
1566 is entirely on one day. The second applies if the range spans several days.
1567 The strings may have two \"%d\" format specifiers which will be filled
1568 with the sequence number of the days, and the total number of days in the
1569 range, respectively."
1570 :group 'org-agenda-line-format
1571 :type '(list
1572 (string :tag "Deadline today ")
1573 (choice :tag "Deadline relative"
1574 (string :tag "Format string")
1575 (function))))
1577 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1578 "Text preceding scheduled items in the agenda view.
1579 This is a list with two strings. The first applies when the item is
1580 scheduled on the current day. The second applies when it has been scheduled
1581 previously, it may contain a %d indicating that this is the nth time that
1582 this item is scheduled, due to automatic rescheduling of unfinished items
1583 for the following day. So this number is one larger than the number of days
1584 that passed since this item was scheduled first."
1585 :group 'org-agenda-line-format
1586 :type '(list
1587 (string :tag "Scheduled today ")
1588 (string :tag "Scheduled previously")))
1590 (defcustom org-agenda-inactive-leader "["
1591 "Text preceding item pulled into the agenda by inactive time stamps.
1592 These entries are added to the agenda when pressing \"[\"."
1593 :group 'org-agenda-line-format
1594 :version "24.1"
1595 :type '(list
1596 (string :tag "Scheduled today ")
1597 (string :tag "Scheduled previously")))
1599 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1600 "Text preceding deadline items in the agenda view.
1601 This is a list with two strings. The first applies when the item has its
1602 deadline on the current day. The second applies when it is in the past or
1603 in the future, it may contain %d to capture how many days away the deadline
1604 is (was)."
1605 :group 'org-agenda-line-format
1606 :type '(list
1607 (string :tag "Deadline today ")
1608 (choice :tag "Deadline relative"
1609 (string :tag "Format string")
1610 (function))))
1612 (defcustom org-agenda-remove-times-when-in-prefix t
1613 "Non-nil means remove duplicate time specifications in agenda items.
1614 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1615 time-of-day specification in a headline or diary entry is extracted and
1616 placed into the prefix. If this option is non-nil, the original specification
1617 \(a timestamp or -range, or just a plain time(range) specification like
1618 11:30-4pm) will be removed for agenda display. This makes the agenda less
1619 cluttered.
1620 The option can be t or nil. It may also be the symbol `beg', indicating
1621 that the time should only be removed when it is located at the beginning of
1622 the headline/diary entry."
1623 :group 'org-agenda-line-format
1624 :type '(choice
1625 (const :tag "Always" t)
1626 (const :tag "Never" nil)
1627 (const :tag "When at beginning of entry" beg)))
1629 (defcustom org-agenda-remove-timeranges-from-blocks nil
1630 "Non-nil means remove time ranges specifications in agenda
1631 items that span on several days."
1632 :group 'org-agenda-line-format
1633 :version "24.1"
1634 :type 'boolean)
1636 (defcustom org-agenda-default-appointment-duration nil
1637 "Default duration for appointments that only have a starting time.
1638 When nil, no duration is specified in such cases.
1639 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1640 :group 'org-agenda-line-format
1641 :type '(choice
1642 (integer :tag "Minutes")
1643 (const :tag "No default duration")))
1645 (defcustom org-agenda-show-inherited-tags t
1646 "Non-nil means show inherited tags in each agenda line."
1647 :group 'org-agenda-line-format
1648 :type 'boolean)
1650 (defcustom org-agenda-hide-tags-regexp nil
1651 "Regular expression used to filter away specific tags in agenda views.
1652 This means that these tags will be present, but not be shown in the agenda
1653 line. Secondary filtering will still work on the hidden tags.
1654 Nil means don't hide any tags."
1655 :group 'org-agenda-line-format
1656 :type '(choice
1657 (const :tag "Hide none" nil)
1658 (string :tag "Regexp ")))
1660 (defcustom org-agenda-remove-tags nil
1661 "Non-nil means remove the tags from the headline copy in the agenda.
1662 When this is the symbol `prefix', only remove tags when
1663 `org-agenda-prefix-format' contains a `%T' specifier."
1664 :group 'org-agenda-line-format
1665 :type '(choice
1666 (const :tag "Always" t)
1667 (const :tag "Never" nil)
1668 (const :tag "When prefix format contains %T" prefix)))
1670 (if (fboundp 'defvaralias)
1671 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1672 'org-agenda-remove-tags))
1674 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1675 "Shift tags in agenda items to this column.
1676 If this number is positive, it specifies the column. If it is negative,
1677 it means that the tags should be flushright to that column. For example,
1678 -80 works well for a normal 80 character screen."
1679 :group 'org-agenda-line-format
1680 :type 'integer)
1682 (if (fboundp 'defvaralias)
1683 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1685 (defcustom org-agenda-fontify-priorities 'cookies
1686 "Non-nil means highlight low and high priorities in agenda.
1687 When t, the highest priority entries are bold, lowest priority italic.
1688 However, settings in `org-priority-faces' will overrule these faces.
1689 When this variable is the symbol `cookies', only fontify the
1690 cookies, not the entire task.
1691 This may also be an association list of priority faces, whose
1692 keys are the character values of `org-highest-priority',
1693 `org-default-priority', and `org-lowest-priority' (the default values
1694 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1695 color as a string, or a list like `(:background \"Red\")'.
1696 If it is a color, the variable `org-faces-easy-properties'
1697 determines if it is a foreground or a background color."
1698 :group 'org-agenda-line-format
1699 :type '(choice
1700 (const :tag "Never" nil)
1701 (const :tag "Defaults" t)
1702 (const :tag "Cookies only" cookies)
1703 (repeat :tag "Specify"
1704 (list (character :tag "Priority" :value ?A)
1705 (choice :tag "Face "
1706 (string :tag "Color")
1707 (sexp :tag "Face"))))))
1709 (defcustom org-agenda-day-face-function nil
1710 "Function called to determine what face should be used to display a day.
1711 The only argument passed to that function is the day. It should
1712 returns a face, or nil if does not want to specify a face and let
1713 the normal rules apply."
1714 :group 'org-agenda-line-format
1715 :version "24.1"
1716 :type 'function)
1718 (defcustom org-agenda-category-icon-alist nil
1719 "Alist of category icon to be displayed in agenda views.
1721 Each entry should have the following format:
1723 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1725 Where CATEGORY-REGEXP is a regexp matching the categories where
1726 the icon should be displayed.
1727 FILE-OR-DATA either a file path or a string containing image data.
1729 The other fields can be omitted safely if not needed:
1730 TYPE indicates the image type.
1731 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1732 image data.
1733 PROPS are additional image attributes to assign to the image,
1734 like, e.g. `:ascent center'.
1736 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1738 If you want to set the display properties yourself, just put a
1739 list as second element:
1741 (CATEGORY-REGEXP (MY PROPERTY LIST))
1743 For example, to display a 16px horizontal space for Emacs
1744 category, you can use:
1746 (\"Emacs\" '(space . (:width (16))))"
1747 :group 'org-agenda-line-format
1748 :version "24.1"
1749 :type '(alist :key-type (string :tag "Regexp matching category")
1750 :value-type (choice (list :tag "Icon"
1751 (string :tag "File or data")
1752 (symbol :tag "Type")
1753 (boolean :tag "Data?")
1754 (repeat :tag "Extra image properties" :inline t symbol))
1755 (list :tag "Display properties" sexp))))
1757 (defgroup org-agenda-column-view nil
1758 "Options concerning column view in the agenda."
1759 :tag "Org Agenda Column View"
1760 :group 'org-agenda)
1762 (defcustom org-agenda-columns-show-summaries t
1763 "Non-nil means show summaries for columns displayed in the agenda view."
1764 :group 'org-agenda-column-view
1765 :type 'boolean)
1767 (defcustom org-agenda-columns-compute-summary-properties t
1768 "Non-nil means recompute all summary properties before column view.
1769 When column view in the agenda is listing properties that have a summary
1770 operator, it can go to all relevant buffers and recompute the summaries
1771 there. This can mean overhead for the agenda column view, but is necessary
1772 to have thing up to date.
1773 As a special case, a CLOCKSUM property also makes sure that the clock
1774 computations are current."
1775 :group 'org-agenda-column-view
1776 :type 'boolean)
1778 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1779 "Non-nil means the duration of an appointment will add to day effort.
1780 The property to which appointment durations will be added is the one given
1781 in the option `org-effort-property'. If an appointment does not have
1782 an end time, `org-agenda-default-appointment-duration' will be used. If that
1783 is not set, an appointment without end time will not contribute to the time
1784 estimate."
1785 :group 'org-agenda-column-view
1786 :type 'boolean)
1788 (defcustom org-agenda-auto-exclude-function nil
1789 "A function called with a tag to decide if it is filtered on '/ RET'.
1790 The sole argument to the function, which is called once for each
1791 possible tag, is a string giving the name of the tag. The
1792 function should return either nil if the tag should be included
1793 as normal, or \"-<TAG>\" to exclude the tag.
1794 Note that for the purpose of tag filtering, only the lower-case version of
1795 all tags will be considered, so that this function will only ever see
1796 the lower-case version of all tags."
1797 :group 'org-agenda
1798 :type 'function)
1800 (defcustom org-agenda-bulk-custom-functions nil
1801 "Alist of characters and custom functions for bulk actions.
1802 For example, this value makes those two functions available:
1804 '((?R set-category)
1805 (?C bulk-cut))
1807 With selected entries in an agenda buffer, `B R' will call
1808 the custom function `set-category' on the selected entries.
1809 Note that functions in this alist don't need to be quoted."
1810 :type 'alist
1811 :version "24.1"
1812 :group 'org-agenda)
1814 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1815 "Execute BODY with point at location given by `org-hd-marker' property.
1816 If STRING is non-nil, the text property will be fetched from position 0
1817 in that string. If STRING is nil, it will be fetched from the beginning
1818 of the current line."
1819 (org-with-gensyms (marker)
1820 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1821 'org-hd-marker ,string)))
1822 (with-current-buffer (marker-buffer ,marker)
1823 (save-excursion
1824 (goto-char ,marker)
1825 ,@body)))))
1826 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1828 (defun org-add-agenda-custom-command (entry)
1829 "Replace or add a command in `org-agenda-custom-commands'.
1830 This is mostly for hacking and trying a new command - once the command
1831 works you probably want to add it to `org-agenda-custom-commands' for good."
1832 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1833 (if ass
1834 (setcdr ass (cdr entry))
1835 (push entry org-agenda-custom-commands))))
1837 ;;; Define the org-agenda-mode
1839 (defvar org-agenda-mode-map (make-sparse-keymap)
1840 "Keymap for `org-agenda-mode'.")
1841 (if (fboundp 'defvaralias)
1842 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1844 (defvar org-agenda-menu) ; defined later in this file.
1845 (defvar org-agenda-restrict nil) ; defined later in this file.
1846 (defvar org-agenda-follow-mode nil)
1847 (defvar org-agenda-entry-text-mode nil)
1848 (defvar org-agenda-clockreport-mode nil)
1849 (defvar org-agenda-show-log nil)
1850 (defvar org-agenda-redo-command nil)
1851 (defvar org-agenda-query-string nil)
1852 (defvar org-agenda-mode-hook nil
1853 "Hook for `org-agenda-mode', run after the mode is turned on.")
1854 (defvar org-agenda-type nil)
1855 (defvar org-agenda-force-single-file nil)
1856 (defvar org-agenda-bulk-marked-entries nil
1857 "List of markers that refer to marked entries in the agenda.")
1859 ;;; Multiple agenda buffers support
1861 (defcustom org-agenda-sticky nil
1862 "Non-nil means agenda q key will bury agenda buffers.
1863 Agenda commands will then show existing buffer instead of generating new ones.
1864 When nil, `q' will kill the single agenda buffer."
1865 :group 'org-agenda
1866 :type 'boolean
1867 :set (lambda (var val)
1868 (if (boundp var)
1869 (org-toggle-sticky-agenda (if val 1 0))
1870 (set var val))))
1872 ;;;###autoload
1873 (defun org-toggle-sticky-agenda (&optional arg)
1874 "Toggle `org-agenda-sticky'."
1875 (interactive "P")
1876 (let ((new-value (if arg
1877 (> (prefix-numeric-value arg) 0)
1878 (not org-agenda-sticky))))
1879 (if (equal new-value org-agenda-sticky)
1880 (and (org-called-interactively-p 'interactive)
1881 (message "Sticky agenda was already %s"
1882 (if org-agenda-sticky "enabled" "disabled")))
1883 (setq org-agenda-sticky new-value)
1884 (org-agenda-kill-all-agenda-buffers)
1885 (and (org-called-interactively-p 'interactive)
1886 (message "Sticky agenda was %s"
1887 (if org-agenda-sticky "enabled" "disabled"))))))
1889 (defvar org-agenda-buffer nil
1890 "Agenda buffer currently being generated.")
1892 (defvar org-agenda-last-prefix-arg nil)
1893 (defvar org-agenda-this-buffer-name nil)
1894 (defvar org-agenda-doing-sticky-redo nil)
1895 (defvar org-agenda-this-buffer-is-sticky nil)
1897 (defconst org-agenda-local-vars
1898 '(org-agenda-this-buffer-name
1899 org-agenda-undo-list
1900 org-agenda-pending-undo-list
1901 org-agenda-follow-mode
1902 org-agenda-entry-text-mode
1903 org-agenda-clockreport-mode
1904 org-agenda-show-log
1905 org-agenda-redo-command
1906 org-agenda-query-string
1907 org-agenda-type
1908 org-agenda-bulk-marked-entries
1909 org-agenda-undo-has-started-in
1910 org-agenda-info
1911 org-agenda-tag-filter-overlays
1912 org-agenda-cat-filter-overlays
1913 org-agenda-pre-window-conf
1914 org-agenda-columns-active
1915 org-agenda-tag-filter
1916 org-agenda-category-filter
1917 org-agenda-markers
1918 org-agenda-last-search-view-search-was-boolean
1919 org-agenda-filtered-by-category
1920 org-agenda-filter-form
1921 org-agenda-show-window
1922 org-agenda-cycle-counter
1923 org-agenda-last-prefix-arg)
1924 "Variables that must be local in agenda buffers to allow multiple buffers.")
1926 (defun org-agenda-mode ()
1927 "Mode for time-sorted view on action items in Org-mode files.
1929 The following commands are available:
1931 \\{org-agenda-mode-map}"
1932 (interactive)
1933 (cond (org-agenda-doing-sticky-redo
1934 ;; Refreshing sticky agenda-buffer
1936 ;; Preserve the value of `org-agenda-local-vars' variables,
1937 ;; while letting `kill-all-local-variables' kill the rest
1938 (let ((save (buffer-local-variables)))
1939 (kill-all-local-variables)
1940 (mapc 'make-local-variable org-agenda-local-vars)
1941 (dolist (elem save)
1942 (let ((var (car elem))
1943 (val (cdr elem)))
1944 (when (and val
1945 (member var org-agenda-local-vars))
1946 (set var val)))))
1947 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1948 (org-agenda-sticky
1949 ;; Creating a sticky Agenda buffer for the first time
1950 (kill-all-local-variables)
1951 (mapc 'make-local-variable org-agenda-local-vars)
1952 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1954 ;; Creating a non-sticky agenda buffer
1955 (kill-all-local-variables)
1956 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1957 (setq org-agenda-undo-list nil
1958 org-agenda-pending-undo-list nil
1959 org-agenda-bulk-marked-entries nil)
1960 (setq major-mode 'org-agenda-mode)
1961 ;; Keep global-font-lock-mode from turning on font-lock-mode
1962 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1963 (setq mode-name "Org-Agenda")
1964 (use-local-map org-agenda-mode-map)
1965 (easy-menu-add org-agenda-menu)
1966 (if org-startup-truncated (setq truncate-lines t))
1967 (org-set-local 'line-move-visual nil)
1968 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1969 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1970 ;; Make sure properties are removed when copying text
1971 (make-local-variable 'filter-buffer-substring-functions)
1972 (add-hook 'filter-buffer-substring-functions
1973 (lambda (fun start end delete)
1974 (substring-no-properties (funcall fun start end delete))))
1975 (unless org-agenda-keep-modes
1976 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1977 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1978 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1979 org-agenda-show-log org-agenda-start-with-log-mode))
1981 (easy-menu-change
1982 '("Agenda") "Agenda Files"
1983 (append
1984 (list
1985 (vector
1986 (if (get 'org-agenda-files 'org-restrict)
1987 "Restricted to single file"
1988 "Edit File List")
1989 '(org-edit-agenda-file-list)
1990 (not (get 'org-agenda-files 'org-restrict)))
1991 "--")
1992 (mapcar 'org-file-menu-entry (org-agenda-files))))
1993 (org-agenda-set-mode-name)
1994 (apply
1995 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1996 (list 'org-agenda-mode-hook)))
1998 (substitute-key-definition 'undo 'org-agenda-undo
1999 org-agenda-mode-map global-map)
2000 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2001 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2002 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2003 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2004 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2005 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2006 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2007 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2008 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2009 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2010 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2011 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2012 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2013 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2014 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2015 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2016 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2017 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2018 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2019 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2020 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2021 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2022 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2023 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2024 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2025 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2026 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2027 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2028 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2029 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2030 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2031 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2032 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2033 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2034 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2035 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2036 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2037 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2038 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2039 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2040 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2041 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2042 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2043 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2044 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2046 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2047 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2048 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2049 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2050 (while l (org-defkey org-agenda-mode-map
2051 (int-to-string (pop l)) 'digit-argument)))
2053 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2054 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2055 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2056 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2057 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2058 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2059 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2060 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2061 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2062 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2063 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2064 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2065 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2066 'org-clock-modify-effort-estimate)
2067 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2068 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2069 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2070 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2071 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2072 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2073 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2074 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2075 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2076 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2077 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2078 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2079 (substitute-key-definition 'next-line 'org-agenda-next-line
2080 org-agenda-mode-map global-map)
2081 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2082 org-agenda-mode-map global-map)
2083 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2084 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2085 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2086 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2087 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2088 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2089 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2090 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2091 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2092 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2093 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2094 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2095 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2096 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2097 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2098 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2099 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2100 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2101 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2102 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2103 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2104 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2105 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2106 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2107 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2108 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2109 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2110 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2111 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2112 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2114 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2115 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2116 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2117 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2118 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2119 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2120 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2121 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2122 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2123 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2124 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2125 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2127 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2128 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2129 (when org-agenda-mouse-1-follows-link
2130 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2131 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2132 '("Agenda"
2133 ("Agenda Files")
2134 "--"
2135 ("Agenda Dates"
2136 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2137 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2138 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2139 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2140 "--"
2141 ("View"
2142 ["Day View" org-agenda-day-view
2143 :active (org-agenda-check-type nil 'agenda)
2144 :style radio :selected (eq org-agenda-current-span 'day)
2145 :keys "v d (or just d)"]
2146 ["Week View" org-agenda-week-view
2147 :active (org-agenda-check-type nil 'agenda)
2148 :style radio :selected (eq org-agenda-current-span 'week)
2149 :keys "v w (or just w)"]
2150 ["Month View" org-agenda-month-view
2151 :active (org-agenda-check-type nil 'agenda)
2152 :style radio :selected (eq org-agenda-current-span 'month)
2153 :keys "v m"]
2154 ["Year View" org-agenda-year-view
2155 :active (org-agenda-check-type nil 'agenda)
2156 :style radio :selected (eq org-agenda-current-span 'year)
2157 :keys "v y"]
2158 "--"
2159 ["Include Diary" org-agenda-toggle-diary
2160 :style toggle :selected org-agenda-include-diary
2161 :active (org-agenda-check-type nil 'agenda)]
2162 ["Include Deadlines" org-agenda-toggle-deadlines
2163 :style toggle :selected org-agenda-include-deadlines
2164 :active (org-agenda-check-type nil 'agenda)]
2165 ["Use Time Grid" org-agenda-toggle-time-grid
2166 :style toggle :selected org-agenda-use-time-grid
2167 :active (org-agenda-check-type nil 'agenda)]
2168 "--"
2169 ["Show clock report" org-agenda-clockreport-mode
2170 :style toggle :selected org-agenda-clockreport-mode
2171 :active (org-agenda-check-type nil 'agenda)]
2172 ["Show some entry text" org-agenda-entry-text-mode
2173 :style toggle :selected org-agenda-entry-text-mode
2174 :active t]
2175 "--"
2176 ["Show Logbook entries" org-agenda-log-mode
2177 :style toggle :selected org-agenda-show-log
2178 :active (org-agenda-check-type nil 'agenda 'timeline)
2179 :keys "v l (or just l)"]
2180 ["Include archived trees" org-agenda-archives-mode
2181 :style toggle :selected org-agenda-archives-mode :active t
2182 :keys "v a"]
2183 ["Include archive files" (org-agenda-archives-mode t)
2184 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2185 :keys "v A"]
2186 "--"
2187 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2188 ["Write view to file" org-agenda-write t]
2189 ["Rebuild buffer" org-agenda-redo t]
2190 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2191 "--"
2192 ["Show original entry" org-agenda-show t]
2193 ["Go To (other window)" org-agenda-goto t]
2194 ["Go To (this window)" org-agenda-switch-to t]
2195 ["Capture with cursor date" org-agenda-capture t]
2196 ["Follow Mode" org-agenda-follow-mode
2197 :style toggle :selected org-agenda-follow-mode :active t]
2198 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2199 "--"
2200 ("TODO"
2201 ["Cycle TODO" org-agenda-todo t]
2202 ["Next TODO set" org-agenda-todo-nextset t]
2203 ["Previous TODO set" org-agenda-todo-previousset t]
2204 ["Add note" org-agenda-add-note t])
2205 ("Archive/Refile/Delete"
2206 ["Archive default" org-agenda-archive-default t]
2207 ["Archive default" org-agenda-archive-default-with-confirmation t]
2208 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2209 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2210 ["Archive subtree" org-agenda-archive t]
2211 "--"
2212 ["Refile" org-agenda-refile t]
2213 "--"
2214 ["Delete subtree" org-agenda-kill t])
2215 ("Bulk action"
2216 ["Mark entry" org-agenda-bulk-mark t]
2217 ["Mark all" org-agenda-bulk-mark-all t]
2218 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2219 ["Unmark entry" org-agenda-bulk-unmark t]
2220 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2221 ["Act on all marked" org-agenda-bulk-action t]
2222 "--"
2223 ("Tags and Properties"
2224 ["Show all Tags" org-agenda-show-tags t]
2225 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2226 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2227 "--"
2228 ["Column View" org-columns t])
2229 ("Deadline/Schedule"
2230 ["Schedule" org-agenda-schedule t]
2231 ["Set Deadline" org-agenda-deadline t]
2232 "--"
2233 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2234 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2235 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2236 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2237 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2238 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2239 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2240 ("Clock and Effort"
2241 ["Clock in" org-agenda-clock-in t]
2242 ["Clock out" org-agenda-clock-out t]
2243 ["Clock cancel" org-agenda-clock-cancel t]
2244 ["Goto running clock" org-clock-goto t]
2245 "--"
2246 ["Set Effort" org-agenda-set-effort t]
2247 ["Change clocked effort" org-clock-modify-effort-estimate
2248 (org-clock-is-active)])
2249 ("Priority"
2250 ["Set Priority" org-agenda-priority t]
2251 ["Increase Priority" org-agenda-priority-up t]
2252 ["Decrease Priority" org-agenda-priority-down t]
2253 ["Show Priority" org-agenda-show-priority t])
2254 ("Calendar/Diary"
2255 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2256 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2257 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2258 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2259 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2260 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2261 "--"
2262 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2263 "--"
2264 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2265 "--"
2266 ("MobileOrg"
2267 ["Push Files and Views" org-mobile-push t]
2268 ["Get Captured and Flagged" org-mobile-pull t]
2269 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2270 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2271 "--"
2272 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2273 "--"
2274 ["Quit" org-agenda-quit t]
2275 ["Exit and Release Buffers" org-agenda-exit t]
2278 ;;; Agenda undo
2280 (defvar org-agenda-allow-remote-undo t
2281 "Non-nil means allow remote undo from the agenda buffer.")
2282 (defvar org-agenda-undo-has-started-in nil
2283 "Buffers that have already seen `undo-start' in the current undo sequence.")
2285 (defun org-agenda-undo ()
2286 "Undo a remote editing step in the agenda.
2287 This undoes changes both in the agenda buffer and in the remote buffer
2288 that have been changed along."
2289 (interactive)
2290 (or org-agenda-allow-remote-undo
2291 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2292 (if (not (eq this-command last-command))
2293 (setq org-agenda-undo-has-started-in nil
2294 org-agenda-pending-undo-list org-agenda-undo-list))
2295 (if (not org-agenda-pending-undo-list)
2296 (error "No further undo information"))
2297 (let* ((entry (pop org-agenda-pending-undo-list))
2298 buf line cmd rembuf)
2299 (setq cmd (pop entry) line (pop entry))
2300 (setq rembuf (nth 2 entry))
2301 (org-with-remote-undo rembuf
2302 (while (bufferp (setq buf (pop entry)))
2303 (if (pop entry)
2304 (with-current-buffer buf
2305 (let ((last-undo-buffer buf)
2306 (inhibit-read-only t))
2307 (unless (memq buf org-agenda-undo-has-started-in)
2308 (push buf org-agenda-undo-has-started-in)
2309 (make-local-variable 'pending-undo-list)
2310 (undo-start))
2311 (while (and pending-undo-list
2312 (listp pending-undo-list)
2313 (not (car pending-undo-list)))
2314 (pop pending-undo-list))
2315 (undo-more 1))))))
2316 (org-goto-line line)
2317 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2319 (defun org-verify-change-for-undo (l1 l2)
2320 "Verify that a real change occurred between the undo lists L1 and L2."
2321 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2322 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2323 (not (eq l1 l2)))
2325 ;;; Agenda dispatch
2327 (defvar org-agenda-restrict-begin (make-marker))
2328 (defvar org-agenda-restrict-end (make-marker))
2329 (defvar org-agenda-last-dispatch-buffer nil)
2330 (defvar org-agenda-overriding-restriction nil)
2332 (defcustom org-agenda-custom-commands-contexts nil
2333 "Alist of custom agenda keys and contextual rules.
2335 For example, if you have a custom agenda command \"p\" and you
2336 want this command to be accessible only from plain text files,
2337 use this:
2339 '((\"p\" (in-file . \"\\.txt\")))
2341 Here are the available contexts definitions:
2343 in-file: command displayed only in matching files
2344 in-mode: command displayed only in matching modes
2345 not-in-file: command not displayed in matching files
2346 not-in-mode: command not displayed in matching modes
2347 [function]: a custom function taking no argument
2349 If you define several checks, the agenda command will be
2350 accessible if there is at least one valid check.
2352 You can also bind a key to another agenda custom command
2353 depending on contextual rules.
2355 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2357 Here it means: in .txt files, use \"p\" as the key for the
2358 agenda command otherwise associated with \"q\". (The command
2359 originally associated with \"q\" is not displayed to avoid
2360 duplicates.)"
2361 ;; :version "24.3"
2362 :group 'org-agenda-custom-commands
2363 :type '(repeat (list :tag "Rule"
2364 (string :tag " Agenda key")
2365 (string :tag "Replace by command")
2366 (repeat :tag "Available when"
2367 (choice
2368 (cons :tag "Condition"
2369 (choice
2370 (const :tag "In file" in-file)
2371 (const :tag "Not in file" not-in-file)
2372 (const :tag "In mode" in-mode)
2373 (const :tag "Not in mode" not-in-mode))
2374 (regexp))
2375 (function :tag "Custom function"))))))
2377 (defvar org-keys nil)
2378 (defvar org-match nil)
2379 ;;;###autoload
2380 (defun org-agenda (&optional arg org-keys restriction)
2381 "Dispatch agenda commands to collect entries to the agenda buffer.
2382 Prompts for a command to execute. Any prefix arg will be passed
2383 on to the selected command. The default selections are:
2385 a Call `org-agenda-list' to display the agenda for current day or week.
2386 t Call `org-todo-list' to display the global todo list.
2387 T Call `org-todo-list' to display the global todo list, select only
2388 entries with a specific TODO keyword (the user gets a prompt).
2389 m Call `org-tags-view' to display headlines with tags matching
2390 a condition (the user is prompted for the condition).
2391 M Like `m', but select only TODO entries, no ordinary headlines.
2392 L Create a timeline for the current buffer.
2393 e Export views to associated files.
2394 s Search entries for keywords.
2395 S Search entries for keywords, only with TODO keywords.
2396 / Multi occur across all agenda files and also files listed
2397 in `org-agenda-text-search-extra-files'.
2398 < Restrict agenda commands to buffer, subtree, or region.
2399 Press several times to get the desired effect.
2400 > Remove a previous restriction.
2401 # List \"stuck\" projects.
2402 ! Configure what \"stuck\" means.
2403 C Configure custom agenda commands.
2405 More commands can be added by configuring the variable
2406 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2407 searches can be pre-defined in this way.
2409 If the current buffer is in Org-mode and visiting a file, you can also
2410 first press `<' once to indicate that the agenda should be temporarily
2411 \(until the next use of \\[org-agenda]) restricted to the current file.
2412 Pressing `<' twice means to restrict to the current subtree or region
2413 \(if active)."
2414 (interactive "P")
2415 (catch 'exit
2416 (let* ((prefix-descriptions nil)
2417 (org-agenda-buffer-name org-agenda-buffer-name)
2418 (org-agenda-window-setup (if (equal (buffer-name)
2419 org-agenda-buffer-name)
2420 'current-window
2421 org-agenda-window-setup))
2422 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2423 (org-agenda-custom-commands
2424 ;; normalize different versions
2425 (delq nil
2426 (mapcar
2427 (lambda (x)
2428 (cond ((stringp (cdr x))
2429 (push x prefix-descriptions)
2430 nil)
2431 ((stringp (nth 1 x)) x)
2432 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2433 (t (cons (car x) (cons "" (cdr x))))))
2434 org-agenda-custom-commands)))
2435 (org-agenda-custom-commands
2436 (org-contextualize-keys
2437 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2438 (buf (current-buffer))
2439 (bfn (buffer-file-name (buffer-base-buffer)))
2440 entry key type org-match lprops ans)
2441 ;; Turn off restriction unless there is an overriding one,
2442 (unless org-agenda-overriding-restriction
2443 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2444 ;; There is a request to keep the file list in place
2445 (put 'org-agenda-files 'org-restrict nil))
2446 (setq org-agenda-restrict nil)
2447 (move-marker org-agenda-restrict-begin nil)
2448 (move-marker org-agenda-restrict-end nil))
2449 ;; Delete old local properties
2450 (put 'org-agenda-redo-command 'org-lprops nil)
2451 ;; Delete previously set last-arguments
2452 (put 'org-agenda-redo-command 'last-args nil)
2453 ;; Remember where this call originated
2454 (setq org-agenda-last-dispatch-buffer (current-buffer))
2455 (unless org-keys
2456 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2457 org-keys (car ans)
2458 restriction (cdr ans)))
2459 ;; If we have sticky agenda buffers, set a name for the buffer,
2460 ;; depending on the invoking keys. The user may still set this
2461 ;; as a command option, which will overwrite what we do here.
2462 (if org-agenda-sticky
2463 (setq org-agenda-buffer-name
2464 (format "*Org Agenda(%s)*" org-keys)))
2465 ;; Establish the restriction, if any
2466 (when (and (not org-agenda-overriding-restriction) restriction)
2467 (put 'org-agenda-files 'org-restrict (list bfn))
2468 (cond
2469 ((eq restriction 'region)
2470 (setq org-agenda-restrict t)
2471 (move-marker org-agenda-restrict-begin (region-beginning))
2472 (move-marker org-agenda-restrict-end (region-end)))
2473 ((eq restriction 'subtree)
2474 (save-excursion
2475 (setq org-agenda-restrict t)
2476 (org-back-to-heading t)
2477 (move-marker org-agenda-restrict-begin (point))
2478 (move-marker org-agenda-restrict-end
2479 (progn (org-end-of-subtree t)))))))
2481 ;; For example the todo list should not need it (but does...)
2482 (cond
2483 ((setq entry (assoc org-keys org-agenda-custom-commands))
2484 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2485 (progn
2486 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2487 lprops (nth 4 entry))
2488 (if org-agenda-sticky
2489 (setq org-agenda-buffer-name
2490 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2491 (format "*Org Agenda(%s)*" org-keys))))
2492 (put 'org-agenda-redo-command 'org-lprops lprops)
2493 (cond
2494 ((eq type 'agenda)
2495 (org-let lprops '(org-agenda-list current-prefix-arg)))
2496 ((eq type 'alltodo)
2497 (org-let lprops '(org-todo-list current-prefix-arg)))
2498 ((eq type 'search)
2499 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2500 ((eq type 'stuck)
2501 (org-let lprops '(org-agenda-list-stuck-projects
2502 current-prefix-arg)))
2503 ((eq type 'tags)
2504 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2505 ((eq type 'tags-todo)
2506 (org-let lprops '(org-tags-view '(4) org-match)))
2507 ((eq type 'todo)
2508 (org-let lprops '(org-todo-list org-match)))
2509 ((eq type 'tags-tree)
2510 (org-check-for-org-mode)
2511 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2512 ((eq type 'todo-tree)
2513 (org-check-for-org-mode)
2514 (org-let lprops
2515 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2516 (regexp-quote org-match) "\\>"))))
2517 ((eq type 'occur-tree)
2518 (org-check-for-org-mode)
2519 (org-let lprops '(org-occur org-match)))
2520 ((functionp type)
2521 (org-let lprops '(funcall type org-match)))
2522 ((fboundp type)
2523 (org-let lprops '(funcall type org-match)))
2524 (t (error "Invalid custom agenda command type %s" type))))
2525 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2526 ((equal org-keys "C")
2527 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2528 (customize-variable 'org-agenda-custom-commands))
2529 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2530 ((equal org-keys "s") (call-interactively 'org-search-view))
2531 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2532 ((equal org-keys "t") (call-interactively 'org-todo-list))
2533 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2534 ((equal org-keys "m") (call-interactively 'org-tags-view))
2535 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2536 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2537 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2538 (org-add-hook
2539 'post-command-hook
2540 (lambda ()
2541 (unless (current-message)
2542 (let* ((m (org-agenda-get-any-marker))
2543 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2544 (when note
2545 (message (concat
2546 "FLAGGING-NOTE ([?] for more info): "
2547 (org-add-props
2548 (replace-regexp-in-string
2549 "\\\\n" "//"
2550 (copy-sequence note))
2551 nil 'face 'org-warning)))))))
2552 t t))
2553 ((equal org-keys "L")
2554 (unless (derived-mode-p 'org-mode)
2555 (error "This is not an Org-mode file"))
2556 (unless restriction
2557 (put 'org-agenda-files 'org-restrict (list bfn))
2558 (org-call-with-arg 'org-timeline arg)))
2559 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2560 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2561 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2562 (t (error "Invalid agenda key"))))))
2564 (defun org-agenda-append-agenda ()
2565 "Append another agenda view to the current one.
2566 This function allows interactive building of block agendas.
2567 Agenda views are separated by `org-agenda-block-separator'."
2568 (interactive)
2569 (unless (derived-mode-p 'org-agenda-mode)
2570 (error "Can only append from within agenda buffer"))
2571 (let ((org-agenda-multi t))
2572 (org-agenda)
2573 (widen)
2574 (org-agenda-finalize)
2575 (org-agenda-fit-window-to-buffer)))
2577 (defun org-agenda-normalize-custom-commands (cmds)
2578 (delq nil
2579 (mapcar
2580 (lambda (x)
2581 (cond ((stringp (cdr x)) nil)
2582 ((stringp (nth 1 x)) x)
2583 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2584 (t (cons (car x) (cons "" (cdr x))))))
2585 cmds)))
2587 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2588 "The user interface for selecting an agenda command."
2589 (catch 'exit
2590 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2591 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2592 (region-p (org-region-active-p))
2593 (custom org-agenda-custom-commands)
2594 (selstring "")
2595 restriction second-time
2596 c entry key type match prefixes rmheader header-end custom1 desc
2597 line lines left right n n1)
2598 (save-window-excursion
2599 (delete-other-windows)
2600 (org-switch-to-buffer-other-window " *Agenda Commands*")
2601 (erase-buffer)
2602 (insert (eval-when-compile
2603 (let ((header
2604 "Press key for an agenda command: < Buffer, subtree/region restriction
2605 -------------------------------- > Remove restriction
2606 a Agenda for current week or day e Export agenda views
2607 t List of all TODO entries T Entries with special TODO kwd
2608 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2609 s Search for keywords S Like s, but only TODO entries
2610 L Timeline for current buffer # List stuck projects (!=configure)
2611 / Multi-occur C Configure custom agenda commands
2612 ? Find :FLAGGED: entries * Toggle sticky agenda views
2614 (start 0))
2615 (while (string-match
2616 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2617 header start)
2618 (setq start (match-end 0))
2619 (add-text-properties (match-beginning 2) (match-end 2)
2620 '(face bold) header))
2621 header)))
2622 (setq header-end (move-marker (make-marker) (point)))
2623 (while t
2624 (setq custom1 custom)
2625 (when (eq rmheader t)
2626 (org-goto-line 1)
2627 (re-search-forward ":" nil t)
2628 (delete-region (match-end 0) (point-at-eol))
2629 (forward-char 1)
2630 (looking-at "-+")
2631 (delete-region (match-end 0) (point-at-eol))
2632 (move-marker header-end (match-end 0)))
2633 (goto-char header-end)
2634 (delete-region (point) (point-max))
2636 ;; Produce all the lines that describe custom commands and prefixes
2637 (setq lines nil)
2638 (while (setq entry (pop custom1))
2639 (setq key (car entry) desc (nth 1 entry)
2640 type (nth 2 entry)
2641 match (nth 3 entry))
2642 (if (> (length key) 1)
2643 (add-to-list 'prefixes (string-to-char key))
2644 (setq line
2645 (format
2646 "%-4s%-14s"
2647 (org-add-props (copy-sequence key)
2648 '(face bold))
2649 (cond
2650 ((string-match "\\S-" desc) desc)
2651 ((eq type 'agenda) "Agenda for current week or day")
2652 ((eq type 'alltodo) "List of all TODO entries")
2653 ((eq type 'search) "Word search")
2654 ((eq type 'stuck) "List of stuck projects")
2655 ((eq type 'todo) "TODO keyword")
2656 ((eq type 'tags) "Tags query")
2657 ((eq type 'tags-todo) "Tags (TODO)")
2658 ((eq type 'tags-tree) "Tags tree")
2659 ((eq type 'todo-tree) "TODO kwd tree")
2660 ((eq type 'occur-tree) "Occur tree")
2661 ((functionp type) (if (symbolp type)
2662 (symbol-name type)
2663 "Lambda expression"))
2664 (t "???"))))
2665 (if org-agenda-menu-show-matcher
2666 (setq line
2667 (concat line ": "
2668 (cond
2669 ((stringp match)
2670 (setq match (copy-sequence match))
2671 (org-add-props match nil 'face 'org-warning))
2672 (match
2673 (format "set of %d commands" (length match)))
2674 (t ""))))
2675 (if (org-string-nw-p match)
2676 (add-text-properties
2677 0 (length line) (list 'help-echo
2678 (concat "Matcher: "match)) line)))
2679 (push line lines)))
2680 (setq lines (nreverse lines))
2681 (when prefixes
2682 (mapc (lambda (x)
2683 (push
2684 (format "%s %s"
2685 (org-add-props (char-to-string x)
2686 nil 'face 'bold)
2687 (or (cdr (assoc (concat selstring
2688 (char-to-string x))
2689 prefix-descriptions))
2690 "Prefix key"))
2691 lines))
2692 prefixes))
2694 ;; Check if we should display in two columns
2695 (if org-agenda-menu-two-columns
2696 (progn
2697 (setq n (length lines)
2698 n1 (+ (/ n 2) (mod n 2))
2699 right (nthcdr n1 lines)
2700 left (copy-sequence lines))
2701 (setcdr (nthcdr (1- n1) left) nil))
2702 (setq left lines right nil))
2703 (while left
2704 (insert "\n" (pop left))
2705 (when right
2706 (if (< (current-column) 40)
2707 (move-to-column 40 t)
2708 (insert " "))
2709 (insert (pop right))))
2711 ;; Make the window the right size
2712 (goto-char (point-min))
2713 (if second-time
2714 (if (not (pos-visible-in-window-p (point-max)))
2715 (org-fit-window-to-buffer))
2716 (setq second-time t)
2717 (org-fit-window-to-buffer))
2719 ;; Ask for selection
2720 (message "Press key for agenda command%s:"
2721 (if (or restrict-ok org-agenda-overriding-restriction)
2722 (if org-agenda-overriding-restriction
2723 " (restriction lock active)"
2724 (if restriction
2725 (format " (restricted to %s)" restriction)
2726 " (unrestricted)"))
2727 ""))
2728 (setq c (read-char-exclusive))
2729 (message "")
2730 (cond
2731 ((assoc (char-to-string c) custom)
2732 (setq selstring (concat selstring (char-to-string c)))
2733 (throw 'exit (cons selstring restriction)))
2734 ((memq c prefixes)
2735 (setq selstring (concat selstring (char-to-string c))
2736 prefixes nil
2737 rmheader (or rmheader t)
2738 custom (delq nil (mapcar
2739 (lambda (x)
2740 (if (or (= (length (car x)) 1)
2741 (/= (string-to-char (car x)) c))
2743 (cons (substring (car x) 1) (cdr x))))
2744 custom))))
2745 ((eq c ?*)
2746 (call-interactively 'org-toggle-sticky-agenda)
2747 (sit-for 2))
2748 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2749 (message "Restriction is only possible in Org-mode buffers")
2750 (ding) (sit-for 1))
2751 ((eq c ?1)
2752 (org-agenda-remove-restriction-lock 'noupdate)
2753 (setq restriction 'buffer))
2754 ((eq c ?0)
2755 (org-agenda-remove-restriction-lock 'noupdate)
2756 (setq restriction (if region-p 'region 'subtree)))
2757 ((eq c ?<)
2758 (org-agenda-remove-restriction-lock 'noupdate)
2759 (setq restriction
2760 (cond
2761 ((eq restriction 'buffer)
2762 (if region-p 'region 'subtree))
2763 ((memq restriction '(subtree region))
2764 nil)
2765 (t 'buffer))))
2766 ((eq c ?>)
2767 (org-agenda-remove-restriction-lock 'noupdate)
2768 (setq restriction nil))
2769 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2770 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2771 ((and (> (length selstring) 0) (eq c ?\d))
2772 (delete-window)
2773 (org-agenda-get-restriction-and-command prefix-descriptions))
2775 ((equal c ?q) (error "Abort"))
2776 (t (error "Invalid key %c" c))))))))
2778 (defun org-agenda-fit-window-to-buffer ()
2779 "Fit the window to the buffer size."
2780 (and (memq org-agenda-window-setup '(reorganize-frame))
2781 (fboundp 'fit-window-to-buffer)
2782 (org-fit-window-to-buffer
2784 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2785 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2787 (defvar org-cmd nil)
2788 (defvar org-agenda-overriding-cmd nil)
2789 (defvar org-agenda-overriding-arguments nil)
2790 (defvar org-agenda-overriding-cmd-arguments nil)
2791 (defun org-agenda-run-series (name series)
2792 (org-let (nth 1 series) '(org-agenda-prepare name))
2793 ;; We need to reset agenda markers here, because when constructing a
2794 ;; block agenda, the individual blocks do not do that.
2795 (org-agenda-reset-markers)
2796 (let* ((org-agenda-multi t)
2797 (redo (list 'org-agenda-run-series name (list 'quote series)))
2798 (cmds (car series))
2799 (gprops (nth 1 series))
2800 match ;; The byte compiler incorrectly complains about this. Keep it!
2801 org-cmd type lprops)
2802 (while (setq org-cmd (pop cmds))
2803 (setq type (car org-cmd)
2804 match (eval (nth 1 org-cmd))
2805 lprops (nth 2 org-cmd))
2806 (let ((org-agenda-overriding-arguments
2807 (if (eq org-agenda-overriding-cmd org-cmd)
2808 (or org-agenda-overriding-arguments
2809 org-agenda-overriding-cmd-arguments))))
2810 (cond
2811 ((eq type 'agenda)
2812 (org-let2 gprops lprops
2813 '(call-interactively 'org-agenda-list)))
2814 ((eq type 'alltodo)
2815 (org-let2 gprops lprops
2816 '(call-interactively 'org-todo-list)))
2817 ((eq type 'search)
2818 (org-let2 gprops lprops
2819 '(org-search-view current-prefix-arg match nil)))
2820 ((eq type 'stuck)
2821 (org-let2 gprops lprops
2822 '(call-interactively 'org-agenda-list-stuck-projects)))
2823 ((eq type 'tags)
2824 (org-let2 gprops lprops
2825 '(org-tags-view current-prefix-arg match)))
2826 ((eq type 'tags-todo)
2827 (org-let2 gprops lprops
2828 '(org-tags-view '(4) match)))
2829 ((eq type 'todo)
2830 (org-let2 gprops lprops
2831 '(org-todo-list match)))
2832 ((fboundp type)
2833 (org-let2 gprops lprops
2834 '(funcall type match)))
2835 (t (error "Invalid type in command series")))))
2836 (widen)
2837 (let ((inhibit-read-only t))
2838 (add-text-properties (point-min) (point-max)
2839 `(org-serie t org-serie-redo-cmd ,redo)))
2840 (setq org-agenda-redo-command redo)
2841 (goto-char (point-min)))
2842 (org-agenda-fit-window-to-buffer)
2843 (org-let (nth 1 series) '(org-agenda-finalize)))
2845 ;;;###autoload
2846 (defmacro org-batch-agenda (cmd-key &rest parameters)
2847 "Run an agenda command in batch mode and send the result to STDOUT.
2848 If CMD-KEY is a string of length 1, it is used as a key in
2849 `org-agenda-custom-commands' and triggers this command. If it is a
2850 longer string it is used as a tags/todo match string.
2851 Parameters are alternating variable names and values that will be bound
2852 before running the agenda command."
2853 (org-eval-in-environment (org-make-parameter-alist parameters)
2854 (if (> (length cmd-key) 2)
2855 (org-tags-view nil cmd-key)
2856 (org-agenda nil cmd-key)))
2857 (set-buffer org-agenda-buffer-name)
2858 (princ (buffer-string)))
2859 (def-edebug-spec org-batch-agenda (form &rest sexp))
2861 (defvar org-agenda-info nil)
2863 ;;;###autoload
2864 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2865 "Run an agenda command in batch mode and send the result to STDOUT.
2866 If CMD-KEY is a string of length 1, it is used as a key in
2867 `org-agenda-custom-commands' and triggers this command. If it is a
2868 longer string it is used as a tags/todo match string.
2869 Parameters are alternating variable names and values that will be bound
2870 before running the agenda command.
2872 The output gives a line for each selected agenda item. Each
2873 item is a list of comma-separated values, like this:
2875 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2877 category The category of the item
2878 head The headline, without TODO kwd, TAGS and PRIORITY
2879 type The type of the agenda entry, can be
2880 todo selected in TODO match
2881 tagsmatch selected in tags match
2882 diary imported from diary
2883 deadline a deadline on given date
2884 scheduled scheduled on given date
2885 timestamp entry has timestamp on given date
2886 closed entry was closed on given date
2887 upcoming-deadline warning about deadline
2888 past-scheduled forwarded scheduled item
2889 block entry has date block including g. date
2890 todo The todo keyword, if any
2891 tags All tags including inherited ones, separated by colons
2892 date The relevant date, like 2007-2-14
2893 time The time, like 15:00-16:50
2894 extra Sting with extra planning info
2895 priority-l The priority letter if any was given
2896 priority-n The computed numerical priority
2897 agenda-day The day in the agenda where this is listed"
2898 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2899 (org-make-parameter-alist parameters))
2900 (if (> (length cmd-key) 2)
2901 (org-tags-view nil cmd-key)
2902 (org-agenda nil cmd-key)))
2903 (set-buffer org-agenda-buffer-name)
2904 (let* ((lines (org-split-string (buffer-string) "\n"))
2905 line)
2906 (while (setq line (pop lines))
2907 (catch 'next
2908 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2909 (setq org-agenda-info
2910 (org-fix-agenda-info (text-properties-at 0 line)))
2911 (princ
2912 (mapconcat 'org-agenda-export-csv-mapper
2913 '(org-category txt type todo tags date time extra
2914 priority-letter priority agenda-day)
2915 ","))
2916 (princ "\n")))))
2917 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2919 (defun org-fix-agenda-info (props)
2920 "Make sure all properties on an agenda item have a canonical form.
2921 This ensures the export commands can easily use it."
2922 (let (tmp re)
2923 (when (setq tmp (plist-get props 'tags))
2924 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2925 (when (setq tmp (plist-get props 'date))
2926 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2927 (let ((calendar-date-display-form '(year "-" month "-" day)))
2928 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2930 (setq tmp (calendar-date-string tmp)))
2931 (setq props (plist-put props 'date tmp)))
2932 (when (setq tmp (plist-get props 'day))
2933 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2934 (let ((calendar-date-display-form '(year "-" month "-" day)))
2935 (setq tmp (calendar-date-string tmp)))
2936 (setq props (plist-put props 'day tmp))
2937 (setq props (plist-put props 'agenda-day tmp)))
2938 (when (setq tmp (plist-get props 'txt))
2939 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2940 (plist-put props 'priority-letter (match-string 1 tmp))
2941 (setq tmp (replace-match "" t t tmp)))
2942 (when (and (setq re (plist-get props 'org-todo-regexp))
2943 (setq re (concat "\\`\\.*" re " ?"))
2944 (string-match re tmp))
2945 (plist-put props 'todo (match-string 1 tmp))
2946 (setq tmp (replace-match "" t t tmp)))
2947 (plist-put props 'txt tmp)))
2948 props)
2950 (defun org-agenda-export-csv-mapper (prop)
2951 (let ((res (plist-get org-agenda-info prop)))
2952 (setq res
2953 (cond
2954 ((not res) "")
2955 ((stringp res) res)
2956 (t (prin1-to-string res))))
2957 (while (string-match "," res)
2958 (setq res (replace-match ";" t t res)))
2959 (org-trim res)))
2961 ;;;###autoload
2962 (defun org-store-agenda-views (&rest parameters)
2963 (interactive)
2964 (eval (list 'org-batch-store-agenda-views)))
2966 ;;;###autoload
2967 (defmacro org-batch-store-agenda-views (&rest parameters)
2968 "Run all custom agenda commands that have a file argument."
2969 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2970 (pop-up-frames nil)
2971 (dir default-directory)
2972 (pars (org-make-parameter-alist parameters))
2973 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
2974 (save-window-excursion
2975 (while cmds
2976 (setq cmd (pop cmds)
2977 thiscmdkey (car cmd)
2978 thiscmdcmd (cdr cmd)
2979 match (nth 2 thiscmdcmd)
2980 bufname (if org-agenda-sticky
2981 (or (and (stringp match)
2982 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
2983 (format "*Org Agenda(%s)*" thiscmdkey))
2984 org-agenda-buffer-name)
2985 cmd-or-set (nth 2 cmd)
2986 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2987 files (nth (if (listp cmd-or-set) 4 5) cmd))
2988 (if (stringp files) (setq files (list files)))
2989 (when files
2990 (org-eval-in-environment (append org-agenda-exporter-settings
2991 opts pars)
2992 (org-agenda nil thiscmdkey))
2993 (set-buffer bufname)
2994 (while files
2995 (org-eval-in-environment (append org-agenda-exporter-settings
2996 opts pars)
2997 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2998 (and (get-buffer bufname)
2999 (kill-buffer bufname)))))))
3000 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3002 (defvar org-agenda-current-span nil
3003 "The current span used in the agenda view.") ; local variable in the agenda buffer
3004 (defun org-agenda-mark-header-line (pos)
3005 "Mark the line at POS as an agenda structure header."
3006 (save-excursion
3007 (goto-char pos)
3008 (put-text-property (point-at-bol) (point-at-eol)
3009 'org-agenda-structural-header t)
3010 (when org-agenda-title-append
3011 (put-text-property (point-at-bol) (point-at-eol)
3012 'org-agenda-title-append org-agenda-title-append))))
3014 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3015 (defvar org-agenda-write-buffer-name "Agenda View")
3016 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3017 "Write the current buffer (an agenda view) as a file.
3018 Depending on the extension of the file name, plain text (.txt),
3019 HTML (.html or .htm) or Postscript (.ps) is produced.
3020 If the extension is .ics, run icalendar export over all files used
3021 to construct the agenda and limit the export to entries listed in the
3022 agenda now.
3023 With prefix argument OPEN, open the new file immediately.
3024 If NOSETTINGS is given, do not scope the settings of
3025 `org-agenda-exporter-settings' into the export commands. This is used when
3026 the settings have already been scoped and we do not wish to overrule other,
3027 higher priority settings.
3028 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3029 (interactive "FWrite agenda to file: \nP")
3030 (if (not (file-writable-p file))
3031 (error "Cannot write agenda to file %s" file))
3032 (org-let (if nosettings nil org-agenda-exporter-settings)
3033 '(save-excursion
3034 (save-window-excursion
3035 (org-agenda-mark-filtered-text)
3036 (let ((bs (copy-sequence (buffer-string))) beg)
3037 (org-agenda-unmark-filtered-text)
3038 (with-temp-buffer
3039 (rename-buffer org-agenda-write-buffer-name t)
3040 (set-buffer-modified-p nil)
3041 (insert bs)
3042 (org-agenda-remove-marked-text 'org-filtered)
3043 (while (setq beg (text-property-any (point-min) (point-max)
3044 'org-filtered t))
3045 (delete-region
3046 beg (or (next-single-property-change beg 'org-filtered)
3047 (point-max))))
3048 (run-hooks 'org-agenda-before-write-hook)
3049 (cond
3050 ((org-bound-and-true-p org-mobile-creating-agendas)
3051 (org-mobile-write-agenda-for-mobile file))
3052 ((string-match "\\.html?\\'" file)
3053 (require 'htmlize)
3054 (set-buffer (htmlize-buffer (current-buffer)))
3055 (when (and org-agenda-export-html-style
3056 (string-match "<style>" org-agenda-export-html-style))
3057 ;; replace <style> section with org-agenda-export-html-style
3058 (goto-char (point-min))
3059 (kill-region (- (search-forward "<style") 6)
3060 (search-forward "</style>"))
3061 (insert org-agenda-export-html-style))
3062 (write-file file)
3063 (kill-buffer (current-buffer))
3064 (message "HTML written to %s" file))
3065 ((string-match "\\.ps\\'" file)
3066 (require 'ps-print)
3067 (ps-print-buffer-with-faces file)
3068 (message "Postscript written to %s" file))
3069 ((string-match "\\.pdf\\'" file)
3070 (require 'ps-print)
3071 (ps-print-buffer-with-faces
3072 (concat (file-name-sans-extension file) ".ps"))
3073 (call-process "ps2pdf" nil nil nil
3074 (expand-file-name
3075 (concat (file-name-sans-extension file) ".ps"))
3076 (expand-file-name file))
3077 (delete-file (concat (file-name-sans-extension file) ".ps"))
3078 (message "PDF written to %s" file))
3079 ((string-match "\\.ics\\'" file)
3080 (require 'org-icalendar)
3081 (let ((org-agenda-marker-table
3082 (org-create-marker-find-array
3083 (org-agenda-collect-markers)))
3084 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3085 (org-combined-agenda-icalendar-file file))
3086 (apply 'org-export-icalendar 'combine
3087 (org-agenda-files nil 'ifmode))))
3089 (let ((bs (buffer-string)))
3090 (find-file file)
3091 (erase-buffer)
3092 (insert bs)
3093 (save-buffer 0)
3094 (kill-buffer (current-buffer))
3095 (message "Plain text written to %s" file))))))))
3096 (set-buffer (or agenda-bufname
3097 (and (called-interactively-p 'any) (buffer-name))
3098 org-agenda-buffer-name)))
3099 (when open (org-open-file file)))
3101 (defvar org-agenda-tag-filter-overlays nil)
3102 (defvar org-agenda-cat-filter-overlays nil)
3104 (defun org-agenda-mark-filtered-text ()
3105 "Mark all text hidden by filtering with a text property."
3106 (let ((inhibit-read-only t))
3107 (mapc
3108 (lambda (o)
3109 (when (equal (overlay-buffer o) (current-buffer))
3110 (put-text-property
3111 (overlay-start o) (overlay-end o)
3112 'org-filtered t)))
3113 (append org-agenda-tag-filter-overlays
3114 org-agenda-cat-filter-overlays))))
3116 (defun org-agenda-unmark-filtered-text ()
3117 "Remove the filtering text property."
3118 (let ((inhibit-read-only t))
3119 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3121 (defun org-agenda-remove-marked-text (property &optional value)
3122 "Delete all text marked with VALUE of PROPERTY.
3123 VALUE defaults to t."
3124 (let (beg)
3125 (setq value (or value t))
3126 (while (setq beg (text-property-any (point-min) (point-max)
3127 property value))
3128 (delete-region
3129 beg (or (next-single-property-change beg 'org-filtered)
3130 (point-max))))))
3132 (defun org-agenda-add-entry-text ()
3133 "Add entry text to agenda lines.
3134 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3135 entry text following headings shown in the agenda.
3136 Drawers will be excluded, also the line with scheduling/deadline info."
3137 (when (and (> org-agenda-add-entry-text-maxlines 0)
3138 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3139 (let (m txt)
3140 (goto-char (point-min))
3141 (while (not (eobp))
3142 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3143 (beginning-of-line 2)
3144 (setq txt (org-agenda-get-some-entry-text
3145 m org-agenda-add-entry-text-maxlines " > "))
3146 (end-of-line 1)
3147 (if (string-match "\\S-" txt)
3148 (insert "\n" txt)
3149 (or (eobp) (forward-char 1))))))))
3151 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3152 &rest keep)
3153 "Extract entry text from MARKER, at most N-LINES lines.
3154 This will ignore drawers etc, just get the text.
3155 If INDENT is given, prefix every line with this string. If KEEP is
3156 given, it is a list of symbols, defining stuff that should not be
3157 removed from the entry content. Currently only `planning' is allowed here."
3158 (let (txt drawer-re kwd-time-re ind)
3159 (save-excursion
3160 (with-current-buffer (marker-buffer marker)
3161 (if (not (derived-mode-p 'org-mode))
3162 (setq txt "")
3163 (save-excursion
3164 (save-restriction
3165 (widen)
3166 (goto-char marker)
3167 (end-of-line 1)
3168 (setq txt (buffer-substring
3169 (min (1+ (point)) (point-max))
3170 (progn (outline-next-heading) (point)))
3171 drawer-re org-drawer-regexp
3172 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3173 ".*\n?"))
3174 (with-temp-buffer
3175 (insert txt)
3176 (when org-agenda-add-entry-text-descriptive-links
3177 (goto-char (point-min))
3178 (while (org-activate-bracket-links (point-max))
3179 (add-text-properties (match-beginning 0) (match-end 0)
3180 '(face org-link))))
3181 (goto-char (point-min))
3182 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3183 (set-text-properties (match-beginning 0) (match-end 0)
3184 nil))
3185 (goto-char (point-min))
3186 (while (re-search-forward drawer-re nil t)
3187 (delete-region
3188 (match-beginning 0)
3189 (progn (re-search-forward
3190 "^[ \t]*:END:.*\n?" nil 'move)
3191 (point))))
3192 (unless (member 'planning keep)
3193 (goto-char (point-min))
3194 (while (re-search-forward kwd-time-re nil t)
3195 (replace-match "")))
3196 (goto-char (point-min))
3197 (when org-agenda-entry-text-exclude-regexps
3198 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3199 (while (setq re (pop re-list))
3200 (goto-char (point-min))
3201 (while (re-search-forward re nil t)
3202 (replace-match "")))))
3203 (goto-char (point-max))
3204 (skip-chars-backward " \t\n")
3205 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3207 ;; find and remove min common indentation
3208 (goto-char (point-min))
3209 (untabify (point-min) (point-max))
3210 (setq ind (org-get-indentation))
3211 (while (not (eobp))
3212 (unless (looking-at "[ \t]*$")
3213 (setq ind (min ind (org-get-indentation))))
3214 (beginning-of-line 2))
3215 (goto-char (point-min))
3216 (while (not (eobp))
3217 (unless (looking-at "[ \t]*$")
3218 (move-to-column ind)
3219 (delete-region (point-at-bol) (point)))
3220 (beginning-of-line 2))
3222 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3224 (goto-char (point-min))
3225 (when indent
3226 (while (and (not (eobp)) (re-search-forward "^" nil t))
3227 (replace-match indent t t)))
3228 (goto-char (point-min))
3229 (while (looking-at "[ \t]*\n") (replace-match ""))
3230 (goto-char (point-max))
3231 (when (> (org-current-line)
3232 n-lines)
3233 (org-goto-line (1+ n-lines))
3234 (backward-char 1))
3235 (setq txt (buffer-substring (point-min) (point)))))))))
3236 txt))
3238 (defun org-agenda-collect-markers ()
3239 "Collect the markers pointing to entries in the agenda buffer."
3240 (let (m markers)
3241 (save-excursion
3242 (goto-char (point-min))
3243 (while (not (eobp))
3244 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3245 (org-get-at-bol 'org-marker)))
3246 (push m markers))
3247 (beginning-of-line 2)))
3248 (nreverse markers)))
3250 (defun org-create-marker-find-array (marker-list)
3251 "Create a alist of files names with all marker positions in that file."
3252 (let (f tbl m a p)
3253 (while (setq m (pop marker-list))
3254 (setq p (marker-position m)
3255 f (buffer-file-name (or (buffer-base-buffer
3256 (marker-buffer m))
3257 (marker-buffer m))))
3258 (if (setq a (assoc f tbl))
3259 (push (marker-position m) (cdr a))
3260 (push (list f p) tbl)))
3261 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3262 tbl)))
3264 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3265 (defun org-check-agenda-marker-table ()
3266 "Check of the current entry is on the marker list."
3267 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3269 (and (setq a (assoc file org-agenda-marker-table))
3270 (save-match-data
3271 (save-excursion
3272 (org-back-to-heading t)
3273 (member (point) (cdr a)))))))
3275 (defun org-check-for-org-mode ()
3276 "Make sure current buffer is in org-mode. Error if not."
3277 (or (derived-mode-p 'org-mode)
3278 (error "Cannot execute org-mode agenda command on buffer in %s"
3279 major-mode)))
3281 ;;; Agenda prepare and finalize
3283 (defvar org-agenda-multi nil) ; dynamically scoped
3284 (defvar org-agenda-pre-window-conf nil)
3285 (defvar org-agenda-columns-active nil)
3286 (defvar org-agenda-name nil)
3287 (defvar org-agenda-tag-filter nil)
3288 (defvar org-agenda-category-filter nil)
3289 (defvar org-agenda-top-category-filter nil)
3290 (defvar org-agenda-tag-filter-while-redo nil)
3291 (defvar org-agenda-tag-filter-preset nil
3292 "A preset of the tags filter used for secondary agenda filtering.
3293 This must be a list of strings, each string must be a single tag preceded
3294 by \"+\" or \"-\".
3295 This variable should not be set directly, but agenda custom commands can
3296 bind it in the options section. The preset filter is a global property of
3297 the entire agenda view. In a block agenda, it will not work reliably to
3298 define a filter for one of the individual blocks. You need to set it in
3299 the global options and expect it to be applied to the entire view.")
3301 (defvar org-agenda-category-filter-preset nil
3302 "A preset of the category filter used for secondary agenda filtering.
3303 This must be a list of strings, each string must be a single category
3304 preceded by \"+\" or \"-\".
3305 This variable should not be set directly, but agenda custom commands can
3306 bind it in the options section. The preset filter is a global property of
3307 the entire agenda view. In a block agenda, it will not work reliably to
3308 define a filter for one of the individual blocks. You need to set it in
3309 the global options and expect it to be applied to the entire view.")
3312 (defun org-agenda-use-sticky-p ()
3313 "Return non-nil if an agenda buffer named
3314 `org-agenda-buffer-name' exists and should be shown instead of
3315 generating a new one."
3316 (and
3317 ;; turned off by user
3318 org-agenda-sticky
3319 ;; For multi-agenda buffer already exists
3320 (not org-agenda-multi)
3321 ;; buffer found
3322 (get-buffer org-agenda-buffer-name)
3323 ;; C-u parameter is same as last call
3324 (with-current-buffer (get-buffer org-agenda-buffer-name)
3325 (and
3326 (equal current-prefix-arg
3327 org-agenda-last-prefix-arg)
3328 ;; In case user turned stickiness on, while having existing
3329 ;; Agenda buffer active, don't reuse that buffer, because it
3330 ;; does not have org variables local
3331 org-agenda-this-buffer-is-sticky))))
3333 (defun org-agenda-prepare-window (abuf)
3334 "Setup agenda buffer in the window."
3335 (let* ((awin (get-buffer-window abuf))
3336 wconf)
3337 (cond
3338 ((equal (current-buffer) abuf) nil)
3339 (awin (select-window awin))
3340 ((not (setq wconf (current-window-configuration))))
3341 ((equal org-agenda-window-setup 'current-window)
3342 (org-pop-to-buffer-same-window abuf))
3343 ((equal org-agenda-window-setup 'other-window)
3344 (org-switch-to-buffer-other-window abuf))
3345 ((equal org-agenda-window-setup 'other-frame)
3346 (switch-to-buffer-other-frame abuf))
3347 ((equal org-agenda-window-setup 'reorganize-frame)
3348 (delete-other-windows)
3349 (org-switch-to-buffer-other-window abuf)))
3350 ;; additional test in case agenda is invoked from within agenda
3351 ;; buffer via elisp link
3352 (unless (equal (current-buffer) abuf)
3353 (org-pop-to-buffer-same-window abuf))
3354 (setq org-agenda-pre-window-conf
3355 (or org-agenda-pre-window-conf wconf))))
3357 (defun org-agenda-prepare (&optional name)
3358 (if (org-agenda-use-sticky-p)
3359 (progn
3360 ;; Popup existing buffer
3361 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3362 (message "Sticky Agenda buffer, use `r' to refresh")
3363 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3364 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3365 (setq org-todo-keywords-for-agenda nil)
3366 (setq org-drawers-for-agenda nil)
3367 (unless org-agenda-persistent-filter
3368 (setq org-agenda-tag-filter nil
3369 org-agenda-category-filter nil))
3370 (put 'org-agenda-tag-filter :preset-filter
3371 org-agenda-tag-filter-preset)
3372 (put 'org-agenda-category-filter :preset-filter
3373 org-agenda-category-filter-preset)
3374 (if org-agenda-multi
3375 (progn
3376 (setq buffer-read-only nil)
3377 (goto-char (point-max))
3378 (unless (or (bobp) org-agenda-compact-blocks
3379 (not org-agenda-block-separator))
3380 (insert "\n"
3381 (if (stringp org-agenda-block-separator)
3382 org-agenda-block-separator
3383 (make-string (window-width) org-agenda-block-separator))
3384 "\n"))
3385 (narrow-to-region (point) (point-max)))
3386 (setq org-done-keywords-for-agenda nil)
3388 ;; Setting any org variables that are in org-agenda-local-vars
3389 ;; list need to be done after the prepare call
3390 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3391 (setq buffer-read-only nil)
3392 (org-agenda-reset-markers)
3393 (let ((inhibit-read-only t)) (erase-buffer))
3394 (org-agenda-mode)
3395 (setq org-agenda-buffer (current-buffer))
3396 (setq org-agenda-contributing-files nil)
3397 (setq org-agenda-columns-active nil)
3398 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3399 (setq org-todo-keywords-for-agenda
3400 (org-uniquify org-todo-keywords-for-agenda))
3401 (setq org-done-keywords-for-agenda
3402 (org-uniquify org-done-keywords-for-agenda))
3403 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3404 (setq org-agenda-last-prefix-arg current-prefix-arg)
3405 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3406 (and name (not org-agenda-name)
3407 (org-set-local 'org-agenda-name name)))
3408 (setq buffer-read-only nil)))
3410 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3411 (defun org-agenda-finalize ()
3412 "Finishing touch for the agenda buffer, called just before displaying it."
3413 (unless org-agenda-multi
3414 (save-excursion
3415 (let ((inhibit-read-only t))
3416 (goto-char (point-min))
3417 (while (org-activate-bracket-links (point-max))
3418 (add-text-properties (match-beginning 0) (match-end 0)
3419 '(face org-link)))
3420 (org-agenda-align-tags)
3421 (unless org-agenda-with-colors
3422 (remove-text-properties (point-min) (point-max) '(face nil))))
3423 (if (and (boundp 'org-agenda-overriding-columns-format)
3424 org-agenda-overriding-columns-format)
3425 (org-set-local 'org-agenda-overriding-columns-format
3426 org-agenda-overriding-columns-format))
3427 (if (and (boundp 'org-agenda-view-columns-initially)
3428 org-agenda-view-columns-initially)
3429 (org-agenda-columns))
3430 (when org-agenda-fontify-priorities
3431 (org-agenda-fontify-priorities))
3432 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3433 (org-agenda-dim-blocked-tasks))
3434 (org-agenda-mark-clocking-task)
3435 (when org-agenda-entry-text-mode
3436 (org-agenda-entry-text-hide)
3437 (org-agenda-entry-text-show))
3438 (if (functionp 'org-habit-insert-consistency-graphs)
3439 (org-habit-insert-consistency-graphs))
3440 (run-hooks 'org-agenda-finalize-hook)
3441 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3442 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3443 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3444 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3445 (org-agenda-filter-apply org-agenda-category-filter 'category))
3446 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3449 (defun org-agenda-mark-clocking-task ()
3450 "Mark the current clock entry in the agenda if it is present."
3451 (mapc (lambda (o)
3452 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3453 (delete-overlay o)))
3454 (overlays-in (point-min) (point-max)))
3455 (when (marker-buffer org-clock-hd-marker)
3456 (save-excursion
3457 (goto-char (point-min))
3458 (let (s ov)
3459 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3460 (goto-char s)
3461 (when (equal (org-get-at-bol 'org-hd-marker)
3462 org-clock-hd-marker)
3463 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3464 (overlay-put ov 'type 'org-agenda-clocking)
3465 (overlay-put ov 'face 'org-agenda-clocking)
3466 (overlay-put ov 'help-echo
3467 "The clock is running in this item")))))))
3469 (defun org-agenda-fontify-priorities ()
3470 "Make highest priority lines bold, and lowest italic."
3471 (interactive)
3472 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3473 (delete-overlay o)))
3474 (overlays-in (point-min) (point-max)))
3475 (save-excursion
3476 (let ((inhibit-read-only t)
3477 b e p ov h l)
3478 (goto-char (point-min))
3479 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3480 (setq h (or (get-char-property (point) 'org-highest-priority)
3481 org-highest-priority)
3482 l (or (get-char-property (point) 'org-lowest-priority)
3483 org-lowest-priority)
3484 p (string-to-char (match-string 1))
3485 b (match-beginning 0)
3486 e (if (eq org-agenda-fontify-priorities 'cookies)
3487 (match-end 0)
3488 (point-at-eol))
3489 ov (make-overlay b e))
3490 (overlay-put
3491 ov 'face
3492 (cond ((org-face-from-face-or-color
3493 'priority nil
3494 (cdr (assoc p org-priority-faces))))
3495 ((and (listp org-agenda-fontify-priorities)
3496 (org-face-from-face-or-color
3497 'priority nil
3498 (cdr (assoc p org-agenda-fontify-priorities)))))
3499 ((equal p l) 'italic)
3500 ((equal p h) 'bold)))
3501 (overlay-put ov 'org-type 'org-priority)))))
3503 (defun org-agenda-dim-blocked-tasks ()
3504 "Dim currently blocked TODO's in the agenda display."
3505 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3506 (delete-overlay o)))
3507 (overlays-in (point-min) (point-max)))
3508 (save-excursion
3509 (let ((inhibit-read-only t)
3510 (org-depend-tag-blocked nil)
3511 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3512 org-blocked-by-checkboxes
3513 invis1 b e p ov h l)
3514 (goto-char (point-min))
3515 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3516 (and pos (goto-char (1+ pos))))
3517 (setq org-blocked-by-checkboxes nil invis1 invis)
3518 (let ((marker (org-get-at-bol 'org-hd-marker)))
3519 (when (and marker
3520 (with-current-buffer (marker-buffer marker)
3521 (save-excursion (goto-char marker)
3522 (org-entry-blocked-p))))
3523 (if org-blocked-by-checkboxes (setq invis1 nil))
3524 (setq b (if invis1
3525 (max (point-min) (1- (point-at-bol)))
3526 (point-at-bol))
3527 e (point-at-eol)
3528 ov (make-overlay b e))
3529 (if invis1
3530 (overlay-put ov 'invisible t)
3531 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3532 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3534 (defvar org-agenda-skip-function nil
3535 "Function to be called at each match during agenda construction.
3536 If this function returns nil, the current match should not be skipped.
3537 Otherwise, the function must return a position from where the search
3538 should be continued.
3539 This may also be a Lisp form, it will be evaluated.
3540 Never set this variable using `setq' or so, because then it will apply
3541 to all future agenda commands. If you do want a global skipping condition,
3542 use the option `org-agenda-skip-function-global' instead.
3543 The correct usage for `org-agenda-skip-function' is to bind it with
3544 `let' to scope it dynamically into the agenda-constructing command.
3545 A good way to set it is through options in `org-agenda-custom-commands'.")
3547 (defun org-agenda-skip ()
3548 "Throw to `:skip' in places that should be skipped.
3549 Also moves point to the end of the skipped region, so that search can
3550 continue from there."
3551 (let ((p (point-at-bol)) to)
3552 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3553 (get-text-property p :org-archived)
3554 (org-end-of-subtree t)
3555 (throw :skip t))
3556 (and org-agenda-skip-comment-trees
3557 (get-text-property p :org-comment)
3558 (org-end-of-subtree t)
3559 (throw :skip t))
3560 (if (equal (char-after p) ?#) (throw :skip t))
3561 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3562 (org-agenda-skip-eval org-agenda-skip-function)))
3563 (goto-char to)
3564 (throw :skip t))))
3566 (defun org-agenda-skip-eval (form)
3567 "If FORM is a function or a list, call (or eval) is and return result.
3568 `save-excursion' and `save-match-data' are wrapped around the call, so point
3569 and match data are returned to the previous state no matter what these
3570 functions do."
3571 (let (fp)
3572 (and form
3573 (or (setq fp (functionp form))
3574 (consp form))
3575 (save-excursion
3576 (save-match-data
3577 (if fp
3578 (funcall form)
3579 (eval form)))))))
3581 (defvar org-agenda-markers nil
3582 "List of all currently active markers created by `org-agenda'.")
3583 (defvar org-agenda-last-marker-time (org-float-time)
3584 "Creation time of the last agenda marker.")
3586 (defun org-agenda-new-marker (&optional pos)
3587 "Return a new agenda marker.
3588 Org-mode keeps a list of these markers and resets them when they are
3589 no longer in use."
3590 (let ((m (copy-marker (or pos (point)))))
3591 (setq org-agenda-last-marker-time (org-float-time))
3592 (if org-agenda-buffer
3593 (with-current-buffer org-agenda-buffer
3594 (push m org-agenda-markers))
3595 (push m org-agenda-markers))
3598 (defun org-agenda-reset-markers ()
3599 "Reset markers created by `org-agenda'."
3600 (while org-agenda-markers
3601 (move-marker (pop org-agenda-markers) nil)))
3603 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3604 "Save relative positions of markers in region.
3605 This check for agenda markers in all agenda buffers currently active."
3606 (dolist (buf (buffer-list))
3607 (with-current-buffer buf
3608 (when (eq major-mode 'org-agenda-mode)
3609 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3610 org-agenda-markers)))))
3612 ;;; Entry text mode
3614 (defun org-agenda-entry-text-show-here ()
3615 "Add some text from the entry as context to the current line."
3616 (let (m txt o)
3617 (setq m (org-get-at-bol 'org-hd-marker))
3618 (unless (marker-buffer m)
3619 (error "No marker points to an entry here"))
3620 (setq txt (concat "\n" (org-no-properties
3621 (org-agenda-get-some-entry-text
3622 m org-agenda-entry-text-maxlines " > "))))
3623 (when (string-match "\\S-" txt)
3624 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3625 (overlay-put o 'evaporate t)
3626 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3627 (overlay-put o 'after-string txt))))
3629 (defun org-agenda-entry-text-show ()
3630 "Add entry context for all agenda lines."
3631 (interactive)
3632 (save-excursion
3633 (goto-char (point-max))
3634 (beginning-of-line 1)
3635 (while (not (bobp))
3636 (when (org-get-at-bol 'org-hd-marker)
3637 (org-agenda-entry-text-show-here))
3638 (beginning-of-line 0))))
3640 (defun org-agenda-entry-text-hide ()
3641 "Remove any shown entry context."
3642 (delq nil
3643 (mapcar (lambda (o)
3644 (if (eq (overlay-get o 'org-overlay-type)
3645 'agenda-entry-content)
3646 (progn (delete-overlay o) t)))
3647 (overlays-in (point-min) (point-max)))))
3649 (defun org-agenda-get-day-face (date)
3650 "Return the face DATE should be displayed with."
3651 (or (and (functionp org-agenda-day-face-function)
3652 (funcall org-agenda-day-face-function date))
3653 (cond ((org-agenda-todayp date)
3654 'org-agenda-date-today)
3655 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3656 'org-agenda-date-weekend)
3657 (t 'org-agenda-date))))
3659 ;;; Agenda timeline
3661 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3663 (defun org-timeline (&optional dotodo)
3664 "Show a time-sorted view of the entries in the current org file.
3665 Only entries with a time stamp of today or later will be listed. With
3666 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3667 under the current date.
3668 If the buffer contains an active region, only check the region for
3669 dates."
3670 (interactive "P")
3671 (let* ((dopast t)
3672 (org-agenda-show-log-scoped org-agenda-show-log)
3673 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3674 (current-buffer))))
3675 (date (calendar-current-date))
3676 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3677 (end (if (org-region-active-p) (region-end) (point-max)))
3678 (day-numbers (org-get-all-dates
3679 beg end 'no-ranges
3680 t org-agenda-show-log-scoped ; always include today
3681 org-timeline-show-empty-dates))
3682 (org-deadline-warning-days 0)
3683 (org-agenda-only-exact-dates t)
3684 (today (org-today))
3685 (past t)
3686 args
3687 s e rtn d emptyp)
3688 (setq org-agenda-redo-command
3689 (list 'progn
3690 (list 'org-switch-to-buffer-other-window (current-buffer))
3691 (list 'org-timeline (list 'quote dotodo))))
3692 (if (not dopast)
3693 ;; Remove past dates from the list of dates.
3694 (setq day-numbers (delq nil (mapcar (lambda(x)
3695 (if (>= x today) x nil))
3696 day-numbers))))
3697 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3698 (org-compile-prefix-format 'timeline)
3699 (org-set-sorting-strategy 'timeline)
3700 (if org-agenda-show-log-scoped (push :closed args))
3701 (push :timestamp args)
3702 (push :deadline args)
3703 (push :scheduled args)
3704 (push :sexp args)
3705 (if dotodo (push :todo args))
3706 (insert "Timeline of file " entry "\n")
3707 (add-text-properties (point-min) (point)
3708 (list 'face 'org-agenda-structure))
3709 (org-agenda-mark-header-line (point-min))
3710 (while (setq d (pop day-numbers))
3711 (if (and (listp d) (eq (car d) :omitted))
3712 (progn
3713 (setq s (point))
3714 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3715 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3716 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3717 (if (and (>= d today)
3718 dopast
3719 past)
3720 (progn
3721 (setq past nil)
3722 (insert (make-string 79 ?-) "\n")))
3723 (setq date (calendar-gregorian-from-absolute d))
3724 (setq s (point))
3725 (setq rtn (and (not emptyp)
3726 (apply 'org-agenda-get-day-entries entry
3727 date args)))
3728 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3729 (progn
3730 (insert
3731 (if (stringp org-agenda-format-date)
3732 (format-time-string org-agenda-format-date
3733 (org-time-from-absolute date))
3734 (funcall org-agenda-format-date date))
3735 "\n")
3736 (put-text-property s (1- (point)) 'face
3737 (org-agenda-get-day-face date))
3738 (put-text-property s (1- (point)) 'org-date-line t)
3739 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3740 (if (equal d today)
3741 (put-text-property s (1- (point)) 'org-today t))
3742 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3743 (put-text-property s (1- (point)) 'day d)))))
3744 (goto-char (point-min))
3745 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3746 (point-min)))
3747 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3748 (org-agenda-finalize)
3749 (setq buffer-read-only t)))
3751 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3752 "Return a list of all relevant day numbers from BEG to END buffer positions.
3753 If NO-RANGES is non-nil, include only the start and end dates of a range,
3754 not every single day in the range. If FORCE-TODAY is non-nil, make
3755 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3756 inactive time stamps (those in square brackets) are included.
3757 When EMPTY is non-nil, also include days without any entries."
3758 (let ((re (concat
3759 (if pre-re pre-re "")
3760 (if inactive org-ts-regexp-both org-ts-regexp)))
3761 dates dates1 date day day1 day2 ts1 ts2 pos)
3762 (if force-today
3763 (setq dates (list (org-today))))
3764 (save-excursion
3765 (goto-char beg)
3766 (while (re-search-forward re end t)
3767 (setq day (time-to-days (org-time-string-to-time
3768 (substring (match-string 1) 0 10)
3769 (current-buffer) (match-beginning 0))))
3770 (or (memq day dates) (push day dates)))
3771 (unless no-ranges
3772 (goto-char beg)
3773 (while (re-search-forward org-tr-regexp end t)
3774 (setq pos (match-beginning 0))
3775 (setq ts1 (substring (match-string 1) 0 10)
3776 ts2 (substring (match-string 2) 0 10)
3777 day1 (time-to-days (org-time-string-to-time
3778 ts1 (current-buffer) pos))
3779 day2 (time-to-days (org-time-string-to-time
3780 ts2 (current-buffer) pos)))
3781 (while (< (setq day1 (1+ day1)) day2)
3782 (or (memq day1 dates) (push day1 dates)))))
3783 (setq dates (sort dates '<))
3784 (when empty
3785 (while (setq day (pop dates))
3786 (setq day2 (car dates))
3787 (push day dates1)
3788 (when (and day2 empty)
3789 (if (or (eq empty t)
3790 (and (numberp empty) (<= (- day2 day) empty)))
3791 (while (< (setq day (1+ day)) day2)
3792 (push (list day) dates1))
3793 (push (cons :omitted (- day2 day)) dates1))))
3794 (setq dates (nreverse dates1)))
3795 dates)))
3797 ;;; Agenda Daily/Weekly
3799 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3800 "Start day for the agenda view.
3801 Custom commands can set this variable in the options section.")
3802 (defvar org-starting-day nil) ; local variable in the agenda buffer
3803 (defvar org-arg-loc nil) ; local variable
3805 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3806 "List of types searched for when creating the daily/weekly agenda.
3807 This variable is a list of symbols that controls the types of
3808 items that appear in the daily/weekly agenda. Allowed symbols in this
3809 list are are
3811 :timestamp List items containing a date stamp or date range matching
3812 the selected date. This includes sexp entries in
3813 angular brackets.
3815 :sexp List entries resulting from plain diary-like sexps.
3817 :deadline List deadline due on that date. When the date is today,
3818 also list any deadlines past due, or due within
3819 `org-deadline-warning-days'. `:deadline' must appear before
3820 `:scheduled' if the setting of
3821 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3822 any effect.
3824 :scheduled List all items which are scheduled for the given date.
3825 The diary for *today* also contains items which were
3826 scheduled earlier and are not yet marked DONE.
3828 By default, all four types are turned on.
3830 Never set this variable globally using `setq', because then it
3831 will apply to all future agenda commands. Instead, bind it with
3832 `let' to scope it dynamically into the agenda-constructing
3833 command. A good way to set it is through options in
3834 `org-agenda-custom-commands'. For a more flexible (though
3835 somewhat less efficient) way of determining what is included in
3836 the daily/weekly agenda, see `org-agenda-skip-function'.")
3838 (defvar org-agenda-buffer-tmp-name nil)
3839 ;;;###autoload
3840 (defun org-agenda-list (&optional arg start-day span)
3841 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3842 The view will be for the current day or week, but from the overview buffer
3843 you will be able to go to other days/weeks.
3845 With a numeric prefix argument in an interactive call, the agenda will
3846 span ARG days. Lisp programs should instead specify SPAN to change
3847 the number of days. SPAN defaults to `org-agenda-span'.
3849 START-DAY defaults to TODAY, or to the most recent match for the weekday
3850 given in `org-agenda-start-on-weekday'."
3851 (interactive "P")
3852 (if org-agenda-overriding-arguments
3853 (setq arg (car org-agenda-overriding-arguments)
3854 start-day (nth 1 org-agenda-overriding-arguments)
3855 span (nth 2 org-agenda-overriding-arguments)))
3856 (if (and (integerp arg) (> arg 0))
3857 (setq span arg arg nil))
3858 (catch 'exit
3859 (setq org-agenda-buffer-name
3860 (or org-agenda-buffer-tmp-name
3861 (if org-agenda-sticky
3862 (cond ((and org-keys (stringp org-match))
3863 (format "*Org Agenda(%s:%s)*" org-keys org-match))
3864 (org-keys
3865 (format "*Org Agenda(%s)*" org-keys))
3866 (t "*Org Agenda(a)*")))
3867 org-agenda-buffer-name))
3868 (org-agenda-prepare "Day/Week")
3869 (setq start-day (or start-day org-agenda-start-day))
3870 (if (stringp start-day)
3871 ;; Convert to an absolute day number
3872 (setq start-day (time-to-days (org-read-date nil t start-day))))
3873 (org-compile-prefix-format 'agenda)
3874 (org-set-sorting-strategy 'agenda)
3875 (let* ((span (org-agenda-ndays-to-span
3876 (or span org-agenda-ndays org-agenda-span)))
3877 (today (org-today))
3878 (sd (or start-day today))
3879 (ndays (org-agenda-span-to-ndays span sd))
3880 (org-agenda-start-on-weekday
3881 (if (eq ndays 7)
3882 org-agenda-start-on-weekday))
3883 (thefiles (org-agenda-files nil 'ifmode))
3884 (files thefiles)
3885 (start (if (or (null org-agenda-start-on-weekday)
3886 (< ndays 7))
3888 (let* ((nt (calendar-day-of-week
3889 (calendar-gregorian-from-absolute sd)))
3890 (n1 org-agenda-start-on-weekday)
3891 (d (- nt n1)))
3892 (- sd (+ (if (< d 0) 7 0) d)))))
3893 (day-numbers (list start))
3894 (day-cnt 0)
3895 (inhibit-redisplay (not debug-on-error))
3896 (org-agenda-show-log-scoped org-agenda-show-log)
3897 s e rtn rtnall file date d start-pos end-pos todayp
3898 clocktable-start clocktable-end filter)
3899 (setq org-agenda-redo-command
3900 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3901 (dotimes (n (1- ndays))
3902 (push (1+ (car day-numbers)) day-numbers))
3903 (setq day-numbers (nreverse day-numbers))
3904 (setq clocktable-start (car day-numbers)
3905 clocktable-end (1+ (or (org-last day-numbers) 0)))
3906 (org-set-local 'org-starting-day (car day-numbers))
3907 (org-set-local 'org-arg-loc arg)
3908 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3909 (unless org-agenda-compact-blocks
3910 (let* ((d1 (car day-numbers))
3911 (d2 (org-last day-numbers))
3912 (w1 (org-days-to-iso-week d1))
3913 (w2 (org-days-to-iso-week d2)))
3914 (setq s (point))
3915 (if org-agenda-overriding-header
3916 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3917 nil 'face 'org-agenda-structure) "\n")
3918 (insert (org-agenda-span-name span)
3919 "-agenda"
3920 (if (< (- d2 d1) 350)
3921 (if (= w1 w2)
3922 (format " (W%02d)" w1)
3923 (format " (W%02d-W%02d)" w1 w2))
3925 ":\n")))
3926 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3927 'org-date-line t))
3928 (org-agenda-mark-header-line s))
3929 (while (setq d (pop day-numbers))
3930 (setq date (calendar-gregorian-from-absolute d)
3931 s (point))
3932 (if (or (setq todayp (= d today))
3933 (and (not start-pos) (= d sd)))
3934 (setq start-pos (point))
3935 (if (and start-pos (not end-pos))
3936 (setq end-pos (point))))
3937 (setq files thefiles
3938 rtnall nil)
3939 (while (setq file (pop files))
3940 (catch 'nextfile
3941 (org-check-agenda-file file)
3942 (let ((org-agenda-entry-types org-agenda-entry-types))
3943 (unless org-agenda-include-deadlines
3944 (setq org-agenda-entry-types
3945 (delq :deadline org-agenda-entry-types)))
3946 (cond
3947 ((memq org-agenda-show-log-scoped '(only clockcheck))
3948 (setq rtn (org-agenda-get-day-entries
3949 file date :closed)))
3950 (org-agenda-show-log-scoped
3951 (setq rtn (apply 'org-agenda-get-day-entries
3952 file date
3953 (append '(:closed) org-agenda-entry-types))))
3955 (setq rtn (apply 'org-agenda-get-day-entries
3956 file date
3957 org-agenda-entry-types)))))
3958 (setq rtnall (append rtnall rtn)))) ;; all entries
3959 (if org-agenda-include-diary
3960 (let ((org-agenda-search-headline-for-time t))
3961 (require 'diary-lib)
3962 (setq rtn (org-get-entries-from-diary date))
3963 (setq rtnall (append rtnall rtn))))
3964 (if (or rtnall org-agenda-show-all-dates)
3965 (progn
3966 (setq day-cnt (1+ day-cnt))
3967 (insert
3968 (if (stringp org-agenda-format-date)
3969 (format-time-string org-agenda-format-date
3970 (org-time-from-absolute date))
3971 (funcall org-agenda-format-date date))
3972 "\n")
3973 (put-text-property s (1- (point)) 'face
3974 (org-agenda-get-day-face date))
3975 (put-text-property s (1- (point)) 'org-date-line t)
3976 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3977 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3978 (when todayp
3979 (put-text-property s (1- (point)) 'org-today t))
3980 (setq rtnall
3981 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3982 (if rtnall (insert ;; all entries
3983 (org-agenda-finalize-entries rtnall)
3984 "\n"))
3985 (put-text-property s (1- (point)) 'day d)
3986 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3987 (when (and org-agenda-clockreport-mode clocktable-start)
3988 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3989 ;; the above line is to ensure the restricted range!
3990 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3991 tbl)
3992 (setq p (org-plist-delete p :block))
3993 (setq p (plist-put p :tstart clocktable-start))
3994 (setq p (plist-put p :tend clocktable-end))
3995 (setq p (plist-put p :scope 'agenda))
3996 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3997 (setq filter (or org-agenda-tag-filter-while-redo
3998 (get 'org-agenda-tag-filter :preset-filter))))
3999 (setq p (plist-put p :tags (mapconcat (lambda (x)
4000 (if (string-match "[<>=]" x)
4003 filter ""))))
4004 (setq tbl (apply 'org-get-clocktable p))
4005 (insert tbl)))
4006 (goto-char (point-min))
4007 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4008 (unless (and (pos-visible-in-window-p (point-min))
4009 (pos-visible-in-window-p (point-max)))
4010 (goto-char (1- (point-max)))
4011 (recenter -1)
4012 (if (not (pos-visible-in-window-p (or start-pos 1)))
4013 (progn
4014 (goto-char (or start-pos 1))
4015 (recenter 1))))
4016 (goto-char (or start-pos 1))
4017 (add-text-properties (point-min) (point-max)
4018 `(org-agenda-type agenda
4019 org-last-args (,arg ,start-day ,span)
4020 org-redo-cmd ,org-agenda-redo-command
4021 org-serie-cmd ,org-cmd))
4022 (if (eq org-agenda-show-log-scoped 'clockcheck)
4023 (org-agenda-show-clocking-issues))
4024 (org-agenda-finalize)
4025 (setq buffer-read-only t)
4026 (message ""))))
4028 (defun org-agenda-ndays-to-span (n)
4029 "Return a span symbol for a span of N days, or N if none matches."
4030 (cond ((symbolp n) n)
4031 ((= n 1) 'day)
4032 ((= n 7) 'week)
4033 (t n)))
4035 (defun org-agenda-span-to-ndays (span &optional start-day)
4036 "Return ndays from SPAN, possibly starting at START-DAY."
4037 (cond ((numberp span) span)
4038 ((eq span 'day) 1)
4039 ((eq span 'week) 7)
4040 ((eq span 'month)
4041 (let ((date (calendar-gregorian-from-absolute start-day)))
4042 (calendar-last-day-of-month (car date) (caddr date))))
4043 ((eq span 'year)
4044 (let ((date (calendar-gregorian-from-absolute start-day)))
4045 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4047 (defun org-agenda-span-name (span)
4048 "Return a SPAN name."
4049 (if (null span)
4051 (if (symbolp span)
4052 (capitalize (symbol-name span))
4053 (format "%d days" span))))
4055 ;;; Agenda word search
4057 (defvar org-agenda-search-history nil)
4059 (defvar org-search-syntax-table nil
4060 "Special syntax table for org-mode search.
4061 In this table, we have single quotes not as word constituents, to
4062 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4064 (defvar org-mode-syntax-table) ; From org.el
4065 (defun org-search-syntax-table ()
4066 (unless org-search-syntax-table
4067 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4068 (modify-syntax-entry ?' "." org-search-syntax-table)
4069 (modify-syntax-entry ?` "." org-search-syntax-table))
4070 org-search-syntax-table)
4072 (defvar org-agenda-last-search-view-search-was-boolean nil)
4074 ;;;###autoload
4075 (defun org-search-view (&optional todo-only string edit-at)
4076 "Show all entries that contain a phrase or words or regular expressions.
4078 With optional prefix argument TODO-ONLY, only consider entries that are
4079 TODO entries. The argument STRING can be used to pass a default search
4080 string into this function. If EDIT-AT is non-nil, it means that the
4081 user should get a chance to edit this string, with cursor at position
4082 EDIT-AT.
4084 The search string can be viewed either as a phrase that should be found as
4085 is, or it can be broken into a number of snippets, each of which must match
4086 in a Boolean way to select an entry. The default depends on the variable
4087 `org-agenda-search-view-always-boolean'.
4088 Even if this is turned off (the default) you can always switch to
4089 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4091 The default is a direct search of the whole phrase, where each space in
4092 the search string can expand to an arbitrary amount of whitespace,
4093 including newlines.
4095 If using a Boolean search, the search string is split on whitespace and
4096 each snippet is searched separately, with logical AND to select an entry.
4097 Words prefixed with a minus must *not* occur in the entry. Words without
4098 a prefix or prefixed with a plus must occur in the entry. Matching is
4099 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4100 match whole words, not parts of a word) if
4101 `org-agenda-search-view-force-full-words' is set (default is nil).
4103 Boolean search snippets enclosed by curly braces are interpreted as
4104 regular expressions that must or (when preceded with \"-\") must not
4105 match in the entry. Snippets enclosed into double quotes will be taken
4106 as a whole, to include whitespace.
4108 - If the search string starts with an asterisk, search only in headlines.
4109 - If (possibly after the leading star) the search string starts with an
4110 exclamation mark, this also means to look at TODO entries only, an effect
4111 that can also be achieved with a prefix argument.
4112 - If (possibly after star and exclamation mark) the search string starts
4113 with a colon, this will mean that the (non-regexp) snippets of the
4114 Boolean search must match as full words.
4116 This command searches the agenda files, and in addition the files listed
4117 in `org-agenda-text-search-extra-files'."
4118 (interactive "P")
4119 (if org-agenda-overriding-arguments
4120 (setq todo-only (car org-agenda-overriding-arguments)
4121 string (nth 1 org-agenda-overriding-arguments)
4122 edit-at (nth 2 org-agenda-overriding-arguments)))
4123 (let* ((props (list 'face nil
4124 'done-face 'org-agenda-done
4125 'org-not-done-regexp org-not-done-regexp
4126 'org-todo-regexp org-todo-regexp
4127 'org-complex-heading-regexp org-complex-heading-regexp
4128 'mouse-face 'highlight
4129 'help-echo (format "mouse-2 or RET jump to location")))
4130 (full-words org-agenda-search-view-force-full-words)
4131 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4132 regexp rtn rtnall files file pos
4133 marker category category-pos tags c neg re boolean
4134 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4135 (unless (and (not edit-at)
4136 (stringp string)
4137 (string-match "\\S-" string))
4138 (setq string (read-string
4139 (if org-agenda-search-view-always-boolean
4140 "[+-]Word/{Regexp} ...: "
4141 "Phrase or [+-]Word/{Regexp} ...: ")
4142 (cond
4143 ((integerp edit-at) (cons string edit-at))
4144 (edit-at string))
4145 'org-agenda-search-history)))
4146 (catch 'exit
4147 (if org-agenda-sticky
4148 (setq org-agenda-buffer-name
4149 (if (stringp string)
4150 (format "*Org Agenda(%s:%s)*"
4151 (or org-keys (or (and todo-only "S") "s")) string)
4152 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4153 (org-agenda-prepare "SEARCH")
4154 (org-compile-prefix-format 'search)
4155 (org-set-sorting-strategy 'search)
4156 (setq org-agenda-redo-command
4157 (list 'org-search-view (if todo-only t nil)
4158 (list 'if 'current-prefix-arg nil string)))
4159 (setq org-agenda-query-string string)
4160 (if (equal (string-to-char string) ?*)
4161 (setq hdl-only t
4162 words (substring string 1))
4163 (setq words string))
4164 (when (equal (string-to-char words) ?!)
4165 (setq todo-only t
4166 words (substring words 1)))
4167 (when (equal (string-to-char words) ?:)
4168 (setq full-words t
4169 words (substring words 1)))
4170 (if (or org-agenda-search-view-always-boolean
4171 (member (string-to-char words) '(?- ?+ ?\{)))
4172 (setq boolean t))
4173 (setq words (org-split-string words))
4174 (let (www w)
4175 (while (setq w (pop words))
4176 (while (and (string-match "\\\\\\'" w) words)
4177 (setq w (concat (substring w 0 -1) " " (pop words))))
4178 (push w www))
4179 (setq words (nreverse www) www nil)
4180 (while (setq w (pop words))
4181 (when (and (string-match "\\`[-+]?{" w)
4182 (not (string-match "}\\'" w)))
4183 (while (and words (not (string-match "}\\'" (car words))))
4184 (setq w (concat w " " (pop words))))
4185 (setq w (concat w " " (pop words))))
4186 (push w www))
4187 (setq words (nreverse www)))
4188 (setq org-agenda-last-search-view-search-was-boolean boolean)
4189 (when boolean
4190 (let (wds w)
4191 (while (setq w (pop words))
4192 (if (or (equal (substring w 0 1) "\"")
4193 (and (> (length w) 1)
4194 (member (substring w 0 1) '("+" "-"))
4195 (equal (substring w 1 2) "\"")))
4196 (while (and words (not (equal (substring w -1) "\"")))
4197 (setq w (concat w " " (pop words)))))
4198 (and (string-match "\\`\\([-+]?\\)\"" w)
4199 (setq w (replace-match "\\1" nil nil w)))
4200 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4201 (push w wds))
4202 (setq words (nreverse wds))))
4203 (if boolean
4204 (mapc (lambda (w)
4205 (setq c (string-to-char w))
4206 (if (equal c ?-)
4207 (setq neg t w (substring w 1))
4208 (if (equal c ?+)
4209 (setq neg nil w (substring w 1))
4210 (setq neg nil)))
4211 (if (string-match "\\`{.*}\\'" w)
4212 (setq re (substring w 1 -1))
4213 (if full-words
4214 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4215 (setq re (regexp-quote (downcase w)))))
4216 (if neg (push re regexps-) (push re regexps+)))
4217 words)
4218 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4219 regexps+))
4220 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4221 (if (not regexps+)
4222 (setq regexp org-outline-regexp-bol)
4223 (setq regexp (pop regexps+))
4224 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4225 regexp))))
4226 (setq files (org-agenda-files nil 'ifmode))
4227 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4228 (pop org-agenda-text-search-extra-files)
4229 (setq files (org-add-archive-files files)))
4230 (setq files (append files org-agenda-text-search-extra-files)
4231 rtnall nil)
4232 (while (setq file (pop files))
4233 (setq ee nil)
4234 (catch 'nextfile
4235 (org-check-agenda-file file)
4236 (setq buffer (if (file-exists-p file)
4237 (org-get-agenda-file-buffer file)
4238 (error "No such file %s" file)))
4239 (if (not buffer)
4240 ;; If file does not exist, make sure an error message is sent
4241 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4242 file))))
4243 (with-current-buffer buffer
4244 (with-syntax-table (org-search-syntax-table)
4245 (unless (derived-mode-p 'org-mode)
4246 (error "Agenda file %s is not in `org-mode'" file))
4247 (let ((case-fold-search t))
4248 (save-excursion
4249 (save-restriction
4250 (if org-agenda-restrict
4251 (narrow-to-region org-agenda-restrict-begin
4252 org-agenda-restrict-end)
4253 (widen))
4254 (goto-char (point-min))
4255 (unless (or (org-at-heading-p)
4256 (outline-next-heading))
4257 (throw 'nextfile t))
4258 (goto-char (max (point-min) (1- (point))))
4259 (while (re-search-forward regexp nil t)
4260 (org-back-to-heading t)
4261 (skip-chars-forward "* ")
4262 (setq beg (point-at-bol)
4263 beg1 (point)
4264 end (progn (outline-next-heading) (point)))
4265 (catch :skip
4266 (goto-char beg)
4267 (org-agenda-skip)
4268 (setq str (buffer-substring-no-properties
4269 (point-at-bol)
4270 (if hdl-only (point-at-eol) end)))
4271 (mapc (lambda (wr) (when (string-match wr str)
4272 (goto-char (1- end))
4273 (throw :skip t)))
4274 regexps-)
4275 (mapc (lambda (wr) (unless (string-match wr str)
4276 (goto-char (1- end))
4277 (throw :skip t)))
4278 (if todo-only
4279 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4280 regexps+)
4281 regexps+))
4282 (goto-char beg)
4283 (setq marker (org-agenda-new-marker (point))
4284 category (org-get-category)
4285 category-pos (get-text-property (point) 'org-category-position)
4286 tags (org-get-tags-at (point))
4287 txt (org-agenda-format-item
4289 (buffer-substring-no-properties
4290 beg1 (point-at-eol))
4291 category tags))
4292 (org-add-props txt props
4293 'org-marker marker 'org-hd-marker marker
4294 'org-todo-regexp org-todo-regexp
4295 'org-complex-heading-regexp org-complex-heading-regexp
4296 'priority 1000 'org-category category
4297 'org-category-position category-pos
4298 'type "search")
4299 (push txt ee)
4300 (goto-char (1- end))))))))))
4301 (setq rtn (nreverse ee))
4302 (setq rtnall (append rtnall rtn)))
4303 (if org-agenda-overriding-header
4304 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4305 nil 'face 'org-agenda-structure) "\n")
4306 (insert "Search words: ")
4307 (add-text-properties (point-min) (1- (point))
4308 (list 'face 'org-agenda-structure))
4309 (setq pos (point))
4310 (insert string "\n")
4311 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4312 (setq pos (point))
4313 (unless org-agenda-multi
4314 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4315 (add-text-properties pos (1- (point))
4316 (list 'face 'org-agenda-structure))))
4317 (org-agenda-mark-header-line (point-min))
4318 (when rtnall
4319 (insert (org-agenda-finalize-entries rtnall) "\n"))
4320 (goto-char (point-min))
4321 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4322 (add-text-properties (point-min) (point-max)
4323 `(org-agenda-type search
4324 org-last-args (,todo-only ,string ,edit-at)
4325 org-redo-cmd ,org-agenda-redo-command
4326 org-serie-cmd ,org-cmd))
4327 (org-agenda-finalize)
4328 (setq buffer-read-only t))))
4330 ;;; Agenda TODO list
4332 (defvar org-select-this-todo-keyword nil)
4333 (defvar org-last-arg nil)
4335 ;;;###autoload
4336 (defun org-todo-list (&optional arg)
4337 "Show all (not done) TODO entries from all agenda file in a single list.
4338 The prefix arg can be used to select a specific TODO keyword and limit
4339 the list to these. When using \\[universal-argument], you will be prompted
4340 for a keyword. A numeric prefix directly selects the Nth keyword in
4341 `org-todo-keywords-1'."
4342 (interactive "P")
4343 (if org-agenda-overriding-arguments
4344 (setq arg org-agenda-overriding-arguments))
4345 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4346 (let* ((today (org-today))
4347 (date (calendar-gregorian-from-absolute today))
4348 (kwds org-todo-keywords-for-agenda)
4349 (completion-ignore-case t)
4350 (org-select-this-todo-keyword
4351 (if (stringp arg) arg
4352 (and arg (integerp arg) (> arg 0)
4353 (nth (1- arg) kwds))))
4354 rtn rtnall files file pos)
4355 (when (equal arg '(4))
4356 (setq org-select-this-todo-keyword
4357 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4358 (mapcar 'list kwds) nil nil)))
4359 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4360 (catch 'exit
4361 (if org-agenda-sticky
4362 (setq org-agenda-buffer-name
4363 (if (stringp org-select-this-todo-keyword)
4364 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4365 org-select-this-todo-keyword)
4366 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4367 (org-agenda-prepare "TODO")
4368 (org-compile-prefix-format 'todo)
4369 (org-set-sorting-strategy 'todo)
4370 (setq org-agenda-redo-command
4371 `(org-todo-list (or current-prefix-arg (quote ,arg))))
4372 (setq files (org-agenda-files nil 'ifmode)
4373 rtnall nil)
4374 (while (setq file (pop files))
4375 (catch 'nextfile
4376 (org-check-agenda-file file)
4377 (setq rtn (org-agenda-get-day-entries file date :todo))
4378 (setq rtnall (append rtnall rtn))))
4379 (if org-agenda-overriding-header
4380 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4381 nil 'face 'org-agenda-structure) "\n")
4382 (insert "Global list of TODO items of type: ")
4383 (add-text-properties (point-min) (1- (point))
4384 (list 'face 'org-agenda-structure
4385 'short-heading
4386 (concat "ToDo: "
4387 (or org-select-this-todo-keyword "ALL"))))
4388 (org-agenda-mark-header-line (point-min))
4389 (setq pos (point))
4390 (insert (or org-select-this-todo-keyword "ALL") "\n")
4391 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4392 (setq pos (point))
4393 (unless org-agenda-multi
4394 (insert "Available with `N r': (0)[ALL]")
4395 (let ((n 0) s)
4396 (mapc (lambda (x)
4397 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4398 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4399 (insert "\n "))
4400 (insert " " s))
4401 kwds))
4402 (insert "\n"))
4403 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4404 (org-agenda-mark-header-line (point-min))
4405 (when rtnall
4406 (insert (org-agenda-finalize-entries rtnall) "\n"))
4407 (goto-char (point-min))
4408 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4409 (add-text-properties (point-min) (point-max)
4410 `(org-agenda-type todo
4411 org-last-args ,arg
4412 org-redo-cmd ,org-agenda-redo-command
4413 org-serie-cmd ,org-cmd))
4414 (org-agenda-finalize)
4415 (setq buffer-read-only t))))
4417 ;;; Agenda tags match
4419 ;;;###autoload
4420 (defun org-tags-view (&optional todo-only match)
4421 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4422 The prefix arg TODO-ONLY limits the search to TODO entries."
4423 (interactive "P")
4424 (if org-agenda-overriding-arguments
4425 (setq todo-only (car org-agenda-overriding-arguments)
4426 match (nth 1 org-agenda-overriding-arguments)))
4427 (let* ((org-tags-match-list-sublevels
4428 org-tags-match-list-sublevels)
4429 (completion-ignore-case t)
4430 rtn rtnall files file pos matcher
4431 buffer)
4432 (when (and (stringp match) (not (string-match "\\S-" match)))
4433 (setq match nil))
4434 (setq matcher (org-make-tags-matcher match)
4435 match (car matcher) matcher (cdr matcher))
4436 (catch 'exit
4437 (if org-agenda-sticky
4438 (setq org-agenda-buffer-name
4439 (if (stringp match)
4440 (format "*Org Agenda(%s:%s)*"
4441 (or org-keys (or (and todo-only "M") "m")) match)
4442 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4443 (org-agenda-prepare (concat "TAGS " match))
4444 (org-compile-prefix-format 'tags)
4445 (org-set-sorting-strategy 'tags)
4446 (setq org-agenda-query-string match)
4447 (setq org-agenda-redo-command
4448 (list 'org-tags-view `(quote ,todo-only)
4449 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4450 (setq files (org-agenda-files nil 'ifmode)
4451 rtnall nil)
4452 (while (setq file (pop files))
4453 (catch 'nextfile
4454 (org-check-agenda-file file)
4455 (setq buffer (if (file-exists-p file)
4456 (org-get-agenda-file-buffer file)
4457 (error "No such file %s" file)))
4458 (if (not buffer)
4459 ;; If file does not exist, error message to agenda
4460 (setq rtn (list
4461 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4462 rtnall (append rtnall rtn))
4463 (with-current-buffer buffer
4464 (unless (derived-mode-p 'org-mode)
4465 (error "Agenda file %s is not in `org-mode'" file))
4466 (save-excursion
4467 (save-restriction
4468 (if org-agenda-restrict
4469 (narrow-to-region org-agenda-restrict-begin
4470 org-agenda-restrict-end)
4471 (widen))
4472 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4473 (setq rtnall (append rtnall rtn))))))))
4474 (if org-agenda-overriding-header
4475 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4476 nil 'face 'org-agenda-structure) "\n")
4477 (insert "Headlines with TAGS match: ")
4478 (add-text-properties (point-min) (1- (point))
4479 (list 'face 'org-agenda-structure
4480 'short-heading
4481 (concat "Match: " match)))
4482 (setq pos (point))
4483 (insert match "\n")
4484 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4485 (setq pos (point))
4486 (unless org-agenda-multi
4487 (insert "Press `C-u r' to search again with new search string\n"))
4488 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4489 (org-agenda-mark-header-line (point-min))
4490 (when rtnall
4491 (insert (org-agenda-finalize-entries rtnall) "\n"))
4492 (goto-char (point-min))
4493 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4494 (add-text-properties (point-min) (point-max)
4495 `(org-agenda-type tags
4496 org-last-args (,todo-only ,match)
4497 org-redo-cmd ,org-agenda-redo-command
4498 org-serie-cmd ,org-cmd))
4499 (org-agenda-finalize)
4500 (setq buffer-read-only t))))
4502 ;;; Agenda Finding stuck projects
4504 (defvar org-agenda-skip-regexp nil
4505 "Regular expression used in skipping subtrees for the agenda.
4506 This is basically a temporary global variable that can be set and then
4507 used by user-defined selections using `org-agenda-skip-function'.")
4509 (defvar org-agenda-overriding-header nil
4510 "When set during agenda, todo and tags searches it replaces the header.
4511 This variable should not be set directly, but custom commands can bind it
4512 in the options section.")
4514 (defun org-agenda-skip-entry-when-regexp-matches ()
4515 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4516 If yes, it returns the end position of this entry, causing agenda commands
4517 to skip the entry but continuing the search in the subtree. This is a
4518 function that can be put into `org-agenda-skip-function' for the duration
4519 of a command."
4520 (let ((end (save-excursion (org-end-of-subtree t)))
4521 skip)
4522 (save-excursion
4523 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4524 (and skip end)))
4526 (defun org-agenda-skip-subtree-when-regexp-matches ()
4527 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4528 If yes, it returns the end position of this tree, causing agenda commands
4529 to skip this subtree. This is a function that can be put into
4530 `org-agenda-skip-function' for the duration of a command."
4531 (let ((end (save-excursion (org-end-of-subtree t)))
4532 skip)
4533 (save-excursion
4534 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4535 (and skip end)))
4537 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4538 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4539 If yes, it returns the end position of the current entry (NOT the tree),
4540 causing agenda commands to skip the entry but continuing the search in
4541 the subtree. This is a function that can be put into
4542 `org-agenda-skip-function' for the duration of a command. An important
4543 use of this function is for the stuck project list."
4544 (let ((end (save-excursion (org-end-of-subtree t)))
4545 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4546 skip)
4547 (save-excursion
4548 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4549 (and skip entry-end)))
4551 (defun org-agenda-skip-entry-if (&rest conditions)
4552 "Skip entry if any of CONDITIONS is true.
4553 See `org-agenda-skip-if' for details."
4554 (org-agenda-skip-if nil conditions))
4556 (defun org-agenda-skip-subtree-if (&rest conditions)
4557 "Skip entry if any of CONDITIONS is true.
4558 See `org-agenda-skip-if' for details."
4559 (org-agenda-skip-if t conditions))
4561 (defun org-agenda-skip-if (subtree conditions)
4562 "Checks current entity for CONDITIONS.
4563 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4564 the entry (i.e. the text before the next heading) is checked.
4566 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4567 from different tests. Valid conditions are:
4569 scheduled Check if there is a scheduled cookie
4570 notscheduled Check if there is no scheduled cookie
4571 deadline Check if there is a deadline
4572 notdeadline Check if there is no deadline
4573 timestamp Check if there is a timestamp (also deadline or scheduled)
4574 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4575 regexp Check if regexp matches
4576 notregexp Check if regexp does not match.
4577 todo Check if TODO keyword matches
4578 nottodo Check if TODO keyword does not match
4580 The regexp is taken from the conditions list, it must come right after
4581 the `regexp' or `notregexp' element.
4583 `todo' and `nottodo' accept as an argument a list of todo
4584 keywords, which may include \"*\" to match any todo keyword.
4586 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4588 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4590 Instead of a list, a keyword class may be given. For example:
4592 (org-agenda-skip-entry-if 'nottodo 'done)
4594 would skip entries that haven't been marked with any of \"DONE\"
4595 keywords. Possible classes are: `todo', `done', `any'.
4597 If any of these conditions is met, this function returns the end point of
4598 the entity, causing the search to continue from there. This is a function
4599 that can be put into `org-agenda-skip-function' for the duration of a command."
4600 (let (beg end m)
4601 (org-back-to-heading t)
4602 (setq beg (point)
4603 end (if subtree
4604 (progn (org-end-of-subtree t) (point))
4605 (progn (outline-next-heading) (1- (point)))))
4606 (goto-char beg)
4607 (and
4609 (and (memq 'scheduled conditions)
4610 (re-search-forward org-scheduled-time-regexp end t))
4611 (and (memq 'notscheduled conditions)
4612 (not (re-search-forward org-scheduled-time-regexp end t)))
4613 (and (memq 'deadline conditions)
4614 (re-search-forward org-deadline-time-regexp end t))
4615 (and (memq 'notdeadline conditions)
4616 (not (re-search-forward org-deadline-time-regexp end t)))
4617 (and (memq 'timestamp conditions)
4618 (re-search-forward org-ts-regexp end t))
4619 (and (memq 'nottimestamp conditions)
4620 (not (re-search-forward org-ts-regexp end t)))
4621 (and (setq m (memq 'regexp conditions))
4622 (stringp (nth 1 m))
4623 (re-search-forward (nth 1 m) end t))
4624 (and (setq m (memq 'notregexp conditions))
4625 (stringp (nth 1 m))
4626 (not (re-search-forward (nth 1 m) end t)))
4627 (and (or
4628 (setq m (memq 'nottodo conditions))
4629 (setq m (memq 'todo-unblocked conditions))
4630 (setq m (memq 'nottodo-unblocked conditions))
4631 (setq m (memq 'todo conditions)))
4632 (org-agenda-skip-if-todo m end)))
4633 end)))
4635 (defun org-agenda-skip-if-todo (args end)
4636 "Helper function for `org-agenda-skip-if', do not use it directly.
4637 ARGS is a list with first element either `todo', `nottodo',
4638 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4639 a list of TODO keywords, or a state symbol `todo' or `done' or
4640 `any'."
4641 (let ((kw (car args))
4642 (arg (cadr args))
4643 todo-wds todo-re)
4644 (setq todo-wds
4645 (org-uniquify
4646 (cond
4647 ((listp arg) ;; list of keywords
4648 (if (member "*" arg)
4649 (mapcar 'substring-no-properties org-todo-keywords-1)
4650 arg))
4651 ((symbolp arg) ;; keyword class name
4652 (cond
4653 ((eq arg 'todo)
4654 (org-delete-all org-done-keywords
4655 (mapcar 'substring-no-properties
4656 org-todo-keywords-1)))
4657 ((eq arg 'done) org-done-keywords)
4658 ((eq arg 'any)
4659 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4660 (setq todo-re
4661 (concat "^\\*+[ \t]+\\<\\("
4662 (mapconcat 'identity todo-wds "\\|")
4663 "\\)\\>"))
4664 (cond
4665 ((eq kw 'todo) (re-search-forward todo-re end t))
4666 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4667 ((eq kw 'todo-unblocked)
4668 (catch 'unblocked
4669 (while (re-search-forward todo-re end t)
4670 (or (org-entry-blocked-p) (throw 'unblocked t)))
4671 nil))
4672 ((eq kw 'nottodo-unblocked)
4673 (catch 'unblocked
4674 (while (re-search-forward todo-re end t)
4675 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4679 ;;;###autoload
4680 (defun org-agenda-list-stuck-projects (&rest ignore)
4681 "Create agenda view for projects that are stuck.
4682 Stuck projects are project that have no next actions. For the definitions
4683 of what a project is and how to check if it stuck, customize the variable
4684 `org-stuck-projects'."
4685 (interactive)
4686 (let* ((org-agenda-skip-function
4687 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4688 ;; We could have used org-agenda-skip-if here.
4689 (org-agenda-overriding-header
4690 (or org-agenda-overriding-header "List of stuck projects: "))
4691 (matcher (nth 0 org-stuck-projects))
4692 (todo (nth 1 org-stuck-projects))
4693 (todo-wds (if (member "*" todo)
4694 (progn
4695 (org-agenda-prepare-buffers (org-agenda-files
4696 nil 'ifmode))
4697 (org-delete-all
4698 org-done-keywords-for-agenda
4699 (copy-sequence org-todo-keywords-for-agenda)))
4700 todo))
4701 (todo-re (concat "^\\*+[ \t]+\\("
4702 (mapconcat 'identity todo-wds "\\|")
4703 "\\)\\>"))
4704 (tags (nth 2 org-stuck-projects))
4705 (tags-re (if (member "*" tags)
4706 (concat org-outline-regexp-bol
4707 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4708 (if tags
4709 (concat org-outline-regexp-bol
4710 ".*:\\("
4711 (mapconcat 'identity tags "\\|")
4712 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4713 (gen-re (nth 3 org-stuck-projects))
4714 (re-list
4715 (delq nil
4716 (list
4717 (if todo todo-re)
4718 (if tags tags-re)
4719 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4720 gen-re)))))
4721 (setq org-agenda-skip-regexp
4722 (if re-list
4723 (mapconcat 'identity re-list "\\|")
4724 (error "No information how to identify unstuck projects")))
4725 (org-tags-view nil matcher)
4726 (with-current-buffer org-agenda-buffer-name
4727 (setq org-agenda-redo-command
4728 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4730 ;;; Diary integration
4732 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4733 (defvar diary-list-entries-hook)
4734 (defvar diary-time-regexp)
4735 (defun org-get-entries-from-diary (date)
4736 "Get the (Emacs Calendar) diary entries for DATE."
4737 (require 'diary-lib)
4738 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4739 (diary-display-hook '(fancy-diary-display))
4740 (diary-display-function 'fancy-diary-display)
4741 (pop-up-frames nil)
4742 (diary-list-entries-hook
4743 (cons 'org-diary-default-entry diary-list-entries-hook))
4744 (diary-file-name-prefix-function nil) ; turn this feature off
4745 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4746 entries
4747 (org-disable-agenda-to-diary t))
4748 (save-excursion
4749 (save-window-excursion
4750 (funcall (if (fboundp 'diary-list-entries)
4751 'diary-list-entries 'list-diary-entries)
4752 date 1)))
4753 (if (not (get-buffer diary-fancy-buffer))
4754 (setq entries nil)
4755 (with-current-buffer diary-fancy-buffer
4756 (setq buffer-read-only nil)
4757 (if (zerop (buffer-size))
4758 ;; No entries
4759 (setq entries nil)
4760 ;; Omit the date and other unnecessary stuff
4761 (org-agenda-cleanup-fancy-diary)
4762 ;; Add prefix to each line and extend the text properties
4763 (if (zerop (buffer-size))
4764 (setq entries nil)
4765 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4766 (setq entries
4767 (with-temp-buffer
4768 (insert entries) (goto-char (point-min))
4769 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4770 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4771 (replace-match (concat "; " (match-string 1)))))
4772 (buffer-string)))))
4773 (set-buffer-modified-p nil)
4774 (kill-buffer diary-fancy-buffer)))
4775 (when entries
4776 (setq entries (org-split-string entries "\n"))
4777 (setq entries
4778 (mapcar
4779 (lambda (x)
4780 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4781 ;; Extend the text properties to the beginning of the line
4782 (org-add-props x (text-properties-at (1- (length x)) x)
4783 'type "diary" 'date date 'face 'org-agenda-diary))
4784 entries)))))
4786 (defvar org-agenda-cleanup-fancy-diary-hook nil
4787 "Hook run when the fancy diary buffer is cleaned up.")
4789 (defun org-agenda-cleanup-fancy-diary ()
4790 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4791 This gets rid of the date, the underline under the date, and
4792 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4793 date. It also removes lines that contain only whitespace."
4794 (goto-char (point-min))
4795 (if (looking-at ".*?:[ \t]*")
4796 (progn
4797 (replace-match "")
4798 (re-search-forward "\n=+$" nil t)
4799 (replace-match "")
4800 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4801 (re-search-forward "\n=+$" nil t)
4802 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4803 (goto-char (point-min))
4804 (while (re-search-forward "^ +\n" nil t)
4805 (replace-match ""))
4806 (goto-char (point-min))
4807 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4808 (replace-match ""))
4809 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4811 ;; Make sure entries from the diary have the right text properties.
4812 (eval-after-load "diary-lib"
4813 '(if (boundp 'diary-modify-entry-list-string-function)
4814 ;; We can rely on the hook, nothing to do
4816 ;; Hook not available, must use advice to make this work
4817 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4818 "Make the position visible."
4819 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4820 (stringp string)
4821 buffer-file-name)
4822 (setq string (org-modify-diary-entry-string string))))))
4824 (defun org-modify-diary-entry-string (string)
4825 "Add text properties to string, allowing org-mode to act on it."
4826 (org-add-props string nil
4827 'mouse-face 'highlight
4828 'help-echo (if buffer-file-name
4829 (format "mouse-2 or RET jump to diary file %s"
4830 (abbreviate-file-name buffer-file-name))
4832 'org-agenda-diary-link t
4833 'org-marker (org-agenda-new-marker (point-at-bol))))
4835 (defun org-diary-default-entry ()
4836 "Add a dummy entry to the diary.
4837 Needed to avoid empty dates which mess up holiday display."
4838 ;; Catch the error if dealing with the new add-to-diary-alist
4839 (when org-disable-agenda-to-diary
4840 (condition-case nil
4841 (org-add-to-diary-list original-date "Org-mode dummy" "")
4842 (error
4843 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4845 (defun org-add-to-diary-list (&rest args)
4846 (if (fboundp 'diary-add-to-list)
4847 (apply 'diary-add-to-list args)
4848 (apply 'add-to-diary-list args)))
4850 (defvar org-diary-last-run-time nil)
4852 ;;;###autoload
4853 (defun org-diary (&rest args)
4854 "Return diary information from org files.
4855 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4856 It accesses org files and extracts information from those files to be
4857 listed in the diary. The function accepts arguments specifying what
4858 items should be listed. For a list of arguments allowed here, see the
4859 variable `org-agenda-entry-types'.
4861 The call in the diary file should look like this:
4863 &%%(org-diary) ~/path/to/some/orgfile.org
4865 Use a separate line for each org file to check. Or, if you omit the file name,
4866 all files listed in `org-agenda-files' will be checked automatically:
4868 &%%(org-diary)
4870 If you don't give any arguments (as in the example above), the default
4871 arguments (:deadline :scheduled :timestamp :sexp) are used.
4872 So the example above may also be written as
4874 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4876 The function expects the lisp variables `entry' and `date' to be provided
4877 by the caller, because this is how the calendar works. Don't use this
4878 function from a program - use `org-agenda-get-day-entries' instead."
4879 (when (> (- (org-float-time)
4880 org-agenda-last-marker-time)
4882 ;; I am not sure if this works with sticky agendas, because the marker
4883 ;; list is then no longer a global variable.
4884 (org-agenda-reset-markers))
4885 (org-compile-prefix-format 'agenda)
4886 (org-set-sorting-strategy 'agenda)
4887 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4888 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4889 (list entry)
4890 (org-agenda-files t)))
4891 (time (org-float-time))
4892 file rtn results)
4893 (when (or (not org-diary-last-run-time)
4894 (> (- time
4895 org-diary-last-run-time)
4897 (org-agenda-prepare-buffers files))
4898 (setq org-diary-last-run-time time)
4899 ;; If this is called during org-agenda, don't return any entries to
4900 ;; the calendar. Org Agenda will list these entries itself.
4901 (if org-disable-agenda-to-diary (setq files nil))
4902 (while (setq file (pop files))
4903 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4904 (setq results (append results rtn)))
4905 (if results
4906 (concat (org-agenda-finalize-entries results) "\n"))))
4908 ;;; Agenda entry finders
4910 (defun org-agenda-get-day-entries (file date &rest args)
4911 "Does the work for `org-diary' and `org-agenda'.
4912 FILE is the path to a file to be checked for entries. DATE is date like
4913 the one returned by `calendar-current-date'. ARGS are symbols indicating
4914 which kind of entries should be extracted. For details about these, see
4915 the documentation of `org-diary'."
4916 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4917 (let* ((org-startup-folded nil)
4918 (org-startup-align-all-tables nil)
4919 (buffer (if (file-exists-p file)
4920 (org-get-agenda-file-buffer file)
4921 (error "No such file %s" file)))
4922 arg results rtn deadline-results)
4923 (if (not buffer)
4924 ;; If file does not exist, make sure an error message ends up in diary
4925 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4926 (with-current-buffer buffer
4927 (unless (derived-mode-p 'org-mode)
4928 (error "Agenda file %s is not in `org-mode'" file))
4929 (setq org-agenda-buffer (or org-agenda-buffer buffer))
4930 (let ((case-fold-search nil))
4931 (save-excursion
4932 (save-restriction
4933 (if org-agenda-restrict
4934 (narrow-to-region org-agenda-restrict-begin
4935 org-agenda-restrict-end)
4936 (widen))
4937 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4938 (while (setq arg (pop args))
4939 (cond
4940 ((and (eq arg :todo)
4941 (equal date (calendar-gregorian-from-absolute
4942 (org-today))))
4943 (setq rtn (org-agenda-get-todos))
4944 (setq results (append results rtn)))
4945 ((eq arg :timestamp)
4946 (setq rtn (org-agenda-get-blocks))
4947 (setq results (append results rtn))
4948 (setq rtn (org-agenda-get-timestamps deadline-results))
4949 (setq results (append results rtn)))
4950 ((eq arg :sexp)
4951 (setq rtn (org-agenda-get-sexps))
4952 (setq results (append results rtn)))
4953 ((eq arg :scheduled)
4954 (setq rtn (org-agenda-get-scheduled deadline-results))
4955 (setq results (append results rtn)))
4956 ((eq arg :closed)
4957 (setq rtn (org-agenda-get-progress))
4958 (setq results (append results rtn)))
4959 ((eq arg :deadline)
4960 (setq rtn (org-agenda-get-deadlines))
4961 (setq deadline-results (copy-sequence rtn))
4962 (setq results (append results rtn))))))))
4963 results))))
4965 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4966 (defun org-agenda-get-todos ()
4967 "Return the TODO information for agenda display."
4968 (let* ((props (list 'face nil
4969 'done-face 'org-agenda-done
4970 'org-not-done-regexp org-not-done-regexp
4971 'org-todo-regexp org-todo-regexp
4972 'org-complex-heading-regexp org-complex-heading-regexp
4973 'mouse-face 'highlight
4974 'help-echo
4975 (format "mouse-2 or RET jump to org file %s"
4976 (abbreviate-file-name buffer-file-name))))
4977 (regexp (format org-heading-keyword-regexp-format
4978 (cond
4979 ((and org-select-this-todo-keyword
4980 (equal org-select-this-todo-keyword "*"))
4981 org-todo-regexp)
4982 (org-select-this-todo-keyword
4983 (concat "\\("
4984 (mapconcat 'identity
4985 (org-split-string
4986 org-select-this-todo-keyword
4987 "|")
4988 "\\|") "\\)"))
4989 (t org-not-done-regexp))))
4990 marker priority category category-pos tags todo-state
4991 ee txt beg end)
4992 (goto-char (point-min))
4993 (while (re-search-forward regexp nil t)
4994 (catch :skip
4995 (save-match-data
4996 (beginning-of-line)
4997 (org-agenda-skip)
4998 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4999 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5000 (goto-char (1+ beg))
5001 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5002 (throw :skip nil)))
5003 (goto-char (match-beginning 2))
5004 (setq marker (org-agenda-new-marker (match-beginning 0))
5005 category (org-get-category)
5006 category-pos (get-text-property (point) 'org-category-position)
5007 txt (org-trim
5008 (buffer-substring (match-beginning 2) (match-end 0)))
5009 tags (org-get-tags-at (point))
5010 txt (org-agenda-format-item "" txt category tags)
5011 priority (1+ (org-get-priority txt))
5012 todo-state (org-get-todo-state))
5013 (org-add-props txt props
5014 'org-marker marker 'org-hd-marker marker
5015 'priority priority 'org-category category
5016 'org-category-position category-pos
5017 'type "todo" 'todo-state todo-state)
5018 (push txt ee)
5019 (if org-agenda-todo-list-sublevels
5020 (goto-char (match-end 2))
5021 (org-end-of-subtree 'invisible))))
5022 (nreverse ee)))
5024 (defun org-agenda-todo-custom-ignore-p (time n)
5025 "Check whether timestamp is farther away then n number of days.
5026 This function is invoked if `org-agenda-todo-ignore-deadlines',
5027 `org-agenda-todo-ignore-scheduled' or
5028 `org-agenda-todo-ignore-timestamp' is set to an integer."
5029 (let ((days (org-days-to-time time)))
5030 (if (>= n 0)
5031 (>= days n)
5032 (<= days n))))
5034 ;;;###autoload
5035 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5036 (&optional end)
5037 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5038 (when (or org-agenda-todo-ignore-with-date
5039 org-agenda-todo-ignore-scheduled
5040 org-agenda-todo-ignore-deadlines
5041 org-agenda-todo-ignore-timestamp)
5042 (setq end (or end (save-excursion (outline-next-heading) (point))))
5043 (save-excursion
5044 (or (and org-agenda-todo-ignore-with-date
5045 (re-search-forward org-ts-regexp end t))
5046 (and org-agenda-todo-ignore-scheduled
5047 (re-search-forward org-scheduled-time-regexp end t)
5048 (cond
5049 ((eq org-agenda-todo-ignore-scheduled 'future)
5050 (> (org-days-to-time (match-string 1)) 0))
5051 ((eq org-agenda-todo-ignore-scheduled 'past)
5052 (<= (org-days-to-time (match-string 1)) 0))
5053 ((numberp org-agenda-todo-ignore-scheduled)
5054 (org-agenda-todo-custom-ignore-p
5055 (match-string 1) org-agenda-todo-ignore-scheduled))
5056 (t)))
5057 (and org-agenda-todo-ignore-deadlines
5058 (re-search-forward org-deadline-time-regexp end t)
5059 (cond
5060 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5061 ((eq org-agenda-todo-ignore-deadlines 'far)
5062 (not (org-deadline-close (match-string 1))))
5063 ((eq org-agenda-todo-ignore-deadlines 'future)
5064 (> (org-days-to-time (match-string 1)) 0))
5065 ((eq org-agenda-todo-ignore-deadlines 'past)
5066 (<= (org-days-to-time (match-string 1)) 0))
5067 ((numberp org-agenda-todo-ignore-deadlines)
5068 (org-agenda-todo-custom-ignore-p
5069 (match-string 1) org-agenda-todo-ignore-deadlines))
5070 (t (org-deadline-close (match-string 1)))))
5071 (and org-agenda-todo-ignore-timestamp
5072 (let ((buffer (current-buffer))
5073 (regexp
5074 (concat
5075 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5076 (start (point)))
5077 ;; Copy current buffer into a temporary one
5078 (with-temp-buffer
5079 (insert-buffer-substring buffer start end)
5080 (goto-char (point-min))
5081 ;; Delete SCHEDULED and DEADLINE items
5082 (while (re-search-forward regexp end t)
5083 (delete-region (match-beginning 0) (match-end 0)))
5084 (goto-char (point-min))
5085 ;; No search for timestamp left
5086 (when (re-search-forward org-ts-regexp nil t)
5087 (cond
5088 ((eq org-agenda-todo-ignore-timestamp 'future)
5089 (> (org-days-to-time (match-string 1)) 0))
5090 ((eq org-agenda-todo-ignore-timestamp 'past)
5091 (<= (org-days-to-time (match-string 1)) 0))
5092 ((numberp org-agenda-todo-ignore-timestamp)
5093 (org-agenda-todo-custom-ignore-p
5094 (match-string 1) org-agenda-todo-ignore-timestamp))
5095 (t))))))))))
5097 (defconst org-agenda-no-heading-message
5098 "No heading for this item in buffer or region.")
5100 (defun org-agenda-get-timestamps (&optional deadline-results)
5101 "Return the date stamp information for agenda display."
5102 (let* ((props (list 'face 'org-agenda-calendar-event
5103 'org-not-done-regexp org-not-done-regexp
5104 'org-todo-regexp org-todo-regexp
5105 'org-complex-heading-regexp org-complex-heading-regexp
5106 'mouse-face 'highlight
5107 'help-echo
5108 (format "mouse-2 or RET jump to org file %s"
5109 (abbreviate-file-name buffer-file-name))))
5110 (d1 (calendar-absolute-from-gregorian date))
5112 (deadline-position-alist
5113 (mapcar (lambda (a) (and (setq mm (get-text-property
5114 0 'org-hd-marker a))
5115 (cons (marker-position mm) a)))
5116 deadline-results))
5117 (remove-re org-ts-regexp)
5118 (regexp
5119 (concat
5120 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5121 (regexp-quote
5122 (substring
5123 (format-time-string
5124 (car org-time-stamp-formats)
5125 (apply 'encode-time ; DATE bound by calendar
5126 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5127 1 11))
5128 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5129 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5130 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5131 donep tmp priority category category-pos ee txt timestr tags
5132 b0 b3 e3 head todo-state end-of-match show-all warntime)
5133 (goto-char (point-min))
5134 (while (setq end-of-match (re-search-forward regexp nil t))
5135 (setq b0 (match-beginning 0)
5136 b3 (match-beginning 3) e3 (match-end 3)
5137 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5138 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5139 (member todo-state
5140 org-agenda-repeating-timestamp-show-all)))
5141 (catch :skip
5142 (and (org-at-date-range-p) (throw :skip nil))
5143 (org-agenda-skip)
5144 (if (and (match-end 1)
5145 (not (= d1 (org-time-string-to-absolute
5146 (match-string 1) d1 nil show-all
5147 (current-buffer) b0))))
5148 (throw :skip nil))
5149 (if (and e3
5150 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5151 (throw :skip nil))
5152 (setq tmp (buffer-substring (max (point-min)
5153 (- b0 org-ds-keyword-length))
5155 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5156 inactivep (= (char-after b0) ?\[)
5157 deadlinep (string-match org-deadline-regexp tmp)
5158 scheduledp (string-match org-scheduled-regexp tmp)
5159 closedp (and org-agenda-include-inactive-timestamps
5160 (string-match org-closed-string tmp))
5161 clockp (and org-agenda-include-inactive-timestamps
5162 (or (string-match org-clock-string tmp)
5163 (string-match "]-+\\'" tmp)))
5164 warntime (org-entry-get (point) "APPT_WARNTIME")
5165 donep (member todo-state org-done-keywords))
5166 (if (or scheduledp deadlinep closedp clockp
5167 (and donep org-agenda-skip-timestamp-if-done))
5168 (throw :skip t))
5169 (if (string-match ">" timestr)
5170 ;; substring should only run to end of time stamp
5171 (setq timestr (substring timestr 0 (match-end 0))))
5172 (setq marker (org-agenda-new-marker b0)
5173 category (org-get-category b0)
5174 category-pos (get-text-property b0 'org-category-position))
5175 (save-excursion
5176 (if (not (re-search-backward org-outline-regexp-bol nil t))
5177 (setq txt org-agenda-no-heading-message)
5178 (goto-char (match-beginning 0))
5179 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5180 (assoc (point) deadline-position-alist))
5181 (throw :skip nil))
5182 (setq hdmarker (org-agenda-new-marker)
5183 tags (org-get-tags-at))
5184 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5185 (setq head (or (match-string 1) ""))
5186 (setq txt (org-agenda-format-item
5187 (if inactivep org-agenda-inactive-leader nil)
5188 head category tags timestr
5189 remove-re)))
5190 (setq priority (org-get-priority txt))
5191 (org-add-props txt props
5192 'org-marker marker 'org-hd-marker hdmarker)
5193 (org-add-props txt nil 'priority priority
5194 'org-category category 'date date
5195 'org-category-position category-pos
5196 'todo-state todo-state
5197 'warntime warntime
5198 'type "timestamp")
5199 (push txt ee))
5200 (if org-agenda-skip-additional-timestamps-same-entry
5201 (outline-next-heading)
5202 (goto-char end-of-match))))
5203 (nreverse ee)))
5205 (defun org-agenda-get-sexps ()
5206 "Return the sexp information for agenda display."
5207 (require 'diary-lib)
5208 (let* ((props (list 'face 'org-agenda-calendar-sexp
5209 'mouse-face 'highlight
5210 'help-echo
5211 (format "mouse-2 or RET jump to org file %s"
5212 (abbreviate-file-name buffer-file-name))))
5213 (regexp "^&?%%(")
5214 marker category extra category-pos ee txt tags entry
5215 result beg b sexp sexp-entry todo-state warntime)
5216 (goto-char (point-min))
5217 (while (re-search-forward regexp nil t)
5218 (catch :skip
5219 (org-agenda-skip)
5220 (setq beg (match-beginning 0))
5221 (goto-char (1- (match-end 0)))
5222 (setq b (point))
5223 (forward-sexp 1)
5224 (setq sexp (buffer-substring b (point)))
5225 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5226 (org-trim (match-string 1))
5227 ""))
5228 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5229 (when result
5230 (setq marker (org-agenda-new-marker beg)
5231 category (org-get-category beg)
5232 category-pos (get-text-property beg 'org-category-position)
5233 tags (save-excursion (org-backward-heading-same-level 0)
5234 (org-get-tags-at))
5235 todo-state (org-get-todo-state)
5236 warntime (org-entry-get (point) "APPT_WARNTIME"))
5238 (dolist (r (if (stringp result)
5239 (list result)
5240 result)) ;; we expect a list here
5241 (when (and org-agenda-diary-sexp-prefix
5242 (string-match org-agenda-diary-sexp-prefix r))
5243 (setq extra (match-string 0 r)
5244 r (replace-match "" nil nil r)))
5245 (if (string-match "\\S-" r)
5246 (setq txt r)
5247 (setq txt "SEXP entry returned empty string"))
5249 (setq txt (org-agenda-format-item
5250 extra txt category tags 'time))
5251 (org-add-props txt props 'org-marker marker)
5252 (org-add-props txt nil
5253 'org-category category 'date date 'todo-state todo-state
5254 'org-category-position category-pos 'tags tags
5255 'type "sexp" 'warntime warntime)
5256 (push txt ee)))))
5257 (nreverse ee)))
5259 ;; Calendar sanity: define some functions that are independent of
5260 ;; `calendar-date-style'.
5261 ;; Normally I would like to use ISO format when calling the diary functions,
5262 ;; but to make sure we still have Emacs 22 compatibility we bind
5263 ;; also `european-calendar-style' and use european format
5264 (defun org-anniversary (year month day &optional mark)
5265 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5266 (org-no-warnings
5267 (let ((calendar-date-style 'european) (european-calendar-style t))
5268 (diary-anniversary day month year mark))))
5269 (defun org-cyclic (N year month day &optional mark)
5270 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5271 (org-no-warnings
5272 (let ((calendar-date-style 'european) (european-calendar-style t))
5273 (diary-cyclic N day month year mark))))
5274 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5275 "Like `diary-block', but with fixed (ISO) order of arguments."
5276 (org-no-warnings
5277 (let ((calendar-date-style 'european) (european-calendar-style t))
5278 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5279 (defun org-date (year month day &optional mark)
5280 "Like `diary-date', but with fixed (ISO) order of arguments."
5281 (org-no-warnings
5282 (let ((calendar-date-style 'european) (european-calendar-style t))
5283 (diary-date day month year mark))))
5284 (defalias 'org-float 'diary-float)
5286 ;; Define the` org-class' function
5287 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5288 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5289 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5290 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5291 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5292 `holidays', then any date that is known by the Emacs calendar to be a
5293 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5294 then those holidays will be skipped."
5295 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5296 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5297 (d (calendar-absolute-from-gregorian date))
5298 (h (when skip-weeks (calendar-check-holidays date))))
5299 (and
5300 (<= date1 d)
5301 (<= d date2)
5302 (= (calendar-day-of-week date) dayname)
5303 (or (not skip-weeks)
5304 (progn
5305 (require 'cal-iso)
5306 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5307 (not (or (and h (memq 'holidays skip-weeks))
5308 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5309 entry)))
5311 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5312 "Like `org-class', but honor `calendar-date-style'.
5313 The order of the first 2 times 3 arguments depends on the variable
5314 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5315 So for American calendars, give this as MONTH DAY YEAR, for European as
5316 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5317 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5318 is any number of ISO weeks in the block period for which the item should
5319 be skipped.
5321 This function is here only for backward compatibility and it is deprecated,
5322 please use `org-class' instead."
5323 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5324 (date2 (org-order-calendar-date-args m2 d2 y2)))
5325 (org-class
5326 (nth 2 date1) (car date1) (nth 1 date1)
5327 (nth 2 date2) (car date2) (nth 1 date2)
5328 dayname skip-weeks)))
5329 (make-obsolete 'org-diary-class 'org-class "")
5331 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5332 (defalias 'org-get-closed 'org-agenda-get-progress)
5333 (defun org-agenda-get-progress ()
5334 "Return the logged TODO entries for agenda display."
5335 (let* ((props (list 'mouse-face 'highlight
5336 'org-not-done-regexp org-not-done-regexp
5337 'org-todo-regexp org-todo-regexp
5338 'org-complex-heading-regexp org-complex-heading-regexp
5339 'help-echo
5340 (format "mouse-2 or RET jump to org file %s"
5341 (abbreviate-file-name buffer-file-name))))
5342 (items (if (consp org-agenda-show-log-scoped)
5343 org-agenda-show-log-scoped
5344 (if (eq org-agenda-show-log-scoped 'clockcheck)
5345 '(clock)
5346 org-agenda-log-mode-items)))
5347 (parts
5348 (delq nil
5349 (list
5350 (if (memq 'closed items) (concat "\\<" org-closed-string))
5351 (if (memq 'clock items) (concat "\\<" org-clock-string))
5352 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5353 (parts-re (if parts (mapconcat 'identity parts "\\|")
5354 (error "`org-agenda-log-mode-items' is empty")))
5355 (regexp (concat
5356 "\\(" parts-re "\\)"
5357 " *\\["
5358 (regexp-quote
5359 (substring
5360 (format-time-string
5361 (car org-time-stamp-formats)
5362 (apply 'encode-time ; DATE bound by calendar
5363 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5364 1 11))))
5365 (org-agenda-search-headline-for-time nil)
5366 marker hdmarker priority category category-pos tags closedp
5367 statep clockp state ee txt extra timestr rest clocked)
5368 (goto-char (point-min))
5369 (while (re-search-forward regexp nil t)
5370 (catch :skip
5371 (org-agenda-skip)
5372 (setq marker (org-agenda-new-marker (match-beginning 0))
5373 closedp (equal (match-string 1) org-closed-string)
5374 statep (equal (string-to-char (match-string 1)) ?-)
5375 clockp (not (or closedp statep))
5376 state (and statep (match-string 2))
5377 category (org-get-category (match-beginning 0))
5378 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5379 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5380 (when (string-match "\\]" timestr)
5381 ;; substring should only run to end of time stamp
5382 (setq rest (substring timestr (match-end 0))
5383 timestr (substring timestr 0 (match-end 0)))
5384 (if (and (not closedp) (not statep)
5385 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5386 rest))
5387 (progn (setq timestr (concat (substring timestr 0 -1)
5388 "-" (match-string 1 rest) "]"))
5389 (setq clocked (match-string 2 rest)))
5390 (setq clocked "-")))
5391 (save-excursion
5392 (setq extra
5393 (cond
5394 ((not org-agenda-log-mode-add-notes) nil)
5395 (statep
5396 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5397 (match-string 1)))
5398 (clockp
5399 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5400 (match-string 1)))))
5401 (if (not (re-search-backward org-outline-regexp-bol nil t))
5402 (setq txt org-agenda-no-heading-message)
5403 (goto-char (match-beginning 0))
5404 (setq hdmarker (org-agenda-new-marker)
5405 tags (org-get-tags-at))
5406 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5407 (setq txt (match-string 1))
5408 (when extra
5409 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5410 (setq txt (concat (substring txt 0 (match-beginning 1))
5411 " - " extra " " (match-string 2 txt)))
5412 (setq txt (concat txt " - " extra))))
5413 (setq txt (org-agenda-format-item
5414 (cond
5415 (closedp "Closed: ")
5416 (statep (concat "State: (" state ")"))
5417 (t (concat "Clocked: (" clocked ")")))
5418 txt category tags timestr)))
5419 (setq priority 100000)
5420 (org-add-props txt props
5421 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5422 'priority priority 'org-category category
5423 'org-category-position category-pos
5424 'type "closed" 'date date
5425 'undone-face 'org-warning 'done-face 'org-agenda-done)
5426 (push txt ee))
5427 (goto-char (point-at-eol))))
5428 (nreverse ee)))
5430 (defun org-agenda-show-clocking-issues ()
5431 "Add overlays, showing issues with clocking.
5432 See also the user option `org-agenda-clock-consistency-checks'."
5433 (interactive)
5434 (let* ((pl org-agenda-clock-consistency-checks)
5435 (re (concat "^[ \t]*"
5436 org-clock-string
5437 "[ \t]+"
5438 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5439 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5440 (tlstart 0.)
5441 (tlend 0.)
5442 (maxtime (org-hh:mm-string-to-minutes
5443 (or (plist-get pl :max-duration) "24:00")))
5444 (mintime (org-hh:mm-string-to-minutes
5445 (or (plist-get pl :min-duration) 0)))
5446 (maxgap (org-hh:mm-string-to-minutes
5447 ;; default 30:00 means never complain
5448 (or (plist-get pl :max-gap) "30:00")))
5449 (gapok (mapcar 'org-hh:mm-string-to-minutes
5450 (plist-get pl :gap-ok-around)))
5451 (def-face (or (plist-get pl :default-face)
5452 '((:background "DarkRed") (:foreground "white"))))
5453 issue face m te ts dt ov)
5454 (goto-char (point-min))
5455 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5456 (setq issue nil face def-face)
5457 (catch 'next
5458 (setq m (org-get-at-bol 'org-marker)
5459 te nil ts nil)
5460 (unless (and m (markerp m))
5461 (setq issue "No valid clock line") (throw 'next t))
5462 (org-with-point-at m
5463 (save-excursion
5464 (goto-char (point-at-bol))
5465 (unless (looking-at re)
5466 (error "No valid Clock line")
5467 (throw 'next t))
5468 (unless (match-end 3)
5469 (setq issue "No end time"
5470 face (or (plist-get pl :no-end-time-face) face))
5471 (throw 'next t))
5472 (setq ts (match-string 1)
5473 te (match-string 3)
5474 ts (org-float-time
5475 (apply 'encode-time (org-parse-time-string ts)))
5476 te (org-float-time
5477 (apply 'encode-time (org-parse-time-string te)))
5478 dt (- te ts))))
5479 (cond
5480 ((> dt (* 60 maxtime))
5481 ;; a very long clocking chunk
5482 (setq issue (format "Clocking interval is very long: %s"
5483 (org-minutes-to-hh:mm-string
5484 (floor (/ (float dt) 60.))))
5485 face (or (plist-get pl :long-face) face)))
5486 ((< dt (* 60 mintime))
5487 ;; a very short clocking chunk
5488 (setq issue (format "Clocking interval is very short: %s"
5489 (org-minutes-to-hh:mm-string
5490 (floor (/ (float dt) 60.))))
5491 face (or (plist-get pl :short-face) face)))
5492 ((and (> tlend 0) (< ts tlend))
5493 ;; Two clock entries are overlapping
5494 (setq issue (format "Clocking overlap: %d minutes"
5495 (/ (- tlend ts) 60))
5496 face (or (plist-get pl :overlap-face) face)))
5497 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5498 ;; There is a gap, lets see if we need to report it
5499 (unless (org-agenda-check-clock-gap tlend ts gapok)
5500 (setq issue (format "Clocking gap: %d minutes"
5501 (/ (- ts tlend) 60))
5502 face (or (plist-get pl :gap-face) face))))
5503 (t nil)))
5504 (setq tlend (or te tlend) tlstart (or ts tlstart))
5505 (when issue
5506 ;; OK, there was some issue, add an overlay to show the issue
5507 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5508 (overlay-put ov 'before-string
5509 (concat
5510 (org-add-props
5511 (format "%-43s" (concat " " issue))
5513 'face face)
5514 "\n"))
5515 (overlay-put ov 'evaporate t)))))
5517 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5518 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5519 (catch 'exit
5520 (unless ok-list
5521 ;; there are no OK times for gaps...
5522 (throw 'exit nil))
5523 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5524 ;; This is more than 24 hours, so it is OK.
5525 ;; because we have at least one OK time, that must be in the
5526 ;; 24 hour interval.
5527 (throw 'exit t))
5528 ;; We have a shorter gap.
5529 ;; Now we have to get the minute of the day when these times are
5530 (let* ((t1dec (decode-time (seconds-to-time t1)))
5531 (t2dec (decode-time (seconds-to-time t2)))
5532 ;; compute the minute on the day
5533 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5534 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5535 (when (< min2 min1)
5536 ;; if min2 is smaller than min1, this means it is on the next day.
5537 ;; Wrap it to after midnight.
5538 (setq min2 (+ min2 1440)))
5539 ;; Now check if any of the OK times is in the gap
5540 (mapc (lambda (x)
5541 ;; Wrap the time to after midnight if necessary
5542 (if (< x min1) (setq x (+ x 1440)))
5543 ;; Check if in interval
5544 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5545 ok-list)
5546 ;; Nope, this gap is not OK
5547 nil)))
5549 (defun org-agenda-get-deadlines ()
5550 "Return the deadline information for agenda display."
5551 (let* ((props (list 'mouse-face 'highlight
5552 'org-not-done-regexp org-not-done-regexp
5553 'org-todo-regexp org-todo-regexp
5554 'org-complex-heading-regexp org-complex-heading-regexp
5555 'help-echo
5556 (format "mouse-2 or RET jump to org file %s"
5557 (abbreviate-file-name buffer-file-name))))
5558 (regexp org-deadline-time-regexp)
5559 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5560 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5561 d2 diff dfrac wdays pos pos1 category category-pos
5562 tags suppress-prewarning ee txt head face s todo-state
5563 show-all upcomingp donep timestr warntime)
5564 (goto-char (point-min))
5565 (while (re-search-forward regexp nil t)
5566 (setq suppress-prewarning nil)
5567 (catch :skip
5568 (org-agenda-skip)
5569 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5570 (save-match-data
5571 (string-match org-scheduled-time-regexp
5572 (buffer-substring (point-at-bol)
5573 (point-at-eol)))))
5574 (setq suppress-prewarning
5575 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5576 org-agenda-skip-deadline-prewarning-if-scheduled
5577 0)))
5578 (setq s (match-string 1)
5579 txt nil
5580 pos (1- (match-beginning 1))
5581 todo-state (save-match-data (org-get-todo-state))
5582 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5583 (member todo-state
5584 org-agenda-repeating-timestamp-show-all))
5585 d2 (org-time-string-to-absolute
5586 (match-string 1) d1 'past show-all
5587 (current-buffer) pos)
5588 diff (- d2 d1)
5589 wdays (if suppress-prewarning
5590 (let ((org-deadline-warning-days suppress-prewarning))
5591 (org-get-wdays s))
5592 (org-get-wdays s))
5593 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5594 upcomingp (and todayp (> diff 0)))
5595 ;; When to show a deadline in the calendar:
5596 ;; If the expiration is within wdays warning time.
5597 ;; Past-due deadlines are only shown on the current date
5598 (if (and (or (and (<= diff wdays)
5599 (and todayp (not org-agenda-only-exact-dates)))
5600 (= diff 0)))
5601 (save-excursion
5602 ;; (setq todo-state (org-get-todo-state))
5603 (setq donep (member todo-state org-done-keywords))
5604 (if (and donep
5605 (or org-agenda-skip-deadline-if-done
5606 (not (= diff 0))))
5607 (setq txt nil)
5608 (setq category (org-get-category)
5609 warntime (org-entry-get (point) "APPT_WARNTIME")
5610 category-pos (get-text-property (point) 'org-category-position))
5611 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5612 (setq txt org-agenda-no-heading-message)
5613 (goto-char (match-end 0))
5614 (setq pos1 (match-beginning 0))
5615 (setq tags (org-get-tags-at pos1))
5616 (setq head (buffer-substring-no-properties
5617 (point)
5618 (progn (skip-chars-forward "^\r\n")
5619 (point))))
5620 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5621 (setq timestr
5622 (concat (substring s (match-beginning 1)) " "))
5623 (setq timestr 'time))
5624 (setq txt (org-agenda-format-item
5625 (if (= diff 0)
5626 (car org-agenda-deadline-leaders)
5627 (if (functionp
5628 (nth 1 org-agenda-deadline-leaders))
5629 (funcall
5630 (nth 1 org-agenda-deadline-leaders)
5631 diff date)
5632 (format (nth 1 org-agenda-deadline-leaders)
5633 diff)))
5634 head category tags
5635 (if (not (= diff 0)) nil timestr)))))
5636 (when txt
5637 (setq face (org-agenda-deadline-face dfrac))
5638 (org-add-props txt props
5639 'org-marker (org-agenda-new-marker pos)
5640 'warntime warntime
5641 'org-hd-marker (org-agenda-new-marker pos1)
5642 'priority (+ (- diff)
5643 (org-get-priority txt))
5644 'org-category category
5645 'org-category-position category-pos
5646 'todo-state todo-state
5647 'type (if upcomingp "upcoming-deadline" "deadline")
5648 'date (if upcomingp date d2)
5649 'face (if donep 'org-agenda-done face)
5650 'undone-face face 'done-face 'org-agenda-done)
5651 (push txt ee))))))
5652 (nreverse ee)))
5654 (defun org-agenda-deadline-face (fraction)
5655 "Return the face to displaying a deadline item.
5656 FRACTION is what fraction of the head-warning time has passed."
5657 (let ((faces org-agenda-deadline-faces) f)
5658 (catch 'exit
5659 (while (setq f (pop faces))
5660 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5662 (defun org-agenda-get-scheduled (&optional deadline-results)
5663 "Return the scheduled information for agenda display."
5664 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5665 'org-todo-regexp org-todo-regexp
5666 'org-complex-heading-regexp org-complex-heading-regexp
5667 'done-face 'org-agenda-done
5668 'mouse-face 'highlight
5669 'help-echo
5670 (format "mouse-2 or RET jump to org file %s"
5671 (abbreviate-file-name buffer-file-name))))
5672 (regexp org-scheduled-time-regexp)
5673 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5674 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5676 (deadline-position-alist
5677 (mapcar (lambda (a) (and (setq mm (get-text-property
5678 0 'org-hd-marker a))
5679 (cons (marker-position mm) a)))
5680 deadline-results))
5681 d2 diff pos pos1 category category-pos tags donep
5682 ee txt head pastschedp todo-state face timestr s habitp show-all
5683 did-habit-check-p warntime)
5684 (goto-char (point-min))
5685 (while (re-search-forward regexp nil t)
5686 (catch :skip
5687 (org-agenda-skip)
5688 (setq s (match-string 1)
5689 txt nil
5690 pos (1- (match-beginning 1))
5691 todo-state (save-match-data (org-get-todo-state))
5692 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5693 (member todo-state
5694 org-agenda-repeating-timestamp-show-all))
5695 d2 (org-time-string-to-absolute
5696 (match-string 1) d1 'past show-all
5697 (current-buffer) pos)
5698 diff (- d2 d1)
5699 warntime (org-entry-get (point) "APPT_WARNTIME"))
5700 (setq pastschedp (and todayp (< diff 0)))
5701 (setq did-habit-check-p nil)
5702 ;; When to show a scheduled item in the calendar:
5703 ;; If it is on or past the date.
5704 (when (or (and (< diff 0)
5705 (< (abs diff) org-scheduled-past-days)
5706 (and todayp (not org-agenda-only-exact-dates)))
5707 (= diff 0)
5708 ;; org-is-habit-p uses org-entry-get, which is expansive
5709 ;; so we go extra mile to only call it once
5710 (and todayp
5711 org-habit-show-all-today
5712 (setq did-habit-check-p t)
5713 (setq habitp (and (functionp 'org-is-habit-p)
5714 (org-is-habit-p)))))
5715 (save-excursion
5716 (setq donep (member todo-state org-done-keywords))
5717 (if (and donep
5718 (or org-agenda-skip-scheduled-if-done
5719 (not (= diff 0))
5720 (and (functionp 'org-is-habit-p)
5721 (org-is-habit-p))))
5722 (setq txt nil)
5723 (setq habitp (if did-habit-check-p habitp
5724 (and (functionp 'org-is-habit-p)
5725 (org-is-habit-p))))
5726 (setq category (org-get-category)
5727 category-pos (get-text-property (point) 'org-category-position))
5728 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5729 (setq txt org-agenda-no-heading-message)
5730 (goto-char (match-end 0))
5731 (setq pos1 (match-beginning 0))
5732 (if habitp
5733 (if (or (not org-habit-show-habits)
5734 (and (not todayp)
5735 org-habit-show-habits-only-for-today))
5736 (throw :skip nil))
5737 (if (and
5738 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5739 (and org-agenda-skip-scheduled-if-deadline-is-shown
5740 pastschedp))
5741 (setq mm (assoc pos1 deadline-position-alist)))
5742 (throw :skip nil)))
5743 (setq tags (org-get-tags-at))
5744 (setq head (buffer-substring-no-properties
5745 (point)
5746 (progn (skip-chars-forward "^\r\n") (point))))
5747 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5748 (setq timestr
5749 (concat (substring s (match-beginning 1)) " "))
5750 (setq timestr 'time))
5751 (setq txt (org-agenda-format-item
5752 (if (= diff 0)
5753 (car org-agenda-scheduled-leaders)
5754 (format (nth 1 org-agenda-scheduled-leaders)
5755 (- 1 diff)))
5756 head category tags
5757 (if (not (= diff 0)) nil timestr)
5758 nil habitp))))
5759 (when txt
5760 (setq face
5761 (cond
5762 ((and (not habitp) pastschedp)
5763 'org-scheduled-previously)
5764 (todayp 'org-scheduled-today)
5765 (t 'org-scheduled))
5766 habitp (and habitp (org-habit-parse-todo)))
5767 (org-add-props txt props
5768 'undone-face face
5769 'face (if donep 'org-agenda-done face)
5770 'org-marker (org-agenda-new-marker pos)
5771 'org-hd-marker (org-agenda-new-marker pos1)
5772 'type (if pastschedp "past-scheduled" "scheduled")
5773 'date (if pastschedp d2 date)
5774 'warntime warntime
5775 'priority (if habitp
5776 (org-habit-get-priority habitp)
5777 (+ 94 (- 5 diff) (org-get-priority txt)))
5778 'org-category category
5779 'category-position category-pos
5780 'org-habit-p habitp
5781 'todo-state todo-state)
5782 (push txt ee))))))
5783 (nreverse ee)))
5785 (defun org-agenda-get-blocks ()
5786 "Return the date-range information for agenda display."
5787 (let* ((props (list 'face nil
5788 'org-not-done-regexp org-not-done-regexp
5789 'org-todo-regexp org-todo-regexp
5790 'org-complex-heading-regexp org-complex-heading-regexp
5791 'mouse-face 'highlight
5792 'help-echo
5793 (format "mouse-2 or RET jump to org file %s"
5794 (abbreviate-file-name buffer-file-name))))
5795 (regexp org-tr-regexp)
5796 (d0 (calendar-absolute-from-gregorian date))
5797 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
5798 todo-state tags pos head donep)
5799 (goto-char (point-min))
5800 (while (re-search-forward regexp nil t)
5801 (catch :skip
5802 (org-agenda-skip)
5803 (setq pos (point))
5804 (let ((start-time (match-string 1))
5805 (end-time (match-string 2)))
5806 (setq s1 (match-string 1)
5807 s2 (match-string 2)
5808 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5809 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5810 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5811 ;; Only allow days between the limits, because the normal
5812 ;; date stamps will catch the limits.
5813 (save-excursion
5814 (setq todo-state (org-get-todo-state))
5815 (setq donep (member todo-state org-done-keywords))
5816 (if (and donep org-agenda-skip-timestamp-if-done)
5817 (throw :skip t))
5818 (setq marker (org-agenda-new-marker (point)))
5819 (setq category (org-get-category)
5820 category-pos (get-text-property (point) 'org-category-position))
5821 (if (not (re-search-backward org-outline-regexp-bol nil t))
5822 (setq txt org-agenda-no-heading-message)
5823 (goto-char (match-beginning 0))
5824 (setq hdmarker (org-agenda-new-marker (point)))
5825 (setq tags (org-get-tags-at))
5826 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5827 (setq head (match-string 1))
5828 (let ((remove-re
5829 (if org-agenda-remove-timeranges-from-blocks
5830 (concat
5831 "<" (regexp-quote s1) ".*?>"
5832 "--"
5833 "<" (regexp-quote s2) ".*?>")
5834 nil)))
5835 (setq txt (org-agenda-format-item
5836 (format
5837 (nth (if (= d1 d2) 0 1)
5838 org-agenda-timerange-leaders)
5839 (1+ (- d0 d1)) (1+ (- d2 d1)))
5840 head category tags
5841 (cond ((and (= d1 d0) (= d2 d0))
5842 (concat "<" start-time ">--<" end-time ">"))
5843 ((= d1 d0)
5844 (concat "<" start-time ">"))
5845 ((= d2 d0)
5846 (concat "<" end-time ">")))
5847 remove-re))))
5848 (org-add-props txt props
5849 'org-marker marker 'org-hd-marker hdmarker
5850 'type "block" 'date date
5851 'todo-state todo-state
5852 'priority (org-get-priority txt) 'org-category category
5853 'org-category-position category-pos)
5854 (push txt ee))))
5855 (goto-char pos)))
5856 ;; Sort the entries by expiration date.
5857 (nreverse ee)))
5859 ;;; Agenda presentation and sorting
5861 (defvar org-prefix-has-time nil
5862 "A flag, set by `org-compile-prefix-format'.
5863 The flag is set if the currently compiled format contains a `%t'.")
5864 (defvar org-prefix-has-tag nil
5865 "A flag, set by `org-compile-prefix-format'.
5866 The flag is set if the currently compiled format contains a `%T'.")
5867 (defvar org-prefix-has-effort nil
5868 "A flag, set by `org-compile-prefix-format'.
5869 The flag is set if the currently compiled format contains a `%e'.")
5870 (defvar org-prefix-category-length nil
5871 "Used by `org-compile-prefix-format' to remember the category field width.")
5872 (defvar org-prefix-category-max-length nil
5873 "Used by `org-compile-prefix-format' to remember the category field width.")
5875 (defun org-agenda-get-category-icon (category)
5876 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5877 (dolist (entry org-agenda-category-icon-alist)
5878 (when (org-string-match-p (car entry) category)
5879 (if (listp (cadr entry))
5880 (return (cadr entry))
5881 (return (apply 'create-image (cdr entry)))))))
5883 (defun org-agenda-format-item (extra txt &optional category tags dotime
5884 remove-re habitp)
5885 "Format TXT to be inserted into the agenda buffer.
5886 In particular, it adds the prefix and corresponding text properties. EXTRA
5887 must be a string and replaces the `%s' specifier in the prefix format.
5888 CATEGORY (string, symbol or nil) may be used to overrule the default
5889 category taken from local variable or file name. It will replace the `%c'
5890 specifier in the format. DOTIME, when non-nil, indicates that a
5891 time-of-day should be extracted from TXT for sorting of this entry, and for
5892 the `%t' specifier in the format. When DOTIME is a string, this string is
5893 searched for a time before TXT is. TAGS can be the tags of the headline.
5894 Any match of REMOVE-RE will be removed from TXT."
5895 ;; We keep the org-prefix-* variable values along with a compiled
5896 ;; formatter, so that multiple agendas existing at the same time, do
5897 ;; not step on each other toes.
5899 ;; It was inconvenient to make these variables buffer local in
5900 ;; Agenda buffers, because this function expects to be called with
5901 ;; the buffer where item comes from being current, and not agenda
5902 ;; buffer
5903 (let* ((bindings (car org-prefix-format-compiled))
5904 (formatter (cadr org-prefix-format-compiled)))
5905 (loop for (var value) in bindings
5906 do (set var value))
5907 (save-match-data
5908 ;; Diary entries sometimes have extra whitespace at the beginning
5909 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5911 ;; Fix the tags part in txt
5912 (setq txt (org-agenda-fix-displayed-tags
5913 txt tags
5914 org-agenda-show-inherited-tags
5915 org-agenda-hide-tags-regexp))
5916 (let* ((category (or category
5917 (if (stringp org-category)
5918 org-category
5919 (and org-category (symbol-name org-category)))
5920 (if buffer-file-name
5921 (file-name-sans-extension
5922 (file-name-nondirectory buffer-file-name))
5923 "")))
5924 (category-icon (org-agenda-get-category-icon category))
5925 (category-icon (if category-icon
5926 (propertize " " 'display category-icon)
5927 ""))
5928 ;; time, tag, effort are needed for the eval of the prefix format
5929 (tag (if tags (nth (1- (length tags)) tags) ""))
5930 time effort neffort
5931 (ts (if dotime (concat
5932 (if (stringp dotime) dotime "")
5933 (and org-agenda-search-headline-for-time txt))))
5934 (time-of-day (and dotime (org-get-time-of-day ts)))
5935 stamp plain s0 s1 s2 rtn srp l
5936 duration thecategory)
5937 (and (derived-mode-p 'org-mode) buffer-file-name
5938 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5939 (when (and dotime time-of-day)
5940 ;; Extract starting and ending time and move them to prefix
5941 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5942 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5943 (setq s0 (match-string 0 ts)
5944 srp (and stamp (match-end 3))
5945 s1 (match-string (if plain 1 2) ts)
5946 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5948 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5949 ;; them, we might want to remove them there to avoid duplication.
5950 ;; The user can turn this off with a variable.
5951 (if (and org-prefix-has-time
5952 org-agenda-remove-times-when-in-prefix (or stamp plain)
5953 (string-match (concat (regexp-quote s0) " *") txt)
5954 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5955 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5956 (= (match-beginning 0) 0)
5958 (setq txt (replace-match "" nil nil txt))))
5959 ;; Normalize the time(s) to 24 hour
5960 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5961 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5963 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5964 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5965 (setq s2
5966 (org-minutes-to-hh:mm-string
5967 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5969 ;; Compute the duration
5970 (when s2
5971 (setq duration (- (org-hh:mm-string-to-minutes s2)
5972 (org-hh:mm-string-to-minutes s1)))))
5974 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5975 txt)
5976 ;; Tags are in the string
5977 (if (or (eq org-agenda-remove-tags t)
5978 (and org-agenda-remove-tags
5979 org-prefix-has-tag))
5980 (setq txt (replace-match "" t t txt))
5981 (setq txt (replace-match
5982 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5983 (match-string 2 txt))
5984 t t txt))))
5985 (when (derived-mode-p 'org-mode)
5986 (setq effort
5987 (condition-case nil
5988 (org-get-effort
5989 (or (get-text-property 0 'org-hd-marker txt)
5990 (get-text-property 0 'org-marker txt)))
5991 (error nil)))
5992 (when effort
5993 (setq neffort (org-duration-string-to-minutes effort)
5994 effort (setq effort (concat "[" effort "]")))))
5995 ;; prevent erroring out with %e format when there is no effort
5996 (or effort (setq effort ""))
5998 (when remove-re
5999 (while (string-match remove-re txt)
6000 (setq txt (replace-match "" t t txt))))
6002 ;; Set org-heading property on `txt' to mark the start of the
6003 ;; heading.
6004 (add-text-properties 0 (length txt) '(org-heading t) txt)
6006 ;; Prepare the variables needed in the eval of the compiled format
6007 (setq time (cond (s2 (concat
6008 (org-agenda-time-of-day-to-ampm-maybe s1)
6009 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6010 (if org-agenda-timegrid-use-ampm " ")))
6011 (s1 (concat
6012 (org-agenda-time-of-day-to-ampm-maybe s1)
6013 (if org-agenda-timegrid-use-ampm
6014 "........ "
6015 "......")))
6016 (t ""))
6017 extra (or (and (not habitp) extra) "")
6018 category (if (symbolp category) (symbol-name category) category)
6019 thecategory (copy-sequence category))
6020 (if (string-match org-bracket-link-regexp category)
6021 (progn
6022 (setq l (if (match-end 3)
6023 (- (match-end 3) (match-beginning 3))
6024 (- (match-end 1) (match-beginning 1))))
6025 (when (< l (or org-prefix-category-length 0))
6026 (setq category (copy-sequence category))
6027 (org-add-props category nil
6028 'extra-space (make-string
6029 (- org-prefix-category-length l 1) ?\ ))))
6030 (if (and org-prefix-category-max-length
6031 (>= (length category) org-prefix-category-max-length))
6032 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6033 ;; Evaluate the compiled format
6034 (setq rtn (concat (eval formatter) txt))
6036 ;; And finally add the text properties
6037 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6038 (org-add-props rtn nil
6039 'org-category (if thecategory (downcase thecategory) category)
6040 'tags (mapcar 'org-downcase-keep-props tags)
6041 'org-highest-priority org-highest-priority
6042 'org-lowest-priority org-lowest-priority
6043 'time-of-day time-of-day
6044 'duration duration
6045 'effort effort
6046 'effort-minutes neffort
6047 'txt txt
6048 'time time
6049 'extra extra
6050 'format org-prefix-format-compiled
6051 'dotime dotime)))))
6053 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6054 "Remove tags string from TXT, and add a modified list of tags.
6055 The modified list may contain inherited tags, and tags matched by
6056 `org-agenda-hide-tags-regexp' will be removed."
6057 (when (or add-inherited hide-re)
6058 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6059 (setq txt (substring txt 0 (match-beginning 0))))
6060 (setq tags
6061 (delq nil
6062 (mapcar (lambda (tg)
6063 (if (or (and hide-re (string-match hide-re tg))
6064 (and (not add-inherited)
6065 (get-text-property 0 'inherited tg)))
6067 tg))
6068 tags)))
6069 (when tags
6070 (let ((have-i (get-text-property 0 'inherited (car tags)))
6072 (setq txt (concat txt " :"
6073 (mapconcat
6074 (lambda (x)
6075 (setq i (get-text-property 0 'inherited x))
6076 (if (and have-i (not i))
6077 (progn
6078 (setq have-i nil)
6079 (concat ":" x))
6081 tags ":")
6082 (if have-i "::" ":"))))))
6083 txt)
6085 (defun org-downcase-keep-props (s)
6086 (let ((props (text-properties-at 0 s)))
6087 (setq s (downcase s))
6088 (add-text-properties 0 (length s) props s)
6091 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6092 (defvar org-agenda-sorting-strategy-selected nil)
6094 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6095 (catch 'exit
6096 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6097 ((and todayp (member 'today (car org-agenda-time-grid))))
6098 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6099 ((member 'weekly (car org-agenda-time-grid)))
6100 (t (throw 'exit list)))
6101 (let* ((have (delq nil (mapcar
6102 (lambda (x) (get-text-property 1 'time-of-day x))
6103 list)))
6104 (string (nth 1 org-agenda-time-grid))
6105 (gridtimes (nth 2 org-agenda-time-grid))
6106 (req (car org-agenda-time-grid))
6107 (remove (member 'remove-match req))
6108 new time)
6109 (if (and (member 'require-timed req) (not have))
6110 ;; don't show empty grid
6111 (throw 'exit list))
6112 (while (setq time (pop gridtimes))
6113 (unless (and remove (member time have))
6114 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6115 (push (org-agenda-format-item
6116 nil string "" nil
6117 (concat (substring time 0 -2) ":" (substring time -2)))
6118 new)
6119 (put-text-property
6120 2 (length (car new)) 'face 'org-time-grid (car new))))
6121 (when (and todayp org-agenda-show-current-time-in-grid)
6122 (push (org-agenda-format-item
6124 org-agenda-current-time-string
6125 "" nil
6126 (format-time-string "%H:%M "))
6127 new)
6128 (put-text-property
6129 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6131 (if (member 'time-up org-agenda-sorting-strategy-selected)
6132 (append new list)
6133 (append list new)))))
6135 (defun org-compile-prefix-format (key)
6136 "Compile the prefix format into a Lisp form that can be evaluated.
6137 The resulting form and associated variable bindings is returned
6138 and stored in the variable `org-prefix-format-compiled'."
6139 (setq org-prefix-has-time nil org-prefix-has-tag nil
6140 org-prefix-category-length nil
6141 org-prefix-has-effort nil)
6142 (let ((s (cond
6143 ((stringp org-agenda-prefix-format)
6144 org-agenda-prefix-format)
6145 ((assq key org-agenda-prefix-format)
6146 (cdr (assq key org-agenda-prefix-format)))
6147 (t " %-12:c%?-12t% s")))
6148 (start 0)
6149 varform vars var e c f opt)
6150 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6151 s start)
6152 (setq var (or (cdr (assoc (match-string 4 s)
6153 '(("c" . category) ("t" . time) ("s" . extra)
6154 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6155 'eval)
6156 c (or (match-string 3 s) "")
6157 opt (match-beginning 1)
6158 start (1+ (match-beginning 0)))
6159 (if (equal var 'time) (setq org-prefix-has-time t))
6160 (if (equal var 'tag) (setq org-prefix-has-tag t))
6161 (if (equal var 'effort) (setq org-prefix-has-effort t))
6162 (setq f (concat "%" (match-string 2 s) "s"))
6163 (when (equal var 'category)
6164 (setq org-prefix-category-length
6165 (floor (abs (string-to-number (match-string 2 s)))))
6166 (setq org-prefix-category-max-length
6167 (let ((x (match-string 2 s)))
6168 (save-match-data
6169 (if (string-match "\\.[0-9]+" x)
6170 (string-to-number (substring (match-string 0 x) 1)))))))
6171 (if (eq var 'eval)
6172 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6173 (if opt
6174 (setq varform
6175 `(if (equal "" ,var)
6177 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6178 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6179 (setq s (replace-match "%s" t nil s))
6180 (push varform vars))
6181 (setq vars (nreverse vars))
6182 (with-current-buffer (or org-agenda-buffer (current-buffer))
6183 (setq org-prefix-format-compiled
6184 (list
6185 `((org-prefix-has-time ,org-prefix-has-time)
6186 (org-prefix-has-tag ,org-prefix-has-tag)
6187 (org-prefix-category-length ,org-prefix-category-length)
6188 (org-prefix-has-effort ,org-prefix-has-effort))
6189 `(format ,s ,@vars))))))
6191 (defun org-set-sorting-strategy (key)
6192 (if (symbolp (car org-agenda-sorting-strategy))
6193 ;; the old format
6194 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6195 (setq org-agenda-sorting-strategy-selected
6196 (or (cdr (assq key org-agenda-sorting-strategy))
6197 (cdr (assq 'agenda org-agenda-sorting-strategy))
6198 '(time-up category-keep priority-down)))))
6200 (defun org-get-time-of-day (s &optional string mod24)
6201 "Check string S for a time of day.
6202 If found, return it as a military time number between 0 and 2400.
6203 If not found, return nil.
6204 The optional STRING argument forces conversion into a 5 character wide string
6205 HH:MM."
6206 (save-match-data
6207 (when
6208 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6209 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6210 (let* ((h (string-to-number (match-string 1 s)))
6211 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6212 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6213 (am-p (equal ampm "am"))
6214 (h1 (cond ((not ampm) h)
6215 ((= h 12) (if am-p 0 12))
6216 (t (+ h (if am-p 0 12)))))
6217 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6218 (mod h1 24) h1))
6219 (t0 (+ (* 100 h2) m))
6220 (t1 (concat (if (>= h1 24) "+" " ")
6221 (if (and org-agenda-time-leading-zero
6222 (< t0 1000)) "0" "")
6223 (if (< t0 100) "0" "")
6224 (if (< t0 10) "0" "")
6225 (int-to-string t0))))
6226 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6228 (defvar org-agenda-before-sorting-filter-function nil
6229 "Function to be applied to agenda items prior to sorting.
6230 Prior to sorting also means just before they are inserted into the agenda.
6232 To aid sorting, you may revisit the original entries and add more text
6233 properties which will later be used by the sorting functions.
6235 The function should take a string argument, an agenda line.
6236 It has access to the text properties in that line, which contain among
6237 other things, the property `org-hd-marker' that points to the entry
6238 where the line comes from. Note that not all lines going into the agenda
6239 have this property, only most.
6241 The function should return the modified string. It is probably best
6242 to ONLY change text properties.
6244 You can also use this function as a filter, by returning nil for lines
6245 you don't want to have in the agenda at all. For this application, you
6246 could bind the variable in the options section of a custom command.")
6248 (defun org-agenda-finalize-entries (list &optional nosort)
6249 "Sort and concatenate the agenda items."
6250 (setq list (mapcar 'org-agenda-highlight-todo list))
6251 (if nosort
6252 list
6253 (when org-agenda-before-sorting-filter-function
6254 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6255 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6257 (defun org-agenda-highlight-todo (x)
6258 (let ((org-done-keywords org-done-keywords-for-agenda)
6259 (case-fold-search nil)
6261 (if (eq x 'line)
6262 (save-excursion
6263 (beginning-of-line 1)
6264 (setq re (org-get-at-bol 'org-todo-regexp))
6265 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6266 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6267 (add-text-properties (match-beginning 0) (match-end 1)
6268 (list 'face (org-get-todo-face 1)))
6269 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6270 (delete-region (match-beginning 1) (1- (match-end 0)))
6271 (goto-char (match-beginning 1))
6272 (insert (format org-agenda-todo-keyword-format s)))))
6273 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6274 (setq re (get-text-property 0 'org-todo-regexp x))
6275 (when (and re
6276 ;; Test `pl' because if there's no heading content,
6277 ;; there's no point matching to highlight. Note
6278 ;; that if we didn't test `pl' first, and there
6279 ;; happened to be no keyword from `org-todo-regexp'
6280 ;; on this heading line, then the `equal' comparison
6281 ;; afterwards would spuriously succeed in the case
6282 ;; where `pl' is nil -- causing an args-out-of-range
6283 ;; error when we try to add text properties to text
6284 ;; that isn't there.
6286 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6287 x pl) pl))
6288 (add-text-properties
6289 (or (match-end 1) (match-end 0)) (match-end 0)
6290 (list 'face (org-get-todo-face (match-string 2 x)))
6292 (when (match-end 1)
6293 (setq x (concat (substring x 0 (match-end 1))
6294 (format org-agenda-todo-keyword-format
6295 (match-string 2 x))
6296 (org-add-props " " (text-properties-at 0 x))
6297 (substring x (match-end 3)))))))
6298 x)))
6300 (defsubst org-cmp-priority (a b)
6301 "Compare the priorities of string A and B."
6302 (let ((pa (or (get-text-property 1 'priority a) 0))
6303 (pb (or (get-text-property 1 'priority b) 0)))
6304 (cond ((> pa pb) +1)
6305 ((< pa pb) -1))))
6307 (defsubst org-cmp-effort (a b)
6308 "Compare the effort values of string A and B."
6309 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6310 (ea (or (get-text-property 1 'effort-minutes a) def))
6311 (eb (or (get-text-property 1 'effort-minutes b) def)))
6312 (cond ((> ea eb) +1)
6313 ((< ea eb) -1))))
6315 (defsubst org-cmp-category (a b)
6316 "Compare the string values of categories of strings A and B."
6317 (let ((ca (or (get-text-property 1 'org-category a) ""))
6318 (cb (or (get-text-property 1 'org-category b) "")))
6319 (cond ((string-lessp ca cb) -1)
6320 ((string-lessp cb ca) +1))))
6322 (defsubst org-cmp-todo-state (a b)
6323 "Compare the todo states of strings A and B."
6324 (let* ((ma (or (get-text-property 1 'org-marker a)
6325 (get-text-property 1 'org-hd-marker a)))
6326 (mb (or (get-text-property 1 'org-marker b)
6327 (get-text-property 1 'org-hd-marker b)))
6328 (fa (and ma (marker-buffer ma)))
6329 (fb (and mb (marker-buffer mb)))
6330 (todo-kwds
6331 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6332 (and fb (with-current-buffer fb org-todo-keywords-1))))
6333 (ta (or (get-text-property 1 'todo-state a) ""))
6334 (tb (or (get-text-property 1 'todo-state b) ""))
6335 (la (- (length (member ta todo-kwds))))
6336 (lb (- (length (member tb todo-kwds))))
6337 (donepa (member ta org-done-keywords-for-agenda))
6338 (donepb (member tb org-done-keywords-for-agenda)))
6339 (cond ((and donepa (not donepb)) -1)
6340 ((and (not donepa) donepb) +1)
6341 ((< la lb) -1)
6342 ((< lb la) +1))))
6344 (defsubst org-cmp-alpha (a b)
6345 "Compare the headlines, alphabetically."
6346 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6347 (plb (text-property-any 0 (length b) 'org-heading t b))
6348 (ta (and pla (substring a pla)))
6349 (tb (and plb (substring b plb))))
6350 (when pla
6351 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6352 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6353 (setq ta (substring ta (match-end 0))))
6354 (setq ta (downcase ta)))
6355 (when plb
6356 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6357 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6358 (setq tb (substring tb (match-end 0))))
6359 (setq tb (downcase tb)))
6360 (cond ((not ta) +1)
6361 ((not tb) -1)
6362 ((string-lessp ta tb) -1)
6363 ((string-lessp tb ta) +1))))
6365 (defsubst org-cmp-tag (a b)
6366 "Compare the string values of the first tags of A and B."
6367 (let ((ta (car (last (get-text-property 1 'tags a))))
6368 (tb (car (last (get-text-property 1 'tags b)))))
6369 (cond ((not ta) +1)
6370 ((not tb) -1)
6371 ((string-lessp ta tb) -1)
6372 ((string-lessp tb ta) +1))))
6374 (defsubst org-cmp-time (a b)
6375 "Compare the time-of-day values of strings A and B."
6376 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6377 (ta (or (get-text-property 1 'time-of-day a) def))
6378 (tb (or (get-text-property 1 'time-of-day b) def)))
6379 (cond ((< ta tb) -1)
6380 ((< tb ta) +1))))
6382 (defsubst org-cmp-habit-p (a b)
6383 "Compare the todo states of strings A and B."
6384 (let ((ha (get-text-property 1 'org-habit-p a))
6385 (hb (get-text-property 1 'org-habit-p b)))
6386 (cond ((and ha (not hb)) -1)
6387 ((and (not ha) hb) +1))))
6389 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6391 (defun org-entries-lessp (a b)
6392 "Predicate for sorting agenda entries."
6393 ;; The following variables will be used when the form is evaluated.
6394 ;; So even though the compiler complains, keep them.
6395 (let* ((ss org-agenda-sorting-strategy-selected)
6396 (time-up (and (org-em 'time-up 'time-down ss)
6397 (org-cmp-time a b)))
6398 (time-down (if time-up (- time-up) nil))
6399 (priority-up (and (org-em 'priority-up 'priority-down ss)
6400 (org-cmp-priority a b)))
6401 (priority-down (if priority-up (- priority-up) nil))
6402 (effort-up (and (org-em 'effort-up 'effort-down ss)
6403 (org-cmp-effort a b)))
6404 (effort-down (if effort-up (- effort-up) nil))
6405 (category-up (and (or (org-em 'category-up 'category-down ss)
6406 (memq 'category-keep ss))
6407 (org-cmp-category a b)))
6408 (category-down (if category-up (- category-up) nil))
6409 (category-keep (if category-up +1 nil))
6410 (tag-up (and (org-em 'tag-up 'tag-down ss)
6411 (org-cmp-tag a b)))
6412 (tag-down (if tag-up (- tag-up) nil))
6413 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6414 (org-cmp-todo-state a b)))
6415 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6416 (habit-up (and (org-em 'habit-up 'habit-down ss)
6417 (org-cmp-habit-p a b)))
6418 (habit-down (if habit-up (- habit-up) nil))
6419 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6420 (org-cmp-alpha a b)))
6421 (alpha-down (if alpha-up (- alpha-up) nil))
6422 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6423 user-defined-up user-defined-down)
6424 (if (and need-user-cmp org-agenda-cmp-user-defined
6425 (functionp org-agenda-cmp-user-defined))
6426 (setq user-defined-up
6427 (funcall org-agenda-cmp-user-defined a b)
6428 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6429 (cdr (assoc
6430 (eval (cons 'or org-agenda-sorting-strategy-selected))
6431 '((-1 . t) (1 . nil) (nil . nil))))))
6433 ;;; Agenda restriction lock
6435 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6436 "Overlay to mark the headline to which agenda commands are restricted.")
6437 (overlay-put org-agenda-restriction-lock-overlay
6438 'face 'org-agenda-restriction-lock)
6439 (overlay-put org-agenda-restriction-lock-overlay
6440 'help-echo "Agendas are currently limited to this subtree.")
6441 (org-detach-overlay org-agenda-restriction-lock-overlay)
6443 (defun org-agenda-set-restriction-lock (&optional type)
6444 "Set restriction lock for agenda, to current subtree or file.
6445 Restriction will be the file if TYPE is `file', or if type is the
6446 universal prefix '(4), or if the cursor is before the first headline
6447 in the file. Otherwise, restriction will be to the current subtree."
6448 (interactive "P")
6449 (and (equal type '(4)) (setq type 'file))
6450 (setq type (cond
6451 (type type)
6452 ((org-at-heading-p) 'subtree)
6453 ((condition-case nil (org-back-to-heading t) (error nil))
6454 'subtree)
6455 (t 'file)))
6456 (if (eq type 'subtree)
6457 (progn
6458 (setq org-agenda-restrict t)
6459 (setq org-agenda-overriding-restriction 'subtree)
6460 (put 'org-agenda-files 'org-restrict
6461 (list (buffer-file-name (buffer-base-buffer))))
6462 (org-back-to-heading t)
6463 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6464 (move-marker org-agenda-restrict-begin (point))
6465 (move-marker org-agenda-restrict-end
6466 (save-excursion (org-end-of-subtree t)))
6467 (message "Locking agenda restriction to subtree"))
6468 (put 'org-agenda-files 'org-restrict
6469 (list (buffer-file-name (buffer-base-buffer))))
6470 (setq org-agenda-restrict nil)
6471 (setq org-agenda-overriding-restriction 'file)
6472 (move-marker org-agenda-restrict-begin nil)
6473 (move-marker org-agenda-restrict-end nil)
6474 (message "Locking agenda restriction to file"))
6475 (setq current-prefix-arg nil)
6476 (org-agenda-maybe-redo))
6478 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6479 "Remove the agenda restriction lock."
6480 (interactive "P")
6481 (org-detach-overlay org-agenda-restriction-lock-overlay)
6482 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6483 (setq org-agenda-overriding-restriction nil)
6484 (setq org-agenda-restrict nil)
6485 (put 'org-agenda-files 'org-restrict nil)
6486 (move-marker org-agenda-restrict-begin nil)
6487 (move-marker org-agenda-restrict-end nil)
6488 (setq current-prefix-arg nil)
6489 (message "Agenda restriction lock removed")
6490 (or noupdate (org-agenda-maybe-redo)))
6492 (defun org-agenda-maybe-redo ()
6493 "If there is any window showing the agenda view, update it."
6494 (let ((w (get-buffer-window org-agenda-buffer-name t))
6495 (w0 (selected-window)))
6496 (when w
6497 (select-window w)
6498 (org-agenda-redo)
6499 (select-window w0)
6500 (if org-agenda-overriding-restriction
6501 (message "Agenda view shifted to new %s restriction"
6502 org-agenda-overriding-restriction)
6503 (message "Agenda restriction lock removed")))))
6505 ;;; Agenda commands
6507 (defun org-agenda-check-type (error &rest types)
6508 "Check if agenda buffer is of allowed type.
6509 If ERROR is non-nil, throw an error, otherwise just return nil."
6510 (if (not org-agenda-type)
6511 (error "No Org agenda currently displayed")
6512 (if (memq org-agenda-type types)
6514 (if error
6515 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6516 nil))))
6518 (defun org-agenda-Quit (&optional arg)
6519 "Exit agenda by removing the window or the buffer."
6520 (interactive)
6521 (if org-agenda-columns-active
6522 (org-columns-quit)
6523 (let ((buf (current-buffer)))
6524 (if (eq org-agenda-window-setup 'other-frame)
6525 (progn
6526 (org-agenda-reset-markers)
6527 (kill-buffer buf)
6528 (org-columns-remove-overlays)
6529 (setq org-agenda-archives-mode nil)
6530 (delete-frame))
6531 (and (not (eq org-agenda-window-setup 'current-window))
6532 (not (one-window-p))
6533 (delete-window))
6534 (org-agenda-reset-markers)
6535 (kill-buffer buf)
6536 (org-columns-remove-overlays)
6537 (setq org-agenda-archives-mode nil)))
6538 ;; Maybe restore the pre-agenda window configuration.
6539 (and org-agenda-restore-windows-after-quit
6540 (not (eq org-agenda-window-setup 'other-frame))
6541 org-agenda-pre-window-conf
6542 (set-window-configuration org-agenda-pre-window-conf)
6543 (setq org-agenda-pre-window-conf nil))))
6545 (defun org-agenda-quit ()
6546 "Exit agenda by killing agenda buffer or burying it when
6547 `org-agenda-sticky' is non-NIL"
6548 (interactive)
6549 (if org-agenda-columns-active
6550 (org-columns-quit)
6551 (if org-agenda-sticky
6552 (let ((buf (current-buffer)))
6553 (if (eq org-agenda-window-setup 'other-frame)
6554 (progn
6555 (delete-frame))
6556 (and (not (eq org-agenda-window-setup 'current-window))
6557 (not (one-window-p))
6558 (delete-window)))
6559 (with-current-buffer buf
6560 (bury-buffer)
6561 ;; Maybe restore the pre-agenda window configuration.
6562 (and org-agenda-restore-windows-after-quit
6563 (not (eq org-agenda-window-setup 'other-frame))
6564 org-agenda-pre-window-conf
6565 (set-window-configuration org-agenda-pre-window-conf)
6566 (setq org-agenda-pre-window-conf nil))))
6567 (org-agenda-Quit))))
6569 (defun org-agenda-exit ()
6570 "Exit agenda by removing the window or the buffer.
6571 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6572 Org-mode buffers visited directly by the user will not be touched."
6573 (interactive)
6574 (org-release-buffers org-agenda-new-buffers)
6575 (setq org-agenda-new-buffers nil)
6576 (org-agenda-Quit))
6578 (defun org-agenda-kill-all-agenda-buffers ()
6579 "Kill all buffers in `org-agena-mode'.
6580 This is used when toggling sticky agendas. You can also explicitly invoke it
6581 with `C-c a C-k'."
6582 (interactive)
6583 (let (blist)
6584 (dolist (buf (buffer-list))
6585 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6586 (push buf blist)))
6587 (mapc 'kill-buffer blist)))
6589 (defun org-agenda-execute (arg)
6590 "Execute another agenda command, keeping same window.
6591 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6592 in the agenda."
6593 (interactive "P")
6594 (let ((org-agenda-window-setup 'current-window))
6595 (org-agenda arg)))
6597 (defun org-agenda-redo (&optional all)
6598 "Rebuild possibly ALL agenda view(s) in the current buffer."
6599 (interactive "P")
6600 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6601 (cpa (unless (eq all t) current-prefix-arg))
6602 (org-agenda-doing-sticky-redo org-agenda-sticky)
6603 (org-agenda-sticky nil)
6604 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6605 org-agenda-buffer-name))
6606 (org-agenda-keep-modes t)
6607 (tag-filter org-agenda-tag-filter)
6608 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6609 (top-cat-filter org-agenda-top-category-filter)
6610 (cat-filter org-agenda-category-filter)
6611 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6612 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6613 (cols org-agenda-columns-active)
6614 (line (org-current-line))
6615 (window-line (- line (org-current-line (window-start))))
6616 (lprops (get 'org-agenda-redo-command 'org-lprops))
6617 (redo-cmd (get-text-property p 'org-redo-cmd))
6618 (last-args (get-text-property p 'org-last-args))
6619 (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
6620 (org-agenda-overriding-cmd-arguments
6621 (unless (eq all t)
6622 (cond ((listp last-args)
6623 (cons (or cpa (car last-args)) (cdr last-args)))
6624 ((stringp last-args)
6625 last-args))))
6626 (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
6627 (put 'org-agenda-tag-filter :preset-filter nil)
6628 (put 'org-agenda-category-filter :preset-filter nil)
6629 (and cols (org-columns-quit))
6630 (message "Rebuilding agenda buffer...")
6631 (if serie-redo-cmd
6632 (eval serie-redo-cmd)
6633 (org-let lprops '(eval redo-cmd)))
6634 (setq org-agenda-undo-list nil
6635 org-agenda-pending-undo-list nil)
6636 (message "Rebuilding agenda buffer...done")
6637 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6638 (put 'org-agenda-category-filter :preset-filter cat-preset)
6639 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6640 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6641 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6642 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6643 (org-goto-line line)
6644 (recenter window-line)))
6646 (defvar org-global-tags-completion-table nil)
6647 (defvar org-agenda-filter-form nil)
6648 (defvar org-agenda-filtered-by-category nil)
6650 (defun org-agenda-filter-by-category (strip)
6651 "Keep only those lines in the agenda buffer that have a specific category.
6652 The category is that of the current line."
6653 (interactive "P")
6654 (if (and org-agenda-filtered-by-category
6655 org-agenda-category-filter)
6656 (org-agenda-filter-show-all-cat)
6657 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6658 (if cat (org-agenda-filter-apply
6659 (list (concat (if strip "-" "+") cat)) 'category)
6660 (error "No category at point")))))
6662 (defun org-find-top-category (&optional pos)
6663 (save-excursion
6664 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6665 (if pos (goto-char pos))
6666 ;; Skip up to the topmost parent
6667 (while (ignore-errors (outline-up-heading 1) t))
6668 (ignore-errors
6669 (nth 4 (org-heading-components))))))
6671 (defvar org-agenda-filtered-by-top-category nil)
6673 (defun org-agenda-filter-by-top-category (strip)
6674 "Keep only those lines in the agenda buffer that have a specific category.
6675 The category is that of the current line."
6676 (interactive "P")
6677 (if org-agenda-filtered-by-top-category
6678 (progn
6679 (setq org-agenda-filtered-by-top-category nil
6680 org-agenda-top-category-filter nil)
6681 (org-agenda-filter-show-all-cat))
6682 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6683 (if cat (org-agenda-filter-top-category-apply cat strip)
6684 (error "No top-level category at point")))))
6686 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6687 "Keep only those lines in the agenda buffer that have a specific tag.
6688 The tag is selected with its fast selection letter, as configured.
6689 With prefix argument STRIP, remove all lines that do have the tag.
6690 A lisp caller can specify CHAR. NARROW means that the new tag should be
6691 used to narrow the search - the interactive user can also press `-' or `+'
6692 to switch to narrowing."
6693 (interactive "P")
6694 (let* ((alist org-tag-alist-for-agenda)
6695 (tag-chars (mapconcat
6696 (lambda (x) (if (and (not (symbolp (car x)))
6697 (cdr x))
6698 (char-to-string (cdr x))
6699 ""))
6700 alist ""))
6701 (efforts (org-split-string
6702 (or (cdr (assoc (concat org-effort-property "_ALL")
6703 org-global-properties))
6704 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6705 "")))
6706 (effort-op org-agenda-filter-effort-default-operator)
6707 (effort-prompt "")
6708 (inhibit-read-only t)
6709 (current org-agenda-tag-filter)
6710 maybe-refresh a n tag)
6711 (unless char
6712 (message
6713 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6714 (if narrow "Narrow" "Filter") tag-chars
6715 (if org-agenda-auto-exclude-function "[RET], " ""))
6716 (setq char (read-char-exclusive)))
6717 (when (member char '(?+ ?-))
6718 ;; Narrowing down
6719 (cond ((equal char ?-) (setq strip t narrow t))
6720 ((equal char ?+) (setq strip nil narrow t)))
6721 (message
6722 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6723 (setq char (read-char-exclusive)))
6724 (when (member char '(?< ?> ?= ??))
6725 ;; An effort operator
6726 (setq effort-op (char-to-string char))
6727 (setq alist nil) ; to make sure it will be interpreted as effort.
6728 (unless (equal char ??)
6729 (loop for i from 0 to 9 do
6730 (setq effort-prompt
6731 (concat
6732 effort-prompt " ["
6733 (if (= i 9) "0" (int-to-string (1+ i)))
6734 "]" (nth i efforts))))
6735 (message "Effort%s: %s " effort-op effort-prompt)
6736 (setq char (read-char-exclusive))
6737 (when (or (< char ?0) (> char ?9))
6738 (error "Need 1-9,0 to select effort"))))
6739 (when (equal char ?\t)
6740 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6741 (org-set-local 'org-global-tags-completion-table
6742 (org-global-tags-completion-table)))
6743 (let ((completion-ignore-case t))
6744 (setq tag (org-icompleting-read
6745 "Tag: " org-global-tags-completion-table))))
6746 (cond
6747 ((equal char ?\r)
6748 (org-agenda-filter-show-all-tag)
6749 (when org-agenda-auto-exclude-function
6750 (setq org-agenda-tag-filter '())
6751 (dolist (tag (org-agenda-get-represented-tags))
6752 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6753 (if modifier
6754 (push modifier org-agenda-tag-filter))))
6755 (if (not (null org-agenda-tag-filter))
6756 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6757 (setq maybe-refresh t))
6758 ((equal char ?/)
6759 (org-agenda-filter-show-all-tag)
6760 (when (get 'org-agenda-tag-filter :preset-filter)
6761 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6762 (setq maybe-refresh t))
6763 ((equal char ?. )
6764 (setq org-agenda-tag-filter
6765 (mapcar (lambda(tag) (concat "+" tag))
6766 (org-get-at-bol 'tags)))
6767 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6768 (setq maybe-refresh t))
6769 ((or (equal char ?\ )
6770 (setq a (rassoc char alist))
6771 (and (>= char ?0) (<= char ?9)
6772 (setq n (if (= char ?0) 9 (- char ?0 1))
6773 tag (concat effort-op (nth n efforts))
6774 a (cons tag nil)))
6775 (and (= char ??)
6776 (setq tag "?eff")
6777 a (cons tag nil))
6778 (and tag (setq a (cons tag nil))))
6779 (org-agenda-filter-show-all-tag)
6780 (setq tag (car a))
6781 (setq org-agenda-tag-filter
6782 (cons (concat (if strip "-" "+") tag)
6783 (if narrow current nil)))
6784 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6785 (setq maybe-refresh t))
6786 (t (error "Invalid tag selection character %c" char)))
6787 (when (and maybe-refresh
6788 (eq org-agenda-clockreport-mode 'with-filter))
6789 (org-agenda-redo))))
6791 (defun org-agenda-get-represented-tags ()
6792 "Get a list of all tags currently represented in the agenda."
6793 (let (p tags)
6794 (save-excursion
6795 (goto-char (point-min))
6796 (while (setq p (next-single-property-change (point) 'tags))
6797 (goto-char p)
6798 (mapc (lambda (x) (add-to-list 'tags x))
6799 (get-text-property (point) 'tags))))
6800 tags))
6802 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6803 "Refine the current filter. See `org-agenda-filter-by-tag'."
6804 (interactive "P")
6805 (org-agenda-filter-by-tag strip char 'refine))
6807 (defun org-agenda-filter-make-matcher ()
6808 "Create the form that tests a line for agenda filter."
6809 (let (f f1)
6810 ;; first compute the tag-filter matcher
6811 (dolist (x (delete-dups
6812 (append (get 'org-agenda-tag-filter
6813 :preset-filter) org-agenda-tag-filter)))
6814 (if (member x '("-" "+"))
6815 (setq f1 (if (equal x "-") 'tags '(not tags)))
6816 (if (string-match "[<=>?]" x)
6817 (setq f1 (org-agenda-filter-effort-form x))
6818 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6819 (if (equal (string-to-char x) ?-)
6820 (setq f1 (list 'not f1))))
6821 (push f1 f))
6822 ;; then compute the category-filter matcher
6823 (dolist (x (delete-dups
6824 (append (get 'org-agenda-category-filter
6825 :preset-filter) org-agenda-category-filter)))
6826 (if (equal "-" (substring x 0 1))
6827 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6828 (setq f1 (list 'equal (substring x 1) 'cat)))
6829 (push f1 f))
6830 (cons 'and (nreverse f))))
6832 (defun org-agenda-filter-effort-form (e)
6833 "Return the form to compare the effort of the current line with what E says.
6834 E looks like \"+<2:25\"."
6835 (let (op)
6836 (setq e (substring e 1))
6837 (setq op (string-to-char e) e (substring e 1))
6838 (setq op (cond ((equal op ?<) '<=)
6839 ((equal op ?>) '>=)
6840 ((equal op ??) op)
6841 (t '=)))
6842 (list 'org-agenda-compare-effort (list 'quote op)
6843 (org-duration-string-to-minutes e))))
6845 (defun org-agenda-compare-effort (op value)
6846 "Compare the effort of the current line with VALUE, using OP.
6847 If the line does not have an effort defined, return nil."
6848 (let ((eff (org-get-at-bol 'effort-minutes)))
6849 (if (equal op ??)
6850 (not eff)
6851 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6852 value))))
6854 (defun org-agenda-filter-apply (filter type)
6855 "Set FILTER as the new agenda filter and apply it."
6856 (let (tags cat)
6857 (if (eq type 'tag)
6858 (setq org-agenda-tag-filter filter)
6859 (setq org-agenda-category-filter filter))
6860 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6861 (if (and (eq type 'category)
6862 (not (equal (substring (car filter) 0 1) "-")))
6863 ;; Only set `org-agenda-filtered-by-category' to t
6864 ;; when a unique category is used as the filter
6865 (setq org-agenda-filtered-by-category t))
6866 (org-agenda-set-mode-name)
6867 (save-excursion
6868 (goto-char (point-min))
6869 (while (not (eobp))
6870 (if (org-get-at-bol 'org-marker)
6871 (progn
6872 (setq tags (org-get-at-bol 'tags) ; used in eval
6873 cat (get-text-property (point) 'org-category))
6874 (if (not (eval org-agenda-filter-form))
6875 (org-agenda-filter-hide-line type))
6876 (beginning-of-line 2))
6877 (beginning-of-line 2))))
6878 (if (get-char-property (point) 'invisible)
6879 (ignore-errors (org-agenda-previous-line)))))
6881 (defun org-agenda-filter-top-category-apply (category &optional negative)
6882 "Set FILTER as the new agenda filter and apply it."
6883 (org-agenda-set-mode-name)
6884 (save-excursion
6885 (goto-char (point-min))
6886 (while (not (eobp))
6887 (let* ((pos (org-get-at-bol 'org-hd-marker))
6888 (topcat (and pos (org-find-top-category pos))))
6889 (if (and topcat (funcall (if negative 'identity 'not)
6890 (string= category topcat)))
6891 (org-agenda-filter-hide-line 'category)))
6892 (beginning-of-line 2)))
6893 (if (get-char-property (point) 'invisible)
6894 (org-agenda-previous-line))
6895 (setq org-agenda-top-category-filter category
6896 org-agenda-filtered-by-top-category t))
6898 (defun org-agenda-filter-hide-line (type)
6899 (let (ov)
6900 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6901 (point-at-eol)))
6902 (overlay-put ov 'invisible t)
6903 (overlay-put ov 'type type)
6904 (if (eq type 'tag)
6905 (push ov org-agenda-tag-filter-overlays)
6906 (push ov org-agenda-cat-filter-overlays))))
6908 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6909 (setq pos (or pos (point)))
6910 (save-excursion
6911 (dolist (ov (overlays-at pos))
6912 (when (and (overlay-get ov 'invisible)
6913 (eq (overlay-get ov 'type) 'tag))
6914 (goto-char pos)
6915 (if (< (overlay-start ov) (point-at-eol))
6916 (move-overlay ov (point-at-eol)
6917 (overlay-end ov)))))))
6919 (defun org-agenda-filter-show-all-tag nil
6920 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6921 (setq org-agenda-tag-filter-overlays nil
6922 org-agenda-tag-filter nil
6923 org-agenda-filter-form nil)
6924 (org-agenda-set-mode-name))
6926 (defun org-agenda-filter-show-all-cat nil
6927 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6928 (setq org-agenda-cat-filter-overlays nil
6929 org-agenda-filtered-by-category nil
6930 org-agenda-category-filter nil
6931 org-agenda-filter-form nil)
6932 (org-agenda-set-mode-name))
6934 (defun org-agenda-manipulate-query-add ()
6935 "Manipulate the query by adding a search term with positive selection.
6936 Positive selection means the term must be matched for selection of an entry."
6937 (interactive)
6938 (org-agenda-manipulate-query ?\[))
6939 (defun org-agenda-manipulate-query-subtract ()
6940 "Manipulate the query by adding a search term with negative selection.
6941 Negative selection means term must not be matched for selection of an entry."
6942 (interactive)
6943 (org-agenda-manipulate-query ?\]))
6944 (defun org-agenda-manipulate-query-add-re ()
6945 "Manipulate the query by adding a search regexp with positive selection.
6946 Positive selection means the regexp must match for selection of an entry."
6947 (interactive)
6948 (org-agenda-manipulate-query ?\{))
6949 (defun org-agenda-manipulate-query-subtract-re ()
6950 "Manipulate the query by adding a search regexp with negative selection.
6951 Negative selection means regexp must not match for selection of an entry."
6952 (interactive)
6953 (org-agenda-manipulate-query ?\}))
6954 (defun org-agenda-manipulate-query (char)
6955 (cond
6956 ((memq org-agenda-type '(timeline agenda))
6957 (let ((org-agenda-include-inactive-timestamps t))
6958 (org-agenda-redo))
6959 (message "Display now includes inactive timestamps as well"))
6960 ((eq org-agenda-type 'search)
6961 (org-add-to-string
6962 'org-agenda-query-string
6963 (if org-agenda-last-search-view-search-was-boolean
6964 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6965 (?\{ . " +{}") (?\} . " -{}"))))
6966 " "))
6967 (setq org-agenda-redo-command
6968 (list 'org-search-view
6969 (car (get-text-property (point) 'org-last-args))
6970 org-agenda-query-string
6971 (+ (length org-agenda-query-string)
6972 (if (member char '(?\{ ?\})) 0 1))))
6973 (set-register org-agenda-query-register org-agenda-query-string)
6974 (let ((org-agenda-overriding-arguments
6975 (cdr org-agenda-redo-command)))
6976 (org-agenda-redo)))
6977 (t (error "Cannot manipulate query for %s-type agenda buffers"
6978 org-agenda-type))))
6980 (defun org-add-to-string (var string)
6981 (set var (concat (symbol-value var) string)))
6983 (defun org-agenda-goto-date (span)
6984 "Jump to DATE in agenda."
6985 (interactive "P")
6986 (let* ((org-read-date-prefer-future
6987 (eval org-agenda-jump-prefer-future))
6988 (date (org-read-date))
6989 (org-agenda-sticky-orig org-agenda-sticky)
6990 (org-agenda-buffer-tmp-name (buffer-name))
6991 (args (get-text-property (point) 'org-last-args))
6992 (0-arg (or current-prefix-arg (car args)))
6993 (2-arg (nth 2 args))
6994 (newcmd (list 'org-agenda-list 0-arg date
6995 (org-agenda-span-to-ndays 2-arg)))
6996 (newargs (cdr newcmd))
6997 (inhibit-read-only t)
6998 org-agenda-sticky)
6999 (if (not (org-agenda-check-type t 'agenda))
7000 (error "Not available in non-agenda blocks")
7001 (add-text-properties (point-min) (point-max)
7002 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7003 (org-agenda-redo)
7004 (setq org-agenda-sticky org-agenda-sticky-orig
7005 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7007 (defun org-agenda-goto-today ()
7008 "Go to today."
7009 (interactive)
7010 (org-agenda-check-type t 'timeline 'agenda)
7011 (let* ((args (get-text-property (point) 'org-last-args))
7012 (curspan (nth 2 args))
7013 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7014 (cond
7015 (tdpos (goto-char tdpos))
7016 ((eq org-agenda-type 'agenda)
7017 (let* ((sd (org-agenda-compute-starting-span
7018 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7019 (org-agenda-overriding-arguments args))
7020 (setf (nth 1 org-agenda-overriding-arguments) sd)
7021 (org-agenda-redo)
7022 (org-agenda-find-same-or-today-or-agenda)))
7023 (t (error "Cannot find today")))))
7025 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7026 (goto-char
7027 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7028 (text-property-any (point-min) (point-max) 'org-today t)
7029 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7030 (and (get-text-property (point) 'org-serie)
7031 (org-agenda-goto-block-beginning))
7032 (point-min))))
7034 (defun org-agenda-goto-block-beginning ()
7035 "Go the agenda block beginning."
7036 (interactive)
7037 (if (not (derived-mode-p 'org-agenda-mode))
7038 (error "Cannot execute this command outside of org-agenda-mode buffers")
7039 (let (dest)
7040 (save-excursion
7041 (unless (looking-at "\\'")
7042 (forward-char))
7043 (let* ((prop 'org-agenda-structural-header)
7044 (p (previous-single-property-change (point) prop))
7045 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7046 (1- (point))) prop)))
7047 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7048 (if (not dest)
7049 (error "Cannot find the beginning of the blog")
7050 (goto-char dest)
7051 (move-beginning-of-line 1)))))
7053 (defun org-agenda-later (arg)
7054 "Go forward in time by thee current span.
7055 With prefix ARG, go forward that many times the current span."
7056 (interactive "p")
7057 (org-agenda-check-type t 'agenda)
7058 (let* ((args (get-text-property (point) 'org-last-args))
7059 (span (or (nth 2 args) org-agenda-current-span))
7060 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7061 (greg (calendar-gregorian-from-absolute sd))
7062 (cnt (org-get-at-bol 'org-day-cnt))
7063 greg2)
7064 (cond
7065 ((numberp span)
7066 (setq sd (+ span sd)))
7067 ((eq span 'day)
7068 (setq sd (+ arg sd)))
7069 ((eq span 'week)
7070 (setq sd (+ (* 7 arg) sd)))
7071 ((eq span 'month)
7072 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7073 sd (calendar-absolute-from-gregorian greg2))
7074 (setcar greg2 (1+ (car greg2))))
7075 ((eq span 'year)
7076 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7077 sd (calendar-absolute-from-gregorian greg2))
7078 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7080 (setq sd (+ (* span arg) sd))))
7081 (let ((org-agenda-overriding-cmd
7082 ;; `cmd' may have been set by `org-agenda-run-series' which
7083 ;; uses `org-agenda-overriding-cmd' to decide whether
7084 ;; overriding is allowed for `cmd'
7085 (get-text-property (point) 'org-serie-cmd))
7086 (org-agenda-overriding-arguments
7087 (list (car args) sd span)))
7088 (org-agenda-redo)
7089 (org-agenda-find-same-or-today-or-agenda cnt))))
7091 (defun org-agenda-earlier (arg)
7092 "Go backward in time by the current span.
7093 With prefix ARG, go backward that many times the current span."
7094 (interactive "p")
7095 (org-agenda-later (- arg)))
7097 (defun org-agenda-view-mode-dispatch ()
7098 "Call one of the view mode commands."
7099 (interactive)
7100 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7101 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7102 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7103 (let ((a (read-char-exclusive)))
7104 (case a
7105 (?\ (call-interactively 'org-agenda-reset-view))
7106 (?d (call-interactively 'org-agenda-day-view))
7107 (?w (call-interactively 'org-agenda-week-view))
7108 (?m (call-interactively 'org-agenda-month-view))
7109 (?y (call-interactively 'org-agenda-year-view))
7110 (?l (call-interactively 'org-agenda-log-mode))
7111 (?L (org-agenda-log-mode '(4)))
7112 (?c (org-agenda-log-mode 'clockcheck))
7113 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7114 (?a (call-interactively 'org-agenda-archives-mode))
7115 (?A (org-agenda-archives-mode 'files))
7116 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7117 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7118 (?G (call-interactively 'org-agenda-toggle-time-grid))
7119 (?D (call-interactively 'org-agenda-toggle-diary))
7120 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7121 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7122 (org-agenda-check-type t 'timeline 'agenda)
7123 (org-agenda-redo))
7124 (message "Display now includes inactive timestamps as well"))
7125 (?q (message "Abort"))
7126 (otherwise (error "Invalid key" )))))
7128 (defun org-agenda-reset-view ()
7129 "Switch to default view for agenda."
7130 (interactive)
7131 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7132 (defun org-agenda-day-view (&optional day-of-year)
7133 "Switch to daily view for agenda.
7134 With argument DAY-OF-YEAR, switch to that day of the year."
7135 (interactive "P")
7136 (org-agenda-change-time-span 'day day-of-year))
7137 (defun org-agenda-week-view (&optional iso-week)
7138 "Switch to daily view for agenda.
7139 With argument ISO-WEEK, switch to the corresponding ISO week.
7140 If ISO-WEEK has more then 2 digits, only the last two encode the
7141 week. Any digits before this encode a year. So 200712 means
7142 week 12 of year 2007. Years in the range 1938-2037 can also be
7143 written as 2-digit years."
7144 (interactive "P")
7145 (org-agenda-change-time-span 'week iso-week))
7146 (defun org-agenda-month-view (&optional month)
7147 "Switch to monthly view for agenda.
7148 With argument MONTH, switch to that month."
7149 (interactive "P")
7150 (org-agenda-change-time-span 'month month))
7151 (defun org-agenda-year-view (&optional year)
7152 "Switch to yearly view for agenda.
7153 With argument YEAR, switch to that year.
7154 If MONTH has more then 2 digits, only the last two encode the
7155 month. Any digits before this encode a year. So 200712 means
7156 December year 2007. Years in the range 1938-2037 can also be
7157 written as 2-digit years."
7158 (interactive "P")
7159 (when year
7160 (setq year (org-small-year-to-year year)))
7161 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7162 (org-agenda-change-time-span 'year year)
7163 (error "Abort")))
7165 (defun org-agenda-change-time-span (span &optional n)
7166 "Change the agenda view to SPAN.
7167 SPAN may be `day', `week', `month', `year'."
7168 (org-agenda-check-type t 'agenda)
7169 (let* ((args (get-text-property (point) 'org-last-args))
7170 (curspan (nth 2 args)))
7171 (if (and (not n) (equal curspan span))
7172 (error "Viewing span is already \"%s\"" span))
7173 (let* ((sd (or (org-get-at-bol 'day)
7174 (nth 1 args)
7175 org-starting-day))
7176 (sd (org-agenda-compute-starting-span sd span n))
7177 (org-agenda-overriding-cmd
7178 (get-text-property (point) 'org-serie-cmd))
7179 (org-agenda-overriding-arguments
7180 (list (car args) sd span)))
7181 (org-agenda-redo)
7182 (org-agenda-find-same-or-today-or-agenda))
7183 (org-agenda-set-mode-name)
7184 (message "Switched to %s view" span)))
7186 (defun org-agenda-compute-starting-span (sd span &optional n)
7187 "Compute starting date for agenda.
7188 SPAN may be `day', `week', `month', `year'. The return value
7189 is a cons cell with the starting date and the number of days,
7190 so that the date SD will be in that range."
7191 (let* ((greg (calendar-gregorian-from-absolute sd))
7192 (dg (nth 1 greg))
7193 (mg (car greg))
7194 (yg (nth 2 greg)))
7195 (cond
7196 ((eq span 'day)
7197 (when n
7198 (setq sd (+ (calendar-absolute-from-gregorian
7199 (list mg 1 yg))
7200 n -1))))
7201 ((eq span 'week)
7202 (let* ((nt (calendar-day-of-week
7203 (calendar-gregorian-from-absolute sd)))
7204 (d (if org-agenda-start-on-weekday
7205 (- nt org-agenda-start-on-weekday)
7208 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7209 (when n
7210 (require 'cal-iso)
7211 (when (> n 99)
7212 (setq y1 (org-small-year-to-year (/ n 100))
7213 n (mod n 100)))
7214 (setq sd
7215 (calendar-absolute-from-iso
7216 (list n 1
7217 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7218 ((eq span 'month)
7219 (let (y1)
7220 (when (and n (> n 99))
7221 (setq y1 (org-small-year-to-year (/ n 100))
7222 n (mod n 100)))
7223 (setq sd (calendar-absolute-from-gregorian
7224 (list (or n mg) 1 (or y1 yg))))))
7225 ((eq span 'year)
7226 (setq sd (calendar-absolute-from-gregorian
7227 (list 1 1 (or n yg))))))
7228 sd))
7230 (defun org-agenda-next-date-line (&optional arg)
7231 "Jump to the next line indicating a date in agenda buffer."
7232 (interactive "p")
7233 (org-agenda-check-type t 'agenda 'timeline)
7234 (beginning-of-line 1)
7235 ;; This does not work if user makes date format that starts with a blank
7236 (if (looking-at "^\\S-") (forward-char 1))
7237 (if (not (re-search-forward "^\\S-" nil t arg))
7238 (progn
7239 (backward-char 1)
7240 (error "No next date after this line in this buffer")))
7241 (goto-char (match-beginning 0)))
7243 (defun org-agenda-previous-date-line (&optional arg)
7244 "Jump to the previous line indicating a date in agenda buffer."
7245 (interactive "p")
7246 (org-agenda-check-type t 'agenda 'timeline)
7247 (beginning-of-line 1)
7248 (if (not (re-search-backward "^\\S-" nil t arg))
7249 (error "No previous date before this line in this buffer")))
7251 ;; Initialize the highlight
7252 (defvar org-hl (make-overlay 1 1))
7253 (overlay-put org-hl 'face 'highlight)
7255 (defun org-highlight (begin end &optional buffer)
7256 "Highlight a region with overlay."
7257 (move-overlay org-hl begin end (or buffer (current-buffer))))
7259 (defun org-unhighlight ()
7260 "Detach overlay INDEX."
7261 (org-detach-overlay org-hl))
7263 (defun org-unhighlight-once ()
7264 "Remove the highlight from its position, and this function from the hook."
7265 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7266 (org-unhighlight))
7268 (defun org-agenda-follow-mode ()
7269 "Toggle follow mode in an agenda buffer."
7270 (interactive)
7271 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7272 (org-agenda-set-mode-name)
7273 (org-agenda-do-context-action)
7274 (message "Follow mode is %s"
7275 (if org-agenda-follow-mode "on" "off")))
7277 (defun org-agenda-entry-text-mode (&optional arg)
7278 "Toggle entry text mode in an agenda buffer."
7279 (interactive "P")
7280 (setq org-agenda-entry-text-mode (or (integerp arg)
7281 (not org-agenda-entry-text-mode)))
7282 (org-agenda-entry-text-hide)
7283 (and org-agenda-entry-text-mode
7284 (let ((org-agenda-entry-text-maxlines
7285 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7286 (org-agenda-entry-text-show)))
7287 (org-agenda-set-mode-name)
7288 (message "Entry text mode is %s. Maximum number of lines is %d"
7289 (if org-agenda-entry-text-mode "on" "off")
7290 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7292 (defun org-agenda-clockreport-mode (&optional with-filter)
7293 "Toggle clocktable mode in an agenda buffer.
7294 With prefix arg WITH-FILTER, make the clocktable respect the current
7295 agenda filter."
7296 (interactive "P")
7297 (org-agenda-check-type t 'agenda)
7298 (if with-filter
7299 (setq org-agenda-clockreport-mode 'with-filter)
7300 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7301 (org-agenda-set-mode-name)
7302 (org-agenda-redo)
7303 (message "Clocktable mode is %s"
7304 (if org-agenda-clockreport-mode "on" "off")))
7306 (defun org-agenda-log-mode (&optional special)
7307 "Toggle log mode in an agenda buffer.
7308 With argument SPECIAL, show all possible log items, not only the ones
7309 configured in `org-agenda-log-mode-items'.
7310 With a double `C-u' prefix arg, show *only* log items, nothing else."
7311 (interactive "P")
7312 (org-agenda-check-type t 'agenda 'timeline)
7313 (setq org-agenda-show-log
7314 (cond
7315 ((equal special '(16)) 'only)
7316 ((eq special 'clockcheck)
7317 (if (eq org-agenda-show-log 'clockcheck)
7318 nil 'clockcheck))
7319 (special '(closed clock state))
7320 (t (not org-agenda-show-log))))
7321 (org-agenda-set-mode-name)
7322 (org-agenda-redo)
7323 (message "Log mode is %s"
7324 (if org-agenda-show-log "on" "off")))
7326 (defun org-agenda-archives-mode (&optional with-files)
7327 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7328 When called with a prefix argument, include all archive files as well."
7329 (interactive "P")
7330 (setq org-agenda-archives-mode
7331 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7332 (org-agenda-set-mode-name)
7333 (org-agenda-redo)
7334 (message
7335 "%s"
7336 (cond
7337 ((eq org-agenda-archives-mode nil)
7338 "No archives are included")
7339 ((eq org-agenda-archives-mode 'trees)
7340 (format "Trees with :%s: tag are included" org-archive-tag))
7341 ((eq org-agenda-archives-mode t)
7342 (format "Trees with :%s: tag and all active archive files are included"
7343 org-archive-tag)))))
7345 (defun org-agenda-toggle-diary ()
7346 "Toggle diary inclusion in an agenda buffer."
7347 (interactive)
7348 (org-agenda-check-type t 'agenda)
7349 (setq org-agenda-include-diary (not org-agenda-include-diary))
7350 (org-agenda-redo)
7351 (org-agenda-set-mode-name)
7352 (message "Diary inclusion turned %s"
7353 (if org-agenda-include-diary "on" "off")))
7355 (defun org-agenda-toggle-deadlines ()
7356 "Toggle inclusion of entries with a deadline in an agenda buffer."
7357 (interactive)
7358 (org-agenda-check-type t 'agenda)
7359 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7360 (org-agenda-redo)
7361 (org-agenda-set-mode-name)
7362 (message "Deadlines inclusion turned %s"
7363 (if org-agenda-include-deadlines "on" "off")))
7365 (defun org-agenda-toggle-time-grid ()
7366 "Toggle time grid in an agenda buffer."
7367 (interactive)
7368 (org-agenda-check-type t 'agenda)
7369 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7370 (org-agenda-redo)
7371 (org-agenda-set-mode-name)
7372 (message "Time-grid turned %s"
7373 (if org-agenda-use-time-grid "on" "off")))
7375 (defun org-agenda-set-mode-name ()
7376 "Set the mode name to indicate all the small mode settings."
7377 (setq mode-name
7378 (list "Org-Agenda"
7379 (if (get 'org-agenda-files 'org-restrict) " []" "")
7381 '(:eval (org-agenda-span-name org-agenda-current-span))
7382 (if org-agenda-follow-mode " Follow" "")
7383 (if org-agenda-entry-text-mode " ETxt" "")
7384 (if org-agenda-include-diary " Diary" "")
7385 (if org-agenda-include-deadlines " Ddl" "")
7386 (if org-agenda-use-time-grid " Grid" "")
7387 (if (and (boundp 'org-habit-show-habits)
7388 org-habit-show-habits) " Habit" "")
7389 (cond
7390 ((consp org-agenda-show-log) " LogAll")
7391 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7392 (org-agenda-show-log " Log")
7393 (t ""))
7394 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7395 :preset-filter))
7396 '(:eval (org-propertize
7397 (concat " <"
7398 (mapconcat
7399 'identity
7400 (append
7401 (get 'org-agenda-category-filter :preset-filter)
7402 org-agenda-category-filter)
7404 ">")
7405 'face 'org-agenda-filter-category
7406 'help-echo "Category used in filtering"))
7408 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7409 :preset-filter))
7410 '(:eval (org-propertize
7411 (concat " {"
7412 (mapconcat
7413 'identity
7414 (append
7415 (get 'org-agenda-tag-filter :preset-filter)
7416 org-agenda-tag-filter)
7418 "}")
7419 'face 'org-agenda-filter-tags
7420 'help-echo "Tags used in filtering"))
7422 (if org-agenda-archives-mode
7423 (if (eq org-agenda-archives-mode t)
7424 " Archives"
7425 (format " :%s:" org-archive-tag))
7427 (if org-agenda-clockreport-mode
7428 (if (eq org-agenda-clockreport-mode 'with-filter)
7429 " Clock{}" " Clock")
7430 "")))
7431 (force-mode-line-update))
7433 (defun org-agenda-post-command-hook ()
7434 (setq org-agenda-type
7435 (or (get-text-property (point) 'org-agenda-type)
7436 (get-text-property (max (point-min) (1- (point)))
7437 'org-agenda-type))))
7439 (defun org-agenda-next-line ()
7440 "Move cursor to the next line, and show if follow mode is active."
7441 (interactive)
7442 (call-interactively 'next-line)
7443 (org-agenda-do-context-action))
7445 (defun org-agenda-previous-line ()
7446 "Move cursor to the previous line, and show if follow-mode is active."
7447 (interactive)
7448 (call-interactively 'previous-line)
7449 (org-agenda-do-context-action))
7451 (defun org-agenda-next-item (n)
7452 "Move cursor to next agenda item."
7453 (interactive "p")
7454 (let ((col (current-column)))
7455 (dotimes (c n)
7456 (when (next-single-property-change (point-at-eol) 'org-marker)
7457 (move-end-of-line 1)
7458 (goto-char (next-single-property-change (point) 'org-marker))))
7459 (org-move-to-column col))
7460 (org-agenda-do-context-action))
7462 (defun org-agenda-previous-item (n)
7463 "Move cursor to next agenda item."
7464 (interactive "p")
7465 (dotimes (c n)
7466 (let ((col (current-column))
7467 (goto (save-excursion
7468 (move-end-of-line 0)
7469 (previous-single-property-change (point) 'org-marker))))
7470 (if goto (goto-char goto))
7471 (org-move-to-column col)))
7472 (org-agenda-do-context-action))
7474 (defun org-agenda-do-context-action ()
7475 "Show outline path and, maybe, follow mode window."
7476 (let ((m (org-get-at-bol 'org-marker)))
7477 (when (and (markerp m) (marker-buffer m))
7478 (and org-agenda-follow-mode
7479 (if org-agenda-follow-indirect
7480 (org-agenda-tree-to-indirect-buffer)
7481 (org-agenda-show)))
7482 (and org-agenda-show-outline-path
7483 (org-with-point-at m (org-display-outline-path t))))))
7485 (defun org-agenda-show-priority ()
7486 "Show the priority of the current item.
7487 This priority is composed of the main priority given with the [#A] cookies,
7488 and by additional input from the age of a schedules or deadline entry."
7489 (interactive)
7490 (let* ((pri (org-get-at-bol 'priority)))
7491 (message "Priority is %d" (if pri pri -1000))))
7493 (defun org-agenda-show-tags ()
7494 "Show the tags applicable to the current item."
7495 (interactive)
7496 (let* ((tags (org-get-at-bol 'tags)))
7497 (if tags
7498 (message "Tags are :%s:"
7499 (org-no-properties (mapconcat 'identity tags ":")))
7500 (message "No tags associated with this line"))))
7502 (defun org-agenda-goto (&optional highlight)
7503 "Go to the Org-mode file which contains the item at point."
7504 (interactive)
7505 (let* ((marker (or (org-get-at-bol 'org-marker)
7506 (org-agenda-error)))
7507 (buffer (marker-buffer marker))
7508 (pos (marker-position marker)))
7509 (switch-to-buffer-other-window buffer)
7510 (widen)
7511 (push-mark)
7512 (goto-char pos)
7513 (when (derived-mode-p 'org-mode)
7514 (org-show-context 'agenda)
7515 (save-excursion
7516 (and (outline-next-heading)
7517 (org-flag-heading nil)))) ; show the next heading
7518 (when (outline-invisible-p)
7519 (show-entry)) ; display invisible text
7520 (recenter (/ (window-height) 2))
7521 (run-hooks 'org-agenda-after-show-hook)
7522 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7524 (defvar org-agenda-after-show-hook nil
7525 "Normal hook run after an item has been shown from the agenda.
7526 Point is in the buffer where the item originated.")
7528 (defun org-agenda-kill ()
7529 "Kill the entry or subtree belonging to the current agenda entry."
7530 (interactive)
7531 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7532 (let* ((bufname-orig (buffer-name))
7533 (marker (or (org-get-at-bol 'org-marker)
7534 (org-agenda-error)))
7535 (buffer (marker-buffer marker))
7536 (pos (marker-position marker))
7537 (type (org-get-at-bol 'type))
7538 dbeg dend (n 0) conf)
7539 (org-with-remote-undo buffer
7540 (with-current-buffer buffer
7541 (save-excursion
7542 (goto-char pos)
7543 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7544 (setq dbeg (progn (org-back-to-heading t) (point))
7545 dend (org-end-of-subtree t t))
7546 (setq dbeg (point-at-bol)
7547 dend (min (point-max) (1+ (point-at-eol)))))
7548 (goto-char dbeg)
7549 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7550 (setq conf (or (eq t org-agenda-confirm-kill)
7551 (and (numberp org-agenda-confirm-kill)
7552 (> n org-agenda-confirm-kill))))
7553 (and conf
7554 (not (y-or-n-p
7555 (format "Delete entry with %d lines in buffer \"%s\"? "
7556 n (buffer-name buffer))))
7557 (error "Abort"))
7558 (let ((org-agenda-buffer-name bufname-orig))
7559 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7560 (with-current-buffer buffer (delete-region dbeg dend))
7561 (message "Agenda item and source killed"))))
7563 (defvar org-archive-default-command) ; defined in org-archive.el
7564 (defun org-agenda-archive-default ()
7565 "Archive the entry or subtree belonging to the current agenda entry."
7566 (interactive)
7567 (require 'org-archive)
7568 (org-agenda-archive-with org-archive-default-command))
7570 (defun org-agenda-archive-default-with-confirmation ()
7571 "Archive the entry or subtree belonging to the current agenda entry."
7572 (interactive)
7573 (require 'org-archive)
7574 (org-agenda-archive-with org-archive-default-command 'confirm))
7576 (defun org-agenda-archive ()
7577 "Archive the entry or subtree belonging to the current agenda entry."
7578 (interactive)
7579 (org-agenda-archive-with 'org-archive-subtree))
7581 (defun org-agenda-archive-to-archive-sibling ()
7582 "Move the entry to the archive sibling."
7583 (interactive)
7584 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7586 (defun org-agenda-archive-with (cmd &optional confirm)
7587 "Move the entry to the archive sibling."
7588 (interactive)
7589 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7590 (let* ((bufname-orig (buffer-name))
7591 (marker (or (org-get-at-bol 'org-marker)
7592 (org-agenda-error)))
7593 (buffer (marker-buffer marker))
7594 (pos (marker-position marker)))
7595 (org-with-remote-undo buffer
7596 (with-current-buffer buffer
7597 (if (derived-mode-p 'org-mode)
7598 (if (and confirm
7599 (not (y-or-n-p "Archive this subtree or entry? ")))
7600 (error "Abort")
7601 (save-excursion
7602 (goto-char pos)
7603 (let ((org-agenda-buffer-name bufname-orig))
7604 (org-remove-subtree-entries-from-agenda))
7605 (org-back-to-heading t)
7606 (funcall cmd)))
7607 (error "Archiving works only in Org-mode files"))))))
7609 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7610 "Remove all lines in the agenda that correspond to a given subtree.
7611 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7612 If this information is not given, the function uses the tree at point."
7613 (let ((buf (or buf (current-buffer))) m p)
7614 (save-excursion
7615 (unless (and beg end)
7616 (org-back-to-heading t)
7617 (setq beg (point))
7618 (org-end-of-subtree t)
7619 (setq end (point)))
7620 (set-buffer (get-buffer org-agenda-buffer-name))
7621 (save-excursion
7622 (goto-char (point-max))
7623 (beginning-of-line 1)
7624 (while (not (bobp))
7625 (when (and (setq m (org-get-at-bol 'org-marker))
7626 (equal buf (marker-buffer m))
7627 (setq p (marker-position m))
7628 (>= p beg)
7629 (< p end))
7630 (let ((inhibit-read-only t))
7631 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7632 (beginning-of-line 0))))))
7634 (defun org-agenda-refile (&optional goto rfloc no-update)
7635 "Refile the item at point."
7636 (interactive "P")
7637 (if (equal goto '(16))
7638 (org-refile-goto-last-stored)
7639 (let* ((buffer-orig (buffer-name))
7640 (marker (or (org-get-at-bol 'org-hd-marker)
7641 (org-agenda-error)))
7642 (buffer (marker-buffer marker))
7643 (pos (marker-position marker))
7644 (rfloc (or rfloc
7645 (org-refile-get-location
7646 (if goto "Goto" "Refile to") buffer
7647 org-refile-allow-creating-parent-nodes))))
7648 (with-current-buffer buffer
7649 (save-excursion
7650 (save-restriction
7651 (widen)
7652 (goto-char marker)
7653 (let ((org-agenda-buffer-name buffer-orig))
7654 (org-remove-subtree-entries-from-agenda))
7655 (org-refile goto buffer rfloc)))))
7656 (unless no-update (org-agenda-redo))))
7658 (defun org-agenda-open-link (&optional arg)
7659 "Follow the link in the current line, if any.
7660 This looks for a link in the displayed line in the agenda. It also looks
7661 at the text of the entry itself."
7662 (interactive "P")
7663 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7664 (org-get-at-bol 'org-marker)))
7665 (buffer (and marker (marker-buffer marker)))
7666 (prefix (buffer-substring
7667 (point-at-bol) (point-at-eol))))
7668 (cond
7669 (buffer
7670 (with-current-buffer buffer
7671 (save-excursion
7672 (save-restriction
7673 (widen)
7674 (goto-char marker)
7675 (org-offer-links-in-entry arg prefix)))))
7676 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7677 (save-excursion
7678 (beginning-of-line 1)
7679 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7680 (org-open-link-from-string (match-string 1)))
7681 (t (error "No link to open here")))))
7683 (defun org-agenda-copy-local-variable (var)
7684 "Get a variable from a referenced buffer and install it here."
7685 (let ((m (org-get-at-bol 'org-marker)))
7686 (when (and m (buffer-live-p (marker-buffer m)))
7687 (org-set-local var (with-current-buffer (marker-buffer m)
7688 (symbol-value var))))))
7690 (defun org-agenda-switch-to (&optional delete-other-windows)
7691 "Go to the Org-mode file which contains the item at point."
7692 (interactive)
7693 (if (and org-return-follows-link
7694 (not (org-get-at-bol 'org-marker))
7695 (org-in-regexp org-bracket-link-regexp))
7696 (org-open-link-from-string (match-string 0))
7697 (let* ((marker (or (org-get-at-bol 'org-marker)
7698 (org-agenda-error)))
7699 (buffer (marker-buffer marker))
7700 (pos (marker-position marker)))
7701 (org-pop-to-buffer-same-window buffer)
7702 (and delete-other-windows (delete-other-windows))
7703 (widen)
7704 (goto-char pos)
7705 (when (derived-mode-p 'org-mode)
7706 (org-show-context 'agenda)
7707 (save-excursion
7708 (and (outline-next-heading)
7709 (org-flag-heading nil))) ; show the next heading
7710 (when (outline-invisible-p)
7711 (show-entry)) ; display invisible text
7712 (run-hooks 'org-agenda-after-show-hook)))))
7714 (defun org-agenda-goto-mouse (ev)
7715 "Go to the Org-mode file which contains the item at the mouse click."
7716 (interactive "e")
7717 (mouse-set-point ev)
7718 (org-agenda-goto))
7720 (defun org-agenda-show (&optional full-entry)
7721 "Display the Org-mode file which contains the item at point.
7722 With prefix argument FULL-ENTRY, make the entire entry visible
7723 if it was hidden in the outline."
7724 (interactive "P")
7725 (let ((win (selected-window)))
7726 (if full-entry
7727 (let ((org-show-entry-below t))
7728 (org-agenda-goto t))
7729 (org-agenda-goto t))
7730 (select-window win)))
7732 (defvar org-agenda-show-window nil)
7733 (defun org-agenda-show-and-scroll-up (&optional arg)
7734 "Display the Org-mode file which contains the item at point.
7735 When called repeatedly, scroll the window that is displaying the buffer.
7736 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7737 `show-subtree' to display the item, so that drawers and logbooks stay
7738 folded."
7739 (interactive "P")
7740 (let ((win (selected-window)))
7741 (if (and (window-live-p org-agenda-show-window)
7742 (eq this-command last-command))
7743 (progn
7744 (select-window org-agenda-show-window)
7745 (ignore-errors (scroll-up)))
7746 (org-agenda-goto t)
7747 (if arg (org-show-entry) (show-subtree))
7748 (setq org-agenda-show-window (selected-window)))
7749 (select-window win)))
7751 (defun org-agenda-show-scroll-down ()
7752 "Scroll down the window showing the agenda."
7753 (interactive)
7754 (let ((win (selected-window)))
7755 (when (window-live-p org-agenda-show-window)
7756 (select-window org-agenda-show-window)
7757 (ignore-errors (scroll-down))
7758 (select-window win))))
7760 (defun org-agenda-show-1 (&optional more)
7761 "Display the Org-mode file which contains the item at point.
7762 The prefix arg selects the amount of information to display:
7764 0 hide the subtree
7765 1 just show the entry according to defaults.
7766 2 show the children view
7767 3 show the subtree view
7768 4 show the entire subtree and any LOGBOOK drawers
7769 5 show the entire subtree and any drawers
7770 With prefix argument FULL-ENTRY, make the entire entry visible
7771 if it was hidden in the outline."
7772 (interactive "p")
7773 (let ((win (selected-window)))
7774 (org-agenda-goto t)
7775 (org-recenter-heading 1)
7776 (cond
7777 ((= more 0)
7778 (hide-subtree)
7779 (save-excursion
7780 (org-back-to-heading)
7781 (run-hook-with-args 'org-cycle-hook 'folded))
7782 (message "Remote: FOLDED"))
7783 ((and (org-called-interactively-p 'any) (= more 1))
7784 (message "Remote: show with default settings"))
7785 ((= more 2)
7786 (show-entry)
7787 (show-children)
7788 (save-excursion
7789 (org-back-to-heading)
7790 (run-hook-with-args 'org-cycle-hook 'children))
7791 (message "Remote: CHILDREN"))
7792 ((= more 3)
7793 (show-subtree)
7794 (save-excursion
7795 (org-back-to-heading)
7796 (run-hook-with-args 'org-cycle-hook 'subtree))
7797 (message "Remote: SUBTREE"))
7798 ((= more 4)
7799 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7800 (org-drawer-regexp
7801 (concat "^[ \t]*:\\("
7802 (mapconcat 'regexp-quote org-drawers "\\|")
7803 "\\):[ \t]*$")))
7804 (show-subtree)
7805 (save-excursion
7806 (org-back-to-heading)
7807 (org-cycle-hide-drawers 'subtree)))
7808 (message "Remote: SUBTREE AND LOGBOOK"))
7809 ((> more 4)
7810 (show-subtree)
7811 (message "Remote: SUBTREE AND ALL DRAWERS")))
7812 (select-window win)))
7814 (defun org-recenter-heading (n)
7815 (save-excursion
7816 (org-back-to-heading)
7817 (recenter n)))
7819 (defvar org-agenda-cycle-counter nil)
7820 (defun org-agenda-cycle-show (&optional n)
7821 "Show the current entry in another window, with default settings.
7822 Default settings are taken from `org-show-hierarchy-above' and siblings.
7823 When use repeatedly in immediate succession, the remote entry will cycle
7824 through visibility
7826 children -> subtree -> folded
7828 When called with a numeric prefix arg, that arg will be passed through to
7829 `org-agenda-show-1'. For the interpretation of that argument, see the
7830 docstring of `org-agenda-show-1'."
7831 (interactive "P")
7832 (if (integerp n)
7833 (setq org-agenda-cycle-counter n)
7834 (if (not (eq last-command this-command))
7835 (setq org-agenda-cycle-counter 1)
7836 (if (equal org-agenda-cycle-counter 0)
7837 (setq org-agenda-cycle-counter 2)
7838 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7839 (if (> org-agenda-cycle-counter 3)
7840 (setq org-agenda-cycle-counter 0)))))
7841 (org-agenda-show-1 org-agenda-cycle-counter))
7843 (defun org-agenda-recenter (arg)
7844 "Display the Org-mode file which contains the item at point and recenter."
7845 (interactive "P")
7846 (let ((win (selected-window)))
7847 (org-agenda-goto t)
7848 (recenter arg)
7849 (select-window win)))
7851 (defun org-agenda-show-mouse (ev)
7852 "Display the Org-mode file which contains the item at the mouse click."
7853 (interactive "e")
7854 (mouse-set-point ev)
7855 (org-agenda-show))
7857 (defun org-agenda-check-no-diary ()
7858 "Check if the entry is a diary link and abort if yes."
7859 (if (org-get-at-bol 'org-agenda-diary-link)
7860 (org-agenda-error)))
7862 (defun org-agenda-error ()
7863 (error "Command not allowed in this line"))
7865 (defun org-agenda-tree-to-indirect-buffer ()
7866 "Show the subtree corresponding to the current entry in an indirect buffer.
7867 This calls the command `org-tree-to-indirect-buffer' from the original
7868 Org-mode buffer.
7869 With numerical prefix arg ARG, go up to this level and then take that tree.
7870 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7871 use the dedicated frame)."
7872 (interactive)
7873 (if (and current-prefix-arg (listp current-prefix-arg))
7874 (org-agenda-do-tree-to-indirect-buffer)
7875 (let ((agenda-window (selected-window))
7876 (indirect-window
7877 (and org-last-indirect-buffer
7878 (get-buffer-window org-last-indirect-buffer))))
7879 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7880 (unwind-protect
7881 (progn
7882 (unless (and indirect-window (window-live-p indirect-window))
7883 (setq indirect-window (split-window agenda-window)))
7884 (select-window indirect-window)
7885 (switch-to-buffer org-last-indirect-buffer :norecord)
7886 (fit-window-to-buffer indirect-window))
7887 (select-window (get-buffer-window org-agenda-buffer-name))))))
7889 (defun org-agenda-do-tree-to-indirect-buffer ()
7890 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7891 (org-agenda-check-no-diary)
7892 (let* ((marker (or (org-get-at-bol 'org-marker)
7893 (org-agenda-error)))
7894 (buffer (marker-buffer marker))
7895 (pos (marker-position marker)))
7896 (with-current-buffer buffer
7897 (save-excursion
7898 (goto-char pos)
7899 (call-interactively 'org-tree-to-indirect-buffer)))))
7901 (defvar org-last-heading-marker (make-marker)
7902 "Marker pointing to the headline that last changed its TODO state
7903 by a remote command from the agenda.")
7905 (defun org-agenda-todo-nextset ()
7906 "Switch TODO entry to next sequence."
7907 (interactive)
7908 (org-agenda-todo 'nextset))
7910 (defun org-agenda-todo-previousset ()
7911 "Switch TODO entry to previous sequence."
7912 (interactive)
7913 (org-agenda-todo 'previousset))
7915 (defun org-agenda-todo (&optional arg)
7916 "Cycle TODO state of line at point, also in Org-mode file.
7917 This changes the line at point, all other lines in the agenda referring to
7918 the same tree node, and the headline of the tree node in the Org-mode file."
7919 (interactive "P")
7920 (org-agenda-check-no-diary)
7921 (let* ((col (current-column))
7922 (marker (or (org-get-at-bol 'org-marker)
7923 (org-agenda-error)))
7924 (buffer (marker-buffer marker))
7925 (pos (marker-position marker))
7926 (hdmarker (org-get-at-bol 'org-hd-marker))
7927 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7928 (inhibit-read-only t)
7929 org-agenda-headline-snapshot-before-repeat newhead just-one)
7930 (org-with-remote-undo buffer
7931 (with-current-buffer buffer
7932 (widen)
7933 (goto-char pos)
7934 (org-show-context 'agenda)
7935 (save-excursion
7936 (and (outline-next-heading)
7937 (org-flag-heading nil))) ; show the next heading
7938 (let ((current-prefix-arg arg))
7939 (call-interactively 'org-todo))
7940 (and (bolp) (forward-char 1))
7941 (setq newhead (org-get-heading))
7942 (when (and (org-bound-and-true-p
7943 org-agenda-headline-snapshot-before-repeat)
7944 (not (equal org-agenda-headline-snapshot-before-repeat
7945 newhead))
7946 todayp)
7947 (setq newhead org-agenda-headline-snapshot-before-repeat
7948 just-one t))
7949 (save-excursion
7950 (org-back-to-heading)
7951 (move-marker org-last-heading-marker (point))))
7952 (beginning-of-line 1)
7953 (save-excursion
7954 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7955 (org-move-to-column col))))
7957 (defun org-agenda-add-note (&optional arg)
7958 "Add a time-stamped note to the entry at point."
7959 (interactive "P")
7960 (org-agenda-check-no-diary)
7961 (let* ((marker (or (org-get-at-bol 'org-marker)
7962 (org-agenda-error)))
7963 (buffer (marker-buffer marker))
7964 (pos (marker-position marker))
7965 (hdmarker (org-get-at-bol 'org-hd-marker))
7966 (inhibit-read-only t))
7967 (with-current-buffer buffer
7968 (widen)
7969 (goto-char pos)
7970 (org-show-context 'agenda)
7971 (save-excursion
7972 (and (outline-next-heading)
7973 (org-flag-heading nil))) ; show the next heading
7974 (org-add-note))))
7976 (defun org-agenda-change-all-lines (newhead hdmarker
7977 &optional fixface just-this)
7978 "Change all lines in the agenda buffer which match HDMARKER.
7979 The new content of the line will be NEWHEAD (as modified by
7980 `org-agenda-format-item'). HDMARKER is checked with
7981 `equal' against all `org-hd-marker' text properties in the file.
7982 If FIXFACE is non-nil, the face of each item is modified according to
7983 the new TODO state.
7984 If JUST-THIS is non-nil, change just the current line, not all.
7985 If FORCE-TAGS is non nil, the car of it returns the new tags."
7986 (let* ((inhibit-read-only t)
7987 (line (org-current-line))
7988 (org-agenda-buffer (current-buffer))
7989 (thetags (with-current-buffer (marker-buffer hdmarker)
7990 (save-excursion (save-restriction (widen)
7991 (goto-char hdmarker)
7992 (org-get-tags-at)))))
7993 props m pl undone-face done-face finish new dotime cat tags)
7994 (save-excursion
7995 (goto-char (point-max))
7996 (beginning-of-line 1)
7997 (while (not finish)
7998 (setq finish (bobp))
7999 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8000 (or (not just-this) (= (org-current-line) line))
8001 (equal m hdmarker))
8002 (setq props (text-properties-at (point))
8003 dotime (org-get-at-bol 'dotime)
8004 cat (org-get-at-bol 'org-category)
8005 tags thetags
8007 (let ((org-prefix-format-compiled
8008 (or (get-text-property (point) 'format)
8009 org-prefix-format-compiled))
8010 (extra (org-get-at-bol 'extra)))
8011 (with-current-buffer (marker-buffer hdmarker)
8012 (save-excursion
8013 (save-restriction
8014 (widen)
8015 (org-agenda-format-item extra newhead cat tags dotime)))))
8016 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8017 undone-face (org-get-at-bol 'undone-face)
8018 done-face (org-get-at-bol 'done-face))
8019 (beginning-of-line 1)
8020 (cond
8021 ((equal new "")
8022 (and (looking-at ".*\n?") (replace-match "")))
8023 ((looking-at ".*")
8024 (replace-match new t t)
8025 (beginning-of-line 1)
8026 (add-text-properties (point-at-bol) (point-at-eol) props)
8027 (when fixface
8028 (add-text-properties
8029 (point-at-bol) (point-at-eol)
8030 (list 'face
8031 (if org-last-todo-state-is-todo
8032 undone-face done-face))))
8033 (org-agenda-highlight-todo 'line)
8034 (beginning-of-line 1))
8035 (t (error "Line update did not work"))))
8036 (beginning-of-line 0)))
8037 (org-agenda-finalize)))
8039 (defun org-agenda-align-tags (&optional line)
8040 "Align all tags in agenda items to `org-agenda-tags-column'."
8041 (let ((inhibit-read-only t) l c)
8042 (save-excursion
8043 (goto-char (if line (point-at-bol) (point-min)))
8044 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8045 (if line (point-at-eol) nil) t)
8046 (add-text-properties
8047 (match-beginning 2) (match-end 2)
8048 (list 'face (delq nil (let ((prop (get-text-property
8049 (match-beginning 2) 'face)))
8050 (or (listp prop) (setq prop (list prop)))
8051 (if (memq 'org-tag prop)
8052 prop
8053 (cons 'org-tag prop))))))
8054 (setq l (- (match-end 2) (match-beginning 2))
8055 c (if (< org-agenda-tags-column 0)
8056 (- (abs org-agenda-tags-column) l)
8057 org-agenda-tags-column))
8058 (delete-region (match-beginning 1) (match-end 1))
8059 (goto-char (match-beginning 1))
8060 (insert (org-add-props
8061 (make-string (max 1 (- c (current-column))) ?\ )
8062 (plist-put (copy-sequence (text-properties-at (point)))
8063 'face nil))))
8064 (goto-char (point-min))
8065 (org-font-lock-add-tag-faces (point-max)))))
8067 (defun org-agenda-priority-up ()
8068 "Increase the priority of line at point, also in Org-mode file."
8069 (interactive)
8070 (org-agenda-priority 'up))
8072 (defun org-agenda-priority-down ()
8073 "Decrease the priority of line at point, also in Org-mode file."
8074 (interactive)
8075 (org-agenda-priority 'down))
8077 (defun org-agenda-priority (&optional force-direction)
8078 "Set the priority of line at point, also in Org-mode file.
8079 This changes the line at point, all other lines in the agenda referring to
8080 the same tree node, and the headline of the tree node in the Org-mode file."
8081 (interactive)
8082 (unless org-enable-priority-commands
8083 (error "Priority commands are disabled"))
8084 (org-agenda-check-no-diary)
8085 (let* ((marker (or (org-get-at-bol 'org-marker)
8086 (org-agenda-error)))
8087 (hdmarker (org-get-at-bol 'org-hd-marker))
8088 (buffer (marker-buffer hdmarker))
8089 (pos (marker-position hdmarker))
8090 (inhibit-read-only t)
8091 newhead)
8092 (org-with-remote-undo buffer
8093 (with-current-buffer buffer
8094 (widen)
8095 (goto-char pos)
8096 (org-show-context 'agenda)
8097 (save-excursion
8098 (and (outline-next-heading)
8099 (org-flag-heading nil))) ; show the next heading
8100 (funcall 'org-priority force-direction)
8101 (end-of-line 1)
8102 (setq newhead (org-get-heading)))
8103 (org-agenda-change-all-lines newhead hdmarker)
8104 (beginning-of-line 1))))
8106 ;; FIXME: should fix the tags property of the agenda line.
8107 (defun org-agenda-set-tags (&optional tag onoff)
8108 "Set tags for the current headline."
8109 (interactive)
8110 (org-agenda-check-no-diary)
8111 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8112 (call-interactively 'org-change-tag-in-region)
8113 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8114 (org-agenda-error)))
8115 (buffer (marker-buffer hdmarker))
8116 (pos (marker-position hdmarker))
8117 (inhibit-read-only t)
8118 newhead)
8119 (org-with-remote-undo buffer
8120 (with-current-buffer buffer
8121 (widen)
8122 (goto-char pos)
8123 (save-excursion
8124 (org-show-context 'agenda))
8125 (save-excursion
8126 (and (outline-next-heading)
8127 (org-flag-heading nil))) ; show the next heading
8128 (goto-char pos)
8129 (if tag
8130 (org-toggle-tag tag onoff)
8131 (call-interactively 'org-set-tags))
8132 (end-of-line 1)
8133 (setq newhead (org-get-heading)))
8134 (org-agenda-change-all-lines newhead hdmarker)
8135 (beginning-of-line 1)))))
8137 (defun org-agenda-set-property ()
8138 "Set a property for the current headline."
8139 (interactive)
8140 (org-agenda-check-no-diary)
8141 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8142 (org-agenda-error)))
8143 (buffer (marker-buffer hdmarker))
8144 (pos (marker-position hdmarker))
8145 (inhibit-read-only t)
8146 newhead)
8147 (org-with-remote-undo buffer
8148 (with-current-buffer buffer
8149 (widen)
8150 (goto-char pos)
8151 (save-excursion
8152 (org-show-context 'agenda))
8153 (save-excursion
8154 (and (outline-next-heading)
8155 (org-flag-heading nil))) ; show the next heading
8156 (goto-char pos)
8157 (call-interactively 'org-set-property)))))
8159 (defun org-agenda-set-effort ()
8160 "Set the effort property for the current headline."
8161 (interactive)
8162 (org-agenda-check-no-diary)
8163 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8164 (org-agenda-error)))
8165 (buffer (marker-buffer hdmarker))
8166 (pos (marker-position hdmarker))
8167 (inhibit-read-only t)
8168 newhead)
8169 (org-with-remote-undo buffer
8170 (with-current-buffer buffer
8171 (widen)
8172 (goto-char pos)
8173 (save-excursion
8174 (org-show-context 'agenda))
8175 (save-excursion
8176 (and (outline-next-heading)
8177 (org-flag-heading nil))) ; show the next heading
8178 (goto-char pos)
8179 (call-interactively 'org-set-effort)
8180 (end-of-line 1)
8181 (setq newhead (org-get-heading)))
8182 (org-agenda-change-all-lines newhead hdmarker))))
8184 (defun org-agenda-toggle-archive-tag ()
8185 "Toggle the archive tag for the current entry."
8186 (interactive)
8187 (org-agenda-check-no-diary)
8188 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8189 (org-agenda-error)))
8190 (buffer (marker-buffer hdmarker))
8191 (pos (marker-position hdmarker))
8192 (inhibit-read-only t)
8193 newhead)
8194 (org-with-remote-undo buffer
8195 (with-current-buffer buffer
8196 (widen)
8197 (goto-char pos)
8198 (org-show-context 'agenda)
8199 (save-excursion
8200 (and (outline-next-heading)
8201 (org-flag-heading nil))) ; show the next heading
8202 (call-interactively 'org-toggle-archive-tag)
8203 (end-of-line 1)
8204 (setq newhead (org-get-heading)))
8205 (org-agenda-change-all-lines newhead hdmarker)
8206 (beginning-of-line 1))))
8208 (defun org-agenda-do-date-later (arg)
8209 (interactive "P")
8210 (cond
8211 ((or (equal arg '(16))
8212 (memq last-command
8213 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8214 (setq this-command 'org-agenda-date-later-minutes)
8215 (org-agenda-date-later-minutes 1))
8216 ((or (equal arg '(4))
8217 (memq last-command
8218 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8219 (setq this-command 'org-agenda-date-later-hours)
8220 (org-agenda-date-later-hours 1))
8222 (org-agenda-date-later (prefix-numeric-value arg)))))
8224 (defun org-agenda-do-date-earlier (arg)
8225 (interactive "P")
8226 (cond
8227 ((or (equal arg '(16))
8228 (memq last-command
8229 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8230 (setq this-command 'org-agenda-date-earlier-minutes)
8231 (org-agenda-date-earlier-minutes 1))
8232 ((or (equal arg '(4))
8233 (memq last-command
8234 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8235 (setq this-command 'org-agenda-date-earlier-hours)
8236 (org-agenda-date-earlier-hours 1))
8238 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8240 (defun org-agenda-date-later (arg &optional what)
8241 "Change the date of this item to ARG day(s) later."
8242 (interactive "p")
8243 (org-agenda-check-type t 'agenda 'timeline)
8244 (org-agenda-check-no-diary)
8245 (let* ((marker (or (org-get-at-bol 'org-marker)
8246 (org-agenda-error)))
8247 (buffer (marker-buffer marker))
8248 (pos (marker-position marker))
8249 cdate today)
8250 (org-with-remote-undo buffer
8251 (with-current-buffer buffer
8252 (widen)
8253 (goto-char pos)
8254 (if (not (org-at-timestamp-p))
8255 (error "Cannot find time stamp"))
8256 (when (and org-agenda-move-date-from-past-immediately-to-today
8257 (equal arg 1)
8258 (or (not what) (eq what 'day))
8259 (not (save-match-data (org-at-date-range-p))))
8260 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8261 cdate (calendar-absolute-from-gregorian
8262 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8263 today (org-today))
8264 (if (> today cdate)
8265 ;; immediately shift to today
8266 (setq arg (- today cdate))))
8267 (org-timestamp-change arg (or what 'day))
8268 (when (and (org-at-date-range-p)
8269 (re-search-backward org-tr-regexp-both (point-at-bol)))
8270 (let ((end org-last-changed-timestamp))
8271 (org-timestamp-change arg (or what 'day))
8272 (setq org-last-changed-timestamp
8273 (concat org-last-changed-timestamp "--" end)))))
8274 (org-agenda-show-new-time marker org-last-changed-timestamp))
8275 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8277 (defun org-agenda-date-earlier (arg &optional what)
8278 "Change the date of this item to ARG day(s) earlier."
8279 (interactive "p")
8280 (org-agenda-date-later (- arg) what))
8282 (defun org-agenda-date-later-minutes (arg)
8283 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8284 (interactive "p")
8285 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8286 (org-agenda-date-later arg 'minute))
8288 (defun org-agenda-date-earlier-minutes (arg)
8289 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8290 (interactive "p")
8291 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8292 (org-agenda-date-earlier arg 'minute))
8294 (defun org-agenda-date-later-hours (arg)
8295 "Change the time of this item, in hour steps."
8296 (interactive "p")
8297 (org-agenda-date-later arg 'hour))
8299 (defun org-agenda-date-earlier-hours (arg)
8300 "Change the time of this item, in hour steps."
8301 (interactive "p")
8302 (org-agenda-date-earlier arg 'hour))
8304 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8305 "Show new date stamp via text properties."
8306 ;; We use text properties to make this undoable
8307 (let ((inhibit-read-only t)
8308 (buffer-invisibility-spec))
8309 (setq stamp (concat " " prefix " => " stamp))
8310 (save-excursion
8311 (goto-char (point-max))
8312 (while (not (bobp))
8313 (when (equal marker (org-get-at-bol 'org-marker))
8314 (org-move-to-column (- (window-width) (length stamp)) t)
8315 (org-agenda-fix-tags-filter-overlays-at (point))
8316 (if (featurep 'xemacs)
8317 ;; Use `duplicable' property to trigger undo recording
8318 (let ((ex (make-extent nil nil))
8319 (gl (make-glyph stamp)))
8320 (set-glyph-face gl 'secondary-selection)
8321 (set-extent-properties
8322 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8323 (insert-extent ex (1- (point)) (point-at-eol)))
8324 (add-text-properties
8325 (1- (point)) (point-at-eol)
8326 (list 'display (org-add-props stamp nil
8327 'face 'secondary-selection))))
8328 (beginning-of-line 1))
8329 (beginning-of-line 0)))))
8331 (defun org-agenda-date-prompt (arg)
8332 "Change the date of this item. Date is prompted for, with default today.
8333 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8334 be used to request time specification in the time stamp."
8335 (interactive "P")
8336 (org-agenda-check-type t 'agenda 'timeline)
8337 (org-agenda-check-no-diary)
8338 (let* ((marker (or (org-get-at-bol 'org-marker)
8339 (org-agenda-error)))
8340 (buffer (marker-buffer marker))
8341 (pos (marker-position marker)))
8342 (org-with-remote-undo buffer
8343 (with-current-buffer buffer
8344 (widen)
8345 (goto-char pos)
8346 (if (not (org-at-timestamp-p t))
8347 (error "Cannot find time stamp"))
8348 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8349 (org-agenda-show-new-time marker org-last-changed-timestamp))
8350 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8352 (defun org-agenda-schedule (arg &optional time)
8353 "Schedule the item at point.
8354 ARG is passed through to `org-schedule'."
8355 (interactive "P")
8356 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8357 (org-agenda-check-no-diary)
8358 (let* ((marker (or (org-get-at-bol 'org-marker)
8359 (org-agenda-error)))
8360 (type (marker-insertion-type marker))
8361 (buffer (marker-buffer marker))
8362 (pos (marker-position marker))
8363 (org-insert-labeled-timestamps-at-point nil)
8365 (set-marker-insertion-type marker t)
8366 (org-with-remote-undo buffer
8367 (with-current-buffer buffer
8368 (widen)
8369 (goto-char pos)
8370 (setq ts (org-schedule arg time)))
8371 (org-agenda-show-new-time marker ts "S"))
8372 (message "Item scheduled for %s" ts)))
8374 (defun org-agenda-deadline (arg &optional time)
8375 "Schedule the item at point.
8376 ARG is passed through to `org-deadline'."
8377 (interactive "P")
8378 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8379 (org-agenda-check-no-diary)
8380 (let* ((marker (or (org-get-at-bol 'org-marker)
8381 (org-agenda-error)))
8382 (buffer (marker-buffer marker))
8383 (pos (marker-position marker))
8384 (org-insert-labeled-timestamps-at-point nil)
8386 (org-with-remote-undo buffer
8387 (with-current-buffer buffer
8388 (widen)
8389 (goto-char pos)
8390 (setq ts (org-deadline arg time)))
8391 (org-agenda-show-new-time marker ts "D"))
8392 (message "Deadline for this item set to %s" ts)))
8394 (defun org-agenda-clock-in (&optional arg)
8395 "Start the clock on the currently selected item."
8396 (interactive "P")
8397 (org-agenda-check-no-diary)
8398 (if (equal arg '(4))
8399 (org-clock-in arg)
8400 (let* ((marker (or (org-get-at-bol 'org-marker)
8401 (org-agenda-error)))
8402 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8403 marker))
8404 (pos (marker-position marker))
8405 newhead)
8406 (org-with-remote-undo (marker-buffer marker)
8407 (with-current-buffer (marker-buffer marker)
8408 (widen)
8409 (goto-char pos)
8410 (org-show-context 'agenda)
8411 (org-show-entry)
8412 (org-cycle-hide-drawers 'children)
8413 (org-clock-in arg)
8414 (setq newhead (org-get-heading)))
8415 (org-agenda-change-all-lines newhead hdmarker)))))
8417 (defun org-agenda-clock-out ()
8418 "Stop the currently running clock."
8419 (interactive)
8420 (unless (marker-buffer org-clock-marker)
8421 (error "No running clock"))
8422 (let ((marker (make-marker)) newhead)
8423 (org-with-remote-undo (marker-buffer org-clock-marker)
8424 (with-current-buffer (marker-buffer org-clock-marker)
8425 (save-excursion
8426 (save-restriction
8427 (widen)
8428 (goto-char org-clock-marker)
8429 (org-back-to-heading t)
8430 (move-marker marker (point))
8431 (org-clock-out)
8432 (setq newhead (org-get-heading))))))
8433 (org-agenda-change-all-lines newhead marker)
8434 (move-marker marker nil)))
8436 (defun org-agenda-clock-cancel (&optional arg)
8437 "Cancel the currently running clock."
8438 (interactive "P")
8439 (unless (marker-buffer org-clock-marker)
8440 (error "No running clock"))
8441 (org-with-remote-undo (marker-buffer org-clock-marker)
8442 (org-clock-cancel)))
8444 (defun org-agenda-clock-goto ()
8445 "Jump to the currently clocked in task within the agenda.
8446 If the currently clocked in task is not listed in the agenda
8447 buffer, display it in another window."
8448 (interactive)
8449 (let (pos)
8450 (mapc (lambda (o)
8451 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8452 (setq pos (overlay-start o))))
8453 (overlays-in (point-min) (point-max)))
8454 (cond (pos (goto-char pos))
8455 ;; If the currently clocked entry is not in the agenda
8456 ;; buffer, we visit it in another window:
8457 (org-clock-current-task
8458 (org-switch-to-buffer-other-window (org-clock-goto)))
8459 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8461 (defun org-agenda-diary-entry-in-org-file ()
8462 "Make a diary entry in the file `org-agenda-diary-file'."
8463 (let (d1 d2 char (text "") dp1 dp2)
8464 (if (equal (buffer-name) "*Calendar*")
8465 (setq d1 (calendar-cursor-to-date t)
8466 d2 (car calendar-mark-ring))
8467 (setq dp1 (get-text-property (point-at-bol) 'day))
8468 (unless dp1 (error "No date defined in current line"))
8469 (setq d1 (calendar-gregorian-from-absolute dp1)
8470 d2 (and (ignore-errors (mark))
8471 (save-excursion
8472 (goto-char (mark))
8473 (setq dp2 (get-text-property (point-at-bol) 'day)))
8474 (calendar-gregorian-from-absolute dp2))))
8475 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8476 (setq char (read-char-exclusive))
8477 (cond
8478 ((equal char ?d)
8479 (setq text (read-string "Day entry: "))
8480 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8481 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8482 ((equal char ?a)
8483 (setq d1 (list (car d1) (nth 1 d1)
8484 (read-number (format "Reference year [%d]: " (nth 2 d1))
8485 (nth 2 d1))))
8486 (setq text (read-string "Anniversary (use %d to show years): "))
8487 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8488 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8489 ((equal char ?b)
8490 (setq text (read-string "Block entry: "))
8491 (unless (and d1 d2 (not (equal d1 d2)))
8492 (error "No block of days selected"))
8493 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8494 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8495 ((equal char ?j)
8496 (org-switch-to-buffer-other-window
8497 (find-file-noselect org-agenda-diary-file))
8498 (require 'org-datetree)
8499 (org-datetree-find-date-create d1)
8500 (org-reveal t))
8501 (t (error "Invalid selection character `%c'" char)))))
8503 (defcustom org-agenda-insert-diary-strategy 'date-tree
8504 "Where in `org-agenda-diary-file' should new entries be added?
8505 Valid values:
8507 date-tree in the date tree, as child of the date
8508 top-level as top-level entries at the end of the file."
8509 :group 'org-agenda
8510 :type '(choice
8511 (const :tag "in a date tree" date-tree)
8512 (const :tag "as top level at end of file" top-level)))
8514 (defcustom org-agenda-insert-diary-extract-time nil
8515 "Non-nil means extract any time specification from the diary entry."
8516 :group 'org-agenda
8517 :version "24.1"
8518 :type 'boolean)
8520 (defcustom org-agenda-bulk-mark-char ">"
8521 "A single-character string to be used as the bulk mark."
8522 :group 'org-agenda
8523 :version "24.1"
8524 :type 'string)
8526 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8527 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8528 If TEXT is not empty, it will become the headline of the new entry, and
8529 the resulting entry will not be shown. When TEXT is empty, switch to
8530 `org-agenda-diary-file' and let the user finish the entry there."
8531 (let ((cw (current-window-configuration)))
8532 (org-switch-to-buffer-other-window
8533 (find-file-noselect org-agenda-diary-file))
8534 (widen)
8535 (goto-char (point-min))
8536 (cond
8537 ((eq type 'anniversary)
8538 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8539 (progn
8540 (or (org-at-heading-p t)
8541 (progn
8542 (outline-next-heading)
8543 (insert "* Anniversaries\n\n")
8544 (beginning-of-line -1)))))
8545 (outline-next-heading)
8546 (org-back-over-empty-lines)
8547 (backward-char 1)
8548 (insert "\n")
8549 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8550 (nth 2 d1) (car d1) (nth 1 d1) text)))
8551 ((eq type 'day)
8552 (let ((org-prefix-has-time t)
8553 (org-agenda-time-leading-zero t)
8554 fmt time time2)
8555 (if org-agenda-insert-diary-extract-time
8556 ;; Use org-agenda-format-item to parse text for a time-range and
8557 ;; remove it. FIXME: This is a hack, we should refactor
8558 ;; that function to make time extraction available separately
8559 (setq fmt (org-agenda-format-item nil text nil nil t)
8560 time (get-text-property 0 'time fmt)
8561 time2 (if (> (length time) 0)
8562 ;; split-string removes trailing ...... if
8563 ;; no end time given. First space
8564 ;; separates time from date.
8565 (concat " " (car (split-string time "\\.")))
8566 nil)
8567 text (get-text-property 0 'txt fmt)))
8568 (if (eq org-agenda-insert-diary-strategy 'top-level)
8569 (org-agenda-insert-diary-as-top-level text)
8570 (require 'org-datetree)
8571 (org-datetree-find-date-create d1)
8572 (org-agenda-insert-diary-make-new-entry text))
8573 (org-insert-time-stamp (org-time-from-absolute
8574 (calendar-absolute-from-gregorian d1))
8575 nil nil nil nil time2))
8576 (end-of-line 0))
8577 ((eq type 'block)
8578 (if (> (calendar-absolute-from-gregorian d1)
8579 (calendar-absolute-from-gregorian d2))
8580 (setq d1 (prog1 d2 (setq d2 d1))))
8581 (if (eq org-agenda-insert-diary-strategy 'top-level)
8582 (org-agenda-insert-diary-as-top-level text)
8583 (require 'org-datetree)
8584 (org-datetree-find-date-create d1)
8585 (org-agenda-insert-diary-make-new-entry text))
8586 (org-insert-time-stamp (org-time-from-absolute
8587 (calendar-absolute-from-gregorian d1)))
8588 (insert "--")
8589 (org-insert-time-stamp (org-time-from-absolute
8590 (calendar-absolute-from-gregorian d2)))
8591 (end-of-line 0)))
8592 (if (string-match "\\S-" text)
8593 (progn
8594 (set-window-configuration cw)
8595 (message "%s entry added to %s"
8596 (capitalize (symbol-name type))
8597 (abbreviate-file-name org-agenda-diary-file)))
8598 (org-reveal t)
8599 (message "Please finish entry here"))))
8601 (defun org-agenda-insert-diary-as-top-level (text)
8602 "Make new entry as a top-level entry at the end of the file.
8603 Add TEXT as headline, and position the cursor in the second line so that
8604 a timestamp can be added there."
8605 (widen)
8606 (goto-char (point-max))
8607 (or (bolp) (insert "\n"))
8608 (insert "* " text "\n")
8609 (if org-adapt-indentation (org-indent-to-column 2)))
8611 (defun org-agenda-insert-diary-make-new-entry (text)
8612 "Make new entry as last child of current entry.
8613 Add TEXT as headline, and position the cursor in the second line so that
8614 a timestamp can be added there."
8615 (let ((org-show-following-heading t)
8616 (org-show-siblings t)
8617 (org-show-hierarchy-above t)
8618 (org-show-entry-below t)
8619 col)
8620 (outline-next-heading)
8621 (org-back-over-empty-lines)
8622 (or (looking-at "[ \t]*$")
8623 (progn (insert "\n") (backward-char 1)))
8624 (org-insert-heading nil t)
8625 (org-do-demote)
8626 (setq col (current-column))
8627 (insert text "\n")
8628 (if org-adapt-indentation (org-indent-to-column col))
8629 (let ((org-show-following-heading t)
8630 (org-show-siblings t)
8631 (org-show-hierarchy-above t)
8632 (org-show-entry-below t))
8633 (org-show-context))))
8635 (defun org-agenda-diary-entry ()
8636 "Make a diary entry, like the `i' command from the calendar.
8637 All the standard commands work: block, weekly etc.
8638 When `org-agenda-diary-file' points to a file,
8639 `org-agenda-diary-entry-in-org-file' is called instead to create
8640 entries in that Org-mode file."
8641 (interactive)
8642 (org-agenda-check-type t 'agenda 'timeline)
8643 (if (not (eq org-agenda-diary-file 'diary-file))
8644 (org-agenda-diary-entry-in-org-file)
8645 (require 'diary-lib)
8646 (let* ((char (progn
8647 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8648 (read-char-exclusive)))
8649 (cmd (cdr (assoc char
8650 '((?d . insert-diary-entry)
8651 (?w . insert-weekly-diary-entry)
8652 (?m . insert-monthly-diary-entry)
8653 (?y . insert-yearly-diary-entry)
8654 (?a . insert-anniversary-diary-entry)
8655 (?b . insert-block-diary-entry)
8656 (?c . insert-cyclic-diary-entry)))))
8657 (oldf (symbol-function 'calendar-cursor-to-date))
8658 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8659 (point (point))
8660 (mark (or (mark t) (point))))
8661 (unless cmd
8662 (error "No command associated with <%c>" char))
8663 (unless (and (get-text-property point 'day)
8664 (or (not (equal ?b char))
8665 (get-text-property mark 'day)))
8666 (error "Don't know which date to use for diary entry"))
8667 ;; We implement this by hacking the `calendar-cursor-to-date' function
8668 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8669 (let ((calendar-mark-ring
8670 (list (calendar-gregorian-from-absolute
8671 (or (get-text-property mark 'day)
8672 (get-text-property point 'day))))))
8673 (unwind-protect
8674 (progn
8675 (fset 'calendar-cursor-to-date
8676 (lambda (&optional error dummy)
8677 (calendar-gregorian-from-absolute
8678 (get-text-property point 'day))))
8679 (call-interactively cmd))
8680 (fset 'calendar-cursor-to-date oldf))))))
8682 (defun org-agenda-execute-calendar-command (cmd)
8683 "Execute a calendar command from the agenda, with the date associated to
8684 the cursor position."
8685 (org-agenda-check-type t 'agenda 'timeline)
8686 (require 'diary-lib)
8687 (unless (get-text-property (point) 'day)
8688 (error "Don't know which date to use for calendar command"))
8689 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8690 (point (point))
8691 (date (calendar-gregorian-from-absolute
8692 (get-text-property point 'day)))
8693 ;; the following 2 vars are needed in the calendar
8694 (displayed-month (car date))
8695 (displayed-year (nth 2 date)))
8696 (unwind-protect
8697 (progn
8698 (fset 'calendar-cursor-to-date
8699 (lambda (&optional error dummy)
8700 (calendar-gregorian-from-absolute
8701 (get-text-property point 'day))))
8702 (call-interactively cmd))
8703 (fset 'calendar-cursor-to-date oldf))))
8705 (defun org-agenda-phases-of-moon ()
8706 "Display the phases of the moon for the 3 months around the cursor date."
8707 (interactive)
8708 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8710 (defun org-agenda-holidays ()
8711 "Display the holidays for the 3 months around the cursor date."
8712 (interactive)
8713 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8715 (defvar calendar-longitude) ; defined in calendar.el
8716 (defvar calendar-latitude) ; defined in calendar.el
8717 (defvar calendar-location-name) ; defined in calendar.el
8719 (defun org-agenda-sunrise-sunset (arg)
8720 "Display sunrise and sunset for the cursor date.
8721 Latitude and longitude can be specified with the variables
8722 `calendar-latitude' and `calendar-longitude'. When called with prefix
8723 argument, latitude and longitude will be prompted for."
8724 (interactive "P")
8725 (require 'solar)
8726 (let ((calendar-longitude (if arg nil calendar-longitude))
8727 (calendar-latitude (if arg nil calendar-latitude))
8728 (calendar-location-name
8729 (if arg "the given coordinates" calendar-location-name)))
8730 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8732 (defun org-agenda-goto-calendar ()
8733 "Open the Emacs calendar with the date at the cursor."
8734 (interactive)
8735 (org-agenda-check-type t 'agenda 'timeline)
8736 (let* ((day (or (get-text-property (point) 'day)
8737 (error "Don't know which date to open in calendar")))
8738 (date (calendar-gregorian-from-absolute day))
8739 (calendar-move-hook nil)
8740 (calendar-view-holidays-initially-flag nil)
8741 (calendar-view-diary-initially-flag nil))
8742 (calendar)
8743 (calendar-goto-date date)))
8745 ;;;###autoload
8746 (defun org-calendar-goto-agenda ()
8747 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8748 This is a command that has to be installed in `calendar-mode-map'."
8749 (interactive)
8750 (org-agenda-list nil (calendar-absolute-from-gregorian
8751 (calendar-cursor-to-date))
8752 nil))
8754 (defun org-agenda-convert-date ()
8755 (interactive)
8756 (org-agenda-check-type t 'agenda 'timeline)
8757 (let ((day (get-text-property (point) 'day))
8758 date s)
8759 (unless day
8760 (error "Don't know which date to convert"))
8761 (setq date (calendar-gregorian-from-absolute day))
8762 (setq s (concat
8763 "Gregorian: " (calendar-date-string date) "\n"
8764 "ISO: " (calendar-iso-date-string date) "\n"
8765 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8766 "Julian: " (calendar-julian-date-string date) "\n"
8767 "Astron. JD: " (calendar-astro-date-string date)
8768 " (Julian date number at noon UTC)\n"
8769 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8770 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8771 "French: " (calendar-french-date-string date) "\n"
8772 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8773 "Mayan: " (calendar-mayan-date-string date) "\n"
8774 "Coptic: " (calendar-coptic-date-string date) "\n"
8775 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8776 "Persian: " (calendar-persian-date-string date) "\n"
8777 "Chinese: " (calendar-chinese-date-string date) "\n"))
8778 (with-output-to-temp-buffer "*Dates*"
8779 (princ s))
8780 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8782 ;;; Bulk commands
8784 (defun org-agenda-bulk-marked-p ()
8785 (eq (get-char-property (point-at-bol) 'type)
8786 'org-marked-entry-overlay))
8788 (defun org-agenda-bulk-mark (&optional arg)
8789 "Mark the entry at point for future bulk action."
8790 (interactive "p")
8791 (dotimes (i (or arg 1))
8792 (unless (org-get-at-bol 'org-agenda-diary-link)
8793 (let* ((m (org-get-at-bol 'org-hd-marker))
8795 (unless (org-agenda-bulk-marked-p)
8796 (unless m (error "Nothing to mark at point"))
8797 (push m org-agenda-bulk-marked-entries)
8798 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8799 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8800 (org-get-todo-face "TODO")
8801 'evaporate)
8802 (overlay-put ov 'type 'org-marked-entry-overlay))
8803 (beginning-of-line 2)
8804 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8805 (beginning-of-line 2))
8806 (message "%d entries marked for bulk action"
8807 (length org-agenda-bulk-marked-entries))))))
8809 (defun org-agenda-bulk-mark-all ()
8810 "Mark all entries for future agenda bulk action."
8811 (interactive)
8812 (org-agenda-bulk-mark-regexp "."))
8814 (defun org-agenda-bulk-mark-regexp (regexp)
8815 "Mark entries matching REGEXP for future agenda bulk action."
8816 (interactive "sMark entries matching regexp: ")
8817 (let ((entries-marked 0))
8818 (save-excursion
8819 (goto-char (point-min))
8820 (goto-char (next-single-property-change (point) 'txt))
8821 (while (re-search-forward regexp nil t)
8822 (when (string-match regexp (get-text-property (point) 'txt))
8823 (setq entries-marked (1+ entries-marked))
8824 (call-interactively 'org-agenda-bulk-mark))))
8825 (if (not entries-marked)
8826 (message "No entry matching this regexp."))))
8828 (defun org-agenda-bulk-unmark (&optional arg)
8829 "Unmark the entry at point for future bulk action."
8830 (interactive "P")
8831 (if arg
8832 (org-agenda-bulk-unmark-all)
8833 (cond ((org-agenda-bulk-marked-p)
8834 (org-agenda-bulk-remove-overlays
8835 (point-at-bol) (+ 2 (point-at-bol)))
8836 (setq org-agenda-bulk-marked-entries
8837 (delete (org-get-at-bol 'org-hd-marker)
8838 org-agenda-bulk-marked-entries))
8839 (beginning-of-line 2)
8840 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8841 (beginning-of-line 2))
8842 (message "%d entries left marked for bulk action"
8843 (length org-agenda-bulk-marked-entries)))
8844 (t (message "No entry to unmark here")))))
8846 (defun org-agenda-bulk-toggle ()
8847 "Toggle marking the entry at point for bulk action."
8848 (interactive)
8849 (if (org-agenda-bulk-marked-p)
8850 (org-agenda-bulk-unmark)
8851 (org-agenda-bulk-mark)))
8853 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8854 "Remove the mark overlays between BEG and END in the agenda buffer.
8855 BEG and END default to the buffer limits.
8857 This only removes the overlays, it does not remove the markers
8858 from the list in `org-agenda-bulk-marked-entries'."
8859 (interactive)
8860 (mapc (lambda (ov)
8861 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8862 (delete-overlay ov)))
8863 (overlays-in (or beg (point-min)) (or end (point-max)))))
8865 (defun org-agenda-bulk-unmark-all ()
8866 "Remove all marks in the agenda buffer.
8867 This will remove the markers and the overlays."
8868 (interactive)
8869 (if (null org-agenda-bulk-marked-entries)
8870 (message "No entry to unmark")
8871 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8872 (setq org-agenda-bulk-marked-entries nil)
8873 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8875 (defcustom org-agenda-persistent-marks nil
8876 "Non-nil means marked items will stay marked after a bulk action.
8877 You can toggle this interactively by typing `p' when prompted for a
8878 bulk action."
8879 :group 'org-agenda
8880 :version "24.1"
8881 :type 'boolean)
8883 (defun org-agenda-bulk-action (&optional arg)
8884 "Execute an remote-editing action on all marked entries.
8885 The prefix arg is passed through to the command if possible."
8886 (interactive "P")
8887 ;; Make sure we have markers, and only valid ones
8888 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8889 (mapc
8890 (lambda (m)
8891 (unless (and (markerp m)
8892 (marker-buffer m)
8893 (buffer-live-p (marker-buffer m))
8894 (marker-position m))
8895 (error "Marker %s for bulk command is invalid" m)))
8896 org-agenda-bulk-marked-entries)
8898 ;; Prompt for the bulk command
8899 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8900 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
8901 "[S]catter [f]unction "
8902 (when org-agenda-bulk-custom-functions
8903 (concat " Custom: ["
8904 (mapconcat (lambda(f) (char-to-string (car f)))
8905 org-agenda-bulk-custom-functions "")
8906 "]"))))
8907 (catch 'exit
8908 (let* ((action (read-char-exclusive))
8909 (org-log-refile (if org-log-refile 'time nil))
8910 (entries (reverse org-agenda-bulk-marked-entries))
8911 (org-overriding-default-time
8912 (if (get-text-property (point) 'org-agenda-date-header)
8913 (org-get-cursor-date)))
8914 redo-at-end
8915 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8916 (cond
8917 ((equal action ?p)
8918 (let ((org-agenda-persistent-marks
8919 (not org-agenda-persistent-marks)))
8920 (org-agenda-bulk-action)
8921 (throw 'exit nil)))
8923 ((equal action ?$)
8924 (setq cmd '(org-agenda-archive)))
8926 ((equal action ?A)
8927 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8929 ((member action '(?r ?w))
8930 (setq rfloc (org-refile-get-location
8931 "Refile to"
8932 (marker-buffer (car entries))
8933 org-refile-allow-creating-parent-nodes))
8934 (if (nth 3 rfloc)
8935 (setcar (nthcdr 3 rfloc)
8936 (move-marker (make-marker) (nth 3 rfloc)
8937 (or (get-file-buffer (nth 1 rfloc))
8938 (find-buffer-visiting (nth 1 rfloc))
8939 (error "This should not happen")))))
8941 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8942 redo-at-end t))
8944 ((equal action ?t)
8945 (setq state (org-icompleting-read
8946 "Todo state: "
8947 (with-current-buffer (marker-buffer (car entries))
8948 (mapcar 'list org-todo-keywords-1))))
8949 (setq cmd `(let ((org-inhibit-blocking t)
8950 (org-inhibit-logging 'note))
8951 (org-agenda-todo ,state))))
8953 ((memq action '(?- ?+))
8954 (setq tag (org-icompleting-read
8955 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8956 (with-current-buffer (marker-buffer (car entries))
8957 (delq nil
8958 (mapcar (lambda (x)
8959 (if (stringp (car x)) x)) org-tag-alist)))))
8960 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8962 ((memq action '(?s ?d))
8963 (let* ((date (unless arg
8964 (or org-overriding-default-time
8965 (org-read-date
8966 nil nil nil
8967 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
8968 nil (format-time-string (car org-time-stamp-formats)
8969 (org-get-cursor-date))))))
8970 (ans (if arg nil org-read-date-final-answer))
8971 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8972 (setq cmd `(let* ((bound (fboundp 'read-string))
8973 (old (and bound (symbol-function 'read-string))))
8974 (unwind-protect
8975 (progn
8976 (fset 'read-string (lambda (&rest ignore) ,ans))
8977 (eval '(,c1 arg)))
8978 (if bound
8979 (fset 'read-string old)
8980 (fmakunbound 'read-string)))))))
8982 ((equal action ?S)
8983 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8984 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8985 (let ((days (read-number
8986 (format "Scatter tasks across how many %sdays: "
8987 (if arg "week" "")) 7)))
8988 (setq cmd
8989 `(let ((distance (1+ (random ,days))))
8990 (if arg
8991 (let ((dist distance)
8992 (day-of-week
8993 (calendar-day-of-week
8994 (calendar-gregorian-from-absolute (org-today)))))
8995 (dotimes (i (1+ dist))
8996 (while (member day-of-week org-agenda-weekend-days)
8997 (incf distance)
8998 (incf day-of-week)
8999 (if (= day-of-week 7)
9000 (setq day-of-week 0)))
9001 (incf day-of-week)
9002 (if (= day-of-week 7)
9003 (setq day-of-week 0)))))
9004 ;; silently fail when try to replan a sexp entry
9005 (condition-case nil
9006 (let* ((date (calendar-gregorian-from-absolute
9007 (+ (org-today) distance)))
9008 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9009 (nth 2 date))))
9010 (org-agenda-schedule nil time))
9011 (error nil)))))))
9013 ((assoc action org-agenda-bulk-custom-functions)
9014 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9015 redo-at-end t))
9017 ((equal action ?f)
9018 (setq cmd (list (intern
9019 (org-icompleting-read "Function: "
9020 obarray 'fboundp t nil nil)))))
9022 (t (error "Invalid bulk action")))
9024 ;; Sort the markers, to make sure that parents are handled before children
9025 (setq entries (sort entries
9026 (lambda (a b)
9027 (cond
9028 ((equal (marker-buffer a) (marker-buffer b))
9029 (< (marker-position a) (marker-position b)))
9031 (string< (buffer-name (marker-buffer a))
9032 (buffer-name (marker-buffer b))))))))
9034 ;; Now loop over all markers and apply cmd
9035 (while (setq e (pop entries))
9036 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9037 (if (not pos)
9038 (progn (message "Skipping removed entry at %s" e)
9039 (setq cntskip (1+ cntskip)))
9040 (goto-char pos)
9041 (let (org-loop-over-headlines-in-active-region)
9042 (eval cmd))
9043 (setq cnt (1+ cnt))))
9044 (when redo-at-end (org-agenda-redo))
9045 (unless org-agenda-persistent-marks
9046 (org-agenda-bulk-unmark-all))
9047 (message "Acted on %d entries%s%s"
9049 (if (= cntskip 0)
9051 (format ", skipped %d (disappeared before their turn)"
9052 cntskip))
9053 (if (not org-agenda-persistent-marks)
9054 "" " (kept marked)"))))))
9056 (defun org-agenda-capture ()
9057 "Call `org-capture' with the date at point."
9058 (interactive)
9059 (if (not (eq major-mode 'org-agenda-mode))
9060 (error "You cannot do this outside of agenda buffers")
9061 (let ((org-overriding-default-time
9062 (org-get-cursor-date)))
9063 (call-interactively 'org-capture))))
9065 ;;; Flagging notes
9067 (defun org-agenda-show-the-flagging-note ()
9068 "Display the flagging note in the other window.
9069 When called a second time in direct sequence, offer to remove the FLAGGING
9070 tag and (if present) the flagging note."
9071 (interactive)
9072 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9073 (win (selected-window))
9074 note heading newhead)
9075 (unless hdmarker
9076 (error "No linked entry at point"))
9077 (if (and (eq this-command last-command)
9078 (y-or-n-p "Unflag and remove any flagging note? "))
9079 (progn
9080 (org-agenda-remove-flag hdmarker)
9081 (let ((win (get-buffer-window "*Flagging Note*")))
9082 (and win (delete-window win)))
9083 (message "Entry unflagged"))
9084 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9085 (unless note
9086 (error "No flagging note"))
9087 (org-kill-new note)
9088 (org-switch-to-buffer-other-window "*Flagging Note*")
9089 (erase-buffer)
9090 (insert note)
9091 (goto-char (point-min))
9092 (while (re-search-forward "\\\\n" nil t)
9093 (replace-match "\n" t t))
9094 (goto-char (point-min))
9095 (select-window win)
9096 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9098 (defun org-agenda-remove-flag (marker)
9099 "Remove the FLAGGED tag and any flagging note in the entry."
9100 (let (newhead)
9101 (org-with-point-at marker
9102 (org-toggle-tag "FLAGGED" 'off)
9103 (org-entry-delete nil "THEFLAGGINGNOTE")
9104 (setq newhead (org-get-heading)))
9105 (org-agenda-change-all-lines newhead marker)
9106 (message "Entry unflagged")))
9108 (defun org-agenda-get-any-marker (&optional pos)
9109 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9110 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9112 ;;; Appointment reminders
9114 (defvar appt-time-msg-list) ; defined in appt.el
9116 ;;;###autoload
9117 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9118 "Activate appointments found in `org-agenda-files'.
9119 With a \\[universal-argument] prefix, refresh the list of
9120 appointments.
9122 If FILTER is t, interactively prompt the user for a regular
9123 expression, and filter out entries that don't match it.
9125 If FILTER is a string, use this string as a regular expression
9126 for filtering entries out.
9128 If FILTER is a function, filter out entries against which
9129 calling the function returns nil. This function takes one
9130 argument: an entry from `org-agenda-get-day-entries'.
9132 FILTER can also be an alist with the car of each cell being
9133 either 'headline or 'category. For example:
9135 '((headline \"IMPORTANT\")
9136 (category \"Work\"))
9138 will only add headlines containing IMPORTANT or headlines
9139 belonging to the \"Work\" category.
9141 ARGS are symbols indicating what kind of entries to consider.
9142 By default `org-agenda-to-appt' will use :deadline, :scheduled
9143 and :timestamp entries. See the docstring of `org-diary' for
9144 details and examples.
9146 If an entry as a APPT_WARNTIME property, its value will be used
9147 to override `appt-message-warning-time'."
9148 (interactive "P")
9149 (if refresh (setq appt-time-msg-list nil))
9150 (if (eq filter t)
9151 (setq filter (read-from-minibuffer "Regexp filter: ")))
9152 (let* ((cnt 0) ; count added events
9153 (scope (or args '(:deadline :scheduled :timestamp)))
9154 (org-agenda-new-buffers nil)
9155 (org-deadline-warning-days 0)
9156 ;; Do not use `org-today' here because appt only takes
9157 ;; time and without date as argument, so it may pass wrong
9158 ;; information otherwise
9159 (today (org-date-to-gregorian
9160 (time-to-days (current-time))))
9161 (org-agenda-restrict nil)
9162 (files (org-agenda-files 'unrestricted)) entries file
9163 (org-agenda-buffer nil))
9164 ;; Get all entries which may contain an appt
9165 (org-agenda-prepare-buffers files)
9166 (while (setq file (pop files))
9167 (setq entries
9168 (delq nil
9169 (append entries
9170 (apply 'org-agenda-get-day-entries
9171 file today scope)))))
9172 ;; Map thru entries and find if we should filter them out
9173 (mapc
9174 (lambda(x)
9175 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9176 (cat (get-text-property 1 'org-category x))
9177 (tod (get-text-property 1 'time-of-day x))
9178 (ok (or (null filter)
9179 (and (stringp filter) (string-match filter evt))
9180 (and (functionp filter) (funcall filter x))
9181 (and (listp filter)
9182 (let ((cat-filter (cadr (assoc 'category filter)))
9183 (evt-filter (cadr (assoc 'headline filter))))
9184 (or (and (stringp cat-filter)
9185 (string-match cat-filter cat))
9186 (and (stringp evt-filter)
9187 (string-match evt-filter evt)))))))
9188 (wrn (get-text-property 1 'warntime x)))
9189 ;; FIXME: Shall we remove text-properties for the appt text?
9190 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9191 (when (and ok tod)
9192 (setq tod (concat "00" (number-to-string tod))
9193 tod (when (string-match
9194 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9195 (concat (match-string 1 tod) ":"
9196 (match-string 2 tod))))
9197 (if (version< emacs-version "23.3")
9198 (appt-add tod evt)
9199 (appt-add tod evt wrn))
9200 (setq cnt (1+ cnt))))) entries)
9201 (org-release-buffers org-agenda-new-buffers)
9202 (if (eq cnt 0)
9203 (message "No event to add")
9204 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9206 (defun org-agenda-todayp (date)
9207 "Does DATE mean today, when considering `org-extend-today-until'?"
9208 (let ((today (org-today))
9209 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9210 date)))
9211 (eq date today)))
9213 (defun org-agenda-todo-yesterday (&optional arg)
9214 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9215 (interactive "P")
9216 (let* ((hour (third (decode-time
9217 (org-current-time))))
9218 (org-extend-today-until (1+ hour)))
9219 (org-agenda-todo arg)))
9221 (provide 'org-agenda)
9223 ;;; org-agenda.el ends here