initialize Babel languages and provide possibility to load extra packages for testing
[org-mode.git] / lisp / org-agenda.el
blobffc27cceb968fc56b01aab0142e498170599ca8e
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (eval-when-compile
50 (require 'cl))
52 (declare-function diary-add-to-list "diary-lib"
53 (date string specifier &optional marker globcolor literal))
54 (declare-function calendar-absolute-from-iso "cal-iso" (date))
55 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
56 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
57 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
58 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
59 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-french-date-string "cal-french" (&optional date))
61 (declare-function calendar-goto-date "cal-move" (date))
62 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
63 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
64 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
65 (declare-function calendar-iso-from-absolute "cal-iso" (date))
66 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
67 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
68 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
69 (declare-function calendar-check-holidays "holidays" (date))
71 (declare-function org-datetree-find-date-create "org-datetree"
72 (date &optional keep-restriction))
73 (declare-function org-columns-quit "org-colview" ())
74 (declare-function diary-date-display-form "diary-lib" (&optional type))
75 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
76 (declare-function org-habit-insert-consistency-graphs
77 "org-habit" (&optional line))
78 (declare-function org-is-habit-p "org-habit" (&optional pom))
79 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
80 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
81 (declare-function org-pop-to-buffer-same-window "org-compat"
82 (&optional buffer-or-name norecord label))
84 (defvar calendar-mode-map)
85 (defvar org-clock-current-task) ; defined in org-clock.el
86 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
87 (defvar org-habit-show-habits)
88 (defvar org-habit-show-habits-only-for-today)
90 ;; Defined somewhere in this file, but used before definition.
91 (defvar org-agenda-buffer-name)
92 (defvar org-agenda-overriding-header)
93 (defvar org-agenda-title-append nil)
94 (defvar entry)
95 (defvar date)
96 (defvar org-agenda-undo-list)
97 (defvar org-agenda-pending-undo-list)
98 (defvar original-date) ; dynamically scoped, calendar.el does scope this
100 (defcustom org-agenda-confirm-kill 1
101 "When set, remote killing from the agenda buffer needs confirmation.
102 When t, a confirmation is always needed. When a number N, confirmation is
103 only needed when the text to be killed contains more than N non-white lines."
104 :group 'org-agenda
105 :type '(choice
106 (const :tag "Never" nil)
107 (const :tag "Always" t)
108 (integer :tag "When more than N lines")))
110 (defcustom org-agenda-compact-blocks nil
111 "Non-nil means make the block agenda more compact.
112 This is done globally by leaving out lines like the agenda span
113 name and week number or the separator lines."
114 :group 'org-agenda
115 :type 'boolean)
117 (defcustom org-agenda-block-separator ?=
118 "The separator between blocks in the agenda.
119 If this is a string, it will be used as the separator, with a newline added.
120 If it is a character, it will be repeated to fill the window width.
121 If nil the separator is disabled. In `org-agenda-custom-commands' this
122 addresses the separator between the current and the previous block."
123 :group 'org-agenda
124 :type '(choice
125 (const :tag "Disabled" nil)
126 (character)
127 (string)))
129 (defgroup org-agenda-export nil
130 "Options concerning exporting agenda views in Org-mode."
131 :tag "Org Agenda Export"
132 :group 'org-agenda)
134 (defcustom org-agenda-with-colors t
135 "Non-nil means use colors in agenda views."
136 :group 'org-agenda-export
137 :type 'boolean)
139 (defcustom org-agenda-exporter-settings nil
140 "Alist of variable/value pairs that should be active during agenda export.
141 This is a good place to set options for ps-print and for htmlize.
142 Note that the way this is implemented, the values will be evaluated
143 before assigned to the variables. So make sure to quote values you do
144 *not* want evaluated, for example
146 (setq org-agenda-exporter-settings
147 '((ps-print-color-p 'black-white)))"
148 :group 'org-agenda-export
149 :type '(repeat
150 (list
151 (variable)
152 (sexp :tag "Value"))))
154 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
155 "Hook run in temporary buffer before writing it to an export file.
156 A useful function is `org-agenda-add-entry-text'."
157 :group 'org-agenda-export
158 :type 'hook
159 :options '(org-agenda-add-entry-text))
161 (defcustom org-agenda-add-entry-text-maxlines 0
162 "Maximum number of entry text lines to be added to agenda.
163 This is only relevant when `org-agenda-add-entry-text' is part of
164 `org-agenda-before-write-hook', which it is by default.
165 When this is 0, nothing will happen. When it is greater than 0, it
166 specifies the maximum number of lines that will be added for each entry
167 that is listed in the agenda view.
169 Note that this variable is not used during display, only when exporting
170 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
171 and `org-agenda-entry-text-maxlines'."
172 :group 'org-agenda
173 :type 'integer)
175 (defcustom org-agenda-add-entry-text-descriptive-links t
176 "Non-nil means export org-links as descriptive links in agenda added text.
177 This variable applies to the text added to the agenda when
178 `org-agenda-add-entry-text-maxlines' is larger than 0.
179 When this variable nil, the URL will (also) be shown."
180 :group 'org-agenda
181 :type 'boolean)
183 (defcustom org-agenda-export-html-style ""
184 "The style specification for exported HTML Agenda files.
185 If this variable contains a string, it will replace the default <style>
186 section as produced by `htmlize'.
187 Since there are different ways of setting style information, this variable
188 needs to contain the full HTML structure to provide a style, including the
189 surrounding HTML tags. The style specifications should include definitions
190 the fonts used by the agenda, here is an example:
192 <style type=\"text/css\">
193 p { font-weight: normal; color: gray; }
194 .org-agenda-structure {
195 font-size: 110%;
196 color: #003399;
197 font-weight: 600;
199 .org-todo {
200 color: #cc6666;
201 font-weight: bold;
203 .org-agenda-done {
204 color: #339933;
206 .org-done {
207 color: #339933;
209 .title { text-align: center; }
210 .todo, .deadline { color: red; }
211 .done { color: green; }
212 </style>
214 or, if you want to keep the style in a file,
216 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
218 As the value of this option simply gets inserted into the HTML <head> header,
219 you can \"misuse\" it to also add other text to the header. However,
220 <style>...</style> is required, if not present the variable will be ignored."
221 :group 'org-agenda-export
222 :group 'org-export-html
223 :type 'string)
225 (defcustom org-agenda-persistent-filter nil
226 "When set, keep filters from one agenda view to the next."
227 :group 'org-agenda
228 :type 'boolean)
230 (defgroup org-agenda-custom-commands nil
231 "Options concerning agenda views in Org-mode."
232 :tag "Org Agenda Custom Commands"
233 :group 'org-agenda)
235 (defconst org-sorting-choice
236 '(choice
237 (const time-up) (const time-down)
238 (const category-keep) (const category-up) (const category-down)
239 (const tag-down) (const tag-up)
240 (const priority-up) (const priority-down)
241 (const todo-state-up) (const todo-state-down)
242 (const effort-up) (const effort-down)
243 (const habit-up) (const habit-down)
244 (const alpha-up) (const alpha-down)
245 (const user-defined-up) (const user-defined-down))
246 "Sorting choices.")
248 ;; Keep custom values for `org-agenda-filter-preset' compatible with
249 ;; the new variable `org-agenda-tag-filter-preset'.
250 (if (fboundp 'defvaralias)
251 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
252 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
254 (defconst org-agenda-custom-commands-local-options
255 `(repeat :tag "Local settings for this command. Remember to quote values"
256 (choice :tag "Setting"
257 (list :tag "Heading for this block"
258 (const org-agenda-overriding-header)
259 (string :tag "Headline"))
260 (list :tag "Files to be searched"
261 (const org-agenda-files)
262 (list
263 (const :format "" quote)
264 (repeat (file))))
265 (list :tag "Sorting strategy"
266 (const org-agenda-sorting-strategy)
267 (list
268 (const :format "" quote)
269 (repeat
270 ,org-sorting-choice)))
271 (list :tag "Prefix format"
272 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
273 (string))
274 (list :tag "Number of days in agenda"
275 (const org-agenda-span)
276 (choice (const :tag "Day" 'day)
277 (const :tag "Week" 'week)
278 (const :tag "Month" 'month)
279 (const :tag "Year" 'year)
280 (integer :tag "Custom")))
281 (list :tag "Fixed starting date"
282 (const org-agenda-start-day)
283 (string :value "2007-11-01"))
284 (list :tag "Start on day of week"
285 (const org-agenda-start-on-weekday)
286 (choice :value 1
287 (const :tag "Today" nil)
288 (integer :tag "Weekday No.")))
289 (list :tag "Include data from diary"
290 (const org-agenda-include-diary)
291 (boolean))
292 (list :tag "Deadline Warning days"
293 (const org-deadline-warning-days)
294 (integer :value 1))
295 (list :tag "Category filter preset"
296 (const org-agenda-category-filter-preset)
297 (list
298 (const :format "" quote)
299 (repeat
300 (string :tag "+category or -category"))))
301 (list :tag "Tags filter preset"
302 (const org-agenda-tag-filter-preset)
303 (list
304 (const :format "" quote)
305 (repeat
306 (string :tag "+tag or -tag"))))
307 (list :tag "Set daily/weekly entry types"
308 (const org-agenda-entry-types)
309 (list
310 (const :format "" quote)
311 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
312 (const :deadline)
313 (const :scheduled)
314 (const :timestamp)
315 (const :sexp))))
316 (list :tag "Standard skipping condition"
317 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
318 (const org-agenda-skip-function)
319 (list
320 (const :format "" quote)
321 (list
322 (choice
323 :tag "Skipping range"
324 (const :tag "Skip entry" org-agenda-skip-entry-if)
325 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
326 (repeat :inline t :tag "Conditions for skipping"
327 (choice
328 :tag "Condition type"
329 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
330 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
331 (list :tag "TODO state is" :inline t
332 (const 'todo)
333 (choice
334 (const :tag "any not-done state" 'todo)
335 (const :tag "any done state" 'done)
336 (const :tag "any state" 'any)
337 (list :tag "Keyword list"
338 (const :format "" quote)
339 (repeat (string :tag "Keyword")))))
340 (list :tag "TODO state is not" :inline t
341 (const 'nottodo)
342 (choice
343 (const :tag "any not-done state" 'todo)
344 (const :tag "any done state" 'done)
345 (const :tag "any state" 'any)
346 (list :tag "Keyword list"
347 (const :format "" quote)
348 (repeat (string :tag "Keyword")))))
349 (const :tag "scheduled" 'scheduled)
350 (const :tag "not scheduled" 'notscheduled)
351 (const :tag "deadline" 'deadline)
352 (const :tag "no deadline" 'notdeadline)
353 (const :tag "timestamp" 'timestamp)
354 (const :tag "no timestamp" 'nottimestamp))))))
355 (list :tag "Non-standard skipping condition"
356 :value (org-agenda-skip-function)
357 (const org-agenda-skip-function)
358 (sexp :tag "Function or form (quoted!)"))
359 (list :tag "Any variable"
360 (variable :tag "Variable")
361 (sexp :tag "Value (sexp)"))))
362 "Selection of examples for agenda command settings.
363 This will be spliced into the custom type of
364 `org-agenda-custom-commands'.")
367 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
368 ((agenda "") (alltodo))))
369 "Custom commands for the agenda.
370 These commands will be offered on the splash screen displayed by the
371 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
373 (key desc type match settings files)
375 key The key (one or more characters as a string) to be associated
376 with the command.
377 desc A description of the command, when omitted or nil, a default
378 description is built using MATCH.
379 type The command type, any of the following symbols:
380 agenda The daily/weekly agenda.
381 todo Entries with a specific TODO keyword, in all agenda files.
382 search Entries containing search words entry or headline.
383 tags Tags/Property/TODO match in all agenda files.
384 tags-todo Tags/P/T match in all agenda files, TODO entries only.
385 todo-tree Sparse tree of specific TODO keyword in *current* file.
386 tags-tree Sparse tree with all tags matches in *current* file.
387 occur-tree Occur sparse tree for *current* file.
388 ... A user-defined function.
389 match What to search for:
390 - a single keyword for TODO keyword searches
391 - a tags match expression for tags searches
392 - a word search expression for text searches.
393 - a regular expression for occur searches
394 For all other commands, this should be the empty string.
395 settings A list of option settings, similar to that in a let form, so like
396 this: ((opt1 val1) (opt2 val2) ...). The values will be
397 evaluated at the moment of execution, so quote them when needed.
398 files A list of files file to write the produced agenda buffer to
399 with the command `org-store-agenda-views'.
400 If a file name ends in \".html\", an HTML version of the buffer
401 is written out. If it ends in \".ps\", a postscript version is
402 produced. Otherwise, only the plain text is written to the file.
404 You can also define a set of commands, to create a composite agenda buffer.
405 In this case, an entry looks like this:
407 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
409 where
411 desc A description string to be displayed in the dispatcher menu.
412 cmd An agenda command, similar to the above. However, tree commands
413 are not allowed, but instead you can get agenda and global todo list.
414 So valid commands for a set are:
415 (agenda \"\" settings)
416 (alltodo \"\" settings)
417 (stuck \"\" settings)
418 (todo \"match\" settings files)
419 (search \"match\" settings files)
420 (tags \"match\" settings files)
421 (tags-todo \"match\" settings files)
423 Each command can carry a list of options, and another set of options can be
424 given for the whole set of commands. Individual command options take
425 precedence over the general options.
427 When using several characters as key to a command, the first characters
428 are prefix commands. For the dispatcher to display useful information, you
429 should provide a description for the prefix, like
431 (setq org-agenda-custom-commands
432 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
433 (\"hl\" tags \"+HOME+Lisa\")
434 (\"hp\" tags \"+HOME+Peter\")
435 (\"hk\" tags \"+HOME+Kim\")))"
436 :group 'org-agenda-custom-commands
437 :type `(repeat
438 (choice :value ("x" "Describe command here" tags "" nil)
439 (list :tag "Single command"
440 (string :tag "Access Key(s) ")
441 (option (string :tag "Description"))
442 (choice
443 (const :tag "Agenda" agenda)
444 (const :tag "TODO list" alltodo)
445 (const :tag "Search words" search)
446 (const :tag "Stuck projects" stuck)
447 (const :tag "Tags/Property match (all agenda files)" tags)
448 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
449 (const :tag "TODO keyword search (all agenda files)" todo)
450 (const :tag "Tags sparse tree (current buffer)" tags-tree)
451 (const :tag "TODO keyword tree (current buffer)" todo-tree)
452 (const :tag "Occur tree (current buffer)" occur-tree)
453 (sexp :tag "Other, user-defined function"))
454 (string :tag "Match (only for some commands)")
455 ,org-agenda-custom-commands-local-options
456 (option (repeat :tag "Export" (file :tag "Export to"))))
457 (list :tag "Command series, all agenda files"
458 (string :tag "Access Key(s)")
459 (string :tag "Description ")
460 (repeat :tag "Component"
461 (choice
462 (list :tag "Agenda"
463 (const :format "" agenda)
464 (const :tag "" :format "" "")
465 ,org-agenda-custom-commands-local-options)
466 (list :tag "TODO list (all keywords)"
467 (const :format "" alltodo)
468 (const :tag "" :format "" "")
469 ,org-agenda-custom-commands-local-options)
470 (list :tag "Search words"
471 (const :format "" search)
472 (string :tag "Match")
473 ,org-agenda-custom-commands-local-options)
474 (list :tag "Stuck projects"
475 (const :format "" stuck)
476 (const :tag "" :format "" "")
477 ,org-agenda-custom-commands-local-options)
478 (list :tag "Tags search"
479 (const :format "" tags)
480 (string :tag "Match")
481 ,org-agenda-custom-commands-local-options)
482 (list :tag "Tags search, TODO entries only"
483 (const :format "" tags-todo)
484 (string :tag "Match")
485 ,org-agenda-custom-commands-local-options)
486 (list :tag "TODO keyword search"
487 (const :format "" todo)
488 (string :tag "Match")
489 ,org-agenda-custom-commands-local-options)
490 (list :tag "Other, user-defined function"
491 (symbol :tag "function")
492 (string :tag "Match")
493 ,org-agenda-custom-commands-local-options)))
495 (repeat :tag "Settings for entire command set"
496 (list (variable :tag "Any variable")
497 (sexp :tag "Value")))
498 (option (repeat :tag "Export" (file :tag "Export to"))))
499 (cons :tag "Prefix key documentation"
500 (string :tag "Access Key(s)")
501 (string :tag "Description ")))))
503 (defcustom org-agenda-query-register ?o
504 "The register holding the current query string.
505 The purpose of this is that if you construct a query string interactively,
506 you can then use it to define a custom command."
507 :group 'org-agenda-custom-commands
508 :type 'character)
510 (defcustom org-stuck-projects
511 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
512 "How to identify stuck projects.
513 This is a list of four items:
514 1. A tags/todo/property matcher string that is used to identify a project.
515 See the manual for a description of tag and property searches.
516 The entire tree below a headline matched by this is considered one project.
517 2. A list of TODO keywords identifying non-stuck projects.
518 If the project subtree contains any headline with one of these todo
519 keywords, the project is considered to be not stuck. If you specify
520 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
521 3. A list of tags identifying non-stuck projects.
522 If the project subtree contains any headline with one of these tags,
523 the project is considered to be not stuck. If you specify \"*\" as
524 a tag, any tag will mark the project unstuck. Note that this is about
525 the explicit presence of a tag somewhere in the subtree, inherited
526 tags to not count here. If inherited tags make a project not stuck,
527 use \"-TAG\" in the tags part of the matcher under (1.) above.
528 4. An arbitrary regular expression matching non-stuck projects.
530 If the project turns out to be not stuck, search continues also in the
531 subtree to see if any of the subtasks have project status.
533 See also the variable `org-tags-match-list-sublevels' which applies
534 to projects matched by this search as well.
536 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
537 or `C-c a #' to produce the list."
538 :group 'org-agenda-custom-commands
539 :type '(list
540 (string :tag "Tags/TODO match to identify a project")
541 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
542 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
543 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
545 (defcustom org-agenda-filter-effort-default-operator "<"
546 "The default operator for effort estimate filtering.
547 If you select an effort estimate limit without first pressing an operator,
548 this one will be used."
549 :group 'org-agenda-custom-commands
550 :type '(choice (const :tag "less or equal" "<")
551 (const :tag "greater or equal"">")
552 (const :tag "equal" "=")))
554 (defgroup org-agenda-skip nil
555 "Options concerning skipping parts of agenda files."
556 :tag "Org Agenda Skip"
557 :group 'org-agenda)
559 (defcustom org-agenda-skip-function-global nil
560 "Function to be called at each match during agenda construction.
561 If this function returns nil, the current match should not be skipped.
562 If the function decided to skip an agenda match, is must return the
563 buffer position from which the search should be continued.
564 This may also be a Lisp form, which will be evaluated.
566 This variable will be applied to every agenda match, including
567 tags/property searches and TODO lists. So try to make the test function
568 do its checking as efficiently as possible. To implement a skipping
569 condition just for specific agenda commands, use the variable
570 `org-agenda-skip-function' which can be set in the options section
571 of custom agenda commands."
572 :group 'org-agenda-skip
573 :type 'sexp)
575 (defgroup org-agenda-daily/weekly nil
576 "Options concerning the daily/weekly agenda."
577 :tag "Org Agenda Daily/Weekly"
578 :group 'org-agenda)
579 (defgroup org-agenda-todo-list nil
580 "Options concerning the global todo list agenda view."
581 :tag "Org Agenda Todo List"
582 :group 'org-agenda)
583 (defgroup org-agenda-match-view nil
584 "Options concerning the general tags/property/todo match agenda view."
585 :tag "Org Agenda Match View"
586 :group 'org-agenda)
587 (defgroup org-agenda-search-view nil
588 "Options concerning the general tags/property/todo match agenda view."
589 :tag "Org Agenda Match View"
590 :group 'org-agenda)
592 (defvar org-agenda-archives-mode nil
593 "Non-nil means the agenda will include archived items.
594 If this is the symbol `trees', trees in the selected agenda scope
595 that are marked with the ARCHIVE tag will be included anyway. When this is
596 t, also all archive files associated with the current selection of agenda
597 files will be included.")
599 (defcustom org-agenda-skip-comment-trees t
600 "Non-nil means skip trees that start with the COMMENT keyword.
601 When nil, these trees are also scanned by agenda commands."
602 :group 'org-agenda-skip
603 :type 'boolean)
605 (defcustom org-agenda-todo-list-sublevels t
606 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
607 When nil, the sublevels of a TODO entry are not checked, resulting in
608 potentially much shorter TODO lists."
609 :group 'org-agenda-skip
610 :group 'org-agenda-todo-list
611 :type 'boolean)
613 (defcustom org-agenda-todo-ignore-with-date nil
614 "Non-nil means don't show entries with a date in the global todo list.
615 You can use this if you prefer to mark mere appointments with a TODO keyword,
616 but don't want them to show up in the TODO list.
617 When this is set, it also covers deadlines and scheduled items, the settings
618 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
619 will be ignored.
620 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
621 :group 'org-agenda-skip
622 :group 'org-agenda-todo-list
623 :type 'boolean)
625 (defcustom org-agenda-todo-ignore-timestamp nil
626 "Non-nil means don't show entries with a timestamp.
627 This applies when creating the global todo list.
628 Valid values are:
630 past Don't show entries for today or in the past.
632 future Don't show entries with a timestamp in the future.
633 The idea behind this is that if it has a future
634 timestamp, you don't want to think about it until the
635 date.
637 all Don't show any entries with a timestamp in the global todo list.
638 The idea behind this is that by setting a timestamp, you
639 have already \"taken care\" of this item.
641 This variable can also have an integer as a value. If positive (N),
642 todos with a timestamp N or more days in the future will be ignored. If
643 negative (-N), todos with a timestamp N or more days in the past will be
644 ignored. If 0, todos with a timestamp either today or in the future will
645 be ignored. For example, a value of -1 will exclude todos with a
646 timestamp in the past (yesterday or earlier), while a value of 7 will
647 exclude todos with a timestamp a week or more in the future.
649 See also `org-agenda-todo-ignore-with-date'.
650 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
651 to make his option also apply to the tags-todo list."
652 :group 'org-agenda-skip
653 :group 'org-agenda-todo-list
654 :version "24.1"
655 :type '(choice
656 (const :tag "Ignore future timestamp todos" future)
657 (const :tag "Ignore past or present timestamp todos" past)
658 (const :tag "Ignore all timestamp todos" all)
659 (const :tag "Show timestamp todos" nil)
660 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
662 (defcustom org-agenda-todo-ignore-scheduled nil
663 "Non-nil means, ignore some scheduled TODO items when making TODO list.
664 This applies when creating the global todo list.
665 Valid values are:
667 past Don't show entries scheduled today or in the past.
669 future Don't show entries scheduled in the future.
670 The idea behind this is that by scheduling it, you don't want to
671 think about it until the scheduled date.
673 all Don't show any scheduled entries in the global todo list.
674 The idea behind this is that by scheduling it, you have already
675 \"taken care\" of this item.
677 t Same as `all', for backward compatibility.
679 This variable can also have an integer as a value. See
680 `org-agenda-todo-ignore-timestamp' for more details.
682 See also `org-agenda-todo-ignore-with-date'.
683 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
684 to make his option also apply to the tags-todo list."
685 :group 'org-agenda-skip
686 :group 'org-agenda-todo-list
687 :type '(choice
688 (const :tag "Ignore future-scheduled todos" future)
689 (const :tag "Ignore past- or present-scheduled todos" past)
690 (const :tag "Ignore all scheduled todos" all)
691 (const :tag "Ignore all scheduled todos (compatibility)" t)
692 (const :tag "Show scheduled todos" nil)
693 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
695 (defcustom org-agenda-todo-ignore-deadlines nil
696 "Non-nil means ignore some deadlined TODO items when making TODO list.
697 There are different motivations for using different values, please think
698 carefully when configuring this variable.
700 This applies when creating the global todo list.
701 Valid values are:
703 near Don't show near deadline entries. A deadline is near when it is
704 closer than `org-deadline-warning-days' days. The idea behind this
705 is that such items will appear in the agenda anyway.
707 far Don't show TODO entries where a deadline has been defined, but
708 the deadline is not near. This is useful if you don't want to
709 use the todo list to figure out what to do now.
711 past Don't show entries with a deadline timestamp for today or in the past.
713 future Don't show entries with a deadline timestamp in the future, not even
714 when they become `near' ones. Use it with caution.
716 all Ignore all TODO entries that do have a deadline.
718 t Same as `near', for backward compatibility.
720 This variable can also have an integer as a value. See
721 `org-agenda-todo-ignore-timestamp' for more details.
723 See also `org-agenda-todo-ignore-with-date'.
724 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
725 to make his option also apply to the tags-todo list."
726 :group 'org-agenda-skip
727 :group 'org-agenda-todo-list
728 :type '(choice
729 (const :tag "Ignore near deadlines" near)
730 (const :tag "Ignore near deadlines (compatibility)" t)
731 (const :tag "Ignore far deadlines" far)
732 (const :tag "Ignore all TODOs with a deadlines" all)
733 (const :tag "Show all TODOs, even if they have a deadline" nil)
734 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
736 (defcustom org-agenda-tags-todo-honor-ignore-options nil
737 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
738 The variables
739 `org-agenda-todo-ignore-with-date',
740 `org-agenda-todo-ignore-timestamp',
741 `org-agenda-todo-ignore-scheduled',
742 `org-agenda-todo-ignore-deadlines'
743 make the global TODO list skip entries that have time stamps of certain
744 kinds. If this option is set, the same options will also apply for the
745 tags-todo search, which is the general tags/property matcher
746 restricted to unfinished TODO entries only."
747 :group 'org-agenda-skip
748 :group 'org-agenda-todo-list
749 :group 'org-agenda-match-view
750 :type 'boolean)
752 (defcustom org-agenda-skip-scheduled-if-done nil
753 "Non-nil means don't show scheduled items in agenda when they are done.
754 This is relevant for the daily/weekly agenda, not for the TODO list. And
755 it applies only to the actual date of the scheduling. Warnings about
756 an item with a past scheduling dates are always turned off when the item
757 is DONE."
758 :group 'org-agenda-skip
759 :group 'org-agenda-daily/weekly
760 :type 'boolean)
762 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
763 "Non-nil means skip scheduling line if same entry shows because of deadline.
764 In the agenda of today, an entry can show up multiple times because
765 it is both scheduled and has a nearby deadline, and maybe a plain time
766 stamp as well.
767 When this variable is t, then only the deadline is shown and the fact that
768 the entry is scheduled today or was scheduled previously is not shown.
769 When this variable is nil, the entry will be shown several times. When
770 the variable is the symbol `not-today', then skip scheduled previously,
771 but not scheduled today."
772 :group 'org-agenda-skip
773 :group 'org-agenda-daily/weekly
774 :type '(choice
775 (const :tag "Never" nil)
776 (const :tag "Always" t)
777 (const :tag "Not when scheduled today" not-today)))
779 (defcustom org-agenda-skip-deadline-if-done nil
780 "Non-nil means don't show deadlines when the corresponding item is done.
781 When nil, the deadline is still shown and should give you a happy feeling.
782 This is relevant for the daily/weekly agenda. And it applied only to the
783 actually date of the deadline. Warnings about approaching and past-due
784 deadlines are always turned off when the item is DONE."
785 :group 'org-agenda-skip
786 :group 'org-agenda-daily/weekly
787 :type 'boolean)
789 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
790 "Non-nil means skip deadline prewarning when entry is also scheduled.
791 This will apply on all days where a prewarning for the deadline would
792 be shown, but not at the day when the entry is actually due. On that day,
793 the deadline will be shown anyway.
794 This variable may be set to nil, t, or a number which will then give
795 the number of days before the actual deadline when the prewarnings
796 should resume.
797 This can be used in a workflow where the first showing of the deadline will
798 trigger you to schedule it, and then you don't want to be reminded of it
799 because you will take care of it on the day when scheduled."
800 :group 'org-agenda-skip
801 :group 'org-agenda-daily/weekly
802 :version "24.1"
803 :type '(choice
804 (const :tag "Alwas show prewarning" nil)
805 (const :tag "Remove prewarning if entry is scheduled" t)
806 (integer :tag "Restart prewarning N days before deadline")))
808 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
809 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
810 When non-nil, after the search for timestamps has matched once in an
811 entry, the rest of the entry will not be searched."
812 :group 'org-agenda-skip
813 :type 'boolean)
815 (defcustom org-agenda-skip-timestamp-if-done nil
816 "Non-nil means don't select item by timestamp or -range if it is DONE."
817 :group 'org-agenda-skip
818 :group 'org-agenda-daily/weekly
819 :type 'boolean)
821 (defcustom org-agenda-dim-blocked-tasks t
822 "Non-nil means dim blocked tasks in the agenda display.
823 This causes some overhead during agenda construction, but if you
824 have turned on `org-enforce-todo-dependencies',
825 `org-enforce-todo-checkbox-dependencies', or any other blocking
826 mechanism, this will create useful feedback in the agenda.
828 Instead of t, this variable can also have the value `invisible'.
829 Then blocked tasks will be invisible and only become visible when
830 they become unblocked. An exemption to this behavior is when a task is
831 blocked because of unchecked checkboxes below it. Since checkboxes do
832 not show up in the agenda views, making this task invisible you remove any
833 trace from agenda views that there is something to do. Therefore, a task
834 that is blocked because of checkboxes will never be made invisible, it
835 will only be dimmed."
836 :group 'org-agenda-daily/weekly
837 :group 'org-agenda-todo-list
838 :type '(choice
839 (const :tag "Do not dim" nil)
840 (const :tag "Dim to a gray face" t)
841 (const :tag "Make invisible" invisible)))
843 (defcustom org-timeline-show-empty-dates 3
844 "Non-nil means `org-timeline' also shows dates without an entry.
845 When nil, only the days which actually have entries are shown.
846 When t, all days between the first and the last date are shown.
847 When an integer, show also empty dates, but if there is a gap of more than
848 N days, just insert a special line indicating the size of the gap."
849 :group 'org-agenda-skip
850 :type '(choice
851 (const :tag "None" nil)
852 (const :tag "All" t)
853 (integer :tag "at most")))
855 (defgroup org-agenda-startup nil
856 "Options concerning initial settings in the Agenda in Org Mode."
857 :tag "Org Agenda Startup"
858 :group 'org-agenda)
860 (defcustom org-agenda-menu-show-matcher t
861 "Non-nil means show the match string in the agenda dispatcher menu.
862 When nil, the matcher string is not shown, but is put into the help-echo
863 property so than moving the mouse over the command shows it.
864 Setting it to nil is good if matcher strings are very long and/or if
865 you want to use two-column display (see `org-agenda-menu-two-column')."
866 :group 'org-agenda
867 :version "24.1"
868 :type 'boolean)
870 (defcustom org-agenda-menu-two-column nil
871 "Non-nil means, use two columns to show custom commands in the dispatcher.
872 If you use this, you probably want to set `org-agenda-menu-show-matcher'
873 to nil."
874 :group 'org-agenda
875 :version "24.1"
876 :type 'boolean)
878 (defcustom org-finalize-agenda-hook nil
879 "Hook run just before displaying an agenda buffer."
880 :group 'org-agenda-startup
881 :type 'hook)
883 (defcustom org-agenda-mouse-1-follows-link nil
884 "Non-nil means mouse-1 on a link will follow the link in the agenda.
885 A longer mouse click will still set point. Does not work on XEmacs.
886 Needs to be set before org.el is loaded."
887 :group 'org-agenda-startup
888 :type 'boolean)
890 (defcustom org-agenda-start-with-follow-mode nil
891 "The initial value of follow mode in a newly created agenda window."
892 :group 'org-agenda-startup
893 :type 'boolean)
895 (defcustom org-agenda-follow-indirect nil
896 "Non-nil means `org-agenda-follow-mode' displays only the
897 current item's tree, in an indirect buffer."
898 :group 'org-agenda
899 :version "24.1"
900 :type 'boolean)
902 (defcustom org-agenda-show-outline-path t
903 "Non-nil means show outline path in echo area after line motion."
904 :group 'org-agenda-startup
905 :type 'boolean)
907 (defcustom org-agenda-start-with-entry-text-mode nil
908 "The initial value of entry-text-mode in a newly created agenda window."
909 :group 'org-agenda-startup
910 :type 'boolean)
912 (defcustom org-agenda-entry-text-maxlines 5
913 "Number of text lines to be added when `E' is pressed in the agenda.
915 Note that this variable only used during agenda display. Add add entry text
916 when exporting the agenda, configure the variable
917 `org-agenda-add-entry-ext-maxlines'."
918 :group 'org-agenda
919 :type 'integer)
921 (defcustom org-agenda-entry-text-exclude-regexps nil
922 "List of regular expressions to clean up entry text.
923 The complete matches of all regular expressions in this list will be
924 removed from entry text before it is shown in the agenda."
925 :group 'org-agenda
926 :type '(repeat (regexp)))
928 (defvar org-agenda-entry-text-cleanup-hook nil
929 "Hook that is run after basic cleanup of entry text to be shown in agenda.
930 This cleanup is done in a temporary buffer, so the function may inspect and
931 change the entire buffer.
932 Some default stuff like drawers and scheduling/deadline dates will already
933 have been removed when this is called, as will any matches for regular
934 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
936 (defvar org-agenda-include-inactive-timestamps nil
937 "Non-nil means include inactive time stamps in agenda and timeline.
938 Dynamically scoped.")
940 (defgroup org-agenda-windows nil
941 "Options concerning the windows used by the Agenda in Org Mode."
942 :tag "Org Agenda Windows"
943 :group 'org-agenda)
945 (defcustom org-agenda-window-setup 'reorganize-frame
946 "How the agenda buffer should be displayed.
947 Possible values for this option are:
949 current-window Show agenda in the current window, keeping all other windows.
950 other-window Use `switch-to-buffer-other-window' to display agenda.
951 reorganize-frame Show only two windows on the current frame, the current
952 window and the agenda.
953 other-frame Use `switch-to-buffer-other-frame' to display agenda.
954 Also, when exiting the agenda, kill that frame.
955 See also the variable `org-agenda-restore-windows-after-quit'."
956 :group 'org-agenda-windows
957 :type '(choice
958 (const current-window)
959 (const other-frame)
960 (const other-window)
961 (const reorganize-frame)))
963 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
964 "The min and max height of the agenda window as a fraction of frame height.
965 The value of the variable is a cons cell with two numbers between 0 and 1.
966 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
967 :group 'org-agenda-windows
968 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
970 (defcustom org-agenda-restore-windows-after-quit nil
971 "Non-nil means restore window configuration upon exiting agenda.
972 Before the window configuration is changed for displaying the agenda,
973 the current status is recorded. When the agenda is exited with
974 `q' or `x' and this option is set, the old state is restored. If
975 `org-agenda-window-setup' is `other-frame', the value of this
976 option will be ignored."
977 :group 'org-agenda-windows
978 :type 'boolean)
980 (defcustom org-agenda-ndays nil
981 "Number of days to include in overview display.
982 Should be 1 or 7.
983 Obsolete, see `org-agenda-span'."
984 :group 'org-agenda-daily/weekly
985 :type 'integer)
987 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
989 (defcustom org-agenda-span 'week
990 "Number of days to include in overview display.
991 Can be day, week, month, year, or any number of days.
992 Custom commands can set this variable in the options section."
993 :group 'org-agenda-daily/weekly
994 :type '(choice (const :tag "Day" day)
995 (const :tag "Week" week)
996 (const :tag "Month" month)
997 (const :tag "Year" year)
998 (integer :tag "Custom")))
1000 (defcustom org-agenda-start-on-weekday 1
1001 "Non-nil means start the overview always on the specified weekday.
1002 0 denotes Sunday, 1 denotes Monday etc.
1003 When nil, always start on the current day.
1004 Custom commands can set this variable in the options section."
1005 :group 'org-agenda-daily/weekly
1006 :type '(choice (const :tag "Today" nil)
1007 (integer :tag "Weekday No.")))
1009 (defcustom org-agenda-show-all-dates t
1010 "Non-nil means `org-agenda' shows every day in the selected range.
1011 When nil, only the days which actually have entries are shown."
1012 :group 'org-agenda-daily/weekly
1013 :type 'boolean)
1015 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1016 "Format string for displaying dates in the agenda.
1017 Used by the daily/weekly agenda and by the timeline. This should be
1018 a format string understood by `format-time-string', or a function returning
1019 the formatted date as a string. The function must take a single argument,
1020 a calendar-style date list like (month day year)."
1021 :group 'org-agenda-daily/weekly
1022 :type '(choice
1023 (string :tag "Format string")
1024 (function :tag "Function")))
1026 (defun org-agenda-format-date-aligned (date)
1027 "Format a date string for display in the daily/weekly agenda, or timeline.
1028 This function makes sure that dates are aligned for easy reading."
1029 (require 'cal-iso)
1030 (let* ((dayname (calendar-day-name date))
1031 (day (cadr date))
1032 (day-of-week (calendar-day-of-week date))
1033 (month (car date))
1034 (monthname (calendar-month-name month))
1035 (year (nth 2 date))
1036 (iso-week (org-days-to-iso-week
1037 (calendar-absolute-from-gregorian date)))
1038 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1039 (1- year))
1040 ((and (= month 12) (<= iso-week 1))
1041 (1+ year))
1042 (t year)))
1043 (weekstring (if (= day-of-week 1)
1044 (format " W%02d" iso-week)
1045 "")))
1046 (format "%-10s %2d %s %4d%s"
1047 dayname day monthname year weekstring)))
1049 (defcustom org-agenda-time-leading-zero nil
1050 "Non-nil means use leading zero for military times in agenda.
1051 For example, 9:30am would become 09:30 rather than 9:30."
1052 :group 'org-agenda-daily/weekly
1053 :version "24.1"
1054 :type 'boolean)
1056 (defcustom org-agenda-timegrid-use-ampm nil
1057 "When set, show AM/PM style timestamps on the timegrid."
1058 :group 'org-agenda
1059 :version "24.1"
1060 :type 'boolean)
1062 (defun org-agenda-time-of-day-to-ampm (time)
1063 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1064 (let* ((hour-number (string-to-number (substring time 0 -3)))
1065 (minute (substring time -2))
1066 (ampm "am"))
1067 (cond
1068 ((equal hour-number 12)
1069 (setq ampm "pm"))
1070 ((> hour-number 12)
1071 (setq ampm "pm")
1072 (setq hour-number (- hour-number 12))))
1073 (concat
1074 (if org-agenda-time-leading-zero
1075 (format "%02d" hour-number)
1076 (format "%02s" (number-to-string hour-number)))
1077 ":" minute ampm)))
1079 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1080 "Conditionally convert TIME to AM/PM format
1081 based on `org-agenda-timegrid-use-ampm'"
1082 (if org-agenda-timegrid-use-ampm
1083 (org-agenda-time-of-day-to-ampm time)
1084 time))
1086 (defcustom org-agenda-weekend-days '(6 0)
1087 "Which days are weekend?
1088 These days get the special face `org-agenda-date-weekend' in the agenda
1089 and timeline buffers."
1090 :group 'org-agenda-daily/weekly
1091 :type '(set :greedy t
1092 (const :tag "Monday" 1)
1093 (const :tag "Tuesday" 2)
1094 (const :tag "Wednesday" 3)
1095 (const :tag "Thursday" 4)
1096 (const :tag "Friday" 5)
1097 (const :tag "Saturday" 6)
1098 (const :tag "Sunday" 0)))
1100 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1101 "Non-nil means jump to today when moving a past date forward in time.
1102 When using S-right in the agenda to move a a date forward, and the date
1103 stamp currently points to the past, the first key press will move it
1104 to today. WHen nil, just move one day forward even if the date stays
1105 in the past."
1106 :group 'org-agenda-daily/weekly
1107 :version "24.1"
1108 :type 'boolean)
1110 (defcustom org-agenda-include-diary nil
1111 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1112 Custom commands can set this variable in the options section."
1113 :group 'org-agenda-daily/weekly
1114 :type 'boolean)
1116 (defcustom org-agenda-include-deadlines t
1117 "If non-nil, include entries within their deadline warning period.
1118 Custom commands can set this variable in the options section."
1119 :group 'org-agenda-daily/weekly
1120 :version "24.1"
1121 :type 'boolean)
1123 (defcustom org-agenda-repeating-timestamp-show-all t
1124 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1125 When set to a list of strings, only show occurrences of repeating
1126 stamps for these TODO keywords. When nil, only one occurrence is
1127 shown, either today or the nearest into the future."
1128 :group 'org-agenda-daily/weekly
1129 :type '(choice
1130 (const :tag "Show repeating stamps" t)
1131 (repeat :tag "Show repeating stamps for these TODO keywords"
1132 (string :tag "TODO Keyword"))
1133 (const :tag "Don't show repeating stamps" nil)))
1135 (defcustom org-scheduled-past-days 10000
1136 "No. of days to continue listing scheduled items that are not marked DONE.
1137 When an item is scheduled on a date, it shows up in the agenda on this
1138 day and will be listed until it is marked done for the number of days
1139 given here."
1140 :group 'org-agenda-daily/weekly
1141 :type 'integer)
1143 (defcustom org-agenda-log-mode-items '(closed clock)
1144 "List of items that should be shown in agenda log mode.
1145 This list may contain the following symbols:
1147 closed Show entries that have been closed on that day.
1148 clock Show entries that have received clocked time on that day.
1149 state Show all logged state changes.
1150 Note that instead of changing this variable, you can also press `C-u l' in
1151 the agenda to display all available LOG items temporarily."
1152 :group 'org-agenda-daily/weekly
1153 :type '(set :greedy t (const closed) (const clock) (const state)))
1155 (defcustom org-agenda-clock-consistency-checks
1156 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1157 :gap-ok-around ("4:00")
1158 :default-face ((:background "DarkRed") (:foreground "white"))
1159 :overlap-face nil :gap-face nil :no-end-time-face nil
1160 :long-face nil :short-face nil)
1161 "This is a property list, with the following keys:
1163 :max-duration Mark clocking chunks that are longer than this time.
1164 This is a time string like \"HH:MM\", or the number
1165 of minutes as an integer.
1167 :min-duration Mark clocking chunks that are shorter that this.
1168 This is a time string like \"HH:MM\", or the number
1169 of minutes as an integer.
1171 :max-gap Mark gaps between clocking chunks that are longer than
1172 this duration. A number of minutes, or a string
1173 like \"HH:MM\".
1175 :gap-ok-around List of times during the day which are usually not working
1176 times. When a gap is detected, but the gap contains any
1177 of these times, the gap is *not* reported. For example,
1178 if this is (\"4:00\" \"13:00\") then gaps that contain
1179 4:00 in the morning (i.e. the night) and 13:00
1180 (i.e. a typical lunch time) do not cause a warning.
1181 You should have at least one time during the night in this
1182 list, or otherwise the first task each morning will trigger
1183 a warning because it follows a long gap.
1185 Furthermore, the following properties can be used to define faces for
1186 issue display.
1188 :default-face the default face, if the specific face is undefined
1189 :overlap-face face for overlapping clocks
1190 :gap-face face for gaps between clocks
1191 :no-end-time-face face for incomplete clocks
1192 :long-face face for clock intervals that are too long
1193 :short-face face for clock intervals that are too short"
1194 :group 'org-agenda-daily/weekly
1195 :group 'org-clock
1196 :version "24.1"
1197 :type 'plist)
1199 (defcustom org-agenda-log-mode-add-notes t
1200 "Non-nil means add first line of notes to log entries in agenda views.
1201 If a log item like a state change or a clock entry is associated with
1202 notes, the first line of these notes will be added to the entry in the
1203 agenda display."
1204 :group 'org-agenda-daily/weekly
1205 :type 'boolean)
1207 (defcustom org-agenda-start-with-log-mode nil
1208 "The initial value of log-mode in a newly created agenda window."
1209 :group 'org-agenda-startup
1210 :group 'org-agenda-daily/weekly
1211 :type 'boolean)
1213 (defcustom org-agenda-start-with-clockreport-mode nil
1214 "The initial value of clockreport-mode in a newly created agenda window."
1215 :group 'org-agenda-startup
1216 :group 'org-agenda-daily/weekly
1217 :type 'boolean)
1219 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1220 "Property list with parameters for the clocktable in clockreport mode.
1221 This is the display mode that shows a clock table in the daily/weekly
1222 agenda, the properties for this dynamic block can be set here.
1223 The usual clocktable parameters are allowed here, but you cannot set
1224 the properties :name, :tstart, :tend, :block, and :scope - these will
1225 be overwritten to make sure the content accurately reflects the
1226 current display in the agenda."
1227 :group 'org-agenda-daily/weekly
1228 :type 'plist)
1230 (defcustom org-agenda-search-view-always-boolean nil
1231 "Non-nil means the search string is interpreted as individual parts.
1233 The search string for search view can either be interpreted as a phrase,
1234 or as a list of snippets that define a boolean search for a number of
1235 strings.
1237 When this is non-nil, the string will be split on whitespace, and each
1238 snippet will be searched individually, and all must match in order to
1239 select an entry. A snippet is then a single string of non-white
1240 characters, or a string in double quotes, or a regexp in {} braces.
1241 If a snippet is preceded by \"-\", the snippet must *not* match.
1242 \"+\" is syntactic sugar for positive selection. Each snippet may
1243 be found as a full word or a partial word, but see the variable
1244 `org-agenda-search-view-force-full-words'.
1246 When this is nil, search will look for the entire search phrase as one,
1247 with each space character matching any amount of whitespace, including
1248 line breaks.
1250 Even when this is nil, you can still switch to Boolean search dynamically
1251 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1252 is a regexp marked with braces like \"{abc}\", this will also switch to
1253 boolean search."
1254 :group 'org-agenda-search-view
1255 :version "24.1"
1256 :type 'boolean)
1258 (if (fboundp 'defvaralias)
1259 (defvaralias 'org-agenda-search-view-search-words-only
1260 'org-agenda-search-view-always-boolean))
1262 (defcustom org-agenda-search-view-force-full-words nil
1263 "Non-nil means, search words must be matches as complete words.
1264 When nil, they may also match part of a word."
1265 :group 'org-agenda-search-view
1266 :version "24.1"
1267 :type 'boolean)
1269 (defgroup org-agenda-time-grid nil
1270 "Options concerning the time grid in the Org-mode Agenda."
1271 :tag "Org Agenda Time Grid"
1272 :group 'org-agenda)
1274 (defcustom org-agenda-search-headline-for-time t
1275 "Non-nil means search headline for a time-of-day.
1276 If the headline contains a time-of-day in one format or another, it will
1277 be used to sort the entry into the time sequence of items for a day.
1278 Some people have time stamps in the headline that refer to the creation
1279 time or so, and then this produces an unwanted side effect. If this is
1280 the case for your, use this variable to turn off searching the headline
1281 for a time."
1282 :group 'org-agenda-time-grid
1283 :type 'boolean)
1285 (defcustom org-agenda-use-time-grid t
1286 "Non-nil means show a time grid in the agenda schedule.
1287 A time grid is a set of lines for specific times (like every two hours between
1288 8:00 and 20:00). The items scheduled for a day at specific times are
1289 sorted in between these lines.
1290 For details about when the grid will be shown, and what it will look like, see
1291 the variable `org-agenda-time-grid'."
1292 :group 'org-agenda-time-grid
1293 :type 'boolean)
1295 (defcustom org-agenda-time-grid
1296 '((daily today require-timed)
1297 "----------------"
1298 (800 1000 1200 1400 1600 1800 2000))
1300 "The settings for time grid for agenda display.
1301 This is a list of three items. The first item is again a list. It contains
1302 symbols specifying conditions when the grid should be displayed:
1304 daily if the agenda shows a single day
1305 weekly if the agenda shows an entire week
1306 today show grid on current date, independent of daily/weekly display
1307 require-timed show grid only if at least one item has a time specification
1309 The second item is a string which will be placed behind the grid time.
1311 The third item is a list of integers, indicating the times that should have
1312 a grid line."
1313 :group 'org-agenda-time-grid
1314 :type
1315 '(list
1316 (set :greedy t :tag "Grid Display Options"
1317 (const :tag "Show grid in single day agenda display" daily)
1318 (const :tag "Show grid in weekly agenda display" weekly)
1319 (const :tag "Always show grid for today" today)
1320 (const :tag "Show grid only if any timed entries are present"
1321 require-timed)
1322 (const :tag "Skip grid times already present in an entry"
1323 remove-match))
1324 (string :tag "Grid String")
1325 (repeat :tag "Grid Times" (integer :tag "Time"))))
1327 (defcustom org-agenda-show-current-time-in-grid t
1328 "Non-nil means show the current time in the time grid."
1329 :group 'org-agenda-time-grid
1330 :version "24.1"
1331 :type 'boolean)
1333 (defcustom org-agenda-current-time-string
1334 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1335 "The string for the current time marker in the agenda."
1336 :group 'org-agenda-time-grid
1337 :version "24.1"
1338 :type 'string)
1340 (defgroup org-agenda-sorting nil
1341 "Options concerning sorting in the Org-mode Agenda."
1342 :tag "Org Agenda Sorting"
1343 :group 'org-agenda)
1345 (defcustom org-agenda-sorting-strategy
1346 '((agenda habit-down time-up priority-down category-keep)
1347 (todo priority-down category-keep)
1348 (tags priority-down category-keep)
1349 (search category-keep))
1350 "Sorting structure for the agenda items of a single day.
1351 This is a list of symbols which will be used in sequence to determine
1352 if an entry should be listed before another entry. The following
1353 symbols are recognized:
1355 time-up Put entries with time-of-day indications first, early first
1356 time-down Put entries with time-of-day indications first, late first
1357 category-keep Keep the default order of categories, corresponding to the
1358 sequence in `org-agenda-files'.
1359 category-up Sort alphabetically by category, A-Z.
1360 category-down Sort alphabetically by category, Z-A.
1361 tag-up Sort alphabetically by last tag, A-Z.
1362 tag-down Sort alphabetically by last tag, Z-A.
1363 priority-up Sort numerically by priority, high priority last.
1364 priority-down Sort numerically by priority, high priority first.
1365 todo-state-up Sort by todo state, tasks that are done last.
1366 todo-state-down Sort by todo state, tasks that are done first.
1367 effort-up Sort numerically by estimated effort, high effort last.
1368 effort-down Sort numerically by estimated effort, high effort first.
1369 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1370 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1371 habit-up Put entries that are habits first
1372 habit-down Put entries that are habits last
1373 alpha-up Sort headlines alphabetically
1374 alpha-down Sort headlines alphabetically, reversed
1376 The different possibilities will be tried in sequence, and testing stops
1377 if one comparison returns a \"not-equal\". For example, the default
1378 '(time-up category-keep priority-down)
1379 means: Pull out all entries having a specified time of day and sort them,
1380 in order to make a time schedule for the current day the first thing in the
1381 agenda listing for the day. Of the entries without a time indication, keep
1382 the grouped in categories, don't sort the categories, but keep them in
1383 the sequence given in `org-agenda-files'. Within each category sort by
1384 priority.
1386 Leaving out `category-keep' would mean that items will be sorted across
1387 categories by priority.
1389 Instead of a single list, this can also be a set of list for specific
1390 contents, with a context symbol in the car of the list, any of
1391 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1393 Custom commands can bind this variable in the options section."
1394 :group 'org-agenda-sorting
1395 :type `(choice
1396 (repeat :tag "General" ,org-sorting-choice)
1397 (list :tag "Individually"
1398 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1399 (repeat ,org-sorting-choice))
1400 (cons (const :tag "Strategy for TODO lists" todo)
1401 (repeat ,org-sorting-choice))
1402 (cons (const :tag "Strategy for Tags matches" tags)
1403 (repeat ,org-sorting-choice))
1404 (cons (const :tag "Strategy for search matches" search)
1405 (repeat ,org-sorting-choice)))))
1407 (defcustom org-agenda-cmp-user-defined nil
1408 "A function to define the comparison `user-defined'.
1409 This function must receive two arguments, agenda entry a and b.
1410 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1411 the user comparison, return nil.
1412 When this is defined, you can make `user-defined-up' and `user-defined-down'
1413 part of an agenda sorting strategy."
1414 :group 'org-agenda-sorting
1415 :type 'symbol)
1417 (defcustom org-sort-agenda-notime-is-late t
1418 "Non-nil means items without time are considered late.
1419 This is only relevant for sorting. When t, items which have no explicit
1420 time like 15:30 will be considered as 99:01, i.e. later than any items which
1421 do have a time. When nil, the default time is before 0:00. You can use this
1422 option to decide if the schedule for today should come before or after timeless
1423 agenda entries."
1424 :group 'org-agenda-sorting
1425 :type 'boolean)
1427 (defcustom org-sort-agenda-noeffort-is-high t
1428 "Non-nil means items without effort estimate are sorted as high effort.
1429 This also applies when filtering an agenda view with respect to the
1430 < or > effort operator. Then, tasks with no effort defined will be treated
1431 as tasks with high effort.
1432 When nil, such items are sorted as 0 minutes effort."
1433 :group 'org-agenda-sorting
1434 :type 'boolean)
1436 (defgroup org-agenda-line-format nil
1437 "Options concerning the entry prefix in the Org-mode agenda display."
1438 :tag "Org Agenda Line Format"
1439 :group 'org-agenda)
1441 (defcustom org-agenda-prefix-format
1442 '((agenda . " %i %-12:c%?-12t% s")
1443 (timeline . " % s")
1444 (todo . " %i %-12:c")
1445 (tags . " %i %-12:c")
1446 (search . " %i %-12:c"))
1447 "Format specifications for the prefix of items in the agenda views.
1448 An alist with five entries, each for the different agenda types. The
1449 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1450 The values are format strings.
1452 This format works similar to a printf format, with the following meaning:
1454 %c the category of the item, \"Diary\" for entries from the diary,
1455 or as given by the CATEGORY keyword or derived from the file name
1456 %e the effort required by the item
1457 %i the icon category of the item, see `org-agenda-category-icon-alist'
1458 %T the last tag of the item (ignore inherited tags, which come first)
1459 %t the HH:MM time-of-day specification if one applies to the entry
1460 %s Scheduling/Deadline information, a short string
1461 %(expression) Eval EXPRESSION and replace the control string
1462 by the result
1464 All specifiers work basically like the standard `%s' of printf, but may
1465 contain two additional characters: a question mark just after the `%'
1466 and a whitespace/punctuation character just before the final letter.
1468 If the first character after `%' is a question mark, the entire field
1469 will only be included if the corresponding value applies to the current
1470 entry. This is useful for fields which should have fixed width when
1471 present, but zero width when absent. For example, \"%?-12t\" will
1472 result in a 12 character time field if a time of the day is specified,
1473 but will completely disappear in entries which do not contain a time.
1475 If there is punctuation or whitespace character just before the final
1476 format letter, this character will be appended to the field value if
1477 the value is not empty. For example, the format \"%-12:c\" leads to
1478 \"Diary: \" if the category is \"Diary\". If the category were be
1479 empty, no additional colon would be inserted.
1481 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1482 which means:
1484 - Indent the line with two space characters
1485 - Give the category a 12 chars wide field, padded with whitespace on
1486 the right (because of `-'). Append a colon if there is a category
1487 (because of `:').
1488 - If there is a time-of-day, put it into a 12 chars wide field. If no
1489 time, don't put in an empty field, just skip it (because of '?').
1490 - Finally, put the scheduling information.
1492 See also the variables `org-agenda-remove-times-when-in-prefix' and
1493 `org-agenda-remove-tags'.
1495 Custom commands can set this variable in the options section."
1496 :type '(choice
1497 (string :tag "General format")
1498 (list :greedy t :tag "View dependent"
1499 (cons (const agenda) (string :tag "Format"))
1500 (cons (const timeline) (string :tag "Format"))
1501 (cons (const todo) (string :tag "Format"))
1502 (cons (const tags) (string :tag "Format"))
1503 (cons (const search) (string :tag "Format"))))
1504 :group 'org-agenda-line-format)
1506 (defvar org-prefix-format-compiled nil
1507 "The compiled prefix format and associated variables.
1508 This is a list where first element is a list of variable bindings, and second
1509 element is the compiled format expression. See the variable
1510 `org-agenda-prefix-format'.")
1512 (defcustom org-agenda-todo-keyword-format "%-1s"
1513 "Format for the TODO keyword in agenda lines.
1514 Set this to something like \"%-12s\" if you want all TODO keywords
1515 to occupy a fixed space in the agenda display."
1516 :group 'org-agenda-line-format
1517 :type 'string)
1519 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1520 "Text preceding timerange entries in the agenda view.
1521 This is a list with two strings. The first applies when the range
1522 is entirely on one day. The second applies if the range spans several days.
1523 The strings may have two \"%d\" format specifiers which will be filled
1524 with the sequence number of the days, and the total number of days in the
1525 range, respectively."
1526 :group 'org-agenda-line-format
1527 :type '(list
1528 (string :tag "Deadline today ")
1529 (choice :tag "Deadline relative"
1530 (string :tag "Format string")
1531 (function))))
1533 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1534 "Text preceding scheduled items in the agenda view.
1535 This is a list with two strings. The first applies when the item is
1536 scheduled on the current day. The second applies when it has been scheduled
1537 previously, it may contain a %d indicating that this is the nth time that
1538 this item is scheduled, due to automatic rescheduling of unfinished items
1539 for the following day. So this number is one larger than the number of days
1540 that passed since this item was scheduled first."
1541 :group 'org-agenda-line-format
1542 :type '(list
1543 (string :tag "Scheduled today ")
1544 (string :tag "Scheduled previously")))
1546 (defcustom org-agenda-inactive-leader "["
1547 "Text preceding item pulled into the agenda by inactive time stamps.
1548 These entries are added to the agenda when pressing \"[\"."
1549 :group 'org-agenda-line-format
1550 :version "24.1"
1551 :type '(list
1552 (string :tag "Scheduled today ")
1553 (string :tag "Scheduled previously")))
1555 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1556 "Text preceding deadline items in the agenda view.
1557 This is a list with two strings. The first applies when the item has its
1558 deadline on the current day. The second applies when it is in the past or
1559 in the future, it may contain %d to capture how many days away the deadline
1560 is (was)."
1561 :group 'org-agenda-line-format
1562 :type '(list
1563 (string :tag "Deadline today ")
1564 (choice :tag "Deadline relative"
1565 (string :tag "Format string")
1566 (function))))
1568 (defcustom org-agenda-remove-times-when-in-prefix t
1569 "Non-nil means remove duplicate time specifications in agenda items.
1570 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1571 time-of-day specification in a headline or diary entry is extracted and
1572 placed into the prefix. If this option is non-nil, the original specification
1573 \(a timestamp or -range, or just a plain time(range) specification like
1574 11:30-4pm) will be removed for agenda display. This makes the agenda less
1575 cluttered.
1576 The option can be t or nil. It may also be the symbol `beg', indicating
1577 that the time should only be removed when it is located at the beginning of
1578 the headline/diary entry."
1579 :group 'org-agenda-line-format
1580 :type '(choice
1581 (const :tag "Always" t)
1582 (const :tag "Never" nil)
1583 (const :tag "When at beginning of entry" beg)))
1585 (defcustom org-agenda-remove-timeranges-from-blocks nil
1586 "Non-nil means remove time ranges specifications in agenda
1587 items that span on several days."
1588 :group 'org-agenda-line-format
1589 :version "24.1"
1590 :type 'boolean)
1592 (defcustom org-agenda-default-appointment-duration nil
1593 "Default duration for appointments that only have a starting time.
1594 When nil, no duration is specified in such cases.
1595 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1596 :group 'org-agenda-line-format
1597 :type '(choice
1598 (integer :tag "Minutes")
1599 (const :tag "No default duration")))
1601 (defcustom org-agenda-show-inherited-tags t
1602 "Non-nil means show inherited tags in each agenda line."
1603 :group 'org-agenda-line-format
1604 :type 'boolean)
1606 (defcustom org-agenda-hide-tags-regexp nil
1607 "Regular expression used to filter away specific tags in agenda views.
1608 This means that these tags will be present, but not be shown in the agenda
1609 line. Secondary filtering will still work on the hidden tags.
1610 Nil means don't hide any tags."
1611 :group 'org-agenda-line-format
1612 :type '(choice
1613 (const :tag "Hide none" nil)
1614 (string :tag "Regexp ")))
1616 (defcustom org-agenda-remove-tags nil
1617 "Non-nil means remove the tags from the headline copy in the agenda.
1618 When this is the symbol `prefix', only remove tags when
1619 `org-agenda-prefix-format' contains a `%T' specifier."
1620 :group 'org-agenda-line-format
1621 :type '(choice
1622 (const :tag "Always" t)
1623 (const :tag "Never" nil)
1624 (const :tag "When prefix format contains %T" prefix)))
1626 (if (fboundp 'defvaralias)
1627 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1628 'org-agenda-remove-tags))
1630 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1631 "Shift tags in agenda items to this column.
1632 If this number is positive, it specifies the column. If it is negative,
1633 it means that the tags should be flushright to that column. For example,
1634 -80 works well for a normal 80 character screen."
1635 :group 'org-agenda-line-format
1636 :type 'integer)
1638 (if (fboundp 'defvaralias)
1639 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1641 (defcustom org-agenda-fontify-priorities 'cookies
1642 "Non-nil means highlight low and high priorities in agenda.
1643 When t, the highest priority entries are bold, lowest priority italic.
1644 However, settings in `org-priority-faces' will overrule these faces.
1645 When this variable is the symbol `cookies', only fontify the
1646 cookies, not the entire task.
1647 This may also be an association list of priority faces, whose
1648 keys are the character values of `org-highest-priority',
1649 `org-default-priority', and `org-lowest-priority' (the default values
1650 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1651 color as a string, or a list like `(:background \"Red\")'.
1652 If it is a color, the variable `org-faces-easy-properties'
1653 determines if it is a foreground or a background color."
1654 :group 'org-agenda-line-format
1655 :type '(choice
1656 (const :tag "Never" nil)
1657 (const :tag "Defaults" t)
1658 (const :tag "Cookies only" cookies)
1659 (repeat :tag "Specify"
1660 (list (character :tag "Priority" :value ?A)
1661 (choice :tag "Face "
1662 (string :tag "Color")
1663 (sexp :tag "Face"))))))
1665 (defcustom org-agenda-day-face-function nil
1666 "Function called to determine what face should be used to display a day.
1667 The only argument passed to that function is the day. It should
1668 returns a face, or nil if does not want to specify a face and let
1669 the normal rules apply."
1670 :group 'org-agenda-line-format
1671 :version "24.1"
1672 :type 'function)
1674 (defcustom org-agenda-category-icon-alist nil
1675 "Alist of category icon to be displayed in agenda views.
1677 Each entry should have the following format:
1679 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1681 Where CATEGORY-REGEXP is a regexp matching the categories where
1682 the icon should be displayed.
1683 FILE-OR-DATA either a file path or a string containing image data.
1685 The other fields can be omitted safely if not needed:
1686 TYPE indicates the image type.
1687 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1688 image data.
1689 PROPS are additional image attributes to assign to the image,
1690 like, e.g. `:ascent center'.
1692 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1694 If you want to set the display properties yourself, just put a
1695 list as second element:
1697 (CATEGORY-REGEXP (MY PROPERTY LIST))
1699 For example, to display a 16px horizontal space for Emacs
1700 category, you can use:
1702 (\"Emacs\" '(space . (:width (16))))"
1703 :group 'org-agenda-line-format
1704 :version "24.1"
1705 :type '(alist :key-type (string :tag "Regexp matching category")
1706 :value-type (choice (list :tag "Icon"
1707 (string :tag "File or data")
1708 (symbol :tag "Type")
1709 (boolean :tag "Data?")
1710 (repeat :tag "Extra image properties" :inline t symbol))
1711 (list :tag "Display properties" sexp))))
1713 (defgroup org-agenda-column-view nil
1714 "Options concerning column view in the agenda."
1715 :tag "Org Agenda Column View"
1716 :group 'org-agenda)
1718 (defcustom org-agenda-columns-show-summaries t
1719 "Non-nil means show summaries for columns displayed in the agenda view."
1720 :group 'org-agenda-column-view
1721 :type 'boolean)
1723 (defcustom org-agenda-columns-compute-summary-properties t
1724 "Non-nil means recompute all summary properties before column view.
1725 When column view in the agenda is listing properties that have a summary
1726 operator, it can go to all relevant buffers and recompute the summaries
1727 there. This can mean overhead for the agenda column view, but is necessary
1728 to have thing up to date.
1729 As a special case, a CLOCKSUM property also makes sure that the clock
1730 computations are current."
1731 :group 'org-agenda-column-view
1732 :type 'boolean)
1734 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1735 "Non-nil means the duration of an appointment will add to day effort.
1736 The property to which appointment durations will be added is the one given
1737 in the option `org-effort-property'. If an appointment does not have
1738 an end time, `org-agenda-default-appointment-duration' will be used. If that
1739 is not set, an appointment without end time will not contribute to the time
1740 estimate."
1741 :group 'org-agenda-column-view
1742 :type 'boolean)
1744 (defcustom org-agenda-auto-exclude-function nil
1745 "A function called with a tag to decide if it is filtered on '/ RET'.
1746 The sole argument to the function, which is called once for each
1747 possible tag, is a string giving the name of the tag. The
1748 function should return either nil if the tag should be included
1749 as normal, or \"-<TAG>\" to exclude the tag.
1750 Note that for the purpose of tag filtering, only the lower-case version of
1751 all tags will be considered, so that this function will only ever see
1752 the lower-case version of all tags."
1753 :group 'org-agenda
1754 :type 'function)
1756 (defcustom org-agenda-bulk-custom-functions nil
1757 "Alist of characters and custom functions for bulk actions.
1758 For example, this value makes those two functions available:
1760 '((?R set-category)
1761 (?C bulk-cut))
1763 With selected entries in an agenda buffer, `B R' will call
1764 the custom function `set-category' on the selected entries.
1765 Note that functions in this alist don't need to be quoted."
1766 :type 'alist
1767 :version "24.1"
1768 :group 'org-agenda)
1770 (eval-when-compile
1771 (require 'cl))
1772 (require 'org)
1774 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1775 "Execute BODY with point at location given by `org-hd-marker' property.
1776 If STRING is non-nil, the text property will be fetched from position 0
1777 in that string. If STRING is nil, it will be fetched from the beginning
1778 of the current line."
1779 (org-with-gensyms (marker)
1780 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1781 'org-hd-marker ,string)))
1782 (with-current-buffer (marker-buffer ,marker)
1783 (save-excursion
1784 (goto-char ,marker)
1785 ,@body)))))
1786 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1788 (defun org-add-agenda-custom-command (entry)
1789 "Replace or add a command in `org-agenda-custom-commands'.
1790 This is mostly for hacking and trying a new command - once the command
1791 works you probably want to add it to `org-agenda-custom-commands' for good."
1792 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1793 (if ass
1794 (setcdr ass (cdr entry))
1795 (push entry org-agenda-custom-commands))))
1797 ;;; Define the org-agenda-mode
1799 (defvar org-agenda-mode-map (make-sparse-keymap)
1800 "Keymap for `org-agenda-mode'.")
1801 (if (fboundp 'defvaralias)
1802 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1804 (defvar org-agenda-menu) ; defined later in this file.
1805 (defvar org-agenda-restrict) ; defined later in this file.
1806 (defvar org-agenda-follow-mode nil)
1807 (defvar org-agenda-entry-text-mode nil)
1808 (defvar org-agenda-clockreport-mode nil)
1809 (defvar org-agenda-show-log nil)
1810 (defvar org-agenda-redo-command nil)
1811 (defvar org-agenda-query-string nil)
1812 (defvar org-agenda-mode-hook nil
1813 "Hook for `org-agenda-mode', run after the mode is turned on.")
1814 (defvar org-agenda-type nil)
1815 (defvar org-agenda-force-single-file nil)
1816 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1819 ;;; Multiple agenda buffers support
1821 (defcustom org-agenda-sticky nil
1822 "Non-nil means agenda q key will bury agenda buffers.
1823 Agenda commands will then show existing buffer instead of generating new ones.
1824 When nil, `q' will kill the single agenda buffer."
1825 :group 'org-agenda
1826 :type 'boolean
1827 :set (lambda (var val)
1828 (if (boundp var)
1829 (org-toggle-sticky-agenda (if val 1 0))
1830 (set var val))))
1832 (defun org-toggle-sticky-agenda (&optional arg)
1833 "Toggle `org-agenda-sticky'."
1834 (interactive "P")
1835 (let ((new-value (if arg
1836 (> (prefix-numeric-value arg) 0)
1837 (not org-agenda-sticky))))
1838 (if (equal new-value org-agenda-sticky)
1839 (message "Sticky agenda was already %s"
1840 (if org-agenda-sticky "enabled" "disabled"))
1841 (setq org-agenda-sticky new-value)
1842 (org-agenda-kill-all-agenda-buffers)
1843 (message "Sticky agenda was %s"
1844 (if org-agenda-sticky "enabled" "disabled")))))
1846 (defvar org-agenda-buffer nil
1847 "Agenda buffer currently being generated.")
1849 (defvar org-agenda-last-prefix-arg nil)
1850 (defvar org-agenda-this-buffer-name nil)
1851 (defvar org-agenda-doing-sticky-redo nil)
1852 (defvar org-agenda-this-buffer-is-sticky nil)
1854 (defconst org-agenda-local-vars
1855 '(org-agenda-this-buffer-name
1856 org-agenda-undo-list
1857 org-agenda-pending-undo-list
1858 org-agenda-follow-mode
1859 org-agenda-entry-text-mode
1860 org-agenda-clockreport-mode
1861 org-agenda-show-log
1862 org-agenda-redo-command
1863 org-agenda-query-string
1864 org-agenda-type
1865 org-agenda-bulk-marked-entries
1866 org-agenda-undo-has-started-in
1867 org-agenda-last-arguments
1868 org-agenda-info
1869 org-agenda-tag-filter-overlays
1870 org-agenda-cat-filter-overlays
1871 org-pre-agenda-window-conf
1872 org-agenda-columns-active
1873 org-agenda-tag-filter
1874 org-agenda-category-filter
1875 org-agenda-markers
1876 org-agenda-last-search-view-search-was-boolean
1877 org-agenda-filtered-by-category
1878 org-agenda-filter-form
1879 org-agenda-show-window
1880 org-agenda-cycle-counter
1881 org-agenda-last-prefix-arg)
1882 "Variables that must be local in agenda buffers to allow multiple buffers.")
1884 (defun org-agenda-mode ()
1885 "Mode for time-sorted view on action items in Org-mode files.
1887 The following commands are available:
1889 \\{org-agenda-mode-map}"
1890 (interactive)
1891 (cond (org-agenda-doing-sticky-redo
1892 ;; Refreshing sticky agenda-buffer
1894 ;; Preserve the value of `org-agenda-local-vars' variables,
1895 ;; while letting `kill-all-local-variables' kill the rest
1896 (let ((save (buffer-local-variables)))
1897 (kill-all-local-variables)
1898 (mapc 'make-local-variable org-agenda-local-vars)
1899 (dolist (elem save)
1900 (let ((var (car elem))
1901 (val (cdr elem)))
1902 (when (and val
1903 (member var org-agenda-local-vars))
1904 (set var val)))))
1905 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1906 (org-agenda-sticky
1907 ;; Creating a sticky Agenda buffer for the first time
1908 (kill-all-local-variables)
1909 (mapc 'make-local-variable org-agenda-local-vars)
1910 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1912 ;; Creating a non-sticky agenda buffer
1913 (kill-all-local-variables)
1914 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1915 (setq org-agenda-undo-list nil
1916 org-agenda-pending-undo-list nil
1917 org-agenda-bulk-marked-entries nil)
1918 (setq major-mode 'org-agenda-mode)
1919 ;; Keep global-font-lock-mode from turning on font-lock-mode
1920 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1921 (setq mode-name "Org-Agenda")
1922 (use-local-map org-agenda-mode-map)
1923 (easy-menu-add org-agenda-menu)
1924 (if org-startup-truncated (setq truncate-lines t))
1925 (org-set-local 'line-move-visual nil)
1926 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1927 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1928 ;; Make sure properties are removed when copying text
1929 (when (boundp 'buffer-substring-filters)
1930 (org-set-local 'buffer-substring-filters
1931 (cons (lambda (x)
1932 (set-text-properties 0 (length x) nil x) x)
1933 buffer-substring-filters)))
1934 (unless org-agenda-keep-modes
1935 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1936 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1937 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1938 org-agenda-show-log org-agenda-start-with-log-mode))
1940 (easy-menu-change
1941 '("Agenda") "Agenda Files"
1942 (append
1943 (list
1944 (vector
1945 (if (get 'org-agenda-files 'org-restrict)
1946 "Restricted to single file"
1947 "Edit File List")
1948 '(org-edit-agenda-file-list)
1949 (not (get 'org-agenda-files 'org-restrict)))
1950 "--")
1951 (mapcar 'org-file-menu-entry (org-agenda-files))))
1952 (org-agenda-set-mode-name)
1953 (apply
1954 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1955 (list 'org-agenda-mode-hook)))
1957 (substitute-key-definition 'undo 'org-agenda-undo
1958 org-agenda-mode-map global-map)
1959 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1960 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1961 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1962 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1963 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1964 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1965 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1966 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1967 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
1968 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
1969 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
1970 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
1971 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
1972 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
1973 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
1974 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
1975 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
1976 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
1977 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
1978 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
1979 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
1980 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
1981 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
1982 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
1983 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
1984 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
1985 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
1986 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
1987 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
1988 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
1989 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
1990 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
1991 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
1992 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
1993 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
1994 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
1995 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
1996 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
1997 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
1998 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
1999 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2000 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2001 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2002 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2003 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2005 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2006 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2007 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2008 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2009 (while l (org-defkey org-agenda-mode-map
2010 (int-to-string (pop l)) 'digit-argument)))
2012 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2013 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2014 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2015 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2016 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2017 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2018 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2019 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2020 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2021 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2022 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2023 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2024 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2025 'org-clock-modify-effort-estimate)
2026 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2027 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2028 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2029 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2030 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2031 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2032 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2033 (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
2034 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2035 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2036 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2037 (substitute-key-definition 'next-line 'org-agenda-next-line
2038 org-agenda-mode-map global-map)
2039 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2040 org-agenda-mode-map global-map)
2041 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2042 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2043 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2044 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2045 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2046 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2047 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2048 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2049 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2050 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2051 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2052 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2053 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2054 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2055 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2056 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2057 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2058 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2059 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2060 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2061 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2062 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2063 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2064 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2065 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2066 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2067 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2068 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2069 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2070 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2072 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2073 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2074 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2075 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2076 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2077 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2078 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2079 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2080 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2081 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2082 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2083 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2085 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2086 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2087 (when org-agenda-mouse-1-follows-link
2088 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2089 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2090 '("Agenda"
2091 ("Agenda Files")
2092 "--"
2093 ("Agenda Dates"
2094 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2095 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2096 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2097 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2098 "--"
2099 ("View"
2100 ["Day View" org-agenda-day-view
2101 :active (org-agenda-check-type nil 'agenda)
2102 :style radio :selected (eq org-agenda-current-span 'day)
2103 :keys "v d (or just d)"]
2104 ["Week View" org-agenda-week-view
2105 :active (org-agenda-check-type nil 'agenda)
2106 :style radio :selected (eq org-agenda-current-span 'week)
2107 :keys "v w (or just w)"]
2108 ["Month View" org-agenda-month-view
2109 :active (org-agenda-check-type nil 'agenda)
2110 :style radio :selected (eq org-agenda-current-span 'month)
2111 :keys "v m"]
2112 ["Year View" org-agenda-year-view
2113 :active (org-agenda-check-type nil 'agenda)
2114 :style radio :selected (eq org-agenda-current-span 'year)
2115 :keys "v y"]
2116 "--"
2117 ["Include Diary" org-agenda-toggle-diary
2118 :style toggle :selected org-agenda-include-diary
2119 :active (org-agenda-check-type nil 'agenda)]
2120 ["Include Deadlines" org-agenda-toggle-deadlines
2121 :style toggle :selected org-agenda-include-deadlines
2122 :active (org-agenda-check-type nil 'agenda)]
2123 ["Use Time Grid" org-agenda-toggle-time-grid
2124 :style toggle :selected org-agenda-use-time-grid
2125 :active (org-agenda-check-type nil 'agenda)]
2126 "--"
2127 ["Show clock report" org-agenda-clockreport-mode
2128 :style toggle :selected org-agenda-clockreport-mode
2129 :active (org-agenda-check-type nil 'agenda)]
2130 ["Show some entry text" org-agenda-entry-text-mode
2131 :style toggle :selected org-agenda-entry-text-mode
2132 :active t]
2133 "--"
2134 ["Show Logbook entries" org-agenda-log-mode
2135 :style toggle :selected org-agenda-show-log
2136 :active (org-agenda-check-type nil 'agenda 'timeline)
2137 :keys "v l (or just l)"]
2138 ["Include archived trees" org-agenda-archives-mode
2139 :style toggle :selected org-agenda-archives-mode :active t
2140 :keys "v a"]
2141 ["Include archive files" (org-agenda-archives-mode t)
2142 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2143 :keys "v A"]
2144 "--"
2145 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2146 ["Write view to file" org-agenda-write t]
2147 ["Rebuild buffer" org-agenda-redo t]
2148 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2149 "--"
2150 ["Show original entry" org-agenda-show t]
2151 ["Go To (other window)" org-agenda-goto t]
2152 ["Go To (this window)" org-agenda-switch-to t]
2153 ["Follow Mode" org-agenda-follow-mode
2154 :style toggle :selected org-agenda-follow-mode :active t]
2155 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2156 "--"
2157 ("TODO"
2158 ["Cycle TODO" org-agenda-todo t]
2159 ["Next TODO set" org-agenda-todo-nextset t]
2160 ["Previous TODO set" org-agenda-todo-previousset t]
2161 ["Add note" org-agenda-add-note t])
2162 ("Archive/Refile/Delete"
2163 ["Archive default" org-agenda-archive-default t]
2164 ["Archive default" org-agenda-archive-default-with-confirmation t]
2165 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2166 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2167 ["Archive subtree" org-agenda-archive t]
2168 "--"
2169 ["Refile" org-agenda-refile t]
2170 "--"
2171 ["Delete subtree" org-agenda-kill t])
2172 ("Bulk action"
2173 ["Mark entry" org-agenda-bulk-mark t]
2174 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2175 ["Unmark entry" org-agenda-bulk-unmark t]
2176 ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
2177 ["Act on all marked" org-agenda-bulk-action t]
2178 "--"
2179 ("Tags and Properties"
2180 ["Show all Tags" org-agenda-show-tags t]
2181 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2182 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2183 "--"
2184 ["Column View" org-columns t])
2185 ("Deadline/Schedule"
2186 ["Schedule" org-agenda-schedule t]
2187 ["Set Deadline" org-agenda-deadline t]
2188 "--"
2189 ["Mark item" org-agenda-action :active t :keys "k m"]
2190 ["Show mark item" org-agenda-action :active t :keys "k v"]
2191 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2192 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2193 "--"
2194 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2195 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2196 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2197 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2198 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2199 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2200 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2201 ("Clock and Effort"
2202 ["Clock in" org-agenda-clock-in t]
2203 ["Clock out" org-agenda-clock-out t]
2204 ["Clock cancel" org-agenda-clock-cancel t]
2205 ["Goto running clock" org-clock-goto t]
2206 "--"
2207 ["Set Effort" org-agenda-set-effort t]
2208 ["Change clocked effort" org-clock-modify-effort-estimate
2209 (org-clock-is-active)])
2210 ("Priority"
2211 ["Set Priority" org-agenda-priority t]
2212 ["Increase Priority" org-agenda-priority-up t]
2213 ["Decrease Priority" org-agenda-priority-down t]
2214 ["Show Priority" org-agenda-show-priority t])
2215 ("Calendar/Diary"
2216 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2217 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2218 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2219 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2220 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2221 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2222 "--"
2223 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2224 "--"
2225 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2226 "--"
2227 ("MobileOrg"
2228 ["Push Files and Views" org-mobile-push t]
2229 ["Get Captured and Flagged" org-mobile-pull t]
2230 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2231 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2232 "--"
2233 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2234 "--"
2235 ["Quit" org-agenda-quit t]
2236 ["Exit and Release Buffers" org-agenda-exit t]
2239 ;;; Agenda undo
2241 (defvar org-agenda-allow-remote-undo t
2242 "Non-nil means allow remote undo from the agenda buffer.")
2243 (defvar org-agenda-undo-list nil
2244 "List of undoable operations in the agenda since last refresh.")
2245 (defvar org-agenda-undo-has-started-in nil
2246 "Buffers that have already seen `undo-start' in the current undo sequence.")
2247 (defvar org-agenda-pending-undo-list nil
2248 "In a series of undo commands, this is the list of remaining undo items.")
2250 (defun org-agenda-undo ()
2251 "Undo a remote editing step in the agenda.
2252 This undoes changes both in the agenda buffer and in the remote buffer
2253 that have been changed along."
2254 (interactive)
2255 (or org-agenda-allow-remote-undo
2256 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2257 (if (not (eq this-command last-command))
2258 (setq org-agenda-undo-has-started-in nil
2259 org-agenda-pending-undo-list org-agenda-undo-list))
2260 (if (not org-agenda-pending-undo-list)
2261 (error "No further undo information"))
2262 (let* ((entry (pop org-agenda-pending-undo-list))
2263 buf line cmd rembuf)
2264 (setq cmd (pop entry) line (pop entry))
2265 (setq rembuf (nth 2 entry))
2266 (org-with-remote-undo rembuf
2267 (while (bufferp (setq buf (pop entry)))
2268 (if (pop entry)
2269 (with-current-buffer buf
2270 (let ((last-undo-buffer buf)
2271 (inhibit-read-only t))
2272 (unless (memq buf org-agenda-undo-has-started-in)
2273 (push buf org-agenda-undo-has-started-in)
2274 (make-local-variable 'pending-undo-list)
2275 (undo-start))
2276 (while (and pending-undo-list
2277 (listp pending-undo-list)
2278 (not (car pending-undo-list)))
2279 (pop pending-undo-list))
2280 (undo-more 1))))))
2281 (org-goto-line line)
2282 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2284 (defun org-verify-change-for-undo (l1 l2)
2285 "Verify that a real change occurred between the undo lists L1 and L2."
2286 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2287 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2288 (not (eq l1 l2)))
2290 ;;; Agenda dispatch
2292 (defvar org-agenda-restrict nil)
2293 (defvar org-agenda-restrict-begin (make-marker))
2294 (defvar org-agenda-restrict-end (make-marker))
2295 (defvar org-agenda-last-dispatch-buffer nil)
2296 (defvar org-agenda-overriding-restriction nil)
2298 ;;;###autoload
2299 (defun org-agenda (&optional arg keys restriction)
2300 "Dispatch agenda commands to collect entries to the agenda buffer.
2301 Prompts for a command to execute. Any prefix arg will be passed
2302 on to the selected command. The default selections are:
2304 a Call `org-agenda-list' to display the agenda for current day or week.
2305 t Call `org-todo-list' to display the global todo list.
2306 T Call `org-todo-list' to display the global todo list, select only
2307 entries with a specific TODO keyword (the user gets a prompt).
2308 m Call `org-tags-view' to display headlines with tags matching
2309 a condition (the user is prompted for the condition).
2310 M Like `m', but select only TODO entries, no ordinary headlines.
2311 L Create a timeline for the current buffer.
2312 e Export views to associated files.
2313 s Search entries for keywords.
2314 / Multi occur across all agenda files and also files listed
2315 in `org-agenda-text-search-extra-files'.
2316 < Restrict agenda commands to buffer, subtree, or region.
2317 Press several times to get the desired effect.
2318 > Remove a previous restriction.
2319 # List \"stuck\" projects.
2320 ! Configure what \"stuck\" means.
2321 C Configure custom agenda commands.
2323 More commands can be added by configuring the variable
2324 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2325 searches can be pre-defined in this way.
2327 If the current buffer is in Org-mode and visiting a file, you can also
2328 first press `<' once to indicate that the agenda should be temporarily
2329 \(until the next use of \\[org-agenda]) restricted to the current file.
2330 Pressing `<' twice means to restrict to the current subtree or region
2331 \(if active)."
2332 (interactive "P")
2333 (catch 'exit
2334 (let* ((prefix-descriptions nil)
2335 (org-agenda-buffer-name org-agenda-buffer-name)
2336 (org-agenda-window-setup (if (equal (buffer-name)
2337 org-agenda-buffer-name)
2338 'current-window
2339 org-agenda-window-setup))
2340 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2341 (org-agenda-custom-commands
2342 ;; normalize different versions
2343 (delq nil
2344 (mapcar
2345 (lambda (x)
2346 (cond ((stringp (cdr x))
2347 (push x prefix-descriptions)
2348 nil)
2349 ((stringp (nth 1 x)) x)
2350 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2351 (t (cons (car x) (cons "" (cdr x))))))
2352 org-agenda-custom-commands)))
2353 (buf (current-buffer))
2354 (bfn (buffer-file-name (buffer-base-buffer)))
2355 entry key type match lprops ans)
2356 ;; Turn off restriction unless there is an overriding one,
2357 (unless org-agenda-overriding-restriction
2358 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2359 ;; There is a request to keep the file list in place
2360 (put 'org-agenda-files 'org-restrict nil))
2361 (setq org-agenda-restrict nil)
2362 (move-marker org-agenda-restrict-begin nil)
2363 (move-marker org-agenda-restrict-end nil))
2364 ;; Delete old local properties
2365 (put 'org-agenda-redo-command 'org-lprops nil)
2366 ;; Delete previously set last-arguments
2367 (put 'org-agenda-redo-command 'last-args nil)
2368 ;; Remember where this call originated
2369 (setq org-agenda-last-dispatch-buffer (current-buffer))
2370 (unless keys
2371 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2372 keys (car ans)
2373 restriction (cdr ans)))
2374 ;; If we have sticky agenda buffers, set a name for the buffer,
2375 ;; depending on the invoking keys. The user may still set this
2376 ;; as a command option, which will overwrite what we do here.
2377 (if org-agenda-sticky
2378 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2379 ;; Establish the restriction, if any
2380 (when (and (not org-agenda-overriding-restriction) restriction)
2381 (put 'org-agenda-files 'org-restrict (list bfn))
2382 (cond
2383 ((eq restriction 'region)
2384 (setq org-agenda-restrict t)
2385 (move-marker org-agenda-restrict-begin (region-beginning))
2386 (move-marker org-agenda-restrict-end (region-end)))
2387 ((eq restriction 'subtree)
2388 (save-excursion
2389 (setq org-agenda-restrict t)
2390 (org-back-to-heading t)
2391 (move-marker org-agenda-restrict-begin (point))
2392 (move-marker org-agenda-restrict-end
2393 (progn (org-end-of-subtree t)))))))
2395 ;; For example the todo list should not need it (but does...)
2396 (cond
2397 ((setq entry (assoc keys org-agenda-custom-commands))
2398 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2399 (progn
2400 (setq type (nth 2 entry) match (eval (nth 3 entry))
2401 lprops (nth 4 entry))
2402 (put 'org-agenda-redo-command 'org-lprops lprops)
2403 (cond
2404 ((eq type 'agenda)
2405 (org-let lprops '(org-agenda-list current-prefix-arg)))
2406 ((eq type 'alltodo)
2407 (org-let lprops '(org-todo-list current-prefix-arg)))
2408 ((eq type 'search)
2409 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2410 ((eq type 'stuck)
2411 (org-let lprops '(org-agenda-list-stuck-projects
2412 current-prefix-arg)))
2413 ((eq type 'tags)
2414 (org-let lprops '(org-tags-view current-prefix-arg match)))
2415 ((eq type 'tags-todo)
2416 (org-let lprops '(org-tags-view '(4) match)))
2417 ((eq type 'todo)
2418 (org-let lprops '(org-todo-list match)))
2419 ((eq type 'tags-tree)
2420 (org-check-for-org-mode)
2421 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2422 ((eq type 'todo-tree)
2423 (org-check-for-org-mode)
2424 (org-let lprops
2425 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2426 (regexp-quote match) "\\>"))))
2427 ((eq type 'occur-tree)
2428 (org-check-for-org-mode)
2429 (org-let lprops '(org-occur match)))
2430 ((functionp type)
2431 (org-let lprops '(funcall type match)))
2432 ((fboundp type)
2433 (org-let lprops '(funcall type match)))
2434 (t (error "Invalid custom agenda command type %s" type))))
2435 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2436 ((equal keys "C")
2437 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2438 (customize-variable 'org-agenda-custom-commands))
2439 ((equal keys "a") (call-interactively 'org-agenda-list))
2440 ((equal keys "s") (call-interactively 'org-search-view))
2441 ((equal keys "t") (call-interactively 'org-todo-list))
2442 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2443 ((equal keys "m") (call-interactively 'org-tags-view))
2444 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2445 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2446 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2447 (org-add-hook
2448 'post-command-hook
2449 (lambda ()
2450 (unless (current-message)
2451 (let* ((m (org-agenda-get-any-marker))
2452 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2453 (when note
2454 (message (concat
2455 "FLAGGING-NOTE ([?] for more info): "
2456 (org-add-props
2457 (replace-regexp-in-string
2458 "\\\\n" "//"
2459 (copy-sequence note))
2460 nil 'face 'org-warning)))))))
2461 t t))
2462 ((equal keys "L")
2463 (unless (eq major-mode 'org-mode)
2464 (error "This is not an Org-mode file"))
2465 (unless restriction
2466 (put 'org-agenda-files 'org-restrict (list bfn))
2467 (org-call-with-arg 'org-timeline arg)))
2468 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2469 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2470 ((equal keys "!") (customize-variable 'org-stuck-projects))
2471 (t (error "Invalid agenda key"))))))
2473 (defun org-agenda-append-agenda ()
2474 "Append another agenda view to the current one.
2475 This function allows interactive building of block agendas.
2476 Agenda views are separated by `org-agenda-block-separator'."
2477 (interactive)
2478 (unless (string= (buffer-name) org-agenda-buffer-name)
2479 (error "Can only append from within agenda buffer"))
2480 (let ((org-agenda-multi t))
2481 (org-agenda)
2482 (widen)))
2484 (defun org-agenda-normalize-custom-commands (cmds)
2485 (delq nil
2486 (mapcar
2487 (lambda (x)
2488 (cond ((stringp (cdr x)) nil)
2489 ((stringp (nth 1 x)) x)
2490 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2491 (t (cons (car x) (cons "" (cdr x))))))
2492 cmds)))
2494 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2495 "The user interface for selecting an agenda command."
2496 (catch 'exit
2497 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2498 (restrict-ok (and bfn (eq major-mode 'org-mode)))
2499 (region-p (org-region-active-p))
2500 (custom org-agenda-custom-commands)
2501 (selstring "")
2502 restriction second-time
2503 c entry key type match prefixes rmheader header-end custom1 desc
2504 line lines left right n n1)
2505 (save-window-excursion
2506 (delete-other-windows)
2507 (org-switch-to-buffer-other-window " *Agenda Commands*")
2508 (erase-buffer)
2509 (insert (eval-when-compile
2510 (let ((header
2511 "Press key for an agenda command: < Buffer, subtree/region restriction
2512 -------------------------------- > Remove restriction
2513 a Agenda for current week or day e Export agenda views
2514 t List of all TODO entries T Entries with special TODO kwd
2515 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2516 L Timeline for current buffer # List stuck projects (!=configure)
2517 s Search for keywords * Toggle sticky agenda views
2518 / Multi-occur ? Find :FLAGGED: entries
2519 C Configure custom agenda commands
2521 (start 0))
2522 (while (string-match
2523 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2524 header start)
2525 (setq start (match-end 0))
2526 (add-text-properties (match-beginning 2) (match-end 2)
2527 '(face bold) header))
2528 header)))
2529 (setq header-end (move-marker (make-marker) (point)))
2530 (while t
2531 (setq custom1 custom)
2532 (when (eq rmheader t)
2533 (org-goto-line 1)
2534 (re-search-forward ":" nil t)
2535 (delete-region (match-end 0) (point-at-eol))
2536 (forward-char 1)
2537 (looking-at "-+")
2538 (delete-region (match-end 0) (point-at-eol))
2539 (move-marker header-end (match-end 0)))
2540 (goto-char header-end)
2541 (delete-region (point) (point-max))
2543 ;; Produce all the lines that describe custom commands and prefixes
2544 (setq lines nil)
2545 (while (setq entry (pop custom1))
2546 (setq key (car entry) desc (nth 1 entry)
2547 type (nth 2 entry)
2548 match (nth 3 entry))
2549 (if (> (length key) 1)
2550 (add-to-list 'prefixes (string-to-char key))
2551 (setq line
2552 (format
2553 "%-4s%-14s"
2554 (org-add-props (copy-sequence key)
2555 '(face bold))
2556 (cond
2557 ((string-match "\\S-" desc) desc)
2558 ((eq type 'agenda) "Agenda for current week or day")
2559 ((eq type 'alltodo) "List of all TODO entries")
2560 ((eq type 'search) "Word search")
2561 ((eq type 'stuck) "List of stuck projects")
2562 ((eq type 'todo) "TODO keyword")
2563 ((eq type 'tags) "Tags query")
2564 ((eq type 'tags-todo) "Tags (TODO)")
2565 ((eq type 'tags-tree) "Tags tree")
2566 ((eq type 'todo-tree) "TODO kwd tree")
2567 ((eq type 'occur-tree) "Occur tree")
2568 ((functionp type) (if (symbolp type)
2569 (symbol-name type)
2570 "Lambda expression"))
2571 (t "???"))))
2572 (if org-agenda-menu-show-matcher
2573 (setq line
2574 (concat line ": "
2575 (cond
2576 ((stringp match)
2577 (setq match (copy-sequence match))
2578 (org-add-props match nil 'face 'org-warning))
2579 (match
2580 (format "set of %d commands" (length match)))
2581 (t ""))))
2582 (if (org-string-nw-p match)
2583 (add-text-properties
2584 0 (length line) (list 'help-echo
2585 (concat "Matcher: "match)) line)))
2586 (push line lines)))
2587 (setq lines (nreverse lines))
2588 (when prefixes
2589 (mapc (lambda (x)
2590 (push
2591 (format "%s %s"
2592 (org-add-props (char-to-string x)
2593 nil 'face 'bold)
2594 (or (cdr (assoc (concat selstring
2595 (char-to-string x))
2596 prefix-descriptions))
2597 "Prefix key"))
2598 lines))
2599 prefixes))
2601 ;; Check if we should display in two columns
2602 (if org-agenda-menu-two-column
2603 (progn
2604 (setq n (length lines)
2605 n1 (+ (/ n 2) (mod n 2))
2606 right (nthcdr n1 lines)
2607 left (copy-sequence lines))
2608 (setcdr (nthcdr (1- n1) left) nil))
2609 (setq left lines right nil))
2610 (while left
2611 (insert "\n" (pop left))
2612 (when right
2613 (if (< (current-column) 40)
2614 (move-to-column 40 t)
2615 (insert " "))
2616 (insert (pop right))))
2618 ;; Make the window the right size
2619 (goto-char (point-min))
2620 (if second-time
2621 (if (not (pos-visible-in-window-p (point-max)))
2622 (org-fit-window-to-buffer))
2623 (setq second-time t)
2624 (org-fit-window-to-buffer))
2626 ;; Ask for selection
2627 (message "Press key for agenda command%s:"
2628 (if (or restrict-ok org-agenda-overriding-restriction)
2629 (if org-agenda-overriding-restriction
2630 " (restriction lock active)"
2631 (if restriction
2632 (format " (restricted to %s)" restriction)
2633 " (unrestricted)"))
2634 ""))
2635 (setq c (read-char-exclusive))
2636 (message "")
2637 (cond
2638 ((assoc (char-to-string c) custom)
2639 (setq selstring (concat selstring (char-to-string c)))
2640 (throw 'exit (cons selstring restriction)))
2641 ((memq c prefixes)
2642 (setq selstring (concat selstring (char-to-string c))
2643 prefixes nil
2644 rmheader (or rmheader t)
2645 custom (delq nil (mapcar
2646 (lambda (x)
2647 (if (or (= (length (car x)) 1)
2648 (/= (string-to-char (car x)) c))
2650 (cons (substring (car x) 1) (cdr x))))
2651 custom))))
2652 ((eq c ?*)
2653 (org-toggle-sticky-agenda)
2654 (sit-for 2))
2655 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2656 (message "Restriction is only possible in Org-mode buffers")
2657 (ding) (sit-for 1))
2658 ((eq c ?1)
2659 (org-agenda-remove-restriction-lock 'noupdate)
2660 (setq restriction 'buffer))
2661 ((eq c ?0)
2662 (org-agenda-remove-restriction-lock 'noupdate)
2663 (setq restriction (if region-p 'region 'subtree)))
2664 ((eq c ?<)
2665 (org-agenda-remove-restriction-lock 'noupdate)
2666 (setq restriction
2667 (cond
2668 ((eq restriction 'buffer)
2669 (if region-p 'region 'subtree))
2670 ((memq restriction '(subtree region))
2671 nil)
2672 (t 'buffer))))
2673 ((eq c ?>)
2674 (org-agenda-remove-restriction-lock 'noupdate)
2675 (setq restriction nil))
2676 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2677 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2678 ((and (> (length selstring) 0) (eq c ?\d))
2679 (delete-window)
2680 (org-agenda-get-restriction-and-command prefix-descriptions))
2682 ((equal c ?q) (error "Abort"))
2683 (t (error "Invalid key %c" c))))))))
2685 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2686 (defvar org-agenda-last-arguments nil
2687 "The arguments of the previous call to `org-agenda'.")
2688 (defun org-agenda-run-series (name series)
2689 (org-let (nth 1 series) '(org-prepare-agenda name))
2690 ;; We need to reset agenda markers here, because when constructing a
2691 ;; block agenda, the individual blocks do not do that.
2692 (org-agenda-reset-markers)
2693 (let* ((org-agenda-multi t)
2694 (redo (list 'org-agenda-run-series name (list 'quote series)))
2695 (org-agenda-overriding-arguments
2696 (or org-agenda-overriding-arguments
2697 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2698 (get 'org-agenda-redo-command 'last-args))))
2699 (cmds (car series))
2700 (gprops (nth 1 series))
2701 match ;; The byte compiler incorrectly complains about this. Keep it!
2702 cmd type lprops)
2703 (while (setq cmd (pop cmds))
2704 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2705 (cond
2706 ((eq type 'agenda)
2707 (org-let2 gprops lprops
2708 '(call-interactively 'org-agenda-list)))
2709 ((eq type 'alltodo)
2710 (org-let2 gprops lprops
2711 '(call-interactively 'org-todo-list)))
2712 ((eq type 'search)
2713 (org-let2 gprops lprops
2714 '(org-search-view current-prefix-arg match nil)))
2715 ((eq type 'stuck)
2716 (org-let2 gprops lprops
2717 '(call-interactively 'org-agenda-list-stuck-projects)))
2718 ((eq type 'tags)
2719 (org-let2 gprops lprops
2720 '(org-tags-view current-prefix-arg match)))
2721 ((eq type 'tags-todo)
2722 (org-let2 gprops lprops
2723 '(org-tags-view '(4) match)))
2724 ((eq type 'todo)
2725 (org-let2 gprops lprops
2726 '(org-todo-list match)))
2727 ((fboundp type)
2728 (org-let2 gprops lprops
2729 '(funcall type match)))
2730 (t (error "Invalid type in command series"))))
2731 (widen)
2732 (setq org-agenda-redo-command redo)
2733 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2734 (goto-char (point-min)))
2735 (org-fit-agenda-window)
2736 (org-let (nth 1 series) '(org-finalize-agenda)))
2738 ;;;###autoload
2739 (defmacro org-batch-agenda (cmd-key &rest parameters)
2740 "Run an agenda command in batch mode and send the result to STDOUT.
2741 If CMD-KEY is a string of length 1, it is used as a key in
2742 `org-agenda-custom-commands' and triggers this command. If it is a
2743 longer string it is used as a tags/todo match string.
2744 Parameters are alternating variable names and values that will be bound
2745 before running the agenda command."
2746 (org-eval-in-environment (org-make-parameter-alist parameters)
2747 (if (> (length cmd-key) 2)
2748 (org-tags-view nil cmd-key)
2749 (org-agenda nil cmd-key)))
2750 (set-buffer org-agenda-buffer-name)
2751 (princ (buffer-string)))
2752 (def-edebug-spec org-batch-agenda (form &rest sexp))
2754 (defvar org-agenda-info nil)
2756 ;;;###autoload
2757 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2758 "Run an agenda command in batch mode and send the result to STDOUT.
2759 If CMD-KEY is a string of length 1, it is used as a key in
2760 `org-agenda-custom-commands' and triggers this command. If it is a
2761 longer string it is used as a tags/todo match string.
2762 Parameters are alternating variable names and values that will be bound
2763 before running the agenda command.
2765 The output gives a line for each selected agenda item. Each
2766 item is a list of comma-separated values, like this:
2768 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2770 category The category of the item
2771 head The headline, without TODO kwd, TAGS and PRIORITY
2772 type The type of the agenda entry, can be
2773 todo selected in TODO match
2774 tagsmatch selected in tags match
2775 diary imported from diary
2776 deadline a deadline on given date
2777 scheduled scheduled on given date
2778 timestamp entry has timestamp on given date
2779 closed entry was closed on given date
2780 upcoming-deadline warning about deadline
2781 past-scheduled forwarded scheduled item
2782 block entry has date block including g. date
2783 todo The todo keyword, if any
2784 tags All tags including inherited ones, separated by colons
2785 date The relevant date, like 2007-2-14
2786 time The time, like 15:00-16:50
2787 extra Sting with extra planning info
2788 priority-l The priority letter if any was given
2789 priority-n The computed numerical priority
2790 agenda-day The day in the agenda where this is listed"
2791 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2792 (org-make-parameter-alist parameters))
2793 (if (> (length cmd-key) 2)
2794 (org-tags-view nil cmd-key)
2795 (org-agenda nil cmd-key)))
2796 (set-buffer org-agenda-buffer-name)
2797 (let* ((lines (org-split-string (buffer-string) "\n"))
2798 line)
2799 (while (setq line (pop lines))
2800 (catch 'next
2801 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2802 (setq org-agenda-info
2803 (org-fix-agenda-info (text-properties-at 0 line)))
2804 (princ
2805 (mapconcat 'org-agenda-export-csv-mapper
2806 '(org-category txt type todo tags date time extra
2807 priority-letter priority agenda-day)
2808 ","))
2809 (princ "\n")))))
2810 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2812 (defun org-fix-agenda-info (props)
2813 "Make sure all properties on an agenda item have a canonical form.
2814 This ensures the export commands can easily use it."
2815 (let (tmp re)
2816 (when (setq tmp (plist-get props 'tags))
2817 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2818 (when (setq tmp (plist-get props 'date))
2819 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2820 (let ((calendar-date-display-form '(year "-" month "-" day)))
2821 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2823 (setq tmp (calendar-date-string tmp)))
2824 (setq props (plist-put props 'date tmp)))
2825 (when (setq tmp (plist-get props 'day))
2826 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2827 (let ((calendar-date-display-form '(year "-" month "-" day)))
2828 (setq tmp (calendar-date-string tmp)))
2829 (setq props (plist-put props 'day tmp))
2830 (setq props (plist-put props 'agenda-day tmp)))
2831 (when (setq tmp (plist-get props 'txt))
2832 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2833 (plist-put props 'priority-letter (match-string 1 tmp))
2834 (setq tmp (replace-match "" t t tmp)))
2835 (when (and (setq re (plist-get props 'org-todo-regexp))
2836 (setq re (concat "\\`\\.*" re " ?"))
2837 (string-match re tmp))
2838 (plist-put props 'todo (match-string 1 tmp))
2839 (setq tmp (replace-match "" t t tmp)))
2840 (plist-put props 'txt tmp)))
2841 props)
2843 (defun org-agenda-export-csv-mapper (prop)
2844 (let ((res (plist-get org-agenda-info prop)))
2845 (setq res
2846 (cond
2847 ((not res) "")
2848 ((stringp res) res)
2849 (t (prin1-to-string res))))
2850 (while (string-match "," res)
2851 (setq res (replace-match ";" t t res)))
2852 (org-trim res)))
2855 ;;;###autoload
2856 (defun org-store-agenda-views (&rest parameters)
2857 (interactive)
2858 (eval (list 'org-batch-store-agenda-views)))
2860 ;;;###autoload
2861 (defmacro org-batch-store-agenda-views (&rest parameters)
2862 "Run all custom agenda commands that have a file argument."
2863 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2864 (pop-up-frames nil)
2865 (dir default-directory)
2866 (pars (org-make-parameter-alist parameters))
2867 cmd thiscmdkey files opts cmd-or-set)
2868 (save-window-excursion
2869 (while cmds
2870 (setq cmd (pop cmds)
2871 thiscmdkey (car cmd)
2872 cmd-or-set (nth 2 cmd)
2873 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2874 files (nth (if (listp cmd-or-set) 4 5) cmd))
2875 (if (stringp files) (setq files (list files)))
2876 (when files
2877 (org-eval-in-environment (append org-agenda-exporter-settings
2878 opts pars)
2879 (org-agenda nil thiscmdkey))
2880 (set-buffer org-agenda-buffer-name)
2881 (while files
2882 (org-eval-in-environment (append org-agenda-exporter-settings
2883 opts pars)
2884 (org-agenda-write (expand-file-name (pop files) dir) nil t)))
2885 (and (get-buffer org-agenda-buffer-name)
2886 (kill-buffer org-agenda-buffer-name)))))))
2887 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2889 (defun org-agenda-mark-header-line (pos)
2890 "Mark the line at POS as an agenda structure header."
2891 (save-excursion
2892 (goto-char pos)
2893 (put-text-property (point-at-bol) (point-at-eol)
2894 'org-agenda-structural-header t)
2895 (when org-agenda-title-append
2896 (put-text-property (point-at-bol) (point-at-eol)
2897 'org-agenda-title-append org-agenda-title-append))))
2899 (defvar org-mobile-creating-agendas)
2900 (defvar org-agenda-write-buffer-name "Agenda View")
2901 (defun org-agenda-write (file &optional open nosettings)
2902 "Write the current buffer (an agenda view) as a file.
2903 Depending on the extension of the file name, plain text (.txt),
2904 HTML (.html or .htm) or Postscript (.ps) is produced.
2905 If the extension is .ics, run icalendar export over all files used
2906 to construct the agenda and limit the export to entries listed in the
2907 agenda now.
2908 With prefix argument OPEN, open the new file immediately.
2909 If NOSETTINGS is given, do not scope the settings of
2910 `org-agenda-exporter-settings' into the export commands. This is used when
2911 the settings have already been scoped and we do not wish to overrule other,
2912 higher priority settings."
2913 (interactive "FWrite agenda to file: \nP")
2914 (if (not (file-writable-p file))
2915 (error "Cannot write agenda to file %s" file))
2916 (org-let (if nosettings nil org-agenda-exporter-settings)
2917 '(save-excursion
2918 (save-window-excursion
2919 (org-agenda-mark-filtered-text)
2920 (let ((bs (copy-sequence (buffer-string))) beg)
2921 (org-agenda-unmark-filtered-text)
2922 (with-temp-buffer
2923 (rename-buffer org-agenda-write-buffer-name t)
2924 (set-buffer-modified-p nil)
2925 (insert bs)
2926 (org-agenda-remove-marked-text 'org-filtered)
2927 (while (setq beg (text-property-any (point-min) (point-max)
2928 'org-filtered t))
2929 (delete-region
2930 beg (or (next-single-property-change beg 'org-filtered)
2931 (point-max))))
2932 (run-hooks 'org-agenda-before-write-hook)
2933 (cond
2934 ((org-bound-and-true-p org-mobile-creating-agendas)
2935 (org-mobile-write-agenda-for-mobile file))
2936 ((string-match "\\.html?\\'" file)
2937 (require 'htmlize)
2938 (set-buffer (htmlize-buffer (current-buffer)))
2940 (when (and org-agenda-export-html-style
2941 (string-match "<style>" org-agenda-export-html-style))
2942 ;; replace <style> section with org-agenda-export-html-style
2943 (goto-char (point-min))
2944 (kill-region (- (search-forward "<style") 6)
2945 (search-forward "</style>"))
2946 (insert org-agenda-export-html-style))
2947 (write-file file)
2948 (kill-buffer (current-buffer))
2949 (message "HTML written to %s" file))
2950 ((string-match "\\.ps\\'" file)
2951 (require 'ps-print)
2952 (ps-print-buffer-with-faces file)
2953 (message "Postscript written to %s" file))
2954 ((string-match "\\.pdf\\'" file)
2955 (require 'ps-print)
2956 (ps-print-buffer-with-faces
2957 (concat (file-name-sans-extension file) ".ps"))
2958 (call-process "ps2pdf" nil nil nil
2959 (expand-file-name
2960 (concat (file-name-sans-extension file) ".ps"))
2961 (expand-file-name file))
2962 (delete-file (concat (file-name-sans-extension file) ".ps"))
2963 (message "PDF written to %s" file))
2964 ((string-match "\\.ics\\'" file)
2965 (require 'org-icalendar)
2966 (let ((org-agenda-marker-table
2967 (org-create-marker-find-array
2968 (org-agenda-collect-markers)))
2969 (org-icalendar-verify-function 'org-check-agenda-marker-table)
2970 (org-combined-agenda-icalendar-file file))
2971 (apply 'org-export-icalendar 'combine
2972 (org-agenda-files nil 'ifmode))))
2974 (let ((bs (buffer-string)))
2975 (find-file file)
2976 (erase-buffer)
2977 (insert bs)
2978 (save-buffer 0)
2979 (kill-buffer (current-buffer))
2980 (message "Plain text written to %s" file))))))))
2981 (set-buffer org-agenda-buffer-name))
2982 (when open (org-open-file file)))
2984 (defvar org-agenda-tag-filter-overlays nil)
2985 (defvar org-agenda-cat-filter-overlays nil)
2987 (defun org-agenda-mark-filtered-text ()
2988 "Mark all text hidden by filtering with a text property."
2989 (let ((inhibit-read-only t))
2990 (mapc
2991 (lambda (o)
2992 (when (equal (overlay-buffer o) (current-buffer))
2993 (put-text-property
2994 (overlay-start o) (overlay-end o)
2995 'org-filtered t)))
2996 (append org-agenda-tag-filter-overlays
2997 org-agenda-cat-filter-overlays))))
2999 (defun org-agenda-unmark-filtered-text ()
3000 "Remove the filtering text property."
3001 (let ((inhibit-read-only t))
3002 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3004 (defun org-agenda-remove-marked-text (property &optional value)
3005 "Delete all text marked with VALUE of PROPERTY.
3006 VALUE defaults to t."
3007 (let (beg)
3008 (setq value (or value t))
3009 (while (setq beg (text-property-any (point-min) (point-max)
3010 property value))
3011 (delete-region
3012 beg (or (next-single-property-change beg 'org-filtered)
3013 (point-max))))))
3015 (defun org-agenda-add-entry-text ()
3016 "Add entry text to agenda lines.
3017 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3018 entry text following headings shown in the agenda.
3019 Drawers will be excluded, also the line with scheduling/deadline info."
3020 (when (and (> org-agenda-add-entry-text-maxlines 0)
3021 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3022 (let (m txt)
3023 (goto-char (point-min))
3024 (while (not (eobp))
3025 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3026 (beginning-of-line 2)
3027 (setq txt (org-agenda-get-some-entry-text
3028 m org-agenda-add-entry-text-maxlines " > "))
3029 (end-of-line 1)
3030 (if (string-match "\\S-" txt)
3031 (insert "\n" txt)
3032 (or (eobp) (forward-char 1))))))))
3034 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3035 &rest keep)
3036 "Extract entry text from MARKER, at most N-LINES lines.
3037 This will ignore drawers etc, just get the text.
3038 If INDENT is given, prefix every line with this string. If KEEP is
3039 given, it is a list of symbols, defining stuff that should not be
3040 removed from the entry content. Currently only `planning' is allowed here."
3041 (let (txt drawer-re kwd-time-re ind)
3042 (save-excursion
3043 (with-current-buffer (marker-buffer marker)
3044 (if (not (eq major-mode 'org-mode))
3045 (setq txt "")
3046 (save-excursion
3047 (save-restriction
3048 (widen)
3049 (goto-char marker)
3050 (end-of-line 1)
3051 (setq txt (buffer-substring
3052 (min (1+ (point)) (point-max))
3053 (progn (outline-next-heading) (point)))
3054 drawer-re org-drawer-regexp
3055 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3056 ".*\n?"))
3057 (with-temp-buffer
3058 (insert txt)
3059 (when org-agenda-add-entry-text-descriptive-links
3060 (goto-char (point-min))
3061 (while (org-activate-bracket-links (point-max))
3062 (add-text-properties (match-beginning 0) (match-end 0)
3063 '(face org-link))))
3064 (goto-char (point-min))
3065 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3066 (set-text-properties (match-beginning 0) (match-end 0)
3067 nil))
3068 (goto-char (point-min))
3069 (while (re-search-forward drawer-re nil t)
3070 (delete-region
3071 (match-beginning 0)
3072 (progn (re-search-forward
3073 "^[ \t]*:END:.*\n?" nil 'move)
3074 (point))))
3075 (unless (member 'planning keep)
3076 (goto-char (point-min))
3077 (while (re-search-forward kwd-time-re nil t)
3078 (replace-match "")))
3079 (goto-char (point-min))
3080 (when org-agenda-entry-text-exclude-regexps
3081 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3082 (while (setq re (pop re-list))
3083 (goto-char (point-min))
3084 (while (re-search-forward re nil t)
3085 (replace-match "")))))
3086 (goto-char (point-max))
3087 (skip-chars-backward " \t\n")
3088 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3090 ;; find and remove min common indentation
3091 (goto-char (point-min))
3092 (untabify (point-min) (point-max))
3093 (setq ind (org-get-indentation))
3094 (while (not (eobp))
3095 (unless (looking-at "[ \t]*$")
3096 (setq ind (min ind (org-get-indentation))))
3097 (beginning-of-line 2))
3098 (goto-char (point-min))
3099 (while (not (eobp))
3100 (unless (looking-at "[ \t]*$")
3101 (move-to-column ind)
3102 (delete-region (point-at-bol) (point)))
3103 (beginning-of-line 2))
3105 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3107 (goto-char (point-min))
3108 (when indent
3109 (while (and (not (eobp)) (re-search-forward "^" nil t))
3110 (replace-match indent t t)))
3111 (goto-char (point-min))
3112 (while (looking-at "[ \t]*\n") (replace-match ""))
3113 (goto-char (point-max))
3114 (when (> (org-current-line)
3115 n-lines)
3116 (org-goto-line (1+ n-lines))
3117 (backward-char 1))
3118 (setq txt (buffer-substring (point-min) (point)))))))))
3119 txt))
3121 (defun org-agenda-collect-markers ()
3122 "Collect the markers pointing to entries in the agenda buffer."
3123 (let (m markers)
3124 (save-excursion
3125 (goto-char (point-min))
3126 (while (not (eobp))
3127 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3128 (org-get-at-bol 'org-marker)))
3129 (push m markers))
3130 (beginning-of-line 2)))
3131 (nreverse markers)))
3133 (defun org-create-marker-find-array (marker-list)
3134 "Create a alist of files names with all marker positions in that file."
3135 (let (f tbl m a p)
3136 (while (setq m (pop marker-list))
3137 (setq p (marker-position m)
3138 f (buffer-file-name (or (buffer-base-buffer
3139 (marker-buffer m))
3140 (marker-buffer m))))
3141 (if (setq a (assoc f tbl))
3142 (push (marker-position m) (cdr a))
3143 (push (list f p) tbl)))
3144 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3145 tbl)))
3147 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3148 (defun org-check-agenda-marker-table ()
3149 "Check of the current entry is on the marker list."
3150 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3152 (and (setq a (assoc file org-agenda-marker-table))
3153 (save-match-data
3154 (save-excursion
3155 (org-back-to-heading t)
3156 (member (point) (cdr a)))))))
3158 (defun org-check-for-org-mode ()
3159 "Make sure current buffer is in org-mode. Error if not."
3160 (or (eq major-mode 'org-mode)
3161 (error "Cannot execute org-mode agenda command on buffer in %s"
3162 major-mode)))
3164 (defun org-fit-agenda-window ()
3165 "Fit the window to the buffer size."
3166 (and (memq org-agenda-window-setup '(reorganize-frame))
3167 (fboundp 'fit-window-to-buffer)
3168 (org-fit-window-to-buffer
3170 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3171 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3173 ;;; Agenda prepare and finalize
3175 (defvar org-agenda-multi nil) ; dynamically scoped
3176 (defvar org-agenda-buffer-name "*Org Agenda*")
3177 (defvar org-pre-agenda-window-conf nil)
3178 (defvar org-agenda-columns-active nil)
3179 (defvar org-agenda-name nil)
3180 (defvar org-agenda-tag-filter nil)
3181 (defvar org-agenda-category-filter nil)
3182 (defvar org-agenda-tag-filter-while-redo nil)
3183 (defvar org-agenda-tag-filter-preset nil
3184 "A preset of the tags filter used for secondary agenda filtering.
3185 This must be a list of strings, each string must be a single tag preceded
3186 by \"+\" or \"-\".
3187 This variable should not be set directly, but agenda custom commands can
3188 bind it in the options section. The preset filter is a global property of
3189 the entire agenda view. In a block agenda, it will not work reliably to
3190 define a filter for one of the individual blocks. You need to set it in
3191 the global options and expect it to be applied to the entire view.")
3193 (defvar org-agenda-category-filter-preset nil
3194 "A preset of the category filter used for secondary agenda filtering.
3195 This must be a list of strings, each string must be a single category
3196 preceded by \"+\" or \"-\".
3197 This variable should not be set directly, but agenda custom commands can
3198 bind it in the options section. The preset filter is a global property of
3199 the entire agenda view. In a block agenda, it will not work reliably to
3200 define a filter for one of the individual blocks. You need to set it in
3201 the global options and expect it to be applied to the entire view.")
3204 (defun org-agenda-use-sticky-p ()
3205 "Return non-NIL if existing agenda buffer named
3206 `org-agenda-buffer-name' exists, and should be shown instead of
3207 generating a new one"
3208 (and
3209 ;; turned off by user
3210 org-agenda-sticky
3211 ;; For multi-agenda buffer already exists
3212 (not org-agenda-multi)
3213 ;; buffer found
3214 (get-buffer org-agenda-buffer-name)
3215 ;; C-u parameter is same as last call
3216 (with-current-buffer (get-buffer org-agenda-buffer-name)
3217 (and
3218 (equal current-prefix-arg
3219 org-agenda-last-prefix-arg)
3220 ;; In case user turned stickiness on, while having existing
3221 ;; Agenda buffer active, don't reuse that buffer, because it
3222 ;; does not have org variables local
3223 org-agenda-this-buffer-is-sticky))))
3225 (defun org-prepare-agenda-window (abuf)
3226 "Setup agenda buffer in the window"
3227 (let* ((awin (get-buffer-window abuf))
3228 wconf)
3229 (cond
3230 ((equal (current-buffer) abuf) nil)
3231 (awin (select-window awin))
3232 ((not (setq wconf (current-window-configuration))))
3233 ((equal org-agenda-window-setup 'current-window)
3234 (org-pop-to-buffer-same-window abuf))
3235 ((equal org-agenda-window-setup 'other-window)
3236 (org-switch-to-buffer-other-window abuf))
3237 ((equal org-agenda-window-setup 'other-frame)
3238 (switch-to-buffer-other-frame abuf))
3239 ((equal org-agenda-window-setup 'reorganize-frame)
3240 (delete-other-windows)
3241 (org-switch-to-buffer-other-window abuf)))
3242 ;; additional test in case agenda is invoked from within agenda
3243 ;; buffer via elisp link
3244 (unless (equal (current-buffer) abuf)
3245 (org-pop-to-buffer-same-window abuf))
3246 (setq org-pre-agenda-window-conf wconf)))
3248 (defun org-prepare-agenda (&optional name)
3249 (if (org-agenda-use-sticky-p)
3250 (progn
3251 ;; Popup existing buffer
3252 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3253 (message "Sticky Agenda buffer, use `r' to refresh")
3254 (throw 'exit nil))
3255 (setq org-todo-keywords-for-agenda nil)
3256 (setq org-drawers-for-agenda nil)
3257 (unless org-agenda-persistent-filter
3258 (setq org-agenda-tag-filter nil
3259 org-agenda-category-filter nil))
3260 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3261 (put 'org-agenda-category-filter :preset-filter
3262 org-agenda-category-filter-preset)
3263 (if org-agenda-multi
3264 (progn
3265 (setq buffer-read-only nil)
3266 (goto-char (point-max))
3267 (unless (or (bobp) org-agenda-compact-blocks
3268 (not org-agenda-block-separator))
3269 (insert "\n"
3270 (if (stringp org-agenda-block-separator)
3271 org-agenda-block-separator
3272 (make-string (window-width) org-agenda-block-separator))
3273 "\n"))
3274 (narrow-to-region (point) (point-max)))
3275 (setq org-done-keywords-for-agenda nil)
3277 ;; Setting any org variables that are in org-agenda-local-vars
3278 ;; list need to be done after the prepare call
3279 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3280 (setq buffer-read-only nil)
3281 (org-agenda-reset-markers)
3282 (let ((inhibit-read-only t)) (erase-buffer))
3283 (org-agenda-mode)
3284 (setq org-agenda-buffer (current-buffer))
3285 (setq org-agenda-contributing-files nil)
3286 (setq org-agenda-columns-active nil)
3287 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3288 (setq org-todo-keywords-for-agenda
3289 (org-uniquify org-todo-keywords-for-agenda))
3290 (setq org-done-keywords-for-agenda
3291 (org-uniquify org-done-keywords-for-agenda))
3292 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3293 (setq org-agenda-last-prefix-arg current-prefix-arg)
3294 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3295 (and name (not org-agenda-name)
3296 (org-set-local 'org-agenda-name name)))
3297 (setq buffer-read-only nil)))
3299 (defun org-finalize-agenda ()
3300 "Finishing touch for the agenda buffer, called just before displaying it."
3301 (unless org-agenda-multi
3302 (save-excursion
3303 (let ((inhibit-read-only t))
3304 (goto-char (point-min))
3305 (while (org-activate-bracket-links (point-max))
3306 (add-text-properties (match-beginning 0) (match-end 0)
3307 '(face org-link)))
3308 (org-agenda-align-tags)
3309 (unless org-agenda-with-colors
3310 (remove-text-properties (point-min) (point-max) '(face nil))))
3311 (if (and (boundp 'org-agenda-overriding-columns-format)
3312 org-agenda-overriding-columns-format)
3313 (org-set-local 'org-agenda-overriding-columns-format
3314 org-agenda-overriding-columns-format))
3315 (if (and (boundp 'org-agenda-view-columns-initially)
3316 org-agenda-view-columns-initially)
3317 (org-agenda-columns))
3318 (when org-agenda-fontify-priorities
3319 (org-agenda-fontify-priorities))
3320 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3321 (org-agenda-dim-blocked-tasks))
3322 (org-agenda-mark-clocking-task)
3323 (when org-agenda-entry-text-mode
3324 (org-agenda-entry-text-hide)
3325 (org-agenda-entry-text-show))
3326 (if (functionp 'org-habit-insert-consistency-graphs)
3327 (org-habit-insert-consistency-graphs))
3328 (run-hooks 'org-finalize-agenda-hook)
3329 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3330 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3331 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3332 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3333 (org-agenda-filter-apply org-agenda-category-filter 'category))
3334 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3337 (defun org-agenda-mark-clocking-task ()
3338 "Mark the current clock entry in the agenda if it is present."
3339 (mapc (lambda (o)
3340 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3341 (delete-overlay o)))
3342 (overlays-in (point-min) (point-max)))
3343 (when (marker-buffer org-clock-hd-marker)
3344 (save-excursion
3345 (goto-char (point-min))
3346 (let (s ov)
3347 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3348 (goto-char s)
3349 (when (equal (org-get-at-bol 'org-hd-marker)
3350 org-clock-hd-marker)
3351 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3352 (overlay-put ov 'type 'org-agenda-clocking)
3353 (overlay-put ov 'face 'org-agenda-clocking)
3354 (overlay-put ov 'help-echo
3355 "The clock is running in this item")))))))
3357 (defun org-agenda-fontify-priorities ()
3358 "Make highest priority lines bold, and lowest italic."
3359 (interactive)
3360 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3361 (delete-overlay o)))
3362 (overlays-in (point-min) (point-max)))
3363 (save-excursion
3364 (let ((inhibit-read-only t)
3365 b e p ov h l)
3366 (goto-char (point-min))
3367 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3368 (setq h (or (get-char-property (point) 'org-highest-priority)
3369 org-highest-priority)
3370 l (or (get-char-property (point) 'org-lowest-priority)
3371 org-lowest-priority)
3372 p (string-to-char (match-string 1))
3373 b (match-beginning 0)
3374 e (if (eq org-agenda-fontify-priorities 'cookies)
3375 (match-end 0)
3376 (point-at-eol))
3377 ov (make-overlay b e))
3378 (overlay-put
3379 ov 'face
3380 (cond ((org-face-from-face-or-color
3381 'priority nil
3382 (cdr (assoc p org-priority-faces))))
3383 ((and (listp org-agenda-fontify-priorities)
3384 (org-face-from-face-or-color
3385 'priority nil
3386 (cdr (assoc p org-agenda-fontify-priorities)))))
3387 ((equal p l) 'italic)
3388 ((equal p h) 'bold)))
3389 (overlay-put ov 'org-type 'org-priority)))))
3391 (defun org-agenda-dim-blocked-tasks ()
3392 "Dim currently blocked TODO's in the agenda display."
3393 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3394 (delete-overlay o)))
3395 (overlays-in (point-min) (point-max)))
3396 (save-excursion
3397 (let ((inhibit-read-only t)
3398 (org-depend-tag-blocked nil)
3399 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3400 org-blocked-by-checkboxes
3401 invis1 b e p ov h l)
3402 (goto-char (point-min))
3403 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3404 (and pos (goto-char (1+ pos))))
3405 (setq org-blocked-by-checkboxes nil invis1 invis)
3406 (let ((marker (org-get-at-bol 'org-hd-marker)))
3407 (when (and marker
3408 (with-current-buffer (marker-buffer marker)
3409 (save-excursion (goto-char marker)
3410 (org-entry-blocked-p))))
3411 (if org-blocked-by-checkboxes (setq invis1 nil))
3412 (setq b (if invis1
3413 (max (point-min) (1- (point-at-bol)))
3414 (point-at-bol))
3415 e (point-at-eol)
3416 ov (make-overlay b e))
3417 (if invis1
3418 (overlay-put ov 'invisible t)
3419 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3420 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3422 (defvar org-agenda-skip-function nil
3423 "Function to be called at each match during agenda construction.
3424 If this function returns nil, the current match should not be skipped.
3425 Otherwise, the function must return a position from where the search
3426 should be continued.
3427 This may also be a Lisp form, it will be evaluated.
3428 Never set this variable using `setq' or so, because then it will apply
3429 to all future agenda commands. If you do want a global skipping condition,
3430 use the option `org-agenda-skip-function-global' instead.
3431 The correct usage for `org-agenda-skip-function' is to bind it with
3432 `let' to scope it dynamically into the agenda-constructing command.
3433 A good way to set it is through options in `org-agenda-custom-commands'.")
3435 (defun org-agenda-skip ()
3436 "Throw to `:skip' in places that should be skipped.
3437 Also moves point to the end of the skipped region, so that search can
3438 continue from there."
3439 (let ((p (point-at-bol)) to)
3440 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3441 (get-text-property p :org-archived)
3442 (org-end-of-subtree t)
3443 (throw :skip t))
3444 (and org-agenda-skip-comment-trees
3445 (get-text-property p :org-comment)
3446 (org-end-of-subtree t)
3447 (throw :skip t))
3448 (if (equal (char-after p) ?#) (throw :skip t))
3449 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3450 (org-agenda-skip-eval org-agenda-skip-function)))
3451 (goto-char to)
3452 (throw :skip t))))
3454 (defun org-agenda-skip-eval (form)
3455 "If FORM is a function or a list, call (or eval) is and return result.
3456 `save-excursion' and `save-match-data' are wrapped around the call, so point
3457 and match data are returned to the previous state no matter what these
3458 functions do."
3459 (let (fp)
3460 (and form
3461 (or (setq fp (functionp form))
3462 (consp form))
3463 (save-excursion
3464 (save-match-data
3465 (if fp
3466 (funcall form)
3467 (eval form)))))))
3469 (defvar org-agenda-markers nil
3470 "List of all currently active markers created by `org-agenda'.")
3471 (defvar org-agenda-last-marker-time (org-float-time)
3472 "Creation time of the last agenda marker.")
3474 (defun org-agenda-new-marker (&optional pos)
3475 "Return a new agenda marker.
3476 Org-mode keeps a list of these markers and resets them when they are
3477 no longer in use."
3478 (let ((m (copy-marker (or pos (point)))))
3479 (setq org-agenda-last-marker-time (org-float-time))
3480 (if org-agenda-buffer
3481 (with-current-buffer org-agenda-buffer
3482 (push m org-agenda-markers))
3483 (push m org-agenda-markers))
3486 (defun org-agenda-reset-markers ()
3487 "Reset markers created by `org-agenda'."
3488 (while org-agenda-markers
3489 (move-marker (pop org-agenda-markers) nil)))
3491 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3492 "Save relative positions of markers in region.
3493 This check for agenda markers in all agenda buffers currently active."
3494 (dolist (buf (buffer-list))
3495 (with-current-buffer buf
3496 (when (eq major-mode 'org-agenda-mode)
3497 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3498 org-agenda-markers)))))
3500 ;;; Entry text mode
3502 (defun org-agenda-entry-text-show-here ()
3503 "Add some text from the entry as context to the current line."
3504 (let (m txt o)
3505 (setq m (org-get-at-bol 'org-hd-marker))
3506 (unless (marker-buffer m)
3507 (error "No marker points to an entry here"))
3508 (setq txt (concat "\n" (org-no-properties
3509 (org-agenda-get-some-entry-text
3510 m org-agenda-entry-text-maxlines " > "))))
3511 (when (string-match "\\S-" txt)
3512 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3513 (overlay-put o 'evaporate t)
3514 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3515 (overlay-put o 'after-string txt))))
3517 (defun org-agenda-entry-text-show ()
3518 "Add entry context for all agenda lines."
3519 (interactive)
3520 (save-excursion
3521 (goto-char (point-max))
3522 (beginning-of-line 1)
3523 (while (not (bobp))
3524 (when (org-get-at-bol 'org-hd-marker)
3525 (org-agenda-entry-text-show-here))
3526 (beginning-of-line 0))))
3528 (defun org-agenda-entry-text-hide ()
3529 "Remove any shown entry context."
3530 (delq nil
3531 (mapcar (lambda (o)
3532 (if (eq (overlay-get o 'org-overlay-type)
3533 'agenda-entry-content)
3534 (progn (delete-overlay o) t)))
3535 (overlays-in (point-min) (point-max)))))
3537 (defun org-agenda-get-day-face (date)
3538 "Return the face DATE should be displayed with."
3539 (or (and (functionp org-agenda-day-face-function)
3540 (funcall org-agenda-day-face-function date))
3541 (cond ((org-agenda-todayp date)
3542 'org-agenda-date-today)
3543 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3544 'org-agenda-date-weekend)
3545 (t 'org-agenda-date))))
3547 ;;; Agenda timeline
3549 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3551 (defun org-timeline (&optional dotodo)
3552 "Show a time-sorted view of the entries in the current org file.
3553 Only entries with a time stamp of today or later will be listed. With
3554 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3555 under the current date.
3556 If the buffer contains an active region, only check the region for
3557 dates."
3558 (interactive "P")
3559 (let* ((dopast t)
3560 (org-agenda-show-log-scoped org-agenda-show-log)
3561 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3562 (current-buffer))))
3563 (date (calendar-current-date))
3564 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3565 (end (if (org-region-active-p) (region-end) (point-max)))
3566 (day-numbers (org-get-all-dates
3567 beg end 'no-ranges
3568 t org-agenda-show-log-scoped ; always include today
3569 org-timeline-show-empty-dates))
3570 (org-deadline-warning-days 0)
3571 (org-agenda-only-exact-dates t)
3572 (today (org-today))
3573 (past t)
3574 args
3575 s e rtn d emptyp)
3576 (setq org-agenda-redo-command
3577 (list 'progn
3578 (list 'org-switch-to-buffer-other-window (current-buffer))
3579 (list 'org-timeline (list 'quote dotodo))))
3580 (if (not dopast)
3581 ;; Remove past dates from the list of dates.
3582 (setq day-numbers (delq nil (mapcar (lambda(x)
3583 (if (>= x today) x nil))
3584 day-numbers))))
3585 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3586 (org-compile-prefix-format 'timeline)
3587 (org-set-sorting-strategy 'timeline)
3588 (if org-agenda-show-log-scoped (push :closed args))
3589 (push :timestamp args)
3590 (push :deadline args)
3591 (push :scheduled args)
3592 (push :sexp args)
3593 (if dotodo (push :todo args))
3594 (insert "Timeline of file " entry "\n")
3595 (add-text-properties (point-min) (point)
3596 (list 'face 'org-agenda-structure))
3597 (org-agenda-mark-header-line (point-min))
3598 (while (setq d (pop day-numbers))
3599 (if (and (listp d) (eq (car d) :omitted))
3600 (progn
3601 (setq s (point))
3602 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3603 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3604 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3605 (if (and (>= d today)
3606 dopast
3607 past)
3608 (progn
3609 (setq past nil)
3610 (insert (make-string 79 ?-) "\n")))
3611 (setq date (calendar-gregorian-from-absolute d))
3612 (setq s (point))
3613 (setq rtn (and (not emptyp)
3614 (apply 'org-agenda-get-day-entries entry
3615 date args)))
3616 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3617 (progn
3618 (insert
3619 (if (stringp org-agenda-format-date)
3620 (format-time-string org-agenda-format-date
3621 (org-time-from-absolute date))
3622 (funcall org-agenda-format-date date))
3623 "\n")
3624 (put-text-property s (1- (point)) 'face
3625 (org-agenda-get-day-face date))
3626 (put-text-property s (1- (point)) 'org-date-line t)
3627 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3628 (if (equal d today)
3629 (put-text-property s (1- (point)) 'org-today t))
3630 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3631 (put-text-property s (1- (point)) 'day d)))))
3632 (goto-char (point-min))
3633 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3634 (point-min)))
3635 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3636 (org-finalize-agenda)
3637 (setq buffer-read-only t)))
3639 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3640 "Return a list of all relevant day numbers from BEG to END buffer positions.
3641 If NO-RANGES is non-nil, include only the start and end dates of a range,
3642 not every single day in the range. If FORCE-TODAY is non-nil, make
3643 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3644 inactive time stamps (those in square brackets) are included.
3645 When EMPTY is non-nil, also include days without any entries."
3646 (let ((re (concat
3647 (if pre-re pre-re "")
3648 (if inactive org-ts-regexp-both org-ts-regexp)))
3649 dates dates1 date day day1 day2 ts1 ts2 pos)
3650 (if force-today
3651 (setq dates (list (org-today))))
3652 (save-excursion
3653 (goto-char beg)
3654 (while (re-search-forward re end t)
3655 (setq day (time-to-days (org-time-string-to-time
3656 (substring (match-string 1) 0 10)
3657 (current-buffer) (match-beginning 0))))
3658 (or (memq day dates) (push day dates)))
3659 (unless no-ranges
3660 (goto-char beg)
3661 (while (re-search-forward org-tr-regexp end t)
3662 (setq pos (match-beginning 0))
3663 (setq ts1 (substring (match-string 1) 0 10)
3664 ts2 (substring (match-string 2) 0 10)
3665 day1 (time-to-days (org-time-string-to-time
3666 ts1 (current-buffer) pos))
3667 day2 (time-to-days (org-time-string-to-time
3668 ts2 (current-buffer) pos)))
3669 (while (< (setq day1 (1+ day1)) day2)
3670 (or (memq day1 dates) (push day1 dates)))))
3671 (setq dates (sort dates '<))
3672 (when empty
3673 (while (setq day (pop dates))
3674 (setq day2 (car dates))
3675 (push day dates1)
3676 (when (and day2 empty)
3677 (if (or (eq empty t)
3678 (and (numberp empty) (<= (- day2 day) empty)))
3679 (while (< (setq day (1+ day)) day2)
3680 (push (list day) dates1))
3681 (push (cons :omitted (- day2 day)) dates1))))
3682 (setq dates (nreverse dates1)))
3683 dates)))
3685 ;;; Agenda Daily/Weekly
3687 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3688 "Start day for the agenda view.
3689 Custom commands can set this variable in the options section.")
3690 (defvar org-starting-day nil) ; local variable in the agenda buffer
3691 (defvar org-agenda-current-span nil
3692 "The current span used in the agenda view.") ; local variable in the agenda buffer
3693 (defvar org-arg-loc nil) ; local variable
3695 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3696 "List of types searched for when creating the daily/weekly agenda.
3697 This variable is a list of symbols that controls the types of
3698 items that appear in the daily/weekly agenda. Allowed symbols in this
3699 list are are
3701 :timestamp List items containing a date stamp or date range matching
3702 the selected date. This includes sexp entries in
3703 angular brackets.
3705 :sexp List entries resulting from plain diary-like sexps.
3707 :deadline List deadline due on that date. When the date is today,
3708 also list any deadlines past due, or due within
3709 `org-deadline-warning-days'. `:deadline' must appear before
3710 `:scheduled' if the setting of
3711 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3712 any effect.
3714 :scheduled List all items which are scheduled for the given date.
3715 The diary for *today* also contains items which were
3716 scheduled earlier and are not yet marked DONE.
3718 By default, all four types are turned on.
3720 Never set this variable globally using `setq', because then it
3721 will apply to all future agenda commands. Instead, bind it with
3722 `let' to scope it dynamically into the agenda-constructing
3723 command. A good way to set it is through options in
3724 `org-agenda-custom-commands'. For a more flexible (though
3725 somewhat less efficient) way of determining what is included in
3726 the daily/weekly agenda, see `org-agenda-skip-function'.")
3728 ;;;###autoload
3729 (defun org-agenda-list (&optional arg start-day span)
3730 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3731 The view will be for the current day or week, but from the overview buffer
3732 you will be able to go to other days/weeks.
3734 With a numeric prefix argument in an interactive call, the agenda will
3735 span ARG days. Lisp programs should instead specify SPAN to change
3736 the number of days. SPAN defaults to `org-agenda-span'.
3738 START-DAY defaults to TODAY, or to the most recent match for the weekday
3739 given in `org-agenda-start-on-weekday'."
3740 (interactive "P")
3741 (if (and (integerp arg) (> arg 0))
3742 (setq span arg arg nil))
3743 (org-prepare-agenda "Day/Week")
3744 (setq start-day (or start-day org-agenda-start-day))
3745 (if org-agenda-overriding-arguments
3746 (setq arg (car org-agenda-overriding-arguments)
3747 start-day (nth 1 org-agenda-overriding-arguments)
3748 span (nth 2 org-agenda-overriding-arguments)))
3749 (if (stringp start-day)
3750 ;; Convert to an absolute day number
3751 (setq start-day (time-to-days (org-read-date nil t start-day))))
3752 (setq org-agenda-last-arguments (list arg start-day span))
3753 (org-compile-prefix-format 'agenda)
3754 (org-set-sorting-strategy 'agenda)
3755 (let* ((span (org-agenda-ndays-to-span
3756 (or span org-agenda-ndays org-agenda-span)))
3757 (today (org-today))
3758 (sd (or start-day today))
3759 (ndays (org-agenda-span-to-ndays span sd))
3760 (org-agenda-start-on-weekday
3761 (if (eq ndays 7)
3762 org-agenda-start-on-weekday))
3763 (thefiles (org-agenda-files nil 'ifmode))
3764 (files thefiles)
3765 (start (if (or (null org-agenda-start-on-weekday)
3766 (< ndays 7))
3768 (let* ((nt (calendar-day-of-week
3769 (calendar-gregorian-from-absolute sd)))
3770 (n1 org-agenda-start-on-weekday)
3771 (d (- nt n1)))
3772 (- sd (+ (if (< d 0) 7 0) d)))))
3773 (day-numbers (list start))
3774 (day-cnt 0)
3775 (inhibit-redisplay (not debug-on-error))
3776 (org-agenda-show-log-scoped org-agenda-show-log)
3777 s e rtn rtnall file date d start-pos end-pos todayp
3778 clocktable-start clocktable-end filter)
3779 (setq org-agenda-redo-command
3780 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3781 (dotimes (n (1- ndays))
3782 (push (1+ (car day-numbers)) day-numbers))
3783 (setq day-numbers (nreverse day-numbers))
3784 (setq clocktable-start (car day-numbers)
3785 clocktable-end (1+ (or (org-last day-numbers) 0)))
3786 (org-set-local 'org-starting-day (car day-numbers))
3787 (org-set-local 'org-arg-loc arg)
3788 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3789 (unless org-agenda-compact-blocks
3790 (let* ((d1 (car day-numbers))
3791 (d2 (org-last day-numbers))
3792 (w1 (org-days-to-iso-week d1))
3793 (w2 (org-days-to-iso-week d2)))
3794 (setq s (point))
3795 (if org-agenda-overriding-header
3796 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3797 nil 'face 'org-agenda-structure) "\n")
3798 (insert (org-agenda-span-name span)
3799 "-agenda"
3800 (if (< (- d2 d1) 350)
3801 (if (= w1 w2)
3802 (format " (W%02d)" w1)
3803 (format " (W%02d-W%02d)" w1 w2))
3805 ":\n")))
3806 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3807 'org-date-line t))
3808 (org-agenda-mark-header-line s))
3809 (while (setq d (pop day-numbers))
3810 (setq date (calendar-gregorian-from-absolute d)
3811 s (point))
3812 (if (or (setq todayp (= d today))
3813 (and (not start-pos) (= d sd)))
3814 (setq start-pos (point))
3815 (if (and start-pos (not end-pos))
3816 (setq end-pos (point))))
3817 (setq files thefiles
3818 rtnall nil)
3819 (while (setq file (pop files))
3820 (catch 'nextfile
3821 (org-check-agenda-file file)
3822 (let ((org-agenda-entry-types org-agenda-entry-types))
3823 (unless org-agenda-include-deadlines
3824 (setq org-agenda-entry-types
3825 (delq :deadline org-agenda-entry-types)))
3826 (cond
3827 ((memq org-agenda-show-log-scoped '(only clockcheck))
3828 (setq rtn (org-agenda-get-day-entries
3829 file date :closed)))
3830 (org-agenda-show-log-scoped
3831 (setq rtn (apply 'org-agenda-get-day-entries
3832 file date
3833 (append '(:closed) org-agenda-entry-types))))
3835 (setq rtn (apply 'org-agenda-get-day-entries
3836 file date
3837 org-agenda-entry-types)))))
3838 (setq rtnall (append rtnall rtn)))) ;; all entries
3839 (if org-agenda-include-diary
3840 (let ((org-agenda-search-headline-for-time t))
3841 (require 'diary-lib)
3842 (setq rtn (org-get-entries-from-diary date))
3843 (setq rtnall (append rtnall rtn))))
3844 (if (or rtnall org-agenda-show-all-dates)
3845 (progn
3846 (setq day-cnt (1+ day-cnt))
3847 (insert
3848 (if (stringp org-agenda-format-date)
3849 (format-time-string org-agenda-format-date
3850 (org-time-from-absolute date))
3851 (funcall org-agenda-format-date date))
3852 "\n")
3853 (put-text-property s (1- (point)) 'face
3854 (org-agenda-get-day-face date))
3855 (put-text-property s (1- (point)) 'org-date-line t)
3856 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3857 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3858 (when todayp
3859 (put-text-property s (1- (point)) 'org-today t))
3860 (if rtnall (insert ;; all entries
3861 (org-finalize-agenda-entries
3862 (org-agenda-add-time-grid-maybe
3863 rtnall ndays todayp))
3864 "\n"))
3865 (put-text-property s (1- (point)) 'day d)
3866 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3867 (when (and org-agenda-clockreport-mode clocktable-start)
3868 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3869 ;; the above line is to ensure the restricted range!
3870 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3871 tbl)
3872 (setq p (org-plist-delete p :block))
3873 (setq p (plist-put p :tstart clocktable-start))
3874 (setq p (plist-put p :tend clocktable-end))
3875 (setq p (plist-put p :scope 'agenda))
3876 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3877 (setq filter (or org-agenda-tag-filter-while-redo
3878 (get 'org-agenda-tag-filter :preset-filter))))
3879 (setq p (plist-put p :tags (mapconcat (lambda (x)
3880 (if (string-match "[<>=]" x)
3883 filter ""))))
3884 (setq tbl (apply 'org-get-clocktable p))
3885 (insert tbl)))
3886 (goto-char (point-min))
3887 (or org-agenda-multi (org-fit-agenda-window))
3888 (unless (and (pos-visible-in-window-p (point-min))
3889 (pos-visible-in-window-p (point-max)))
3890 (goto-char (1- (point-max)))
3891 (recenter -1)
3892 (if (not (pos-visible-in-window-p (or start-pos 1)))
3893 (progn
3894 (goto-char (or start-pos 1))
3895 (recenter 1))))
3896 (goto-char (or start-pos 1))
3897 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3898 (if (eq org-agenda-show-log-scoped 'clockcheck)
3899 (org-agenda-show-clocking-issues))
3900 (org-finalize-agenda)
3901 (setq buffer-read-only t)
3902 (message "")))
3904 (defun org-agenda-ndays-to-span (n)
3905 "Return a span symbol for a span of N days, or N if none matches."
3906 (cond ((symbolp n) n)
3907 ((= n 1) 'day)
3908 ((= n 7) 'week)
3909 (t n)))
3911 (defun org-agenda-span-to-ndays (span start-day)
3912 "Return ndays from SPAN starting at START-DAY."
3913 (cond ((numberp span) span)
3914 ((eq span 'day) 1)
3915 ((eq span 'week) 7)
3916 ((eq span 'month)
3917 (let ((date (calendar-gregorian-from-absolute start-day)))
3918 (calendar-last-day-of-month (car date) (caddr date))))
3919 ((eq span 'year)
3920 (let ((date (calendar-gregorian-from-absolute start-day)))
3921 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3923 (defun org-agenda-span-name (span)
3924 "Return a SPAN name."
3925 (if (null span)
3927 (if (symbolp span)
3928 (capitalize (symbol-name span))
3929 (format "%d days" span))))
3931 ;;; Agenda word search
3933 (defvar org-agenda-search-history nil)
3934 (defvar org-todo-only nil)
3936 (defvar org-search-syntax-table nil
3937 "Special syntax table for org-mode search.
3938 In this table, we have single quotes not as word constituents, to
3939 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3941 (defun org-search-syntax-table ()
3942 (unless org-search-syntax-table
3943 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3944 (modify-syntax-entry ?' "." org-search-syntax-table)
3945 (modify-syntax-entry ?` "." org-search-syntax-table))
3946 org-search-syntax-table)
3948 (defvar org-agenda-last-search-view-search-was-boolean nil)
3950 ;;;###autoload
3951 (defun org-search-view (&optional todo-only string edit-at)
3952 "Show all entries that contain a phrase or words or regular expressions.
3954 With optional prefix argument TODO-ONLY, only consider entries that are
3955 TODO entries. The argument STRING can be used to pass a default search
3956 string into this function. If EDIT-AT is non-nil, it means that the
3957 user should get a chance to edit this string, with cursor at position
3958 EDIT-AT.
3960 The search string can be viewed either as a phrase that should be found as
3961 is, or it can be broken into a number of snippets, each of which must match
3962 in a Boolean way to select an entry. The default depends on the variable
3963 `org-agenda-search-view-always-boolean'.
3964 Even if this is turned off (the default) you can always switch to
3965 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
3967 The default is a direct search of the whole phrase, where each space in
3968 the search string can expand to an arbitrary amount of whitespace,
3969 including newlines.
3971 If using a Boolean search, the search string is split on whitespace and
3972 each snippet is searched separately, with logical AND to select an entry.
3973 Words prefixed with a minus must *not* occur in the entry. Words without
3974 a prefix or prefixed with a plus must occur in the entry. Matching is
3975 case-insensitive. Words are enclosed by word delimiters (i.e. they must
3976 match whole words, not parts of a word) if
3977 `org-agenda-search-view-force-full-words' is set (default is nil).
3979 Boolean search snippets enclosed by curly braces are interpreted as
3980 regular expressions that must or (when preceded with \"-\") must not
3981 match in the entry. Snippets enclosed into double quotes will be taken
3982 as a whole, to include whitespace.
3984 - If the search string starts with an asterisk, search only in headlines.
3985 - If (possibly after the leading star) the search string starts with an
3986 exclamation mark, this also means to look at TODO entries only, an effect
3987 that can also be achieved with a prefix argument.
3988 - If (possibly after star and exclamation mark) the search string starts
3989 with a colon, this will mean that the (non-regexp) snippets of the
3990 Boolean search must match as full words.
3992 This command searches the agenda files, and in addition the files listed
3993 in `org-agenda-text-search-extra-files'."
3994 (interactive "P")
3995 (org-prepare-agenda "SEARCH")
3996 (org-compile-prefix-format 'search)
3997 (org-set-sorting-strategy 'search)
3998 (let* ((props (list 'face nil
3999 'done-face 'org-agenda-done
4000 'org-not-done-regexp org-not-done-regexp
4001 'org-todo-regexp org-todo-regexp
4002 'org-complex-heading-regexp org-complex-heading-regexp
4003 'mouse-face 'highlight
4004 'help-echo (format "mouse-2 or RET jump to location")))
4005 (full-words org-agenda-search-view-force-full-words)
4006 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4007 regexp rtn rtnall files file pos
4008 marker category org-category-pos tags c neg re boolean
4009 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4010 (unless (and (not edit-at)
4011 (stringp string)
4012 (string-match "\\S-" string))
4013 (setq string (read-string
4014 (if org-agenda-search-view-always-boolean
4015 "[+-]Word/{Regexp} ...: "
4016 "Phrase, or [+-]Word/{Regexp} ...: ")
4017 (cond
4018 ((integerp edit-at) (cons string edit-at))
4019 (edit-at string))
4020 'org-agenda-search-history)))
4021 (org-set-local 'org-todo-only todo-only)
4022 (setq org-agenda-redo-command
4023 (list 'org-search-view (if todo-only t nil) string
4024 '(if current-prefix-arg 1 nil)))
4025 (setq org-agenda-query-string string)
4027 (if (equal (string-to-char string) ?*)
4028 (setq hdl-only t
4029 words (substring string 1))
4030 (setq words string))
4031 (when (equal (string-to-char words) ?!)
4032 (setq todo-only t
4033 words (substring words 1)))
4034 (when (equal (string-to-char words) ?:)
4035 (setq full-words t
4036 words (substring words 1)))
4037 (if (or org-agenda-search-view-always-boolean
4038 (member (string-to-char words) '(?- ?+ ?\{)))
4039 (setq boolean t))
4040 (setq words (org-split-string words))
4041 (let (www w)
4042 (while (setq w (pop words))
4043 (while (and (string-match "\\\\\\'" w) words)
4044 (setq w (concat (substring w 0 -1) " " (pop words))))
4045 (push w www))
4046 (setq words (nreverse www) www nil)
4047 (while (setq w (pop words))
4048 (when (and (string-match "\\`[-+]?{" w)
4049 (not (string-match "}\\'" w)))
4050 (while (and words (not (string-match "}\\'" (car words))))
4051 (setq w (concat w " " (pop words))))
4052 (setq w (concat w " " (pop words))))
4053 (push w www))
4054 (setq words (nreverse www)))
4055 (setq org-agenda-last-search-view-search-was-boolean boolean)
4056 (when boolean
4057 (let (wds w)
4058 (while (setq w (pop words))
4059 (if (or (equal (substring w 0 1) "\"")
4060 (and (> (length w) 1)
4061 (member (substring w 0 1) '("+" "-"))
4062 (equal (substring w 1 2) "\"")))
4063 (while (and words (not (equal (substring w -1) "\"")))
4064 (setq w (concat w " " (pop words)))))
4065 (and (string-match "\\`\\([-+]?\\)\"" w)
4066 (setq w (replace-match "\\1" nil nil w)))
4067 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4068 (push w wds))
4069 (setq words (nreverse wds))))
4070 (if boolean
4071 (mapc (lambda (w)
4072 (setq c (string-to-char w))
4073 (if (equal c ?-)
4074 (setq neg t w (substring w 1))
4075 (if (equal c ?+)
4076 (setq neg nil w (substring w 1))
4077 (setq neg nil)))
4078 (if (string-match "\\`{.*}\\'" w)
4079 (setq re (substring w 1 -1))
4080 (if full-words
4081 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4082 (setq re (regexp-quote (downcase w)))))
4083 (if neg (push re regexps-) (push re regexps+)))
4084 words)
4085 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4086 regexps+))
4087 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4088 (if (not regexps+)
4089 (setq regexp org-outline-regexp-bol)
4090 (setq regexp (pop regexps+))
4091 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4092 regexp))))
4093 (setq files (org-agenda-files nil 'ifmode))
4094 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4095 (pop org-agenda-text-search-extra-files)
4096 (setq files (org-add-archive-files files)))
4097 (setq files (append files org-agenda-text-search-extra-files)
4098 rtnall nil)
4099 (while (setq file (pop files))
4100 (setq ee nil)
4101 (catch 'nextfile
4102 (org-check-agenda-file file)
4103 (setq buffer (if (file-exists-p file)
4104 (org-get-agenda-file-buffer file)
4105 (error "No such file %s" file)))
4106 (if (not buffer)
4107 ;; If file does not exist, make sure an error message is sent
4108 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4109 file))))
4110 (with-current-buffer buffer
4111 (with-syntax-table (org-search-syntax-table)
4112 (unless (eq major-mode 'org-mode)
4113 (error "Agenda file %s is not in `org-mode'" file))
4114 (let ((case-fold-search t))
4115 (save-excursion
4116 (save-restriction
4117 (if org-agenda-restrict
4118 (narrow-to-region org-agenda-restrict-begin
4119 org-agenda-restrict-end)
4120 (widen))
4121 (goto-char (point-min))
4122 (unless (or (org-at-heading-p)
4123 (outline-next-heading))
4124 (throw 'nextfile t))
4125 (goto-char (max (point-min) (1- (point))))
4126 (while (re-search-forward regexp nil t)
4127 (org-back-to-heading t)
4128 (skip-chars-forward "* ")
4129 (setq beg (point-at-bol)
4130 beg1 (point)
4131 end (progn (outline-next-heading) (point)))
4132 (catch :skip
4133 (goto-char beg)
4134 (org-agenda-skip)
4135 (setq str (buffer-substring-no-properties
4136 (point-at-bol)
4137 (if hdl-only (point-at-eol) end)))
4138 (mapc (lambda (wr) (when (string-match wr str)
4139 (goto-char (1- end))
4140 (throw :skip t)))
4141 regexps-)
4142 (mapc (lambda (wr) (unless (string-match wr str)
4143 (goto-char (1- end))
4144 (throw :skip t)))
4145 (if todo-only
4146 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4147 regexps+)
4148 regexps+))
4149 (goto-char beg)
4150 (setq marker (org-agenda-new-marker (point))
4151 category (org-get-category)
4152 org-category-pos (get-text-property (point) 'org-category-position)
4153 tags (org-get-tags-at (point))
4154 txt (org-agenda-format-item
4156 (buffer-substring-no-properties
4157 beg1 (point-at-eol))
4158 category tags))
4159 (org-add-props txt props
4160 'org-marker marker 'org-hd-marker marker
4161 'org-todo-regexp org-todo-regexp
4162 'org-complex-heading-regexp org-complex-heading-regexp
4163 'priority 1000 'org-category category
4164 'org-category-position org-category-pos
4165 'type "search")
4166 (push txt ee)
4167 (goto-char (1- end))))))))))
4168 (setq rtn (nreverse ee))
4169 (setq rtnall (append rtnall rtn)))
4170 (if org-agenda-overriding-header
4171 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4172 nil 'face 'org-agenda-structure) "\n")
4173 (insert "Search words: ")
4174 (add-text-properties (point-min) (1- (point))
4175 (list 'face 'org-agenda-structure))
4176 (setq pos (point))
4177 (insert string "\n")
4178 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4179 (setq pos (point))
4180 (unless org-agenda-multi
4181 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4182 (add-text-properties pos (1- (point))
4183 (list 'face 'org-agenda-structure))))
4184 (org-agenda-mark-header-line (point-min))
4185 (when rtnall
4186 (insert (org-finalize-agenda-entries rtnall) "\n"))
4187 (goto-char (point-min))
4188 (or org-agenda-multi (org-fit-agenda-window))
4189 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4190 (org-finalize-agenda)
4191 (setq buffer-read-only t)))
4193 ;;; Agenda TODO list
4195 (defvar org-select-this-todo-keyword nil)
4196 (defvar org-last-arg nil)
4198 ;;;###autoload
4199 (defun org-todo-list (arg)
4200 "Show all (not done) TODO entries from all agenda file in a single list.
4201 The prefix arg can be used to select a specific TODO keyword and limit
4202 the list to these. When using \\[universal-argument], you will be prompted
4203 for a keyword. A numeric prefix directly selects the Nth keyword in
4204 `org-todo-keywords-1'."
4205 (interactive "P")
4206 (org-prepare-agenda "TODO")
4207 (org-compile-prefix-format 'todo)
4208 (org-set-sorting-strategy 'todo)
4209 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4210 (let* ((today (org-today))
4211 (date (calendar-gregorian-from-absolute today))
4212 (kwds org-todo-keywords-for-agenda)
4213 (completion-ignore-case t)
4214 (org-select-this-todo-keyword
4215 (if (stringp arg) arg
4216 (and arg (integerp arg) (> arg 0)
4217 (nth (1- arg) kwds))))
4218 rtn rtnall files file pos)
4219 (when (equal arg '(4))
4220 (setq org-select-this-todo-keyword
4221 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4222 (mapcar 'list kwds) nil nil)))
4223 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4224 (org-set-local 'org-last-arg arg)
4225 (setq org-agenda-redo-command
4226 '(org-todo-list (or current-prefix-arg org-last-arg)))
4227 (setq files (org-agenda-files nil 'ifmode)
4228 rtnall nil)
4229 (while (setq file (pop files))
4230 (catch 'nextfile
4231 (org-check-agenda-file file)
4232 (setq rtn (org-agenda-get-day-entries file date :todo))
4233 (setq rtnall (append rtnall rtn))))
4234 (if org-agenda-overriding-header
4235 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4236 nil 'face 'org-agenda-structure) "\n")
4237 (insert "Global list of TODO items of type: ")
4238 (add-text-properties (point-min) (1- (point))
4239 (list 'face 'org-agenda-structure
4240 'short-heading
4241 (concat "ToDo: "
4242 (or org-select-this-todo-keyword "ALL"))))
4243 (org-agenda-mark-header-line (point-min))
4244 (setq pos (point))
4245 (insert (or org-select-this-todo-keyword "ALL") "\n")
4246 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4247 (setq pos (point))
4248 (unless org-agenda-multi
4249 (insert "Available with `N r': (0)ALL")
4250 (let ((n 0) s)
4251 (mapc (lambda (x)
4252 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4253 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4254 (insert "\n "))
4255 (insert " " s))
4256 kwds))
4257 (insert "\n"))
4258 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4259 (org-agenda-mark-header-line (point-min))
4260 (when rtnall
4261 (insert (org-finalize-agenda-entries rtnall) "\n"))
4262 (goto-char (point-min))
4263 (or org-agenda-multi (org-fit-agenda-window))
4264 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4265 (org-finalize-agenda)
4266 (setq buffer-read-only t)))
4268 ;;; Agenda tags match
4270 ;;;###autoload
4271 (defun org-tags-view (&optional todo-only match)
4272 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4273 The prefix arg TODO-ONLY limits the search to TODO entries."
4274 (interactive "P")
4275 (let* ((org-tags-match-list-sublevels
4276 org-tags-match-list-sublevels)
4277 (completion-ignore-case t)
4278 rtn rtnall files file pos matcher
4279 buffer)
4280 (when (and (stringp match) (not (string-match "\\S-" match)))
4281 (setq match nil))
4282 (setq matcher (org-make-tags-matcher match)
4283 match (car matcher) matcher (cdr matcher))
4284 (org-prepare-agenda (concat "TAGS " match))
4285 (org-compile-prefix-format 'tags)
4286 (org-set-sorting-strategy 'tags)
4287 (setq org-agenda-query-string match)
4288 (setq org-agenda-redo-command
4289 (list 'org-tags-view (list 'quote todo-only)
4290 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4291 (setq files (org-agenda-files nil 'ifmode)
4292 rtnall nil)
4293 (while (setq file (pop files))
4294 (catch 'nextfile
4295 (org-check-agenda-file file)
4296 (setq buffer (if (file-exists-p file)
4297 (org-get-agenda-file-buffer file)
4298 (error "No such file %s" file)))
4299 (if (not buffer)
4300 ;; If file does not exist, error message to agenda
4301 (setq rtn (list
4302 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4303 rtnall (append rtnall rtn))
4304 (with-current-buffer buffer
4305 (unless (eq major-mode 'org-mode)
4306 (error "Agenda file %s is not in `org-mode'" file))
4307 (save-excursion
4308 (save-restriction
4309 (if org-agenda-restrict
4310 (narrow-to-region org-agenda-restrict-begin
4311 org-agenda-restrict-end)
4312 (widen))
4313 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4314 (setq rtnall (append rtnall rtn))))))))
4315 (if org-agenda-overriding-header
4316 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4317 nil 'face 'org-agenda-structure) "\n")
4318 (insert "Headlines with TAGS match: ")
4319 (add-text-properties (point-min) (1- (point))
4320 (list 'face 'org-agenda-structure
4321 'short-heading
4322 (concat "Match: " match)))
4323 (setq pos (point))
4324 (insert match "\n")
4325 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4326 (setq pos (point))
4327 (unless org-agenda-multi
4328 (insert "Press `C-u r' to search again with new search string\n"))
4329 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4330 (org-agenda-mark-header-line (point-min))
4331 (when rtnall
4332 (insert (org-finalize-agenda-entries rtnall) "\n"))
4333 (goto-char (point-min))
4334 (or org-agenda-multi (org-fit-agenda-window))
4335 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4336 (org-finalize-agenda)
4337 (setq buffer-read-only t)))
4339 ;;; Agenda Finding stuck projects
4341 (defvar org-agenda-skip-regexp nil
4342 "Regular expression used in skipping subtrees for the agenda.
4343 This is basically a temporary global variable that can be set and then
4344 used by user-defined selections using `org-agenda-skip-function'.")
4346 (defvar org-agenda-overriding-header nil
4347 "When set during agenda, todo and tags searches it replaces the header.
4348 This variable should not be set directly, but custom commands can bind it
4349 in the options section.")
4351 (defun org-agenda-skip-entry-when-regexp-matches ()
4352 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4353 If yes, it returns the end position of this entry, causing agenda commands
4354 to skip the entry but continuing the search in the subtree. This is a
4355 function that can be put into `org-agenda-skip-function' for the duration
4356 of a command."
4357 (let ((end (save-excursion (org-end-of-subtree t)))
4358 skip)
4359 (save-excursion
4360 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4361 (and skip end)))
4363 (defun org-agenda-skip-subtree-when-regexp-matches ()
4364 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4365 If yes, it returns the end position of this tree, causing agenda commands
4366 to skip this subtree. This is a function that can be put into
4367 `org-agenda-skip-function' for the duration of a command."
4368 (let ((end (save-excursion (org-end-of-subtree t)))
4369 skip)
4370 (save-excursion
4371 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4372 (and skip end)))
4374 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4375 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4376 If yes, it returns the end position of the current entry (NOT the tree),
4377 causing agenda commands to skip the entry but continuing the search in
4378 the subtree. This is a function that can be put into
4379 `org-agenda-skip-function' for the duration of a command. An important
4380 use of this function is for the stuck project list."
4381 (let ((end (save-excursion (org-end-of-subtree t)))
4382 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4383 skip)
4384 (save-excursion
4385 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4386 (and skip entry-end)))
4388 (defun org-agenda-skip-entry-if (&rest conditions)
4389 "Skip entry if any of CONDITIONS is true.
4390 See `org-agenda-skip-if' for details."
4391 (org-agenda-skip-if nil conditions))
4393 (defun org-agenda-skip-subtree-if (&rest conditions)
4394 "Skip entry if any of CONDITIONS is true.
4395 See `org-agenda-skip-if' for details."
4396 (org-agenda-skip-if t conditions))
4398 (defun org-agenda-skip-if (subtree conditions)
4399 "Checks current entity for CONDITIONS.
4400 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4401 the entry (i.e. the text before the next heading) is checked.
4403 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4404 from different tests. Valid conditions are:
4406 scheduled Check if there is a scheduled cookie
4407 notscheduled Check if there is no scheduled cookie
4408 deadline Check if there is a deadline
4409 notdeadline Check if there is no deadline
4410 timestamp Check if there is a timestamp (also deadline or scheduled)
4411 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4412 regexp Check if regexp matches
4413 notregexp Check if regexp does not match.
4414 todo Check if TODO keyword matches
4415 nottodo Check if TODO keyword does not match
4417 The regexp is taken from the conditions list, it must come right after
4418 the `regexp' or `notregexp' element.
4420 `todo' and `nottodo' accept as an argument a list of todo
4421 keywords, which may include \"*\" to match any todo keyword.
4423 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4425 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4427 Instead of a list, a keyword class may be given. For example:
4429 (org-agenda-skip-entry-if 'nottodo 'done)
4431 would skip entries that haven't been marked with any of \"DONE\"
4432 keywords. Possible classes are: `todo', `done', `any'.
4434 If any of these conditions is met, this function returns the end point of
4435 the entity, causing the search to continue from there. This is a function
4436 that can be put into `org-agenda-skip-function' for the duration of a command."
4437 (let (beg end m)
4438 (org-back-to-heading t)
4439 (setq beg (point)
4440 end (if subtree
4441 (progn (org-end-of-subtree t) (point))
4442 (progn (outline-next-heading) (1- (point)))))
4443 (goto-char beg)
4444 (and
4446 (and (memq 'scheduled conditions)
4447 (re-search-forward org-scheduled-time-regexp end t))
4448 (and (memq 'notscheduled conditions)
4449 (not (re-search-forward org-scheduled-time-regexp end t)))
4450 (and (memq 'deadline conditions)
4451 (re-search-forward org-deadline-time-regexp end t))
4452 (and (memq 'notdeadline conditions)
4453 (not (re-search-forward org-deadline-time-regexp end t)))
4454 (and (memq 'timestamp conditions)
4455 (re-search-forward org-ts-regexp end t))
4456 (and (memq 'nottimestamp conditions)
4457 (not (re-search-forward org-ts-regexp end t)))
4458 (and (setq m (memq 'regexp conditions))
4459 (stringp (nth 1 m))
4460 (re-search-forward (nth 1 m) end t))
4461 (and (setq m (memq 'notregexp conditions))
4462 (stringp (nth 1 m))
4463 (not (re-search-forward (nth 1 m) end t)))
4464 (and (or
4465 (setq m (memq 'nottodo conditions))
4466 (setq m (memq 'todo-unblocked conditions))
4467 (setq m (memq 'nottodo-unblocked conditions))
4468 (setq m (memq 'todo conditions)))
4469 (org-agenda-skip-if-todo m end)))
4470 end)))
4472 (defun org-agenda-skip-if-todo (args end)
4473 "Helper function for `org-agenda-skip-if', do not use it directly.
4474 ARGS is a list with first element either `todo', `nottodo',
4475 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4476 a list of TODO keywords, or a state symbol `todo' or `done' or
4477 `any'."
4478 (let ((kw (car args))
4479 (arg (cadr args))
4480 todo-wds todo-re)
4481 (setq todo-wds
4482 (org-uniquify
4483 (cond
4484 ((listp arg) ;; list of keywords
4485 (if (member "*" arg)
4486 (mapcar 'substring-no-properties org-todo-keywords-1)
4487 arg))
4488 ((symbolp arg) ;; keyword class name
4489 (cond
4490 ((eq arg 'todo)
4491 (org-delete-all org-done-keywords
4492 (mapcar 'substring-no-properties
4493 org-todo-keywords-1)))
4494 ((eq arg 'done) org-done-keywords)
4495 ((eq arg 'any)
4496 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4497 (setq todo-re
4498 (concat "^\\*+[ \t]+\\<\\("
4499 (mapconcat 'identity todo-wds "\\|")
4500 "\\)\\>"))
4501 (cond
4502 ((eq kw 'todo) (re-search-forward todo-re end t))
4503 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4504 ((eq kw 'todo-unblocked)
4505 (catch 'unblocked
4506 (while (re-search-forward todo-re end t)
4507 (or (org-entry-blocked-p) (throw 'unblocked t)))
4508 nil))
4509 ((eq kw 'nottodo-unblocked)
4510 (catch 'unblocked
4511 (while (re-search-forward todo-re end t)
4512 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4516 ;;;###autoload
4517 (defun org-agenda-list-stuck-projects (&rest ignore)
4518 "Create agenda view for projects that are stuck.
4519 Stuck projects are project that have no next actions. For the definitions
4520 of what a project is and how to check if it stuck, customize the variable
4521 `org-stuck-projects'."
4522 (interactive)
4523 (let* ((org-agenda-skip-function
4524 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4525 ;; We could have used org-agenda-skip-if here.
4526 (org-agenda-overriding-header
4527 (or org-agenda-overriding-header "List of stuck projects: "))
4528 (matcher (nth 0 org-stuck-projects))
4529 (todo (nth 1 org-stuck-projects))
4530 (todo-wds (if (member "*" todo)
4531 (progn
4532 (org-prepare-agenda-buffers (org-agenda-files
4533 nil 'ifmode))
4534 (org-delete-all
4535 org-done-keywords-for-agenda
4536 (copy-sequence org-todo-keywords-for-agenda)))
4537 todo))
4538 (todo-re (concat "^\\*+[ \t]+\\("
4539 (mapconcat 'identity todo-wds "\\|")
4540 "\\)\\>"))
4541 (tags (nth 2 org-stuck-projects))
4542 (tags-re (if (member "*" tags)
4543 (concat org-outline-regexp-bol
4544 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4545 (if tags
4546 (concat org-outline-regexp-bol
4547 ".*:\\("
4548 (mapconcat 'identity tags "\\|")
4549 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4550 (gen-re (nth 3 org-stuck-projects))
4551 (re-list
4552 (delq nil
4553 (list
4554 (if todo todo-re)
4555 (if tags tags-re)
4556 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4557 gen-re)))))
4558 (setq org-agenda-skip-regexp
4559 (if re-list
4560 (mapconcat 'identity re-list "\\|")
4561 (error "No information how to identify unstuck projects")))
4562 (org-tags-view nil matcher)
4563 (with-current-buffer org-agenda-buffer-name
4564 (setq org-agenda-redo-command
4565 '(org-agenda-list-stuck-projects
4566 (or current-prefix-arg org-last-arg))))))
4568 ;;; Diary integration
4570 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4571 (defvar diary-list-entries-hook)
4572 (defvar diary-time-regexp)
4573 (defun org-get-entries-from-diary (date)
4574 "Get the (Emacs Calendar) diary entries for DATE."
4575 (require 'diary-lib)
4576 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4577 (diary-display-hook '(fancy-diary-display))
4578 (diary-display-function 'fancy-diary-display)
4579 (pop-up-frames nil)
4580 (diary-list-entries-hook
4581 (cons 'org-diary-default-entry diary-list-entries-hook))
4582 (diary-file-name-prefix-function nil) ; turn this feature off
4583 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4584 entries
4585 (org-disable-agenda-to-diary t))
4586 (save-excursion
4587 (save-window-excursion
4588 (funcall (if (fboundp 'diary-list-entries)
4589 'diary-list-entries 'list-diary-entries)
4590 date 1)))
4591 (if (not (get-buffer diary-fancy-buffer))
4592 (setq entries nil)
4593 (with-current-buffer diary-fancy-buffer
4594 (setq buffer-read-only nil)
4595 (if (zerop (buffer-size))
4596 ;; No entries
4597 (setq entries nil)
4598 ;; Omit the date and other unnecessary stuff
4599 (org-agenda-cleanup-fancy-diary)
4600 ;; Add prefix to each line and extend the text properties
4601 (if (zerop (buffer-size))
4602 (setq entries nil)
4603 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4604 (setq entries
4605 (with-temp-buffer
4606 (insert entries) (goto-char (point-min))
4607 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4608 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4609 (replace-match (concat "; " (match-string 1)))))
4610 (buffer-string)))))
4611 (set-buffer-modified-p nil)
4612 (kill-buffer diary-fancy-buffer)))
4613 (when entries
4614 (setq entries (org-split-string entries "\n"))
4615 (setq entries
4616 (mapcar
4617 (lambda (x)
4618 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4619 ;; Extend the text properties to the beginning of the line
4620 (org-add-props x (text-properties-at (1- (length x)) x)
4621 'type "diary" 'date date 'face 'org-agenda-diary))
4622 entries)))))
4624 (defvar org-agenda-cleanup-fancy-diary-hook nil
4625 "Hook run when the fancy diary buffer is cleaned up.")
4627 (defun org-agenda-cleanup-fancy-diary ()
4628 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4629 This gets rid of the date, the underline under the date, and
4630 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4631 date. It also removes lines that contain only whitespace."
4632 (goto-char (point-min))
4633 (if (looking-at ".*?:[ \t]*")
4634 (progn
4635 (replace-match "")
4636 (re-search-forward "\n=+$" nil t)
4637 (replace-match "")
4638 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4639 (re-search-forward "\n=+$" nil t)
4640 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4641 (goto-char (point-min))
4642 (while (re-search-forward "^ +\n" nil t)
4643 (replace-match ""))
4644 (goto-char (point-min))
4645 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4646 (replace-match ""))
4647 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4649 ;; Make sure entries from the diary have the right text properties.
4650 (eval-after-load "diary-lib"
4651 '(if (boundp 'diary-modify-entry-list-string-function)
4652 ;; We can rely on the hook, nothing to do
4654 ;; Hook not available, must use advice to make this work
4655 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4656 "Make the position visible."
4657 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4658 (stringp string)
4659 buffer-file-name)
4660 (setq string (org-modify-diary-entry-string string))))))
4662 (defun org-modify-diary-entry-string (string)
4663 "Add text properties to string, allowing org-mode to act on it."
4664 (org-add-props string nil
4665 'mouse-face 'highlight
4666 'help-echo (if buffer-file-name
4667 (format "mouse-2 or RET jump to diary file %s"
4668 (abbreviate-file-name buffer-file-name))
4670 'org-agenda-diary-link t
4671 'org-marker (org-agenda-new-marker (point-at-bol))))
4673 (defun org-diary-default-entry ()
4674 "Add a dummy entry to the diary.
4675 Needed to avoid empty dates which mess up holiday display."
4676 ;; Catch the error if dealing with the new add-to-diary-alist
4677 (when org-disable-agenda-to-diary
4678 (condition-case nil
4679 (org-add-to-diary-list original-date "Org-mode dummy" "")
4680 (error
4681 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4683 (defun org-add-to-diary-list (&rest args)
4684 (if (fboundp 'diary-add-to-list)
4685 (apply 'diary-add-to-list args)
4686 (apply 'add-to-diary-list args)))
4688 (defvar org-diary-last-run-time nil)
4690 ;;;###autoload
4691 (defun org-diary (&rest args)
4692 "Return diary information from org-files.
4693 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4694 It accesses org files and extracts information from those files to be
4695 listed in the diary. The function accepts arguments specifying what
4696 items should be listed. For a list of arguments allowed here, see the
4697 variable `org-agenda-entry-types'.
4699 The call in the diary file should look like this:
4701 &%%(org-diary) ~/path/to/some/orgfile.org
4703 Use a separate line for each org file to check. Or, if you omit the file name,
4704 all files listed in `org-agenda-files' will be checked automatically:
4706 &%%(org-diary)
4708 If you don't give any arguments (as in the example above), the default
4709 arguments (:deadline :scheduled :timestamp :sexp) are used.
4710 So the example above may also be written as
4712 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4714 The function expects the lisp variables `entry' and `date' to be provided
4715 by the caller, because this is how the calendar works. Don't use this
4716 function from a program - use `org-agenda-get-day-entries' instead."
4717 (when (> (- (org-float-time)
4718 org-agenda-last-marker-time)
4720 ;; I am not sure if this works with sticky agendas, because the marker
4721 ;; list is then no longer a global variable.
4722 (org-agenda-reset-markers))
4723 (org-compile-prefix-format 'agenda)
4724 (org-set-sorting-strategy 'agenda)
4725 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4726 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4727 (list entry)
4728 (org-agenda-files t)))
4729 (time (org-float-time))
4730 file rtn results)
4731 (when (or (not org-diary-last-run-time)
4732 (> (- time
4733 org-diary-last-run-time)
4735 (org-prepare-agenda-buffers files))
4736 (setq org-diary-last-run-time time)
4737 ;; If this is called during org-agenda, don't return any entries to
4738 ;; the calendar. Org Agenda will list these entries itself.
4739 (if org-disable-agenda-to-diary (setq files nil))
4740 (while (setq file (pop files))
4741 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4742 (setq results (append results rtn)))
4743 (if results
4744 (concat (org-finalize-agenda-entries results) "\n"))))
4746 ;;; Agenda entry finders
4748 (defun org-agenda-get-day-entries (file date &rest args)
4749 "Does the work for `org-diary' and `org-agenda'.
4750 FILE is the path to a file to be checked for entries. DATE is date like
4751 the one returned by `calendar-current-date'. ARGS are symbols indicating
4752 which kind of entries should be extracted. For details about these, see
4753 the documentation of `org-diary'."
4754 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4755 (let* ((org-startup-folded nil)
4756 (org-startup-align-all-tables nil)
4757 (buffer (if (file-exists-p file)
4758 (org-get-agenda-file-buffer file)
4759 (error "No such file %s" file)))
4760 arg results rtn deadline-results)
4761 (if (not buffer)
4762 ;; If file does not exist, make sure an error message ends up in diary
4763 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4764 (with-current-buffer buffer
4765 (unless (eq major-mode 'org-mode)
4766 (error "Agenda file %s is not in `org-mode'" file))
4767 (let ((case-fold-search nil))
4768 (save-excursion
4769 (save-restriction
4770 (if org-agenda-restrict
4771 (narrow-to-region org-agenda-restrict-begin
4772 org-agenda-restrict-end)
4773 (widen))
4774 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4775 (while (setq arg (pop args))
4776 (cond
4777 ((and (eq arg :todo)
4778 (equal date (calendar-gregorian-from-absolute
4779 (org-today))))
4780 (setq rtn (org-agenda-get-todos))
4781 (setq results (append results rtn)))
4782 ((eq arg :timestamp)
4783 (setq rtn (org-agenda-get-blocks))
4784 (setq results (append results rtn))
4785 (setq rtn (org-agenda-get-timestamps))
4786 (setq results (append results rtn)))
4787 ((eq arg :sexp)
4788 (setq rtn (org-agenda-get-sexps))
4789 (setq results (append results rtn)))
4790 ((eq arg :scheduled)
4791 (setq rtn (org-agenda-get-scheduled deadline-results))
4792 (setq results (append results rtn)))
4793 ((eq arg :closed)
4794 (setq rtn (org-agenda-get-progress))
4795 (setq results (append results rtn)))
4796 ((eq arg :deadline)
4797 (setq rtn (org-agenda-get-deadlines))
4798 (setq deadline-results (copy-sequence rtn))
4799 (setq results (append results rtn))))))))
4800 results))))
4802 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4803 (defun org-agenda-get-todos ()
4804 "Return the TODO information for agenda display."
4805 (let* ((props (list 'face nil
4806 'done-face 'org-agenda-done
4807 'org-not-done-regexp org-not-done-regexp
4808 'org-todo-regexp org-todo-regexp
4809 'org-complex-heading-regexp org-complex-heading-regexp
4810 'mouse-face 'highlight
4811 'help-echo
4812 (format "mouse-2 or RET jump to org file %s"
4813 (abbreviate-file-name buffer-file-name))))
4814 (regexp (format org-heading-keyword-regexp-format
4815 (cond
4816 ((and org-select-this-todo-keyword
4817 (equal org-select-this-todo-keyword "*"))
4818 org-todo-regexp)
4819 (org-select-this-todo-keyword
4820 (concat "\\("
4821 (mapconcat 'identity
4822 (org-split-string
4823 org-select-this-todo-keyword
4824 "|")
4825 "\\|") "\\)"))
4826 (t org-not-done-regexp))))
4827 marker priority category org-category-pos tags todo-state
4828 ee txt beg end)
4829 (goto-char (point-min))
4830 (while (re-search-forward regexp nil t)
4831 (catch :skip
4832 (save-match-data
4833 (beginning-of-line)
4834 (org-agenda-skip)
4835 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4836 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4837 (goto-char (1+ beg))
4838 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4839 (throw :skip nil)))
4840 (goto-char (match-beginning 2))
4841 (setq marker (org-agenda-new-marker (match-beginning 0))
4842 category (org-get-category)
4843 org-category-pos (get-text-property (point) 'org-category-position)
4844 txt (org-trim
4845 (buffer-substring (match-beginning 2) (match-end 0)))
4846 tags (org-get-tags-at (point))
4847 txt (org-agenda-format-item "" txt category tags)
4848 priority (1+ (org-get-priority txt))
4849 todo-state (org-get-todo-state))
4850 (org-add-props txt props
4851 'org-marker marker 'org-hd-marker marker
4852 'priority priority 'org-category category
4853 'org-category-position org-category-pos
4854 'type "todo" 'todo-state todo-state)
4855 (push txt ee)
4856 (if org-agenda-todo-list-sublevels
4857 (goto-char (match-end 2))
4858 (org-end-of-subtree 'invisible))))
4859 (nreverse ee)))
4861 (defun org-agenda-todo-custom-ignore-p (time n)
4862 "Check whether timestamp is farther away then n number of days.
4863 This function is invoked if `org-agenda-todo-ignore-deadlines',
4864 `org-agenda-todo-ignore-scheduled' or
4865 `org-agenda-todo-ignore-timestamp' is set to an integer."
4866 (let ((days (org-days-to-time time)))
4867 (if (>= n 0)
4868 (>= days n)
4869 (<= days n))))
4871 ;;;###autoload
4872 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4873 (&optional end)
4874 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4875 (when (or org-agenda-todo-ignore-with-date
4876 org-agenda-todo-ignore-scheduled
4877 org-agenda-todo-ignore-deadlines
4878 org-agenda-todo-ignore-timestamp)
4879 (setq end (or end (save-excursion (outline-next-heading) (point))))
4880 (save-excursion
4881 (or (and org-agenda-todo-ignore-with-date
4882 (re-search-forward org-ts-regexp end t))
4883 (and org-agenda-todo-ignore-scheduled
4884 (re-search-forward org-scheduled-time-regexp end t)
4885 (cond
4886 ((eq org-agenda-todo-ignore-scheduled 'future)
4887 (> (org-days-to-time (match-string 1)) 0))
4888 ((eq org-agenda-todo-ignore-scheduled 'past)
4889 (<= (org-days-to-time (match-string 1)) 0))
4890 ((numberp org-agenda-todo-ignore-scheduled)
4891 (org-agenda-todo-custom-ignore-p
4892 (match-string 1) org-agenda-todo-ignore-scheduled))
4893 (t)))
4894 (and org-agenda-todo-ignore-deadlines
4895 (re-search-forward org-deadline-time-regexp end t)
4896 (cond
4897 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4898 ((eq org-agenda-todo-ignore-deadlines 'far)
4899 (not (org-deadline-close (match-string 1))))
4900 ((eq org-agenda-todo-ignore-deadlines 'future)
4901 (> (org-days-to-time (match-string 1)) 0))
4902 ((eq org-agenda-todo-ignore-deadlines 'past)
4903 (<= (org-days-to-time (match-string 1)) 0))
4904 ((numberp org-agenda-todo-ignore-deadlines)
4905 (org-agenda-todo-custom-ignore-p
4906 (match-string 1) org-agenda-todo-ignore-deadlines))
4907 (t (org-deadline-close (match-string 1)))))
4908 (and org-agenda-todo-ignore-timestamp
4909 (let ((buffer (current-buffer))
4910 (regexp
4911 (concat
4912 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4913 (start (point)))
4914 ;; Copy current buffer into a temporary one
4915 (with-temp-buffer
4916 (insert-buffer-substring buffer start end)
4917 (goto-char (point-min))
4918 ;; Delete SCHEDULED and DEADLINE items
4919 (while (re-search-forward regexp end t)
4920 (delete-region (match-beginning 0) (match-end 0)))
4921 (goto-char (point-min))
4922 ;; No search for timestamp left
4923 (when (re-search-forward org-ts-regexp nil t)
4924 (cond
4925 ((eq org-agenda-todo-ignore-timestamp 'future)
4926 (> (org-days-to-time (match-string 1)) 0))
4927 ((eq org-agenda-todo-ignore-timestamp 'past)
4928 (<= (org-days-to-time (match-string 1)) 0))
4929 ((numberp org-agenda-todo-ignore-timestamp)
4930 (org-agenda-todo-custom-ignore-p
4931 (match-string 1) org-agenda-todo-ignore-timestamp))
4932 (t))))))))))
4934 (defconst org-agenda-no-heading-message
4935 "No heading for this item in buffer or region.")
4937 (defun org-agenda-get-timestamps ()
4938 "Return the date stamp information for agenda display."
4939 (let* ((props (list 'face 'org-agenda-calendar-event
4940 'org-not-done-regexp org-not-done-regexp
4941 'org-todo-regexp org-todo-regexp
4942 'org-complex-heading-regexp org-complex-heading-regexp
4943 'mouse-face 'highlight
4944 'help-echo
4945 (format "mouse-2 or RET jump to org file %s"
4946 (abbreviate-file-name buffer-file-name))))
4947 (d1 (calendar-absolute-from-gregorian date))
4948 (remove-re
4949 (concat
4950 (regexp-quote
4951 (format-time-string
4952 "<%Y-%m-%d"
4953 (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
4954 ".*?>"))
4955 (regexp
4956 (concat
4957 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4958 (regexp-quote
4959 (substring
4960 (format-time-string
4961 (car org-time-stamp-formats)
4962 (apply 'encode-time ; DATE bound by calendar
4963 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
4964 1 11))
4965 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
4966 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
4967 marker hdmarker deadlinep scheduledp clockp closedp inactivep
4968 donep tmp priority category org-category-pos ee txt timestr tags
4969 b0 b3 e3 head todo-state end-of-match show-all)
4970 (goto-char (point-min))
4971 (while (setq end-of-match (re-search-forward regexp nil t))
4972 (setq b0 (match-beginning 0)
4973 b3 (match-beginning 3) e3 (match-end 3)
4974 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
4975 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
4976 (member todo-state
4977 org-agenda-repeating-timestamp-show-all)))
4978 (catch :skip
4979 (and (org-at-date-range-p) (throw :skip nil))
4980 (org-agenda-skip)
4981 (if (and (match-end 1)
4982 (not (= d1 (org-time-string-to-absolute
4983 (match-string 1) d1 nil show-all
4984 (current-buffer) b0))))
4985 (throw :skip nil))
4986 (if (and e3
4987 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
4988 (throw :skip nil))
4989 (setq tmp (buffer-substring (max (point-min)
4990 (- b0 org-ds-keyword-length))
4992 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
4993 inactivep (= (char-after b0) ?\[)
4994 deadlinep (string-match org-deadline-regexp tmp)
4995 scheduledp (string-match org-scheduled-regexp tmp)
4996 closedp (and org-agenda-include-inactive-timestamps
4997 (string-match org-closed-string tmp))
4998 clockp (and org-agenda-include-inactive-timestamps
4999 (or (string-match org-clock-string tmp)
5000 (string-match "]-+\\'" tmp)))
5001 donep (member todo-state org-done-keywords))
5002 (if (or scheduledp deadlinep closedp clockp
5003 (and donep org-agenda-skip-timestamp-if-done))
5004 (throw :skip t))
5005 (if (string-match ">" timestr)
5006 ;; substring should only run to end of time stamp
5007 (setq timestr (substring timestr 0 (match-end 0))))
5008 (setq marker (org-agenda-new-marker b0)
5009 category (org-get-category b0)
5010 org-category-pos (get-text-property b0 'org-category-position))
5011 (save-excursion
5012 (if (not (re-search-backward org-outline-regexp-bol nil t))
5013 (setq txt org-agenda-no-heading-message)
5014 (goto-char (match-beginning 0))
5015 (setq hdmarker (org-agenda-new-marker)
5016 tags (org-get-tags-at))
5017 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5018 (setq head (or (match-string 1) ""))
5019 (setq txt (org-agenda-format-item
5020 (if inactivep org-agenda-inactive-leader nil)
5021 head category tags timestr
5022 remove-re)))
5023 (setq priority (org-get-priority txt))
5024 (org-add-props txt props
5025 'org-marker marker 'org-hd-marker hdmarker)
5026 (org-add-props txt nil 'priority priority
5027 'org-category category 'date date
5028 'org-category-position org-category-pos
5029 'todo-state todo-state
5030 'type "timestamp")
5031 (push txt ee))
5032 (if org-agenda-skip-additional-timestamps-same-entry
5033 (outline-next-heading)
5034 (goto-char end-of-match))))
5035 (nreverse ee)))
5037 (defun org-agenda-get-sexps ()
5038 "Return the sexp information for agenda display."
5039 (require 'diary-lib)
5040 (let* ((props (list 'face 'org-agenda-calendar-sexp
5041 'mouse-face 'highlight
5042 'help-echo
5043 (format "mouse-2 or RET jump to org file %s"
5044 (abbreviate-file-name buffer-file-name))))
5045 (regexp "^&?%%(")
5046 marker category org-category-pos ee txt tags entry
5047 result beg b sexp sexp-entry todo-state)
5048 (goto-char (point-min))
5049 (while (re-search-forward regexp nil t)
5050 (catch :skip
5051 (org-agenda-skip)
5052 (setq beg (match-beginning 0))
5053 (goto-char (1- (match-end 0)))
5054 (setq b (point))
5055 (forward-sexp 1)
5056 (setq sexp (buffer-substring b (point)))
5057 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5058 (org-trim (match-string 1))
5059 ""))
5060 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5061 (when result
5062 (setq marker (org-agenda-new-marker beg)
5063 category (org-get-category beg)
5064 org-category-pos (get-text-property beg 'org-category-position)
5065 todo-state (org-get-todo-state))
5067 (dolist (r (if (stringp result)
5068 (list result)
5069 result)) ;; we expect a list here
5070 (if (string-match "\\S-" r)
5071 (setq txt r)
5072 (setq txt "SEXP entry returned empty string"))
5074 (setq txt (org-agenda-format-item
5075 "" txt category tags 'time))
5076 (org-add-props txt props 'org-marker marker)
5077 (org-add-props txt nil
5078 'org-category category 'date date 'todo-state todo-state
5079 'org-category-position org-category-pos
5080 'type "sexp")
5081 (push txt ee)))))
5082 (nreverse ee)))
5084 ;; Calendar sanity: define some functions that are independent of
5085 ;; `calendar-date-style'.
5086 ;; Normally I would like to use ISO format when calling the diary functions,
5087 ;; but to make sure we still have Emacs 22 compatibility we bind
5088 ;; also `european-calendar-style' and use european format
5089 (defun org-anniversary (year month day &optional mark)
5090 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5091 (org-no-warnings
5092 (let ((calendar-date-style 'european) (european-calendar-style t))
5093 (diary-anniversary day month year mark))))
5094 (defun org-cyclic (N year month day &optional mark)
5095 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5096 (org-no-warnings
5097 (let ((calendar-date-style 'european) (european-calendar-style t))
5098 (diary-cyclic N day month year mark))))
5099 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5100 "Like `diary-block', but with fixed (ISO) order of arguments."
5101 (org-no-warnings
5102 (let ((calendar-date-style 'european) (european-calendar-style t))
5103 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5104 (defun org-date (year month day &optional mark)
5105 "Like `diary-date', but with fixed (ISO) order of arguments."
5106 (org-no-warnings
5107 (let ((calendar-date-style 'european) (european-calendar-style t))
5108 (diary-date day month year mark))))
5109 (defalias 'org-float 'diary-float)
5111 ;; Define the` org-class' function
5112 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5113 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5114 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5115 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5116 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5117 `holidays', then any date that is known by the Emacs calendar to be a
5118 holiday will also be skipped."
5119 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5120 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5121 (d (calendar-absolute-from-gregorian date)))
5122 (and
5123 (<= date1 d)
5124 (<= d date2)
5125 (= (calendar-day-of-week date) dayname)
5126 (or (not skip-weeks)
5127 (progn
5128 (require 'cal-iso)
5129 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5130 (not (and (memq 'holidays skip-weeks)
5131 (calendar-check-holidays date)))
5132 entry)))
5134 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5135 "Like `org-class', but honor `calendar-date-style'.
5136 The order of the first 2 times 3 arguments depends on the variable
5137 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5138 So for American calendars, give this as MONTH DAY YEAR, for European as
5139 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5140 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5141 is any number of ISO weeks in the block period for which the item should
5142 be skipped.
5144 This function is here only for backward compatibility and it is deprecated,
5145 please use `org-class' instead."
5146 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5147 (date2 (org-order-calendar-date-args m2 d2 y2)))
5148 (org-class
5149 (nth 2 date1) (car date1) (nth 1 date1)
5150 (nth 2 date2) (car date2) (nth 1 date2)
5151 dayname skip-weeks)))
5152 (make-obsolete 'org-diary-class 'org-class "")
5154 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5155 (defalias 'org-get-closed 'org-agenda-get-progress)
5156 (defun org-agenda-get-progress ()
5157 "Return the logged TODO entries for agenda display."
5158 (let* ((props (list 'mouse-face 'highlight
5159 'org-not-done-regexp org-not-done-regexp
5160 'org-todo-regexp org-todo-regexp
5161 'org-complex-heading-regexp org-complex-heading-regexp
5162 'help-echo
5163 (format "mouse-2 or RET jump to org file %s"
5164 (abbreviate-file-name buffer-file-name))))
5165 (items (if (consp org-agenda-show-log-scoped)
5166 org-agenda-show-log-scoped
5167 (if (eq org-agenda-show-log-scoped 'clockcheck)
5168 '(clock)
5169 org-agenda-log-mode-items)))
5170 (parts
5171 (delq nil
5172 (list
5173 (if (memq 'closed items) (concat "\\<" org-closed-string))
5174 (if (memq 'clock items) (concat "\\<" org-clock-string))
5175 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5176 (parts-re (if parts (mapconcat 'identity parts "\\|")
5177 (error "`org-agenda-log-mode-items' is empty")))
5178 (regexp (concat
5179 "\\(" parts-re "\\)"
5180 " *\\["
5181 (regexp-quote
5182 (substring
5183 (format-time-string
5184 (car org-time-stamp-formats)
5185 (apply 'encode-time ; DATE bound by calendar
5186 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5187 1 11))))
5188 (org-agenda-search-headline-for-time nil)
5189 marker hdmarker priority category org-category-pos tags closedp
5190 statep clockp state ee txt extra timestr rest clocked)
5191 (goto-char (point-min))
5192 (while (re-search-forward regexp nil t)
5193 (catch :skip
5194 (org-agenda-skip)
5195 (setq marker (org-agenda-new-marker (match-beginning 0))
5196 closedp (equal (match-string 1) org-closed-string)
5197 statep (equal (string-to-char (match-string 1)) ?-)
5198 clockp (not (or closedp statep))
5199 state (and statep (match-string 2))
5200 category (org-get-category (match-beginning 0))
5201 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5202 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5203 (when (string-match "\\]" timestr)
5204 ;; substring should only run to end of time stamp
5205 (setq rest (substring timestr (match-end 0))
5206 timestr (substring timestr 0 (match-end 0)))
5207 (if (and (not closedp) (not statep)
5208 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5209 rest))
5210 (progn (setq timestr (concat (substring timestr 0 -1)
5211 "-" (match-string 1 rest) "]"))
5212 (setq clocked (match-string 2 rest)))
5213 (setq clocked "-")))
5214 (save-excursion
5215 (setq extra
5216 (cond
5217 ((not org-agenda-log-mode-add-notes) nil)
5218 (statep
5219 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5220 (match-string 1)))
5221 (clockp
5222 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5223 (match-string 1)))))
5224 (if (not (re-search-backward org-outline-regexp-bol nil t))
5225 (setq txt org-agenda-no-heading-message)
5226 (goto-char (match-beginning 0))
5227 (setq hdmarker (org-agenda-new-marker)
5228 tags (org-get-tags-at))
5229 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5230 (setq txt (match-string 1))
5231 (when extra
5232 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5233 (setq txt (concat (substring txt 0 (match-beginning 1))
5234 " - " extra " " (match-string 2 txt)))
5235 (setq txt (concat txt " - " extra))))
5236 (setq txt (org-agenda-format-item
5237 (cond
5238 (closedp "Closed: ")
5239 (statep (concat "State: (" state ")"))
5240 (t (concat "Clocked: (" clocked ")")))
5241 txt category tags timestr)))
5242 (setq priority 100000)
5243 (org-add-props txt props
5244 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5245 'priority priority 'org-category category
5246 'org-category-position org-category-pos
5247 'type "closed" 'date date
5248 'undone-face 'org-warning 'done-face 'org-agenda-done)
5249 (push txt ee))
5250 (goto-char (point-at-eol))))
5251 (nreverse ee)))
5253 (defun org-agenda-show-clocking-issues ()
5254 "Add overlays, showing issues with clocking.
5255 See also the user option `org-agenda-clock-consistency-checks'."
5256 (interactive)
5257 (let* ((pl org-agenda-clock-consistency-checks)
5258 (re (concat "^[ \t]*"
5259 org-clock-string
5260 "[ \t]+"
5261 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5262 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5263 (tlstart 0.)
5264 (tlend 0.)
5265 (maxtime (org-hh:mm-string-to-minutes
5266 (or (plist-get pl :max-duration) "24:00")))
5267 (mintime (org-hh:mm-string-to-minutes
5268 (or (plist-get pl :min-duration) 0)))
5269 (maxgap (org-hh:mm-string-to-minutes
5270 ;; default 30:00 means never complain
5271 (or (plist-get pl :max-gap) "30:00")))
5272 (gapok (mapcar 'org-hh:mm-string-to-minutes
5273 (plist-get pl :gap-ok-around)))
5274 (def-face (or (plist-get pl :default-face)
5275 '((:background "DarkRed") (:foreground "white"))))
5276 issue face m te ts dt ov)
5277 (goto-char (point-min))
5278 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5279 (setq issue nil face def-face)
5280 (catch 'next
5281 (setq m (org-get-at-bol 'org-marker)
5282 te nil ts nil)
5283 (unless (and m (markerp m))
5284 (setq issue "No valid clock line") (throw 'next t))
5285 (org-with-point-at m
5286 (save-excursion
5287 (goto-char (point-at-bol))
5288 (unless (looking-at re)
5289 (error "No valid Clock line")
5290 (throw 'next t))
5291 (unless (match-end 3)
5292 (setq issue "No end time"
5293 face (or (plist-get pl :no-end-time-face) face))
5294 (throw 'next t))
5295 (setq ts (match-string 1)
5296 te (match-string 3)
5297 ts (org-float-time
5298 (apply 'encode-time (org-parse-time-string ts)))
5299 te (org-float-time
5300 (apply 'encode-time (org-parse-time-string te)))
5301 dt (- te ts))))
5302 (cond
5303 ((> dt (* 60 maxtime))
5304 ;; a very long clocking chunk
5305 (setq issue (format "Clocking interval is very long: %s"
5306 (org-minutes-to-hh:mm-string
5307 (floor (/ (float dt) 60.))))
5308 face (or (plist-get pl :long-face) face)))
5309 ((< dt (* 60 mintime))
5310 ;; a very short clocking chunk
5311 (setq issue (format "Clocking interval is very short: %s"
5312 (org-minutes-to-hh:mm-string
5313 (floor (/ (float dt) 60.))))
5314 face (or (plist-get pl :short-face) face)))
5315 ((and (> tlend 0) (< ts tlend))
5316 ;; Two clock entries are overlapping
5317 (setq issue (format "Clocking overlap: %d minutes"
5318 (/ (- tlend ts) 60))
5319 face (or (plist-get pl :overlap-face) face)))
5320 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5321 ;; There is a gap, lets see if we need to report it
5322 (unless (org-agenda-check-clock-gap tlend ts gapok)
5323 (setq issue (format "Clocking gap: %d minutes"
5324 (/ (- ts tlend) 60))
5325 face (or (plist-get pl :gap-face) face))))
5326 (t nil)))
5327 (setq tlend (or te tlend) tlstart (or ts tlstart))
5328 (when issue
5329 ;; OK, there was some issue, add an overlay to show the issue
5330 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5331 (overlay-put ov 'before-string
5332 (concat
5333 (org-add-props
5334 (format "%-43s" (concat " " issue))
5336 'face face)
5337 "\n"))
5338 (overlay-put ov 'evaporate t)))))
5340 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5341 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5342 (catch 'exit
5343 (unless ok-list
5344 ;; there are no OK times for gaps...
5345 (throw 'exit nil))
5346 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5347 ;; This is more than 24 hours, so it is OK.
5348 ;; because we have at least one OK time, that must be in the
5349 ;; 24 hour interval.
5350 (throw 'exit t))
5351 ;; We have a shorter gap.
5352 ;; Now we have to get the minute of the day when these times are
5353 (let* ((t1dec (decode-time (seconds-to-time t1)))
5354 (t2dec (decode-time (seconds-to-time t2)))
5355 ;; compute the minute on the day
5356 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5357 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5358 (when (< min2 min1)
5359 ;; if min2 is smaller than min1, this means it is on the next day.
5360 ;; Wrap it to after midnight.
5361 (setq min2 (+ min2 1440)))
5362 ;; Now check if any of the OK times is in the gap
5363 (mapc (lambda (x)
5364 ;; Wrap the time to after midnight if necessary
5365 (if (< x min1) (setq x (+ x 1440)))
5366 ;; Check if in interval
5367 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5368 ok-list)
5369 ;; Nope, this gap is not OK
5370 nil)))
5372 (defun org-agenda-get-deadlines ()
5373 "Return the deadline information for agenda display."
5374 (let* ((props (list 'mouse-face 'highlight
5375 'org-not-done-regexp org-not-done-regexp
5376 'org-todo-regexp org-todo-regexp
5377 'org-complex-heading-regexp org-complex-heading-regexp
5378 'help-echo
5379 (format "mouse-2 or RET jump to org file %s"
5380 (abbreviate-file-name buffer-file-name))))
5381 (regexp org-deadline-time-regexp)
5382 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5383 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5384 d2 diff dfrac wdays pos pos1 category org-category-pos
5385 tags suppress-prewarning ee txt head face s todo-state
5386 show-all upcomingp donep timestr)
5387 (goto-char (point-min))
5388 (while (re-search-forward regexp nil t)
5389 (setq suppress-prewarning nil)
5390 (catch :skip
5391 (org-agenda-skip)
5392 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5393 (save-match-data
5394 (string-match org-scheduled-time-regexp
5395 (buffer-substring (point-at-bol)
5396 (point-at-eol)))))
5397 (setq suppress-prewarning
5398 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5399 org-agenda-skip-deadline-prewarning-if-scheduled
5400 0)))
5401 (setq s (match-string 1)
5402 txt nil
5403 pos (1- (match-beginning 1))
5404 todo-state (save-match-data (org-get-todo-state))
5405 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5406 (member todo-state
5407 org-agenda-repeating-timestamp-show-all))
5408 d2 (org-time-string-to-absolute
5409 (match-string 1) d1 'past show-all
5410 (current-buffer) pos)
5411 diff (- d2 d1)
5412 wdays (if suppress-prewarning
5413 (let ((org-deadline-warning-days suppress-prewarning))
5414 (org-get-wdays s))
5415 (org-get-wdays s))
5416 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5417 upcomingp (and todayp (> diff 0)))
5418 ;; When to show a deadline in the calendar:
5419 ;; If the expiration is within wdays warning time.
5420 ;; Past-due deadlines are only shown on the current date
5421 (if (and (or (and (<= diff wdays)
5422 (and todayp (not org-agenda-only-exact-dates)))
5423 (= diff 0)))
5424 (save-excursion
5425 ;; (setq todo-state (org-get-todo-state))
5426 (setq donep (member todo-state org-done-keywords))
5427 (if (and donep
5428 (or org-agenda-skip-deadline-if-done
5429 (not (= diff 0))))
5430 (setq txt nil)
5431 (setq category (org-get-category)
5432 org-category-pos (get-text-property (point) 'org-category-position))
5433 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5434 (setq txt org-agenda-no-heading-message)
5435 (goto-char (match-end 0))
5436 (setq pos1 (match-beginning 0))
5437 (setq tags (org-get-tags-at pos1))
5438 (setq head (buffer-substring-no-properties
5439 (point)
5440 (progn (skip-chars-forward "^\r\n")
5441 (point))))
5442 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5443 (setq timestr
5444 (concat (substring s (match-beginning 1)) " "))
5445 (setq timestr 'time))
5446 (setq txt (org-agenda-format-item
5447 (if (= diff 0)
5448 (car org-agenda-deadline-leaders)
5449 (if (functionp
5450 (nth 1 org-agenda-deadline-leaders))
5451 (funcall
5452 (nth 1 org-agenda-deadline-leaders)
5453 diff date)
5454 (format (nth 1 org-agenda-deadline-leaders)
5455 diff)))
5456 head category tags
5457 (if (not (= diff 0)) nil timestr)))))
5458 (when txt
5459 (setq face (org-agenda-deadline-face dfrac))
5460 (org-add-props txt props
5461 'org-marker (org-agenda-new-marker pos)
5462 'org-hd-marker (org-agenda-new-marker pos1)
5463 'priority (+ (- diff)
5464 (org-get-priority txt))
5465 'org-category category
5466 'org-category-position org-category-pos
5467 'todo-state todo-state
5468 'type (if upcomingp "upcoming-deadline" "deadline")
5469 'date (if upcomingp date d2)
5470 'face (if donep 'org-agenda-done face)
5471 'undone-face face 'done-face 'org-agenda-done)
5472 (push txt ee))))))
5473 (nreverse ee)))
5475 (defun org-agenda-deadline-face (fraction)
5476 "Return the face to displaying a deadline item.
5477 FRACTION is what fraction of the head-warning time has passed."
5478 (let ((faces org-agenda-deadline-faces) f)
5479 (catch 'exit
5480 (while (setq f (pop faces))
5481 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5483 (defun org-agenda-get-scheduled (&optional deadline-results)
5484 "Return the scheduled information for agenda display."
5485 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5486 'org-todo-regexp org-todo-regexp
5487 'org-complex-heading-regexp org-complex-heading-regexp
5488 'done-face 'org-agenda-done
5489 'mouse-face 'highlight
5490 'help-echo
5491 (format "mouse-2 or RET jump to org file %s"
5492 (abbreviate-file-name buffer-file-name))))
5493 (regexp org-scheduled-time-regexp)
5494 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5495 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5497 (deadline-position-alist
5498 (mapcar (lambda (a) (and (setq mm (get-text-property
5499 0 'org-hd-marker a))
5500 (cons (marker-position mm) a)))
5501 deadline-results))
5502 d2 diff pos pos1 category org-category-pos tags donep
5503 ee txt head pastschedp todo-state face timestr s habitp show-all)
5504 (goto-char (point-min))
5505 (while (re-search-forward regexp nil t)
5506 (catch :skip
5507 (org-agenda-skip)
5508 (setq s (match-string 1)
5509 txt nil
5510 pos (1- (match-beginning 1))
5511 todo-state (save-match-data (org-get-todo-state))
5512 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5513 (member todo-state
5514 org-agenda-repeating-timestamp-show-all))
5515 d2 (org-time-string-to-absolute
5516 (match-string 1) d1 'past show-all
5517 (current-buffer) pos)
5518 diff (- d2 d1))
5519 (setq pastschedp (and todayp (< diff 0)))
5520 ;; When to show a scheduled item in the calendar:
5521 ;; If it is on or past the date.
5522 (when (or (and (< diff 0)
5523 (< (abs diff) org-scheduled-past-days)
5524 (and todayp (not org-agenda-only-exact-dates)))
5525 (= diff 0))
5526 (save-excursion
5527 (setq donep (member todo-state org-done-keywords))
5528 (if (and donep
5529 (or org-agenda-skip-scheduled-if-done
5530 (not (= diff 0))
5531 (and (functionp 'org-is-habit-p)
5532 (org-is-habit-p))))
5533 (setq txt nil)
5534 (setq habitp (and (functionp 'org-is-habit-p)
5535 (org-is-habit-p)))
5536 (setq category (org-get-category)
5537 org-category-pos (get-text-property (point) 'org-category-position))
5538 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5539 (setq txt org-agenda-no-heading-message)
5540 (goto-char (match-end 0))
5541 (setq pos1 (match-beginning 0))
5542 (if habitp
5543 (if (or (not org-habit-show-habits)
5544 (and (not todayp)
5545 org-habit-show-habits-only-for-today))
5546 (throw :skip nil))
5547 (if (and
5548 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5549 (and org-agenda-skip-scheduled-if-deadline-is-shown
5550 pastschedp))
5551 (setq mm (assoc pos1 deadline-position-alist)))
5552 (throw :skip nil)))
5553 (setq tags (org-get-tags-at))
5554 (setq head (buffer-substring-no-properties
5555 (point)
5556 (progn (skip-chars-forward "^\r\n") (point))))
5557 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5558 (setq timestr
5559 (concat (substring s (match-beginning 1)) " "))
5560 (setq timestr 'time))
5561 (setq txt (org-agenda-format-item
5562 (if (= diff 0)
5563 (car org-agenda-scheduled-leaders)
5564 (format (nth 1 org-agenda-scheduled-leaders)
5565 (- 1 diff)))
5566 head category tags
5567 (if (not (= diff 0)) nil timestr)
5568 nil habitp))))
5569 (when txt
5570 (setq face
5571 (cond
5572 ((and (not habitp) pastschedp)
5573 'org-scheduled-previously)
5574 (todayp 'org-scheduled-today)
5575 (t 'org-scheduled))
5576 habitp (and habitp (org-habit-parse-todo)))
5577 (org-add-props txt props
5578 'undone-face face
5579 'face (if donep 'org-agenda-done face)
5580 'org-marker (org-agenda-new-marker pos)
5581 'org-hd-marker (org-agenda-new-marker pos1)
5582 'type (if pastschedp "past-scheduled" "scheduled")
5583 'date (if pastschedp d2 date)
5584 'priority (if habitp
5585 (org-habit-get-priority habitp)
5586 (+ 94 (- 5 diff) (org-get-priority txt)))
5587 'org-category category
5588 'org-category-position org-category-pos
5589 'org-habit-p habitp
5590 'todo-state todo-state)
5591 (push txt ee))))))
5592 (nreverse ee)))
5594 (defun org-agenda-get-blocks ()
5595 "Return the date-range information for agenda display."
5596 (let* ((props (list 'face nil
5597 'org-not-done-regexp org-not-done-regexp
5598 'org-todo-regexp org-todo-regexp
5599 'org-complex-heading-regexp org-complex-heading-regexp
5600 'mouse-face 'highlight
5601 'help-echo
5602 (format "mouse-2 or RET jump to org file %s"
5603 (abbreviate-file-name buffer-file-name))))
5604 (regexp org-tr-regexp)
5605 (d0 (calendar-absolute-from-gregorian date))
5606 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5607 todo-state tags pos head donep)
5608 (goto-char (point-min))
5609 (while (re-search-forward regexp nil t)
5610 (catch :skip
5611 (org-agenda-skip)
5612 (setq pos (point))
5613 (let ((start-time (match-string 1))
5614 (end-time (match-string 2)))
5615 (setq s1 (match-string 1)
5616 s2 (match-string 2)
5617 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5618 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5619 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5620 ;; Only allow days between the limits, because the normal
5621 ;; date stamps will catch the limits.
5622 (save-excursion
5623 (setq todo-state (org-get-todo-state))
5624 (setq donep (member todo-state org-done-keywords))
5625 (if (and donep org-agenda-skip-timestamp-if-done)
5626 (throw :skip t))
5627 (setq marker (org-agenda-new-marker (point)))
5628 (setq category (org-get-category)
5629 org-category-pos (get-text-property (point) 'org-category-position))
5630 (if (not (re-search-backward org-outline-regexp-bol nil t))
5631 (setq txt org-agenda-no-heading-message)
5632 (goto-char (match-beginning 0))
5633 (setq hdmarker (org-agenda-new-marker (point)))
5634 (setq tags (org-get-tags-at))
5635 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5636 (setq head (match-string 1))
5637 (let ((remove-re
5638 (if org-agenda-remove-timeranges-from-blocks
5639 (concat
5640 "<" (regexp-quote s1) ".*?>"
5641 "--"
5642 "<" (regexp-quote s2) ".*?>")
5643 nil)))
5644 (setq txt (org-agenda-format-item
5645 (format
5646 (nth (if (= d1 d2) 0 1)
5647 org-agenda-timerange-leaders)
5648 (1+ (- d0 d1)) (1+ (- d2 d1)))
5649 head category tags
5650 (cond ((and (= d1 d0) (= d2 d0))
5651 (concat "<" start-time ">--<" end-time ">"))
5652 ((= d1 d0)
5653 (concat "<" start-time ">"))
5654 ((= d2 d0)
5655 (concat "<" end-time ">"))
5656 (t nil))
5657 remove-re))))
5658 (org-add-props txt props
5659 'org-marker marker 'org-hd-marker hdmarker
5660 'type "block" 'date date
5661 'todo-state todo-state
5662 'priority (org-get-priority txt) 'org-category category
5663 'org-category-position org-category-pos)
5664 (push txt ee))))
5665 (goto-char pos)))
5666 ;; Sort the entries by expiration date.
5667 (nreverse ee)))
5669 ;;; Agenda presentation and sorting
5671 (defvar org-prefix-has-time nil
5672 "A flag, set by `org-compile-prefix-format'.
5673 The flag is set if the currently compiled format contains a `%t'.")
5674 (defvar org-prefix-has-tag nil
5675 "A flag, set by `org-compile-prefix-format'.
5676 The flag is set if the currently compiled format contains a `%T'.")
5677 (defvar org-prefix-has-effort nil
5678 "A flag, set by `org-compile-prefix-format'.
5679 The flag is set if the currently compiled format contains a `%e'.")
5680 (defvar org-prefix-category-length nil
5681 "Used by `org-compile-prefix-format' to remember the category field width.")
5682 (defvar org-prefix-category-max-length nil
5683 "Used by `org-compile-prefix-format' to remember the category field width.")
5685 (defun org-agenda-get-category-icon (category)
5686 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5687 (dolist (entry org-agenda-category-icon-alist)
5688 (when (org-string-match-p (car entry) category)
5689 (if (listp (cadr entry))
5690 (return (cadr entry))
5691 (return (apply 'create-image (cdr entry)))))))
5693 (defun org-agenda-format-item (extra txt &optional category tags dotime
5694 remove-re habitp)
5695 "Format TXT to be inserted into the agenda buffer.
5696 In particular, it adds the prefix and corresponding text properties. EXTRA
5697 must be a string and replaces the `%s' specifier in the prefix format.
5698 CATEGORY (string, symbol or nil) may be used to overrule the default
5699 category taken from local variable or file name. It will replace the `%c'
5700 specifier in the format. DOTIME, when non-nil, indicates that a
5701 time-of-day should be extracted from TXT for sorting of this entry, and for
5702 the `%t' specifier in the format. When DOTIME is a string, this string is
5703 searched for a time before TXT is. TAGS can be the tags of the headline.
5704 Any match of REMOVE-RE will be removed from TXT."
5705 ;; We keep the org-prefix-* variable values along with a compiled
5706 ;; formatter, so that multiple agendas existing at the same time, do
5707 ;; not step on each other toes.
5709 ;; It was inconvenient to make these variables buffer local in
5710 ;; Agenda buffers, because this function expects to be called with
5711 ;; the buffer where item comes from being current, and not agenda
5712 ;; buffer
5713 (let* ((bindings (car org-prefix-format-compiled))
5714 (formatter (cadr org-prefix-format-compiled)))
5715 (loop for (var value) in bindings
5716 do (set var value))
5717 (save-match-data
5718 ;; Diary entries sometimes have extra whitespace at the beginning
5719 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5721 ;; Fix the tags part in txt
5722 (setq txt (org-agenda-fix-displayed-tags
5723 txt tags
5724 org-agenda-show-inherited-tags
5725 org-agenda-hide-tags-regexp))
5726 (let* ((category (or category
5727 (if (stringp org-category)
5728 org-category
5729 (and org-category (symbol-name org-category)))
5730 (if buffer-file-name
5731 (file-name-sans-extension
5732 (file-name-nondirectory buffer-file-name))
5733 "")))
5734 (category-icon (org-agenda-get-category-icon category))
5735 (category-icon (if category-icon
5736 (propertize " " 'display category-icon)
5737 ""))
5738 ;; time, tag, effort are needed for the eval of the prefix format
5739 (tag (if tags (nth (1- (length tags)) tags) ""))
5740 time effort neffort
5741 (ts (if dotime (concat
5742 (if (stringp dotime) dotime "")
5743 (and org-agenda-search-headline-for-time txt))))
5744 (time-of-day (and dotime (org-get-time-of-day ts)))
5745 stamp plain s0 s1 s2 rtn srp l
5746 duration thecategory)
5747 (and (eq major-mode 'org-mode) buffer-file-name
5748 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5749 (when (and dotime time-of-day)
5750 ;; Extract starting and ending time and move them to prefix
5751 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5752 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5753 (setq s0 (match-string 0 ts)
5754 srp (and stamp (match-end 3))
5755 s1 (match-string (if plain 1 2) ts)
5756 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5758 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5759 ;; them, we might want to remove them there to avoid duplication.
5760 ;; The user can turn this off with a variable.
5761 (if (and org-prefix-has-time
5762 org-agenda-remove-times-when-in-prefix (or stamp plain)
5763 (string-match (concat (regexp-quote s0) " *") txt)
5764 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5765 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5766 (= (match-beginning 0) 0)
5768 (setq txt (replace-match "" nil nil txt))))
5769 ;; Normalize the time(s) to 24 hour
5770 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5771 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5773 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5774 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5775 (setq s2
5776 (org-minutes-to-hh:mm-string
5777 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5779 ;; Compute the duration
5780 (when s2
5781 (setq duration (- (org-hh:mm-string-to-minutes s2)
5782 (org-hh:mm-string-to-minutes s1)))))
5784 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5785 txt)
5786 ;; Tags are in the string
5787 (if (or (eq org-agenda-remove-tags t)
5788 (and org-agenda-remove-tags
5789 org-prefix-has-tag))
5790 (setq txt (replace-match "" t t txt))
5791 (setq txt (replace-match
5792 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5793 (match-string 2 txt))
5794 t t txt))))
5795 (when (eq major-mode 'org-mode)
5796 (setq effort
5797 (condition-case nil
5798 (org-get-effort
5799 (or (get-text-property 0 'org-hd-marker txt)
5800 (get-text-property 0 'org-marker txt)))
5801 (error nil)))
5802 (when effort
5803 (setq neffort (org-duration-string-to-minutes effort)
5804 effort (setq effort (concat "[" effort "]")))))
5805 ;; prevent erroring out with %e format when there is no effort
5806 (or effort (setq effort ""))
5808 (when remove-re
5809 (while (string-match remove-re txt)
5810 (setq txt (replace-match "" t t txt))))
5812 ;; Set org-heading property on `txt' to mark the start of the
5813 ;; heading.
5814 (add-text-properties 0 (length txt) '(org-heading t) txt)
5816 ;; Prepare the variables needed in the eval of the compiled format
5817 (setq time (cond (s2 (concat
5818 (org-agenda-time-of-day-to-ampm-maybe s1)
5819 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5820 (if org-agenda-timegrid-use-ampm " ")))
5821 (s1 (concat
5822 (org-agenda-time-of-day-to-ampm-maybe s1)
5823 (if org-agenda-timegrid-use-ampm
5824 "........ "
5825 "......")))
5826 (t ""))
5827 extra (or (and (not habitp) extra) "")
5828 category (if (symbolp category) (symbol-name category) category)
5829 thecategory (copy-sequence category))
5830 (if (string-match org-bracket-link-regexp category)
5831 (progn
5832 (setq l (if (match-end 3)
5833 (- (match-end 3) (match-beginning 3))
5834 (- (match-end 1) (match-beginning 1))))
5835 (when (< l (or org-prefix-category-length 0))
5836 (setq category (copy-sequence category))
5837 (org-add-props category nil
5838 'extra-space (make-string
5839 (- org-prefix-category-length l 1) ?\ ))))
5840 (if (and org-prefix-category-max-length
5841 (>= (length category) org-prefix-category-max-length))
5842 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5843 ;; Evaluate the compiled format
5844 (setq rtn (concat (eval formatter) txt))
5846 ;; And finally add the text properties
5847 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5848 (org-add-props rtn nil
5849 'org-category (if thecategory (downcase thecategory) category)
5850 'tags (mapcar 'org-downcase-keep-props tags)
5851 'org-highest-priority org-highest-priority
5852 'org-lowest-priority org-lowest-priority
5853 'time-of-day time-of-day
5854 'duration duration
5855 'effort effort
5856 'effort-minutes neffort
5857 'txt txt
5858 'time time
5859 'extra extra
5860 'format org-prefix-format-compiled
5861 'dotime dotime)))))
5863 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5864 "Remove tags string from TXT, and add a modified list of tags.
5865 The modified list may contain inherited tags, and tags matched by
5866 `org-agenda-hide-tags-regexp' will be removed."
5867 (when (or add-inherited hide-re)
5868 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5869 (setq txt (substring txt 0 (match-beginning 0))))
5870 (setq tags
5871 (delq nil
5872 (mapcar (lambda (tg)
5873 (if (or (and hide-re (string-match hide-re tg))
5874 (and (not add-inherited)
5875 (get-text-property 0 'inherited tg)))
5877 tg))
5878 tags)))
5879 (when tags
5880 (let ((have-i (get-text-property 0 'inherited (car tags)))
5882 (setq txt (concat txt " :"
5883 (mapconcat
5884 (lambda (x)
5885 (setq i (get-text-property 0 'inherited x))
5886 (if (and have-i (not i))
5887 (progn
5888 (setq have-i nil)
5889 (concat ":" x))
5891 tags ":")
5892 (if have-i "::" ":"))))))
5893 txt)
5895 (defun org-downcase-keep-props (s)
5896 (let ((props (text-properties-at 0 s)))
5897 (setq s (downcase s))
5898 (add-text-properties 0 (length s) props s)
5901 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5902 (defvar org-agenda-sorting-strategy-selected nil)
5904 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5905 (catch 'exit
5906 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5907 ((and todayp (member 'today (car org-agenda-time-grid))))
5908 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5909 ((member 'weekly (car org-agenda-time-grid)))
5910 (t (throw 'exit list)))
5911 (let* ((have (delq nil (mapcar
5912 (lambda (x) (get-text-property 1 'time-of-day x))
5913 list)))
5914 (string (nth 1 org-agenda-time-grid))
5915 (gridtimes (nth 2 org-agenda-time-grid))
5916 (req (car org-agenda-time-grid))
5917 (remove (member 'remove-match req))
5918 new time)
5919 (if (and (member 'require-timed req) (not have))
5920 ;; don't show empty grid
5921 (throw 'exit list))
5922 (while (setq time (pop gridtimes))
5923 (unless (and remove (member time have))
5924 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5925 (push (org-agenda-format-item
5926 nil string "" nil
5927 (concat (substring time 0 -2) ":" (substring time -2)))
5928 new)
5929 (put-text-property
5930 2 (length (car new)) 'face 'org-time-grid (car new))))
5931 (when (and todayp org-agenda-show-current-time-in-grid)
5932 (push (org-agenda-format-item
5934 org-agenda-current-time-string
5935 "" nil
5936 (format-time-string "%H:%M "))
5937 new)
5938 (put-text-property
5939 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5941 (if (member 'time-up org-agenda-sorting-strategy-selected)
5942 (append new list)
5943 (append list new)))))
5945 (defun org-compile-prefix-format (key)
5946 "Compile the prefix format into a Lisp form that can be evaluated.
5947 The resulting form and associated variable bindings is returned
5948 and stored in the variable `org-prefix-format-compiled'."
5949 (setq org-prefix-has-time nil org-prefix-has-tag nil
5950 org-prefix-category-length nil
5951 org-prefix-has-effort nil)
5952 (let ((s (cond
5953 ((stringp org-agenda-prefix-format)
5954 org-agenda-prefix-format)
5955 ((assq key org-agenda-prefix-format)
5956 (cdr (assq key org-agenda-prefix-format)))
5957 (t " %-12:c%?-12t% s")))
5958 (start 0)
5959 varform vars var e c f opt)
5960 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
5961 s start)
5962 (setq var (or (cdr (assoc (match-string 4 s)
5963 '(("c" . category) ("t" . time) ("s" . extra)
5964 ("i" . category-icon) ("T" . tag) ("e" . effort))))
5965 'eval)
5966 c (or (match-string 3 s) "")
5967 opt (match-beginning 1)
5968 start (1+ (match-beginning 0)))
5969 (if (equal var 'time) (setq org-prefix-has-time t))
5970 (if (equal var 'tag) (setq org-prefix-has-tag t))
5971 (if (equal var 'effort) (setq org-prefix-has-effort t))
5972 (setq f (concat "%" (match-string 2 s) "s"))
5973 (when (equal var 'category)
5974 (setq org-prefix-category-length
5975 (floor (abs (string-to-number (match-string 2 s)))))
5976 (setq org-prefix-category-max-length
5977 (let ((x (match-string 2 s)))
5978 (save-match-data
5979 (if (string-match "\\.[0-9]+" x)
5980 (string-to-number (substring (match-string 0 x) 1)))))))
5981 (if (eq var 'eval)
5982 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
5983 (if opt
5984 (setq varform
5985 `(if (equal "" ,var)
5987 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
5988 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
5989 (setq s (replace-match "%s" t nil s))
5990 (push varform vars))
5991 (setq vars (nreverse vars))
5992 (with-current-buffer org-agenda-buffer
5993 (setq org-prefix-format-compiled
5994 (list
5995 `((org-prefix-has-time ,org-prefix-has-time)
5996 (org-prefix-has-tag ,org-prefix-has-tag)
5997 (org-prefix-category-length ,org-prefix-category-length)
5998 (org-prefix-has-effort ,org-prefix-has-effort))
5999 `(format ,s ,@vars))))))
6001 (defun org-set-sorting-strategy (key)
6002 (if (symbolp (car org-agenda-sorting-strategy))
6003 ;; the old format
6004 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6005 (setq org-agenda-sorting-strategy-selected
6006 (or (cdr (assq key org-agenda-sorting-strategy))
6007 (cdr (assq 'agenda org-agenda-sorting-strategy))
6008 '(time-up category-keep priority-down)))))
6010 (defun org-get-time-of-day (s &optional string mod24)
6011 "Check string S for a time of day.
6012 If found, return it as a military time number between 0 and 2400.
6013 If not found, return nil.
6014 The optional STRING argument forces conversion into a 5 character wide string
6015 HH:MM."
6016 (save-match-data
6017 (when
6018 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6019 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6020 (let* ((h (string-to-number (match-string 1 s)))
6021 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6022 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6023 (am-p (equal ampm "am"))
6024 (h1 (cond ((not ampm) h)
6025 ((= h 12) (if am-p 0 12))
6026 (t (+ h (if am-p 0 12)))))
6027 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6028 (mod h1 24) h1))
6029 (t0 (+ (* 100 h2) m))
6030 (t1 (concat (if (>= h1 24) "+" " ")
6031 (if (and org-agenda-time-leading-zero
6032 (< t0 1000)) "0" "")
6033 (if (< t0 100) "0" "")
6034 (if (< t0 10) "0" "")
6035 (int-to-string t0))))
6036 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6038 (defvar org-agenda-before-sorting-filter-function nil
6039 "Function to be applied to agenda items prior to sorting.
6040 Prior to sorting also means just before they are inserted into the agenda.
6042 To aid sorting, you may revisit the original entries and add more text
6043 properties which will later be used by the sorting functions.
6045 The function should take a string argument, an agenda line.
6046 It has access to the text properties in that line, which contain among
6047 other things, the property `org-hd-marker' that points to the entry
6048 where the line comes from. Note that not all lines going into the agenda
6049 have this property, only most.
6051 The function should return the modified string. It is probably best
6052 to ONLY change text properties.
6054 You can also use this function as a filter, by returning nil for lines
6055 you don't want to have in the agenda at all. For this application, you
6056 could bind the variable in the options section of a custom command.")
6058 (defun org-finalize-agenda-entries (list &optional nosort)
6059 "Sort and concatenate the agenda items."
6060 (setq list (mapcar 'org-agenda-highlight-todo list))
6061 (if nosort
6062 list
6063 (when org-agenda-before-sorting-filter-function
6064 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6065 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6067 (defun org-agenda-highlight-todo (x)
6068 (let ((org-done-keywords org-done-keywords-for-agenda)
6069 (case-fold-search nil)
6071 (if (eq x 'line)
6072 (save-excursion
6073 (beginning-of-line 1)
6074 (setq re (org-get-at-bol 'org-todo-regexp))
6075 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6076 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6077 (add-text-properties (match-beginning 0) (match-end 1)
6078 (list 'face (org-get-todo-face 1)))
6079 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6080 (delete-region (match-beginning 1) (1- (match-end 0)))
6081 (goto-char (match-beginning 1))
6082 (insert (format org-agenda-todo-keyword-format s)))))
6083 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6084 (setq re (get-text-property 0 'org-todo-regexp x))
6085 (when (and re
6086 ;; Test `pl' because if there's no heading content,
6087 ;; there's no point matching to highlight. Note
6088 ;; that if we didn't test `pl' first, and there
6089 ;; happened to be no keyword from `org-todo-regexp'
6090 ;; on this heading line, then the `equal' comparison
6091 ;; afterwards would spuriously succeed in the case
6092 ;; where `pl' is nil -- causing an args-out-of-range
6093 ;; error when we try to add text properties to text
6094 ;; that isn't there.
6096 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6097 x pl) pl))
6098 (add-text-properties
6099 (or (match-end 1) (match-end 0)) (match-end 0)
6100 (list 'face (org-get-todo-face (match-string 2 x)))
6102 (when (match-end 1)
6103 (setq x (concat (substring x 0 (match-end 1))
6104 (format org-agenda-todo-keyword-format
6105 (match-string 2 x))
6106 (org-add-props " " (text-properties-at 0 x))
6107 (substring x (match-end 3)))))))
6108 x)))
6110 (defsubst org-cmp-priority (a b)
6111 "Compare the priorities of string A and B."
6112 (let ((pa (or (get-text-property 1 'priority a) 0))
6113 (pb (or (get-text-property 1 'priority b) 0)))
6114 (cond ((> pa pb) +1)
6115 ((< pa pb) -1)
6116 (t nil))))
6118 (defsubst org-cmp-effort (a b)
6119 "Compare the effort values of string A and B."
6120 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6121 (ea (or (get-text-property 1 'effort-minutes a) def))
6122 (eb (or (get-text-property 1 'effort-minutes b) def)))
6123 (cond ((> ea eb) +1)
6124 ((< ea eb) -1)
6125 (t nil))))
6127 (defsubst org-cmp-category (a b)
6128 "Compare the string values of categories of strings A and B."
6129 (let ((ca (or (get-text-property 1 'org-category a) ""))
6130 (cb (or (get-text-property 1 'org-category b) "")))
6131 (cond ((string-lessp ca cb) -1)
6132 ((string-lessp cb ca) +1)
6133 (t nil))))
6135 (defsubst org-cmp-todo-state (a b)
6136 "Compare the todo states of strings A and B."
6137 (let* ((ma (or (get-text-property 1 'org-marker a)
6138 (get-text-property 1 'org-hd-marker a)))
6139 (mb (or (get-text-property 1 'org-marker b)
6140 (get-text-property 1 'org-hd-marker b)))
6141 (fa (and ma (marker-buffer ma)))
6142 (fb (and mb (marker-buffer mb)))
6143 (todo-kwds
6144 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6145 (and fb (with-current-buffer fb org-todo-keywords-1))))
6146 (ta (or (get-text-property 1 'todo-state a) ""))
6147 (tb (or (get-text-property 1 'todo-state b) ""))
6148 (la (- (length (member ta todo-kwds))))
6149 (lb (- (length (member tb todo-kwds))))
6150 (donepa (member ta org-done-keywords-for-agenda))
6151 (donepb (member tb org-done-keywords-for-agenda)))
6152 (cond ((and donepa (not donepb)) -1)
6153 ((and (not donepa) donepb) +1)
6154 ((< la lb) -1)
6155 ((< lb la) +1)
6156 (t nil))))
6158 (defsubst org-cmp-alpha (a b)
6159 "Compare the headlines, alphabetically."
6160 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6161 (plb (text-property-any 0 (length b) 'org-heading t b))
6162 (ta (and pla (substring a pla)))
6163 (tb (and plb (substring b plb))))
6164 (when pla
6165 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6166 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6167 (setq ta (substring ta (match-end 0))))
6168 (setq ta (downcase ta)))
6169 (when plb
6170 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6171 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6172 (setq tb (substring tb (match-end 0))))
6173 (setq tb (downcase tb)))
6174 (cond ((not ta) +1)
6175 ((not tb) -1)
6176 ((string-lessp ta tb) -1)
6177 ((string-lessp tb ta) +1)
6178 (t nil))))
6180 (defsubst org-cmp-tag (a b)
6181 "Compare the string values of the first tags of A and B."
6182 (let ((ta (car (last (get-text-property 1 'tags a))))
6183 (tb (car (last (get-text-property 1 'tags b)))))
6184 (cond ((not ta) +1)
6185 ((not tb) -1)
6186 ((string-lessp ta tb) -1)
6187 ((string-lessp tb ta) +1)
6188 (t nil))))
6190 (defsubst org-cmp-time (a b)
6191 "Compare the time-of-day values of strings A and B."
6192 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6193 (ta (or (get-text-property 1 'time-of-day a) def))
6194 (tb (or (get-text-property 1 'time-of-day b) def)))
6195 (cond ((< ta tb) -1)
6196 ((< tb ta) +1)
6197 (t nil))))
6199 (defsubst org-cmp-habit-p (a b)
6200 "Compare the todo states of strings A and B."
6201 (let ((ha (get-text-property 1 'org-habit-p a))
6202 (hb (get-text-property 1 'org-habit-p b)))
6203 (cond ((and ha (not hb)) -1)
6204 ((and (not ha) hb) +1)
6205 (t nil))))
6207 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6209 (defun org-entries-lessp (a b)
6210 "Predicate for sorting agenda entries."
6211 ;; The following variables will be used when the form is evaluated.
6212 ;; So even though the compiler complains, keep them.
6213 (let* ((ss org-agenda-sorting-strategy-selected)
6214 (time-up (and (org-em 'time-up 'time-down ss)
6215 (org-cmp-time a b)))
6216 (time-down (if time-up (- time-up) nil))
6217 (priority-up (and (org-em 'priority-up 'priority-down ss)
6218 (org-cmp-priority a b)))
6219 (priority-down (if priority-up (- priority-up) nil))
6220 (effort-up (and (org-em 'effort-up 'effort-down ss)
6221 (org-cmp-effort a b)))
6222 (effort-down (if effort-up (- effort-up) nil))
6223 (category-up (and (or (org-em 'category-up 'category-down ss)
6224 (memq 'category-keep ss))
6225 (org-cmp-category a b)))
6226 (category-down (if category-up (- category-up) nil))
6227 (category-keep (if category-up +1 nil))
6228 (tag-up (and (org-em 'tag-up 'tag-down ss)
6229 (org-cmp-tag a b)))
6230 (tag-down (if tag-up (- tag-up) nil))
6231 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6232 (org-cmp-todo-state a b)))
6233 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6234 (habit-up (and (org-em 'habit-up 'habit-down ss)
6235 (org-cmp-habit-p a b)))
6236 (habit-down (if habit-up (- habit-up) nil))
6237 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6238 (org-cmp-alpha a b)))
6239 (alpha-down (if alpha-up (- alpha-up) nil))
6240 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6241 user-defined-up user-defined-down)
6242 (if (and need-user-cmp org-agenda-cmp-user-defined
6243 (functionp org-agenda-cmp-user-defined))
6244 (setq user-defined-up
6245 (funcall org-agenda-cmp-user-defined a b)
6246 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6247 (cdr (assoc
6248 (eval (cons 'or org-agenda-sorting-strategy-selected))
6249 '((-1 . t) (1 . nil) (nil . nil))))))
6251 ;;; Agenda restriction lock
6253 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6254 "Overlay to mark the headline to which agenda commands are restricted.")
6255 (overlay-put org-agenda-restriction-lock-overlay
6256 'face 'org-agenda-restriction-lock)
6257 (overlay-put org-agenda-restriction-lock-overlay
6258 'help-echo "Agendas are currently limited to this subtree.")
6259 (org-detach-overlay org-agenda-restriction-lock-overlay)
6261 (defun org-agenda-set-restriction-lock (&optional type)
6262 "Set restriction lock for agenda, to current subtree or file.
6263 Restriction will be the file if TYPE is `file', or if type is the
6264 universal prefix '(4), or if the cursor is before the first headline
6265 in the file. Otherwise, restriction will be to the current subtree."
6266 (interactive "P")
6267 (and (equal type '(4)) (setq type 'file))
6268 (setq type (cond
6269 (type type)
6270 ((org-at-heading-p) 'subtree)
6271 ((condition-case nil (org-back-to-heading t) (error nil))
6272 'subtree)
6273 (t 'file)))
6274 (if (eq type 'subtree)
6275 (progn
6276 (setq org-agenda-restrict t)
6277 (setq org-agenda-overriding-restriction 'subtree)
6278 (put 'org-agenda-files 'org-restrict
6279 (list (buffer-file-name (buffer-base-buffer))))
6280 (org-back-to-heading t)
6281 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6282 (move-marker org-agenda-restrict-begin (point))
6283 (move-marker org-agenda-restrict-end
6284 (save-excursion (org-end-of-subtree t)))
6285 (message "Locking agenda restriction to subtree"))
6286 (put 'org-agenda-files 'org-restrict
6287 (list (buffer-file-name (buffer-base-buffer))))
6288 (setq org-agenda-restrict nil)
6289 (setq org-agenda-overriding-restriction 'file)
6290 (move-marker org-agenda-restrict-begin nil)
6291 (move-marker org-agenda-restrict-end nil)
6292 (message "Locking agenda restriction to file"))
6293 (setq current-prefix-arg nil)
6294 (org-agenda-maybe-redo))
6296 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6297 "Remove the agenda restriction lock."
6298 (interactive "P")
6299 (org-detach-overlay org-agenda-restriction-lock-overlay)
6300 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6301 (setq org-agenda-overriding-restriction nil)
6302 (setq org-agenda-restrict nil)
6303 (put 'org-agenda-files 'org-restrict nil)
6304 (move-marker org-agenda-restrict-begin nil)
6305 (move-marker org-agenda-restrict-end nil)
6306 (setq current-prefix-arg nil)
6307 (message "Agenda restriction lock removed")
6308 (or noupdate (org-agenda-maybe-redo)))
6310 (defun org-agenda-maybe-redo ()
6311 "If there is any window showing the agenda view, update it."
6312 (let ((w (get-buffer-window org-agenda-buffer-name t))
6313 (w0 (selected-window)))
6314 (when w
6315 (select-window w)
6316 (org-agenda-redo)
6317 (select-window w0)
6318 (if org-agenda-overriding-restriction
6319 (message "Agenda view shifted to new %s restriction"
6320 org-agenda-overriding-restriction)
6321 (message "Agenda restriction lock removed")))))
6323 ;;; Agenda commands
6325 (defun org-agenda-check-type (error &rest types)
6326 "Check if agenda buffer is of allowed type.
6327 If ERROR is non-nil, throw an error, otherwise just return nil."
6328 (if (memq org-agenda-type types)
6330 (if error
6331 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6332 nil)))
6334 (defun org-agenda-Quit (&optional arg)
6335 "Exit agenda by removing the window or the buffer"
6336 (interactive)
6337 (if org-agenda-columns-active
6338 (org-columns-quit)
6339 (let ((buf (current-buffer)))
6340 (if (eq org-agenda-window-setup 'other-frame)
6341 (progn
6342 (org-agenda-reset-markers)
6343 (kill-buffer buf)
6344 (org-columns-remove-overlays)
6345 (setq org-agenda-archives-mode nil)
6346 (delete-frame))
6347 (and (not (eq org-agenda-window-setup 'current-window))
6348 (not (one-window-p))
6349 (delete-window))
6350 (org-agenda-reset-markers)
6351 (kill-buffer buf)
6352 (org-columns-remove-overlays)
6353 (setq org-agenda-archives-mode nil)))
6354 ;; Maybe restore the pre-agenda window configuration.
6355 (and org-agenda-restore-windows-after-quit
6356 (not (eq org-agenda-window-setup 'other-frame))
6357 org-pre-agenda-window-conf
6358 (set-window-configuration org-pre-agenda-window-conf))))
6360 (defun org-agenda-quit ()
6361 "Exit agenda by killing agenda buffer or burying it when
6362 `org-agenda-sticky' is non-NIL"
6363 (interactive)
6364 (if org-agenda-columns-active
6365 (org-columns-quit)
6366 (if org-agenda-sticky
6367 (let ((buf (current-buffer)))
6368 (if (eq org-agenda-window-setup 'other-frame)
6369 (progn
6370 (delete-frame))
6371 (and (not (eq org-agenda-window-setup 'current-window))
6372 (not (one-window-p))
6373 (delete-window)))
6374 (with-current-buffer buf
6375 (bury-buffer)))
6376 (org-agenda-Quit))))
6378 (defun org-agenda-exit ()
6379 "Exit agenda by removing the window or the buffer.
6380 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6381 Org-mode buffers visited directly by the user will not be touched."
6382 (interactive)
6383 (org-release-buffers org-agenda-new-buffers)
6384 (setq org-agenda-new-buffers nil)
6385 (org-agenda-Quit))
6387 (defun org-agenda-kill-all-agenda-buffers ()
6388 "Kill all buffers in `org-agena-mode'.
6389 This is used when toggling sticky agendas. You can also explicitly invoke it
6390 with `C-c a C-k'."
6391 (interactive)
6392 (let (blist)
6393 (dolist (buf (buffer-list))
6394 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6395 (push buf blist)))
6396 (mapc 'kill-buffer blist)))
6398 (defun org-agenda-execute (arg)
6399 "Execute another agenda command, keeping same window.
6400 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6401 in the agenda."
6402 (interactive "P")
6403 (let ((org-agenda-window-setup 'current-window))
6404 (org-agenda arg)))
6406 (defun org-agenda-redo ()
6407 "Rebuild Agenda.
6408 When this is the global TODO list, a prefix argument will be interpreted."
6409 (interactive)
6410 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6411 (org-agenda-sticky nil)
6412 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6413 org-agenda-buffer-name))
6414 (org-agenda-keep-modes t)
6415 (tag-filter org-agenda-tag-filter)
6416 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6417 (cat-filter org-agenda-category-filter)
6418 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6419 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6420 (cols org-agenda-columns-active)
6421 (line (org-current-line))
6422 (window-line (- line (org-current-line (window-start))))
6423 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6424 (put 'org-agenda-tag-filter :preset-filter nil)
6425 (put 'org-agenda-category-filter :preset-filter nil)
6426 (and cols (org-columns-quit))
6427 (message "Rebuilding agenda buffer...")
6428 (org-let lprops '(eval org-agenda-redo-command))
6429 (setq org-agenda-undo-list nil
6430 org-agenda-pending-undo-list nil)
6431 (message "Rebuilding agenda buffer...done")
6432 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6433 (put 'org-agenda-category-filter :preset-filter cat-preset)
6434 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6435 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6436 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6437 (org-goto-line line)
6438 (recenter window-line)))
6440 (defvar org-global-tags-completion-table nil)
6441 (defvar org-agenda-filter-form nil)
6442 (defvar org-agenda-filtered-by-category nil)
6444 (defun org-agenda-filter-by-category (strip)
6445 "Keep only those lines in the agenda buffer that have a specific category.
6446 The category is that of the current line."
6447 (interactive "P")
6448 (if org-agenda-filtered-by-category
6449 (org-agenda-filter-show-all-cat)
6450 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6451 (if cat (org-agenda-filter-apply
6452 (list (concat (if strip "-" "+") cat)) 'category)
6453 (error "No category at point")))))
6455 (defun org-find-top-category (&optional pos)
6456 (save-excursion
6457 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6458 (if pos (goto-char pos))
6459 ;; Skip up to the topmost parent
6460 (while (ignore-errors (outline-up-heading 1) t))
6461 (ignore-errors
6462 (nth 4 (org-heading-components))))))
6464 (defvar org-agenda-filtered-by-top-category nil)
6466 (defun org-agenda-filter-by-top-category (strip)
6467 "Keep only those lines in the agenda buffer that have a specific category.
6468 The category is that of the current line."
6469 (interactive "P")
6470 (if org-agenda-filtered-by-top-category
6471 (progn
6472 (setq org-agenda-filtered-by-top-category nil)
6473 (org-agenda-filter-show-all-cat))
6474 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6475 (if cat (org-agenda-filter-top-category-apply cat strip)
6476 (error "No top-level category at point")))))
6478 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6479 "Keep only those lines in the agenda buffer that have a specific tag.
6480 The tag is selected with its fast selection letter, as configured.
6481 With prefix argument STRIP, remove all lines that do have the tag.
6482 A lisp caller can specify CHAR. NARROW means that the new tag should be
6483 used to narrow the search - the interactive user can also press `-' or `+'
6484 to switch to narrowing."
6485 (interactive "P")
6486 (let* ((alist org-tag-alist-for-agenda)
6487 (tag-chars (mapconcat
6488 (lambda (x) (if (and (not (symbolp (car x)))
6489 (cdr x))
6490 (char-to-string (cdr x))
6491 ""))
6492 alist ""))
6493 (efforts (org-split-string
6494 (or (cdr (assoc (concat org-effort-property "_ALL")
6495 org-global-properties))
6496 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6497 "")))
6498 (effort-op org-agenda-filter-effort-default-operator)
6499 (effort-prompt "")
6500 (inhibit-read-only t)
6501 (current org-agenda-tag-filter)
6502 maybe-refresh a n tag)
6503 (unless char
6504 (message
6505 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6506 (if narrow "Narrow" "Filter") tag-chars
6507 (if org-agenda-auto-exclude-function "[RET], " ""))
6508 (setq char (read-char-exclusive)))
6509 (when (member char '(?+ ?-))
6510 ;; Narrowing down
6511 (cond ((equal char ?-) (setq strip t narrow t))
6512 ((equal char ?+) (setq strip nil narrow t)))
6513 (message
6514 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6515 (setq char (read-char-exclusive)))
6516 (when (member char '(?< ?> ?= ??))
6517 ;; An effort operator
6518 (setq effort-op (char-to-string char))
6519 (setq alist nil) ; to make sure it will be interpreted as effort.
6520 (unless (equal char ??)
6521 (loop for i from 0 to 9 do
6522 (setq effort-prompt
6523 (concat
6524 effort-prompt " ["
6525 (if (= i 9) "0" (int-to-string (1+ i)))
6526 "]" (nth i efforts))))
6527 (message "Effort%s: %s " effort-op effort-prompt)
6528 (setq char (read-char-exclusive))
6529 (when (or (< char ?0) (> char ?9))
6530 (error "Need 1-9,0 to select effort"))))
6531 (when (equal char ?\t)
6532 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6533 (org-set-local 'org-global-tags-completion-table
6534 (org-global-tags-completion-table)))
6535 (let ((completion-ignore-case t))
6536 (setq tag (org-icompleting-read
6537 "Tag: " org-global-tags-completion-table))))
6538 (cond
6539 ((equal char ?\r)
6540 (org-agenda-filter-show-all-tag)
6541 (when org-agenda-auto-exclude-function
6542 (setq org-agenda-tag-filter '())
6543 (dolist (tag (org-agenda-get-represented-tags))
6544 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6545 (if modifier
6546 (push modifier org-agenda-tag-filter))))
6547 (if (not (null org-agenda-tag-filter))
6548 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6549 (setq maybe-refresh t))
6550 ((equal char ?/)
6551 (org-agenda-filter-show-all-tag)
6552 (when (get 'org-agenda-tag-filter :preset-filter)
6553 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6554 (setq maybe-refresh t))
6555 ((equal char ?. )
6556 (setq org-agenda-tag-filter
6557 (mapcar (lambda(tag) (concat "+" tag))
6558 (org-get-at-bol 'tags)))
6559 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6560 (setq maybe-refresh t))
6561 ((or (equal char ?\ )
6562 (setq a (rassoc char alist))
6563 (and (>= char ?0) (<= char ?9)
6564 (setq n (if (= char ?0) 9 (- char ?0 1))
6565 tag (concat effort-op (nth n efforts))
6566 a (cons tag nil)))
6567 (and (= char ??)
6568 (setq tag "?eff")
6569 a (cons tag nil))
6570 (and tag (setq a (cons tag nil))))
6571 (org-agenda-filter-show-all-tag)
6572 (setq tag (car a))
6573 (setq org-agenda-tag-filter
6574 (cons (concat (if strip "-" "+") tag)
6575 (if narrow current nil)))
6576 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6577 (setq maybe-refresh t))
6578 (t (error "Invalid tag selection character %c" char)))
6579 (when (and maybe-refresh
6580 (eq org-agenda-clockreport-mode 'with-filter))
6581 (org-agenda-redo))))
6583 (defun org-agenda-get-represented-tags ()
6584 "Get a list of all tags currently represented in the agenda."
6585 (let (p tags)
6586 (save-excursion
6587 (goto-char (point-min))
6588 (while (setq p (next-single-property-change (point) 'tags))
6589 (goto-char p)
6590 (mapc (lambda (x) (add-to-list 'tags x))
6591 (get-text-property (point) 'tags))))
6592 tags))
6594 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6595 "Refine the current filter. See `org-agenda-filter-by-tag'."
6596 (interactive "P")
6597 (org-agenda-filter-by-tag strip char 'refine))
6599 (defun org-agenda-filter-make-matcher ()
6600 "Create the form that tests a line for agenda filter."
6601 (let (f f1)
6602 ;; first compute the tag-filter matcher
6603 (dolist (x (delete-dups
6604 (append (get 'org-agenda-tag-filter
6605 :preset-filter) org-agenda-tag-filter)))
6606 (if (member x '("-" "+"))
6607 (setq f1 (if (equal x "-") 'tags '(not tags)))
6608 (if (string-match "[<=>?]" x)
6609 (setq f1 (org-agenda-filter-effort-form x))
6610 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6611 (if (equal (string-to-char x) ?-)
6612 (setq f1 (list 'not f1))))
6613 (push f1 f))
6614 ;; then compute the category-filter matcher
6615 (dolist (x (delete-dups
6616 (append (get 'org-agenda-category-filter
6617 :preset-filter) org-agenda-category-filter)))
6618 (if (equal "-" (substring x 0 1))
6619 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6620 (setq f1 (list 'equal (substring x 1) 'cat)))
6621 (push f1 f))
6622 (cons 'and (nreverse f))))
6624 (defun org-agenda-filter-effort-form (e)
6625 "Return the form to compare the effort of the current line with what E says.
6626 E looks like \"+<2:25\"."
6627 (let (op)
6628 (setq e (substring e 1))
6629 (setq op (string-to-char e) e (substring e 1))
6630 (setq op (cond ((equal op ?<) '<=)
6631 ((equal op ?>) '>=)
6632 ((equal op ??) op)
6633 (t '=)))
6634 (list 'org-agenda-compare-effort (list 'quote op)
6635 (org-duration-string-to-minutes e))))
6637 (defun org-agenda-compare-effort (op value)
6638 "Compare the effort of the current line with VALUE, using OP.
6639 If the line does not have an effort defined, return nil."
6640 (let ((eff (org-get-at-bol 'effort-minutes)))
6641 (if (equal op ??)
6642 (not eff)
6643 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6644 value))))
6646 (defun org-agenda-filter-apply (filter type)
6647 "Set FILTER as the new agenda filter and apply it."
6648 (let (tags cat)
6649 (if (eq type 'tag)
6650 (setq org-agenda-tag-filter filter)
6651 (setq org-agenda-category-filter filter))
6652 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6653 (if (and (eq type 'category)
6654 (not (equal (substring (car filter) 0 1) "-")))
6655 ;; Only set `org-agenda-filtered-by-category' to t
6656 ;; when a unique category is used as the filter
6657 (setq org-agenda-filtered-by-category t))
6658 (org-agenda-set-mode-name)
6659 (save-excursion
6660 (goto-char (point-min))
6661 (while (not (eobp))
6662 (if (org-get-at-bol 'org-marker)
6663 (progn
6664 (setq tags (org-get-at-bol 'tags) ; used in eval
6665 cat (get-text-property (point) 'org-category))
6666 (if (not (eval org-agenda-filter-form))
6667 (org-agenda-filter-hide-line type))
6668 (beginning-of-line 2))
6669 (beginning-of-line 2))))
6670 (if (get-char-property (point) 'invisible)
6671 (ignore-errors (org-agenda-previous-line)))))
6673 (defun org-agenda-filter-top-category-apply (category &optional negative)
6674 "Set FILTER as the new agenda filter and apply it."
6675 (org-agenda-set-mode-name)
6676 (save-excursion
6677 (goto-char (point-min))
6678 (while (not (eobp))
6679 (let* ((pos (org-get-at-bol 'org-hd-marker))
6680 (topcat (and pos (org-find-top-category pos))))
6681 (if (and topcat (funcall (if negative 'identity 'not)
6682 (string= category topcat)))
6683 (org-agenda-filter-hide-line 'category)))
6684 (beginning-of-line 2)))
6685 (if (get-char-property (point) 'invisible)
6686 (org-agenda-previous-line))
6687 (setq org-agenda-filtered-by-top-category t))
6689 (defun org-agenda-filter-hide-line (type)
6690 (let (ov)
6691 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6692 (point-at-eol)))
6693 (overlay-put ov 'invisible t)
6694 (overlay-put ov 'type type)
6695 (if (eq type 'tag)
6696 (push ov org-agenda-tag-filter-overlays)
6697 (push ov org-agenda-cat-filter-overlays))))
6699 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6700 (setq pos (or pos (point)))
6701 (save-excursion
6702 (dolist (ov (overlays-at pos))
6703 (when (and (overlay-get ov 'invisible)
6704 (eq (overlay-get ov 'type) 'tag))
6705 (goto-char pos)
6706 (if (< (overlay-start ov) (point-at-eol))
6707 (move-overlay ov (point-at-eol)
6708 (overlay-end ov)))))))
6710 (defun org-agenda-filter-show-all-tag nil
6711 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6712 (setq org-agenda-tag-filter-overlays nil
6713 org-agenda-tag-filter nil
6714 org-agenda-filter-form nil)
6715 (org-agenda-set-mode-name))
6717 (defun org-agenda-filter-show-all-cat nil
6718 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6719 (setq org-agenda-cat-filter-overlays nil
6720 org-agenda-filtered-by-category nil
6721 org-agenda-category-filter nil
6722 org-agenda-filter-form nil)
6723 (org-agenda-set-mode-name))
6725 (defun org-agenda-manipulate-query-add ()
6726 "Manipulate the query by adding a search term with positive selection.
6727 Positive selection means the term must be matched for selection of an entry."
6728 (interactive)
6729 (org-agenda-manipulate-query ?\[))
6730 (defun org-agenda-manipulate-query-subtract ()
6731 "Manipulate the query by adding a search term with negative selection.
6732 Negative selection means term must not be matched for selection of an entry."
6733 (interactive)
6734 (org-agenda-manipulate-query ?\]))
6735 (defun org-agenda-manipulate-query-add-re ()
6736 "Manipulate the query by adding a search regexp with positive selection.
6737 Positive selection means the regexp must match for selection of an entry."
6738 (interactive)
6739 (org-agenda-manipulate-query ?\{))
6740 (defun org-agenda-manipulate-query-subtract-re ()
6741 "Manipulate the query by adding a search regexp with negative selection.
6742 Negative selection means regexp must not match for selection of an entry."
6743 (interactive)
6744 (org-agenda-manipulate-query ?\}))
6745 (defun org-agenda-manipulate-query (char)
6746 (cond
6747 ((memq org-agenda-type '(timeline agenda))
6748 (let ((org-agenda-include-inactive-timestamps t))
6749 (org-agenda-redo))
6750 (message "Display now includes inactive timestamps as well"))
6751 ((eq org-agenda-type 'search)
6752 (org-add-to-string
6753 'org-agenda-query-string
6754 (if org-agenda-last-search-view-search-was-boolean
6755 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6756 (?\{ . " +{}") (?\} . " -{}"))))
6757 " "))
6758 (setq org-agenda-redo-command
6759 (list 'org-search-view
6760 org-todo-only
6761 org-agenda-query-string
6762 (+ (length org-agenda-query-string)
6763 (if (member char '(?\{ ?\})) 0 1))))
6764 (set-register org-agenda-query-register org-agenda-query-string)
6765 (org-agenda-redo))
6766 (t (error "Cannot manipulate query for %s-type agenda buffers"
6767 org-agenda-type))))
6769 (defun org-add-to-string (var string)
6770 (set var (concat (symbol-value var) string)))
6772 (defun org-agenda-goto-date (date)
6773 "Jump to DATE in agenda."
6774 (interactive (list (let ((org-read-date-prefer-future
6775 (eval org-agenda-jump-prefer-future)))
6776 (org-read-date))))
6777 (org-agenda-list nil date))
6779 (defun org-agenda-goto-today ()
6780 "Go to today."
6781 (interactive)
6782 (org-agenda-check-type t 'timeline 'agenda)
6783 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6784 (cond
6785 (tdpos (goto-char tdpos))
6786 ((eq org-agenda-type 'agenda)
6787 (let* ((sd (org-agenda-compute-starting-span
6788 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6789 (org-agenda-overriding-arguments org-agenda-last-arguments))
6790 (setf (nth 1 org-agenda-overriding-arguments) sd)
6791 (org-agenda-redo)
6792 (org-agenda-find-same-or-today-or-agenda)))
6793 (t (error "Cannot find today")))))
6795 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6796 (goto-char
6797 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6798 (text-property-any (point-min) (point-max) 'org-today t)
6799 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6800 (point-min))))
6802 (defun org-agenda-later (arg)
6803 "Go forward in time by thee current span.
6804 With prefix ARG, go forward that many times the current span."
6805 (interactive "p")
6806 (org-agenda-check-type t 'agenda)
6807 (let* ((span org-agenda-current-span)
6808 (sd org-starting-day)
6809 (greg (calendar-gregorian-from-absolute sd))
6810 (cnt (org-get-at-bol 'org-day-cnt))
6811 greg2)
6812 (cond
6813 ((eq span 'day)
6814 (setq sd (+ arg sd)))
6815 ((eq span 'week)
6816 (setq sd (+ (* 7 arg) sd)))
6817 ((eq span 'month)
6818 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6819 sd (calendar-absolute-from-gregorian greg2))
6820 (setcar greg2 (1+ (car greg2))))
6821 ((eq span 'year)
6822 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6823 sd (calendar-absolute-from-gregorian greg2))
6824 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6826 (setq sd (+ (* span arg) sd))))
6827 (let ((org-agenda-overriding-arguments
6828 (list (car org-agenda-last-arguments) sd span t)))
6829 (org-agenda-redo)
6830 (org-agenda-find-same-or-today-or-agenda cnt))))
6832 (defun org-agenda-earlier (arg)
6833 "Go backward in time by the current span.
6834 With prefix ARG, go backward that many times the current span."
6835 (interactive "p")
6836 (org-agenda-later (- arg)))
6838 (defun org-agenda-view-mode-dispatch ()
6839 "Call one of the view mode commands."
6840 (interactive)
6841 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6842 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6843 [a]rch-trees [A]rch-files clock[R]eport include[D]iary
6844 [E]ntryText")
6845 (let ((a (read-char-exclusive)))
6846 (case a
6847 (?\ (call-interactively 'org-agenda-reset-view))
6848 (?d (call-interactively 'org-agenda-day-view))
6849 (?w (call-interactively 'org-agenda-week-view))
6850 (?m (call-interactively 'org-agenda-month-view))
6851 (?y (call-interactively 'org-agenda-year-view))
6852 (?l (call-interactively 'org-agenda-log-mode))
6853 (?L (org-agenda-log-mode '(4)))
6854 (?c (org-agenda-log-mode 'clockcheck))
6855 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6856 (?a (call-interactively 'org-agenda-archives-mode))
6857 (?A (org-agenda-archives-mode 'files))
6858 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6859 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6860 (?G (call-interactively 'org-agenda-toggle-time-grid))
6861 (?D (call-interactively 'org-agenda-toggle-diary))
6862 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6863 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6864 (org-agenda-check-type t 'timeline 'agenda)
6865 (org-agenda-redo))
6866 (message "Display now includes inactive timestamps as well"))
6867 (?q (message "Abort"))
6868 (otherwise (error "Invalid key" )))))
6870 (defun org-agenda-reset-view ()
6871 "Switch to default view for agenda."
6872 (interactive)
6873 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6874 (defun org-agenda-day-view (&optional day-of-year)
6875 "Switch to daily view for agenda.
6876 With argument DAY-OF-YEAR, switch to that day of the year."
6877 (interactive "P")
6878 (org-agenda-change-time-span 'day day-of-year))
6879 (defun org-agenda-week-view (&optional iso-week)
6880 "Switch to daily view for agenda.
6881 With argument ISO-WEEK, switch to the corresponding ISO week.
6882 If ISO-WEEK has more then 2 digits, only the last two encode the
6883 week. Any digits before this encode a year. So 200712 means
6884 week 12 of year 2007. Years in the range 1938-2037 can also be
6885 written as 2-digit years."
6886 (interactive "P")
6887 (org-agenda-change-time-span 'week iso-week))
6888 (defun org-agenda-month-view (&optional month)
6889 "Switch to monthly view for agenda.
6890 With argument MONTH, switch to that month."
6891 (interactive "P")
6892 (org-agenda-change-time-span 'month month))
6893 (defun org-agenda-year-view (&optional year)
6894 "Switch to yearly view for agenda.
6895 With argument YEAR, switch to that year.
6896 If MONTH has more then 2 digits, only the last two encode the
6897 month. Any digits before this encode a year. So 200712 means
6898 December year 2007. Years in the range 1938-2037 can also be
6899 written as 2-digit years."
6900 (interactive "P")
6901 (when year
6902 (setq year (org-small-year-to-year year)))
6903 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6904 (org-agenda-change-time-span 'year year)
6905 (error "Abort")))
6907 (defun org-agenda-change-time-span (span &optional n)
6908 "Change the agenda view to SPAN.
6909 SPAN may be `day', `week', `month', `year'."
6910 (org-agenda-check-type t 'agenda)
6911 (if (and (not n) (equal org-agenda-current-span span))
6912 (error "Viewing span is already \"%s\"" span))
6913 (let* ((sd (or (org-get-at-bol 'day)
6914 org-starting-day))
6915 (sd (org-agenda-compute-starting-span sd span n))
6916 (org-agenda-overriding-arguments
6917 (or org-agenda-overriding-arguments
6918 (list (car org-agenda-last-arguments) sd span t))))
6919 (org-agenda-redo)
6920 (org-agenda-find-same-or-today-or-agenda))
6921 (org-agenda-set-mode-name)
6922 (message "Switched to %s view" span))
6924 (defun org-agenda-compute-starting-span (sd span &optional n)
6925 "Compute starting date for agenda.
6926 SPAN may be `day', `week', `month', `year'. The return value
6927 is a cons cell with the starting date and the number of days,
6928 so that the date SD will be in that range."
6929 (let* ((greg (calendar-gregorian-from-absolute sd))
6930 (dg (nth 1 greg))
6931 (mg (car greg))
6932 (yg (nth 2 greg)))
6933 (cond
6934 ((eq span 'day)
6935 (when n
6936 (setq sd (+ (calendar-absolute-from-gregorian
6937 (list mg 1 yg))
6938 n -1))))
6939 ((eq span 'week)
6940 (let* ((nt (calendar-day-of-week
6941 (calendar-gregorian-from-absolute sd)))
6942 (d (if org-agenda-start-on-weekday
6943 (- nt org-agenda-start-on-weekday)
6946 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
6947 (when n
6948 (require 'cal-iso)
6949 (when (> n 99)
6950 (setq y1 (org-small-year-to-year (/ n 100))
6951 n (mod n 100)))
6952 (setq sd
6953 (calendar-absolute-from-iso
6954 (list n 1
6955 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
6956 ((eq span 'month)
6957 (let (y1)
6958 (when (and n (> n 99))
6959 (setq y1 (org-small-year-to-year (/ n 100))
6960 n (mod n 100)))
6961 (setq sd (calendar-absolute-from-gregorian
6962 (list (or n mg) 1 (or y1 yg))))))
6963 ((eq span 'year)
6964 (setq sd (calendar-absolute-from-gregorian
6965 (list 1 1 (or n yg))))))
6966 sd))
6968 (defun org-agenda-next-date-line (&optional arg)
6969 "Jump to the next line indicating a date in agenda buffer."
6970 (interactive "p")
6971 (org-agenda-check-type t 'agenda 'timeline)
6972 (beginning-of-line 1)
6973 ;; This does not work if user makes date format that starts with a blank
6974 (if (looking-at "^\\S-") (forward-char 1))
6975 (if (not (re-search-forward "^\\S-" nil t arg))
6976 (progn
6977 (backward-char 1)
6978 (error "No next date after this line in this buffer")))
6979 (goto-char (match-beginning 0)))
6981 (defun org-agenda-previous-date-line (&optional arg)
6982 "Jump to the previous line indicating a date in agenda buffer."
6983 (interactive "p")
6984 (org-agenda-check-type t 'agenda 'timeline)
6985 (beginning-of-line 1)
6986 (if (not (re-search-backward "^\\S-" nil t arg))
6987 (error "No previous date before this line in this buffer")))
6989 ;; Initialize the highlight
6990 (defvar org-hl (make-overlay 1 1))
6991 (overlay-put org-hl 'face 'highlight)
6993 (defun org-highlight (begin end &optional buffer)
6994 "Highlight a region with overlay."
6995 (move-overlay org-hl begin end (or buffer (current-buffer))))
6997 (defun org-unhighlight ()
6998 "Detach overlay INDEX."
6999 (org-detach-overlay org-hl))
7001 ;; FIXME this is currently not used.
7002 (defun org-highlight-until-next-command (beg end &optional buffer)
7003 "Move the highlight overlay to BEG/END, remove it before the next command."
7004 (org-highlight beg end buffer)
7005 (add-hook 'pre-command-hook 'org-unhighlight-once))
7006 (defun org-unhighlight-once ()
7007 "Remove the highlight from its position, and this function from the hook."
7008 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7009 (org-unhighlight))
7011 (defun org-agenda-follow-mode ()
7012 "Toggle follow mode in an agenda buffer."
7013 (interactive)
7014 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7015 (org-agenda-set-mode-name)
7016 (org-agenda-do-context-action)
7017 (message "Follow mode is %s"
7018 (if org-agenda-follow-mode "on" "off")))
7020 (defun org-agenda-entry-text-mode (&optional arg)
7021 "Toggle entry text mode in an agenda buffer."
7022 (interactive "P")
7023 (setq org-agenda-entry-text-mode (or (integerp arg)
7024 (not org-agenda-entry-text-mode)))
7025 (org-agenda-entry-text-hide)
7026 (and org-agenda-entry-text-mode
7027 (let ((org-agenda-entry-text-maxlines
7028 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7029 (org-agenda-entry-text-show)))
7030 (org-agenda-set-mode-name)
7031 (message "Entry text mode is %s. Maximum number of lines is %d"
7032 (if org-agenda-entry-text-mode "on" "off")
7033 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7035 (defun org-agenda-clockreport-mode (&optional with-filter)
7036 "Toggle clocktable mode in an agenda buffer.
7037 With prefix arg WITH-FILTER, make the clocktable respect the current
7038 agenda filter."
7039 (interactive "P")
7040 (org-agenda-check-type t 'agenda)
7041 (if with-filter
7042 (setq org-agenda-clockreport-mode 'with-filter)
7043 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7044 (org-agenda-set-mode-name)
7045 (org-agenda-redo)
7046 (message "Clocktable mode is %s"
7047 (if org-agenda-clockreport-mode "on" "off")))
7049 (defun org-agenda-log-mode (&optional special)
7050 "Toggle log mode in an agenda buffer.
7051 With argument SPECIAL, show all possible log items, not only the ones
7052 configured in `org-agenda-log-mode-items'.
7053 With a double `C-u' prefix arg, show *only* log items, nothing else."
7054 (interactive "P")
7055 (org-agenda-check-type t 'agenda 'timeline)
7056 (setq org-agenda-show-log
7057 (cond
7058 ((equal special '(16)) 'only)
7059 ((eq special 'clockcheck)
7060 (if (eq org-agenda-show-log 'clockcheck)
7061 nil 'clockcheck))
7062 (special '(closed clock state))
7063 (t (not org-agenda-show-log))))
7064 (org-agenda-set-mode-name)
7065 (org-agenda-redo)
7066 (message "Log mode is %s"
7067 (if org-agenda-show-log "on" "off")))
7069 (defun org-agenda-archives-mode (&optional with-files)
7070 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7071 When called with a prefix argument, include all archive files as well."
7072 (interactive "P")
7073 (setq org-agenda-archives-mode
7074 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7075 (org-agenda-set-mode-name)
7076 (org-agenda-redo)
7077 (message
7078 "%s"
7079 (cond
7080 ((eq org-agenda-archives-mode nil)
7081 "No archives are included")
7082 ((eq org-agenda-archives-mode 'trees)
7083 (format "Trees with :%s: tag are included" org-archive-tag))
7084 ((eq org-agenda-archives-mode t)
7085 (format "Trees with :%s: tag and all active archive files are included"
7086 org-archive-tag)))))
7088 (defun org-agenda-toggle-diary ()
7089 "Toggle diary inclusion in an agenda buffer."
7090 (interactive)
7091 (org-agenda-check-type t 'agenda)
7092 (setq org-agenda-include-diary (not org-agenda-include-diary))
7093 (org-agenda-redo)
7094 (org-agenda-set-mode-name)
7095 (message "Diary inclusion turned %s"
7096 (if org-agenda-include-diary "on" "off")))
7098 (defun org-agenda-toggle-deadlines ()
7099 "Toggle inclusion of entries with a deadline in an agenda buffer."
7100 (interactive)
7101 (org-agenda-check-type t 'agenda)
7102 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7103 (org-agenda-redo)
7104 (org-agenda-set-mode-name)
7105 (message "Deadlines inclusion turned %s"
7106 (if org-agenda-include-deadlines "on" "off")))
7108 (defun org-agenda-toggle-time-grid ()
7109 "Toggle time grid in an agenda buffer."
7110 (interactive)
7111 (org-agenda-check-type t 'agenda)
7112 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7113 (org-agenda-redo)
7114 (org-agenda-set-mode-name)
7115 (message "Time-grid turned %s"
7116 (if org-agenda-use-time-grid "on" "off")))
7118 (defun org-agenda-set-mode-name ()
7119 "Set the mode name to indicate all the small mode settings."
7120 (setq mode-name
7121 (list "Org-Agenda"
7122 (if (get 'org-agenda-files 'org-restrict) " []" "")
7124 '(:eval (org-agenda-span-name org-agenda-current-span))
7125 (if org-agenda-follow-mode " Follow" "")
7126 (if org-agenda-entry-text-mode " ETxt" "")
7127 (if org-agenda-include-diary " Diary" "")
7128 (if org-agenda-include-deadlines " Ddl" "")
7129 (if org-agenda-use-time-grid " Grid" "")
7130 (if (and (boundp 'org-habit-show-habits)
7131 org-habit-show-habits) " Habit" "")
7132 (cond
7133 ((consp org-agenda-show-log) " LogAll")
7134 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7135 (org-agenda-show-log " Log")
7136 (t ""))
7137 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7138 :preset-filter))
7139 '(:eval (org-propertize
7140 (concat " <"
7141 (mapconcat
7142 'identity
7143 (append
7144 (get 'org-agenda-category-filter :preset-filter)
7145 org-agenda-category-filter)
7147 ">")
7148 'face 'org-agenda-filter-category
7149 'help-echo "Category used in filtering"))
7151 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7152 :preset-filter))
7153 '(:eval (org-propertize
7154 (concat " {"
7155 (mapconcat
7156 'identity
7157 (append
7158 (get 'org-agenda-tag-filter :preset-filter)
7159 org-agenda-tag-filter)
7161 "}")
7162 'face 'org-agenda-filter-tags
7163 'help-echo "Tags used in filtering"))
7165 (if org-agenda-archives-mode
7166 (if (eq org-agenda-archives-mode t)
7167 " Archives"
7168 (format " :%s:" org-archive-tag))
7170 (if org-agenda-clockreport-mode
7171 (if (eq org-agenda-clockreport-mode 'with-filter)
7172 " Clock{}" " Clock")
7173 "")))
7174 (force-mode-line-update))
7176 (defun org-agenda-post-command-hook ()
7177 (setq org-agenda-type
7178 (or (get-text-property (point) 'org-agenda-type)
7179 (get-text-property (max (point-min) (1- (point)))
7180 'org-agenda-type))))
7182 (defun org-agenda-next-line ()
7183 "Move cursor to the next line, and show if follow mode is active."
7184 (interactive)
7185 (call-interactively 'next-line)
7186 (org-agenda-do-context-action))
7188 (defun org-agenda-previous-line ()
7189 "Move cursor to the previous line, and show if follow-mode is active."
7190 (interactive)
7191 (call-interactively 'previous-line)
7192 (org-agenda-do-context-action))
7194 (defun org-agenda-do-context-action ()
7195 "Show outline path and, maybe, follow mode window."
7196 (let ((m (org-get-at-bol 'org-marker)))
7197 (when (and (markerp m) (marker-buffer m))
7198 (and org-agenda-follow-mode
7199 (if org-agenda-follow-indirect
7200 (org-agenda-tree-to-indirect-buffer)
7201 (org-agenda-show)))
7202 (and org-agenda-show-outline-path
7203 (org-with-point-at m (org-display-outline-path t))))))
7205 (defun org-agenda-show-priority ()
7206 "Show the priority of the current item.
7207 This priority is composed of the main priority given with the [#A] cookies,
7208 and by additional input from the age of a schedules or deadline entry."
7209 (interactive)
7210 (let* ((pri (org-get-at-bol 'priority)))
7211 (message "Priority is %d" (if pri pri -1000))))
7213 (defun org-agenda-show-tags ()
7214 "Show the tags applicable to the current item."
7215 (interactive)
7216 (let* ((tags (org-get-at-bol 'tags)))
7217 (if tags
7218 (message "Tags are :%s:"
7219 (org-no-properties (mapconcat 'identity tags ":")))
7220 (message "No tags associated with this line"))))
7222 (defun org-agenda-goto (&optional highlight)
7223 "Go to the Org-mode file which contains the item at point."
7224 (interactive)
7225 (let* ((marker (or (org-get-at-bol 'org-marker)
7226 (org-agenda-error)))
7227 (buffer (marker-buffer marker))
7228 (pos (marker-position marker)))
7229 (switch-to-buffer-other-window buffer)
7230 (widen)
7231 (push-mark)
7232 (goto-char pos)
7233 (when (eq major-mode 'org-mode)
7234 (org-show-context 'agenda)
7235 (save-excursion
7236 (and (outline-next-heading)
7237 (org-flag-heading nil)))) ; show the next heading
7238 (when (outline-invisible-p)
7239 (show-entry)) ; display invisible text
7240 (recenter (/ (window-height) 2))
7241 (run-hooks 'org-agenda-after-show-hook)
7242 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7244 (defvar org-agenda-after-show-hook nil
7245 "Normal hook run after an item has been shown from the agenda.
7246 Point is in the buffer where the item originated.")
7248 (defun org-agenda-kill ()
7249 "Kill the entry or subtree belonging to the current agenda entry."
7250 (interactive)
7251 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7252 (let* ((marker (or (org-get-at-bol 'org-marker)
7253 (org-agenda-error)))
7254 (buffer (marker-buffer marker))
7255 (pos (marker-position marker))
7256 (type (org-get-at-bol 'type))
7257 dbeg dend (n 0) conf)
7258 (org-with-remote-undo buffer
7259 (with-current-buffer buffer
7260 (save-excursion
7261 (goto-char pos)
7262 (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
7263 (setq dbeg (progn (org-back-to-heading t) (point))
7264 dend (org-end-of-subtree t t))
7265 (setq dbeg (point-at-bol)
7266 dend (min (point-max) (1+ (point-at-eol)))))
7267 (goto-char dbeg)
7268 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7269 (setq conf (or (eq t org-agenda-confirm-kill)
7270 (and (numberp org-agenda-confirm-kill)
7271 (> n org-agenda-confirm-kill))))
7272 (and conf
7273 (not (y-or-n-p
7274 (format "Delete entry with %d lines in buffer \"%s\"? "
7275 n (buffer-name buffer))))
7276 (error "Abort"))
7277 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7278 (with-current-buffer buffer (delete-region dbeg dend))
7279 (message "Agenda item and source killed"))))
7281 (defvar org-archive-default-command)
7282 (defun org-agenda-archive-default ()
7283 "Archive the entry or subtree belonging to the current agenda entry."
7284 (interactive)
7285 (require 'org-archive)
7286 (org-agenda-archive-with org-archive-default-command))
7288 (defun org-agenda-archive-default-with-confirmation ()
7289 "Archive the entry or subtree belonging to the current agenda entry."
7290 (interactive)
7291 (require 'org-archive)
7292 (org-agenda-archive-with org-archive-default-command 'confirm))
7294 (defun org-agenda-archive ()
7295 "Archive the entry or subtree belonging to the current agenda entry."
7296 (interactive)
7297 (org-agenda-archive-with 'org-archive-subtree))
7299 (defun org-agenda-archive-to-archive-sibling ()
7300 "Move the entry to the archive sibling."
7301 (interactive)
7302 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7304 (defun org-agenda-archive-with (cmd &optional confirm)
7305 "Move the entry to the archive sibling."
7306 (interactive)
7307 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7308 (let* ((marker (or (org-get-at-bol 'org-marker)
7309 (org-agenda-error)))
7310 (buffer (marker-buffer marker))
7311 (pos (marker-position marker)))
7312 (org-with-remote-undo buffer
7313 (with-current-buffer buffer
7314 (if (eq major-mode 'org-mode)
7315 (if (and confirm
7316 (not (y-or-n-p "Archive this subtree or entry? ")))
7317 (error "Abort")
7318 (save-excursion
7319 (goto-char pos)
7320 (org-remove-subtree-entries-from-agenda)
7321 (org-back-to-heading t)
7322 (funcall cmd)))
7323 (error "Archiving works only in Org-mode files"))))))
7325 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7326 "Remove all lines in the agenda that correspond to a given subtree.
7327 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7328 If this information is not given, the function uses the tree at point."
7329 (let ((buf (or buf (current-buffer))) m p)
7330 (save-excursion
7331 (unless (and beg end)
7332 (org-back-to-heading t)
7333 (setq beg (point))
7334 (org-end-of-subtree t)
7335 (setq end (point)))
7336 (set-buffer (get-buffer org-agenda-buffer-name))
7337 (save-excursion
7338 (goto-char (point-max))
7339 (beginning-of-line 1)
7340 (while (not (bobp))
7341 (when (and (setq m (org-get-at-bol 'org-marker))
7342 (equal buf (marker-buffer m))
7343 (setq p (marker-position m))
7344 (>= p beg)
7345 (< p end))
7346 (let ((inhibit-read-only t))
7347 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7348 (beginning-of-line 0))))))
7350 (defun org-agenda-refile (&optional goto rfloc no-update)
7351 "Refile the item at point."
7352 (interactive "P")
7353 (if (equal goto '(16))
7354 (org-refile-goto-last-stored)
7355 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7356 (org-agenda-error)))
7357 (buffer (marker-buffer marker))
7358 (pos (marker-position marker))
7359 (rfloc (or rfloc
7360 (org-refile-get-location
7361 (if goto "Goto" "Refile to") buffer
7362 org-refile-allow-creating-parent-nodes))))
7363 (with-current-buffer buffer
7364 (save-excursion
7365 (save-restriction
7366 (widen)
7367 (goto-char marker)
7368 (org-remove-subtree-entries-from-agenda)
7369 (org-refile goto buffer rfloc)))))
7370 (unless no-update (org-agenda-redo))))
7372 (defun org-agenda-open-link (&optional arg)
7373 "Follow the link in the current line, if any.
7374 This looks for a link in the displayed line in the agenda. It also looks
7375 at the text of the entry itself."
7376 (interactive "P")
7377 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7378 (org-get-at-bol 'org-marker)))
7379 (buffer (and marker (marker-buffer marker)))
7380 (prefix (buffer-substring
7381 (point-at-bol) (point-at-eol))))
7382 (cond
7383 (buffer
7384 (with-current-buffer buffer
7385 (save-excursion
7386 (save-restriction
7387 (widen)
7388 (goto-char marker)
7389 (org-offer-links-in-entry arg prefix)))))
7390 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7391 (save-excursion
7392 (beginning-of-line 1)
7393 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7394 (org-open-link-from-string (match-string 1)))
7395 (t (error "No link to open here")))))
7397 (defun org-agenda-copy-local-variable (var)
7398 "Get a variable from a referenced buffer and install it here."
7399 (let ((m (org-get-at-bol 'org-marker)))
7400 (when (and m (buffer-live-p (marker-buffer m)))
7401 (org-set-local var (with-current-buffer (marker-buffer m)
7402 (symbol-value var))))))
7404 (defun org-agenda-switch-to (&optional delete-other-windows)
7405 "Go to the Org-mode file which contains the item at point."
7406 (interactive)
7407 (if (and org-return-follows-link
7408 (not (org-get-at-bol 'org-marker))
7409 (org-in-regexp org-bracket-link-regexp))
7410 (org-open-link-from-string (match-string 0))
7411 (let* ((marker (or (org-get-at-bol 'org-marker)
7412 (org-agenda-error)))
7413 (buffer (marker-buffer marker))
7414 (pos (marker-position marker)))
7415 (org-pop-to-buffer-same-window buffer)
7416 (and delete-other-windows (delete-other-windows))
7417 (widen)
7418 (goto-char pos)
7419 (when (eq major-mode 'org-mode)
7420 (org-show-context 'agenda)
7421 (save-excursion
7422 (and (outline-next-heading)
7423 (org-flag-heading nil))) ; show the next heading
7424 (when (outline-invisible-p)
7425 (show-entry)))))) ; display invisible text
7427 (defun org-agenda-goto-mouse (ev)
7428 "Go to the Org-mode file which contains the item at the mouse click."
7429 (interactive "e")
7430 (mouse-set-point ev)
7431 (org-agenda-goto))
7433 (defun org-agenda-show (&optional full-entry)
7434 "Display the Org-mode file which contains the item at point.
7435 With prefix argument FULL-ENTRY, make the entire entry visible
7436 if it was hidden in the outline."
7437 (interactive "P")
7438 (let ((win (selected-window)))
7439 (if full-entry
7440 (let ((org-show-entry-below t))
7441 (org-agenda-goto t))
7442 (org-agenda-goto t))
7443 (select-window win)))
7445 (defvar org-agenda-show-window nil)
7446 (defun org-agenda-show-and-scroll-up (&optional arg)
7447 "Display the Org-mode file which contains the item at point.
7448 When called repeatedly, scroll the window that is displaying the buffer.
7449 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7450 `show-subtree' to display the item, so that drawers and logbooks stay
7451 folded."
7452 (interactive "P")
7453 (let ((win (selected-window)))
7454 (if (and (window-live-p org-agenda-show-window)
7455 (eq this-command last-command))
7456 (progn
7457 (select-window org-agenda-show-window)
7458 (ignore-errors (scroll-up)))
7459 (org-agenda-goto t)
7460 (if arg (org-show-entry) (show-subtree))
7461 (setq org-agenda-show-window (selected-window)))
7462 (select-window win)))
7464 (defun org-agenda-show-scroll-down ()
7465 "Scroll down the window showing the agenda."
7466 (interactive)
7467 (let ((win (selected-window)))
7468 (when (window-live-p org-agenda-show-window)
7469 (select-window org-agenda-show-window)
7470 (ignore-errors (scroll-down))
7471 (select-window win))))
7473 (defun org-agenda-show-1 (&optional more)
7474 "Display the Org-mode file which contains the item at point.
7475 The prefix arg selects the amount of information to display:
7477 0 hide the subtree
7478 1 just show the entry according to defaults.
7479 2 show the children view
7480 3 show the subtree view
7481 4 show the entire subtree and any LOGBOOK drawers
7482 5 show the entire subtree and any drawers
7483 With prefix argument FULL-ENTRY, make the entire entry visible
7484 if it was hidden in the outline."
7485 (interactive "p")
7486 (let ((win (selected-window)))
7487 (org-agenda-goto t)
7488 (org-recenter-heading 1)
7489 (cond
7490 ((= more 0)
7491 (hide-subtree)
7492 (save-excursion
7493 (org-back-to-heading)
7494 (run-hook-with-args 'org-cycle-hook 'folded))
7495 (message "Remote: FOLDED"))
7496 ((and (org-called-interactively-p 'any) (= more 1))
7497 (message "Remote: show with default settings"))
7498 ((= more 2)
7499 (show-entry)
7500 (show-children)
7501 (save-excursion
7502 (org-back-to-heading)
7503 (run-hook-with-args 'org-cycle-hook 'children))
7504 (message "Remote: CHILDREN"))
7505 ((= more 3)
7506 (show-subtree)
7507 (save-excursion
7508 (org-back-to-heading)
7509 (run-hook-with-args 'org-cycle-hook 'subtree))
7510 (message "Remote: SUBTREE"))
7511 ((= more 4)
7512 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7513 (org-drawer-regexp
7514 (concat "^[ \t]*:\\("
7515 (mapconcat 'regexp-quote org-drawers "\\|")
7516 "\\):[ \t]*$")))
7517 (show-subtree)
7518 (save-excursion
7519 (org-back-to-heading)
7520 (org-cycle-hide-drawers 'subtree)))
7521 (message "Remote: SUBTREE AND LOGBOOK"))
7522 ((> more 4)
7523 (show-subtree)
7524 (message "Remote: SUBTREE AND ALL DRAWERS")))
7525 (select-window win)))
7527 (defun org-recenter-heading (n)
7528 (save-excursion
7529 (org-back-to-heading)
7530 (recenter n)))
7532 (defvar org-agenda-cycle-counter nil)
7533 (defun org-agenda-cycle-show (&optional n)
7534 "Show the current entry in another window, with default settings.
7535 Default settings are taken from `org-show-hierarchy-above' and siblings.
7536 When use repeatedly in immediate succession, the remote entry will cycle
7537 through visibility
7539 children -> subtree -> folded
7541 When called with a numeric prefix arg, that arg will be passed through to
7542 `org-agenda-show-1'. For the interpretation of that argument, see the
7543 docstring of `org-agenda-show-1'."
7544 (interactive "P")
7545 (if (integerp n)
7546 (setq org-agenda-cycle-counter n)
7547 (if (not (eq last-command this-command))
7548 (setq org-agenda-cycle-counter 1)
7549 (if (equal org-agenda-cycle-counter 0)
7550 (setq org-agenda-cycle-counter 2)
7551 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7552 (if (> org-agenda-cycle-counter 3)
7553 (setq org-agenda-cycle-counter 0)))))
7554 (org-agenda-show-1 org-agenda-cycle-counter))
7556 (defun org-agenda-recenter (arg)
7557 "Display the Org-mode file which contains the item at point and recenter."
7558 (interactive "P")
7559 (let ((win (selected-window)))
7560 (org-agenda-goto t)
7561 (recenter arg)
7562 (select-window win)))
7564 (defun org-agenda-show-mouse (ev)
7565 "Display the Org-mode file which contains the item at the mouse click."
7566 (interactive "e")
7567 (mouse-set-point ev)
7568 (org-agenda-show))
7570 (defun org-agenda-check-no-diary ()
7571 "Check if the entry is a diary link and abort if yes."
7572 (if (org-get-at-bol 'org-agenda-diary-link)
7573 (org-agenda-error)))
7575 (defun org-agenda-error ()
7576 (error "Command not allowed in this line"))
7578 (defun org-agenda-tree-to-indirect-buffer ()
7579 "Show the subtree corresponding to the current entry in an indirect buffer.
7580 This calls the command `org-tree-to-indirect-buffer' from the original
7581 Org-mode buffer.
7582 With numerical prefix arg ARG, go up to this level and then take that tree.
7583 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7584 use the dedicated frame)."
7585 (interactive)
7586 (if (and current-prefix-arg (listp current-prefix-arg))
7587 (org-agenda-do-tree-to-indirect-buffer)
7588 (let ((agenda-window (selected-window))
7589 (indirect-window
7590 (and org-last-indirect-buffer
7591 (get-buffer-window org-last-indirect-buffer))))
7592 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7593 (unwind-protect
7594 (progn
7595 (unless (and indirect-window (window-live-p indirect-window))
7596 (setq indirect-window (split-window agenda-window)))
7597 (select-window indirect-window)
7598 (switch-to-buffer org-last-indirect-buffer :norecord)
7599 (fit-window-to-buffer indirect-window))
7600 (select-window (get-buffer-window org-agenda-buffer-name))))))
7602 (defun org-agenda-do-tree-to-indirect-buffer ()
7603 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7604 (org-agenda-check-no-diary)
7605 (let* ((marker (or (org-get-at-bol 'org-marker)
7606 (org-agenda-error)))
7607 (buffer (marker-buffer marker))
7608 (pos (marker-position marker)))
7609 (with-current-buffer buffer
7610 (save-excursion
7611 (goto-char pos)
7612 (call-interactively 'org-tree-to-indirect-buffer)))))
7614 (defvar org-last-heading-marker (make-marker)
7615 "Marker pointing to the headline that last changed its TODO state
7616 by a remote command from the agenda.")
7618 (defun org-agenda-todo-nextset ()
7619 "Switch TODO entry to next sequence."
7620 (interactive)
7621 (org-agenda-todo 'nextset))
7623 (defun org-agenda-todo-previousset ()
7624 "Switch TODO entry to previous sequence."
7625 (interactive)
7626 (org-agenda-todo 'previousset))
7628 (defun org-agenda-todo (&optional arg)
7629 "Cycle TODO state of line at point, also in Org-mode file.
7630 This changes the line at point, all other lines in the agenda referring to
7631 the same tree node, and the headline of the tree node in the Org-mode file."
7632 (interactive "P")
7633 (org-agenda-check-no-diary)
7634 (let* ((col (current-column))
7635 (marker (or (org-get-at-bol 'org-marker)
7636 (org-agenda-error)))
7637 (buffer (marker-buffer marker))
7638 (pos (marker-position marker))
7639 (hdmarker (org-get-at-bol 'org-hd-marker))
7640 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7641 (inhibit-read-only t)
7642 org-agenda-headline-snapshot-before-repeat newhead just-one)
7643 (org-with-remote-undo buffer
7644 (with-current-buffer buffer
7645 (widen)
7646 (goto-char pos)
7647 (org-show-context 'agenda)
7648 (save-excursion
7649 (and (outline-next-heading)
7650 (org-flag-heading nil))) ; show the next heading
7651 (let ((current-prefix-arg arg))
7652 (call-interactively 'org-todo))
7653 (and (bolp) (forward-char 1))
7654 (setq newhead (org-get-heading))
7655 (when (and (org-bound-and-true-p
7656 org-agenda-headline-snapshot-before-repeat)
7657 (not (equal org-agenda-headline-snapshot-before-repeat
7658 newhead))
7659 todayp)
7660 (setq newhead org-agenda-headline-snapshot-before-repeat
7661 just-one t))
7662 (save-excursion
7663 (org-back-to-heading)
7664 (move-marker org-last-heading-marker (point))))
7665 (beginning-of-line 1)
7666 (save-excursion
7667 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7668 (org-move-to-column col))))
7670 (defun org-agenda-add-note (&optional arg)
7671 "Add a time-stamped note to the entry at point."
7672 (interactive "P")
7673 (org-agenda-check-no-diary)
7674 (let* ((marker (or (org-get-at-bol 'org-marker)
7675 (org-agenda-error)))
7676 (buffer (marker-buffer marker))
7677 (pos (marker-position marker))
7678 (hdmarker (org-get-at-bol 'org-hd-marker))
7679 (inhibit-read-only t))
7680 (with-current-buffer buffer
7681 (widen)
7682 (goto-char pos)
7683 (org-show-context 'agenda)
7684 (save-excursion
7685 (and (outline-next-heading)
7686 (org-flag-heading nil))) ; show the next heading
7687 (org-add-note))))
7689 (defun org-agenda-change-all-lines (newhead hdmarker
7690 &optional fixface just-this)
7691 "Change all lines in the agenda buffer which match HDMARKER.
7692 The new content of the line will be NEWHEAD (as modified by
7693 `org-agenda-format-item'). HDMARKER is checked with
7694 `equal' against all `org-hd-marker' text properties in the file.
7695 If FIXFACE is non-nil, the face of each item is modified according to
7696 the new TODO state.
7697 If JUST-THIS is non-nil, change just the current line, not all.
7698 If FORCE-TAGS is non nil, the car of it returns the new tags."
7699 (let* ((inhibit-read-only t)
7700 (line (org-current-line))
7701 (org-agenda-buffer (current-buffer))
7702 (thetags (with-current-buffer (marker-buffer hdmarker)
7703 (save-excursion (save-restriction (widen)
7704 (goto-char hdmarker)
7705 (org-get-tags-at)))))
7706 props m pl undone-face done-face finish new dotime cat tags)
7707 (save-excursion
7708 (goto-char (point-max))
7709 (beginning-of-line 1)
7710 (while (not finish)
7711 (setq finish (bobp))
7712 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7713 (or (not just-this) (= (org-current-line) line))
7714 (equal m hdmarker))
7715 (setq props (text-properties-at (point))
7716 dotime (org-get-at-bol 'dotime)
7717 cat (org-get-at-bol 'org-category)
7718 tags thetags
7720 (let ((org-prefix-format-compiled
7721 (or (get-text-property (point) 'format)
7722 org-prefix-format-compiled))
7723 (extra (org-get-at-bol 'extra)))
7724 (with-current-buffer (marker-buffer hdmarker)
7725 (save-excursion
7726 (save-restriction
7727 (widen)
7728 (org-agenda-format-item extra newhead cat tags dotime)))))
7729 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7730 undone-face (org-get-at-bol 'undone-face)
7731 done-face (org-get-at-bol 'done-face))
7732 (beginning-of-line 1)
7733 (cond
7734 ((equal new "")
7735 (and (looking-at ".*\n?") (replace-match "")))
7736 ((looking-at ".*")
7737 (replace-match new t t)
7738 (beginning-of-line 1)
7739 (add-text-properties (point-at-bol) (point-at-eol) props)
7740 (when fixface
7741 (add-text-properties
7742 (point-at-bol) (point-at-eol)
7743 (list 'face
7744 (if org-last-todo-state-is-todo
7745 undone-face done-face))))
7746 (org-agenda-highlight-todo 'line)
7747 (beginning-of-line 1))
7748 (t (error "Line update did not work"))))
7749 (beginning-of-line 0)))
7750 (org-finalize-agenda)))
7752 (defun org-agenda-align-tags (&optional line)
7753 "Align all tags in agenda items to `org-agenda-tags-column'."
7754 (let ((inhibit-read-only t) l c)
7755 (save-excursion
7756 (goto-char (if line (point-at-bol) (point-min)))
7757 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7758 (if line (point-at-eol) nil) t)
7759 (add-text-properties
7760 (match-beginning 2) (match-end 2)
7761 (list 'face (delq nil (let ((prop (get-text-property
7762 (match-beginning 2) 'face)))
7763 (or (listp prop) (setq prop (list prop)))
7764 (if (memq 'org-tag prop)
7765 prop
7766 (cons 'org-tag prop))))))
7767 (setq l (- (match-end 2) (match-beginning 2))
7768 c (if (< org-agenda-tags-column 0)
7769 (- (abs org-agenda-tags-column) l)
7770 org-agenda-tags-column))
7771 (delete-region (match-beginning 1) (match-end 1))
7772 (goto-char (match-beginning 1))
7773 (insert (org-add-props
7774 (make-string (max 1 (- c (current-column))) ?\ )
7775 (plist-put (copy-sequence (text-properties-at (point)))
7776 'face nil))))
7777 (goto-char (point-min))
7778 (org-font-lock-add-tag-faces (point-max)))))
7780 (defun org-agenda-priority-up ()
7781 "Increase the priority of line at point, also in Org-mode file."
7782 (interactive)
7783 (org-agenda-priority 'up))
7785 (defun org-agenda-priority-down ()
7786 "Decrease the priority of line at point, also in Org-mode file."
7787 (interactive)
7788 (org-agenda-priority 'down))
7790 (defun org-agenda-priority (&optional force-direction)
7791 "Set the priority of line at point, also in Org-mode file.
7792 This changes the line at point, all other lines in the agenda referring to
7793 the same tree node, and the headline of the tree node in the Org-mode file."
7794 (interactive)
7795 (unless org-enable-priority-commands
7796 (error "Priority commands are disabled"))
7797 (org-agenda-check-no-diary)
7798 (let* ((marker (or (org-get-at-bol 'org-marker)
7799 (org-agenda-error)))
7800 (hdmarker (org-get-at-bol 'org-hd-marker))
7801 (buffer (marker-buffer hdmarker))
7802 (pos (marker-position hdmarker))
7803 (inhibit-read-only t)
7804 newhead)
7805 (org-with-remote-undo buffer
7806 (with-current-buffer buffer
7807 (widen)
7808 (goto-char pos)
7809 (org-show-context 'agenda)
7810 (save-excursion
7811 (and (outline-next-heading)
7812 (org-flag-heading nil))) ; show the next heading
7813 (funcall 'org-priority force-direction)
7814 (end-of-line 1)
7815 (setq newhead (org-get-heading)))
7816 (org-agenda-change-all-lines newhead hdmarker)
7817 (beginning-of-line 1))))
7819 ;; FIXME: should fix the tags property of the agenda line.
7820 (defun org-agenda-set-tags (&optional tag onoff)
7821 "Set tags for the current headline."
7822 (interactive)
7823 (org-agenda-check-no-diary)
7824 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7825 (call-interactively 'org-change-tag-in-region)
7826 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7827 (org-agenda-error)))
7828 (buffer (marker-buffer hdmarker))
7829 (pos (marker-position hdmarker))
7830 (inhibit-read-only t)
7831 newhead)
7832 (org-with-remote-undo buffer
7833 (with-current-buffer buffer
7834 (widen)
7835 (goto-char pos)
7836 (save-excursion
7837 (org-show-context 'agenda))
7838 (save-excursion
7839 (and (outline-next-heading)
7840 (org-flag-heading nil))) ; show the next heading
7841 (goto-char pos)
7842 (if tag
7843 (org-toggle-tag tag onoff)
7844 (call-interactively 'org-set-tags))
7845 (end-of-line 1)
7846 (setq newhead (org-get-heading)))
7847 (org-agenda-change-all-lines newhead hdmarker)
7848 (beginning-of-line 1)))))
7850 (defun org-agenda-set-property ()
7851 "Set a property for the current headline."
7852 (interactive)
7853 (org-agenda-check-no-diary)
7854 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7855 (org-agenda-error)))
7856 (buffer (marker-buffer hdmarker))
7857 (pos (marker-position hdmarker))
7858 (inhibit-read-only t)
7859 newhead)
7860 (org-with-remote-undo buffer
7861 (with-current-buffer buffer
7862 (widen)
7863 (goto-char pos)
7864 (save-excursion
7865 (org-show-context 'agenda))
7866 (save-excursion
7867 (and (outline-next-heading)
7868 (org-flag-heading nil))) ; show the next heading
7869 (goto-char pos)
7870 (call-interactively 'org-set-property)))))
7872 (defun org-agenda-set-effort ()
7873 "Set the effort property for the current headline."
7874 (interactive)
7875 (org-agenda-check-no-diary)
7876 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7877 (org-agenda-error)))
7878 (buffer (marker-buffer hdmarker))
7879 (pos (marker-position hdmarker))
7880 (inhibit-read-only t)
7881 newhead)
7882 (org-with-remote-undo buffer
7883 (with-current-buffer buffer
7884 (widen)
7885 (goto-char pos)
7886 (save-excursion
7887 (org-show-context 'agenda))
7888 (save-excursion
7889 (and (outline-next-heading)
7890 (org-flag-heading nil))) ; show the next heading
7891 (goto-char pos)
7892 (call-interactively 'org-set-effort)
7893 (end-of-line 1)
7894 (setq newhead (org-get-heading)))
7895 (org-agenda-change-all-lines newhead hdmarker))))
7897 (defun org-agenda-toggle-archive-tag ()
7898 "Toggle the archive tag for the current entry."
7899 (interactive)
7900 (org-agenda-check-no-diary)
7901 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7902 (org-agenda-error)))
7903 (buffer (marker-buffer hdmarker))
7904 (pos (marker-position hdmarker))
7905 (inhibit-read-only t)
7906 newhead)
7907 (org-with-remote-undo buffer
7908 (with-current-buffer buffer
7909 (widen)
7910 (goto-char pos)
7911 (org-show-context 'agenda)
7912 (save-excursion
7913 (and (outline-next-heading)
7914 (org-flag-heading nil))) ; show the next heading
7915 (call-interactively 'org-toggle-archive-tag)
7916 (end-of-line 1)
7917 (setq newhead (org-get-heading)))
7918 (org-agenda-change-all-lines newhead hdmarker)
7919 (beginning-of-line 1))))
7921 (defun org-agenda-do-date-later (arg)
7922 (interactive "P")
7923 (cond
7924 ((or (equal arg '(16))
7925 (memq last-command
7926 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7927 (setq this-command 'org-agenda-date-later-minutes)
7928 (org-agenda-date-later-minutes 1))
7929 ((or (equal arg '(4))
7930 (memq last-command
7931 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7932 (setq this-command 'org-agenda-date-later-hours)
7933 (org-agenda-date-later-hours 1))
7935 (org-agenda-date-later (prefix-numeric-value arg)))))
7937 (defun org-agenda-do-date-earlier (arg)
7938 (interactive "P")
7939 (cond
7940 ((or (equal arg '(16))
7941 (memq last-command
7942 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
7943 (setq this-command 'org-agenda-date-earlier-minutes)
7944 (org-agenda-date-earlier-minutes 1))
7945 ((or (equal arg '(4))
7946 (memq last-command
7947 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
7948 (setq this-command 'org-agenda-date-earlier-hours)
7949 (org-agenda-date-earlier-hours 1))
7951 (org-agenda-date-earlier (prefix-numeric-value arg)))))
7953 (defun org-agenda-date-later (arg &optional what)
7954 "Change the date of this item to ARG day(s) later."
7955 (interactive "p")
7956 (org-agenda-check-type t 'agenda 'timeline)
7957 (org-agenda-check-no-diary)
7958 (let* ((marker (or (org-get-at-bol 'org-marker)
7959 (org-agenda-error)))
7960 (buffer (marker-buffer marker))
7961 (pos (marker-position marker))
7962 cdate today)
7963 (org-with-remote-undo buffer
7964 (with-current-buffer buffer
7965 (widen)
7966 (goto-char pos)
7967 (if (not (org-at-timestamp-p))
7968 (error "Cannot find time stamp"))
7969 (when (and org-agenda-move-date-from-past-immediately-to-today
7970 (equal arg 1)
7971 (or (not what) (eq what 'day))
7972 (not (save-match-data (org-at-date-range-p))))
7973 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
7974 cdate (calendar-absolute-from-gregorian
7975 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
7976 today (org-today))
7977 (if (> today cdate)
7978 ;; immediately shift to today
7979 (setq arg (- today cdate))))
7980 (org-timestamp-change arg (or what 'day))
7981 (when (and (org-at-date-range-p)
7982 (re-search-backward org-tr-regexp-both (point-at-bol)))
7983 (let ((end org-last-changed-timestamp))
7984 (org-timestamp-change arg (or what 'day))
7985 (setq org-last-changed-timestamp
7986 (concat org-last-changed-timestamp "--" end)))))
7987 (org-agenda-show-new-time marker org-last-changed-timestamp))
7988 (message "Time stamp changed to %s" org-last-changed-timestamp)))
7990 (defun org-agenda-date-earlier (arg &optional what)
7991 "Change the date of this item to ARG day(s) earlier."
7992 (interactive "p")
7993 (org-agenda-date-later (- arg) what))
7995 (defun org-agenda-date-later-minutes (arg)
7996 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
7997 (interactive "p")
7998 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
7999 (org-agenda-date-later arg 'minute))
8001 (defun org-agenda-date-earlier-minutes (arg)
8002 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8003 (interactive "p")
8004 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8005 (org-agenda-date-earlier arg 'minute))
8007 (defun org-agenda-date-later-hours (arg)
8008 "Change the time of this item, in hour steps."
8009 (interactive "p")
8010 (org-agenda-date-later arg 'hour))
8012 (defun org-agenda-date-earlier-hours (arg)
8013 "Change the time of this item, in hour steps."
8014 (interactive "p")
8015 (org-agenda-date-earlier arg 'hour))
8017 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8018 "Show new date stamp via text properties."
8019 ;; We use text properties to make this undoable
8020 (let ((inhibit-read-only t)
8021 (buffer-invisibility-spec))
8022 (setq stamp (concat " " prefix " => " stamp))
8023 (save-excursion
8024 (goto-char (point-max))
8025 (while (not (bobp))
8026 (when (equal marker (org-get-at-bol 'org-marker))
8027 (org-move-to-column (- (window-width) (length stamp)) t)
8028 (org-agenda-fix-tags-filter-overlays-at (point))
8029 (if (featurep 'xemacs)
8030 ;; Use `duplicable' property to trigger undo recording
8031 (let ((ex (make-extent nil nil))
8032 (gl (make-glyph stamp)))
8033 (set-glyph-face gl 'secondary-selection)
8034 (set-extent-properties
8035 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8036 (insert-extent ex (1- (point)) (point-at-eol)))
8037 (add-text-properties
8038 (1- (point)) (point-at-eol)
8039 (list 'display (org-add-props stamp nil
8040 'face 'secondary-selection))))
8041 (beginning-of-line 1))
8042 (beginning-of-line 0)))))
8044 (defun org-agenda-date-prompt (arg)
8045 "Change the date of this item. Date is prompted for, with default today.
8046 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8047 be used to request time specification in the time stamp."
8048 (interactive "P")
8049 (org-agenda-check-type t 'agenda 'timeline)
8050 (org-agenda-check-no-diary)
8051 (let* ((marker (or (org-get-at-bol 'org-marker)
8052 (org-agenda-error)))
8053 (buffer (marker-buffer marker))
8054 (pos (marker-position marker)))
8055 (org-with-remote-undo buffer
8056 (with-current-buffer buffer
8057 (widen)
8058 (goto-char pos)
8059 (if (not (org-at-timestamp-p t))
8060 (error "Cannot find time stamp"))
8061 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8062 (org-agenda-show-new-time marker org-last-changed-timestamp))
8063 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8065 (defun org-agenda-schedule (arg &optional time)
8066 "Schedule the item at point.
8067 ARG is passed through to `org-schedule'."
8068 (interactive "P")
8069 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8070 (org-agenda-check-no-diary)
8071 (let* ((marker (or (org-get-at-bol 'org-marker)
8072 (org-agenda-error)))
8073 (type (marker-insertion-type marker))
8074 (buffer (marker-buffer marker))
8075 (pos (marker-position marker))
8076 (org-insert-labeled-timestamps-at-point nil)
8078 (set-marker-insertion-type marker t)
8079 (org-with-remote-undo buffer
8080 (with-current-buffer buffer
8081 (widen)
8082 (goto-char pos)
8083 (setq ts (org-schedule arg time)))
8084 (org-agenda-show-new-time marker ts "S"))
8085 (message "Item scheduled for %s" ts)))
8087 (defun org-agenda-deadline (arg &optional time)
8088 "Schedule the item at point.
8089 ARG is passed through to `org-deadline'."
8090 (interactive "P")
8091 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8092 (org-agenda-check-no-diary)
8093 (let* ((marker (or (org-get-at-bol 'org-marker)
8094 (org-agenda-error)))
8095 (buffer (marker-buffer marker))
8096 (pos (marker-position marker))
8097 (org-insert-labeled-timestamps-at-point nil)
8099 (org-with-remote-undo buffer
8100 (with-current-buffer buffer
8101 (widen)
8102 (goto-char pos)
8103 (setq ts (org-deadline arg time)))
8104 (org-agenda-show-new-time marker ts "D"))
8105 (message "Deadline for this item set to %s" ts)))
8107 (defun org-agenda-action ()
8108 "Select entry for agenda action, or execute an agenda action.
8109 This command prompts for another letter. Valid inputs are:
8111 m Mark the entry at point for an agenda action
8112 s Schedule the marked entry to the date at the cursor
8113 d Set the deadline of the marked entry to the date at the cursor
8114 r Call `org-remember' with cursor date as the default date
8115 c Call `org-capture' with cursor date as the default date
8116 SPC Show marked entry in other window
8117 TAB Visit marked entry in other window
8119 The cursor may be at a date in the calendar, or in the Org agenda."
8120 (interactive)
8121 (let (ans)
8122 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8123 (setq ans (read-char-exclusive))
8124 (cond
8125 ((equal ans ?m)
8126 ;; Mark this entry
8127 (if (eq major-mode 'org-agenda-mode)
8128 (let ((m (or (org-get-at-bol 'org-hd-marker)
8129 (org-get-at-bol 'org-marker))))
8130 (if m
8131 (progn
8132 (move-marker org-agenda-action-marker
8133 (marker-position m) (marker-buffer m))
8134 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8135 (error "Don't know which entry to mark")))
8136 (error "This command works only in the agenda")))
8137 ((equal ans ?s)
8138 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8139 ((equal ans ?d)
8140 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8141 ((equal ans ?r)
8142 (org-agenda-do-action '(org-remember) t))
8143 ((equal ans ?c)
8144 (org-agenda-do-action '(org-capture) t))
8145 ((equal ans ?\ )
8146 (let ((cw (selected-window)))
8147 (org-switch-to-buffer-other-window
8148 (marker-buffer org-agenda-action-marker))
8149 (goto-char org-agenda-action-marker)
8150 (org-show-context 'agenda)
8151 (select-window cw)))
8152 ((equal ans ?\C-i)
8153 (org-switch-to-buffer-other-window
8154 (marker-buffer org-agenda-action-marker))
8155 (goto-char org-agenda-action-marker)
8156 (org-show-context 'agenda))
8157 (t (error "Invalid agenda action %c" ans)))))
8159 (defun org-agenda-do-action (form &optional current-buffer)
8160 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8161 (let ((org-overriding-default-time (org-get-cursor-date)))
8162 (if current-buffer
8163 (eval form)
8164 (if (not (marker-buffer org-agenda-action-marker))
8165 (error "No entry has been selected for agenda action")
8166 (with-current-buffer (marker-buffer org-agenda-action-marker)
8167 (save-excursion
8168 (save-restriction
8169 (widen)
8170 (goto-char org-agenda-action-marker)
8171 (eval form))))))))
8173 (defun org-agenda-clock-in (&optional arg)
8174 "Start the clock on the currently selected item."
8175 (interactive "P")
8176 (org-agenda-check-no-diary)
8177 (if (equal arg '(4))
8178 (org-clock-in arg)
8179 (let* ((marker (or (org-get-at-bol 'org-marker)
8180 (org-agenda-error)))
8181 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8182 marker))
8183 (pos (marker-position marker))
8184 newhead)
8185 (org-with-remote-undo (marker-buffer marker)
8186 (with-current-buffer (marker-buffer marker)
8187 (widen)
8188 (goto-char pos)
8189 (org-show-context 'agenda)
8190 (org-show-entry)
8191 (org-cycle-hide-drawers 'children)
8192 (org-clock-in arg)
8193 (setq newhead (org-get-heading)))
8194 (org-agenda-change-all-lines newhead hdmarker)))))
8196 (defun org-agenda-clock-out ()
8197 "Stop the currently running clock."
8198 (interactive)
8199 (unless (marker-buffer org-clock-marker)
8200 (error "No running clock"))
8201 (let ((marker (make-marker)) newhead)
8202 (org-with-remote-undo (marker-buffer org-clock-marker)
8203 (with-current-buffer (marker-buffer org-clock-marker)
8204 (save-excursion
8205 (save-restriction
8206 (widen)
8207 (goto-char org-clock-marker)
8208 (org-back-to-heading t)
8209 (move-marker marker (point))
8210 (org-clock-out)
8211 (setq newhead (org-get-heading))))))
8212 (org-agenda-change-all-lines newhead marker)
8213 (move-marker marker nil)))
8215 (defun org-agenda-clock-cancel (&optional arg)
8216 "Cancel the currently running clock."
8217 (interactive "P")
8218 (unless (marker-buffer org-clock-marker)
8219 (error "No running clock"))
8220 (org-with-remote-undo (marker-buffer org-clock-marker)
8221 (org-clock-cancel)))
8223 (defun org-agenda-clock-goto ()
8224 "Jump to the currently clocked in task within the agenda.
8225 If the currently clocked in task is not listed in the agenda
8226 buffer, display it in another window."
8227 (interactive)
8228 (let (pos)
8229 (mapc (lambda (o)
8230 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8231 (setq pos (overlay-start o))))
8232 (overlays-in (point-min) (point-max)))
8233 (cond (pos (goto-char pos))
8234 ;; If the currently clocked entry is not in the agenda
8235 ;; buffer, we visit it in another window:
8236 (org-clock-current-task
8237 (org-switch-to-buffer-other-window (org-clock-goto)))
8238 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8240 (defun org-agenda-diary-entry-in-org-file ()
8241 "Make a diary entry in the file `org-agenda-diary-file'."
8242 (let (d1 d2 char (text "") dp1 dp2)
8243 (if (equal (buffer-name) "*Calendar*")
8244 (setq d1 (calendar-cursor-to-date t)
8245 d2 (car calendar-mark-ring))
8246 (setq dp1 (get-text-property (point-at-bol) 'day))
8247 (unless dp1 (error "No date defined in current line"))
8248 (setq d1 (calendar-gregorian-from-absolute dp1)
8249 d2 (and (ignore-errors (mark))
8250 (save-excursion
8251 (goto-char (mark))
8252 (setq dp2 (get-text-property (point-at-bol) 'day)))
8253 (calendar-gregorian-from-absolute dp2))))
8254 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8255 (setq char (read-char-exclusive))
8256 (cond
8257 ((equal char ?d)
8258 (setq text (read-string "Day entry: "))
8259 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8260 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8261 ((equal char ?a)
8262 (setq d1 (list (car d1) (nth 1 d1)
8263 (read-number (format "Reference year [%d]: " (nth 2 d1))
8264 (nth 2 d1))))
8265 (setq text (read-string "Anniversary (use %d to show years): "))
8266 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8267 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8268 ((equal char ?b)
8269 (setq text (read-string "Block entry: "))
8270 (unless (and d1 d2 (not (equal d1 d2)))
8271 (error "No block of days selected"))
8272 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8273 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8274 ((equal char ?j)
8275 (org-switch-to-buffer-other-window
8276 (find-file-noselect org-agenda-diary-file))
8277 (require 'org-datetree)
8278 (org-datetree-find-date-create d1)
8279 (org-reveal t))
8280 (t (error "Invalid selection character `%c'" char)))))
8282 (defcustom org-agenda-insert-diary-strategy 'date-tree
8283 "Where in `org-agenda-diary-file' should new entries be added?
8284 Valid values:
8286 date-tree in the date tree, as child of the date
8287 top-level as top-level entries at the end of the file."
8288 :group 'org-agenda
8289 :type '(choice
8290 (const :tag "in a date tree" date-tree)
8291 (const :tag "as top level at end of file" top-level)))
8293 (defcustom org-agenda-insert-diary-extract-time nil
8294 "Non-nil means extract any time specification from the diary entry."
8295 :group 'org-agenda
8296 :version "24.1"
8297 :type 'boolean)
8299 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8300 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8301 If TEXT is not empty, it will become the headline of the new entry, and
8302 the resulting entry will not be shown. When TEXT is empty, switch to
8303 `org-agenda-diary-file' and let the user finish the entry there."
8304 (let ((cw (current-window-configuration)))
8305 (org-switch-to-buffer-other-window
8306 (find-file-noselect org-agenda-diary-file))
8307 (widen)
8308 (goto-char (point-min))
8309 (cond
8310 ((eq type 'anniversary)
8311 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8312 (progn
8313 (or (org-at-heading-p t)
8314 (progn
8315 (outline-next-heading)
8316 (insert "* Anniversaries\n\n")
8317 (beginning-of-line -1)))))
8318 (outline-next-heading)
8319 (org-back-over-empty-lines)
8320 (backward-char 1)
8321 (insert "\n")
8322 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8323 (nth 2 d1) (car d1) (nth 1 d1) text)))
8324 ((eq type 'day)
8325 (let ((org-prefix-has-time t)
8326 (org-agenda-time-leading-zero t)
8327 fmt time time2)
8328 (if org-agenda-insert-diary-extract-time
8329 ;; Use org-agenda-format-item to parse text for a time-range and
8330 ;; remove it. FIXME: This is a hack, we should refactor
8331 ;; that function to make time extraction available separately
8332 (setq fmt (org-agenda-format-item nil text nil nil t)
8333 time (get-text-property 0 'time fmt)
8334 time2 (if (> (length time) 0)
8335 ;; split-string removes trailing ...... if
8336 ;; no end time given. First space
8337 ;; separates time from date.
8338 (concat " " (car (split-string time "\\.")))
8339 nil)
8340 text (get-text-property 0 'txt fmt)))
8341 (if (eq org-agenda-insert-diary-strategy 'top-level)
8342 (org-agenda-insert-diary-as-top-level text)
8343 (require 'org-datetree)
8344 (org-datetree-find-date-create d1)
8345 (org-agenda-insert-diary-make-new-entry text))
8346 (org-insert-time-stamp (org-time-from-absolute
8347 (calendar-absolute-from-gregorian d1))
8348 nil nil nil nil time2))
8349 (end-of-line 0))
8350 ((eq type 'block)
8351 (if (> (calendar-absolute-from-gregorian d1)
8352 (calendar-absolute-from-gregorian d2))
8353 (setq d1 (prog1 d2 (setq d2 d1))))
8354 (if (eq org-agenda-insert-diary-strategy 'top-level)
8355 (org-agenda-insert-diary-as-top-level text)
8356 (require 'org-datetree)
8357 (org-datetree-find-date-create d1)
8358 (org-agenda-insert-diary-make-new-entry text))
8359 (org-insert-time-stamp (org-time-from-absolute
8360 (calendar-absolute-from-gregorian d1)))
8361 (insert "--")
8362 (org-insert-time-stamp (org-time-from-absolute
8363 (calendar-absolute-from-gregorian d2)))
8364 (end-of-line 0)))
8365 (if (string-match "\\S-" text)
8366 (progn
8367 (set-window-configuration cw)
8368 (message "%s entry added to %s"
8369 (capitalize (symbol-name type))
8370 (abbreviate-file-name org-agenda-diary-file)))
8371 (org-reveal t)
8372 (message "Please finish entry here"))))
8374 (defun org-agenda-insert-diary-as-top-level (text)
8375 "Make new entry as a top-level entry at the end of the file.
8376 Add TEXT as headline, and position the cursor in the second line so that
8377 a timestamp can be added there."
8378 (widen)
8379 (goto-char (point-max))
8380 (or (bolp) (insert "\n"))
8381 (insert "* " text "\n")
8382 (if org-adapt-indentation (org-indent-to-column 2)))
8384 (defun org-agenda-insert-diary-make-new-entry (text)
8385 "Make new entry as last child of current entry.
8386 Add TEXT as headline, and position the cursor in the second line so that
8387 a timestamp can be added there."
8388 (let ((org-show-following-heading t)
8389 (org-show-siblings t)
8390 (org-show-hierarchy-above t)
8391 (org-show-entry-below t)
8392 col)
8393 (outline-next-heading)
8394 (org-back-over-empty-lines)
8395 (or (looking-at "[ \t]*$")
8396 (progn (insert "\n") (backward-char 1)))
8397 (org-insert-heading nil t)
8398 (org-do-demote)
8399 (setq col (current-column))
8400 (insert text "\n")
8401 (if org-adapt-indentation (org-indent-to-column col))
8402 (let ((org-show-following-heading t)
8403 (org-show-siblings t)
8404 (org-show-hierarchy-above t)
8405 (org-show-entry-below t))
8406 (org-show-context))))
8408 (defun org-agenda-diary-entry ()
8409 "Make a diary entry, like the `i' command from the calendar.
8410 All the standard commands work: block, weekly etc.
8411 When `org-agenda-diary-file' points to a file,
8412 `org-agenda-diary-entry-in-org-file' is called instead to create
8413 entries in that Org-mode file."
8414 (interactive)
8415 (org-agenda-check-type t 'agenda 'timeline)
8416 (if (not (eq org-agenda-diary-file 'diary-file))
8417 (org-agenda-diary-entry-in-org-file)
8418 (require 'diary-lib)
8419 (let* ((char (progn
8420 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8421 (read-char-exclusive)))
8422 (cmd (cdr (assoc char
8423 '((?d . insert-diary-entry)
8424 (?w . insert-weekly-diary-entry)
8425 (?m . insert-monthly-diary-entry)
8426 (?y . insert-yearly-diary-entry)
8427 (?a . insert-anniversary-diary-entry)
8428 (?b . insert-block-diary-entry)
8429 (?c . insert-cyclic-diary-entry)))))
8430 (oldf (symbol-function 'calendar-cursor-to-date))
8431 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8432 (point (point))
8433 (mark (or (mark t) (point))))
8434 (unless cmd
8435 (error "No command associated with <%c>" char))
8436 (unless (and (get-text-property point 'day)
8437 (or (not (equal ?b char))
8438 (get-text-property mark 'day)))
8439 (error "Don't know which date to use for diary entry"))
8440 ;; We implement this by hacking the `calendar-cursor-to-date' function
8441 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8442 (let ((calendar-mark-ring
8443 (list (calendar-gregorian-from-absolute
8444 (or (get-text-property mark 'day)
8445 (get-text-property point 'day))))))
8446 (unwind-protect
8447 (progn
8448 (fset 'calendar-cursor-to-date
8449 (lambda (&optional error dummy)
8450 (calendar-gregorian-from-absolute
8451 (get-text-property point 'day))))
8452 (call-interactively cmd))
8453 (fset 'calendar-cursor-to-date oldf))))))
8455 (defun org-agenda-execute-calendar-command (cmd)
8456 "Execute a calendar command from the agenda, with the date associated to
8457 the cursor position."
8458 (org-agenda-check-type t 'agenda 'timeline)
8459 (require 'diary-lib)
8460 (unless (get-text-property (point) 'day)
8461 (error "Don't know which date to use for calendar command"))
8462 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8463 (point (point))
8464 (date (calendar-gregorian-from-absolute
8465 (get-text-property point 'day)))
8466 ;; the following 2 vars are needed in the calendar
8467 (displayed-month (car date))
8468 (displayed-year (nth 2 date)))
8469 (unwind-protect
8470 (progn
8471 (fset 'calendar-cursor-to-date
8472 (lambda (&optional error dummy)
8473 (calendar-gregorian-from-absolute
8474 (get-text-property point 'day))))
8475 (call-interactively cmd))
8476 (fset 'calendar-cursor-to-date oldf))))
8478 (defun org-agenda-phases-of-moon ()
8479 "Display the phases of the moon for the 3 months around the cursor date."
8480 (interactive)
8481 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8483 (defun org-agenda-holidays ()
8484 "Display the holidays for the 3 months around the cursor date."
8485 (interactive)
8486 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8488 (defvar calendar-longitude)
8489 (defvar calendar-latitude)
8490 (defvar calendar-location-name)
8492 (defun org-agenda-sunrise-sunset (arg)
8493 "Display sunrise and sunset for the cursor date.
8494 Latitude and longitude can be specified with the variables
8495 `calendar-latitude' and `calendar-longitude'. When called with prefix
8496 argument, latitude and longitude will be prompted for."
8497 (interactive "P")
8498 (require 'solar)
8499 (let ((calendar-longitude (if arg nil calendar-longitude))
8500 (calendar-latitude (if arg nil calendar-latitude))
8501 (calendar-location-name
8502 (if arg "the given coordinates" calendar-location-name)))
8503 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8505 (defun org-agenda-goto-calendar ()
8506 "Open the Emacs calendar with the date at the cursor."
8507 (interactive)
8508 (org-agenda-check-type t 'agenda 'timeline)
8509 (let* ((day (or (get-text-property (point) 'day)
8510 (error "Don't know which date to open in calendar")))
8511 (date (calendar-gregorian-from-absolute day))
8512 (calendar-move-hook nil)
8513 (calendar-view-holidays-initially-flag nil)
8514 (calendar-view-diary-initially-flag nil))
8515 (calendar)
8516 (calendar-goto-date date)))
8518 ;;;###autoload
8519 (defun org-calendar-goto-agenda ()
8520 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8521 This is a command that has to be installed in `calendar-mode-map'."
8522 (interactive)
8523 (org-agenda-list nil (calendar-absolute-from-gregorian
8524 (calendar-cursor-to-date))
8525 nil))
8527 (defun org-agenda-convert-date ()
8528 (interactive)
8529 (org-agenda-check-type t 'agenda 'timeline)
8530 (let ((day (get-text-property (point) 'day))
8531 date s)
8532 (unless day
8533 (error "Don't know which date to convert"))
8534 (setq date (calendar-gregorian-from-absolute day))
8535 (setq s (concat
8536 "Gregorian: " (calendar-date-string date) "\n"
8537 "ISO: " (calendar-iso-date-string date) "\n"
8538 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8539 "Julian: " (calendar-julian-date-string date) "\n"
8540 "Astron. JD: " (calendar-astro-date-string date)
8541 " (Julian date number at noon UTC)\n"
8542 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8543 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8544 "French: " (calendar-french-date-string date) "\n"
8545 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8546 "Mayan: " (calendar-mayan-date-string date) "\n"
8547 "Coptic: " (calendar-coptic-date-string date) "\n"
8548 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8549 "Persian: " (calendar-persian-date-string date) "\n"
8550 "Chinese: " (calendar-chinese-date-string date) "\n"))
8551 (with-output-to-temp-buffer "*Dates*"
8552 (princ s))
8553 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8555 ;;; Bulk commands
8557 (defvar org-agenda-bulk-marked-entries nil
8558 "List of markers that refer to marked entries in the agenda.")
8560 (defun org-agenda-bulk-marked-p ()
8561 (eq (get-char-property (point-at-bol) 'type)
8562 'org-marked-entry-overlay))
8564 (defun org-agenda-bulk-mark (&optional arg)
8565 "Mark the entry at point for future bulk action."
8566 (interactive "p")
8567 (dotimes (i (or arg 1))
8568 (unless (org-get-at-bol 'org-agenda-diary-link)
8569 (let* ((m (org-get-at-bol 'org-hd-marker))
8571 (unless (org-agenda-bulk-marked-p)
8572 (unless m (error "Nothing to mark at point"))
8573 (push m org-agenda-bulk-marked-entries)
8574 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8575 (org-overlay-display ov "> "
8576 (org-get-todo-face "TODO")
8577 'evaporate)
8578 (overlay-put ov 'type 'org-marked-entry-overlay))
8579 (beginning-of-line 2)
8580 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8581 (beginning-of-line 2))
8582 (message "%d entries marked for bulk action"
8583 (length org-agenda-bulk-marked-entries))))))
8585 (defun org-agenda-bulk-mark-regexp (regexp)
8586 "Mark entries match REGEXP."
8587 (interactive "sMark entries matching regexp: ")
8588 (let (entries-marked)
8589 (save-excursion
8590 (goto-char (point-min))
8591 (goto-char (next-single-property-change (point) 'txt))
8592 (while (re-search-forward regexp nil t)
8593 (when (string-match regexp (get-text-property (point) 'txt))
8594 (setq entries-marked (+ entries-marked 1))
8595 (call-interactively 'org-agenda-bulk-mark))))
8596 (if (not entries-marked)
8597 (message "No entry matching this regexp."))))
8599 (defun org-agenda-bulk-unmark ()
8600 "Unmark the entry at point for future bulk action."
8601 (interactive)
8602 (when (org-agenda-bulk-marked-p)
8603 (org-agenda-bulk-remove-overlays
8604 (point-at-bol) (+ 2 (point-at-bol)))
8605 (setq org-agenda-bulk-marked-entries
8606 (delete (org-get-at-bol 'org-hd-marker)
8607 org-agenda-bulk-marked-entries)))
8608 (beginning-of-line 2)
8609 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8610 (beginning-of-line 2))
8611 (message "%d entries marked for bulk action"
8612 (length org-agenda-bulk-marked-entries)))
8614 (defun org-agenda-bulk-toggle ()
8615 "Toggle marking the entry at point for bulk action."
8616 (interactive)
8617 (if (org-agenda-bulk-marked-p)
8618 (org-agenda-bulk-unmark)
8619 (org-agenda-bulk-mark)))
8621 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8622 "Remove the mark overlays between BEG and END in the agenda buffer.
8623 BEG and END default to the buffer limits.
8625 This only removes the overlays, it does not remove the markers
8626 from the list in `org-agenda-bulk-marked-entries'."
8627 (interactive)
8628 (mapc (lambda (ov)
8629 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8630 (delete-overlay ov)))
8631 (overlays-in (or beg (point-min)) (or end (point-max)))))
8633 (defun org-agenda-bulk-remove-all-marks ()
8634 "Remove all marks in the agenda buffer.
8635 This will remove the markers, and the overlays."
8636 (interactive)
8637 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8638 (setq org-agenda-bulk-marked-entries nil)
8639 (org-agenda-bulk-remove-overlays (point-min) (point-max)))
8641 (defun org-agenda-bulk-action (&optional arg)
8642 "Execute an remote-editing action on all marked entries.
8643 The prefix arg is passed through to the command if possible."
8644 (interactive "P")
8645 ;; Make sure we have markers, and only valid ones
8646 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8647 (mapc
8648 (lambda (m)
8649 (unless (and (markerp m)
8650 (marker-buffer m)
8651 (buffer-live-p (marker-buffer m))
8652 (marker-position m))
8653 (error "Marker %s for bulk command is invalid" m)))
8654 org-agenda-bulk-marked-entries)
8656 ;; Prompt for the bulk command
8657 (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
8658 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
8659 (when org-agenda-bulk-custom-functions
8660 (concat " Custom: ["
8661 (mapconcat (lambda(f) (char-to-string (car f)))
8662 org-agenda-bulk-custom-functions "")
8663 "]"))))
8664 (let* ((action (read-char-exclusive))
8665 (org-log-refile (if org-log-refile 'time nil))
8666 (entries (reverse org-agenda-bulk-marked-entries))
8667 redo-at-end
8668 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8669 (cond
8670 ((equal action ?$)
8671 (setq cmd '(org-agenda-archive)))
8673 ((equal action ?A)
8674 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8676 ((member action '(?r ?w))
8677 (setq rfloc (org-refile-get-location
8678 "Refile to"
8679 (marker-buffer (car org-agenda-bulk-marked-entries))
8680 org-refile-allow-creating-parent-nodes))
8681 (if (nth 3 rfloc)
8682 (setcar (nthcdr 3 rfloc)
8683 (move-marker (make-marker) (nth 3 rfloc)
8684 (or (get-file-buffer (nth 1 rfloc))
8685 (find-buffer-visiting (nth 1 rfloc))
8686 (error "This should not happen")))))
8688 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8689 redo-at-end t))
8691 ((equal action ?t)
8692 (setq state (org-icompleting-read
8693 "Todo state: "
8694 (with-current-buffer (marker-buffer (car entries))
8695 (mapcar 'list org-todo-keywords-1))))
8696 (setq cmd `(let ((org-inhibit-blocking t)
8697 (org-inhibit-logging 'note))
8698 (org-agenda-todo ,state))))
8700 ((memq action '(?- ?+))
8701 (setq tag (org-icompleting-read
8702 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8703 (with-current-buffer (marker-buffer (car entries))
8704 (delq nil
8705 (mapcar (lambda (x)
8706 (if (stringp (car x)) x)) org-tag-alist)))))
8707 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8709 ((memq action '(?s ?d))
8710 (let* ((date (unless arg
8711 (org-read-date
8712 nil nil nil
8713 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8714 (ans (if arg nil org-read-date-final-answer))
8715 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8716 (setq cmd `(let* ((bound (fboundp 'read-string))
8717 (old (and bound (symbol-function 'read-string))))
8718 (unwind-protect
8719 (progn
8720 (fset 'read-string (lambda (&rest ignore) ,ans))
8721 (eval '(,c1 arg)))
8722 (if bound
8723 (fset 'read-string old)
8724 (fmakunbound 'read-string)))))))
8726 ((equal action ?S)
8727 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8728 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8729 (let ((days (read-number
8730 (format "Scatter tasks across how many %sdays: "
8731 (if arg "week" "")) 7)))
8732 (setq cmd
8733 `(let ((distance (1+ (random ,days))))
8734 (if arg
8735 (let ((dist distance)
8736 (day-of-week
8737 (calendar-day-of-week
8738 (calendar-gregorian-from-absolute (org-today)))))
8739 (dotimes (i (1+ dist))
8740 (while (member day-of-week org-agenda-weekend-days)
8741 (incf distance)
8742 (incf day-of-week)
8743 (if (= day-of-week 7)
8744 (setq day-of-week 0)))
8745 (incf day-of-week)
8746 (if (= day-of-week 7)
8747 (setq day-of-week 0)))))
8748 ;; silently fail when try to replan a sexp entry
8749 (condition-case nil
8750 (let* ((date (calendar-gregorian-from-absolute
8751 (+ (org-today) distance)))
8752 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8753 (nth 2 date))))
8754 (org-agenda-schedule nil time))
8755 (error nil)))))))
8757 ((assoc action org-agenda-bulk-custom-functions)
8758 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8759 redo-at-end t))
8761 ((equal action ?f)
8762 (setq cmd (list (intern
8763 (org-icompleting-read "Function: "
8764 obarray 'fboundp t nil nil)))))
8766 (t (error "Invalid bulk action")))
8768 ;; Sort the markers, to make sure that parents are handled before children
8769 (setq entries (sort entries
8770 (lambda (a b)
8771 (cond
8772 ((equal (marker-buffer a) (marker-buffer b))
8773 (< (marker-position a) (marker-position b)))
8775 (string< (buffer-name (marker-buffer a))
8776 (buffer-name (marker-buffer b))))))))
8778 ;; Now loop over all markers and apply cmd
8779 (while (setq e (pop entries))
8780 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8781 (if (not pos)
8782 (progn (message "Skipping removed entry at %s" e)
8783 (setq cntskip (1+ cntskip)))
8784 (goto-char pos)
8785 (let (org-loop-over-headlines-in-active-region)
8786 (eval cmd))
8787 (setq org-agenda-bulk-marked-entries
8788 (delete e org-agenda-bulk-marked-entries))
8789 (setq cnt (1+ cnt))))
8790 (setq org-agenda-bulk-marked-entries nil)
8791 (org-agenda-bulk-remove-all-marks)
8792 (when redo-at-end (org-agenda-redo))
8793 (message "Acted on %d entries%s"
8795 (if (= cntskip 0)
8797 (format ", skipped %d (disappeared before their turn)"
8798 cntskip)))))
8800 ;;; Flagging notes
8802 (defun org-agenda-show-the-flagging-note ()
8803 "Display the flagging note in the other window.
8804 When called a second time in direct sequence, offer to remove the FLAGGING
8805 tag and (if present) the flagging note."
8806 (interactive)
8807 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8808 (win (selected-window))
8809 note heading newhead)
8810 (unless hdmarker
8811 (error "No linked entry at point"))
8812 (if (and (eq this-command last-command)
8813 (y-or-n-p "Unflag and remove any flagging note? "))
8814 (progn
8815 (org-agenda-remove-flag hdmarker)
8816 (let ((win (get-buffer-window "*Flagging Note*")))
8817 (and win (delete-window win)))
8818 (message "Entry unflagged"))
8819 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8820 (unless note
8821 (error "No flagging note"))
8822 (org-kill-new note)
8823 (org-switch-to-buffer-other-window "*Flagging Note*")
8824 (erase-buffer)
8825 (insert note)
8826 (goto-char (point-min))
8827 (while (re-search-forward "\\\\n" nil t)
8828 (replace-match "\n" t t))
8829 (goto-char (point-min))
8830 (select-window win)
8831 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8833 (defun org-agenda-remove-flag (marker)
8834 "Remove the FLAGGED tag and any flagging note in the entry."
8835 (let (newhead)
8836 (org-with-point-at marker
8837 (org-toggle-tag "FLAGGED" 'off)
8838 (org-entry-delete nil "THEFLAGGINGNOTE")
8839 (setq newhead (org-get-heading)))
8840 (org-agenda-change-all-lines newhead marker)
8841 (message "Entry unflagged")))
8843 (defun org-agenda-get-any-marker (&optional pos)
8844 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8845 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8847 ;;; Appointment reminders
8849 (defvar appt-time-msg-list)
8851 ;;;###autoload
8852 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8853 "Activate appointments found in `org-agenda-files'.
8854 With a \\[universal-argument] prefix, refresh the list of
8855 appointments.
8857 If FILTER is t, interactively prompt the user for a regular
8858 expression, and filter out entries that don't match it.
8860 If FILTER is a string, use this string as a regular expression
8861 for filtering entries out.
8863 If FILTER is a function, filter out entries against which
8864 calling the function returns nil. This function takes one
8865 argument: an entry from `org-agenda-get-day-entries'.
8867 FILTER can also be an alist with the car of each cell being
8868 either 'headline or 'category. For example:
8870 '((headline \"IMPORTANT\")
8871 (category \"Work\"))
8873 will only add headlines containing IMPORTANT or headlines
8874 belonging to the \"Work\" category.
8876 ARGS are symbols indicating what kind of entries to consider.
8877 By default `org-agenda-to-appt' will use :deadline, :scheduled
8878 and :timestamp entries. See the docstring of `org-diary' for
8879 details and examples."
8880 (interactive "P")
8881 (if refresh (setq appt-time-msg-list nil))
8882 (if (eq filter t)
8883 (setq filter (read-from-minibuffer "Regexp filter: ")))
8884 (let* ((cnt 0) ; count added events
8885 (scope (or args '(:deadline :scheduled :timestamp)))
8886 (org-agenda-new-buffers nil)
8887 (org-deadline-warning-days 0)
8888 ;; Do not use `org-today' here because appt only takes
8889 ;; time and without date as argument, so it may pass wrong
8890 ;; information otherwise
8891 (today (org-date-to-gregorian
8892 (time-to-days (current-time))))
8893 (org-agenda-restrict nil)
8894 (files (org-agenda-files 'unrestricted)) entries file
8895 (org-agenda-buffer nil))
8896 ;; Get all entries which may contain an appt
8897 (org-prepare-agenda-buffers files)
8898 (while (setq file (pop files))
8899 (setq entries
8900 (delq nil
8901 (append entries
8902 (apply 'org-agenda-get-day-entries
8903 file today scope)))))
8904 ;; Map thru entries and find if we should filter them out
8905 (mapc
8906 (lambda(x)
8907 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
8908 (cat (get-text-property 1 'org-category x))
8909 (tod (get-text-property 1 'time-of-day x))
8910 (ok (or (null filter)
8911 (and (stringp filter) (string-match filter evt))
8912 (and (functionp filter) (funcall filter x))
8913 (and (listp filter)
8914 (let ((cat-filter (cadr (assoc 'category filter)))
8915 (evt-filter (cadr (assoc 'headline filter))))
8916 (or (and (stringp cat-filter)
8917 (string-match cat-filter cat))
8918 (and (stringp evt-filter)
8919 (string-match evt-filter evt))))))))
8920 ;; FIXME: Shall we remove text-properties for the appt text?
8921 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
8922 (when (and ok tod)
8923 (setq tod (concat "00" (number-to-string tod))
8924 tod (when (string-match
8925 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
8926 (concat (match-string 1 tod) ":"
8927 (match-string 2 tod))))
8928 (appt-add tod evt)
8929 (setq cnt (1+ cnt))))) entries)
8930 (org-release-buffers org-agenda-new-buffers)
8931 (if (eq cnt 0)
8932 (message "No event to add")
8933 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
8935 (defun org-agenda-todayp (date)
8936 "Does DATE mean today, when considering `org-extend-today-until'?"
8937 (let ((today (org-today))
8938 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
8939 date)))
8940 (eq date today)))
8942 (defun org-agenda-todo-yesterday (&optional arg)
8943 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
8944 (interactive "P")
8945 (let* ((hour (third (decode-time
8946 (org-current-time))))
8947 (org-extend-today-until (1+ hour)))
8948 (org-agenda-todo arg)))
8950 (provide 'org-agenda)
8952 ;;; org-agenda.el ends here