ox-html: Fix stack overflow in regexp matching
[org-mode.git] / lisp / org-agenda.el
blobefde57050c24409fdcc69ef607bcecf18095ed91
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags do not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
847 "Non-nil means skip scheduled delay when entry also has a deadline.
848 This variable may be set to nil, t, the symbol `post-deadline',
849 or a number which will then give the number of days after the actual
850 scheduled date when the delay should expire. The symbol `post-deadline'
851 eliminates the schedule delay when the date is posterior to the deadline."
852 :group 'org-agenda-skip
853 :group 'org-agenda-daily/weekly
854 :version "24.3"
855 :type '(choice
856 (const :tag "Always honor delay" nil)
857 (const :tag "Ignore delay if posterior to the deadline" post-deadline)
858 (const :tag "Ignore delay if entry has a deadline" t)
859 (integer :tag "Honor delay up until N days after the scheduled date")))
861 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
862 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
863 When non-nil, after the search for timestamps has matched once in an
864 entry, the rest of the entry will not be searched."
865 :group 'org-agenda-skip
866 :type 'boolean)
868 (defcustom org-agenda-skip-timestamp-if-done nil
869 "Non-nil means don't select item by timestamp or -range if it is DONE."
870 :group 'org-agenda-skip
871 :group 'org-agenda-daily/weekly
872 :type 'boolean)
874 (defcustom org-agenda-dim-blocked-tasks nil
875 "Non-nil means dim blocked tasks in the agenda display.
876 This causes some overhead during agenda construction, but if you
877 have turned on `org-enforce-todo-dependencies',
878 `org-enforce-todo-checkbox-dependencies', or any other blocking
879 mechanism, this will create useful feedback in the agenda.
881 Instead of t, this variable can also have the value `invisible'.
882 Then blocked tasks will be invisible and only become visible when
883 they become unblocked. An exemption to this behavior is when a task is
884 blocked because of unchecked checkboxes below it. Since checkboxes do
885 not show up in the agenda views, making this task invisible you remove any
886 trace from agenda views that there is something to do. Therefore, a task
887 that is blocked because of checkboxes will never be made invisible, it
888 will only be dimmed."
889 :group 'org-agenda-daily/weekly
890 :group 'org-agenda-todo-list
891 :version "24.3"
892 :type '(choice
893 (const :tag "Do not dim" nil)
894 (const :tag "Dim to a gray face" t)
895 (const :tag "Make invisible" invisible)))
897 (defcustom org-timeline-show-empty-dates 3
898 "Non-nil means `org-timeline' also shows dates without an entry.
899 When nil, only the days which actually have entries are shown.
900 When t, all days between the first and the last date are shown.
901 When an integer, show also empty dates, but if there is a gap of more than
902 N days, just insert a special line indicating the size of the gap."
903 :group 'org-agenda-skip
904 :type '(choice
905 (const :tag "None" nil)
906 (const :tag "All" t)
907 (integer :tag "at most")))
909 (defgroup org-agenda-startup nil
910 "Options concerning initial settings in the Agenda in Org Mode."
911 :tag "Org Agenda Startup"
912 :group 'org-agenda)
914 (defcustom org-agenda-menu-show-matcher t
915 "Non-nil means show the match string in the agenda dispatcher menu.
916 When nil, the matcher string is not shown, but is put into the help-echo
917 property so than moving the mouse over the command shows it.
918 Setting it to nil is good if matcher strings are very long and/or if
919 you want to use two-columns display (see `org-agenda-menu-two-columns')."
920 :group 'org-agenda
921 :version "24.1"
922 :type 'boolean)
924 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
926 (defcustom org-agenda-menu-two-columns nil
927 "Non-nil means, use two columns to show custom commands in the dispatcher.
928 If you use this, you probably want to set `org-agenda-menu-show-matcher'
929 to nil."
930 :group 'org-agenda
931 :version "24.1"
932 :type 'boolean)
934 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
935 (defcustom org-agenda-finalize-hook nil
936 "Hook run just before displaying an agenda buffer.
937 The buffer is still writable when the hook is called.
939 You can modify some of the buffer substrings but you should be
940 extra careful not to modify the text properties of the agenda
941 headlines as the agenda display heavily relies on them."
942 :group 'org-agenda-startup
943 :type 'hook)
945 (defcustom org-agenda-mouse-1-follows-link nil
946 "Non-nil means mouse-1 on a link will follow the link in the agenda.
947 A longer mouse click will still set point. Does not work on XEmacs.
948 Needs to be set before org.el is loaded."
949 :group 'org-agenda-startup
950 :type 'boolean)
952 (defcustom org-agenda-start-with-follow-mode nil
953 "The initial value of follow mode in a newly created agenda window."
954 :group 'org-agenda-startup
955 :type 'boolean)
957 (defcustom org-agenda-follow-indirect nil
958 "Non-nil means `org-agenda-follow-mode' displays only the
959 current item's tree, in an indirect buffer."
960 :group 'org-agenda
961 :version "24.1"
962 :type 'boolean)
964 (defcustom org-agenda-show-outline-path t
965 "Non-nil means show outline path in echo area after line motion."
966 :group 'org-agenda-startup
967 :type 'boolean)
969 (defcustom org-agenda-start-with-entry-text-mode nil
970 "The initial value of entry-text-mode in a newly created agenda window."
971 :group 'org-agenda-startup
972 :type 'boolean)
974 (defcustom org-agenda-entry-text-maxlines 5
975 "Number of text lines to be added when `E' is pressed in the agenda.
977 Note that this variable only used during agenda display. Add add entry text
978 when exporting the agenda, configure the variable
979 `org-agenda-add-entry-ext-maxlines'."
980 :group 'org-agenda
981 :type 'integer)
983 (defcustom org-agenda-entry-text-exclude-regexps nil
984 "List of regular expressions to clean up entry text.
985 The complete matches of all regular expressions in this list will be
986 removed from entry text before it is shown in the agenda."
987 :group 'org-agenda
988 :type '(repeat (regexp)))
990 (defvar org-agenda-entry-text-cleanup-hook nil
991 "Hook that is run after basic cleanup of entry text to be shown in agenda.
992 This cleanup is done in a temporary buffer, so the function may inspect and
993 change the entire buffer.
994 Some default stuff like drawers and scheduling/deadline dates will already
995 have been removed when this is called, as will any matches for regular
996 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
998 (defvar org-agenda-include-inactive-timestamps nil
999 "Non-nil means include inactive time stamps in agenda and timeline.
1000 Dynamically scoped.")
1002 (defgroup org-agenda-windows nil
1003 "Options concerning the windows used by the Agenda in Org Mode."
1004 :tag "Org Agenda Windows"
1005 :group 'org-agenda)
1007 (defcustom org-agenda-window-setup 'reorganize-frame
1008 "How the agenda buffer should be displayed.
1009 Possible values for this option are:
1011 current-window Show agenda in the current window, keeping all other windows.
1012 other-window Use `switch-to-buffer-other-window' to display agenda.
1013 reorganize-frame Show only two windows on the current frame, the current
1014 window and the agenda.
1015 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1016 Also, when exiting the agenda, kill that frame.
1017 See also the variable `org-agenda-restore-windows-after-quit'."
1018 :group 'org-agenda-windows
1019 :type '(choice
1020 (const current-window)
1021 (const other-frame)
1022 (const other-window)
1023 (const reorganize-frame)))
1025 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1026 "The min and max height of the agenda window as a fraction of frame height.
1027 The value of the variable is a cons cell with two numbers between 0 and 1.
1028 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1029 :group 'org-agenda-windows
1030 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1032 (defcustom org-agenda-restore-windows-after-quit nil
1033 "Non-nil means restore window configuration upon exiting agenda.
1034 Before the window configuration is changed for displaying the agenda,
1035 the current status is recorded. When the agenda is exited with
1036 `q' or `x' and this option is set, the old state is restored. If
1037 `org-agenda-window-setup' is `other-frame', the value of this
1038 option will be ignored."
1039 :group 'org-agenda-windows
1040 :type 'boolean)
1042 (defcustom org-agenda-ndays nil
1043 "Number of days to include in overview display.
1044 Should be 1 or 7.
1045 Obsolete, see `org-agenda-span'."
1046 :group 'org-agenda-daily/weekly
1047 :type 'integer)
1049 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1051 (defcustom org-agenda-span 'week
1052 "Number of days to include in overview display.
1053 Can be day, week, month, year, or any number of days.
1054 Custom commands can set this variable in the options section."
1055 :group 'org-agenda-daily/weekly
1056 :type '(choice (const :tag "Day" day)
1057 (const :tag "Week" week)
1058 (const :tag "Month" month)
1059 (const :tag "Year" year)
1060 (integer :tag "Custom")))
1062 (defcustom org-agenda-start-on-weekday 1
1063 "Non-nil means start the overview always on the specified weekday.
1064 0 denotes Sunday, 1 denotes Monday etc.
1065 When nil, always start on the current day.
1066 Custom commands can set this variable in the options section."
1067 :group 'org-agenda-daily/weekly
1068 :type '(choice (const :tag "Today" nil)
1069 (integer :tag "Weekday No.")))
1071 (defcustom org-agenda-show-all-dates t
1072 "Non-nil means `org-agenda' shows every day in the selected range.
1073 When nil, only the days which actually have entries are shown."
1074 :group 'org-agenda-daily/weekly
1075 :type 'boolean)
1077 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1078 "Format string for displaying dates in the agenda.
1079 Used by the daily/weekly agenda and by the timeline. This should be
1080 a format string understood by `format-time-string', or a function returning
1081 the formatted date as a string. The function must take a single argument,
1082 a calendar-style date list like (month day year)."
1083 :group 'org-agenda-daily/weekly
1084 :type '(choice
1085 (string :tag "Format string")
1086 (function :tag "Function")))
1088 (defun org-agenda-format-date-aligned (date)
1089 "Format a date string for display in the daily/weekly agenda, or timeline.
1090 This function makes sure that dates are aligned for easy reading."
1091 (require 'cal-iso)
1092 (let* ((dayname (calendar-day-name date))
1093 (day (cadr date))
1094 (day-of-week (calendar-day-of-week date))
1095 (month (car date))
1096 (monthname (calendar-month-name month))
1097 (year (nth 2 date))
1098 (iso-week (org-days-to-iso-week
1099 (calendar-absolute-from-gregorian date)))
1100 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1101 (1- year))
1102 ((and (= month 12) (<= iso-week 1))
1103 (1+ year))
1104 (t year)))
1105 (weekstring (if (= day-of-week 1)
1106 (format " W%02d" iso-week)
1107 "")))
1108 (format "%-10s %2d %s %4d%s"
1109 dayname day monthname year weekstring)))
1111 (defcustom org-agenda-time-leading-zero nil
1112 "Non-nil means use leading zero for military times in agenda.
1113 For example, 9:30am would become 09:30 rather than 9:30."
1114 :group 'org-agenda-daily/weekly
1115 :version "24.1"
1116 :type 'boolean)
1118 (defcustom org-agenda-timegrid-use-ampm nil
1119 "When set, show AM/PM style timestamps on the timegrid."
1120 :group 'org-agenda
1121 :version "24.1"
1122 :type 'boolean)
1124 (defun org-agenda-time-of-day-to-ampm (time)
1125 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1126 (let* ((hour-number (string-to-number (substring time 0 -3)))
1127 (minute (substring time -2))
1128 (ampm "am"))
1129 (cond
1130 ((equal hour-number 12)
1131 (setq ampm "pm"))
1132 ((> hour-number 12)
1133 (setq ampm "pm")
1134 (setq hour-number (- hour-number 12))))
1135 (concat
1136 (if org-agenda-time-leading-zero
1137 (format "%02d" hour-number)
1138 (format "%02s" (number-to-string hour-number)))
1139 ":" minute ampm)))
1141 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1142 "Conditionally convert TIME to AM/PM format
1143 based on `org-agenda-timegrid-use-ampm'"
1144 (if org-agenda-timegrid-use-ampm
1145 (org-agenda-time-of-day-to-ampm time)
1146 time))
1148 (defcustom org-agenda-weekend-days '(6 0)
1149 "Which days are weekend?
1150 These days get the special face `org-agenda-date-weekend' in the agenda
1151 and timeline buffers."
1152 :group 'org-agenda-daily/weekly
1153 :type '(set :greedy t
1154 (const :tag "Monday" 1)
1155 (const :tag "Tuesday" 2)
1156 (const :tag "Wednesday" 3)
1157 (const :tag "Thursday" 4)
1158 (const :tag "Friday" 5)
1159 (const :tag "Saturday" 6)
1160 (const :tag "Sunday" 0)))
1162 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1163 "Non-nil means jump to today when moving a past date forward in time.
1164 When using S-right in the agenda to move a a date forward, and the date
1165 stamp currently points to the past, the first key press will move it
1166 to today. WHen nil, just move one day forward even if the date stays
1167 in the past."
1168 :group 'org-agenda-daily/weekly
1169 :version "24.1"
1170 :type 'boolean)
1172 (defcustom org-agenda-include-diary nil
1173 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1174 Custom commands can set this variable in the options section."
1175 :group 'org-agenda-daily/weekly
1176 :type 'boolean)
1178 (defcustom org-agenda-include-deadlines t
1179 "If non-nil, include entries within their deadline warning period.
1180 Custom commands can set this variable in the options section."
1181 :group 'org-agenda-daily/weekly
1182 :version "24.1"
1183 :type 'boolean)
1185 (defcustom org-agenda-repeating-timestamp-show-all t
1186 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1187 When set to a list of strings, only show occurrences of repeating
1188 stamps for these TODO keywords. When nil, only one occurrence is
1189 shown, either today or the nearest into the future."
1190 :group 'org-agenda-daily/weekly
1191 :type '(choice
1192 (const :tag "Show repeating stamps" t)
1193 (repeat :tag "Show repeating stamps for these TODO keywords"
1194 (string :tag "TODO Keyword"))
1195 (const :tag "Don't show repeating stamps" nil)))
1197 (defcustom org-scheduled-past-days 10000
1198 "No. of days to continue listing scheduled items that are not marked DONE.
1199 When an item is scheduled on a date, it shows up in the agenda on this
1200 day and will be listed until it is marked done for the number of days
1201 given here."
1202 :group 'org-agenda-daily/weekly
1203 :type 'integer)
1205 (defcustom org-agenda-log-mode-items '(closed clock)
1206 "List of items that should be shown in agenda log mode.
1207 This list may contain the following symbols:
1209 closed Show entries that have been closed on that day.
1210 clock Show entries that have received clocked time on that day.
1211 state Show all logged state changes.
1212 Note that instead of changing this variable, you can also press `C-u l' in
1213 the agenda to display all available LOG items temporarily."
1214 :group 'org-agenda-daily/weekly
1215 :type '(set :greedy t (const closed) (const clock) (const state)))
1217 (defcustom org-agenda-clock-consistency-checks
1218 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1219 :gap-ok-around ("4:00")
1220 :default-face ((:background "DarkRed") (:foreground "white"))
1221 :overlap-face nil :gap-face nil :no-end-time-face nil
1222 :long-face nil :short-face nil)
1223 "This is a property list, with the following keys:
1225 :max-duration Mark clocking chunks that are longer than this time.
1226 This is a time string like \"HH:MM\", or the number
1227 of minutes as an integer.
1229 :min-duration Mark clocking chunks that are shorter that this.
1230 This is a time string like \"HH:MM\", or the number
1231 of minutes as an integer.
1233 :max-gap Mark gaps between clocking chunks that are longer than
1234 this duration. A number of minutes, or a string
1235 like \"HH:MM\".
1237 :gap-ok-around List of times during the day which are usually not working
1238 times. When a gap is detected, but the gap contains any
1239 of these times, the gap is *not* reported. For example,
1240 if this is (\"4:00\" \"13:00\") then gaps that contain
1241 4:00 in the morning (i.e. the night) and 13:00
1242 (i.e. a typical lunch time) do not cause a warning.
1243 You should have at least one time during the night in this
1244 list, or otherwise the first task each morning will trigger
1245 a warning because it follows a long gap.
1247 Furthermore, the following properties can be used to define faces for
1248 issue display.
1250 :default-face the default face, if the specific face is undefined
1251 :overlap-face face for overlapping clocks
1252 :gap-face face for gaps between clocks
1253 :no-end-time-face face for incomplete clocks
1254 :long-face face for clock intervals that are too long
1255 :short-face face for clock intervals that are too short"
1256 :group 'org-agenda-daily/weekly
1257 :group 'org-clock
1258 :version "24.1"
1259 :type 'plist)
1261 (defcustom org-agenda-log-mode-add-notes t
1262 "Non-nil means add first line of notes to log entries in agenda views.
1263 If a log item like a state change or a clock entry is associated with
1264 notes, the first line of these notes will be added to the entry in the
1265 agenda display."
1266 :group 'org-agenda-daily/weekly
1267 :type 'boolean)
1269 (defcustom org-agenda-start-with-log-mode nil
1270 "The initial value of log-mode in a newly created agenda window.
1271 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1272 explanations on the possible values."
1273 :group 'org-agenda-startup
1274 :group 'org-agenda-daily/weekly
1275 :type '(choice (const :tag "Don't show log items" nil)
1276 (const :tag "Show only log items" 'only)
1277 (const :tag "Show all possible log items" 'clockcheck)
1278 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1279 (choice (const :tag "Show closed log items" 'closed)
1280 (const :tag "Show clocked log items" 'clock)
1281 (const :tag "Show all logged state changes" 'state)))))
1283 (defcustom org-agenda-start-with-clockreport-mode nil
1284 "The initial value of clockreport-mode in a newly created agenda window."
1285 :group 'org-agenda-startup
1286 :group 'org-agenda-daily/weekly
1287 :type 'boolean)
1289 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1290 "Property list with parameters for the clocktable in clockreport mode.
1291 This is the display mode that shows a clock table in the daily/weekly
1292 agenda, the properties for this dynamic block can be set here.
1293 The usual clocktable parameters are allowed here, but you cannot set
1294 the properties :name, :tstart, :tend, :block, and :scope - these will
1295 be overwritten to make sure the content accurately reflects the
1296 current display in the agenda."
1297 :group 'org-agenda-daily/weekly
1298 :type 'plist)
1300 (defcustom org-agenda-search-view-always-boolean nil
1301 "Non-nil means the search string is interpreted as individual parts.
1303 The search string for search view can either be interpreted as a phrase,
1304 or as a list of snippets that define a boolean search for a number of
1305 strings.
1307 When this is non-nil, the string will be split on whitespace, and each
1308 snippet will be searched individually, and all must match in order to
1309 select an entry. A snippet is then a single string of non-white
1310 characters, or a string in double quotes, or a regexp in {} braces.
1311 If a snippet is preceded by \"-\", the snippet must *not* match.
1312 \"+\" is syntactic sugar for positive selection. Each snippet may
1313 be found as a full word or a partial word, but see the variable
1314 `org-agenda-search-view-force-full-words'.
1316 When this is nil, search will look for the entire search phrase as one,
1317 with each space character matching any amount of whitespace, including
1318 line breaks.
1320 Even when this is nil, you can still switch to Boolean search dynamically
1321 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1322 is a regexp marked with braces like \"{abc}\", this will also switch to
1323 boolean search."
1324 :group 'org-agenda-search-view
1325 :version "24.1"
1326 :type 'boolean)
1328 (if (fboundp 'defvaralias)
1329 (defvaralias 'org-agenda-search-view-search-words-only
1330 'org-agenda-search-view-always-boolean))
1332 (defcustom org-agenda-search-view-force-full-words nil
1333 "Non-nil means, search words must be matches as complete words.
1334 When nil, they may also match part of a word."
1335 :group 'org-agenda-search-view
1336 :version "24.1"
1337 :type 'boolean)
1339 (defcustom org-agenda-search-view-max-outline-level nil
1340 "Maximum outline level to display in search view.
1341 E.g. when this is set to 1, the search view will only
1342 show headlines of level 1."
1343 :group 'org-agenda-search-view
1344 :version "24.3"
1345 :type 'integer)
1347 (defgroup org-agenda-time-grid nil
1348 "Options concerning the time grid in the Org-mode Agenda."
1349 :tag "Org Agenda Time Grid"
1350 :group 'org-agenda)
1352 (defcustom org-agenda-search-headline-for-time t
1353 "Non-nil means search headline for a time-of-day.
1354 If the headline contains a time-of-day in one format or another, it will
1355 be used to sort the entry into the time sequence of items for a day.
1356 Some people have time stamps in the headline that refer to the creation
1357 time or so, and then this produces an unwanted side effect. If this is
1358 the case for your, use this variable to turn off searching the headline
1359 for a time."
1360 :group 'org-agenda-time-grid
1361 :type 'boolean)
1363 (defcustom org-agenda-use-time-grid t
1364 "Non-nil means show a time grid in the agenda schedule.
1365 A time grid is a set of lines for specific times (like every two hours between
1366 8:00 and 20:00). The items scheduled for a day at specific times are
1367 sorted in between these lines.
1368 For details about when the grid will be shown, and what it will look like, see
1369 the variable `org-agenda-time-grid'."
1370 :group 'org-agenda-time-grid
1371 :type 'boolean)
1373 (defcustom org-agenda-time-grid
1374 '((daily today require-timed)
1375 "----------------"
1376 (800 1000 1200 1400 1600 1800 2000))
1378 "The settings for time grid for agenda display.
1379 This is a list of three items. The first item is again a list. It contains
1380 symbols specifying conditions when the grid should be displayed:
1382 daily if the agenda shows a single day
1383 weekly if the agenda shows an entire week
1384 today show grid on current date, independent of daily/weekly display
1385 require-timed show grid only if at least one item has a time specification
1387 The second item is a string which will be placed behind the grid time.
1389 The third item is a list of integers, indicating the times that should have
1390 a grid line."
1391 :group 'org-agenda-time-grid
1392 :type
1393 '(list
1394 (set :greedy t :tag "Grid Display Options"
1395 (const :tag "Show grid in single day agenda display" daily)
1396 (const :tag "Show grid in weekly agenda display" weekly)
1397 (const :tag "Always show grid for today" today)
1398 (const :tag "Show grid only if any timed entries are present"
1399 require-timed)
1400 (const :tag "Skip grid times already present in an entry"
1401 remove-match))
1402 (string :tag "Grid String")
1403 (repeat :tag "Grid Times" (integer :tag "Time"))))
1405 (defcustom org-agenda-show-current-time-in-grid t
1406 "Non-nil means show the current time in the time grid."
1407 :group 'org-agenda-time-grid
1408 :version "24.1"
1409 :type 'boolean)
1411 (defcustom org-agenda-current-time-string
1412 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1413 "The string for the current time marker in the agenda."
1414 :group 'org-agenda-time-grid
1415 :version "24.1"
1416 :type 'string)
1418 (defgroup org-agenda-sorting nil
1419 "Options concerning sorting in the Org-mode Agenda."
1420 :tag "Org Agenda Sorting"
1421 :group 'org-agenda)
1423 (defcustom org-agenda-sorting-strategy
1424 '((agenda habit-down time-up priority-down category-keep)
1425 (todo priority-down category-keep)
1426 (tags priority-down category-keep)
1427 (search category-keep))
1428 "Sorting structure for the agenda items of a single day.
1429 This is a list of symbols which will be used in sequence to determine
1430 if an entry should be listed before another entry. The following
1431 symbols are recognized:
1433 time-up Put entries with time-of-day indications first, early first
1434 time-down Put entries with time-of-day indications first, late first
1435 timestamp-up Sort by any timestamp, early first
1436 timestamp-down Sort by any timestamp, late first
1437 scheduled-up Sort by scheduled timestamp, early first
1438 scheduled-down Sort by scheduled timestamp, late first
1439 deadline-up Sort by deadline timestamp, early first
1440 deadline-down Sort by deadline timestamp, late first
1441 ts-up Sort by active timestamp, early first
1442 ts-down Sort by active timestamp, late first
1443 tsia-up Sort by inactive timestamp, early first
1444 tsia-down Sort by inactive timestamp, late first
1445 category-keep Keep the default order of categories, corresponding to the
1446 sequence in `org-agenda-files'.
1447 category-up Sort alphabetically by category, A-Z.
1448 category-down Sort alphabetically by category, Z-A.
1449 tag-up Sort alphabetically by last tag, A-Z.
1450 tag-down Sort alphabetically by last tag, Z-A.
1451 priority-up Sort numerically by priority, high priority last.
1452 priority-down Sort numerically by priority, high priority first.
1453 todo-state-up Sort by todo state, tasks that are done last.
1454 todo-state-down Sort by todo state, tasks that are done first.
1455 effort-up Sort numerically by estimated effort, high effort last.
1456 effort-down Sort numerically by estimated effort, high effort first.
1457 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1458 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1459 habit-up Put entries that are habits first
1460 habit-down Put entries that are habits last
1461 alpha-up Sort headlines alphabetically
1462 alpha-down Sort headlines alphabetically, reversed
1464 The different possibilities will be tried in sequence, and testing stops
1465 if one comparison returns a \"not-equal\". For example, the default
1466 '(time-up category-keep priority-down)
1467 means: Pull out all entries having a specified time of day and sort them,
1468 in order to make a time schedule for the current day the first thing in the
1469 agenda listing for the day. Of the entries without a time indication, keep
1470 the grouped in categories, don't sort the categories, but keep them in
1471 the sequence given in `org-agenda-files'. Within each category sort by
1472 priority.
1474 Leaving out `category-keep' would mean that items will be sorted across
1475 categories by priority.
1477 Instead of a single list, this can also be a set of list for specific
1478 contents, with a context symbol in the car of the list, any of
1479 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1481 Custom commands can bind this variable in the options section."
1482 :group 'org-agenda-sorting
1483 :type `(choice
1484 (repeat :tag "General" ,org-sorting-choice)
1485 (list :tag "Individually"
1486 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1487 (repeat ,org-sorting-choice))
1488 (cons (const :tag "Strategy for TODO lists" todo)
1489 (repeat ,org-sorting-choice))
1490 (cons (const :tag "Strategy for Tags matches" tags)
1491 (repeat ,org-sorting-choice))
1492 (cons (const :tag "Strategy for search matches" search)
1493 (repeat ,org-sorting-choice)))))
1495 (defcustom org-agenda-cmp-user-defined nil
1496 "A function to define the comparison `user-defined'.
1497 This function must receive two arguments, agenda entry a and b.
1498 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1499 the user comparison, return nil.
1500 When this is defined, you can make `user-defined-up' and `user-defined-down'
1501 part of an agenda sorting strategy."
1502 :group 'org-agenda-sorting
1503 :type 'symbol)
1505 (defcustom org-sort-agenda-notime-is-late t
1506 "Non-nil means items without time are considered late.
1507 This is only relevant for sorting. When t, items which have no explicit
1508 time like 15:30 will be considered as 99:01, i.e. later than any items which
1509 do have a time. When nil, the default time is before 0:00. You can use this
1510 option to decide if the schedule for today should come before or after timeless
1511 agenda entries."
1512 :group 'org-agenda-sorting
1513 :type 'boolean)
1515 (defcustom org-sort-agenda-noeffort-is-high t
1516 "Non-nil means items without effort estimate are sorted as high effort.
1517 This also applies when filtering an agenda view with respect to the
1518 < or > effort operator. Then, tasks with no effort defined will be treated
1519 as tasks with high effort.
1520 When nil, such items are sorted as 0 minutes effort."
1521 :group 'org-agenda-sorting
1522 :type 'boolean)
1524 (defgroup org-agenda-line-format nil
1525 "Options concerning the entry prefix in the Org-mode agenda display."
1526 :tag "Org Agenda Line Format"
1527 :group 'org-agenda)
1529 (defcustom org-agenda-prefix-format
1530 '((agenda . " %i %-12:c%?-12t% s")
1531 (timeline . " % s")
1532 (todo . " %i %-12:c")
1533 (tags . " %i %-12:c")
1534 (search . " %i %-12:c"))
1535 "Format specifications for the prefix of items in the agenda views.
1536 An alist with five entries, each for the different agenda types. The
1537 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1538 The values are format strings.
1540 This format works similar to a printf format, with the following meaning:
1542 %c the category of the item, \"Diary\" for entries from the diary,
1543 or as given by the CATEGORY keyword or derived from the file name
1544 %e the effort required by the item
1545 %l the level of the item (insert X space(s) if item is of level X)
1546 %i the icon category of the item, see `org-agenda-category-icon-alist'
1547 %T the last tag of the item (ignore inherited tags, which come first)
1548 %t the HH:MM time-of-day specification if one applies to the entry
1549 %s Scheduling/Deadline information, a short string
1550 %b show breadcrumbs, i.e., the names of the higher levels
1551 %(expression) Eval EXPRESSION and replace the control string
1552 by the result
1554 All specifiers work basically like the standard `%s' of printf, but may
1555 contain two additional characters: a question mark just after the `%'
1556 and a whitespace/punctuation character just before the final letter.
1558 If the first character after `%' is a question mark, the entire field
1559 will only be included if the corresponding value applies to the current
1560 entry. This is useful for fields which should have fixed width when
1561 present, but zero width when absent. For example, \"%?-12t\" will
1562 result in a 12 character time field if a time of the day is specified,
1563 but will completely disappear in entries which do not contain a time.
1565 If there is punctuation or whitespace character just before the
1566 final format letter, this character will be appended to the field
1567 value if the value is not empty. For example, the format
1568 \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
1569 the category is empty, no additional colon is inserted.
1571 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1572 which means:
1574 - Indent the line with two space characters
1575 - Give the category a 12 chars wide field, padded with whitespace on
1576 the right (because of `-'). Append a colon if there is a category
1577 (because of `:').
1578 - If there is a time-of-day, put it into a 12 chars wide field. If no
1579 time, don't put in an empty field, just skip it (because of '?').
1580 - Finally, put the scheduling information.
1582 See also the variables `org-agenda-remove-times-when-in-prefix' and
1583 `org-agenda-remove-tags'.
1585 Custom commands can set this variable in the options section."
1586 :type '(choice
1587 (string :tag "General format")
1588 (list :greedy t :tag "View dependent"
1589 (cons (const agenda) (string :tag "Format"))
1590 (cons (const timeline) (string :tag "Format"))
1591 (cons (const todo) (string :tag "Format"))
1592 (cons (const tags) (string :tag "Format"))
1593 (cons (const search) (string :tag "Format"))))
1594 :group 'org-agenda-line-format)
1596 (defvar org-prefix-format-compiled nil
1597 "The compiled prefix format and associated variables.
1598 This is a list where first element is a list of variable bindings, and second
1599 element is the compiled format expression. See the variable
1600 `org-agenda-prefix-format'.")
1602 (defcustom org-agenda-todo-keyword-format "%-1s"
1603 "Format for the TODO keyword in agenda lines.
1604 Set this to something like \"%-12s\" if you want all TODO keywords
1605 to occupy a fixed space in the agenda display."
1606 :group 'org-agenda-line-format
1607 :type 'string)
1609 (defcustom org-agenda-diary-sexp-prefix nil
1610 "A regexp that matches part of a diary sexp entry
1611 which should be treated as scheduling/deadline information in
1612 `org-agenda'.
1614 For example, you can use this to extract the `diary-remind-message' from
1615 `diary-remind' entries."
1616 :group 'org-agenda-line-format
1617 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1619 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1620 "Text preceding timerange entries in the agenda view.
1621 This is a list with two strings. The first applies when the range
1622 is entirely on one day. The second applies if the range spans several days.
1623 The strings may have two \"%d\" format specifiers which will be filled
1624 with the sequence number of the days, and the total number of days in the
1625 range, respectively."
1626 :group 'org-agenda-line-format
1627 :type '(list
1628 (string :tag "Deadline today ")
1629 (choice :tag "Deadline relative"
1630 (string :tag "Format string")
1631 (function))))
1633 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1634 "Text preceding scheduled items in the agenda view.
1635 This is a list with two strings. The first applies when the item is
1636 scheduled on the current day. The second applies when it has been scheduled
1637 previously, it may contain a %d indicating that this is the nth time that
1638 this item is scheduled, due to automatic rescheduling of unfinished items
1639 for the following day. So this number is one larger than the number of days
1640 that passed since this item was scheduled first."
1641 :group 'org-agenda-line-format
1642 :type '(list
1643 (string :tag "Scheduled today ")
1644 (string :tag "Scheduled previously")))
1646 (defcustom org-agenda-inactive-leader "["
1647 "Text preceding item pulled into the agenda by inactive time stamps.
1648 These entries are added to the agenda when pressing \"[\"."
1649 :group 'org-agenda-line-format
1650 :version "24.1"
1651 :type '(list
1652 (string :tag "Scheduled today ")
1653 (string :tag "Scheduled previously")))
1655 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1656 "Text preceding deadline items in the agenda view.
1657 This is a list with two strings. The first applies when the item has its
1658 deadline on the current day. The second applies when it is in the past or
1659 in the future, it may contain %d to capture how many days away the deadline
1660 is (was)."
1661 :group 'org-agenda-line-format
1662 :type '(list
1663 (string :tag "Deadline today ")
1664 (choice :tag "Deadline relative"
1665 (string :tag "Format string")
1666 (function))))
1668 (defcustom org-agenda-remove-times-when-in-prefix t
1669 "Non-nil means remove duplicate time specifications in agenda items.
1670 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1671 time-of-day specification in a headline or diary entry is extracted and
1672 placed into the prefix. If this option is non-nil, the original specification
1673 \(a timestamp or -range, or just a plain time(range) specification like
1674 11:30-4pm) will be removed for agenda display. This makes the agenda less
1675 cluttered.
1676 The option can be t or nil. It may also be the symbol `beg', indicating
1677 that the time should only be removed when it is located at the beginning of
1678 the headline/diary entry."
1679 :group 'org-agenda-line-format
1680 :type '(choice
1681 (const :tag "Always" t)
1682 (const :tag "Never" nil)
1683 (const :tag "When at beginning of entry" beg)))
1685 (defcustom org-agenda-remove-timeranges-from-blocks nil
1686 "Non-nil means remove time ranges specifications in agenda
1687 items that span on several days."
1688 :group 'org-agenda-line-format
1689 :version "24.1"
1690 :type 'boolean)
1692 (defcustom org-agenda-default-appointment-duration nil
1693 "Default duration for appointments that only have a starting time.
1694 When nil, no duration is specified in such cases.
1695 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1696 :group 'org-agenda-line-format
1697 :type '(choice
1698 (integer :tag "Minutes")
1699 (const :tag "No default duration")))
1701 (defcustom org-agenda-show-inherited-tags t
1702 "Non-nil means show inherited tags in each agenda line.
1704 When this option is set to 'always, it take precedences over
1705 `org-agenda-use-tag-inheritance' and inherited tags are shown
1706 in every agenda.
1708 When this option is set to t (the default), inherited tags are
1709 shown when they are available, i.e. when the value of
1710 `org-agenda-use-tag-inheritance' has been taken into account.
1712 This can be set to a list of agenda types in which the agenda
1713 must display the inherited tags. Available types are 'todo,
1714 'agenda, 'search and 'timeline.
1716 When set to nil, never show inherited tags in agenda lines."
1717 :group 'org-agenda-line-format
1718 :group 'org-agenda
1719 :version "24.3"
1720 :type '(choice
1721 (const :tag "Show inherited tags when available" t)
1722 (const :tag "Always show inherited tags" 'always)
1723 (repeat :tag "Show inherited tags only in selected agenda types"
1724 (symbol :tag "Agenda type"))))
1726 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1727 "List of agenda view types where to use tag inheritance.
1729 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1730 controlled by `org-use-tag-inheritance'. In other agenda types,
1731 `org-use-tag-inheritance' is not used for the selection of the
1732 agenda entries. Still, you may want the agenda to be aware of
1733 the inherited tags anyway, e.g. for later tag filtering.
1735 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1737 This variable has no effect if `org-agenda-show-inherited-tags'
1738 is set to 'always. In that case, the agenda is aware of those
1739 tags.
1741 The default value sets tags in every agenda type. Setting this
1742 option to nil will speed up non-tags agenda view a lot."
1743 :group 'org-agenda
1744 :version "24.3"
1745 :type '(choice
1746 (const :tag "Use tag inheritance in all agenda types" t)
1747 (repeat :tag "Use tag inheritance in selected agenda types"
1748 (symbol :tag "Agenda type"))))
1750 (defcustom org-agenda-hide-tags-regexp nil
1751 "Regular expression used to filter away specific tags in agenda views.
1752 This means that these tags will be present, but not be shown in the agenda
1753 line. Secondary filtering will still work on the hidden tags.
1754 Nil means don't hide any tags."
1755 :group 'org-agenda-line-format
1756 :type '(choice
1757 (const :tag "Hide none" nil)
1758 (string :tag "Regexp ")))
1760 (defcustom org-agenda-remove-tags nil
1761 "Non-nil means remove the tags from the headline copy in the agenda.
1762 When this is the symbol `prefix', only remove tags when
1763 `org-agenda-prefix-format' contains a `%T' specifier."
1764 :group 'org-agenda-line-format
1765 :type '(choice
1766 (const :tag "Always" t)
1767 (const :tag "Never" nil)
1768 (const :tag "When prefix format contains %T" prefix)))
1770 (if (fboundp 'defvaralias)
1771 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1772 'org-agenda-remove-tags))
1774 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1775 "Shift tags in agenda items to this column.
1776 If this number is positive, it specifies the column. If it is negative,
1777 it means that the tags should be flushright to that column. For example,
1778 -80 works well for a normal 80 character screen."
1779 :group 'org-agenda-line-format
1780 :type 'integer)
1782 (if (fboundp 'defvaralias)
1783 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1785 (defcustom org-agenda-fontify-priorities 'cookies
1786 "Non-nil means highlight low and high priorities in agenda.
1787 When t, the highest priority entries are bold, lowest priority italic.
1788 However, settings in `org-priority-faces' will overrule these faces.
1789 When this variable is the symbol `cookies', only fontify the
1790 cookies, not the entire task.
1791 This may also be an association list of priority faces, whose
1792 keys are the character values of `org-highest-priority',
1793 `org-default-priority', and `org-lowest-priority' (the default values
1794 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1795 color as a string, or a list like `(:background \"Red\")'.
1796 If it is a color, the variable `org-faces-easy-properties'
1797 determines if it is a foreground or a background color."
1798 :group 'org-agenda-line-format
1799 :type '(choice
1800 (const :tag "Never" nil)
1801 (const :tag "Defaults" t)
1802 (const :tag "Cookies only" cookies)
1803 (repeat :tag "Specify"
1804 (list (character :tag "Priority" :value ?A)
1805 (choice :tag "Face "
1806 (string :tag "Color")
1807 (sexp :tag "Face"))))))
1809 (defcustom org-agenda-day-face-function nil
1810 "Function called to determine what face should be used to display a day.
1811 The only argument passed to that function is the day. It should
1812 returns a face, or nil if does not want to specify a face and let
1813 the normal rules apply."
1814 :group 'org-agenda-line-format
1815 :version "24.1"
1816 :type 'function)
1818 (defcustom org-agenda-category-icon-alist nil
1819 "Alist of category icon to be displayed in agenda views.
1821 Each entry should have the following format:
1823 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1825 Where CATEGORY-REGEXP is a regexp matching the categories where
1826 the icon should be displayed.
1827 FILE-OR-DATA either a file path or a string containing image data.
1829 The other fields can be omitted safely if not needed:
1830 TYPE indicates the image type.
1831 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1832 image data.
1833 PROPS are additional image attributes to assign to the image,
1834 like, e.g. `:ascent center'.
1836 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1838 If you want to set the display properties yourself, just put a
1839 list as second element:
1841 (CATEGORY-REGEXP (MY PROPERTY LIST))
1843 For example, to display a 16px horizontal space for Emacs
1844 category, you can use:
1846 (\"Emacs\" '(space . (:width (16))))"
1847 :group 'org-agenda-line-format
1848 :version "24.1"
1849 :type '(alist :key-type (string :tag "Regexp matching category")
1850 :value-type (choice (list :tag "Icon"
1851 (string :tag "File or data")
1852 (symbol :tag "Type")
1853 (boolean :tag "Data?")
1854 (repeat :tag "Extra image properties" :inline t symbol))
1855 (list :tag "Display properties" sexp))))
1857 (defgroup org-agenda-column-view nil
1858 "Options concerning column view in the agenda."
1859 :tag "Org Agenda Column View"
1860 :group 'org-agenda)
1862 (defcustom org-agenda-columns-show-summaries t
1863 "Non-nil means show summaries for columns displayed in the agenda view."
1864 :group 'org-agenda-column-view
1865 :type 'boolean)
1867 (defcustom org-agenda-columns-compute-summary-properties t
1868 "Non-nil means recompute all summary properties before column view.
1869 When column view in the agenda is listing properties that have a summary
1870 operator, it can go to all relevant buffers and recompute the summaries
1871 there. This can mean overhead for the agenda column view, but is necessary
1872 to have thing up to date.
1873 As a special case, a CLOCKSUM property also makes sure that the clock
1874 computations are current."
1875 :group 'org-agenda-column-view
1876 :type 'boolean)
1878 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1879 "Non-nil means the duration of an appointment will add to day effort.
1880 The property to which appointment durations will be added is the one given
1881 in the option `org-effort-property'. If an appointment does not have
1882 an end time, `org-agenda-default-appointment-duration' will be used. If that
1883 is not set, an appointment without end time will not contribute to the time
1884 estimate."
1885 :group 'org-agenda-column-view
1886 :type 'boolean)
1888 (defcustom org-agenda-auto-exclude-function nil
1889 "A function called with a tag to decide if it is filtered on '/ RET'.
1890 The sole argument to the function, which is called once for each
1891 possible tag, is a string giving the name of the tag. The
1892 function should return either nil if the tag should be included
1893 as normal, or \"-<TAG>\" to exclude the tag.
1894 Note that for the purpose of tag filtering, only the lower-case version of
1895 all tags will be considered, so that this function will only ever see
1896 the lower-case version of all tags."
1897 :group 'org-agenda
1898 :type 'function)
1900 (defcustom org-agenda-bulk-custom-functions nil
1901 "Alist of characters and custom functions for bulk actions.
1902 For example, this value makes those two functions available:
1904 '((?R set-category)
1905 (?C bulk-cut))
1907 With selected entries in an agenda buffer, `B R' will call
1908 the custom function `set-category' on the selected entries.
1909 Note that functions in this alist don't need to be quoted."
1910 :type 'alist
1911 :version "24.1"
1912 :group 'org-agenda)
1914 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1915 "Execute BODY with point at location given by `org-hd-marker' property.
1916 If STRING is non-nil, the text property will be fetched from position 0
1917 in that string. If STRING is nil, it will be fetched from the beginning
1918 of the current line."
1919 (org-with-gensyms (marker)
1920 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1921 'org-hd-marker ,string)))
1922 (with-current-buffer (marker-buffer ,marker)
1923 (save-excursion
1924 (goto-char ,marker)
1925 ,@body)))))
1926 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1928 (defun org-add-agenda-custom-command (entry)
1929 "Replace or add a command in `org-agenda-custom-commands'.
1930 This is mostly for hacking and trying a new command - once the command
1931 works you probably want to add it to `org-agenda-custom-commands' for good."
1932 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1933 (if ass
1934 (setcdr ass (cdr entry))
1935 (push entry org-agenda-custom-commands))))
1937 ;;; Define the org-agenda-mode
1939 (defvar org-agenda-mode-map (make-sparse-keymap)
1940 "Keymap for `org-agenda-mode'.")
1941 (if (fboundp 'defvaralias)
1942 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1944 (defvar org-agenda-menu) ; defined later in this file.
1945 (defvar org-agenda-restrict nil) ; defined later in this file.
1946 (defvar org-agenda-follow-mode nil)
1947 (defvar org-agenda-entry-text-mode nil)
1948 (defvar org-agenda-clockreport-mode nil)
1949 (defvar org-agenda-show-log nil)
1950 (defvar org-agenda-redo-command nil)
1951 (defvar org-agenda-query-string nil)
1952 (defvar org-agenda-mode-hook nil
1953 "Hook run after `org-agenda-mode' is turned on.
1954 The buffer is still writable when this hook is called.")
1955 (defvar org-agenda-type nil)
1956 (defvar org-agenda-force-single-file nil)
1957 (defvar org-agenda-bulk-marked-entries nil
1958 "List of markers that refer to marked entries in the agenda.")
1960 ;;; Multiple agenda buffers support
1962 (defcustom org-agenda-sticky nil
1963 "Non-nil means agenda q key will bury agenda buffers.
1964 Agenda commands will then show existing buffer instead of generating new ones.
1965 When nil, `q' will kill the single agenda buffer."
1966 :group 'org-agenda
1967 :version "24.3"
1968 :type 'boolean)
1971 ;;;###autoload
1972 (defun org-toggle-sticky-agenda (&optional arg)
1973 "Toggle `org-agenda-sticky'."
1974 (interactive "P")
1975 (let ((new-value (if arg
1976 (> (prefix-numeric-value arg) 0)
1977 (not org-agenda-sticky))))
1978 (if (equal new-value org-agenda-sticky)
1979 (and (org-called-interactively-p 'interactive)
1980 (message "Sticky agenda was already %s"
1981 (if org-agenda-sticky "enabled" "disabled")))
1982 (setq org-agenda-sticky new-value)
1983 (org-agenda-kill-all-agenda-buffers)
1984 (and (org-called-interactively-p 'interactive)
1985 (message "Sticky agenda was %s"
1986 (if org-agenda-sticky "enabled" "disabled"))))))
1988 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1989 Toggle `org-agenda-sticky'.
1991 \(fn &optional ARG)" t nil)
1993 (defvar org-agenda-buffer nil
1994 "Agenda buffer currently being generated.")
1996 (defvar org-agenda-last-prefix-arg nil)
1997 (defvar org-agenda-this-buffer-name nil)
1998 (defvar org-agenda-doing-sticky-redo nil)
1999 (defvar org-agenda-this-buffer-is-sticky nil)
2001 (defconst org-agenda-local-vars
2002 '(org-agenda-this-buffer-name
2003 org-agenda-undo-list
2004 org-agenda-pending-undo-list
2005 org-agenda-follow-mode
2006 org-agenda-entry-text-mode
2007 org-agenda-clockreport-mode
2008 org-agenda-show-log
2009 org-agenda-redo-command
2010 org-agenda-query-string
2011 org-agenda-type
2012 org-agenda-bulk-marked-entries
2013 org-agenda-undo-has-started-in
2014 org-agenda-info
2015 org-agenda-tag-filter-overlays
2016 org-agenda-cat-filter-overlays
2017 org-agenda-pre-window-conf
2018 org-agenda-columns-active
2019 org-agenda-tag-filter
2020 org-agenda-category-filter
2021 org-agenda-markers
2022 org-agenda-last-search-view-search-was-boolean
2023 org-agenda-filtered-by-category
2024 org-agenda-filter-form
2025 org-agenda-cycle-counter
2026 org-agenda-last-prefix-arg)
2027 "Variables that must be local in agenda buffers to allow multiple buffers.")
2029 (defun org-agenda-mode ()
2030 "Mode for time-sorted view on action items in Org-mode files.
2032 The following commands are available:
2034 \\{org-agenda-mode-map}"
2035 (interactive)
2036 (cond (org-agenda-doing-sticky-redo
2037 ;; Refreshing sticky agenda-buffer
2039 ;; Preserve the value of `org-agenda-local-vars' variables,
2040 ;; while letting `kill-all-local-variables' kill the rest
2041 (let ((save (buffer-local-variables)))
2042 (kill-all-local-variables)
2043 (mapc 'make-local-variable org-agenda-local-vars)
2044 (dolist (elem save)
2045 (let ((var (car elem))
2046 (val (cdr elem)))
2047 (when (and val
2048 (member var org-agenda-local-vars))
2049 (set var val)))))
2050 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2051 (org-agenda-sticky
2052 ;; Creating a sticky Agenda buffer for the first time
2053 (kill-all-local-variables)
2054 (mapc 'make-local-variable org-agenda-local-vars)
2055 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2057 ;; Creating a non-sticky agenda buffer
2058 (kill-all-local-variables)
2059 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2060 (setq org-agenda-undo-list nil
2061 org-agenda-pending-undo-list nil
2062 org-agenda-bulk-marked-entries nil)
2063 (setq major-mode 'org-agenda-mode)
2064 ;; Keep global-font-lock-mode from turning on font-lock-mode
2065 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2066 (setq mode-name "Org-Agenda")
2067 (use-local-map org-agenda-mode-map)
2068 (easy-menu-add org-agenda-menu)
2069 (if org-startup-truncated (setq truncate-lines t))
2070 (org-set-local 'line-move-visual nil)
2071 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2072 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2073 ;; Make sure properties are removed when copying text
2074 (make-local-variable 'filter-buffer-substring-functions)
2075 (add-hook 'filter-buffer-substring-functions
2076 (lambda (fun start end delete)
2077 (substring-no-properties (funcall fun start end delete))))
2078 (unless org-agenda-keep-modes
2079 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2080 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2081 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2082 org-agenda-show-log org-agenda-start-with-log-mode))
2084 (easy-menu-change
2085 '("Agenda") "Agenda Files"
2086 (append
2087 (list
2088 (vector
2089 (if (get 'org-agenda-files 'org-restrict)
2090 "Restricted to single file"
2091 "Edit File List")
2092 '(org-edit-agenda-file-list)
2093 (not (get 'org-agenda-files 'org-restrict)))
2094 "--")
2095 (mapcar 'org-file-menu-entry (org-agenda-files))))
2096 (org-agenda-set-mode-name)
2097 (apply
2098 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2099 (list 'org-agenda-mode-hook)))
2101 (substitute-key-definition 'undo 'org-agenda-undo
2102 org-agenda-mode-map global-map)
2103 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2104 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2105 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2106 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2107 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2108 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2109 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2110 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2111 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2112 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2113 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2114 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2115 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2116 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2117 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2118 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2119 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2120 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2121 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2122 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2123 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2124 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2125 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2126 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2127 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2128 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2129 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2130 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2131 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2132 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2133 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2134 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2135 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2136 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2137 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2138 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2139 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2140 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2141 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2142 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2143 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2144 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2145 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2146 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2147 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2148 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2150 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2151 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2152 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2153 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2154 (while l (org-defkey org-agenda-mode-map
2155 (int-to-string (pop l)) 'digit-argument)))
2157 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2158 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2159 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2160 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2161 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2162 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2163 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2164 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2165 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2166 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2167 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2168 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2169 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2170 'org-clock-modify-effort-estimate)
2171 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2172 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2173 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2174 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2175 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2176 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2177 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2178 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2179 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2180 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2181 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2182 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2183 (substitute-key-definition 'next-line 'org-agenda-next-line
2184 org-agenda-mode-map global-map)
2185 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2186 org-agenda-mode-map global-map)
2187 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2188 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2189 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2190 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2191 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2192 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2193 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2194 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2195 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2196 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2197 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2198 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2199 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2200 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2201 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2202 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2203 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2204 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2205 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2206 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2207 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2208 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2209 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2210 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2211 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2212 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2213 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2214 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2215 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2216 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2218 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2219 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2220 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2221 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2222 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2223 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2224 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2225 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2226 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2227 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2228 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2229 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2231 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2232 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2233 (when org-agenda-mouse-1-follows-link
2234 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2235 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2236 '("Agenda"
2237 ("Agenda Files")
2238 "--"
2239 ("Agenda Dates"
2240 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2241 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2242 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2243 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2244 "--"
2245 ("View"
2246 ["Day View" org-agenda-day-view
2247 :active (org-agenda-check-type nil 'agenda)
2248 :style radio :selected (eq org-agenda-current-span 'day)
2249 :keys "v d (or just d)"]
2250 ["Week View" org-agenda-week-view
2251 :active (org-agenda-check-type nil 'agenda)
2252 :style radio :selected (eq org-agenda-current-span 'week)
2253 :keys "v w (or just w)"]
2254 ["Month View" org-agenda-month-view
2255 :active (org-agenda-check-type nil 'agenda)
2256 :style radio :selected (eq org-agenda-current-span 'month)
2257 :keys "v m"]
2258 ["Year View" org-agenda-year-view
2259 :active (org-agenda-check-type nil 'agenda)
2260 :style radio :selected (eq org-agenda-current-span 'year)
2261 :keys "v y"]
2262 "--"
2263 ["Include Diary" org-agenda-toggle-diary
2264 :style toggle :selected org-agenda-include-diary
2265 :active (org-agenda-check-type nil 'agenda)]
2266 ["Include Deadlines" org-agenda-toggle-deadlines
2267 :style toggle :selected org-agenda-include-deadlines
2268 :active (org-agenda-check-type nil 'agenda)]
2269 ["Use Time Grid" org-agenda-toggle-time-grid
2270 :style toggle :selected org-agenda-use-time-grid
2271 :active (org-agenda-check-type nil 'agenda)]
2272 "--"
2273 ["Show clock report" org-agenda-clockreport-mode
2274 :style toggle :selected org-agenda-clockreport-mode
2275 :active (org-agenda-check-type nil 'agenda)]
2276 ["Show some entry text" org-agenda-entry-text-mode
2277 :style toggle :selected org-agenda-entry-text-mode
2278 :active t]
2279 "--"
2280 ["Show Logbook entries" org-agenda-log-mode
2281 :style toggle :selected org-agenda-show-log
2282 :active (org-agenda-check-type nil 'agenda 'timeline)
2283 :keys "v l (or just l)"]
2284 ["Include archived trees" org-agenda-archives-mode
2285 :style toggle :selected org-agenda-archives-mode :active t
2286 :keys "v a"]
2287 ["Include archive files" (org-agenda-archives-mode t)
2288 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2289 :keys "v A"]
2290 "--"
2291 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2292 ["Write view to file" org-agenda-write t]
2293 ["Rebuild buffer" org-agenda-redo t]
2294 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2295 "--"
2296 ["Show original entry" org-agenda-show t]
2297 ["Go To (other window)" org-agenda-goto t]
2298 ["Go To (this window)" org-agenda-switch-to t]
2299 ["Capture with cursor date" org-agenda-capture t]
2300 ["Follow Mode" org-agenda-follow-mode
2301 :style toggle :selected org-agenda-follow-mode :active t]
2302 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2303 "--"
2304 ("TODO"
2305 ["Cycle TODO" org-agenda-todo t]
2306 ["Next TODO set" org-agenda-todo-nextset t]
2307 ["Previous TODO set" org-agenda-todo-previousset t]
2308 ["Add note" org-agenda-add-note t])
2309 ("Archive/Refile/Delete"
2310 ["Archive default" org-agenda-archive-default t]
2311 ["Archive default" org-agenda-archive-default-with-confirmation t]
2312 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2313 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2314 ["Archive subtree" org-agenda-archive t]
2315 "--"
2316 ["Refile" org-agenda-refile t]
2317 "--"
2318 ["Delete subtree" org-agenda-kill t])
2319 ("Bulk action"
2320 ["Mark entry" org-agenda-bulk-mark t]
2321 ["Mark all" org-agenda-bulk-mark-all t]
2322 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2323 ["Unmark entry" org-agenda-bulk-unmark t]
2324 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2325 ["Act on all marked" org-agenda-bulk-action t]
2326 "--"
2327 ("Tags and Properties"
2328 ["Show all Tags" org-agenda-show-tags t]
2329 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2330 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2331 "--"
2332 ["Column View" org-columns t])
2333 ("Deadline/Schedule"
2334 ["Schedule" org-agenda-schedule t]
2335 ["Set Deadline" org-agenda-deadline t]
2336 "--"
2337 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2338 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2339 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2340 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2341 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2342 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2343 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2344 ("Clock and Effort"
2345 ["Clock in" org-agenda-clock-in t]
2346 ["Clock out" org-agenda-clock-out t]
2347 ["Clock cancel" org-agenda-clock-cancel t]
2348 ["Goto running clock" org-clock-goto t]
2349 "--"
2350 ["Set Effort" org-agenda-set-effort t]
2351 ["Change clocked effort" org-clock-modify-effort-estimate
2352 (org-clock-is-active)])
2353 ("Priority"
2354 ["Set Priority" org-agenda-priority t]
2355 ["Increase Priority" org-agenda-priority-up t]
2356 ["Decrease Priority" org-agenda-priority-down t]
2357 ["Show Priority" org-show-priority t])
2358 ("Calendar/Diary"
2359 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2360 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2361 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2362 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2363 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2364 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2365 "--"
2366 ["Create iCalendar File" org-icalendar-combine-agenda-files t])
2367 "--"
2368 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2369 "--"
2370 ("MobileOrg"
2371 ["Push Files and Views" org-mobile-push t]
2372 ["Get Captured and Flagged" org-mobile-pull t]
2373 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2374 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2375 "--"
2376 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2377 "--"
2378 ["Quit" org-agenda-quit t]
2379 ["Exit and Release Buffers" org-agenda-exit t]
2382 ;;; Agenda undo
2384 (defvar org-agenda-allow-remote-undo t
2385 "Non-nil means allow remote undo from the agenda buffer.")
2386 (defvar org-agenda-undo-has-started-in nil
2387 "Buffers that have already seen `undo-start' in the current undo sequence.")
2389 (defun org-agenda-undo ()
2390 "Undo a remote editing step in the agenda.
2391 This undoes changes both in the agenda buffer and in the remote buffer
2392 that have been changed along."
2393 (interactive)
2394 (or org-agenda-allow-remote-undo
2395 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2396 (if (not (eq this-command last-command))
2397 (setq org-agenda-undo-has-started-in nil
2398 org-agenda-pending-undo-list org-agenda-undo-list))
2399 (if (not org-agenda-pending-undo-list)
2400 (error "No further undo information"))
2401 (let* ((entry (pop org-agenda-pending-undo-list))
2402 buf line cmd rembuf)
2403 (setq cmd (pop entry) line (pop entry))
2404 (setq rembuf (nth 2 entry))
2405 (org-with-remote-undo rembuf
2406 (while (bufferp (setq buf (pop entry)))
2407 (if (pop entry)
2408 (with-current-buffer buf
2409 (let ((last-undo-buffer buf)
2410 (inhibit-read-only t))
2411 (unless (memq buf org-agenda-undo-has-started-in)
2412 (push buf org-agenda-undo-has-started-in)
2413 (make-local-variable 'pending-undo-list)
2414 (undo-start))
2415 (while (and pending-undo-list
2416 (listp pending-undo-list)
2417 (not (car pending-undo-list)))
2418 (pop pending-undo-list))
2419 (undo-more 1))))))
2420 (org-goto-line line)
2421 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2423 (defun org-verify-change-for-undo (l1 l2)
2424 "Verify that a real change occurred between the undo lists L1 and L2."
2425 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2426 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2427 (not (eq l1 l2)))
2429 ;;; Agenda dispatch
2431 (defvar org-agenda-restrict-begin (make-marker))
2432 (defvar org-agenda-restrict-end (make-marker))
2433 (defvar org-agenda-last-dispatch-buffer nil)
2434 (defvar org-agenda-overriding-restriction nil)
2436 (defcustom org-agenda-custom-commands-contexts nil
2437 "Alist of custom agenda keys and contextual rules.
2439 For example, if you have a custom agenda command \"p\" and you
2440 want this command to be accessible only from plain text files,
2441 use this:
2443 '((\"p\" ((in-file . \"\\.txt\"))))
2445 Here are the available contexts definitions:
2447 in-file: command displayed only in matching files
2448 in-mode: command displayed only in matching modes
2449 not-in-file: command not displayed in matching files
2450 not-in-mode: command not displayed in matching modes
2451 in-buffer: command displayed only in matching buffers
2452 not-in-buffer: command not displayed in matching buffers
2453 [function]: a custom function taking no argument
2455 If you define several checks, the agenda command will be
2456 accessible if there is at least one valid check.
2458 You can also bind a key to another agenda custom command
2459 depending on contextual rules.
2461 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2463 Here it means: in .txt files, use \"p\" as the key for the
2464 agenda command otherwise associated with \"q\". (The command
2465 originally associated with \"q\" is not displayed to avoid
2466 duplicates.)"
2467 :version "24.3"
2468 :group 'org-agenda-custom-commands
2469 :type '(repeat (list :tag "Rule"
2470 (string :tag " Agenda key")
2471 (string :tag "Replace by command")
2472 (repeat :tag "Available when"
2473 (choice
2474 (cons :tag "Condition"
2475 (choice
2476 (const :tag "In file" in-file)
2477 (const :tag "Not in file" not-in-file)
2478 (const :tag "In buffer" in-buffer)
2479 (const :tag "Not in buffer" not-in-buffer)
2480 (const :tag "In mode" in-mode)
2481 (const :tag "Not in mode" not-in-mode))
2482 (regexp))
2483 (function :tag "Custom function"))))))
2485 (defcustom org-agenda-max-entries nil
2486 "Maximum number of entries to display in an agenda.
2487 This can be nil (no limit) or an integer or an alist of agenda
2488 types with an associated number of entries to display in this
2489 type."
2490 :version "24.3"
2491 :group 'org-agenda-custom-commands
2492 :type '(choice (symbol :tag "No limit" nil)
2493 (integer :tag "Max number of entries")
2494 (repeat
2495 (cons (choice :tag "Agenda type"
2496 (const agenda)
2497 (const todo)
2498 (const tags)
2499 (const search)
2500 (const timeline))
2501 (integer :tag "Max number of entries")))))
2503 (defcustom org-agenda-max-todos nil
2504 "Maximum number of TODOs to display in an agenda.
2505 This can be nil (no limit) or an integer or an alist of agenda
2506 types with an associated number of entries to display in this
2507 type."
2508 :version "24.3"
2509 :group 'org-agenda-custom-commands
2510 :type '(choice (symbol :tag "No limit" nil)
2511 (integer :tag "Max number of entries")
2512 (repeat
2513 (cons (choice :tag "Agenda type"
2514 (const agenda)
2515 (const todo)
2516 (const tags)
2517 (const search)
2518 (const timeline))
2519 (integer :tag "Max number of entries")))))
2521 (defcustom org-agenda-max-tags nil
2522 "Maximum number of tagged entries to display in an agenda.
2523 This can be nil (no limit) or an integer or an alist of agenda
2524 types with an associated number of entries to display in this
2525 type."
2526 :version "24.3"
2527 :group 'org-agenda-custom-commands
2528 :type '(choice (symbol :tag "No limit" nil)
2529 (integer :tag "Max number of entries")
2530 (repeat
2531 (cons (choice :tag "Agenda type"
2532 (const agenda)
2533 (const todo)
2534 (const tags)
2535 (const search)
2536 (const timeline))
2537 (integer :tag "Max number of entries")))))
2539 (defcustom org-agenda-max-effort nil
2540 "Maximum cumulated effort duration for the agenda.
2541 This can be nil (no limit) or a number of minutes (as an integer)
2542 or an alist of agenda types with an associated number of minutes
2543 to limit entries to in this type."
2544 :version "24.3"
2545 :group 'org-agenda-custom-commands
2546 :type '(choice (symbol :tag "No limit" nil)
2547 (integer :tag "Max number of entries")
2548 (repeat
2549 (cons (choice :tag "Agenda type"
2550 (const agenda)
2551 (const todo)
2552 (const tags)
2553 (const search)
2554 (const timeline))
2555 (integer :tag "Max number of entries")))))
2557 (defvar org-keys nil)
2558 (defvar org-match nil)
2559 ;;;###autoload
2560 (defun org-agenda (&optional arg org-keys restriction)
2561 "Dispatch agenda commands to collect entries to the agenda buffer.
2562 Prompts for a command to execute. Any prefix arg will be passed
2563 on to the selected command. The default selections are:
2565 a Call `org-agenda-list' to display the agenda for current day or week.
2566 t Call `org-todo-list' to display the global todo list.
2567 T Call `org-todo-list' to display the global todo list, select only
2568 entries with a specific TODO keyword (the user gets a prompt).
2569 m Call `org-tags-view' to display headlines with tags matching
2570 a condition (the user is prompted for the condition).
2571 M Like `m', but select only TODO entries, no ordinary headlines.
2572 L Create a timeline for the current buffer.
2573 e Export views to associated files.
2574 s Search entries for keywords.
2575 S Search entries for keywords, only with TODO keywords.
2576 / Multi occur across all agenda files and also files listed
2577 in `org-agenda-text-search-extra-files'.
2578 < Restrict agenda commands to buffer, subtree, or region.
2579 Press several times to get the desired effect.
2580 > Remove a previous restriction.
2581 # List \"stuck\" projects.
2582 ! Configure what \"stuck\" means.
2583 C Configure custom agenda commands.
2585 More commands can be added by configuring the variable
2586 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2587 searches can be pre-defined in this way.
2589 If the current buffer is in Org-mode and visiting a file, you can also
2590 first press `<' once to indicate that the agenda should be temporarily
2591 \(until the next use of \\[org-agenda]) restricted to the current file.
2592 Pressing `<' twice means to restrict to the current subtree or region
2593 \(if active)."
2594 (interactive "P")
2595 (catch 'exit
2596 (let* ((prefix-descriptions nil)
2597 (org-agenda-buffer-name org-agenda-buffer-name)
2598 (org-agenda-window-setup (if (equal (buffer-name)
2599 org-agenda-buffer-name)
2600 'current-window
2601 org-agenda-window-setup))
2602 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2603 (org-agenda-custom-commands
2604 ;; normalize different versions
2605 (delq nil
2606 (mapcar
2607 (lambda (x)
2608 (cond ((stringp (cdr x))
2609 (push x prefix-descriptions)
2610 nil)
2611 ((stringp (nth 1 x)) x)
2612 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2613 (t (cons (car x) (cons "" (cdr x))))))
2614 org-agenda-custom-commands)))
2615 (org-agenda-custom-commands
2616 (org-contextualize-keys
2617 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2618 (buf (current-buffer))
2619 (bfn (buffer-file-name (buffer-base-buffer)))
2620 entry key type org-match lprops ans)
2621 ;; Turn off restriction unless there is an overriding one,
2622 (unless org-agenda-overriding-restriction
2623 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2624 ;; There is a request to keep the file list in place
2625 (put 'org-agenda-files 'org-restrict nil))
2626 (setq org-agenda-restrict nil)
2627 (move-marker org-agenda-restrict-begin nil)
2628 (move-marker org-agenda-restrict-end nil))
2629 ;; Delete old local properties
2630 (put 'org-agenda-redo-command 'org-lprops nil)
2631 ;; Delete previously set last-arguments
2632 (put 'org-agenda-redo-command 'last-args nil)
2633 ;; Remember where this call originated
2634 (setq org-agenda-last-dispatch-buffer (current-buffer))
2635 (unless org-keys
2636 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2637 org-keys (car ans)
2638 restriction (cdr ans)))
2639 ;; If we have sticky agenda buffers, set a name for the buffer,
2640 ;; depending on the invoking keys. The user may still set this
2641 ;; as a command option, which will overwrite what we do here.
2642 (if org-agenda-sticky
2643 (setq org-agenda-buffer-name
2644 (format "*Org Agenda(%s)*" org-keys)))
2645 ;; Establish the restriction, if any
2646 (when (and (not org-agenda-overriding-restriction) restriction)
2647 (put 'org-agenda-files 'org-restrict (list bfn))
2648 (cond
2649 ((eq restriction 'region)
2650 (setq org-agenda-restrict t)
2651 (move-marker org-agenda-restrict-begin (region-beginning))
2652 (move-marker org-agenda-restrict-end (region-end)))
2653 ((eq restriction 'subtree)
2654 (save-excursion
2655 (setq org-agenda-restrict t)
2656 (org-back-to-heading t)
2657 (move-marker org-agenda-restrict-begin (point))
2658 (move-marker org-agenda-restrict-end
2659 (progn (org-end-of-subtree t)))))))
2661 ;; For example the todo list should not need it (but does...)
2662 (cond
2663 ((setq entry (assoc org-keys org-agenda-custom-commands))
2664 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2665 (progn
2666 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2667 lprops (nth 4 entry))
2668 (if org-agenda-sticky
2669 (setq org-agenda-buffer-name
2670 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2671 (format "*Org Agenda(%s)*" org-keys))))
2672 (put 'org-agenda-redo-command 'org-lprops lprops)
2673 (cond
2674 ((eq type 'agenda)
2675 (org-let lprops '(org-agenda-list current-prefix-arg)))
2676 ((eq type 'alltodo)
2677 (org-let lprops '(org-todo-list current-prefix-arg)))
2678 ((eq type 'search)
2679 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2680 ((eq type 'stuck)
2681 (org-let lprops '(org-agenda-list-stuck-projects
2682 current-prefix-arg)))
2683 ((eq type 'tags)
2684 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2685 ((eq type 'tags-todo)
2686 (org-let lprops '(org-tags-view '(4) org-match)))
2687 ((eq type 'todo)
2688 (org-let lprops '(org-todo-list org-match)))
2689 ((eq type 'tags-tree)
2690 (org-check-for-org-mode)
2691 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2692 ((eq type 'todo-tree)
2693 (org-check-for-org-mode)
2694 (org-let lprops
2695 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2696 (regexp-quote org-match) "\\>"))))
2697 ((eq type 'occur-tree)
2698 (org-check-for-org-mode)
2699 (org-let lprops '(org-occur org-match)))
2700 ((functionp type)
2701 (org-let lprops '(funcall type org-match)))
2702 ((fboundp type)
2703 (org-let lprops '(funcall type org-match)))
2704 (t (error "Invalid custom agenda command type %s" type))))
2705 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2706 ((equal org-keys "C")
2707 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2708 (customize-variable 'org-agenda-custom-commands))
2709 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2710 ((equal org-keys "s") (call-interactively 'org-search-view))
2711 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2712 ((equal org-keys "t") (call-interactively 'org-todo-list))
2713 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2714 ((equal org-keys "m") (call-interactively 'org-tags-view))
2715 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2716 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2717 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2718 (org-add-hook
2719 'post-command-hook
2720 (lambda ()
2721 (unless (current-message)
2722 (let* ((m (org-agenda-get-any-marker))
2723 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2724 (when note
2725 (message (concat
2726 "FLAGGING-NOTE ([?] for more info): "
2727 (org-add-props
2728 (replace-regexp-in-string
2729 "\\\\n" "//"
2730 (copy-sequence note))
2731 nil 'face 'org-warning)))))))
2732 t t))
2733 ((equal org-keys "L")
2734 (unless (derived-mode-p 'org-mode)
2735 (error "This is not an Org-mode file"))
2736 (unless restriction
2737 (put 'org-agenda-files 'org-restrict (list bfn))
2738 (org-call-with-arg 'org-timeline arg)))
2739 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2740 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2741 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2742 (t (error "Invalid agenda key"))))))
2744 (autoload 'org-agenda "org-agenda" "\
2745 Dispatch agenda commands to collect entries to the agenda buffer.
2746 Prompts for a command to execute. Any prefix arg will be passed
2747 on to the selected command. The default selections are:
2749 a Call `org-agenda-list' to display the agenda for current day or week.
2750 t Call `org-todo-list' to display the global todo list.
2751 T Call `org-todo-list' to display the global todo list, select only
2752 entries with a specific TODO keyword (the user gets a prompt).
2753 m Call `org-tags-view' to display headlines with tags matching
2754 a condition (the user is prompted for the condition).
2755 M Like `m', but select only TODO entries, no ordinary headlines.
2756 L Create a timeline for the current buffer.
2757 e Export views to associated files.
2758 s Search entries for keywords.
2759 S Search entries for keywords, only with TODO keywords.
2760 / Multi occur across all agenda files and also files listed
2761 in `org-agenda-text-search-extra-files'.
2762 < Restrict agenda commands to buffer, subtree, or region.
2763 Press several times to get the desired effect.
2764 > Remove a previous restriction.
2765 # List \"stuck\" projects.
2766 ! Configure what \"stuck\" means.
2767 C Configure custom agenda commands.
2769 More commands can be added by configuring the variable
2770 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2771 searches can be pre-defined in this way.
2773 If the current buffer is in Org-mode and visiting a file, you can also
2774 first press `<' once to indicate that the agenda should be temporarily
2775 \(until the next use of \\[org-agenda]) restricted to the current file.
2776 Pressing `<' twice means to restrict to the current subtree or region
2777 \(if active).
2779 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2781 (defun org-agenda-append-agenda ()
2782 "Append another agenda view to the current one.
2783 This function allows interactive building of block agendas.
2784 Agenda views are separated by `org-agenda-block-separator'."
2785 (interactive)
2786 (unless (derived-mode-p 'org-agenda-mode)
2787 (error "Can only append from within agenda buffer"))
2788 (let ((org-agenda-multi t))
2789 (org-agenda)
2790 (widen)
2791 (org-agenda-finalize)
2792 (org-agenda-fit-window-to-buffer)))
2794 (defun org-agenda-normalize-custom-commands (cmds)
2795 (delq nil
2796 (mapcar
2797 (lambda (x)
2798 (cond ((stringp (cdr x)) nil)
2799 ((stringp (nth 1 x)) x)
2800 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2801 (t (cons (car x) (cons "" (cdr x))))))
2802 cmds)))
2804 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2805 "The user interface for selecting an agenda command."
2806 (catch 'exit
2807 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2808 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2809 (region-p (org-region-active-p))
2810 (custom org-agenda-custom-commands)
2811 (selstring "")
2812 restriction second-time
2813 c entry key type match prefixes rmheader header-end custom1 desc
2814 line lines left right n n1)
2815 (save-window-excursion
2816 (delete-other-windows)
2817 (org-switch-to-buffer-other-window " *Agenda Commands*")
2818 (erase-buffer)
2819 (insert (eval-when-compile
2820 (let ((header
2821 "Press key for an agenda command: < Buffer, subtree/region restriction
2822 -------------------------------- > Remove restriction
2823 a Agenda for current week or day e Export agenda views
2824 t List of all TODO entries T Entries with special TODO kwd
2825 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2826 s Search for keywords S Like s, but only TODO entries
2827 L Timeline for current buffer # List stuck projects (!=configure)
2828 / Multi-occur C Configure custom agenda commands
2829 ? Find :FLAGGED: entries * Toggle sticky agenda views
2831 (start 0))
2832 (while (string-match
2833 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2834 header start)
2835 (setq start (match-end 0))
2836 (add-text-properties (match-beginning 2) (match-end 2)
2837 '(face bold) header))
2838 header)))
2839 (setq header-end (point-marker))
2840 (while t
2841 (setq custom1 custom)
2842 (when (eq rmheader t)
2843 (org-goto-line 1)
2844 (re-search-forward ":" nil t)
2845 (delete-region (match-end 0) (point-at-eol))
2846 (forward-char 1)
2847 (looking-at "-+")
2848 (delete-region (match-end 0) (point-at-eol))
2849 (move-marker header-end (match-end 0)))
2850 (goto-char header-end)
2851 (delete-region (point) (point-max))
2853 ;; Produce all the lines that describe custom commands and prefixes
2854 (setq lines nil)
2855 (while (setq entry (pop custom1))
2856 (setq key (car entry) desc (nth 1 entry)
2857 type (nth 2 entry)
2858 match (nth 3 entry))
2859 (if (> (length key) 1)
2860 (add-to-list 'prefixes (string-to-char key))
2861 (setq line
2862 (format
2863 "%-4s%-14s"
2864 (org-add-props (copy-sequence key)
2865 '(face bold))
2866 (cond
2867 ((string-match "\\S-" desc) desc)
2868 ((eq type 'agenda) "Agenda for current week or day")
2869 ((eq type 'alltodo) "List of all TODO entries")
2870 ((eq type 'search) "Word search")
2871 ((eq type 'stuck) "List of stuck projects")
2872 ((eq type 'todo) "TODO keyword")
2873 ((eq type 'tags) "Tags query")
2874 ((eq type 'tags-todo) "Tags (TODO)")
2875 ((eq type 'tags-tree) "Tags tree")
2876 ((eq type 'todo-tree) "TODO kwd tree")
2877 ((eq type 'occur-tree) "Occur tree")
2878 ((functionp type) (if (symbolp type)
2879 (symbol-name type)
2880 "Lambda expression"))
2881 (t "???"))))
2882 (if org-agenda-menu-show-matcher
2883 (setq line
2884 (concat line ": "
2885 (cond
2886 ((stringp match)
2887 (setq match (copy-sequence match))
2888 (org-add-props match nil 'face 'org-warning))
2889 ((listp type)
2890 (format "set of %d commands" (length type))))))
2891 (if (org-string-nw-p match)
2892 (add-text-properties
2893 0 (length line) (list 'help-echo
2894 (concat "Matcher: " match)) line)))
2895 (push line lines)))
2896 (setq lines (nreverse lines))
2897 (when prefixes
2898 (mapc (lambda (x)
2899 (push
2900 (format "%s %s"
2901 (org-add-props (char-to-string x)
2902 nil 'face 'bold)
2903 (or (cdr (assoc (concat selstring
2904 (char-to-string x))
2905 prefix-descriptions))
2906 "Prefix key"))
2907 lines))
2908 prefixes))
2910 ;; Check if we should display in two columns
2911 (if org-agenda-menu-two-columns
2912 (progn
2913 (setq n (length lines)
2914 n1 (+ (/ n 2) (mod n 2))
2915 right (nthcdr n1 lines)
2916 left (copy-sequence lines))
2917 (setcdr (nthcdr (1- n1) left) nil))
2918 (setq left lines right nil))
2919 (while left
2920 (insert "\n" (pop left))
2921 (when right
2922 (if (< (current-column) 40)
2923 (move-to-column 40 t)
2924 (insert " "))
2925 (insert (pop right))))
2927 ;; Make the window the right size
2928 (goto-char (point-min))
2929 (if second-time
2930 (if (not (pos-visible-in-window-p (point-max)))
2931 (org-fit-window-to-buffer))
2932 (setq second-time t)
2933 (org-fit-window-to-buffer))
2935 ;; Ask for selection
2936 (message "Press key for agenda command%s:"
2937 (if (or restrict-ok org-agenda-overriding-restriction)
2938 (if org-agenda-overriding-restriction
2939 " (restriction lock active)"
2940 (if restriction
2941 (format " (restricted to %s)" restriction)
2942 " (unrestricted)"))
2943 ""))
2944 (setq c (read-char-exclusive))
2945 (message "")
2946 (cond
2947 ((assoc (char-to-string c) custom)
2948 (setq selstring (concat selstring (char-to-string c)))
2949 (throw 'exit (cons selstring restriction)))
2950 ((memq c prefixes)
2951 (setq selstring (concat selstring (char-to-string c))
2952 prefixes nil
2953 rmheader (or rmheader t)
2954 custom (delq nil (mapcar
2955 (lambda (x)
2956 (if (or (= (length (car x)) 1)
2957 (/= (string-to-char (car x)) c))
2959 (cons (substring (car x) 1) (cdr x))))
2960 custom))))
2961 ((eq c ?*)
2962 (call-interactively 'org-toggle-sticky-agenda)
2963 (sit-for 2))
2964 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2965 (message "Restriction is only possible in Org-mode buffers")
2966 (ding) (sit-for 1))
2967 ((eq c ?1)
2968 (org-agenda-remove-restriction-lock 'noupdate)
2969 (setq restriction 'buffer))
2970 ((eq c ?0)
2971 (org-agenda-remove-restriction-lock 'noupdate)
2972 (setq restriction (if region-p 'region 'subtree)))
2973 ((eq c ?<)
2974 (org-agenda-remove-restriction-lock 'noupdate)
2975 (setq restriction
2976 (cond
2977 ((eq restriction 'buffer)
2978 (if region-p 'region 'subtree))
2979 ((memq restriction '(subtree region))
2980 nil)
2981 (t 'buffer))))
2982 ((eq c ?>)
2983 (org-agenda-remove-restriction-lock 'noupdate)
2984 (setq restriction nil))
2985 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2986 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2987 ((and (> (length selstring) 0) (eq c ?\d))
2988 (delete-window)
2989 (org-agenda-get-restriction-and-command prefix-descriptions))
2991 ((equal c ?q) (error "Abort"))
2992 (t (error "Invalid key %c" c))))))))
2994 (defun org-agenda-fit-window-to-buffer ()
2995 "Fit the window to the buffer size."
2996 (and (memq org-agenda-window-setup '(reorganize-frame))
2997 (fboundp 'fit-window-to-buffer)
2998 (org-fit-window-to-buffer
3000 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3001 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3003 (defvar org-cmd nil)
3004 (defvar org-agenda-overriding-cmd nil)
3005 (defvar org-agenda-overriding-arguments nil)
3006 (defvar org-agenda-overriding-cmd-arguments nil)
3007 (defun org-agenda-run-series (name series)
3008 (org-let (nth 1 series) '(org-agenda-prepare name))
3009 ;; We need to reset agenda markers here, because when constructing a
3010 ;; block agenda, the individual blocks do not do that.
3011 (org-agenda-reset-markers)
3012 (let* ((org-agenda-multi t)
3013 (redo (list 'org-agenda-run-series name (list 'quote series)))
3014 (cmds (car series))
3015 (gprops (nth 1 series))
3016 match ;; The byte compiler incorrectly complains about this. Keep it!
3017 org-cmd type lprops)
3018 (while (setq org-cmd (pop cmds))
3019 (setq type (car org-cmd)
3020 match (eval (nth 1 org-cmd))
3021 lprops (nth 2 org-cmd))
3022 (let ((org-agenda-overriding-arguments
3023 (if (eq org-agenda-overriding-cmd org-cmd)
3024 (or org-agenda-overriding-arguments
3025 org-agenda-overriding-cmd-arguments))))
3026 (cond
3027 ((eq type 'agenda)
3028 (org-let2 gprops lprops
3029 '(call-interactively 'org-agenda-list)))
3030 ((eq type 'alltodo)
3031 (org-let2 gprops lprops
3032 '(call-interactively 'org-todo-list)))
3033 ((eq type 'search)
3034 (org-let2 gprops lprops
3035 '(org-search-view current-prefix-arg match nil)))
3036 ((eq type 'stuck)
3037 (org-let2 gprops lprops
3038 '(call-interactively 'org-agenda-list-stuck-projects)))
3039 ((eq type 'tags)
3040 (org-let2 gprops lprops
3041 '(org-tags-view current-prefix-arg match)))
3042 ((eq type 'tags-todo)
3043 (org-let2 gprops lprops
3044 '(org-tags-view '(4) match)))
3045 ((eq type 'todo)
3046 (org-let2 gprops lprops
3047 '(org-todo-list match)))
3048 ((fboundp type)
3049 (org-let2 gprops lprops
3050 '(funcall type match)))
3051 (t (error "Invalid type in command series")))))
3052 (widen)
3053 (let ((inhibit-read-only t))
3054 (add-text-properties (point-min) (point-max)
3055 `(org-series t org-series-redo-cmd ,redo)))
3056 (setq org-agenda-redo-command redo)
3057 (goto-char (point-min)))
3058 (org-agenda-fit-window-to-buffer)
3059 (org-let (nth 1 series) '(org-agenda-finalize)))
3061 ;;;###autoload
3062 (defmacro org-batch-agenda (cmd-key &rest parameters)
3063 "Run an agenda command in batch mode and send the result to STDOUT.
3064 If CMD-KEY is a string of length 1, it is used as a key in
3065 `org-agenda-custom-commands' and triggers this command. If it is a
3066 longer string it is used as a tags/todo match string.
3067 Parameters are alternating variable names and values that will be bound
3068 before running the agenda command."
3069 (org-eval-in-environment (org-make-parameter-alist parameters)
3070 (if (> (length cmd-key) 2)
3071 (org-tags-view nil cmd-key)
3072 (org-agenda nil cmd-key)))
3073 (set-buffer org-agenda-buffer-name)
3074 (princ (buffer-string)))
3076 (autoload 'org-batch-agenda "org-agenda" "\
3077 Run an agenda command in batch mode and send the result to STDOUT.
3078 If CMD-KEY is a string of length 1, it is used as a key in
3079 `org-agenda-custom-commands' and triggers this command. If it is a
3080 longer string it is used as a tags/todo match string.
3081 Parameters are alternating variable names and values that will be bound
3082 before running the agenda command.
3084 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3085 (def-edebug-spec org-batch-agenda (form &rest sexp))
3087 (defvar org-agenda-info nil)
3089 ;;;###autoload
3090 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
3091 "Run an agenda command in batch mode and send the result to STDOUT.
3092 If CMD-KEY is a string of length 1, it is used as a key in
3093 `org-agenda-custom-commands' and triggers this command. If it is a
3094 longer string it is used as a tags/todo match string.
3095 Parameters are alternating variable names and values that will be bound
3096 before running the agenda command.
3098 The output gives a line for each selected agenda item. Each
3099 item is a list of comma-separated values, like this:
3101 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3103 category The category of the item
3104 head The headline, without TODO kwd, TAGS and PRIORITY
3105 type The type of the agenda entry, can be
3106 todo selected in TODO match
3107 tagsmatch selected in tags match
3108 diary imported from diary
3109 deadline a deadline on given date
3110 scheduled scheduled on given date
3111 timestamp entry has timestamp on given date
3112 closed entry was closed on given date
3113 upcoming-deadline warning about deadline
3114 past-scheduled forwarded scheduled item
3115 block entry has date block including g. date
3116 todo The todo keyword, if any
3117 tags All tags including inherited ones, separated by colons
3118 date The relevant date, like 2007-2-14
3119 time The time, like 15:00-16:50
3120 extra Sting with extra planning info
3121 priority-l The priority letter if any was given
3122 priority-n The computed numerical priority
3123 agenda-day The day in the agenda where this is listed"
3124 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3125 (org-make-parameter-alist parameters))
3126 (if (> (length cmd-key) 2)
3127 (org-tags-view nil cmd-key)
3128 (org-agenda nil cmd-key)))
3129 (set-buffer org-agenda-buffer-name)
3130 (let* ((lines (org-split-string (buffer-string) "\n"))
3131 line)
3132 (while (setq line (pop lines))
3133 (catch 'next
3134 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3135 (setq org-agenda-info
3136 (org-fix-agenda-info (text-properties-at 0 line)))
3137 (princ
3138 (mapconcat 'org-agenda-export-csv-mapper
3139 '(org-category txt type todo tags date time extra
3140 priority-letter priority agenda-day)
3141 ","))
3142 (princ "\n")))))
3144 (autoload 'org-batch-agenda-csv "org-agenda" "\
3145 Run an agenda command in batch mode and send the result to STDOUT.
3146 If CMD-KEY is a string of length 1, it is used as a key in
3147 `org-agenda-custom-commands' and triggers this command. If it is a
3148 longer string it is used as a tags/todo match string.
3149 Parameters are alternating variable names and values that will be bound
3150 before running the agenda command.
3152 The output gives a line for each selected agenda item. Each
3153 item is a list of comma-separated values, like this:
3155 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3157 category The category of the item
3158 head The headline, without TODO kwd, TAGS and PRIORITY
3159 type The type of the agenda entry, can be
3160 todo selected in TODO match
3161 tagsmatch selected in tags match
3162 diary imported from diary
3163 deadline a deadline on given date
3164 scheduled scheduled on given date
3165 timestamp entry has timestamp on given date
3166 closed entry was closed on given date
3167 upcoming-deadline warning about deadline
3168 past-scheduled forwarded scheduled item
3169 block entry has date block including g. date
3170 todo The todo keyword, if any
3171 tags All tags including inherited ones, separated by colons
3172 date The relevant date, like 2007-2-14
3173 time The time, like 15:00-16:50
3174 extra Sting with extra planning info
3175 priority-l The priority letter if any was given
3176 priority-n The computed numerical priority
3177 agenda-day The day in the agenda where this is listed
3179 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3180 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3182 (defun org-fix-agenda-info (props)
3183 "Make sure all properties on an agenda item have a canonical form.
3184 This ensures the export commands can easily use it."
3185 (let (tmp re)
3186 (when (setq tmp (plist-get props 'tags))
3187 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3188 (when (setq tmp (plist-get props 'date))
3189 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3190 (let ((calendar-date-display-form '(year "-" month "-" day)))
3191 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3193 (setq tmp (calendar-date-string tmp)))
3194 (setq props (plist-put props 'date tmp)))
3195 (when (setq tmp (plist-get props 'day))
3196 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3197 (let ((calendar-date-display-form '(year "-" month "-" day)))
3198 (setq tmp (calendar-date-string tmp)))
3199 (setq props (plist-put props 'day tmp))
3200 (setq props (plist-put props 'agenda-day tmp)))
3201 (when (setq tmp (plist-get props 'txt))
3202 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3203 (plist-put props 'priority-letter (match-string 1 tmp))
3204 (setq tmp (replace-match "" t t tmp)))
3205 (when (and (setq re (plist-get props 'org-todo-regexp))
3206 (setq re (concat "\\`\\.*" re " ?"))
3207 (string-match re tmp))
3208 (plist-put props 'todo (match-string 1 tmp))
3209 (setq tmp (replace-match "" t t tmp)))
3210 (plist-put props 'txt tmp)))
3211 props)
3213 (defun org-agenda-export-csv-mapper (prop)
3214 (let ((res (plist-get org-agenda-info prop)))
3215 (setq res
3216 (cond
3217 ((not res) "")
3218 ((stringp res) res)
3219 (t (prin1-to-string res))))
3220 (while (string-match "," res)
3221 (setq res (replace-match ";" t t res)))
3222 (org-trim res)))
3224 ;;;###autoload
3225 (defun org-store-agenda-views (&rest parameters)
3226 (interactive)
3227 (eval (list 'org-batch-store-agenda-views)))
3229 (autoload 'org-store-agenda-views "org-agenda" "\
3232 \(fn &rest PARAMETERS)" t nil)
3234 ;;;###autoload
3235 (defmacro org-batch-store-agenda-views (&rest parameters)
3236 "Run all custom agenda commands that have a file argument."
3237 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3238 (pop-up-frames nil)
3239 (dir default-directory)
3240 (pars (org-make-parameter-alist parameters))
3241 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3242 (save-window-excursion
3243 (while cmds
3244 (setq cmd (pop cmds)
3245 thiscmdkey (car cmd)
3246 thiscmdcmd (cdr cmd)
3247 match (nth 2 thiscmdcmd)
3248 bufname (if org-agenda-sticky
3249 (or (and (stringp match)
3250 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3251 (format "*Org Agenda(%s)*" thiscmdkey))
3252 org-agenda-buffer-name)
3253 cmd-or-set (nth 2 cmd)
3254 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3255 files (nth (if (listp cmd-or-set) 4 5) cmd))
3256 (if (stringp files) (setq files (list files)))
3257 (when files
3258 (org-eval-in-environment (append org-agenda-exporter-settings
3259 opts pars)
3260 (org-agenda nil thiscmdkey))
3261 (set-buffer bufname)
3262 (while files
3263 (org-eval-in-environment (append org-agenda-exporter-settings
3264 opts pars)
3265 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3266 (and (get-buffer bufname)
3267 (kill-buffer bufname)))))))
3269 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3270 Run all custom agenda commands that have a file argument.
3272 \(fn &rest PARAMETERS)" nil t)
3273 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3275 (defvar org-agenda-current-span nil
3276 "The current span used in the agenda view.") ; local variable in the agenda buffer
3277 (defun org-agenda-mark-header-line (pos)
3278 "Mark the line at POS as an agenda structure header."
3279 (save-excursion
3280 (goto-char pos)
3281 (put-text-property (point-at-bol) (point-at-eol)
3282 'org-agenda-structural-header t)
3283 (when org-agenda-title-append
3284 (put-text-property (point-at-bol) (point-at-eol)
3285 'org-agenda-title-append org-agenda-title-append))))
3287 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3288 (defvar org-agenda-write-buffer-name "Agenda View")
3289 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3290 "Write the current buffer (an agenda view) as a file.
3291 Depending on the extension of the file name, plain text (.txt),
3292 HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
3293 If the extension is .ics, run icalendar export over all files used
3294 to construct the agenda and limit the export to entries listed in the
3295 agenda now.
3296 If the extension is .org, collect all subtrees corresponding to the
3297 agenda entries and add them in an .org file.
3298 With prefix argument OPEN, open the new file immediately.
3299 If NOSETTINGS is given, do not scope the settings of
3300 `org-agenda-exporter-settings' into the export commands. This is used when
3301 the settings have already been scoped and we do not wish to overrule other,
3302 higher priority settings.
3303 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3304 (interactive "FWrite agenda to file: \nP")
3305 (if (not (file-writable-p file))
3306 (error "Cannot write agenda to file %s" file))
3307 (org-let (if nosettings nil org-agenda-exporter-settings)
3308 '(save-excursion
3309 (save-window-excursion
3310 (org-agenda-mark-filtered-text)
3311 (let ((bs (copy-sequence (buffer-string))) beg content)
3312 (org-agenda-unmark-filtered-text)
3313 (with-temp-buffer
3314 (rename-buffer org-agenda-write-buffer-name t)
3315 (set-buffer-modified-p nil)
3316 (insert bs)
3317 (org-agenda-remove-marked-text 'org-filtered)
3318 (while (setq beg (text-property-any (point-min) (point-max)
3319 'org-filtered t))
3320 (delete-region
3321 beg (or (next-single-property-change beg 'org-filtered)
3322 (point-max))))
3323 (run-hooks 'org-agenda-before-write-hook)
3324 (cond
3325 ((org-bound-and-true-p org-mobile-creating-agendas)
3326 (org-mobile-write-agenda-for-mobile file))
3327 ((string-match "\\.org\\'" file)
3328 (let (content p m message-log-max)
3329 (goto-char (point-min))
3330 (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
3331 (goto-char p)
3332 (setq m (get-text-property (point) 'org-hd-marker))
3333 (when m
3334 (push (save-excursion
3335 (set-buffer (marker-buffer m))
3336 (goto-char m)
3337 (org-copy-subtree 1 nil t t)
3338 org-subtree-clip)
3339 content)))
3340 (find-file file)
3341 (erase-buffer)
3342 (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
3343 (write-file file)
3344 (kill-buffer (current-buffer))
3345 (message "Org file written to %s" file)))
3346 ((string-match "\\.html?\\'" file)
3347 (require 'htmlize)
3348 (set-buffer (htmlize-buffer (current-buffer)))
3349 (when org-agenda-export-html-style
3350 ;; replace <style> section with org-agenda-export-html-style
3351 (goto-char (point-min))
3352 (kill-region (- (search-forward "<style") 6)
3353 (search-forward "</style>"))
3354 (insert org-agenda-export-html-style))
3355 (write-file file)
3356 (kill-buffer (current-buffer))
3357 (message "HTML written to %s" file))
3358 ((string-match "\\.ps\\'" file)
3359 (require 'ps-print)
3360 (ps-print-buffer-with-faces file)
3361 (message "Postscript written to %s" file))
3362 ((string-match "\\.pdf\\'" file)
3363 (require 'ps-print)
3364 (ps-print-buffer-with-faces
3365 (concat (file-name-sans-extension file) ".ps"))
3366 (call-process "ps2pdf" nil nil nil
3367 (expand-file-name
3368 (concat (file-name-sans-extension file) ".ps"))
3369 (expand-file-name file))
3370 (delete-file (concat (file-name-sans-extension file) ".ps"))
3371 (message "PDF written to %s" file))
3372 ((string-match "\\.ics\\'" file)
3373 (require 'ox-icalendar)
3374 (org-icalendar-export-current-agenda (expand-file-name file)))
3376 (let ((bs (buffer-string)))
3377 (find-file file)
3378 (erase-buffer)
3379 (insert bs)
3380 (save-buffer 0)
3381 (kill-buffer (current-buffer))
3382 (message "Plain text written to %s" file))))))))
3383 (set-buffer (or agenda-bufname
3384 (and (org-called-interactively-p 'any) (buffer-name))
3385 org-agenda-buffer-name)))
3386 (when open (org-open-file file)))
3388 (defvar org-agenda-tag-filter-overlays nil)
3389 (defvar org-agenda-cat-filter-overlays nil)
3391 (defun org-agenda-mark-filtered-text ()
3392 "Mark all text hidden by filtering with a text property."
3393 (let ((inhibit-read-only t))
3394 (mapc
3395 (lambda (o)
3396 (when (equal (overlay-buffer o) (current-buffer))
3397 (put-text-property
3398 (overlay-start o) (overlay-end o)
3399 'org-filtered t)))
3400 (append org-agenda-tag-filter-overlays
3401 org-agenda-cat-filter-overlays))))
3403 (defun org-agenda-unmark-filtered-text ()
3404 "Remove the filtering text property."
3405 (let ((inhibit-read-only t))
3406 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3408 (defun org-agenda-remove-marked-text (property &optional value)
3409 "Delete all text marked with VALUE of PROPERTY.
3410 VALUE defaults to t."
3411 (let (beg)
3412 (setq value (or value t))
3413 (while (setq beg (text-property-any (point-min) (point-max)
3414 property value))
3415 (delete-region
3416 beg (or (next-single-property-change beg 'org-filtered)
3417 (point-max))))))
3419 (defun org-agenda-add-entry-text ()
3420 "Add entry text to agenda lines.
3421 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3422 entry text following headings shown in the agenda.
3423 Drawers will be excluded, also the line with scheduling/deadline info."
3424 (when (and (> org-agenda-add-entry-text-maxlines 0)
3425 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3426 (let (m txt)
3427 (goto-char (point-min))
3428 (while (not (eobp))
3429 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3430 (beginning-of-line 2)
3431 (setq txt (org-agenda-get-some-entry-text
3432 m org-agenda-add-entry-text-maxlines " > "))
3433 (end-of-line 1)
3434 (if (string-match "\\S-" txt)
3435 (insert "\n" txt)
3436 (or (eobp) (forward-char 1))))))))
3438 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3439 &rest keep)
3440 "Extract entry text from MARKER, at most N-LINES lines.
3441 This will ignore drawers etc, just get the text.
3442 If INDENT is given, prefix every line with this string. If KEEP is
3443 given, it is a list of symbols, defining stuff that should not be
3444 removed from the entry content. Currently only `planning' is allowed here."
3445 (let (txt drawer-re kwd-time-re ind)
3446 (save-excursion
3447 (with-current-buffer (marker-buffer marker)
3448 (if (not (derived-mode-p 'org-mode))
3449 (setq txt "")
3450 (save-excursion
3451 (save-restriction
3452 (widen)
3453 (goto-char marker)
3454 (end-of-line 1)
3455 (setq txt (buffer-substring
3456 (min (1+ (point)) (point-max))
3457 (progn (outline-next-heading) (point)))
3458 drawer-re org-drawer-regexp
3459 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3460 ".*\n?"))
3461 (with-temp-buffer
3462 (insert txt)
3463 (when org-agenda-add-entry-text-descriptive-links
3464 (goto-char (point-min))
3465 (while (org-activate-bracket-links (point-max))
3466 (add-text-properties (match-beginning 0) (match-end 0)
3467 '(face org-link))))
3468 (goto-char (point-min))
3469 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3470 (set-text-properties (match-beginning 0) (match-end 0)
3471 nil))
3472 (goto-char (point-min))
3473 (while (re-search-forward drawer-re nil t)
3474 (delete-region
3475 (match-beginning 0)
3476 (progn (re-search-forward
3477 "^[ \t]*:END:.*\n?" nil 'move)
3478 (point))))
3479 (unless (member 'planning keep)
3480 (goto-char (point-min))
3481 (while (re-search-forward kwd-time-re nil t)
3482 (replace-match "")))
3483 (goto-char (point-min))
3484 (when org-agenda-entry-text-exclude-regexps
3485 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3486 (while (setq re (pop re-list))
3487 (goto-char (point-min))
3488 (while (re-search-forward re nil t)
3489 (replace-match "")))))
3490 (goto-char (point-max))
3491 (skip-chars-backward " \t\n")
3492 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3494 ;; find and remove min common indentation
3495 (goto-char (point-min))
3496 (untabify (point-min) (point-max))
3497 (setq ind (org-get-indentation))
3498 (while (not (eobp))
3499 (unless (looking-at "[ \t]*$")
3500 (setq ind (min ind (org-get-indentation))))
3501 (beginning-of-line 2))
3502 (goto-char (point-min))
3503 (while (not (eobp))
3504 (unless (looking-at "[ \t]*$")
3505 (move-to-column ind)
3506 (delete-region (point-at-bol) (point)))
3507 (beginning-of-line 2))
3509 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3511 (goto-char (point-min))
3512 (when indent
3513 (while (and (not (eobp)) (re-search-forward "^" nil t))
3514 (replace-match indent t t)))
3515 (goto-char (point-min))
3516 (while (looking-at "[ \t]*\n") (replace-match ""))
3517 (goto-char (point-max))
3518 (when (> (org-current-line)
3519 n-lines)
3520 (org-goto-line (1+ n-lines))
3521 (backward-char 1))
3522 (setq txt (buffer-substring (point-min) (point)))))))))
3523 txt))
3525 (defun org-agenda-collect-markers ()
3526 "Collect the markers pointing to entries in the agenda buffer."
3527 (let (m markers)
3528 (save-excursion
3529 (goto-char (point-min))
3530 (while (not (eobp))
3531 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3532 (org-get-at-bol 'org-marker)))
3533 (push m markers))
3534 (beginning-of-line 2)))
3535 (nreverse markers)))
3537 (defun org-create-marker-find-array (marker-list)
3538 "Create a alist of files names with all marker positions in that file."
3539 (let (f tbl m a p)
3540 (while (setq m (pop marker-list))
3541 (setq p (marker-position m)
3542 f (buffer-file-name (or (buffer-base-buffer
3543 (marker-buffer m))
3544 (marker-buffer m))))
3545 (if (setq a (assoc f tbl))
3546 (push (marker-position m) (cdr a))
3547 (push (list f p) tbl)))
3548 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3549 tbl)))
3551 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3552 (defun org-check-agenda-marker-table ()
3553 "Check of the current entry is on the marker list."
3554 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3556 (and (setq a (assoc file org-agenda-marker-table))
3557 (save-match-data
3558 (save-excursion
3559 (org-back-to-heading t)
3560 (member (point) (cdr a)))))))
3562 (defun org-check-for-org-mode ()
3563 "Make sure current buffer is in org-mode. Error if not."
3564 (or (derived-mode-p 'org-mode)
3565 (error "Cannot execute org-mode agenda command on buffer in %s"
3566 major-mode)))
3568 ;;; Agenda prepare and finalize
3570 (defvar org-agenda-multi nil) ; dynamically scoped
3571 (defvar org-agenda-pre-window-conf nil)
3572 (defvar org-agenda-columns-active nil)
3573 (defvar org-agenda-name nil)
3574 (defvar org-agenda-tag-filter nil)
3575 (defvar org-agenda-category-filter nil)
3576 (defvar org-agenda-top-category-filter nil)
3577 (defvar org-agenda-tag-filter-while-redo nil)
3578 (defvar org-agenda-tag-filter-preset nil
3579 "A preset of the tags filter used for secondary agenda filtering.
3580 This must be a list of strings, each string must be a single tag preceded
3581 by \"+\" or \"-\".
3582 This variable should not be set directly, but agenda custom commands can
3583 bind it in the options section. The preset filter is a global property of
3584 the entire agenda view. In a block agenda, it will not work reliably to
3585 define a filter for one of the individual blocks. You need to set it in
3586 the global options and expect it to be applied to the entire view.")
3588 (defvar org-agenda-category-filter-preset nil
3589 "A preset of the category filter used for secondary agenda filtering.
3590 This must be a list of strings, each string must be a single category
3591 preceded by \"+\" or \"-\".
3592 This variable should not be set directly, but agenda custom commands can
3593 bind it in the options section. The preset filter is a global property of
3594 the entire agenda view. In a block agenda, it will not work reliably to
3595 define a filter for one of the individual blocks. You need to set it in
3596 the global options and expect it to be applied to the entire view.")
3599 (defun org-agenda-use-sticky-p ()
3600 "Return non-nil if an agenda buffer named
3601 `org-agenda-buffer-name' exists and should be shown instead of
3602 generating a new one."
3603 (and
3604 ;; turned off by user
3605 org-agenda-sticky
3606 ;; For multi-agenda buffer already exists
3607 (not org-agenda-multi)
3608 ;; buffer found
3609 (get-buffer org-agenda-buffer-name)
3610 ;; C-u parameter is same as last call
3611 (with-current-buffer (get-buffer org-agenda-buffer-name)
3612 (and
3613 (equal current-prefix-arg
3614 org-agenda-last-prefix-arg)
3615 ;; In case user turned stickiness on, while having existing
3616 ;; Agenda buffer active, don't reuse that buffer, because it
3617 ;; does not have org variables local
3618 org-agenda-this-buffer-is-sticky))))
3620 (defun org-agenda-prepare-window (abuf)
3621 "Setup agenda buffer in the window."
3622 (let* ((awin (get-buffer-window abuf))
3623 wconf)
3624 (cond
3625 ((equal (current-buffer) abuf) nil)
3626 (awin (select-window awin))
3627 ((not (setq wconf (current-window-configuration))))
3628 ((equal org-agenda-window-setup 'current-window)
3629 (org-pop-to-buffer-same-window abuf))
3630 ((equal org-agenda-window-setup 'other-window)
3631 (org-switch-to-buffer-other-window abuf))
3632 ((equal org-agenda-window-setup 'other-frame)
3633 (switch-to-buffer-other-frame abuf))
3634 ((equal org-agenda-window-setup 'reorganize-frame)
3635 (delete-other-windows)
3636 (org-switch-to-buffer-other-window abuf)))
3637 ;; additional test in case agenda is invoked from within agenda
3638 ;; buffer via elisp link
3639 (unless (equal (current-buffer) abuf)
3640 (org-pop-to-buffer-same-window abuf))
3641 (setq org-agenda-pre-window-conf
3642 (or org-agenda-pre-window-conf wconf))))
3644 (defun org-agenda-prepare (&optional name)
3645 (if (org-agenda-use-sticky-p)
3646 (progn
3647 ;; Popup existing buffer
3648 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3649 (message "Sticky Agenda buffer, use `r' to refresh")
3650 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3651 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3652 (setq org-todo-keywords-for-agenda nil)
3653 (setq org-drawers-for-agenda nil)
3654 (unless org-agenda-persistent-filter
3655 (setq org-agenda-tag-filter nil
3656 org-agenda-category-filter nil))
3657 (put 'org-agenda-tag-filter :preset-filter
3658 org-agenda-tag-filter-preset)
3659 (put 'org-agenda-category-filter :preset-filter
3660 org-agenda-category-filter-preset)
3661 (if org-agenda-multi
3662 (progn
3663 (setq buffer-read-only nil)
3664 (goto-char (point-max))
3665 (unless (or (bobp) org-agenda-compact-blocks
3666 (not org-agenda-block-separator))
3667 (insert "\n"
3668 (if (stringp org-agenda-block-separator)
3669 org-agenda-block-separator
3670 (make-string (window-width) org-agenda-block-separator))
3671 "\n"))
3672 (narrow-to-region (point) (point-max)))
3673 (setq org-done-keywords-for-agenda nil)
3675 ;; Setting any org variables that are in org-agenda-local-vars
3676 ;; list need to be done after the prepare call
3677 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3678 (setq buffer-read-only nil)
3679 (org-agenda-reset-markers)
3680 (let ((inhibit-read-only t)) (erase-buffer))
3681 (org-agenda-mode)
3682 (setq org-agenda-buffer (current-buffer))
3683 (setq org-agenda-contributing-files nil)
3684 (setq org-agenda-columns-active nil)
3685 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3686 (setq org-todo-keywords-for-agenda
3687 (org-uniquify org-todo-keywords-for-agenda))
3688 (setq org-done-keywords-for-agenda
3689 (org-uniquify org-done-keywords-for-agenda))
3690 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3691 (setq org-agenda-last-prefix-arg current-prefix-arg)
3692 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3693 (and name (not org-agenda-name)
3694 (org-set-local 'org-agenda-name name)))
3695 (setq buffer-read-only nil)))
3697 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3698 (defun org-agenda-finalize ()
3699 "Finishing touch for the agenda buffer, called just before displaying it."
3700 (unless org-agenda-multi
3701 (save-excursion
3702 (let ((inhibit-read-only t))
3703 (goto-char (point-min))
3704 (save-excursion
3705 (while (org-activate-bracket-links (point-max))
3706 (add-text-properties (match-beginning 0) (match-end 0)
3707 '(face org-link))))
3708 (save-excursion
3709 (while (org-activate-plain-links (point-max))
3710 (add-text-properties (match-beginning 0) (match-end 0)
3711 '(face org-link))))
3712 (unless (eq org-agenda-remove-tags t)
3713 (org-agenda-align-tags))
3714 (unless org-agenda-with-colors
3715 (remove-text-properties (point-min) (point-max) '(face nil)))
3716 (if (and (boundp 'org-agenda-overriding-columns-format)
3717 org-agenda-overriding-columns-format)
3718 (org-set-local 'org-agenda-overriding-columns-format
3719 org-agenda-overriding-columns-format))
3720 (if (and (boundp 'org-agenda-view-columns-initially)
3721 org-agenda-view-columns-initially)
3722 (org-agenda-columns))
3723 (when org-agenda-fontify-priorities
3724 (org-agenda-fontify-priorities))
3725 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3726 (org-agenda-dim-blocked-tasks))
3727 ;; We need to widen when `org-agenda-finalize' is called from
3728 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3729 (when org-clock-current-task
3730 (save-restriction
3731 (widen)
3732 (org-agenda-mark-clocking-task)))
3733 (when org-agenda-entry-text-mode
3734 (org-agenda-entry-text-hide)
3735 (org-agenda-entry-text-show))
3736 (if (and (functionp 'org-habit-insert-consistency-graphs)
3737 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3738 (org-habit-insert-consistency-graphs))
3739 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3740 (unless (or (eq org-agenda-show-inherited-tags 'always)
3741 (and (listp org-agenda-show-inherited-tags)
3742 (memq org-agenda-type org-agenda-show-inherited-tags))
3743 (and (eq org-agenda-show-inherited-tags t)
3744 (or (eq org-agenda-use-tag-inheritance t)
3745 (and (listp org-agenda-use-tag-inheritance)
3746 (not (memq org-agenda-type
3747 org-agenda-use-tag-inheritance))))))
3748 (let (mrk)
3749 (save-excursion
3750 (goto-char (point-min))
3751 (while (equal (forward-line) 0)
3752 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3753 (get-text-property (point) 'org-hd-marker)))
3754 (put-text-property (point-at-bol) (point-at-eol)
3755 'tags (org-with-point-at mrk
3756 (delete-dups
3757 (mapcar 'downcase (org-get-tags-at))))))))))
3758 (run-hooks 'org-agenda-finalize-hook)
3759 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3760 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3761 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3762 (org-agenda-filter-apply org-agenda-category-filter 'category))
3763 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3765 (defun org-agenda-mark-clocking-task ()
3766 "Mark the current clock entry in the agenda if it is present."
3767 (org-agenda-unmark-clocking-task)
3768 (when (marker-buffer org-clock-hd-marker)
3769 (save-excursion
3770 (goto-char (point-min))
3771 (let (s ov)
3772 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3773 (goto-char s)
3774 (when (equal (org-get-at-bol 'org-hd-marker)
3775 org-clock-hd-marker)
3776 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3777 (overlay-put ov 'type 'org-agenda-clocking)
3778 (overlay-put ov 'face 'org-agenda-clocking)
3779 (overlay-put ov 'help-echo
3780 "The clock is running in this item")))))))
3782 (defun org-agenda-unmark-clocking-task ()
3783 "Unmark the current clocking task."
3784 (mapc (lambda (o)
3785 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3786 (delete-overlay o)))
3787 (overlays-in (point-min) (point-max))))
3789 (defun org-agenda-fontify-priorities ()
3790 "Make highest priority lines bold, and lowest italic."
3791 (interactive)
3792 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3793 (delete-overlay o)))
3794 (overlays-in (point-min) (point-max)))
3795 (save-excursion
3796 (let (b e p ov h l)
3797 (goto-char (point-min))
3798 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3799 (setq h (or (get-char-property (point) 'org-highest-priority)
3800 org-highest-priority)
3801 l (or (get-char-property (point) 'org-lowest-priority)
3802 org-lowest-priority)
3803 p (string-to-char (match-string 1))
3804 b (match-beginning 0)
3805 e (if (eq org-agenda-fontify-priorities 'cookies)
3806 (match-end 0)
3807 (point-at-eol))
3808 ov (make-overlay b e))
3809 (overlay-put
3810 ov 'face
3811 (cons (cond ((org-face-from-face-or-color
3812 'priority nil
3813 (cdr (assoc p org-priority-faces))))
3814 ((and (listp org-agenda-fontify-priorities)
3815 (org-face-from-face-or-color
3816 'priority nil
3817 (cdr (assoc p org-agenda-fontify-priorities)))))
3818 ((equal p l) 'italic)
3819 ((equal p h) 'bold))
3820 'org-priority))
3821 (overlay-put ov 'org-type 'org-priority)))))
3823 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3824 (interactive "P")
3825 "Dim currently blocked TODO's in the agenda display."
3826 (message "Dim or hide blocked tasks...")
3827 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3828 (delete-overlay o)))
3829 (overlays-in (point-min) (point-max)))
3830 (save-excursion
3831 (let ((inhibit-read-only t)
3832 (org-depend-tag-blocked nil)
3833 (invis (or (not (null invisible))
3834 (eq org-agenda-dim-blocked-tasks 'invisible)))
3835 org-blocked-by-checkboxes
3836 invis1 b e p ov h l)
3837 (goto-char (point-min))
3838 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3839 (and pos (goto-char (1+ pos))))
3840 (setq org-blocked-by-checkboxes nil invis1 invis)
3841 (let ((marker (org-get-at-bol 'org-hd-marker)))
3842 (when (and marker
3843 (with-current-buffer (marker-buffer marker)
3844 (save-excursion (goto-char marker)
3845 (org-entry-blocked-p))))
3846 (if org-blocked-by-checkboxes (setq invis1 nil))
3847 (setq b (if invis1
3848 (max (point-min) (1- (point-at-bol)))
3849 (point-at-bol))
3850 e (point-at-eol)
3851 ov (make-overlay b e))
3852 (if invis1
3853 (overlay-put ov 'invisible t)
3854 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3855 (overlay-put ov 'org-type 'org-blocked-todo))))))
3856 (message "Dim or hide blocked tasks...done"))
3858 (defvar org-agenda-skip-function nil
3859 "Function to be called at each match during agenda construction.
3860 If this function returns nil, the current match should not be skipped.
3861 Otherwise, the function must return a position from where the search
3862 should be continued.
3863 This may also be a Lisp form, it will be evaluated.
3864 Never set this variable using `setq' or so, because then it will apply
3865 to all future agenda commands. If you do want a global skipping condition,
3866 use the option `org-agenda-skip-function-global' instead.
3867 The correct usage for `org-agenda-skip-function' is to bind it with
3868 `let' to scope it dynamically into the agenda-constructing command.
3869 A good way to set it is through options in `org-agenda-custom-commands'.")
3871 (defun org-agenda-skip ()
3872 "Throw to `:skip' in places that should be skipped.
3873 Also moves point to the end of the skipped region, so that search can
3874 continue from there."
3875 (let ((p (point-at-bol)) to)
3876 (when (or
3877 (save-excursion (goto-char p) (looking-at comment-start-skip))
3878 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3879 (get-text-property p :org-archived)
3880 (org-end-of-subtree t))
3881 (and org-agenda-skip-comment-trees
3882 (get-text-property p :org-comment)
3883 (org-end-of-subtree t))
3884 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3885 (org-agenda-skip-eval org-agenda-skip-function)))
3886 (goto-char to))
3887 (org-in-src-block-p t))
3888 (throw :skip t))))
3890 (defun org-agenda-skip-eval (form)
3891 "If FORM is a function or a list, call (or eval) is and return result.
3892 `save-excursion' and `save-match-data' are wrapped around the call, so point
3893 and match data are returned to the previous state no matter what these
3894 functions do."
3895 (let (fp)
3896 (and form
3897 (or (setq fp (functionp form))
3898 (consp form))
3899 (save-excursion
3900 (save-match-data
3901 (if fp
3902 (funcall form)
3903 (eval form)))))))
3905 (defvar org-agenda-markers nil
3906 "List of all currently active markers created by `org-agenda'.")
3907 (defvar org-agenda-last-marker-time (org-float-time)
3908 "Creation time of the last agenda marker.")
3910 (defun org-agenda-new-marker (&optional pos)
3911 "Return a new agenda marker.
3912 Org-mode keeps a list of these markers and resets them when they are
3913 no longer in use."
3914 (let ((m (copy-marker (or pos (point)))))
3915 (setq org-agenda-last-marker-time (org-float-time))
3916 (if org-agenda-buffer
3917 (with-current-buffer org-agenda-buffer
3918 (push m org-agenda-markers))
3919 (push m org-agenda-markers))
3922 (defun org-agenda-reset-markers ()
3923 "Reset markers created by `org-agenda'."
3924 (while org-agenda-markers
3925 (move-marker (pop org-agenda-markers) nil)))
3927 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3928 "Save relative positions of markers in region.
3929 This check for agenda markers in all agenda buffers currently active."
3930 (dolist (buf (buffer-list))
3931 (with-current-buffer buf
3932 (when (eq major-mode 'org-agenda-mode)
3933 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3934 org-agenda-markers)))))
3936 ;;; Entry text mode
3938 (defun org-agenda-entry-text-show-here ()
3939 "Add some text from the entry as context to the current line."
3940 (let (m txt o)
3941 (setq m (org-get-at-bol 'org-hd-marker))
3942 (unless (marker-buffer m)
3943 (error "No marker points to an entry here"))
3944 (setq txt (concat "\n" (org-no-properties
3945 (org-agenda-get-some-entry-text
3946 m org-agenda-entry-text-maxlines " > "))))
3947 (when (string-match "\\S-" txt)
3948 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3949 (overlay-put o 'evaporate t)
3950 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3951 (overlay-put o 'after-string txt))))
3953 (defun org-agenda-entry-text-show ()
3954 "Add entry context for all agenda lines."
3955 (interactive)
3956 (save-excursion
3957 (goto-char (point-max))
3958 (beginning-of-line 1)
3959 (while (not (bobp))
3960 (when (org-get-at-bol 'org-hd-marker)
3961 (org-agenda-entry-text-show-here))
3962 (beginning-of-line 0))))
3964 (defun org-agenda-entry-text-hide ()
3965 "Remove any shown entry context."
3966 (delq nil
3967 (mapcar (lambda (o)
3968 (if (eq (overlay-get o 'org-overlay-type)
3969 'agenda-entry-content)
3970 (progn (delete-overlay o) t)))
3971 (overlays-in (point-min) (point-max)))))
3973 (defun org-agenda-get-day-face (date)
3974 "Return the face DATE should be displayed with."
3975 (or (and (functionp org-agenda-day-face-function)
3976 (funcall org-agenda-day-face-function date))
3977 (cond ((org-agenda-todayp date)
3978 'org-agenda-date-today)
3979 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3980 'org-agenda-date-weekend)
3981 (t 'org-agenda-date))))
3983 ;;; Agenda timeline
3985 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3987 (defun org-timeline (&optional dotodo)
3988 "Show a time-sorted view of the entries in the current org file.
3989 Only entries with a time stamp of today or later will be listed. With
3990 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3991 under the current date.
3992 If the buffer contains an active region, only check the region for
3993 dates."
3994 (interactive "P")
3995 (let* ((dopast t)
3996 (org-agenda-show-log-scoped org-agenda-show-log)
3997 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3998 (current-buffer))))
3999 (date (calendar-current-date))
4000 (beg (if (org-region-active-p) (region-beginning) (point-min)))
4001 (end (if (org-region-active-p) (region-end) (point-max)))
4002 (day-numbers (org-get-all-dates
4003 beg end 'no-ranges
4004 t org-agenda-show-log-scoped ; always include today
4005 org-timeline-show-empty-dates))
4006 (org-deadline-warning-days 0)
4007 (org-agenda-only-exact-dates t)
4008 (today (org-today))
4009 (past t)
4010 args
4011 s e rtn d emptyp)
4012 (setq org-agenda-redo-command
4013 (list 'progn
4014 (list 'org-switch-to-buffer-other-window (current-buffer))
4015 (list 'org-timeline (list 'quote dotodo))))
4016 (if (not dopast)
4017 ;; Remove past dates from the list of dates.
4018 (setq day-numbers (delq nil (mapcar (lambda(x)
4019 (if (>= x today) x nil))
4020 day-numbers))))
4021 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
4022 (org-compile-prefix-format 'timeline)
4023 (org-set-sorting-strategy 'timeline)
4024 (if org-agenda-show-log-scoped (push :closed args))
4025 (push :timestamp args)
4026 (push :deadline args)
4027 (push :scheduled args)
4028 (push :sexp args)
4029 (if dotodo (push :todo args))
4030 (insert "Timeline of file " entry "\n")
4031 (add-text-properties (point-min) (point)
4032 (list 'face 'org-agenda-structure))
4033 (org-agenda-mark-header-line (point-min))
4034 (while (setq d (pop day-numbers))
4035 (if (and (listp d) (eq (car d) :omitted))
4036 (progn
4037 (setq s (point))
4038 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
4039 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
4040 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
4041 (if (and (>= d today)
4042 dopast
4043 past)
4044 (progn
4045 (setq past nil)
4046 (insert (make-string 79 ?-) "\n")))
4047 (setq date (calendar-gregorian-from-absolute d))
4048 (setq s (point))
4049 (setq rtn (and (not emptyp)
4050 (apply 'org-agenda-get-day-entries entry
4051 date args)))
4052 (if (or rtn (equal d today) org-timeline-show-empty-dates)
4053 (progn
4054 (insert
4055 (if (stringp org-agenda-format-date)
4056 (format-time-string org-agenda-format-date
4057 (org-time-from-absolute date))
4058 (funcall org-agenda-format-date date))
4059 "\n")
4060 (put-text-property s (1- (point)) 'face
4061 (org-agenda-get-day-face date))
4062 (put-text-property s (1- (point)) 'org-date-line t)
4063 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4064 (if (equal d today)
4065 (put-text-property s (1- (point)) 'org-today t))
4066 (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
4067 (put-text-property s (1- (point)) 'day d)))))
4068 (goto-char (point-min))
4069 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
4070 (point-min)))
4071 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
4072 (org-agenda-finalize)
4073 (setq buffer-read-only t)))
4075 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
4076 "Return a list of all relevant day numbers from BEG to END buffer positions.
4077 If NO-RANGES is non-nil, include only the start and end dates of a range,
4078 not every single day in the range. If FORCE-TODAY is non-nil, make
4079 sure that TODAY is included in the list. If INACTIVE is non-nil, also
4080 inactive time stamps (those in square brackets) are included.
4081 When EMPTY is non-nil, also include days without any entries."
4082 (let ((re (concat
4083 (if pre-re pre-re "")
4084 (if inactive org-ts-regexp-both org-ts-regexp)))
4085 dates dates1 date day day1 day2 ts1 ts2 pos)
4086 (if force-today
4087 (setq dates (list (org-today))))
4088 (save-excursion
4089 (goto-char beg)
4090 (while (re-search-forward re end t)
4091 (setq day (time-to-days (org-time-string-to-time
4092 (substring (match-string 1) 0 10)
4093 (current-buffer) (match-beginning 0))))
4094 (or (memq day dates) (push day dates)))
4095 (unless no-ranges
4096 (goto-char beg)
4097 (while (re-search-forward org-tr-regexp end t)
4098 (setq pos (match-beginning 0))
4099 (setq ts1 (substring (match-string 1) 0 10)
4100 ts2 (substring (match-string 2) 0 10)
4101 day1 (time-to-days (org-time-string-to-time
4102 ts1 (current-buffer) pos))
4103 day2 (time-to-days (org-time-string-to-time
4104 ts2 (current-buffer) pos)))
4105 (while (< (setq day1 (1+ day1)) day2)
4106 (or (memq day1 dates) (push day1 dates)))))
4107 (setq dates (sort dates '<))
4108 (when empty
4109 (while (setq day (pop dates))
4110 (setq day2 (car dates))
4111 (push day dates1)
4112 (when (and day2 empty)
4113 (if (or (eq empty t)
4114 (and (numberp empty) (<= (- day2 day) empty)))
4115 (while (< (setq day (1+ day)) day2)
4116 (push (list day) dates1))
4117 (push (cons :omitted (- day2 day)) dates1))))
4118 (setq dates (nreverse dates1)))
4119 dates)))
4121 ;;; Agenda Daily/Weekly
4123 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4124 "Start day for the agenda view.
4125 Custom commands can set this variable in the options section.
4126 See the docstring of `org-read-date' on allowed values.")
4127 (defvar org-starting-day nil) ; local variable in the agenda buffer
4128 (defvar org-arg-loc nil) ; local variable
4130 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4131 "List of types searched for when creating the daily/weekly agenda.
4132 This variable is a list of symbols that controls the types of
4133 items that appear in the daily/weekly agenda. Allowed symbols in this
4134 list are are
4136 :timestamp List items containing a date stamp or date range matching
4137 the selected date. This includes sexp entries in
4138 angular brackets.
4140 :sexp List entries resulting from plain diary-like sexps.
4142 :deadline List deadline due on that date. When the date is today,
4143 also list any deadlines past due, or due within
4144 `org-deadline-warning-days'. `:deadline' must appear before
4145 `:scheduled' if the setting of
4146 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4147 any effect.
4149 :scheduled List all items which are scheduled for the given date.
4150 The diary for *today* also contains items which were
4151 scheduled earlier and are not yet marked DONE.
4153 By default, all four types are turned on.
4155 Never set this variable globally using `setq', because then it
4156 will apply to all future agenda commands. Instead, bind it with
4157 `let' to scope it dynamically into the agenda-constructing
4158 command. A good way to set it is through options in
4159 `org-agenda-custom-commands'. For a more flexible (though
4160 somewhat less efficient) way of determining what is included in
4161 the daily/weekly agenda, see `org-agenda-skip-function'.")
4163 (defvar org-agenda-buffer-tmp-name nil)
4164 ;;;###autoload
4165 (defun org-agenda-list (&optional arg start-day span)
4166 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4167 The view will be for the current day or week, but from the overview buffer
4168 you will be able to go to other days/weeks.
4170 With a numeric prefix argument in an interactive call, the agenda will
4171 span ARG days. Lisp programs should instead specify SPAN to change
4172 the number of days. SPAN defaults to `org-agenda-span'.
4174 START-DAY defaults to TODAY, or to the most recent match for the weekday
4175 given in `org-agenda-start-on-weekday'."
4176 (interactive "P")
4177 (if org-agenda-overriding-arguments
4178 (setq arg (car org-agenda-overriding-arguments)
4179 start-day (nth 1 org-agenda-overriding-arguments)
4180 span (nth 2 org-agenda-overriding-arguments)))
4181 (if (and (integerp arg) (> arg 0))
4182 (setq span arg arg nil))
4183 (catch 'exit
4184 (setq org-agenda-buffer-name
4185 (or org-agenda-buffer-tmp-name
4186 (if org-agenda-sticky
4187 (cond ((and org-keys (stringp org-match))
4188 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4189 (org-keys
4190 (format "*Org Agenda(%s)*" org-keys))
4191 (t "*Org Agenda(a)*")))
4192 org-agenda-buffer-name))
4193 (org-agenda-prepare "Day/Week")
4194 (setq start-day (or start-day org-agenda-start-day))
4195 (if (stringp start-day)
4196 ;; Convert to an absolute day number
4197 (setq start-day (time-to-days (org-read-date nil t start-day))))
4198 (org-compile-prefix-format 'agenda)
4199 (org-set-sorting-strategy 'agenda)
4200 (let* ((span (org-agenda-ndays-to-span
4201 (or span org-agenda-ndays org-agenda-span)))
4202 (today (org-today))
4203 (sd (or start-day today))
4204 (ndays (org-agenda-span-to-ndays span sd))
4205 (org-agenda-start-on-weekday
4206 (if (eq ndays 7)
4207 org-agenda-start-on-weekday))
4208 (thefiles (org-agenda-files nil 'ifmode))
4209 (files thefiles)
4210 (start (if (or (null org-agenda-start-on-weekday)
4211 (< ndays 7))
4213 (let* ((nt (calendar-day-of-week
4214 (calendar-gregorian-from-absolute sd)))
4215 (n1 org-agenda-start-on-weekday)
4216 (d (- nt n1)))
4217 (- sd (+ (if (< d 0) 7 0) d)))))
4218 (day-numbers (list start))
4219 (day-cnt 0)
4220 (inhibit-redisplay (not debug-on-error))
4221 (org-agenda-show-log-scoped org-agenda-show-log)
4222 s e rtn rtnall file date d start-pos end-pos todayp
4223 clocktable-start clocktable-end filter)
4224 (setq org-agenda-redo-command
4225 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4226 (dotimes (n (1- ndays))
4227 (push (1+ (car day-numbers)) day-numbers))
4228 (setq day-numbers (nreverse day-numbers))
4229 (setq clocktable-start (car day-numbers)
4230 clocktable-end (1+ (or (org-last day-numbers) 0)))
4231 (org-set-local 'org-starting-day (car day-numbers))
4232 (org-set-local 'org-arg-loc arg)
4233 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4234 (unless org-agenda-compact-blocks
4235 (let* ((d1 (car day-numbers))
4236 (d2 (org-last day-numbers))
4237 (w1 (org-days-to-iso-week d1))
4238 (w2 (org-days-to-iso-week d2)))
4239 (setq s (point))
4240 (if org-agenda-overriding-header
4241 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4242 nil 'face 'org-agenda-structure) "\n")
4243 (insert (org-agenda-span-name span)
4244 "-agenda"
4245 (if (< (- d2 d1) 350)
4246 (if (= w1 w2)
4247 (format " (W%02d)" w1)
4248 (format " (W%02d-W%02d)" w1 w2))
4250 ":\n")))
4251 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4252 'org-date-line t))
4253 (org-agenda-mark-header-line s))
4254 (while (setq d (pop day-numbers))
4255 (setq date (calendar-gregorian-from-absolute d)
4256 s (point))
4257 (if (or (setq todayp (= d today))
4258 (and (not start-pos) (= d sd)))
4259 (setq start-pos (point))
4260 (if (and start-pos (not end-pos))
4261 (setq end-pos (point))))
4262 (setq files thefiles
4263 rtnall nil)
4264 (while (setq file (pop files))
4265 (catch 'nextfile
4266 (org-check-agenda-file file)
4267 (let ((org-agenda-entry-types org-agenda-entry-types))
4268 (unless org-agenda-include-deadlines
4269 (setq org-agenda-entry-types
4270 (delq :deadline org-agenda-entry-types)))
4271 (cond
4272 ((memq org-agenda-show-log-scoped '(only clockcheck))
4273 (setq rtn (org-agenda-get-day-entries
4274 file date :closed)))
4275 (org-agenda-show-log-scoped
4276 (setq rtn (apply 'org-agenda-get-day-entries
4277 file date
4278 (append '(:closed) org-agenda-entry-types))))
4280 (setq rtn (apply 'org-agenda-get-day-entries
4281 file date
4282 org-agenda-entry-types)))))
4283 (setq rtnall (append rtnall rtn)))) ;; all entries
4284 (if org-agenda-include-diary
4285 (let ((org-agenda-search-headline-for-time t))
4286 (require 'diary-lib)
4287 (setq rtn (org-get-entries-from-diary date))
4288 (setq rtnall (append rtnall rtn))))
4289 (if (or rtnall org-agenda-show-all-dates)
4290 (progn
4291 (setq day-cnt (1+ day-cnt))
4292 (insert
4293 (if (stringp org-agenda-format-date)
4294 (format-time-string org-agenda-format-date
4295 (org-time-from-absolute date))
4296 (funcall org-agenda-format-date date))
4297 "\n")
4298 (put-text-property s (1- (point)) 'face
4299 (org-agenda-get-day-face date))
4300 (put-text-property s (1- (point)) 'org-date-line t)
4301 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4302 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4303 (when todayp
4304 (put-text-property s (1- (point)) 'org-today t))
4305 (setq rtnall
4306 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4307 (if rtnall (insert ;; all entries
4308 (org-agenda-finalize-entries rtnall 'agenda)
4309 "\n"))
4310 (put-text-property s (1- (point)) 'day d)
4311 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4312 (when (and org-agenda-clockreport-mode clocktable-start)
4313 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4314 ;; the above line is to ensure the restricted range!
4315 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4316 tbl)
4317 (setq p (org-plist-delete p :block))
4318 (setq p (plist-put p :tstart clocktable-start))
4319 (setq p (plist-put p :tend clocktable-end))
4320 (setq p (plist-put p :scope 'agenda))
4321 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4322 (setq filter (or org-agenda-tag-filter-while-redo
4323 (get 'org-agenda-tag-filter :preset-filter))))
4324 (setq p (plist-put p :tags (mapconcat (lambda (x)
4325 (if (string-match "[<>=]" x)
4328 filter ""))))
4329 (setq tbl (apply 'org-clock-get-clocktable p))
4330 (insert tbl)))
4331 (goto-char (point-min))
4332 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4333 (unless (and (pos-visible-in-window-p (point-min))
4334 (pos-visible-in-window-p (point-max)))
4335 (goto-char (1- (point-max)))
4336 (recenter -1)
4337 (if (not (pos-visible-in-window-p (or start-pos 1)))
4338 (progn
4339 (goto-char (or start-pos 1))
4340 (recenter 1))))
4341 (goto-char (or start-pos 1))
4342 (add-text-properties (point-min) (point-max)
4343 `(org-agenda-type agenda
4344 org-last-args (,arg ,start-day ,span)
4345 org-redo-cmd ,org-agenda-redo-command
4346 org-series-cmd ,org-cmd))
4347 (if (eq org-agenda-show-log-scoped 'clockcheck)
4348 (org-agenda-show-clocking-issues))
4349 (org-agenda-finalize)
4350 (setq buffer-read-only t)
4351 (message ""))))
4353 (autoload 'org-agenda-list "org-agenda" "\
4354 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4355 The view will be for the current day or week, but from the overview buffer
4356 you will be able to go to other days/weeks.
4358 With a numeric prefix argument in an interactive call, the agenda will
4359 span ARG days. Lisp programs should instead specify SPAN to change
4360 the number of days. SPAN defaults to `org-agenda-span'.
4362 START-DAY defaults to TODAY, or to the most recent match for the weekday
4363 given in `org-agenda-start-on-weekday'.
4365 \(fn &optional ARG START-DAY SPAN)" t nil)
4367 (defun org-agenda-ndays-to-span (n)
4368 "Return a span symbol for a span of N days, or N if none matches."
4369 (cond ((symbolp n) n)
4370 ((= n 1) 'day)
4371 ((= n 7) 'week)
4372 (t n)))
4374 (defun org-agenda-span-to-ndays (span &optional start-day)
4375 "Return ndays from SPAN, possibly starting at START-DAY."
4376 (cond ((numberp span) span)
4377 ((eq span 'day) 1)
4378 ((eq span 'week) 7)
4379 ((eq span 'month)
4380 (let ((date (calendar-gregorian-from-absolute start-day)))
4381 (calendar-last-day-of-month (car date) (caddr date))))
4382 ((eq span 'year)
4383 (let ((date (calendar-gregorian-from-absolute start-day)))
4384 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4386 (defun org-agenda-span-name (span)
4387 "Return a SPAN name."
4388 (if (null span)
4390 (if (symbolp span)
4391 (capitalize (symbol-name span))
4392 (format "%d days" span))))
4394 ;;; Agenda word search
4396 (defvar org-agenda-search-history nil)
4398 (defvar org-search-syntax-table nil
4399 "Special syntax table for org-mode search.
4400 In this table, we have single quotes not as word constituents, to
4401 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4403 (defvar org-mode-syntax-table) ; From org.el
4404 (defun org-search-syntax-table ()
4405 (unless org-search-syntax-table
4406 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4407 (modify-syntax-entry ?' "." org-search-syntax-table)
4408 (modify-syntax-entry ?` "." org-search-syntax-table))
4409 org-search-syntax-table)
4411 (defvar org-agenda-last-search-view-search-was-boolean nil)
4413 ;;;###autoload
4414 (defun org-search-view (&optional todo-only string edit-at)
4415 "Show all entries that contain a phrase or words or regular expressions.
4417 With optional prefix argument TODO-ONLY, only consider entries that are
4418 TODO entries. The argument STRING can be used to pass a default search
4419 string into this function. If EDIT-AT is non-nil, it means that the
4420 user should get a chance to edit this string, with cursor at position
4421 EDIT-AT.
4423 The search string can be viewed either as a phrase that should be found as
4424 is, or it can be broken into a number of snippets, each of which must match
4425 in a Boolean way to select an entry. The default depends on the variable
4426 `org-agenda-search-view-always-boolean'.
4427 Even if this is turned off (the default) you can always switch to
4428 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4430 The default is a direct search of the whole phrase, where each space in
4431 the search string can expand to an arbitrary amount of whitespace,
4432 including newlines.
4434 If using a Boolean search, the search string is split on whitespace and
4435 each snippet is searched separately, with logical AND to select an entry.
4436 Words prefixed with a minus must *not* occur in the entry. Words without
4437 a prefix or prefixed with a plus must occur in the entry. Matching is
4438 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4439 match whole words, not parts of a word) if
4440 `org-agenda-search-view-force-full-words' is set (default is nil).
4442 Boolean search snippets enclosed by curly braces are interpreted as
4443 regular expressions that must or (when preceded with \"-\") must not
4444 match in the entry. Snippets enclosed into double quotes will be taken
4445 as a whole, to include whitespace.
4447 - If the search string starts with an asterisk, search only in headlines.
4448 - If (possibly after the leading star) the search string starts with an
4449 exclamation mark, this also means to look at TODO entries only, an effect
4450 that can also be achieved with a prefix argument.
4451 - If (possibly after star and exclamation mark) the search string starts
4452 with a colon, this will mean that the (non-regexp) snippets of the
4453 Boolean search must match as full words.
4455 This command searches the agenda files, and in addition the files listed
4456 in `org-agenda-text-search-extra-files'."
4457 (interactive "P")
4458 (if org-agenda-overriding-arguments
4459 (setq todo-only (car org-agenda-overriding-arguments)
4460 string (nth 1 org-agenda-overriding-arguments)
4461 edit-at (nth 2 org-agenda-overriding-arguments)))
4462 (let* ((props (list 'face nil
4463 'done-face 'org-agenda-done
4464 'org-not-done-regexp org-not-done-regexp
4465 'org-todo-regexp org-todo-regexp
4466 'org-complex-heading-regexp org-complex-heading-regexp
4467 'mouse-face 'highlight
4468 'help-echo (format "mouse-2 or RET jump to location")))
4469 (full-words org-agenda-search-view-force-full-words)
4470 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4471 regexp rtn rtnall files file pos inherited-tags
4472 marker category category-pos level tags c neg re boolean
4473 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4474 (unless (and (not edit-at)
4475 (stringp string)
4476 (string-match "\\S-" string))
4477 (setq string (read-string
4478 (if org-agenda-search-view-always-boolean
4479 "[+-]Word/{Regexp} ...: "
4480 "Phrase or [+-]Word/{Regexp} ...: ")
4481 (cond
4482 ((integerp edit-at) (cons string edit-at))
4483 (edit-at string))
4484 'org-agenda-search-history)))
4485 (catch 'exit
4486 (if org-agenda-sticky
4487 (setq org-agenda-buffer-name
4488 (if (stringp string)
4489 (format "*Org Agenda(%s:%s)*"
4490 (or org-keys (or (and todo-only "S") "s")) string)
4491 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4492 (org-agenda-prepare "SEARCH")
4493 (org-compile-prefix-format 'search)
4494 (org-set-sorting-strategy 'search)
4495 (setq org-agenda-redo-command
4496 (list 'org-search-view (if todo-only t nil)
4497 (list 'if 'current-prefix-arg nil string)))
4498 (setq org-agenda-query-string string)
4499 (if (equal (string-to-char string) ?*)
4500 (setq hdl-only t
4501 words (substring string 1))
4502 (setq words string))
4503 (when (equal (string-to-char words) ?!)
4504 (setq todo-only t
4505 words (substring words 1)))
4506 (when (equal (string-to-char words) ?:)
4507 (setq full-words t
4508 words (substring words 1)))
4509 (if (or org-agenda-search-view-always-boolean
4510 (member (string-to-char words) '(?- ?+ ?\{)))
4511 (setq boolean t))
4512 (setq words (org-split-string words))
4513 (let (www w)
4514 (while (setq w (pop words))
4515 (while (and (string-match "\\\\\\'" w) words)
4516 (setq w (concat (substring w 0 -1) " " (pop words))))
4517 (push w www))
4518 (setq words (nreverse www) www nil)
4519 (while (setq w (pop words))
4520 (when (and (string-match "\\`[-+]?{" w)
4521 (not (string-match "}\\'" w)))
4522 (while (and words (not (string-match "}\\'" (car words))))
4523 (setq w (concat w " " (pop words))))
4524 (setq w (concat w " " (pop words))))
4525 (push w www))
4526 (setq words (nreverse www)))
4527 (setq org-agenda-last-search-view-search-was-boolean boolean)
4528 (when boolean
4529 (let (wds w)
4530 (while (setq w (pop words))
4531 (if (or (equal (substring w 0 1) "\"")
4532 (and (> (length w) 1)
4533 (member (substring w 0 1) '("+" "-"))
4534 (equal (substring w 1 2) "\"")))
4535 (while (and words (not (equal (substring w -1) "\"")))
4536 (setq w (concat w " " (pop words)))))
4537 (and (string-match "\\`\\([-+]?\\)\"" w)
4538 (setq w (replace-match "\\1" nil nil w)))
4539 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4540 (push w wds))
4541 (setq words (nreverse wds))))
4542 (if boolean
4543 (mapc (lambda (w)
4544 (setq c (string-to-char w))
4545 (if (equal c ?-)
4546 (setq neg t w (substring w 1))
4547 (if (equal c ?+)
4548 (setq neg nil w (substring w 1))
4549 (setq neg nil)))
4550 (if (string-match "\\`{.*}\\'" w)
4551 (setq re (substring w 1 -1))
4552 (if full-words
4553 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4554 (setq re (regexp-quote (downcase w)))))
4555 (if neg (push re regexps-) (push re regexps+)))
4556 words)
4557 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4558 regexps+))
4559 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4560 (if (not regexps+)
4561 (setq regexp org-outline-regexp-bol)
4562 (setq regexp (pop regexps+))
4563 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4564 regexp))))
4565 (setq files (org-agenda-files nil 'ifmode))
4566 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4567 (pop org-agenda-text-search-extra-files)
4568 (setq files (org-add-archive-files files)))
4569 (setq files (append files org-agenda-text-search-extra-files)
4570 rtnall nil)
4571 (while (setq file (pop files))
4572 (setq ee nil)
4573 (catch 'nextfile
4574 (org-check-agenda-file file)
4575 (setq buffer (if (file-exists-p file)
4576 (org-get-agenda-file-buffer file)
4577 (error "No such file %s" file)))
4578 (if (not buffer)
4579 ;; If file does not exist, make sure an error message is sent
4580 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4581 file))))
4582 (with-current-buffer buffer
4583 (with-syntax-table (org-search-syntax-table)
4584 (unless (derived-mode-p 'org-mode)
4585 (error "Agenda file %s is not in `org-mode'" file))
4586 (let ((case-fold-search t))
4587 (save-excursion
4588 (save-restriction
4589 (if org-agenda-restrict
4590 (narrow-to-region org-agenda-restrict-begin
4591 org-agenda-restrict-end)
4592 (widen))
4593 (goto-char (point-min))
4594 (unless (or (org-at-heading-p)
4595 (outline-next-heading))
4596 (throw 'nextfile t))
4597 (goto-char (max (point-min) (1- (point))))
4598 (while (re-search-forward regexp nil t)
4599 (org-back-to-heading t)
4600 (while (and org-agenda-search-view-max-outline-level
4601 (> (org-reduced-level (org-outline-level))
4602 org-agenda-search-view-max-outline-level)
4603 (forward-line -1)
4604 (outline-back-to-heading t)))
4605 (skip-chars-forward "* ")
4606 (setq beg (point-at-bol)
4607 beg1 (point)
4608 end (progn
4609 (outline-next-heading)
4610 (while (and org-agenda-search-view-max-outline-level
4611 (> (org-reduced-level (org-outline-level))
4612 org-agenda-search-view-max-outline-level)
4613 (forward-line 1)
4614 (outline-next-heading)))
4615 (point)))
4617 (catch :skip
4618 (goto-char beg)
4619 (org-agenda-skip)
4620 (setq str (buffer-substring-no-properties
4621 (point-at-bol)
4622 (if hdl-only (point-at-eol) end)))
4623 (mapc (lambda (wr) (when (string-match wr str)
4624 (goto-char (1- end))
4625 (throw :skip t)))
4626 regexps-)
4627 (mapc (lambda (wr) (unless (string-match wr str)
4628 (goto-char (1- end))
4629 (throw :skip t)))
4630 (if todo-only
4631 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4632 regexps+)
4633 regexps+))
4634 (goto-char beg)
4635 (setq marker (org-agenda-new-marker (point))
4636 category (org-get-category)
4637 level (make-string (org-reduced-level (org-outline-level)) ? )
4638 category-pos (get-text-property (point) 'org-category-position)
4639 inherited-tags
4640 (or (eq org-agenda-show-inherited-tags 'always)
4641 (and (listp org-agenda-show-inherited-tags)
4642 (memq 'todo org-agenda-show-inherited-tags))
4643 (and (eq org-agenda-show-inherited-tags t)
4644 (or (eq org-agenda-use-tag-inheritance t)
4645 (memq 'todo org-agenda-use-tag-inheritance))))
4646 tags (org-get-tags-at nil (not inherited-tags))
4647 txt (org-agenda-format-item
4649 (buffer-substring-no-properties
4650 beg1 (point-at-eol))
4651 level category tags t))
4652 (org-add-props txt props
4653 'org-marker marker 'org-hd-marker marker
4654 'org-todo-regexp org-todo-regexp
4655 'level level
4656 'org-complex-heading-regexp org-complex-heading-regexp
4657 'priority 1000 'org-category category
4658 'org-category-position category-pos
4659 'type "search")
4660 (push txt ee)
4661 (goto-char (1- end))))))))))
4662 (setq rtn (nreverse ee))
4663 (setq rtnall (append rtnall rtn)))
4664 (if org-agenda-overriding-header
4665 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4666 nil 'face 'org-agenda-structure) "\n")
4667 (insert "Search words: ")
4668 (add-text-properties (point-min) (1- (point))
4669 (list 'face 'org-agenda-structure))
4670 (setq pos (point))
4671 (insert string "\n")
4672 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4673 (setq pos (point))
4674 (unless org-agenda-multi
4675 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4676 (add-text-properties pos (1- (point))
4677 (list 'face 'org-agenda-structure))))
4678 (org-agenda-mark-header-line (point-min))
4679 (when rtnall
4680 (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
4681 (goto-char (point-min))
4682 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4683 (add-text-properties (point-min) (point-max)
4684 `(org-agenda-type search
4685 org-last-args (,todo-only ,string ,edit-at)
4686 org-redo-cmd ,org-agenda-redo-command
4687 org-series-cmd ,org-cmd))
4688 (org-agenda-finalize)
4689 (setq buffer-read-only t))))
4691 (autoload 'org-search-view "org-agenda" "\
4692 Show all entries that contain a phrase or words or regular expressions.
4694 With optional prefix argument TODO-ONLY, only consider entries that are
4695 TODO entries. The argument STRING can be used to pass a default search
4696 string into this function. If EDIT-AT is non-nil, it means that the
4697 user should get a chance to edit this string, with cursor at position
4698 EDIT-AT.
4700 The search string can be viewed either as a phrase that should be found as
4701 is, or it can be broken into a number of snippets, each of which must match
4702 in a Boolean way to select an entry. The default depends on the variable
4703 `org-agenda-search-view-always-boolean'.
4704 Even if this is turned off (the default) you can always switch to
4705 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4707 The default is a direct search of the whole phrase, where each space in
4708 the search string can expand to an arbitrary amount of whitespace,
4709 including newlines.
4711 If using a Boolean search, the search string is split on whitespace and
4712 each snippet is searched separately, with logical AND to select an entry.
4713 Words prefixed with a minus must *not* occur in the entry. Words without
4714 a prefix or prefixed with a plus must occur in the entry. Matching is
4715 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4716 match whole words, not parts of a word) if
4717 `org-agenda-search-view-force-full-words' is set (default is nil).
4719 Boolean search snippets enclosed by curly braces are interpreted as
4720 regular expressions that must or (when preceded with \"-\") must not
4721 match in the entry. Snippets enclosed into double quotes will be taken
4722 as a whole, to include whitespace.
4724 - If the search string starts with an asterisk, search only in headlines.
4725 - If (possibly after the leading star) the search string starts with an
4726 exclamation mark, this also means to look at TODO entries only, an effect
4727 that can also be achieved with a prefix argument.
4728 - If (possibly after star and exclamation mark) the search string starts
4729 with a colon, this will mean that the (non-regexp) snippets of the
4730 Boolean search must match as full words.
4732 This command searches the agenda files, and in addition the files listed
4733 in `org-agenda-text-search-extra-files'.
4735 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4737 ;;; Agenda TODO list
4739 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4740 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4741 (concat
4742 (if (or (equal keywords "ALL") (not keywords))
4743 (propertize "ALL" 'face 'warning)
4744 (mapconcat
4745 (lambda (kw)
4746 (propertize kw 'face (org-get-todo-face kw)))
4747 (org-split-string keywords "|")
4748 "|"))
4749 "\n"))
4751 (defvar org-select-this-todo-keyword nil)
4752 (defvar org-last-arg nil)
4754 ;;;###autoload
4755 (defun org-todo-list (&optional arg)
4756 "Show all (not done) TODO entries from all agenda file in a single list.
4757 The prefix arg can be used to select a specific TODO keyword and limit
4758 the list to these. When using \\[universal-argument], you will be prompted
4759 for a keyword. A numeric prefix directly selects the Nth keyword in
4760 `org-todo-keywords-1'."
4761 (interactive "P")
4762 (if org-agenda-overriding-arguments
4763 (setq arg org-agenda-overriding-arguments))
4764 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4765 (let* ((today (org-today))
4766 (date (calendar-gregorian-from-absolute today))
4767 (kwds org-todo-keywords-for-agenda)
4768 (completion-ignore-case t)
4769 (org-select-this-todo-keyword
4770 (if (stringp arg) arg
4771 (and arg (integerp arg) (> arg 0)
4772 (nth (1- arg) kwds))))
4773 rtn rtnall files file pos)
4774 (when (equal arg '(4))
4775 (setq org-select-this-todo-keyword
4776 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4777 (mapcar 'list kwds) nil nil)))
4778 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4779 (catch 'exit
4780 (if org-agenda-sticky
4781 (setq org-agenda-buffer-name
4782 (if (stringp org-select-this-todo-keyword)
4783 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4784 org-select-this-todo-keyword)
4785 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4786 (org-agenda-prepare "TODO")
4787 (org-compile-prefix-format 'todo)
4788 (org-set-sorting-strategy 'todo)
4789 (setq org-agenda-redo-command
4790 `(org-todo-list (or (and (numberp current-prefix-arg)
4791 current-prefix-arg)
4792 ,org-select-this-todo-keyword
4793 current-prefix-arg ,arg)))
4794 (setq files (org-agenda-files nil 'ifmode)
4795 rtnall nil)
4796 (while (setq file (pop files))
4797 (catch 'nextfile
4798 (org-check-agenda-file file)
4799 (setq rtn (org-agenda-get-day-entries file date :todo))
4800 (setq rtnall (append rtnall rtn))))
4801 (if org-agenda-overriding-header
4802 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4803 nil 'face 'org-agenda-structure) "\n")
4804 (insert "Global list of TODO items of type: ")
4805 (add-text-properties (point-min) (1- (point))
4806 (list 'face 'org-agenda-structure
4807 'short-heading
4808 (concat "ToDo: "
4809 (or org-select-this-todo-keyword "ALL"))))
4810 (org-agenda-mark-header-line (point-min))
4811 (insert (org-agenda-propertize-selected-todo-keywords
4812 org-select-this-todo-keyword))
4813 (setq pos (point))
4814 (unless org-agenda-multi
4815 (insert "Available with `N r': (0)[ALL]")
4816 (let ((n 0) s)
4817 (mapc (lambda (x)
4818 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4819 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4820 (insert "\n "))
4821 (insert " " s))
4822 kwds))
4823 (insert "\n"))
4824 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4825 (org-agenda-mark-header-line (point-min))
4826 (when rtnall
4827 (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
4828 (goto-char (point-min))
4829 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4830 (add-text-properties (point-min) (point-max)
4831 `(org-agenda-type todo
4832 org-last-args ,arg
4833 org-redo-cmd ,org-agenda-redo-command
4834 org-series-cmd ,org-cmd))
4835 (org-agenda-finalize)
4836 (setq buffer-read-only t))))
4838 (autoload 'org-todo-list "org-agenda" "\
4839 Show all (not done) TODO entries from all agenda file in a single list.
4840 The prefix arg can be used to select a specific TODO keyword and limit
4841 the list to these. When using \\[universal-argument], you will be prompted
4842 for a keyword. A numeric prefix directly selects the Nth keyword in
4843 `org-todo-keywords-1'.
4845 \(fn &optional ARG)" t nil)
4847 ;;; Agenda tags match
4849 ;;;###autoload
4850 (defun org-tags-view (&optional todo-only match)
4851 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4852 The prefix arg TODO-ONLY limits the search to TODO entries."
4853 (interactive "P")
4854 (if org-agenda-overriding-arguments
4855 (setq todo-only (car org-agenda-overriding-arguments)
4856 match (nth 1 org-agenda-overriding-arguments)))
4857 (let* ((org-tags-match-list-sublevels
4858 org-tags-match-list-sublevels)
4859 (completion-ignore-case t)
4860 rtn rtnall files file pos matcher
4861 buffer)
4862 (when (and (stringp match) (not (string-match "\\S-" match)))
4863 (setq match nil))
4864 (setq matcher (org-make-tags-matcher match)
4865 match (car matcher) matcher (cdr matcher))
4866 (catch 'exit
4867 (if org-agenda-sticky
4868 (setq org-agenda-buffer-name
4869 (if (stringp match)
4870 (format "*Org Agenda(%s:%s)*"
4871 (or org-keys (or (and todo-only "M") "m")) match)
4872 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4873 (org-agenda-prepare (concat "TAGS " match))
4874 (org-compile-prefix-format 'tags)
4875 (org-set-sorting-strategy 'tags)
4876 (setq org-agenda-query-string match)
4877 (setq org-agenda-redo-command
4878 (list 'org-tags-view `(quote ,todo-only)
4879 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4880 (setq files (org-agenda-files nil 'ifmode)
4881 rtnall nil)
4882 (while (setq file (pop files))
4883 (catch 'nextfile
4884 (org-check-agenda-file file)
4885 (setq buffer (if (file-exists-p file)
4886 (org-get-agenda-file-buffer file)
4887 (error "No such file %s" file)))
4888 (if (not buffer)
4889 ;; If file does not exist, error message to agenda
4890 (setq rtn (list
4891 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4892 rtnall (append rtnall rtn))
4893 (with-current-buffer buffer
4894 (unless (derived-mode-p 'org-mode)
4895 (error "Agenda file %s is not in `org-mode'" file))
4896 (save-excursion
4897 (save-restriction
4898 (if org-agenda-restrict
4899 (narrow-to-region org-agenda-restrict-begin
4900 org-agenda-restrict-end)
4901 (widen))
4902 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4903 (setq rtnall (append rtnall rtn))))))))
4904 (if org-agenda-overriding-header
4905 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4906 nil 'face 'org-agenda-structure) "\n")
4907 (insert "Headlines with TAGS match: ")
4908 (add-text-properties (point-min) (1- (point))
4909 (list 'face 'org-agenda-structure
4910 'short-heading
4911 (concat "Match: " match)))
4912 (setq pos (point))
4913 (insert match "\n")
4914 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4915 (setq pos (point))
4916 (unless org-agenda-multi
4917 (insert "Press `C-u r' to search again with new search string\n"))
4918 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4919 (org-agenda-mark-header-line (point-min))
4920 (when rtnall
4921 (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
4922 (goto-char (point-min))
4923 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4924 (add-text-properties (point-min) (point-max)
4925 `(org-agenda-type tags
4926 org-last-args (,todo-only ,match)
4927 org-redo-cmd ,org-agenda-redo-command
4928 org-series-cmd ,org-cmd))
4929 (org-agenda-finalize)
4930 (setq buffer-read-only t))))
4932 (autoload 'org-tags-view "org-agenda" "\
4933 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4934 The prefix arg TODO-ONLY limits the search to TODO entries.
4936 \(fn &optional TODO-ONLY MATCH)" t nil)
4938 ;;; Agenda Finding stuck projects
4940 (defvar org-agenda-skip-regexp nil
4941 "Regular expression used in skipping subtrees for the agenda.
4942 This is basically a temporary global variable that can be set and then
4943 used by user-defined selections using `org-agenda-skip-function'.")
4945 (defvar org-agenda-overriding-header nil
4946 "When set during agenda, todo and tags searches it replaces the header.
4947 This variable should not be set directly, but custom commands can bind it
4948 in the options section.")
4950 (defun org-agenda-skip-entry-when-regexp-matches ()
4951 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4952 If yes, it returns the end position of this entry, causing agenda commands
4953 to skip the entry but continuing the search in the subtree. This is a
4954 function that can be put into `org-agenda-skip-function' for the duration
4955 of a command."
4956 (let ((end (save-excursion (org-end-of-subtree t)))
4957 skip)
4958 (save-excursion
4959 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4960 (and skip end)))
4962 (defun org-agenda-skip-subtree-when-regexp-matches ()
4963 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4964 If yes, it returns the end position of this tree, causing agenda commands
4965 to skip this subtree. This is a function that can be put into
4966 `org-agenda-skip-function' for the duration of a command."
4967 (let ((end (save-excursion (org-end-of-subtree t)))
4968 skip)
4969 (save-excursion
4970 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4971 (and skip end)))
4973 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4974 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4975 If yes, it returns the end position of the current entry (NOT the tree),
4976 causing agenda commands to skip the entry but continuing the search in
4977 the subtree. This is a function that can be put into
4978 `org-agenda-skip-function' for the duration of a command. An important
4979 use of this function is for the stuck project list."
4980 (let ((end (save-excursion (org-end-of-subtree t)))
4981 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4982 skip)
4983 (save-excursion
4984 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4985 (and skip entry-end)))
4987 (defun org-agenda-skip-entry-if (&rest conditions)
4988 "Skip entry if any of CONDITIONS is true.
4989 See `org-agenda-skip-if' for details."
4990 (org-agenda-skip-if nil conditions))
4992 (defun org-agenda-skip-subtree-if (&rest conditions)
4993 "Skip entry if any of CONDITIONS is true.
4994 See `org-agenda-skip-if' for details."
4995 (org-agenda-skip-if t conditions))
4997 (defun org-agenda-skip-if (subtree conditions)
4998 "Checks current entity for CONDITIONS.
4999 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
5000 the entry (i.e. the text before the next heading) is checked.
5002 CONDITIONS is a list of symbols, boolean OR is used to combine the results
5003 from different tests. Valid conditions are:
5005 scheduled Check if there is a scheduled cookie
5006 notscheduled Check if there is no scheduled cookie
5007 deadline Check if there is a deadline
5008 notdeadline Check if there is no deadline
5009 timestamp Check if there is a timestamp (also deadline or scheduled)
5010 nottimestamp Check if there is no timestamp (also deadline or scheduled)
5011 regexp Check if regexp matches
5012 notregexp Check if regexp does not match.
5013 todo Check if TODO keyword matches
5014 nottodo Check if TODO keyword does not match
5016 The regexp is taken from the conditions list, it must come right after
5017 the `regexp' or `notregexp' element.
5019 `todo' and `nottodo' accept as an argument a list of todo
5020 keywords, which may include \"*\" to match any todo keyword.
5022 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
5024 would skip all entries with \"TODO\" or \"WAITING\" keywords.
5026 Instead of a list, a keyword class may be given. For example:
5028 (org-agenda-skip-entry-if 'nottodo 'done)
5030 would skip entries that haven't been marked with any of \"DONE\"
5031 keywords. Possible classes are: `todo', `done', `any'.
5033 If any of these conditions is met, this function returns the end point of
5034 the entity, causing the search to continue from there. This is a function
5035 that can be put into `org-agenda-skip-function' for the duration of a command."
5036 (let (beg end m)
5037 (org-back-to-heading t)
5038 (setq beg (point)
5039 end (if subtree
5040 (progn (org-end-of-subtree t) (point))
5041 (progn (outline-next-heading) (1- (point)))))
5042 (goto-char beg)
5043 (and
5045 (and (memq 'scheduled conditions)
5046 (re-search-forward org-scheduled-time-regexp end t))
5047 (and (memq 'notscheduled conditions)
5048 (not (re-search-forward org-scheduled-time-regexp end t)))
5049 (and (memq 'deadline conditions)
5050 (re-search-forward org-deadline-time-regexp end t))
5051 (and (memq 'notdeadline conditions)
5052 (not (re-search-forward org-deadline-time-regexp end t)))
5053 (and (memq 'timestamp conditions)
5054 (re-search-forward org-ts-regexp end t))
5055 (and (memq 'nottimestamp conditions)
5056 (not (re-search-forward org-ts-regexp end t)))
5057 (and (setq m (memq 'regexp conditions))
5058 (stringp (nth 1 m))
5059 (re-search-forward (nth 1 m) end t))
5060 (and (setq m (memq 'notregexp conditions))
5061 (stringp (nth 1 m))
5062 (not (re-search-forward (nth 1 m) end t)))
5063 (and (or
5064 (setq m (memq 'nottodo conditions))
5065 (setq m (memq 'todo-unblocked conditions))
5066 (setq m (memq 'nottodo-unblocked conditions))
5067 (setq m (memq 'todo conditions)))
5068 (org-agenda-skip-if-todo m end)))
5069 end)))
5071 (defun org-agenda-skip-if-todo (args end)
5072 "Helper function for `org-agenda-skip-if', do not use it directly.
5073 ARGS is a list with first element either `todo', `nottodo',
5074 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
5075 a list of TODO keywords, or a state symbol `todo' or `done' or
5076 `any'."
5077 (let ((kw (car args))
5078 (arg (cadr args))
5079 todo-wds todo-re)
5080 (setq todo-wds
5081 (org-uniquify
5082 (cond
5083 ((listp arg) ;; list of keywords
5084 (if (member "*" arg)
5085 (mapcar 'substring-no-properties org-todo-keywords-1)
5086 arg))
5087 ((symbolp arg) ;; keyword class name
5088 (cond
5089 ((eq arg 'todo)
5090 (org-delete-all org-done-keywords
5091 (mapcar 'substring-no-properties
5092 org-todo-keywords-1)))
5093 ((eq arg 'done) org-done-keywords)
5094 ((eq arg 'any)
5095 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
5096 (setq todo-re
5097 (concat "^\\*+[ \t]+\\<\\("
5098 (mapconcat 'identity todo-wds "\\|")
5099 "\\)\\>"))
5100 (cond
5101 ((eq kw 'todo) (re-search-forward todo-re end t))
5102 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
5103 ((eq kw 'todo-unblocked)
5104 (catch 'unblocked
5105 (while (re-search-forward todo-re end t)
5106 (or (org-entry-blocked-p) (throw 'unblocked t)))
5107 nil))
5108 ((eq kw 'nottodo-unblocked)
5109 (catch 'unblocked
5110 (while (re-search-forward todo-re end t)
5111 (or (org-entry-blocked-p) (throw 'unblocked nil)))
5115 ;;;###autoload
5116 (defun org-agenda-list-stuck-projects (&rest ignore)
5117 "Create agenda view for projects that are stuck.
5118 Stuck projects are project that have no next actions. For the definitions
5119 of what a project is and how to check if it stuck, customize the variable
5120 `org-stuck-projects'."
5121 (interactive)
5122 (let* ((org-agenda-skip-function
5123 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5124 ;; We could have used org-agenda-skip-if here.
5125 (org-agenda-overriding-header
5126 (or org-agenda-overriding-header "List of stuck projects: "))
5127 (matcher (nth 0 org-stuck-projects))
5128 (todo (nth 1 org-stuck-projects))
5129 (todo-wds (if (member "*" todo)
5130 (progn
5131 (org-agenda-prepare-buffers (org-agenda-files
5132 nil 'ifmode))
5133 (org-delete-all
5134 org-done-keywords-for-agenda
5135 (copy-sequence org-todo-keywords-for-agenda)))
5136 todo))
5137 (todo-re (concat "^\\*+[ \t]+\\("
5138 (mapconcat 'identity todo-wds "\\|")
5139 "\\)\\>"))
5140 (tags (nth 2 org-stuck-projects))
5141 (tags-re (if (member "*" tags)
5142 (concat org-outline-regexp-bol
5143 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5144 (if tags
5145 (concat org-outline-regexp-bol
5146 ".*:\\("
5147 (mapconcat 'identity tags "\\|")
5148 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5149 (gen-re (nth 3 org-stuck-projects))
5150 (re-list
5151 (delq nil
5152 (list
5153 (if todo todo-re)
5154 (if tags tags-re)
5155 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5156 gen-re)))))
5157 (setq org-agenda-skip-regexp
5158 (if re-list
5159 (mapconcat 'identity re-list "\\|")
5160 (error "No information how to identify unstuck projects")))
5161 (org-tags-view nil matcher)
5162 (with-current-buffer org-agenda-buffer-name
5163 (setq org-agenda-redo-command
5164 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5166 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
5167 Create agenda view for projects that are stuck.
5168 Stuck projects are project that have no next actions. For the definitions
5169 of what a project is and how to check if it stuck, customize the variable
5170 `org-stuck-projects'.
5172 \(fn &rest IGNORE)" t nil)
5174 ;;; Diary integration
5176 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5177 (defvar diary-list-entries-hook)
5178 (defvar diary-time-regexp)
5179 (defun org-get-entries-from-diary (date)
5180 "Get the (Emacs Calendar) diary entries for DATE."
5181 (require 'diary-lib)
5182 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5183 (diary-display-hook '(fancy-diary-display))
5184 (diary-display-function 'fancy-diary-display)
5185 (pop-up-frames nil)
5186 (diary-list-entries-hook
5187 (cons 'org-diary-default-entry diary-list-entries-hook))
5188 (diary-file-name-prefix nil) ; turn this feature off
5189 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5190 entries
5191 (org-disable-agenda-to-diary t))
5192 (save-excursion
5193 (save-window-excursion
5194 (funcall (if (fboundp 'diary-list-entries)
5195 'diary-list-entries 'list-diary-entries)
5196 date 1)))
5197 (if (not (get-buffer diary-fancy-buffer))
5198 (setq entries nil)
5199 (with-current-buffer diary-fancy-buffer
5200 (setq buffer-read-only nil)
5201 (if (zerop (buffer-size))
5202 ;; No entries
5203 (setq entries nil)
5204 ;; Omit the date and other unnecessary stuff
5205 (org-agenda-cleanup-fancy-diary)
5206 ;; Add prefix to each line and extend the text properties
5207 (if (zerop (buffer-size))
5208 (setq entries nil)
5209 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5210 (setq entries
5211 (with-temp-buffer
5212 (insert entries) (goto-char (point-min))
5213 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5214 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5215 (replace-match (concat "; " (match-string 1)))))
5216 (buffer-string)))))
5217 (set-buffer-modified-p nil)
5218 (kill-buffer diary-fancy-buffer)))
5219 (when entries
5220 (setq entries (org-split-string entries "\n"))
5221 (setq entries
5222 (mapcar
5223 (lambda (x)
5224 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5225 ;; Extend the text properties to the beginning of the line
5226 (org-add-props x (text-properties-at (1- (length x)) x)
5227 'type "diary" 'date date 'face 'org-agenda-diary))
5228 entries)))))
5230 (defvar org-agenda-cleanup-fancy-diary-hook nil
5231 "Hook run when the fancy diary buffer is cleaned up.")
5233 (defun org-agenda-cleanup-fancy-diary ()
5234 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5235 This gets rid of the date, the underline under the date, and
5236 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5237 date. It also removes lines that contain only whitespace."
5238 (goto-char (point-min))
5239 (if (looking-at ".*?:[ \t]*")
5240 (progn
5241 (replace-match "")
5242 (re-search-forward "\n=+$" nil t)
5243 (replace-match "")
5244 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5245 (re-search-forward "\n=+$" nil t)
5246 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5247 (goto-char (point-min))
5248 (while (re-search-forward "^ +\n" nil t)
5249 (replace-match ""))
5250 (goto-char (point-min))
5251 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5252 (replace-match ""))
5253 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5255 ;; Make sure entries from the diary have the right text properties.
5256 (eval-after-load "diary-lib"
5257 '(if (boundp 'diary-modify-entry-list-string-function)
5258 ;; We can rely on the hook, nothing to do
5260 ;; Hook not available, must use advice to make this work
5261 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5262 "Make the position visible."
5263 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5264 (stringp string)
5265 buffer-file-name)
5266 (setq string (org-modify-diary-entry-string string))))))
5268 (defun org-modify-diary-entry-string (string)
5269 "Add text properties to string, allowing org-mode to act on it."
5270 (org-add-props string nil
5271 'mouse-face 'highlight
5272 'help-echo (if buffer-file-name
5273 (format "mouse-2 or RET jump to diary file %s"
5274 (abbreviate-file-name buffer-file-name))
5276 'org-agenda-diary-link t
5277 'org-marker (org-agenda-new-marker (point-at-bol))))
5279 (defun org-diary-default-entry ()
5280 "Add a dummy entry to the diary.
5281 Needed to avoid empty dates which mess up holiday display."
5282 ;; Catch the error if dealing with the new add-to-diary-alist
5283 (when org-disable-agenda-to-diary
5284 (condition-case nil
5285 (org-add-to-diary-list original-date "Org-mode dummy" "")
5286 (error
5287 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5289 (defun org-add-to-diary-list (&rest args)
5290 (if (fboundp 'diary-add-to-list)
5291 (apply 'diary-add-to-list args)
5292 (apply 'add-to-diary-list args)))
5294 (defvar org-diary-last-run-time nil)
5296 ;;;###autoload
5297 (defun org-diary (&rest args)
5298 "Return diary information from org files.
5299 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5300 It accesses org files and extracts information from those files to be
5301 listed in the diary. The function accepts arguments specifying what
5302 items should be listed. For a list of arguments allowed here, see the
5303 variable `org-agenda-entry-types'.
5305 The call in the diary file should look like this:
5307 &%%(org-diary) ~/path/to/some/orgfile.org
5309 Use a separate line for each org file to check. Or, if you omit the file name,
5310 all files listed in `org-agenda-files' will be checked automatically:
5312 &%%(org-diary)
5314 If you don't give any arguments (as in the example above), the default
5315 arguments (:deadline :scheduled :timestamp :sexp) are used.
5316 So the example above may also be written as
5318 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5320 The function expects the lisp variables `entry' and `date' to be provided
5321 by the caller, because this is how the calendar works. Don't use this
5322 function from a program - use `org-agenda-get-day-entries' instead."
5323 (when (> (- (org-float-time)
5324 org-agenda-last-marker-time)
5326 ;; I am not sure if this works with sticky agendas, because the marker
5327 ;; list is then no longer a global variable.
5328 (org-agenda-reset-markers))
5329 (org-compile-prefix-format 'agenda)
5330 (org-set-sorting-strategy 'agenda)
5331 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5332 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5333 (list entry)
5334 (org-agenda-files t)))
5335 (time (org-float-time))
5336 file rtn results)
5337 (when (or (not org-diary-last-run-time)
5338 (> (- time
5339 org-diary-last-run-time)
5341 (org-agenda-prepare-buffers files))
5342 (setq org-diary-last-run-time time)
5343 ;; If this is called during org-agenda, don't return any entries to
5344 ;; the calendar. Org Agenda will list these entries itself.
5345 (if org-disable-agenda-to-diary (setq files nil))
5346 (while (setq file (pop files))
5347 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5348 (setq results (append results rtn)))
5349 (when results
5350 (setq results
5351 (mapcar (lambda (i) (replace-regexp-in-string
5352 org-bracket-link-regexp "\\3" i)) results))
5353 (concat (org-agenda-finalize-entries results) "\n"))))
5355 (autoload 'org-diary "org-agenda" "\
5356 Return diary information from org files.
5357 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5358 It accesses org files and extracts information from those files to be
5359 listed in the diary. The function accepts arguments specifying what
5360 items should be listed. For a list of arguments allowed here, see the
5361 variable `org-agenda-entry-types'.
5363 The call in the diary file should look like this:
5365 &%%(org-diary) ~/path/to/some/orgfile.org
5367 Use a separate line for each org file to check. Or, if you omit the file name,
5368 all files listed in `org-agenda-files' will be checked automatically:
5370 &%%(org-diary)
5372 If you don't give any arguments (as in the example above), the default
5373 arguments (:deadline :scheduled :timestamp :sexp) are used.
5374 So the example above may also be written as
5376 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5378 The function expects the lisp variables `entry' and `date' to be provided
5379 by the caller, because this is how the calendar works. Don't use this
5380 function from a program - use `org-agenda-get-day-entries' instead.
5382 \(fn &rest ARGS)" nil nil)
5384 ;;; Agenda entry finders
5386 (defun org-agenda-get-day-entries (file date &rest args)
5387 "Does the work for `org-diary' and `org-agenda'.
5388 FILE is the path to a file to be checked for entries. DATE is date like
5389 the one returned by `calendar-current-date'. ARGS are symbols indicating
5390 which kind of entries should be extracted. For details about these, see
5391 the documentation of `org-diary'."
5392 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5393 (let* ((org-startup-folded nil)
5394 (org-startup-align-all-tables nil)
5395 (buffer (if (file-exists-p file)
5396 (org-get-agenda-file-buffer file)
5397 (error "No such file %s" file)))
5398 arg results rtn deadline-results)
5399 (if (not buffer)
5400 ;; If file does not exist, make sure an error message ends up in diary
5401 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5402 (with-current-buffer buffer
5403 (unless (derived-mode-p 'org-mode)
5404 (error "Agenda file %s is not in `org-mode'" file))
5405 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5406 (let ((case-fold-search nil))
5407 (save-excursion
5408 (save-restriction
5409 (if org-agenda-restrict
5410 (narrow-to-region org-agenda-restrict-begin
5411 org-agenda-restrict-end)
5412 (widen))
5413 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5414 (while (setq arg (pop args))
5415 (cond
5416 ((and (eq arg :todo)
5417 (equal date (calendar-gregorian-from-absolute
5418 (org-today))))
5419 (setq rtn (org-agenda-get-todos))
5420 (setq results (append results rtn)))
5421 ((eq arg :timestamp)
5422 (setq rtn (org-agenda-get-blocks))
5423 (setq results (append results rtn))
5424 (setq rtn (org-agenda-get-timestamps deadline-results))
5425 (setq results (append results rtn)))
5426 ((eq arg :sexp)
5427 (setq rtn (org-agenda-get-sexps))
5428 (setq results (append results rtn)))
5429 ((eq arg :scheduled)
5430 (setq rtn (org-agenda-get-scheduled deadline-results))
5431 (setq results (append results rtn)))
5432 ((eq arg :closed)
5433 (setq rtn (org-agenda-get-progress))
5434 (setq results (append results rtn)))
5435 ((eq arg :deadline)
5436 (setq rtn (org-agenda-get-deadlines))
5437 (setq deadline-results (copy-sequence rtn))
5438 (setq results (append results rtn))))))))
5439 results))))
5441 (defsubst org-em (x y list)
5442 "Is X or Y a member of LIST?"
5443 (or (memq x list) (memq y list)))
5445 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5446 (defvar org-agenda-sorting-strategy-selected nil)
5448 (defun org-agenda-get-todos ()
5449 "Return the TODO information for agenda display."
5450 (let* ((props (list 'face nil
5451 'done-face 'org-agenda-done
5452 'org-not-done-regexp org-not-done-regexp
5453 'org-todo-regexp org-todo-regexp
5454 'org-complex-heading-regexp org-complex-heading-regexp
5455 'mouse-face 'highlight
5456 'help-echo
5457 (format "mouse-2 or RET jump to org file %s"
5458 (abbreviate-file-name buffer-file-name))))
5459 (regexp (format org-heading-keyword-regexp-format
5460 (cond
5461 ((and org-select-this-todo-keyword
5462 (equal org-select-this-todo-keyword "*"))
5463 org-todo-regexp)
5464 (org-select-this-todo-keyword
5465 (concat "\\("
5466 (mapconcat 'identity
5467 (org-split-string
5468 org-select-this-todo-keyword
5469 "|")
5470 "\\|") "\\)"))
5471 (t org-not-done-regexp))))
5472 marker priority category category-pos level tags todo-state ts-date ts-date-type
5473 ee txt beg end inherited-tags)
5474 (goto-char (point-min))
5475 (while (re-search-forward regexp nil t)
5476 (catch :skip
5477 (save-match-data
5478 (beginning-of-line)
5479 (org-agenda-skip)
5480 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5481 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5482 (goto-char (1+ beg))
5483 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5484 (throw :skip nil)))
5485 (goto-char (match-beginning 2))
5486 (setq marker (org-agenda-new-marker (match-beginning 0))
5487 category (org-get-category)
5488 ts-date (let (ts)
5489 (save-match-data
5490 (cond ((org-em 'scheduled-up 'scheduled-down
5491 org-agenda-sorting-strategy-selected)
5492 (setq ts (org-entry-get (point) "SCHEDULED")
5493 ts-date-type " scheduled"))
5494 ((org-em 'deadline-up 'deadline-down
5495 org-agenda-sorting-strategy-selected)
5496 (setq ts (org-entry-get (point) "DEADLINE")
5497 ts-date-type " deadline"))
5498 ((org-em 'ts-up 'ts-down
5499 org-agenda-sorting-strategy-selected)
5500 (setq ts (org-entry-get (point) "TIMESTAMP")
5501 ts-date-type " timestamp"))
5502 ((org-em 'tsia-up 'tsia-down
5503 org-agenda-sorting-strategy-selected)
5504 (setq ts (org-entry-get (point) "TIMESTAMP_IA")
5505 ts-date-type " timestamp_ia"))
5506 ((org-em 'timestamp-up 'timestamp-down
5507 org-agenda-sorting-strategy-selected)
5508 (setq ts (or (org-entry-get (point) "SCHEDULED")
5509 (org-entry-get (point) "DEADLINE")
5510 (org-entry-get (point) "TIMESTAMP")
5511 (org-entry-get (point) "TIMESTAMP_IA"))
5512 ts-date-type ""))
5513 (t (setq ts-date-type "")))
5514 (when ts (ignore-errors (org-time-string-to-absolute ts)))))
5515 category-pos (get-text-property (point) 'org-category-position)
5516 txt (org-trim
5517 (buffer-substring (match-beginning 2) (match-end 0)))
5518 inherited-tags
5519 (or (eq org-agenda-show-inherited-tags 'always)
5520 (and (listp org-agenda-show-inherited-tags)
5521 (memq 'todo org-agenda-show-inherited-tags))
5522 (and (eq org-agenda-show-inherited-tags t)
5523 (or (eq org-agenda-use-tag-inheritance t)
5524 (memq 'todo org-agenda-use-tag-inheritance))))
5525 tags (org-get-tags-at nil (not inherited-tags))
5526 level (make-string (org-reduced-level (org-outline-level)) ? )
5527 txt (org-agenda-format-item "" txt level category tags t)
5528 priority (1+ (org-get-priority txt))
5529 todo-state (org-get-todo-state))
5530 (org-add-props txt props
5531 'org-marker marker 'org-hd-marker marker
5532 'priority priority 'org-category category
5533 'level level
5534 'ts-date ts-date
5535 'org-category-position category-pos
5536 'type (concat "todo" ts-date-type) 'todo-state todo-state)
5537 (push txt ee)
5538 (if org-agenda-todo-list-sublevels
5539 (goto-char (match-end 2))
5540 (org-end-of-subtree 'invisible))))
5541 (nreverse ee)))
5543 (defun org-agenda-todo-custom-ignore-p (time n)
5544 "Check whether timestamp is farther away than n number of days.
5545 This function is invoked if `org-agenda-todo-ignore-deadlines',
5546 `org-agenda-todo-ignore-scheduled' or
5547 `org-agenda-todo-ignore-timestamp' is set to an integer."
5548 (let ((days (org-time-stamp-to-now
5549 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5550 (if (>= n 0)
5551 (>= days n)
5552 (<= days n))))
5554 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5555 (&optional end)
5556 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5557 (when (or org-agenda-todo-ignore-with-date
5558 org-agenda-todo-ignore-scheduled
5559 org-agenda-todo-ignore-deadlines
5560 org-agenda-todo-ignore-timestamp)
5561 (setq end (or end (save-excursion (outline-next-heading) (point))))
5562 (save-excursion
5563 (or (and org-agenda-todo-ignore-with-date
5564 (re-search-forward org-ts-regexp end t))
5565 (and org-agenda-todo-ignore-scheduled
5566 (re-search-forward org-scheduled-time-regexp end t)
5567 (cond
5568 ((eq org-agenda-todo-ignore-scheduled 'future)
5569 (> (org-time-stamp-to-now
5570 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5571 ((eq org-agenda-todo-ignore-scheduled 'past)
5572 (<= (org-time-stamp-to-now
5573 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5574 ((numberp org-agenda-todo-ignore-scheduled)
5575 (org-agenda-todo-custom-ignore-p
5576 (match-string 1) org-agenda-todo-ignore-scheduled))
5577 (t)))
5578 (and org-agenda-todo-ignore-deadlines
5579 (re-search-forward org-deadline-time-regexp end t)
5580 (cond
5581 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5582 ((eq org-agenda-todo-ignore-deadlines 'far)
5583 (not (org-deadline-close (match-string 1))))
5584 ((eq org-agenda-todo-ignore-deadlines 'future)
5585 (> (org-time-stamp-to-now
5586 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5587 ((eq org-agenda-todo-ignore-deadlines 'past)
5588 (<= (org-time-stamp-to-now
5589 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5590 ((numberp org-agenda-todo-ignore-deadlines)
5591 (org-agenda-todo-custom-ignore-p
5592 (match-string 1) org-agenda-todo-ignore-deadlines))
5593 (t (org-deadline-close (match-string 1)))))
5594 (and org-agenda-todo-ignore-timestamp
5595 (let ((buffer (current-buffer))
5596 (regexp
5597 (concat
5598 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5599 (start (point)))
5600 ;; Copy current buffer into a temporary one
5601 (with-temp-buffer
5602 (insert-buffer-substring buffer start end)
5603 (goto-char (point-min))
5604 ;; Delete SCHEDULED and DEADLINE items
5605 (while (re-search-forward regexp end t)
5606 (delete-region (match-beginning 0) (match-end 0)))
5607 (goto-char (point-min))
5608 ;; No search for timestamp left
5609 (when (re-search-forward org-ts-regexp nil t)
5610 (cond
5611 ((eq org-agenda-todo-ignore-timestamp 'future)
5612 (> (org-time-stamp-to-now
5613 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5614 ((eq org-agenda-todo-ignore-timestamp 'past)
5615 (<= (org-time-stamp-to-now
5616 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5617 ((numberp org-agenda-todo-ignore-timestamp)
5618 (org-agenda-todo-custom-ignore-p
5619 (match-string 1) org-agenda-todo-ignore-timestamp))
5620 (t))))))))))
5622 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5623 Do we have a reason to ignore this TODO entry because it has a time stamp?
5625 \(fn &optional END)" nil nil)
5627 (defun org-agenda-get-timestamps (&optional deadline-results)
5628 "Return the date stamp information for agenda display."
5629 (let* ((props (list 'face 'org-agenda-calendar-event
5630 'org-not-done-regexp org-not-done-regexp
5631 'org-todo-regexp org-todo-regexp
5632 'org-complex-heading-regexp org-complex-heading-regexp
5633 'mouse-face 'highlight
5634 'help-echo
5635 (format "mouse-2 or RET jump to org file %s"
5636 (abbreviate-file-name buffer-file-name))))
5637 (d1 (calendar-absolute-from-gregorian date))
5639 (deadline-position-alist
5640 (mapcar (lambda (a) (and (setq mm (get-text-property
5641 0 'org-hd-marker a))
5642 (cons (marker-position mm) a)))
5643 deadline-results))
5644 (remove-re org-ts-regexp)
5645 (regexp
5646 (concat
5647 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5648 (regexp-quote
5649 (substring
5650 (format-time-string
5651 (car org-time-stamp-formats)
5652 (apply 'encode-time ; DATE bound by calendar
5653 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5654 1 11))
5655 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5656 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5657 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5658 donep tmp priority category category-pos level ee txt timestr tags
5659 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5660 inherited-tags ts-date)
5661 (goto-char (point-min))
5662 (while (setq end-of-match (re-search-forward regexp nil t))
5663 (setq b0 (match-beginning 0)
5664 b3 (match-beginning 3) e3 (match-end 3)
5665 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5666 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5667 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5668 (member todo-state
5669 org-agenda-repeating-timestamp-show-all)))
5670 (catch :skip
5671 (and (org-at-date-range-p) (throw :skip nil))
5672 (org-agenda-skip)
5673 (if (and (match-end 1)
5674 (not (= d1 (org-time-string-to-absolute
5675 (match-string 1) d1 nil show-all
5676 (current-buffer) b0))))
5677 (throw :skip nil))
5678 (if (and e3
5679 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5680 (throw :skip nil))
5681 (setq tmp (buffer-substring (max (point-min)
5682 (- b0 org-ds-keyword-length))
5684 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5685 inactivep (= (char-after b0) ?\[)
5686 deadlinep (string-match org-deadline-regexp tmp)
5687 scheduledp (string-match org-scheduled-regexp tmp)
5688 closedp (and org-agenda-include-inactive-timestamps
5689 (string-match org-closed-string tmp))
5690 clockp (and org-agenda-include-inactive-timestamps
5691 (or (string-match org-clock-string tmp)
5692 (string-match "]-+\\'" tmp)))
5693 warntime (get-text-property (point) 'org-appt-warntime)
5694 donep (member todo-state org-done-keywords))
5695 (if (or scheduledp deadlinep closedp clockp
5696 (and donep org-agenda-skip-timestamp-if-done))
5697 (throw :skip t))
5698 (if (string-match ">" timestr)
5699 ;; substring should only run to end of time stamp
5700 (setq timestr (substring timestr 0 (match-end 0))))
5701 (setq marker (org-agenda-new-marker b0)
5702 category (org-get-category b0)
5703 category-pos (get-text-property b0 'org-category-position))
5704 (save-excursion
5705 (if (not (re-search-backward org-outline-regexp-bol nil t))
5706 (throw :skip nil)
5707 (goto-char (match-beginning 0))
5708 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5709 (assoc (point) deadline-position-alist))
5710 (throw :skip nil))
5711 (setq hdmarker (org-agenda-new-marker)
5712 inherited-tags
5713 (or (eq org-agenda-show-inherited-tags 'always)
5714 (and (listp org-agenda-show-inherited-tags)
5715 (memq 'agenda org-agenda-show-inherited-tags))
5716 (and (eq org-agenda-show-inherited-tags t)
5717 (or (eq org-agenda-use-tag-inheritance t)
5718 (memq 'agenda org-agenda-use-tag-inheritance))))
5719 tags (org-get-tags-at nil (not inherited-tags))
5720 level (make-string (org-reduced-level (org-outline-level)) ? ))
5721 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5722 (setq head (or (match-string 1) ""))
5723 (setq txt (org-agenda-format-item
5724 (if inactivep org-agenda-inactive-leader nil)
5725 head level category tags timestr
5726 remove-re habitp)))
5727 (setq priority (org-get-priority txt))
5728 (org-add-props txt props 'priority priority
5729 'org-marker marker 'org-hd-marker hdmarker
5730 'org-category category 'date date
5731 'level level
5732 'ts-date
5733 (ignore-errors (org-time-string-to-absolute timestr))
5734 'org-category-position category-pos
5735 'todo-state todo-state
5736 'warntime warntime
5737 'type "timestamp")
5738 (push txt ee))
5739 (if org-agenda-skip-additional-timestamps-same-entry
5740 (outline-next-heading)
5741 (goto-char end-of-match))))
5742 (nreverse ee)))
5744 (defun org-agenda-get-sexps ()
5745 "Return the sexp information for agenda display."
5746 (require 'diary-lib)
5747 (let* ((props (list 'face 'org-agenda-calendar-sexp
5748 'mouse-face 'highlight
5749 'help-echo
5750 (format "mouse-2 or RET jump to org file %s"
5751 (abbreviate-file-name buffer-file-name))))
5752 (regexp "^&?%%(")
5753 marker category extra category-pos level ee txt tags entry
5754 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5755 (goto-char (point-min))
5756 (while (re-search-forward regexp nil t)
5757 (catch :skip
5758 (org-agenda-skip)
5759 (setq beg (match-beginning 0))
5760 (goto-char (1- (match-end 0)))
5761 (setq b (point))
5762 (forward-sexp 1)
5763 (setq sexp (buffer-substring b (point)))
5764 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5765 (org-trim (match-string 1))
5766 ""))
5767 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5768 (when result
5769 (setq marker (org-agenda-new-marker beg)
5770 level (make-string (org-reduced-level (org-outline-level)) ? )
5771 category (org-get-category beg)
5772 category-pos (get-text-property beg 'org-category-position)
5773 inherited-tags
5774 (or (eq org-agenda-show-inherited-tags 'always)
5775 (and (listp org-agenda-show-inherited-tags)
5776 (memq 'agenda org-agenda-show-inherited-tags))
5777 (and (eq org-agenda-show-inherited-tags t)
5778 (or (eq org-agenda-use-tag-inheritance t)
5779 (memq 'agenda org-agenda-use-tag-inheritance))))
5780 tags (org-get-tags-at nil (not inherited-tags))
5781 todo-state (org-get-todo-state)
5782 warntime (get-text-property (point) 'org-appt-warntime)
5783 extra nil)
5785 (dolist (r (if (stringp result)
5786 (list result)
5787 result)) ;; we expect a list here
5788 (when (and org-agenda-diary-sexp-prefix
5789 (string-match org-agenda-diary-sexp-prefix r))
5790 (setq extra (match-string 0 r)
5791 r (replace-match "" nil nil r)))
5792 (if (string-match "\\S-" r)
5793 (setq txt r)
5794 (setq txt "SEXP entry returned empty string"))
5795 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5796 (org-add-props txt props 'org-marker marker
5797 'org-category category 'date date 'todo-state todo-state
5798 'org-category-position category-pos 'tags tags
5799 'level level
5800 'type "sexp" 'warntime warntime)
5801 (push txt ee)))))
5802 (nreverse ee)))
5804 ;; Calendar sanity: define some functions that are independent of
5805 ;; `calendar-date-style'.
5806 ;; Normally I would like to use ISO format when calling the diary functions,
5807 ;; but to make sure we still have Emacs 22 compatibility we bind
5808 ;; also `european-calendar-style' and use european format
5809 (defun org-anniversary (year month day &optional mark)
5810 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5811 (org-no-warnings
5812 (let ((calendar-date-style 'european) (european-calendar-style t))
5813 (diary-anniversary day month year mark))))
5814 (defun org-cyclic (N year month day &optional mark)
5815 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5816 (org-no-warnings
5817 (let ((calendar-date-style 'european) (european-calendar-style t))
5818 (diary-cyclic N day month year mark))))
5819 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5820 "Like `diary-block', but with fixed (ISO) order of arguments."
5821 (org-no-warnings
5822 (let ((calendar-date-style 'european) (european-calendar-style t))
5823 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5824 (defun org-date (year month day &optional mark)
5825 "Like `diary-date', but with fixed (ISO) order of arguments."
5826 (org-no-warnings
5827 (let ((calendar-date-style 'european) (european-calendar-style t))
5828 (diary-date day month year mark))))
5830 ;; Define the` org-class' function
5831 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5832 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5833 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5834 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5835 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5836 `holidays', then any date that is known by the Emacs calendar to be a
5837 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5838 then those holidays will be skipped."
5839 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5840 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5841 (d (calendar-absolute-from-gregorian date))
5842 (h (when skip-weeks (calendar-check-holidays date))))
5843 (and
5844 (<= date1 d)
5845 (<= d date2)
5846 (= (calendar-day-of-week date) dayname)
5847 (or (not skip-weeks)
5848 (progn
5849 (require 'cal-iso)
5850 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5851 (not (or (and h (memq 'holidays skip-weeks))
5852 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5853 entry)))
5855 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5856 "Like `org-class', but honor `calendar-date-style'.
5857 The order of the first 2 times 3 arguments depends on the variable
5858 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5859 So for American calendars, give this as MONTH DAY YEAR, for European as
5860 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5861 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5862 is any number of ISO weeks in the block period for which the item should
5863 be skipped.
5865 This function is here only for backward compatibility and it is deprecated,
5866 please use `org-class' instead."
5867 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5868 (date2 (org-order-calendar-date-args m2 d2 y2)))
5869 (org-class
5870 (nth 2 date1) (car date1) (nth 1 date1)
5871 (nth 2 date2) (car date2) (nth 1 date2)
5872 dayname skip-weeks)))
5873 (make-obsolete 'org-diary-class 'org-class "")
5875 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5876 (defalias 'org-get-closed 'org-agenda-get-progress)
5877 (defun org-agenda-get-progress ()
5878 "Return the logged TODO entries for agenda display."
5879 (let* ((props (list 'mouse-face 'highlight
5880 'org-not-done-regexp org-not-done-regexp
5881 'org-todo-regexp org-todo-regexp
5882 'org-complex-heading-regexp org-complex-heading-regexp
5883 'help-echo
5884 (format "mouse-2 or RET jump to org file %s"
5885 (abbreviate-file-name buffer-file-name))))
5886 (items (if (consp org-agenda-show-log-scoped)
5887 org-agenda-show-log-scoped
5888 (if (eq org-agenda-show-log-scoped 'clockcheck)
5889 '(clock)
5890 org-agenda-log-mode-items)))
5891 (parts
5892 (delq nil
5893 (list
5894 (if (memq 'closed items) (concat "\\<" org-closed-string))
5895 (if (memq 'clock items) (concat "\\<" org-clock-string))
5896 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5897 (parts-re (if parts (mapconcat 'identity parts "\\|")
5898 (error "`org-agenda-log-mode-items' is empty")))
5899 (regexp (concat
5900 "\\(" parts-re "\\)"
5901 " *\\["
5902 (regexp-quote
5903 (substring
5904 (format-time-string
5905 (car org-time-stamp-formats)
5906 (apply 'encode-time ; DATE bound by calendar
5907 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5908 1 11))))
5909 (org-agenda-search-headline-for-time nil)
5910 marker hdmarker priority category category-pos level tags closedp
5911 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5912 (goto-char (point-min))
5913 (while (re-search-forward regexp nil t)
5914 (catch :skip
5915 (org-agenda-skip)
5916 (setq marker (org-agenda-new-marker (match-beginning 0))
5917 closedp (equal (match-string 1) org-closed-string)
5918 statep (equal (string-to-char (match-string 1)) ?-)
5919 clockp (not (or closedp statep))
5920 state (and statep (match-string 2))
5921 category (org-get-category (match-beginning 0))
5922 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5923 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5924 (when (string-match "\\]" timestr)
5925 ;; substring should only run to end of time stamp
5926 (setq rest (substring timestr (match-end 0))
5927 timestr (substring timestr 0 (match-end 0)))
5928 (if (and (not closedp) (not statep)
5929 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5930 rest))
5931 (progn (setq timestr (concat (substring timestr 0 -1)
5932 "-" (match-string 1 rest) "]"))
5933 (setq clocked (match-string 2 rest)))
5934 (setq clocked "-")))
5935 (save-excursion
5936 (setq extra
5937 (cond
5938 ((not org-agenda-log-mode-add-notes) nil)
5939 (statep
5940 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5941 (match-string 1)))
5942 (clockp
5943 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5944 (match-string 1)))))
5945 (if (not (re-search-backward org-outline-regexp-bol nil t))
5946 (throw :skip nil)
5947 (goto-char (match-beginning 0))
5948 (setq hdmarker (org-agenda-new-marker)
5949 inherited-tags
5950 (or (eq org-agenda-show-inherited-tags 'always)
5951 (and (listp org-agenda-show-inherited-tags)
5952 (memq 'todo org-agenda-show-inherited-tags))
5953 (and (eq org-agenda-show-inherited-tags t)
5954 (or (eq org-agenda-use-tag-inheritance t)
5955 (memq 'todo org-agenda-use-tag-inheritance))))
5956 tags (org-get-tags-at nil (not inherited-tags))
5957 level (make-string (org-reduced-level (org-outline-level)) ? ))
5958 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5959 (setq txt (match-string 1))
5960 (when extra
5961 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5962 (setq txt (concat (substring txt 0 (match-beginning 1))
5963 " - " extra " " (match-string 2 txt)))
5964 (setq txt (concat txt " - " extra))))
5965 (setq txt (org-agenda-format-item
5966 (cond
5967 (closedp "Closed: ")
5968 (statep (concat "State: (" state ")"))
5969 (t (concat "Clocked: (" clocked ")")))
5970 txt level category tags timestr)))
5971 (setq priority 100000)
5972 (org-add-props txt props
5973 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5974 'priority priority 'org-category category
5975 'org-category-position category-pos
5976 'level level
5977 'type "closed" 'date date
5978 'undone-face 'org-warning 'done-face 'org-agenda-done)
5979 (push txt ee))
5980 (goto-char (point-at-eol))))
5981 (nreverse ee)))
5983 (defun org-agenda-show-clocking-issues ()
5984 "Add overlays, showing issues with clocking.
5985 See also the user option `org-agenda-clock-consistency-checks'."
5986 (interactive)
5987 (let* ((org-time-clocksum-use-effort-durations nil)
5988 (pl org-agenda-clock-consistency-checks)
5989 (re (concat "^[ \t]*"
5990 org-clock-string
5991 "[ \t]+"
5992 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5993 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5994 (tlstart 0.)
5995 (tlend 0.)
5996 (maxtime (org-hh:mm-string-to-minutes
5997 (or (plist-get pl :max-duration) "24:00")))
5998 (mintime (org-hh:mm-string-to-minutes
5999 (or (plist-get pl :min-duration) 0)))
6000 (maxgap (org-hh:mm-string-to-minutes
6001 ;; default 30:00 means never complain
6002 (or (plist-get pl :max-gap) "30:00")))
6003 (gapok (mapcar 'org-hh:mm-string-to-minutes
6004 (plist-get pl :gap-ok-around)))
6005 (def-face (or (plist-get pl :default-face)
6006 '((:background "DarkRed") (:foreground "white"))))
6007 issue face m te ts dt ov)
6008 (goto-char (point-min))
6009 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
6010 (setq issue nil face def-face)
6011 (catch 'next
6012 (setq m (org-get-at-bol 'org-marker)
6013 te nil ts nil)
6014 (unless (and m (markerp m))
6015 (setq issue "No valid clock line") (throw 'next t))
6016 (org-with-point-at m
6017 (save-excursion
6018 (goto-char (point-at-bol))
6019 (unless (looking-at re)
6020 (error "No valid Clock line")
6021 (throw 'next t))
6022 (unless (match-end 3)
6023 (setq issue "No end time"
6024 face (or (plist-get pl :no-end-time-face) face))
6025 (throw 'next t))
6026 (setq ts (match-string 1)
6027 te (match-string 3)
6028 ts (org-float-time
6029 (apply 'encode-time (org-parse-time-string ts)))
6030 te (org-float-time
6031 (apply 'encode-time (org-parse-time-string te)))
6032 dt (- te ts))))
6033 (cond
6034 ((> dt (* 60 maxtime))
6035 ;; a very long clocking chunk
6036 (setq issue (format "Clocking interval is very long: %s"
6037 (org-minutes-to-clocksum-string
6038 (floor (/ (float dt) 60.))))
6039 face (or (plist-get pl :long-face) face)))
6040 ((< dt (* 60 mintime))
6041 ;; a very short clocking chunk
6042 (setq issue (format "Clocking interval is very short: %s"
6043 (org-minutes-to-clocksum-string
6044 (floor (/ (float dt) 60.))))
6045 face (or (plist-get pl :short-face) face)))
6046 ((and (> tlend 0) (< ts tlend))
6047 ;; Two clock entries are overlapping
6048 (setq issue (format "Clocking overlap: %d minutes"
6049 (/ (- tlend ts) 60))
6050 face (or (plist-get pl :overlap-face) face)))
6051 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
6052 ;; There is a gap, lets see if we need to report it
6053 (unless (org-agenda-check-clock-gap tlend ts gapok)
6054 (setq issue (format "Clocking gap: %d minutes"
6055 (/ (- ts tlend) 60))
6056 face (or (plist-get pl :gap-face) face))))
6057 (t nil)))
6058 (setq tlend (or te tlend) tlstart (or ts tlstart))
6059 (when issue
6060 ;; OK, there was some issue, add an overlay to show the issue
6061 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
6062 (overlay-put ov 'before-string
6063 (concat
6064 (org-add-props
6065 (format "%-43s" (concat " " issue))
6067 'face face)
6068 "\n"))
6069 (overlay-put ov 'evaporate t)))))
6071 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
6072 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
6073 (catch 'exit
6074 (unless ok-list
6075 ;; there are no OK times for gaps...
6076 (throw 'exit nil))
6077 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
6078 ;; This is more than 24 hours, so it is OK.
6079 ;; because we have at least one OK time, that must be in the
6080 ;; 24 hour interval.
6081 (throw 'exit t))
6082 ;; We have a shorter gap.
6083 ;; Now we have to get the minute of the day when these times are
6084 (let* ((t1dec (decode-time (seconds-to-time t1)))
6085 (t2dec (decode-time (seconds-to-time t2)))
6086 ;; compute the minute on the day
6087 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
6088 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
6089 (when (< min2 min1)
6090 ;; if min2 is smaller than min1, this means it is on the next day.
6091 ;; Wrap it to after midnight.
6092 (setq min2 (+ min2 1440)))
6093 ;; Now check if any of the OK times is in the gap
6094 (mapc (lambda (x)
6095 ;; Wrap the time to after midnight if necessary
6096 (if (< x min1) (setq x (+ x 1440)))
6097 ;; Check if in interval
6098 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
6099 ok-list)
6100 ;; Nope, this gap is not OK
6101 nil)))
6103 (defun org-agenda-get-deadlines ()
6104 "Return the deadline information for agenda display."
6105 (let* ((props (list 'mouse-face 'highlight
6106 'org-not-done-regexp org-not-done-regexp
6107 'org-todo-regexp org-todo-regexp
6108 'org-complex-heading-regexp org-complex-heading-regexp
6109 'help-echo
6110 (format "mouse-2 or RET jump to org file %s"
6111 (abbreviate-file-name buffer-file-name))))
6112 (regexp org-deadline-time-regexp)
6113 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6114 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6115 d2 diff dfrac wdays pos pos1 category category-pos level
6116 tags suppress-prewarning ee txt head face s todo-state
6117 show-all upcomingp donep timestr warntime inherited-tags ts-date)
6118 (goto-char (point-min))
6119 (while (re-search-forward regexp nil t)
6120 (catch :skip
6121 (org-agenda-skip)
6122 (setq s (match-string 1)
6123 txt nil
6124 pos (1- (match-beginning 1))
6125 todo-state (save-match-data (org-get-todo-state))
6126 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6127 (member todo-state
6128 org-agenda-repeating-timestamp-show-all))
6129 d2 (org-time-string-to-absolute
6130 s d1 'past show-all (current-buffer) pos)
6131 diff (- d2 d1))
6132 (setq suppress-prewarning
6133 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
6134 (let ((item (buffer-substring (point-at-bol)
6135 (point-at-eol))))
6136 (save-match-data
6137 (and (string-match
6138 org-scheduled-time-regexp item)
6139 (match-string 1 item)))))))
6140 (cond
6141 ((not ds) nil)
6142 ;; The current item has a scheduled date (in ds), so
6143 ;; evaluate its prewarning lead time.
6144 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
6145 ;; Use global prewarning-restart lead time.
6146 org-agenda-skip-deadline-prewarning-if-scheduled)
6147 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
6148 'pre-scheduled)
6149 ;; Set prewarning to no earlier than scheduled.
6150 (min (- d2 (org-time-string-to-absolute
6151 ds d1 'past show-all (current-buffer) pos))
6152 org-deadline-warning-days))
6153 ;; Set prewarning to deadline.
6154 (t 0))))
6155 (setq wdays (if suppress-prewarning
6156 (let ((org-deadline-warning-days suppress-prewarning))
6157 (org-get-wdays s))
6158 (org-get-wdays s))
6159 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6160 upcomingp (and todayp (> diff 0)))
6161 ;; When to show a deadline in the calendar:
6162 ;; If the expiration is within wdays warning time.
6163 ;; Past-due deadlines are only shown on the current date
6164 (if (and (or (and (<= diff wdays)
6165 (and todayp (not org-agenda-only-exact-dates)))
6166 (= diff 0)))
6167 (save-excursion
6168 ;; (setq todo-state (org-get-todo-state))
6169 (setq donep (member todo-state org-done-keywords))
6170 (if (and donep
6171 (or org-agenda-skip-deadline-if-done
6172 (not (= diff 0))))
6173 (setq txt nil)
6174 (setq category (org-get-category)
6175 warntime (get-text-property (point) 'org-appt-warntime)
6176 category-pos (get-text-property (point) 'org-category-position))
6177 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6178 (throw :skip nil)
6179 (goto-char (match-end 0))
6180 (setq pos1 (match-beginning 0))
6181 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6182 (setq inherited-tags
6183 (or (eq org-agenda-show-inherited-tags 'always)
6184 (and (listp org-agenda-show-inherited-tags)
6185 (memq 'agenda org-agenda-show-inherited-tags))
6186 (and (eq org-agenda-show-inherited-tags t)
6187 (or (eq org-agenda-use-tag-inheritance t)
6188 (memq 'agenda org-agenda-use-tag-inheritance))))
6189 tags (org-get-tags-at pos1 (not inherited-tags)))
6190 (setq head (buffer-substring
6191 (point)
6192 (progn (skip-chars-forward "^\r\n")
6193 (point))))
6194 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6195 (setq timestr
6196 (concat (substring s (match-beginning 1)) " "))
6197 (setq timestr 'time))
6198 (setq txt (org-agenda-format-item
6199 (if (= diff 0)
6200 (car org-agenda-deadline-leaders)
6201 (if (functionp
6202 (nth 1 org-agenda-deadline-leaders))
6203 (funcall
6204 (nth 1 org-agenda-deadline-leaders)
6205 diff date)
6206 (format (nth 1 org-agenda-deadline-leaders)
6207 diff)))
6208 head level category tags
6209 (if (not (= diff 0)) nil timestr)))))
6210 (when txt
6211 (setq face (org-agenda-deadline-face dfrac))
6212 (org-add-props txt props
6213 'org-marker (org-agenda-new-marker pos)
6214 'warntime warntime
6215 'level level
6216 'ts-date d2
6217 'org-hd-marker (org-agenda-new-marker pos1)
6218 'priority (+ (- diff)
6219 (org-get-priority txt))
6220 'org-category category
6221 'org-category-position category-pos
6222 'todo-state todo-state
6223 'type (if upcomingp "upcoming-deadline" "deadline")
6224 'date (if upcomingp date d2)
6225 'face (if donep 'org-agenda-done face)
6226 'undone-face face 'done-face 'org-agenda-done)
6227 (push txt ee))))))
6228 (nreverse ee)))
6230 (defun org-agenda-deadline-face (fraction)
6231 "Return the face to displaying a deadline item.
6232 FRACTION is what fraction of the head-warning time has passed."
6233 (let ((faces org-agenda-deadline-faces) f)
6234 (catch 'exit
6235 (while (setq f (pop faces))
6236 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6238 (defun org-agenda-get-scheduled (&optional deadline-results)
6239 "Return the scheduled information for agenda display."
6240 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6241 'org-todo-regexp org-todo-regexp
6242 'org-complex-heading-regexp org-complex-heading-regexp
6243 'done-face 'org-agenda-done
6244 'mouse-face 'highlight
6245 'help-echo
6246 (format "mouse-2 or RET jump to org file %s"
6247 (abbreviate-file-name buffer-file-name))))
6248 (regexp org-scheduled-time-regexp)
6249 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6250 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6252 (deadline-position-alist
6253 (mapcar (lambda (a) (and (setq mm (get-text-property
6254 0 'org-hd-marker a))
6255 (cons (marker-position mm) a)))
6256 deadline-results))
6257 d2 diff pos pos1 category category-pos level tags donep
6258 ee txt head pastschedp todo-state face timestr s habitp show-all
6259 did-habit-check-p warntime inherited-tags ts-date suppress-delay
6260 ddays)
6261 (goto-char (point-min))
6262 (while (re-search-forward regexp nil t)
6263 (catch :skip
6264 (org-agenda-skip)
6265 (setq s (match-string 1)
6266 txt nil
6267 pos (1- (match-beginning 1))
6268 todo-state (save-match-data (org-get-todo-state))
6269 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6270 (member todo-state
6271 org-agenda-repeating-timestamp-show-all))
6272 d2 (org-time-string-to-absolute
6273 s d1 'past show-all (current-buffer) pos)
6274 diff (- d2 d1)
6275 warntime (get-text-property (point) 'org-appt-warntime))
6276 (setq pastschedp (and todayp (< diff 0)))
6277 (setq did-habit-check-p nil)
6278 (setq suppress-delay
6279 (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
6280 (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
6281 (save-match-data
6282 (and (string-match
6283 org-deadline-time-regexp item)
6284 (match-string 1 item)))))))
6285 (cond
6286 ((not ds) nil)
6287 ;; The current item has a deadline date (in ds), so
6288 ;; evaluate its delay time.
6289 ((integerp org-agenda-skip-scheduled-delay-if-deadline)
6290 ;; Use global delay time.
6291 (- org-agenda-skip-scheduled-delay-if-deadline))
6292 ((eq org-agenda-skip-scheduled-delay-if-deadline
6293 'post-deadline)
6294 ;; Set delay to no later than deadline.
6295 (min (- d2 (org-time-string-to-absolute
6296 ds d1 'past show-all (current-buffer) pos))
6297 org-scheduled-delay-days))
6298 (t 0))))
6299 (setq ddays (if suppress-delay
6300 (let ((org-scheduled-delay-days suppress-delay))
6301 (org-get-wdays s t t))
6302 (org-get-wdays s t)))
6303 ;; Use a delay of 0 when there is a repeater and the delay is
6304 ;; of the form --3d
6305 (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
6306 (< (org-time-string-to-absolute s)
6307 (org-time-string-to-absolute
6308 s d2 'past nil (current-buffer) pos)))
6309 (setq ddays 0))
6310 ;; When to show a scheduled item in the calendar:
6311 ;; If it is on or past the date.
6312 (when (or (and (> ddays 0) (= diff (- ddays)))
6313 (and (zerop ddays) (= diff 0))
6314 (and (< (+ diff ddays) 0)
6315 (< (abs diff) org-scheduled-past-days)
6316 (and todayp (not org-agenda-only-exact-dates)))
6317 ;; org-is-habit-p uses org-entry-get, which is expansive
6318 ;; so we go extra mile to only call it once
6319 (and todayp
6320 (boundp 'org-habit-show-all-today)
6321 org-habit-show-all-today
6322 (setq did-habit-check-p t)
6323 (setq habitp (and (functionp 'org-is-habit-p)
6324 (org-is-habit-p)))))
6325 (save-excursion
6326 (setq donep (member todo-state org-done-keywords))
6327 (if (and donep
6328 (or org-agenda-skip-scheduled-if-done
6329 (not (= diff 0))
6330 (and (functionp 'org-is-habit-p)
6331 (org-is-habit-p))))
6332 (setq txt nil)
6333 (setq habitp (if did-habit-check-p habitp
6334 (and (functionp 'org-is-habit-p)
6335 (org-is-habit-p))))
6336 (setq category (org-get-category)
6337 category-pos (get-text-property (point) 'org-category-position))
6338 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6339 (throw :skip nil)
6340 (goto-char (match-end 0))
6341 (setq pos1 (match-beginning 0))
6342 (if habitp
6343 (if (or (not org-habit-show-habits)
6344 (and (not todayp)
6345 (boundp 'org-habit-show-habits-only-for-today)
6346 org-habit-show-habits-only-for-today))
6347 (throw :skip nil))
6348 (if (and
6349 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6350 (and org-agenda-skip-scheduled-if-deadline-is-shown
6351 pastschedp))
6352 (setq mm (assoc pos1 deadline-position-alist)))
6353 (throw :skip nil)))
6354 (setq inherited-tags
6355 (or (eq org-agenda-show-inherited-tags 'always)
6356 (and (listp org-agenda-show-inherited-tags)
6357 (memq 'agenda org-agenda-show-inherited-tags))
6358 (and (eq org-agenda-show-inherited-tags t)
6359 (or (eq org-agenda-use-tag-inheritance t)
6360 (memq 'agenda org-agenda-use-tag-inheritance))))
6362 tags (org-get-tags-at nil (not inherited-tags)))
6363 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6364 (setq head (buffer-substring
6365 (point)
6366 (progn (skip-chars-forward "^\r\n") (point))))
6367 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6368 (setq timestr
6369 (concat (substring s (match-beginning 1)) " "))
6370 (setq timestr 'time))
6371 (setq txt (org-agenda-format-item
6372 (if (= diff 0)
6373 (car org-agenda-scheduled-leaders)
6374 (format (nth 1 org-agenda-scheduled-leaders)
6375 (- 1 diff)))
6376 head level category tags
6377 (if (not (= diff 0)) nil timestr)
6378 nil habitp))))
6379 (when txt
6380 (setq face
6381 (cond
6382 ((and (not habitp) pastschedp)
6383 'org-scheduled-previously)
6384 (todayp 'org-scheduled-today)
6385 (t 'org-scheduled))
6386 habitp (and habitp (org-habit-parse-todo)))
6387 (org-add-props txt props
6388 'undone-face face
6389 'face (if donep 'org-agenda-done face)
6390 'org-marker (org-agenda-new-marker pos)
6391 'org-hd-marker (org-agenda-new-marker pos1)
6392 'type (if pastschedp "past-scheduled" "scheduled")
6393 'date (if pastschedp d2 date)
6394 'ts-date d2
6395 'warntime warntime
6396 'level level
6397 'priority (if habitp
6398 (org-habit-get-priority habitp)
6399 (+ 94 (- 5 diff) (org-get-priority txt)))
6400 'org-category category
6401 'category-position category-pos
6402 'org-habit-p habitp
6403 'todo-state todo-state)
6404 (push txt ee))))))
6405 (nreverse ee)))
6407 (defun org-agenda-get-blocks ()
6408 "Return the date-range information for agenda display."
6409 (let* ((props (list 'face nil
6410 'org-not-done-regexp org-not-done-regexp
6411 'org-todo-regexp org-todo-regexp
6412 'org-complex-heading-regexp org-complex-heading-regexp
6413 'mouse-face 'highlight
6414 'help-echo
6415 (format "mouse-2 or RET jump to org file %s"
6416 (abbreviate-file-name buffer-file-name))))
6417 (regexp org-tr-regexp)
6418 (d0 (calendar-absolute-from-gregorian date))
6419 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6420 level todo-state tags pos head donep inherited-tags)
6421 (goto-char (point-min))
6422 (while (re-search-forward regexp nil t)
6423 (catch :skip
6424 (org-agenda-skip)
6425 (setq pos (point))
6426 (let ((start-time (match-string 1))
6427 (end-time (match-string 2)))
6428 (setq s1 (match-string 1)
6429 s2 (match-string 2)
6430 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6431 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6432 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6433 ;; Only allow days between the limits, because the normal
6434 ;; date stamps will catch the limits.
6435 (save-excursion
6436 (setq todo-state (org-get-todo-state))
6437 (setq donep (member todo-state org-done-keywords))
6438 (if (and donep org-agenda-skip-timestamp-if-done)
6439 (throw :skip t))
6440 (setq marker (org-agenda-new-marker (point)))
6441 (setq category (org-get-category)
6442 category-pos (get-text-property (point) 'org-category-position))
6443 (if (not (re-search-backward org-outline-regexp-bol nil t))
6444 (throw :skip nil)
6445 (goto-char (match-beginning 0))
6446 (setq hdmarker (org-agenda-new-marker (point))
6447 inherited-tags
6448 (or (eq org-agenda-show-inherited-tags 'always)
6449 (and (listp org-agenda-show-inherited-tags)
6450 (memq 'agenda org-agenda-show-inherited-tags))
6451 (and (eq org-agenda-show-inherited-tags t)
6452 (or (eq org-agenda-use-tag-inheritance t)
6453 (memq 'agenda org-agenda-use-tag-inheritance))))
6455 tags (org-get-tags-at nil (not inherited-tags)))
6456 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6457 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6458 (setq head (match-string 1))
6459 (let ((remove-re
6460 (if org-agenda-remove-timeranges-from-blocks
6461 (concat
6462 "<" (regexp-quote s1) ".*?>"
6463 "--"
6464 "<" (regexp-quote s2) ".*?>")
6465 nil)))
6466 (setq txt (org-agenda-format-item
6467 (format
6468 (nth (if (= d1 d2) 0 1)
6469 org-agenda-timerange-leaders)
6470 (1+ (- d0 d1)) (1+ (- d2 d1)))
6471 head level category tags
6472 (cond ((and (= d1 d0) (= d2 d0))
6473 (concat "<" start-time ">--<" end-time ">"))
6474 ((= d1 d0)
6475 (concat "<" start-time ">"))
6476 ((= d2 d0)
6477 (concat "<" end-time ">")))
6478 remove-re))))
6479 (org-add-props txt props
6480 'org-marker marker 'org-hd-marker hdmarker
6481 'type "block" 'date date
6482 'level level
6483 'todo-state todo-state
6484 'priority (org-get-priority txt) 'org-category category
6485 'org-category-position category-pos)
6486 (push txt ee))))
6487 (goto-char pos)))
6488 ;; Sort the entries by expiration date.
6489 (nreverse ee)))
6491 ;;; Agenda presentation and sorting
6493 (defvar org-prefix-has-time nil
6494 "A flag, set by `org-compile-prefix-format'.
6495 The flag is set if the currently compiled format contains a `%t'.")
6496 (defvar org-prefix-has-tag nil
6497 "A flag, set by `org-compile-prefix-format'.
6498 The flag is set if the currently compiled format contains a `%T'.")
6499 (defvar org-prefix-has-effort nil
6500 "A flag, set by `org-compile-prefix-format'.
6501 The flag is set if the currently compiled format contains a `%e'.")
6502 (defvar org-prefix-has-breadcrumbs nil
6503 "A flag, set by `org-compile-prefix-format'.
6504 The flag is set if the currently compiled format contains a `%b'.")
6505 (defvar org-prefix-category-length nil
6506 "Used by `org-compile-prefix-format' to remember the category field width.")
6507 (defvar org-prefix-category-max-length nil
6508 "Used by `org-compile-prefix-format' to remember the category field width.")
6510 (defun org-agenda-get-category-icon (category)
6511 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6512 (dolist (entry org-agenda-category-icon-alist)
6513 (when (org-string-match-p (car entry) category)
6514 (if (listp (cadr entry))
6515 (return (cadr entry))
6516 (return (apply 'create-image (cdr entry)))))))
6518 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6519 remove-re habitp)
6520 "Format TXT to be inserted into the agenda buffer.
6521 In particular, add the prefix and corresponding text properties.
6523 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6524 LEVEL may be a string to replace the `%l' specifier.
6525 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6526 category taken from local variable or file name. It will replace the `%c'
6527 specifier in the format.
6528 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6529 TXT for sorting of this entry, and for the `%t' specifier in the format.
6530 When DOTIME is a string, this string is searched for a time before TXT is.
6531 TAGS can be the tags of the headline.
6532 Any match of REMOVE-RE will be removed from TXT."
6533 ;; We keep the org-prefix-* variable values along with a compiled
6534 ;; formatter, so that multiple agendas existing at the same time do
6535 ;; not step on each other toes.
6537 ;; It was inconvenient to make these variables buffer local in
6538 ;; Agenda buffers, because this function expects to be called with
6539 ;; the buffer where item comes from being current, and not agenda
6540 ;; buffer
6541 (let* ((bindings (car org-prefix-format-compiled))
6542 (formatter (cadr org-prefix-format-compiled)))
6543 (loop for (var value) in bindings
6544 do (set var value))
6545 (save-match-data
6546 ;; Diary entries sometimes have extra whitespace at the beginning
6547 (setq txt (org-trim txt))
6549 ;; Fix the tags part in txt
6550 (setq txt (org-agenda-fix-displayed-tags
6551 txt tags
6552 org-agenda-show-inherited-tags
6553 org-agenda-hide-tags-regexp))
6555 (let* ((category (or category
6556 (if (stringp org-category)
6557 org-category
6558 (and org-category (symbol-name org-category)))
6559 (if buffer-file-name
6560 (file-name-sans-extension
6561 (file-name-nondirectory buffer-file-name))
6562 "")))
6563 (category-icon (org-agenda-get-category-icon category))
6564 (category-icon (if category-icon
6565 (propertize " " 'display category-icon)
6566 ""))
6567 ;; time, tag, effort are needed for the eval of the prefix format
6568 (tag (if tags (nth (1- (length tags)) tags) ""))
6569 time effort neffort
6570 (ts (if dotime (concat
6571 (if (stringp dotime) dotime "")
6572 (and org-agenda-search-headline-for-time txt))))
6573 (time-of-day (and dotime (org-get-time-of-day ts)))
6574 stamp plain s0 s1 s2 rtn srp l
6575 duration thecategory breadcrumbs)
6576 (and (derived-mode-p 'org-mode) buffer-file-name
6577 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6578 (when (and dotime time-of-day)
6579 ;; Extract starting and ending time and move them to prefix
6580 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6581 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6582 (setq s0 (match-string 0 ts)
6583 srp (and stamp (match-end 3))
6584 s1 (match-string (if plain 1 2) ts)
6585 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6587 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6588 ;; them, we might want to remove them there to avoid duplication.
6589 ;; The user can turn this off with a variable.
6590 (if (and org-prefix-has-time
6591 org-agenda-remove-times-when-in-prefix (or stamp plain)
6592 (string-match (concat (regexp-quote s0) " *") txt)
6593 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6594 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6595 (= (match-beginning 0) 0)
6597 (setq txt (replace-match "" nil nil txt))))
6598 ;; Normalize the time(s) to 24 hour
6599 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6600 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6602 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6603 (let (org-time-clocksum-use-effort-durations)
6604 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6605 (setq s2
6606 (org-minutes-to-clocksum-string
6607 (+ (org-hh:mm-string-to-minutes s1)
6608 org-agenda-default-appointment-duration)))))
6610 ;; Compute the duration
6611 (when s2
6612 (setq duration (- (org-hh:mm-string-to-minutes s2)
6613 (org-hh:mm-string-to-minutes s1)))))
6615 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6616 txt)
6617 ;; Tags are in the string
6618 (if (or (eq org-agenda-remove-tags t)
6619 (and org-agenda-remove-tags
6620 org-prefix-has-tag))
6621 (setq txt (replace-match "" t t txt))
6622 (setq txt (replace-match
6623 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6624 (match-string 2 txt))
6625 t t txt))))
6626 (when (derived-mode-p 'org-mode)
6627 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6628 (if effort
6629 (setq neffort (org-duration-string-to-minutes effort)
6630 effort (setq effort (concat "[" effort "]")))
6631 ;; prevent erroring out with %e format when there is no effort
6632 (setq effort "")))
6634 (when remove-re
6635 (while (string-match remove-re txt)
6636 (setq txt (replace-match "" t t txt))))
6638 ;; Set org-heading property on `txt' to mark the start of the
6639 ;; heading.
6640 (add-text-properties 0 (length txt) '(org-heading t) txt)
6642 ;; Prepare the variables needed in the eval of the compiled format
6643 (if org-prefix-has-breadcrumbs
6644 (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
6645 (let ((s (org-display-outline-path nil nil "->" t)))
6646 (if (eq "" s) "" (concat s "->"))))))
6647 (setq time (cond (s2 (concat
6648 (org-agenda-time-of-day-to-ampm-maybe s1)
6649 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6650 (if org-agenda-timegrid-use-ampm " ")))
6651 (s1 (concat
6652 (org-agenda-time-of-day-to-ampm-maybe s1)
6653 (if org-agenda-timegrid-use-ampm
6654 "........ "
6655 "......")))
6656 (t ""))
6657 extra (or (and (not habitp) extra) "")
6658 category (if (symbolp category) (symbol-name category) category)
6659 thecategory (copy-sequence category)
6660 level (or level ""))
6661 (if (string-match org-bracket-link-regexp category)
6662 (progn
6663 (setq l (if (match-end 3)
6664 (- (match-end 3) (match-beginning 3))
6665 (- (match-end 1) (match-beginning 1))))
6666 (when (< l (or org-prefix-category-length 0))
6667 (setq category (copy-sequence category))
6668 (org-add-props category nil
6669 'extra-space (make-string
6670 (- org-prefix-category-length l 1) ?\ ))))
6671 (if (and org-prefix-category-max-length
6672 (>= (length category) org-prefix-category-max-length))
6673 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6674 ;; Evaluate the compiled format
6675 (setq rtn (concat (eval formatter) txt))
6677 ;; And finally add the text properties
6678 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6679 (org-add-props rtn nil
6680 'org-category (if thecategory (downcase thecategory) category)
6681 'tags (mapcar 'org-downcase-keep-props tags)
6682 'org-highest-priority org-highest-priority
6683 'org-lowest-priority org-lowest-priority
6684 'time-of-day time-of-day
6685 'duration duration
6686 'effort effort
6687 'effort-minutes neffort
6688 'breadcrumbs breadcrumbs
6689 'txt txt
6690 'level level
6691 'time time
6692 'extra extra
6693 'format org-prefix-format-compiled
6694 'dotime dotime)))))
6696 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6697 "Remove tags string from TXT, and add a modified list of tags.
6698 The modified list may contain inherited tags, and tags matched by
6699 `org-agenda-hide-tags-regexp' will be removed."
6700 (when (or add-inherited hide-re)
6701 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6702 (setq txt (substring txt 0 (match-beginning 0))))
6703 (setq tags
6704 (delq nil
6705 (mapcar (lambda (tg)
6706 (if (or (and hide-re (string-match hide-re tg))
6707 (and (not add-inherited)
6708 (get-text-property 0 'inherited tg)))
6710 tg))
6711 tags)))
6712 (when tags
6713 (let ((have-i (get-text-property 0 'inherited (car tags)))
6715 (setq txt (concat txt " :"
6716 (mapconcat
6717 (lambda (x)
6718 (setq i (get-text-property 0 'inherited x))
6719 (if (and have-i (not i))
6720 (progn
6721 (setq have-i nil)
6722 (concat ":" x))
6724 tags ":")
6725 (if have-i "::" ":"))))))
6726 txt)
6728 (defun org-downcase-keep-props (s)
6729 (let ((props (text-properties-at 0 s)))
6730 (setq s (downcase s))
6731 (add-text-properties 0 (length s) props s)
6734 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6736 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6737 "Add a time-grid for agenda items which need it.
6739 LIST is the list of agenda items formatted by `org-agenda-list'.
6740 NDAYS is the span of the current agenda view.
6741 TODAYP is `t' when the current agenda view is on today."
6742 (catch 'exit
6743 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6744 ((and todayp (member 'today (car org-agenda-time-grid))))
6745 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6746 ((member 'weekly (car org-agenda-time-grid)))
6747 (t (throw 'exit list)))
6748 (let* ((have (delq nil (mapcar
6749 (lambda (x) (get-text-property 1 'time-of-day x))
6750 list)))
6751 (string (nth 1 org-agenda-time-grid))
6752 (gridtimes (nth 2 org-agenda-time-grid))
6753 (req (car org-agenda-time-grid))
6754 (remove (member 'remove-match req))
6755 new time)
6756 (if (and (member 'require-timed req) (not have))
6757 ;; don't show empty grid
6758 (throw 'exit list))
6759 (while (setq time (pop gridtimes))
6760 (unless (and remove (member time have))
6761 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6762 (push (org-agenda-format-item
6763 nil string nil "" nil
6764 (concat (substring time 0 -2) ":" (substring time -2)))
6765 new)
6766 (put-text-property
6767 2 (length (car new)) 'face 'org-time-grid (car new))))
6768 (when (and todayp org-agenda-show-current-time-in-grid)
6769 (push (org-agenda-format-item
6770 nil org-agenda-current-time-string nil "" nil
6771 (format-time-string "%H:%M "))
6772 new)
6773 (put-text-property
6774 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6776 (if (member 'time-up org-agenda-sorting-strategy-selected)
6777 (append new list)
6778 (append list new)))))
6780 (defun org-compile-prefix-format (key)
6781 "Compile the prefix format into a Lisp form that can be evaluated.
6782 The resulting form and associated variable bindings is returned
6783 and stored in the variable `org-prefix-format-compiled'."
6784 (setq org-prefix-has-time nil
6785 org-prefix-has-tag nil
6786 org-prefix-category-length nil
6787 org-prefix-has-effort nil
6788 org-prefix-has-breadcrumbs nil)
6789 (let ((s (cond
6790 ((stringp org-agenda-prefix-format)
6791 org-agenda-prefix-format)
6792 ((assq key org-agenda-prefix-format)
6793 (cdr (assq key org-agenda-prefix-format)))
6794 (t " %-12:c%?-12t% s")))
6795 (start 0)
6796 varform vars var e c f opt)
6797 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
6798 s start)
6799 (setq var (or (cdr (assoc (match-string 4 s)
6800 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6801 ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
6802 'eval)
6803 c (or (match-string 3 s) "")
6804 opt (match-beginning 1)
6805 start (1+ (match-beginning 0)))
6806 (if (equal var 'time) (setq org-prefix-has-time t))
6807 (if (equal var 'tag) (setq org-prefix-has-tag t))
6808 (if (equal var 'effort) (setq org-prefix-has-effort t))
6809 (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
6810 (setq f (concat "%" (match-string 2 s) "s"))
6811 (when (equal var 'category)
6812 (setq org-prefix-category-length
6813 (floor (abs (string-to-number (match-string 2 s)))))
6814 (setq org-prefix-category-max-length
6815 (let ((x (match-string 2 s)))
6816 (save-match-data
6817 (if (string-match "\\.[0-9]+" x)
6818 (string-to-number (substring (match-string 0 x) 1)))))))
6819 (if (eq var 'eval)
6820 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6821 (if opt
6822 (setq varform
6823 `(if (equal "" ,var)
6825 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6826 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6827 (setq s (replace-match "%s" t nil s))
6828 (push varform vars))
6829 (setq vars (nreverse vars))
6830 (with-current-buffer (or org-agenda-buffer (current-buffer))
6831 (setq org-prefix-format-compiled
6832 (list
6833 `((org-prefix-has-time ,org-prefix-has-time)
6834 (org-prefix-has-tag ,org-prefix-has-tag)
6835 (org-prefix-category-length ,org-prefix-category-length)
6836 (org-prefix-has-effort ,org-prefix-has-effort)
6837 (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
6838 `(format ,s ,@vars))))))
6840 (defun org-set-sorting-strategy (key)
6841 (if (symbolp (car org-agenda-sorting-strategy))
6842 ;; the old format
6843 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6844 (setq org-agenda-sorting-strategy-selected
6845 (or (cdr (assq key org-agenda-sorting-strategy))
6846 (cdr (assq 'agenda org-agenda-sorting-strategy))
6847 '(time-up category-keep priority-down)))))
6849 (defun org-get-time-of-day (s &optional string mod24)
6850 "Check string S for a time of day.
6851 If found, return it as a military time number between 0 and 2400.
6852 If not found, return nil.
6853 The optional STRING argument forces conversion into a 5 character wide string
6854 HH:MM."
6855 (save-match-data
6856 (when
6857 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6858 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6859 (let* ((h (string-to-number (match-string 1 s)))
6860 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6861 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6862 (am-p (equal ampm "am"))
6863 (h1 (cond ((not ampm) h)
6864 ((= h 12) (if am-p 0 12))
6865 (t (+ h (if am-p 0 12)))))
6866 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6867 (mod h1 24) h1))
6868 (t0 (+ (* 100 h2) m))
6869 (t1 (concat (if (>= h1 24) "+" " ")
6870 (if (and org-agenda-time-leading-zero
6871 (< t0 1000)) "0" "")
6872 (if (< t0 100) "0" "")
6873 (if (< t0 10) "0" "")
6874 (int-to-string t0))))
6875 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6877 (defvar org-agenda-before-sorting-filter-function nil
6878 "Function to be applied to agenda items prior to sorting.
6879 Prior to sorting also means just before they are inserted into the agenda.
6881 To aid sorting, you may revisit the original entries and add more text
6882 properties which will later be used by the sorting functions.
6884 The function should take a string argument, an agenda line.
6885 It has access to the text properties in that line, which contain among
6886 other things, the property `org-hd-marker' that points to the entry
6887 where the line comes from. Note that not all lines going into the agenda
6888 have this property, only most.
6890 The function should return the modified string. It is probably best
6891 to ONLY change text properties.
6893 You can also use this function as a filter, by returning nil for lines
6894 you don't want to have in the agenda at all. For this application, you
6895 could bind the variable in the options section of a custom command.")
6897 (defun org-agenda-finalize-entries (list &optional type)
6898 "Sort, limit and concatenate the LIST of agenda items.
6899 The optional argument TYPE tells the agenda type."
6900 (let ((max-effort (cond ((listp org-agenda-max-effort)
6901 (cdr (assoc type org-agenda-max-effort)))
6902 (t org-agenda-max-effort)))
6903 (max-todo (cond ((listp org-agenda-max-todos)
6904 (cdr (assoc type org-agenda-max-todos)))
6905 (t org-agenda-max-todos)))
6906 (max-tags (cond ((listp org-agenda-max-tags)
6907 (cdr (assoc type org-agenda-max-tags)))
6908 (t org-agenda-max-tags)))
6909 (max-entries (cond ((listp org-agenda-max-entries)
6910 (cdr (assoc type org-agenda-max-entries)))
6911 (t org-agenda-max-entries))) l)
6912 (when org-agenda-before-sorting-filter-function
6913 (setq list
6914 (delq nil
6915 (mapcar
6916 org-agenda-before-sorting-filter-function list))))
6917 (setq list (mapcar 'org-agenda-highlight-todo list)
6918 list (mapcar 'identity (sort list 'org-entries-lessp))
6919 list (org-agenda-limit-entries
6920 list 'effort-minutes max-effort 'identity)
6921 list (org-agenda-limit-entries list 'todo-state max-todo)
6922 list (org-agenda-limit-entries list 'tags max-tags)
6923 list (org-agenda-limit-entries list 'org-hd-marker max-entries)
6924 list (mapconcat 'identity list "\n"))))
6926 (defun org-agenda-limit-entries (list prop limit &optional fn)
6927 "Limit the number of agenda entries."
6928 (if limit
6929 (let ((f (or fn (lambda (p) (and p 1)))) (lim 0))
6930 (delq nil
6931 (mapcar
6932 (lambda (e)
6933 (let ((pval (funcall f (get-text-property 1 prop e))))
6934 (if pval (setq lim (+ lim pval)))
6935 (if (or (not pval) (<= lim limit)) e)))
6936 list)))
6937 list))
6939 (defun org-agenda-highlight-todo (x)
6940 (let ((org-done-keywords org-done-keywords-for-agenda)
6941 (case-fold-search nil)
6943 (if (eq x 'line)
6944 (save-excursion
6945 (beginning-of-line 1)
6946 (setq re (org-get-at-bol 'org-todo-regexp))
6947 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6948 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6949 (add-text-properties (match-beginning 0) (match-end 1)
6950 (list 'face (org-get-todo-face 1)))
6951 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6952 (delete-region (match-beginning 1) (1- (match-end 0)))
6953 (goto-char (match-beginning 1))
6954 (insert (format org-agenda-todo-keyword-format s)))))
6955 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6956 (setq re (get-text-property 0 'org-todo-regexp x))
6957 (when (and re
6958 ;; Test `pl' because if there's no heading content,
6959 ;; there's no point matching to highlight. Note
6960 ;; that if we didn't test `pl' first, and there
6961 ;; happened to be no keyword from `org-todo-regexp'
6962 ;; on this heading line, then the `equal' comparison
6963 ;; afterwards would spuriously succeed in the case
6964 ;; where `pl' is nil -- causing an args-out-of-range
6965 ;; error when we try to add text properties to text
6966 ;; that isn't there.
6968 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6969 x pl) pl))
6970 (add-text-properties
6971 (or (match-end 1) (match-end 0)) (match-end 0)
6972 (list 'face (org-get-todo-face (match-string 2 x)))
6974 (when (match-end 1)
6975 (setq x (concat (substring x 0 (match-end 1))
6976 (format org-agenda-todo-keyword-format
6977 (match-string 2 x))
6978 (org-add-props " " (text-properties-at 0 x))
6979 (substring x (match-end 3)))))))
6980 x)))
6982 (defsubst org-cmp-priority (a b)
6983 "Compare the priorities of string A and B."
6984 (let ((pa (or (get-text-property 1 'priority a) 0))
6985 (pb (or (get-text-property 1 'priority b) 0)))
6986 (cond ((> pa pb) +1)
6987 ((< pa pb) -1))))
6989 (defsubst org-cmp-effort (a b)
6990 "Compare the effort values of string A and B."
6991 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6992 (ea (or (get-text-property 1 'effort-minutes a) def))
6993 (eb (or (get-text-property 1 'effort-minutes b) def)))
6994 (cond ((> ea eb) +1)
6995 ((< ea eb) -1))))
6997 (defsubst org-cmp-category (a b)
6998 "Compare the string values of categories of strings A and B."
6999 (let ((ca (or (get-text-property 1 'org-category a) ""))
7000 (cb (or (get-text-property 1 'org-category b) "")))
7001 (cond ((string-lessp ca cb) -1)
7002 ((string-lessp cb ca) +1))))
7004 (defsubst org-cmp-todo-state (a b)
7005 "Compare the todo states of strings A and B."
7006 (let* ((ma (or (get-text-property 1 'org-marker a)
7007 (get-text-property 1 'org-hd-marker a)))
7008 (mb (or (get-text-property 1 'org-marker b)
7009 (get-text-property 1 'org-hd-marker b)))
7010 (fa (and ma (marker-buffer ma)))
7011 (fb (and mb (marker-buffer mb)))
7012 (todo-kwds
7013 (or (and fa (with-current-buffer fa org-todo-keywords-1))
7014 (and fb (with-current-buffer fb org-todo-keywords-1))))
7015 (ta (or (get-text-property 1 'todo-state a) ""))
7016 (tb (or (get-text-property 1 'todo-state b) ""))
7017 (la (- (length (member ta todo-kwds))))
7018 (lb (- (length (member tb todo-kwds))))
7019 (donepa (member ta org-done-keywords-for-agenda))
7020 (donepb (member tb org-done-keywords-for-agenda)))
7021 (cond ((and donepa (not donepb)) -1)
7022 ((and (not donepa) donepb) +1)
7023 ((< la lb) -1)
7024 ((< lb la) +1))))
7026 (defsubst org-cmp-alpha (a b)
7027 "Compare the headlines, alphabetically."
7028 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
7029 (plb (text-property-any 0 (length b) 'org-heading t b))
7030 (ta (and pla (substring a pla)))
7031 (tb (and plb (substring b plb))))
7032 (when pla
7033 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
7034 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
7035 (setq ta (substring ta (match-end 0))))
7036 (setq ta (downcase ta)))
7037 (when plb
7038 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
7039 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
7040 (setq tb (substring tb (match-end 0))))
7041 (setq tb (downcase tb)))
7042 (cond ((not ta) +1)
7043 ((not tb) -1)
7044 ((string-lessp ta tb) -1)
7045 ((string-lessp tb ta) +1))))
7047 (defsubst org-cmp-tag (a b)
7048 "Compare the string values of the first tags of A and B."
7049 (let ((ta (car (last (get-text-property 1 'tags a))))
7050 (tb (car (last (get-text-property 1 'tags b)))))
7051 (cond ((not ta) +1)
7052 ((not tb) -1)
7053 ((string-lessp ta tb) -1)
7054 ((string-lessp tb ta) +1))))
7056 (defsubst org-cmp-time (a b)
7057 "Compare the time-of-day values of strings A and B."
7058 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7059 (ta (or (get-text-property 1 'time-of-day a) def))
7060 (tb (or (get-text-property 1 'time-of-day b) def)))
7061 (cond ((< ta tb) -1)
7062 ((< tb ta) +1))))
7064 (defsubst org-cmp-ts (a b &optional type)
7065 "Compare the timestamps values of entries A and B.
7066 When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
7067 or \"timestamp_ia\", compare within each of these type.
7068 When TYPE is the empty string, compare all timestamps
7069 without respect of their type."
7070 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
7071 (ta (or (and (string-match type (get-text-property 1 'type a))
7072 (get-text-property 1 'ts-date a)) def))
7073 (tb (or (and (string-match type (get-text-property 1 'type b))
7074 (get-text-property 1 'ts-date b)) def)))
7075 (cond ((< ta tb) -1)
7076 ((< tb ta) +1))))
7078 (defsubst org-cmp-habit-p (a b)
7079 "Compare the todo states of strings A and B."
7080 (let ((ha (get-text-property 1 'org-habit-p a))
7081 (hb (get-text-property 1 'org-habit-p b)))
7082 (cond ((and ha (not hb)) -1)
7083 ((and (not ha) hb) +1))))
7085 (defun org-entries-lessp (a b)
7086 "Predicate for sorting agenda entries."
7087 ;; The following variables will be used when the form is evaluated.
7088 ;; So even though the compiler complains, keep them.
7089 (let* ((ss org-agenda-sorting-strategy-selected)
7090 (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
7091 (org-cmp-ts a b "")))
7092 (timestamp-down (if timestamp-up (- timestamp-up) nil))
7093 (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
7094 (org-cmp-ts a b "scheduled")))
7095 (scheduled-down (if scheduled-up (- scheduled-up) nil))
7096 (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
7097 (org-cmp-ts a b "deadline")))
7098 (deadline-down (if deadline-up (- deadline-up) nil))
7099 (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
7100 (org-cmp-ts a b "iatimestamp_ia")))
7101 (tsia-down (if tsia-up (- tsia-up) nil))
7102 (ts-up (and (org-em 'ts-up 'ts-down ss)
7103 (org-cmp-ts a b "timestamp")))
7104 (ts-down (if ts-up (- ts-up) nil))
7105 (time-up (and (org-em 'time-up 'time-down ss)
7106 (org-cmp-time a b)))
7107 (time-down (if time-up (- time-up) nil))
7108 (priority-up (and (org-em 'priority-up 'priority-down ss)
7109 (org-cmp-priority a b)))
7110 (priority-down (if priority-up (- priority-up) nil))
7111 (effort-up (and (org-em 'effort-up 'effort-down ss)
7112 (org-cmp-effort a b)))
7113 (effort-down (if effort-up (- effort-up) nil))
7114 (category-up (and (or (org-em 'category-up 'category-down ss)
7115 (memq 'category-keep ss))
7116 (org-cmp-category a b)))
7117 (category-down (if category-up (- category-up) nil))
7118 (category-keep (if category-up +1 nil))
7119 (tag-up (and (org-em 'tag-up 'tag-down ss)
7120 (org-cmp-tag a b)))
7121 (tag-down (if tag-up (- tag-up) nil))
7122 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
7123 (org-cmp-todo-state a b)))
7124 (todo-state-down (if todo-state-up (- todo-state-up) nil))
7125 (habit-up (and (org-em 'habit-up 'habit-down ss)
7126 (org-cmp-habit-p a b)))
7127 (habit-down (if habit-up (- habit-up) nil))
7128 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
7129 (org-cmp-alpha a b)))
7130 (alpha-down (if alpha-up (- alpha-up) nil))
7131 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
7132 user-defined-up user-defined-down)
7133 (if (and need-user-cmp org-agenda-cmp-user-defined
7134 (functionp org-agenda-cmp-user-defined))
7135 (setq user-defined-up
7136 (funcall org-agenda-cmp-user-defined a b)
7137 user-defined-down (if user-defined-up (- user-defined-up) nil)))
7138 (cdr (assoc
7139 (eval (cons 'or org-agenda-sorting-strategy-selected))
7140 '((-1 . t) (1 . nil) (nil . nil))))))
7142 ;;; Agenda restriction lock
7144 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
7145 "Overlay to mark the headline to which agenda commands are restricted.")
7146 (overlay-put org-agenda-restriction-lock-overlay
7147 'face 'org-agenda-restriction-lock)
7148 (overlay-put org-agenda-restriction-lock-overlay
7149 'help-echo "Agendas are currently limited to this subtree.")
7150 (org-detach-overlay org-agenda-restriction-lock-overlay)
7152 (defun org-agenda-set-restriction-lock (&optional type)
7153 "Set restriction lock for agenda, to current subtree or file.
7154 Restriction will be the file if TYPE is `file', or if type is the
7155 universal prefix '(4), or if the cursor is before the first headline
7156 in the file. Otherwise, restriction will be to the current subtree."
7157 (interactive "P")
7158 (and (equal type '(4)) (setq type 'file))
7159 (setq type (cond
7160 (type type)
7161 ((org-at-heading-p) 'subtree)
7162 ((condition-case nil (org-back-to-heading t) (error nil))
7163 'subtree)
7164 (t 'file)))
7165 (if (eq type 'subtree)
7166 (progn
7167 (setq org-agenda-restrict t)
7168 (setq org-agenda-overriding-restriction 'subtree)
7169 (put 'org-agenda-files 'org-restrict
7170 (list (buffer-file-name (buffer-base-buffer))))
7171 (org-back-to-heading t)
7172 (move-overlay org-agenda-restriction-lock-overlay
7173 (point) (save-excursion (org-end-of-subtree t t) (point)))
7174 (move-marker org-agenda-restrict-begin (point))
7175 (move-marker org-agenda-restrict-end
7176 (save-excursion (org-end-of-subtree t t)))
7177 (message "Locking agenda restriction to subtree"))
7178 (put 'org-agenda-files 'org-restrict
7179 (list (buffer-file-name (buffer-base-buffer))))
7180 (setq org-agenda-restrict nil)
7181 (setq org-agenda-overriding-restriction 'file)
7182 (move-marker org-agenda-restrict-begin nil)
7183 (move-marker org-agenda-restrict-end nil)
7184 (message "Locking agenda restriction to file"))
7185 (setq current-prefix-arg nil)
7186 (org-agenda-maybe-redo))
7188 (defun org-agenda-remove-restriction-lock (&optional noupdate)
7189 "Remove the agenda restriction lock."
7190 (interactive "P")
7191 (org-detach-overlay org-agenda-restriction-lock-overlay)
7192 (org-detach-overlay org-speedbar-restriction-lock-overlay)
7193 (setq org-agenda-overriding-restriction nil)
7194 (setq org-agenda-restrict nil)
7195 (put 'org-agenda-files 'org-restrict nil)
7196 (move-marker org-agenda-restrict-begin nil)
7197 (move-marker org-agenda-restrict-end nil)
7198 (setq current-prefix-arg nil)
7199 (message "Agenda restriction lock removed")
7200 (or noupdate (org-agenda-maybe-redo)))
7202 (defun org-agenda-maybe-redo ()
7203 "If there is any window showing the agenda view, update it."
7204 (let ((w (get-buffer-window org-agenda-buffer-name t))
7205 (w0 (selected-window)))
7206 (when w
7207 (select-window w)
7208 (org-agenda-redo)
7209 (select-window w0)
7210 (if org-agenda-overriding-restriction
7211 (message "Agenda view shifted to new %s restriction"
7212 org-agenda-overriding-restriction)
7213 (message "Agenda restriction lock removed")))))
7215 ;;; Agenda commands
7217 (defun org-agenda-check-type (error &rest types)
7218 "Check if agenda buffer is of allowed type.
7219 If ERROR is non-nil, throw an error, otherwise just return nil.
7220 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
7221 (if (not org-agenda-type)
7222 (error "No Org agenda currently displayed")
7223 (if (memq org-agenda-type types)
7225 (if error
7226 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
7227 nil))))
7229 (defun org-agenda-Quit ()
7230 "Exit the agenda and kill buffers loaded by `org-agenda'.
7231 Also restore the window configuration."
7232 (interactive)
7233 (if org-agenda-columns-active
7234 (org-columns-quit)
7235 (let ((buf (current-buffer)))
7236 (if (eq org-agenda-window-setup 'other-frame)
7237 (progn
7238 (org-agenda-reset-markers)
7239 (kill-buffer buf)
7240 (org-columns-remove-overlays)
7241 (setq org-agenda-archives-mode nil)
7242 (delete-frame))
7243 (and (not (eq org-agenda-window-setup 'current-window))
7244 (not (one-window-p))
7245 (delete-window))
7246 (org-agenda-reset-markers)
7247 (kill-buffer buf)
7248 (org-columns-remove-overlays)
7249 (setq org-agenda-archives-mode nil)))
7250 ;; Maybe restore the pre-agenda window configuration.
7251 (and org-agenda-restore-windows-after-quit
7252 (not (eq org-agenda-window-setup 'other-frame))
7253 org-agenda-pre-window-conf
7254 (set-window-configuration org-agenda-pre-window-conf)
7255 (setq org-agenda-pre-window-conf nil))))
7257 (defun org-agenda-quit ()
7258 "Exit the agenda and restore the window configuration.
7259 When `org-agenda-sticky' is non-nil, only bury the agenda."
7260 (interactive)
7261 (if (and (eq org-indirect-buffer-display 'other-window)
7262 org-last-indirect-buffer)
7263 (let ((org-last-indirect-window
7264 (get-buffer-window org-last-indirect-buffer)))
7265 (if org-last-indirect-window
7266 (delete-window org-last-indirect-window))))
7267 (if org-agenda-columns-active
7268 (org-columns-quit)
7269 (if org-agenda-sticky
7270 (let ((buf (current-buffer)))
7271 (if (eq org-agenda-window-setup 'other-frame)
7272 (progn
7273 (delete-frame))
7274 (and (not (eq org-agenda-window-setup 'current-window))
7275 (not (one-window-p))
7276 (delete-window)))
7277 (with-current-buffer buf
7278 (bury-buffer)
7279 ;; Maybe restore the pre-agenda window configuration.
7280 (and org-agenda-restore-windows-after-quit
7281 (not (eq org-agenda-window-setup 'other-frame))
7282 org-agenda-pre-window-conf
7283 (set-window-configuration org-agenda-pre-window-conf)
7284 (setq org-agenda-pre-window-conf nil))))
7285 (org-agenda-Quit))))
7287 (defun org-agenda-exit ()
7288 "Exit the agenda and restore the window configuration.
7289 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7290 buffers visited directly by the user will not be touched."
7291 (interactive)
7292 (org-release-buffers org-agenda-new-buffers)
7293 (setq org-agenda-new-buffers nil)
7294 (org-agenda-Quit))
7296 (defun org-agenda-kill-all-agenda-buffers ()
7297 "Kill all buffers in `org-agenda-mode'.
7298 This is used when toggling sticky agendas.
7299 You can also explicitly invoke it with `C-c a C-k'."
7300 (interactive)
7301 (let (blist)
7302 (dolist (buf (buffer-list))
7303 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7304 (push buf blist)))
7305 (mapc 'kill-buffer blist)))
7307 (defun org-agenda-execute (arg)
7308 "Execute another agenda command, keeping same window.
7309 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7310 in the agenda."
7311 (interactive "P")
7312 (let ((org-agenda-window-setup 'current-window))
7313 (org-agenda arg)))
7315 (defun org-agenda-redo (&optional all)
7316 "Rebuild possibly ALL agenda view(s) in the current buffer."
7317 (interactive "P")
7318 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7319 (cpa (unless (eq all t) current-prefix-arg))
7320 (org-agenda-doing-sticky-redo org-agenda-sticky)
7321 (org-agenda-sticky nil)
7322 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7323 org-agenda-buffer-name))
7324 (org-agenda-keep-modes t)
7325 (tag-filter org-agenda-tag-filter)
7326 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7327 (top-cat-filter org-agenda-top-category-filter)
7328 (cat-filter org-agenda-category-filter)
7329 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7330 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7331 (cols org-agenda-columns-active)
7332 (line (org-current-line))
7333 (window-line (- line (org-current-line (window-start))))
7334 (lprops (get 'org-agenda-redo-command 'org-lprops))
7335 (redo-cmd (get-text-property p 'org-redo-cmd))
7336 (last-args (get-text-property p 'org-last-args))
7337 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7338 (org-agenda-overriding-cmd-arguments
7339 (unless (eq all t)
7340 (cond ((listp last-args)
7341 (cons (or cpa (car last-args)) (cdr last-args)))
7342 ((stringp last-args)
7343 last-args))))
7344 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7345 (put 'org-agenda-tag-filter :preset-filter nil)
7346 (put 'org-agenda-category-filter :preset-filter nil)
7347 (and cols (org-columns-quit))
7348 (message "Rebuilding agenda buffer...")
7349 (if series-redo-cmd
7350 (eval series-redo-cmd)
7351 (org-let lprops '(eval redo-cmd)))
7352 (setq org-agenda-undo-list nil
7353 org-agenda-pending-undo-list nil)
7354 (message "Rebuilding agenda buffer...done")
7355 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7356 (put 'org-agenda-category-filter :preset-filter cat-preset)
7357 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7358 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7359 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7360 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7361 (org-goto-line line)
7362 (recenter window-line)))
7364 (defvar org-global-tags-completion-table nil)
7365 (defvar org-agenda-filter-form nil)
7366 (defvar org-agenda-filtered-by-category nil)
7368 (defun org-agenda-filter-by-category (strip)
7369 "Keep only those lines in the agenda buffer that have a specific category.
7370 The category is that of the current line."
7371 (interactive "P")
7372 (if (and org-agenda-filtered-by-category
7373 org-agenda-category-filter)
7374 (org-agenda-filter-show-all-cat)
7375 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7376 (if cat (org-agenda-filter-apply
7377 (list (concat (if strip "-" "+") cat)) 'category)
7378 (error "No category at point")))))
7380 (defun org-find-top-category (&optional pos)
7381 (save-excursion
7382 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7383 (if pos (goto-char pos))
7384 ;; Skip up to the topmost parent
7385 (while (ignore-errors (outline-up-heading 1) t))
7386 (ignore-errors
7387 (nth 4 (org-heading-components))))))
7389 (defvar org-agenda-filtered-by-top-category nil)
7391 (defun org-agenda-filter-by-top-category (strip)
7392 "Keep only those lines in the agenda buffer that have a specific category.
7393 The category is that of the current line."
7394 (interactive "P")
7395 (if org-agenda-filtered-by-top-category
7396 (progn
7397 (setq org-agenda-filtered-by-top-category nil
7398 org-agenda-top-category-filter nil)
7399 (org-agenda-filter-show-all-cat))
7400 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7401 (if cat (org-agenda-filter-top-category-apply cat strip)
7402 (error "No top-level category at point")))))
7404 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7405 "Keep only those lines in the agenda buffer that have a specific tag.
7406 The tag is selected with its fast selection letter, as configured.
7407 With prefix argument STRIP, remove all lines that do have the tag.
7408 A lisp caller can specify CHAR. NARROW means that the new tag should be
7409 used to narrow the search - the interactive user can also press `-' or `+'
7410 to switch to narrowing."
7411 (interactive "P")
7412 (let* ((alist org-tag-alist-for-agenda)
7413 (tag-chars (mapconcat
7414 (lambda (x) (if (and (not (symbolp (car x)))
7415 (cdr x))
7416 (char-to-string (cdr x))
7417 ""))
7418 alist ""))
7419 (efforts (org-split-string
7420 (or (cdr (assoc (concat org-effort-property "_ALL")
7421 org-global-properties))
7422 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7423 "")))
7424 (effort-op org-agenda-filter-effort-default-operator)
7425 (effort-prompt "")
7426 (inhibit-read-only t)
7427 (current org-agenda-tag-filter)
7428 maybe-refresh a n tag)
7429 (unless char
7430 (message
7431 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7432 (if narrow "Narrow" "Filter") tag-chars
7433 (if org-agenda-auto-exclude-function "[RET], " ""))
7434 (setq char (read-char-exclusive)))
7435 (when (member char '(?+ ?-))
7436 ;; Narrowing down
7437 (cond ((equal char ?-) (setq strip t narrow t))
7438 ((equal char ?+) (setq strip nil narrow t)))
7439 (message
7440 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7441 (setq char (read-char-exclusive)))
7442 (when (member char '(?< ?> ?= ??))
7443 ;; An effort operator
7444 (setq effort-op (char-to-string char))
7445 (setq alist nil) ; to make sure it will be interpreted as effort.
7446 (unless (equal char ??)
7447 (loop for i from 0 to 9 do
7448 (setq effort-prompt
7449 (concat
7450 effort-prompt " ["
7451 (if (= i 9) "0" (int-to-string (1+ i)))
7452 "]" (nth i efforts))))
7453 (message "Effort%s: %s " effort-op effort-prompt)
7454 (setq char (read-char-exclusive))
7455 (when (or (< char ?0) (> char ?9))
7456 (error "Need 1-9,0 to select effort"))))
7457 (when (equal char ?\t)
7458 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7459 (org-set-local 'org-global-tags-completion-table
7460 (org-global-tags-completion-table)))
7461 (let ((completion-ignore-case t))
7462 (setq tag (org-icompleting-read
7463 "Tag: " org-global-tags-completion-table))))
7464 (cond
7465 ((equal char ?\r)
7466 (org-agenda-filter-show-all-tag)
7467 (when org-agenda-auto-exclude-function
7468 (setq org-agenda-tag-filter '())
7469 (dolist (tag (org-agenda-get-represented-tags))
7470 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7471 (if modifier
7472 (push modifier org-agenda-tag-filter))))
7473 (if (not (null org-agenda-tag-filter))
7474 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7475 (setq maybe-refresh t))
7476 ((equal char ?/)
7477 (org-agenda-filter-show-all-tag)
7478 (when (get 'org-agenda-tag-filter :preset-filter)
7479 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7480 (setq maybe-refresh t))
7481 ((equal char ?. )
7482 (setq org-agenda-tag-filter
7483 (mapcar (lambda(tag) (concat "+" tag))
7484 (org-get-at-bol 'tags)))
7485 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7486 (setq maybe-refresh t))
7487 ((or (equal char ?\ )
7488 (setq a (rassoc char alist))
7489 (and (>= char ?0) (<= char ?9)
7490 (setq n (if (= char ?0) 9 (- char ?0 1))
7491 tag (concat effort-op (nth n efforts))
7492 a (cons tag nil)))
7493 (and (= char ??)
7494 (setq tag "?eff")
7495 a (cons tag nil))
7496 (and tag (setq a (cons tag nil))))
7497 (org-agenda-filter-show-all-tag)
7498 (setq tag (car a))
7499 (setq org-agenda-tag-filter
7500 (cons (concat (if strip "-" "+") tag)
7501 (if narrow current nil)))
7502 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7503 (setq maybe-refresh t))
7504 (t (error "Invalid tag selection character %c" char)))
7505 (when (and maybe-refresh
7506 (eq org-agenda-clockreport-mode 'with-filter))
7507 (org-agenda-redo))))
7509 (defun org-agenda-get-represented-tags ()
7510 "Get a list of all tags currently represented in the agenda."
7511 (let (p tags)
7512 (save-excursion
7513 (goto-char (point-min))
7514 (while (setq p (next-single-property-change (point) 'tags))
7515 (goto-char p)
7516 (mapc (lambda (x) (add-to-list 'tags x))
7517 (get-text-property (point) 'tags))))
7518 tags))
7520 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7521 "Refine the current filter. See `org-agenda-filter-by-tag'."
7522 (interactive "P")
7523 (org-agenda-filter-by-tag strip char 'refine))
7525 (defun org-agenda-filter-make-matcher ()
7526 "Create the form that tests a line for agenda filter."
7527 (let (f f1)
7528 ;; first compute the tag-filter matcher
7529 (dolist (x (delete-dups
7530 (append (get 'org-agenda-tag-filter
7531 :preset-filter) org-agenda-tag-filter)))
7532 (if (member x '("-" "+"))
7533 (setq f1 (if (equal x "-") 'tags '(not tags)))
7534 (if (string-match "[<=>?]" x)
7535 (setq f1 (org-agenda-filter-effort-form x))
7536 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7537 (if (equal (string-to-char x) ?-)
7538 (setq f1 (list 'not f1))))
7539 (push f1 f))
7540 ;; then compute the category-filter matcher
7541 (dolist (x (delete-dups
7542 (append (get 'org-agenda-category-filter
7543 :preset-filter) org-agenda-category-filter)))
7544 (if (equal "-" (substring x 0 1))
7545 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7546 (setq f1 (list 'equal (substring x 1) 'cat)))
7547 (push f1 f))
7548 (cons 'and (nreverse f))))
7550 (defun org-agenda-filter-effort-form (e)
7551 "Return the form to compare the effort of the current line with what E says.
7552 E looks like \"+<2:25\"."
7553 (let (op)
7554 (setq e (substring e 1))
7555 (setq op (string-to-char e) e (substring e 1))
7556 (setq op (cond ((equal op ?<) '<=)
7557 ((equal op ?>) '>=)
7558 ((equal op ??) op)
7559 (t '=)))
7560 (list 'org-agenda-compare-effort (list 'quote op)
7561 (org-duration-string-to-minutes e))))
7563 (defun org-agenda-compare-effort (op value)
7564 "Compare the effort of the current line with VALUE, using OP.
7565 If the line does not have an effort defined, return nil."
7566 (let ((eff (org-get-at-bol 'effort-minutes)))
7567 (if (equal op ??)
7568 (not eff)
7569 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7570 value))))
7572 (defun org-agenda-filter-apply (filter type)
7573 "Set FILTER as the new agenda filter and apply it."
7574 (let (tags cat)
7575 (if (eq type 'tag)
7576 (setq org-agenda-tag-filter filter)
7577 (setq org-agenda-category-filter filter))
7578 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7579 (if (and (eq type 'category)
7580 (not (equal (substring (car filter) 0 1) "-")))
7581 ;; Only set `org-agenda-filtered-by-category' to t
7582 ;; when a unique category is used as the filter
7583 (setq org-agenda-filtered-by-category t))
7584 (org-agenda-set-mode-name)
7585 (save-excursion
7586 (goto-char (point-min))
7587 (while (not (eobp))
7588 (if (org-get-at-bol 'org-marker)
7589 (progn
7590 (setq tags (org-get-at-bol 'tags) ; used in eval
7591 cat (get-text-property (point) 'org-category))
7592 (if (not (eval org-agenda-filter-form))
7593 (org-agenda-filter-hide-line type))
7594 (beginning-of-line 2))
7595 (beginning-of-line 2))))
7596 (if (get-char-property (point) 'invisible)
7597 (ignore-errors (org-agenda-previous-line)))))
7599 (defun org-agenda-filter-top-category-apply (category &optional negative)
7600 "Set FILTER as the new agenda filter and apply it."
7601 (org-agenda-set-mode-name)
7602 (save-excursion
7603 (goto-char (point-min))
7604 (while (not (eobp))
7605 (let* ((pos (org-get-at-bol 'org-hd-marker))
7606 (topcat (and pos (org-find-top-category pos))))
7607 (if (and topcat (funcall (if negative 'identity 'not)
7608 (string= category topcat)))
7609 (org-agenda-filter-hide-line 'category)))
7610 (beginning-of-line 2)))
7611 (if (get-char-property (point) 'invisible)
7612 (org-agenda-previous-line))
7613 (setq org-agenda-top-category-filter category
7614 org-agenda-filtered-by-top-category t))
7616 (defun org-agenda-filter-hide-line (type)
7617 (let (ov)
7618 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7619 (point-at-eol)))
7620 (overlay-put ov 'invisible t)
7621 (overlay-put ov 'type type)
7622 (if (eq type 'tag)
7623 (push ov org-agenda-tag-filter-overlays)
7624 (push ov org-agenda-cat-filter-overlays))))
7626 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7627 (setq pos (or pos (point)))
7628 (save-excursion
7629 (dolist (ov (overlays-at pos))
7630 (when (and (overlay-get ov 'invisible)
7631 (eq (overlay-get ov 'type) 'tag))
7632 (goto-char pos)
7633 (if (< (overlay-start ov) (point-at-eol))
7634 (move-overlay ov (point-at-eol)
7635 (overlay-end ov)))))))
7637 (defun org-agenda-filter-show-all-tag nil
7638 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7639 (setq org-agenda-tag-filter-overlays nil
7640 org-agenda-tag-filter nil
7641 org-agenda-filter-form nil)
7642 (org-agenda-set-mode-name))
7644 (defun org-agenda-filter-show-all-cat nil
7645 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7646 (setq org-agenda-cat-filter-overlays nil
7647 org-agenda-filtered-by-category nil
7648 org-agenda-category-filter nil
7649 org-agenda-filter-form nil)
7650 (org-agenda-set-mode-name))
7652 (defun org-agenda-manipulate-query-add ()
7653 "Manipulate the query by adding a search term with positive selection.
7654 Positive selection means the term must be matched for selection of an entry."
7655 (interactive)
7656 (org-agenda-manipulate-query ?\[))
7657 (defun org-agenda-manipulate-query-subtract ()
7658 "Manipulate the query by adding a search term with negative selection.
7659 Negative selection means term must not be matched for selection of an entry."
7660 (interactive)
7661 (org-agenda-manipulate-query ?\]))
7662 (defun org-agenda-manipulate-query-add-re ()
7663 "Manipulate the query by adding a search regexp with positive selection.
7664 Positive selection means the regexp must match for selection of an entry."
7665 (interactive)
7666 (org-agenda-manipulate-query ?\{))
7667 (defun org-agenda-manipulate-query-subtract-re ()
7668 "Manipulate the query by adding a search regexp with negative selection.
7669 Negative selection means regexp must not match for selection of an entry."
7670 (interactive)
7671 (org-agenda-manipulate-query ?\}))
7672 (defun org-agenda-manipulate-query (char)
7673 (cond
7674 ((memq org-agenda-type '(timeline agenda))
7675 (let ((org-agenda-include-inactive-timestamps t))
7676 (org-agenda-redo))
7677 (message "Display now includes inactive timestamps as well"))
7678 ((eq org-agenda-type 'search)
7679 (org-add-to-string
7680 'org-agenda-query-string
7681 (if org-agenda-last-search-view-search-was-boolean
7682 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7683 (?\{ . " +{}") (?\} . " -{}"))))
7684 " "))
7685 (setq org-agenda-redo-command
7686 (list 'org-search-view
7687 (car (get-text-property (min (1- (point-max)) (point))
7688 'org-last-args))
7689 org-agenda-query-string
7690 (+ (length org-agenda-query-string)
7691 (if (member char '(?\{ ?\})) 0 1))))
7692 (set-register org-agenda-query-register org-agenda-query-string)
7693 (let ((org-agenda-overriding-arguments
7694 (cdr org-agenda-redo-command)))
7695 (org-agenda-redo)))
7696 (t (error "Cannot manipulate query for %s-type agenda buffers"
7697 org-agenda-type))))
7699 (defun org-add-to-string (var string)
7700 (set var (concat (symbol-value var) string)))
7702 (defun org-agenda-goto-date (span)
7703 "Jump to DATE in agenda."
7704 (interactive "P")
7705 (let* ((org-read-date-prefer-future
7706 (eval org-agenda-jump-prefer-future))
7707 (date (org-read-date))
7708 (org-agenda-sticky-orig org-agenda-sticky)
7709 (org-agenda-buffer-tmp-name (buffer-name))
7710 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7711 (0-arg (or current-prefix-arg (car args)))
7712 (2-arg (nth 2 args))
7713 (newcmd (list 'org-agenda-list 0-arg date
7714 (org-agenda-span-to-ndays 2-arg)))
7715 (newargs (cdr newcmd))
7716 (inhibit-read-only t)
7717 org-agenda-sticky)
7718 (if (not (org-agenda-check-type t 'agenda))
7719 (error "Not available in non-agenda blocks")
7720 (add-text-properties (point-min) (point-max)
7721 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7722 (org-agenda-redo)
7723 (setq org-agenda-sticky org-agenda-sticky-orig
7724 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7726 (defun org-agenda-goto-today ()
7727 "Go to today."
7728 (interactive)
7729 (org-agenda-check-type t 'timeline 'agenda)
7730 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7731 (curspan (nth 2 args))
7732 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7733 (cond
7734 (tdpos (goto-char tdpos))
7735 ((eq org-agenda-type 'agenda)
7736 (let* ((sd (org-agenda-compute-starting-span
7737 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7738 (org-agenda-overriding-arguments args))
7739 (setf (nth 1 org-agenda-overriding-arguments) sd)
7740 (org-agenda-redo)
7741 (org-agenda-find-same-or-today-or-agenda)))
7742 (t (error "Cannot find today")))))
7744 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7745 (goto-char
7746 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7747 (text-property-any (point-min) (point-max) 'org-today t)
7748 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7749 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7750 (org-agenda-goto-block-beginning))
7751 (point-min))))
7753 (defun org-agenda-goto-block-beginning ()
7754 "Go the agenda block beginning."
7755 (interactive)
7756 (if (not (derived-mode-p 'org-agenda-mode))
7757 (error "Cannot execute this command outside of org-agenda-mode buffers")
7758 (let (dest)
7759 (save-excursion
7760 (unless (looking-at "\\'")
7761 (forward-char))
7762 (let* ((prop 'org-agenda-structural-header)
7763 (p (previous-single-property-change (point) prop))
7764 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7765 (1- (point))) prop)))
7766 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7767 (if (not dest)
7768 (error "Cannot find the beginning of the blog")
7769 (goto-char dest)
7770 (move-beginning-of-line 1)))))
7772 (defun org-agenda-later (arg)
7773 "Go forward in time by the current span.
7774 With prefix ARG, go forward that many times the current span."
7775 (interactive "p")
7776 (org-agenda-check-type t 'agenda)
7777 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7778 (span (or (nth 2 args) org-agenda-current-span))
7779 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7780 (greg (calendar-gregorian-from-absolute sd))
7781 (cnt (org-get-at-bol 'org-day-cnt))
7782 greg2)
7783 (cond
7784 ((numberp span)
7785 (setq sd (+ (* span arg) sd)))
7786 ((eq span 'day)
7787 (setq sd (+ arg sd)))
7788 ((eq span 'week)
7789 (setq sd (+ (* 7 arg) sd)))
7790 ((eq span 'month)
7791 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7792 sd (calendar-absolute-from-gregorian greg2))
7793 (setcar greg2 (1+ (car greg2))))
7794 ((eq span 'year)
7795 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7796 sd (calendar-absolute-from-gregorian greg2))
7797 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7799 (setq sd (+ (* span arg) sd))))
7800 (let ((org-agenda-overriding-cmd
7801 ;; `cmd' may have been set by `org-agenda-run-series' which
7802 ;; uses `org-agenda-overriding-cmd' to decide whether
7803 ;; overriding is allowed for `cmd'
7804 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7805 (org-agenda-overriding-arguments
7806 (list (car args) sd span)))
7807 (org-agenda-redo)
7808 (org-agenda-find-same-or-today-or-agenda cnt))))
7810 (defun org-agenda-earlier (arg)
7811 "Go backward in time by the current span.
7812 With prefix ARG, go backward that many times the current span."
7813 (interactive "p")
7814 (org-agenda-later (- arg)))
7816 (defun org-agenda-view-mode-dispatch ()
7817 "Call one of the view mode commands."
7818 (interactive)
7819 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7820 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7821 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7822 (let ((a (read-char-exclusive)))
7823 (case a
7824 (?\ (call-interactively 'org-agenda-reset-view))
7825 (?d (call-interactively 'org-agenda-day-view))
7826 (?w (call-interactively 'org-agenda-week-view))
7827 (?m (call-interactively 'org-agenda-month-view))
7828 (?y (call-interactively 'org-agenda-year-view))
7829 (?l (call-interactively 'org-agenda-log-mode))
7830 (?L (org-agenda-log-mode '(4)))
7831 (?c (org-agenda-log-mode 'clockcheck))
7832 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7833 (?a (call-interactively 'org-agenda-archives-mode))
7834 (?A (org-agenda-archives-mode 'files))
7835 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7836 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7837 (?G (call-interactively 'org-agenda-toggle-time-grid))
7838 (?D (call-interactively 'org-agenda-toggle-diary))
7839 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7840 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7841 (org-agenda-check-type t 'timeline 'agenda)
7842 (org-agenda-redo))
7843 (message "Display now includes inactive timestamps as well"))
7844 (?q (message "Abort"))
7845 (otherwise (error "Invalid key" )))))
7847 (defun org-agenda-reset-view ()
7848 "Switch to default view for agenda."
7849 (interactive)
7850 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7851 (defun org-agenda-day-view (&optional day-of-year)
7852 "Switch to daily view for agenda.
7853 With argument DAY-OF-YEAR, switch to that day of the year."
7854 (interactive "P")
7855 (org-agenda-change-time-span 'day day-of-year))
7856 (defun org-agenda-week-view (&optional iso-week)
7857 "Switch to daily view for agenda.
7858 With argument ISO-WEEK, switch to the corresponding ISO week.
7859 If ISO-WEEK has more then 2 digits, only the last two encode the
7860 week. Any digits before this encode a year. So 200712 means
7861 week 12 of year 2007. Years in the range 1938-2037 can also be
7862 written as 2-digit years."
7863 (interactive "P")
7864 (org-agenda-change-time-span 'week iso-week))
7865 (defun org-agenda-month-view (&optional month)
7866 "Switch to monthly view for agenda.
7867 With argument MONTH, switch to that month."
7868 (interactive "P")
7869 (org-agenda-change-time-span 'month month))
7870 (defun org-agenda-year-view (&optional year)
7871 "Switch to yearly view for agenda.
7872 With argument YEAR, switch to that year.
7873 If MONTH has more then 2 digits, only the last two encode the
7874 month. Any digits before this encode a year. So 200712 means
7875 December year 2007. Years in the range 1938-2037 can also be
7876 written as 2-digit years."
7877 (interactive "P")
7878 (when year
7879 (setq year (org-small-year-to-year year)))
7880 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7881 (org-agenda-change-time-span 'year year)
7882 (error "Abort")))
7884 (defun org-agenda-change-time-span (span &optional n)
7885 "Change the agenda view to SPAN.
7886 SPAN may be `day', `week', `month', `year'."
7887 (org-agenda-check-type t 'agenda)
7888 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7889 (curspan (nth 2 args)))
7890 (if (and (not n) (equal curspan span))
7891 (error "Viewing span is already \"%s\"" span))
7892 (let* ((sd (or (org-get-at-bol 'day)
7893 (nth 1 args)
7894 org-starting-day))
7895 (sd (org-agenda-compute-starting-span sd span n))
7896 (org-agenda-overriding-cmd
7897 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7898 (org-agenda-overriding-arguments
7899 (list (car args) sd span)))
7900 (org-agenda-redo)
7901 (org-agenda-find-same-or-today-or-agenda))
7902 (org-agenda-set-mode-name)
7903 (message "Switched to %s view" span)))
7905 (defun org-agenda-compute-starting-span (sd span &optional n)
7906 "Compute starting date for agenda.
7907 SPAN may be `day', `week', `month', `year'. The return value
7908 is a cons cell with the starting date and the number of days,
7909 so that the date SD will be in that range."
7910 (let* ((greg (calendar-gregorian-from-absolute sd))
7911 (dg (nth 1 greg))
7912 (mg (car greg))
7913 (yg (nth 2 greg)))
7914 (cond
7915 ((eq span 'day)
7916 (when n
7917 (setq sd (+ (calendar-absolute-from-gregorian
7918 (list mg 1 yg))
7919 n -1))))
7920 ((eq span 'week)
7921 (let* ((nt (calendar-day-of-week
7922 (calendar-gregorian-from-absolute sd)))
7923 (d (if org-agenda-start-on-weekday
7924 (- nt org-agenda-start-on-weekday)
7927 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7928 (when n
7929 (require 'cal-iso)
7930 (when (> n 99)
7931 (setq y1 (org-small-year-to-year (/ n 100))
7932 n (mod n 100)))
7933 (setq sd
7934 (calendar-absolute-from-iso
7935 (list n 1
7936 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7937 ((eq span 'month)
7938 (let (y1)
7939 (when (and n (> n 99))
7940 (setq y1 (org-small-year-to-year (/ n 100))
7941 n (mod n 100)))
7942 (setq sd (calendar-absolute-from-gregorian
7943 (list (or n mg) 1 (or y1 yg))))))
7944 ((eq span 'year)
7945 (setq sd (calendar-absolute-from-gregorian
7946 (list 1 1 (or n yg))))))
7947 sd))
7949 (defun org-agenda-next-date-line (&optional arg)
7950 "Jump to the next line indicating a date in agenda buffer."
7951 (interactive "p")
7952 (org-agenda-check-type t 'agenda 'timeline)
7953 (beginning-of-line 1)
7954 ;; This does not work if user makes date format that starts with a blank
7955 (if (looking-at "^\\S-") (forward-char 1))
7956 (if (not (re-search-forward "^\\S-" nil t arg))
7957 (progn
7958 (backward-char 1)
7959 (error "No next date after this line in this buffer")))
7960 (goto-char (match-beginning 0)))
7962 (defun org-agenda-previous-date-line (&optional arg)
7963 "Jump to the previous line indicating a date in agenda buffer."
7964 (interactive "p")
7965 (org-agenda-check-type t 'agenda 'timeline)
7966 (beginning-of-line 1)
7967 (if (not (re-search-backward "^\\S-" nil t arg))
7968 (error "No previous date before this line in this buffer")))
7970 ;; Initialize the highlight
7971 (defvar org-hl (make-overlay 1 1))
7972 (overlay-put org-hl 'face 'highlight)
7974 (defun org-highlight (begin end &optional buffer)
7975 "Highlight a region with overlay."
7976 (move-overlay org-hl begin end (or buffer (current-buffer))))
7978 (defun org-unhighlight ()
7979 "Detach overlay INDEX."
7980 (org-detach-overlay org-hl))
7982 (defun org-unhighlight-once ()
7983 "Remove the highlight from its position, and this function from the hook."
7984 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7985 (org-unhighlight))
7987 (defvar org-agenda-pre-follow-window-conf nil)
7988 (defun org-agenda-follow-mode ()
7989 "Toggle follow mode in an agenda buffer."
7990 (interactive)
7991 (unless org-agenda-follow-mode
7992 (setq org-agenda-pre-follow-window-conf
7993 (current-window-configuration)))
7994 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7995 (unless org-agenda-follow-mode
7996 (set-window-configuration org-agenda-pre-follow-window-conf))
7997 (org-agenda-set-mode-name)
7998 (org-agenda-do-context-action)
7999 (message "Follow mode is %s"
8000 (if org-agenda-follow-mode "on" "off")))
8002 (defun org-agenda-entry-text-mode (&optional arg)
8003 "Toggle entry text mode in an agenda buffer."
8004 (interactive "P")
8005 (setq org-agenda-entry-text-mode (or (integerp arg)
8006 (not org-agenda-entry-text-mode)))
8007 (org-agenda-entry-text-hide)
8008 (and org-agenda-entry-text-mode
8009 (let ((org-agenda-entry-text-maxlines
8010 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8011 (org-agenda-entry-text-show)))
8012 (org-agenda-set-mode-name)
8013 (message "Entry text mode is %s. Maximum number of lines is %d"
8014 (if org-agenda-entry-text-mode "on" "off")
8015 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
8017 (defun org-agenda-clockreport-mode (&optional with-filter)
8018 "Toggle clocktable mode in an agenda buffer.
8019 With prefix arg WITH-FILTER, make the clocktable respect the current
8020 agenda filter."
8021 (interactive "P")
8022 (org-agenda-check-type t 'agenda)
8023 (if with-filter
8024 (setq org-agenda-clockreport-mode 'with-filter)
8025 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
8026 (org-agenda-set-mode-name)
8027 (org-agenda-redo)
8028 (message "Clocktable mode is %s"
8029 (if org-agenda-clockreport-mode "on" "off")))
8031 (defun org-agenda-log-mode (&optional special)
8032 "Toggle log mode in an agenda buffer.
8033 With argument SPECIAL, show all possible log items, not only the ones
8034 configured in `org-agenda-log-mode-items'.
8035 With a double `C-u' prefix arg, show *only* log items, nothing else."
8036 (interactive "P")
8037 (org-agenda-check-type t 'agenda 'timeline)
8038 (setq org-agenda-show-log
8039 (cond
8040 ((equal special '(16)) 'only)
8041 ((eq special 'clockcheck)
8042 (if (eq org-agenda-show-log 'clockcheck)
8043 nil 'clockcheck))
8044 (special '(closed clock state))
8045 (t (not org-agenda-show-log))))
8046 (org-agenda-set-mode-name)
8047 (org-agenda-redo)
8048 (message "Log mode is %s"
8049 (if org-agenda-show-log "on" "off")))
8051 (defun org-agenda-archives-mode (&optional with-files)
8052 "Toggle inclusion of items in trees marked with :ARCHIVE:.
8053 When called with a prefix argument, include all archive files as well."
8054 (interactive "P")
8055 (setq org-agenda-archives-mode
8056 (if with-files t (if org-agenda-archives-mode nil 'trees)))
8057 (org-agenda-set-mode-name)
8058 (org-agenda-redo)
8059 (message
8060 "%s"
8061 (cond
8062 ((eq org-agenda-archives-mode nil)
8063 "No archives are included")
8064 ((eq org-agenda-archives-mode 'trees)
8065 (format "Trees with :%s: tag are included" org-archive-tag))
8066 ((eq org-agenda-archives-mode t)
8067 (format "Trees with :%s: tag and all active archive files are included"
8068 org-archive-tag)))))
8070 (defun org-agenda-toggle-diary ()
8071 "Toggle diary inclusion in an agenda buffer."
8072 (interactive)
8073 (org-agenda-check-type t 'agenda)
8074 (setq org-agenda-include-diary (not org-agenda-include-diary))
8075 (org-agenda-redo)
8076 (org-agenda-set-mode-name)
8077 (message "Diary inclusion turned %s"
8078 (if org-agenda-include-diary "on" "off")))
8080 (defun org-agenda-toggle-deadlines ()
8081 "Toggle inclusion of entries with a deadline in an agenda buffer."
8082 (interactive)
8083 (org-agenda-check-type t 'agenda)
8084 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
8085 (org-agenda-redo)
8086 (org-agenda-set-mode-name)
8087 (message "Deadlines inclusion turned %s"
8088 (if org-agenda-include-deadlines "on" "off")))
8090 (defun org-agenda-toggle-time-grid ()
8091 "Toggle time grid in an agenda buffer."
8092 (interactive)
8093 (org-agenda-check-type t 'agenda)
8094 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
8095 (org-agenda-redo)
8096 (org-agenda-set-mode-name)
8097 (message "Time-grid turned %s"
8098 (if org-agenda-use-time-grid "on" "off")))
8100 (defun org-agenda-set-mode-name ()
8101 "Set the mode name to indicate all the small mode settings."
8102 (setq mode-name
8103 (list "Org-Agenda"
8104 (if (get 'org-agenda-files 'org-restrict) " []" "")
8106 '(:eval (org-agenda-span-name org-agenda-current-span))
8107 (if org-agenda-follow-mode " Follow" "")
8108 (if org-agenda-entry-text-mode " ETxt" "")
8109 (if org-agenda-include-diary " Diary" "")
8110 (if org-agenda-include-deadlines " Ddl" "")
8111 (if org-agenda-use-time-grid " Grid" "")
8112 (if (and (boundp 'org-habit-show-habits)
8113 org-habit-show-habits) " Habit" "")
8114 (cond
8115 ((consp org-agenda-show-log) " LogAll")
8116 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
8117 (org-agenda-show-log " Log")
8118 (t ""))
8119 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
8120 :preset-filter))
8121 '(:eval (org-propertize
8122 (concat " <"
8123 (mapconcat
8124 'identity
8125 (append
8126 (get 'org-agenda-category-filter :preset-filter)
8127 org-agenda-category-filter)
8129 ">")
8130 'face 'org-agenda-filter-category
8131 'help-echo "Category used in filtering"))
8133 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
8134 :preset-filter))
8135 '(:eval (org-propertize
8136 (concat " {"
8137 (mapconcat
8138 'identity
8139 (append
8140 (get 'org-agenda-tag-filter :preset-filter)
8141 org-agenda-tag-filter)
8143 "}")
8144 'face 'org-agenda-filter-tags
8145 'help-echo "Tags used in filtering"))
8147 (if org-agenda-archives-mode
8148 (if (eq org-agenda-archives-mode t)
8149 " Archives"
8150 (format " :%s:" org-archive-tag))
8152 (if org-agenda-clockreport-mode
8153 (if (eq org-agenda-clockreport-mode 'with-filter)
8154 " Clock{}" " Clock")
8155 "")))
8156 (force-mode-line-update))
8158 (define-obsolete-function-alias
8159 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
8161 (defun org-agenda-update-agenda-type ()
8162 "Update the agenda type after each command."
8163 (setq org-agenda-type
8164 (or (get-text-property (point) 'org-agenda-type)
8165 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
8167 (defun org-agenda-next-line ()
8168 "Move cursor to the next line, and show if follow mode is active."
8169 (interactive)
8170 (call-interactively 'next-line)
8171 (org-agenda-do-context-action))
8173 (defun org-agenda-previous-line ()
8174 "Move cursor to the previous line, and show if follow-mode is active."
8175 (interactive)
8176 (call-interactively 'previous-line)
8177 (org-agenda-do-context-action))
8179 (defun org-agenda-next-item (n)
8180 "Move cursor to next agenda item."
8181 (interactive "p")
8182 (let ((col (current-column)))
8183 (dotimes (c n)
8184 (when (next-single-property-change (point-at-eol) 'org-marker)
8185 (move-end-of-line 1)
8186 (goto-char (next-single-property-change (point) 'org-marker))))
8187 (org-move-to-column col))
8188 (org-agenda-do-context-action))
8190 (defun org-agenda-previous-item (n)
8191 "Move cursor to next agenda item."
8192 (interactive "p")
8193 (dotimes (c n)
8194 (let ((col (current-column))
8195 (goto (save-excursion
8196 (move-end-of-line 0)
8197 (previous-single-property-change (point) 'org-marker))))
8198 (if goto (goto-char goto))
8199 (org-move-to-column col)))
8200 (org-agenda-do-context-action))
8202 (defun org-agenda-do-context-action ()
8203 "Show outline path and, maybe, follow mode window."
8204 (let ((m (org-get-at-bol 'org-marker)))
8205 (when (and (markerp m) (marker-buffer m))
8206 (and org-agenda-follow-mode
8207 (if org-agenda-follow-indirect
8208 (org-agenda-tree-to-indirect-buffer nil)
8209 (org-agenda-show)))
8210 (and org-agenda-show-outline-path
8211 (org-with-point-at m (org-display-outline-path t))))))
8213 (defun org-agenda-show-tags ()
8214 "Show the tags applicable to the current item."
8215 (interactive)
8216 (let* ((tags (org-get-at-bol 'tags)))
8217 (if tags
8218 (message "Tags are :%s:"
8219 (org-no-properties (mapconcat 'identity tags ":")))
8220 (message "No tags associated with this line"))))
8222 (defun org-agenda-goto (&optional highlight)
8223 "Go to the Org-mode file which contains the item at point."
8224 (interactive)
8225 (let* ((marker (or (org-get-at-bol 'org-marker)
8226 (org-agenda-error)))
8227 (buffer (marker-buffer marker))
8228 (pos (marker-position marker)))
8229 (switch-to-buffer-other-window buffer)
8230 (widen)
8231 (push-mark)
8232 (goto-char pos)
8233 (when (derived-mode-p 'org-mode)
8234 (org-show-context 'agenda)
8235 (save-excursion
8236 (and (outline-next-heading)
8237 (org-flag-heading nil)))) ; show the next heading
8238 (when (outline-invisible-p)
8239 (show-entry)) ; display invisible text
8240 (recenter (/ (window-height) 2))
8241 (run-hooks 'org-agenda-after-show-hook)
8242 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
8244 (defvar org-agenda-after-show-hook nil
8245 "Normal hook run after an item has been shown from the agenda.
8246 Point is in the buffer where the item originated.")
8248 (defun org-agenda-kill ()
8249 "Kill the entry or subtree belonging to the current agenda entry."
8250 (interactive)
8251 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8252 (let* ((bufname-orig (buffer-name))
8253 (marker (or (org-get-at-bol 'org-marker)
8254 (org-agenda-error)))
8255 (buffer (marker-buffer marker))
8256 (pos (marker-position marker))
8257 (type (org-get-at-bol 'type))
8258 dbeg dend (n 0) conf)
8259 (org-with-remote-undo buffer
8260 (with-current-buffer buffer
8261 (save-excursion
8262 (goto-char pos)
8263 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
8264 (setq dbeg (progn (org-back-to-heading t) (point))
8265 dend (org-end-of-subtree t t))
8266 (setq dbeg (point-at-bol)
8267 dend (min (point-max) (1+ (point-at-eol)))))
8268 (goto-char dbeg)
8269 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8270 (setq conf (or (eq t org-agenda-confirm-kill)
8271 (and (numberp org-agenda-confirm-kill)
8272 (> n org-agenda-confirm-kill))))
8273 (and conf
8274 (not (y-or-n-p
8275 (format "Delete entry with %d lines in buffer \"%s\"? "
8276 n (buffer-name buffer))))
8277 (error "Abort"))
8278 (let ((org-agenda-buffer-name bufname-orig))
8279 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8280 (with-current-buffer buffer (delete-region dbeg dend))
8281 (message "Agenda item and source killed"))))
8283 (defvar org-archive-default-command) ; defined in org-archive.el
8284 (defun org-agenda-archive-default ()
8285 "Archive the entry or subtree belonging to the current agenda entry."
8286 (interactive)
8287 (require 'org-archive)
8288 (org-agenda-archive-with org-archive-default-command))
8290 (defun org-agenda-archive-default-with-confirmation ()
8291 "Archive the entry or subtree belonging to the current agenda entry."
8292 (interactive)
8293 (require 'org-archive)
8294 (org-agenda-archive-with org-archive-default-command 'confirm))
8296 (defun org-agenda-archive ()
8297 "Archive the entry or subtree belonging to the current agenda entry."
8298 (interactive)
8299 (org-agenda-archive-with 'org-archive-subtree))
8301 (defun org-agenda-archive-to-archive-sibling ()
8302 "Move the entry to the archive sibling."
8303 (interactive)
8304 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8306 (defun org-agenda-archive-with (cmd &optional confirm)
8307 "Move the entry to the archive sibling."
8308 (interactive)
8309 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8310 (let* ((bufname-orig (buffer-name))
8311 (marker (or (org-get-at-bol 'org-marker)
8312 (org-agenda-error)))
8313 (buffer (marker-buffer marker))
8314 (pos (marker-position marker)))
8315 (org-with-remote-undo buffer
8316 (with-current-buffer buffer
8317 (if (derived-mode-p 'org-mode)
8318 (if (and confirm
8319 (not (y-or-n-p "Archive this subtree or entry? ")))
8320 (error "Abort")
8321 (save-excursion
8322 (goto-char pos)
8323 (let ((org-agenda-buffer-name bufname-orig))
8324 (org-remove-subtree-entries-from-agenda))
8325 (org-back-to-heading t)
8326 (funcall cmd)))
8327 (error "Archiving works only in Org-mode files"))))))
8329 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8330 "Remove all lines in the agenda that correspond to a given subtree.
8331 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8332 If this information is not given, the function uses the tree at point."
8333 (let ((buf (or buf (current-buffer))) m p)
8334 (save-excursion
8335 (unless (and beg end)
8336 (org-back-to-heading t)
8337 (setq beg (point))
8338 (org-end-of-subtree t)
8339 (setq end (point)))
8340 (set-buffer (get-buffer org-agenda-buffer-name))
8341 (save-excursion
8342 (goto-char (point-max))
8343 (beginning-of-line 1)
8344 (while (not (bobp))
8345 (when (and (setq m (org-get-at-bol 'org-marker))
8346 (equal buf (marker-buffer m))
8347 (setq p (marker-position m))
8348 (>= p beg)
8349 (< p end))
8350 (let ((inhibit-read-only t))
8351 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8352 (beginning-of-line 0))))))
8354 (defun org-agenda-refile (&optional goto rfloc no-update)
8355 "Refile the item at point."
8356 (interactive "P")
8357 (if (equal goto '(16))
8358 (org-refile-goto-last-stored)
8359 (let* ((buffer-orig (buffer-name))
8360 (marker (or (org-get-at-bol 'org-hd-marker)
8361 (org-agenda-error)))
8362 (buffer (marker-buffer marker))
8363 (pos (marker-position marker))
8364 (rfloc (or rfloc
8365 (org-refile-get-location
8366 (if goto "Goto" "Refile to") buffer
8367 org-refile-allow-creating-parent-nodes))))
8368 (with-current-buffer buffer
8369 (save-excursion
8370 (save-restriction
8371 (widen)
8372 (goto-char marker)
8373 (let ((org-agenda-buffer-name buffer-orig))
8374 (org-remove-subtree-entries-from-agenda))
8375 (org-refile goto buffer rfloc)))))
8376 (unless no-update (org-agenda-redo))))
8378 (defun org-agenda-open-link (&optional arg)
8379 "Open the link(s) in the current entry, if any.
8380 This looks for a link in the displayed line in the agenda.
8381 It also looks at the text of the entry itself."
8382 (interactive "P")
8383 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8384 (org-get-at-bol 'org-marker)))
8385 (buffer (and marker (marker-buffer marker)))
8386 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8387 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8388 (lk0 (car lkall))
8389 (lk (if (stringp lk0) (list lk0) lk0))
8390 (lkend (cdr lkall))
8391 trg)
8392 (cond
8393 ((and buffer lk)
8394 (mapcar (lambda(l)
8395 (with-current-buffer buffer
8396 (setq trg (and (string-match org-bracket-link-regexp l)
8397 (match-string 1 l)))
8398 (if (or (not trg) (string-match org-any-link-re trg))
8399 (save-excursion
8400 (save-restriction
8401 (widen)
8402 (goto-char marker)
8403 (when (search-forward l nil lkend)
8404 (goto-char (match-beginning 0))
8405 (org-open-at-point))))
8406 ;; This is an internal link, widen the buffer
8407 (switch-to-buffer-other-window buffer)
8408 (widen)
8409 (goto-char marker)
8410 (when (search-forward l nil lkend)
8411 (goto-char (match-beginning 0))
8412 (org-open-at-point)))))
8413 lk))
8414 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8415 (save-excursion
8416 (beginning-of-line 1)
8417 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8418 (org-open-link-from-string (match-string 1)))
8419 (t (message "No link to open here")))))
8421 (defun org-agenda-copy-local-variable (var)
8422 "Get a variable from a referenced buffer and install it here."
8423 (let ((m (org-get-at-bol 'org-marker)))
8424 (when (and m (buffer-live-p (marker-buffer m)))
8425 (org-set-local var (with-current-buffer (marker-buffer m)
8426 (symbol-value var))))))
8428 (defun org-agenda-switch-to (&optional delete-other-windows)
8429 "Go to the Org-mode file which contains the item at point."
8430 (interactive)
8431 (if (and org-return-follows-link
8432 (not (org-get-at-bol 'org-marker))
8433 (org-in-regexp org-bracket-link-regexp))
8434 (org-open-link-from-string (match-string 0))
8435 (let* ((marker (or (org-get-at-bol 'org-marker)
8436 (org-agenda-error)))
8437 (buffer (marker-buffer marker))
8438 (pos (marker-position marker)))
8439 (org-pop-to-buffer-same-window buffer)
8440 (and delete-other-windows (delete-other-windows))
8441 (widen)
8442 (goto-char pos)
8443 (when (derived-mode-p 'org-mode)
8444 (org-show-context 'agenda)
8445 (save-excursion
8446 (and (outline-next-heading)
8447 (org-flag-heading nil))) ; show the next heading
8448 (when (outline-invisible-p)
8449 (show-entry)) ; display invisible text
8450 (run-hooks 'org-agenda-after-show-hook)))))
8452 (defun org-agenda-goto-mouse (ev)
8453 "Go to the Org-mode file which contains the item at the mouse click."
8454 (interactive "e")
8455 (mouse-set-point ev)
8456 (org-agenda-goto))
8458 (defun org-agenda-show (&optional full-entry)
8459 "Display the Org-mode file which contains the item at point.
8460 With prefix argument FULL-ENTRY, make the entire entry visible
8461 if it was hidden in the outline."
8462 (interactive "P")
8463 (let ((win (selected-window)))
8464 (if full-entry
8465 (let ((org-show-entry-below t))
8466 (org-agenda-goto t))
8467 (org-agenda-goto t))
8468 (select-window win)))
8470 (defvar org-agenda-show-window nil)
8471 (defun org-agenda-show-and-scroll-up (&optional arg)
8472 "Display the Org-mode file which contains the item at point.
8473 When called repeatedly, scroll the window that is displaying the buffer.
8474 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8475 `show-subtree' to display the item, so that drawers and logbooks stay
8476 folded."
8477 (interactive "P")
8478 (let ((win (selected-window)))
8479 (if (and (window-live-p org-agenda-show-window)
8480 (eq this-command last-command))
8481 (progn
8482 (select-window org-agenda-show-window)
8483 (ignore-errors (scroll-up)))
8484 (org-agenda-goto t)
8485 (if arg (org-show-entry) (show-subtree))
8486 (setq org-agenda-show-window (selected-window)))
8487 (select-window win)))
8489 (defun org-agenda-show-scroll-down ()
8490 "Scroll down the window showing the agenda."
8491 (interactive)
8492 (let ((win (selected-window)))
8493 (when (window-live-p org-agenda-show-window)
8494 (select-window org-agenda-show-window)
8495 (ignore-errors (scroll-down))
8496 (select-window win))))
8498 (defun org-agenda-show-1 (&optional more)
8499 "Display the Org-mode file which contains the item at point.
8500 The prefix arg selects the amount of information to display:
8502 0 hide the subtree
8503 1 just show the entry according to defaults.
8504 2 show the children view
8505 3 show the subtree view
8506 4 show the entire subtree and any LOGBOOK drawers
8507 5 show the entire subtree and any drawers
8508 With prefix argument FULL-ENTRY, make the entire entry visible
8509 if it was hidden in the outline."
8510 (interactive "p")
8511 (let ((win (selected-window)))
8512 (org-agenda-goto t)
8513 (org-recenter-heading 1)
8514 (cond
8515 ((= more 0)
8516 (hide-subtree)
8517 (save-excursion
8518 (org-back-to-heading)
8519 (run-hook-with-args 'org-cycle-hook 'folded))
8520 (message "Remote: FOLDED"))
8521 ((and (org-called-interactively-p 'any) (= more 1))
8522 (message "Remote: show with default settings"))
8523 ((= more 2)
8524 (show-entry)
8525 (show-children)
8526 (save-excursion
8527 (org-back-to-heading)
8528 (run-hook-with-args 'org-cycle-hook 'children))
8529 (message "Remote: CHILDREN"))
8530 ((= more 3)
8531 (show-subtree)
8532 (save-excursion
8533 (org-back-to-heading)
8534 (run-hook-with-args 'org-cycle-hook 'subtree))
8535 (message "Remote: SUBTREE"))
8536 ((= more 4)
8537 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8538 (org-drawer-regexp
8539 (concat "^[ \t]*:\\("
8540 (mapconcat 'regexp-quote org-drawers "\\|")
8541 "\\):[ \t]*$")))
8542 (show-subtree)
8543 (save-excursion
8544 (org-back-to-heading)
8545 (org-cycle-hide-drawers 'subtree)))
8546 (message "Remote: SUBTREE AND LOGBOOK"))
8547 ((> more 4)
8548 (show-subtree)
8549 (message "Remote: SUBTREE AND ALL DRAWERS")))
8550 (select-window win)))
8552 (defun org-recenter-heading (n)
8553 (save-excursion
8554 (org-back-to-heading)
8555 (recenter n)))
8557 (defvar org-agenda-cycle-counter nil)
8558 (defun org-agenda-cycle-show (&optional n)
8559 "Show the current entry in another window, with default settings.
8560 Default settings are taken from `org-show-hierarchy-above' and siblings.
8561 When use repeatedly in immediate succession, the remote entry will cycle
8562 through visibility
8564 children -> subtree -> folded
8566 When called with a numeric prefix arg, that arg will be passed through to
8567 `org-agenda-show-1'. For the interpretation of that argument, see the
8568 docstring of `org-agenda-show-1'."
8569 (interactive "P")
8570 (if (integerp n)
8571 (setq org-agenda-cycle-counter n)
8572 (if (not (eq last-command this-command))
8573 (setq org-agenda-cycle-counter 1)
8574 (if (equal org-agenda-cycle-counter 0)
8575 (setq org-agenda-cycle-counter 2)
8576 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8577 (if (> org-agenda-cycle-counter 3)
8578 (setq org-agenda-cycle-counter 0)))))
8579 (org-agenda-show-1 org-agenda-cycle-counter))
8581 (defun org-agenda-recenter (arg)
8582 "Display the Org-mode file which contains the item at point and recenter."
8583 (interactive "P")
8584 (let ((win (selected-window)))
8585 (org-agenda-goto t)
8586 (recenter arg)
8587 (select-window win)))
8589 (defun org-agenda-show-mouse (ev)
8590 "Display the Org-mode file which contains the item at the mouse click."
8591 (interactive "e")
8592 (mouse-set-point ev)
8593 (org-agenda-show))
8595 (defun org-agenda-check-no-diary ()
8596 "Check if the entry is a diary link and abort if yes."
8597 (if (org-get-at-bol 'org-agenda-diary-link)
8598 (org-agenda-error)))
8600 (defun org-agenda-error ()
8601 (error "Command not allowed in this line"))
8603 (defun org-agenda-tree-to-indirect-buffer (arg)
8604 "Show the subtree corresponding to the current entry in an indirect buffer.
8605 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8607 With a numerical prefix ARG, go up to this level and then take that tree.
8608 With a negative numeric ARG, go up by this number of levels.
8609 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8610 use the dedicated frame)."
8611 (interactive "P")
8612 (if current-prefix-arg
8613 (org-agenda-do-tree-to-indirect-buffer arg)
8614 (let ((agenda-buffer (buffer-name))
8615 (agenda-window (selected-window))
8616 (indirect-window
8617 (and org-last-indirect-buffer
8618 (get-buffer-window org-last-indirect-buffer))))
8619 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8620 (unless (or (eq org-indirect-buffer-display 'new-frame)
8621 (eq org-indirect-buffer-display 'dedicated-frame))
8622 (unwind-protect
8623 (unless (and indirect-window (window-live-p indirect-window))
8624 (setq indirect-window (split-window agenda-window)))
8625 (and indirect-window (select-window indirect-window))
8626 (switch-to-buffer org-last-indirect-buffer :norecord)
8627 (fit-window-to-buffer indirect-window)))
8628 (select-window (get-buffer-window agenda-buffer)))))
8630 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8631 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8632 (org-agenda-check-no-diary)
8633 (let* ((marker (or (org-get-at-bol 'org-marker)
8634 (org-agenda-error)))
8635 (buffer (marker-buffer marker))
8636 (pos (marker-position marker)))
8637 (with-current-buffer buffer
8638 (save-excursion
8639 (goto-char pos)
8640 (funcall 'org-tree-to-indirect-buffer arg)))))
8642 (defvar org-last-heading-marker (make-marker)
8643 "Marker pointing to the headline that last changed its TODO state
8644 by a remote command from the agenda.")
8646 (defun org-agenda-todo-nextset ()
8647 "Switch TODO entry to next sequence."
8648 (interactive)
8649 (org-agenda-todo 'nextset))
8651 (defun org-agenda-todo-previousset ()
8652 "Switch TODO entry to previous sequence."
8653 (interactive)
8654 (org-agenda-todo 'previousset))
8656 (defun org-agenda-todo (&optional arg)
8657 "Cycle TODO state of line at point, also in Org-mode file.
8658 This changes the line at point, all other lines in the agenda referring to
8659 the same tree node, and the headline of the tree node in the Org-mode file."
8660 (interactive "P")
8661 (org-agenda-check-no-diary)
8662 (let* ((col (current-column))
8663 (marker (or (org-get-at-bol 'org-marker)
8664 (org-agenda-error)))
8665 (buffer (marker-buffer marker))
8666 (pos (marker-position marker))
8667 (hdmarker (org-get-at-bol 'org-hd-marker))
8668 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8669 (inhibit-read-only t)
8670 org-agenda-headline-snapshot-before-repeat newhead just-one)
8671 (org-with-remote-undo buffer
8672 (with-current-buffer buffer
8673 (widen)
8674 (goto-char pos)
8675 (org-show-context 'agenda)
8676 (save-excursion
8677 (and (outline-next-heading)
8678 (org-flag-heading nil))) ; show the next heading
8679 (let ((current-prefix-arg arg))
8680 (call-interactively 'org-todo))
8681 (and (bolp) (forward-char 1))
8682 (setq newhead (org-get-heading))
8683 (when (and (org-bound-and-true-p
8684 org-agenda-headline-snapshot-before-repeat)
8685 (not (equal org-agenda-headline-snapshot-before-repeat
8686 newhead))
8687 todayp)
8688 (setq newhead org-agenda-headline-snapshot-before-repeat
8689 just-one t))
8690 (save-excursion
8691 (org-back-to-heading)
8692 (move-marker org-last-heading-marker (point))))
8693 (beginning-of-line 1)
8694 (save-excursion
8695 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8696 (org-move-to-column col))))
8698 (defun org-agenda-add-note (&optional arg)
8699 "Add a time-stamped note to the entry at point."
8700 (interactive "P")
8701 (org-agenda-check-no-diary)
8702 (let* ((marker (or (org-get-at-bol 'org-marker)
8703 (org-agenda-error)))
8704 (buffer (marker-buffer marker))
8705 (pos (marker-position marker))
8706 (hdmarker (org-get-at-bol 'org-hd-marker))
8707 (inhibit-read-only t))
8708 (with-current-buffer buffer
8709 (widen)
8710 (goto-char pos)
8711 (org-show-context 'agenda)
8712 (save-excursion
8713 (and (outline-next-heading)
8714 (org-flag-heading nil))) ; show the next heading
8715 (org-add-note))))
8717 (defun org-agenda-change-all-lines (newhead hdmarker
8718 &optional fixface just-this)
8719 "Change all lines in the agenda buffer which match HDMARKER.
8720 The new content of the line will be NEWHEAD (as modified by
8721 `org-agenda-format-item'). HDMARKER is checked with
8722 `equal' against all `org-hd-marker' text properties in the file.
8723 If FIXFACE is non-nil, the face of each item is modified according to
8724 the new TODO state.
8725 If JUST-THIS is non-nil, change just the current line, not all.
8726 If FORCE-TAGS is non nil, the car of it returns the new tags."
8727 (let* ((inhibit-read-only t)
8728 (line (org-current-line))
8729 (org-agenda-buffer (current-buffer))
8730 (thetags (with-current-buffer (marker-buffer hdmarker)
8731 (save-excursion (save-restriction (widen)
8732 (goto-char hdmarker)
8733 (org-get-tags-at)))))
8734 props m pl undone-face done-face finish new dotime level cat tags)
8735 (save-excursion
8736 (goto-char (point-max))
8737 (beginning-of-line 1)
8738 (while (not finish)
8739 (setq finish (bobp))
8740 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8741 (or (not just-this) (= (org-current-line) line))
8742 (equal m hdmarker))
8743 (setq props (text-properties-at (point))
8744 dotime (org-get-at-bol 'dotime)
8745 cat (org-get-at-bol 'org-category)
8746 level (org-get-at-bol 'level)
8747 tags thetags
8749 (let ((org-prefix-format-compiled
8750 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8751 org-prefix-format-compiled))
8752 (extra (org-get-at-bol 'extra)))
8753 (with-current-buffer (marker-buffer hdmarker)
8754 (save-excursion
8755 (save-restriction
8756 (widen)
8757 (org-agenda-format-item extra newhead level cat tags dotime)))))
8758 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8759 undone-face (org-get-at-bol 'undone-face)
8760 done-face (org-get-at-bol 'done-face))
8761 (beginning-of-line 1)
8762 (cond
8763 ((equal new "")
8764 (and (looking-at ".*\n?") (replace-match "")))
8765 ((looking-at ".*")
8766 (replace-match new t t)
8767 (beginning-of-line 1)
8768 (add-text-properties (point-at-bol) (point-at-eol) props)
8769 (when fixface
8770 (add-text-properties
8771 (point-at-bol) (point-at-eol)
8772 (list 'face
8773 (if org-last-todo-state-is-todo
8774 undone-face done-face))))
8775 (org-agenda-highlight-todo 'line)
8776 (beginning-of-line 1))
8777 (t (error "Line update did not work")))
8778 (save-restriction
8779 (narrow-to-region (point-at-bol) (point-at-eol))
8780 (org-agenda-finalize)))
8781 (beginning-of-line 0)))))
8783 (defun org-agenda-align-tags (&optional line)
8784 "Align all tags in agenda items to `org-agenda-tags-column'."
8785 (let ((inhibit-read-only t) l c)
8786 (save-excursion
8787 (goto-char (if line (point-at-bol) (point-min)))
8788 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8789 (if line (point-at-eol) nil) t)
8790 (add-text-properties
8791 (match-beginning 2) (match-end 2)
8792 (list 'face (delq nil (let ((prop (get-text-property
8793 (match-beginning 2) 'face)))
8794 (or (listp prop) (setq prop (list prop)))
8795 (if (memq 'org-tag prop)
8796 prop
8797 (cons 'org-tag prop))))))
8798 (setq l (- (match-end 2) (match-beginning 2))
8799 c (if (< org-agenda-tags-column 0)
8800 (- (abs org-agenda-tags-column) l)
8801 org-agenda-tags-column))
8802 (delete-region (match-beginning 1) (match-end 1))
8803 (goto-char (match-beginning 1))
8804 (insert (org-add-props
8805 (make-string (max 1 (- c (current-column))) ?\ )
8806 (plist-put (copy-sequence (text-properties-at (point)))
8807 'face nil))))
8808 (goto-char (point-min))
8809 (org-font-lock-add-tag-faces (point-max)))))
8811 (defun org-agenda-priority-up ()
8812 "Increase the priority of line at point, also in Org-mode file."
8813 (interactive)
8814 (org-agenda-priority 'up))
8816 (defun org-agenda-priority-down ()
8817 "Decrease the priority of line at point, also in Org-mode file."
8818 (interactive)
8819 (org-agenda-priority 'down))
8821 (defun org-agenda-priority (&optional force-direction)
8822 "Set the priority of line at point, also in Org-mode file.
8823 This changes the line at point, all other lines in the agenda referring to
8824 the same tree node, and the headline of the tree node in the Org-mode file.
8825 Called with a universal prefix arg, show the priority instead of setting it."
8826 (interactive "P")
8827 (if (equal force-direction '(4))
8828 (org-show-priority)
8829 (unless org-enable-priority-commands
8830 (error "Priority commands are disabled"))
8831 (org-agenda-check-no-diary)
8832 (let* ((marker (or (org-get-at-bol 'org-marker)
8833 (org-agenda-error)))
8834 (hdmarker (org-get-at-bol 'org-hd-marker))
8835 (buffer (marker-buffer hdmarker))
8836 (pos (marker-position hdmarker))
8837 (inhibit-read-only t)
8838 newhead)
8839 (org-with-remote-undo buffer
8840 (with-current-buffer buffer
8841 (widen)
8842 (goto-char pos)
8843 (org-show-context 'agenda)
8844 (save-excursion
8845 (and (outline-next-heading)
8846 (org-flag-heading nil))) ; show the next heading
8847 (funcall 'org-priority force-direction)
8848 (end-of-line 1)
8849 (setq newhead (org-get-heading)))
8850 (org-agenda-change-all-lines newhead hdmarker)
8851 (beginning-of-line 1)))))
8853 ;; FIXME: should fix the tags property of the agenda line.
8854 (defun org-agenda-set-tags (&optional tag onoff)
8855 "Set tags for the current headline."
8856 (interactive)
8857 (org-agenda-check-no-diary)
8858 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8859 (call-interactively 'org-change-tag-in-region)
8860 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8861 (org-agenda-error)))
8862 (buffer (marker-buffer hdmarker))
8863 (pos (marker-position hdmarker))
8864 (inhibit-read-only t)
8865 newhead)
8866 (org-with-remote-undo buffer
8867 (with-current-buffer buffer
8868 (widen)
8869 (goto-char pos)
8870 (save-excursion
8871 (org-show-context 'agenda))
8872 (save-excursion
8873 (and (outline-next-heading)
8874 (org-flag-heading nil))) ; show the next heading
8875 (goto-char pos)
8876 (if tag
8877 (org-toggle-tag tag onoff)
8878 (call-interactively 'org-set-tags))
8879 (end-of-line 1)
8880 (setq newhead (org-get-heading)))
8881 (org-agenda-change-all-lines newhead hdmarker)
8882 (beginning-of-line 1)))))
8884 (defun org-agenda-set-property ()
8885 "Set a property for the current headline."
8886 (interactive)
8887 (org-agenda-check-no-diary)
8888 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8889 (org-agenda-error)))
8890 (buffer (marker-buffer hdmarker))
8891 (pos (marker-position hdmarker))
8892 (inhibit-read-only t)
8893 newhead)
8894 (org-with-remote-undo buffer
8895 (with-current-buffer buffer
8896 (widen)
8897 (goto-char pos)
8898 (save-excursion
8899 (org-show-context 'agenda))
8900 (save-excursion
8901 (and (outline-next-heading)
8902 (org-flag-heading nil))) ; show the next heading
8903 (goto-char pos)
8904 (call-interactively 'org-set-property)))))
8906 (defun org-agenda-set-effort ()
8907 "Set the effort property for the current headline."
8908 (interactive)
8909 (org-agenda-check-no-diary)
8910 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8911 (org-agenda-error)))
8912 (buffer (marker-buffer hdmarker))
8913 (pos (marker-position hdmarker))
8914 (inhibit-read-only t)
8915 newhead)
8916 (org-with-remote-undo buffer
8917 (with-current-buffer buffer
8918 (widen)
8919 (goto-char pos)
8920 (save-excursion
8921 (org-show-context 'agenda))
8922 (save-excursion
8923 (and (outline-next-heading)
8924 (org-flag-heading nil))) ; show the next heading
8925 (goto-char pos)
8926 (call-interactively 'org-set-effort)
8927 (end-of-line 1)
8928 (setq newhead (org-get-heading)))
8929 (org-agenda-change-all-lines newhead hdmarker))))
8931 (defun org-agenda-toggle-archive-tag ()
8932 "Toggle the archive tag for the current entry."
8933 (interactive)
8934 (org-agenda-check-no-diary)
8935 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8936 (org-agenda-error)))
8937 (buffer (marker-buffer hdmarker))
8938 (pos (marker-position hdmarker))
8939 (inhibit-read-only t)
8940 newhead)
8941 (org-with-remote-undo buffer
8942 (with-current-buffer buffer
8943 (widen)
8944 (goto-char pos)
8945 (org-show-context 'agenda)
8946 (save-excursion
8947 (and (outline-next-heading)
8948 (org-flag-heading nil))) ; show the next heading
8949 (call-interactively 'org-toggle-archive-tag)
8950 (end-of-line 1)
8951 (setq newhead (org-get-heading)))
8952 (org-agenda-change-all-lines newhead hdmarker)
8953 (beginning-of-line 1))))
8955 (defun org-agenda-do-date-later (arg)
8956 (interactive "P")
8957 (cond
8958 ((or (equal arg '(16))
8959 (memq last-command
8960 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8961 (setq this-command 'org-agenda-date-later-minutes)
8962 (org-agenda-date-later-minutes 1))
8963 ((or (equal arg '(4))
8964 (memq last-command
8965 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8966 (setq this-command 'org-agenda-date-later-hours)
8967 (org-agenda-date-later-hours 1))
8969 (org-agenda-date-later (prefix-numeric-value arg)))))
8971 (defun org-agenda-do-date-earlier (arg)
8972 (interactive "P")
8973 (cond
8974 ((or (equal arg '(16))
8975 (memq last-command
8976 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8977 (setq this-command 'org-agenda-date-earlier-minutes)
8978 (org-agenda-date-earlier-minutes 1))
8979 ((or (equal arg '(4))
8980 (memq last-command
8981 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8982 (setq this-command 'org-agenda-date-earlier-hours)
8983 (org-agenda-date-earlier-hours 1))
8985 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8987 (defun org-agenda-date-later (arg &optional what)
8988 "Change the date of this item to ARG day(s) later."
8989 (interactive "p")
8990 (org-agenda-check-type t 'agenda 'timeline)
8991 (org-agenda-check-no-diary)
8992 (let* ((marker (or (org-get-at-bol 'org-marker)
8993 (org-agenda-error)))
8994 (buffer (marker-buffer marker))
8995 (pos (marker-position marker))
8996 cdate today)
8997 (org-with-remote-undo buffer
8998 (with-current-buffer buffer
8999 (widen)
9000 (goto-char pos)
9001 (if (not (org-at-timestamp-p))
9002 (error "Cannot find time stamp"))
9003 (when (and org-agenda-move-date-from-past-immediately-to-today
9004 (equal arg 1)
9005 (or (not what) (eq what 'day))
9006 (not (save-match-data (org-at-date-range-p))))
9007 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
9008 cdate (calendar-absolute-from-gregorian
9009 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
9010 today (org-today))
9011 (if (> today cdate)
9012 ;; immediately shift to today
9013 (setq arg (- today cdate))))
9014 (org-timestamp-change arg (or what 'day))
9015 (when (and (org-at-date-range-p)
9016 (re-search-backward org-tr-regexp-both (point-at-bol)))
9017 (let ((end org-last-changed-timestamp))
9018 (org-timestamp-change arg (or what 'day))
9019 (setq org-last-changed-timestamp
9020 (concat org-last-changed-timestamp "--" end)))))
9021 (org-agenda-show-new-time marker org-last-changed-timestamp))
9022 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9024 (defun org-agenda-date-earlier (arg &optional what)
9025 "Change the date of this item to ARG day(s) earlier."
9026 (interactive "p")
9027 (org-agenda-date-later (- arg) what))
9029 (defun org-agenda-date-later-minutes (arg)
9030 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9031 (interactive "p")
9032 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9033 (org-agenda-date-later arg 'minute))
9035 (defun org-agenda-date-earlier-minutes (arg)
9036 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
9037 (interactive "p")
9038 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
9039 (org-agenda-date-earlier arg 'minute))
9041 (defun org-agenda-date-later-hours (arg)
9042 "Change the time of this item, in hour steps."
9043 (interactive "p")
9044 (org-agenda-date-later arg 'hour))
9046 (defun org-agenda-date-earlier-hours (arg)
9047 "Change the time of this item, in hour steps."
9048 (interactive "p")
9049 (org-agenda-date-earlier arg 'hour))
9051 (defun org-agenda-show-new-time (marker stamp &optional prefix)
9052 "Show new date stamp via text properties."
9053 ;; We use text properties to make this undoable
9054 (let ((inhibit-read-only t))
9055 (setq stamp (concat prefix " => " stamp " "))
9056 (save-excursion
9057 (goto-char (point-max))
9058 (while (not (bobp))
9059 (when (equal marker (org-get-at-bol 'org-marker))
9060 (org-move-to-column (- (window-width) (length stamp)) t)
9061 (org-agenda-fix-tags-filter-overlays-at (point))
9062 (if (featurep 'xemacs)
9063 ;; Use `duplicable' property to trigger undo recording
9064 (let ((ex (make-extent nil nil))
9065 (gl (make-glyph stamp)))
9066 (set-glyph-face gl 'secondary-selection)
9067 (set-extent-properties
9068 ex (list 'invisible t 'end-glyph gl 'duplicable t))
9069 (insert-extent ex (1- (point)) (point-at-eol)))
9070 (add-text-properties
9071 (1- (point)) (point-at-eol)
9072 (list 'display (org-add-props stamp nil
9073 'face 'secondary-selection))))
9074 (beginning-of-line 1))
9075 (beginning-of-line 0)))))
9077 (defun org-agenda-date-prompt (arg)
9078 "Change the date of this item. Date is prompted for, with default today.
9079 The prefix ARG is passed to the `org-time-stamp' command and can therefore
9080 be used to request time specification in the time stamp."
9081 (interactive "P")
9082 (org-agenda-check-type t 'agenda 'timeline)
9083 (org-agenda-check-no-diary)
9084 (let* ((marker (or (org-get-at-bol 'org-marker)
9085 (org-agenda-error)))
9086 (buffer (marker-buffer marker))
9087 (pos (marker-position marker)))
9088 (org-with-remote-undo buffer
9089 (with-current-buffer buffer
9090 (widen)
9091 (goto-char pos)
9092 (if (not (org-at-timestamp-p t))
9093 (error "Cannot find time stamp"))
9094 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
9095 (org-agenda-show-new-time marker org-last-changed-timestamp))
9096 (message "Time stamp changed to %s" org-last-changed-timestamp)))
9098 (defun org-agenda-schedule (arg &optional time)
9099 "Schedule the item at point.
9100 ARG is passed through to `org-schedule'."
9101 (interactive "P")
9102 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9103 (org-agenda-check-no-diary)
9104 (let* ((marker (or (org-get-at-bol 'org-marker)
9105 (org-agenda-error)))
9106 (type (marker-insertion-type marker))
9107 (buffer (marker-buffer marker))
9108 (pos (marker-position marker))
9109 (org-insert-labeled-timestamps-at-point nil)
9111 (set-marker-insertion-type marker t)
9112 (org-with-remote-undo buffer
9113 (with-current-buffer buffer
9114 (widen)
9115 (goto-char pos)
9116 (setq ts (org-schedule arg time)))
9117 (org-agenda-show-new-time marker ts " S"))
9118 (message "%s" ts)))
9120 (defun org-agenda-deadline (arg &optional time)
9121 "Schedule the item at point.
9122 ARG is passed through to `org-deadline'."
9123 (interactive "P")
9124 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
9125 (org-agenda-check-no-diary)
9126 (let* ((marker (or (org-get-at-bol 'org-marker)
9127 (org-agenda-error)))
9128 (buffer (marker-buffer marker))
9129 (pos (marker-position marker))
9130 (org-insert-labeled-timestamps-at-point nil)
9132 (org-with-remote-undo buffer
9133 (with-current-buffer buffer
9134 (widen)
9135 (goto-char pos)
9136 (setq ts (org-deadline arg time)))
9137 (org-agenda-show-new-time marker ts " D"))
9138 (message "%s" ts)))
9140 (defun org-agenda-clock-in (&optional arg)
9141 "Start the clock on the currently selected item."
9142 (interactive "P")
9143 (org-agenda-check-no-diary)
9144 (if (equal arg '(4))
9145 (org-clock-in arg)
9146 (let* ((marker (or (org-get-at-bol 'org-marker)
9147 (org-agenda-error)))
9148 (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
9149 (pos (marker-position marker))
9150 (col (current-column))
9151 newhead)
9152 (org-with-remote-undo (marker-buffer marker)
9153 (with-current-buffer (marker-buffer marker)
9154 (widen)
9155 (goto-char pos)
9156 (org-show-context 'agenda)
9157 (org-show-entry)
9158 (org-cycle-hide-drawers 'children)
9159 (org-clock-in arg)
9160 (setq newhead (org-get-heading)))
9161 (org-agenda-change-all-lines newhead hdmarker))
9162 (org-move-to-column col))))
9164 (defun org-agenda-clock-out ()
9165 "Stop the currently running clock."
9166 (interactive)
9167 (unless (marker-buffer org-clock-marker)
9168 (error "No running clock"))
9169 (let ((marker (make-marker)) (col (current-column)) newhead)
9170 (org-with-remote-undo (marker-buffer org-clock-marker)
9171 (with-current-buffer (marker-buffer org-clock-marker)
9172 (save-excursion
9173 (save-restriction
9174 (widen)
9175 (goto-char org-clock-marker)
9176 (org-back-to-heading t)
9177 (move-marker marker (point))
9178 (org-clock-out)
9179 (setq newhead (org-get-heading))))))
9180 (org-agenda-change-all-lines newhead marker)
9181 (move-marker marker nil)
9182 (org-move-to-column col)
9183 (org-agenda-unmark-clocking-task)))
9185 (defun org-agenda-clock-cancel (&optional arg)
9186 "Cancel the currently running clock."
9187 (interactive "P")
9188 (unless (marker-buffer org-clock-marker)
9189 (error "No running clock"))
9190 (org-with-remote-undo (marker-buffer org-clock-marker)
9191 (org-clock-cancel)))
9193 (defun org-agenda-clock-goto ()
9194 "Jump to the currently clocked in task within the agenda.
9195 If the currently clocked in task is not listed in the agenda
9196 buffer, display it in another window."
9197 (interactive)
9198 (let (pos)
9199 (mapc (lambda (o)
9200 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
9201 (setq pos (overlay-start o))))
9202 (overlays-in (point-min) (point-max)))
9203 (cond (pos (goto-char pos))
9204 ;; If the currently clocked entry is not in the agenda
9205 ;; buffer, we visit it in another window:
9206 (org-clock-current-task
9207 (org-switch-to-buffer-other-window (org-clock-goto)))
9208 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
9210 (defun org-agenda-diary-entry-in-org-file ()
9211 "Make a diary entry in the file `org-agenda-diary-file'."
9212 (let (d1 d2 char (text "") dp1 dp2)
9213 (if (equal (buffer-name) "*Calendar*")
9214 (setq d1 (calendar-cursor-to-date t)
9215 d2 (car calendar-mark-ring))
9216 (setq dp1 (get-text-property (point-at-bol) 'day))
9217 (unless dp1 (error "No date defined in current line"))
9218 (setq d1 (calendar-gregorian-from-absolute dp1)
9219 d2 (and (ignore-errors (mark))
9220 (save-excursion
9221 (goto-char (mark))
9222 (setq dp2 (get-text-property (point-at-bol) 'day)))
9223 (calendar-gregorian-from-absolute dp2))))
9224 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
9225 (setq char (read-char-exclusive))
9226 (cond
9227 ((equal char ?d)
9228 (setq text (read-string "Day entry: "))
9229 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
9230 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9231 ((equal char ?a)
9232 (setq d1 (list (car d1) (nth 1 d1)
9233 (read-number (format "Reference year [%d]: " (nth 2 d1))
9234 (nth 2 d1))))
9235 (setq text (read-string "Anniversary (use %d to show years): "))
9236 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
9237 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9238 ((equal char ?b)
9239 (setq text (read-string "Block entry: "))
9240 (unless (and d1 d2 (not (equal d1 d2)))
9241 (error "No block of days selected"))
9242 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
9243 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
9244 ((equal char ?j)
9245 (org-switch-to-buffer-other-window
9246 (find-file-noselect org-agenda-diary-file))
9247 (require 'org-datetree)
9248 (org-datetree-find-date-create d1)
9249 (org-reveal t))
9250 (t (error "Invalid selection character `%c'" char)))))
9252 (defcustom org-agenda-insert-diary-strategy 'date-tree
9253 "Where in `org-agenda-diary-file' should new entries be added?
9254 Valid values:
9256 date-tree in the date tree, as child of the date
9257 top-level as top-level entries at the end of the file."
9258 :group 'org-agenda
9259 :type '(choice
9260 (const :tag "in a date tree" date-tree)
9261 (const :tag "as top level at end of file" top-level)))
9263 (defcustom org-agenda-insert-diary-extract-time nil
9264 "Non-nil means extract any time specification from the diary entry."
9265 :group 'org-agenda
9266 :version "24.1"
9267 :type 'boolean)
9269 (defcustom org-agenda-bulk-mark-char ">"
9270 "A single-character string to be used as the bulk mark."
9271 :group 'org-agenda
9272 :version "24.1"
9273 :type 'string)
9275 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9276 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9277 If TEXT is not empty, it will become the headline of the new entry, and
9278 the resulting entry will not be shown. When TEXT is empty, switch to
9279 `org-agenda-diary-file' and let the user finish the entry there."
9280 (let ((cw (current-window-configuration)))
9281 (org-switch-to-buffer-other-window
9282 (find-file-noselect org-agenda-diary-file))
9283 (widen)
9284 (goto-char (point-min))
9285 (cond
9286 ((eq type 'anniversary)
9287 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9288 (progn
9289 (or (org-at-heading-p t)
9290 (progn
9291 (outline-next-heading)
9292 (insert "* Anniversaries\n\n")
9293 (beginning-of-line -1)))))
9294 (outline-next-heading)
9295 (org-back-over-empty-lines)
9296 (backward-char 1)
9297 (insert "\n")
9298 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9299 (nth 2 d1) (car d1) (nth 1 d1) text)))
9300 ((eq type 'day)
9301 (let ((org-prefix-has-time t)
9302 (org-agenda-time-leading-zero t)
9303 fmt time time2)
9304 (if org-agenda-insert-diary-extract-time
9305 ;; Use org-agenda-format-item to parse text for a time-range and
9306 ;; remove it. FIXME: This is a hack, we should refactor
9307 ;; that function to make time extraction available separately
9308 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9309 time (get-text-property 0 'time fmt)
9310 time2 (if (> (length time) 0)
9311 ;; split-string removes trailing ...... if
9312 ;; no end time given. First space
9313 ;; separates time from date.
9314 (concat " " (car (split-string time "\\.")))
9315 nil)
9316 text (get-text-property 0 'txt fmt)))
9317 (if (eq org-agenda-insert-diary-strategy 'top-level)
9318 (org-agenda-insert-diary-as-top-level text)
9319 (require 'org-datetree)
9320 (org-datetree-find-date-create d1)
9321 (org-agenda-insert-diary-make-new-entry text))
9322 (org-insert-time-stamp (org-time-from-absolute
9323 (calendar-absolute-from-gregorian d1))
9324 nil nil nil nil time2))
9325 (end-of-line 0))
9326 ((eq type 'block)
9327 (if (> (calendar-absolute-from-gregorian d1)
9328 (calendar-absolute-from-gregorian d2))
9329 (setq d1 (prog1 d2 (setq d2 d1))))
9330 (if (eq org-agenda-insert-diary-strategy 'top-level)
9331 (org-agenda-insert-diary-as-top-level text)
9332 (require 'org-datetree)
9333 (org-datetree-find-date-create d1)
9334 (org-agenda-insert-diary-make-new-entry text))
9335 (org-insert-time-stamp (org-time-from-absolute
9336 (calendar-absolute-from-gregorian d1)))
9337 (insert "--")
9338 (org-insert-time-stamp (org-time-from-absolute
9339 (calendar-absolute-from-gregorian d2)))
9340 (end-of-line 0)))
9341 (if (string-match "\\S-" text)
9342 (progn
9343 (set-window-configuration cw)
9344 (message "%s entry added to %s"
9345 (capitalize (symbol-name type))
9346 (abbreviate-file-name org-agenda-diary-file)))
9347 (org-reveal t)
9348 (message "Please finish entry here"))))
9350 (defun org-agenda-insert-diary-as-top-level (text)
9351 "Make new entry as a top-level entry at the end of the file.
9352 Add TEXT as headline, and position the cursor in the second line so that
9353 a timestamp can be added there."
9354 (widen)
9355 (goto-char (point-max))
9356 (or (bolp) (insert "\n"))
9357 (insert "* " text "\n")
9358 (if org-adapt-indentation (org-indent-to-column 2)))
9360 (defun org-agenda-insert-diary-make-new-entry (text)
9361 "Make new entry as last child of current entry.
9362 Add TEXT as headline, and position the cursor in the second line so that
9363 a timestamp can be added there."
9364 (let ((org-show-following-heading t)
9365 (org-show-siblings t)
9366 (org-show-hierarchy-above t)
9367 (org-show-entry-below t)
9368 col)
9369 (outline-next-heading)
9370 (org-back-over-empty-lines)
9371 (or (looking-at "[ \t]*$")
9372 (progn (insert "\n") (backward-char 1)))
9373 (org-insert-heading nil t)
9374 (org-do-demote)
9375 (setq col (current-column))
9376 (insert text "\n")
9377 (if org-adapt-indentation (org-indent-to-column col))
9378 (let ((org-show-following-heading t)
9379 (org-show-siblings t)
9380 (org-show-hierarchy-above t)
9381 (org-show-entry-below t))
9382 (org-show-context))))
9384 (defun org-agenda-diary-entry ()
9385 "Make a diary entry, like the `i' command from the calendar.
9386 All the standard commands work: block, weekly etc.
9387 When `org-agenda-diary-file' points to a file,
9388 `org-agenda-diary-entry-in-org-file' is called instead to create
9389 entries in that Org-mode file."
9390 (interactive)
9391 (if (not (eq org-agenda-diary-file 'diary-file))
9392 (org-agenda-diary-entry-in-org-file)
9393 (require 'diary-lib)
9394 (let* ((char (progn
9395 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9396 (read-char-exclusive)))
9397 (cmd (cdr (assoc char
9398 '((?d . insert-diary-entry)
9399 (?w . insert-weekly-diary-entry)
9400 (?m . insert-monthly-diary-entry)
9401 (?y . insert-yearly-diary-entry)
9402 (?a . insert-anniversary-diary-entry)
9403 (?b . insert-block-diary-entry)
9404 (?c . insert-cyclic-diary-entry)))))
9405 (oldf (symbol-function 'calendar-cursor-to-date))
9406 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9407 (point (point))
9408 (mark (or (mark t) (point))))
9409 (unless cmd
9410 (error "No command associated with <%c>" char))
9411 (unless (and (get-text-property point 'day)
9412 (or (not (equal ?b char))
9413 (get-text-property mark 'day)))
9414 (error "Don't know which date to use for diary entry"))
9415 ;; We implement this by hacking the `calendar-cursor-to-date' function
9416 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9417 (let ((calendar-mark-ring
9418 (list (calendar-gregorian-from-absolute
9419 (or (get-text-property mark 'day)
9420 (get-text-property point 'day))))))
9421 (unwind-protect
9422 (progn
9423 (fset 'calendar-cursor-to-date
9424 (lambda (&optional error dummy)
9425 (calendar-gregorian-from-absolute
9426 (get-text-property point 'day))))
9427 (call-interactively cmd))
9428 (fset 'calendar-cursor-to-date oldf))))))
9430 (defun org-agenda-execute-calendar-command (cmd)
9431 "Execute a calendar command from the agenda with date from cursor."
9432 (org-agenda-check-type t 'agenda 'timeline)
9433 (require 'diary-lib)
9434 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9435 (error "Don't know which date to use for the calendar command"))
9436 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9437 (point (point))
9438 (date (calendar-gregorian-from-absolute
9439 (get-text-property point 'day)))
9440 ;; the following 2 vars are needed in the calendar
9441 (displayed-month (car date))
9442 (displayed-year (nth 2 date)))
9443 (unwind-protect
9444 (progn
9445 (fset 'calendar-cursor-to-date
9446 (lambda (&optional error dummy)
9447 (calendar-gregorian-from-absolute
9448 (get-text-property point 'day))))
9449 (call-interactively cmd))
9450 (fset 'calendar-cursor-to-date oldf))))
9452 (defun org-agenda-phases-of-moon ()
9453 "Display the phases of the moon for the 3 months around the cursor date."
9454 (interactive)
9455 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9457 (defun org-agenda-holidays ()
9458 "Display the holidays for the 3 months around the cursor date."
9459 (interactive)
9460 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9462 (defvar calendar-longitude) ; defined in calendar.el
9463 (defvar calendar-latitude) ; defined in calendar.el
9464 (defvar calendar-location-name) ; defined in calendar.el
9466 (defun org-agenda-sunrise-sunset (arg)
9467 "Display sunrise and sunset for the cursor date.
9468 Latitude and longitude can be specified with the variables
9469 `calendar-latitude' and `calendar-longitude'. When called with prefix
9470 argument, latitude and longitude will be prompted for."
9471 (interactive "P")
9472 (require 'solar)
9473 (let ((calendar-longitude (if arg nil calendar-longitude))
9474 (calendar-latitude (if arg nil calendar-latitude))
9475 (calendar-location-name
9476 (if arg "the given coordinates" calendar-location-name)))
9477 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9479 (defun org-agenda-goto-calendar ()
9480 "Open the Emacs calendar with the date at the cursor."
9481 (interactive)
9482 (org-agenda-check-type t 'agenda 'timeline)
9483 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9484 (error "Don't know which date to open in calendar")))
9485 (date (calendar-gregorian-from-absolute day))
9486 (calendar-move-hook nil)
9487 (calendar-view-holidays-initially-flag nil)
9488 (calendar-view-diary-initially-flag nil))
9489 (calendar)
9490 (calendar-goto-date date)))
9492 ;;;###autoload
9493 (defun org-calendar-goto-agenda ()
9494 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9495 This is a command that has to be installed in `calendar-mode-map'."
9496 (interactive)
9497 (org-agenda-list nil (calendar-absolute-from-gregorian
9498 (calendar-cursor-to-date))
9499 nil))
9501 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9502 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9503 This is a command that has to be installed in `calendar-mode-map'.
9505 \(fn)" t nil)
9507 (defun org-agenda-convert-date ()
9508 (interactive)
9509 (org-agenda-check-type t 'agenda 'timeline)
9510 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9511 date s)
9512 (unless day
9513 (error "Don't know which date to convert"))
9514 (setq date (calendar-gregorian-from-absolute day))
9515 (setq s (concat
9516 "Gregorian: " (calendar-date-string date) "\n"
9517 "ISO: " (calendar-iso-date-string date) "\n"
9518 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9519 "Julian: " (calendar-julian-date-string date) "\n"
9520 "Astron. JD: " (calendar-astro-date-string date)
9521 " (Julian date number at noon UTC)\n"
9522 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9523 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9524 "French: " (calendar-french-date-string date) "\n"
9525 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9526 "Mayan: " (calendar-mayan-date-string date) "\n"
9527 "Coptic: " (calendar-coptic-date-string date) "\n"
9528 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9529 "Persian: " (calendar-persian-date-string date) "\n"
9530 "Chinese: " (calendar-chinese-date-string date) "\n"))
9531 (with-output-to-temp-buffer "*Dates*"
9532 (princ s))
9533 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9535 ;;; Bulk commands
9537 (defun org-agenda-bulk-marked-p ()
9538 (eq (get-char-property (point-at-bol) 'type)
9539 'org-marked-entry-overlay))
9541 (defun org-agenda-bulk-mark (&optional arg)
9542 "Mark the entry at point for future bulk action."
9543 (interactive "p")
9544 (dotimes (i (or arg 1))
9545 (unless (org-get-at-bol 'org-agenda-diary-link)
9546 (let* ((m (org-get-at-bol 'org-hd-marker))
9548 (unless (org-agenda-bulk-marked-p)
9549 (unless m (error "Nothing to mark at point"))
9550 (push m org-agenda-bulk-marked-entries)
9551 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9552 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9553 (org-get-todo-face "TODO")
9554 'evaporate)
9555 (overlay-put ov 'type 'org-marked-entry-overlay))
9556 (beginning-of-line 2)
9557 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9558 (beginning-of-line 2))
9559 (message "%d entries marked for bulk action"
9560 (length org-agenda-bulk-marked-entries))))))
9562 (defun org-agenda-bulk-mark-all ()
9563 "Mark all entries for future agenda bulk action."
9564 (interactive)
9565 (org-agenda-bulk-mark-regexp "."))
9567 (defun org-agenda-bulk-mark-regexp (regexp)
9568 "Mark entries matching REGEXP for future agenda bulk action."
9569 (interactive "sMark entries matching regexp: ")
9570 (let ((entries-marked 0))
9571 (save-excursion
9572 (goto-char (point-min))
9573 (goto-char (next-single-property-change (point) 'txt))
9574 (while (re-search-forward regexp nil t)
9575 (when (string-match regexp (get-text-property (point) 'txt))
9576 (setq entries-marked (1+ entries-marked))
9577 (call-interactively 'org-agenda-bulk-mark))))
9578 (if (not entries-marked)
9579 (message "No entry matching this regexp."))))
9581 (defun org-agenda-bulk-unmark (&optional arg)
9582 "Unmark the entry at point for future bulk action."
9583 (interactive "P")
9584 (if arg
9585 (org-agenda-bulk-unmark-all)
9586 (cond ((org-agenda-bulk-marked-p)
9587 (org-agenda-bulk-remove-overlays
9588 (point-at-bol) (+ 2 (point-at-bol)))
9589 (setq org-agenda-bulk-marked-entries
9590 (delete (org-get-at-bol 'org-hd-marker)
9591 org-agenda-bulk-marked-entries))
9592 (beginning-of-line 2)
9593 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9594 (beginning-of-line 2))
9595 (message "%d entries left marked for bulk action"
9596 (length org-agenda-bulk-marked-entries)))
9597 (t (message "No entry to unmark here")))))
9599 (defun org-agenda-bulk-toggle ()
9600 "Toggle marking the entry at point for bulk action."
9601 (interactive)
9602 (if (org-agenda-bulk-marked-p)
9603 (org-agenda-bulk-unmark)
9604 (org-agenda-bulk-mark)))
9606 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9607 "Remove the mark overlays between BEG and END in the agenda buffer.
9608 BEG and END default to the buffer limits.
9610 This only removes the overlays, it does not remove the markers
9611 from the list in `org-agenda-bulk-marked-entries'."
9612 (interactive)
9613 (mapc (lambda (ov)
9614 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9615 (delete-overlay ov)))
9616 (overlays-in (or beg (point-min)) (or end (point-max)))))
9618 (defun org-agenda-bulk-unmark-all ()
9619 "Remove all marks in the agenda buffer.
9620 This will remove the markers and the overlays."
9621 (interactive)
9622 (if (null org-agenda-bulk-marked-entries)
9623 (message "No entry to unmark")
9624 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9625 (setq org-agenda-bulk-marked-entries nil)
9626 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9628 (defcustom org-agenda-persistent-marks nil
9629 "Non-nil means marked items will stay marked after a bulk action.
9630 You can toggle this interactively by typing `p' when prompted for a
9631 bulk action."
9632 :group 'org-agenda
9633 :version "24.1"
9634 :type 'boolean)
9636 (defun org-agenda-bulk-action (&optional arg)
9637 "Execute an remote-editing action on all marked entries.
9638 The prefix arg is passed through to the command if possible."
9639 (interactive "P")
9640 ;; Make sure we have markers, and only valid ones
9641 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9642 (mapc
9643 (lambda (m)
9644 (unless (and (markerp m)
9645 (marker-buffer m)
9646 (buffer-live-p (marker-buffer m))
9647 (marker-position m))
9648 (error "Marker %s for bulk command is invalid" m)))
9649 org-agenda-bulk-marked-entries)
9651 ;; Prompt for the bulk command
9652 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9653 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9654 "[S]catter [f]unction "
9655 (when org-agenda-bulk-custom-functions
9656 (concat " Custom: ["
9657 (mapconcat (lambda(f) (char-to-string (car f)))
9658 org-agenda-bulk-custom-functions "")
9659 "]"))))
9660 (catch 'exit
9661 (let* ((action (read-char-exclusive))
9662 (org-log-refile (if org-log-refile 'time nil))
9663 (entries (reverse org-agenda-bulk-marked-entries))
9664 (org-overriding-default-time
9665 (if (get-text-property (point) 'org-agenda-date-header)
9666 (org-get-cursor-date)))
9667 redo-at-end
9668 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9669 (cond
9670 ((equal action ?p)
9671 (let ((org-agenda-persistent-marks
9672 (not org-agenda-persistent-marks)))
9673 (org-agenda-bulk-action)
9674 (throw 'exit nil)))
9676 ((equal action ?$)
9677 (setq cmd '(org-agenda-archive)))
9679 ((equal action ?A)
9680 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9682 ((member action '(?r ?w))
9683 (setq rfloc (org-refile-get-location
9684 "Refile to"
9685 (marker-buffer (car entries))
9686 org-refile-allow-creating-parent-nodes))
9687 (if (nth 3 rfloc)
9688 (setcar (nthcdr 3 rfloc)
9689 (move-marker (make-marker) (nth 3 rfloc)
9690 (or (get-file-buffer (nth 1 rfloc))
9691 (find-buffer-visiting (nth 1 rfloc))
9692 (error "This should not happen")))))
9694 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9695 redo-at-end t))
9697 ((equal action ?t)
9698 (setq state (org-icompleting-read
9699 "Todo state: "
9700 (with-current-buffer (marker-buffer (car entries))
9701 (mapcar 'list org-todo-keywords-1))))
9702 (setq cmd `(let ((org-inhibit-blocking t)
9703 (org-inhibit-logging 'note))
9704 (org-agenda-todo ,state))))
9706 ((memq action '(?- ?+))
9707 (setq tag (org-icompleting-read
9708 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9709 (with-current-buffer (marker-buffer (car entries))
9710 (delq nil
9711 (mapcar (lambda (x)
9712 (if (stringp (car x)) x)) org-tag-alist)))))
9713 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9715 ((memq action '(?s ?d))
9716 (let* ((time
9717 (unless arg
9718 (org-read-date
9719 nil nil nil
9720 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9721 org-overriding-default-time)))
9722 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9723 (setq cmd `(eval '(,c1 arg ,time)))))
9725 ((equal action ?S)
9726 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9727 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9728 (let ((days (read-number
9729 (format "Scatter tasks across how many %sdays: "
9730 (if arg "week" "")) 7)))
9731 (setq cmd
9732 `(let ((distance (1+ (random ,days))))
9733 (if arg
9734 (let ((dist distance)
9735 (day-of-week
9736 (calendar-day-of-week
9737 (calendar-gregorian-from-absolute (org-today)))))
9738 (dotimes (i (1+ dist))
9739 (while (member day-of-week org-agenda-weekend-days)
9740 (incf distance)
9741 (incf day-of-week)
9742 (if (= day-of-week 7)
9743 (setq day-of-week 0)))
9744 (incf day-of-week)
9745 (if (= day-of-week 7)
9746 (setq day-of-week 0)))))
9747 ;; silently fail when try to replan a sexp entry
9748 (condition-case nil
9749 (let* ((date (calendar-gregorian-from-absolute
9750 (+ (org-today) distance)))
9751 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9752 (nth 2 date))))
9753 (org-agenda-schedule nil time))
9754 (error nil)))))))
9756 ((assoc action org-agenda-bulk-custom-functions)
9757 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9758 redo-at-end t))
9760 ((equal action ?f)
9761 (setq cmd (list (intern
9762 (org-icompleting-read "Function: "
9763 obarray 'fboundp t nil nil)))))
9765 (t (error "Invalid bulk action")))
9767 ;; Sort the markers, to make sure that parents are handled before children
9768 (setq entries (sort entries
9769 (lambda (a b)
9770 (cond
9771 ((equal (marker-buffer a) (marker-buffer b))
9772 (< (marker-position a) (marker-position b)))
9774 (string< (buffer-name (marker-buffer a))
9775 (buffer-name (marker-buffer b))))))))
9777 ;; Now loop over all markers and apply cmd
9778 (while (setq e (pop entries))
9779 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9780 (if (not pos)
9781 (progn (message "Skipping removed entry at %s" e)
9782 (setq cntskip (1+ cntskip)))
9783 (goto-char pos)
9784 (let (org-loop-over-headlines-in-active-region)
9785 (eval cmd))
9786 (setq cnt (1+ cnt))))
9787 (when redo-at-end (org-agenda-redo))
9788 (unless org-agenda-persistent-marks
9789 (org-agenda-bulk-unmark-all))
9790 (message "Acted on %d entries%s%s"
9792 (if (= cntskip 0)
9794 (format ", skipped %d (disappeared before their turn)"
9795 cntskip))
9796 (if (not org-agenda-persistent-marks)
9797 "" " (kept marked)"))))))
9799 (defun org-agenda-capture (&optional with-time)
9800 "Call `org-capture' with the date at point.
9801 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9802 current HH:MM time."
9803 (interactive "P")
9804 (if (not (eq major-mode 'org-agenda-mode))
9805 (user-error "You cannot do this outside of agenda buffers")
9806 (let ((org-overriding-default-time
9807 (org-get-cursor-date (equal with-time 1))))
9808 (call-interactively 'org-capture))))
9810 ;;; Flagging notes
9812 (defun org-agenda-show-the-flagging-note ()
9813 "Display the flagging note in the other window.
9814 When called a second time in direct sequence, offer to remove the FLAGGING
9815 tag and (if present) the flagging note."
9816 (interactive)
9817 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9818 (win (selected-window))
9819 note heading newhead)
9820 (unless hdmarker
9821 (error "No linked entry at point"))
9822 (if (and (eq this-command last-command)
9823 (y-or-n-p "Unflag and remove any flagging note? "))
9824 (progn
9825 (org-agenda-remove-flag hdmarker)
9826 (let ((win (get-buffer-window "*Flagging Note*")))
9827 (and win (delete-window win)))
9828 (message "Entry unflagged"))
9829 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9830 (unless note
9831 (error "No flagging note"))
9832 (org-kill-new note)
9833 (org-switch-to-buffer-other-window "*Flagging Note*")
9834 (erase-buffer)
9835 (insert note)
9836 (goto-char (point-min))
9837 (while (re-search-forward "\\\\n" nil t)
9838 (replace-match "\n" t t))
9839 (goto-char (point-min))
9840 (select-window win)
9841 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9843 (defun org-agenda-remove-flag (marker)
9844 "Remove the FLAGGED tag and any flagging note in the entry."
9845 (let (newhead)
9846 (org-with-point-at marker
9847 (org-toggle-tag "FLAGGED" 'off)
9848 (org-entry-delete nil "THEFLAGGINGNOTE")
9849 (setq newhead (org-get-heading)))
9850 (org-agenda-change-all-lines newhead marker)
9851 (message "Entry unflagged")))
9853 (defun org-agenda-get-any-marker (&optional pos)
9854 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9855 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9857 ;;; Appointment reminders
9859 (defvar appt-time-msg-list) ; defined in appt.el
9861 ;;;###autoload
9862 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9863 "Activate appointments found in `org-agenda-files'.
9864 With a \\[universal-argument] prefix, refresh the list of
9865 appointments.
9867 If FILTER is t, interactively prompt the user for a regular
9868 expression, and filter out entries that don't match it.
9870 If FILTER is a string, use this string as a regular expression
9871 for filtering entries out.
9873 If FILTER is a function, filter out entries against which
9874 calling the function returns nil. This function takes one
9875 argument: an entry from `org-agenda-get-day-entries'.
9877 FILTER can also be an alist with the car of each cell being
9878 either 'headline or 'category. For example:
9880 '((headline \"IMPORTANT\")
9881 (category \"Work\"))
9883 will only add headlines containing IMPORTANT or headlines
9884 belonging to the \"Work\" category.
9886 ARGS are symbols indicating what kind of entries to consider.
9887 By default `org-agenda-to-appt' will use :deadline, :scheduled
9888 and :timestamp entries. See the docstring of `org-diary' for
9889 details and examples.
9891 If an entry has a APPT_WARNTIME property, its value will be used
9892 to override `appt-message-warning-time'."
9893 (interactive "P")
9894 (if refresh (setq appt-time-msg-list nil))
9895 (if (eq filter t)
9896 (setq filter (read-from-minibuffer "Regexp filter: ")))
9897 (let* ((cnt 0) ; count added events
9898 (scope (or args '(:deadline :scheduled :timestamp)))
9899 (org-agenda-new-buffers nil)
9900 (org-deadline-warning-days 0)
9901 ;; Do not use `org-today' here because appt only takes
9902 ;; time and without date as argument, so it may pass wrong
9903 ;; information otherwise
9904 (today (org-date-to-gregorian
9905 (time-to-days (current-time))))
9906 (org-agenda-restrict nil)
9907 (files (org-agenda-files 'unrestricted)) entries file
9908 (org-agenda-buffer nil))
9909 ;; Get all entries which may contain an appt
9910 (org-agenda-prepare-buffers files)
9911 (while (setq file (pop files))
9912 (setq entries
9913 (delq nil
9914 (append entries
9915 (apply 'org-agenda-get-day-entries
9916 file today scope)))))
9917 ;; Map thru entries and find if we should filter them out
9918 (mapc
9919 (lambda(x)
9920 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9921 (cat (get-text-property 1 'org-category x))
9922 (tod (get-text-property 1 'time-of-day x))
9923 (ok (or (null filter)
9924 (and (stringp filter) (string-match filter evt))
9925 (and (functionp filter) (funcall filter x))
9926 (and (listp filter)
9927 (let ((cat-filter (cadr (assoc 'category filter)))
9928 (evt-filter (cadr (assoc 'headline filter))))
9929 (or (and (stringp cat-filter)
9930 (string-match cat-filter cat))
9931 (and (stringp evt-filter)
9932 (string-match evt-filter evt)))))))
9933 (wrn (get-text-property 1 'warntime x)))
9934 ;; FIXME: Shall we remove text-properties for the appt text?
9935 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9936 (when (and ok tod)
9937 (setq tod (concat "00" (number-to-string tod))
9938 tod (when (string-match
9939 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9940 (concat (match-string 1 tod) ":"
9941 (match-string 2 tod))))
9942 (if (version< emacs-version "23.3")
9943 (appt-add tod evt)
9944 (appt-add tod evt wrn))
9945 (setq cnt (1+ cnt))))) entries)
9946 (org-release-buffers org-agenda-new-buffers)
9947 (if (eq cnt 0)
9948 (message "No event to add")
9949 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9951 (autoload 'org-agenda-to-appt "org-agenda" "\
9952 Activate appointments found in `org-agenda-files'.
9953 With a \\[universal-argument] prefix, refresh the list of
9954 appointments.
9956 If FILTER is t, interactively prompt the user for a regular
9957 expression, and filter out entries that don't match it.
9959 If FILTER is a string, use this string as a regular expression
9960 for filtering entries out.
9962 If FILTER is a function, filter out entries against which
9963 calling the function returns nil. This function takes one
9964 argument: an entry from `org-agenda-get-day-entries'.
9966 FILTER can also be an alist with the car of each cell being
9967 either 'headline or 'category. For example:
9969 '((headline \"IMPORTANT\")
9970 (category \"Work\"))
9972 will only add headlines containing IMPORTANT or headlines
9973 belonging to the \"Work\" category.
9975 ARGS are symbols indicating what kind of entries to consider.
9976 By default `org-agenda-to-appt' will use :deadline, :scheduled
9977 and :timestamp entries. See the docstring of `org-diary' for
9978 details and examples.
9980 If an entry has a APPT_WARNTIME property, its value will be used
9981 to override `appt-message-warning-time'.
9983 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9985 (defun org-agenda-todayp (date)
9986 "Does DATE mean today, when considering `org-extend-today-until'?"
9987 (let ((today (org-today))
9988 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9989 date)))
9990 (eq date today)))
9992 (defun org-agenda-todo-yesterday (&optional arg)
9993 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9994 (interactive "P")
9995 (let* ((hour (third (decode-time
9996 (org-current-time))))
9997 (org-extend-today-until (1+ hour)))
9998 (org-agenda-todo arg)))
10000 (provide 'org-agenda)
10002 ;;; org-agenda.el ends here