Merge branch 'maint'
[org-mode.git] / lisp / org-agenda.el
blob48f1dda35d66e6e6fcd971a788b7dcdc3a8ddfa3
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-additional-timestamps-same-entry nil
847 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
848 When non-nil, after the search for timestamps has matched once in an
849 entry, the rest of the entry will not be searched."
850 :group 'org-agenda-skip
851 :type 'boolean)
853 (defcustom org-agenda-skip-timestamp-if-done nil
854 "Non-nil means don't select item by timestamp or -range if it is DONE."
855 :group 'org-agenda-skip
856 :group 'org-agenda-daily/weekly
857 :type 'boolean)
859 (defcustom org-agenda-dim-blocked-tasks nil
860 "Non-nil means dim blocked tasks in the agenda display.
861 This causes some overhead during agenda construction, but if you
862 have turned on `org-enforce-todo-dependencies',
863 `org-enforce-todo-checkbox-dependencies', or any other blocking
864 mechanism, this will create useful feedback in the agenda.
866 Instead of t, this variable can also have the value `invisible'.
867 Then blocked tasks will be invisible and only become visible when
868 they become unblocked. An exemption to this behavior is when a task is
869 blocked because of unchecked checkboxes below it. Since checkboxes do
870 not show up in the agenda views, making this task invisible you remove any
871 trace from agenda views that there is something to do. Therefore, a task
872 that is blocked because of checkboxes will never be made invisible, it
873 will only be dimmed."
874 :group 'org-agenda-daily/weekly
875 :group 'org-agenda-todo-list
876 :version "24.3"
877 :type '(choice
878 (const :tag "Do not dim" nil)
879 (const :tag "Dim to a gray face" t)
880 (const :tag "Make invisible" invisible)))
882 (defcustom org-timeline-show-empty-dates 3
883 "Non-nil means `org-timeline' also shows dates without an entry.
884 When nil, only the days which actually have entries are shown.
885 When t, all days between the first and the last date are shown.
886 When an integer, show also empty dates, but if there is a gap of more than
887 N days, just insert a special line indicating the size of the gap."
888 :group 'org-agenda-skip
889 :type '(choice
890 (const :tag "None" nil)
891 (const :tag "All" t)
892 (integer :tag "at most")))
894 (defgroup org-agenda-startup nil
895 "Options concerning initial settings in the Agenda in Org Mode."
896 :tag "Org Agenda Startup"
897 :group 'org-agenda)
899 (defcustom org-agenda-menu-show-matcher t
900 "Non-nil means show the match string in the agenda dispatcher menu.
901 When nil, the matcher string is not shown, but is put into the help-echo
902 property so than moving the mouse over the command shows it.
903 Setting it to nil is good if matcher strings are very long and/or if
904 you want to use two-columns display (see `org-agenda-menu-two-columns')."
905 :group 'org-agenda
906 :version "24.1"
907 :type 'boolean)
909 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
911 (defcustom org-agenda-menu-two-columns nil
912 "Non-nil means, use two columns to show custom commands in the dispatcher.
913 If you use this, you probably want to set `org-agenda-menu-show-matcher'
914 to nil."
915 :group 'org-agenda
916 :version "24.1"
917 :type 'boolean)
919 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
920 (defcustom org-agenda-finalize-hook nil
921 "Hook run just before displaying an agenda buffer.
922 The buffer is still writable when the hook is called.
924 You can modify some of the buffer substrings but you should be
925 extra careful not to modify the text properties of the agenda
926 headlines as the agenda display heavily relies on them."
927 :group 'org-agenda-startup
928 :type 'hook)
930 (defcustom org-agenda-mouse-1-follows-link nil
931 "Non-nil means mouse-1 on a link will follow the link in the agenda.
932 A longer mouse click will still set point. Does not work on XEmacs.
933 Needs to be set before org.el is loaded."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-follow-mode nil
938 "The initial value of follow mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-follow-indirect nil
943 "Non-nil means `org-agenda-follow-mode' displays only the
944 current item's tree, in an indirect buffer."
945 :group 'org-agenda
946 :version "24.1"
947 :type 'boolean)
949 (defcustom org-agenda-show-outline-path t
950 "Non-nil means show outline path in echo area after line motion."
951 :group 'org-agenda-startup
952 :type 'boolean)
954 (defcustom org-agenda-start-with-entry-text-mode nil
955 "The initial value of entry-text-mode in a newly created agenda window."
956 :group 'org-agenda-startup
957 :type 'boolean)
959 (defcustom org-agenda-entry-text-maxlines 5
960 "Number of text lines to be added when `E' is pressed in the agenda.
962 Note that this variable only used during agenda display. Add add entry text
963 when exporting the agenda, configure the variable
964 `org-agenda-add-entry-ext-maxlines'."
965 :group 'org-agenda
966 :type 'integer)
968 (defcustom org-agenda-entry-text-exclude-regexps nil
969 "List of regular expressions to clean up entry text.
970 The complete matches of all regular expressions in this list will be
971 removed from entry text before it is shown in the agenda."
972 :group 'org-agenda
973 :type '(repeat (regexp)))
975 (defvar org-agenda-entry-text-cleanup-hook nil
976 "Hook that is run after basic cleanup of entry text to be shown in agenda.
977 This cleanup is done in a temporary buffer, so the function may inspect and
978 change the entire buffer.
979 Some default stuff like drawers and scheduling/deadline dates will already
980 have been removed when this is called, as will any matches for regular
981 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
983 (defvar org-agenda-include-inactive-timestamps nil
984 "Non-nil means include inactive time stamps in agenda and timeline.
985 Dynamically scoped.")
987 (defgroup org-agenda-windows nil
988 "Options concerning the windows used by the Agenda in Org Mode."
989 :tag "Org Agenda Windows"
990 :group 'org-agenda)
992 (defcustom org-agenda-window-setup 'reorganize-frame
993 "How the agenda buffer should be displayed.
994 Possible values for this option are:
996 current-window Show agenda in the current window, keeping all other windows.
997 other-window Use `switch-to-buffer-other-window' to display agenda.
998 reorganize-frame Show only two windows on the current frame, the current
999 window and the agenda.
1000 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1001 Also, when exiting the agenda, kill that frame.
1002 See also the variable `org-agenda-restore-windows-after-quit'."
1003 :group 'org-agenda-windows
1004 :type '(choice
1005 (const current-window)
1006 (const other-frame)
1007 (const other-window)
1008 (const reorganize-frame)))
1010 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1011 "The min and max height of the agenda window as a fraction of frame height.
1012 The value of the variable is a cons cell with two numbers between 0 and 1.
1013 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1014 :group 'org-agenda-windows
1015 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1017 (defcustom org-agenda-restore-windows-after-quit nil
1018 "Non-nil means restore window configuration upon exiting agenda.
1019 Before the window configuration is changed for displaying the agenda,
1020 the current status is recorded. When the agenda is exited with
1021 `q' or `x' and this option is set, the old state is restored. If
1022 `org-agenda-window-setup' is `other-frame', the value of this
1023 option will be ignored."
1024 :group 'org-agenda-windows
1025 :type 'boolean)
1027 (defcustom org-agenda-ndays nil
1028 "Number of days to include in overview display.
1029 Should be 1 or 7.
1030 Obsolete, see `org-agenda-span'."
1031 :group 'org-agenda-daily/weekly
1032 :type 'integer)
1034 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1036 (defcustom org-agenda-span 'week
1037 "Number of days to include in overview display.
1038 Can be day, week, month, year, or any number of days.
1039 Custom commands can set this variable in the options section."
1040 :group 'org-agenda-daily/weekly
1041 :type '(choice (const :tag "Day" day)
1042 (const :tag "Week" week)
1043 (const :tag "Month" month)
1044 (const :tag "Year" year)
1045 (integer :tag "Custom")))
1047 (defcustom org-agenda-start-on-weekday 1
1048 "Non-nil means start the overview always on the specified weekday.
1049 0 denotes Sunday, 1 denotes Monday etc.
1050 When nil, always start on the current day.
1051 Custom commands can set this variable in the options section."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice (const :tag "Today" nil)
1054 (integer :tag "Weekday No.")))
1056 (defcustom org-agenda-show-all-dates t
1057 "Non-nil means `org-agenda' shows every day in the selected range.
1058 When nil, only the days which actually have entries are shown."
1059 :group 'org-agenda-daily/weekly
1060 :type 'boolean)
1062 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1063 "Format string for displaying dates in the agenda.
1064 Used by the daily/weekly agenda and by the timeline. This should be
1065 a format string understood by `format-time-string', or a function returning
1066 the formatted date as a string. The function must take a single argument,
1067 a calendar-style date list like (month day year)."
1068 :group 'org-agenda-daily/weekly
1069 :type '(choice
1070 (string :tag "Format string")
1071 (function :tag "Function")))
1073 (defun org-agenda-format-date-aligned (date)
1074 "Format a date string for display in the daily/weekly agenda, or timeline.
1075 This function makes sure that dates are aligned for easy reading."
1076 (require 'cal-iso)
1077 (let* ((dayname (calendar-day-name date))
1078 (day (cadr date))
1079 (day-of-week (calendar-day-of-week date))
1080 (month (car date))
1081 (monthname (calendar-month-name month))
1082 (year (nth 2 date))
1083 (iso-week (org-days-to-iso-week
1084 (calendar-absolute-from-gregorian date)))
1085 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1086 (1- year))
1087 ((and (= month 12) (<= iso-week 1))
1088 (1+ year))
1089 (t year)))
1090 (weekstring (if (= day-of-week 1)
1091 (format " W%02d" iso-week)
1092 "")))
1093 (format "%-10s %2d %s %4d%s"
1094 dayname day monthname year weekstring)))
1096 (defcustom org-agenda-time-leading-zero nil
1097 "Non-nil means use leading zero for military times in agenda.
1098 For example, 9:30am would become 09:30 rather than 9:30."
1099 :group 'org-agenda-daily/weekly
1100 :version "24.1"
1101 :type 'boolean)
1103 (defcustom org-agenda-timegrid-use-ampm nil
1104 "When set, show AM/PM style timestamps on the timegrid."
1105 :group 'org-agenda
1106 :version "24.1"
1107 :type 'boolean)
1109 (defun org-agenda-time-of-day-to-ampm (time)
1110 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1111 (let* ((hour-number (string-to-number (substring time 0 -3)))
1112 (minute (substring time -2))
1113 (ampm "am"))
1114 (cond
1115 ((equal hour-number 12)
1116 (setq ampm "pm"))
1117 ((> hour-number 12)
1118 (setq ampm "pm")
1119 (setq hour-number (- hour-number 12))))
1120 (concat
1121 (if org-agenda-time-leading-zero
1122 (format "%02d" hour-number)
1123 (format "%02s" (number-to-string hour-number)))
1124 ":" minute ampm)))
1126 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1127 "Conditionally convert TIME to AM/PM format
1128 based on `org-agenda-timegrid-use-ampm'"
1129 (if org-agenda-timegrid-use-ampm
1130 (org-agenda-time-of-day-to-ampm time)
1131 time))
1133 (defcustom org-agenda-weekend-days '(6 0)
1134 "Which days are weekend?
1135 These days get the special face `org-agenda-date-weekend' in the agenda
1136 and timeline buffers."
1137 :group 'org-agenda-daily/weekly
1138 :type '(set :greedy t
1139 (const :tag "Monday" 1)
1140 (const :tag "Tuesday" 2)
1141 (const :tag "Wednesday" 3)
1142 (const :tag "Thursday" 4)
1143 (const :tag "Friday" 5)
1144 (const :tag "Saturday" 6)
1145 (const :tag "Sunday" 0)))
1147 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1148 "Non-nil means jump to today when moving a past date forward in time.
1149 When using S-right in the agenda to move a a date forward, and the date
1150 stamp currently points to the past, the first key press will move it
1151 to today. WHen nil, just move one day forward even if the date stays
1152 in the past."
1153 :group 'org-agenda-daily/weekly
1154 :version "24.1"
1155 :type 'boolean)
1157 (defcustom org-agenda-include-diary nil
1158 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1159 Custom commands can set this variable in the options section."
1160 :group 'org-agenda-daily/weekly
1161 :type 'boolean)
1163 (defcustom org-agenda-include-deadlines t
1164 "If non-nil, include entries within their deadline warning period.
1165 Custom commands can set this variable in the options section."
1166 :group 'org-agenda-daily/weekly
1167 :version "24.1"
1168 :type 'boolean)
1170 (defcustom org-agenda-repeating-timestamp-show-all t
1171 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1172 When set to a list of strings, only show occurrences of repeating
1173 stamps for these TODO keywords. When nil, only one occurrence is
1174 shown, either today or the nearest into the future."
1175 :group 'org-agenda-daily/weekly
1176 :type '(choice
1177 (const :tag "Show repeating stamps" t)
1178 (repeat :tag "Show repeating stamps for these TODO keywords"
1179 (string :tag "TODO Keyword"))
1180 (const :tag "Don't show repeating stamps" nil)))
1182 (defcustom org-scheduled-past-days 10000
1183 "No. of days to continue listing scheduled items that are not marked DONE.
1184 When an item is scheduled on a date, it shows up in the agenda on this
1185 day and will be listed until it is marked done for the number of days
1186 given here."
1187 :group 'org-agenda-daily/weekly
1188 :type 'integer)
1190 (defcustom org-agenda-log-mode-items '(closed clock)
1191 "List of items that should be shown in agenda log mode.
1192 This list may contain the following symbols:
1194 closed Show entries that have been closed on that day.
1195 clock Show entries that have received clocked time on that day.
1196 state Show all logged state changes.
1197 Note that instead of changing this variable, you can also press `C-u l' in
1198 the agenda to display all available LOG items temporarily."
1199 :group 'org-agenda-daily/weekly
1200 :type '(set :greedy t (const closed) (const clock) (const state)))
1202 (defcustom org-agenda-clock-consistency-checks
1203 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1204 :gap-ok-around ("4:00")
1205 :default-face ((:background "DarkRed") (:foreground "white"))
1206 :overlap-face nil :gap-face nil :no-end-time-face nil
1207 :long-face nil :short-face nil)
1208 "This is a property list, with the following keys:
1210 :max-duration Mark clocking chunks that are longer than this time.
1211 This is a time string like \"HH:MM\", or the number
1212 of minutes as an integer.
1214 :min-duration Mark clocking chunks that are shorter that this.
1215 This is a time string like \"HH:MM\", or the number
1216 of minutes as an integer.
1218 :max-gap Mark gaps between clocking chunks that are longer than
1219 this duration. A number of minutes, or a string
1220 like \"HH:MM\".
1222 :gap-ok-around List of times during the day which are usually not working
1223 times. When a gap is detected, but the gap contains any
1224 of these times, the gap is *not* reported. For example,
1225 if this is (\"4:00\" \"13:00\") then gaps that contain
1226 4:00 in the morning (i.e. the night) and 13:00
1227 (i.e. a typical lunch time) do not cause a warning.
1228 You should have at least one time during the night in this
1229 list, or otherwise the first task each morning will trigger
1230 a warning because it follows a long gap.
1232 Furthermore, the following properties can be used to define faces for
1233 issue display.
1235 :default-face the default face, if the specific face is undefined
1236 :overlap-face face for overlapping clocks
1237 :gap-face face for gaps between clocks
1238 :no-end-time-face face for incomplete clocks
1239 :long-face face for clock intervals that are too long
1240 :short-face face for clock intervals that are too short"
1241 :group 'org-agenda-daily/weekly
1242 :group 'org-clock
1243 :version "24.1"
1244 :type 'plist)
1246 (defcustom org-agenda-log-mode-add-notes t
1247 "Non-nil means add first line of notes to log entries in agenda views.
1248 If a log item like a state change or a clock entry is associated with
1249 notes, the first line of these notes will be added to the entry in the
1250 agenda display."
1251 :group 'org-agenda-daily/weekly
1252 :type 'boolean)
1254 (defcustom org-agenda-start-with-log-mode nil
1255 "The initial value of log-mode in a newly created agenda window.
1256 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1257 explanations on the possible values."
1258 :group 'org-agenda-startup
1259 :group 'org-agenda-daily/weekly
1260 :type '(choice (const :tag "Don't show log items" nil)
1261 (const :tag "Show only log items" 'only)
1262 (const :tag "Show all possible log items" 'clockcheck)
1263 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1264 (choice (const :tag "Show closed log items" 'closed)
1265 (const :tag "Show clocked log items" 'clock)
1266 (const :tag "Show all logged state changes" 'state)))))
1268 (defcustom org-agenda-start-with-clockreport-mode nil
1269 "The initial value of clockreport-mode in a newly created agenda window."
1270 :group 'org-agenda-startup
1271 :group 'org-agenda-daily/weekly
1272 :type 'boolean)
1274 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1275 "Property list with parameters for the clocktable in clockreport mode.
1276 This is the display mode that shows a clock table in the daily/weekly
1277 agenda, the properties for this dynamic block can be set here.
1278 The usual clocktable parameters are allowed here, but you cannot set
1279 the properties :name, :tstart, :tend, :block, and :scope - these will
1280 be overwritten to make sure the content accurately reflects the
1281 current display in the agenda."
1282 :group 'org-agenda-daily/weekly
1283 :type 'plist)
1285 (defcustom org-agenda-search-view-always-boolean nil
1286 "Non-nil means the search string is interpreted as individual parts.
1288 The search string for search view can either be interpreted as a phrase,
1289 or as a list of snippets that define a boolean search for a number of
1290 strings.
1292 When this is non-nil, the string will be split on whitespace, and each
1293 snippet will be searched individually, and all must match in order to
1294 select an entry. A snippet is then a single string of non-white
1295 characters, or a string in double quotes, or a regexp in {} braces.
1296 If a snippet is preceded by \"-\", the snippet must *not* match.
1297 \"+\" is syntactic sugar for positive selection. Each snippet may
1298 be found as a full word or a partial word, but see the variable
1299 `org-agenda-search-view-force-full-words'.
1301 When this is nil, search will look for the entire search phrase as one,
1302 with each space character matching any amount of whitespace, including
1303 line breaks.
1305 Even when this is nil, you can still switch to Boolean search dynamically
1306 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1307 is a regexp marked with braces like \"{abc}\", this will also switch to
1308 boolean search."
1309 :group 'org-agenda-search-view
1310 :version "24.1"
1311 :type 'boolean)
1313 (if (fboundp 'defvaralias)
1314 (defvaralias 'org-agenda-search-view-search-words-only
1315 'org-agenda-search-view-always-boolean))
1317 (defcustom org-agenda-search-view-force-full-words nil
1318 "Non-nil means, search words must be matches as complete words.
1319 When nil, they may also match part of a word."
1320 :group 'org-agenda-search-view
1321 :version "24.1"
1322 :type 'boolean)
1324 (defcustom org-agenda-search-view-max-outline-level nil
1325 "Maximum outline level to display in search view.
1326 E.g. when this is set to 1, the search view will only
1327 show headlines of level 1."
1328 :group 'org-agenda-search-view
1329 :version "24.3"
1330 :type 'integer)
1332 (defgroup org-agenda-time-grid nil
1333 "Options concerning the time grid in the Org-mode Agenda."
1334 :tag "Org Agenda Time Grid"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-search-headline-for-time t
1338 "Non-nil means search headline for a time-of-day.
1339 If the headline contains a time-of-day in one format or another, it will
1340 be used to sort the entry into the time sequence of items for a day.
1341 Some people have time stamps in the headline that refer to the creation
1342 time or so, and then this produces an unwanted side effect. If this is
1343 the case for your, use this variable to turn off searching the headline
1344 for a time."
1345 :group 'org-agenda-time-grid
1346 :type 'boolean)
1348 (defcustom org-agenda-use-time-grid t
1349 "Non-nil means show a time grid in the agenda schedule.
1350 A time grid is a set of lines for specific times (like every two hours between
1351 8:00 and 20:00). The items scheduled for a day at specific times are
1352 sorted in between these lines.
1353 For details about when the grid will be shown, and what it will look like, see
1354 the variable `org-agenda-time-grid'."
1355 :group 'org-agenda-time-grid
1356 :type 'boolean)
1358 (defcustom org-agenda-time-grid
1359 '((daily today require-timed)
1360 "----------------"
1361 (800 1000 1200 1400 1600 1800 2000))
1363 "The settings for time grid for agenda display.
1364 This is a list of three items. The first item is again a list. It contains
1365 symbols specifying conditions when the grid should be displayed:
1367 daily if the agenda shows a single day
1368 weekly if the agenda shows an entire week
1369 today show grid on current date, independent of daily/weekly display
1370 require-timed show grid only if at least one item has a time specification
1372 The second item is a string which will be placed behind the grid time.
1374 The third item is a list of integers, indicating the times that should have
1375 a grid line."
1376 :group 'org-agenda-time-grid
1377 :type
1378 '(list
1379 (set :greedy t :tag "Grid Display Options"
1380 (const :tag "Show grid in single day agenda display" daily)
1381 (const :tag "Show grid in weekly agenda display" weekly)
1382 (const :tag "Always show grid for today" today)
1383 (const :tag "Show grid only if any timed entries are present"
1384 require-timed)
1385 (const :tag "Skip grid times already present in an entry"
1386 remove-match))
1387 (string :tag "Grid String")
1388 (repeat :tag "Grid Times" (integer :tag "Time"))))
1390 (defcustom org-agenda-show-current-time-in-grid t
1391 "Non-nil means show the current time in the time grid."
1392 :group 'org-agenda-time-grid
1393 :version "24.1"
1394 :type 'boolean)
1396 (defcustom org-agenda-current-time-string
1397 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1398 "The string for the current time marker in the agenda."
1399 :group 'org-agenda-time-grid
1400 :version "24.1"
1401 :type 'string)
1403 (defgroup org-agenda-sorting nil
1404 "Options concerning sorting in the Org-mode Agenda."
1405 :tag "Org Agenda Sorting"
1406 :group 'org-agenda)
1408 (defcustom org-agenda-sorting-strategy
1409 '((agenda habit-down time-up priority-down category-keep)
1410 (todo priority-down category-keep)
1411 (tags priority-down category-keep)
1412 (search category-keep))
1413 "Sorting structure for the agenda items of a single day.
1414 This is a list of symbols which will be used in sequence to determine
1415 if an entry should be listed before another entry. The following
1416 symbols are recognized:
1418 time-up Put entries with time-of-day indications first, early first
1419 time-down Put entries with time-of-day indications first, late first
1420 category-keep Keep the default order of categories, corresponding to the
1421 sequence in `org-agenda-files'.
1422 category-up Sort alphabetically by category, A-Z.
1423 category-down Sort alphabetically by category, Z-A.
1424 tag-up Sort alphabetically by last tag, A-Z.
1425 tag-down Sort alphabetically by last tag, Z-A.
1426 priority-up Sort numerically by priority, high priority last.
1427 priority-down Sort numerically by priority, high priority first.
1428 todo-state-up Sort by todo state, tasks that are done last.
1429 todo-state-down Sort by todo state, tasks that are done first.
1430 effort-up Sort numerically by estimated effort, high effort last.
1431 effort-down Sort numerically by estimated effort, high effort first.
1432 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1433 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1434 habit-up Put entries that are habits first
1435 habit-down Put entries that are habits last
1436 alpha-up Sort headlines alphabetically
1437 alpha-down Sort headlines alphabetically, reversed
1439 The different possibilities will be tried in sequence, and testing stops
1440 if one comparison returns a \"not-equal\". For example, the default
1441 '(time-up category-keep priority-down)
1442 means: Pull out all entries having a specified time of day and sort them,
1443 in order to make a time schedule for the current day the first thing in the
1444 agenda listing for the day. Of the entries without a time indication, keep
1445 the grouped in categories, don't sort the categories, but keep them in
1446 the sequence given in `org-agenda-files'. Within each category sort by
1447 priority.
1449 Leaving out `category-keep' would mean that items will be sorted across
1450 categories by priority.
1452 Instead of a single list, this can also be a set of list for specific
1453 contents, with a context symbol in the car of the list, any of
1454 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1456 Custom commands can bind this variable in the options section."
1457 :group 'org-agenda-sorting
1458 :type `(choice
1459 (repeat :tag "General" ,org-sorting-choice)
1460 (list :tag "Individually"
1461 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1462 (repeat ,org-sorting-choice))
1463 (cons (const :tag "Strategy for TODO lists" todo)
1464 (repeat ,org-sorting-choice))
1465 (cons (const :tag "Strategy for Tags matches" tags)
1466 (repeat ,org-sorting-choice))
1467 (cons (const :tag "Strategy for search matches" search)
1468 (repeat ,org-sorting-choice)))))
1470 (defcustom org-agenda-cmp-user-defined nil
1471 "A function to define the comparison `user-defined'.
1472 This function must receive two arguments, agenda entry a and b.
1473 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1474 the user comparison, return nil.
1475 When this is defined, you can make `user-defined-up' and `user-defined-down'
1476 part of an agenda sorting strategy."
1477 :group 'org-agenda-sorting
1478 :type 'symbol)
1480 (defcustom org-sort-agenda-notime-is-late t
1481 "Non-nil means items without time are considered late.
1482 This is only relevant for sorting. When t, items which have no explicit
1483 time like 15:30 will be considered as 99:01, i.e. later than any items which
1484 do have a time. When nil, the default time is before 0:00. You can use this
1485 option to decide if the schedule for today should come before or after timeless
1486 agenda entries."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defcustom org-sort-agenda-noeffort-is-high t
1491 "Non-nil means items without effort estimate are sorted as high effort.
1492 This also applies when filtering an agenda view with respect to the
1493 < or > effort operator. Then, tasks with no effort defined will be treated
1494 as tasks with high effort.
1495 When nil, such items are sorted as 0 minutes effort."
1496 :group 'org-agenda-sorting
1497 :type 'boolean)
1499 (defgroup org-agenda-line-format nil
1500 "Options concerning the entry prefix in the Org-mode agenda display."
1501 :tag "Org Agenda Line Format"
1502 :group 'org-agenda)
1504 (defcustom org-agenda-prefix-format
1505 '((agenda . " %i %-12:c%?-12t% s")
1506 (timeline . " % s")
1507 (todo . " %i %-12:c")
1508 (tags . " %i %-12:c")
1509 (search . " %i %-12:c"))
1510 "Format specifications for the prefix of items in the agenda views.
1511 An alist with five entries, each for the different agenda types. The
1512 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1513 The values are format strings.
1515 This format works similar to a printf format, with the following meaning:
1517 %c the category of the item, \"Diary\" for entries from the diary,
1518 or as given by the CATEGORY keyword or derived from the file name
1519 %e the effort required by the item
1520 %l the level of the item (insert X space(s) if item is of level X)
1521 %i the icon category of the item, see `org-agenda-category-icon-alist'
1522 %T the last tag of the item (ignore inherited tags, which come first)
1523 %t the HH:MM time-of-day specification if one applies to the entry
1524 %s Scheduling/Deadline information, a short string
1525 %(expression) Eval EXPRESSION and replace the control string
1526 by the result
1528 All specifiers work basically like the standard `%s' of printf, but may
1529 contain two additional characters: a question mark just after the `%'
1530 and a whitespace/punctuation character just before the final letter.
1532 If the first character after `%' is a question mark, the entire field
1533 will only be included if the corresponding value applies to the current
1534 entry. This is useful for fields which should have fixed width when
1535 present, but zero width when absent. For example, \"%?-12t\" will
1536 result in a 12 character time field if a time of the day is specified,
1537 but will completely disappear in entries which do not contain a time.
1539 If there is punctuation or whitespace character just before the final
1540 format letter, this character will be appended to the field value if
1541 the value is not empty. For example, the format \"%-12:c\" leads to
1542 \"Diary: \" if the category is \"Diary\". If the category were be
1543 empty, no additional colon would be inserted.
1545 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1546 which means:
1548 - Indent the line with two space characters
1549 - Give the category a 12 chars wide field, padded with whitespace on
1550 the right (because of `-'). Append a colon if there is a category
1551 (because of `:').
1552 - If there is a time-of-day, put it into a 12 chars wide field. If no
1553 time, don't put in an empty field, just skip it (because of '?').
1554 - Finally, put the scheduling information.
1556 See also the variables `org-agenda-remove-times-when-in-prefix' and
1557 `org-agenda-remove-tags'.
1559 Custom commands can set this variable in the options section."
1560 :type '(choice
1561 (string :tag "General format")
1562 (list :greedy t :tag "View dependent"
1563 (cons (const agenda) (string :tag "Format"))
1564 (cons (const timeline) (string :tag "Format"))
1565 (cons (const todo) (string :tag "Format"))
1566 (cons (const tags) (string :tag "Format"))
1567 (cons (const search) (string :tag "Format"))))
1568 :group 'org-agenda-line-format)
1570 (defvar org-prefix-format-compiled nil
1571 "The compiled prefix format and associated variables.
1572 This is a list where first element is a list of variable bindings, and second
1573 element is the compiled format expression. See the variable
1574 `org-agenda-prefix-format'.")
1576 (defcustom org-agenda-todo-keyword-format "%-1s"
1577 "Format for the TODO keyword in agenda lines.
1578 Set this to something like \"%-12s\" if you want all TODO keywords
1579 to occupy a fixed space in the agenda display."
1580 :group 'org-agenda-line-format
1581 :type 'string)
1583 (defcustom org-agenda-diary-sexp-prefix nil
1584 "A regexp that matches part of a diary sexp entry
1585 which should be treated as scheduling/deadline information in
1586 `org-agenda'.
1588 For example, you can use this to extract the `diary-remind-message' from
1589 `diary-remind' entries."
1590 :group 'org-agenda-line-format
1591 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1593 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1594 "Text preceding timerange entries in the agenda view.
1595 This is a list with two strings. The first applies when the range
1596 is entirely on one day. The second applies if the range spans several days.
1597 The strings may have two \"%d\" format specifiers which will be filled
1598 with the sequence number of the days, and the total number of days in the
1599 range, respectively."
1600 :group 'org-agenda-line-format
1601 :type '(list
1602 (string :tag "Deadline today ")
1603 (choice :tag "Deadline relative"
1604 (string :tag "Format string")
1605 (function))))
1607 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1608 "Text preceding scheduled items in the agenda view.
1609 This is a list with two strings. The first applies when the item is
1610 scheduled on the current day. The second applies when it has been scheduled
1611 previously, it may contain a %d indicating that this is the nth time that
1612 this item is scheduled, due to automatic rescheduling of unfinished items
1613 for the following day. So this number is one larger than the number of days
1614 that passed since this item was scheduled first."
1615 :group 'org-agenda-line-format
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-inactive-leader "["
1621 "Text preceding item pulled into the agenda by inactive time stamps.
1622 These entries are added to the agenda when pressing \"[\"."
1623 :group 'org-agenda-line-format
1624 :version "24.1"
1625 :type '(list
1626 (string :tag "Scheduled today ")
1627 (string :tag "Scheduled previously")))
1629 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1630 "Text preceding deadline items in the agenda view.
1631 This is a list with two strings. The first applies when the item has its
1632 deadline on the current day. The second applies when it is in the past or
1633 in the future, it may contain %d to capture how many days away the deadline
1634 is (was)."
1635 :group 'org-agenda-line-format
1636 :type '(list
1637 (string :tag "Deadline today ")
1638 (choice :tag "Deadline relative"
1639 (string :tag "Format string")
1640 (function))))
1642 (defcustom org-agenda-remove-times-when-in-prefix t
1643 "Non-nil means remove duplicate time specifications in agenda items.
1644 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1645 time-of-day specification in a headline or diary entry is extracted and
1646 placed into the prefix. If this option is non-nil, the original specification
1647 \(a timestamp or -range, or just a plain time(range) specification like
1648 11:30-4pm) will be removed for agenda display. This makes the agenda less
1649 cluttered.
1650 The option can be t or nil. It may also be the symbol `beg', indicating
1651 that the time should only be removed when it is located at the beginning of
1652 the headline/diary entry."
1653 :group 'org-agenda-line-format
1654 :type '(choice
1655 (const :tag "Always" t)
1656 (const :tag "Never" nil)
1657 (const :tag "When at beginning of entry" beg)))
1659 (defcustom org-agenda-remove-timeranges-from-blocks nil
1660 "Non-nil means remove time ranges specifications in agenda
1661 items that span on several days."
1662 :group 'org-agenda-line-format
1663 :version "24.1"
1664 :type 'boolean)
1666 (defcustom org-agenda-default-appointment-duration nil
1667 "Default duration for appointments that only have a starting time.
1668 When nil, no duration is specified in such cases.
1669 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1670 :group 'org-agenda-line-format
1671 :type '(choice
1672 (integer :tag "Minutes")
1673 (const :tag "No default duration")))
1675 (defcustom org-agenda-show-inherited-tags t
1676 "Non-nil means show inherited tags in each agenda line.
1678 When this option is set to 'always, it take precedences over
1679 `org-agenda-use-tag-inheritance' and inherited tags are shown
1680 in every agenda.
1682 When this option is set to t (the default), inherited tags are
1683 shown when they are available, i.e. when the value of
1684 `org-agenda-use-tag-inheritance' has been taken into account.
1686 This can be set to a list of agenda types in which the agenda
1687 must display the inherited tags. Available types are 'todo,
1688 'agenda, 'search and 'timeline.
1690 When set to nil, never show inherited tags in agenda lines."
1691 :group 'org-agenda-line-format
1692 :group 'org-agenda
1693 :version "24.3"
1694 :type '(choice
1695 (const :tag "Show inherited tags when available" t)
1696 (const :tag "Always show inherited tags" 'always)
1697 (repeat :tag "Show inherited tags only in selected agenda types"
1698 (symbol :tag "Agenda type"))))
1700 (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
1701 "List of agenda view types where to use tag inheritance.
1703 In tags/tags-todo/tags-tree agenda views, tag inheritance is
1704 controlled by `org-use-tag-inheritance'. In other agenda types,
1705 `org-use-tag-inheritance' is not used for the selection of the
1706 agenda entries. Still, you may want the agenda to be aware of
1707 the inherited tags anyway, e.g. for later tag filtering.
1709 Allowed value are 'todo, 'search, 'timeline and 'agenda.
1711 This variable has no effect if `org-agenda-show-inherited-tags'
1712 is set to 'always. In that case, the agenda is aware of those
1713 tags.
1715 The default value sets tags in every agenda type. Setting this
1716 option to nil will speed up non-tags agenda view a lot."
1717 :group 'org-agenda
1718 :version "24.3"
1719 :type '(choice
1720 (const :tag "Use tag inheritance in all agenda types" t)
1721 (repeat :tag "Use tag inheritance in selected agenda types"
1722 (symbol :tag "Agenda type"))))
1724 (defcustom org-agenda-hide-tags-regexp nil
1725 "Regular expression used to filter away specific tags in agenda views.
1726 This means that these tags will be present, but not be shown in the agenda
1727 line. Secondary filtering will still work on the hidden tags.
1728 Nil means don't hide any tags."
1729 :group 'org-agenda-line-format
1730 :type '(choice
1731 (const :tag "Hide none" nil)
1732 (string :tag "Regexp ")))
1734 (defcustom org-agenda-remove-tags nil
1735 "Non-nil means remove the tags from the headline copy in the agenda.
1736 When this is the symbol `prefix', only remove tags when
1737 `org-agenda-prefix-format' contains a `%T' specifier."
1738 :group 'org-agenda-line-format
1739 :type '(choice
1740 (const :tag "Always" t)
1741 (const :tag "Never" nil)
1742 (const :tag "When prefix format contains %T" prefix)))
1744 (if (fboundp 'defvaralias)
1745 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1746 'org-agenda-remove-tags))
1748 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1749 "Shift tags in agenda items to this column.
1750 If this number is positive, it specifies the column. If it is negative,
1751 it means that the tags should be flushright to that column. For example,
1752 -80 works well for a normal 80 character screen."
1753 :group 'org-agenda-line-format
1754 :type 'integer)
1756 (if (fboundp 'defvaralias)
1757 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1759 (defcustom org-agenda-fontify-priorities 'cookies
1760 "Non-nil means highlight low and high priorities in agenda.
1761 When t, the highest priority entries are bold, lowest priority italic.
1762 However, settings in `org-priority-faces' will overrule these faces.
1763 When this variable is the symbol `cookies', only fontify the
1764 cookies, not the entire task.
1765 This may also be an association list of priority faces, whose
1766 keys are the character values of `org-highest-priority',
1767 `org-default-priority', and `org-lowest-priority' (the default values
1768 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1769 color as a string, or a list like `(:background \"Red\")'.
1770 If it is a color, the variable `org-faces-easy-properties'
1771 determines if it is a foreground or a background color."
1772 :group 'org-agenda-line-format
1773 :type '(choice
1774 (const :tag "Never" nil)
1775 (const :tag "Defaults" t)
1776 (const :tag "Cookies only" cookies)
1777 (repeat :tag "Specify"
1778 (list (character :tag "Priority" :value ?A)
1779 (choice :tag "Face "
1780 (string :tag "Color")
1781 (sexp :tag "Face"))))))
1783 (defcustom org-agenda-day-face-function nil
1784 "Function called to determine what face should be used to display a day.
1785 The only argument passed to that function is the day. It should
1786 returns a face, or nil if does not want to specify a face and let
1787 the normal rules apply."
1788 :group 'org-agenda-line-format
1789 :version "24.1"
1790 :type 'function)
1792 (defcustom org-agenda-category-icon-alist nil
1793 "Alist of category icon to be displayed in agenda views.
1795 Each entry should have the following format:
1797 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1799 Where CATEGORY-REGEXP is a regexp matching the categories where
1800 the icon should be displayed.
1801 FILE-OR-DATA either a file path or a string containing image data.
1803 The other fields can be omitted safely if not needed:
1804 TYPE indicates the image type.
1805 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1806 image data.
1807 PROPS are additional image attributes to assign to the image,
1808 like, e.g. `:ascent center'.
1810 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1812 If you want to set the display properties yourself, just put a
1813 list as second element:
1815 (CATEGORY-REGEXP (MY PROPERTY LIST))
1817 For example, to display a 16px horizontal space for Emacs
1818 category, you can use:
1820 (\"Emacs\" '(space . (:width (16))))"
1821 :group 'org-agenda-line-format
1822 :version "24.1"
1823 :type '(alist :key-type (string :tag "Regexp matching category")
1824 :value-type (choice (list :tag "Icon"
1825 (string :tag "File or data")
1826 (symbol :tag "Type")
1827 (boolean :tag "Data?")
1828 (repeat :tag "Extra image properties" :inline t symbol))
1829 (list :tag "Display properties" sexp))))
1831 (defgroup org-agenda-column-view nil
1832 "Options concerning column view in the agenda."
1833 :tag "Org Agenda Column View"
1834 :group 'org-agenda)
1836 (defcustom org-agenda-columns-show-summaries t
1837 "Non-nil means show summaries for columns displayed in the agenda view."
1838 :group 'org-agenda-column-view
1839 :type 'boolean)
1841 (defcustom org-agenda-columns-compute-summary-properties t
1842 "Non-nil means recompute all summary properties before column view.
1843 When column view in the agenda is listing properties that have a summary
1844 operator, it can go to all relevant buffers and recompute the summaries
1845 there. This can mean overhead for the agenda column view, but is necessary
1846 to have thing up to date.
1847 As a special case, a CLOCKSUM property also makes sure that the clock
1848 computations are current."
1849 :group 'org-agenda-column-view
1850 :type 'boolean)
1852 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1853 "Non-nil means the duration of an appointment will add to day effort.
1854 The property to which appointment durations will be added is the one given
1855 in the option `org-effort-property'. If an appointment does not have
1856 an end time, `org-agenda-default-appointment-duration' will be used. If that
1857 is not set, an appointment without end time will not contribute to the time
1858 estimate."
1859 :group 'org-agenda-column-view
1860 :type 'boolean)
1862 (defcustom org-agenda-auto-exclude-function nil
1863 "A function called with a tag to decide if it is filtered on '/ RET'.
1864 The sole argument to the function, which is called once for each
1865 possible tag, is a string giving the name of the tag. The
1866 function should return either nil if the tag should be included
1867 as normal, or \"-<TAG>\" to exclude the tag.
1868 Note that for the purpose of tag filtering, only the lower-case version of
1869 all tags will be considered, so that this function will only ever see
1870 the lower-case version of all tags."
1871 :group 'org-agenda
1872 :type 'function)
1874 (defcustom org-agenda-bulk-custom-functions nil
1875 "Alist of characters and custom functions for bulk actions.
1876 For example, this value makes those two functions available:
1878 '((?R set-category)
1879 (?C bulk-cut))
1881 With selected entries in an agenda buffer, `B R' will call
1882 the custom function `set-category' on the selected entries.
1883 Note that functions in this alist don't need to be quoted."
1884 :type 'alist
1885 :version "24.1"
1886 :group 'org-agenda)
1888 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1889 "Execute BODY with point at location given by `org-hd-marker' property.
1890 If STRING is non-nil, the text property will be fetched from position 0
1891 in that string. If STRING is nil, it will be fetched from the beginning
1892 of the current line."
1893 (org-with-gensyms (marker)
1894 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1895 'org-hd-marker ,string)))
1896 (with-current-buffer (marker-buffer ,marker)
1897 (save-excursion
1898 (goto-char ,marker)
1899 ,@body)))))
1900 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1902 (defun org-add-agenda-custom-command (entry)
1903 "Replace or add a command in `org-agenda-custom-commands'.
1904 This is mostly for hacking and trying a new command - once the command
1905 works you probably want to add it to `org-agenda-custom-commands' for good."
1906 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1907 (if ass
1908 (setcdr ass (cdr entry))
1909 (push entry org-agenda-custom-commands))))
1911 ;;; Define the org-agenda-mode
1913 (defvar org-agenda-mode-map (make-sparse-keymap)
1914 "Keymap for `org-agenda-mode'.")
1915 (if (fboundp 'defvaralias)
1916 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1918 (defvar org-agenda-menu) ; defined later in this file.
1919 (defvar org-agenda-restrict nil) ; defined later in this file.
1920 (defvar org-agenda-follow-mode nil)
1921 (defvar org-agenda-entry-text-mode nil)
1922 (defvar org-agenda-clockreport-mode nil)
1923 (defvar org-agenda-show-log nil)
1924 (defvar org-agenda-redo-command nil)
1925 (defvar org-agenda-query-string nil)
1926 (defvar org-agenda-mode-hook nil
1927 "Hook run after `org-agenda-mode' is turned on.
1928 The buffer is still writable when this hook is called.")
1929 (defvar org-agenda-type nil)
1930 (defvar org-agenda-force-single-file nil)
1931 (defvar org-agenda-bulk-marked-entries nil
1932 "List of markers that refer to marked entries in the agenda.")
1934 ;;; Multiple agenda buffers support
1936 (defcustom org-agenda-sticky nil
1937 "Non-nil means agenda q key will bury agenda buffers.
1938 Agenda commands will then show existing buffer instead of generating new ones.
1939 When nil, `q' will kill the single agenda buffer."
1940 :group 'org-agenda
1941 :version "24.3"
1942 :type 'boolean)
1945 ;;;###autoload
1946 (defun org-toggle-sticky-agenda (&optional arg)
1947 "Toggle `org-agenda-sticky'."
1948 (interactive "P")
1949 (let ((new-value (if arg
1950 (> (prefix-numeric-value arg) 0)
1951 (not org-agenda-sticky))))
1952 (if (equal new-value org-agenda-sticky)
1953 (and (org-called-interactively-p 'interactive)
1954 (message "Sticky agenda was already %s"
1955 (if org-agenda-sticky "enabled" "disabled")))
1956 (setq org-agenda-sticky new-value)
1957 (org-agenda-kill-all-agenda-buffers)
1958 (and (org-called-interactively-p 'interactive)
1959 (message "Sticky agenda was %s"
1960 (if org-agenda-sticky "enabled" "disabled"))))))
1962 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1963 Toggle `org-agenda-sticky'.
1965 \(fn &optional ARG)" t nil)
1967 (defvar org-agenda-buffer nil
1968 "Agenda buffer currently being generated.")
1970 (defvar org-agenda-last-prefix-arg nil)
1971 (defvar org-agenda-this-buffer-name nil)
1972 (defvar org-agenda-doing-sticky-redo nil)
1973 (defvar org-agenda-this-buffer-is-sticky nil)
1975 (defconst org-agenda-local-vars
1976 '(org-agenda-this-buffer-name
1977 org-agenda-undo-list
1978 org-agenda-pending-undo-list
1979 org-agenda-follow-mode
1980 org-agenda-entry-text-mode
1981 org-agenda-clockreport-mode
1982 org-agenda-show-log
1983 org-agenda-redo-command
1984 org-agenda-query-string
1985 org-agenda-type
1986 org-agenda-bulk-marked-entries
1987 org-agenda-undo-has-started-in
1988 org-agenda-info
1989 org-agenda-tag-filter-overlays
1990 org-agenda-cat-filter-overlays
1991 org-agenda-pre-window-conf
1992 org-agenda-columns-active
1993 org-agenda-tag-filter
1994 org-agenda-category-filter
1995 org-agenda-markers
1996 org-agenda-last-search-view-search-was-boolean
1997 org-agenda-filtered-by-category
1998 org-agenda-filter-form
1999 org-agenda-show-window
2000 org-agenda-cycle-counter
2001 org-agenda-last-prefix-arg)
2002 "Variables that must be local in agenda buffers to allow multiple buffers.")
2004 (defun org-agenda-mode ()
2005 "Mode for time-sorted view on action items in Org-mode files.
2007 The following commands are available:
2009 \\{org-agenda-mode-map}"
2010 (interactive)
2011 (cond (org-agenda-doing-sticky-redo
2012 ;; Refreshing sticky agenda-buffer
2014 ;; Preserve the value of `org-agenda-local-vars' variables,
2015 ;; while letting `kill-all-local-variables' kill the rest
2016 (let ((save (buffer-local-variables)))
2017 (kill-all-local-variables)
2018 (mapc 'make-local-variable org-agenda-local-vars)
2019 (dolist (elem save)
2020 (let ((var (car elem))
2021 (val (cdr elem)))
2022 (when (and val
2023 (member var org-agenda-local-vars))
2024 (set var val)))))
2025 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2026 (org-agenda-sticky
2027 ;; Creating a sticky Agenda buffer for the first time
2028 (kill-all-local-variables)
2029 (mapc 'make-local-variable org-agenda-local-vars)
2030 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
2032 ;; Creating a non-sticky agenda buffer
2033 (kill-all-local-variables)
2034 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
2035 (setq org-agenda-undo-list nil
2036 org-agenda-pending-undo-list nil
2037 org-agenda-bulk-marked-entries nil)
2038 (setq major-mode 'org-agenda-mode)
2039 ;; Keep global-font-lock-mode from turning on font-lock-mode
2040 (org-set-local 'font-lock-global-modes (list 'not major-mode))
2041 (setq mode-name "Org-Agenda")
2042 (use-local-map org-agenda-mode-map)
2043 (easy-menu-add org-agenda-menu)
2044 (if org-startup-truncated (setq truncate-lines t))
2045 (org-set-local 'line-move-visual nil)
2046 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2047 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2048 ;; Make sure properties are removed when copying text
2049 (make-local-variable 'filter-buffer-substring-functions)
2050 (add-hook 'filter-buffer-substring-functions
2051 (lambda (fun start end delete)
2052 (substring-no-properties (funcall fun start end delete))))
2053 (unless org-agenda-keep-modes
2054 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2055 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2056 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2057 org-agenda-show-log org-agenda-start-with-log-mode))
2059 (easy-menu-change
2060 '("Agenda") "Agenda Files"
2061 (append
2062 (list
2063 (vector
2064 (if (get 'org-agenda-files 'org-restrict)
2065 "Restricted to single file"
2066 "Edit File List")
2067 '(org-edit-agenda-file-list)
2068 (not (get 'org-agenda-files 'org-restrict)))
2069 "--")
2070 (mapcar 'org-file-menu-entry (org-agenda-files))))
2071 (org-agenda-set-mode-name)
2072 (apply
2073 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2074 (list 'org-agenda-mode-hook)))
2076 (substitute-key-definition 'undo 'org-agenda-undo
2077 org-agenda-mode-map global-map)
2078 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2079 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2080 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2081 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2082 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2083 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2084 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2085 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2086 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2087 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2088 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2089 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2090 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2091 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2093 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2094 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2095 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2096 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2097 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2098 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2099 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2100 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2101 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2102 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2103 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2104 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2105 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2106 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2107 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2108 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2109 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2110 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2111 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2112 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2113 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2114 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2115 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2116 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2117 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2118 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2119 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2120 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2121 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2122 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2123 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2125 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2126 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2127 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2128 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2129 (while l (org-defkey org-agenda-mode-map
2130 (int-to-string (pop l)) 'digit-argument)))
2132 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2133 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2134 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2135 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2136 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2137 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2138 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2139 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2140 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2141 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2142 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2143 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2144 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2145 'org-clock-modify-effort-estimate)
2146 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2147 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2148 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2149 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2150 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2151 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2152 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2153 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2154 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2155 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2156 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2157 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2158 (substitute-key-definition 'next-line 'org-agenda-next-line
2159 org-agenda-mode-map global-map)
2160 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2161 org-agenda-mode-map global-map)
2162 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2163 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2164 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2165 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2166 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2167 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2168 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2169 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2170 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2171 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2172 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2173 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2174 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2175 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2176 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2177 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2178 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2179 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2180 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2181 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2182 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2183 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2184 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2185 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2186 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2187 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2188 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2189 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2190 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2191 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2193 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2194 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2195 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2196 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2197 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2198 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2199 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2200 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2201 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2202 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2203 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2204 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2206 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2207 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2208 (when org-agenda-mouse-1-follows-link
2209 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2210 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2211 '("Agenda"
2212 ("Agenda Files")
2213 "--"
2214 ("Agenda Dates"
2215 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2216 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2217 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2218 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2219 "--"
2220 ("View"
2221 ["Day View" org-agenda-day-view
2222 :active (org-agenda-check-type nil 'agenda)
2223 :style radio :selected (eq org-agenda-current-span 'day)
2224 :keys "v d (or just d)"]
2225 ["Week View" org-agenda-week-view
2226 :active (org-agenda-check-type nil 'agenda)
2227 :style radio :selected (eq org-agenda-current-span 'week)
2228 :keys "v w (or just w)"]
2229 ["Month View" org-agenda-month-view
2230 :active (org-agenda-check-type nil 'agenda)
2231 :style radio :selected (eq org-agenda-current-span 'month)
2232 :keys "v m"]
2233 ["Year View" org-agenda-year-view
2234 :active (org-agenda-check-type nil 'agenda)
2235 :style radio :selected (eq org-agenda-current-span 'year)
2236 :keys "v y"]
2237 "--"
2238 ["Include Diary" org-agenda-toggle-diary
2239 :style toggle :selected org-agenda-include-diary
2240 :active (org-agenda-check-type nil 'agenda)]
2241 ["Include Deadlines" org-agenda-toggle-deadlines
2242 :style toggle :selected org-agenda-include-deadlines
2243 :active (org-agenda-check-type nil 'agenda)]
2244 ["Use Time Grid" org-agenda-toggle-time-grid
2245 :style toggle :selected org-agenda-use-time-grid
2246 :active (org-agenda-check-type nil 'agenda)]
2247 "--"
2248 ["Show clock report" org-agenda-clockreport-mode
2249 :style toggle :selected org-agenda-clockreport-mode
2250 :active (org-agenda-check-type nil 'agenda)]
2251 ["Show some entry text" org-agenda-entry-text-mode
2252 :style toggle :selected org-agenda-entry-text-mode
2253 :active t]
2254 "--"
2255 ["Show Logbook entries" org-agenda-log-mode
2256 :style toggle :selected org-agenda-show-log
2257 :active (org-agenda-check-type nil 'agenda 'timeline)
2258 :keys "v l (or just l)"]
2259 ["Include archived trees" org-agenda-archives-mode
2260 :style toggle :selected org-agenda-archives-mode :active t
2261 :keys "v a"]
2262 ["Include archive files" (org-agenda-archives-mode t)
2263 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2264 :keys "v A"]
2265 "--"
2266 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2267 ["Write view to file" org-agenda-write t]
2268 ["Rebuild buffer" org-agenda-redo t]
2269 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2270 "--"
2271 ["Show original entry" org-agenda-show t]
2272 ["Go To (other window)" org-agenda-goto t]
2273 ["Go To (this window)" org-agenda-switch-to t]
2274 ["Capture with cursor date" org-agenda-capture t]
2275 ["Follow Mode" org-agenda-follow-mode
2276 :style toggle :selected org-agenda-follow-mode :active t]
2277 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2278 "--"
2279 ("TODO"
2280 ["Cycle TODO" org-agenda-todo t]
2281 ["Next TODO set" org-agenda-todo-nextset t]
2282 ["Previous TODO set" org-agenda-todo-previousset t]
2283 ["Add note" org-agenda-add-note t])
2284 ("Archive/Refile/Delete"
2285 ["Archive default" org-agenda-archive-default t]
2286 ["Archive default" org-agenda-archive-default-with-confirmation t]
2287 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2288 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2289 ["Archive subtree" org-agenda-archive t]
2290 "--"
2291 ["Refile" org-agenda-refile t]
2292 "--"
2293 ["Delete subtree" org-agenda-kill t])
2294 ("Bulk action"
2295 ["Mark entry" org-agenda-bulk-mark t]
2296 ["Mark all" org-agenda-bulk-mark-all t]
2297 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2298 ["Unmark entry" org-agenda-bulk-unmark t]
2299 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2300 ["Act on all marked" org-agenda-bulk-action t]
2301 "--"
2302 ("Tags and Properties"
2303 ["Show all Tags" org-agenda-show-tags t]
2304 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2305 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2306 "--"
2307 ["Column View" org-columns t])
2308 ("Deadline/Schedule"
2309 ["Schedule" org-agenda-schedule t]
2310 ["Set Deadline" org-agenda-deadline t]
2311 "--"
2312 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2313 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2314 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2315 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2316 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2317 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2318 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2319 ("Clock and Effort"
2320 ["Clock in" org-agenda-clock-in t]
2321 ["Clock out" org-agenda-clock-out t]
2322 ["Clock cancel" org-agenda-clock-cancel t]
2323 ["Goto running clock" org-clock-goto t]
2324 "--"
2325 ["Set Effort" org-agenda-set-effort t]
2326 ["Change clocked effort" org-clock-modify-effort-estimate
2327 (org-clock-is-active)])
2328 ("Priority"
2329 ["Set Priority" org-agenda-priority t]
2330 ["Increase Priority" org-agenda-priority-up t]
2331 ["Decrease Priority" org-agenda-priority-down t]
2332 ["Show Priority" org-show-priority t])
2333 ("Calendar/Diary"
2334 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2335 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2336 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2337 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2338 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2339 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2340 "--"
2341 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2342 "--"
2343 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2344 "--"
2345 ("MobileOrg"
2346 ["Push Files and Views" org-mobile-push t]
2347 ["Get Captured and Flagged" org-mobile-pull t]
2348 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2349 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2350 "--"
2351 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2352 "--"
2353 ["Quit" org-agenda-quit t]
2354 ["Exit and Release Buffers" org-agenda-exit t]
2357 ;;; Agenda undo
2359 (defvar org-agenda-allow-remote-undo t
2360 "Non-nil means allow remote undo from the agenda buffer.")
2361 (defvar org-agenda-undo-has-started-in nil
2362 "Buffers that have already seen `undo-start' in the current undo sequence.")
2364 (defun org-agenda-undo ()
2365 "Undo a remote editing step in the agenda.
2366 This undoes changes both in the agenda buffer and in the remote buffer
2367 that have been changed along."
2368 (interactive)
2369 (or org-agenda-allow-remote-undo
2370 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2371 (if (not (eq this-command last-command))
2372 (setq org-agenda-undo-has-started-in nil
2373 org-agenda-pending-undo-list org-agenda-undo-list))
2374 (if (not org-agenda-pending-undo-list)
2375 (error "No further undo information"))
2376 (let* ((entry (pop org-agenda-pending-undo-list))
2377 buf line cmd rembuf)
2378 (setq cmd (pop entry) line (pop entry))
2379 (setq rembuf (nth 2 entry))
2380 (org-with-remote-undo rembuf
2381 (while (bufferp (setq buf (pop entry)))
2382 (if (pop entry)
2383 (with-current-buffer buf
2384 (let ((last-undo-buffer buf)
2385 (inhibit-read-only t))
2386 (unless (memq buf org-agenda-undo-has-started-in)
2387 (push buf org-agenda-undo-has-started-in)
2388 (make-local-variable 'pending-undo-list)
2389 (undo-start))
2390 (while (and pending-undo-list
2391 (listp pending-undo-list)
2392 (not (car pending-undo-list)))
2393 (pop pending-undo-list))
2394 (undo-more 1))))))
2395 (org-goto-line line)
2396 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2398 (defun org-verify-change-for-undo (l1 l2)
2399 "Verify that a real change occurred between the undo lists L1 and L2."
2400 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2401 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2402 (not (eq l1 l2)))
2404 ;;; Agenda dispatch
2406 (defvar org-agenda-restrict-begin (make-marker))
2407 (defvar org-agenda-restrict-end (make-marker))
2408 (defvar org-agenda-last-dispatch-buffer nil)
2409 (defvar org-agenda-overriding-restriction nil)
2411 (defcustom org-agenda-custom-commands-contexts nil
2412 "Alist of custom agenda keys and contextual rules.
2414 For example, if you have a custom agenda command \"p\" and you
2415 want this command to be accessible only from plain text files,
2416 use this:
2418 '((\"p\" ((in-file . \"\\.txt\"))))
2420 Here are the available contexts definitions:
2422 in-file: command displayed only in matching files
2423 in-mode: command displayed only in matching modes
2424 not-in-file: command not displayed in matching files
2425 not-in-mode: command not displayed in matching modes
2426 [function]: a custom function taking no argument
2428 If you define several checks, the agenda command will be
2429 accessible if there is at least one valid check.
2431 You can also bind a key to another agenda custom command
2432 depending on contextual rules.
2434 '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
2436 Here it means: in .txt files, use \"p\" as the key for the
2437 agenda command otherwise associated with \"q\". (The command
2438 originally associated with \"q\" is not displayed to avoid
2439 duplicates.)"
2440 :version "24.3"
2441 :group 'org-agenda-custom-commands
2442 :type '(repeat (list :tag "Rule"
2443 (string :tag " Agenda key")
2444 (string :tag "Replace by command")
2445 (repeat :tag "Available when"
2446 (choice
2447 (cons :tag "Condition"
2448 (choice
2449 (const :tag "In file" in-file)
2450 (const :tag "Not in file" not-in-file)
2451 (const :tag "In mode" in-mode)
2452 (const :tag "Not in mode" not-in-mode))
2453 (regexp))
2454 (function :tag "Custom function"))))))
2456 (defvar org-keys nil)
2457 (defvar org-match nil)
2458 ;;;###autoload
2459 (defun org-agenda (&optional arg org-keys restriction)
2460 "Dispatch agenda commands to collect entries to the agenda buffer.
2461 Prompts for a command to execute. Any prefix arg will be passed
2462 on to the selected command. The default selections are:
2464 a Call `org-agenda-list' to display the agenda for current day or week.
2465 t Call `org-todo-list' to display the global todo list.
2466 T Call `org-todo-list' to display the global todo list, select only
2467 entries with a specific TODO keyword (the user gets a prompt).
2468 m Call `org-tags-view' to display headlines with tags matching
2469 a condition (the user is prompted for the condition).
2470 M Like `m', but select only TODO entries, no ordinary headlines.
2471 L Create a timeline for the current buffer.
2472 e Export views to associated files.
2473 s Search entries for keywords.
2474 S Search entries for keywords, only with TODO keywords.
2475 / Multi occur across all agenda files and also files listed
2476 in `org-agenda-text-search-extra-files'.
2477 < Restrict agenda commands to buffer, subtree, or region.
2478 Press several times to get the desired effect.
2479 > Remove a previous restriction.
2480 # List \"stuck\" projects.
2481 ! Configure what \"stuck\" means.
2482 C Configure custom agenda commands.
2484 More commands can be added by configuring the variable
2485 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2486 searches can be pre-defined in this way.
2488 If the current buffer is in Org-mode and visiting a file, you can also
2489 first press `<' once to indicate that the agenda should be temporarily
2490 \(until the next use of \\[org-agenda]) restricted to the current file.
2491 Pressing `<' twice means to restrict to the current subtree or region
2492 \(if active)."
2493 (interactive "P")
2494 (catch 'exit
2495 (let* ((prefix-descriptions nil)
2496 (org-agenda-buffer-name org-agenda-buffer-name)
2497 (org-agenda-window-setup (if (equal (buffer-name)
2498 org-agenda-buffer-name)
2499 'current-window
2500 org-agenda-window-setup))
2501 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2502 (org-agenda-custom-commands
2503 ;; normalize different versions
2504 (delq nil
2505 (mapcar
2506 (lambda (x)
2507 (cond ((stringp (cdr x))
2508 (push x prefix-descriptions)
2509 nil)
2510 ((stringp (nth 1 x)) x)
2511 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2512 (t (cons (car x) (cons "" (cdr x))))))
2513 org-agenda-custom-commands)))
2514 (org-agenda-custom-commands
2515 (org-contextualize-keys
2516 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2517 (buf (current-buffer))
2518 (bfn (buffer-file-name (buffer-base-buffer)))
2519 entry key type org-match lprops ans)
2520 ;; Turn off restriction unless there is an overriding one,
2521 (unless org-agenda-overriding-restriction
2522 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2523 ;; There is a request to keep the file list in place
2524 (put 'org-agenda-files 'org-restrict nil))
2525 (setq org-agenda-restrict nil)
2526 (move-marker org-agenda-restrict-begin nil)
2527 (move-marker org-agenda-restrict-end nil))
2528 ;; Delete old local properties
2529 (put 'org-agenda-redo-command 'org-lprops nil)
2530 ;; Delete previously set last-arguments
2531 (put 'org-agenda-redo-command 'last-args nil)
2532 ;; Remember where this call originated
2533 (setq org-agenda-last-dispatch-buffer (current-buffer))
2534 (unless org-keys
2535 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2536 org-keys (car ans)
2537 restriction (cdr ans)))
2538 ;; If we have sticky agenda buffers, set a name for the buffer,
2539 ;; depending on the invoking keys. The user may still set this
2540 ;; as a command option, which will overwrite what we do here.
2541 (if org-agenda-sticky
2542 (setq org-agenda-buffer-name
2543 (format "*Org Agenda(%s)*" org-keys)))
2544 ;; Establish the restriction, if any
2545 (when (and (not org-agenda-overriding-restriction) restriction)
2546 (put 'org-agenda-files 'org-restrict (list bfn))
2547 (cond
2548 ((eq restriction 'region)
2549 (setq org-agenda-restrict t)
2550 (move-marker org-agenda-restrict-begin (region-beginning))
2551 (move-marker org-agenda-restrict-end (region-end)))
2552 ((eq restriction 'subtree)
2553 (save-excursion
2554 (setq org-agenda-restrict t)
2555 (org-back-to-heading t)
2556 (move-marker org-agenda-restrict-begin (point))
2557 (move-marker org-agenda-restrict-end
2558 (progn (org-end-of-subtree t)))))))
2560 ;; For example the todo list should not need it (but does...)
2561 (cond
2562 ((setq entry (assoc org-keys org-agenda-custom-commands))
2563 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2564 (progn
2565 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2566 lprops (nth 4 entry))
2567 (if org-agenda-sticky
2568 (setq org-agenda-buffer-name
2569 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2570 (format "*Org Agenda(%s)*" org-keys))))
2571 (put 'org-agenda-redo-command 'org-lprops lprops)
2572 (cond
2573 ((eq type 'agenda)
2574 (org-let lprops '(org-agenda-list current-prefix-arg)))
2575 ((eq type 'alltodo)
2576 (org-let lprops '(org-todo-list current-prefix-arg)))
2577 ((eq type 'search)
2578 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2579 ((eq type 'stuck)
2580 (org-let lprops '(org-agenda-list-stuck-projects
2581 current-prefix-arg)))
2582 ((eq type 'tags)
2583 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2584 ((eq type 'tags-todo)
2585 (org-let lprops '(org-tags-view '(4) org-match)))
2586 ((eq type 'todo)
2587 (org-let lprops '(org-todo-list org-match)))
2588 ((eq type 'tags-tree)
2589 (org-check-for-org-mode)
2590 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2591 ((eq type 'todo-tree)
2592 (org-check-for-org-mode)
2593 (org-let lprops
2594 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2595 (regexp-quote org-match) "\\>"))))
2596 ((eq type 'occur-tree)
2597 (org-check-for-org-mode)
2598 (org-let lprops '(org-occur org-match)))
2599 ((functionp type)
2600 (org-let lprops '(funcall type org-match)))
2601 ((fboundp type)
2602 (org-let lprops '(funcall type org-match)))
2603 (t (error "Invalid custom agenda command type %s" type))))
2604 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2605 ((equal org-keys "C")
2606 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2607 (customize-variable 'org-agenda-custom-commands))
2608 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2609 ((equal org-keys "s") (call-interactively 'org-search-view))
2610 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2611 ((equal org-keys "t") (call-interactively 'org-todo-list))
2612 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2613 ((equal org-keys "m") (call-interactively 'org-tags-view))
2614 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2615 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2616 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2617 (org-add-hook
2618 'post-command-hook
2619 (lambda ()
2620 (unless (current-message)
2621 (let* ((m (org-agenda-get-any-marker))
2622 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2623 (when note
2624 (message (concat
2625 "FLAGGING-NOTE ([?] for more info): "
2626 (org-add-props
2627 (replace-regexp-in-string
2628 "\\\\n" "//"
2629 (copy-sequence note))
2630 nil 'face 'org-warning)))))))
2631 t t))
2632 ((equal org-keys "L")
2633 (unless (derived-mode-p 'org-mode)
2634 (error "This is not an Org-mode file"))
2635 (unless restriction
2636 (put 'org-agenda-files 'org-restrict (list bfn))
2637 (org-call-with-arg 'org-timeline arg)))
2638 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2639 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2640 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2641 (t (error "Invalid agenda key"))))))
2643 (autoload 'org-agenda "org-agenda" "\
2644 Dispatch agenda commands to collect entries to the agenda buffer.
2645 Prompts for a command to execute. Any prefix arg will be passed
2646 on to the selected command. The default selections are:
2648 a Call `org-agenda-list' to display the agenda for current day or week.
2649 t Call `org-todo-list' to display the global todo list.
2650 T Call `org-todo-list' to display the global todo list, select only
2651 entries with a specific TODO keyword (the user gets a prompt).
2652 m Call `org-tags-view' to display headlines with tags matching
2653 a condition (the user is prompted for the condition).
2654 M Like `m', but select only TODO entries, no ordinary headlines.
2655 L Create a timeline for the current buffer.
2656 e Export views to associated files.
2657 s Search entries for keywords.
2658 S Search entries for keywords, only with TODO keywords.
2659 / Multi occur across all agenda files and also files listed
2660 in `org-agenda-text-search-extra-files'.
2661 < Restrict agenda commands to buffer, subtree, or region.
2662 Press several times to get the desired effect.
2663 > Remove a previous restriction.
2664 # List \"stuck\" projects.
2665 ! Configure what \"stuck\" means.
2666 C Configure custom agenda commands.
2668 More commands can be added by configuring the variable
2669 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2670 searches can be pre-defined in this way.
2672 If the current buffer is in Org-mode and visiting a file, you can also
2673 first press `<' once to indicate that the agenda should be temporarily
2674 \(until the next use of \\[org-agenda]) restricted to the current file.
2675 Pressing `<' twice means to restrict to the current subtree or region
2676 \(if active).
2678 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2680 (defun org-agenda-append-agenda ()
2681 "Append another agenda view to the current one.
2682 This function allows interactive building of block agendas.
2683 Agenda views are separated by `org-agenda-block-separator'."
2684 (interactive)
2685 (unless (derived-mode-p 'org-agenda-mode)
2686 (error "Can only append from within agenda buffer"))
2687 (let ((org-agenda-multi t))
2688 (org-agenda)
2689 (widen)
2690 (org-agenda-finalize)
2691 (org-agenda-fit-window-to-buffer)))
2693 (defun org-agenda-normalize-custom-commands (cmds)
2694 (delq nil
2695 (mapcar
2696 (lambda (x)
2697 (cond ((stringp (cdr x)) nil)
2698 ((stringp (nth 1 x)) x)
2699 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2700 (t (cons (car x) (cons "" (cdr x))))))
2701 cmds)))
2703 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2704 "The user interface for selecting an agenda command."
2705 (catch 'exit
2706 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2707 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2708 (region-p (org-region-active-p))
2709 (custom org-agenda-custom-commands)
2710 (selstring "")
2711 restriction second-time
2712 c entry key type match prefixes rmheader header-end custom1 desc
2713 line lines left right n n1)
2714 (save-window-excursion
2715 (delete-other-windows)
2716 (org-switch-to-buffer-other-window " *Agenda Commands*")
2717 (erase-buffer)
2718 (insert (eval-when-compile
2719 (let ((header
2720 "Press key for an agenda command: < Buffer, subtree/region restriction
2721 -------------------------------- > Remove restriction
2722 a Agenda for current week or day e Export agenda views
2723 t List of all TODO entries T Entries with special TODO kwd
2724 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2725 s Search for keywords S Like s, but only TODO entries
2726 L Timeline for current buffer # List stuck projects (!=configure)
2727 / Multi-occur C Configure custom agenda commands
2728 ? Find :FLAGGED: entries * Toggle sticky agenda views
2730 (start 0))
2731 (while (string-match
2732 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2733 header start)
2734 (setq start (match-end 0))
2735 (add-text-properties (match-beginning 2) (match-end 2)
2736 '(face bold) header))
2737 header)))
2738 (setq header-end (point-marker))
2739 (while t
2740 (setq custom1 custom)
2741 (when (eq rmheader t)
2742 (org-goto-line 1)
2743 (re-search-forward ":" nil t)
2744 (delete-region (match-end 0) (point-at-eol))
2745 (forward-char 1)
2746 (looking-at "-+")
2747 (delete-region (match-end 0) (point-at-eol))
2748 (move-marker header-end (match-end 0)))
2749 (goto-char header-end)
2750 (delete-region (point) (point-max))
2752 ;; Produce all the lines that describe custom commands and prefixes
2753 (setq lines nil)
2754 (while (setq entry (pop custom1))
2755 (setq key (car entry) desc (nth 1 entry)
2756 type (nth 2 entry)
2757 match (nth 3 entry))
2758 (if (> (length key) 1)
2759 (add-to-list 'prefixes (string-to-char key))
2760 (setq line
2761 (format
2762 "%-4s%-14s"
2763 (org-add-props (copy-sequence key)
2764 '(face bold))
2765 (cond
2766 ((string-match "\\S-" desc) desc)
2767 ((eq type 'agenda) "Agenda for current week or day")
2768 ((eq type 'alltodo) "List of all TODO entries")
2769 ((eq type 'search) "Word search")
2770 ((eq type 'stuck) "List of stuck projects")
2771 ((eq type 'todo) "TODO keyword")
2772 ((eq type 'tags) "Tags query")
2773 ((eq type 'tags-todo) "Tags (TODO)")
2774 ((eq type 'tags-tree) "Tags tree")
2775 ((eq type 'todo-tree) "TODO kwd tree")
2776 ((eq type 'occur-tree) "Occur tree")
2777 ((functionp type) (if (symbolp type)
2778 (symbol-name type)
2779 "Lambda expression"))
2780 (t "???"))))
2781 (if org-agenda-menu-show-matcher
2782 (setq line
2783 (concat line ": "
2784 (cond
2785 ((stringp match)
2786 (setq match (copy-sequence match))
2787 (org-add-props match nil 'face 'org-warning))
2788 ((listp type)
2789 (format "set of %d commands" (length type))))))
2790 (if (org-string-nw-p match)
2791 (add-text-properties
2792 0 (length line) (list 'help-echo
2793 (concat "Matcher: " match)) line)))
2794 (push line lines)))
2795 (setq lines (nreverse lines))
2796 (when prefixes
2797 (mapc (lambda (x)
2798 (push
2799 (format "%s %s"
2800 (org-add-props (char-to-string x)
2801 nil 'face 'bold)
2802 (or (cdr (assoc (concat selstring
2803 (char-to-string x))
2804 prefix-descriptions))
2805 "Prefix key"))
2806 lines))
2807 prefixes))
2809 ;; Check if we should display in two columns
2810 (if org-agenda-menu-two-columns
2811 (progn
2812 (setq n (length lines)
2813 n1 (+ (/ n 2) (mod n 2))
2814 right (nthcdr n1 lines)
2815 left (copy-sequence lines))
2816 (setcdr (nthcdr (1- n1) left) nil))
2817 (setq left lines right nil))
2818 (while left
2819 (insert "\n" (pop left))
2820 (when right
2821 (if (< (current-column) 40)
2822 (move-to-column 40 t)
2823 (insert " "))
2824 (insert (pop right))))
2826 ;; Make the window the right size
2827 (goto-char (point-min))
2828 (if second-time
2829 (if (not (pos-visible-in-window-p (point-max)))
2830 (org-fit-window-to-buffer))
2831 (setq second-time t)
2832 (org-fit-window-to-buffer))
2834 ;; Ask for selection
2835 (message "Press key for agenda command%s:"
2836 (if (or restrict-ok org-agenda-overriding-restriction)
2837 (if org-agenda-overriding-restriction
2838 " (restriction lock active)"
2839 (if restriction
2840 (format " (restricted to %s)" restriction)
2841 " (unrestricted)"))
2842 ""))
2843 (setq c (read-char-exclusive))
2844 (message "")
2845 (cond
2846 ((assoc (char-to-string c) custom)
2847 (setq selstring (concat selstring (char-to-string c)))
2848 (throw 'exit (cons selstring restriction)))
2849 ((memq c prefixes)
2850 (setq selstring (concat selstring (char-to-string c))
2851 prefixes nil
2852 rmheader (or rmheader t)
2853 custom (delq nil (mapcar
2854 (lambda (x)
2855 (if (or (= (length (car x)) 1)
2856 (/= (string-to-char (car x)) c))
2858 (cons (substring (car x) 1) (cdr x))))
2859 custom))))
2860 ((eq c ?*)
2861 (call-interactively 'org-toggle-sticky-agenda)
2862 (sit-for 2))
2863 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2864 (message "Restriction is only possible in Org-mode buffers")
2865 (ding) (sit-for 1))
2866 ((eq c ?1)
2867 (org-agenda-remove-restriction-lock 'noupdate)
2868 (setq restriction 'buffer))
2869 ((eq c ?0)
2870 (org-agenda-remove-restriction-lock 'noupdate)
2871 (setq restriction (if region-p 'region 'subtree)))
2872 ((eq c ?<)
2873 (org-agenda-remove-restriction-lock 'noupdate)
2874 (setq restriction
2875 (cond
2876 ((eq restriction 'buffer)
2877 (if region-p 'region 'subtree))
2878 ((memq restriction '(subtree region))
2879 nil)
2880 (t 'buffer))))
2881 ((eq c ?>)
2882 (org-agenda-remove-restriction-lock 'noupdate)
2883 (setq restriction nil))
2884 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2885 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2886 ((and (> (length selstring) 0) (eq c ?\d))
2887 (delete-window)
2888 (org-agenda-get-restriction-and-command prefix-descriptions))
2890 ((equal c ?q) (error "Abort"))
2891 (t (error "Invalid key %c" c))))))))
2893 (defun org-agenda-fit-window-to-buffer ()
2894 "Fit the window to the buffer size."
2895 (and (memq org-agenda-window-setup '(reorganize-frame))
2896 (fboundp 'fit-window-to-buffer)
2897 (org-fit-window-to-buffer
2899 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2900 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2902 (defvar org-cmd nil)
2903 (defvar org-agenda-overriding-cmd nil)
2904 (defvar org-agenda-overriding-arguments nil)
2905 (defvar org-agenda-overriding-cmd-arguments nil)
2906 (defun org-agenda-run-series (name series)
2907 (org-let (nth 1 series) '(org-agenda-prepare name))
2908 ;; We need to reset agenda markers here, because when constructing a
2909 ;; block agenda, the individual blocks do not do that.
2910 (org-agenda-reset-markers)
2911 (let* ((org-agenda-multi t)
2912 (redo (list 'org-agenda-run-series name (list 'quote series)))
2913 (cmds (car series))
2914 (gprops (nth 1 series))
2915 match ;; The byte compiler incorrectly complains about this. Keep it!
2916 org-cmd type lprops)
2917 (while (setq org-cmd (pop cmds))
2918 (setq type (car org-cmd)
2919 match (eval (nth 1 org-cmd))
2920 lprops (nth 2 org-cmd))
2921 (let ((org-agenda-overriding-arguments
2922 (if (eq org-agenda-overriding-cmd org-cmd)
2923 (or org-agenda-overriding-arguments
2924 org-agenda-overriding-cmd-arguments))))
2925 (cond
2926 ((eq type 'agenda)
2927 (org-let2 gprops lprops
2928 '(call-interactively 'org-agenda-list)))
2929 ((eq type 'alltodo)
2930 (org-let2 gprops lprops
2931 '(call-interactively 'org-todo-list)))
2932 ((eq type 'search)
2933 (org-let2 gprops lprops
2934 '(org-search-view current-prefix-arg match nil)))
2935 ((eq type 'stuck)
2936 (org-let2 gprops lprops
2937 '(call-interactively 'org-agenda-list-stuck-projects)))
2938 ((eq type 'tags)
2939 (org-let2 gprops lprops
2940 '(org-tags-view current-prefix-arg match)))
2941 ((eq type 'tags-todo)
2942 (org-let2 gprops lprops
2943 '(org-tags-view '(4) match)))
2944 ((eq type 'todo)
2945 (org-let2 gprops lprops
2946 '(org-todo-list match)))
2947 ((fboundp type)
2948 (org-let2 gprops lprops
2949 '(funcall type match)))
2950 (t (error "Invalid type in command series")))))
2951 (widen)
2952 (let ((inhibit-read-only t))
2953 (add-text-properties (point-min) (point-max)
2954 `(org-series t org-series-redo-cmd ,redo)))
2955 (setq org-agenda-redo-command redo)
2956 (goto-char (point-min)))
2957 (org-agenda-fit-window-to-buffer)
2958 (org-let (nth 1 series) '(org-agenda-finalize)))
2960 ;;;###autoload
2961 (defmacro org-batch-agenda (cmd-key &rest parameters)
2962 "Run an agenda command in batch mode and send the result to STDOUT.
2963 If CMD-KEY is a string of length 1, it is used as a key in
2964 `org-agenda-custom-commands' and triggers this command. If it is a
2965 longer string it is used as a tags/todo match string.
2966 Parameters are alternating variable names and values that will be bound
2967 before running the agenda command."
2968 (org-eval-in-environment (org-make-parameter-alist parameters)
2969 (if (> (length cmd-key) 2)
2970 (org-tags-view nil cmd-key)
2971 (org-agenda nil cmd-key)))
2972 (set-buffer org-agenda-buffer-name)
2973 (princ (buffer-string)))
2975 (autoload 'org-batch-agenda "org-agenda" "\
2976 Run an agenda command in batch mode and send the result to STDOUT.
2977 If CMD-KEY is a string of length 1, it is used as a key in
2978 `org-agenda-custom-commands' and triggers this command. If it is a
2979 longer string it is used as a tags/todo match string.
2980 Parameters are alternating variable names and values that will be bound
2981 before running the agenda command.
2983 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2984 (def-edebug-spec org-batch-agenda (form &rest sexp))
2986 (defvar org-agenda-info nil)
2988 ;;;###autoload
2989 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2990 "Run an agenda command in batch mode and send the result to STDOUT.
2991 If CMD-KEY is a string of length 1, it is used as a key in
2992 `org-agenda-custom-commands' and triggers this command. If it is a
2993 longer string it is used as a tags/todo match string.
2994 Parameters are alternating variable names and values that will be bound
2995 before running the agenda command.
2997 The output gives a line for each selected agenda item. Each
2998 item is a list of comma-separated values, like this:
3000 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3002 category The category of the item
3003 head The headline, without TODO kwd, TAGS and PRIORITY
3004 type The type of the agenda entry, can be
3005 todo selected in TODO match
3006 tagsmatch selected in tags match
3007 diary imported from diary
3008 deadline a deadline on given date
3009 scheduled scheduled on given date
3010 timestamp entry has timestamp on given date
3011 closed entry was closed on given date
3012 upcoming-deadline warning about deadline
3013 past-scheduled forwarded scheduled item
3014 block entry has date block including g. date
3015 todo The todo keyword, if any
3016 tags All tags including inherited ones, separated by colons
3017 date The relevant date, like 2007-2-14
3018 time The time, like 15:00-16:50
3019 extra Sting with extra planning info
3020 priority-l The priority letter if any was given
3021 priority-n The computed numerical priority
3022 agenda-day The day in the agenda where this is listed"
3023 (org-eval-in-environment (append '((org-agenda-remove-tags t))
3024 (org-make-parameter-alist parameters))
3025 (if (> (length cmd-key) 2)
3026 (org-tags-view nil cmd-key)
3027 (org-agenda nil cmd-key)))
3028 (set-buffer org-agenda-buffer-name)
3029 (let* ((lines (org-split-string (buffer-string) "\n"))
3030 line)
3031 (while (setq line (pop lines))
3032 (catch 'next
3033 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
3034 (setq org-agenda-info
3035 (org-fix-agenda-info (text-properties-at 0 line)))
3036 (princ
3037 (mapconcat 'org-agenda-export-csv-mapper
3038 '(org-category txt type todo tags date time extra
3039 priority-letter priority agenda-day)
3040 ","))
3041 (princ "\n")))))
3043 (autoload 'org-batch-agenda-csv "org-agenda" "\
3044 Run an agenda command in batch mode and send the result to STDOUT.
3045 If CMD-KEY is a string of length 1, it is used as a key in
3046 `org-agenda-custom-commands' and triggers this command. If it is a
3047 longer string it is used as a tags/todo match string.
3048 Parameters are alternating variable names and values that will be bound
3049 before running the agenda command.
3051 The output gives a line for each selected agenda item. Each
3052 item is a list of comma-separated values, like this:
3054 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3056 category The category of the item
3057 head The headline, without TODO kwd, TAGS and PRIORITY
3058 type The type of the agenda entry, can be
3059 todo selected in TODO match
3060 tagsmatch selected in tags match
3061 diary imported from diary
3062 deadline a deadline on given date
3063 scheduled scheduled on given date
3064 timestamp entry has timestamp on given date
3065 closed entry was closed on given date
3066 upcoming-deadline warning about deadline
3067 past-scheduled forwarded scheduled item
3068 block entry has date block including g. date
3069 todo The todo keyword, if any
3070 tags All tags including inherited ones, separated by colons
3071 date The relevant date, like 2007-2-14
3072 time The time, like 15:00-16:50
3073 extra Sting with extra planning info
3074 priority-l The priority letter if any was given
3075 priority-n The computed numerical priority
3076 agenda-day The day in the agenda where this is listed
3078 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3079 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3081 (defun org-fix-agenda-info (props)
3082 "Make sure all properties on an agenda item have a canonical form.
3083 This ensures the export commands can easily use it."
3084 (let (tmp re)
3085 (when (setq tmp (plist-get props 'tags))
3086 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3087 (when (setq tmp (plist-get props 'date))
3088 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3089 (let ((calendar-date-display-form '(year "-" month "-" day)))
3090 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3092 (setq tmp (calendar-date-string tmp)))
3093 (setq props (plist-put props 'date tmp)))
3094 (when (setq tmp (plist-get props 'day))
3095 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3096 (let ((calendar-date-display-form '(year "-" month "-" day)))
3097 (setq tmp (calendar-date-string tmp)))
3098 (setq props (plist-put props 'day tmp))
3099 (setq props (plist-put props 'agenda-day tmp)))
3100 (when (setq tmp (plist-get props 'txt))
3101 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3102 (plist-put props 'priority-letter (match-string 1 tmp))
3103 (setq tmp (replace-match "" t t tmp)))
3104 (when (and (setq re (plist-get props 'org-todo-regexp))
3105 (setq re (concat "\\`\\.*" re " ?"))
3106 (string-match re tmp))
3107 (plist-put props 'todo (match-string 1 tmp))
3108 (setq tmp (replace-match "" t t tmp)))
3109 (plist-put props 'txt tmp)))
3110 props)
3112 (defun org-agenda-export-csv-mapper (prop)
3113 (let ((res (plist-get org-agenda-info prop)))
3114 (setq res
3115 (cond
3116 ((not res) "")
3117 ((stringp res) res)
3118 (t (prin1-to-string res))))
3119 (while (string-match "," res)
3120 (setq res (replace-match ";" t t res)))
3121 (org-trim res)))
3123 ;;;###autoload
3124 (defun org-store-agenda-views (&rest parameters)
3125 (interactive)
3126 (eval (list 'org-batch-store-agenda-views)))
3128 (autoload 'org-store-agenda-views "org-agenda" "\
3131 \(fn &rest PARAMETERS)" t nil)
3133 ;;;###autoload
3134 (defmacro org-batch-store-agenda-views (&rest parameters)
3135 "Run all custom agenda commands that have a file argument."
3136 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3137 (pop-up-frames nil)
3138 (dir default-directory)
3139 (pars (org-make-parameter-alist parameters))
3140 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3141 (save-window-excursion
3142 (while cmds
3143 (setq cmd (pop cmds)
3144 thiscmdkey (car cmd)
3145 thiscmdcmd (cdr cmd)
3146 match (nth 2 thiscmdcmd)
3147 bufname (if org-agenda-sticky
3148 (or (and (stringp match)
3149 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3150 (format "*Org Agenda(%s)*" thiscmdkey))
3151 org-agenda-buffer-name)
3152 cmd-or-set (nth 2 cmd)
3153 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3154 files (nth (if (listp cmd-or-set) 4 5) cmd))
3155 (if (stringp files) (setq files (list files)))
3156 (when files
3157 (org-eval-in-environment (append org-agenda-exporter-settings
3158 opts pars)
3159 (org-agenda nil thiscmdkey))
3160 (set-buffer bufname)
3161 (while files
3162 (org-eval-in-environment (append org-agenda-exporter-settings
3163 opts pars)
3164 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3165 (and (get-buffer bufname)
3166 (kill-buffer bufname)))))))
3168 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3169 Run all custom agenda commands that have a file argument.
3171 \(fn &rest PARAMETERS)" nil t)
3172 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3174 (defvar org-agenda-current-span nil
3175 "The current span used in the agenda view.") ; local variable in the agenda buffer
3176 (defun org-agenda-mark-header-line (pos)
3177 "Mark the line at POS as an agenda structure header."
3178 (save-excursion
3179 (goto-char pos)
3180 (put-text-property (point-at-bol) (point-at-eol)
3181 'org-agenda-structural-header t)
3182 (when org-agenda-title-append
3183 (put-text-property (point-at-bol) (point-at-eol)
3184 'org-agenda-title-append org-agenda-title-append))))
3186 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3187 (defvar org-agenda-write-buffer-name "Agenda View")
3188 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3189 "Write the current buffer (an agenda view) as a file.
3190 Depending on the extension of the file name, plain text (.txt),
3191 HTML (.html or .htm) or Postscript (.ps) is produced.
3192 If the extension is .ics, run icalendar export over all files used
3193 to construct the agenda and limit the export to entries listed in the
3194 agenda now.
3195 With prefix argument OPEN, open the new file immediately.
3196 If NOSETTINGS is given, do not scope the settings of
3197 `org-agenda-exporter-settings' into the export commands. This is used when
3198 the settings have already been scoped and we do not wish to overrule other,
3199 higher priority settings.
3200 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3201 (interactive "FWrite agenda to file: \nP")
3202 (if (not (file-writable-p file))
3203 (error "Cannot write agenda to file %s" file))
3204 (org-let (if nosettings nil org-agenda-exporter-settings)
3205 '(save-excursion
3206 (save-window-excursion
3207 (org-agenda-mark-filtered-text)
3208 (let ((bs (copy-sequence (buffer-string))) beg)
3209 (org-agenda-unmark-filtered-text)
3210 (with-temp-buffer
3211 (rename-buffer org-agenda-write-buffer-name t)
3212 (set-buffer-modified-p nil)
3213 (insert bs)
3214 (org-agenda-remove-marked-text 'org-filtered)
3215 (while (setq beg (text-property-any (point-min) (point-max)
3216 'org-filtered t))
3217 (delete-region
3218 beg (or (next-single-property-change beg 'org-filtered)
3219 (point-max))))
3220 (run-hooks 'org-agenda-before-write-hook)
3221 (cond
3222 ((org-bound-and-true-p org-mobile-creating-agendas)
3223 (org-mobile-write-agenda-for-mobile file))
3224 ((string-match "\\.html?\\'" file)
3225 (require 'htmlize)
3226 (set-buffer (htmlize-buffer (current-buffer)))
3227 (when org-agenda-export-html-style
3228 ;; replace <style> section with org-agenda-export-html-style
3229 (goto-char (point-min))
3230 (kill-region (- (search-forward "<style") 6)
3231 (search-forward "</style>"))
3232 (insert org-agenda-export-html-style))
3233 (write-file file)
3234 (kill-buffer (current-buffer))
3235 (message "HTML written to %s" file))
3236 ((string-match "\\.ps\\'" file)
3237 (require 'ps-print)
3238 (ps-print-buffer-with-faces file)
3239 (message "Postscript written to %s" file))
3240 ((string-match "\\.pdf\\'" file)
3241 (require 'ps-print)
3242 (ps-print-buffer-with-faces
3243 (concat (file-name-sans-extension file) ".ps"))
3244 (call-process "ps2pdf" nil nil nil
3245 (expand-file-name
3246 (concat (file-name-sans-extension file) ".ps"))
3247 (expand-file-name file))
3248 (delete-file (concat (file-name-sans-extension file) ".ps"))
3249 (message "PDF written to %s" file))
3250 ((string-match "\\.ics\\'" file)
3251 (require 'org-icalendar)
3252 (let ((org-agenda-marker-table
3253 (org-create-marker-find-array
3254 (org-agenda-collect-markers)))
3255 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3256 (org-combined-agenda-icalendar-file file))
3257 (apply 'org-export-icalendar 'combine
3258 (org-agenda-files nil 'ifmode))))
3260 (let ((bs (buffer-string)))
3261 (find-file file)
3262 (erase-buffer)
3263 (insert bs)
3264 (save-buffer 0)
3265 (kill-buffer (current-buffer))
3266 (message "Plain text written to %s" file))))))))
3267 (set-buffer (or agenda-bufname
3268 (and (org-called-interactively-p 'any) (buffer-name))
3269 org-agenda-buffer-name)))
3270 (when open (org-open-file file)))
3272 (defvar org-agenda-tag-filter-overlays nil)
3273 (defvar org-agenda-cat-filter-overlays nil)
3275 (defun org-agenda-mark-filtered-text ()
3276 "Mark all text hidden by filtering with a text property."
3277 (let ((inhibit-read-only t))
3278 (mapc
3279 (lambda (o)
3280 (when (equal (overlay-buffer o) (current-buffer))
3281 (put-text-property
3282 (overlay-start o) (overlay-end o)
3283 'org-filtered t)))
3284 (append org-agenda-tag-filter-overlays
3285 org-agenda-cat-filter-overlays))))
3287 (defun org-agenda-unmark-filtered-text ()
3288 "Remove the filtering text property."
3289 (let ((inhibit-read-only t))
3290 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3292 (defun org-agenda-remove-marked-text (property &optional value)
3293 "Delete all text marked with VALUE of PROPERTY.
3294 VALUE defaults to t."
3295 (let (beg)
3296 (setq value (or value t))
3297 (while (setq beg (text-property-any (point-min) (point-max)
3298 property value))
3299 (delete-region
3300 beg (or (next-single-property-change beg 'org-filtered)
3301 (point-max))))))
3303 (defun org-agenda-add-entry-text ()
3304 "Add entry text to agenda lines.
3305 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3306 entry text following headings shown in the agenda.
3307 Drawers will be excluded, also the line with scheduling/deadline info."
3308 (when (and (> org-agenda-add-entry-text-maxlines 0)
3309 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3310 (let (m txt)
3311 (goto-char (point-min))
3312 (while (not (eobp))
3313 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3314 (beginning-of-line 2)
3315 (setq txt (org-agenda-get-some-entry-text
3316 m org-agenda-add-entry-text-maxlines " > "))
3317 (end-of-line 1)
3318 (if (string-match "\\S-" txt)
3319 (insert "\n" txt)
3320 (or (eobp) (forward-char 1))))))))
3322 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3323 &rest keep)
3324 "Extract entry text from MARKER, at most N-LINES lines.
3325 This will ignore drawers etc, just get the text.
3326 If INDENT is given, prefix every line with this string. If KEEP is
3327 given, it is a list of symbols, defining stuff that should not be
3328 removed from the entry content. Currently only `planning' is allowed here."
3329 (let (txt drawer-re kwd-time-re ind)
3330 (save-excursion
3331 (with-current-buffer (marker-buffer marker)
3332 (if (not (derived-mode-p 'org-mode))
3333 (setq txt "")
3334 (save-excursion
3335 (save-restriction
3336 (widen)
3337 (goto-char marker)
3338 (end-of-line 1)
3339 (setq txt (buffer-substring
3340 (min (1+ (point)) (point-max))
3341 (progn (outline-next-heading) (point)))
3342 drawer-re org-drawer-regexp
3343 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3344 ".*\n?"))
3345 (with-temp-buffer
3346 (insert txt)
3347 (when org-agenda-add-entry-text-descriptive-links
3348 (goto-char (point-min))
3349 (while (org-activate-bracket-links (point-max))
3350 (add-text-properties (match-beginning 0) (match-end 0)
3351 '(face org-link))))
3352 (goto-char (point-min))
3353 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3354 (set-text-properties (match-beginning 0) (match-end 0)
3355 nil))
3356 (goto-char (point-min))
3357 (while (re-search-forward drawer-re nil t)
3358 (delete-region
3359 (match-beginning 0)
3360 (progn (re-search-forward
3361 "^[ \t]*:END:.*\n?" nil 'move)
3362 (point))))
3363 (unless (member 'planning keep)
3364 (goto-char (point-min))
3365 (while (re-search-forward kwd-time-re nil t)
3366 (replace-match "")))
3367 (goto-char (point-min))
3368 (when org-agenda-entry-text-exclude-regexps
3369 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3370 (while (setq re (pop re-list))
3371 (goto-char (point-min))
3372 (while (re-search-forward re nil t)
3373 (replace-match "")))))
3374 (goto-char (point-max))
3375 (skip-chars-backward " \t\n")
3376 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3378 ;; find and remove min common indentation
3379 (goto-char (point-min))
3380 (untabify (point-min) (point-max))
3381 (setq ind (org-get-indentation))
3382 (while (not (eobp))
3383 (unless (looking-at "[ \t]*$")
3384 (setq ind (min ind (org-get-indentation))))
3385 (beginning-of-line 2))
3386 (goto-char (point-min))
3387 (while (not (eobp))
3388 (unless (looking-at "[ \t]*$")
3389 (move-to-column ind)
3390 (delete-region (point-at-bol) (point)))
3391 (beginning-of-line 2))
3393 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3395 (goto-char (point-min))
3396 (when indent
3397 (while (and (not (eobp)) (re-search-forward "^" nil t))
3398 (replace-match indent t t)))
3399 (goto-char (point-min))
3400 (while (looking-at "[ \t]*\n") (replace-match ""))
3401 (goto-char (point-max))
3402 (when (> (org-current-line)
3403 n-lines)
3404 (org-goto-line (1+ n-lines))
3405 (backward-char 1))
3406 (setq txt (buffer-substring (point-min) (point)))))))))
3407 txt))
3409 (defun org-agenda-collect-markers ()
3410 "Collect the markers pointing to entries in the agenda buffer."
3411 (let (m markers)
3412 (save-excursion
3413 (goto-char (point-min))
3414 (while (not (eobp))
3415 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3416 (org-get-at-bol 'org-marker)))
3417 (push m markers))
3418 (beginning-of-line 2)))
3419 (nreverse markers)))
3421 (defun org-create-marker-find-array (marker-list)
3422 "Create a alist of files names with all marker positions in that file."
3423 (let (f tbl m a p)
3424 (while (setq m (pop marker-list))
3425 (setq p (marker-position m)
3426 f (buffer-file-name (or (buffer-base-buffer
3427 (marker-buffer m))
3428 (marker-buffer m))))
3429 (if (setq a (assoc f tbl))
3430 (push (marker-position m) (cdr a))
3431 (push (list f p) tbl)))
3432 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3433 tbl)))
3435 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3436 (defun org-check-agenda-marker-table ()
3437 "Check of the current entry is on the marker list."
3438 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3440 (and (setq a (assoc file org-agenda-marker-table))
3441 (save-match-data
3442 (save-excursion
3443 (org-back-to-heading t)
3444 (member (point) (cdr a)))))))
3446 (defun org-check-for-org-mode ()
3447 "Make sure current buffer is in org-mode. Error if not."
3448 (or (derived-mode-p 'org-mode)
3449 (error "Cannot execute org-mode agenda command on buffer in %s"
3450 major-mode)))
3452 ;;; Agenda prepare and finalize
3454 (defvar org-agenda-multi nil) ; dynamically scoped
3455 (defvar org-agenda-pre-window-conf nil)
3456 (defvar org-agenda-columns-active nil)
3457 (defvar org-agenda-name nil)
3458 (defvar org-agenda-tag-filter nil)
3459 (defvar org-agenda-category-filter nil)
3460 (defvar org-agenda-top-category-filter nil)
3461 (defvar org-agenda-tag-filter-while-redo nil)
3462 (defvar org-agenda-tag-filter-preset nil
3463 "A preset of the tags filter used for secondary agenda filtering.
3464 This must be a list of strings, each string must be a single tag preceded
3465 by \"+\" or \"-\".
3466 This variable should not be set directly, but agenda custom commands can
3467 bind it in the options section. The preset filter is a global property of
3468 the entire agenda view. In a block agenda, it will not work reliably to
3469 define a filter for one of the individual blocks. You need to set it in
3470 the global options and expect it to be applied to the entire view.")
3472 (defvar org-agenda-category-filter-preset nil
3473 "A preset of the category filter used for secondary agenda filtering.
3474 This must be a list of strings, each string must be a single category
3475 preceded by \"+\" or \"-\".
3476 This variable should not be set directly, but agenda custom commands can
3477 bind it in the options section. The preset filter is a global property of
3478 the entire agenda view. In a block agenda, it will not work reliably to
3479 define a filter for one of the individual blocks. You need to set it in
3480 the global options and expect it to be applied to the entire view.")
3483 (defun org-agenda-use-sticky-p ()
3484 "Return non-nil if an agenda buffer named
3485 `org-agenda-buffer-name' exists and should be shown instead of
3486 generating a new one."
3487 (and
3488 ;; turned off by user
3489 org-agenda-sticky
3490 ;; For multi-agenda buffer already exists
3491 (not org-agenda-multi)
3492 ;; buffer found
3493 (get-buffer org-agenda-buffer-name)
3494 ;; C-u parameter is same as last call
3495 (with-current-buffer (get-buffer org-agenda-buffer-name)
3496 (and
3497 (equal current-prefix-arg
3498 org-agenda-last-prefix-arg)
3499 ;; In case user turned stickiness on, while having existing
3500 ;; Agenda buffer active, don't reuse that buffer, because it
3501 ;; does not have org variables local
3502 org-agenda-this-buffer-is-sticky))))
3504 (defun org-agenda-prepare-window (abuf)
3505 "Setup agenda buffer in the window."
3506 (let* ((awin (get-buffer-window abuf))
3507 wconf)
3508 (cond
3509 ((equal (current-buffer) abuf) nil)
3510 (awin (select-window awin))
3511 ((not (setq wconf (current-window-configuration))))
3512 ((equal org-agenda-window-setup 'current-window)
3513 (org-pop-to-buffer-same-window abuf))
3514 ((equal org-agenda-window-setup 'other-window)
3515 (org-switch-to-buffer-other-window abuf))
3516 ((equal org-agenda-window-setup 'other-frame)
3517 (switch-to-buffer-other-frame abuf))
3518 ((equal org-agenda-window-setup 'reorganize-frame)
3519 (delete-other-windows)
3520 (org-switch-to-buffer-other-window abuf)))
3521 ;; additional test in case agenda is invoked from within agenda
3522 ;; buffer via elisp link
3523 (unless (equal (current-buffer) abuf)
3524 (org-pop-to-buffer-same-window abuf))
3525 (setq org-agenda-pre-window-conf
3526 (or org-agenda-pre-window-conf wconf))))
3528 (defun org-agenda-prepare (&optional name)
3529 (if (org-agenda-use-sticky-p)
3530 (progn
3531 ;; Popup existing buffer
3532 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3533 (message "Sticky Agenda buffer, use `r' to refresh")
3534 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3535 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3536 (setq org-todo-keywords-for-agenda nil)
3537 (setq org-drawers-for-agenda nil)
3538 (unless org-agenda-persistent-filter
3539 (setq org-agenda-tag-filter nil
3540 org-agenda-category-filter nil))
3541 (put 'org-agenda-tag-filter :preset-filter
3542 org-agenda-tag-filter-preset)
3543 (put 'org-agenda-category-filter :preset-filter
3544 org-agenda-category-filter-preset)
3545 (if org-agenda-multi
3546 (progn
3547 (setq buffer-read-only nil)
3548 (goto-char (point-max))
3549 (unless (or (bobp) org-agenda-compact-blocks
3550 (not org-agenda-block-separator))
3551 (insert "\n"
3552 (if (stringp org-agenda-block-separator)
3553 org-agenda-block-separator
3554 (make-string (window-width) org-agenda-block-separator))
3555 "\n"))
3556 (narrow-to-region (point) (point-max)))
3557 (setq org-done-keywords-for-agenda nil)
3559 ;; Setting any org variables that are in org-agenda-local-vars
3560 ;; list need to be done after the prepare call
3561 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3562 (setq buffer-read-only nil)
3563 (org-agenda-reset-markers)
3564 (let ((inhibit-read-only t)) (erase-buffer))
3565 (org-agenda-mode)
3566 (setq org-agenda-buffer (current-buffer))
3567 (setq org-agenda-contributing-files nil)
3568 (setq org-agenda-columns-active nil)
3569 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3570 (setq org-todo-keywords-for-agenda
3571 (org-uniquify org-todo-keywords-for-agenda))
3572 (setq org-done-keywords-for-agenda
3573 (org-uniquify org-done-keywords-for-agenda))
3574 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3575 (setq org-agenda-last-prefix-arg current-prefix-arg)
3576 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3577 (and name (not org-agenda-name)
3578 (org-set-local 'org-agenda-name name)))
3579 (setq buffer-read-only nil)))
3581 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3582 (defun org-agenda-finalize ()
3583 "Finishing touch for the agenda buffer, called just before displaying it."
3584 (unless org-agenda-multi
3585 (save-excursion
3586 (let ((inhibit-read-only t))
3587 (goto-char (point-min))
3588 (save-excursion
3589 (while (org-activate-bracket-links (point-max))
3590 (add-text-properties (match-beginning 0) (match-end 0)
3591 '(face org-link))))
3592 (save-excursion
3593 (while (org-activate-plain-links (point-max))
3594 (add-text-properties (match-beginning 0) (match-end 0)
3595 '(face org-link))))
3596 (unless (eq org-agenda-remove-tags t)
3597 (org-agenda-align-tags))
3598 (unless org-agenda-with-colors
3599 (remove-text-properties (point-min) (point-max) '(face nil)))
3600 (if (and (boundp 'org-agenda-overriding-columns-format)
3601 org-agenda-overriding-columns-format)
3602 (org-set-local 'org-agenda-overriding-columns-format
3603 org-agenda-overriding-columns-format))
3604 (if (and (boundp 'org-agenda-view-columns-initially)
3605 org-agenda-view-columns-initially)
3606 (org-agenda-columns))
3607 (when org-agenda-fontify-priorities
3608 (org-agenda-fontify-priorities))
3609 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3610 (org-agenda-dim-blocked-tasks))
3611 ;; We need to widen when `org-agenda-finalize' is called from
3612 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3613 (when org-clock-current-task
3614 (save-restriction
3615 (widen)
3616 (org-agenda-mark-clocking-task)))
3617 (when org-agenda-entry-text-mode
3618 (org-agenda-entry-text-hide)
3619 (org-agenda-entry-text-show))
3620 (if (and (functionp 'org-habit-insert-consistency-graphs)
3621 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3622 (org-habit-insert-consistency-graphs))
3623 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3624 (unless (or (eq org-agenda-show-inherited-tags 'always)
3625 (and (listp org-agenda-show-inherited-tags)
3626 (memq org-agenda-type org-agenda-show-inherited-tags))
3627 (and (eq org-agenda-show-inherited-tags t)
3628 (or (eq org-agenda-use-tag-inheritance t)
3629 (and (listp org-agenda-use-tag-inheritance)
3630 (not (memq org-agenda-type
3631 org-agenda-use-tag-inheritance))))))
3632 (let (mrk)
3633 (save-excursion
3634 (goto-char (point-min))
3635 (while (equal (forward-line) 0)
3636 (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
3637 (get-text-property (point) 'org-hd-marker)))
3638 (put-text-property (point-at-bol) (point-at-eol)
3639 'tags (org-with-point-at mrk
3640 (delete-dups
3641 (mapcar 'downcase (org-get-tags-at))))))))))
3642 (run-hooks 'org-agenda-finalize-hook)
3643 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3644 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3645 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3646 (org-agenda-filter-apply org-agenda-category-filter 'category))
3647 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
3649 (defun org-agenda-mark-clocking-task ()
3650 "Mark the current clock entry in the agenda if it is present."
3651 (mapc (lambda (o)
3652 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3653 (delete-overlay o)))
3654 (overlays-in (point-min) (point-max)))
3655 (when (marker-buffer org-clock-hd-marker)
3656 (save-excursion
3657 (goto-char (point-min))
3658 (let (s ov)
3659 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3660 (goto-char s)
3661 (when (equal (org-get-at-bol 'org-hd-marker)
3662 org-clock-hd-marker)
3663 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3664 (overlay-put ov 'type 'org-agenda-clocking)
3665 (overlay-put ov 'face 'org-agenda-clocking)
3666 (overlay-put ov 'help-echo
3667 "The clock is running in this item")))))))
3669 (defun org-agenda-fontify-priorities ()
3670 "Make highest priority lines bold, and lowest italic."
3671 (interactive)
3672 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3673 (delete-overlay o)))
3674 (overlays-in (point-min) (point-max)))
3675 (save-excursion
3676 (let ((inhibit-read-only t)
3677 b e p ov h l)
3678 (goto-char (point-min))
3679 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3680 (setq h (or (get-char-property (point) 'org-highest-priority)
3681 org-highest-priority)
3682 l (or (get-char-property (point) 'org-lowest-priority)
3683 org-lowest-priority)
3684 p (string-to-char (match-string 1))
3685 b (match-beginning 0)
3686 e (if (eq org-agenda-fontify-priorities 'cookies)
3687 (match-end 0)
3688 (point-at-eol))
3689 ov (make-overlay b e))
3690 (overlay-put
3691 ov 'face
3692 (cond ((org-face-from-face-or-color
3693 'priority nil
3694 (cdr (assoc p org-priority-faces))))
3695 ((and (listp org-agenda-fontify-priorities)
3696 (org-face-from-face-or-color
3697 'priority nil
3698 (cdr (assoc p org-agenda-fontify-priorities)))))
3699 ((equal p l) 'italic)
3700 ((equal p h) 'bold)))
3701 (overlay-put ov 'org-type 'org-priority)))))
3703 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3704 (interactive "P")
3705 "Dim currently blocked TODO's in the agenda display."
3706 (message "Dim or hide blocked tasks...")
3707 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3708 (delete-overlay o)))
3709 (overlays-in (point-min) (point-max)))
3710 (save-excursion
3711 (let ((inhibit-read-only t)
3712 (org-depend-tag-blocked nil)
3713 (invis (or (not (null invisible))
3714 (eq org-agenda-dim-blocked-tasks 'invisible)))
3715 org-blocked-by-checkboxes
3716 invis1 b e p ov h l)
3717 (goto-char (point-min))
3718 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3719 (and pos (goto-char (1+ pos))))
3720 (setq org-blocked-by-checkboxes nil invis1 invis)
3721 (let ((marker (org-get-at-bol 'org-hd-marker)))
3722 (when (and marker
3723 (with-current-buffer (marker-buffer marker)
3724 (save-excursion (goto-char marker)
3725 (org-entry-blocked-p))))
3726 (if org-blocked-by-checkboxes (setq invis1 nil))
3727 (setq b (if invis1
3728 (max (point-min) (1- (point-at-bol)))
3729 (point-at-bol))
3730 e (point-at-eol)
3731 ov (make-overlay b e))
3732 (if invis1
3733 (overlay-put ov 'invisible t)
3734 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3735 (overlay-put ov 'org-type 'org-blocked-todo))))))
3736 (message "Dim or hide blocked tasks...done"))
3738 (defvar org-agenda-skip-function nil
3739 "Function to be called at each match during agenda construction.
3740 If this function returns nil, the current match should not be skipped.
3741 Otherwise, the function must return a position from where the search
3742 should be continued.
3743 This may also be a Lisp form, it will be evaluated.
3744 Never set this variable using `setq' or so, because then it will apply
3745 to all future agenda commands. If you do want a global skipping condition,
3746 use the option `org-agenda-skip-function-global' instead.
3747 The correct usage for `org-agenda-skip-function' is to bind it with
3748 `let' to scope it dynamically into the agenda-constructing command.
3749 A good way to set it is through options in `org-agenda-custom-commands'.")
3751 (defun org-agenda-skip ()
3752 "Throw to `:skip' in places that should be skipped.
3753 Also moves point to the end of the skipped region, so that search can
3754 continue from there."
3755 (let ((p (point-at-bol)) to)
3756 (when (or
3757 (eq (get-text-property p 'face) 'font-lock-comment-face)
3758 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3759 (get-text-property p :org-archived)
3760 (org-end-of-subtree t))
3761 (and org-agenda-skip-comment-trees
3762 (get-text-property p :org-comment)
3763 (org-end-of-subtree t))
3764 (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3765 (org-agenda-skip-eval org-agenda-skip-function)))
3766 (goto-char to))
3767 (org-in-src-block-p t))
3768 (throw :skip t))))
3770 (defun org-agenda-skip-eval (form)
3771 "If FORM is a function or a list, call (or eval) is and return result.
3772 `save-excursion' and `save-match-data' are wrapped around the call, so point
3773 and match data are returned to the previous state no matter what these
3774 functions do."
3775 (let (fp)
3776 (and form
3777 (or (setq fp (functionp form))
3778 (consp form))
3779 (save-excursion
3780 (save-match-data
3781 (if fp
3782 (funcall form)
3783 (eval form)))))))
3785 (defvar org-agenda-markers nil
3786 "List of all currently active markers created by `org-agenda'.")
3787 (defvar org-agenda-last-marker-time (org-float-time)
3788 "Creation time of the last agenda marker.")
3790 (defun org-agenda-new-marker (&optional pos)
3791 "Return a new agenda marker.
3792 Org-mode keeps a list of these markers and resets them when they are
3793 no longer in use."
3794 (let ((m (copy-marker (or pos (point)))))
3795 (setq org-agenda-last-marker-time (org-float-time))
3796 (if org-agenda-buffer
3797 (with-current-buffer org-agenda-buffer
3798 (push m org-agenda-markers))
3799 (push m org-agenda-markers))
3802 (defun org-agenda-reset-markers ()
3803 "Reset markers created by `org-agenda'."
3804 (while org-agenda-markers
3805 (move-marker (pop org-agenda-markers) nil)))
3807 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3808 "Save relative positions of markers in region.
3809 This check for agenda markers in all agenda buffers currently active."
3810 (dolist (buf (buffer-list))
3811 (with-current-buffer buf
3812 (when (eq major-mode 'org-agenda-mode)
3813 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3814 org-agenda-markers)))))
3816 ;;; Entry text mode
3818 (defun org-agenda-entry-text-show-here ()
3819 "Add some text from the entry as context to the current line."
3820 (let (m txt o)
3821 (setq m (org-get-at-bol 'org-hd-marker))
3822 (unless (marker-buffer m)
3823 (error "No marker points to an entry here"))
3824 (setq txt (concat "\n" (org-no-properties
3825 (org-agenda-get-some-entry-text
3826 m org-agenda-entry-text-maxlines " > "))))
3827 (when (string-match "\\S-" txt)
3828 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3829 (overlay-put o 'evaporate t)
3830 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3831 (overlay-put o 'after-string txt))))
3833 (defun org-agenda-entry-text-show ()
3834 "Add entry context for all agenda lines."
3835 (interactive)
3836 (save-excursion
3837 (goto-char (point-max))
3838 (beginning-of-line 1)
3839 (while (not (bobp))
3840 (when (org-get-at-bol 'org-hd-marker)
3841 (org-agenda-entry-text-show-here))
3842 (beginning-of-line 0))))
3844 (defun org-agenda-entry-text-hide ()
3845 "Remove any shown entry context."
3846 (delq nil
3847 (mapcar (lambda (o)
3848 (if (eq (overlay-get o 'org-overlay-type)
3849 'agenda-entry-content)
3850 (progn (delete-overlay o) t)))
3851 (overlays-in (point-min) (point-max)))))
3853 (defun org-agenda-get-day-face (date)
3854 "Return the face DATE should be displayed with."
3855 (or (and (functionp org-agenda-day-face-function)
3856 (funcall org-agenda-day-face-function date))
3857 (cond ((org-agenda-todayp date)
3858 'org-agenda-date-today)
3859 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3860 'org-agenda-date-weekend)
3861 (t 'org-agenda-date))))
3863 ;;; Agenda timeline
3865 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3867 (defun org-timeline (&optional dotodo)
3868 "Show a time-sorted view of the entries in the current org file.
3869 Only entries with a time stamp of today or later will be listed. With
3870 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3871 under the current date.
3872 If the buffer contains an active region, only check the region for
3873 dates."
3874 (interactive "P")
3875 (let* ((dopast t)
3876 (org-agenda-show-log-scoped org-agenda-show-log)
3877 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3878 (current-buffer))))
3879 (date (calendar-current-date))
3880 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3881 (end (if (org-region-active-p) (region-end) (point-max)))
3882 (day-numbers (org-get-all-dates
3883 beg end 'no-ranges
3884 t org-agenda-show-log-scoped ; always include today
3885 org-timeline-show-empty-dates))
3886 (org-deadline-warning-days 0)
3887 (org-agenda-only-exact-dates t)
3888 (today (org-today))
3889 (past t)
3890 args
3891 s e rtn d emptyp)
3892 (setq org-agenda-redo-command
3893 (list 'progn
3894 (list 'org-switch-to-buffer-other-window (current-buffer))
3895 (list 'org-timeline (list 'quote dotodo))))
3896 (if (not dopast)
3897 ;; Remove past dates from the list of dates.
3898 (setq day-numbers (delq nil (mapcar (lambda(x)
3899 (if (>= x today) x nil))
3900 day-numbers))))
3901 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3902 (org-compile-prefix-format 'timeline)
3903 (org-set-sorting-strategy 'timeline)
3904 (if org-agenda-show-log-scoped (push :closed args))
3905 (push :timestamp args)
3906 (push :deadline args)
3907 (push :scheduled args)
3908 (push :sexp args)
3909 (if dotodo (push :todo args))
3910 (insert "Timeline of file " entry "\n")
3911 (add-text-properties (point-min) (point)
3912 (list 'face 'org-agenda-structure))
3913 (org-agenda-mark-header-line (point-min))
3914 (while (setq d (pop day-numbers))
3915 (if (and (listp d) (eq (car d) :omitted))
3916 (progn
3917 (setq s (point))
3918 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3919 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3920 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3921 (if (and (>= d today)
3922 dopast
3923 past)
3924 (progn
3925 (setq past nil)
3926 (insert (make-string 79 ?-) "\n")))
3927 (setq date (calendar-gregorian-from-absolute d))
3928 (setq s (point))
3929 (setq rtn (and (not emptyp)
3930 (apply 'org-agenda-get-day-entries entry
3931 date args)))
3932 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3933 (progn
3934 (insert
3935 (if (stringp org-agenda-format-date)
3936 (format-time-string org-agenda-format-date
3937 (org-time-from-absolute date))
3938 (funcall org-agenda-format-date date))
3939 "\n")
3940 (put-text-property s (1- (point)) 'face
3941 (org-agenda-get-day-face date))
3942 (put-text-property s (1- (point)) 'org-date-line t)
3943 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3944 (if (equal d today)
3945 (put-text-property s (1- (point)) 'org-today t))
3946 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3947 (put-text-property s (1- (point)) 'day d)))))
3948 (goto-char (point-min))
3949 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3950 (point-min)))
3951 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3952 (org-agenda-finalize)
3953 (setq buffer-read-only t)))
3955 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3956 "Return a list of all relevant day numbers from BEG to END buffer positions.
3957 If NO-RANGES is non-nil, include only the start and end dates of a range,
3958 not every single day in the range. If FORCE-TODAY is non-nil, make
3959 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3960 inactive time stamps (those in square brackets) are included.
3961 When EMPTY is non-nil, also include days without any entries."
3962 (let ((re (concat
3963 (if pre-re pre-re "")
3964 (if inactive org-ts-regexp-both org-ts-regexp)))
3965 dates dates1 date day day1 day2 ts1 ts2 pos)
3966 (if force-today
3967 (setq dates (list (org-today))))
3968 (save-excursion
3969 (goto-char beg)
3970 (while (re-search-forward re end t)
3971 (setq day (time-to-days (org-time-string-to-time
3972 (substring (match-string 1) 0 10)
3973 (current-buffer) (match-beginning 0))))
3974 (or (memq day dates) (push day dates)))
3975 (unless no-ranges
3976 (goto-char beg)
3977 (while (re-search-forward org-tr-regexp end t)
3978 (setq pos (match-beginning 0))
3979 (setq ts1 (substring (match-string 1) 0 10)
3980 ts2 (substring (match-string 2) 0 10)
3981 day1 (time-to-days (org-time-string-to-time
3982 ts1 (current-buffer) pos))
3983 day2 (time-to-days (org-time-string-to-time
3984 ts2 (current-buffer) pos)))
3985 (while (< (setq day1 (1+ day1)) day2)
3986 (or (memq day1 dates) (push day1 dates)))))
3987 (setq dates (sort dates '<))
3988 (when empty
3989 (while (setq day (pop dates))
3990 (setq day2 (car dates))
3991 (push day dates1)
3992 (when (and day2 empty)
3993 (if (or (eq empty t)
3994 (and (numberp empty) (<= (- day2 day) empty)))
3995 (while (< (setq day (1+ day)) day2)
3996 (push (list day) dates1))
3997 (push (cons :omitted (- day2 day)) dates1))))
3998 (setq dates (nreverse dates1)))
3999 dates)))
4001 ;;; Agenda Daily/Weekly
4003 (defvar org-agenda-start-day nil ; dynamically scoped parameter
4004 "Start day for the agenda view.
4005 Custom commands can set this variable in the options section.")
4006 (defvar org-starting-day nil) ; local variable in the agenda buffer
4007 (defvar org-arg-loc nil) ; local variable
4009 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
4010 "List of types searched for when creating the daily/weekly agenda.
4011 This variable is a list of symbols that controls the types of
4012 items that appear in the daily/weekly agenda. Allowed symbols in this
4013 list are are
4015 :timestamp List items containing a date stamp or date range matching
4016 the selected date. This includes sexp entries in
4017 angular brackets.
4019 :sexp List entries resulting from plain diary-like sexps.
4021 :deadline List deadline due on that date. When the date is today,
4022 also list any deadlines past due, or due within
4023 `org-deadline-warning-days'. `:deadline' must appear before
4024 `:scheduled' if the setting of
4025 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
4026 any effect.
4028 :scheduled List all items which are scheduled for the given date.
4029 The diary for *today* also contains items which were
4030 scheduled earlier and are not yet marked DONE.
4032 By default, all four types are turned on.
4034 Never set this variable globally using `setq', because then it
4035 will apply to all future agenda commands. Instead, bind it with
4036 `let' to scope it dynamically into the agenda-constructing
4037 command. A good way to set it is through options in
4038 `org-agenda-custom-commands'. For a more flexible (though
4039 somewhat less efficient) way of determining what is included in
4040 the daily/weekly agenda, see `org-agenda-skip-function'.")
4042 (defvar org-agenda-buffer-tmp-name nil)
4043 ;;;###autoload
4044 (defun org-agenda-list (&optional arg start-day span)
4045 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
4046 The view will be for the current day or week, but from the overview buffer
4047 you will be able to go to other days/weeks.
4049 With a numeric prefix argument in an interactive call, the agenda will
4050 span ARG days. Lisp programs should instead specify SPAN to change
4051 the number of days. SPAN defaults to `org-agenda-span'.
4053 START-DAY defaults to TODAY, or to the most recent match for the weekday
4054 given in `org-agenda-start-on-weekday'."
4055 (interactive "P")
4056 (if org-agenda-overriding-arguments
4057 (setq arg (car org-agenda-overriding-arguments)
4058 start-day (nth 1 org-agenda-overriding-arguments)
4059 span (nth 2 org-agenda-overriding-arguments)))
4060 (if (and (integerp arg) (> arg 0))
4061 (setq span arg arg nil))
4062 (catch 'exit
4063 (setq org-agenda-buffer-name
4064 (or org-agenda-buffer-tmp-name
4065 (if org-agenda-sticky
4066 (cond ((and org-keys (stringp org-match))
4067 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4068 (org-keys
4069 (format "*Org Agenda(%s)*" org-keys))
4070 (t "*Org Agenda(a)*")))
4071 org-agenda-buffer-name))
4072 (org-agenda-prepare "Day/Week")
4073 (setq start-day (or start-day org-agenda-start-day))
4074 (if (stringp start-day)
4075 ;; Convert to an absolute day number
4076 (setq start-day (time-to-days (org-read-date nil t start-day))))
4077 (org-compile-prefix-format 'agenda)
4078 (org-set-sorting-strategy 'agenda)
4079 (let* ((span (org-agenda-ndays-to-span
4080 (or span org-agenda-ndays org-agenda-span)))
4081 (today (org-today))
4082 (sd (or start-day today))
4083 (ndays (org-agenda-span-to-ndays span sd))
4084 (org-agenda-start-on-weekday
4085 (if (eq ndays 7)
4086 org-agenda-start-on-weekday))
4087 (thefiles (org-agenda-files nil 'ifmode))
4088 (files thefiles)
4089 (start (if (or (null org-agenda-start-on-weekday)
4090 (< ndays 7))
4092 (let* ((nt (calendar-day-of-week
4093 (calendar-gregorian-from-absolute sd)))
4094 (n1 org-agenda-start-on-weekday)
4095 (d (- nt n1)))
4096 (- sd (+ (if (< d 0) 7 0) d)))))
4097 (day-numbers (list start))
4098 (day-cnt 0)
4099 (inhibit-redisplay (not debug-on-error))
4100 (org-agenda-show-log-scoped org-agenda-show-log)
4101 s e rtn rtnall file date d start-pos end-pos todayp
4102 clocktable-start clocktable-end filter)
4103 (setq org-agenda-redo-command
4104 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4105 (dotimes (n (1- ndays))
4106 (push (1+ (car day-numbers)) day-numbers))
4107 (setq day-numbers (nreverse day-numbers))
4108 (setq clocktable-start (car day-numbers)
4109 clocktable-end (1+ (or (org-last day-numbers) 0)))
4110 (org-set-local 'org-starting-day (car day-numbers))
4111 (org-set-local 'org-arg-loc arg)
4112 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4113 (unless org-agenda-compact-blocks
4114 (let* ((d1 (car day-numbers))
4115 (d2 (org-last day-numbers))
4116 (w1 (org-days-to-iso-week d1))
4117 (w2 (org-days-to-iso-week d2)))
4118 (setq s (point))
4119 (if org-agenda-overriding-header
4120 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4121 nil 'face 'org-agenda-structure) "\n")
4122 (insert (org-agenda-span-name span)
4123 "-agenda"
4124 (if (< (- d2 d1) 350)
4125 (if (= w1 w2)
4126 (format " (W%02d)" w1)
4127 (format " (W%02d-W%02d)" w1 w2))
4129 ":\n")))
4130 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4131 'org-date-line t))
4132 (org-agenda-mark-header-line s))
4133 (while (setq d (pop day-numbers))
4134 (setq date (calendar-gregorian-from-absolute d)
4135 s (point))
4136 (if (or (setq todayp (= d today))
4137 (and (not start-pos) (= d sd)))
4138 (setq start-pos (point))
4139 (if (and start-pos (not end-pos))
4140 (setq end-pos (point))))
4141 (setq files thefiles
4142 rtnall nil)
4143 (while (setq file (pop files))
4144 (catch 'nextfile
4145 (org-check-agenda-file file)
4146 (let ((org-agenda-entry-types org-agenda-entry-types))
4147 (unless org-agenda-include-deadlines
4148 (setq org-agenda-entry-types
4149 (delq :deadline org-agenda-entry-types)))
4150 (cond
4151 ((memq org-agenda-show-log-scoped '(only clockcheck))
4152 (setq rtn (org-agenda-get-day-entries
4153 file date :closed)))
4154 (org-agenda-show-log-scoped
4155 (setq rtn (apply 'org-agenda-get-day-entries
4156 file date
4157 (append '(:closed) org-agenda-entry-types))))
4159 (setq rtn (apply 'org-agenda-get-day-entries
4160 file date
4161 org-agenda-entry-types)))))
4162 (setq rtnall (append rtnall rtn)))) ;; all entries
4163 (if org-agenda-include-diary
4164 (let ((org-agenda-search-headline-for-time t))
4165 (require 'diary-lib)
4166 (setq rtn (org-get-entries-from-diary date))
4167 (setq rtnall (append rtnall rtn))))
4168 (if (or rtnall org-agenda-show-all-dates)
4169 (progn
4170 (setq day-cnt (1+ day-cnt))
4171 (insert
4172 (if (stringp org-agenda-format-date)
4173 (format-time-string org-agenda-format-date
4174 (org-time-from-absolute date))
4175 (funcall org-agenda-format-date date))
4176 "\n")
4177 (put-text-property s (1- (point)) 'face
4178 (org-agenda-get-day-face date))
4179 (put-text-property s (1- (point)) 'org-date-line t)
4180 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4181 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4182 (when todayp
4183 (put-text-property s (1- (point)) 'org-today t))
4184 (setq rtnall
4185 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4186 (if rtnall (insert ;; all entries
4187 (org-agenda-finalize-entries rtnall)
4188 "\n"))
4189 (put-text-property s (1- (point)) 'day d)
4190 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4191 (when (and org-agenda-clockreport-mode clocktable-start)
4192 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4193 ;; the above line is to ensure the restricted range!
4194 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4195 tbl)
4196 (setq p (org-plist-delete p :block))
4197 (setq p (plist-put p :tstart clocktable-start))
4198 (setq p (plist-put p :tend clocktable-end))
4199 (setq p (plist-put p :scope 'agenda))
4200 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4201 (setq filter (or org-agenda-tag-filter-while-redo
4202 (get 'org-agenda-tag-filter :preset-filter))))
4203 (setq p (plist-put p :tags (mapconcat (lambda (x)
4204 (if (string-match "[<>=]" x)
4207 filter ""))))
4208 (setq tbl (apply 'org-clock-get-clocktable p))
4209 (insert tbl)))
4210 (goto-char (point-min))
4211 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4212 (unless (and (pos-visible-in-window-p (point-min))
4213 (pos-visible-in-window-p (point-max)))
4214 (goto-char (1- (point-max)))
4215 (recenter -1)
4216 (if (not (pos-visible-in-window-p (or start-pos 1)))
4217 (progn
4218 (goto-char (or start-pos 1))
4219 (recenter 1))))
4220 (goto-char (or start-pos 1))
4221 (add-text-properties (point-min) (point-max)
4222 `(org-agenda-type agenda
4223 org-last-args (,arg ,start-day ,span)
4224 org-redo-cmd ,org-agenda-redo-command
4225 org-series-cmd ,org-cmd))
4226 (if (eq org-agenda-show-log-scoped 'clockcheck)
4227 (org-agenda-show-clocking-issues))
4228 (org-agenda-finalize)
4229 (setq buffer-read-only t)
4230 (message ""))))
4232 (autoload 'org-agenda-list "org-agenda" "\
4233 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4234 The view will be for the current day or week, but from the overview buffer
4235 you will be able to go to other days/weeks.
4237 With a numeric prefix argument in an interactive call, the agenda will
4238 span ARG days. Lisp programs should instead specify SPAN to change
4239 the number of days. SPAN defaults to `org-agenda-span'.
4241 START-DAY defaults to TODAY, or to the most recent match for the weekday
4242 given in `org-agenda-start-on-weekday'.
4244 \(fn &optional ARG START-DAY SPAN)" t nil)
4246 (defun org-agenda-ndays-to-span (n)
4247 "Return a span symbol for a span of N days, or N if none matches."
4248 (cond ((symbolp n) n)
4249 ((= n 1) 'day)
4250 ((= n 7) 'week)
4251 (t n)))
4253 (defun org-agenda-span-to-ndays (span &optional start-day)
4254 "Return ndays from SPAN, possibly starting at START-DAY."
4255 (cond ((numberp span) span)
4256 ((eq span 'day) 1)
4257 ((eq span 'week) 7)
4258 ((eq span 'month)
4259 (let ((date (calendar-gregorian-from-absolute start-day)))
4260 (calendar-last-day-of-month (car date) (caddr date))))
4261 ((eq span 'year)
4262 (let ((date (calendar-gregorian-from-absolute start-day)))
4263 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4265 (defun org-agenda-span-name (span)
4266 "Return a SPAN name."
4267 (if (null span)
4269 (if (symbolp span)
4270 (capitalize (symbol-name span))
4271 (format "%d days" span))))
4273 ;;; Agenda word search
4275 (defvar org-agenda-search-history nil)
4277 (defvar org-search-syntax-table nil
4278 "Special syntax table for org-mode search.
4279 In this table, we have single quotes not as word constituents, to
4280 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4282 (defvar org-mode-syntax-table) ; From org.el
4283 (defun org-search-syntax-table ()
4284 (unless org-search-syntax-table
4285 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4286 (modify-syntax-entry ?' "." org-search-syntax-table)
4287 (modify-syntax-entry ?` "." org-search-syntax-table))
4288 org-search-syntax-table)
4290 (defvar org-agenda-last-search-view-search-was-boolean nil)
4292 ;;;###autoload
4293 (defun org-search-view (&optional todo-only string edit-at)
4294 "Show all entries that contain a phrase or words or regular expressions.
4296 With optional prefix argument TODO-ONLY, only consider entries that are
4297 TODO entries. The argument STRING can be used to pass a default search
4298 string into this function. If EDIT-AT is non-nil, it means that the
4299 user should get a chance to edit this string, with cursor at position
4300 EDIT-AT.
4302 The search string can be viewed either as a phrase that should be found as
4303 is, or it can be broken into a number of snippets, each of which must match
4304 in a Boolean way to select an entry. The default depends on the variable
4305 `org-agenda-search-view-always-boolean'.
4306 Even if this is turned off (the default) you can always switch to
4307 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4309 The default is a direct search of the whole phrase, where each space in
4310 the search string can expand to an arbitrary amount of whitespace,
4311 including newlines.
4313 If using a Boolean search, the search string is split on whitespace and
4314 each snippet is searched separately, with logical AND to select an entry.
4315 Words prefixed with a minus must *not* occur in the entry. Words without
4316 a prefix or prefixed with a plus must occur in the entry. Matching is
4317 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4318 match whole words, not parts of a word) if
4319 `org-agenda-search-view-force-full-words' is set (default is nil).
4321 Boolean search snippets enclosed by curly braces are interpreted as
4322 regular expressions that must or (when preceded with \"-\") must not
4323 match in the entry. Snippets enclosed into double quotes will be taken
4324 as a whole, to include whitespace.
4326 - If the search string starts with an asterisk, search only in headlines.
4327 - If (possibly after the leading star) the search string starts with an
4328 exclamation mark, this also means to look at TODO entries only, an effect
4329 that can also be achieved with a prefix argument.
4330 - If (possibly after star and exclamation mark) the search string starts
4331 with a colon, this will mean that the (non-regexp) snippets of the
4332 Boolean search must match as full words.
4334 This command searches the agenda files, and in addition the files listed
4335 in `org-agenda-text-search-extra-files'."
4336 (interactive "P")
4337 (if org-agenda-overriding-arguments
4338 (setq todo-only (car org-agenda-overriding-arguments)
4339 string (nth 1 org-agenda-overriding-arguments)
4340 edit-at (nth 2 org-agenda-overriding-arguments)))
4341 (let* ((props (list 'face nil
4342 'done-face 'org-agenda-done
4343 'org-not-done-regexp org-not-done-regexp
4344 'org-todo-regexp org-todo-regexp
4345 'org-complex-heading-regexp org-complex-heading-regexp
4346 'mouse-face 'highlight
4347 'help-echo (format "mouse-2 or RET jump to location")))
4348 (full-words org-agenda-search-view-force-full-words)
4349 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4350 regexp rtn rtnall files file pos inherited-tags
4351 marker category category-pos level tags c neg re boolean
4352 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4353 (unless (and (not edit-at)
4354 (stringp string)
4355 (string-match "\\S-" string))
4356 (setq string (read-string
4357 (if org-agenda-search-view-always-boolean
4358 "[+-]Word/{Regexp} ...: "
4359 "Phrase or [+-]Word/{Regexp} ...: ")
4360 (cond
4361 ((integerp edit-at) (cons string edit-at))
4362 (edit-at string))
4363 'org-agenda-search-history)))
4364 (catch 'exit
4365 (if org-agenda-sticky
4366 (setq org-agenda-buffer-name
4367 (if (stringp string)
4368 (format "*Org Agenda(%s:%s)*"
4369 (or org-keys (or (and todo-only "S") "s")) string)
4370 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4371 (org-agenda-prepare "SEARCH")
4372 (org-compile-prefix-format 'search)
4373 (org-set-sorting-strategy 'search)
4374 (setq org-agenda-redo-command
4375 (list 'org-search-view (if todo-only t nil)
4376 (list 'if 'current-prefix-arg nil string)))
4377 (setq org-agenda-query-string string)
4378 (if (equal (string-to-char string) ?*)
4379 (setq hdl-only t
4380 words (substring string 1))
4381 (setq words string))
4382 (when (equal (string-to-char words) ?!)
4383 (setq todo-only t
4384 words (substring words 1)))
4385 (when (equal (string-to-char words) ?:)
4386 (setq full-words t
4387 words (substring words 1)))
4388 (if (or org-agenda-search-view-always-boolean
4389 (member (string-to-char words) '(?- ?+ ?\{)))
4390 (setq boolean t))
4391 (setq words (org-split-string words))
4392 (let (www w)
4393 (while (setq w (pop words))
4394 (while (and (string-match "\\\\\\'" w) words)
4395 (setq w (concat (substring w 0 -1) " " (pop words))))
4396 (push w www))
4397 (setq words (nreverse www) www nil)
4398 (while (setq w (pop words))
4399 (when (and (string-match "\\`[-+]?{" w)
4400 (not (string-match "}\\'" w)))
4401 (while (and words (not (string-match "}\\'" (car words))))
4402 (setq w (concat w " " (pop words))))
4403 (setq w (concat w " " (pop words))))
4404 (push w www))
4405 (setq words (nreverse www)))
4406 (setq org-agenda-last-search-view-search-was-boolean boolean)
4407 (when boolean
4408 (let (wds w)
4409 (while (setq w (pop words))
4410 (if (or (equal (substring w 0 1) "\"")
4411 (and (> (length w) 1)
4412 (member (substring w 0 1) '("+" "-"))
4413 (equal (substring w 1 2) "\"")))
4414 (while (and words (not (equal (substring w -1) "\"")))
4415 (setq w (concat w " " (pop words)))))
4416 (and (string-match "\\`\\([-+]?\\)\"" w)
4417 (setq w (replace-match "\\1" nil nil w)))
4418 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4419 (push w wds))
4420 (setq words (nreverse wds))))
4421 (if boolean
4422 (mapc (lambda (w)
4423 (setq c (string-to-char w))
4424 (if (equal c ?-)
4425 (setq neg t w (substring w 1))
4426 (if (equal c ?+)
4427 (setq neg nil w (substring w 1))
4428 (setq neg nil)))
4429 (if (string-match "\\`{.*}\\'" w)
4430 (setq re (substring w 1 -1))
4431 (if full-words
4432 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4433 (setq re (regexp-quote (downcase w)))))
4434 (if neg (push re regexps-) (push re regexps+)))
4435 words)
4436 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4437 regexps+))
4438 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4439 (if (not regexps+)
4440 (setq regexp org-outline-regexp-bol)
4441 (setq regexp (pop regexps+))
4442 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4443 regexp))))
4444 (setq files (org-agenda-files nil 'ifmode))
4445 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4446 (pop org-agenda-text-search-extra-files)
4447 (setq files (org-add-archive-files files)))
4448 (setq files (append files org-agenda-text-search-extra-files)
4449 rtnall nil)
4450 (while (setq file (pop files))
4451 (setq ee nil)
4452 (catch 'nextfile
4453 (org-check-agenda-file file)
4454 (setq buffer (if (file-exists-p file)
4455 (org-get-agenda-file-buffer file)
4456 (error "No such file %s" file)))
4457 (if (not buffer)
4458 ;; If file does not exist, make sure an error message is sent
4459 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4460 file))))
4461 (with-current-buffer buffer
4462 (with-syntax-table (org-search-syntax-table)
4463 (unless (derived-mode-p 'org-mode)
4464 (error "Agenda file %s is not in `org-mode'" file))
4465 (let ((case-fold-search t))
4466 (save-excursion
4467 (save-restriction
4468 (if org-agenda-restrict
4469 (narrow-to-region org-agenda-restrict-begin
4470 org-agenda-restrict-end)
4471 (widen))
4472 (goto-char (point-min))
4473 (unless (or (org-at-heading-p)
4474 (outline-next-heading))
4475 (throw 'nextfile t))
4476 (goto-char (max (point-min) (1- (point))))
4477 (while (re-search-forward regexp nil t)
4478 (org-back-to-heading t)
4479 (while (and org-agenda-search-view-max-outline-level
4480 (> (org-reduced-level (org-outline-level))
4481 org-agenda-search-view-max-outline-level)
4482 (forward-line -1)
4483 (outline-back-to-heading t)))
4484 (skip-chars-forward "* ")
4485 (setq beg (point-at-bol)
4486 beg1 (point)
4487 end (progn
4488 (outline-next-heading)
4489 (while (and org-agenda-search-view-max-outline-level
4490 (> (org-reduced-level (org-outline-level))
4491 org-agenda-search-view-max-outline-level)
4492 (forward-line 1)
4493 (outline-next-heading)))
4494 (point)))
4496 (catch :skip
4497 (goto-char beg)
4498 (org-agenda-skip)
4499 (setq str (buffer-substring-no-properties
4500 (point-at-bol)
4501 (if hdl-only (point-at-eol) end)))
4502 (mapc (lambda (wr) (when (string-match wr str)
4503 (goto-char (1- end))
4504 (throw :skip t)))
4505 regexps-)
4506 (mapc (lambda (wr) (unless (string-match wr str)
4507 (goto-char (1- end))
4508 (throw :skip t)))
4509 (if todo-only
4510 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4511 regexps+)
4512 regexps+))
4513 (goto-char beg)
4514 (setq marker (org-agenda-new-marker (point))
4515 category (org-get-category)
4516 level (make-string (org-reduced-level (org-outline-level)) ? )
4517 category-pos (get-text-property (point) 'org-category-position)
4518 inherited-tags
4519 (or (eq org-agenda-show-inherited-tags 'always)
4520 (and (listp org-agenda-show-inherited-tags)
4521 (memq 'todo org-agenda-show-inherited-tags))
4522 (and (eq org-agenda-show-inherited-tags t)
4523 (or (eq org-agenda-use-tag-inheritance t)
4524 (memq 'todo org-agenda-use-tag-inheritance))))
4525 tags (org-get-tags-at nil (not inherited-tags))
4526 txt (org-agenda-format-item
4528 (buffer-substring-no-properties
4529 beg1 (point-at-eol))
4530 level category tags t))
4531 (org-add-props txt props
4532 'org-marker marker 'org-hd-marker marker
4533 'org-todo-regexp org-todo-regexp
4534 'level level
4535 'org-complex-heading-regexp org-complex-heading-regexp
4536 'priority 1000 'org-category category
4537 'org-category-position category-pos
4538 'type "search")
4539 (push txt ee)
4540 (goto-char (1- end))))))))))
4541 (setq rtn (nreverse ee))
4542 (setq rtnall (append rtnall rtn)))
4543 (if org-agenda-overriding-header
4544 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4545 nil 'face 'org-agenda-structure) "\n")
4546 (insert "Search words: ")
4547 (add-text-properties (point-min) (1- (point))
4548 (list 'face 'org-agenda-structure))
4549 (setq pos (point))
4550 (insert string "\n")
4551 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4552 (setq pos (point))
4553 (unless org-agenda-multi
4554 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4555 (add-text-properties pos (1- (point))
4556 (list 'face 'org-agenda-structure))))
4557 (org-agenda-mark-header-line (point-min))
4558 (when rtnall
4559 (insert (org-agenda-finalize-entries rtnall) "\n"))
4560 (goto-char (point-min))
4561 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4562 (add-text-properties (point-min) (point-max)
4563 `(org-agenda-type search
4564 org-last-args (,todo-only ,string ,edit-at)
4565 org-redo-cmd ,org-agenda-redo-command
4566 org-series-cmd ,org-cmd))
4567 (org-agenda-finalize)
4568 (setq buffer-read-only t))))
4570 (autoload 'org-search-view "org-agenda" "\
4571 Show all entries that contain a phrase or words or regular expressions.
4573 With optional prefix argument TODO-ONLY, only consider entries that are
4574 TODO entries. The argument STRING can be used to pass a default search
4575 string into this function. If EDIT-AT is non-nil, it means that the
4576 user should get a chance to edit this string, with cursor at position
4577 EDIT-AT.
4579 The search string can be viewed either as a phrase that should be found as
4580 is, or it can be broken into a number of snippets, each of which must match
4581 in a Boolean way to select an entry. The default depends on the variable
4582 `org-agenda-search-view-always-boolean'.
4583 Even if this is turned off (the default) you can always switch to
4584 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4586 The default is a direct search of the whole phrase, where each space in
4587 the search string can expand to an arbitrary amount of whitespace,
4588 including newlines.
4590 If using a Boolean search, the search string is split on whitespace and
4591 each snippet is searched separately, with logical AND to select an entry.
4592 Words prefixed with a minus must *not* occur in the entry. Words without
4593 a prefix or prefixed with a plus must occur in the entry. Matching is
4594 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4595 match whole words, not parts of a word) if
4596 `org-agenda-search-view-force-full-words' is set (default is nil).
4598 Boolean search snippets enclosed by curly braces are interpreted as
4599 regular expressions that must or (when preceded with \"-\") must not
4600 match in the entry. Snippets enclosed into double quotes will be taken
4601 as a whole, to include whitespace.
4603 - If the search string starts with an asterisk, search only in headlines.
4604 - If (possibly after the leading star) the search string starts with an
4605 exclamation mark, this also means to look at TODO entries only, an effect
4606 that can also be achieved with a prefix argument.
4607 - If (possibly after star and exclamation mark) the search string starts
4608 with a colon, this will mean that the (non-regexp) snippets of the
4609 Boolean search must match as full words.
4611 This command searches the agenda files, and in addition the files listed
4612 in `org-agenda-text-search-extra-files'.
4614 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4616 ;;; Agenda TODO list
4618 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4619 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4620 (concat
4621 (if (or (equal keywords "ALL") (not keywords))
4622 (propertize "ALL" 'face 'warning)
4623 (mapconcat
4624 (lambda (kw)
4625 (propertize kw 'face (org-get-todo-face kw)))
4626 (org-split-string keywords "|")
4627 "|"))
4628 "\n"))
4630 (defvar org-select-this-todo-keyword nil)
4631 (defvar org-last-arg nil)
4633 ;;;###autoload
4634 (defun org-todo-list (&optional arg)
4635 "Show all (not done) TODO entries from all agenda file in a single list.
4636 The prefix arg can be used to select a specific TODO keyword and limit
4637 the list to these. When using \\[universal-argument], you will be prompted
4638 for a keyword. A numeric prefix directly selects the Nth keyword in
4639 `org-todo-keywords-1'."
4640 (interactive "P")
4641 (if org-agenda-overriding-arguments
4642 (setq arg org-agenda-overriding-arguments))
4643 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4644 (let* ((today (org-today))
4645 (date (calendar-gregorian-from-absolute today))
4646 (kwds org-todo-keywords-for-agenda)
4647 (completion-ignore-case t)
4648 (org-select-this-todo-keyword
4649 (if (stringp arg) arg
4650 (and arg (integerp arg) (> arg 0)
4651 (nth (1- arg) kwds))))
4652 rtn rtnall files file pos)
4653 (when (equal arg '(4))
4654 (setq org-select-this-todo-keyword
4655 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4656 (mapcar 'list kwds) nil nil)))
4657 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4658 (catch 'exit
4659 (if org-agenda-sticky
4660 (setq org-agenda-buffer-name
4661 (if (stringp org-select-this-todo-keyword)
4662 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4663 org-select-this-todo-keyword)
4664 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4665 (org-agenda-prepare "TODO")
4666 (org-compile-prefix-format 'todo)
4667 (org-set-sorting-strategy 'todo)
4668 (setq org-agenda-redo-command
4669 `(org-todo-list (or (and (numberp current-prefix-arg)
4670 current-prefix-arg)
4671 ,org-select-this-todo-keyword
4672 current-prefix-arg ,arg)))
4673 (setq files (org-agenda-files nil 'ifmode)
4674 rtnall nil)
4675 (while (setq file (pop files))
4676 (catch 'nextfile
4677 (org-check-agenda-file file)
4678 (setq rtn (org-agenda-get-day-entries file date :todo))
4679 (setq rtnall (append rtnall rtn))))
4680 (if org-agenda-overriding-header
4681 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4682 nil 'face 'org-agenda-structure) "\n")
4683 (insert "Global list of TODO items of type: ")
4684 (add-text-properties (point-min) (1- (point))
4685 (list 'face 'org-agenda-structure
4686 'short-heading
4687 (concat "ToDo: "
4688 (or org-select-this-todo-keyword "ALL"))))
4689 (org-agenda-mark-header-line (point-min))
4690 (insert (org-agenda-propertize-selected-todo-keywords
4691 org-select-this-todo-keyword))
4692 (setq pos (point))
4693 (unless org-agenda-multi
4694 (insert "Available with `N r': (0)[ALL]")
4695 (let ((n 0) s)
4696 (mapc (lambda (x)
4697 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4698 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4699 (insert "\n "))
4700 (insert " " s))
4701 kwds))
4702 (insert "\n"))
4703 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4704 (org-agenda-mark-header-line (point-min))
4705 (when rtnall
4706 (insert (org-agenda-finalize-entries rtnall) "\n"))
4707 (goto-char (point-min))
4708 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4709 (add-text-properties (point-min) (point-max)
4710 `(org-agenda-type todo
4711 org-last-args ,arg
4712 org-redo-cmd ,org-agenda-redo-command
4713 org-series-cmd ,org-cmd))
4714 (org-agenda-finalize)
4715 (setq buffer-read-only t))))
4717 (autoload 'org-todo-list "org-agenda" "\
4718 Show all (not done) TODO entries from all agenda file in a single list.
4719 The prefix arg can be used to select a specific TODO keyword and limit
4720 the list to these. When using \\[universal-argument], you will be prompted
4721 for a keyword. A numeric prefix directly selects the Nth keyword in
4722 `org-todo-keywords-1'.
4724 \(fn &optional ARG)" t nil)
4726 ;;; Agenda tags match
4728 ;;;###autoload
4729 (defun org-tags-view (&optional todo-only match)
4730 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4731 The prefix arg TODO-ONLY limits the search to TODO entries."
4732 (interactive "P")
4733 (if org-agenda-overriding-arguments
4734 (setq todo-only (car org-agenda-overriding-arguments)
4735 match (nth 1 org-agenda-overriding-arguments)))
4736 (let* ((org-tags-match-list-sublevels
4737 org-tags-match-list-sublevels)
4738 (completion-ignore-case t)
4739 rtn rtnall files file pos matcher
4740 buffer)
4741 (when (and (stringp match) (not (string-match "\\S-" match)))
4742 (setq match nil))
4743 (setq matcher (org-make-tags-matcher match)
4744 match (car matcher) matcher (cdr matcher))
4745 (catch 'exit
4746 (if org-agenda-sticky
4747 (setq org-agenda-buffer-name
4748 (if (stringp match)
4749 (format "*Org Agenda(%s:%s)*"
4750 (or org-keys (or (and todo-only "M") "m")) match)
4751 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4752 (org-agenda-prepare (concat "TAGS " match))
4753 (org-compile-prefix-format 'tags)
4754 (org-set-sorting-strategy 'tags)
4755 (setq org-agenda-query-string match)
4756 (setq org-agenda-redo-command
4757 (list 'org-tags-view `(quote ,todo-only)
4758 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4759 (setq files (org-agenda-files nil 'ifmode)
4760 rtnall nil)
4761 (while (setq file (pop files))
4762 (catch 'nextfile
4763 (org-check-agenda-file file)
4764 (setq buffer (if (file-exists-p file)
4765 (org-get-agenda-file-buffer file)
4766 (error "No such file %s" file)))
4767 (if (not buffer)
4768 ;; If file does not exist, error message to agenda
4769 (setq rtn (list
4770 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4771 rtnall (append rtnall rtn))
4772 (with-current-buffer buffer
4773 (unless (derived-mode-p 'org-mode)
4774 (error "Agenda file %s is not in `org-mode'" file))
4775 (save-excursion
4776 (save-restriction
4777 (if org-agenda-restrict
4778 (narrow-to-region org-agenda-restrict-begin
4779 org-agenda-restrict-end)
4780 (widen))
4781 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4782 (setq rtnall (append rtnall rtn))))))))
4783 (if org-agenda-overriding-header
4784 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4785 nil 'face 'org-agenda-structure) "\n")
4786 (insert "Headlines with TAGS match: ")
4787 (add-text-properties (point-min) (1- (point))
4788 (list 'face 'org-agenda-structure
4789 'short-heading
4790 (concat "Match: " match)))
4791 (setq pos (point))
4792 (insert match "\n")
4793 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4794 (setq pos (point))
4795 (unless org-agenda-multi
4796 (insert "Press `C-u r' to search again with new search string\n"))
4797 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4798 (org-agenda-mark-header-line (point-min))
4799 (when rtnall
4800 (insert (org-agenda-finalize-entries rtnall) "\n"))
4801 (goto-char (point-min))
4802 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4803 (add-text-properties (point-min) (point-max)
4804 `(org-agenda-type tags
4805 org-last-args (,todo-only ,match)
4806 org-redo-cmd ,org-agenda-redo-command
4807 org-series-cmd ,org-cmd))
4808 (org-agenda-finalize)
4809 (setq buffer-read-only t))))
4811 (autoload 'org-tags-view "org-agenda" "\
4812 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4813 The prefix arg TODO-ONLY limits the search to TODO entries.
4815 \(fn &optional TODO-ONLY MATCH)" t nil)
4817 ;;; Agenda Finding stuck projects
4819 (defvar org-agenda-skip-regexp nil
4820 "Regular expression used in skipping subtrees for the agenda.
4821 This is basically a temporary global variable that can be set and then
4822 used by user-defined selections using `org-agenda-skip-function'.")
4824 (defvar org-agenda-overriding-header nil
4825 "When set during agenda, todo and tags searches it replaces the header.
4826 This variable should not be set directly, but custom commands can bind it
4827 in the options section.")
4829 (defun org-agenda-skip-entry-when-regexp-matches ()
4830 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4831 If yes, it returns the end position of this entry, causing agenda commands
4832 to skip the entry but continuing the search in the subtree. This is a
4833 function that can be put into `org-agenda-skip-function' for the duration
4834 of a command."
4835 (let ((end (save-excursion (org-end-of-subtree t)))
4836 skip)
4837 (save-excursion
4838 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4839 (and skip end)))
4841 (defun org-agenda-skip-subtree-when-regexp-matches ()
4842 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4843 If yes, it returns the end position of this tree, causing agenda commands
4844 to skip this subtree. This is a function that can be put into
4845 `org-agenda-skip-function' for the duration of a command."
4846 (let ((end (save-excursion (org-end-of-subtree t)))
4847 skip)
4848 (save-excursion
4849 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4850 (and skip end)))
4852 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4853 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4854 If yes, it returns the end position of the current entry (NOT the tree),
4855 causing agenda commands to skip the entry but continuing the search in
4856 the subtree. This is a function that can be put into
4857 `org-agenda-skip-function' for the duration of a command. An important
4858 use of this function is for the stuck project list."
4859 (let ((end (save-excursion (org-end-of-subtree t)))
4860 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4861 skip)
4862 (save-excursion
4863 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4864 (and skip entry-end)))
4866 (defun org-agenda-skip-entry-if (&rest conditions)
4867 "Skip entry if any of CONDITIONS is true.
4868 See `org-agenda-skip-if' for details."
4869 (org-agenda-skip-if nil conditions))
4871 (defun org-agenda-skip-subtree-if (&rest conditions)
4872 "Skip entry if any of CONDITIONS is true.
4873 See `org-agenda-skip-if' for details."
4874 (org-agenda-skip-if t conditions))
4876 (defun org-agenda-skip-if (subtree conditions)
4877 "Checks current entity for CONDITIONS.
4878 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4879 the entry (i.e. the text before the next heading) is checked.
4881 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4882 from different tests. Valid conditions are:
4884 scheduled Check if there is a scheduled cookie
4885 notscheduled Check if there is no scheduled cookie
4886 deadline Check if there is a deadline
4887 notdeadline Check if there is no deadline
4888 timestamp Check if there is a timestamp (also deadline or scheduled)
4889 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4890 regexp Check if regexp matches
4891 notregexp Check if regexp does not match.
4892 todo Check if TODO keyword matches
4893 nottodo Check if TODO keyword does not match
4895 The regexp is taken from the conditions list, it must come right after
4896 the `regexp' or `notregexp' element.
4898 `todo' and `nottodo' accept as an argument a list of todo
4899 keywords, which may include \"*\" to match any todo keyword.
4901 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4903 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4905 Instead of a list, a keyword class may be given. For example:
4907 (org-agenda-skip-entry-if 'nottodo 'done)
4909 would skip entries that haven't been marked with any of \"DONE\"
4910 keywords. Possible classes are: `todo', `done', `any'.
4912 If any of these conditions is met, this function returns the end point of
4913 the entity, causing the search to continue from there. This is a function
4914 that can be put into `org-agenda-skip-function' for the duration of a command."
4915 (let (beg end m)
4916 (org-back-to-heading t)
4917 (setq beg (point)
4918 end (if subtree
4919 (progn (org-end-of-subtree t) (point))
4920 (progn (outline-next-heading) (1- (point)))))
4921 (goto-char beg)
4922 (and
4924 (and (memq 'scheduled conditions)
4925 (re-search-forward org-scheduled-time-regexp end t))
4926 (and (memq 'notscheduled conditions)
4927 (not (re-search-forward org-scheduled-time-regexp end t)))
4928 (and (memq 'deadline conditions)
4929 (re-search-forward org-deadline-time-regexp end t))
4930 (and (memq 'notdeadline conditions)
4931 (not (re-search-forward org-deadline-time-regexp end t)))
4932 (and (memq 'timestamp conditions)
4933 (re-search-forward org-ts-regexp end t))
4934 (and (memq 'nottimestamp conditions)
4935 (not (re-search-forward org-ts-regexp end t)))
4936 (and (setq m (memq 'regexp conditions))
4937 (stringp (nth 1 m))
4938 (re-search-forward (nth 1 m) end t))
4939 (and (setq m (memq 'notregexp conditions))
4940 (stringp (nth 1 m))
4941 (not (re-search-forward (nth 1 m) end t)))
4942 (and (or
4943 (setq m (memq 'nottodo conditions))
4944 (setq m (memq 'todo-unblocked conditions))
4945 (setq m (memq 'nottodo-unblocked conditions))
4946 (setq m (memq 'todo conditions)))
4947 (org-agenda-skip-if-todo m end)))
4948 end)))
4950 (defun org-agenda-skip-if-todo (args end)
4951 "Helper function for `org-agenda-skip-if', do not use it directly.
4952 ARGS is a list with first element either `todo', `nottodo',
4953 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4954 a list of TODO keywords, or a state symbol `todo' or `done' or
4955 `any'."
4956 (let ((kw (car args))
4957 (arg (cadr args))
4958 todo-wds todo-re)
4959 (setq todo-wds
4960 (org-uniquify
4961 (cond
4962 ((listp arg) ;; list of keywords
4963 (if (member "*" arg)
4964 (mapcar 'substring-no-properties org-todo-keywords-1)
4965 arg))
4966 ((symbolp arg) ;; keyword class name
4967 (cond
4968 ((eq arg 'todo)
4969 (org-delete-all org-done-keywords
4970 (mapcar 'substring-no-properties
4971 org-todo-keywords-1)))
4972 ((eq arg 'done) org-done-keywords)
4973 ((eq arg 'any)
4974 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4975 (setq todo-re
4976 (concat "^\\*+[ \t]+\\<\\("
4977 (mapconcat 'identity todo-wds "\\|")
4978 "\\)\\>"))
4979 (cond
4980 ((eq kw 'todo) (re-search-forward todo-re end t))
4981 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4982 ((eq kw 'todo-unblocked)
4983 (catch 'unblocked
4984 (while (re-search-forward todo-re end t)
4985 (or (org-entry-blocked-p) (throw 'unblocked t)))
4986 nil))
4987 ((eq kw 'nottodo-unblocked)
4988 (catch 'unblocked
4989 (while (re-search-forward todo-re end t)
4990 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4994 ;;;###autoload
4995 (defun org-agenda-list-stuck-projects (&rest ignore)
4996 "Create agenda view for projects that are stuck.
4997 Stuck projects are project that have no next actions. For the definitions
4998 of what a project is and how to check if it stuck, customize the variable
4999 `org-stuck-projects'."
5000 (interactive)
5001 (let* ((org-agenda-skip-function
5002 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
5003 ;; We could have used org-agenda-skip-if here.
5004 (org-agenda-overriding-header
5005 (or org-agenda-overriding-header "List of stuck projects: "))
5006 (matcher (nth 0 org-stuck-projects))
5007 (todo (nth 1 org-stuck-projects))
5008 (todo-wds (if (member "*" todo)
5009 (progn
5010 (org-agenda-prepare-buffers (org-agenda-files
5011 nil 'ifmode))
5012 (org-delete-all
5013 org-done-keywords-for-agenda
5014 (copy-sequence org-todo-keywords-for-agenda)))
5015 todo))
5016 (todo-re (concat "^\\*+[ \t]+\\("
5017 (mapconcat 'identity todo-wds "\\|")
5018 "\\)\\>"))
5019 (tags (nth 2 org-stuck-projects))
5020 (tags-re (if (member "*" tags)
5021 (concat org-outline-regexp-bol
5022 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
5023 (if tags
5024 (concat org-outline-regexp-bol
5025 ".*:\\("
5026 (mapconcat 'identity tags "\\|")
5027 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
5028 (gen-re (nth 3 org-stuck-projects))
5029 (re-list
5030 (delq nil
5031 (list
5032 (if todo todo-re)
5033 (if tags tags-re)
5034 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
5035 gen-re)))))
5036 (setq org-agenda-skip-regexp
5037 (if re-list
5038 (mapconcat 'identity re-list "\\|")
5039 (error "No information how to identify unstuck projects")))
5040 (org-tags-view nil matcher)
5041 (with-current-buffer org-agenda-buffer-name
5042 (setq org-agenda-redo-command
5043 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
5045 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
5046 Create agenda view for projects that are stuck.
5047 Stuck projects are project that have no next actions. For the definitions
5048 of what a project is and how to check if it stuck, customize the variable
5049 `org-stuck-projects'.
5051 \(fn &rest IGNORE)" t nil)
5053 ;;; Diary integration
5055 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
5056 (defvar diary-list-entries-hook)
5057 (defvar diary-time-regexp)
5058 (defun org-get-entries-from-diary (date)
5059 "Get the (Emacs Calendar) diary entries for DATE."
5060 (require 'diary-lib)
5061 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
5062 (diary-display-hook '(fancy-diary-display))
5063 (diary-display-function 'fancy-diary-display)
5064 (pop-up-frames nil)
5065 (diary-list-entries-hook
5066 (cons 'org-diary-default-entry diary-list-entries-hook))
5067 (diary-file-name-prefix nil) ; turn this feature off
5068 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5069 entries
5070 (org-disable-agenda-to-diary t))
5071 (save-excursion
5072 (save-window-excursion
5073 (funcall (if (fboundp 'diary-list-entries)
5074 'diary-list-entries 'list-diary-entries)
5075 date 1)))
5076 (if (not (get-buffer diary-fancy-buffer))
5077 (setq entries nil)
5078 (with-current-buffer diary-fancy-buffer
5079 (setq buffer-read-only nil)
5080 (if (zerop (buffer-size))
5081 ;; No entries
5082 (setq entries nil)
5083 ;; Omit the date and other unnecessary stuff
5084 (org-agenda-cleanup-fancy-diary)
5085 ;; Add prefix to each line and extend the text properties
5086 (if (zerop (buffer-size))
5087 (setq entries nil)
5088 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5089 (setq entries
5090 (with-temp-buffer
5091 (insert entries) (goto-char (point-min))
5092 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5093 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5094 (replace-match (concat "; " (match-string 1)))))
5095 (buffer-string)))))
5096 (set-buffer-modified-p nil)
5097 (kill-buffer diary-fancy-buffer)))
5098 (when entries
5099 (setq entries (org-split-string entries "\n"))
5100 (setq entries
5101 (mapcar
5102 (lambda (x)
5103 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5104 ;; Extend the text properties to the beginning of the line
5105 (org-add-props x (text-properties-at (1- (length x)) x)
5106 'type "diary" 'date date 'face 'org-agenda-diary))
5107 entries)))))
5109 (defvar org-agenda-cleanup-fancy-diary-hook nil
5110 "Hook run when the fancy diary buffer is cleaned up.")
5112 (defun org-agenda-cleanup-fancy-diary ()
5113 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5114 This gets rid of the date, the underline under the date, and
5115 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5116 date. It also removes lines that contain only whitespace."
5117 (goto-char (point-min))
5118 (if (looking-at ".*?:[ \t]*")
5119 (progn
5120 (replace-match "")
5121 (re-search-forward "\n=+$" nil t)
5122 (replace-match "")
5123 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5124 (re-search-forward "\n=+$" nil t)
5125 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5126 (goto-char (point-min))
5127 (while (re-search-forward "^ +\n" nil t)
5128 (replace-match ""))
5129 (goto-char (point-min))
5130 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5131 (replace-match ""))
5132 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5134 ;; Make sure entries from the diary have the right text properties.
5135 (eval-after-load "diary-lib"
5136 '(if (boundp 'diary-modify-entry-list-string-function)
5137 ;; We can rely on the hook, nothing to do
5139 ;; Hook not available, must use advice to make this work
5140 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5141 "Make the position visible."
5142 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5143 (stringp string)
5144 buffer-file-name)
5145 (setq string (org-modify-diary-entry-string string))))))
5147 (defun org-modify-diary-entry-string (string)
5148 "Add text properties to string, allowing org-mode to act on it."
5149 (org-add-props string nil
5150 'mouse-face 'highlight
5151 'help-echo (if buffer-file-name
5152 (format "mouse-2 or RET jump to diary file %s"
5153 (abbreviate-file-name buffer-file-name))
5155 'org-agenda-diary-link t
5156 'org-marker (org-agenda-new-marker (point-at-bol))))
5158 (defun org-diary-default-entry ()
5159 "Add a dummy entry to the diary.
5160 Needed to avoid empty dates which mess up holiday display."
5161 ;; Catch the error if dealing with the new add-to-diary-alist
5162 (when org-disable-agenda-to-diary
5163 (condition-case nil
5164 (org-add-to-diary-list original-date "Org-mode dummy" "")
5165 (error
5166 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5168 (defun org-add-to-diary-list (&rest args)
5169 (if (fboundp 'diary-add-to-list)
5170 (apply 'diary-add-to-list args)
5171 (apply 'add-to-diary-list args)))
5173 (defvar org-diary-last-run-time nil)
5175 ;;;###autoload
5176 (defun org-diary (&rest args)
5177 "Return diary information from org files.
5178 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5179 It accesses org files and extracts information from those files to be
5180 listed in the diary. The function accepts arguments specifying what
5181 items should be listed. For a list of arguments allowed here, see the
5182 variable `org-agenda-entry-types'.
5184 The call in the diary file should look like this:
5186 &%%(org-diary) ~/path/to/some/orgfile.org
5188 Use a separate line for each org file to check. Or, if you omit the file name,
5189 all files listed in `org-agenda-files' will be checked automatically:
5191 &%%(org-diary)
5193 If you don't give any arguments (as in the example above), the default
5194 arguments (:deadline :scheduled :timestamp :sexp) are used.
5195 So the example above may also be written as
5197 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5199 The function expects the lisp variables `entry' and `date' to be provided
5200 by the caller, because this is how the calendar works. Don't use this
5201 function from a program - use `org-agenda-get-day-entries' instead."
5202 (when (> (- (org-float-time)
5203 org-agenda-last-marker-time)
5205 ;; I am not sure if this works with sticky agendas, because the marker
5206 ;; list is then no longer a global variable.
5207 (org-agenda-reset-markers))
5208 (org-compile-prefix-format 'agenda)
5209 (org-set-sorting-strategy 'agenda)
5210 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5211 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5212 (list entry)
5213 (org-agenda-files t)))
5214 (time (org-float-time))
5215 file rtn results)
5216 (when (or (not org-diary-last-run-time)
5217 (> (- time
5218 org-diary-last-run-time)
5220 (org-agenda-prepare-buffers files))
5221 (setq org-diary-last-run-time time)
5222 ;; If this is called during org-agenda, don't return any entries to
5223 ;; the calendar. Org Agenda will list these entries itself.
5224 (if org-disable-agenda-to-diary (setq files nil))
5225 (while (setq file (pop files))
5226 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5227 (setq results (append results rtn)))
5228 (if results
5229 (concat (org-agenda-finalize-entries results) "\n"))))
5231 (autoload 'org-diary "org-agenda" "\
5232 Return diary information from org files.
5233 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5234 It accesses org files and extracts information from those files to be
5235 listed in the diary. The function accepts arguments specifying what
5236 items should be listed. For a list of arguments allowed here, see the
5237 variable `org-agenda-entry-types'.
5239 The call in the diary file should look like this:
5241 &%%(org-diary) ~/path/to/some/orgfile.org
5243 Use a separate line for each org file to check. Or, if you omit the file name,
5244 all files listed in `org-agenda-files' will be checked automatically:
5246 &%%(org-diary)
5248 If you don't give any arguments (as in the example above), the default
5249 arguments (:deadline :scheduled :timestamp :sexp) are used.
5250 So the example above may also be written as
5252 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5254 The function expects the lisp variables `entry' and `date' to be provided
5255 by the caller, because this is how the calendar works. Don't use this
5256 function from a program - use `org-agenda-get-day-entries' instead.
5258 \(fn &rest ARGS)" nil nil)
5260 ;;; Agenda entry finders
5262 (defun org-agenda-get-day-entries (file date &rest args)
5263 "Does the work for `org-diary' and `org-agenda'.
5264 FILE is the path to a file to be checked for entries. DATE is date like
5265 the one returned by `calendar-current-date'. ARGS are symbols indicating
5266 which kind of entries should be extracted. For details about these, see
5267 the documentation of `org-diary'."
5268 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5269 (let* ((org-startup-folded nil)
5270 (org-startup-align-all-tables nil)
5271 (buffer (if (file-exists-p file)
5272 (org-get-agenda-file-buffer file)
5273 (error "No such file %s" file)))
5274 arg results rtn deadline-results)
5275 (if (not buffer)
5276 ;; If file does not exist, make sure an error message ends up in diary
5277 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5278 (with-current-buffer buffer
5279 (unless (derived-mode-p 'org-mode)
5280 (error "Agenda file %s is not in `org-mode'" file))
5281 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5282 (let ((case-fold-search nil))
5283 (save-excursion
5284 (save-restriction
5285 (if org-agenda-restrict
5286 (narrow-to-region org-agenda-restrict-begin
5287 org-agenda-restrict-end)
5288 (widen))
5289 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5290 (while (setq arg (pop args))
5291 (cond
5292 ((and (eq arg :todo)
5293 (equal date (calendar-gregorian-from-absolute
5294 (org-today))))
5295 (setq rtn (org-agenda-get-todos))
5296 (setq results (append results rtn)))
5297 ((eq arg :timestamp)
5298 (setq rtn (org-agenda-get-blocks))
5299 (setq results (append results rtn))
5300 (setq rtn (org-agenda-get-timestamps deadline-results))
5301 (setq results (append results rtn)))
5302 ((eq arg :sexp)
5303 (setq rtn (org-agenda-get-sexps))
5304 (setq results (append results rtn)))
5305 ((eq arg :scheduled)
5306 (setq rtn (org-agenda-get-scheduled deadline-results))
5307 (setq results (append results rtn)))
5308 ((eq arg :closed)
5309 (setq rtn (org-agenda-get-progress))
5310 (setq results (append results rtn)))
5311 ((eq arg :deadline)
5312 (setq rtn (org-agenda-get-deadlines))
5313 (setq deadline-results (copy-sequence rtn))
5314 (setq results (append results rtn))))))))
5315 results))))
5317 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5318 (defun org-agenda-get-todos ()
5319 "Return the TODO information for agenda display."
5320 (let* ((props (list 'face nil
5321 'done-face 'org-agenda-done
5322 'org-not-done-regexp org-not-done-regexp
5323 'org-todo-regexp org-todo-regexp
5324 'org-complex-heading-regexp org-complex-heading-regexp
5325 'mouse-face 'highlight
5326 'help-echo
5327 (format "mouse-2 or RET jump to org file %s"
5328 (abbreviate-file-name buffer-file-name))))
5329 (regexp (format org-heading-keyword-regexp-format
5330 (cond
5331 ((and org-select-this-todo-keyword
5332 (equal org-select-this-todo-keyword "*"))
5333 org-todo-regexp)
5334 (org-select-this-todo-keyword
5335 (concat "\\("
5336 (mapconcat 'identity
5337 (org-split-string
5338 org-select-this-todo-keyword
5339 "|")
5340 "\\|") "\\)"))
5341 (t org-not-done-regexp))))
5342 marker priority category category-pos level tags todo-state
5343 ee txt beg end inherited-tags)
5344 (goto-char (point-min))
5345 (while (re-search-forward regexp nil t)
5346 (catch :skip
5347 (save-match-data
5348 (beginning-of-line)
5349 (org-agenda-skip)
5350 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5351 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5352 (goto-char (1+ beg))
5353 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5354 (throw :skip nil)))
5355 (goto-char (match-beginning 2))
5356 (setq marker (org-agenda-new-marker (match-beginning 0))
5357 category (org-get-category)
5358 category-pos (get-text-property (point) 'org-category-position)
5359 txt (org-trim
5360 (buffer-substring (match-beginning 2) (match-end 0)))
5361 inherited-tags
5362 (or (eq org-agenda-show-inherited-tags 'always)
5363 (and (listp org-agenda-show-inherited-tags)
5364 (memq 'todo org-agenda-show-inherited-tags))
5365 (and (eq org-agenda-show-inherited-tags t)
5366 (or (eq org-agenda-use-tag-inheritance t)
5367 (memq 'todo org-agenda-use-tag-inheritance))))
5368 tags (org-get-tags-at nil (not inherited-tags))
5369 level (make-string (org-reduced-level (org-outline-level)) ? )
5370 txt (org-agenda-format-item "" txt level category tags t)
5371 priority (1+ (org-get-priority txt))
5372 todo-state (org-get-todo-state))
5373 (org-add-props txt props
5374 'org-marker marker 'org-hd-marker marker
5375 'priority priority 'org-category category
5376 'level level
5377 'org-category-position category-pos
5378 'type "todo" 'todo-state todo-state)
5379 (push txt ee)
5380 (if org-agenda-todo-list-sublevels
5381 (goto-char (match-end 2))
5382 (org-end-of-subtree 'invisible))))
5383 (nreverse ee)))
5385 (defun org-agenda-todo-custom-ignore-p (time n)
5386 "Check whether timestamp is farther away than n number of days.
5387 This function is invoked if `org-agenda-todo-ignore-deadlines',
5388 `org-agenda-todo-ignore-scheduled' or
5389 `org-agenda-todo-ignore-timestamp' is set to an integer."
5390 (let ((days (org-time-stamp-to-now
5391 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5392 (if (>= n 0)
5393 (>= days n)
5394 (<= days n))))
5396 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5397 (&optional end)
5398 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5399 (when (or org-agenda-todo-ignore-with-date
5400 org-agenda-todo-ignore-scheduled
5401 org-agenda-todo-ignore-deadlines
5402 org-agenda-todo-ignore-timestamp)
5403 (setq end (or end (save-excursion (outline-next-heading) (point))))
5404 (save-excursion
5405 (or (and org-agenda-todo-ignore-with-date
5406 (re-search-forward org-ts-regexp end t))
5407 (and org-agenda-todo-ignore-scheduled
5408 (re-search-forward org-scheduled-time-regexp end t)
5409 (cond
5410 ((eq org-agenda-todo-ignore-scheduled 'future)
5411 (> (org-time-stamp-to-now
5412 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5413 ((eq org-agenda-todo-ignore-scheduled 'past)
5414 (<= (org-time-stamp-to-now
5415 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5416 ((numberp org-agenda-todo-ignore-scheduled)
5417 (org-agenda-todo-custom-ignore-p
5418 (match-string 1) org-agenda-todo-ignore-scheduled))
5419 (t)))
5420 (and org-agenda-todo-ignore-deadlines
5421 (re-search-forward org-deadline-time-regexp end t)
5422 (cond
5423 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5424 ((eq org-agenda-todo-ignore-deadlines 'far)
5425 (not (org-deadline-close (match-string 1))))
5426 ((eq org-agenda-todo-ignore-deadlines 'future)
5427 (> (org-time-stamp-to-now
5428 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5429 ((eq org-agenda-todo-ignore-deadlines 'past)
5430 (<= (org-time-stamp-to-now
5431 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5432 ((numberp org-agenda-todo-ignore-deadlines)
5433 (org-agenda-todo-custom-ignore-p
5434 (match-string 1) org-agenda-todo-ignore-deadlines))
5435 (t (org-deadline-close (match-string 1)))))
5436 (and org-agenda-todo-ignore-timestamp
5437 (let ((buffer (current-buffer))
5438 (regexp
5439 (concat
5440 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5441 (start (point)))
5442 ;; Copy current buffer into a temporary one
5443 (with-temp-buffer
5444 (insert-buffer-substring buffer start end)
5445 (goto-char (point-min))
5446 ;; Delete SCHEDULED and DEADLINE items
5447 (while (re-search-forward regexp end t)
5448 (delete-region (match-beginning 0) (match-end 0)))
5449 (goto-char (point-min))
5450 ;; No search for timestamp left
5451 (when (re-search-forward org-ts-regexp nil t)
5452 (cond
5453 ((eq org-agenda-todo-ignore-timestamp 'future)
5454 (> (org-time-stamp-to-now
5455 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5456 ((eq org-agenda-todo-ignore-timestamp 'past)
5457 (<= (org-time-stamp-to-now
5458 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5459 ((numberp org-agenda-todo-ignore-timestamp)
5460 (org-agenda-todo-custom-ignore-p
5461 (match-string 1) org-agenda-todo-ignore-timestamp))
5462 (t))))))))))
5464 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5465 Do we have a reason to ignore this TODO entry because it has a time stamp?
5467 \(fn &optional END)" nil nil)
5469 (defconst org-agenda-no-heading-message
5470 "No heading for this item in buffer or region.")
5472 (defun org-agenda-get-timestamps (&optional deadline-results)
5473 "Return the date stamp information for agenda display."
5474 (let* ((props (list 'face 'org-agenda-calendar-event
5475 'org-not-done-regexp org-not-done-regexp
5476 'org-todo-regexp org-todo-regexp
5477 'org-complex-heading-regexp org-complex-heading-regexp
5478 'mouse-face 'highlight
5479 'help-echo
5480 (format "mouse-2 or RET jump to org file %s"
5481 (abbreviate-file-name buffer-file-name))))
5482 (d1 (calendar-absolute-from-gregorian date))
5484 (deadline-position-alist
5485 (mapcar (lambda (a) (and (setq mm (get-text-property
5486 0 'org-hd-marker a))
5487 (cons (marker-position mm) a)))
5488 deadline-results))
5489 (remove-re org-ts-regexp)
5490 (regexp
5491 (concat
5492 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5493 (regexp-quote
5494 (substring
5495 (format-time-string
5496 (car org-time-stamp-formats)
5497 (apply 'encode-time ; DATE bound by calendar
5498 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5499 1 11))
5500 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5501 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5502 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5503 donep tmp priority category category-pos level ee txt timestr tags
5504 b0 b3 e3 head todo-state end-of-match show-all warntime habitp
5505 inherited-tags)
5506 (goto-char (point-min))
5507 (while (setq end-of-match (re-search-forward regexp nil t))
5508 (setq b0 (match-beginning 0)
5509 b3 (match-beginning 3) e3 (match-end 3)
5510 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5511 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5512 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5513 (member todo-state
5514 org-agenda-repeating-timestamp-show-all)))
5515 (catch :skip
5516 (and (org-at-date-range-p) (throw :skip nil))
5517 (org-agenda-skip)
5518 (if (and (match-end 1)
5519 (not (= d1 (org-time-string-to-absolute
5520 (match-string 1) d1 nil show-all
5521 (current-buffer) b0))))
5522 (throw :skip nil))
5523 (if (and e3
5524 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5525 (throw :skip nil))
5526 (setq tmp (buffer-substring (max (point-min)
5527 (- b0 org-ds-keyword-length))
5529 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5530 inactivep (= (char-after b0) ?\[)
5531 deadlinep (string-match org-deadline-regexp tmp)
5532 scheduledp (string-match org-scheduled-regexp tmp)
5533 closedp (and org-agenda-include-inactive-timestamps
5534 (string-match org-closed-string tmp))
5535 clockp (and org-agenda-include-inactive-timestamps
5536 (or (string-match org-clock-string tmp)
5537 (string-match "]-+\\'" tmp)))
5538 warntime (get-text-property (point) 'org-appt-warntime)
5539 donep (member todo-state org-done-keywords))
5540 (if (or scheduledp deadlinep closedp clockp
5541 (and donep org-agenda-skip-timestamp-if-done))
5542 (throw :skip t))
5543 (if (string-match ">" timestr)
5544 ;; substring should only run to end of time stamp
5545 (setq timestr (substring timestr 0 (match-end 0))))
5546 (setq marker (org-agenda-new-marker b0)
5547 category (org-get-category b0)
5548 category-pos (get-text-property b0 'org-category-position))
5549 (save-excursion
5550 (if (not (re-search-backward org-outline-regexp-bol nil t))
5551 (setq txt org-agenda-no-heading-message)
5552 (goto-char (match-beginning 0))
5553 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5554 (assoc (point) deadline-position-alist))
5555 (throw :skip nil))
5556 (setq hdmarker (org-agenda-new-marker)
5557 inherited-tags
5558 (or (eq org-agenda-show-inherited-tags 'always)
5559 (and (listp org-agenda-show-inherited-tags)
5560 (memq 'agenda org-agenda-show-inherited-tags))
5561 (and (eq org-agenda-show-inherited-tags t)
5562 (or (eq org-agenda-use-tag-inheritance t)
5563 (memq 'agenda org-agenda-use-tag-inheritance))))
5564 tags (org-get-tags-at nil (not inherited-tags))
5565 level (make-string (org-reduced-level (org-outline-level)) ? ))
5566 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5567 (setq head (or (match-string 1) ""))
5568 (setq txt (org-agenda-format-item
5569 (if inactivep org-agenda-inactive-leader nil)
5570 head level category tags timestr
5571 remove-re habitp)))
5572 (setq priority (org-get-priority txt))
5573 (org-add-props txt props 'priority priority
5574 'org-marker marker 'org-hd-marker hdmarker
5575 'org-category category 'date date
5576 'level level
5577 'org-category-position category-pos
5578 'todo-state todo-state
5579 'warntime warntime
5580 'type "timestamp")
5581 (push txt ee))
5582 (if org-agenda-skip-additional-timestamps-same-entry
5583 (outline-next-heading)
5584 (goto-char end-of-match))))
5585 (nreverse ee)))
5587 (defun org-agenda-get-sexps ()
5588 "Return the sexp information for agenda display."
5589 (require 'diary-lib)
5590 (let* ((props (list 'face 'org-agenda-calendar-sexp
5591 'mouse-face 'highlight
5592 'help-echo
5593 (format "mouse-2 or RET jump to org file %s"
5594 (abbreviate-file-name buffer-file-name))))
5595 (regexp "^&?%%(")
5596 marker category extra category-pos level ee txt tags entry
5597 result beg b sexp sexp-entry todo-state warntime inherited-tags)
5598 (goto-char (point-min))
5599 (while (re-search-forward regexp nil t)
5600 (catch :skip
5601 (org-agenda-skip)
5602 (setq beg (match-beginning 0))
5603 (goto-char (1- (match-end 0)))
5604 (setq b (point))
5605 (forward-sexp 1)
5606 (setq sexp (buffer-substring b (point)))
5607 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5608 (org-trim (match-string 1))
5609 ""))
5610 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5611 (when result
5612 (setq marker (org-agenda-new-marker beg)
5613 level (make-string (org-reduced-level (org-outline-level)) ? )
5614 category (org-get-category beg)
5615 category-pos (get-text-property beg 'org-category-position)
5616 inherited-tags
5617 (or (eq org-agenda-show-inherited-tags 'always)
5618 (and (listp org-agenda-show-inherited-tags)
5619 (memq 'agenda org-agenda-show-inherited-tags))
5620 (and (eq org-agenda-show-inherited-tags t)
5621 (or (eq org-agenda-use-tag-inheritance t)
5622 (memq 'agenda org-agenda-use-tag-inheritance))))
5623 tags (org-get-tags-at nil (not inherited-tags))
5624 todo-state (org-get-todo-state)
5625 warntime (get-text-property (point) 'org-appt-warntime)
5626 extra nil)
5628 (dolist (r (if (stringp result)
5629 (list result)
5630 result)) ;; we expect a list here
5631 (when (and org-agenda-diary-sexp-prefix
5632 (string-match org-agenda-diary-sexp-prefix r))
5633 (setq extra (match-string 0 r)
5634 r (replace-match "" nil nil r)))
5635 (if (string-match "\\S-" r)
5636 (setq txt r)
5637 (setq txt "SEXP entry returned empty string"))
5638 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5639 (org-add-props txt props 'org-marker marker
5640 'org-category category 'date date 'todo-state todo-state
5641 'org-category-position category-pos 'tags tags
5642 'level level
5643 'type "sexp" 'warntime warntime)
5644 (push txt ee)))))
5645 (nreverse ee)))
5647 ;; Calendar sanity: define some functions that are independent of
5648 ;; `calendar-date-style'.
5649 ;; Normally I would like to use ISO format when calling the diary functions,
5650 ;; but to make sure we still have Emacs 22 compatibility we bind
5651 ;; also `european-calendar-style' and use european format
5652 (defun org-anniversary (year month day &optional mark)
5653 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5654 (org-no-warnings
5655 (let ((calendar-date-style 'european) (european-calendar-style t))
5656 (diary-anniversary day month year mark))))
5657 (defun org-cyclic (N year month day &optional mark)
5658 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5659 (org-no-warnings
5660 (let ((calendar-date-style 'european) (european-calendar-style t))
5661 (diary-cyclic N day month year mark))))
5662 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5663 "Like `diary-block', but with fixed (ISO) order of arguments."
5664 (org-no-warnings
5665 (let ((calendar-date-style 'european) (european-calendar-style t))
5666 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5667 (defun org-date (year month day &optional mark)
5668 "Like `diary-date', but with fixed (ISO) order of arguments."
5669 (org-no-warnings
5670 (let ((calendar-date-style 'european) (european-calendar-style t))
5671 (diary-date day month year mark))))
5673 ;; Define the` org-class' function
5674 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5675 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5676 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5677 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5678 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5679 `holidays', then any date that is known by the Emacs calendar to be a
5680 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5681 then those holidays will be skipped."
5682 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5683 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5684 (d (calendar-absolute-from-gregorian date))
5685 (h (when skip-weeks (calendar-check-holidays date))))
5686 (and
5687 (<= date1 d)
5688 (<= d date2)
5689 (= (calendar-day-of-week date) dayname)
5690 (or (not skip-weeks)
5691 (progn
5692 (require 'cal-iso)
5693 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5694 (not (or (and h (memq 'holidays skip-weeks))
5695 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5696 entry)))
5698 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5699 "Like `org-class', but honor `calendar-date-style'.
5700 The order of the first 2 times 3 arguments depends on the variable
5701 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5702 So for American calendars, give this as MONTH DAY YEAR, for European as
5703 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5704 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5705 is any number of ISO weeks in the block period for which the item should
5706 be skipped.
5708 This function is here only for backward compatibility and it is deprecated,
5709 please use `org-class' instead."
5710 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5711 (date2 (org-order-calendar-date-args m2 d2 y2)))
5712 (org-class
5713 (nth 2 date1) (car date1) (nth 1 date1)
5714 (nth 2 date2) (car date2) (nth 1 date2)
5715 dayname skip-weeks)))
5716 (make-obsolete 'org-diary-class 'org-class "")
5718 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5719 (defalias 'org-get-closed 'org-agenda-get-progress)
5720 (defun org-agenda-get-progress ()
5721 "Return the logged TODO entries for agenda display."
5722 (let* ((props (list 'mouse-face 'highlight
5723 'org-not-done-regexp org-not-done-regexp
5724 'org-todo-regexp org-todo-regexp
5725 'org-complex-heading-regexp org-complex-heading-regexp
5726 'help-echo
5727 (format "mouse-2 or RET jump to org file %s"
5728 (abbreviate-file-name buffer-file-name))))
5729 (items (if (consp org-agenda-show-log-scoped)
5730 org-agenda-show-log-scoped
5731 (if (eq org-agenda-show-log-scoped 'clockcheck)
5732 '(clock)
5733 org-agenda-log-mode-items)))
5734 (parts
5735 (delq nil
5736 (list
5737 (if (memq 'closed items) (concat "\\<" org-closed-string))
5738 (if (memq 'clock items) (concat "\\<" org-clock-string))
5739 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5740 (parts-re (if parts (mapconcat 'identity parts "\\|")
5741 (error "`org-agenda-log-mode-items' is empty")))
5742 (regexp (concat
5743 "\\(" parts-re "\\)"
5744 " *\\["
5745 (regexp-quote
5746 (substring
5747 (format-time-string
5748 (car org-time-stamp-formats)
5749 (apply 'encode-time ; DATE bound by calendar
5750 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5751 1 11))))
5752 (org-agenda-search-headline-for-time nil)
5753 marker hdmarker priority category category-pos level tags closedp
5754 statep clockp state ee txt extra timestr rest clocked inherited-tags)
5755 (goto-char (point-min))
5756 (while (re-search-forward regexp nil t)
5757 (catch :skip
5758 (org-agenda-skip)
5759 (setq marker (org-agenda-new-marker (match-beginning 0))
5760 closedp (equal (match-string 1) org-closed-string)
5761 statep (equal (string-to-char (match-string 1)) ?-)
5762 clockp (not (or closedp statep))
5763 state (and statep (match-string 2))
5764 category (org-get-category (match-beginning 0))
5765 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5766 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5767 (when (string-match "\\]" timestr)
5768 ;; substring should only run to end of time stamp
5769 (setq rest (substring timestr (match-end 0))
5770 timestr (substring timestr 0 (match-end 0)))
5771 (if (and (not closedp) (not statep)
5772 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5773 rest))
5774 (progn (setq timestr (concat (substring timestr 0 -1)
5775 "-" (match-string 1 rest) "]"))
5776 (setq clocked (match-string 2 rest)))
5777 (setq clocked "-")))
5778 (save-excursion
5779 (setq extra
5780 (cond
5781 ((not org-agenda-log-mode-add-notes) nil)
5782 (statep
5783 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5784 (match-string 1)))
5785 (clockp
5786 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5787 (match-string 1)))))
5788 (if (not (re-search-backward org-outline-regexp-bol nil t))
5789 (setq txt org-agenda-no-heading-message)
5790 (goto-char (match-beginning 0))
5791 (setq hdmarker (org-agenda-new-marker)
5792 inherited-tags
5793 (or (eq org-agenda-show-inherited-tags 'always)
5794 (and (listp org-agenda-show-inherited-tags)
5795 (memq 'todo org-agenda-show-inherited-tags))
5796 (and (eq org-agenda-show-inherited-tags t)
5797 (or (eq org-agenda-use-tag-inheritance t)
5798 (memq 'todo org-agenda-use-tag-inheritance))))
5799 tags (org-get-tags-at nil (not inherited-tags))
5800 level (make-string (org-reduced-level (org-outline-level)) ? ))
5801 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5802 (setq txt (match-string 1))
5803 (when extra
5804 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5805 (setq txt (concat (substring txt 0 (match-beginning 1))
5806 " - " extra " " (match-string 2 txt)))
5807 (setq txt (concat txt " - " extra))))
5808 (setq txt (org-agenda-format-item
5809 (cond
5810 (closedp "Closed: ")
5811 (statep (concat "State: (" state ")"))
5812 (t (concat "Clocked: (" clocked ")")))
5813 txt level category tags timestr)))
5814 (setq priority 100000)
5815 (org-add-props txt props
5816 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5817 'priority priority 'org-category category
5818 'org-category-position category-pos
5819 'level level
5820 'type "closed" 'date date
5821 'undone-face 'org-warning 'done-face 'org-agenda-done)
5822 (push txt ee))
5823 (goto-char (point-at-eol))))
5824 (nreverse ee)))
5826 (defun org-agenda-show-clocking-issues ()
5827 "Add overlays, showing issues with clocking.
5828 See also the user option `org-agenda-clock-consistency-checks'."
5829 (interactive)
5830 (let* ((org-time-clocksum-use-effort-durations nil)
5831 (pl org-agenda-clock-consistency-checks)
5832 (re (concat "^[ \t]*"
5833 org-clock-string
5834 "[ \t]+"
5835 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5836 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5837 (tlstart 0.)
5838 (tlend 0.)
5839 (maxtime (org-hh:mm-string-to-minutes
5840 (or (plist-get pl :max-duration) "24:00")))
5841 (mintime (org-hh:mm-string-to-minutes
5842 (or (plist-get pl :min-duration) 0)))
5843 (maxgap (org-hh:mm-string-to-minutes
5844 ;; default 30:00 means never complain
5845 (or (plist-get pl :max-gap) "30:00")))
5846 (gapok (mapcar 'org-hh:mm-string-to-minutes
5847 (plist-get pl :gap-ok-around)))
5848 (def-face (or (plist-get pl :default-face)
5849 '((:background "DarkRed") (:foreground "white"))))
5850 issue face m te ts dt ov)
5851 (goto-char (point-min))
5852 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5853 (setq issue nil face def-face)
5854 (catch 'next
5855 (setq m (org-get-at-bol 'org-marker)
5856 te nil ts nil)
5857 (unless (and m (markerp m))
5858 (setq issue "No valid clock line") (throw 'next t))
5859 (org-with-point-at m
5860 (save-excursion
5861 (goto-char (point-at-bol))
5862 (unless (looking-at re)
5863 (error "No valid Clock line")
5864 (throw 'next t))
5865 (unless (match-end 3)
5866 (setq issue "No end time"
5867 face (or (plist-get pl :no-end-time-face) face))
5868 (throw 'next t))
5869 (setq ts (match-string 1)
5870 te (match-string 3)
5871 ts (org-float-time
5872 (apply 'encode-time (org-parse-time-string ts)))
5873 te (org-float-time
5874 (apply 'encode-time (org-parse-time-string te)))
5875 dt (- te ts))))
5876 (cond
5877 ((> dt (* 60 maxtime))
5878 ;; a very long clocking chunk
5879 (setq issue (format "Clocking interval is very long: %s"
5880 (org-minutes-to-clocksum-string
5881 (floor (/ (float dt) 60.))))
5882 face (or (plist-get pl :long-face) face)))
5883 ((< dt (* 60 mintime))
5884 ;; a very short clocking chunk
5885 (setq issue (format "Clocking interval is very short: %s"
5886 (org-minutes-to-clocksum-string
5887 (floor (/ (float dt) 60.))))
5888 face (or (plist-get pl :short-face) face)))
5889 ((and (> tlend 0) (< ts tlend))
5890 ;; Two clock entries are overlapping
5891 (setq issue (format "Clocking overlap: %d minutes"
5892 (/ (- tlend ts) 60))
5893 face (or (plist-get pl :overlap-face) face)))
5894 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5895 ;; There is a gap, lets see if we need to report it
5896 (unless (org-agenda-check-clock-gap tlend ts gapok)
5897 (setq issue (format "Clocking gap: %d minutes"
5898 (/ (- ts tlend) 60))
5899 face (or (plist-get pl :gap-face) face))))
5900 (t nil)))
5901 (setq tlend (or te tlend) tlstart (or ts tlstart))
5902 (when issue
5903 ;; OK, there was some issue, add an overlay to show the issue
5904 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5905 (overlay-put ov 'before-string
5906 (concat
5907 (org-add-props
5908 (format "%-43s" (concat " " issue))
5910 'face face)
5911 "\n"))
5912 (overlay-put ov 'evaporate t)))))
5914 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5915 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5916 (catch 'exit
5917 (unless ok-list
5918 ;; there are no OK times for gaps...
5919 (throw 'exit nil))
5920 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5921 ;; This is more than 24 hours, so it is OK.
5922 ;; because we have at least one OK time, that must be in the
5923 ;; 24 hour interval.
5924 (throw 'exit t))
5925 ;; We have a shorter gap.
5926 ;; Now we have to get the minute of the day when these times are
5927 (let* ((t1dec (decode-time (seconds-to-time t1)))
5928 (t2dec (decode-time (seconds-to-time t2)))
5929 ;; compute the minute on the day
5930 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5931 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5932 (when (< min2 min1)
5933 ;; if min2 is smaller than min1, this means it is on the next day.
5934 ;; Wrap it to after midnight.
5935 (setq min2 (+ min2 1440)))
5936 ;; Now check if any of the OK times is in the gap
5937 (mapc (lambda (x)
5938 ;; Wrap the time to after midnight if necessary
5939 (if (< x min1) (setq x (+ x 1440)))
5940 ;; Check if in interval
5941 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5942 ok-list)
5943 ;; Nope, this gap is not OK
5944 nil)))
5946 (defun org-agenda-get-deadlines ()
5947 "Return the deadline information for agenda display."
5948 (let* ((props (list 'mouse-face 'highlight
5949 'org-not-done-regexp org-not-done-regexp
5950 'org-todo-regexp org-todo-regexp
5951 'org-complex-heading-regexp org-complex-heading-regexp
5952 'help-echo
5953 (format "mouse-2 or RET jump to org file %s"
5954 (abbreviate-file-name buffer-file-name))))
5955 (regexp org-deadline-time-regexp)
5956 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5957 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5958 d2 diff dfrac wdays pos pos1 category category-pos level
5959 tags suppress-prewarning ee txt head face s todo-state
5960 show-all upcomingp donep timestr warntime)
5961 (goto-char (point-min))
5962 (while (re-search-forward regexp nil t)
5963 (catch :skip
5964 (org-agenda-skip)
5965 (setq s (match-string 1)
5966 txt nil
5967 pos (1- (match-beginning 1))
5968 todo-state (save-match-data (org-get-todo-state))
5969 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5970 (member todo-state
5971 org-agenda-repeating-timestamp-show-all))
5972 d2 (org-time-string-to-absolute
5973 (match-string 1) d1 'past show-all
5974 (current-buffer) pos)
5975 diff (- d2 d1))
5976 (setq suppress-prewarning
5977 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5978 (let ((item (buffer-substring (point-at-bol)
5979 (point-at-eol))))
5980 (save-match-data
5981 (and (string-match
5982 org-scheduled-time-regexp item)
5983 (match-string 1 item)))))))
5984 (cond
5985 ((not ds) nil)
5986 ;; The current item has a scheduled date (in ds), so
5987 ;; evaluate its prewarning lead time.
5988 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5989 ;; Use global prewarning-restart lead time.
5990 org-agenda-skip-deadline-prewarning-if-scheduled)
5991 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5992 'pre-scheduled)
5993 ;; Set prewarning to no earlier than scheduled.
5994 (min (- d2 (org-time-string-to-absolute
5995 ds d1 'past show-all (current-buffer) pos))
5996 org-deadline-warning-days))
5997 ;; Set prewarning to deadline.
5998 (t 0))))
5999 (setq wdays (if suppress-prewarning
6000 (let ((org-deadline-warning-days suppress-prewarning))
6001 (org-get-wdays s))
6002 (org-get-wdays s))
6003 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
6004 upcomingp (and todayp (> diff 0)))
6005 ;; When to show a deadline in the calendar:
6006 ;; If the expiration is within wdays warning time.
6007 ;; Past-due deadlines are only shown on the current date
6008 (if (and (or (and (<= diff wdays)
6009 (and todayp (not org-agenda-only-exact-dates)))
6010 (= diff 0)))
6011 (save-excursion
6012 ;; (setq todo-state (org-get-todo-state))
6013 (setq donep (member todo-state org-done-keywords))
6014 (if (and donep
6015 (or org-agenda-skip-deadline-if-done
6016 (not (= diff 0))))
6017 (setq txt nil)
6018 (setq category (org-get-category)
6019 warntime (get-text-property (point) 'org-appt-warntime)
6020 category-pos (get-text-property (point) 'org-category-position))
6021 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6022 (setq txt org-agenda-no-heading-message)
6023 (goto-char (match-end 0))
6024 (setq pos1 (match-beginning 0))
6025 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6026 (setq tags (org-get-tags-at pos1 t))
6027 (setq head (buffer-substring-no-properties
6028 (point)
6029 (progn (skip-chars-forward "^\r\n")
6030 (point))))
6031 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6032 (setq timestr
6033 (concat (substring s (match-beginning 1)) " "))
6034 (setq timestr 'time))
6035 (setq txt (org-agenda-format-item
6036 (if (= diff 0)
6037 (car org-agenda-deadline-leaders)
6038 (if (functionp
6039 (nth 1 org-agenda-deadline-leaders))
6040 (funcall
6041 (nth 1 org-agenda-deadline-leaders)
6042 diff date)
6043 (format (nth 1 org-agenda-deadline-leaders)
6044 diff)))
6045 head level category tags
6046 (if (not (= diff 0)) nil timestr)))))
6047 (when txt
6048 (setq face (org-agenda-deadline-face dfrac))
6049 (org-add-props txt props
6050 'org-marker (org-agenda-new-marker pos)
6051 'warntime warntime
6052 'level level
6053 'org-hd-marker (org-agenda-new-marker pos1)
6054 'priority (+ (- diff)
6055 (org-get-priority txt))
6056 'org-category category
6057 'org-category-position category-pos
6058 'todo-state todo-state
6059 'type (if upcomingp "upcoming-deadline" "deadline")
6060 'date (if upcomingp date d2)
6061 'face (if donep 'org-agenda-done face)
6062 'undone-face face 'done-face 'org-agenda-done)
6063 (push txt ee))))))
6064 (nreverse ee)))
6066 (defun org-agenda-deadline-face (fraction)
6067 "Return the face to displaying a deadline item.
6068 FRACTION is what fraction of the head-warning time has passed."
6069 (let ((faces org-agenda-deadline-faces) f)
6070 (catch 'exit
6071 (while (setq f (pop faces))
6072 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
6074 (defun org-agenda-get-scheduled (&optional deadline-results)
6075 "Return the scheduled information for agenda display."
6076 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
6077 'org-todo-regexp org-todo-regexp
6078 'org-complex-heading-regexp org-complex-heading-regexp
6079 'done-face 'org-agenda-done
6080 'mouse-face 'highlight
6081 'help-echo
6082 (format "mouse-2 or RET jump to org file %s"
6083 (abbreviate-file-name buffer-file-name))))
6084 (regexp org-scheduled-time-regexp)
6085 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
6086 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
6088 (deadline-position-alist
6089 (mapcar (lambda (a) (and (setq mm (get-text-property
6090 0 'org-hd-marker a))
6091 (cons (marker-position mm) a)))
6092 deadline-results))
6093 d2 diff pos pos1 category category-pos level tags donep
6094 ee txt head pastschedp todo-state face timestr s habitp show-all
6095 did-habit-check-p warntime inherited-tags)
6096 (goto-char (point-min))
6097 (while (re-search-forward regexp nil t)
6098 (catch :skip
6099 (org-agenda-skip)
6100 (setq s (match-string 1)
6101 txt nil
6102 pos (1- (match-beginning 1))
6103 todo-state (save-match-data (org-get-todo-state))
6104 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6105 (member todo-state
6106 org-agenda-repeating-timestamp-show-all))
6107 d2 (org-time-string-to-absolute
6108 (match-string 1) d1 'past show-all
6109 (current-buffer) pos)
6110 diff (- d2 d1)
6111 warntime (get-text-property (point) 'org-appt-warntime))
6112 (setq pastschedp (and todayp (< diff 0)))
6113 (setq did-habit-check-p nil)
6114 ;; When to show a scheduled item in the calendar:
6115 ;; If it is on or past the date.
6116 (when (or (and (< diff 0)
6117 (< (abs diff) org-scheduled-past-days)
6118 (and todayp (not org-agenda-only-exact-dates)))
6119 (= diff 0)
6120 ;; org-is-habit-p uses org-entry-get, which is expansive
6121 ;; so we go extra mile to only call it once
6122 (and todayp
6123 (boundp 'org-habit-show-all-today)
6124 org-habit-show-all-today
6125 (setq did-habit-check-p t)
6126 (setq habitp (and (functionp 'org-is-habit-p)
6127 (org-is-habit-p)))))
6128 (save-excursion
6129 (setq donep (member todo-state org-done-keywords))
6130 (if (and donep
6131 (or org-agenda-skip-scheduled-if-done
6132 (not (= diff 0))
6133 (and (functionp 'org-is-habit-p)
6134 (org-is-habit-p))))
6135 (setq txt nil)
6136 (setq habitp (if did-habit-check-p habitp
6137 (and (functionp 'org-is-habit-p)
6138 (org-is-habit-p))))
6139 (setq category (org-get-category)
6140 category-pos (get-text-property (point) 'org-category-position))
6141 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6142 (setq txt org-agenda-no-heading-message)
6143 (goto-char (match-end 0))
6144 (setq pos1 (match-beginning 0))
6145 (if habitp
6146 (if (or (not org-habit-show-habits)
6147 (and (not todayp)
6148 (boundp 'org-habit-show-habits-only-for-today)
6149 org-habit-show-habits-only-for-today))
6150 (throw :skip nil))
6151 (if (and
6152 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6153 (and org-agenda-skip-scheduled-if-deadline-is-shown
6154 pastschedp))
6155 (setq mm (assoc pos1 deadline-position-alist)))
6156 (throw :skip nil)))
6157 (setq inherited-tags
6158 (or (eq org-agenda-show-inherited-tags 'always)
6159 (and (listp org-agenda-show-inherited-tags)
6160 (memq 'agenda org-agenda-show-inherited-tags))
6161 (and (eq org-agenda-show-inherited-tags t)
6162 (or (eq org-agenda-use-tag-inheritance t)
6163 (memq 'agenda org-agenda-use-tag-inheritance))))
6165 tags (org-get-tags-at nil (not inherited-tags)))
6166 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6167 (setq head (buffer-substring-no-properties
6168 (point)
6169 (progn (skip-chars-forward "^\r\n") (point))))
6170 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6171 (setq timestr
6172 (concat (substring s (match-beginning 1)) " "))
6173 (setq timestr 'time))
6174 (setq txt (org-agenda-format-item
6175 (if (= diff 0)
6176 (car org-agenda-scheduled-leaders)
6177 (format (nth 1 org-agenda-scheduled-leaders)
6178 (- 1 diff)))
6179 head level category tags
6180 (if (not (= diff 0)) nil timestr)
6181 nil habitp))))
6182 (when txt
6183 (setq face
6184 (cond
6185 ((and (not habitp) pastschedp)
6186 'org-scheduled-previously)
6187 (todayp 'org-scheduled-today)
6188 (t 'org-scheduled))
6189 habitp (and habitp (org-habit-parse-todo)))
6190 (org-add-props txt props
6191 'undone-face face
6192 'face (if donep 'org-agenda-done face)
6193 'org-marker (org-agenda-new-marker pos)
6194 'org-hd-marker (org-agenda-new-marker pos1)
6195 'type (if pastschedp "past-scheduled" "scheduled")
6196 'date (if pastschedp d2 date)
6197 'warntime warntime
6198 'level level
6199 'priority (if habitp
6200 (org-habit-get-priority habitp)
6201 (+ 94 (- 5 diff) (org-get-priority txt)))
6202 'org-category category
6203 'category-position category-pos
6204 'org-habit-p habitp
6205 'todo-state todo-state)
6206 (push txt ee))))))
6207 (nreverse ee)))
6209 (defun org-agenda-get-blocks ()
6210 "Return the date-range information for agenda display."
6211 (let* ((props (list 'face nil
6212 'org-not-done-regexp org-not-done-regexp
6213 'org-todo-regexp org-todo-regexp
6214 'org-complex-heading-regexp org-complex-heading-regexp
6215 'mouse-face 'highlight
6216 'help-echo
6217 (format "mouse-2 or RET jump to org file %s"
6218 (abbreviate-file-name buffer-file-name))))
6219 (regexp org-tr-regexp)
6220 (d0 (calendar-absolute-from-gregorian date))
6221 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6222 level todo-state tags pos head donep inherited-tags)
6223 (goto-char (point-min))
6224 (while (re-search-forward regexp nil t)
6225 (catch :skip
6226 (org-agenda-skip)
6227 (setq pos (point))
6228 (let ((start-time (match-string 1))
6229 (end-time (match-string 2)))
6230 (setq s1 (match-string 1)
6231 s2 (match-string 2)
6232 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6233 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6234 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6235 ;; Only allow days between the limits, because the normal
6236 ;; date stamps will catch the limits.
6237 (save-excursion
6238 (setq todo-state (org-get-todo-state))
6239 (setq donep (member todo-state org-done-keywords))
6240 (if (and donep org-agenda-skip-timestamp-if-done)
6241 (throw :skip t))
6242 (setq marker (org-agenda-new-marker (point)))
6243 (setq category (org-get-category)
6244 category-pos (get-text-property (point) 'org-category-position))
6245 (if (not (re-search-backward org-outline-regexp-bol nil t))
6246 (setq txt org-agenda-no-heading-message)
6247 (goto-char (match-beginning 0))
6248 (setq hdmarker (org-agenda-new-marker (point))
6249 inherited-tags
6250 (or (eq org-agenda-show-inherited-tags 'always)
6251 (and (listp org-agenda-show-inherited-tags)
6252 (memq 'agenda org-agenda-show-inherited-tags))
6253 (and (eq org-agenda-show-inherited-tags t)
6254 (or (eq org-agenda-use-tag-inheritance t)
6255 (memq 'agenda org-agenda-use-tag-inheritance))))
6257 tags (org-get-tags-at nil (not inherited-tags)))
6258 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6259 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6260 (setq head (match-string 1))
6261 (let ((remove-re
6262 (if org-agenda-remove-timeranges-from-blocks
6263 (concat
6264 "<" (regexp-quote s1) ".*?>"
6265 "--"
6266 "<" (regexp-quote s2) ".*?>")
6267 nil)))
6268 (setq txt (org-agenda-format-item
6269 (format
6270 (nth (if (= d1 d2) 0 1)
6271 org-agenda-timerange-leaders)
6272 (1+ (- d0 d1)) (1+ (- d2 d1)))
6273 head level category tags
6274 (cond ((and (= d1 d0) (= d2 d0))
6275 (concat "<" start-time ">--<" end-time ">"))
6276 ((= d1 d0)
6277 (concat "<" start-time ">"))
6278 ((= d2 d0)
6279 (concat "<" end-time ">")))
6280 remove-re))))
6281 (org-add-props txt props
6282 'org-marker marker 'org-hd-marker hdmarker
6283 'type "block" 'date date
6284 'level level
6285 'todo-state todo-state
6286 'priority (org-get-priority txt) 'org-category category
6287 'org-category-position category-pos)
6288 (push txt ee))))
6289 (goto-char pos)))
6290 ;; Sort the entries by expiration date.
6291 (nreverse ee)))
6293 ;;; Agenda presentation and sorting
6295 (defvar org-prefix-has-time nil
6296 "A flag, set by `org-compile-prefix-format'.
6297 The flag is set if the currently compiled format contains a `%t'.")
6298 (defvar org-prefix-has-tag nil
6299 "A flag, set by `org-compile-prefix-format'.
6300 The flag is set if the currently compiled format contains a `%T'.")
6301 (defvar org-prefix-has-effort nil
6302 "A flag, set by `org-compile-prefix-format'.
6303 The flag is set if the currently compiled format contains a `%e'.")
6304 (defvar org-prefix-category-length nil
6305 "Used by `org-compile-prefix-format' to remember the category field width.")
6306 (defvar org-prefix-category-max-length nil
6307 "Used by `org-compile-prefix-format' to remember the category field width.")
6309 (defun org-agenda-get-category-icon (category)
6310 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6311 (dolist (entry org-agenda-category-icon-alist)
6312 (when (org-string-match-p (car entry) category)
6313 (if (listp (cadr entry))
6314 (return (cadr entry))
6315 (return (apply 'create-image (cdr entry)))))))
6317 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6318 remove-re habitp)
6319 "Format TXT to be inserted into the agenda buffer.
6320 In particular, add the prefix and corresponding text properties.
6322 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6323 LEVEL may be a string to replace the `%l' specifier.
6324 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6325 category taken from local variable or file name. It will replace the `%c'
6326 specifier in the format.
6327 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6328 TXT for sorting of this entry, and for the `%t' specifier in the format.
6329 When DOTIME is a string, this string is searched for a time before TXT is.
6330 TAGS can be the tags of the headline.
6331 Any match of REMOVE-RE will be removed from TXT."
6332 ;; We keep the org-prefix-* variable values along with a compiled
6333 ;; formatter, so that multiple agendas existing at the same time do
6334 ;; not step on each other toes.
6336 ;; It was inconvenient to make these variables buffer local in
6337 ;; Agenda buffers, because this function expects to be called with
6338 ;; the buffer where item comes from being current, and not agenda
6339 ;; buffer
6340 (let* ((bindings (car org-prefix-format-compiled))
6341 (formatter (cadr org-prefix-format-compiled)))
6342 (loop for (var value) in bindings
6343 do (set var value))
6344 (save-match-data
6345 ;; Diary entries sometimes have extra whitespace at the beginning
6346 (setq txt (org-trim txt))
6348 ;; Fix the tags part in txt
6349 (setq txt (org-agenda-fix-displayed-tags
6350 txt tags
6351 org-agenda-show-inherited-tags
6352 org-agenda-hide-tags-regexp))
6354 (let* ((category (or category
6355 (if (stringp org-category)
6356 org-category
6357 (and org-category (symbol-name org-category)))
6358 (if buffer-file-name
6359 (file-name-sans-extension
6360 (file-name-nondirectory buffer-file-name))
6361 "")))
6362 (category-icon (org-agenda-get-category-icon category))
6363 (category-icon (if category-icon
6364 (propertize " " 'display category-icon)
6365 ""))
6366 ;; time, tag, effort are needed for the eval of the prefix format
6367 (tag (if tags (nth (1- (length tags)) tags) ""))
6368 time effort neffort
6369 (ts (if dotime (concat
6370 (if (stringp dotime) dotime "")
6371 (and org-agenda-search-headline-for-time txt))))
6372 (time-of-day (and dotime (org-get-time-of-day ts)))
6373 stamp plain s0 s1 s2 rtn srp l
6374 duration thecategory)
6375 (and (derived-mode-p 'org-mode) buffer-file-name
6376 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6377 (when (and dotime time-of-day)
6378 ;; Extract starting and ending time and move them to prefix
6379 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6380 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6381 (setq s0 (match-string 0 ts)
6382 srp (and stamp (match-end 3))
6383 s1 (match-string (if plain 1 2) ts)
6384 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6386 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6387 ;; them, we might want to remove them there to avoid duplication.
6388 ;; The user can turn this off with a variable.
6389 (if (and org-prefix-has-time
6390 org-agenda-remove-times-when-in-prefix (or stamp plain)
6391 (string-match (concat (regexp-quote s0) " *") txt)
6392 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6393 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6394 (= (match-beginning 0) 0)
6396 (setq txt (replace-match "" nil nil txt))))
6397 ;; Normalize the time(s) to 24 hour
6398 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6399 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6401 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6402 (let (org-time-clocksum-use-effort-durations)
6403 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6404 (setq s2
6405 (org-minutes-to-clocksum-string
6406 (+ (org-hh:mm-string-to-minutes s1)
6407 org-agenda-default-appointment-duration)))))
6409 ;; Compute the duration
6410 (when s2
6411 (setq duration (- (org-hh:mm-string-to-minutes s2)
6412 (org-hh:mm-string-to-minutes s1)))))
6414 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6415 txt)
6416 ;; Tags are in the string
6417 (if (or (eq org-agenda-remove-tags t)
6418 (and org-agenda-remove-tags
6419 org-prefix-has-tag))
6420 (setq txt (replace-match "" t t txt))
6421 (setq txt (replace-match
6422 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6423 (match-string 2 txt))
6424 t t txt))))
6425 (when (derived-mode-p 'org-mode)
6426 (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
6427 (when effort
6428 (setq neffort (org-duration-string-to-minutes effort)
6429 effort (setq effort (concat "[" effort "]")))))
6430 ;; prevent erroring out with %e format when there is no effort
6431 (or effort (setq effort ""))
6433 (when remove-re
6434 (while (string-match remove-re txt)
6435 (setq txt (replace-match "" t t txt))))
6437 ;; Set org-heading property on `txt' to mark the start of the
6438 ;; heading.
6439 (add-text-properties 0 (length txt) '(org-heading t) txt)
6441 ;; Prepare the variables needed in the eval of the compiled format
6442 (setq time (cond (s2 (concat
6443 (org-agenda-time-of-day-to-ampm-maybe s1)
6444 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6445 (if org-agenda-timegrid-use-ampm " ")))
6446 (s1 (concat
6447 (org-agenda-time-of-day-to-ampm-maybe s1)
6448 (if org-agenda-timegrid-use-ampm
6449 "........ "
6450 "......")))
6451 (t ""))
6452 extra (or (and (not habitp) extra) "")
6453 category (if (symbolp category) (symbol-name category) category)
6454 thecategory (copy-sequence category)
6455 level (or level ""))
6456 (if (string-match org-bracket-link-regexp category)
6457 (progn
6458 (setq l (if (match-end 3)
6459 (- (match-end 3) (match-beginning 3))
6460 (- (match-end 1) (match-beginning 1))))
6461 (when (< l (or org-prefix-category-length 0))
6462 (setq category (copy-sequence category))
6463 (org-add-props category nil
6464 'extra-space (make-string
6465 (- org-prefix-category-length l 1) ?\ ))))
6466 (if (and org-prefix-category-max-length
6467 (>= (length category) org-prefix-category-max-length))
6468 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6469 ;; Evaluate the compiled format
6470 (setq rtn (concat (eval formatter) txt))
6472 ;; And finally add the text properties
6473 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6474 (org-add-props rtn nil
6475 'org-category (if thecategory (downcase thecategory) category)
6476 'tags (mapcar 'org-downcase-keep-props tags)
6477 'org-highest-priority org-highest-priority
6478 'org-lowest-priority org-lowest-priority
6479 'time-of-day time-of-day
6480 'duration duration
6481 'effort effort
6482 'effort-minutes neffort
6483 'txt txt
6484 'level level
6485 'time time
6486 'extra extra
6487 'format org-prefix-format-compiled
6488 'dotime dotime)))))
6490 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6491 "Remove tags string from TXT, and add a modified list of tags.
6492 The modified list may contain inherited tags, and tags matched by
6493 `org-agenda-hide-tags-regexp' will be removed."
6494 (when (or add-inherited hide-re)
6495 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6496 (setq txt (substring txt 0 (match-beginning 0))))
6497 (setq tags
6498 (delq nil
6499 (mapcar (lambda (tg)
6500 (if (or (and hide-re (string-match hide-re tg))
6501 (and (not add-inherited)
6502 (get-text-property 0 'inherited tg)))
6504 tg))
6505 tags)))
6506 (when tags
6507 (let ((have-i (get-text-property 0 'inherited (car tags)))
6509 (setq txt (concat txt " :"
6510 (mapconcat
6511 (lambda (x)
6512 (setq i (get-text-property 0 'inherited x))
6513 (if (and have-i (not i))
6514 (progn
6515 (setq have-i nil)
6516 (concat ":" x))
6518 tags ":")
6519 (if have-i "::" ":"))))))
6520 txt)
6522 (defun org-downcase-keep-props (s)
6523 (let ((props (text-properties-at 0 s)))
6524 (setq s (downcase s))
6525 (add-text-properties 0 (length s) props s)
6528 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6529 (defvar org-agenda-sorting-strategy-selected nil)
6531 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6532 "Add a time-grid for agenda items which need it.
6534 LIST is the list of agenda items formatted by `org-agenda-list'.
6535 NDAYS is the span of the current agenda view.
6536 TODAYP is `t' when the current agenda view is on today."
6537 (catch 'exit
6538 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6539 ((and todayp (member 'today (car org-agenda-time-grid))))
6540 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6541 ((member 'weekly (car org-agenda-time-grid)))
6542 (t (throw 'exit list)))
6543 (let* ((have (delq nil (mapcar
6544 (lambda (x) (get-text-property 1 'time-of-day x))
6545 list)))
6546 (string (nth 1 org-agenda-time-grid))
6547 (gridtimes (nth 2 org-agenda-time-grid))
6548 (req (car org-agenda-time-grid))
6549 (remove (member 'remove-match req))
6550 new time)
6551 (if (and (member 'require-timed req) (not have))
6552 ;; don't show empty grid
6553 (throw 'exit list))
6554 (while (setq time (pop gridtimes))
6555 (unless (and remove (member time have))
6556 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6557 (push (org-agenda-format-item
6558 nil string nil "" nil
6559 (concat (substring time 0 -2) ":" (substring time -2)))
6560 new)
6561 (put-text-property
6562 2 (length (car new)) 'face 'org-time-grid (car new))))
6563 (when (and todayp org-agenda-show-current-time-in-grid)
6564 (push (org-agenda-format-item
6565 nil org-agenda-current-time-string nil "" nil
6566 (format-time-string "%H:%M "))
6567 new)
6568 (put-text-property
6569 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6571 (if (member 'time-up org-agenda-sorting-strategy-selected)
6572 (append new list)
6573 (append list new)))))
6575 (defun org-compile-prefix-format (key)
6576 "Compile the prefix format into a Lisp form that can be evaluated.
6577 The resulting form and associated variable bindings is returned
6578 and stored in the variable `org-prefix-format-compiled'."
6579 (setq org-prefix-has-time nil
6580 org-prefix-has-tag nil
6581 org-prefix-category-length nil
6582 org-prefix-has-effort nil)
6583 (let ((s (cond
6584 ((stringp org-agenda-prefix-format)
6585 org-agenda-prefix-format)
6586 ((assq key org-agenda-prefix-format)
6587 (cdr (assq key org-agenda-prefix-format)))
6588 (t " %-12:c%?-12t% s")))
6589 (start 0)
6590 varform vars var e c f opt)
6591 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6592 s start)
6593 (setq var (or (cdr (assoc (match-string 4 s)
6594 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6595 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6596 'eval)
6597 c (or (match-string 3 s) "")
6598 opt (match-beginning 1)
6599 start (1+ (match-beginning 0)))
6600 (if (equal var 'time) (setq org-prefix-has-time t))
6601 (if (equal var 'tag) (setq org-prefix-has-tag t))
6602 (if (equal var 'effort) (setq org-prefix-has-effort t))
6603 (setq f (concat "%" (match-string 2 s) "s"))
6604 (when (equal var 'category)
6605 (setq org-prefix-category-length
6606 (floor (abs (string-to-number (match-string 2 s)))))
6607 (setq org-prefix-category-max-length
6608 (let ((x (match-string 2 s)))
6609 (save-match-data
6610 (if (string-match "\\.[0-9]+" x)
6611 (string-to-number (substring (match-string 0 x) 1)))))))
6612 (if (eq var 'eval)
6613 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6614 (if opt
6615 (setq varform
6616 `(if (equal "" ,var)
6618 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6619 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6620 (setq s (replace-match "%s" t nil s))
6621 (push varform vars))
6622 (setq vars (nreverse vars))
6623 (with-current-buffer (or org-agenda-buffer (current-buffer))
6624 (setq org-prefix-format-compiled
6625 (list
6626 `((org-prefix-has-time ,org-prefix-has-time)
6627 (org-prefix-has-tag ,org-prefix-has-tag)
6628 (org-prefix-category-length ,org-prefix-category-length)
6629 (org-prefix-has-effort ,org-prefix-has-effort))
6630 `(format ,s ,@vars))))))
6632 (defun org-set-sorting-strategy (key)
6633 (if (symbolp (car org-agenda-sorting-strategy))
6634 ;; the old format
6635 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6636 (setq org-agenda-sorting-strategy-selected
6637 (or (cdr (assq key org-agenda-sorting-strategy))
6638 (cdr (assq 'agenda org-agenda-sorting-strategy))
6639 '(time-up category-keep priority-down)))))
6641 (defun org-get-time-of-day (s &optional string mod24)
6642 "Check string S for a time of day.
6643 If found, return it as a military time number between 0 and 2400.
6644 If not found, return nil.
6645 The optional STRING argument forces conversion into a 5 character wide string
6646 HH:MM."
6647 (save-match-data
6648 (when
6649 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6650 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6651 (let* ((h (string-to-number (match-string 1 s)))
6652 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6653 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6654 (am-p (equal ampm "am"))
6655 (h1 (cond ((not ampm) h)
6656 ((= h 12) (if am-p 0 12))
6657 (t (+ h (if am-p 0 12)))))
6658 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6659 (mod h1 24) h1))
6660 (t0 (+ (* 100 h2) m))
6661 (t1 (concat (if (>= h1 24) "+" " ")
6662 (if (and org-agenda-time-leading-zero
6663 (< t0 1000)) "0" "")
6664 (if (< t0 100) "0" "")
6665 (if (< t0 10) "0" "")
6666 (int-to-string t0))))
6667 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6669 (defvar org-agenda-before-sorting-filter-function nil
6670 "Function to be applied to agenda items prior to sorting.
6671 Prior to sorting also means just before they are inserted into the agenda.
6673 To aid sorting, you may revisit the original entries and add more text
6674 properties which will later be used by the sorting functions.
6676 The function should take a string argument, an agenda line.
6677 It has access to the text properties in that line, which contain among
6678 other things, the property `org-hd-marker' that points to the entry
6679 where the line comes from. Note that not all lines going into the agenda
6680 have this property, only most.
6682 The function should return the modified string. It is probably best
6683 to ONLY change text properties.
6685 You can also use this function as a filter, by returning nil for lines
6686 you don't want to have in the agenda at all. For this application, you
6687 could bind the variable in the options section of a custom command.")
6689 (defun org-agenda-finalize-entries (list &optional nosort)
6690 "Sort and concatenate the agenda items."
6691 (setq list (mapcar 'org-agenda-highlight-todo list))
6692 (if nosort
6693 list
6694 (when org-agenda-before-sorting-filter-function
6695 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6696 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6698 (defun org-agenda-highlight-todo (x)
6699 (let ((org-done-keywords org-done-keywords-for-agenda)
6700 (case-fold-search nil)
6702 (if (eq x 'line)
6703 (save-excursion
6704 (beginning-of-line 1)
6705 (setq re (org-get-at-bol 'org-todo-regexp))
6706 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6707 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6708 (add-text-properties (match-beginning 0) (match-end 1)
6709 (list 'face (org-get-todo-face 1)))
6710 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6711 (delete-region (match-beginning 1) (1- (match-end 0)))
6712 (goto-char (match-beginning 1))
6713 (insert (format org-agenda-todo-keyword-format s)))))
6714 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6715 (setq re (get-text-property 0 'org-todo-regexp x))
6716 (when (and re
6717 ;; Test `pl' because if there's no heading content,
6718 ;; there's no point matching to highlight. Note
6719 ;; that if we didn't test `pl' first, and there
6720 ;; happened to be no keyword from `org-todo-regexp'
6721 ;; on this heading line, then the `equal' comparison
6722 ;; afterwards would spuriously succeed in the case
6723 ;; where `pl' is nil -- causing an args-out-of-range
6724 ;; error when we try to add text properties to text
6725 ;; that isn't there.
6727 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6728 x pl) pl))
6729 (add-text-properties
6730 (or (match-end 1) (match-end 0)) (match-end 0)
6731 (list 'face (org-get-todo-face (match-string 2 x)))
6733 (when (match-end 1)
6734 (setq x (concat (substring x 0 (match-end 1))
6735 (format org-agenda-todo-keyword-format
6736 (match-string 2 x))
6737 (org-add-props " " (text-properties-at 0 x))
6738 (substring x (match-end 3)))))))
6739 x)))
6741 (defsubst org-cmp-priority (a b)
6742 "Compare the priorities of string A and B."
6743 (let ((pa (or (get-text-property 1 'priority a) 0))
6744 (pb (or (get-text-property 1 'priority b) 0)))
6745 (cond ((> pa pb) +1)
6746 ((< pa pb) -1))))
6748 (defsubst org-cmp-effort (a b)
6749 "Compare the effort values of string A and B."
6750 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6751 (ea (or (get-text-property 1 'effort-minutes a) def))
6752 (eb (or (get-text-property 1 'effort-minutes b) def)))
6753 (cond ((> ea eb) +1)
6754 ((< ea eb) -1))))
6756 (defsubst org-cmp-category (a b)
6757 "Compare the string values of categories of strings A and B."
6758 (let ((ca (or (get-text-property 1 'org-category a) ""))
6759 (cb (or (get-text-property 1 'org-category b) "")))
6760 (cond ((string-lessp ca cb) -1)
6761 ((string-lessp cb ca) +1))))
6763 (defsubst org-cmp-todo-state (a b)
6764 "Compare the todo states of strings A and B."
6765 (let* ((ma (or (get-text-property 1 'org-marker a)
6766 (get-text-property 1 'org-hd-marker a)))
6767 (mb (or (get-text-property 1 'org-marker b)
6768 (get-text-property 1 'org-hd-marker b)))
6769 (fa (and ma (marker-buffer ma)))
6770 (fb (and mb (marker-buffer mb)))
6771 (todo-kwds
6772 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6773 (and fb (with-current-buffer fb org-todo-keywords-1))))
6774 (ta (or (get-text-property 1 'todo-state a) ""))
6775 (tb (or (get-text-property 1 'todo-state b) ""))
6776 (la (- (length (member ta todo-kwds))))
6777 (lb (- (length (member tb todo-kwds))))
6778 (donepa (member ta org-done-keywords-for-agenda))
6779 (donepb (member tb org-done-keywords-for-agenda)))
6780 (cond ((and donepa (not donepb)) -1)
6781 ((and (not donepa) donepb) +1)
6782 ((< la lb) -1)
6783 ((< lb la) +1))))
6785 (defsubst org-cmp-alpha (a b)
6786 "Compare the headlines, alphabetically."
6787 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6788 (plb (text-property-any 0 (length b) 'org-heading t b))
6789 (ta (and pla (substring a pla)))
6790 (tb (and plb (substring b plb))))
6791 (when pla
6792 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6793 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6794 (setq ta (substring ta (match-end 0))))
6795 (setq ta (downcase ta)))
6796 (when plb
6797 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6798 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6799 (setq tb (substring tb (match-end 0))))
6800 (setq tb (downcase tb)))
6801 (cond ((not ta) +1)
6802 ((not tb) -1)
6803 ((string-lessp ta tb) -1)
6804 ((string-lessp tb ta) +1))))
6806 (defsubst org-cmp-tag (a b)
6807 "Compare the string values of the first tags of A and B."
6808 (let ((ta (car (last (get-text-property 1 'tags a))))
6809 (tb (car (last (get-text-property 1 'tags b)))))
6810 (cond ((not ta) +1)
6811 ((not tb) -1)
6812 ((string-lessp ta tb) -1)
6813 ((string-lessp tb ta) +1))))
6815 (defsubst org-cmp-time (a b)
6816 "Compare the time-of-day values of strings A and B."
6817 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6818 (ta (or (get-text-property 1 'time-of-day a) def))
6819 (tb (or (get-text-property 1 'time-of-day b) def)))
6820 (cond ((< ta tb) -1)
6821 ((< tb ta) +1))))
6823 (defsubst org-cmp-habit-p (a b)
6824 "Compare the todo states of strings A and B."
6825 (let ((ha (get-text-property 1 'org-habit-p a))
6826 (hb (get-text-property 1 'org-habit-p b)))
6827 (cond ((and ha (not hb)) -1)
6828 ((and (not ha) hb) +1))))
6830 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6832 (defun org-entries-lessp (a b)
6833 "Predicate for sorting agenda entries."
6834 ;; The following variables will be used when the form is evaluated.
6835 ;; So even though the compiler complains, keep them.
6836 (let* ((ss org-agenda-sorting-strategy-selected)
6837 (time-up (and (org-em 'time-up 'time-down ss)
6838 (org-cmp-time a b)))
6839 (time-down (if time-up (- time-up) nil))
6840 (priority-up (and (org-em 'priority-up 'priority-down ss)
6841 (org-cmp-priority a b)))
6842 (priority-down (if priority-up (- priority-up) nil))
6843 (effort-up (and (org-em 'effort-up 'effort-down ss)
6844 (org-cmp-effort a b)))
6845 (effort-down (if effort-up (- effort-up) nil))
6846 (category-up (and (or (org-em 'category-up 'category-down ss)
6847 (memq 'category-keep ss))
6848 (org-cmp-category a b)))
6849 (category-down (if category-up (- category-up) nil))
6850 (category-keep (if category-up +1 nil))
6851 (tag-up (and (org-em 'tag-up 'tag-down ss)
6852 (org-cmp-tag a b)))
6853 (tag-down (if tag-up (- tag-up) nil))
6854 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6855 (org-cmp-todo-state a b)))
6856 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6857 (habit-up (and (org-em 'habit-up 'habit-down ss)
6858 (org-cmp-habit-p a b)))
6859 (habit-down (if habit-up (- habit-up) nil))
6860 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6861 (org-cmp-alpha a b)))
6862 (alpha-down (if alpha-up (- alpha-up) nil))
6863 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6864 user-defined-up user-defined-down)
6865 (if (and need-user-cmp org-agenda-cmp-user-defined
6866 (functionp org-agenda-cmp-user-defined))
6867 (setq user-defined-up
6868 (funcall org-agenda-cmp-user-defined a b)
6869 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6870 (cdr (assoc
6871 (eval (cons 'or org-agenda-sorting-strategy-selected))
6872 '((-1 . t) (1 . nil) (nil . nil))))))
6874 ;;; Agenda restriction lock
6876 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6877 "Overlay to mark the headline to which agenda commands are restricted.")
6878 (overlay-put org-agenda-restriction-lock-overlay
6879 'face 'org-agenda-restriction-lock)
6880 (overlay-put org-agenda-restriction-lock-overlay
6881 'help-echo "Agendas are currently limited to this subtree.")
6882 (org-detach-overlay org-agenda-restriction-lock-overlay)
6884 (defun org-agenda-set-restriction-lock (&optional type)
6885 "Set restriction lock for agenda, to current subtree or file.
6886 Restriction will be the file if TYPE is `file', or if type is the
6887 universal prefix '(4), or if the cursor is before the first headline
6888 in the file. Otherwise, restriction will be to the current subtree."
6889 (interactive "P")
6890 (and (equal type '(4)) (setq type 'file))
6891 (setq type (cond
6892 (type type)
6893 ((org-at-heading-p) 'subtree)
6894 ((condition-case nil (org-back-to-heading t) (error nil))
6895 'subtree)
6896 (t 'file)))
6897 (if (eq type 'subtree)
6898 (progn
6899 (setq org-agenda-restrict t)
6900 (setq org-agenda-overriding-restriction 'subtree)
6901 (put 'org-agenda-files 'org-restrict
6902 (list (buffer-file-name (buffer-base-buffer))))
6903 (org-back-to-heading t)
6904 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6905 (move-marker org-agenda-restrict-begin (point))
6906 (move-marker org-agenda-restrict-end
6907 (save-excursion (org-end-of-subtree t)))
6908 (message "Locking agenda restriction to subtree"))
6909 (put 'org-agenda-files 'org-restrict
6910 (list (buffer-file-name (buffer-base-buffer))))
6911 (setq org-agenda-restrict nil)
6912 (setq org-agenda-overriding-restriction 'file)
6913 (move-marker org-agenda-restrict-begin nil)
6914 (move-marker org-agenda-restrict-end nil)
6915 (message "Locking agenda restriction to file"))
6916 (setq current-prefix-arg nil)
6917 (org-agenda-maybe-redo))
6919 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6920 "Remove the agenda restriction lock."
6921 (interactive "P")
6922 (org-detach-overlay org-agenda-restriction-lock-overlay)
6923 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6924 (setq org-agenda-overriding-restriction nil)
6925 (setq org-agenda-restrict nil)
6926 (put 'org-agenda-files 'org-restrict nil)
6927 (move-marker org-agenda-restrict-begin nil)
6928 (move-marker org-agenda-restrict-end nil)
6929 (setq current-prefix-arg nil)
6930 (message "Agenda restriction lock removed")
6931 (or noupdate (org-agenda-maybe-redo)))
6933 (defun org-agenda-maybe-redo ()
6934 "If there is any window showing the agenda view, update it."
6935 (let ((w (get-buffer-window org-agenda-buffer-name t))
6936 (w0 (selected-window)))
6937 (when w
6938 (select-window w)
6939 (org-agenda-redo)
6940 (select-window w0)
6941 (if org-agenda-overriding-restriction
6942 (message "Agenda view shifted to new %s restriction"
6943 org-agenda-overriding-restriction)
6944 (message "Agenda restriction lock removed")))))
6946 ;;; Agenda commands
6948 (defun org-agenda-check-type (error &rest types)
6949 "Check if agenda buffer is of allowed type.
6950 If ERROR is non-nil, throw an error, otherwise just return nil.
6951 Allowed types are 'agenda 'timeline 'todo 'tags 'search."
6952 (if (not org-agenda-type)
6953 (error "No Org agenda currently displayed")
6954 (if (memq org-agenda-type types)
6956 (if error
6957 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6958 nil))))
6960 (defun org-agenda-Quit ()
6961 "Exit the agenda and kill buffers loaded by `org-agenda'.
6962 Also restore the window configuration."
6963 (interactive)
6964 (if org-agenda-columns-active
6965 (org-columns-quit)
6966 (let ((buf (current-buffer)))
6967 (if (eq org-agenda-window-setup 'other-frame)
6968 (progn
6969 (org-agenda-reset-markers)
6970 (kill-buffer buf)
6971 (org-columns-remove-overlays)
6972 (setq org-agenda-archives-mode nil)
6973 (delete-frame))
6974 (and (not (eq org-agenda-window-setup 'current-window))
6975 (not (one-window-p))
6976 (delete-window))
6977 (org-agenda-reset-markers)
6978 (kill-buffer buf)
6979 (org-columns-remove-overlays)
6980 (setq org-agenda-archives-mode nil)))
6981 ;; Maybe restore the pre-agenda window configuration.
6982 (and org-agenda-restore-windows-after-quit
6983 (not (eq org-agenda-window-setup 'other-frame))
6984 org-agenda-pre-window-conf
6985 (set-window-configuration org-agenda-pre-window-conf)
6986 (setq org-agenda-pre-window-conf nil))))
6988 (defun org-agenda-quit ()
6989 "Exit the agenda and restore the window configuration.
6990 When `org-agenda-sticky' is non-nil, only bury the agenda."
6991 (interactive)
6992 (if (and (eq org-indirect-buffer-display 'other-window)
6993 org-last-indirect-buffer)
6994 (let ((org-last-indirect-window
6995 (get-buffer-window org-last-indirect-buffer)))
6996 (if org-last-indirect-window
6997 (delete-window org-last-indirect-window))))
6998 (if org-agenda-columns-active
6999 (org-columns-quit)
7000 (if org-agenda-sticky
7001 (let ((buf (current-buffer)))
7002 (if (eq org-agenda-window-setup 'other-frame)
7003 (progn
7004 (delete-frame))
7005 (and (not (eq org-agenda-window-setup 'current-window))
7006 (not (one-window-p))
7007 (delete-window)))
7008 (with-current-buffer buf
7009 (bury-buffer)
7010 ;; Maybe restore the pre-agenda window configuration.
7011 (and org-agenda-restore-windows-after-quit
7012 (not (eq org-agenda-window-setup 'other-frame))
7013 org-agenda-pre-window-conf
7014 (set-window-configuration org-agenda-pre-window-conf)
7015 (setq org-agenda-pre-window-conf nil))))
7016 (org-agenda-Quit))))
7018 (defun org-agenda-exit ()
7019 "Exit the agenda and restore the window configuration.
7020 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
7021 buffers visited directly by the user will not be touched."
7022 (interactive)
7023 (org-release-buffers org-agenda-new-buffers)
7024 (setq org-agenda-new-buffers nil)
7025 (org-agenda-Quit))
7027 (defun org-agenda-kill-all-agenda-buffers ()
7028 "Kill all buffers in `org-agenda-mode'.
7029 This is used when toggling sticky agendas.
7030 You can also explicitly invoke it with `C-c a C-k'."
7031 (interactive)
7032 (let (blist)
7033 (dolist (buf (buffer-list))
7034 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
7035 (push buf blist)))
7036 (mapc 'kill-buffer blist)))
7038 (defun org-agenda-execute (arg)
7039 "Execute another agenda command, keeping same window.
7040 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
7041 in the agenda."
7042 (interactive "P")
7043 (let ((org-agenda-window-setup 'current-window))
7044 (org-agenda arg)))
7046 (defun org-agenda-redo (&optional all)
7047 "Rebuild possibly ALL agenda view(s) in the current buffer."
7048 (interactive "P")
7049 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
7050 (cpa (unless (eq all t) current-prefix-arg))
7051 (org-agenda-doing-sticky-redo org-agenda-sticky)
7052 (org-agenda-sticky nil)
7053 (org-agenda-buffer-name (or org-agenda-this-buffer-name
7054 org-agenda-buffer-name))
7055 (org-agenda-keep-modes t)
7056 (tag-filter org-agenda-tag-filter)
7057 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
7058 (top-cat-filter org-agenda-top-category-filter)
7059 (cat-filter org-agenda-category-filter)
7060 (cat-preset (get 'org-agenda-category-filter :preset-filter))
7061 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
7062 (cols org-agenda-columns-active)
7063 (line (org-current-line))
7064 (window-line (- line (org-current-line (window-start))))
7065 (lprops (get 'org-agenda-redo-command 'org-lprops))
7066 (redo-cmd (get-text-property p 'org-redo-cmd))
7067 (last-args (get-text-property p 'org-last-args))
7068 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
7069 (org-agenda-overriding-cmd-arguments
7070 (unless (eq all t)
7071 (cond ((listp last-args)
7072 (cons (or cpa (car last-args)) (cdr last-args)))
7073 ((stringp last-args)
7074 last-args))))
7075 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
7076 (put 'org-agenda-tag-filter :preset-filter nil)
7077 (put 'org-agenda-category-filter :preset-filter nil)
7078 (and cols (org-columns-quit))
7079 (message "Rebuilding agenda buffer...")
7080 (if series-redo-cmd
7081 (eval series-redo-cmd)
7082 (org-let lprops '(eval redo-cmd)))
7083 (setq org-agenda-undo-list nil
7084 org-agenda-pending-undo-list nil)
7085 (message "Rebuilding agenda buffer...done")
7086 (put 'org-agenda-tag-filter :preset-filter tag-preset)
7087 (put 'org-agenda-category-filter :preset-filter cat-preset)
7088 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
7089 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
7090 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
7091 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
7092 (org-goto-line line)
7093 (recenter window-line)))
7095 (defvar org-global-tags-completion-table nil)
7096 (defvar org-agenda-filter-form nil)
7097 (defvar org-agenda-filtered-by-category nil)
7099 (defun org-agenda-filter-by-category (strip)
7100 "Keep only those lines in the agenda buffer that have a specific category.
7101 The category is that of the current line."
7102 (interactive "P")
7103 (if (and org-agenda-filtered-by-category
7104 org-agenda-category-filter)
7105 (org-agenda-filter-show-all-cat)
7106 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
7107 (if cat (org-agenda-filter-apply
7108 (list (concat (if strip "-" "+") cat)) 'category)
7109 (error "No category at point")))))
7111 (defun org-find-top-category (&optional pos)
7112 (save-excursion
7113 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7114 (if pos (goto-char pos))
7115 ;; Skip up to the topmost parent
7116 (while (ignore-errors (outline-up-heading 1) t))
7117 (ignore-errors
7118 (nth 4 (org-heading-components))))))
7120 (defvar org-agenda-filtered-by-top-category nil)
7122 (defun org-agenda-filter-by-top-category (strip)
7123 "Keep only those lines in the agenda buffer that have a specific category.
7124 The category is that of the current line."
7125 (interactive "P")
7126 (if org-agenda-filtered-by-top-category
7127 (progn
7128 (setq org-agenda-filtered-by-top-category nil
7129 org-agenda-top-category-filter nil)
7130 (org-agenda-filter-show-all-cat))
7131 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7132 (if cat (org-agenda-filter-top-category-apply cat strip)
7133 (error "No top-level category at point")))))
7135 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7136 "Keep only those lines in the agenda buffer that have a specific tag.
7137 The tag is selected with its fast selection letter, as configured.
7138 With prefix argument STRIP, remove all lines that do have the tag.
7139 A lisp caller can specify CHAR. NARROW means that the new tag should be
7140 used to narrow the search - the interactive user can also press `-' or `+'
7141 to switch to narrowing."
7142 (interactive "P")
7143 (let* ((alist org-tag-alist-for-agenda)
7144 (tag-chars (mapconcat
7145 (lambda (x) (if (and (not (symbolp (car x)))
7146 (cdr x))
7147 (char-to-string (cdr x))
7148 ""))
7149 alist ""))
7150 (efforts (org-split-string
7151 (or (cdr (assoc (concat org-effort-property "_ALL")
7152 org-global-properties))
7153 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7154 "")))
7155 (effort-op org-agenda-filter-effort-default-operator)
7156 (effort-prompt "")
7157 (inhibit-read-only t)
7158 (current org-agenda-tag-filter)
7159 maybe-refresh a n tag)
7160 (unless char
7161 (message
7162 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7163 (if narrow "Narrow" "Filter") tag-chars
7164 (if org-agenda-auto-exclude-function "[RET], " ""))
7165 (setq char (read-char-exclusive)))
7166 (when (member char '(?+ ?-))
7167 ;; Narrowing down
7168 (cond ((equal char ?-) (setq strip t narrow t))
7169 ((equal char ?+) (setq strip nil narrow t)))
7170 (message
7171 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7172 (setq char (read-char-exclusive)))
7173 (when (member char '(?< ?> ?= ??))
7174 ;; An effort operator
7175 (setq effort-op (char-to-string char))
7176 (setq alist nil) ; to make sure it will be interpreted as effort.
7177 (unless (equal char ??)
7178 (loop for i from 0 to 9 do
7179 (setq effort-prompt
7180 (concat
7181 effort-prompt " ["
7182 (if (= i 9) "0" (int-to-string (1+ i)))
7183 "]" (nth i efforts))))
7184 (message "Effort%s: %s " effort-op effort-prompt)
7185 (setq char (read-char-exclusive))
7186 (when (or (< char ?0) (> char ?9))
7187 (error "Need 1-9,0 to select effort"))))
7188 (when (equal char ?\t)
7189 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7190 (org-set-local 'org-global-tags-completion-table
7191 (org-global-tags-completion-table)))
7192 (let ((completion-ignore-case t))
7193 (setq tag (org-icompleting-read
7194 "Tag: " org-global-tags-completion-table))))
7195 (cond
7196 ((equal char ?\r)
7197 (org-agenda-filter-show-all-tag)
7198 (when org-agenda-auto-exclude-function
7199 (setq org-agenda-tag-filter '())
7200 (dolist (tag (org-agenda-get-represented-tags))
7201 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7202 (if modifier
7203 (push modifier org-agenda-tag-filter))))
7204 (if (not (null org-agenda-tag-filter))
7205 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7206 (setq maybe-refresh t))
7207 ((equal char ?/)
7208 (org-agenda-filter-show-all-tag)
7209 (when (get 'org-agenda-tag-filter :preset-filter)
7210 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7211 (setq maybe-refresh t))
7212 ((equal char ?. )
7213 (setq org-agenda-tag-filter
7214 (mapcar (lambda(tag) (concat "+" tag))
7215 (org-get-at-bol 'tags)))
7216 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7217 (setq maybe-refresh t))
7218 ((or (equal char ?\ )
7219 (setq a (rassoc char alist))
7220 (and (>= char ?0) (<= char ?9)
7221 (setq n (if (= char ?0) 9 (- char ?0 1))
7222 tag (concat effort-op (nth n efforts))
7223 a (cons tag nil)))
7224 (and (= char ??)
7225 (setq tag "?eff")
7226 a (cons tag nil))
7227 (and tag (setq a (cons tag nil))))
7228 (org-agenda-filter-show-all-tag)
7229 (setq tag (car a))
7230 (setq org-agenda-tag-filter
7231 (cons (concat (if strip "-" "+") tag)
7232 (if narrow current nil)))
7233 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7234 (setq maybe-refresh t))
7235 (t (error "Invalid tag selection character %c" char)))
7236 (when (and maybe-refresh
7237 (eq org-agenda-clockreport-mode 'with-filter))
7238 (org-agenda-redo))))
7240 (defun org-agenda-get-represented-tags ()
7241 "Get a list of all tags currently represented in the agenda."
7242 (let (p tags)
7243 (save-excursion
7244 (goto-char (point-min))
7245 (while (setq p (next-single-property-change (point) 'tags))
7246 (goto-char p)
7247 (mapc (lambda (x) (add-to-list 'tags x))
7248 (get-text-property (point) 'tags))))
7249 tags))
7251 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7252 "Refine the current filter. See `org-agenda-filter-by-tag'."
7253 (interactive "P")
7254 (org-agenda-filter-by-tag strip char 'refine))
7256 (defun org-agenda-filter-make-matcher ()
7257 "Create the form that tests a line for agenda filter."
7258 (let (f f1)
7259 ;; first compute the tag-filter matcher
7260 (dolist (x (delete-dups
7261 (append (get 'org-agenda-tag-filter
7262 :preset-filter) org-agenda-tag-filter)))
7263 (if (member x '("-" "+"))
7264 (setq f1 (if (equal x "-") 'tags '(not tags)))
7265 (if (string-match "[<=>?]" x)
7266 (setq f1 (org-agenda-filter-effort-form x))
7267 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7268 (if (equal (string-to-char x) ?-)
7269 (setq f1 (list 'not f1))))
7270 (push f1 f))
7271 ;; then compute the category-filter matcher
7272 (dolist (x (delete-dups
7273 (append (get 'org-agenda-category-filter
7274 :preset-filter) org-agenda-category-filter)))
7275 (if (equal "-" (substring x 0 1))
7276 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7277 (setq f1 (list 'equal (substring x 1) 'cat)))
7278 (push f1 f))
7279 (cons 'and (nreverse f))))
7281 (defun org-agenda-filter-effort-form (e)
7282 "Return the form to compare the effort of the current line with what E says.
7283 E looks like \"+<2:25\"."
7284 (let (op)
7285 (setq e (substring e 1))
7286 (setq op (string-to-char e) e (substring e 1))
7287 (setq op (cond ((equal op ?<) '<=)
7288 ((equal op ?>) '>=)
7289 ((equal op ??) op)
7290 (t '=)))
7291 (list 'org-agenda-compare-effort (list 'quote op)
7292 (org-duration-string-to-minutes e))))
7294 (defun org-agenda-compare-effort (op value)
7295 "Compare the effort of the current line with VALUE, using OP.
7296 If the line does not have an effort defined, return nil."
7297 (let ((eff (org-get-at-bol 'effort-minutes)))
7298 (if (equal op ??)
7299 (not eff)
7300 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7301 value))))
7303 (defun org-agenda-filter-apply (filter type)
7304 "Set FILTER as the new agenda filter and apply it."
7305 (let (tags cat)
7306 (if (eq type 'tag)
7307 (setq org-agenda-tag-filter filter)
7308 (setq org-agenda-category-filter filter))
7309 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7310 (if (and (eq type 'category)
7311 (not (equal (substring (car filter) 0 1) "-")))
7312 ;; Only set `org-agenda-filtered-by-category' to t
7313 ;; when a unique category is used as the filter
7314 (setq org-agenda-filtered-by-category t))
7315 (org-agenda-set-mode-name)
7316 (save-excursion
7317 (goto-char (point-min))
7318 (while (not (eobp))
7319 (if (org-get-at-bol 'org-marker)
7320 (progn
7321 (setq tags (org-get-at-bol 'tags) ; used in eval
7322 cat (get-text-property (point) 'org-category))
7323 (if (not (eval org-agenda-filter-form))
7324 (org-agenda-filter-hide-line type))
7325 (beginning-of-line 2))
7326 (beginning-of-line 2))))
7327 (if (get-char-property (point) 'invisible)
7328 (ignore-errors (org-agenda-previous-line)))))
7330 (defun org-agenda-filter-top-category-apply (category &optional negative)
7331 "Set FILTER as the new agenda filter and apply it."
7332 (org-agenda-set-mode-name)
7333 (save-excursion
7334 (goto-char (point-min))
7335 (while (not (eobp))
7336 (let* ((pos (org-get-at-bol 'org-hd-marker))
7337 (topcat (and pos (org-find-top-category pos))))
7338 (if (and topcat (funcall (if negative 'identity 'not)
7339 (string= category topcat)))
7340 (org-agenda-filter-hide-line 'category)))
7341 (beginning-of-line 2)))
7342 (if (get-char-property (point) 'invisible)
7343 (org-agenda-previous-line))
7344 (setq org-agenda-top-category-filter category
7345 org-agenda-filtered-by-top-category t))
7347 (defun org-agenda-filter-hide-line (type)
7348 (let (ov)
7349 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7350 (point-at-eol)))
7351 (overlay-put ov 'invisible t)
7352 (overlay-put ov 'type type)
7353 (if (eq type 'tag)
7354 (push ov org-agenda-tag-filter-overlays)
7355 (push ov org-agenda-cat-filter-overlays))))
7357 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7358 (setq pos (or pos (point)))
7359 (save-excursion
7360 (dolist (ov (overlays-at pos))
7361 (when (and (overlay-get ov 'invisible)
7362 (eq (overlay-get ov 'type) 'tag))
7363 (goto-char pos)
7364 (if (< (overlay-start ov) (point-at-eol))
7365 (move-overlay ov (point-at-eol)
7366 (overlay-end ov)))))))
7368 (defun org-agenda-filter-show-all-tag nil
7369 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7370 (setq org-agenda-tag-filter-overlays nil
7371 org-agenda-tag-filter nil
7372 org-agenda-filter-form nil)
7373 (org-agenda-set-mode-name))
7375 (defun org-agenda-filter-show-all-cat nil
7376 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7377 (setq org-agenda-cat-filter-overlays nil
7378 org-agenda-filtered-by-category nil
7379 org-agenda-category-filter nil
7380 org-agenda-filter-form nil)
7381 (org-agenda-set-mode-name))
7383 (defun org-agenda-manipulate-query-add ()
7384 "Manipulate the query by adding a search term with positive selection.
7385 Positive selection means the term must be matched for selection of an entry."
7386 (interactive)
7387 (org-agenda-manipulate-query ?\[))
7388 (defun org-agenda-manipulate-query-subtract ()
7389 "Manipulate the query by adding a search term with negative selection.
7390 Negative selection means term must not be matched for selection of an entry."
7391 (interactive)
7392 (org-agenda-manipulate-query ?\]))
7393 (defun org-agenda-manipulate-query-add-re ()
7394 "Manipulate the query by adding a search regexp with positive selection.
7395 Positive selection means the regexp must match for selection of an entry."
7396 (interactive)
7397 (org-agenda-manipulate-query ?\{))
7398 (defun org-agenda-manipulate-query-subtract-re ()
7399 "Manipulate the query by adding a search regexp with negative selection.
7400 Negative selection means regexp must not match for selection of an entry."
7401 (interactive)
7402 (org-agenda-manipulate-query ?\}))
7403 (defun org-agenda-manipulate-query (char)
7404 (cond
7405 ((memq org-agenda-type '(timeline agenda))
7406 (let ((org-agenda-include-inactive-timestamps t))
7407 (org-agenda-redo))
7408 (message "Display now includes inactive timestamps as well"))
7409 ((eq org-agenda-type 'search)
7410 (org-add-to-string
7411 'org-agenda-query-string
7412 (if org-agenda-last-search-view-search-was-boolean
7413 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7414 (?\{ . " +{}") (?\} . " -{}"))))
7415 " "))
7416 (setq org-agenda-redo-command
7417 (list 'org-search-view
7418 (car (get-text-property (min (1- (point-max)) (point))
7419 'org-last-args))
7420 org-agenda-query-string
7421 (+ (length org-agenda-query-string)
7422 (if (member char '(?\{ ?\})) 0 1))))
7423 (set-register org-agenda-query-register org-agenda-query-string)
7424 (let ((org-agenda-overriding-arguments
7425 (cdr org-agenda-redo-command)))
7426 (org-agenda-redo)))
7427 (t (error "Cannot manipulate query for %s-type agenda buffers"
7428 org-agenda-type))))
7430 (defun org-add-to-string (var string)
7431 (set var (concat (symbol-value var) string)))
7433 (defun org-agenda-goto-date (span)
7434 "Jump to DATE in agenda."
7435 (interactive "P")
7436 (let* ((org-read-date-prefer-future
7437 (eval org-agenda-jump-prefer-future))
7438 (date (org-read-date))
7439 (org-agenda-sticky-orig org-agenda-sticky)
7440 (org-agenda-buffer-tmp-name (buffer-name))
7441 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7442 (0-arg (or current-prefix-arg (car args)))
7443 (2-arg (nth 2 args))
7444 (newcmd (list 'org-agenda-list 0-arg date
7445 (org-agenda-span-to-ndays 2-arg)))
7446 (newargs (cdr newcmd))
7447 (inhibit-read-only t)
7448 org-agenda-sticky)
7449 (if (not (org-agenda-check-type t 'agenda))
7450 (error "Not available in non-agenda blocks")
7451 (add-text-properties (point-min) (point-max)
7452 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7453 (org-agenda-redo)
7454 (setq org-agenda-sticky org-agenda-sticky-orig
7455 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7457 (defun org-agenda-goto-today ()
7458 "Go to today."
7459 (interactive)
7460 (org-agenda-check-type t 'timeline 'agenda)
7461 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7462 (curspan (nth 2 args))
7463 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7464 (cond
7465 (tdpos (goto-char tdpos))
7466 ((eq org-agenda-type 'agenda)
7467 (let* ((sd (org-agenda-compute-starting-span
7468 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7469 (org-agenda-overriding-arguments args))
7470 (setf (nth 1 org-agenda-overriding-arguments) sd)
7471 (org-agenda-redo)
7472 (org-agenda-find-same-or-today-or-agenda)))
7473 (t (error "Cannot find today")))))
7475 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7476 (goto-char
7477 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7478 (text-property-any (point-min) (point-max) 'org-today t)
7479 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7480 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7481 (org-agenda-goto-block-beginning))
7482 (point-min))))
7484 (defun org-agenda-goto-block-beginning ()
7485 "Go the agenda block beginning."
7486 (interactive)
7487 (if (not (derived-mode-p 'org-agenda-mode))
7488 (error "Cannot execute this command outside of org-agenda-mode buffers")
7489 (let (dest)
7490 (save-excursion
7491 (unless (looking-at "\\'")
7492 (forward-char))
7493 (let* ((prop 'org-agenda-structural-header)
7494 (p (previous-single-property-change (point) prop))
7495 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7496 (1- (point))) prop)))
7497 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7498 (if (not dest)
7499 (error "Cannot find the beginning of the blog")
7500 (goto-char dest)
7501 (move-beginning-of-line 1)))))
7503 (defun org-agenda-later (arg)
7504 "Go forward in time by the current span.
7505 With prefix ARG, go forward that many times the current span."
7506 (interactive "p")
7507 (org-agenda-check-type t 'agenda)
7508 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7509 (span (or (nth 2 args) org-agenda-current-span))
7510 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7511 (greg (calendar-gregorian-from-absolute sd))
7512 (cnt (org-get-at-bol 'org-day-cnt))
7513 greg2)
7514 (cond
7515 ((numberp span)
7516 (setq sd (+ (* span arg) sd)))
7517 ((eq span 'day)
7518 (setq sd (+ arg sd)))
7519 ((eq span 'week)
7520 (setq sd (+ (* 7 arg) sd)))
7521 ((eq span 'month)
7522 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7523 sd (calendar-absolute-from-gregorian greg2))
7524 (setcar greg2 (1+ (car greg2))))
7525 ((eq span 'year)
7526 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7527 sd (calendar-absolute-from-gregorian greg2))
7528 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7530 (setq sd (+ (* span arg) sd))))
7531 (let ((org-agenda-overriding-cmd
7532 ;; `cmd' may have been set by `org-agenda-run-series' which
7533 ;; uses `org-agenda-overriding-cmd' to decide whether
7534 ;; overriding is allowed for `cmd'
7535 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7536 (org-agenda-overriding-arguments
7537 (list (car args) sd span)))
7538 (org-agenda-redo)
7539 (org-agenda-find-same-or-today-or-agenda cnt))))
7541 (defun org-agenda-earlier (arg)
7542 "Go backward in time by the current span.
7543 With prefix ARG, go backward that many times the current span."
7544 (interactive "p")
7545 (org-agenda-later (- arg)))
7547 (defun org-agenda-view-mode-dispatch ()
7548 "Call one of the view mode commands."
7549 (interactive)
7550 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7551 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7552 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7553 (let ((a (read-char-exclusive)))
7554 (case a
7555 (?\ (call-interactively 'org-agenda-reset-view))
7556 (?d (call-interactively 'org-agenda-day-view))
7557 (?w (call-interactively 'org-agenda-week-view))
7558 (?m (call-interactively 'org-agenda-month-view))
7559 (?y (call-interactively 'org-agenda-year-view))
7560 (?l (call-interactively 'org-agenda-log-mode))
7561 (?L (org-agenda-log-mode '(4)))
7562 (?c (org-agenda-log-mode 'clockcheck))
7563 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7564 (?a (call-interactively 'org-agenda-archives-mode))
7565 (?A (org-agenda-archives-mode 'files))
7566 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7567 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7568 (?G (call-interactively 'org-agenda-toggle-time-grid))
7569 (?D (call-interactively 'org-agenda-toggle-diary))
7570 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7571 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7572 (org-agenda-check-type t 'timeline 'agenda)
7573 (org-agenda-redo))
7574 (message "Display now includes inactive timestamps as well"))
7575 (?q (message "Abort"))
7576 (otherwise (error "Invalid key" )))))
7578 (defun org-agenda-reset-view ()
7579 "Switch to default view for agenda."
7580 (interactive)
7581 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7582 (defun org-agenda-day-view (&optional day-of-year)
7583 "Switch to daily view for agenda.
7584 With argument DAY-OF-YEAR, switch to that day of the year."
7585 (interactive "P")
7586 (org-agenda-change-time-span 'day day-of-year))
7587 (defun org-agenda-week-view (&optional iso-week)
7588 "Switch to daily view for agenda.
7589 With argument ISO-WEEK, switch to the corresponding ISO week.
7590 If ISO-WEEK has more then 2 digits, only the last two encode the
7591 week. Any digits before this encode a year. So 200712 means
7592 week 12 of year 2007. Years in the range 1938-2037 can also be
7593 written as 2-digit years."
7594 (interactive "P")
7595 (org-agenda-change-time-span 'week iso-week))
7596 (defun org-agenda-month-view (&optional month)
7597 "Switch to monthly view for agenda.
7598 With argument MONTH, switch to that month."
7599 (interactive "P")
7600 (org-agenda-change-time-span 'month month))
7601 (defun org-agenda-year-view (&optional year)
7602 "Switch to yearly view for agenda.
7603 With argument YEAR, switch to that year.
7604 If MONTH has more then 2 digits, only the last two encode the
7605 month. Any digits before this encode a year. So 200712 means
7606 December year 2007. Years in the range 1938-2037 can also be
7607 written as 2-digit years."
7608 (interactive "P")
7609 (when year
7610 (setq year (org-small-year-to-year year)))
7611 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7612 (org-agenda-change-time-span 'year year)
7613 (error "Abort")))
7615 (defun org-agenda-change-time-span (span &optional n)
7616 "Change the agenda view to SPAN.
7617 SPAN may be `day', `week', `month', `year'."
7618 (org-agenda-check-type t 'agenda)
7619 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7620 (curspan (nth 2 args)))
7621 (if (and (not n) (equal curspan span))
7622 (error "Viewing span is already \"%s\"" span))
7623 (let* ((sd (or (org-get-at-bol 'day)
7624 (nth 1 args)
7625 org-starting-day))
7626 (sd (org-agenda-compute-starting-span sd span n))
7627 (org-agenda-overriding-cmd
7628 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7629 (org-agenda-overriding-arguments
7630 (list (car args) sd span)))
7631 (org-agenda-redo)
7632 (org-agenda-find-same-or-today-or-agenda))
7633 (org-agenda-set-mode-name)
7634 (message "Switched to %s view" span)))
7636 (defun org-agenda-compute-starting-span (sd span &optional n)
7637 "Compute starting date for agenda.
7638 SPAN may be `day', `week', `month', `year'. The return value
7639 is a cons cell with the starting date and the number of days,
7640 so that the date SD will be in that range."
7641 (let* ((greg (calendar-gregorian-from-absolute sd))
7642 (dg (nth 1 greg))
7643 (mg (car greg))
7644 (yg (nth 2 greg)))
7645 (cond
7646 ((eq span 'day)
7647 (when n
7648 (setq sd (+ (calendar-absolute-from-gregorian
7649 (list mg 1 yg))
7650 n -1))))
7651 ((eq span 'week)
7652 (let* ((nt (calendar-day-of-week
7653 (calendar-gregorian-from-absolute sd)))
7654 (d (if org-agenda-start-on-weekday
7655 (- nt org-agenda-start-on-weekday)
7658 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7659 (when n
7660 (require 'cal-iso)
7661 (when (> n 99)
7662 (setq y1 (org-small-year-to-year (/ n 100))
7663 n (mod n 100)))
7664 (setq sd
7665 (calendar-absolute-from-iso
7666 (list n 1
7667 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7668 ((eq span 'month)
7669 (let (y1)
7670 (when (and n (> n 99))
7671 (setq y1 (org-small-year-to-year (/ n 100))
7672 n (mod n 100)))
7673 (setq sd (calendar-absolute-from-gregorian
7674 (list (or n mg) 1 (or y1 yg))))))
7675 ((eq span 'year)
7676 (setq sd (calendar-absolute-from-gregorian
7677 (list 1 1 (or n yg))))))
7678 sd))
7680 (defun org-agenda-next-date-line (&optional arg)
7681 "Jump to the next line indicating a date in agenda buffer."
7682 (interactive "p")
7683 (org-agenda-check-type t 'agenda 'timeline)
7684 (beginning-of-line 1)
7685 ;; This does not work if user makes date format that starts with a blank
7686 (if (looking-at "^\\S-") (forward-char 1))
7687 (if (not (re-search-forward "^\\S-" nil t arg))
7688 (progn
7689 (backward-char 1)
7690 (error "No next date after this line in this buffer")))
7691 (goto-char (match-beginning 0)))
7693 (defun org-agenda-previous-date-line (&optional arg)
7694 "Jump to the previous line indicating a date in agenda buffer."
7695 (interactive "p")
7696 (org-agenda-check-type t 'agenda 'timeline)
7697 (beginning-of-line 1)
7698 (if (not (re-search-backward "^\\S-" nil t arg))
7699 (error "No previous date before this line in this buffer")))
7701 ;; Initialize the highlight
7702 (defvar org-hl (make-overlay 1 1))
7703 (overlay-put org-hl 'face 'highlight)
7705 (defun org-highlight (begin end &optional buffer)
7706 "Highlight a region with overlay."
7707 (move-overlay org-hl begin end (or buffer (current-buffer))))
7709 (defun org-unhighlight ()
7710 "Detach overlay INDEX."
7711 (org-detach-overlay org-hl))
7713 (defun org-unhighlight-once ()
7714 "Remove the highlight from its position, and this function from the hook."
7715 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7716 (org-unhighlight))
7718 (defvar org-agenda-pre-follow-window-conf nil)
7719 (defun org-agenda-follow-mode ()
7720 "Toggle follow mode in an agenda buffer."
7721 (interactive)
7722 (unless org-agenda-follow-mode
7723 (setq org-agenda-pre-follow-window-conf
7724 (current-window-configuration)))
7725 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7726 (unless org-agenda-follow-mode
7727 (set-window-configuration org-agenda-pre-follow-window-conf))
7728 (org-agenda-set-mode-name)
7729 (org-agenda-do-context-action)
7730 (message "Follow mode is %s"
7731 (if org-agenda-follow-mode "on" "off")))
7733 (defun org-agenda-entry-text-mode (&optional arg)
7734 "Toggle entry text mode in an agenda buffer."
7735 (interactive "P")
7736 (setq org-agenda-entry-text-mode (or (integerp arg)
7737 (not org-agenda-entry-text-mode)))
7738 (org-agenda-entry-text-hide)
7739 (and org-agenda-entry-text-mode
7740 (let ((org-agenda-entry-text-maxlines
7741 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7742 (org-agenda-entry-text-show)))
7743 (org-agenda-set-mode-name)
7744 (message "Entry text mode is %s. Maximum number of lines is %d"
7745 (if org-agenda-entry-text-mode "on" "off")
7746 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7748 (defun org-agenda-clockreport-mode (&optional with-filter)
7749 "Toggle clocktable mode in an agenda buffer.
7750 With prefix arg WITH-FILTER, make the clocktable respect the current
7751 agenda filter."
7752 (interactive "P")
7753 (org-agenda-check-type t 'agenda)
7754 (if with-filter
7755 (setq org-agenda-clockreport-mode 'with-filter)
7756 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7757 (org-agenda-set-mode-name)
7758 (org-agenda-redo)
7759 (message "Clocktable mode is %s"
7760 (if org-agenda-clockreport-mode "on" "off")))
7762 (defun org-agenda-log-mode (&optional special)
7763 "Toggle log mode in an agenda buffer.
7764 With argument SPECIAL, show all possible log items, not only the ones
7765 configured in `org-agenda-log-mode-items'.
7766 With a double `C-u' prefix arg, show *only* log items, nothing else."
7767 (interactive "P")
7768 (org-agenda-check-type t 'agenda 'timeline)
7769 (setq org-agenda-show-log
7770 (cond
7771 ((equal special '(16)) 'only)
7772 ((eq special 'clockcheck)
7773 (if (eq org-agenda-show-log 'clockcheck)
7774 nil 'clockcheck))
7775 (special '(closed clock state))
7776 (t (not org-agenda-show-log))))
7777 (org-agenda-set-mode-name)
7778 (org-agenda-redo)
7779 (message "Log mode is %s"
7780 (if org-agenda-show-log "on" "off")))
7782 (defun org-agenda-archives-mode (&optional with-files)
7783 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7784 When called with a prefix argument, include all archive files as well."
7785 (interactive "P")
7786 (setq org-agenda-archives-mode
7787 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7788 (org-agenda-set-mode-name)
7789 (org-agenda-redo)
7790 (message
7791 "%s"
7792 (cond
7793 ((eq org-agenda-archives-mode nil)
7794 "No archives are included")
7795 ((eq org-agenda-archives-mode 'trees)
7796 (format "Trees with :%s: tag are included" org-archive-tag))
7797 ((eq org-agenda-archives-mode t)
7798 (format "Trees with :%s: tag and all active archive files are included"
7799 org-archive-tag)))))
7801 (defun org-agenda-toggle-diary ()
7802 "Toggle diary inclusion in an agenda buffer."
7803 (interactive)
7804 (org-agenda-check-type t 'agenda)
7805 (setq org-agenda-include-diary (not org-agenda-include-diary))
7806 (org-agenda-redo)
7807 (org-agenda-set-mode-name)
7808 (message "Diary inclusion turned %s"
7809 (if org-agenda-include-diary "on" "off")))
7811 (defun org-agenda-toggle-deadlines ()
7812 "Toggle inclusion of entries with a deadline in an agenda buffer."
7813 (interactive)
7814 (org-agenda-check-type t 'agenda)
7815 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7816 (org-agenda-redo)
7817 (org-agenda-set-mode-name)
7818 (message "Deadlines inclusion turned %s"
7819 (if org-agenda-include-deadlines "on" "off")))
7821 (defun org-agenda-toggle-time-grid ()
7822 "Toggle time grid in an agenda buffer."
7823 (interactive)
7824 (org-agenda-check-type t 'agenda)
7825 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7826 (org-agenda-redo)
7827 (org-agenda-set-mode-name)
7828 (message "Time-grid turned %s"
7829 (if org-agenda-use-time-grid "on" "off")))
7831 (defun org-agenda-set-mode-name ()
7832 "Set the mode name to indicate all the small mode settings."
7833 (setq mode-name
7834 (list "Org-Agenda"
7835 (if (get 'org-agenda-files 'org-restrict) " []" "")
7837 '(:eval (org-agenda-span-name org-agenda-current-span))
7838 (if org-agenda-follow-mode " Follow" "")
7839 (if org-agenda-entry-text-mode " ETxt" "")
7840 (if org-agenda-include-diary " Diary" "")
7841 (if org-agenda-include-deadlines " Ddl" "")
7842 (if org-agenda-use-time-grid " Grid" "")
7843 (if (and (boundp 'org-habit-show-habits)
7844 org-habit-show-habits) " Habit" "")
7845 (cond
7846 ((consp org-agenda-show-log) " LogAll")
7847 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7848 (org-agenda-show-log " Log")
7849 (t ""))
7850 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7851 :preset-filter))
7852 '(:eval (org-propertize
7853 (concat " <"
7854 (mapconcat
7855 'identity
7856 (append
7857 (get 'org-agenda-category-filter :preset-filter)
7858 org-agenda-category-filter)
7860 ">")
7861 'face 'org-agenda-filter-category
7862 'help-echo "Category used in filtering"))
7864 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7865 :preset-filter))
7866 '(:eval (org-propertize
7867 (concat " {"
7868 (mapconcat
7869 'identity
7870 (append
7871 (get 'org-agenda-tag-filter :preset-filter)
7872 org-agenda-tag-filter)
7874 "}")
7875 'face 'org-agenda-filter-tags
7876 'help-echo "Tags used in filtering"))
7878 (if org-agenda-archives-mode
7879 (if (eq org-agenda-archives-mode t)
7880 " Archives"
7881 (format " :%s:" org-archive-tag))
7883 (if org-agenda-clockreport-mode
7884 (if (eq org-agenda-clockreport-mode 'with-filter)
7885 " Clock{}" " Clock")
7886 "")))
7887 (force-mode-line-update))
7889 (define-obsolete-function-alias
7890 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7892 (defun org-agenda-update-agenda-type ()
7893 "Update the agenda type after each command."
7894 (setq org-agenda-type
7895 (or (get-text-property (point) 'org-agenda-type)
7896 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7898 (defun org-agenda-next-line ()
7899 "Move cursor to the next line, and show if follow mode is active."
7900 (interactive)
7901 (call-interactively 'next-line)
7902 (org-agenda-do-context-action))
7904 (defun org-agenda-previous-line ()
7905 "Move cursor to the previous line, and show if follow-mode is active."
7906 (interactive)
7907 (call-interactively 'previous-line)
7908 (org-agenda-do-context-action))
7910 (defun org-agenda-next-item (n)
7911 "Move cursor to next agenda item."
7912 (interactive "p")
7913 (let ((col (current-column)))
7914 (dotimes (c n)
7915 (when (next-single-property-change (point-at-eol) 'org-marker)
7916 (move-end-of-line 1)
7917 (goto-char (next-single-property-change (point) 'org-marker))))
7918 (org-move-to-column col))
7919 (org-agenda-do-context-action))
7921 (defun org-agenda-previous-item (n)
7922 "Move cursor to next agenda item."
7923 (interactive "p")
7924 (dotimes (c n)
7925 (let ((col (current-column))
7926 (goto (save-excursion
7927 (move-end-of-line 0)
7928 (previous-single-property-change (point) 'org-marker))))
7929 (if goto (goto-char goto))
7930 (org-move-to-column col)))
7931 (org-agenda-do-context-action))
7933 (defun org-agenda-do-context-action ()
7934 "Show outline path and, maybe, follow mode window."
7935 (let ((m (org-get-at-bol 'org-marker)))
7936 (when (and (markerp m) (marker-buffer m))
7937 (and org-agenda-follow-mode
7938 (if org-agenda-follow-indirect
7939 (org-agenda-tree-to-indirect-buffer nil)
7940 (org-agenda-show)))
7941 (and org-agenda-show-outline-path
7942 (org-with-point-at m (org-display-outline-path t))))))
7944 (defun org-agenda-show-tags ()
7945 "Show the tags applicable to the current item."
7946 (interactive)
7947 (let* ((tags (org-get-at-bol 'tags)))
7948 (if tags
7949 (message "Tags are :%s:"
7950 (org-no-properties (mapconcat 'identity tags ":")))
7951 (message "No tags associated with this line"))))
7953 (defun org-agenda-goto (&optional highlight)
7954 "Go to the Org-mode file which contains the item at point."
7955 (interactive)
7956 (let* ((marker (or (org-get-at-bol 'org-marker)
7957 (org-agenda-error)))
7958 (buffer (marker-buffer marker))
7959 (pos (marker-position marker)))
7960 (switch-to-buffer-other-window buffer)
7961 (widen)
7962 (push-mark)
7963 (goto-char pos)
7964 (when (derived-mode-p 'org-mode)
7965 (org-show-context 'agenda)
7966 (save-excursion
7967 (and (outline-next-heading)
7968 (org-flag-heading nil)))) ; show the next heading
7969 (when (outline-invisible-p)
7970 (show-entry)) ; display invisible text
7971 (recenter (/ (window-height) 2))
7972 (run-hooks 'org-agenda-after-show-hook)
7973 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7975 (defvar org-agenda-after-show-hook nil
7976 "Normal hook run after an item has been shown from the agenda.
7977 Point is in the buffer where the item originated.")
7979 (defun org-agenda-kill ()
7980 "Kill the entry or subtree belonging to the current agenda entry."
7981 (interactive)
7982 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7983 (let* ((bufname-orig (buffer-name))
7984 (marker (or (org-get-at-bol 'org-marker)
7985 (org-agenda-error)))
7986 (buffer (marker-buffer marker))
7987 (pos (marker-position marker))
7988 (type (org-get-at-bol 'type))
7989 dbeg dend (n 0) conf)
7990 (org-with-remote-undo buffer
7991 (with-current-buffer buffer
7992 (save-excursion
7993 (goto-char pos)
7994 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7995 (setq dbeg (progn (org-back-to-heading t) (point))
7996 dend (org-end-of-subtree t t))
7997 (setq dbeg (point-at-bol)
7998 dend (min (point-max) (1+ (point-at-eol)))))
7999 (goto-char dbeg)
8000 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
8001 (setq conf (or (eq t org-agenda-confirm-kill)
8002 (and (numberp org-agenda-confirm-kill)
8003 (> n org-agenda-confirm-kill))))
8004 (and conf
8005 (not (y-or-n-p
8006 (format "Delete entry with %d lines in buffer \"%s\"? "
8007 n (buffer-name buffer))))
8008 (error "Abort"))
8009 (let ((org-agenda-buffer-name bufname-orig))
8010 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
8011 (with-current-buffer buffer (delete-region dbeg dend))
8012 (message "Agenda item and source killed"))))
8014 (defvar org-archive-default-command) ; defined in org-archive.el
8015 (defun org-agenda-archive-default ()
8016 "Archive the entry or subtree belonging to the current agenda entry."
8017 (interactive)
8018 (require 'org-archive)
8019 (org-agenda-archive-with org-archive-default-command))
8021 (defun org-agenda-archive-default-with-confirmation ()
8022 "Archive the entry or subtree belonging to the current agenda entry."
8023 (interactive)
8024 (require 'org-archive)
8025 (org-agenda-archive-with org-archive-default-command 'confirm))
8027 (defun org-agenda-archive ()
8028 "Archive the entry or subtree belonging to the current agenda entry."
8029 (interactive)
8030 (org-agenda-archive-with 'org-archive-subtree))
8032 (defun org-agenda-archive-to-archive-sibling ()
8033 "Move the entry to the archive sibling."
8034 (interactive)
8035 (org-agenda-archive-with 'org-archive-to-archive-sibling))
8037 (defun org-agenda-archive-with (cmd &optional confirm)
8038 "Move the entry to the archive sibling."
8039 (interactive)
8040 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
8041 (let* ((bufname-orig (buffer-name))
8042 (marker (or (org-get-at-bol 'org-marker)
8043 (org-agenda-error)))
8044 (buffer (marker-buffer marker))
8045 (pos (marker-position marker)))
8046 (org-with-remote-undo buffer
8047 (with-current-buffer buffer
8048 (if (derived-mode-p 'org-mode)
8049 (if (and confirm
8050 (not (y-or-n-p "Archive this subtree or entry? ")))
8051 (error "Abort")
8052 (save-excursion
8053 (goto-char pos)
8054 (let ((org-agenda-buffer-name bufname-orig))
8055 (org-remove-subtree-entries-from-agenda))
8056 (org-back-to-heading t)
8057 (funcall cmd)))
8058 (error "Archiving works only in Org-mode files"))))))
8060 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
8061 "Remove all lines in the agenda that correspond to a given subtree.
8062 The subtree is the one in buffer BUF, starting at BEG and ending at END.
8063 If this information is not given, the function uses the tree at point."
8064 (let ((buf (or buf (current-buffer))) m p)
8065 (save-excursion
8066 (unless (and beg end)
8067 (org-back-to-heading t)
8068 (setq beg (point))
8069 (org-end-of-subtree t)
8070 (setq end (point)))
8071 (set-buffer (get-buffer org-agenda-buffer-name))
8072 (save-excursion
8073 (goto-char (point-max))
8074 (beginning-of-line 1)
8075 (while (not (bobp))
8076 (when (and (setq m (org-get-at-bol 'org-marker))
8077 (equal buf (marker-buffer m))
8078 (setq p (marker-position m))
8079 (>= p beg)
8080 (< p end))
8081 (let ((inhibit-read-only t))
8082 (delete-region (point-at-bol) (1+ (point-at-eol)))))
8083 (beginning-of-line 0))))))
8085 (defun org-agenda-refile (&optional goto rfloc no-update)
8086 "Refile the item at point."
8087 (interactive "P")
8088 (if (equal goto '(16))
8089 (org-refile-goto-last-stored)
8090 (let* ((buffer-orig (buffer-name))
8091 (marker (or (org-get-at-bol 'org-hd-marker)
8092 (org-agenda-error)))
8093 (buffer (marker-buffer marker))
8094 (pos (marker-position marker))
8095 (rfloc (or rfloc
8096 (org-refile-get-location
8097 (if goto "Goto" "Refile to") buffer
8098 org-refile-allow-creating-parent-nodes))))
8099 (with-current-buffer buffer
8100 (save-excursion
8101 (save-restriction
8102 (widen)
8103 (goto-char marker)
8104 (let ((org-agenda-buffer-name buffer-orig))
8105 (org-remove-subtree-entries-from-agenda))
8106 (org-refile goto buffer rfloc)))))
8107 (unless no-update (org-agenda-redo))))
8109 (defun org-agenda-open-link (&optional arg)
8110 "Open the link(s) in the current entry, if any.
8111 This looks for a link in the displayed line in the agenda.
8112 It also looks at the text of the entry itself."
8113 (interactive "P")
8114 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8115 (org-get-at-bol 'org-marker)))
8116 (buffer (and marker (marker-buffer marker)))
8117 (prefix (buffer-substring (point-at-bol) (point-at-eol)))
8118 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8119 (lk0 (car lkall))
8120 (lk (if (stringp lk0) (list lk0) lk0))
8121 (lkend (cdr lkall))
8122 trg)
8123 (cond
8124 ((and buffer lk)
8125 (mapcar (lambda(l)
8126 (with-current-buffer buffer
8127 (setq trg (and (string-match org-bracket-link-regexp l)
8128 (match-string 1 l)))
8129 (if (or (not trg) (string-match org-any-link-re trg))
8130 (save-excursion
8131 (save-restriction
8132 (widen)
8133 (goto-char marker)
8134 (when (search-forward l nil lkend)
8135 (goto-char (match-beginning 0))
8136 (org-open-at-point))))
8137 ;; This is an internal link, widen the buffer
8138 (switch-to-buffer-other-window buffer)
8139 (widen)
8140 (goto-char marker)
8141 (when (search-forward l nil lkend)
8142 (goto-char (match-beginning 0))
8143 (org-open-at-point)))))
8144 lk))
8145 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8146 (save-excursion
8147 (beginning-of-line 1)
8148 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8149 (org-open-link-from-string (match-string 1)))
8150 (t (message "No link to open here")))))
8152 (defun org-agenda-copy-local-variable (var)
8153 "Get a variable from a referenced buffer and install it here."
8154 (let ((m (org-get-at-bol 'org-marker)))
8155 (when (and m (buffer-live-p (marker-buffer m)))
8156 (org-set-local var (with-current-buffer (marker-buffer m)
8157 (symbol-value var))))))
8159 (defun org-agenda-switch-to (&optional delete-other-windows)
8160 "Go to the Org-mode file which contains the item at point."
8161 (interactive)
8162 (if (and org-return-follows-link
8163 (not (org-get-at-bol 'org-marker))
8164 (org-in-regexp org-bracket-link-regexp))
8165 (org-open-link-from-string (match-string 0))
8166 (let* ((marker (or (org-get-at-bol 'org-marker)
8167 (org-agenda-error)))
8168 (buffer (marker-buffer marker))
8169 (pos (marker-position marker)))
8170 (org-pop-to-buffer-same-window buffer)
8171 (and delete-other-windows (delete-other-windows))
8172 (widen)
8173 (goto-char pos)
8174 (when (derived-mode-p 'org-mode)
8175 (org-show-context 'agenda)
8176 (save-excursion
8177 (and (outline-next-heading)
8178 (org-flag-heading nil))) ; show the next heading
8179 (when (outline-invisible-p)
8180 (show-entry)) ; display invisible text
8181 (run-hooks 'org-agenda-after-show-hook)))))
8183 (defun org-agenda-goto-mouse (ev)
8184 "Go to the Org-mode file which contains the item at the mouse click."
8185 (interactive "e")
8186 (mouse-set-point ev)
8187 (org-agenda-goto))
8189 (defun org-agenda-show (&optional full-entry)
8190 "Display the Org-mode file which contains the item at point.
8191 With prefix argument FULL-ENTRY, make the entire entry visible
8192 if it was hidden in the outline."
8193 (interactive "P")
8194 (let ((win (selected-window)))
8195 (if full-entry
8196 (let ((org-show-entry-below t))
8197 (org-agenda-goto t))
8198 (org-agenda-goto t))
8199 (select-window win)))
8201 (defvar org-agenda-show-window nil)
8202 (defun org-agenda-show-and-scroll-up (&optional arg)
8203 "Display the Org-mode file which contains the item at point.
8204 When called repeatedly, scroll the window that is displaying the buffer.
8205 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8206 `show-subtree' to display the item, so that drawers and logbooks stay
8207 folded."
8208 (interactive "P")
8209 (let ((win (selected-window)))
8210 (if (and (window-live-p org-agenda-show-window)
8211 (eq this-command last-command))
8212 (progn
8213 (select-window org-agenda-show-window)
8214 (ignore-errors (scroll-up)))
8215 (org-agenda-goto t)
8216 (if arg (org-show-entry) (show-subtree))
8217 (setq org-agenda-show-window (selected-window)))
8218 (select-window win)))
8220 (defun org-agenda-show-scroll-down ()
8221 "Scroll down the window showing the agenda."
8222 (interactive)
8223 (let ((win (selected-window)))
8224 (when (window-live-p org-agenda-show-window)
8225 (select-window org-agenda-show-window)
8226 (ignore-errors (scroll-down))
8227 (select-window win))))
8229 (defun org-agenda-show-1 (&optional more)
8230 "Display the Org-mode file which contains the item at point.
8231 The prefix arg selects the amount of information to display:
8233 0 hide the subtree
8234 1 just show the entry according to defaults.
8235 2 show the children view
8236 3 show the subtree view
8237 4 show the entire subtree and any LOGBOOK drawers
8238 5 show the entire subtree and any drawers
8239 With prefix argument FULL-ENTRY, make the entire entry visible
8240 if it was hidden in the outline."
8241 (interactive "p")
8242 (let ((win (selected-window)))
8243 (org-agenda-goto t)
8244 (org-recenter-heading 1)
8245 (cond
8246 ((= more 0)
8247 (hide-subtree)
8248 (save-excursion
8249 (org-back-to-heading)
8250 (run-hook-with-args 'org-cycle-hook 'folded))
8251 (message "Remote: FOLDED"))
8252 ((and (org-called-interactively-p 'any) (= more 1))
8253 (message "Remote: show with default settings"))
8254 ((= more 2)
8255 (show-entry)
8256 (show-children)
8257 (save-excursion
8258 (org-back-to-heading)
8259 (run-hook-with-args 'org-cycle-hook 'children))
8260 (message "Remote: CHILDREN"))
8261 ((= more 3)
8262 (show-subtree)
8263 (save-excursion
8264 (org-back-to-heading)
8265 (run-hook-with-args 'org-cycle-hook 'subtree))
8266 (message "Remote: SUBTREE"))
8267 ((= more 4)
8268 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8269 (org-drawer-regexp
8270 (concat "^[ \t]*:\\("
8271 (mapconcat 'regexp-quote org-drawers "\\|")
8272 "\\):[ \t]*$")))
8273 (show-subtree)
8274 (save-excursion
8275 (org-back-to-heading)
8276 (org-cycle-hide-drawers 'subtree)))
8277 (message "Remote: SUBTREE AND LOGBOOK"))
8278 ((> more 4)
8279 (show-subtree)
8280 (message "Remote: SUBTREE AND ALL DRAWERS")))
8281 (select-window win)))
8283 (defun org-recenter-heading (n)
8284 (save-excursion
8285 (org-back-to-heading)
8286 (recenter n)))
8288 (defvar org-agenda-cycle-counter nil)
8289 (defun org-agenda-cycle-show (&optional n)
8290 "Show the current entry in another window, with default settings.
8291 Default settings are taken from `org-show-hierarchy-above' and siblings.
8292 When use repeatedly in immediate succession, the remote entry will cycle
8293 through visibility
8295 children -> subtree -> folded
8297 When called with a numeric prefix arg, that arg will be passed through to
8298 `org-agenda-show-1'. For the interpretation of that argument, see the
8299 docstring of `org-agenda-show-1'."
8300 (interactive "P")
8301 (if (integerp n)
8302 (setq org-agenda-cycle-counter n)
8303 (if (not (eq last-command this-command))
8304 (setq org-agenda-cycle-counter 1)
8305 (if (equal org-agenda-cycle-counter 0)
8306 (setq org-agenda-cycle-counter 2)
8307 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8308 (if (> org-agenda-cycle-counter 3)
8309 (setq org-agenda-cycle-counter 0)))))
8310 (org-agenda-show-1 org-agenda-cycle-counter))
8312 (defun org-agenda-recenter (arg)
8313 "Display the Org-mode file which contains the item at point and recenter."
8314 (interactive "P")
8315 (let ((win (selected-window)))
8316 (org-agenda-goto t)
8317 (recenter arg)
8318 (select-window win)))
8320 (defun org-agenda-show-mouse (ev)
8321 "Display the Org-mode file which contains the item at the mouse click."
8322 (interactive "e")
8323 (mouse-set-point ev)
8324 (org-agenda-show))
8326 (defun org-agenda-check-no-diary ()
8327 "Check if the entry is a diary link and abort if yes."
8328 (if (org-get-at-bol 'org-agenda-diary-link)
8329 (org-agenda-error)))
8331 (defun org-agenda-error ()
8332 (error "Command not allowed in this line"))
8334 (defun org-agenda-tree-to-indirect-buffer (arg)
8335 "Show the subtree corresponding to the current entry in an indirect buffer.
8336 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8338 With a numerical prefix ARG, go up to this level and then take that tree.
8339 With a negative numeric ARG, go up by this number of levels.
8340 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8341 use the dedicated frame)."
8342 (interactive "P")
8343 (if current-prefix-arg
8344 (org-agenda-do-tree-to-indirect-buffer arg)
8345 (let ((agenda-buffer (buffer-name))
8346 (agenda-window (selected-window))
8347 (indirect-window
8348 (and org-last-indirect-buffer
8349 (get-buffer-window org-last-indirect-buffer))))
8350 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8351 (unless (or (eq org-indirect-buffer-display 'new-frame)
8352 (eq org-indirect-buffer-display 'dedicated-frame))
8353 (unwind-protect
8354 (unless (and indirect-window (window-live-p indirect-window))
8355 (setq indirect-window (split-window agenda-window)))
8356 (and indirect-window (select-window indirect-window))
8357 (switch-to-buffer org-last-indirect-buffer :norecord)
8358 (fit-window-to-buffer indirect-window)))
8359 (select-window (get-buffer-window agenda-buffer)))))
8361 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8362 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8363 (org-agenda-check-no-diary)
8364 (let* ((marker (or (org-get-at-bol 'org-marker)
8365 (org-agenda-error)))
8366 (buffer (marker-buffer marker))
8367 (pos (marker-position marker)))
8368 (with-current-buffer buffer
8369 (save-excursion
8370 (goto-char pos)
8371 (funcall 'org-tree-to-indirect-buffer arg)))))
8373 (defvar org-last-heading-marker (make-marker)
8374 "Marker pointing to the headline that last changed its TODO state
8375 by a remote command from the agenda.")
8377 (defun org-agenda-todo-nextset ()
8378 "Switch TODO entry to next sequence."
8379 (interactive)
8380 (org-agenda-todo 'nextset))
8382 (defun org-agenda-todo-previousset ()
8383 "Switch TODO entry to previous sequence."
8384 (interactive)
8385 (org-agenda-todo 'previousset))
8387 (defun org-agenda-todo (&optional arg)
8388 "Cycle TODO state of line at point, also in Org-mode file.
8389 This changes the line at point, all other lines in the agenda referring to
8390 the same tree node, and the headline of the tree node in the Org-mode file."
8391 (interactive "P")
8392 (org-agenda-check-no-diary)
8393 (let* ((col (current-column))
8394 (marker (or (org-get-at-bol 'org-marker)
8395 (org-agenda-error)))
8396 (buffer (marker-buffer marker))
8397 (pos (marker-position marker))
8398 (hdmarker (org-get-at-bol 'org-hd-marker))
8399 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8400 (inhibit-read-only t)
8401 org-agenda-headline-snapshot-before-repeat newhead just-one)
8402 (org-with-remote-undo buffer
8403 (with-current-buffer buffer
8404 (widen)
8405 (goto-char pos)
8406 (org-show-context 'agenda)
8407 (save-excursion
8408 (and (outline-next-heading)
8409 (org-flag-heading nil))) ; show the next heading
8410 (let ((current-prefix-arg arg))
8411 (call-interactively 'org-todo))
8412 (and (bolp) (forward-char 1))
8413 (setq newhead (org-get-heading))
8414 (when (and (org-bound-and-true-p
8415 org-agenda-headline-snapshot-before-repeat)
8416 (not (equal org-agenda-headline-snapshot-before-repeat
8417 newhead))
8418 todayp)
8419 (setq newhead org-agenda-headline-snapshot-before-repeat
8420 just-one t))
8421 (save-excursion
8422 (org-back-to-heading)
8423 (move-marker org-last-heading-marker (point))))
8424 (beginning-of-line 1)
8425 (save-excursion
8426 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8427 (org-move-to-column col))))
8429 (defun org-agenda-add-note (&optional arg)
8430 "Add a time-stamped note to the entry at point."
8431 (interactive "P")
8432 (org-agenda-check-no-diary)
8433 (let* ((marker (or (org-get-at-bol 'org-marker)
8434 (org-agenda-error)))
8435 (buffer (marker-buffer marker))
8436 (pos (marker-position marker))
8437 (hdmarker (org-get-at-bol 'org-hd-marker))
8438 (inhibit-read-only t))
8439 (with-current-buffer buffer
8440 (widen)
8441 (goto-char pos)
8442 (org-show-context 'agenda)
8443 (save-excursion
8444 (and (outline-next-heading)
8445 (org-flag-heading nil))) ; show the next heading
8446 (org-add-note))))
8448 (defun org-agenda-change-all-lines (newhead hdmarker
8449 &optional fixface just-this)
8450 "Change all lines in the agenda buffer which match HDMARKER.
8451 The new content of the line will be NEWHEAD (as modified by
8452 `org-agenda-format-item'). HDMARKER is checked with
8453 `equal' against all `org-hd-marker' text properties in the file.
8454 If FIXFACE is non-nil, the face of each item is modified according to
8455 the new TODO state.
8456 If JUST-THIS is non-nil, change just the current line, not all.
8457 If FORCE-TAGS is non nil, the car of it returns the new tags."
8458 (let* ((inhibit-read-only t)
8459 (line (org-current-line))
8460 (org-agenda-buffer (current-buffer))
8461 (thetags (with-current-buffer (marker-buffer hdmarker)
8462 (save-excursion (save-restriction (widen)
8463 (goto-char hdmarker)
8464 (org-get-tags-at)))))
8465 props m pl undone-face done-face finish new dotime level cat tags)
8466 (save-excursion
8467 (goto-char (point-max))
8468 (beginning-of-line 1)
8469 (while (not finish)
8470 (setq finish (bobp))
8471 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8472 (or (not just-this) (= (org-current-line) line))
8473 (equal m hdmarker))
8474 (setq props (text-properties-at (point))
8475 dotime (org-get-at-bol 'dotime)
8476 cat (org-get-at-bol 'org-category)
8477 level (org-get-at-bol 'level)
8478 tags thetags
8480 (let ((org-prefix-format-compiled
8481 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8482 org-prefix-format-compiled))
8483 (extra (org-get-at-bol 'extra)))
8484 (with-current-buffer (marker-buffer hdmarker)
8485 (save-excursion
8486 (save-restriction
8487 (widen)
8488 (org-agenda-format-item extra newhead level cat tags dotime)))))
8489 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8490 undone-face (org-get-at-bol 'undone-face)
8491 done-face (org-get-at-bol 'done-face))
8492 (beginning-of-line 1)
8493 (cond
8494 ((equal new "")
8495 (and (looking-at ".*\n?") (replace-match "")))
8496 ((looking-at ".*")
8497 (replace-match new t t)
8498 (beginning-of-line 1)
8499 (add-text-properties (point-at-bol) (point-at-eol) props)
8500 (when fixface
8501 (add-text-properties
8502 (point-at-bol) (point-at-eol)
8503 (list 'face
8504 (if org-last-todo-state-is-todo
8505 undone-face done-face))))
8506 (org-agenda-highlight-todo 'line)
8507 (beginning-of-line 1))
8508 (t (error "Line update did not work")))
8509 (save-restriction
8510 (narrow-to-region (point-at-bol) (point-at-eol))
8511 (org-agenda-finalize)))
8512 (beginning-of-line 0)))))
8514 (defun org-agenda-align-tags (&optional line)
8515 "Align all tags in agenda items to `org-agenda-tags-column'."
8516 (let ((inhibit-read-only t) l c)
8517 (save-excursion
8518 (goto-char (if line (point-at-bol) (point-min)))
8519 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8520 (if line (point-at-eol) nil) t)
8521 (add-text-properties
8522 (match-beginning 2) (match-end 2)
8523 (list 'face (delq nil (let ((prop (get-text-property
8524 (match-beginning 2) 'face)))
8525 (or (listp prop) (setq prop (list prop)))
8526 (if (memq 'org-tag prop)
8527 prop
8528 (cons 'org-tag prop))))))
8529 (setq l (- (match-end 2) (match-beginning 2))
8530 c (if (< org-agenda-tags-column 0)
8531 (- (abs org-agenda-tags-column) l)
8532 org-agenda-tags-column))
8533 (delete-region (match-beginning 1) (match-end 1))
8534 (goto-char (match-beginning 1))
8535 (insert (org-add-props
8536 (make-string (max 1 (- c (current-column))) ?\ )
8537 (plist-put (copy-sequence (text-properties-at (point)))
8538 'face nil))))
8539 (goto-char (point-min))
8540 (org-font-lock-add-tag-faces (point-max)))))
8542 (defun org-agenda-priority-up ()
8543 "Increase the priority of line at point, also in Org-mode file."
8544 (interactive)
8545 (org-agenda-priority 'up))
8547 (defun org-agenda-priority-down ()
8548 "Decrease the priority of line at point, also in Org-mode file."
8549 (interactive)
8550 (org-agenda-priority 'down))
8552 (defun org-agenda-priority (&optional force-direction)
8553 "Set the priority of line at point, also in Org-mode file.
8554 This changes the line at point, all other lines in the agenda referring to
8555 the same tree node, and the headline of the tree node in the Org-mode file.
8556 Called with a universal prefix arg, show the priority instead of setting it."
8557 (interactive "P")
8558 (if (equal force-direction '(4))
8559 (org-show-priority)
8560 (unless org-enable-priority-commands
8561 (error "Priority commands are disabled"))
8562 (org-agenda-check-no-diary)
8563 (let* ((marker (or (org-get-at-bol 'org-marker)
8564 (org-agenda-error)))
8565 (hdmarker (org-get-at-bol 'org-hd-marker))
8566 (buffer (marker-buffer hdmarker))
8567 (pos (marker-position hdmarker))
8568 (inhibit-read-only t)
8569 newhead)
8570 (org-with-remote-undo buffer
8571 (with-current-buffer buffer
8572 (widen)
8573 (goto-char pos)
8574 (org-show-context 'agenda)
8575 (save-excursion
8576 (and (outline-next-heading)
8577 (org-flag-heading nil))) ; show the next heading
8578 (funcall 'org-priority force-direction)
8579 (end-of-line 1)
8580 (setq newhead (org-get-heading)))
8581 (org-agenda-change-all-lines newhead hdmarker)
8582 (beginning-of-line 1)))))
8584 ;; FIXME: should fix the tags property of the agenda line.
8585 (defun org-agenda-set-tags (&optional tag onoff)
8586 "Set tags for the current headline."
8587 (interactive)
8588 (org-agenda-check-no-diary)
8589 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8590 (call-interactively 'org-change-tag-in-region)
8591 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8592 (org-agenda-error)))
8593 (buffer (marker-buffer hdmarker))
8594 (pos (marker-position hdmarker))
8595 (inhibit-read-only t)
8596 newhead)
8597 (org-with-remote-undo buffer
8598 (with-current-buffer buffer
8599 (widen)
8600 (goto-char pos)
8601 (save-excursion
8602 (org-show-context 'agenda))
8603 (save-excursion
8604 (and (outline-next-heading)
8605 (org-flag-heading nil))) ; show the next heading
8606 (goto-char pos)
8607 (if tag
8608 (org-toggle-tag tag onoff)
8609 (call-interactively 'org-set-tags))
8610 (end-of-line 1)
8611 (setq newhead (org-get-heading)))
8612 (org-agenda-change-all-lines newhead hdmarker)
8613 (beginning-of-line 1)))))
8615 (defun org-agenda-set-property ()
8616 "Set a property for the current headline."
8617 (interactive)
8618 (org-agenda-check-no-diary)
8619 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8620 (org-agenda-error)))
8621 (buffer (marker-buffer hdmarker))
8622 (pos (marker-position hdmarker))
8623 (inhibit-read-only t)
8624 newhead)
8625 (org-with-remote-undo buffer
8626 (with-current-buffer buffer
8627 (widen)
8628 (goto-char pos)
8629 (save-excursion
8630 (org-show-context 'agenda))
8631 (save-excursion
8632 (and (outline-next-heading)
8633 (org-flag-heading nil))) ; show the next heading
8634 (goto-char pos)
8635 (call-interactively 'org-set-property)))))
8637 (defun org-agenda-set-effort ()
8638 "Set the effort property for the current headline."
8639 (interactive)
8640 (org-agenda-check-no-diary)
8641 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8642 (org-agenda-error)))
8643 (buffer (marker-buffer hdmarker))
8644 (pos (marker-position hdmarker))
8645 (inhibit-read-only t)
8646 newhead)
8647 (org-with-remote-undo buffer
8648 (with-current-buffer buffer
8649 (widen)
8650 (goto-char pos)
8651 (save-excursion
8652 (org-show-context 'agenda))
8653 (save-excursion
8654 (and (outline-next-heading)
8655 (org-flag-heading nil))) ; show the next heading
8656 (goto-char pos)
8657 (call-interactively 'org-set-effort)
8658 (end-of-line 1)
8659 (setq newhead (org-get-heading)))
8660 (org-agenda-change-all-lines newhead hdmarker))))
8662 (defun org-agenda-toggle-archive-tag ()
8663 "Toggle the archive tag for the current entry."
8664 (interactive)
8665 (org-agenda-check-no-diary)
8666 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8667 (org-agenda-error)))
8668 (buffer (marker-buffer hdmarker))
8669 (pos (marker-position hdmarker))
8670 (inhibit-read-only t)
8671 newhead)
8672 (org-with-remote-undo buffer
8673 (with-current-buffer buffer
8674 (widen)
8675 (goto-char pos)
8676 (org-show-context 'agenda)
8677 (save-excursion
8678 (and (outline-next-heading)
8679 (org-flag-heading nil))) ; show the next heading
8680 (call-interactively 'org-toggle-archive-tag)
8681 (end-of-line 1)
8682 (setq newhead (org-get-heading)))
8683 (org-agenda-change-all-lines newhead hdmarker)
8684 (beginning-of-line 1))))
8686 (defun org-agenda-do-date-later (arg)
8687 (interactive "P")
8688 (cond
8689 ((or (equal arg '(16))
8690 (memq last-command
8691 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8692 (setq this-command 'org-agenda-date-later-minutes)
8693 (org-agenda-date-later-minutes 1))
8694 ((or (equal arg '(4))
8695 (memq last-command
8696 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8697 (setq this-command 'org-agenda-date-later-hours)
8698 (org-agenda-date-later-hours 1))
8700 (org-agenda-date-later (prefix-numeric-value arg)))))
8702 (defun org-agenda-do-date-earlier (arg)
8703 (interactive "P")
8704 (cond
8705 ((or (equal arg '(16))
8706 (memq last-command
8707 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8708 (setq this-command 'org-agenda-date-earlier-minutes)
8709 (org-agenda-date-earlier-minutes 1))
8710 ((or (equal arg '(4))
8711 (memq last-command
8712 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8713 (setq this-command 'org-agenda-date-earlier-hours)
8714 (org-agenda-date-earlier-hours 1))
8716 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8718 (defun org-agenda-date-later (arg &optional what)
8719 "Change the date of this item to ARG day(s) later."
8720 (interactive "p")
8721 (org-agenda-check-type t 'agenda 'timeline)
8722 (org-agenda-check-no-diary)
8723 (let* ((marker (or (org-get-at-bol 'org-marker)
8724 (org-agenda-error)))
8725 (buffer (marker-buffer marker))
8726 (pos (marker-position marker))
8727 cdate today)
8728 (org-with-remote-undo buffer
8729 (with-current-buffer buffer
8730 (widen)
8731 (goto-char pos)
8732 (if (not (org-at-timestamp-p))
8733 (error "Cannot find time stamp"))
8734 (when (and org-agenda-move-date-from-past-immediately-to-today
8735 (equal arg 1)
8736 (or (not what) (eq what 'day))
8737 (not (save-match-data (org-at-date-range-p))))
8738 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8739 cdate (calendar-absolute-from-gregorian
8740 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8741 today (org-today))
8742 (if (> today cdate)
8743 ;; immediately shift to today
8744 (setq arg (- today cdate))))
8745 (org-timestamp-change arg (or what 'day))
8746 (when (and (org-at-date-range-p)
8747 (re-search-backward org-tr-regexp-both (point-at-bol)))
8748 (let ((end org-last-changed-timestamp))
8749 (org-timestamp-change arg (or what 'day))
8750 (setq org-last-changed-timestamp
8751 (concat org-last-changed-timestamp "--" end)))))
8752 (org-agenda-show-new-time marker org-last-changed-timestamp))
8753 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8755 (defun org-agenda-date-earlier (arg &optional what)
8756 "Change the date of this item to ARG day(s) earlier."
8757 (interactive "p")
8758 (org-agenda-date-later (- arg) what))
8760 (defun org-agenda-date-later-minutes (arg)
8761 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8762 (interactive "p")
8763 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8764 (org-agenda-date-later arg 'minute))
8766 (defun org-agenda-date-earlier-minutes (arg)
8767 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8768 (interactive "p")
8769 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8770 (org-agenda-date-earlier arg 'minute))
8772 (defun org-agenda-date-later-hours (arg)
8773 "Change the time of this item, in hour steps."
8774 (interactive "p")
8775 (org-agenda-date-later arg 'hour))
8777 (defun org-agenda-date-earlier-hours (arg)
8778 "Change the time of this item, in hour steps."
8779 (interactive "p")
8780 (org-agenda-date-earlier arg 'hour))
8782 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8783 "Show new date stamp via text properties."
8784 ;; We use text properties to make this undoable
8785 (let ((inhibit-read-only t)
8786 (buffer-invisibility-spec))
8787 (setq stamp (concat " " prefix " => " stamp))
8788 (save-excursion
8789 (goto-char (point-max))
8790 (while (not (bobp))
8791 (when (equal marker (org-get-at-bol 'org-marker))
8792 (org-move-to-column (- (window-width) (length stamp)) t)
8793 (org-agenda-fix-tags-filter-overlays-at (point))
8794 (if (featurep 'xemacs)
8795 ;; Use `duplicable' property to trigger undo recording
8796 (let ((ex (make-extent nil nil))
8797 (gl (make-glyph stamp)))
8798 (set-glyph-face gl 'secondary-selection)
8799 (set-extent-properties
8800 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8801 (insert-extent ex (1- (point)) (point-at-eol)))
8802 (add-text-properties
8803 (1- (point)) (point-at-eol)
8804 (list 'display (org-add-props stamp nil
8805 'face 'secondary-selection))))
8806 (beginning-of-line 1))
8807 (beginning-of-line 0)))))
8809 (defun org-agenda-date-prompt (arg)
8810 "Change the date of this item. Date is prompted for, with default today.
8811 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8812 be used to request time specification in the time stamp."
8813 (interactive "P")
8814 (org-agenda-check-type t 'agenda 'timeline)
8815 (org-agenda-check-no-diary)
8816 (let* ((marker (or (org-get-at-bol 'org-marker)
8817 (org-agenda-error)))
8818 (buffer (marker-buffer marker))
8819 (pos (marker-position marker)))
8820 (org-with-remote-undo buffer
8821 (with-current-buffer buffer
8822 (widen)
8823 (goto-char pos)
8824 (if (not (org-at-timestamp-p t))
8825 (error "Cannot find time stamp"))
8826 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8827 (org-agenda-show-new-time marker org-last-changed-timestamp))
8828 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8830 (defun org-agenda-schedule (arg &optional time)
8831 "Schedule the item at point.
8832 ARG is passed through to `org-schedule'."
8833 (interactive "P")
8834 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8835 (org-agenda-check-no-diary)
8836 (let* ((marker (or (org-get-at-bol 'org-marker)
8837 (org-agenda-error)))
8838 (type (marker-insertion-type marker))
8839 (buffer (marker-buffer marker))
8840 (pos (marker-position marker))
8841 (org-insert-labeled-timestamps-at-point nil)
8843 (set-marker-insertion-type marker t)
8844 (org-with-remote-undo buffer
8845 (with-current-buffer buffer
8846 (widen)
8847 (goto-char pos)
8848 (setq ts (org-schedule arg time)))
8849 (org-agenda-show-new-time marker ts "S"))
8850 (message "%s" ts)))
8852 (defun org-agenda-deadline (arg &optional time)
8853 "Schedule the item at point.
8854 ARG is passed through to `org-deadline'."
8855 (interactive "P")
8856 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8857 (org-agenda-check-no-diary)
8858 (let* ((marker (or (org-get-at-bol 'org-marker)
8859 (org-agenda-error)))
8860 (buffer (marker-buffer marker))
8861 (pos (marker-position marker))
8862 (org-insert-labeled-timestamps-at-point nil)
8864 (org-with-remote-undo buffer
8865 (with-current-buffer buffer
8866 (widen)
8867 (goto-char pos)
8868 (setq ts (org-deadline arg time)))
8869 (org-agenda-show-new-time marker ts "D"))
8870 (message "%s" ts)))
8872 (defun org-agenda-clock-in (&optional arg)
8873 "Start the clock on the currently selected item."
8874 (interactive "P")
8875 (org-agenda-check-no-diary)
8876 (if (equal arg '(4))
8877 (org-clock-in arg)
8878 (let* ((marker (or (org-get-at-bol 'org-marker)
8879 (org-agenda-error)))
8880 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8881 marker))
8882 (pos (marker-position marker))
8883 newhead)
8884 (org-with-remote-undo (marker-buffer marker)
8885 (with-current-buffer (marker-buffer marker)
8886 (widen)
8887 (goto-char pos)
8888 (org-show-context 'agenda)
8889 (org-show-entry)
8890 (org-cycle-hide-drawers 'children)
8891 (org-clock-in arg)
8892 (setq newhead (org-get-heading)))
8893 (org-agenda-change-all-lines newhead hdmarker)))))
8895 (defun org-agenda-clock-out ()
8896 "Stop the currently running clock."
8897 (interactive)
8898 (unless (marker-buffer org-clock-marker)
8899 (error "No running clock"))
8900 (let ((marker (make-marker)) newhead)
8901 (org-with-remote-undo (marker-buffer org-clock-marker)
8902 (with-current-buffer (marker-buffer org-clock-marker)
8903 (save-excursion
8904 (save-restriction
8905 (widen)
8906 (goto-char org-clock-marker)
8907 (org-back-to-heading t)
8908 (move-marker marker (point))
8909 (org-clock-out)
8910 (setq newhead (org-get-heading))))))
8911 (org-agenda-change-all-lines newhead marker)
8912 (move-marker marker nil)))
8914 (defun org-agenda-clock-cancel (&optional arg)
8915 "Cancel the currently running clock."
8916 (interactive "P")
8917 (unless (marker-buffer org-clock-marker)
8918 (error "No running clock"))
8919 (org-with-remote-undo (marker-buffer org-clock-marker)
8920 (org-clock-cancel)))
8922 (defun org-agenda-clock-goto ()
8923 "Jump to the currently clocked in task within the agenda.
8924 If the currently clocked in task is not listed in the agenda
8925 buffer, display it in another window."
8926 (interactive)
8927 (let (pos)
8928 (mapc (lambda (o)
8929 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8930 (setq pos (overlay-start o))))
8931 (overlays-in (point-min) (point-max)))
8932 (cond (pos (goto-char pos))
8933 ;; If the currently clocked entry is not in the agenda
8934 ;; buffer, we visit it in another window:
8935 (org-clock-current-task
8936 (org-switch-to-buffer-other-window (org-clock-goto)))
8937 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8939 (defun org-agenda-diary-entry-in-org-file ()
8940 "Make a diary entry in the file `org-agenda-diary-file'."
8941 (let (d1 d2 char (text "") dp1 dp2)
8942 (if (equal (buffer-name) "*Calendar*")
8943 (setq d1 (calendar-cursor-to-date t)
8944 d2 (car calendar-mark-ring))
8945 (setq dp1 (get-text-property (point-at-bol) 'day))
8946 (unless dp1 (error "No date defined in current line"))
8947 (setq d1 (calendar-gregorian-from-absolute dp1)
8948 d2 (and (ignore-errors (mark))
8949 (save-excursion
8950 (goto-char (mark))
8951 (setq dp2 (get-text-property (point-at-bol) 'day)))
8952 (calendar-gregorian-from-absolute dp2))))
8953 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8954 (setq char (read-char-exclusive))
8955 (cond
8956 ((equal char ?d)
8957 (setq text (read-string "Day entry: "))
8958 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8959 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8960 ((equal char ?a)
8961 (setq d1 (list (car d1) (nth 1 d1)
8962 (read-number (format "Reference year [%d]: " (nth 2 d1))
8963 (nth 2 d1))))
8964 (setq text (read-string "Anniversary (use %d to show years): "))
8965 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8966 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8967 ((equal char ?b)
8968 (setq text (read-string "Block entry: "))
8969 (unless (and d1 d2 (not (equal d1 d2)))
8970 (error "No block of days selected"))
8971 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8972 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8973 ((equal char ?j)
8974 (org-switch-to-buffer-other-window
8975 (find-file-noselect org-agenda-diary-file))
8976 (require 'org-datetree)
8977 (org-datetree-find-date-create d1)
8978 (org-reveal t))
8979 (t (error "Invalid selection character `%c'" char)))))
8981 (defcustom org-agenda-insert-diary-strategy 'date-tree
8982 "Where in `org-agenda-diary-file' should new entries be added?
8983 Valid values:
8985 date-tree in the date tree, as child of the date
8986 top-level as top-level entries at the end of the file."
8987 :group 'org-agenda
8988 :type '(choice
8989 (const :tag "in a date tree" date-tree)
8990 (const :tag "as top level at end of file" top-level)))
8992 (defcustom org-agenda-insert-diary-extract-time nil
8993 "Non-nil means extract any time specification from the diary entry."
8994 :group 'org-agenda
8995 :version "24.1"
8996 :type 'boolean)
8998 (defcustom org-agenda-bulk-mark-char ">"
8999 "A single-character string to be used as the bulk mark."
9000 :group 'org-agenda
9001 :version "24.1"
9002 :type 'string)
9004 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
9005 "Add a diary entry with TYPE to `org-agenda-diary-file'.
9006 If TEXT is not empty, it will become the headline of the new entry, and
9007 the resulting entry will not be shown. When TEXT is empty, switch to
9008 `org-agenda-diary-file' and let the user finish the entry there."
9009 (let ((cw (current-window-configuration)))
9010 (org-switch-to-buffer-other-window
9011 (find-file-noselect org-agenda-diary-file))
9012 (widen)
9013 (goto-char (point-min))
9014 (cond
9015 ((eq type 'anniversary)
9016 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
9017 (progn
9018 (or (org-at-heading-p t)
9019 (progn
9020 (outline-next-heading)
9021 (insert "* Anniversaries\n\n")
9022 (beginning-of-line -1)))))
9023 (outline-next-heading)
9024 (org-back-over-empty-lines)
9025 (backward-char 1)
9026 (insert "\n")
9027 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
9028 (nth 2 d1) (car d1) (nth 1 d1) text)))
9029 ((eq type 'day)
9030 (let ((org-prefix-has-time t)
9031 (org-agenda-time-leading-zero t)
9032 fmt time time2)
9033 (if org-agenda-insert-diary-extract-time
9034 ;; Use org-agenda-format-item to parse text for a time-range and
9035 ;; remove it. FIXME: This is a hack, we should refactor
9036 ;; that function to make time extraction available separately
9037 (setq fmt (org-agenda-format-item nil text nil nil nil t)
9038 time (get-text-property 0 'time fmt)
9039 time2 (if (> (length time) 0)
9040 ;; split-string removes trailing ...... if
9041 ;; no end time given. First space
9042 ;; separates time from date.
9043 (concat " " (car (split-string time "\\.")))
9044 nil)
9045 text (get-text-property 0 'txt fmt)))
9046 (if (eq org-agenda-insert-diary-strategy 'top-level)
9047 (org-agenda-insert-diary-as-top-level text)
9048 (require 'org-datetree)
9049 (org-datetree-find-date-create d1)
9050 (org-agenda-insert-diary-make-new-entry text))
9051 (org-insert-time-stamp (org-time-from-absolute
9052 (calendar-absolute-from-gregorian d1))
9053 nil nil nil nil time2))
9054 (end-of-line 0))
9055 ((eq type 'block)
9056 (if (> (calendar-absolute-from-gregorian d1)
9057 (calendar-absolute-from-gregorian d2))
9058 (setq d1 (prog1 d2 (setq d2 d1))))
9059 (if (eq org-agenda-insert-diary-strategy 'top-level)
9060 (org-agenda-insert-diary-as-top-level text)
9061 (require 'org-datetree)
9062 (org-datetree-find-date-create d1)
9063 (org-agenda-insert-diary-make-new-entry text))
9064 (org-insert-time-stamp (org-time-from-absolute
9065 (calendar-absolute-from-gregorian d1)))
9066 (insert "--")
9067 (org-insert-time-stamp (org-time-from-absolute
9068 (calendar-absolute-from-gregorian d2)))
9069 (end-of-line 0)))
9070 (if (string-match "\\S-" text)
9071 (progn
9072 (set-window-configuration cw)
9073 (message "%s entry added to %s"
9074 (capitalize (symbol-name type))
9075 (abbreviate-file-name org-agenda-diary-file)))
9076 (org-reveal t)
9077 (message "Please finish entry here"))))
9079 (defun org-agenda-insert-diary-as-top-level (text)
9080 "Make new entry as a top-level entry at the end of the file.
9081 Add TEXT as headline, and position the cursor in the second line so that
9082 a timestamp can be added there."
9083 (widen)
9084 (goto-char (point-max))
9085 (or (bolp) (insert "\n"))
9086 (insert "* " text "\n")
9087 (if org-adapt-indentation (org-indent-to-column 2)))
9089 (defun org-agenda-insert-diary-make-new-entry (text)
9090 "Make new entry as last child of current entry.
9091 Add TEXT as headline, and position the cursor in the second line so that
9092 a timestamp can be added there."
9093 (let ((org-show-following-heading t)
9094 (org-show-siblings t)
9095 (org-show-hierarchy-above t)
9096 (org-show-entry-below t)
9097 col)
9098 (outline-next-heading)
9099 (org-back-over-empty-lines)
9100 (or (looking-at "[ \t]*$")
9101 (progn (insert "\n") (backward-char 1)))
9102 (org-insert-heading nil t)
9103 (org-do-demote)
9104 (setq col (current-column))
9105 (insert text "\n")
9106 (if org-adapt-indentation (org-indent-to-column col))
9107 (let ((org-show-following-heading t)
9108 (org-show-siblings t)
9109 (org-show-hierarchy-above t)
9110 (org-show-entry-below t))
9111 (org-show-context))))
9113 (defun org-agenda-diary-entry ()
9114 "Make a diary entry, like the `i' command from the calendar.
9115 All the standard commands work: block, weekly etc.
9116 When `org-agenda-diary-file' points to a file,
9117 `org-agenda-diary-entry-in-org-file' is called instead to create
9118 entries in that Org-mode file."
9119 (interactive)
9120 (if (not (eq org-agenda-diary-file 'diary-file))
9121 (org-agenda-diary-entry-in-org-file)
9122 (require 'diary-lib)
9123 (let* ((char (progn
9124 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9125 (read-char-exclusive)))
9126 (cmd (cdr (assoc char
9127 '((?d . insert-diary-entry)
9128 (?w . insert-weekly-diary-entry)
9129 (?m . insert-monthly-diary-entry)
9130 (?y . insert-yearly-diary-entry)
9131 (?a . insert-anniversary-diary-entry)
9132 (?b . insert-block-diary-entry)
9133 (?c . insert-cyclic-diary-entry)))))
9134 (oldf (symbol-function 'calendar-cursor-to-date))
9135 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9136 (point (point))
9137 (mark (or (mark t) (point))))
9138 (unless cmd
9139 (error "No command associated with <%c>" char))
9140 (unless (and (get-text-property point 'day)
9141 (or (not (equal ?b char))
9142 (get-text-property mark 'day)))
9143 (error "Don't know which date to use for diary entry"))
9144 ;; We implement this by hacking the `calendar-cursor-to-date' function
9145 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9146 (let ((calendar-mark-ring
9147 (list (calendar-gregorian-from-absolute
9148 (or (get-text-property mark 'day)
9149 (get-text-property point 'day))))))
9150 (unwind-protect
9151 (progn
9152 (fset 'calendar-cursor-to-date
9153 (lambda (&optional error dummy)
9154 (calendar-gregorian-from-absolute
9155 (get-text-property point 'day))))
9156 (call-interactively cmd))
9157 (fset 'calendar-cursor-to-date oldf))))))
9159 (defun org-agenda-execute-calendar-command (cmd)
9160 "Execute a calendar command from the agenda with date from cursor."
9161 (org-agenda-check-type t 'agenda 'timeline)
9162 (require 'diary-lib)
9163 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9164 (error "Don't know which date to use for the calendar command"))
9165 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9166 (point (point))
9167 (date (calendar-gregorian-from-absolute
9168 (get-text-property point 'day)))
9169 ;; the following 2 vars are needed in the calendar
9170 (displayed-month (car date))
9171 (displayed-year (nth 2 date)))
9172 (unwind-protect
9173 (progn
9174 (fset 'calendar-cursor-to-date
9175 (lambda (&optional error dummy)
9176 (calendar-gregorian-from-absolute
9177 (get-text-property point 'day))))
9178 (call-interactively cmd))
9179 (fset 'calendar-cursor-to-date oldf))))
9181 (defun org-agenda-phases-of-moon ()
9182 "Display the phases of the moon for the 3 months around the cursor date."
9183 (interactive)
9184 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9186 (defun org-agenda-holidays ()
9187 "Display the holidays for the 3 months around the cursor date."
9188 (interactive)
9189 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9191 (defvar calendar-longitude) ; defined in calendar.el
9192 (defvar calendar-latitude) ; defined in calendar.el
9193 (defvar calendar-location-name) ; defined in calendar.el
9195 (defun org-agenda-sunrise-sunset (arg)
9196 "Display sunrise and sunset for the cursor date.
9197 Latitude and longitude can be specified with the variables
9198 `calendar-latitude' and `calendar-longitude'. When called with prefix
9199 argument, latitude and longitude will be prompted for."
9200 (interactive "P")
9201 (require 'solar)
9202 (let ((calendar-longitude (if arg nil calendar-longitude))
9203 (calendar-latitude (if arg nil calendar-latitude))
9204 (calendar-location-name
9205 (if arg "the given coordinates" calendar-location-name)))
9206 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9208 (defun org-agenda-goto-calendar ()
9209 "Open the Emacs calendar with the date at the cursor."
9210 (interactive)
9211 (org-agenda-check-type t 'agenda 'timeline)
9212 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9213 (error "Don't know which date to open in calendar")))
9214 (date (calendar-gregorian-from-absolute day))
9215 (calendar-move-hook nil)
9216 (calendar-view-holidays-initially-flag nil)
9217 (calendar-view-diary-initially-flag nil))
9218 (calendar)
9219 (calendar-goto-date date)))
9221 ;;;###autoload
9222 (defun org-calendar-goto-agenda ()
9223 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9224 This is a command that has to be installed in `calendar-mode-map'."
9225 (interactive)
9226 (org-agenda-list nil (calendar-absolute-from-gregorian
9227 (calendar-cursor-to-date))
9228 nil))
9230 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9231 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9232 This is a command that has to be installed in `calendar-mode-map'.
9234 \(fn)" t nil)
9236 (defun org-agenda-convert-date ()
9237 (interactive)
9238 (org-agenda-check-type t 'agenda 'timeline)
9239 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9240 date s)
9241 (unless day
9242 (error "Don't know which date to convert"))
9243 (setq date (calendar-gregorian-from-absolute day))
9244 (setq s (concat
9245 "Gregorian: " (calendar-date-string date) "\n"
9246 "ISO: " (calendar-iso-date-string date) "\n"
9247 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9248 "Julian: " (calendar-julian-date-string date) "\n"
9249 "Astron. JD: " (calendar-astro-date-string date)
9250 " (Julian date number at noon UTC)\n"
9251 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9252 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9253 "French: " (calendar-french-date-string date) "\n"
9254 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9255 "Mayan: " (calendar-mayan-date-string date) "\n"
9256 "Coptic: " (calendar-coptic-date-string date) "\n"
9257 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9258 "Persian: " (calendar-persian-date-string date) "\n"
9259 "Chinese: " (calendar-chinese-date-string date) "\n"))
9260 (with-output-to-temp-buffer "*Dates*"
9261 (princ s))
9262 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9264 ;;; Bulk commands
9266 (defun org-agenda-bulk-marked-p ()
9267 (eq (get-char-property (point-at-bol) 'type)
9268 'org-marked-entry-overlay))
9270 (defun org-agenda-bulk-mark (&optional arg)
9271 "Mark the entry at point for future bulk action."
9272 (interactive "p")
9273 (dotimes (i (or arg 1))
9274 (unless (org-get-at-bol 'org-agenda-diary-link)
9275 (let* ((m (org-get-at-bol 'org-hd-marker))
9277 (unless (org-agenda-bulk-marked-p)
9278 (unless m (error "Nothing to mark at point"))
9279 (push m org-agenda-bulk-marked-entries)
9280 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9281 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9282 (org-get-todo-face "TODO")
9283 'evaporate)
9284 (overlay-put ov 'type 'org-marked-entry-overlay))
9285 (beginning-of-line 2)
9286 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9287 (beginning-of-line 2))
9288 (message "%d entries marked for bulk action"
9289 (length org-agenda-bulk-marked-entries))))))
9291 (defun org-agenda-bulk-mark-all ()
9292 "Mark all entries for future agenda bulk action."
9293 (interactive)
9294 (org-agenda-bulk-mark-regexp "."))
9296 (defun org-agenda-bulk-mark-regexp (regexp)
9297 "Mark entries matching REGEXP for future agenda bulk action."
9298 (interactive "sMark entries matching regexp: ")
9299 (let ((entries-marked 0))
9300 (save-excursion
9301 (goto-char (point-min))
9302 (goto-char (next-single-property-change (point) 'txt))
9303 (while (re-search-forward regexp nil t)
9304 (when (string-match regexp (get-text-property (point) 'txt))
9305 (setq entries-marked (1+ entries-marked))
9306 (call-interactively 'org-agenda-bulk-mark))))
9307 (if (not entries-marked)
9308 (message "No entry matching this regexp."))))
9310 (defun org-agenda-bulk-unmark (&optional arg)
9311 "Unmark the entry at point for future bulk action."
9312 (interactive "P")
9313 (if arg
9314 (org-agenda-bulk-unmark-all)
9315 (cond ((org-agenda-bulk-marked-p)
9316 (org-agenda-bulk-remove-overlays
9317 (point-at-bol) (+ 2 (point-at-bol)))
9318 (setq org-agenda-bulk-marked-entries
9319 (delete (org-get-at-bol 'org-hd-marker)
9320 org-agenda-bulk-marked-entries))
9321 (beginning-of-line 2)
9322 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9323 (beginning-of-line 2))
9324 (message "%d entries left marked for bulk action"
9325 (length org-agenda-bulk-marked-entries)))
9326 (t (message "No entry to unmark here")))))
9328 (defun org-agenda-bulk-toggle ()
9329 "Toggle marking the entry at point for bulk action."
9330 (interactive)
9331 (if (org-agenda-bulk-marked-p)
9332 (org-agenda-bulk-unmark)
9333 (org-agenda-bulk-mark)))
9335 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9336 "Remove the mark overlays between BEG and END in the agenda buffer.
9337 BEG and END default to the buffer limits.
9339 This only removes the overlays, it does not remove the markers
9340 from the list in `org-agenda-bulk-marked-entries'."
9341 (interactive)
9342 (mapc (lambda (ov)
9343 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9344 (delete-overlay ov)))
9345 (overlays-in (or beg (point-min)) (or end (point-max)))))
9347 (defun org-agenda-bulk-unmark-all ()
9348 "Remove all marks in the agenda buffer.
9349 This will remove the markers and the overlays."
9350 (interactive)
9351 (if (null org-agenda-bulk-marked-entries)
9352 (message "No entry to unmark")
9353 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9354 (setq org-agenda-bulk-marked-entries nil)
9355 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9357 (defcustom org-agenda-persistent-marks nil
9358 "Non-nil means marked items will stay marked after a bulk action.
9359 You can toggle this interactively by typing `p' when prompted for a
9360 bulk action."
9361 :group 'org-agenda
9362 :version "24.1"
9363 :type 'boolean)
9365 (defun org-agenda-bulk-action (&optional arg)
9366 "Execute an remote-editing action on all marked entries.
9367 The prefix arg is passed through to the command if possible."
9368 (interactive "P")
9369 ;; Make sure we have markers, and only valid ones
9370 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9371 (mapc
9372 (lambda (m)
9373 (unless (and (markerp m)
9374 (marker-buffer m)
9375 (buffer-live-p (marker-buffer m))
9376 (marker-position m))
9377 (error "Marker %s for bulk command is invalid" m)))
9378 org-agenda-bulk-marked-entries)
9380 ;; Prompt for the bulk command
9381 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9382 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9383 "[S]catter [f]unction "
9384 (when org-agenda-bulk-custom-functions
9385 (concat " Custom: ["
9386 (mapconcat (lambda(f) (char-to-string (car f)))
9387 org-agenda-bulk-custom-functions "")
9388 "]"))))
9389 (catch 'exit
9390 (let* ((action (read-char-exclusive))
9391 (org-log-refile (if org-log-refile 'time nil))
9392 (entries (reverse org-agenda-bulk-marked-entries))
9393 (org-overriding-default-time
9394 (if (get-text-property (point) 'org-agenda-date-header)
9395 (org-get-cursor-date)))
9396 redo-at-end
9397 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9398 (cond
9399 ((equal action ?p)
9400 (let ((org-agenda-persistent-marks
9401 (not org-agenda-persistent-marks)))
9402 (org-agenda-bulk-action)
9403 (throw 'exit nil)))
9405 ((equal action ?$)
9406 (setq cmd '(org-agenda-archive)))
9408 ((equal action ?A)
9409 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9411 ((member action '(?r ?w))
9412 (setq rfloc (org-refile-get-location
9413 "Refile to"
9414 (marker-buffer (car entries))
9415 org-refile-allow-creating-parent-nodes))
9416 (if (nth 3 rfloc)
9417 (setcar (nthcdr 3 rfloc)
9418 (move-marker (make-marker) (nth 3 rfloc)
9419 (or (get-file-buffer (nth 1 rfloc))
9420 (find-buffer-visiting (nth 1 rfloc))
9421 (error "This should not happen")))))
9423 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9424 redo-at-end t))
9426 ((equal action ?t)
9427 (setq state (org-icompleting-read
9428 "Todo state: "
9429 (with-current-buffer (marker-buffer (car entries))
9430 (mapcar 'list org-todo-keywords-1))))
9431 (setq cmd `(let ((org-inhibit-blocking t)
9432 (org-inhibit-logging 'note))
9433 (org-agenda-todo ,state))))
9435 ((memq action '(?- ?+))
9436 (setq tag (org-icompleting-read
9437 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9438 (with-current-buffer (marker-buffer (car entries))
9439 (delq nil
9440 (mapcar (lambda (x)
9441 (if (stringp (car x)) x)) org-tag-alist)))))
9442 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9444 ((memq action '(?s ?d))
9445 (let* ((time
9446 (unless arg
9447 (org-read-date
9448 nil nil nil
9449 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9450 org-overriding-default-time)))
9451 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9452 (setq cmd `(eval '(,c1 arg ,time)))))
9454 ((equal action ?S)
9455 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9456 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9457 (let ((days (read-number
9458 (format "Scatter tasks across how many %sdays: "
9459 (if arg "week" "")) 7)))
9460 (setq cmd
9461 `(let ((distance (1+ (random ,days))))
9462 (if arg
9463 (let ((dist distance)
9464 (day-of-week
9465 (calendar-day-of-week
9466 (calendar-gregorian-from-absolute (org-today)))))
9467 (dotimes (i (1+ dist))
9468 (while (member day-of-week org-agenda-weekend-days)
9469 (incf distance)
9470 (incf day-of-week)
9471 (if (= day-of-week 7)
9472 (setq day-of-week 0)))
9473 (incf day-of-week)
9474 (if (= day-of-week 7)
9475 (setq day-of-week 0)))))
9476 ;; silently fail when try to replan a sexp entry
9477 (condition-case nil
9478 (let* ((date (calendar-gregorian-from-absolute
9479 (+ (org-today) distance)))
9480 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9481 (nth 2 date))))
9482 (org-agenda-schedule nil time))
9483 (error nil)))))))
9485 ((assoc action org-agenda-bulk-custom-functions)
9486 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9487 redo-at-end t))
9489 ((equal action ?f)
9490 (setq cmd (list (intern
9491 (org-icompleting-read "Function: "
9492 obarray 'fboundp t nil nil)))))
9494 (t (error "Invalid bulk action")))
9496 ;; Sort the markers, to make sure that parents are handled before children
9497 (setq entries (sort entries
9498 (lambda (a b)
9499 (cond
9500 ((equal (marker-buffer a) (marker-buffer b))
9501 (< (marker-position a) (marker-position b)))
9503 (string< (buffer-name (marker-buffer a))
9504 (buffer-name (marker-buffer b))))))))
9506 ;; Now loop over all markers and apply cmd
9507 (while (setq e (pop entries))
9508 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9509 (if (not pos)
9510 (progn (message "Skipping removed entry at %s" e)
9511 (setq cntskip (1+ cntskip)))
9512 (goto-char pos)
9513 (let (org-loop-over-headlines-in-active-region)
9514 (eval cmd))
9515 (setq cnt (1+ cnt))))
9516 (when redo-at-end (org-agenda-redo))
9517 (unless org-agenda-persistent-marks
9518 (org-agenda-bulk-unmark-all))
9519 (message "Acted on %d entries%s%s"
9521 (if (= cntskip 0)
9523 (format ", skipped %d (disappeared before their turn)"
9524 cntskip))
9525 (if (not org-agenda-persistent-marks)
9526 "" " (kept marked)"))))))
9528 (defun org-agenda-capture (&optional with-time)
9529 "Call `org-capture' with the date at point.
9530 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9531 current HH:MM time."
9532 (interactive "P")
9533 (if (not (eq major-mode 'org-agenda-mode))
9534 (user-error "You cannot do this outside of agenda buffers")
9535 (let ((org-overriding-default-time
9536 (org-get-cursor-date (equal with-time 1))))
9537 (call-interactively 'org-capture))))
9539 ;;; Flagging notes
9541 (defun org-agenda-show-the-flagging-note ()
9542 "Display the flagging note in the other window.
9543 When called a second time in direct sequence, offer to remove the FLAGGING
9544 tag and (if present) the flagging note."
9545 (interactive)
9546 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9547 (win (selected-window))
9548 note heading newhead)
9549 (unless hdmarker
9550 (error "No linked entry at point"))
9551 (if (and (eq this-command last-command)
9552 (y-or-n-p "Unflag and remove any flagging note? "))
9553 (progn
9554 (org-agenda-remove-flag hdmarker)
9555 (let ((win (get-buffer-window "*Flagging Note*")))
9556 (and win (delete-window win)))
9557 (message "Entry unflagged"))
9558 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9559 (unless note
9560 (error "No flagging note"))
9561 (org-kill-new note)
9562 (org-switch-to-buffer-other-window "*Flagging Note*")
9563 (erase-buffer)
9564 (insert note)
9565 (goto-char (point-min))
9566 (while (re-search-forward "\\\\n" nil t)
9567 (replace-match "\n" t t))
9568 (goto-char (point-min))
9569 (select-window win)
9570 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9572 (defun org-agenda-remove-flag (marker)
9573 "Remove the FLAGGED tag and any flagging note in the entry."
9574 (let (newhead)
9575 (org-with-point-at marker
9576 (org-toggle-tag "FLAGGED" 'off)
9577 (org-entry-delete nil "THEFLAGGINGNOTE")
9578 (setq newhead (org-get-heading)))
9579 (org-agenda-change-all-lines newhead marker)
9580 (message "Entry unflagged")))
9582 (defun org-agenda-get-any-marker (&optional pos)
9583 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9584 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9586 ;;; Appointment reminders
9588 (defvar appt-time-msg-list) ; defined in appt.el
9590 ;;;###autoload
9591 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9592 "Activate appointments found in `org-agenda-files'.
9593 With a \\[universal-argument] prefix, refresh the list of
9594 appointments.
9596 If FILTER is t, interactively prompt the user for a regular
9597 expression, and filter out entries that don't match it.
9599 If FILTER is a string, use this string as a regular expression
9600 for filtering entries out.
9602 If FILTER is a function, filter out entries against which
9603 calling the function returns nil. This function takes one
9604 argument: an entry from `org-agenda-get-day-entries'.
9606 FILTER can also be an alist with the car of each cell being
9607 either 'headline or 'category. For example:
9609 '((headline \"IMPORTANT\")
9610 (category \"Work\"))
9612 will only add headlines containing IMPORTANT or headlines
9613 belonging to the \"Work\" category.
9615 ARGS are symbols indicating what kind of entries to consider.
9616 By default `org-agenda-to-appt' will use :deadline, :scheduled
9617 and :timestamp entries. See the docstring of `org-diary' for
9618 details and examples.
9620 If an entry as a APPT_WARNTIME property, its value will be used
9621 to override `appt-message-warning-time'."
9622 (interactive "P")
9623 (if refresh (setq appt-time-msg-list nil))
9624 (if (eq filter t)
9625 (setq filter (read-from-minibuffer "Regexp filter: ")))
9626 (let* ((cnt 0) ; count added events
9627 (scope (or args '(:deadline :scheduled :timestamp)))
9628 (org-agenda-new-buffers nil)
9629 (org-deadline-warning-days 0)
9630 ;; Do not use `org-today' here because appt only takes
9631 ;; time and without date as argument, so it may pass wrong
9632 ;; information otherwise
9633 (today (org-date-to-gregorian
9634 (time-to-days (current-time))))
9635 (org-agenda-restrict nil)
9636 (files (org-agenda-files 'unrestricted)) entries file
9637 (org-agenda-buffer nil))
9638 ;; Get all entries which may contain an appt
9639 (org-agenda-prepare-buffers files)
9640 (while (setq file (pop files))
9641 (setq entries
9642 (delq nil
9643 (append entries
9644 (apply 'org-agenda-get-day-entries
9645 file today scope)))))
9646 ;; Map thru entries and find if we should filter them out
9647 (mapc
9648 (lambda(x)
9649 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9650 (cat (get-text-property 1 'org-category x))
9651 (tod (get-text-property 1 'time-of-day x))
9652 (ok (or (null filter)
9653 (and (stringp filter) (string-match filter evt))
9654 (and (functionp filter) (funcall filter x))
9655 (and (listp filter)
9656 (let ((cat-filter (cadr (assoc 'category filter)))
9657 (evt-filter (cadr (assoc 'headline filter))))
9658 (or (and (stringp cat-filter)
9659 (string-match cat-filter cat))
9660 (and (stringp evt-filter)
9661 (string-match evt-filter evt)))))))
9662 (wrn (get-text-property 1 'warntime x)))
9663 ;; FIXME: Shall we remove text-properties for the appt text?
9664 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9665 (when (and ok tod)
9666 (setq tod (concat "00" (number-to-string tod))
9667 tod (when (string-match
9668 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9669 (concat (match-string 1 tod) ":"
9670 (match-string 2 tod))))
9671 (if (version< emacs-version "23.3")
9672 (appt-add tod evt)
9673 (appt-add tod evt wrn))
9674 (setq cnt (1+ cnt))))) entries)
9675 (org-release-buffers org-agenda-new-buffers)
9676 (if (eq cnt 0)
9677 (message "No event to add")
9678 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9680 (autoload 'org-agenda-to-appt "org-agenda" "\
9681 Activate appointments found in `org-agenda-files'.
9682 With a \\[universal-argument] prefix, refresh the list of
9683 appointments.
9685 If FILTER is t, interactively prompt the user for a regular
9686 expression, and filter out entries that don't match it.
9688 If FILTER is a string, use this string as a regular expression
9689 for filtering entries out.
9691 If FILTER is a function, filter out entries against which
9692 calling the function returns nil. This function takes one
9693 argument: an entry from `org-agenda-get-day-entries'.
9695 FILTER can also be an alist with the car of each cell being
9696 either 'headline or 'category. For example:
9698 '((headline \"IMPORTANT\")
9699 (category \"Work\"))
9701 will only add headlines containing IMPORTANT or headlines
9702 belonging to the \"Work\" category.
9704 ARGS are symbols indicating what kind of entries to consider.
9705 By default `org-agenda-to-appt' will use :deadline, :scheduled
9706 and :timestamp entries. See the docstring of `org-diary' for
9707 details and examples.
9709 If an entry as a APPT_WARNTIME property, its value will be used
9710 to override `appt-message-warning-time'.
9712 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9714 (defun org-agenda-todayp (date)
9715 "Does DATE mean today, when considering `org-extend-today-until'?"
9716 (let ((today (org-today))
9717 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9718 date)))
9719 (eq date today)))
9721 (defun org-agenda-todo-yesterday (&optional arg)
9722 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9723 (interactive "P")
9724 (let* ((hour (third (decode-time
9725 (org-current-time))))
9726 (org-extend-today-until (1+ hour)))
9727 (org-agenda-todo arg)))
9729 (provide 'org-agenda)
9731 ;;; org-agenda.el ends here