org-publish.el (org-publish-cache-ctime-of-src): Simplify.
[org-mode.git] / lisp / org-agenda.el
blobaf65425eb68bdc58c604e51b68f16df0b1c02456
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)
89 (defvar org-habit-show-all-today nil)
91 ;; Defined somewhere in this file, but used before definition.
92 (defvar org-agenda-buffer-name)
93 (defvar org-agenda-overriding-header)
94 (defvar org-agenda-title-append nil)
95 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
96 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
97 (defvar org-agenda-undo-list)
98 (defvar org-agenda-pending-undo-list)
99 (defvar original-date) ; dynamically scoped, calendar.el does scope this
101 (defcustom org-agenda-confirm-kill 1
102 "When set, remote killing from the agenda buffer needs confirmation.
103 When t, a confirmation is always needed. When a number N, confirmation is
104 only needed when the text to be killed contains more than N non-white lines."
105 :group 'org-agenda
106 :type '(choice
107 (const :tag "Never" nil)
108 (const :tag "Always" t)
109 (integer :tag "When more than N lines")))
111 (defcustom org-agenda-compact-blocks nil
112 "Non-nil means make the block agenda more compact.
113 This is done globally by leaving out lines like the agenda span
114 name and week number or the separator lines."
115 :group 'org-agenda
116 :type 'boolean)
118 (defcustom org-agenda-block-separator ?=
119 "The separator between blocks in the agenda.
120 If this is a string, it will be used as the separator, with a newline added.
121 If it is a character, it will be repeated to fill the window width.
122 If nil the separator is disabled. In `org-agenda-custom-commands' this
123 addresses the separator between the current and the previous block."
124 :group 'org-agenda
125 :type '(choice
126 (const :tag "Disabled" nil)
127 (character)
128 (string)))
130 (defgroup org-agenda-export nil
131 "Options concerning exporting agenda views in Org-mode."
132 :tag "Org Agenda Export"
133 :group 'org-agenda)
135 (defcustom org-agenda-with-colors t
136 "Non-nil means use colors in agenda views."
137 :group 'org-agenda-export
138 :type 'boolean)
140 (defcustom org-agenda-exporter-settings nil
141 "Alist of variable/value pairs that should be active during agenda export.
142 This is a good place to set options for ps-print and for htmlize.
143 Note that the way this is implemented, the values will be evaluated
144 before assigned to the variables. So make sure to quote values you do
145 *not* want evaluated, for example
147 (setq org-agenda-exporter-settings
148 '((ps-print-color-p 'black-white)))"
149 :group 'org-agenda-export
150 :type '(repeat
151 (list
152 (variable)
153 (sexp :tag "Value"))))
155 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
156 "Hook run in temporary buffer before writing it to an export file.
157 A useful function is `org-agenda-add-entry-text'."
158 :group 'org-agenda-export
159 :type 'hook
160 :options '(org-agenda-add-entry-text))
162 (defcustom org-agenda-add-entry-text-maxlines 0
163 "Maximum number of entry text lines to be added to agenda.
164 This is only relevant when `org-agenda-add-entry-text' is part of
165 `org-agenda-before-write-hook', which it is by default.
166 When this is 0, nothing will happen. When it is greater than 0, it
167 specifies the maximum number of lines that will be added for each entry
168 that is listed in the agenda view.
170 Note that this variable is not used during display, only when exporting
171 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
172 and `org-agenda-entry-text-maxlines'."
173 :group 'org-agenda
174 :type 'integer)
176 (defcustom org-agenda-add-entry-text-descriptive-links t
177 "Non-nil means export org-links as descriptive links in agenda added text.
178 This variable applies to the text added to the agenda when
179 `org-agenda-add-entry-text-maxlines' is larger than 0.
180 When this variable nil, the URL will (also) be shown."
181 :group 'org-agenda
182 :type 'boolean)
184 (defcustom org-agenda-export-html-style ""
185 "The style specification for exported HTML Agenda files.
186 If this variable contains a string, it will replace the default <style>
187 section as produced by `htmlize'.
188 Since there are different ways of setting style information, this variable
189 needs to contain the full HTML structure to provide a style, including the
190 surrounding HTML tags. The style specifications should include definitions
191 the fonts used by the agenda, here is an example:
193 <style type=\"text/css\">
194 p { font-weight: normal; color: gray; }
195 .org-agenda-structure {
196 font-size: 110%;
197 color: #003399;
198 font-weight: 600;
200 .org-todo {
201 color: #cc6666;
202 font-weight: bold;
204 .org-agenda-done {
205 color: #339933;
207 .org-done {
208 color: #339933;
210 .title { text-align: center; }
211 .todo, .deadline { color: red; }
212 .done { color: green; }
213 </style>
215 or, if you want to keep the style in a file,
217 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
219 As the value of this option simply gets inserted into the HTML <head> header,
220 you can \"misuse\" it to also add other text to the header. However,
221 <style>...</style> is required, if not present the variable will be ignored."
222 :group 'org-agenda-export
223 :group 'org-export-html
224 :type 'string)
226 (defcustom org-agenda-persistent-filter nil
227 "When set, keep filters from one agenda view to the next."
228 :group 'org-agenda
229 :type 'boolean)
231 (defgroup org-agenda-custom-commands nil
232 "Options concerning agenda views in Org-mode."
233 :tag "Org Agenda Custom Commands"
234 :group 'org-agenda)
236 (defconst org-sorting-choice
237 '(choice
238 (const time-up) (const time-down)
239 (const category-keep) (const category-up) (const category-down)
240 (const tag-down) (const tag-up)
241 (const priority-up) (const priority-down)
242 (const todo-state-up) (const todo-state-down)
243 (const effort-up) (const effort-down)
244 (const habit-up) (const habit-down)
245 (const alpha-up) (const alpha-down)
246 (const user-defined-up) (const user-defined-down))
247 "Sorting choices.")
249 ;; Keep custom values for `org-agenda-filter-preset' compatible with
250 ;; the new variable `org-agenda-tag-filter-preset'.
251 (if (fboundp 'defvaralias)
252 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
253 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
255 (defconst org-agenda-custom-commands-local-options
256 `(repeat :tag "Local settings for this command. Remember to quote values"
257 (choice :tag "Setting"
258 (list :tag "Heading for this block"
259 (const org-agenda-overriding-header)
260 (string :tag "Headline"))
261 (list :tag "Files to be searched"
262 (const org-agenda-files)
263 (list
264 (const :format "" quote)
265 (repeat (file))))
266 (list :tag "Sorting strategy"
267 (const org-agenda-sorting-strategy)
268 (list
269 (const :format "" quote)
270 (repeat
271 ,org-sorting-choice)))
272 (list :tag "Prefix format"
273 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
274 (string))
275 (list :tag "Number of days in agenda"
276 (const org-agenda-span)
277 (choice (const :tag "Day" 'day)
278 (const :tag "Week" 'week)
279 (const :tag "Month" 'month)
280 (const :tag "Year" 'year)
281 (integer :tag "Custom")))
282 (list :tag "Fixed starting date"
283 (const org-agenda-start-day)
284 (string :value "2007-11-01"))
285 (list :tag "Start on day of week"
286 (const org-agenda-start-on-weekday)
287 (choice :value 1
288 (const :tag "Today" nil)
289 (integer :tag "Weekday No.")))
290 (list :tag "Include data from diary"
291 (const org-agenda-include-diary)
292 (boolean))
293 (list :tag "Deadline Warning days"
294 (const org-deadline-warning-days)
295 (integer :value 1))
296 (list :tag "Category filter preset"
297 (const org-agenda-category-filter-preset)
298 (list
299 (const :format "" quote)
300 (repeat
301 (string :tag "+category or -category"))))
302 (list :tag "Tags filter preset"
303 (const org-agenda-tag-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+tag or -tag"))))
308 (list :tag "Set daily/weekly entry types"
309 (const org-agenda-entry-types)
310 (list
311 (const :format "" quote)
312 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
313 (const :deadline)
314 (const :scheduled)
315 (const :timestamp)
316 (const :sexp))))
317 (list :tag "Standard skipping condition"
318 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
319 (const org-agenda-skip-function)
320 (list
321 (const :format "" quote)
322 (list
323 (choice
324 :tag "Skipping range"
325 (const :tag "Skip entry" org-agenda-skip-entry-if)
326 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
327 (repeat :inline t :tag "Conditions for skipping"
328 (choice
329 :tag "Condition type"
330 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
331 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
332 (list :tag "TODO state is" :inline t
333 (const 'todo)
334 (choice
335 (const :tag "any not-done state" 'todo)
336 (const :tag "any done state" 'done)
337 (const :tag "any state" 'any)
338 (list :tag "Keyword list"
339 (const :format "" quote)
340 (repeat (string :tag "Keyword")))))
341 (list :tag "TODO state is not" :inline t
342 (const 'nottodo)
343 (choice
344 (const :tag "any not-done state" 'todo)
345 (const :tag "any done state" 'done)
346 (const :tag "any state" 'any)
347 (list :tag "Keyword list"
348 (const :format "" quote)
349 (repeat (string :tag "Keyword")))))
350 (const :tag "scheduled" 'scheduled)
351 (const :tag "not scheduled" 'notscheduled)
352 (const :tag "deadline" 'deadline)
353 (const :tag "no deadline" 'notdeadline)
354 (const :tag "timestamp" 'timestamp)
355 (const :tag "no timestamp" 'nottimestamp))))))
356 (list :tag "Non-standard skipping condition"
357 :value (org-agenda-skip-function)
358 (const org-agenda-skip-function)
359 (sexp :tag "Function or form (quoted!)"))
360 (list :tag "Any variable"
361 (variable :tag "Variable")
362 (sexp :tag "Value (sexp)"))))
363 "Selection of examples for agenda command settings.
364 This will be spliced into the custom type of
365 `org-agenda-custom-commands'.")
368 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
369 ((agenda "") (alltodo))))
370 "Custom commands for the agenda.
371 These commands will be offered on the splash screen displayed by the
372 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
374 (key desc type match settings files)
376 key The key (one or more characters as a string) to be associated
377 with the command.
378 desc A description of the command, when omitted or nil, a default
379 description is built using MATCH.
380 type The command type, any of the following symbols:
381 agenda The daily/weekly agenda.
382 todo Entries with a specific TODO keyword, in all agenda files.
383 search Entries containing search words entry or headline.
384 tags Tags/Property/TODO match in all agenda files.
385 tags-todo Tags/P/T match in all agenda files, TODO entries only.
386 todo-tree Sparse tree of specific TODO keyword in *current* file.
387 tags-tree Sparse tree with all tags matches in *current* file.
388 occur-tree Occur sparse tree for *current* file.
389 ... A user-defined function.
390 match What to search for:
391 - a single keyword for TODO keyword searches
392 - a tags match expression for tags searches
393 - a word search expression for text searches.
394 - a regular expression for occur searches
395 For all other commands, this should be the empty string.
396 settings A list of option settings, similar to that in a let form, so like
397 this: ((opt1 val1) (opt2 val2) ...). The values will be
398 evaluated at the moment of execution, so quote them when needed.
399 files A list of files file to write the produced agenda buffer to
400 with the command `org-store-agenda-views'.
401 If a file name ends in \".html\", an HTML version of the buffer
402 is written out. If it ends in \".ps\", a postscript version is
403 produced. Otherwise, only the plain text is written to the file.
405 You can also define a set of commands, to create a composite agenda buffer.
406 In this case, an entry looks like this:
408 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
410 where
412 desc A description string to be displayed in the dispatcher menu.
413 cmd An agenda command, similar to the above. However, tree commands
414 are not allowed, but instead you can get agenda and global todo list.
415 So valid commands for a set are:
416 (agenda \"\" settings)
417 (alltodo \"\" settings)
418 (stuck \"\" settings)
419 (todo \"match\" settings files)
420 (search \"match\" settings files)
421 (tags \"match\" settings files)
422 (tags-todo \"match\" settings files)
424 Each command can carry a list of options, and another set of options can be
425 given for the whole set of commands. Individual command options take
426 precedence over the general options.
428 When using several characters as key to a command, the first characters
429 are prefix commands. For the dispatcher to display useful information, you
430 should provide a description for the prefix, like
432 (setq org-agenda-custom-commands
433 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
434 (\"hl\" tags \"+HOME+Lisa\")
435 (\"hp\" tags \"+HOME+Peter\")
436 (\"hk\" tags \"+HOME+Kim\")))"
437 :group 'org-agenda-custom-commands
438 :type `(repeat
439 (choice :value ("x" "Describe command here" tags "" nil)
440 (list :tag "Single command"
441 (string :tag "Access Key(s) ")
442 (option (string :tag "Description"))
443 (choice
444 (const :tag "Agenda" agenda)
445 (const :tag "TODO list" alltodo)
446 (const :tag "Search words" search)
447 (const :tag "Stuck projects" stuck)
448 (const :tag "Tags/Property match (all agenda files)" tags)
449 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
450 (const :tag "TODO keyword search (all agenda files)" todo)
451 (const :tag "Tags sparse tree (current buffer)" tags-tree)
452 (const :tag "TODO keyword tree (current buffer)" todo-tree)
453 (const :tag "Occur tree (current buffer)" occur-tree)
454 (sexp :tag "Other, user-defined function"))
455 (string :tag "Match (only for some commands)")
456 ,org-agenda-custom-commands-local-options
457 (option (repeat :tag "Export" (file :tag "Export to"))))
458 (list :tag "Command series, all agenda files"
459 (string :tag "Access Key(s)")
460 (string :tag "Description ")
461 (repeat :tag "Component"
462 (choice
463 (list :tag "Agenda"
464 (const :format "" agenda)
465 (const :tag "" :format "" "")
466 ,org-agenda-custom-commands-local-options)
467 (list :tag "TODO list (all keywords)"
468 (const :format "" alltodo)
469 (const :tag "" :format "" "")
470 ,org-agenda-custom-commands-local-options)
471 (list :tag "Search words"
472 (const :format "" search)
473 (string :tag "Match")
474 ,org-agenda-custom-commands-local-options)
475 (list :tag "Stuck projects"
476 (const :format "" stuck)
477 (const :tag "" :format "" "")
478 ,org-agenda-custom-commands-local-options)
479 (list :tag "Tags search"
480 (const :format "" tags)
481 (string :tag "Match")
482 ,org-agenda-custom-commands-local-options)
483 (list :tag "Tags search, TODO entries only"
484 (const :format "" tags-todo)
485 (string :tag "Match")
486 ,org-agenda-custom-commands-local-options)
487 (list :tag "TODO keyword search"
488 (const :format "" todo)
489 (string :tag "Match")
490 ,org-agenda-custom-commands-local-options)
491 (list :tag "Other, user-defined function"
492 (symbol :tag "function")
493 (string :tag "Match")
494 ,org-agenda-custom-commands-local-options)))
496 (repeat :tag "Settings for entire command set"
497 (list (variable :tag "Any variable")
498 (sexp :tag "Value")))
499 (option (repeat :tag "Export" (file :tag "Export to"))))
500 (cons :tag "Prefix key documentation"
501 (string :tag "Access Key(s)")
502 (string :tag "Description ")))))
504 (defcustom org-agenda-query-register ?o
505 "The register holding the current query string.
506 The purpose of this is that if you construct a query string interactively,
507 you can then use it to define a custom command."
508 :group 'org-agenda-custom-commands
509 :type 'character)
511 (defcustom org-stuck-projects
512 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
513 "How to identify stuck projects.
514 This is a list of four items:
515 1. A tags/todo/property matcher string that is used to identify a project.
516 See the manual for a description of tag and property searches.
517 The entire tree below a headline matched by this is considered one project.
518 2. A list of TODO keywords identifying non-stuck projects.
519 If the project subtree contains any headline with one of these todo
520 keywords, the project is considered to be not stuck. If you specify
521 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
522 3. A list of tags identifying non-stuck projects.
523 If the project subtree contains any headline with one of these tags,
524 the project is considered to be not stuck. If you specify \"*\" as
525 a tag, any tag will mark the project unstuck. Note that this is about
526 the explicit presence of a tag somewhere in the subtree, inherited
527 tags to not count here. If inherited tags make a project not stuck,
528 use \"-TAG\" in the tags part of the matcher under (1.) above.
529 4. An arbitrary regular expression matching non-stuck projects.
531 If the project turns out to be not stuck, search continues also in the
532 subtree to see if any of the subtasks have project status.
534 See also the variable `org-tags-match-list-sublevels' which applies
535 to projects matched by this search as well.
537 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
538 or `C-c a #' to produce the list."
539 :group 'org-agenda-custom-commands
540 :type '(list
541 (string :tag "Tags/TODO match to identify a project")
542 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
543 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
544 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
546 (defcustom org-agenda-filter-effort-default-operator "<"
547 "The default operator for effort estimate filtering.
548 If you select an effort estimate limit without first pressing an operator,
549 this one will be used."
550 :group 'org-agenda-custom-commands
551 :type '(choice (const :tag "less or equal" "<")
552 (const :tag "greater or equal"">")
553 (const :tag "equal" "=")))
555 (defgroup org-agenda-skip nil
556 "Options concerning skipping parts of agenda files."
557 :tag "Org Agenda Skip"
558 :group 'org-agenda)
560 (defcustom org-agenda-skip-function-global nil
561 "Function to be called at each match during agenda construction.
562 If this function returns nil, the current match should not be skipped.
563 If the function decided to skip an agenda match, is must return the
564 buffer position from which the search should be continued.
565 This may also be a Lisp form, which will be evaluated.
567 This variable will be applied to every agenda match, including
568 tags/property searches and TODO lists. So try to make the test function
569 do its checking as efficiently as possible. To implement a skipping
570 condition just for specific agenda commands, use the variable
571 `org-agenda-skip-function' which can be set in the options section
572 of custom agenda commands."
573 :group 'org-agenda-skip
574 :type 'sexp)
576 (defgroup org-agenda-daily/weekly nil
577 "Options concerning the daily/weekly agenda."
578 :tag "Org Agenda Daily/Weekly"
579 :group 'org-agenda)
580 (defgroup org-agenda-todo-list nil
581 "Options concerning the global todo list agenda view."
582 :tag "Org Agenda Todo List"
583 :group 'org-agenda)
584 (defgroup org-agenda-match-view nil
585 "Options concerning the general tags/property/todo match agenda view."
586 :tag "Org Agenda Match View"
587 :group 'org-agenda)
588 (defgroup org-agenda-search-view nil
589 "Options concerning the general tags/property/todo match agenda view."
590 :tag "Org Agenda Match View"
591 :group 'org-agenda)
593 (defvar org-agenda-archives-mode nil
594 "Non-nil means the agenda will include archived items.
595 If this is the symbol `trees', trees in the selected agenda scope
596 that are marked with the ARCHIVE tag will be included anyway. When this is
597 t, also all archive files associated with the current selection of agenda
598 files will be included.")
600 (defcustom org-agenda-skip-comment-trees t
601 "Non-nil means skip trees that start with the COMMENT keyword.
602 When nil, these trees are also scanned by agenda commands."
603 :group 'org-agenda-skip
604 :type 'boolean)
606 (defcustom org-agenda-todo-list-sublevels t
607 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
608 When nil, the sublevels of a TODO entry are not checked, resulting in
609 potentially much shorter TODO lists."
610 :group 'org-agenda-skip
611 :group 'org-agenda-todo-list
612 :type 'boolean)
614 (defcustom org-agenda-todo-ignore-with-date nil
615 "Non-nil means don't show entries with a date in the global todo list.
616 You can use this if you prefer to mark mere appointments with a TODO keyword,
617 but don't want them to show up in the TODO list.
618 When this is set, it also covers deadlines and scheduled items, the settings
619 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
620 will be ignored.
621 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
622 :group 'org-agenda-skip
623 :group 'org-agenda-todo-list
624 :type 'boolean)
626 (defcustom org-agenda-todo-ignore-timestamp nil
627 "Non-nil means don't show entries with a timestamp.
628 This applies when creating the global todo list.
629 Valid values are:
631 past Don't show entries for today or in the past.
633 future Don't show entries with a timestamp in the future.
634 The idea behind this is that if it has a future
635 timestamp, you don't want to think about it until the
636 date.
638 all Don't show any entries with a timestamp in the global todo list.
639 The idea behind this is that by setting a timestamp, you
640 have already \"taken care\" of this item.
642 This variable can also have an integer as a value. If positive (N),
643 todos with a timestamp N or more days in the future will be ignored. If
644 negative (-N), todos with a timestamp N or more days in the past will be
645 ignored. If 0, todos with a timestamp either today or in the future will
646 be ignored. For example, a value of -1 will exclude todos with a
647 timestamp in the past (yesterday or earlier), while a value of 7 will
648 exclude todos with a timestamp a week or more in the future.
650 See also `org-agenda-todo-ignore-with-date'.
651 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
652 to make his option also apply to the tags-todo list."
653 :group 'org-agenda-skip
654 :group 'org-agenda-todo-list
655 :version "24.1"
656 :type '(choice
657 (const :tag "Ignore future timestamp todos" future)
658 (const :tag "Ignore past or present timestamp todos" past)
659 (const :tag "Ignore all timestamp todos" all)
660 (const :tag "Show timestamp todos" nil)
661 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
663 (defcustom org-agenda-todo-ignore-scheduled nil
664 "Non-nil means, ignore some scheduled TODO items when making TODO list.
665 This applies when creating the global todo list.
666 Valid values are:
668 past Don't show entries scheduled today or in the past.
670 future Don't show entries scheduled in the future.
671 The idea behind this is that by scheduling it, you don't want to
672 think about it until the scheduled date.
674 all Don't show any scheduled entries in the global todo list.
675 The idea behind this is that by scheduling it, you have already
676 \"taken care\" of this item.
678 t Same as `all', for backward compatibility.
680 This variable can also have an integer as a value. See
681 `org-agenda-todo-ignore-timestamp' for more details.
683 See also `org-agenda-todo-ignore-with-date'.
684 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
685 to make his option also apply to the tags-todo list."
686 :group 'org-agenda-skip
687 :group 'org-agenda-todo-list
688 :type '(choice
689 (const :tag "Ignore future-scheduled todos" future)
690 (const :tag "Ignore past- or present-scheduled todos" past)
691 (const :tag "Ignore all scheduled todos" all)
692 (const :tag "Ignore all scheduled todos (compatibility)" t)
693 (const :tag "Show scheduled todos" nil)
694 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
696 (defcustom org-agenda-todo-ignore-deadlines nil
697 "Non-nil means ignore some deadlined TODO items when making TODO list.
698 There are different motivations for using different values, please think
699 carefully when configuring this variable.
701 This applies when creating the global todo list.
702 Valid values are:
704 near Don't show near deadline entries. A deadline is near when it is
705 closer than `org-deadline-warning-days' days. The idea behind this
706 is that such items will appear in the agenda anyway.
708 far Don't show TODO entries where a deadline has been defined, but
709 the deadline is not near. This is useful if you don't want to
710 use the todo list to figure out what to do now.
712 past Don't show entries with a deadline timestamp for today or in the past.
714 future Don't show entries with a deadline timestamp in the future, not even
715 when they become `near' ones. Use it with caution.
717 all Ignore all TODO entries that do have a deadline.
719 t Same as `near', for backward compatibility.
721 This variable can also have an integer as a value. See
722 `org-agenda-todo-ignore-timestamp' for more details.
724 See also `org-agenda-todo-ignore-with-date'.
725 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
726 to make his option also apply to the tags-todo list."
727 :group 'org-agenda-skip
728 :group 'org-agenda-todo-list
729 :type '(choice
730 (const :tag "Ignore near deadlines" near)
731 (const :tag "Ignore near deadlines (compatibility)" t)
732 (const :tag "Ignore far deadlines" far)
733 (const :tag "Ignore all TODOs with a deadlines" all)
734 (const :tag "Show all TODOs, even if they have a deadline" nil)
735 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
737 (defcustom org-agenda-tags-todo-honor-ignore-options nil
738 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
739 The variables
740 `org-agenda-todo-ignore-with-date',
741 `org-agenda-todo-ignore-timestamp',
742 `org-agenda-todo-ignore-scheduled',
743 `org-agenda-todo-ignore-deadlines'
744 make the global TODO list skip entries that have time stamps of certain
745 kinds. If this option is set, the same options will also apply for the
746 tags-todo search, which is the general tags/property matcher
747 restricted to unfinished TODO entries only."
748 :group 'org-agenda-skip
749 :group 'org-agenda-todo-list
750 :group 'org-agenda-match-view
751 :type 'boolean)
753 (defcustom org-agenda-skip-scheduled-if-done nil
754 "Non-nil means don't show scheduled items in agenda when they are done.
755 This is relevant for the daily/weekly agenda, not for the TODO list. And
756 it applies only to the actual date of the scheduling. Warnings about
757 an item with a past scheduling dates are always turned off when the item
758 is DONE."
759 :group 'org-agenda-skip
760 :group 'org-agenda-daily/weekly
761 :type 'boolean)
763 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
764 "Non-nil means skip scheduling line if same entry shows because of deadline.
765 In the agenda of today, an entry can show up multiple times because
766 it is both scheduled and has a nearby deadline, and maybe a plain time
767 stamp as well.
768 When this variable is t, then only the deadline is shown and the fact that
769 the entry is scheduled today or was scheduled previously is not shown.
770 When this variable is nil, the entry will be shown several times. When
771 the variable is the symbol `not-today', then skip scheduled previously,
772 but not scheduled today."
773 :group 'org-agenda-skip
774 :group 'org-agenda-daily/weekly
775 :type '(choice
776 (const :tag "Never" nil)
777 (const :tag "Always" t)
778 (const :tag "Not when scheduled today" not-today)))
780 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
781 "Non-nil means skip timestamp line if same entry shows because of deadline.
782 In the agenda of today, an entry can show up multiple times
783 because it has both a plain timestamp and has a nearby deadline.
784 When this variable is t, then only the deadline is shown and the
785 fact that the entry has a timestamp for or including today is not
786 shown. When this variable is nil, the entry will be shown
787 several times."
788 :group 'org-agenda-skip
789 :group 'org-agenda-daily/weekly
790 :version "24.1"
791 :type '(choice
792 (const :tag "Never" nil)
793 (const :tag "Always" t)))
795 (defcustom org-agenda-skip-deadline-if-done nil
796 "Non-nil means don't show deadlines when the corresponding item is done.
797 When nil, the deadline is still shown and should give you a happy feeling.
798 This is relevant for the daily/weekly agenda. And it applied only to the
799 actually date of the deadline. Warnings about approaching and past-due
800 deadlines are always turned off when the item is DONE."
801 :group 'org-agenda-skip
802 :group 'org-agenda-daily/weekly
803 :type 'boolean)
805 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
806 "Non-nil means skip deadline prewarning when entry is also scheduled.
807 This will apply on all days where a prewarning for the deadline would
808 be shown, but not at the day when the entry is actually due. On that day,
809 the deadline will be shown anyway.
810 This variable may be set to nil, t, or a number which will then give
811 the number of days before the actual deadline when the prewarnings
812 should resume.
813 This can be used in a workflow where the first showing of the deadline will
814 trigger you to schedule it, and then you don't want to be reminded of it
815 because you will take care of it on the day when scheduled."
816 :group 'org-agenda-skip
817 :group 'org-agenda-daily/weekly
818 :version "24.1"
819 :type '(choice
820 (const :tag "Alwas show prewarning" nil)
821 (const :tag "Remove prewarning if entry is scheduled" t)
822 (integer :tag "Restart prewarning N days before deadline")))
824 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
825 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
826 When non-nil, after the search for timestamps has matched once in an
827 entry, the rest of the entry will not be searched."
828 :group 'org-agenda-skip
829 :type 'boolean)
831 (defcustom org-agenda-skip-timestamp-if-done nil
832 "Non-nil means don't select item by timestamp or -range if it is DONE."
833 :group 'org-agenda-skip
834 :group 'org-agenda-daily/weekly
835 :type 'boolean)
837 (defcustom org-agenda-dim-blocked-tasks t
838 "Non-nil means dim blocked tasks in the agenda display.
839 This causes some overhead during agenda construction, but if you
840 have turned on `org-enforce-todo-dependencies',
841 `org-enforce-todo-checkbox-dependencies', or any other blocking
842 mechanism, this will create useful feedback in the agenda.
844 Instead of t, this variable can also have the value `invisible'.
845 Then blocked tasks will be invisible and only become visible when
846 they become unblocked. An exemption to this behavior is when a task is
847 blocked because of unchecked checkboxes below it. Since checkboxes do
848 not show up in the agenda views, making this task invisible you remove any
849 trace from agenda views that there is something to do. Therefore, a task
850 that is blocked because of checkboxes will never be made invisible, it
851 will only be dimmed."
852 :group 'org-agenda-daily/weekly
853 :group 'org-agenda-todo-list
854 :type '(choice
855 (const :tag "Do not dim" nil)
856 (const :tag "Dim to a gray face" t)
857 (const :tag "Make invisible" invisible)))
859 (defcustom org-timeline-show-empty-dates 3
860 "Non-nil means `org-timeline' also shows dates without an entry.
861 When nil, only the days which actually have entries are shown.
862 When t, all days between the first and the last date are shown.
863 When an integer, show also empty dates, but if there is a gap of more than
864 N days, just insert a special line indicating the size of the gap."
865 :group 'org-agenda-skip
866 :type '(choice
867 (const :tag "None" nil)
868 (const :tag "All" t)
869 (integer :tag "at most")))
871 (defgroup org-agenda-startup nil
872 "Options concerning initial settings in the Agenda in Org Mode."
873 :tag "Org Agenda Startup"
874 :group 'org-agenda)
876 (defcustom org-agenda-menu-show-matcher t
877 "Non-nil means show the match string in the agenda dispatcher menu.
878 When nil, the matcher string is not shown, but is put into the help-echo
879 property so than moving the mouse over the command shows it.
880 Setting it to nil is good if matcher strings are very long and/or if
881 you want to use two-column display (see `org-agenda-menu-two-column')."
882 :group 'org-agenda
883 :version "24.1"
884 :type 'boolean)
886 (defcustom org-agenda-menu-two-column nil
887 "Non-nil means, use two columns to show custom commands in the dispatcher.
888 If you use this, you probably want to set `org-agenda-menu-show-matcher'
889 to nil."
890 :group 'org-agenda
891 :version "24.1"
892 :type 'boolean)
894 (defcustom org-finalize-agenda-hook nil
895 "Hook run just before displaying an agenda buffer."
896 :group 'org-agenda-startup
897 :type 'hook)
899 (defcustom org-agenda-mouse-1-follows-link nil
900 "Non-nil means mouse-1 on a link will follow the link in the agenda.
901 A longer mouse click will still set point. Does not work on XEmacs.
902 Needs to be set before org.el is loaded."
903 :group 'org-agenda-startup
904 :type 'boolean)
906 (defcustom org-agenda-start-with-follow-mode nil
907 "The initial value of follow mode in a newly created agenda window."
908 :group 'org-agenda-startup
909 :type 'boolean)
911 (defcustom org-agenda-follow-indirect nil
912 "Non-nil means `org-agenda-follow-mode' displays only the
913 current item's tree, in an indirect buffer."
914 :group 'org-agenda
915 :version "24.1"
916 :type 'boolean)
918 (defcustom org-agenda-show-outline-path t
919 "Non-nil means show outline path in echo area after line motion."
920 :group 'org-agenda-startup
921 :type 'boolean)
923 (defcustom org-agenda-start-with-entry-text-mode nil
924 "The initial value of entry-text-mode in a newly created agenda window."
925 :group 'org-agenda-startup
926 :type 'boolean)
928 (defcustom org-agenda-entry-text-maxlines 5
929 "Number of text lines to be added when `E' is pressed in the agenda.
931 Note that this variable only used during agenda display. Add add entry text
932 when exporting the agenda, configure the variable
933 `org-agenda-add-entry-ext-maxlines'."
934 :group 'org-agenda
935 :type 'integer)
937 (defcustom org-agenda-entry-text-exclude-regexps nil
938 "List of regular expressions to clean up entry text.
939 The complete matches of all regular expressions in this list will be
940 removed from entry text before it is shown in the agenda."
941 :group 'org-agenda
942 :type '(repeat (regexp)))
944 (defvar org-agenda-entry-text-cleanup-hook nil
945 "Hook that is run after basic cleanup of entry text to be shown in agenda.
946 This cleanup is done in a temporary buffer, so the function may inspect and
947 change the entire buffer.
948 Some default stuff like drawers and scheduling/deadline dates will already
949 have been removed when this is called, as will any matches for regular
950 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
952 (defvar org-agenda-include-inactive-timestamps nil
953 "Non-nil means include inactive time stamps in agenda and timeline.
954 Dynamically scoped.")
956 (defgroup org-agenda-windows nil
957 "Options concerning the windows used by the Agenda in Org Mode."
958 :tag "Org Agenda Windows"
959 :group 'org-agenda)
961 (defcustom org-agenda-window-setup 'reorganize-frame
962 "How the agenda buffer should be displayed.
963 Possible values for this option are:
965 current-window Show agenda in the current window, keeping all other windows.
966 other-window Use `switch-to-buffer-other-window' to display agenda.
967 reorganize-frame Show only two windows on the current frame, the current
968 window and the agenda.
969 other-frame Use `switch-to-buffer-other-frame' to display agenda.
970 Also, when exiting the agenda, kill that frame.
971 See also the variable `org-agenda-restore-windows-after-quit'."
972 :group 'org-agenda-windows
973 :type '(choice
974 (const current-window)
975 (const other-frame)
976 (const other-window)
977 (const reorganize-frame)))
979 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
980 "The min and max height of the agenda window as a fraction of frame height.
981 The value of the variable is a cons cell with two numbers between 0 and 1.
982 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
983 :group 'org-agenda-windows
984 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
986 (defcustom org-agenda-restore-windows-after-quit nil
987 "Non-nil means restore window configuration upon exiting agenda.
988 Before the window configuration is changed for displaying the agenda,
989 the current status is recorded. When the agenda is exited with
990 `q' or `x' and this option is set, the old state is restored. If
991 `org-agenda-window-setup' is `other-frame', the value of this
992 option will be ignored."
993 :group 'org-agenda-windows
994 :type 'boolean)
996 (defcustom org-agenda-ndays nil
997 "Number of days to include in overview display.
998 Should be 1 or 7.
999 Obsolete, see `org-agenda-span'."
1000 :group 'org-agenda-daily/weekly
1001 :type 'integer)
1003 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1005 (defcustom org-agenda-span 'week
1006 "Number of days to include in overview display.
1007 Can be day, week, month, year, or any number of days.
1008 Custom commands can set this variable in the options section."
1009 :group 'org-agenda-daily/weekly
1010 :type '(choice (const :tag "Day" day)
1011 (const :tag "Week" week)
1012 (const :tag "Month" month)
1013 (const :tag "Year" year)
1014 (integer :tag "Custom")))
1016 (defcustom org-agenda-start-on-weekday 1
1017 "Non-nil means start the overview always on the specified weekday.
1018 0 denotes Sunday, 1 denotes Monday etc.
1019 When nil, always start on the current day.
1020 Custom commands can set this variable in the options section."
1021 :group 'org-agenda-daily/weekly
1022 :type '(choice (const :tag "Today" nil)
1023 (integer :tag "Weekday No.")))
1025 (defcustom org-agenda-show-all-dates t
1026 "Non-nil means `org-agenda' shows every day in the selected range.
1027 When nil, only the days which actually have entries are shown."
1028 :group 'org-agenda-daily/weekly
1029 :type 'boolean)
1031 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1032 "Format string for displaying dates in the agenda.
1033 Used by the daily/weekly agenda and by the timeline. This should be
1034 a format string understood by `format-time-string', or a function returning
1035 the formatted date as a string. The function must take a single argument,
1036 a calendar-style date list like (month day year)."
1037 :group 'org-agenda-daily/weekly
1038 :type '(choice
1039 (string :tag "Format string")
1040 (function :tag "Function")))
1042 (defun org-agenda-format-date-aligned (date)
1043 "Format a date string for display in the daily/weekly agenda, or timeline.
1044 This function makes sure that dates are aligned for easy reading."
1045 (require 'cal-iso)
1046 (let* ((dayname (calendar-day-name date))
1047 (day (cadr date))
1048 (day-of-week (calendar-day-of-week date))
1049 (month (car date))
1050 (monthname (calendar-month-name month))
1051 (year (nth 2 date))
1052 (iso-week (org-days-to-iso-week
1053 (calendar-absolute-from-gregorian date)))
1054 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1055 (1- year))
1056 ((and (= month 12) (<= iso-week 1))
1057 (1+ year))
1058 (t year)))
1059 (weekstring (if (= day-of-week 1)
1060 (format " W%02d" iso-week)
1061 "")))
1062 (format "%-10s %2d %s %4d%s"
1063 dayname day monthname year weekstring)))
1065 (defcustom org-agenda-time-leading-zero nil
1066 "Non-nil means use leading zero for military times in agenda.
1067 For example, 9:30am would become 09:30 rather than 9:30."
1068 :group 'org-agenda-daily/weekly
1069 :version "24.1"
1070 :type 'boolean)
1072 (defcustom org-agenda-timegrid-use-ampm nil
1073 "When set, show AM/PM style timestamps on the timegrid."
1074 :group 'org-agenda
1075 :version "24.1"
1076 :type 'boolean)
1078 (defun org-agenda-time-of-day-to-ampm (time)
1079 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1080 (let* ((hour-number (string-to-number (substring time 0 -3)))
1081 (minute (substring time -2))
1082 (ampm "am"))
1083 (cond
1084 ((equal hour-number 12)
1085 (setq ampm "pm"))
1086 ((> hour-number 12)
1087 (setq ampm "pm")
1088 (setq hour-number (- hour-number 12))))
1089 (concat
1090 (if org-agenda-time-leading-zero
1091 (format "%02d" hour-number)
1092 (format "%02s" (number-to-string hour-number)))
1093 ":" minute ampm)))
1095 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1096 "Conditionally convert TIME to AM/PM format
1097 based on `org-agenda-timegrid-use-ampm'"
1098 (if org-agenda-timegrid-use-ampm
1099 (org-agenda-time-of-day-to-ampm time)
1100 time))
1102 (defcustom org-agenda-weekend-days '(6 0)
1103 "Which days are weekend?
1104 These days get the special face `org-agenda-date-weekend' in the agenda
1105 and timeline buffers."
1106 :group 'org-agenda-daily/weekly
1107 :type '(set :greedy t
1108 (const :tag "Monday" 1)
1109 (const :tag "Tuesday" 2)
1110 (const :tag "Wednesday" 3)
1111 (const :tag "Thursday" 4)
1112 (const :tag "Friday" 5)
1113 (const :tag "Saturday" 6)
1114 (const :tag "Sunday" 0)))
1116 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1117 "Non-nil means jump to today when moving a past date forward in time.
1118 When using S-right in the agenda to move a a date forward, and the date
1119 stamp currently points to the past, the first key press will move it
1120 to today. WHen nil, just move one day forward even if the date stays
1121 in the past."
1122 :group 'org-agenda-daily/weekly
1123 :version "24.1"
1124 :type 'boolean)
1126 (defcustom org-agenda-include-diary nil
1127 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1128 Custom commands can set this variable in the options section."
1129 :group 'org-agenda-daily/weekly
1130 :type 'boolean)
1132 (defcustom org-agenda-include-deadlines t
1133 "If non-nil, include entries within their deadline warning period.
1134 Custom commands can set this variable in the options section."
1135 :group 'org-agenda-daily/weekly
1136 :version "24.1"
1137 :type 'boolean)
1139 (defcustom org-agenda-repeating-timestamp-show-all t
1140 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1141 When set to a list of strings, only show occurrences of repeating
1142 stamps for these TODO keywords. When nil, only one occurrence is
1143 shown, either today or the nearest into the future."
1144 :group 'org-agenda-daily/weekly
1145 :type '(choice
1146 (const :tag "Show repeating stamps" t)
1147 (repeat :tag "Show repeating stamps for these TODO keywords"
1148 (string :tag "TODO Keyword"))
1149 (const :tag "Don't show repeating stamps" nil)))
1151 (defcustom org-scheduled-past-days 10000
1152 "No. of days to continue listing scheduled items that are not marked DONE.
1153 When an item is scheduled on a date, it shows up in the agenda on this
1154 day and will be listed until it is marked done for the number of days
1155 given here."
1156 :group 'org-agenda-daily/weekly
1157 :type 'integer)
1159 (defcustom org-agenda-log-mode-items '(closed clock)
1160 "List of items that should be shown in agenda log mode.
1161 This list may contain the following symbols:
1163 closed Show entries that have been closed on that day.
1164 clock Show entries that have received clocked time on that day.
1165 state Show all logged state changes.
1166 Note that instead of changing this variable, you can also press `C-u l' in
1167 the agenda to display all available LOG items temporarily."
1168 :group 'org-agenda-daily/weekly
1169 :type '(set :greedy t (const closed) (const clock) (const state)))
1171 (defcustom org-agenda-clock-consistency-checks
1172 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1173 :gap-ok-around ("4:00")
1174 :default-face ((:background "DarkRed") (:foreground "white"))
1175 :overlap-face nil :gap-face nil :no-end-time-face nil
1176 :long-face nil :short-face nil)
1177 "This is a property list, with the following keys:
1179 :max-duration Mark clocking chunks that are longer than this time.
1180 This is a time string like \"HH:MM\", or the number
1181 of minutes as an integer.
1183 :min-duration Mark clocking chunks that are shorter that this.
1184 This is a time string like \"HH:MM\", or the number
1185 of minutes as an integer.
1187 :max-gap Mark gaps between clocking chunks that are longer than
1188 this duration. A number of minutes, or a string
1189 like \"HH:MM\".
1191 :gap-ok-around List of times during the day which are usually not working
1192 times. When a gap is detected, but the gap contains any
1193 of these times, the gap is *not* reported. For example,
1194 if this is (\"4:00\" \"13:00\") then gaps that contain
1195 4:00 in the morning (i.e. the night) and 13:00
1196 (i.e. a typical lunch time) do not cause a warning.
1197 You should have at least one time during the night in this
1198 list, or otherwise the first task each morning will trigger
1199 a warning because it follows a long gap.
1201 Furthermore, the following properties can be used to define faces for
1202 issue display.
1204 :default-face the default face, if the specific face is undefined
1205 :overlap-face face for overlapping clocks
1206 :gap-face face for gaps between clocks
1207 :no-end-time-face face for incomplete clocks
1208 :long-face face for clock intervals that are too long
1209 :short-face face for clock intervals that are too short"
1210 :group 'org-agenda-daily/weekly
1211 :group 'org-clock
1212 :version "24.1"
1213 :type 'plist)
1215 (defcustom org-agenda-log-mode-add-notes t
1216 "Non-nil means add first line of notes to log entries in agenda views.
1217 If a log item like a state change or a clock entry is associated with
1218 notes, the first line of these notes will be added to the entry in the
1219 agenda display."
1220 :group 'org-agenda-daily/weekly
1221 :type 'boolean)
1223 (defcustom org-agenda-start-with-log-mode nil
1224 "The initial value of log-mode in a newly created agenda window.
1225 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1226 explanations on the possible values."
1227 :group 'org-agenda-startup
1228 :group 'org-agenda-daily/weekly
1229 :type '(choice (const :tag "Don't show log items" nil)
1230 (const :tag "Show only log items" 'only)
1231 (const :tag "Show all possible log items" 'clockcheck)
1232 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1233 (choice (const :tag "Show closed log items" 'closed)
1234 (const :tag "Show clocked log items" 'clock)
1235 (const :tag "Show all logged state changes" 'state)))))
1237 (defcustom org-agenda-start-with-clockreport-mode nil
1238 "The initial value of clockreport-mode in a newly created agenda window."
1239 :group 'org-agenda-startup
1240 :group 'org-agenda-daily/weekly
1241 :type 'boolean)
1243 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1244 "Property list with parameters for the clocktable in clockreport mode.
1245 This is the display mode that shows a clock table in the daily/weekly
1246 agenda, the properties for this dynamic block can be set here.
1247 The usual clocktable parameters are allowed here, but you cannot set
1248 the properties :name, :tstart, :tend, :block, and :scope - these will
1249 be overwritten to make sure the content accurately reflects the
1250 current display in the agenda."
1251 :group 'org-agenda-daily/weekly
1252 :type 'plist)
1254 (defcustom org-agenda-search-view-always-boolean nil
1255 "Non-nil means the search string is interpreted as individual parts.
1257 The search string for search view can either be interpreted as a phrase,
1258 or as a list of snippets that define a boolean search for a number of
1259 strings.
1261 When this is non-nil, the string will be split on whitespace, and each
1262 snippet will be searched individually, and all must match in order to
1263 select an entry. A snippet is then a single string of non-white
1264 characters, or a string in double quotes, or a regexp in {} braces.
1265 If a snippet is preceded by \"-\", the snippet must *not* match.
1266 \"+\" is syntactic sugar for positive selection. Each snippet may
1267 be found as a full word or a partial word, but see the variable
1268 `org-agenda-search-view-force-full-words'.
1270 When this is nil, search will look for the entire search phrase as one,
1271 with each space character matching any amount of whitespace, including
1272 line breaks.
1274 Even when this is nil, you can still switch to Boolean search dynamically
1275 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1276 is a regexp marked with braces like \"{abc}\", this will also switch to
1277 boolean search."
1278 :group 'org-agenda-search-view
1279 :version "24.1"
1280 :type 'boolean)
1282 (if (fboundp 'defvaralias)
1283 (defvaralias 'org-agenda-search-view-search-words-only
1284 'org-agenda-search-view-always-boolean))
1286 (defcustom org-agenda-search-view-force-full-words nil
1287 "Non-nil means, search words must be matches as complete words.
1288 When nil, they may also match part of a word."
1289 :group 'org-agenda-search-view
1290 :version "24.1"
1291 :type 'boolean)
1293 (defgroup org-agenda-time-grid nil
1294 "Options concerning the time grid in the Org-mode Agenda."
1295 :tag "Org Agenda Time Grid"
1296 :group 'org-agenda)
1298 (defcustom org-agenda-search-headline-for-time t
1299 "Non-nil means search headline for a time-of-day.
1300 If the headline contains a time-of-day in one format or another, it will
1301 be used to sort the entry into the time sequence of items for a day.
1302 Some people have time stamps in the headline that refer to the creation
1303 time or so, and then this produces an unwanted side effect. If this is
1304 the case for your, use this variable to turn off searching the headline
1305 for a time."
1306 :group 'org-agenda-time-grid
1307 :type 'boolean)
1309 (defcustom org-agenda-use-time-grid t
1310 "Non-nil means show a time grid in the agenda schedule.
1311 A time grid is a set of lines for specific times (like every two hours between
1312 8:00 and 20:00). The items scheduled for a day at specific times are
1313 sorted in between these lines.
1314 For details about when the grid will be shown, and what it will look like, see
1315 the variable `org-agenda-time-grid'."
1316 :group 'org-agenda-time-grid
1317 :type 'boolean)
1319 (defcustom org-agenda-time-grid
1320 '((daily today require-timed)
1321 "----------------"
1322 (800 1000 1200 1400 1600 1800 2000))
1324 "The settings for time grid for agenda display.
1325 This is a list of three items. The first item is again a list. It contains
1326 symbols specifying conditions when the grid should be displayed:
1328 daily if the agenda shows a single day
1329 weekly if the agenda shows an entire week
1330 today show grid on current date, independent of daily/weekly display
1331 require-timed show grid only if at least one item has a time specification
1333 The second item is a string which will be placed behind the grid time.
1335 The third item is a list of integers, indicating the times that should have
1336 a grid line."
1337 :group 'org-agenda-time-grid
1338 :type
1339 '(list
1340 (set :greedy t :tag "Grid Display Options"
1341 (const :tag "Show grid in single day agenda display" daily)
1342 (const :tag "Show grid in weekly agenda display" weekly)
1343 (const :tag "Always show grid for today" today)
1344 (const :tag "Show grid only if any timed entries are present"
1345 require-timed)
1346 (const :tag "Skip grid times already present in an entry"
1347 remove-match))
1348 (string :tag "Grid String")
1349 (repeat :tag "Grid Times" (integer :tag "Time"))))
1351 (defcustom org-agenda-show-current-time-in-grid t
1352 "Non-nil means show the current time in the time grid."
1353 :group 'org-agenda-time-grid
1354 :version "24.1"
1355 :type 'boolean)
1357 (defcustom org-agenda-current-time-string
1358 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1359 "The string for the current time marker in the agenda."
1360 :group 'org-agenda-time-grid
1361 :version "24.1"
1362 :type 'string)
1364 (defgroup org-agenda-sorting nil
1365 "Options concerning sorting in the Org-mode Agenda."
1366 :tag "Org Agenda Sorting"
1367 :group 'org-agenda)
1369 (defcustom org-agenda-sorting-strategy
1370 '((agenda habit-down time-up priority-down category-keep)
1371 (todo priority-down category-keep)
1372 (tags priority-down category-keep)
1373 (search category-keep))
1374 "Sorting structure for the agenda items of a single day.
1375 This is a list of symbols which will be used in sequence to determine
1376 if an entry should be listed before another entry. The following
1377 symbols are recognized:
1379 time-up Put entries with time-of-day indications first, early first
1380 time-down Put entries with time-of-day indications first, late first
1381 category-keep Keep the default order of categories, corresponding to the
1382 sequence in `org-agenda-files'.
1383 category-up Sort alphabetically by category, A-Z.
1384 category-down Sort alphabetically by category, Z-A.
1385 tag-up Sort alphabetically by last tag, A-Z.
1386 tag-down Sort alphabetically by last tag, Z-A.
1387 priority-up Sort numerically by priority, high priority last.
1388 priority-down Sort numerically by priority, high priority first.
1389 todo-state-up Sort by todo state, tasks that are done last.
1390 todo-state-down Sort by todo state, tasks that are done first.
1391 effort-up Sort numerically by estimated effort, high effort last.
1392 effort-down Sort numerically by estimated effort, high effort first.
1393 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1394 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1395 habit-up Put entries that are habits first
1396 habit-down Put entries that are habits last
1397 alpha-up Sort headlines alphabetically
1398 alpha-down Sort headlines alphabetically, reversed
1400 The different possibilities will be tried in sequence, and testing stops
1401 if one comparison returns a \"not-equal\". For example, the default
1402 '(time-up category-keep priority-down)
1403 means: Pull out all entries having a specified time of day and sort them,
1404 in order to make a time schedule for the current day the first thing in the
1405 agenda listing for the day. Of the entries without a time indication, keep
1406 the grouped in categories, don't sort the categories, but keep them in
1407 the sequence given in `org-agenda-files'. Within each category sort by
1408 priority.
1410 Leaving out `category-keep' would mean that items will be sorted across
1411 categories by priority.
1413 Instead of a single list, this can also be a set of list for specific
1414 contents, with a context symbol in the car of the list, any of
1415 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1417 Custom commands can bind this variable in the options section."
1418 :group 'org-agenda-sorting
1419 :type `(choice
1420 (repeat :tag "General" ,org-sorting-choice)
1421 (list :tag "Individually"
1422 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1423 (repeat ,org-sorting-choice))
1424 (cons (const :tag "Strategy for TODO lists" todo)
1425 (repeat ,org-sorting-choice))
1426 (cons (const :tag "Strategy for Tags matches" tags)
1427 (repeat ,org-sorting-choice))
1428 (cons (const :tag "Strategy for search matches" search)
1429 (repeat ,org-sorting-choice)))))
1431 (defcustom org-agenda-cmp-user-defined nil
1432 "A function to define the comparison `user-defined'.
1433 This function must receive two arguments, agenda entry a and b.
1434 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1435 the user comparison, return nil.
1436 When this is defined, you can make `user-defined-up' and `user-defined-down'
1437 part of an agenda sorting strategy."
1438 :group 'org-agenda-sorting
1439 :type 'symbol)
1441 (defcustom org-sort-agenda-notime-is-late t
1442 "Non-nil means items without time are considered late.
1443 This is only relevant for sorting. When t, items which have no explicit
1444 time like 15:30 will be considered as 99:01, i.e. later than any items which
1445 do have a time. When nil, the default time is before 0:00. You can use this
1446 option to decide if the schedule for today should come before or after timeless
1447 agenda entries."
1448 :group 'org-agenda-sorting
1449 :type 'boolean)
1451 (defcustom org-sort-agenda-noeffort-is-high t
1452 "Non-nil means items without effort estimate are sorted as high effort.
1453 This also applies when filtering an agenda view with respect to the
1454 < or > effort operator. Then, tasks with no effort defined will be treated
1455 as tasks with high effort.
1456 When nil, such items are sorted as 0 minutes effort."
1457 :group 'org-agenda-sorting
1458 :type 'boolean)
1460 (defgroup org-agenda-line-format nil
1461 "Options concerning the entry prefix in the Org-mode agenda display."
1462 :tag "Org Agenda Line Format"
1463 :group 'org-agenda)
1465 (defcustom org-agenda-prefix-format
1466 '((agenda . " %i %-12:c%?-12t% s")
1467 (timeline . " % s")
1468 (todo . " %i %-12:c")
1469 (tags . " %i %-12:c")
1470 (search . " %i %-12:c"))
1471 "Format specifications for the prefix of items in the agenda views.
1472 An alist with five entries, each for the different agenda types. The
1473 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1474 The values are format strings.
1476 This format works similar to a printf format, with the following meaning:
1478 %c the category of the item, \"Diary\" for entries from the diary,
1479 or as given by the CATEGORY keyword or derived from the file name
1480 %e the effort required by the item
1481 %i the icon category of the item, see `org-agenda-category-icon-alist'
1482 %T the last tag of the item (ignore inherited tags, which come first)
1483 %t the HH:MM time-of-day specification if one applies to the entry
1484 %s Scheduling/Deadline information, a short string
1485 %(expression) Eval EXPRESSION and replace the control string
1486 by the result
1488 All specifiers work basically like the standard `%s' of printf, but may
1489 contain two additional characters: a question mark just after the `%'
1490 and a whitespace/punctuation character just before the final letter.
1492 If the first character after `%' is a question mark, the entire field
1493 will only be included if the corresponding value applies to the current
1494 entry. This is useful for fields which should have fixed width when
1495 present, but zero width when absent. For example, \"%?-12t\" will
1496 result in a 12 character time field if a time of the day is specified,
1497 but will completely disappear in entries which do not contain a time.
1499 If there is punctuation or whitespace character just before the final
1500 format letter, this character will be appended to the field value if
1501 the value is not empty. For example, the format \"%-12:c\" leads to
1502 \"Diary: \" if the category is \"Diary\". If the category were be
1503 empty, no additional colon would be inserted.
1505 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1506 which means:
1508 - Indent the line with two space characters
1509 - Give the category a 12 chars wide field, padded with whitespace on
1510 the right (because of `-'). Append a colon if there is a category
1511 (because of `:').
1512 - If there is a time-of-day, put it into a 12 chars wide field. If no
1513 time, don't put in an empty field, just skip it (because of '?').
1514 - Finally, put the scheduling information.
1516 See also the variables `org-agenda-remove-times-when-in-prefix' and
1517 `org-agenda-remove-tags'.
1519 Custom commands can set this variable in the options section."
1520 :type '(choice
1521 (string :tag "General format")
1522 (list :greedy t :tag "View dependent"
1523 (cons (const agenda) (string :tag "Format"))
1524 (cons (const timeline) (string :tag "Format"))
1525 (cons (const todo) (string :tag "Format"))
1526 (cons (const tags) (string :tag "Format"))
1527 (cons (const search) (string :tag "Format"))))
1528 :group 'org-agenda-line-format)
1530 (defvar org-prefix-format-compiled nil
1531 "The compiled prefix format and associated variables.
1532 This is a list where first element is a list of variable bindings, and second
1533 element is the compiled format expression. See the variable
1534 `org-agenda-prefix-format'.")
1536 (defcustom org-agenda-todo-keyword-format "%-1s"
1537 "Format for the TODO keyword in agenda lines.
1538 Set this to something like \"%-12s\" if you want all TODO keywords
1539 to occupy a fixed space in the agenda display."
1540 :group 'org-agenda-line-format
1541 :type 'string)
1543 (defcustom org-agenda-diary-sexp-prefix nil
1544 "A regexp that matches part of a diary sexp entry
1545 which should be treated as scheduling/deadline information in
1546 `org-agenda'.
1548 For example, you can use this to extract the `diary-remind-message' from
1549 `diary-remind' entries."
1550 :group 'org-agenda-line-format
1551 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1553 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1554 "Text preceding timerange entries in the agenda view.
1555 This is a list with two strings. The first applies when the range
1556 is entirely on one day. The second applies if the range spans several days.
1557 The strings may have two \"%d\" format specifiers which will be filled
1558 with the sequence number of the days, and the total number of days in the
1559 range, respectively."
1560 :group 'org-agenda-line-format
1561 :type '(list
1562 (string :tag "Deadline today ")
1563 (choice :tag "Deadline relative"
1564 (string :tag "Format string")
1565 (function))))
1567 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1568 "Text preceding scheduled items in the agenda view.
1569 This is a list with two strings. The first applies when the item is
1570 scheduled on the current day. The second applies when it has been scheduled
1571 previously, it may contain a %d indicating that this is the nth time that
1572 this item is scheduled, due to automatic rescheduling of unfinished items
1573 for the following day. So this number is one larger than the number of days
1574 that passed since this item was scheduled first."
1575 :group 'org-agenda-line-format
1576 :type '(list
1577 (string :tag "Scheduled today ")
1578 (string :tag "Scheduled previously")))
1580 (defcustom org-agenda-inactive-leader "["
1581 "Text preceding item pulled into the agenda by inactive time stamps.
1582 These entries are added to the agenda when pressing \"[\"."
1583 :group 'org-agenda-line-format
1584 :version "24.1"
1585 :type '(list
1586 (string :tag "Scheduled today ")
1587 (string :tag "Scheduled previously")))
1589 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1590 "Text preceding deadline items in the agenda view.
1591 This is a list with two strings. The first applies when the item has its
1592 deadline on the current day. The second applies when it is in the past or
1593 in the future, it may contain %d to capture how many days away the deadline
1594 is (was)."
1595 :group 'org-agenda-line-format
1596 :type '(list
1597 (string :tag "Deadline today ")
1598 (choice :tag "Deadline relative"
1599 (string :tag "Format string")
1600 (function))))
1602 (defcustom org-agenda-remove-times-when-in-prefix t
1603 "Non-nil means remove duplicate time specifications in agenda items.
1604 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1605 time-of-day specification in a headline or diary entry is extracted and
1606 placed into the prefix. If this option is non-nil, the original specification
1607 \(a timestamp or -range, or just a plain time(range) specification like
1608 11:30-4pm) will be removed for agenda display. This makes the agenda less
1609 cluttered.
1610 The option can be t or nil. It may also be the symbol `beg', indicating
1611 that the time should only be removed when it is located at the beginning of
1612 the headline/diary entry."
1613 :group 'org-agenda-line-format
1614 :type '(choice
1615 (const :tag "Always" t)
1616 (const :tag "Never" nil)
1617 (const :tag "When at beginning of entry" beg)))
1619 (defcustom org-agenda-remove-timeranges-from-blocks nil
1620 "Non-nil means remove time ranges specifications in agenda
1621 items that span on several days."
1622 :group 'org-agenda-line-format
1623 :version "24.1"
1624 :type 'boolean)
1626 (defcustom org-agenda-default-appointment-duration nil
1627 "Default duration for appointments that only have a starting time.
1628 When nil, no duration is specified in such cases.
1629 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1630 :group 'org-agenda-line-format
1631 :type '(choice
1632 (integer :tag "Minutes")
1633 (const :tag "No default duration")))
1635 (defcustom org-agenda-show-inherited-tags t
1636 "Non-nil means show inherited tags in each agenda line."
1637 :group 'org-agenda-line-format
1638 :type 'boolean)
1640 (defcustom org-agenda-hide-tags-regexp nil
1641 "Regular expression used to filter away specific tags in agenda views.
1642 This means that these tags will be present, but not be shown in the agenda
1643 line. Secondary filtering will still work on the hidden tags.
1644 Nil means don't hide any tags."
1645 :group 'org-agenda-line-format
1646 :type '(choice
1647 (const :tag "Hide none" nil)
1648 (string :tag "Regexp ")))
1650 (defcustom org-agenda-remove-tags nil
1651 "Non-nil means remove the tags from the headline copy in the agenda.
1652 When this is the symbol `prefix', only remove tags when
1653 `org-agenda-prefix-format' contains a `%T' specifier."
1654 :group 'org-agenda-line-format
1655 :type '(choice
1656 (const :tag "Always" t)
1657 (const :tag "Never" nil)
1658 (const :tag "When prefix format contains %T" prefix)))
1660 (if (fboundp 'defvaralias)
1661 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1662 'org-agenda-remove-tags))
1664 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1665 "Shift tags in agenda items to this column.
1666 If this number is positive, it specifies the column. If it is negative,
1667 it means that the tags should be flushright to that column. For example,
1668 -80 works well for a normal 80 character screen."
1669 :group 'org-agenda-line-format
1670 :type 'integer)
1672 (if (fboundp 'defvaralias)
1673 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1675 (defcustom org-agenda-fontify-priorities 'cookies
1676 "Non-nil means highlight low and high priorities in agenda.
1677 When t, the highest priority entries are bold, lowest priority italic.
1678 However, settings in `org-priority-faces' will overrule these faces.
1679 When this variable is the symbol `cookies', only fontify the
1680 cookies, not the entire task.
1681 This may also be an association list of priority faces, whose
1682 keys are the character values of `org-highest-priority',
1683 `org-default-priority', and `org-lowest-priority' (the default values
1684 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1685 color as a string, or a list like `(:background \"Red\")'.
1686 If it is a color, the variable `org-faces-easy-properties'
1687 determines if it is a foreground or a background color."
1688 :group 'org-agenda-line-format
1689 :type '(choice
1690 (const :tag "Never" nil)
1691 (const :tag "Defaults" t)
1692 (const :tag "Cookies only" cookies)
1693 (repeat :tag "Specify"
1694 (list (character :tag "Priority" :value ?A)
1695 (choice :tag "Face "
1696 (string :tag "Color")
1697 (sexp :tag "Face"))))))
1699 (defcustom org-agenda-day-face-function nil
1700 "Function called to determine what face should be used to display a day.
1701 The only argument passed to that function is the day. It should
1702 returns a face, or nil if does not want to specify a face and let
1703 the normal rules apply."
1704 :group 'org-agenda-line-format
1705 :version "24.1"
1706 :type 'function)
1708 (defcustom org-agenda-category-icon-alist nil
1709 "Alist of category icon to be displayed in agenda views.
1711 Each entry should have the following format:
1713 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1715 Where CATEGORY-REGEXP is a regexp matching the categories where
1716 the icon should be displayed.
1717 FILE-OR-DATA either a file path or a string containing image data.
1719 The other fields can be omitted safely if not needed:
1720 TYPE indicates the image type.
1721 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1722 image data.
1723 PROPS are additional image attributes to assign to the image,
1724 like, e.g. `:ascent center'.
1726 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1728 If you want to set the display properties yourself, just put a
1729 list as second element:
1731 (CATEGORY-REGEXP (MY PROPERTY LIST))
1733 For example, to display a 16px horizontal space for Emacs
1734 category, you can use:
1736 (\"Emacs\" '(space . (:width (16))))"
1737 :group 'org-agenda-line-format
1738 :version "24.1"
1739 :type '(alist :key-type (string :tag "Regexp matching category")
1740 :value-type (choice (list :tag "Icon"
1741 (string :tag "File or data")
1742 (symbol :tag "Type")
1743 (boolean :tag "Data?")
1744 (repeat :tag "Extra image properties" :inline t symbol))
1745 (list :tag "Display properties" sexp))))
1747 (defgroup org-agenda-column-view nil
1748 "Options concerning column view in the agenda."
1749 :tag "Org Agenda Column View"
1750 :group 'org-agenda)
1752 (defcustom org-agenda-columns-show-summaries t
1753 "Non-nil means show summaries for columns displayed in the agenda view."
1754 :group 'org-agenda-column-view
1755 :type 'boolean)
1757 (defcustom org-agenda-columns-compute-summary-properties t
1758 "Non-nil means recompute all summary properties before column view.
1759 When column view in the agenda is listing properties that have a summary
1760 operator, it can go to all relevant buffers and recompute the summaries
1761 there. This can mean overhead for the agenda column view, but is necessary
1762 to have thing up to date.
1763 As a special case, a CLOCKSUM property also makes sure that the clock
1764 computations are current."
1765 :group 'org-agenda-column-view
1766 :type 'boolean)
1768 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1769 "Non-nil means the duration of an appointment will add to day effort.
1770 The property to which appointment durations will be added is the one given
1771 in the option `org-effort-property'. If an appointment does not have
1772 an end time, `org-agenda-default-appointment-duration' will be used. If that
1773 is not set, an appointment without end time will not contribute to the time
1774 estimate."
1775 :group 'org-agenda-column-view
1776 :type 'boolean)
1778 (defcustom org-agenda-auto-exclude-function nil
1779 "A function called with a tag to decide if it is filtered on '/ RET'.
1780 The sole argument to the function, which is called once for each
1781 possible tag, is a string giving the name of the tag. The
1782 function should return either nil if the tag should be included
1783 as normal, or \"-<TAG>\" to exclude the tag.
1784 Note that for the purpose of tag filtering, only the lower-case version of
1785 all tags will be considered, so that this function will only ever see
1786 the lower-case version of all tags."
1787 :group 'org-agenda
1788 :type 'function)
1790 (defcustom org-agenda-bulk-custom-functions nil
1791 "Alist of characters and custom functions for bulk actions.
1792 For example, this value makes those two functions available:
1794 '((?R set-category)
1795 (?C bulk-cut))
1797 With selected entries in an agenda buffer, `B R' will call
1798 the custom function `set-category' on the selected entries.
1799 Note that functions in this alist don't need to be quoted."
1800 :type 'alist
1801 :version "24.1"
1802 :group 'org-agenda)
1804 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1805 "Execute BODY with point at location given by `org-hd-marker' property.
1806 If STRING is non-nil, the text property will be fetched from position 0
1807 in that string. If STRING is nil, it will be fetched from the beginning
1808 of the current line."
1809 (org-with-gensyms (marker)
1810 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1811 'org-hd-marker ,string)))
1812 (with-current-buffer (marker-buffer ,marker)
1813 (save-excursion
1814 (goto-char ,marker)
1815 ,@body)))))
1816 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1818 (defun org-add-agenda-custom-command (entry)
1819 "Replace or add a command in `org-agenda-custom-commands'.
1820 This is mostly for hacking and trying a new command - once the command
1821 works you probably want to add it to `org-agenda-custom-commands' for good."
1822 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1823 (if ass
1824 (setcdr ass (cdr entry))
1825 (push entry org-agenda-custom-commands))))
1827 ;;; Define the org-agenda-mode
1829 (defvar org-agenda-mode-map (make-sparse-keymap)
1830 "Keymap for `org-agenda-mode'.")
1831 (if (fboundp 'defvaralias)
1832 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1834 (defvar org-agenda-menu) ; defined later in this file.
1835 (defvar org-agenda-restrict) ; defined later in this file.
1836 (defvar org-agenda-follow-mode nil)
1837 (defvar org-agenda-entry-text-mode nil)
1838 (defvar org-agenda-clockreport-mode nil)
1839 (defvar org-agenda-show-log nil)
1840 (defvar org-agenda-redo-command nil)
1841 (defvar org-agenda-query-string nil)
1842 (defvar org-agenda-mode-hook nil
1843 "Hook for `org-agenda-mode', run after the mode is turned on.")
1844 (defvar org-agenda-type nil)
1845 (defvar org-agenda-force-single-file nil)
1846 (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
1849 ;;; Multiple agenda buffers support
1851 (defcustom org-agenda-sticky nil
1852 "Non-nil means agenda q key will bury agenda buffers.
1853 Agenda commands will then show existing buffer instead of generating new ones.
1854 When nil, `q' will kill the single agenda buffer."
1855 :group 'org-agenda
1856 :type 'boolean
1857 :set (lambda (var val)
1858 (if (boundp var)
1859 (org-toggle-sticky-agenda (if val 1 0))
1860 (set var val))))
1862 (defun org-toggle-sticky-agenda (&optional arg)
1863 "Toggle `org-agenda-sticky'."
1864 (interactive "P")
1865 (let ((new-value (if arg
1866 (> (prefix-numeric-value arg) 0)
1867 (not org-agenda-sticky))))
1868 (if (equal new-value org-agenda-sticky)
1869 (and (org-called-interactively-p 'interactive)
1870 (message "Sticky agenda was already %s"
1871 (if org-agenda-sticky "enabled" "disabled")))
1872 (setq org-agenda-sticky new-value)
1873 (org-agenda-kill-all-agenda-buffers)
1874 (and (org-called-interactively-p 'interactive)
1875 (message "Sticky agenda was %s"
1876 (if org-agenda-sticky "enabled" "disabled"))))))
1878 (defvar org-agenda-buffer nil
1879 "Agenda buffer currently being generated.")
1881 (defvar org-agenda-last-prefix-arg nil)
1882 (defvar org-agenda-this-buffer-name nil)
1883 (defvar org-agenda-doing-sticky-redo nil)
1884 (defvar org-agenda-this-buffer-is-sticky nil)
1886 (defconst org-agenda-local-vars
1887 '(org-agenda-this-buffer-name
1888 org-agenda-undo-list
1889 org-agenda-pending-undo-list
1890 org-agenda-follow-mode
1891 org-agenda-entry-text-mode
1892 org-agenda-clockreport-mode
1893 org-agenda-show-log
1894 org-agenda-redo-command
1895 org-agenda-query-string
1896 org-agenda-type
1897 org-agenda-bulk-marked-entries
1898 org-agenda-undo-has-started-in
1899 org-agenda-last-arguments
1900 org-agenda-info
1901 org-agenda-tag-filter-overlays
1902 org-agenda-cat-filter-overlays
1903 org-pre-agenda-window-conf
1904 org-agenda-columns-active
1905 org-agenda-tag-filter
1906 org-agenda-category-filter
1907 org-agenda-markers
1908 org-agenda-last-search-view-search-was-boolean
1909 org-agenda-filtered-by-category
1910 org-agenda-filter-form
1911 org-agenda-show-window
1912 org-agenda-cycle-counter
1913 org-agenda-last-prefix-arg)
1914 "Variables that must be local in agenda buffers to allow multiple buffers.")
1916 (defun org-agenda-mode ()
1917 "Mode for time-sorted view on action items in Org-mode files.
1919 The following commands are available:
1921 \\{org-agenda-mode-map}"
1922 (interactive)
1923 (cond (org-agenda-doing-sticky-redo
1924 ;; Refreshing sticky agenda-buffer
1926 ;; Preserve the value of `org-agenda-local-vars' variables,
1927 ;; while letting `kill-all-local-variables' kill the rest
1928 (let ((save (buffer-local-variables)))
1929 (kill-all-local-variables)
1930 (mapc 'make-local-variable org-agenda-local-vars)
1931 (dolist (elem save)
1932 (let ((var (car elem))
1933 (val (cdr elem)))
1934 (when (and val
1935 (member var org-agenda-local-vars))
1936 (set var val)))))
1937 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1938 (org-agenda-sticky
1939 ;; Creating a sticky Agenda buffer for the first time
1940 (kill-all-local-variables)
1941 (mapc 'make-local-variable org-agenda-local-vars)
1942 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1944 ;; Creating a non-sticky agenda buffer
1945 (kill-all-local-variables)
1946 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1947 (setq org-agenda-undo-list nil
1948 org-agenda-pending-undo-list nil
1949 org-agenda-bulk-marked-entries nil)
1950 (setq major-mode 'org-agenda-mode)
1951 ;; Keep global-font-lock-mode from turning on font-lock-mode
1952 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1953 (setq mode-name "Org-Agenda")
1954 (use-local-map org-agenda-mode-map)
1955 (easy-menu-add org-agenda-menu)
1956 (if org-startup-truncated (setq truncate-lines t))
1957 (org-set-local 'line-move-visual nil)
1958 (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
1959 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
1960 ;; Make sure properties are removed when copying text
1961 (make-local-variable 'filter-buffer-substring-functions)
1962 (add-hook 'filter-buffer-substring-functions
1963 (lambda (fun start end delete)
1964 (substring-no-properties (funcall fun start end delete))))
1965 (unless org-agenda-keep-modes
1966 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
1967 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
1968 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
1969 org-agenda-show-log org-agenda-start-with-log-mode))
1971 (easy-menu-change
1972 '("Agenda") "Agenda Files"
1973 (append
1974 (list
1975 (vector
1976 (if (get 'org-agenda-files 'org-restrict)
1977 "Restricted to single file"
1978 "Edit File List")
1979 '(org-edit-agenda-file-list)
1980 (not (get 'org-agenda-files 'org-restrict)))
1981 "--")
1982 (mapcar 'org-file-menu-entry (org-agenda-files))))
1983 (org-agenda-set-mode-name)
1984 (apply
1985 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
1986 (list 'org-agenda-mode-hook)))
1988 (substitute-key-definition 'undo 'org-agenda-undo
1989 org-agenda-mode-map global-map)
1990 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
1991 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
1992 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
1993 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
1994 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
1995 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
1996 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
1997 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
1998 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
1999 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2000 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2001 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2002 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2003 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2004 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2005 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2006 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2007 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2008 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2009 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2010 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2011 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2012 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2013 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2014 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2015 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2016 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2017 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2018 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2019 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2020 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2021 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2022 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2023 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2024 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2025 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2026 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2027 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2028 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2029 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2030 (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
2031 (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
2032 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2033 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2034 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2035 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2037 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2038 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2039 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2040 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2041 (while l (org-defkey org-agenda-mode-map
2042 (int-to-string (pop l)) 'digit-argument)))
2044 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2045 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2046 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2047 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2048 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2049 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2050 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2051 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2052 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2053 (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
2054 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2055 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2056 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2057 'org-clock-modify-effort-estimate)
2058 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2059 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2060 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2061 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2062 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2063 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2064 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2065 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2066 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2067 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2068 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2069 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2070 (substitute-key-definition 'next-line 'org-agenda-next-line
2071 org-agenda-mode-map global-map)
2072 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2073 org-agenda-mode-map global-map)
2074 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2075 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2076 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2077 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2078 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
2079 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2080 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2081 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2082 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2083 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2084 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2085 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2086 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2087 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2088 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2089 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2090 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2091 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2092 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2093 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2094 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2095 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2096 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2097 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2098 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2099 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2100 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2101 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2102 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2103 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2105 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2106 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2107 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2108 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2109 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2110 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2111 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2112 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2113 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2114 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2115 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2116 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2118 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2119 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2120 (when org-agenda-mouse-1-follows-link
2121 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2122 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2123 '("Agenda"
2124 ("Agenda Files")
2125 "--"
2126 ("Agenda Dates"
2127 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2128 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2129 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2130 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2131 "--"
2132 ("View"
2133 ["Day View" org-agenda-day-view
2134 :active (org-agenda-check-type nil 'agenda)
2135 :style radio :selected (eq org-agenda-current-span 'day)
2136 :keys "v d (or just d)"]
2137 ["Week View" org-agenda-week-view
2138 :active (org-agenda-check-type nil 'agenda)
2139 :style radio :selected (eq org-agenda-current-span 'week)
2140 :keys "v w (or just w)"]
2141 ["Month View" org-agenda-month-view
2142 :active (org-agenda-check-type nil 'agenda)
2143 :style radio :selected (eq org-agenda-current-span 'month)
2144 :keys "v m"]
2145 ["Year View" org-agenda-year-view
2146 :active (org-agenda-check-type nil 'agenda)
2147 :style radio :selected (eq org-agenda-current-span 'year)
2148 :keys "v y"]
2149 "--"
2150 ["Include Diary" org-agenda-toggle-diary
2151 :style toggle :selected org-agenda-include-diary
2152 :active (org-agenda-check-type nil 'agenda)]
2153 ["Include Deadlines" org-agenda-toggle-deadlines
2154 :style toggle :selected org-agenda-include-deadlines
2155 :active (org-agenda-check-type nil 'agenda)]
2156 ["Use Time Grid" org-agenda-toggle-time-grid
2157 :style toggle :selected org-agenda-use-time-grid
2158 :active (org-agenda-check-type nil 'agenda)]
2159 "--"
2160 ["Show clock report" org-agenda-clockreport-mode
2161 :style toggle :selected org-agenda-clockreport-mode
2162 :active (org-agenda-check-type nil 'agenda)]
2163 ["Show some entry text" org-agenda-entry-text-mode
2164 :style toggle :selected org-agenda-entry-text-mode
2165 :active t]
2166 "--"
2167 ["Show Logbook entries" org-agenda-log-mode
2168 :style toggle :selected org-agenda-show-log
2169 :active (org-agenda-check-type nil 'agenda 'timeline)
2170 :keys "v l (or just l)"]
2171 ["Include archived trees" org-agenda-archives-mode
2172 :style toggle :selected org-agenda-archives-mode :active t
2173 :keys "v a"]
2174 ["Include archive files" (org-agenda-archives-mode t)
2175 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2176 :keys "v A"]
2177 "--"
2178 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2179 ["Write view to file" org-agenda-write t]
2180 ["Rebuild buffer" org-agenda-redo t]
2181 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2182 "--"
2183 ["Show original entry" org-agenda-show t]
2184 ["Go To (other window)" org-agenda-goto t]
2185 ["Go To (this window)" org-agenda-switch-to t]
2186 ["Follow Mode" org-agenda-follow-mode
2187 :style toggle :selected org-agenda-follow-mode :active t]
2188 ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2189 "--"
2190 ("TODO"
2191 ["Cycle TODO" org-agenda-todo t]
2192 ["Next TODO set" org-agenda-todo-nextset t]
2193 ["Previous TODO set" org-agenda-todo-previousset t]
2194 ["Add note" org-agenda-add-note t])
2195 ("Archive/Refile/Delete"
2196 ["Archive default" org-agenda-archive-default t]
2197 ["Archive default" org-agenda-archive-default-with-confirmation t]
2198 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2199 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2200 ["Archive subtree" org-agenda-archive t]
2201 "--"
2202 ["Refile" org-agenda-refile t]
2203 "--"
2204 ["Delete subtree" org-agenda-kill t])
2205 ("Bulk action"
2206 ["Mark entry" org-agenda-bulk-mark t]
2207 ["Mark all" org-agenda-bulk-mark-all t]
2208 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2209 ["Unmark entry" org-agenda-bulk-unmark t]
2210 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
2211 ["Act on all marked" org-agenda-bulk-action t]
2212 "--"
2213 ("Tags and Properties"
2214 ["Show all Tags" org-agenda-show-tags t]
2215 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2216 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2217 "--"
2218 ["Column View" org-columns t])
2219 ("Deadline/Schedule"
2220 ["Schedule" org-agenda-schedule t]
2221 ["Set Deadline" org-agenda-deadline t]
2222 "--"
2223 ["Mark item" org-agenda-action :active t :keys "k m"]
2224 ["Show mark item" org-agenda-action :active t :keys "k v"]
2225 ["Schedule marked item" org-agenda-action :active t :keys "k s"]
2226 ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
2227 "--"
2228 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2229 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2230 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2231 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2232 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2233 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2234 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2235 ("Clock and Effort"
2236 ["Clock in" org-agenda-clock-in t]
2237 ["Clock out" org-agenda-clock-out t]
2238 ["Clock cancel" org-agenda-clock-cancel t]
2239 ["Goto running clock" org-clock-goto t]
2240 "--"
2241 ["Set Effort" org-agenda-set-effort t]
2242 ["Change clocked effort" org-clock-modify-effort-estimate
2243 (org-clock-is-active)])
2244 ("Priority"
2245 ["Set Priority" org-agenda-priority t]
2246 ["Increase Priority" org-agenda-priority-up t]
2247 ["Decrease Priority" org-agenda-priority-down t]
2248 ["Show Priority" org-agenda-show-priority t])
2249 ("Calendar/Diary"
2250 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2251 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2252 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2253 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2254 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2255 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2256 "--"
2257 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2258 "--"
2259 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2260 "--"
2261 ("MobileOrg"
2262 ["Push Files and Views" org-mobile-push t]
2263 ["Get Captured and Flagged" org-mobile-pull t]
2264 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2265 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2266 "--"
2267 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2268 "--"
2269 ["Quit" org-agenda-quit t]
2270 ["Exit and Release Buffers" org-agenda-exit t]
2273 ;;; Agenda undo
2275 (defvar org-agenda-allow-remote-undo t
2276 "Non-nil means allow remote undo from the agenda buffer.")
2277 (defvar org-agenda-undo-list nil
2278 "List of undoable operations in the agenda since last refresh.")
2279 (defvar org-agenda-undo-has-started-in nil
2280 "Buffers that have already seen `undo-start' in the current undo sequence.")
2281 (defvar org-agenda-pending-undo-list nil
2282 "In a series of undo commands, this is the list of remaining undo items.")
2284 (defun org-agenda-undo ()
2285 "Undo a remote editing step in the agenda.
2286 This undoes changes both in the agenda buffer and in the remote buffer
2287 that have been changed along."
2288 (interactive)
2289 (or org-agenda-allow-remote-undo
2290 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2291 (if (not (eq this-command last-command))
2292 (setq org-agenda-undo-has-started-in nil
2293 org-agenda-pending-undo-list org-agenda-undo-list))
2294 (if (not org-agenda-pending-undo-list)
2295 (error "No further undo information"))
2296 (let* ((entry (pop org-agenda-pending-undo-list))
2297 buf line cmd rembuf)
2298 (setq cmd (pop entry) line (pop entry))
2299 (setq rembuf (nth 2 entry))
2300 (org-with-remote-undo rembuf
2301 (while (bufferp (setq buf (pop entry)))
2302 (if (pop entry)
2303 (with-current-buffer buf
2304 (let ((last-undo-buffer buf)
2305 (inhibit-read-only t))
2306 (unless (memq buf org-agenda-undo-has-started-in)
2307 (push buf org-agenda-undo-has-started-in)
2308 (make-local-variable 'pending-undo-list)
2309 (undo-start))
2310 (while (and pending-undo-list
2311 (listp pending-undo-list)
2312 (not (car pending-undo-list)))
2313 (pop pending-undo-list))
2314 (undo-more 1))))))
2315 (org-goto-line line)
2316 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2318 (defun org-verify-change-for-undo (l1 l2)
2319 "Verify that a real change occurred between the undo lists L1 and L2."
2320 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2321 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2322 (not (eq l1 l2)))
2324 ;;; Agenda dispatch
2326 (defvar org-agenda-restrict nil)
2327 (defvar org-agenda-restrict-begin (make-marker))
2328 (defvar org-agenda-restrict-end (make-marker))
2329 (defvar org-agenda-last-dispatch-buffer nil)
2330 (defvar org-agenda-overriding-restriction nil)
2332 ;;;###autoload
2333 (defun org-agenda (&optional arg keys restriction)
2334 "Dispatch agenda commands to collect entries to the agenda buffer.
2335 Prompts for a command to execute. Any prefix arg will be passed
2336 on to the selected command. The default selections are:
2338 a Call `org-agenda-list' to display the agenda for current day or week.
2339 t Call `org-todo-list' to display the global todo list.
2340 T Call `org-todo-list' to display the global todo list, select only
2341 entries with a specific TODO keyword (the user gets a prompt).
2342 m Call `org-tags-view' to display headlines with tags matching
2343 a condition (the user is prompted for the condition).
2344 M Like `m', but select only TODO entries, no ordinary headlines.
2345 L Create a timeline for the current buffer.
2346 e Export views to associated files.
2347 s Search entries for keywords.
2348 / Multi occur across all agenda files and also files listed
2349 in `org-agenda-text-search-extra-files'.
2350 < Restrict agenda commands to buffer, subtree, or region.
2351 Press several times to get the desired effect.
2352 > Remove a previous restriction.
2353 # List \"stuck\" projects.
2354 ! Configure what \"stuck\" means.
2355 C Configure custom agenda commands.
2357 More commands can be added by configuring the variable
2358 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2359 searches can be pre-defined in this way.
2361 If the current buffer is in Org-mode and visiting a file, you can also
2362 first press `<' once to indicate that the agenda should be temporarily
2363 \(until the next use of \\[org-agenda]) restricted to the current file.
2364 Pressing `<' twice means to restrict to the current subtree or region
2365 \(if active)."
2366 (interactive "P")
2367 (catch 'exit
2368 (let* ((prefix-descriptions nil)
2369 (org-agenda-buffer-name org-agenda-buffer-name)
2370 (org-agenda-window-setup (if (equal (buffer-name)
2371 org-agenda-buffer-name)
2372 'current-window
2373 org-agenda-window-setup))
2374 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2375 (org-agenda-custom-commands
2376 ;; normalize different versions
2377 (delq nil
2378 (mapcar
2379 (lambda (x)
2380 (cond ((stringp (cdr x))
2381 (push x prefix-descriptions)
2382 nil)
2383 ((stringp (nth 1 x)) x)
2384 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2385 (t (cons (car x) (cons "" (cdr x))))))
2386 org-agenda-custom-commands)))
2387 (buf (current-buffer))
2388 (bfn (buffer-file-name (buffer-base-buffer)))
2389 entry key type match lprops ans)
2390 ;; Turn off restriction unless there is an overriding one,
2391 (unless org-agenda-overriding-restriction
2392 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2393 ;; There is a request to keep the file list in place
2394 (put 'org-agenda-files 'org-restrict nil))
2395 (setq org-agenda-restrict nil)
2396 (move-marker org-agenda-restrict-begin nil)
2397 (move-marker org-agenda-restrict-end nil))
2398 ;; Delete old local properties
2399 (put 'org-agenda-redo-command 'org-lprops nil)
2400 ;; Delete previously set last-arguments
2401 (put 'org-agenda-redo-command 'last-args nil)
2402 ;; Remember where this call originated
2403 (setq org-agenda-last-dispatch-buffer (current-buffer))
2404 (unless keys
2405 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2406 keys (car ans)
2407 restriction (cdr ans)))
2408 ;; If we have sticky agenda buffers, set a name for the buffer,
2409 ;; depending on the invoking keys. The user may still set this
2410 ;; as a command option, which will overwrite what we do here.
2411 (if org-agenda-sticky
2412 (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
2413 ;; Establish the restriction, if any
2414 (when (and (not org-agenda-overriding-restriction) restriction)
2415 (put 'org-agenda-files 'org-restrict (list bfn))
2416 (cond
2417 ((eq restriction 'region)
2418 (setq org-agenda-restrict t)
2419 (move-marker org-agenda-restrict-begin (region-beginning))
2420 (move-marker org-agenda-restrict-end (region-end)))
2421 ((eq restriction 'subtree)
2422 (save-excursion
2423 (setq org-agenda-restrict t)
2424 (org-back-to-heading t)
2425 (move-marker org-agenda-restrict-begin (point))
2426 (move-marker org-agenda-restrict-end
2427 (progn (org-end-of-subtree t)))))))
2429 ;; For example the todo list should not need it (but does...)
2430 (cond
2431 ((setq entry (assoc keys org-agenda-custom-commands))
2432 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2433 (progn
2434 (setq type (nth 2 entry) match (eval (nth 3 entry))
2435 lprops (nth 4 entry))
2436 (put 'org-agenda-redo-command 'org-lprops lprops)
2437 (cond
2438 ((eq type 'agenda)
2439 (org-let lprops '(org-agenda-list current-prefix-arg)))
2440 ((eq type 'alltodo)
2441 (org-let lprops '(org-todo-list current-prefix-arg)))
2442 ((eq type 'search)
2443 (org-let lprops '(org-search-view current-prefix-arg match nil)))
2444 ((eq type 'stuck)
2445 (org-let lprops '(org-agenda-list-stuck-projects
2446 current-prefix-arg)))
2447 ((eq type 'tags)
2448 (org-let lprops '(org-tags-view current-prefix-arg match)))
2449 ((eq type 'tags-todo)
2450 (org-let lprops '(org-tags-view '(4) match)))
2451 ((eq type 'todo)
2452 (org-let lprops '(org-todo-list match)))
2453 ((eq type 'tags-tree)
2454 (org-check-for-org-mode)
2455 (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
2456 ((eq type 'todo-tree)
2457 (org-check-for-org-mode)
2458 (org-let lprops
2459 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2460 (regexp-quote match) "\\>"))))
2461 ((eq type 'occur-tree)
2462 (org-check-for-org-mode)
2463 (org-let lprops '(org-occur match)))
2464 ((functionp type)
2465 (org-let lprops '(funcall type match)))
2466 ((fboundp type)
2467 (org-let lprops '(funcall type match)))
2468 (t (error "Invalid custom agenda command type %s" type))))
2469 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2470 ((equal keys "C")
2471 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2472 (customize-variable 'org-agenda-custom-commands))
2473 ((equal keys "a") (call-interactively 'org-agenda-list))
2474 ((equal keys "s") (call-interactively 'org-search-view))
2475 ((equal keys "t") (call-interactively 'org-todo-list))
2476 ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2477 ((equal keys "m") (call-interactively 'org-tags-view))
2478 ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2479 ((equal keys "e") (call-interactively 'org-store-agenda-views))
2480 ((equal keys "?") (org-tags-view nil "+FLAGGED")
2481 (org-add-hook
2482 'post-command-hook
2483 (lambda ()
2484 (unless (current-message)
2485 (let* ((m (org-agenda-get-any-marker))
2486 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2487 (when note
2488 (message (concat
2489 "FLAGGING-NOTE ([?] for more info): "
2490 (org-add-props
2491 (replace-regexp-in-string
2492 "\\\\n" "//"
2493 (copy-sequence note))
2494 nil 'face 'org-warning)))))))
2495 t t))
2496 ((equal keys "L")
2497 (unless (derived-mode-p 'org-mode)
2498 (error "This is not an Org-mode file"))
2499 (unless restriction
2500 (put 'org-agenda-files 'org-restrict (list bfn))
2501 (org-call-with-arg 'org-timeline arg)))
2502 ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2503 ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
2504 ((equal keys "!") (customize-variable 'org-stuck-projects))
2505 (t (error "Invalid agenda key"))))))
2507 (defun org-agenda-append-agenda ()
2508 "Append another agenda view to the current one.
2509 This function allows interactive building of block agendas.
2510 Agenda views are separated by `org-agenda-block-separator'."
2511 (interactive)
2512 (unless (string= (buffer-name) org-agenda-buffer-name)
2513 (error "Can only append from within agenda buffer"))
2514 (let ((org-agenda-multi t))
2515 (org-agenda)
2516 (widen)))
2518 (defun org-agenda-normalize-custom-commands (cmds)
2519 (delq nil
2520 (mapcar
2521 (lambda (x)
2522 (cond ((stringp (cdr x)) nil)
2523 ((stringp (nth 1 x)) x)
2524 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2525 (t (cons (car x) (cons "" (cdr x))))))
2526 cmds)))
2528 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2529 "The user interface for selecting an agenda command."
2530 (catch 'exit
2531 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2532 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2533 (region-p (org-region-active-p))
2534 (custom org-agenda-custom-commands)
2535 (selstring "")
2536 restriction second-time
2537 c entry key type match prefixes rmheader header-end custom1 desc
2538 line lines left right n n1)
2539 (save-window-excursion
2540 (delete-other-windows)
2541 (org-switch-to-buffer-other-window " *Agenda Commands*")
2542 (erase-buffer)
2543 (insert (eval-when-compile
2544 (let ((header
2545 "Press key for an agenda command: < Buffer, subtree/region restriction
2546 -------------------------------- > Remove restriction
2547 a Agenda for current week or day e Export agenda views
2548 t List of all TODO entries T Entries with special TODO kwd
2549 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2550 L Timeline for current buffer # List stuck projects (!=configure)
2551 s Search for keywords * Toggle sticky agenda views
2552 / Multi-occur ? Find :FLAGGED: entries
2553 C Configure custom agenda commands
2555 (start 0))
2556 (while (string-match
2557 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2558 header start)
2559 (setq start (match-end 0))
2560 (add-text-properties (match-beginning 2) (match-end 2)
2561 '(face bold) header))
2562 header)))
2563 (setq header-end (move-marker (make-marker) (point)))
2564 (while t
2565 (setq custom1 custom)
2566 (when (eq rmheader t)
2567 (org-goto-line 1)
2568 (re-search-forward ":" nil t)
2569 (delete-region (match-end 0) (point-at-eol))
2570 (forward-char 1)
2571 (looking-at "-+")
2572 (delete-region (match-end 0) (point-at-eol))
2573 (move-marker header-end (match-end 0)))
2574 (goto-char header-end)
2575 (delete-region (point) (point-max))
2577 ;; Produce all the lines that describe custom commands and prefixes
2578 (setq lines nil)
2579 (while (setq entry (pop custom1))
2580 (setq key (car entry) desc (nth 1 entry)
2581 type (nth 2 entry)
2582 match (nth 3 entry))
2583 (if (> (length key) 1)
2584 (add-to-list 'prefixes (string-to-char key))
2585 (setq line
2586 (format
2587 "%-4s%-14s"
2588 (org-add-props (copy-sequence key)
2589 '(face bold))
2590 (cond
2591 ((string-match "\\S-" desc) desc)
2592 ((eq type 'agenda) "Agenda for current week or day")
2593 ((eq type 'alltodo) "List of all TODO entries")
2594 ((eq type 'search) "Word search")
2595 ((eq type 'stuck) "List of stuck projects")
2596 ((eq type 'todo) "TODO keyword")
2597 ((eq type 'tags) "Tags query")
2598 ((eq type 'tags-todo) "Tags (TODO)")
2599 ((eq type 'tags-tree) "Tags tree")
2600 ((eq type 'todo-tree) "TODO kwd tree")
2601 ((eq type 'occur-tree) "Occur tree")
2602 ((functionp type) (if (symbolp type)
2603 (symbol-name type)
2604 "Lambda expression"))
2605 (t "???"))))
2606 (if org-agenda-menu-show-matcher
2607 (setq line
2608 (concat line ": "
2609 (cond
2610 ((stringp match)
2611 (setq match (copy-sequence match))
2612 (org-add-props match nil 'face 'org-warning))
2613 (match
2614 (format "set of %d commands" (length match)))
2615 (t ""))))
2616 (if (org-string-nw-p match)
2617 (add-text-properties
2618 0 (length line) (list 'help-echo
2619 (concat "Matcher: "match)) line)))
2620 (push line lines)))
2621 (setq lines (nreverse lines))
2622 (when prefixes
2623 (mapc (lambda (x)
2624 (push
2625 (format "%s %s"
2626 (org-add-props (char-to-string x)
2627 nil 'face 'bold)
2628 (or (cdr (assoc (concat selstring
2629 (char-to-string x))
2630 prefix-descriptions))
2631 "Prefix key"))
2632 lines))
2633 prefixes))
2635 ;; Check if we should display in two columns
2636 (if org-agenda-menu-two-column
2637 (progn
2638 (setq n (length lines)
2639 n1 (+ (/ n 2) (mod n 2))
2640 right (nthcdr n1 lines)
2641 left (copy-sequence lines))
2642 (setcdr (nthcdr (1- n1) left) nil))
2643 (setq left lines right nil))
2644 (while left
2645 (insert "\n" (pop left))
2646 (when right
2647 (if (< (current-column) 40)
2648 (move-to-column 40 t)
2649 (insert " "))
2650 (insert (pop right))))
2652 ;; Make the window the right size
2653 (goto-char (point-min))
2654 (if second-time
2655 (if (not (pos-visible-in-window-p (point-max)))
2656 (org-fit-window-to-buffer))
2657 (setq second-time t)
2658 (org-fit-window-to-buffer))
2660 ;; Ask for selection
2661 (message "Press key for agenda command%s:"
2662 (if (or restrict-ok org-agenda-overriding-restriction)
2663 (if org-agenda-overriding-restriction
2664 " (restriction lock active)"
2665 (if restriction
2666 (format " (restricted to %s)" restriction)
2667 " (unrestricted)"))
2668 ""))
2669 (setq c (read-char-exclusive))
2670 (message "")
2671 (cond
2672 ((assoc (char-to-string c) custom)
2673 (setq selstring (concat selstring (char-to-string c)))
2674 (throw 'exit (cons selstring restriction)))
2675 ((memq c prefixes)
2676 (setq selstring (concat selstring (char-to-string c))
2677 prefixes nil
2678 rmheader (or rmheader t)
2679 custom (delq nil (mapcar
2680 (lambda (x)
2681 (if (or (= (length (car x)) 1)
2682 (/= (string-to-char (car x)) c))
2684 (cons (substring (car x) 1) (cdr x))))
2685 custom))))
2686 ((eq c ?*)
2687 (call-interactively 'org-toggle-sticky-agenda)
2688 (sit-for 2))
2689 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2690 (message "Restriction is only possible in Org-mode buffers")
2691 (ding) (sit-for 1))
2692 ((eq c ?1)
2693 (org-agenda-remove-restriction-lock 'noupdate)
2694 (setq restriction 'buffer))
2695 ((eq c ?0)
2696 (org-agenda-remove-restriction-lock 'noupdate)
2697 (setq restriction (if region-p 'region 'subtree)))
2698 ((eq c ?<)
2699 (org-agenda-remove-restriction-lock 'noupdate)
2700 (setq restriction
2701 (cond
2702 ((eq restriction 'buffer)
2703 (if region-p 'region 'subtree))
2704 ((memq restriction '(subtree region))
2705 nil)
2706 (t 'buffer))))
2707 ((eq c ?>)
2708 (org-agenda-remove-restriction-lock 'noupdate)
2709 (setq restriction nil))
2710 ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2711 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2712 ((and (> (length selstring) 0) (eq c ?\d))
2713 (delete-window)
2714 (org-agenda-get-restriction-and-command prefix-descriptions))
2716 ((equal c ?q) (error "Abort"))
2717 (t (error "Invalid key %c" c))))))))
2719 (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
2720 (defvar org-agenda-last-arguments nil
2721 "The arguments of the previous call to `org-agenda'.")
2722 (defun org-agenda-run-series (name series)
2723 (org-let (nth 1 series) '(org-prepare-agenda name))
2724 ;; We need to reset agenda markers here, because when constructing a
2725 ;; block agenda, the individual blocks do not do that.
2726 (org-agenda-reset-markers)
2727 (let* ((org-agenda-multi t)
2728 (redo (list 'org-agenda-run-series name (list 'quote series)))
2729 (org-agenda-overriding-arguments
2730 (or org-agenda-overriding-arguments
2731 (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
2732 (get 'org-agenda-redo-command 'last-args))))
2733 (cmds (car series))
2734 (gprops (nth 1 series))
2735 match ;; The byte compiler incorrectly complains about this. Keep it!
2736 cmd type lprops)
2737 (while (setq cmd (pop cmds))
2738 (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
2739 (cond
2740 ((eq type 'agenda)
2741 (org-let2 gprops lprops
2742 '(call-interactively 'org-agenda-list)))
2743 ((eq type 'alltodo)
2744 (org-let2 gprops lprops
2745 '(call-interactively 'org-todo-list)))
2746 ((eq type 'search)
2747 (org-let2 gprops lprops
2748 '(org-search-view current-prefix-arg match nil)))
2749 ((eq type 'stuck)
2750 (org-let2 gprops lprops
2751 '(call-interactively 'org-agenda-list-stuck-projects)))
2752 ((eq type 'tags)
2753 (org-let2 gprops lprops
2754 '(org-tags-view current-prefix-arg match)))
2755 ((eq type 'tags-todo)
2756 (org-let2 gprops lprops
2757 '(org-tags-view '(4) match)))
2758 ((eq type 'todo)
2759 (org-let2 gprops lprops
2760 '(org-todo-list match)))
2761 ((fboundp type)
2762 (org-let2 gprops lprops
2763 '(funcall type match)))
2764 (t (error "Invalid type in command series"))))
2765 (widen)
2766 (setq org-agenda-redo-command redo)
2767 (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
2768 (goto-char (point-min)))
2769 (org-fit-agenda-window)
2770 (org-let (nth 1 series) '(org-finalize-agenda)))
2772 ;;;###autoload
2773 (defmacro org-batch-agenda (cmd-key &rest parameters)
2774 "Run an agenda command in batch mode and send the result to STDOUT.
2775 If CMD-KEY is a string of length 1, it is used as a key in
2776 `org-agenda-custom-commands' and triggers this command. If it is a
2777 longer string it is used as a tags/todo match string.
2778 Parameters are alternating variable names and values that will be bound
2779 before running the agenda command."
2780 (org-eval-in-environment (org-make-parameter-alist parameters)
2781 (if (> (length cmd-key) 2)
2782 (org-tags-view nil cmd-key)
2783 (org-agenda nil cmd-key)))
2784 (set-buffer org-agenda-buffer-name)
2785 (princ (buffer-string)))
2786 (def-edebug-spec org-batch-agenda (form &rest sexp))
2788 (defvar org-agenda-info nil)
2790 ;;;###autoload
2791 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2792 "Run an agenda command in batch mode and send the result to STDOUT.
2793 If CMD-KEY is a string of length 1, it is used as a key in
2794 `org-agenda-custom-commands' and triggers this command. If it is a
2795 longer string it is used as a tags/todo match string.
2796 Parameters are alternating variable names and values that will be bound
2797 before running the agenda command.
2799 The output gives a line for each selected agenda item. Each
2800 item is a list of comma-separated values, like this:
2802 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2804 category The category of the item
2805 head The headline, without TODO kwd, TAGS and PRIORITY
2806 type The type of the agenda entry, can be
2807 todo selected in TODO match
2808 tagsmatch selected in tags match
2809 diary imported from diary
2810 deadline a deadline on given date
2811 scheduled scheduled on given date
2812 timestamp entry has timestamp on given date
2813 closed entry was closed on given date
2814 upcoming-deadline warning about deadline
2815 past-scheduled forwarded scheduled item
2816 block entry has date block including g. date
2817 todo The todo keyword, if any
2818 tags All tags including inherited ones, separated by colons
2819 date The relevant date, like 2007-2-14
2820 time The time, like 15:00-16:50
2821 extra Sting with extra planning info
2822 priority-l The priority letter if any was given
2823 priority-n The computed numerical priority
2824 agenda-day The day in the agenda where this is listed"
2825 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2826 (org-make-parameter-alist parameters))
2827 (if (> (length cmd-key) 2)
2828 (org-tags-view nil cmd-key)
2829 (org-agenda nil cmd-key)))
2830 (set-buffer org-agenda-buffer-name)
2831 (let* ((lines (org-split-string (buffer-string) "\n"))
2832 line)
2833 (while (setq line (pop lines))
2834 (catch 'next
2835 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2836 (setq org-agenda-info
2837 (org-fix-agenda-info (text-properties-at 0 line)))
2838 (princ
2839 (mapconcat 'org-agenda-export-csv-mapper
2840 '(org-category txt type todo tags date time extra
2841 priority-letter priority agenda-day)
2842 ","))
2843 (princ "\n")))))
2844 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
2846 (defun org-fix-agenda-info (props)
2847 "Make sure all properties on an agenda item have a canonical form.
2848 This ensures the export commands can easily use it."
2849 (let (tmp re)
2850 (when (setq tmp (plist-get props 'tags))
2851 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
2852 (when (setq tmp (plist-get props 'date))
2853 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2854 (let ((calendar-date-display-form '(year "-" month "-" day)))
2855 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
2857 (setq tmp (calendar-date-string tmp)))
2858 (setq props (plist-put props 'date tmp)))
2859 (when (setq tmp (plist-get props 'day))
2860 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
2861 (let ((calendar-date-display-form '(year "-" month "-" day)))
2862 (setq tmp (calendar-date-string tmp)))
2863 (setq props (plist-put props 'day tmp))
2864 (setq props (plist-put props 'agenda-day tmp)))
2865 (when (setq tmp (plist-get props 'txt))
2866 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
2867 (plist-put props 'priority-letter (match-string 1 tmp))
2868 (setq tmp (replace-match "" t t tmp)))
2869 (when (and (setq re (plist-get props 'org-todo-regexp))
2870 (setq re (concat "\\`\\.*" re " ?"))
2871 (string-match re tmp))
2872 (plist-put props 'todo (match-string 1 tmp))
2873 (setq tmp (replace-match "" t t tmp)))
2874 (plist-put props 'txt tmp)))
2875 props)
2877 (defun org-agenda-export-csv-mapper (prop)
2878 (let ((res (plist-get org-agenda-info prop)))
2879 (setq res
2880 (cond
2881 ((not res) "")
2882 ((stringp res) res)
2883 (t (prin1-to-string res))))
2884 (while (string-match "," res)
2885 (setq res (replace-match ";" t t res)))
2886 (org-trim res)))
2888 ;;;###autoload
2889 (defun org-store-agenda-views (&rest parameters)
2890 (interactive)
2891 (eval (list 'org-batch-store-agenda-views)))
2893 ;;;###autoload
2894 (defmacro org-batch-store-agenda-views (&rest parameters)
2895 "Run all custom agenda commands that have a file argument."
2896 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
2897 (pop-up-frames nil)
2898 (dir default-directory)
2899 (pars (org-make-parameter-alist parameters))
2900 cmd thiscmdkey files opts cmd-or-set bufname)
2901 (save-window-excursion
2902 (while cmds
2903 (setq cmd (pop cmds)
2904 thiscmdkey (car cmd)
2905 bufname (if org-agenda-sticky (format "*Org Agenda(%s)*" thiscmdkey)
2906 org-agenda-buffer-name)
2907 cmd-or-set (nth 2 cmd)
2908 opts (nth (if (listp cmd-or-set) 3 4) cmd)
2909 files (nth (if (listp cmd-or-set) 4 5) cmd))
2910 (if (stringp files) (setq files (list files)))
2911 (when files
2912 (org-eval-in-environment (append org-agenda-exporter-settings
2913 opts pars)
2914 (org-agenda nil thiscmdkey))
2915 (set-buffer bufname)
2916 (while files
2917 (org-eval-in-environment (append org-agenda-exporter-settings
2918 opts pars)
2919 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
2920 (and (get-buffer bufname)
2921 (kill-buffer bufname)))))))
2922 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
2924 (defun org-agenda-mark-header-line (pos)
2925 "Mark the line at POS as an agenda structure header."
2926 (save-excursion
2927 (goto-char pos)
2928 (put-text-property (point-at-bol) (point-at-eol)
2929 'org-agenda-structural-header t)
2930 (when org-agenda-title-append
2931 (put-text-property (point-at-bol) (point-at-eol)
2932 'org-agenda-title-append org-agenda-title-append))))
2934 (defvar org-mobile-creating-agendas)
2935 (defvar org-agenda-write-buffer-name "Agenda View")
2936 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
2937 "Write the current buffer (an agenda view) as a file.
2938 Depending on the extension of the file name, plain text (.txt),
2939 HTML (.html or .htm) or Postscript (.ps) is produced.
2940 If the extension is .ics, run icalendar export over all files used
2941 to construct the agenda and limit the export to entries listed in the
2942 agenda now.
2943 With prefix argument OPEN, open the new file immediately.
2944 If NOSETTINGS is given, do not scope the settings of
2945 `org-agenda-exporter-settings' into the export commands. This is used when
2946 the settings have already been scoped and we do not wish to overrule other,
2947 higher priority settings.
2948 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
2949 (interactive "FWrite agenda to file: \nP")
2950 (if (not (file-writable-p file))
2951 (error "Cannot write agenda to file %s" file))
2952 (org-let (if nosettings nil org-agenda-exporter-settings)
2953 '(save-excursion
2954 (save-window-excursion
2955 (org-agenda-mark-filtered-text)
2956 (let ((bs (copy-sequence (buffer-string))) beg)
2957 (org-agenda-unmark-filtered-text)
2958 (with-temp-buffer
2959 (rename-buffer org-agenda-write-buffer-name t)
2960 (set-buffer-modified-p nil)
2961 (insert bs)
2962 (org-agenda-remove-marked-text 'org-filtered)
2963 (while (setq beg (text-property-any (point-min) (point-max)
2964 'org-filtered t))
2965 (delete-region
2966 beg (or (next-single-property-change beg 'org-filtered)
2967 (point-max))))
2968 (run-hooks 'org-agenda-before-write-hook)
2969 (cond
2970 ((org-bound-and-true-p org-mobile-creating-agendas)
2971 (org-mobile-write-agenda-for-mobile file))
2972 ((string-match "\\.html?\\'" file)
2973 (require 'htmlize)
2974 (set-buffer (htmlize-buffer (current-buffer)))
2975 (when (and org-agenda-export-html-style
2976 (string-match "<style>" org-agenda-export-html-style))
2977 ;; replace <style> section with org-agenda-export-html-style
2978 (goto-char (point-min))
2979 (kill-region (- (search-forward "<style") 6)
2980 (search-forward "</style>"))
2981 (insert org-agenda-export-html-style))
2982 (write-file file)
2983 (kill-buffer (current-buffer))
2984 (message "HTML written to %s" file))
2985 ((string-match "\\.ps\\'" file)
2986 (require 'ps-print)
2987 (ps-print-buffer-with-faces file)
2988 (message "Postscript written to %s" file))
2989 ((string-match "\\.pdf\\'" file)
2990 (require 'ps-print)
2991 (ps-print-buffer-with-faces
2992 (concat (file-name-sans-extension file) ".ps"))
2993 (call-process "ps2pdf" nil nil nil
2994 (expand-file-name
2995 (concat (file-name-sans-extension file) ".ps"))
2996 (expand-file-name file))
2997 (delete-file (concat (file-name-sans-extension file) ".ps"))
2998 (message "PDF written to %s" file))
2999 ((string-match "\\.ics\\'" file)
3000 (require 'org-icalendar)
3001 (let ((org-agenda-marker-table
3002 (org-create-marker-find-array
3003 (org-agenda-collect-markers)))
3004 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3005 (org-combined-agenda-icalendar-file file))
3006 (apply 'org-export-icalendar 'combine
3007 (org-agenda-files nil 'ifmode))))
3009 (let ((bs (buffer-string)))
3010 (find-file file)
3011 (erase-buffer)
3012 (insert bs)
3013 (save-buffer 0)
3014 (kill-buffer (current-buffer))
3015 (message "Plain text written to %s" file))))))))
3016 (set-buffer (or agenda-bufname
3017 (and (called-interactively-p 'any) (buffer-name))
3018 org-agenda-buffer-name)))
3019 (when open (org-open-file file)))
3021 (defvar org-agenda-tag-filter-overlays nil)
3022 (defvar org-agenda-cat-filter-overlays nil)
3024 (defun org-agenda-mark-filtered-text ()
3025 "Mark all text hidden by filtering with a text property."
3026 (let ((inhibit-read-only t))
3027 (mapc
3028 (lambda (o)
3029 (when (equal (overlay-buffer o) (current-buffer))
3030 (put-text-property
3031 (overlay-start o) (overlay-end o)
3032 'org-filtered t)))
3033 (append org-agenda-tag-filter-overlays
3034 org-agenda-cat-filter-overlays))))
3036 (defun org-agenda-unmark-filtered-text ()
3037 "Remove the filtering text property."
3038 (let ((inhibit-read-only t))
3039 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3041 (defun org-agenda-remove-marked-text (property &optional value)
3042 "Delete all text marked with VALUE of PROPERTY.
3043 VALUE defaults to t."
3044 (let (beg)
3045 (setq value (or value t))
3046 (while (setq beg (text-property-any (point-min) (point-max)
3047 property value))
3048 (delete-region
3049 beg (or (next-single-property-change beg 'org-filtered)
3050 (point-max))))))
3052 (defun org-agenda-add-entry-text ()
3053 "Add entry text to agenda lines.
3054 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3055 entry text following headings shown in the agenda.
3056 Drawers will be excluded, also the line with scheduling/deadline info."
3057 (when (and (> org-agenda-add-entry-text-maxlines 0)
3058 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3059 (let (m txt)
3060 (goto-char (point-min))
3061 (while (not (eobp))
3062 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3063 (beginning-of-line 2)
3064 (setq txt (org-agenda-get-some-entry-text
3065 m org-agenda-add-entry-text-maxlines " > "))
3066 (end-of-line 1)
3067 (if (string-match "\\S-" txt)
3068 (insert "\n" txt)
3069 (or (eobp) (forward-char 1))))))))
3071 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3072 &rest keep)
3073 "Extract entry text from MARKER, at most N-LINES lines.
3074 This will ignore drawers etc, just get the text.
3075 If INDENT is given, prefix every line with this string. If KEEP is
3076 given, it is a list of symbols, defining stuff that should not be
3077 removed from the entry content. Currently only `planning' is allowed here."
3078 (let (txt drawer-re kwd-time-re ind)
3079 (save-excursion
3080 (with-current-buffer (marker-buffer marker)
3081 (if (not (derived-mode-p 'org-mode))
3082 (setq txt "")
3083 (save-excursion
3084 (save-restriction
3085 (widen)
3086 (goto-char marker)
3087 (end-of-line 1)
3088 (setq txt (buffer-substring
3089 (min (1+ (point)) (point-max))
3090 (progn (outline-next-heading) (point)))
3091 drawer-re org-drawer-regexp
3092 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3093 ".*\n?"))
3094 (with-temp-buffer
3095 (insert txt)
3096 (when org-agenda-add-entry-text-descriptive-links
3097 (goto-char (point-min))
3098 (while (org-activate-bracket-links (point-max))
3099 (add-text-properties (match-beginning 0) (match-end 0)
3100 '(face org-link))))
3101 (goto-char (point-min))
3102 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3103 (set-text-properties (match-beginning 0) (match-end 0)
3104 nil))
3105 (goto-char (point-min))
3106 (while (re-search-forward drawer-re nil t)
3107 (delete-region
3108 (match-beginning 0)
3109 (progn (re-search-forward
3110 "^[ \t]*:END:.*\n?" nil 'move)
3111 (point))))
3112 (unless (member 'planning keep)
3113 (goto-char (point-min))
3114 (while (re-search-forward kwd-time-re nil t)
3115 (replace-match "")))
3116 (goto-char (point-min))
3117 (when org-agenda-entry-text-exclude-regexps
3118 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3119 (while (setq re (pop re-list))
3120 (goto-char (point-min))
3121 (while (re-search-forward re nil t)
3122 (replace-match "")))))
3123 (goto-char (point-max))
3124 (skip-chars-backward " \t\n")
3125 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3127 ;; find and remove min common indentation
3128 (goto-char (point-min))
3129 (untabify (point-min) (point-max))
3130 (setq ind (org-get-indentation))
3131 (while (not (eobp))
3132 (unless (looking-at "[ \t]*$")
3133 (setq ind (min ind (org-get-indentation))))
3134 (beginning-of-line 2))
3135 (goto-char (point-min))
3136 (while (not (eobp))
3137 (unless (looking-at "[ \t]*$")
3138 (move-to-column ind)
3139 (delete-region (point-at-bol) (point)))
3140 (beginning-of-line 2))
3142 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3144 (goto-char (point-min))
3145 (when indent
3146 (while (and (not (eobp)) (re-search-forward "^" nil t))
3147 (replace-match indent t t)))
3148 (goto-char (point-min))
3149 (while (looking-at "[ \t]*\n") (replace-match ""))
3150 (goto-char (point-max))
3151 (when (> (org-current-line)
3152 n-lines)
3153 (org-goto-line (1+ n-lines))
3154 (backward-char 1))
3155 (setq txt (buffer-substring (point-min) (point)))))))))
3156 txt))
3158 (defun org-agenda-collect-markers ()
3159 "Collect the markers pointing to entries in the agenda buffer."
3160 (let (m markers)
3161 (save-excursion
3162 (goto-char (point-min))
3163 (while (not (eobp))
3164 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3165 (org-get-at-bol 'org-marker)))
3166 (push m markers))
3167 (beginning-of-line 2)))
3168 (nreverse markers)))
3170 (defun org-create-marker-find-array (marker-list)
3171 "Create a alist of files names with all marker positions in that file."
3172 (let (f tbl m a p)
3173 (while (setq m (pop marker-list))
3174 (setq p (marker-position m)
3175 f (buffer-file-name (or (buffer-base-buffer
3176 (marker-buffer m))
3177 (marker-buffer m))))
3178 (if (setq a (assoc f tbl))
3179 (push (marker-position m) (cdr a))
3180 (push (list f p) tbl)))
3181 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3182 tbl)))
3184 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3185 (defun org-check-agenda-marker-table ()
3186 "Check of the current entry is on the marker list."
3187 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3189 (and (setq a (assoc file org-agenda-marker-table))
3190 (save-match-data
3191 (save-excursion
3192 (org-back-to-heading t)
3193 (member (point) (cdr a)))))))
3195 (defun org-check-for-org-mode ()
3196 "Make sure current buffer is in org-mode. Error if not."
3197 (or (derived-mode-p 'org-mode)
3198 (error "Cannot execute org-mode agenda command on buffer in %s"
3199 major-mode)))
3201 (defun org-fit-agenda-window ()
3202 "Fit the window to the buffer size."
3203 (and (memq org-agenda-window-setup '(reorganize-frame))
3204 (fboundp 'fit-window-to-buffer)
3205 (org-fit-window-to-buffer
3207 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
3208 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
3210 ;;; Agenda prepare and finalize
3212 (defvar org-agenda-multi nil) ; dynamically scoped
3213 (defvar org-agenda-buffer-name "*Org Agenda*")
3214 (defvar org-pre-agenda-window-conf nil)
3215 (defvar org-agenda-columns-active nil)
3216 (defvar org-agenda-name nil)
3217 (defvar org-agenda-tag-filter nil)
3218 (defvar org-agenda-category-filter nil)
3219 (defvar org-agenda-top-category-filter nil)
3220 (defvar org-agenda-tag-filter-while-redo nil)
3221 (defvar org-agenda-tag-filter-preset nil
3222 "A preset of the tags filter used for secondary agenda filtering.
3223 This must be a list of strings, each string must be a single tag preceded
3224 by \"+\" or \"-\".
3225 This variable should not be set directly, but agenda custom commands can
3226 bind it in the options section. The preset filter is a global property of
3227 the entire agenda view. In a block agenda, it will not work reliably to
3228 define a filter for one of the individual blocks. You need to set it in
3229 the global options and expect it to be applied to the entire view.")
3231 (defvar org-agenda-category-filter-preset nil
3232 "A preset of the category filter used for secondary agenda filtering.
3233 This must be a list of strings, each string must be a single category
3234 preceded by \"+\" or \"-\".
3235 This variable should not be set directly, but agenda custom commands can
3236 bind it in the options section. The preset filter is a global property of
3237 the entire agenda view. In a block agenda, it will not work reliably to
3238 define a filter for one of the individual blocks. You need to set it in
3239 the global options and expect it to be applied to the entire view.")
3242 (defun org-agenda-use-sticky-p ()
3243 "Return non-nil if an agenda buffer named
3244 `org-agenda-buffer-name' exists and should be shown instead of
3245 generating a new one."
3246 (and
3247 ;; turned off by user
3248 org-agenda-sticky
3249 ;; For multi-agenda buffer already exists
3250 (not org-agenda-multi)
3251 ;; buffer found
3252 (get-buffer org-agenda-buffer-name)
3253 ;; C-u parameter is same as last call
3254 (with-current-buffer (get-buffer org-agenda-buffer-name)
3255 (and
3256 (equal current-prefix-arg
3257 org-agenda-last-prefix-arg)
3258 ;; In case user turned stickiness on, while having existing
3259 ;; Agenda buffer active, don't reuse that buffer, because it
3260 ;; does not have org variables local
3261 org-agenda-this-buffer-is-sticky))))
3263 (defun org-prepare-agenda-window (abuf)
3264 "Setup agenda buffer in the window."
3265 (let* ((awin (get-buffer-window abuf))
3266 wconf)
3267 (cond
3268 ((equal (current-buffer) abuf) nil)
3269 (awin (select-window awin))
3270 ((not (setq wconf (current-window-configuration))))
3271 ((equal org-agenda-window-setup 'current-window)
3272 (org-pop-to-buffer-same-window abuf))
3273 ((equal org-agenda-window-setup 'other-window)
3274 (org-switch-to-buffer-other-window abuf))
3275 ((equal org-agenda-window-setup 'other-frame)
3276 (switch-to-buffer-other-frame abuf))
3277 ((equal org-agenda-window-setup 'reorganize-frame)
3278 (delete-other-windows)
3279 (org-switch-to-buffer-other-window abuf)))
3280 ;; additional test in case agenda is invoked from within agenda
3281 ;; buffer via elisp link
3282 (unless (equal (current-buffer) abuf)
3283 (org-pop-to-buffer-same-window abuf))
3284 (setq org-pre-agenda-window-conf wconf)))
3286 (defun org-prepare-agenda (&optional name)
3287 (if (org-agenda-use-sticky-p)
3288 (progn
3289 ;; Popup existing buffer
3290 (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
3291 (message "Sticky Agenda buffer, use `r' to refresh")
3292 (throw 'exit nil))
3293 (setq org-todo-keywords-for-agenda nil)
3294 (setq org-drawers-for-agenda nil)
3295 (unless org-agenda-persistent-filter
3296 (setq org-agenda-tag-filter nil
3297 org-agenda-category-filter nil))
3298 (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
3299 (put 'org-agenda-category-filter :preset-filter
3300 org-agenda-category-filter-preset)
3301 (if org-agenda-multi
3302 (progn
3303 (setq buffer-read-only nil)
3304 (goto-char (point-max))
3305 (unless (or (bobp) org-agenda-compact-blocks
3306 (not org-agenda-block-separator))
3307 (insert "\n"
3308 (if (stringp org-agenda-block-separator)
3309 org-agenda-block-separator
3310 (make-string (window-width) org-agenda-block-separator))
3311 "\n"))
3312 (narrow-to-region (point) (point-max)))
3313 (setq org-done-keywords-for-agenda nil)
3315 ;; Setting any org variables that are in org-agenda-local-vars
3316 ;; list need to be done after the prepare call
3317 (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
3318 (setq buffer-read-only nil)
3319 (org-agenda-reset-markers)
3320 (let ((inhibit-read-only t)) (erase-buffer))
3321 (org-agenda-mode)
3322 (setq org-agenda-buffer (current-buffer))
3323 (setq org-agenda-contributing-files nil)
3324 (setq org-agenda-columns-active nil)
3325 (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
3326 (setq org-todo-keywords-for-agenda
3327 (org-uniquify org-todo-keywords-for-agenda))
3328 (setq org-done-keywords-for-agenda
3329 (org-uniquify org-done-keywords-for-agenda))
3330 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3331 (setq org-agenda-last-prefix-arg current-prefix-arg)
3332 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3333 (and name (not org-agenda-name)
3334 (org-set-local 'org-agenda-name name)))
3335 (setq buffer-read-only nil)))
3337 (defun org-finalize-agenda ()
3338 "Finishing touch for the agenda buffer, called just before displaying it."
3339 (unless org-agenda-multi
3340 (save-excursion
3341 (let ((inhibit-read-only t))
3342 (goto-char (point-min))
3343 (while (org-activate-bracket-links (point-max))
3344 (add-text-properties (match-beginning 0) (match-end 0)
3345 '(face org-link)))
3346 (org-agenda-align-tags)
3347 (unless org-agenda-with-colors
3348 (remove-text-properties (point-min) (point-max) '(face nil))))
3349 (if (and (boundp 'org-agenda-overriding-columns-format)
3350 org-agenda-overriding-columns-format)
3351 (org-set-local 'org-agenda-overriding-columns-format
3352 org-agenda-overriding-columns-format))
3353 (if (and (boundp 'org-agenda-view-columns-initially)
3354 org-agenda-view-columns-initially)
3355 (org-agenda-columns))
3356 (when org-agenda-fontify-priorities
3357 (org-agenda-fontify-priorities))
3358 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3359 (org-agenda-dim-blocked-tasks))
3360 (org-agenda-mark-clocking-task)
3361 (when org-agenda-entry-text-mode
3362 (org-agenda-entry-text-hide)
3363 (org-agenda-entry-text-show))
3364 (if (functionp 'org-habit-insert-consistency-graphs)
3365 (org-habit-insert-consistency-graphs))
3366 (run-hooks 'org-finalize-agenda-hook)
3367 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3368 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3369 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3370 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3371 (org-agenda-filter-apply org-agenda-category-filter 'category))
3372 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
3375 (defun org-agenda-mark-clocking-task ()
3376 "Mark the current clock entry in the agenda if it is present."
3377 (mapc (lambda (o)
3378 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3379 (delete-overlay o)))
3380 (overlays-in (point-min) (point-max)))
3381 (when (marker-buffer org-clock-hd-marker)
3382 (save-excursion
3383 (goto-char (point-min))
3384 (let (s ov)
3385 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3386 (goto-char s)
3387 (when (equal (org-get-at-bol 'org-hd-marker)
3388 org-clock-hd-marker)
3389 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3390 (overlay-put ov 'type 'org-agenda-clocking)
3391 (overlay-put ov 'face 'org-agenda-clocking)
3392 (overlay-put ov 'help-echo
3393 "The clock is running in this item")))))))
3395 (defun org-agenda-fontify-priorities ()
3396 "Make highest priority lines bold, and lowest italic."
3397 (interactive)
3398 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3399 (delete-overlay o)))
3400 (overlays-in (point-min) (point-max)))
3401 (save-excursion
3402 (let ((inhibit-read-only t)
3403 b e p ov h l)
3404 (goto-char (point-min))
3405 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3406 (setq h (or (get-char-property (point) 'org-highest-priority)
3407 org-highest-priority)
3408 l (or (get-char-property (point) 'org-lowest-priority)
3409 org-lowest-priority)
3410 p (string-to-char (match-string 1))
3411 b (match-beginning 0)
3412 e (if (eq org-agenda-fontify-priorities 'cookies)
3413 (match-end 0)
3414 (point-at-eol))
3415 ov (make-overlay b e))
3416 (overlay-put
3417 ov 'face
3418 (cond ((org-face-from-face-or-color
3419 'priority nil
3420 (cdr (assoc p org-priority-faces))))
3421 ((and (listp org-agenda-fontify-priorities)
3422 (org-face-from-face-or-color
3423 'priority nil
3424 (cdr (assoc p org-agenda-fontify-priorities)))))
3425 ((equal p l) 'italic)
3426 ((equal p h) 'bold)))
3427 (overlay-put ov 'org-type 'org-priority)))))
3429 (defun org-agenda-dim-blocked-tasks ()
3430 "Dim currently blocked TODO's in the agenda display."
3431 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3432 (delete-overlay o)))
3433 (overlays-in (point-min) (point-max)))
3434 (save-excursion
3435 (let ((inhibit-read-only t)
3436 (org-depend-tag-blocked nil)
3437 (invis (eq org-agenda-dim-blocked-tasks 'invisible))
3438 org-blocked-by-checkboxes
3439 invis1 b e p ov h l)
3440 (goto-char (point-min))
3441 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3442 (and pos (goto-char (1+ pos))))
3443 (setq org-blocked-by-checkboxes nil invis1 invis)
3444 (let ((marker (org-get-at-bol 'org-hd-marker)))
3445 (when (and marker
3446 (with-current-buffer (marker-buffer marker)
3447 (save-excursion (goto-char marker)
3448 (org-entry-blocked-p))))
3449 (if org-blocked-by-checkboxes (setq invis1 nil))
3450 (setq b (if invis1
3451 (max (point-min) (1- (point-at-bol)))
3452 (point-at-bol))
3453 e (point-at-eol)
3454 ov (make-overlay b e))
3455 (if invis1
3456 (overlay-put ov 'invisible t)
3457 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3458 (overlay-put ov 'org-type 'org-blocked-todo)))))))
3460 (defvar org-agenda-skip-function nil
3461 "Function to be called at each match during agenda construction.
3462 If this function returns nil, the current match should not be skipped.
3463 Otherwise, the function must return a position from where the search
3464 should be continued.
3465 This may also be a Lisp form, it will be evaluated.
3466 Never set this variable using `setq' or so, because then it will apply
3467 to all future agenda commands. If you do want a global skipping condition,
3468 use the option `org-agenda-skip-function-global' instead.
3469 The correct usage for `org-agenda-skip-function' is to bind it with
3470 `let' to scope it dynamically into the agenda-constructing command.
3471 A good way to set it is through options in `org-agenda-custom-commands'.")
3473 (defun org-agenda-skip ()
3474 "Throw to `:skip' in places that should be skipped.
3475 Also moves point to the end of the skipped region, so that search can
3476 continue from there."
3477 (let ((p (point-at-bol)) to)
3478 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3479 (get-text-property p :org-archived)
3480 (org-end-of-subtree t)
3481 (throw :skip t))
3482 (and org-agenda-skip-comment-trees
3483 (get-text-property p :org-comment)
3484 (org-end-of-subtree t)
3485 (throw :skip t))
3486 (if (equal (char-after p) ?#) (throw :skip t))
3487 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3488 (org-agenda-skip-eval org-agenda-skip-function)))
3489 (goto-char to)
3490 (throw :skip t))))
3492 (defun org-agenda-skip-eval (form)
3493 "If FORM is a function or a list, call (or eval) is and return result.
3494 `save-excursion' and `save-match-data' are wrapped around the call, so point
3495 and match data are returned to the previous state no matter what these
3496 functions do."
3497 (let (fp)
3498 (and form
3499 (or (setq fp (functionp form))
3500 (consp form))
3501 (save-excursion
3502 (save-match-data
3503 (if fp
3504 (funcall form)
3505 (eval form)))))))
3507 (defvar org-agenda-markers nil
3508 "List of all currently active markers created by `org-agenda'.")
3509 (defvar org-agenda-last-marker-time (org-float-time)
3510 "Creation time of the last agenda marker.")
3512 (defun org-agenda-new-marker (&optional pos)
3513 "Return a new agenda marker.
3514 Org-mode keeps a list of these markers and resets them when they are
3515 no longer in use."
3516 (let ((m (copy-marker (or pos (point)))))
3517 (setq org-agenda-last-marker-time (org-float-time))
3518 (if org-agenda-buffer
3519 (with-current-buffer org-agenda-buffer
3520 (push m org-agenda-markers))
3521 (push m org-agenda-markers))
3524 (defun org-agenda-reset-markers ()
3525 "Reset markers created by `org-agenda'."
3526 (while org-agenda-markers
3527 (move-marker (pop org-agenda-markers) nil)))
3529 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3530 "Save relative positions of markers in region.
3531 This check for agenda markers in all agenda buffers currently active."
3532 (dolist (buf (buffer-list))
3533 (with-current-buffer buf
3534 (when (eq major-mode 'org-agenda-mode)
3535 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3536 org-agenda-markers)))))
3538 ;;; Entry text mode
3540 (defun org-agenda-entry-text-show-here ()
3541 "Add some text from the entry as context to the current line."
3542 (let (m txt o)
3543 (setq m (org-get-at-bol 'org-hd-marker))
3544 (unless (marker-buffer m)
3545 (error "No marker points to an entry here"))
3546 (setq txt (concat "\n" (org-no-properties
3547 (org-agenda-get-some-entry-text
3548 m org-agenda-entry-text-maxlines " > "))))
3549 (when (string-match "\\S-" txt)
3550 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3551 (overlay-put o 'evaporate t)
3552 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3553 (overlay-put o 'after-string txt))))
3555 (defun org-agenda-entry-text-show ()
3556 "Add entry context for all agenda lines."
3557 (interactive)
3558 (save-excursion
3559 (goto-char (point-max))
3560 (beginning-of-line 1)
3561 (while (not (bobp))
3562 (when (org-get-at-bol 'org-hd-marker)
3563 (org-agenda-entry-text-show-here))
3564 (beginning-of-line 0))))
3566 (defun org-agenda-entry-text-hide ()
3567 "Remove any shown entry context."
3568 (delq nil
3569 (mapcar (lambda (o)
3570 (if (eq (overlay-get o 'org-overlay-type)
3571 'agenda-entry-content)
3572 (progn (delete-overlay o) t)))
3573 (overlays-in (point-min) (point-max)))))
3575 (defun org-agenda-get-day-face (date)
3576 "Return the face DATE should be displayed with."
3577 (or (and (functionp org-agenda-day-face-function)
3578 (funcall org-agenda-day-face-function date))
3579 (cond ((org-agenda-todayp date)
3580 'org-agenda-date-today)
3581 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3582 'org-agenda-date-weekend)
3583 (t 'org-agenda-date))))
3585 ;;; Agenda timeline
3587 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3589 (defun org-timeline (&optional dotodo)
3590 "Show a time-sorted view of the entries in the current org file.
3591 Only entries with a time stamp of today or later will be listed. With
3592 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3593 under the current date.
3594 If the buffer contains an active region, only check the region for
3595 dates."
3596 (interactive "P")
3597 (let* ((dopast t)
3598 (org-agenda-show-log-scoped org-agenda-show-log)
3599 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3600 (current-buffer))))
3601 (date (calendar-current-date))
3602 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3603 (end (if (org-region-active-p) (region-end) (point-max)))
3604 (day-numbers (org-get-all-dates
3605 beg end 'no-ranges
3606 t org-agenda-show-log-scoped ; always include today
3607 org-timeline-show-empty-dates))
3608 (org-deadline-warning-days 0)
3609 (org-agenda-only-exact-dates t)
3610 (today (org-today))
3611 (past t)
3612 args
3613 s e rtn d emptyp)
3614 (setq org-agenda-redo-command
3615 (list 'progn
3616 (list 'org-switch-to-buffer-other-window (current-buffer))
3617 (list 'org-timeline (list 'quote dotodo))))
3618 (if (not dopast)
3619 ;; Remove past dates from the list of dates.
3620 (setq day-numbers (delq nil (mapcar (lambda(x)
3621 (if (>= x today) x nil))
3622 day-numbers))))
3623 (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
3624 (org-compile-prefix-format 'timeline)
3625 (org-set-sorting-strategy 'timeline)
3626 (if org-agenda-show-log-scoped (push :closed args))
3627 (push :timestamp args)
3628 (push :deadline args)
3629 (push :scheduled args)
3630 (push :sexp args)
3631 (if dotodo (push :todo args))
3632 (insert "Timeline of file " entry "\n")
3633 (add-text-properties (point-min) (point)
3634 (list 'face 'org-agenda-structure))
3635 (org-agenda-mark-header-line (point-min))
3636 (while (setq d (pop day-numbers))
3637 (if (and (listp d) (eq (car d) :omitted))
3638 (progn
3639 (setq s (point))
3640 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3641 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3642 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3643 (if (and (>= d today)
3644 dopast
3645 past)
3646 (progn
3647 (setq past nil)
3648 (insert (make-string 79 ?-) "\n")))
3649 (setq date (calendar-gregorian-from-absolute d))
3650 (setq s (point))
3651 (setq rtn (and (not emptyp)
3652 (apply 'org-agenda-get-day-entries entry
3653 date args)))
3654 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3655 (progn
3656 (insert
3657 (if (stringp org-agenda-format-date)
3658 (format-time-string org-agenda-format-date
3659 (org-time-from-absolute date))
3660 (funcall org-agenda-format-date date))
3661 "\n")
3662 (put-text-property s (1- (point)) 'face
3663 (org-agenda-get-day-face date))
3664 (put-text-property s (1- (point)) 'org-date-line t)
3665 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3666 (if (equal d today)
3667 (put-text-property s (1- (point)) 'org-today t))
3668 (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
3669 (put-text-property s (1- (point)) 'day d)))))
3670 (goto-char (point-min))
3671 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3672 (point-min)))
3673 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3674 (org-finalize-agenda)
3675 (setq buffer-read-only t)))
3677 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3678 "Return a list of all relevant day numbers from BEG to END buffer positions.
3679 If NO-RANGES is non-nil, include only the start and end dates of a range,
3680 not every single day in the range. If FORCE-TODAY is non-nil, make
3681 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3682 inactive time stamps (those in square brackets) are included.
3683 When EMPTY is non-nil, also include days without any entries."
3684 (let ((re (concat
3685 (if pre-re pre-re "")
3686 (if inactive org-ts-regexp-both org-ts-regexp)))
3687 dates dates1 date day day1 day2 ts1 ts2 pos)
3688 (if force-today
3689 (setq dates (list (org-today))))
3690 (save-excursion
3691 (goto-char beg)
3692 (while (re-search-forward re end t)
3693 (setq day (time-to-days (org-time-string-to-time
3694 (substring (match-string 1) 0 10)
3695 (current-buffer) (match-beginning 0))))
3696 (or (memq day dates) (push day dates)))
3697 (unless no-ranges
3698 (goto-char beg)
3699 (while (re-search-forward org-tr-regexp end t)
3700 (setq pos (match-beginning 0))
3701 (setq ts1 (substring (match-string 1) 0 10)
3702 ts2 (substring (match-string 2) 0 10)
3703 day1 (time-to-days (org-time-string-to-time
3704 ts1 (current-buffer) pos))
3705 day2 (time-to-days (org-time-string-to-time
3706 ts2 (current-buffer) pos)))
3707 (while (< (setq day1 (1+ day1)) day2)
3708 (or (memq day1 dates) (push day1 dates)))))
3709 (setq dates (sort dates '<))
3710 (when empty
3711 (while (setq day (pop dates))
3712 (setq day2 (car dates))
3713 (push day dates1)
3714 (when (and day2 empty)
3715 (if (or (eq empty t)
3716 (and (numberp empty) (<= (- day2 day) empty)))
3717 (while (< (setq day (1+ day)) day2)
3718 (push (list day) dates1))
3719 (push (cons :omitted (- day2 day)) dates1))))
3720 (setq dates (nreverse dates1)))
3721 dates)))
3723 ;;; Agenda Daily/Weekly
3725 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3726 "Start day for the agenda view.
3727 Custom commands can set this variable in the options section.")
3728 (defvar org-starting-day nil) ; local variable in the agenda buffer
3729 (defvar org-agenda-current-span nil
3730 "The current span used in the agenda view.") ; local variable in the agenda buffer
3731 (defvar org-arg-loc nil) ; local variable
3733 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3734 "List of types searched for when creating the daily/weekly agenda.
3735 This variable is a list of symbols that controls the types of
3736 items that appear in the daily/weekly agenda. Allowed symbols in this
3737 list are are
3739 :timestamp List items containing a date stamp or date range matching
3740 the selected date. This includes sexp entries in
3741 angular brackets.
3743 :sexp List entries resulting from plain diary-like sexps.
3745 :deadline List deadline due on that date. When the date is today,
3746 also list any deadlines past due, or due within
3747 `org-deadline-warning-days'. `:deadline' must appear before
3748 `:scheduled' if the setting of
3749 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3750 any effect.
3752 :scheduled List all items which are scheduled for the given date.
3753 The diary for *today* also contains items which were
3754 scheduled earlier and are not yet marked DONE.
3756 By default, all four types are turned on.
3758 Never set this variable globally using `setq', because then it
3759 will apply to all future agenda commands. Instead, bind it with
3760 `let' to scope it dynamically into the agenda-constructing
3761 command. A good way to set it is through options in
3762 `org-agenda-custom-commands'. For a more flexible (though
3763 somewhat less efficient) way of determining what is included in
3764 the daily/weekly agenda, see `org-agenda-skip-function'.")
3766 ;;;###autoload
3767 (defun org-agenda-list (&optional arg start-day span)
3768 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3769 The view will be for the current day or week, but from the overview buffer
3770 you will be able to go to other days/weeks.
3772 With a numeric prefix argument in an interactive call, the agenda will
3773 span ARG days. Lisp programs should instead specify SPAN to change
3774 the number of days. SPAN defaults to `org-agenda-span'.
3776 START-DAY defaults to TODAY, or to the most recent match for the weekday
3777 given in `org-agenda-start-on-weekday'."
3778 (interactive "P")
3779 (if (and (integerp arg) (> arg 0))
3780 (setq span arg arg nil))
3781 (org-prepare-agenda "Day/Week")
3782 (setq start-day (or start-day org-agenda-start-day))
3783 (if org-agenda-overriding-arguments
3784 (setq arg (car org-agenda-overriding-arguments)
3785 start-day (nth 1 org-agenda-overriding-arguments)
3786 span (nth 2 org-agenda-overriding-arguments)))
3787 (if (stringp start-day)
3788 ;; Convert to an absolute day number
3789 (setq start-day (time-to-days (org-read-date nil t start-day))))
3790 (setq org-agenda-last-arguments (list arg start-day span))
3791 (org-compile-prefix-format 'agenda)
3792 (org-set-sorting-strategy 'agenda)
3793 (let* ((span (org-agenda-ndays-to-span
3794 (or span org-agenda-ndays org-agenda-span)))
3795 (today (org-today))
3796 (sd (or start-day today))
3797 (ndays (org-agenda-span-to-ndays span sd))
3798 (org-agenda-start-on-weekday
3799 (if (eq ndays 7)
3800 org-agenda-start-on-weekday))
3801 (thefiles (org-agenda-files nil 'ifmode))
3802 (files thefiles)
3803 (start (if (or (null org-agenda-start-on-weekday)
3804 (< ndays 7))
3806 (let* ((nt (calendar-day-of-week
3807 (calendar-gregorian-from-absolute sd)))
3808 (n1 org-agenda-start-on-weekday)
3809 (d (- nt n1)))
3810 (- sd (+ (if (< d 0) 7 0) d)))))
3811 (day-numbers (list start))
3812 (day-cnt 0)
3813 (inhibit-redisplay (not debug-on-error))
3814 (org-agenda-show-log-scoped org-agenda-show-log)
3815 s e rtn rtnall file date d start-pos end-pos todayp
3816 clocktable-start clocktable-end filter)
3817 (setq org-agenda-redo-command
3818 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
3819 (dotimes (n (1- ndays))
3820 (push (1+ (car day-numbers)) day-numbers))
3821 (setq day-numbers (nreverse day-numbers))
3822 (setq clocktable-start (car day-numbers)
3823 clocktable-end (1+ (or (org-last day-numbers) 0)))
3824 (org-set-local 'org-starting-day (car day-numbers))
3825 (org-set-local 'org-arg-loc arg)
3826 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
3827 (unless org-agenda-compact-blocks
3828 (let* ((d1 (car day-numbers))
3829 (d2 (org-last day-numbers))
3830 (w1 (org-days-to-iso-week d1))
3831 (w2 (org-days-to-iso-week d2)))
3832 (setq s (point))
3833 (if org-agenda-overriding-header
3834 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
3835 nil 'face 'org-agenda-structure) "\n")
3836 (insert (org-agenda-span-name span)
3837 "-agenda"
3838 (if (< (- d2 d1) 350)
3839 (if (= w1 w2)
3840 (format " (W%02d)" w1)
3841 (format " (W%02d-W%02d)" w1 w2))
3843 ":\n")))
3844 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
3845 'org-date-line t))
3846 (org-agenda-mark-header-line s))
3847 (while (setq d (pop day-numbers))
3848 (setq date (calendar-gregorian-from-absolute d)
3849 s (point))
3850 (if (or (setq todayp (= d today))
3851 (and (not start-pos) (= d sd)))
3852 (setq start-pos (point))
3853 (if (and start-pos (not end-pos))
3854 (setq end-pos (point))))
3855 (setq files thefiles
3856 rtnall nil)
3857 (while (setq file (pop files))
3858 (catch 'nextfile
3859 (org-check-agenda-file file)
3860 (let ((org-agenda-entry-types org-agenda-entry-types))
3861 (unless org-agenda-include-deadlines
3862 (setq org-agenda-entry-types
3863 (delq :deadline org-agenda-entry-types)))
3864 (cond
3865 ((memq org-agenda-show-log-scoped '(only clockcheck))
3866 (setq rtn (org-agenda-get-day-entries
3867 file date :closed)))
3868 (org-agenda-show-log-scoped
3869 (setq rtn (apply 'org-agenda-get-day-entries
3870 file date
3871 (append '(:closed) org-agenda-entry-types))))
3873 (setq rtn (apply 'org-agenda-get-day-entries
3874 file date
3875 org-agenda-entry-types)))))
3876 (setq rtnall (append rtnall rtn)))) ;; all entries
3877 (if org-agenda-include-diary
3878 (let ((org-agenda-search-headline-for-time t))
3879 (require 'diary-lib)
3880 (setq rtn (org-get-entries-from-diary date))
3881 (setq rtnall (append rtnall rtn))))
3882 (if (or rtnall org-agenda-show-all-dates)
3883 (progn
3884 (setq day-cnt (1+ day-cnt))
3885 (insert
3886 (if (stringp org-agenda-format-date)
3887 (format-time-string org-agenda-format-date
3888 (org-time-from-absolute date))
3889 (funcall org-agenda-format-date date))
3890 "\n")
3891 (put-text-property s (1- (point)) 'face
3892 (org-agenda-get-day-face date))
3893 (put-text-property s (1- (point)) 'org-date-line t)
3894 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3895 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
3896 (when todayp
3897 (put-text-property s (1- (point)) 'org-today t))
3898 (setq rtnall
3899 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
3900 (if rtnall (insert ;; all entries
3901 (org-finalize-agenda-entries rtnall)
3902 "\n"))
3903 (put-text-property s (1- (point)) 'day d)
3904 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
3905 (when (and org-agenda-clockreport-mode clocktable-start)
3906 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
3907 ;; the above line is to ensure the restricted range!
3908 (p (copy-sequence org-agenda-clockreport-parameter-plist))
3909 tbl)
3910 (setq p (org-plist-delete p :block))
3911 (setq p (plist-put p :tstart clocktable-start))
3912 (setq p (plist-put p :tend clocktable-end))
3913 (setq p (plist-put p :scope 'agenda))
3914 (when (and (eq org-agenda-clockreport-mode 'with-filter)
3915 (setq filter (or org-agenda-tag-filter-while-redo
3916 (get 'org-agenda-tag-filter :preset-filter))))
3917 (setq p (plist-put p :tags (mapconcat (lambda (x)
3918 (if (string-match "[<>=]" x)
3921 filter ""))))
3922 (setq tbl (apply 'org-get-clocktable p))
3923 (insert tbl)))
3924 (goto-char (point-min))
3925 (or org-agenda-multi (org-fit-agenda-window))
3926 (unless (and (pos-visible-in-window-p (point-min))
3927 (pos-visible-in-window-p (point-max)))
3928 (goto-char (1- (point-max)))
3929 (recenter -1)
3930 (if (not (pos-visible-in-window-p (or start-pos 1)))
3931 (progn
3932 (goto-char (or start-pos 1))
3933 (recenter 1))))
3934 (goto-char (or start-pos 1))
3935 (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
3936 (if (eq org-agenda-show-log-scoped 'clockcheck)
3937 (org-agenda-show-clocking-issues))
3938 (org-finalize-agenda)
3939 (setq buffer-read-only t)
3940 (message "")))
3942 (defun org-agenda-ndays-to-span (n)
3943 "Return a span symbol for a span of N days, or N if none matches."
3944 (cond ((symbolp n) n)
3945 ((= n 1) 'day)
3946 ((= n 7) 'week)
3947 (t n)))
3949 (defun org-agenda-span-to-ndays (span start-day)
3950 "Return ndays from SPAN starting at START-DAY."
3951 (cond ((numberp span) span)
3952 ((eq span 'day) 1)
3953 ((eq span 'week) 7)
3954 ((eq span 'month)
3955 (let ((date (calendar-gregorian-from-absolute start-day)))
3956 (calendar-last-day-of-month (car date) (caddr date))))
3957 ((eq span 'year)
3958 (let ((date (calendar-gregorian-from-absolute start-day)))
3959 (if (calendar-leap-year-p (caddr date)) 366 365)))))
3961 (defun org-agenda-span-name (span)
3962 "Return a SPAN name."
3963 (if (null span)
3965 (if (symbolp span)
3966 (capitalize (symbol-name span))
3967 (format "%d days" span))))
3969 ;;; Agenda word search
3971 (defvar org-agenda-search-history nil)
3972 (defvar org-todo-only nil)
3974 (defvar org-search-syntax-table nil
3975 "Special syntax table for org-mode search.
3976 In this table, we have single quotes not as word constituents, to
3977 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
3979 (defun org-search-syntax-table ()
3980 (unless org-search-syntax-table
3981 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
3982 (modify-syntax-entry ?' "." org-search-syntax-table)
3983 (modify-syntax-entry ?` "." org-search-syntax-table))
3984 org-search-syntax-table)
3986 (defvar org-agenda-last-search-view-search-was-boolean nil)
3988 ;;;###autoload
3989 (defun org-search-view (&optional todo-only string edit-at)
3990 "Show all entries that contain a phrase or words or regular expressions.
3992 With optional prefix argument TODO-ONLY, only consider entries that are
3993 TODO entries. The argument STRING can be used to pass a default search
3994 string into this function. If EDIT-AT is non-nil, it means that the
3995 user should get a chance to edit this string, with cursor at position
3996 EDIT-AT.
3998 The search string can be viewed either as a phrase that should be found as
3999 is, or it can be broken into a number of snippets, each of which must match
4000 in a Boolean way to select an entry. The default depends on the variable
4001 `org-agenda-search-view-always-boolean'.
4002 Even if this is turned off (the default) you can always switch to
4003 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4005 The default is a direct search of the whole phrase, where each space in
4006 the search string can expand to an arbitrary amount of whitespace,
4007 including newlines.
4009 If using a Boolean search, the search string is split on whitespace and
4010 each snippet is searched separately, with logical AND to select an entry.
4011 Words prefixed with a minus must *not* occur in the entry. Words without
4012 a prefix or prefixed with a plus must occur in the entry. Matching is
4013 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4014 match whole words, not parts of a word) if
4015 `org-agenda-search-view-force-full-words' is set (default is nil).
4017 Boolean search snippets enclosed by curly braces are interpreted as
4018 regular expressions that must or (when preceded with \"-\") must not
4019 match in the entry. Snippets enclosed into double quotes will be taken
4020 as a whole, to include whitespace.
4022 - If the search string starts with an asterisk, search only in headlines.
4023 - If (possibly after the leading star) the search string starts with an
4024 exclamation mark, this also means to look at TODO entries only, an effect
4025 that can also be achieved with a prefix argument.
4026 - If (possibly after star and exclamation mark) the search string starts
4027 with a colon, this will mean that the (non-regexp) snippets of the
4028 Boolean search must match as full words.
4030 This command searches the agenda files, and in addition the files listed
4031 in `org-agenda-text-search-extra-files'."
4032 (interactive "P")
4033 (org-prepare-agenda "SEARCH")
4034 (org-compile-prefix-format 'search)
4035 (org-set-sorting-strategy 'search)
4036 (let* ((props (list 'face nil
4037 'done-face 'org-agenda-done
4038 'org-not-done-regexp org-not-done-regexp
4039 'org-todo-regexp org-todo-regexp
4040 'org-complex-heading-regexp org-complex-heading-regexp
4041 'mouse-face 'highlight
4042 'help-echo (format "mouse-2 or RET jump to location")))
4043 (full-words org-agenda-search-view-force-full-words)
4044 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4045 regexp rtn rtnall files file pos
4046 marker category org-category-pos tags c neg re boolean
4047 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4048 (unless (and (not edit-at)
4049 (stringp string)
4050 (string-match "\\S-" string))
4051 (setq string (read-string
4052 (if org-agenda-search-view-always-boolean
4053 "[+-]Word/{Regexp} ...: "
4054 "Phrase, or [+-]Word/{Regexp} ...: ")
4055 (cond
4056 ((integerp edit-at) (cons string edit-at))
4057 (edit-at string))
4058 'org-agenda-search-history)))
4059 (org-set-local 'org-todo-only todo-only)
4060 (setq org-agenda-redo-command
4061 (list 'org-search-view (if todo-only t nil) string
4062 '(if current-prefix-arg 1 nil)))
4063 (setq org-agenda-query-string string)
4065 (if (equal (string-to-char string) ?*)
4066 (setq hdl-only t
4067 words (substring string 1))
4068 (setq words string))
4069 (when (equal (string-to-char words) ?!)
4070 (setq todo-only t
4071 words (substring words 1)))
4072 (when (equal (string-to-char words) ?:)
4073 (setq full-words t
4074 words (substring words 1)))
4075 (if (or org-agenda-search-view-always-boolean
4076 (member (string-to-char words) '(?- ?+ ?\{)))
4077 (setq boolean t))
4078 (setq words (org-split-string words))
4079 (let (www w)
4080 (while (setq w (pop words))
4081 (while (and (string-match "\\\\\\'" w) words)
4082 (setq w (concat (substring w 0 -1) " " (pop words))))
4083 (push w www))
4084 (setq words (nreverse www) www nil)
4085 (while (setq w (pop words))
4086 (when (and (string-match "\\`[-+]?{" w)
4087 (not (string-match "}\\'" w)))
4088 (while (and words (not (string-match "}\\'" (car words))))
4089 (setq w (concat w " " (pop words))))
4090 (setq w (concat w " " (pop words))))
4091 (push w www))
4092 (setq words (nreverse www)))
4093 (setq org-agenda-last-search-view-search-was-boolean boolean)
4094 (when boolean
4095 (let (wds w)
4096 (while (setq w (pop words))
4097 (if (or (equal (substring w 0 1) "\"")
4098 (and (> (length w) 1)
4099 (member (substring w 0 1) '("+" "-"))
4100 (equal (substring w 1 2) "\"")))
4101 (while (and words (not (equal (substring w -1) "\"")))
4102 (setq w (concat w " " (pop words)))))
4103 (and (string-match "\\`\\([-+]?\\)\"" w)
4104 (setq w (replace-match "\\1" nil nil w)))
4105 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4106 (push w wds))
4107 (setq words (nreverse wds))))
4108 (if boolean
4109 (mapc (lambda (w)
4110 (setq c (string-to-char w))
4111 (if (equal c ?-)
4112 (setq neg t w (substring w 1))
4113 (if (equal c ?+)
4114 (setq neg nil w (substring w 1))
4115 (setq neg nil)))
4116 (if (string-match "\\`{.*}\\'" w)
4117 (setq re (substring w 1 -1))
4118 (if full-words
4119 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4120 (setq re (regexp-quote (downcase w)))))
4121 (if neg (push re regexps-) (push re regexps+)))
4122 words)
4123 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4124 regexps+))
4125 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4126 (if (not regexps+)
4127 (setq regexp org-outline-regexp-bol)
4128 (setq regexp (pop regexps+))
4129 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4130 regexp))))
4131 (setq files (org-agenda-files nil 'ifmode))
4132 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4133 (pop org-agenda-text-search-extra-files)
4134 (setq files (org-add-archive-files files)))
4135 (setq files (append files org-agenda-text-search-extra-files)
4136 rtnall nil)
4137 (while (setq file (pop files))
4138 (setq ee nil)
4139 (catch 'nextfile
4140 (org-check-agenda-file file)
4141 (setq buffer (if (file-exists-p file)
4142 (org-get-agenda-file-buffer file)
4143 (error "No such file %s" file)))
4144 (if (not buffer)
4145 ;; If file does not exist, make sure an error message is sent
4146 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4147 file))))
4148 (with-current-buffer buffer
4149 (with-syntax-table (org-search-syntax-table)
4150 (unless (derived-mode-p 'org-mode)
4151 (error "Agenda file %s is not in `org-mode'" file))
4152 (let ((case-fold-search t))
4153 (save-excursion
4154 (save-restriction
4155 (if org-agenda-restrict
4156 (narrow-to-region org-agenda-restrict-begin
4157 org-agenda-restrict-end)
4158 (widen))
4159 (goto-char (point-min))
4160 (unless (or (org-at-heading-p)
4161 (outline-next-heading))
4162 (throw 'nextfile t))
4163 (goto-char (max (point-min) (1- (point))))
4164 (while (re-search-forward regexp nil t)
4165 (org-back-to-heading t)
4166 (skip-chars-forward "* ")
4167 (setq beg (point-at-bol)
4168 beg1 (point)
4169 end (progn (outline-next-heading) (point)))
4170 (catch :skip
4171 (goto-char beg)
4172 (org-agenda-skip)
4173 (setq str (buffer-substring-no-properties
4174 (point-at-bol)
4175 (if hdl-only (point-at-eol) end)))
4176 (mapc (lambda (wr) (when (string-match wr str)
4177 (goto-char (1- end))
4178 (throw :skip t)))
4179 regexps-)
4180 (mapc (lambda (wr) (unless (string-match wr str)
4181 (goto-char (1- end))
4182 (throw :skip t)))
4183 (if todo-only
4184 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4185 regexps+)
4186 regexps+))
4187 (goto-char beg)
4188 (setq marker (org-agenda-new-marker (point))
4189 category (org-get-category)
4190 org-category-pos (get-text-property (point) 'org-category-position)
4191 tags (org-get-tags-at (point))
4192 txt (org-agenda-format-item
4194 (buffer-substring-no-properties
4195 beg1 (point-at-eol))
4196 category tags))
4197 (org-add-props txt props
4198 'org-marker marker 'org-hd-marker marker
4199 'org-todo-regexp org-todo-regexp
4200 'org-complex-heading-regexp org-complex-heading-regexp
4201 'priority 1000 'org-category category
4202 'org-category-position org-category-pos
4203 'type "search")
4204 (push txt ee)
4205 (goto-char (1- end))))))))))
4206 (setq rtn (nreverse ee))
4207 (setq rtnall (append rtnall rtn)))
4208 (if org-agenda-overriding-header
4209 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4210 nil 'face 'org-agenda-structure) "\n")
4211 (insert "Search words: ")
4212 (add-text-properties (point-min) (1- (point))
4213 (list 'face 'org-agenda-structure))
4214 (setq pos (point))
4215 (insert string "\n")
4216 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4217 (setq pos (point))
4218 (unless org-agenda-multi
4219 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4220 (add-text-properties pos (1- (point))
4221 (list 'face 'org-agenda-structure))))
4222 (org-agenda-mark-header-line (point-min))
4223 (when rtnall
4224 (insert (org-finalize-agenda-entries rtnall) "\n"))
4225 (goto-char (point-min))
4226 (or org-agenda-multi (org-fit-agenda-window))
4227 (add-text-properties (point-min) (point-max) '(org-agenda-type search))
4228 (org-finalize-agenda)
4229 (setq buffer-read-only t)))
4231 ;;; Agenda TODO list
4233 (defvar org-select-this-todo-keyword nil)
4234 (defvar org-last-arg nil)
4236 ;;;###autoload
4237 (defun org-todo-list (arg)
4238 "Show all (not done) TODO entries from all agenda file in a single list.
4239 The prefix arg can be used to select a specific TODO keyword and limit
4240 the list to these. When using \\[universal-argument], you will be prompted
4241 for a keyword. A numeric prefix directly selects the Nth keyword in
4242 `org-todo-keywords-1'."
4243 (interactive "P")
4244 (org-prepare-agenda "TODO")
4245 (org-compile-prefix-format 'todo)
4246 (org-set-sorting-strategy 'todo)
4247 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4248 (let* ((today (org-today))
4249 (date (calendar-gregorian-from-absolute today))
4250 (kwds org-todo-keywords-for-agenda)
4251 (completion-ignore-case t)
4252 (org-select-this-todo-keyword
4253 (if (stringp arg) arg
4254 (and arg (integerp arg) (> arg 0)
4255 (nth (1- arg) kwds))))
4256 rtn rtnall files file pos)
4257 (when (equal arg '(4))
4258 (setq org-select-this-todo-keyword
4259 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4260 (mapcar 'list kwds) nil nil)))
4261 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4262 (org-set-local 'org-last-arg arg)
4263 (setq org-agenda-redo-command
4264 '(org-todo-list (or current-prefix-arg org-last-arg)))
4265 (setq files (org-agenda-files nil 'ifmode)
4266 rtnall nil)
4267 (while (setq file (pop files))
4268 (catch 'nextfile
4269 (org-check-agenda-file file)
4270 (setq rtn (org-agenda-get-day-entries file date :todo))
4271 (setq rtnall (append rtnall rtn))))
4272 (if org-agenda-overriding-header
4273 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4274 nil 'face 'org-agenda-structure) "\n")
4275 (insert "Global list of TODO items of type: ")
4276 (add-text-properties (point-min) (1- (point))
4277 (list 'face 'org-agenda-structure
4278 'short-heading
4279 (concat "ToDo: "
4280 (or org-select-this-todo-keyword "ALL"))))
4281 (org-agenda-mark-header-line (point-min))
4282 (setq pos (point))
4283 (insert (or org-select-this-todo-keyword "ALL") "\n")
4284 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4285 (setq pos (point))
4286 (unless org-agenda-multi
4287 (insert "Available with `N r': (0)ALL")
4288 (let ((n 0) s)
4289 (mapc (lambda (x)
4290 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4291 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4292 (insert "\n "))
4293 (insert " " s))
4294 kwds))
4295 (insert "\n"))
4296 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4297 (org-agenda-mark-header-line (point-min))
4298 (when rtnall
4299 (insert (org-finalize-agenda-entries rtnall) "\n"))
4300 (goto-char (point-min))
4301 (or org-agenda-multi (org-fit-agenda-window))
4302 (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
4303 (org-finalize-agenda)
4304 (setq buffer-read-only t)))
4306 ;;; Agenda tags match
4308 ;;;###autoload
4309 (defun org-tags-view (&optional todo-only match)
4310 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4311 The prefix arg TODO-ONLY limits the search to TODO entries."
4312 (interactive "P")
4313 (let* ((org-tags-match-list-sublevels
4314 org-tags-match-list-sublevels)
4315 (completion-ignore-case t)
4316 rtn rtnall files file pos matcher
4317 buffer)
4318 (when (and (stringp match) (not (string-match "\\S-" match)))
4319 (setq match nil))
4320 (setq matcher (org-make-tags-matcher match)
4321 match (car matcher) matcher (cdr matcher))
4322 (org-prepare-agenda (concat "TAGS " match))
4323 (org-compile-prefix-format 'tags)
4324 (org-set-sorting-strategy 'tags)
4325 (setq org-agenda-query-string match)
4326 (setq org-agenda-redo-command
4327 (list 'org-tags-view (list 'quote todo-only)
4328 (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
4329 (setq files (org-agenda-files nil 'ifmode)
4330 rtnall nil)
4331 (while (setq file (pop files))
4332 (catch 'nextfile
4333 (org-check-agenda-file file)
4334 (setq buffer (if (file-exists-p file)
4335 (org-get-agenda-file-buffer file)
4336 (error "No such file %s" file)))
4337 (if (not buffer)
4338 ;; If file does not exist, error message to agenda
4339 (setq rtn (list
4340 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4341 rtnall (append rtnall rtn))
4342 (with-current-buffer buffer
4343 (unless (derived-mode-p 'org-mode)
4344 (error "Agenda file %s is not in `org-mode'" file))
4345 (save-excursion
4346 (save-restriction
4347 (if org-agenda-restrict
4348 (narrow-to-region org-agenda-restrict-begin
4349 org-agenda-restrict-end)
4350 (widen))
4351 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4352 (setq rtnall (append rtnall rtn))))))))
4353 (if org-agenda-overriding-header
4354 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4355 nil 'face 'org-agenda-structure) "\n")
4356 (insert "Headlines with TAGS match: ")
4357 (add-text-properties (point-min) (1- (point))
4358 (list 'face 'org-agenda-structure
4359 'short-heading
4360 (concat "Match: " match)))
4361 (setq pos (point))
4362 (insert match "\n")
4363 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4364 (setq pos (point))
4365 (unless org-agenda-multi
4366 (insert "Press `C-u r' to search again with new search string\n"))
4367 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4368 (org-agenda-mark-header-line (point-min))
4369 (when rtnall
4370 (insert (org-finalize-agenda-entries rtnall) "\n"))
4371 (goto-char (point-min))
4372 (or org-agenda-multi (org-fit-agenda-window))
4373 (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
4374 (org-finalize-agenda)
4375 (setq buffer-read-only t)))
4377 ;;; Agenda Finding stuck projects
4379 (defvar org-agenda-skip-regexp nil
4380 "Regular expression used in skipping subtrees for the agenda.
4381 This is basically a temporary global variable that can be set and then
4382 used by user-defined selections using `org-agenda-skip-function'.")
4384 (defvar org-agenda-overriding-header nil
4385 "When set during agenda, todo and tags searches it replaces the header.
4386 This variable should not be set directly, but custom commands can bind it
4387 in the options section.")
4389 (defun org-agenda-skip-entry-when-regexp-matches ()
4390 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4391 If yes, it returns the end position of this entry, causing agenda commands
4392 to skip the entry but continuing the search in the subtree. This is a
4393 function that can be put into `org-agenda-skip-function' for the duration
4394 of a command."
4395 (let ((end (save-excursion (org-end-of-subtree t)))
4396 skip)
4397 (save-excursion
4398 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4399 (and skip end)))
4401 (defun org-agenda-skip-subtree-when-regexp-matches ()
4402 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4403 If yes, it returns the end position of this tree, causing agenda commands
4404 to skip this subtree. This is a function that can be put into
4405 `org-agenda-skip-function' for the duration of a command."
4406 (let ((end (save-excursion (org-end-of-subtree t)))
4407 skip)
4408 (save-excursion
4409 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4410 (and skip end)))
4412 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4413 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4414 If yes, it returns the end position of the current entry (NOT the tree),
4415 causing agenda commands to skip the entry but continuing the search in
4416 the subtree. This is a function that can be put into
4417 `org-agenda-skip-function' for the duration of a command. An important
4418 use of this function is for the stuck project list."
4419 (let ((end (save-excursion (org-end-of-subtree t)))
4420 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4421 skip)
4422 (save-excursion
4423 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4424 (and skip entry-end)))
4426 (defun org-agenda-skip-entry-if (&rest conditions)
4427 "Skip entry if any of CONDITIONS is true.
4428 See `org-agenda-skip-if' for details."
4429 (org-agenda-skip-if nil conditions))
4431 (defun org-agenda-skip-subtree-if (&rest conditions)
4432 "Skip entry if any of CONDITIONS is true.
4433 See `org-agenda-skip-if' for details."
4434 (org-agenda-skip-if t conditions))
4436 (defun org-agenda-skip-if (subtree conditions)
4437 "Checks current entity for CONDITIONS.
4438 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4439 the entry (i.e. the text before the next heading) is checked.
4441 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4442 from different tests. Valid conditions are:
4444 scheduled Check if there is a scheduled cookie
4445 notscheduled Check if there is no scheduled cookie
4446 deadline Check if there is a deadline
4447 notdeadline Check if there is no deadline
4448 timestamp Check if there is a timestamp (also deadline or scheduled)
4449 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4450 regexp Check if regexp matches
4451 notregexp Check if regexp does not match.
4452 todo Check if TODO keyword matches
4453 nottodo Check if TODO keyword does not match
4455 The regexp is taken from the conditions list, it must come right after
4456 the `regexp' or `notregexp' element.
4458 `todo' and `nottodo' accept as an argument a list of todo
4459 keywords, which may include \"*\" to match any todo keyword.
4461 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4463 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4465 Instead of a list, a keyword class may be given. For example:
4467 (org-agenda-skip-entry-if 'nottodo 'done)
4469 would skip entries that haven't been marked with any of \"DONE\"
4470 keywords. Possible classes are: `todo', `done', `any'.
4472 If any of these conditions is met, this function returns the end point of
4473 the entity, causing the search to continue from there. This is a function
4474 that can be put into `org-agenda-skip-function' for the duration of a command."
4475 (let (beg end m)
4476 (org-back-to-heading t)
4477 (setq beg (point)
4478 end (if subtree
4479 (progn (org-end-of-subtree t) (point))
4480 (progn (outline-next-heading) (1- (point)))))
4481 (goto-char beg)
4482 (and
4484 (and (memq 'scheduled conditions)
4485 (re-search-forward org-scheduled-time-regexp end t))
4486 (and (memq 'notscheduled conditions)
4487 (not (re-search-forward org-scheduled-time-regexp end t)))
4488 (and (memq 'deadline conditions)
4489 (re-search-forward org-deadline-time-regexp end t))
4490 (and (memq 'notdeadline conditions)
4491 (not (re-search-forward org-deadline-time-regexp end t)))
4492 (and (memq 'timestamp conditions)
4493 (re-search-forward org-ts-regexp end t))
4494 (and (memq 'nottimestamp conditions)
4495 (not (re-search-forward org-ts-regexp end t)))
4496 (and (setq m (memq 'regexp conditions))
4497 (stringp (nth 1 m))
4498 (re-search-forward (nth 1 m) end t))
4499 (and (setq m (memq 'notregexp conditions))
4500 (stringp (nth 1 m))
4501 (not (re-search-forward (nth 1 m) end t)))
4502 (and (or
4503 (setq m (memq 'nottodo conditions))
4504 (setq m (memq 'todo-unblocked conditions))
4505 (setq m (memq 'nottodo-unblocked conditions))
4506 (setq m (memq 'todo conditions)))
4507 (org-agenda-skip-if-todo m end)))
4508 end)))
4510 (defun org-agenda-skip-if-todo (args end)
4511 "Helper function for `org-agenda-skip-if', do not use it directly.
4512 ARGS is a list with first element either `todo', `nottodo',
4513 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4514 a list of TODO keywords, or a state symbol `todo' or `done' or
4515 `any'."
4516 (let ((kw (car args))
4517 (arg (cadr args))
4518 todo-wds todo-re)
4519 (setq todo-wds
4520 (org-uniquify
4521 (cond
4522 ((listp arg) ;; list of keywords
4523 (if (member "*" arg)
4524 (mapcar 'substring-no-properties org-todo-keywords-1)
4525 arg))
4526 ((symbolp arg) ;; keyword class name
4527 (cond
4528 ((eq arg 'todo)
4529 (org-delete-all org-done-keywords
4530 (mapcar 'substring-no-properties
4531 org-todo-keywords-1)))
4532 ((eq arg 'done) org-done-keywords)
4533 ((eq arg 'any)
4534 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4535 (setq todo-re
4536 (concat "^\\*+[ \t]+\\<\\("
4537 (mapconcat 'identity todo-wds "\\|")
4538 "\\)\\>"))
4539 (cond
4540 ((eq kw 'todo) (re-search-forward todo-re end t))
4541 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4542 ((eq kw 'todo-unblocked)
4543 (catch 'unblocked
4544 (while (re-search-forward todo-re end t)
4545 (or (org-entry-blocked-p) (throw 'unblocked t)))
4546 nil))
4547 ((eq kw 'nottodo-unblocked)
4548 (catch 'unblocked
4549 (while (re-search-forward todo-re end t)
4550 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4554 ;;;###autoload
4555 (defun org-agenda-list-stuck-projects (&rest ignore)
4556 "Create agenda view for projects that are stuck.
4557 Stuck projects are project that have no next actions. For the definitions
4558 of what a project is and how to check if it stuck, customize the variable
4559 `org-stuck-projects'."
4560 (interactive)
4561 (let* ((org-agenda-skip-function
4562 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4563 ;; We could have used org-agenda-skip-if here.
4564 (org-agenda-overriding-header
4565 (or org-agenda-overriding-header "List of stuck projects: "))
4566 (matcher (nth 0 org-stuck-projects))
4567 (todo (nth 1 org-stuck-projects))
4568 (todo-wds (if (member "*" todo)
4569 (progn
4570 (org-prepare-agenda-buffers (org-agenda-files
4571 nil 'ifmode))
4572 (org-delete-all
4573 org-done-keywords-for-agenda
4574 (copy-sequence org-todo-keywords-for-agenda)))
4575 todo))
4576 (todo-re (concat "^\\*+[ \t]+\\("
4577 (mapconcat 'identity todo-wds "\\|")
4578 "\\)\\>"))
4579 (tags (nth 2 org-stuck-projects))
4580 (tags-re (if (member "*" tags)
4581 (concat org-outline-regexp-bol
4582 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4583 (if tags
4584 (concat org-outline-regexp-bol
4585 ".*:\\("
4586 (mapconcat 'identity tags "\\|")
4587 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4588 (gen-re (nth 3 org-stuck-projects))
4589 (re-list
4590 (delq nil
4591 (list
4592 (if todo todo-re)
4593 (if tags tags-re)
4594 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4595 gen-re)))))
4596 (setq org-agenda-skip-regexp
4597 (if re-list
4598 (mapconcat 'identity re-list "\\|")
4599 (error "No information how to identify unstuck projects")))
4600 (org-tags-view nil matcher)
4601 (with-current-buffer org-agenda-buffer-name
4602 (setq org-agenda-redo-command
4603 '(org-agenda-list-stuck-projects
4604 (or current-prefix-arg org-last-arg))))))
4606 ;;; Diary integration
4608 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4609 (defvar diary-list-entries-hook)
4610 (defvar diary-time-regexp)
4611 (defun org-get-entries-from-diary (date)
4612 "Get the (Emacs Calendar) diary entries for DATE."
4613 (require 'diary-lib)
4614 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4615 (diary-display-hook '(fancy-diary-display))
4616 (diary-display-function 'fancy-diary-display)
4617 (pop-up-frames nil)
4618 (diary-list-entries-hook
4619 (cons 'org-diary-default-entry diary-list-entries-hook))
4620 (diary-file-name-prefix-function nil) ; turn this feature off
4621 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
4622 entries
4623 (org-disable-agenda-to-diary t))
4624 (save-excursion
4625 (save-window-excursion
4626 (funcall (if (fboundp 'diary-list-entries)
4627 'diary-list-entries 'list-diary-entries)
4628 date 1)))
4629 (if (not (get-buffer diary-fancy-buffer))
4630 (setq entries nil)
4631 (with-current-buffer diary-fancy-buffer
4632 (setq buffer-read-only nil)
4633 (if (zerop (buffer-size))
4634 ;; No entries
4635 (setq entries nil)
4636 ;; Omit the date and other unnecessary stuff
4637 (org-agenda-cleanup-fancy-diary)
4638 ;; Add prefix to each line and extend the text properties
4639 (if (zerop (buffer-size))
4640 (setq entries nil)
4641 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
4642 (setq entries
4643 (with-temp-buffer
4644 (insert entries) (goto-char (point-min))
4645 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
4646 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
4647 (replace-match (concat "; " (match-string 1)))))
4648 (buffer-string)))))
4649 (set-buffer-modified-p nil)
4650 (kill-buffer diary-fancy-buffer)))
4651 (when entries
4652 (setq entries (org-split-string entries "\n"))
4653 (setq entries
4654 (mapcar
4655 (lambda (x)
4656 (setq x (org-agenda-format-item "" x "Diary" nil 'time))
4657 ;; Extend the text properties to the beginning of the line
4658 (org-add-props x (text-properties-at (1- (length x)) x)
4659 'type "diary" 'date date 'face 'org-agenda-diary))
4660 entries)))))
4662 (defvar org-agenda-cleanup-fancy-diary-hook nil
4663 "Hook run when the fancy diary buffer is cleaned up.")
4665 (defun org-agenda-cleanup-fancy-diary ()
4666 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
4667 This gets rid of the date, the underline under the date, and
4668 the dummy entry installed by `org-mode' to ensure non-empty diary for each
4669 date. It also removes lines that contain only whitespace."
4670 (goto-char (point-min))
4671 (if (looking-at ".*?:[ \t]*")
4672 (progn
4673 (replace-match "")
4674 (re-search-forward "\n=+$" nil t)
4675 (replace-match "")
4676 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
4677 (re-search-forward "\n=+$" nil t)
4678 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
4679 (goto-char (point-min))
4680 (while (re-search-forward "^ +\n" nil t)
4681 (replace-match ""))
4682 (goto-char (point-min))
4683 (if (re-search-forward "^Org-mode dummy\n?" nil t)
4684 (replace-match ""))
4685 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
4687 ;; Make sure entries from the diary have the right text properties.
4688 (eval-after-load "diary-lib"
4689 '(if (boundp 'diary-modify-entry-list-string-function)
4690 ;; We can rely on the hook, nothing to do
4692 ;; Hook not available, must use advice to make this work
4693 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
4694 "Make the position visible."
4695 (if (and org-disable-agenda-to-diary ;; called from org-agenda
4696 (stringp string)
4697 buffer-file-name)
4698 (setq string (org-modify-diary-entry-string string))))))
4700 (defun org-modify-diary-entry-string (string)
4701 "Add text properties to string, allowing org-mode to act on it."
4702 (org-add-props string nil
4703 'mouse-face 'highlight
4704 'help-echo (if buffer-file-name
4705 (format "mouse-2 or RET jump to diary file %s"
4706 (abbreviate-file-name buffer-file-name))
4708 'org-agenda-diary-link t
4709 'org-marker (org-agenda-new-marker (point-at-bol))))
4711 (defun org-diary-default-entry ()
4712 "Add a dummy entry to the diary.
4713 Needed to avoid empty dates which mess up holiday display."
4714 ;; Catch the error if dealing with the new add-to-diary-alist
4715 (when org-disable-agenda-to-diary
4716 (condition-case nil
4717 (org-add-to-diary-list original-date "Org-mode dummy" "")
4718 (error
4719 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
4721 (defun org-add-to-diary-list (&rest args)
4722 (if (fboundp 'diary-add-to-list)
4723 (apply 'diary-add-to-list args)
4724 (apply 'add-to-diary-list args)))
4726 (defvar org-diary-last-run-time nil)
4728 ;;;###autoload
4729 (defun org-diary (&rest args)
4730 "Return diary information from org-files.
4731 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
4732 It accesses org files and extracts information from those files to be
4733 listed in the diary. The function accepts arguments specifying what
4734 items should be listed. For a list of arguments allowed here, see the
4735 variable `org-agenda-entry-types'.
4737 The call in the diary file should look like this:
4739 &%%(org-diary) ~/path/to/some/orgfile.org
4741 Use a separate line for each org file to check. Or, if you omit the file name,
4742 all files listed in `org-agenda-files' will be checked automatically:
4744 &%%(org-diary)
4746 If you don't give any arguments (as in the example above), the default
4747 arguments (:deadline :scheduled :timestamp :sexp) are used.
4748 So the example above may also be written as
4750 &%%(org-diary :deadline :timestamp :sexp :scheduled)
4752 The function expects the lisp variables `entry' and `date' to be provided
4753 by the caller, because this is how the calendar works. Don't use this
4754 function from a program - use `org-agenda-get-day-entries' instead."
4755 (when (> (- (org-float-time)
4756 org-agenda-last-marker-time)
4758 ;; I am not sure if this works with sticky agendas, because the marker
4759 ;; list is then no longer a global variable.
4760 (org-agenda-reset-markers))
4761 ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
4762 (when (buffer-live-p org-agenda-buffer)
4763 (org-compile-prefix-format 'agenda))
4764 (org-set-sorting-strategy 'agenda)
4765 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4766 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
4767 (list entry)
4768 (org-agenda-files t)))
4769 (time (org-float-time))
4770 file rtn results)
4771 (when (or (not org-diary-last-run-time)
4772 (> (- time
4773 org-diary-last-run-time)
4775 (org-prepare-agenda-buffers files))
4776 (setq org-diary-last-run-time time)
4777 ;; If this is called during org-agenda, don't return any entries to
4778 ;; the calendar. Org Agenda will list these entries itself.
4779 (if org-disable-agenda-to-diary (setq files nil))
4780 (while (setq file (pop files))
4781 (setq rtn (apply 'org-agenda-get-day-entries file date args))
4782 (setq results (append results rtn)))
4783 (if results
4784 (concat (org-finalize-agenda-entries results) "\n"))))
4786 ;;; Agenda entry finders
4788 (defun org-agenda-get-day-entries (file date &rest args)
4789 "Does the work for `org-diary' and `org-agenda'.
4790 FILE is the path to a file to be checked for entries. DATE is date like
4791 the one returned by `calendar-current-date'. ARGS are symbols indicating
4792 which kind of entries should be extracted. For details about these, see
4793 the documentation of `org-diary'."
4794 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
4795 (let* ((org-startup-folded nil)
4796 (org-startup-align-all-tables nil)
4797 (buffer (if (file-exists-p file)
4798 (org-get-agenda-file-buffer file)
4799 (error "No such file %s" file)))
4800 arg results rtn deadline-results)
4801 (if (not buffer)
4802 ;; If file does not exist, make sure an error message ends up in diary
4803 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4804 (with-current-buffer buffer
4805 (unless (derived-mode-p 'org-mode)
4806 (error "Agenda file %s is not in `org-mode'" file))
4807 (let ((case-fold-search nil))
4808 (save-excursion
4809 (save-restriction
4810 (if org-agenda-restrict
4811 (narrow-to-region org-agenda-restrict-begin
4812 org-agenda-restrict-end)
4813 (widen))
4814 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
4815 (while (setq arg (pop args))
4816 (cond
4817 ((and (eq arg :todo)
4818 (equal date (calendar-gregorian-from-absolute
4819 (org-today))))
4820 (setq rtn (org-agenda-get-todos))
4821 (setq results (append results rtn)))
4822 ((eq arg :timestamp)
4823 (setq rtn (org-agenda-get-blocks))
4824 (setq results (append results rtn))
4825 (setq rtn (org-agenda-get-timestamps deadline-results))
4826 (setq results (append results rtn)))
4827 ((eq arg :sexp)
4828 (setq rtn (org-agenda-get-sexps))
4829 (setq results (append results rtn)))
4830 ((eq arg :scheduled)
4831 (setq rtn (org-agenda-get-scheduled deadline-results))
4832 (setq results (append results rtn)))
4833 ((eq arg :closed)
4834 (setq rtn (org-agenda-get-progress))
4835 (setq results (append results rtn)))
4836 ((eq arg :deadline)
4837 (setq rtn (org-agenda-get-deadlines))
4838 (setq deadline-results (copy-sequence rtn))
4839 (setq results (append results rtn))))))))
4840 results))))
4842 (defvar org-heading-keyword-regexp-format) ; defined in org.el
4843 (defun org-agenda-get-todos ()
4844 "Return the TODO information for agenda display."
4845 (let* ((props (list 'face nil
4846 'done-face 'org-agenda-done
4847 'org-not-done-regexp org-not-done-regexp
4848 'org-todo-regexp org-todo-regexp
4849 'org-complex-heading-regexp org-complex-heading-regexp
4850 'mouse-face 'highlight
4851 'help-echo
4852 (format "mouse-2 or RET jump to org file %s"
4853 (abbreviate-file-name buffer-file-name))))
4854 (regexp (format org-heading-keyword-regexp-format
4855 (cond
4856 ((and org-select-this-todo-keyword
4857 (equal org-select-this-todo-keyword "*"))
4858 org-todo-regexp)
4859 (org-select-this-todo-keyword
4860 (concat "\\("
4861 (mapconcat 'identity
4862 (org-split-string
4863 org-select-this-todo-keyword
4864 "|")
4865 "\\|") "\\)"))
4866 (t org-not-done-regexp))))
4867 marker priority category org-category-pos tags todo-state
4868 ee txt beg end)
4869 (goto-char (point-min))
4870 (while (re-search-forward regexp nil t)
4871 (catch :skip
4872 (save-match-data
4873 (beginning-of-line)
4874 (org-agenda-skip)
4875 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
4876 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
4877 (goto-char (1+ beg))
4878 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
4879 (throw :skip nil)))
4880 (goto-char (match-beginning 2))
4881 (setq marker (org-agenda-new-marker (match-beginning 0))
4882 category (org-get-category)
4883 org-category-pos (get-text-property (point) 'org-category-position)
4884 txt (org-trim
4885 (buffer-substring (match-beginning 2) (match-end 0)))
4886 tags (org-get-tags-at (point))
4887 txt (org-agenda-format-item "" txt category tags)
4888 priority (1+ (org-get-priority txt))
4889 todo-state (org-get-todo-state))
4890 (org-add-props txt props
4891 'org-marker marker 'org-hd-marker marker
4892 'priority priority 'org-category category
4893 'org-category-position org-category-pos
4894 'type "todo" 'todo-state todo-state)
4895 (push txt ee)
4896 (if org-agenda-todo-list-sublevels
4897 (goto-char (match-end 2))
4898 (org-end-of-subtree 'invisible))))
4899 (nreverse ee)))
4901 (defun org-agenda-todo-custom-ignore-p (time n)
4902 "Check whether timestamp is farther away then n number of days.
4903 This function is invoked if `org-agenda-todo-ignore-deadlines',
4904 `org-agenda-todo-ignore-scheduled' or
4905 `org-agenda-todo-ignore-timestamp' is set to an integer."
4906 (let ((days (org-days-to-time time)))
4907 (if (>= n 0)
4908 (>= days n)
4909 (<= days n))))
4911 ;;;###autoload
4912 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
4913 (&optional end)
4914 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
4915 (when (or org-agenda-todo-ignore-with-date
4916 org-agenda-todo-ignore-scheduled
4917 org-agenda-todo-ignore-deadlines
4918 org-agenda-todo-ignore-timestamp)
4919 (setq end (or end (save-excursion (outline-next-heading) (point))))
4920 (save-excursion
4921 (or (and org-agenda-todo-ignore-with-date
4922 (re-search-forward org-ts-regexp end t))
4923 (and org-agenda-todo-ignore-scheduled
4924 (re-search-forward org-scheduled-time-regexp end t)
4925 (cond
4926 ((eq org-agenda-todo-ignore-scheduled 'future)
4927 (> (org-days-to-time (match-string 1)) 0))
4928 ((eq org-agenda-todo-ignore-scheduled 'past)
4929 (<= (org-days-to-time (match-string 1)) 0))
4930 ((numberp org-agenda-todo-ignore-scheduled)
4931 (org-agenda-todo-custom-ignore-p
4932 (match-string 1) org-agenda-todo-ignore-scheduled))
4933 (t)))
4934 (and org-agenda-todo-ignore-deadlines
4935 (re-search-forward org-deadline-time-regexp end t)
4936 (cond
4937 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
4938 ((eq org-agenda-todo-ignore-deadlines 'far)
4939 (not (org-deadline-close (match-string 1))))
4940 ((eq org-agenda-todo-ignore-deadlines 'future)
4941 (> (org-days-to-time (match-string 1)) 0))
4942 ((eq org-agenda-todo-ignore-deadlines 'past)
4943 (<= (org-days-to-time (match-string 1)) 0))
4944 ((numberp org-agenda-todo-ignore-deadlines)
4945 (org-agenda-todo-custom-ignore-p
4946 (match-string 1) org-agenda-todo-ignore-deadlines))
4947 (t (org-deadline-close (match-string 1)))))
4948 (and org-agenda-todo-ignore-timestamp
4949 (let ((buffer (current-buffer))
4950 (regexp
4951 (concat
4952 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
4953 (start (point)))
4954 ;; Copy current buffer into a temporary one
4955 (with-temp-buffer
4956 (insert-buffer-substring buffer start end)
4957 (goto-char (point-min))
4958 ;; Delete SCHEDULED and DEADLINE items
4959 (while (re-search-forward regexp end t)
4960 (delete-region (match-beginning 0) (match-end 0)))
4961 (goto-char (point-min))
4962 ;; No search for timestamp left
4963 (when (re-search-forward org-ts-regexp nil t)
4964 (cond
4965 ((eq org-agenda-todo-ignore-timestamp 'future)
4966 (> (org-days-to-time (match-string 1)) 0))
4967 ((eq org-agenda-todo-ignore-timestamp 'past)
4968 (<= (org-days-to-time (match-string 1)) 0))
4969 ((numberp org-agenda-todo-ignore-timestamp)
4970 (org-agenda-todo-custom-ignore-p
4971 (match-string 1) org-agenda-todo-ignore-timestamp))
4972 (t))))))))))
4974 (defconst org-agenda-no-heading-message
4975 "No heading for this item in buffer or region.")
4977 (defun org-agenda-get-timestamps (&optional deadline-results)
4978 "Return the date stamp information for agenda display."
4979 (let* ((props (list 'face 'org-agenda-calendar-event
4980 'org-not-done-regexp org-not-done-regexp
4981 'org-todo-regexp org-todo-regexp
4982 'org-complex-heading-regexp org-complex-heading-regexp
4983 'mouse-face 'highlight
4984 'help-echo
4985 (format "mouse-2 or RET jump to org file %s"
4986 (abbreviate-file-name buffer-file-name))))
4987 (d1 (calendar-absolute-from-gregorian date))
4989 (deadline-position-alist
4990 (mapcar (lambda (a) (and (setq mm (get-text-property
4991 0 'org-hd-marker a))
4992 (cons (marker-position mm) a)))
4993 deadline-results))
4994 (remove-re org-ts-regexp)
4995 (regexp
4996 (concat
4997 (if org-agenda-include-inactive-timestamps "[[<]" "<")
4998 (regexp-quote
4999 (substring
5000 (format-time-string
5001 (car org-time-stamp-formats)
5002 (apply 'encode-time ; DATE bound by calendar
5003 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5004 1 11))
5005 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5006 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5007 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5008 donep tmp priority category org-category-pos ee txt timestr tags
5009 b0 b3 e3 head todo-state end-of-match show-all)
5010 (goto-char (point-min))
5011 (while (setq end-of-match (re-search-forward regexp nil t))
5012 (setq b0 (match-beginning 0)
5013 b3 (match-beginning 3) e3 (match-end 3)
5014 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5015 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5016 (member todo-state
5017 org-agenda-repeating-timestamp-show-all)))
5018 (catch :skip
5019 (and (org-at-date-range-p) (throw :skip nil))
5020 (org-agenda-skip)
5021 (if (and (match-end 1)
5022 (not (= d1 (org-time-string-to-absolute
5023 (match-string 1) d1 nil show-all
5024 (current-buffer) b0))))
5025 (throw :skip nil))
5026 (if (and e3
5027 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5028 (throw :skip nil))
5029 (setq tmp (buffer-substring (max (point-min)
5030 (- b0 org-ds-keyword-length))
5032 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5033 inactivep (= (char-after b0) ?\[)
5034 deadlinep (string-match org-deadline-regexp tmp)
5035 scheduledp (string-match org-scheduled-regexp tmp)
5036 closedp (and org-agenda-include-inactive-timestamps
5037 (string-match org-closed-string tmp))
5038 clockp (and org-agenda-include-inactive-timestamps
5039 (or (string-match org-clock-string tmp)
5040 (string-match "]-+\\'" tmp)))
5041 donep (member todo-state org-done-keywords))
5042 (if (or scheduledp deadlinep closedp clockp
5043 (and donep org-agenda-skip-timestamp-if-done))
5044 (throw :skip t))
5045 (if (string-match ">" timestr)
5046 ;; substring should only run to end of time stamp
5047 (setq timestr (substring timestr 0 (match-end 0))))
5048 (setq marker (org-agenda-new-marker b0)
5049 category (org-get-category b0)
5050 org-category-pos (get-text-property b0 'org-category-position))
5051 (save-excursion
5052 (if (not (re-search-backward org-outline-regexp-bol nil t))
5053 (setq txt org-agenda-no-heading-message)
5054 (goto-char (match-beginning 0))
5055 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5056 (assoc (point) deadline-position-alist))
5057 (throw :skip nil))
5058 (setq hdmarker (org-agenda-new-marker)
5059 tags (org-get-tags-at))
5060 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5061 (setq head (or (match-string 1) ""))
5062 (setq txt (org-agenda-format-item
5063 (if inactivep org-agenda-inactive-leader nil)
5064 head category tags timestr
5065 remove-re)))
5066 (setq priority (org-get-priority txt))
5067 (org-add-props txt props
5068 'org-marker marker 'org-hd-marker hdmarker)
5069 (org-add-props txt nil 'priority priority
5070 'org-category category 'date date
5071 'org-category-position org-category-pos
5072 'todo-state todo-state
5073 'type "timestamp")
5074 (push txt ee))
5075 (if org-agenda-skip-additional-timestamps-same-entry
5076 (outline-next-heading)
5077 (goto-char end-of-match))))
5078 (nreverse ee)))
5080 (defun org-agenda-get-sexps ()
5081 "Return the sexp information for agenda display."
5082 (require 'diary-lib)
5083 (let* ((props (list 'face 'org-agenda-calendar-sexp
5084 'mouse-face 'highlight
5085 'help-echo
5086 (format "mouse-2 or RET jump to org file %s"
5087 (abbreviate-file-name buffer-file-name))))
5088 (regexp "^&?%%(")
5089 marker category extra org-category-pos ee txt tags entry
5090 result beg b sexp sexp-entry todo-state)
5091 (goto-char (point-min))
5092 (while (re-search-forward regexp nil t)
5093 (catch :skip
5094 (org-agenda-skip)
5095 (setq beg (match-beginning 0))
5096 (goto-char (1- (match-end 0)))
5097 (setq b (point))
5098 (forward-sexp 1)
5099 (setq sexp (buffer-substring b (point)))
5100 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5101 (org-trim (match-string 1))
5102 ""))
5103 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5104 (when result
5105 (setq marker (org-agenda-new-marker beg)
5106 category (org-get-category beg)
5107 org-category-pos (get-text-property beg 'org-category-position)
5108 tags (save-excursion (org-backward-heading-same-level 0) (org-get-tags))
5109 todo-state (org-get-todo-state))
5111 (dolist (r (if (stringp result)
5112 (list result)
5113 result)) ;; we expect a list here
5114 (when (and org-agenda-diary-sexp-prefix
5115 (string-match org-agenda-diary-sexp-prefix r))
5116 (setq extra (match-string 0 r)
5117 r (replace-match "" nil nil r)))
5118 (if (string-match "\\S-" r)
5119 (setq txt r)
5120 (setq txt "SEXP entry returned empty string"))
5122 (setq txt (org-agenda-format-item
5123 extra txt category tags 'time))
5124 (org-add-props txt props 'org-marker marker)
5125 (org-add-props txt nil
5126 'org-category category 'date date 'todo-state todo-state
5127 'org-category-position org-category-pos 'tags tags
5128 'type "sexp")
5129 (push txt ee)))))
5130 (nreverse ee)))
5132 ;; Calendar sanity: define some functions that are independent of
5133 ;; `calendar-date-style'.
5134 ;; Normally I would like to use ISO format when calling the diary functions,
5135 ;; but to make sure we still have Emacs 22 compatibility we bind
5136 ;; also `european-calendar-style' and use european format
5137 (defun org-anniversary (year month day &optional mark)
5138 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5139 (org-no-warnings
5140 (let ((calendar-date-style 'european) (european-calendar-style t))
5141 (diary-anniversary day month year mark))))
5142 (defun org-cyclic (N year month day &optional mark)
5143 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5144 (org-no-warnings
5145 (let ((calendar-date-style 'european) (european-calendar-style t))
5146 (diary-cyclic N day month year mark))))
5147 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5148 "Like `diary-block', but with fixed (ISO) order of arguments."
5149 (org-no-warnings
5150 (let ((calendar-date-style 'european) (european-calendar-style t))
5151 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5152 (defun org-date (year month day &optional mark)
5153 "Like `diary-date', but with fixed (ISO) order of arguments."
5154 (org-no-warnings
5155 (let ((calendar-date-style 'european) (european-calendar-style t))
5156 (diary-date day month year mark))))
5157 (defalias 'org-float 'diary-float)
5159 ;; Define the` org-class' function
5160 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5161 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5162 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5163 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5164 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5165 `holidays', then any date that is known by the Emacs calendar to be a
5166 holiday will also be skipped."
5167 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5168 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5169 (d (calendar-absolute-from-gregorian date)))
5170 (and
5171 (<= date1 d)
5172 (<= d date2)
5173 (= (calendar-day-of-week date) dayname)
5174 (or (not skip-weeks)
5175 (progn
5176 (require 'cal-iso)
5177 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5178 (not (and (memq 'holidays skip-weeks)
5179 (calendar-check-holidays date)))
5180 entry)))
5182 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5183 "Like `org-class', but honor `calendar-date-style'.
5184 The order of the first 2 times 3 arguments depends on the variable
5185 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5186 So for American calendars, give this as MONTH DAY YEAR, for European as
5187 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5188 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5189 is any number of ISO weeks in the block period for which the item should
5190 be skipped.
5192 This function is here only for backward compatibility and it is deprecated,
5193 please use `org-class' instead."
5194 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5195 (date2 (org-order-calendar-date-args m2 d2 y2)))
5196 (org-class
5197 (nth 2 date1) (car date1) (nth 1 date1)
5198 (nth 2 date2) (car date2) (nth 1 date2)
5199 dayname skip-weeks)))
5200 (make-obsolete 'org-diary-class 'org-class "")
5202 (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
5203 (defalias 'org-get-closed 'org-agenda-get-progress)
5204 (defun org-agenda-get-progress ()
5205 "Return the logged TODO entries for agenda display."
5206 (let* ((props (list 'mouse-face 'highlight
5207 'org-not-done-regexp org-not-done-regexp
5208 'org-todo-regexp org-todo-regexp
5209 'org-complex-heading-regexp org-complex-heading-regexp
5210 'help-echo
5211 (format "mouse-2 or RET jump to org file %s"
5212 (abbreviate-file-name buffer-file-name))))
5213 (items (if (consp org-agenda-show-log-scoped)
5214 org-agenda-show-log-scoped
5215 (if (eq org-agenda-show-log-scoped 'clockcheck)
5216 '(clock)
5217 org-agenda-log-mode-items)))
5218 (parts
5219 (delq nil
5220 (list
5221 (if (memq 'closed items) (concat "\\<" org-closed-string))
5222 (if (memq 'clock items) (concat "\\<" org-clock-string))
5223 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5224 (parts-re (if parts (mapconcat 'identity parts "\\|")
5225 (error "`org-agenda-log-mode-items' is empty")))
5226 (regexp (concat
5227 "\\(" parts-re "\\)"
5228 " *\\["
5229 (regexp-quote
5230 (substring
5231 (format-time-string
5232 (car org-time-stamp-formats)
5233 (apply 'encode-time ; DATE bound by calendar
5234 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5235 1 11))))
5236 (org-agenda-search-headline-for-time nil)
5237 marker hdmarker priority category org-category-pos tags closedp
5238 statep clockp state ee txt extra timestr rest clocked)
5239 (goto-char (point-min))
5240 (while (re-search-forward regexp nil t)
5241 (catch :skip
5242 (org-agenda-skip)
5243 (setq marker (org-agenda-new-marker (match-beginning 0))
5244 closedp (equal (match-string 1) org-closed-string)
5245 statep (equal (string-to-char (match-string 1)) ?-)
5246 clockp (not (or closedp statep))
5247 state (and statep (match-string 2))
5248 category (org-get-category (match-beginning 0))
5249 org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
5250 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5251 (when (string-match "\\]" timestr)
5252 ;; substring should only run to end of time stamp
5253 (setq rest (substring timestr (match-end 0))
5254 timestr (substring timestr 0 (match-end 0)))
5255 (if (and (not closedp) (not statep)
5256 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5257 rest))
5258 (progn (setq timestr (concat (substring timestr 0 -1)
5259 "-" (match-string 1 rest) "]"))
5260 (setq clocked (match-string 2 rest)))
5261 (setq clocked "-")))
5262 (save-excursion
5263 (setq extra
5264 (cond
5265 ((not org-agenda-log-mode-add-notes) nil)
5266 (statep
5267 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5268 (match-string 1)))
5269 (clockp
5270 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5271 (match-string 1)))))
5272 (if (not (re-search-backward org-outline-regexp-bol nil t))
5273 (setq txt org-agenda-no-heading-message)
5274 (goto-char (match-beginning 0))
5275 (setq hdmarker (org-agenda-new-marker)
5276 tags (org-get-tags-at))
5277 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5278 (setq txt (match-string 1))
5279 (when extra
5280 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5281 (setq txt (concat (substring txt 0 (match-beginning 1))
5282 " - " extra " " (match-string 2 txt)))
5283 (setq txt (concat txt " - " extra))))
5284 (setq txt (org-agenda-format-item
5285 (cond
5286 (closedp "Closed: ")
5287 (statep (concat "State: (" state ")"))
5288 (t (concat "Clocked: (" clocked ")")))
5289 txt category tags timestr)))
5290 (setq priority 100000)
5291 (org-add-props txt props
5292 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5293 'priority priority 'org-category category
5294 'org-category-position org-category-pos
5295 'type "closed" 'date date
5296 'undone-face 'org-warning 'done-face 'org-agenda-done)
5297 (push txt ee))
5298 (goto-char (point-at-eol))))
5299 (nreverse ee)))
5301 (defun org-agenda-show-clocking-issues ()
5302 "Add overlays, showing issues with clocking.
5303 See also the user option `org-agenda-clock-consistency-checks'."
5304 (interactive)
5305 (let* ((pl org-agenda-clock-consistency-checks)
5306 (re (concat "^[ \t]*"
5307 org-clock-string
5308 "[ \t]+"
5309 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5310 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5311 (tlstart 0.)
5312 (tlend 0.)
5313 (maxtime (org-hh:mm-string-to-minutes
5314 (or (plist-get pl :max-duration) "24:00")))
5315 (mintime (org-hh:mm-string-to-minutes
5316 (or (plist-get pl :min-duration) 0)))
5317 (maxgap (org-hh:mm-string-to-minutes
5318 ;; default 30:00 means never complain
5319 (or (plist-get pl :max-gap) "30:00")))
5320 (gapok (mapcar 'org-hh:mm-string-to-minutes
5321 (plist-get pl :gap-ok-around)))
5322 (def-face (or (plist-get pl :default-face)
5323 '((:background "DarkRed") (:foreground "white"))))
5324 issue face m te ts dt ov)
5325 (goto-char (point-min))
5326 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5327 (setq issue nil face def-face)
5328 (catch 'next
5329 (setq m (org-get-at-bol 'org-marker)
5330 te nil ts nil)
5331 (unless (and m (markerp m))
5332 (setq issue "No valid clock line") (throw 'next t))
5333 (org-with-point-at m
5334 (save-excursion
5335 (goto-char (point-at-bol))
5336 (unless (looking-at re)
5337 (error "No valid Clock line")
5338 (throw 'next t))
5339 (unless (match-end 3)
5340 (setq issue "No end time"
5341 face (or (plist-get pl :no-end-time-face) face))
5342 (throw 'next t))
5343 (setq ts (match-string 1)
5344 te (match-string 3)
5345 ts (org-float-time
5346 (apply 'encode-time (org-parse-time-string ts)))
5347 te (org-float-time
5348 (apply 'encode-time (org-parse-time-string te)))
5349 dt (- te ts))))
5350 (cond
5351 ((> dt (* 60 maxtime))
5352 ;; a very long clocking chunk
5353 (setq issue (format "Clocking interval is very long: %s"
5354 (org-minutes-to-hh:mm-string
5355 (floor (/ (float dt) 60.))))
5356 face (or (plist-get pl :long-face) face)))
5357 ((< dt (* 60 mintime))
5358 ;; a very short clocking chunk
5359 (setq issue (format "Clocking interval is very short: %s"
5360 (org-minutes-to-hh:mm-string
5361 (floor (/ (float dt) 60.))))
5362 face (or (plist-get pl :short-face) face)))
5363 ((and (> tlend 0) (< ts tlend))
5364 ;; Two clock entries are overlapping
5365 (setq issue (format "Clocking overlap: %d minutes"
5366 (/ (- tlend ts) 60))
5367 face (or (plist-get pl :overlap-face) face)))
5368 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5369 ;; There is a gap, lets see if we need to report it
5370 (unless (org-agenda-check-clock-gap tlend ts gapok)
5371 (setq issue (format "Clocking gap: %d minutes"
5372 (/ (- ts tlend) 60))
5373 face (or (plist-get pl :gap-face) face))))
5374 (t nil)))
5375 (setq tlend (or te tlend) tlstart (or ts tlstart))
5376 (when issue
5377 ;; OK, there was some issue, add an overlay to show the issue
5378 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5379 (overlay-put ov 'before-string
5380 (concat
5381 (org-add-props
5382 (format "%-43s" (concat " " issue))
5384 'face face)
5385 "\n"))
5386 (overlay-put ov 'evaporate t)))))
5388 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5389 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5390 (catch 'exit
5391 (unless ok-list
5392 ;; there are no OK times for gaps...
5393 (throw 'exit nil))
5394 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5395 ;; This is more than 24 hours, so it is OK.
5396 ;; because we have at least one OK time, that must be in the
5397 ;; 24 hour interval.
5398 (throw 'exit t))
5399 ;; We have a shorter gap.
5400 ;; Now we have to get the minute of the day when these times are
5401 (let* ((t1dec (decode-time (seconds-to-time t1)))
5402 (t2dec (decode-time (seconds-to-time t2)))
5403 ;; compute the minute on the day
5404 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5405 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5406 (when (< min2 min1)
5407 ;; if min2 is smaller than min1, this means it is on the next day.
5408 ;; Wrap it to after midnight.
5409 (setq min2 (+ min2 1440)))
5410 ;; Now check if any of the OK times is in the gap
5411 (mapc (lambda (x)
5412 ;; Wrap the time to after midnight if necessary
5413 (if (< x min1) (setq x (+ x 1440)))
5414 ;; Check if in interval
5415 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5416 ok-list)
5417 ;; Nope, this gap is not OK
5418 nil)))
5420 (defun org-agenda-get-deadlines ()
5421 "Return the deadline information for agenda display."
5422 (let* ((props (list 'mouse-face 'highlight
5423 'org-not-done-regexp org-not-done-regexp
5424 'org-todo-regexp org-todo-regexp
5425 'org-complex-heading-regexp org-complex-heading-regexp
5426 'help-echo
5427 (format "mouse-2 or RET jump to org file %s"
5428 (abbreviate-file-name buffer-file-name))))
5429 (regexp org-deadline-time-regexp)
5430 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5431 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5432 d2 diff dfrac wdays pos pos1 category org-category-pos
5433 tags suppress-prewarning ee txt head face s todo-state
5434 show-all upcomingp donep timestr)
5435 (goto-char (point-min))
5436 (while (re-search-forward regexp nil t)
5437 (setq suppress-prewarning nil)
5438 (catch :skip
5439 (org-agenda-skip)
5440 (when (and org-agenda-skip-deadline-prewarning-if-scheduled
5441 (save-match-data
5442 (string-match org-scheduled-time-regexp
5443 (buffer-substring (point-at-bol)
5444 (point-at-eol)))))
5445 (setq suppress-prewarning
5446 (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5447 org-agenda-skip-deadline-prewarning-if-scheduled
5448 0)))
5449 (setq s (match-string 1)
5450 txt nil
5451 pos (1- (match-beginning 1))
5452 todo-state (save-match-data (org-get-todo-state))
5453 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5454 (member todo-state
5455 org-agenda-repeating-timestamp-show-all))
5456 d2 (org-time-string-to-absolute
5457 (match-string 1) d1 'past show-all
5458 (current-buffer) pos)
5459 diff (- d2 d1)
5460 wdays (if suppress-prewarning
5461 (let ((org-deadline-warning-days suppress-prewarning))
5462 (org-get-wdays s))
5463 (org-get-wdays s))
5464 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5465 upcomingp (and todayp (> diff 0)))
5466 ;; When to show a deadline in the calendar:
5467 ;; If the expiration is within wdays warning time.
5468 ;; Past-due deadlines are only shown on the current date
5469 (if (and (or (and (<= diff wdays)
5470 (and todayp (not org-agenda-only-exact-dates)))
5471 (= diff 0)))
5472 (save-excursion
5473 ;; (setq todo-state (org-get-todo-state))
5474 (setq donep (member todo-state org-done-keywords))
5475 (if (and donep
5476 (or org-agenda-skip-deadline-if-done
5477 (not (= diff 0))))
5478 (setq txt nil)
5479 (setq category (org-get-category)
5480 org-category-pos (get-text-property (point) 'org-category-position))
5481 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5482 (setq txt org-agenda-no-heading-message)
5483 (goto-char (match-end 0))
5484 (setq pos1 (match-beginning 0))
5485 (setq tags (org-get-tags-at pos1))
5486 (setq head (buffer-substring-no-properties
5487 (point)
5488 (progn (skip-chars-forward "^\r\n")
5489 (point))))
5490 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5491 (setq timestr
5492 (concat (substring s (match-beginning 1)) " "))
5493 (setq timestr 'time))
5494 (setq txt (org-agenda-format-item
5495 (if (= diff 0)
5496 (car org-agenda-deadline-leaders)
5497 (if (functionp
5498 (nth 1 org-agenda-deadline-leaders))
5499 (funcall
5500 (nth 1 org-agenda-deadline-leaders)
5501 diff date)
5502 (format (nth 1 org-agenda-deadline-leaders)
5503 diff)))
5504 head category tags
5505 (if (not (= diff 0)) nil timestr)))))
5506 (when txt
5507 (setq face (org-agenda-deadline-face dfrac))
5508 (org-add-props txt props
5509 'org-marker (org-agenda-new-marker pos)
5510 'org-hd-marker (org-agenda-new-marker pos1)
5511 'priority (+ (- diff)
5512 (org-get-priority txt))
5513 'org-category category
5514 'org-category-position org-category-pos
5515 'todo-state todo-state
5516 'type (if upcomingp "upcoming-deadline" "deadline")
5517 'date (if upcomingp date d2)
5518 'face (if donep 'org-agenda-done face)
5519 'undone-face face 'done-face 'org-agenda-done)
5520 (push txt ee))))))
5521 (nreverse ee)))
5523 (defun org-agenda-deadline-face (fraction)
5524 "Return the face to displaying a deadline item.
5525 FRACTION is what fraction of the head-warning time has passed."
5526 (let ((faces org-agenda-deadline-faces) f)
5527 (catch 'exit
5528 (while (setq f (pop faces))
5529 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5531 (defun org-agenda-get-scheduled (&optional deadline-results)
5532 "Return the scheduled information for agenda display."
5533 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5534 'org-todo-regexp org-todo-regexp
5535 'org-complex-heading-regexp org-complex-heading-regexp
5536 'done-face 'org-agenda-done
5537 'mouse-face 'highlight
5538 'help-echo
5539 (format "mouse-2 or RET jump to org file %s"
5540 (abbreviate-file-name buffer-file-name))))
5541 (regexp org-scheduled-time-regexp)
5542 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5543 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5545 (deadline-position-alist
5546 (mapcar (lambda (a) (and (setq mm (get-text-property
5547 0 'org-hd-marker a))
5548 (cons (marker-position mm) a)))
5549 deadline-results))
5550 d2 diff pos pos1 category org-category-pos tags donep
5551 ee txt head pastschedp todo-state face timestr s habitp show-all
5552 did-habit-check-p)
5553 (goto-char (point-min))
5554 (while (re-search-forward regexp nil t)
5555 (catch :skip
5556 (org-agenda-skip)
5557 (setq s (match-string 1)
5558 txt nil
5559 pos (1- (match-beginning 1))
5560 todo-state (save-match-data (org-get-todo-state))
5561 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5562 (member todo-state
5563 org-agenda-repeating-timestamp-show-all))
5564 d2 (org-time-string-to-absolute
5565 (match-string 1) d1 'past show-all
5566 (current-buffer) pos)
5567 diff (- d2 d1))
5568 (setq pastschedp (and todayp (< diff 0)))
5569 (setq did-habit-check-p nil)
5570 ;; When to show a scheduled item in the calendar:
5571 ;; If it is on or past the date.
5572 (when (or (and (< diff 0)
5573 (< (abs diff) org-scheduled-past-days)
5574 (and todayp (not org-agenda-only-exact-dates)))
5575 (= diff 0)
5576 ;; org-is-habit-p uses org-entry-get, which is expansive
5577 ;; so we go extra mile to only call it once
5578 (and todayp
5579 org-habit-show-all-today
5580 (setq did-habit-check-p t)
5581 (setq habitp (and (functionp 'org-is-habit-p)
5582 (org-is-habit-p)))))
5583 (save-excursion
5584 (setq donep (member todo-state org-done-keywords))
5585 (if (and donep
5586 (or org-agenda-skip-scheduled-if-done
5587 (not (= diff 0))
5588 (and (functionp 'org-is-habit-p)
5589 (org-is-habit-p))))
5590 (setq txt nil)
5591 (setq habitp (if did-habit-check-p habitp
5592 (and (functionp 'org-is-habit-p)
5593 (org-is-habit-p))))
5594 (setq category (org-get-category)
5595 org-category-pos (get-text-property (point) 'org-category-position))
5596 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5597 (setq txt org-agenda-no-heading-message)
5598 (goto-char (match-end 0))
5599 (setq pos1 (match-beginning 0))
5600 (if habitp
5601 (if (or (not org-habit-show-habits)
5602 (and (not todayp)
5603 org-habit-show-habits-only-for-today))
5604 (throw :skip nil))
5605 (if (and
5606 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
5607 (and org-agenda-skip-scheduled-if-deadline-is-shown
5608 pastschedp))
5609 (setq mm (assoc pos1 deadline-position-alist)))
5610 (throw :skip nil)))
5611 (setq tags (org-get-tags-at))
5612 (setq head (buffer-substring-no-properties
5613 (point)
5614 (progn (skip-chars-forward "^\r\n") (point))))
5615 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5616 (setq timestr
5617 (concat (substring s (match-beginning 1)) " "))
5618 (setq timestr 'time))
5619 (setq txt (org-agenda-format-item
5620 (if (= diff 0)
5621 (car org-agenda-scheduled-leaders)
5622 (format (nth 1 org-agenda-scheduled-leaders)
5623 (- 1 diff)))
5624 head category tags
5625 (if (not (= diff 0)) nil timestr)
5626 nil habitp))))
5627 (when txt
5628 (setq face
5629 (cond
5630 ((and (not habitp) pastschedp)
5631 'org-scheduled-previously)
5632 (todayp 'org-scheduled-today)
5633 (t 'org-scheduled))
5634 habitp (and habitp (org-habit-parse-todo)))
5635 (org-add-props txt props
5636 'undone-face face
5637 'face (if donep 'org-agenda-done face)
5638 'org-marker (org-agenda-new-marker pos)
5639 'org-hd-marker (org-agenda-new-marker pos1)
5640 'type (if pastschedp "past-scheduled" "scheduled")
5641 'date (if pastschedp d2 date)
5642 'priority (if habitp
5643 (org-habit-get-priority habitp)
5644 (+ 94 (- 5 diff) (org-get-priority txt)))
5645 'org-category category
5646 'org-category-position org-category-pos
5647 'org-habit-p habitp
5648 'todo-state todo-state)
5649 (push txt ee))))))
5650 (nreverse ee)))
5652 (defun org-agenda-get-blocks ()
5653 "Return the date-range information for agenda display."
5654 (let* ((props (list 'face nil
5655 'org-not-done-regexp org-not-done-regexp
5656 'org-todo-regexp org-todo-regexp
5657 'org-complex-heading-regexp org-complex-heading-regexp
5658 'mouse-face 'highlight
5659 'help-echo
5660 (format "mouse-2 or RET jump to org file %s"
5661 (abbreviate-file-name buffer-file-name))))
5662 (regexp org-tr-regexp)
5663 (d0 (calendar-absolute-from-gregorian date))
5664 marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
5665 todo-state tags pos head donep)
5666 (goto-char (point-min))
5667 (while (re-search-forward regexp nil t)
5668 (catch :skip
5669 (org-agenda-skip)
5670 (setq pos (point))
5671 (let ((start-time (match-string 1))
5672 (end-time (match-string 2)))
5673 (setq s1 (match-string 1)
5674 s2 (match-string 2)
5675 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
5676 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
5677 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
5678 ;; Only allow days between the limits, because the normal
5679 ;; date stamps will catch the limits.
5680 (save-excursion
5681 (setq todo-state (org-get-todo-state))
5682 (setq donep (member todo-state org-done-keywords))
5683 (if (and donep org-agenda-skip-timestamp-if-done)
5684 (throw :skip t))
5685 (setq marker (org-agenda-new-marker (point)))
5686 (setq category (org-get-category)
5687 org-category-pos (get-text-property (point) 'org-category-position))
5688 (if (not (re-search-backward org-outline-regexp-bol nil t))
5689 (setq txt org-agenda-no-heading-message)
5690 (goto-char (match-beginning 0))
5691 (setq hdmarker (org-agenda-new-marker (point)))
5692 (setq tags (org-get-tags-at))
5693 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5694 (setq head (match-string 1))
5695 (let ((remove-re
5696 (if org-agenda-remove-timeranges-from-blocks
5697 (concat
5698 "<" (regexp-quote s1) ".*?>"
5699 "--"
5700 "<" (regexp-quote s2) ".*?>")
5701 nil)))
5702 (setq txt (org-agenda-format-item
5703 (format
5704 (nth (if (= d1 d2) 0 1)
5705 org-agenda-timerange-leaders)
5706 (1+ (- d0 d1)) (1+ (- d2 d1)))
5707 head category tags
5708 (cond ((and (= d1 d0) (= d2 d0))
5709 (concat "<" start-time ">--<" end-time ">"))
5710 ((= d1 d0)
5711 (concat "<" start-time ">"))
5712 ((= d2 d0)
5713 (concat "<" end-time ">"))
5714 (t nil))
5715 remove-re))))
5716 (org-add-props txt props
5717 'org-marker marker 'org-hd-marker hdmarker
5718 'type "block" 'date date
5719 'todo-state todo-state
5720 'priority (org-get-priority txt) 'org-category category
5721 'org-category-position org-category-pos)
5722 (push txt ee))))
5723 (goto-char pos)))
5724 ;; Sort the entries by expiration date.
5725 (nreverse ee)))
5727 ;;; Agenda presentation and sorting
5729 (defvar org-prefix-has-time nil
5730 "A flag, set by `org-compile-prefix-format'.
5731 The flag is set if the currently compiled format contains a `%t'.")
5732 (defvar org-prefix-has-tag nil
5733 "A flag, set by `org-compile-prefix-format'.
5734 The flag is set if the currently compiled format contains a `%T'.")
5735 (defvar org-prefix-has-effort nil
5736 "A flag, set by `org-compile-prefix-format'.
5737 The flag is set if the currently compiled format contains a `%e'.")
5738 (defvar org-prefix-category-length nil
5739 "Used by `org-compile-prefix-format' to remember the category field width.")
5740 (defvar org-prefix-category-max-length nil
5741 "Used by `org-compile-prefix-format' to remember the category field width.")
5743 (defun org-agenda-get-category-icon (category)
5744 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
5745 (dolist (entry org-agenda-category-icon-alist)
5746 (when (org-string-match-p (car entry) category)
5747 (if (listp (cadr entry))
5748 (return (cadr entry))
5749 (return (apply 'create-image (cdr entry)))))))
5751 (defun org-agenda-format-item (extra txt &optional category tags dotime
5752 remove-re habitp)
5753 "Format TXT to be inserted into the agenda buffer.
5754 In particular, it adds the prefix and corresponding text properties. EXTRA
5755 must be a string and replaces the `%s' specifier in the prefix format.
5756 CATEGORY (string, symbol or nil) may be used to overrule the default
5757 category taken from local variable or file name. It will replace the `%c'
5758 specifier in the format. DOTIME, when non-nil, indicates that a
5759 time-of-day should be extracted from TXT for sorting of this entry, and for
5760 the `%t' specifier in the format. When DOTIME is a string, this string is
5761 searched for a time before TXT is. TAGS can be the tags of the headline.
5762 Any match of REMOVE-RE will be removed from TXT."
5763 ;; We keep the org-prefix-* variable values along with a compiled
5764 ;; formatter, so that multiple agendas existing at the same time, do
5765 ;; not step on each other toes.
5767 ;; It was inconvenient to make these variables buffer local in
5768 ;; Agenda buffers, because this function expects to be called with
5769 ;; the buffer where item comes from being current, and not agenda
5770 ;; buffer
5771 (let* ((bindings (car org-prefix-format-compiled))
5772 (formatter (cadr org-prefix-format-compiled)))
5773 (loop for (var value) in bindings
5774 do (set var value))
5775 (save-match-data
5776 ;; Diary entries sometimes have extra whitespace at the beginning
5777 (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
5779 ;; Fix the tags part in txt
5780 (setq txt (org-agenda-fix-displayed-tags
5781 txt tags
5782 org-agenda-show-inherited-tags
5783 org-agenda-hide-tags-regexp))
5784 (let* ((category (or category
5785 (if (stringp org-category)
5786 org-category
5787 (and org-category (symbol-name org-category)))
5788 (if buffer-file-name
5789 (file-name-sans-extension
5790 (file-name-nondirectory buffer-file-name))
5791 "")))
5792 (category-icon (org-agenda-get-category-icon category))
5793 (category-icon (if category-icon
5794 (propertize " " 'display category-icon)
5795 ""))
5796 ;; time, tag, effort are needed for the eval of the prefix format
5797 (tag (if tags (nth (1- (length tags)) tags) ""))
5798 time effort neffort
5799 (ts (if dotime (concat
5800 (if (stringp dotime) dotime "")
5801 (and org-agenda-search-headline-for-time txt))))
5802 (time-of-day (and dotime (org-get-time-of-day ts)))
5803 stamp plain s0 s1 s2 rtn srp l
5804 duration thecategory)
5805 (and (derived-mode-p 'org-mode) buffer-file-name
5806 (add-to-list 'org-agenda-contributing-files buffer-file-name))
5807 (when (and dotime time-of-day)
5808 ;; Extract starting and ending time and move them to prefix
5809 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
5810 (setq plain (string-match org-plain-time-of-day-regexp ts)))
5811 (setq s0 (match-string 0 ts)
5812 srp (and stamp (match-end 3))
5813 s1 (match-string (if plain 1 2) ts)
5814 s2 (match-string (if plain 8 (if srp 4 6)) ts))
5816 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
5817 ;; them, we might want to remove them there to avoid duplication.
5818 ;; The user can turn this off with a variable.
5819 (if (and org-prefix-has-time
5820 org-agenda-remove-times-when-in-prefix (or stamp plain)
5821 (string-match (concat (regexp-quote s0) " *") txt)
5822 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
5823 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
5824 (= (match-beginning 0) 0)
5826 (setq txt (replace-match "" nil nil txt))))
5827 ;; Normalize the time(s) to 24 hour
5828 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
5829 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
5831 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
5832 (when (and s1 (not s2) org-agenda-default-appointment-duration)
5833 (setq s2
5834 (org-minutes-to-hh:mm-string
5835 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
5837 ;; Compute the duration
5838 (when s2
5839 (setq duration (- (org-hh:mm-string-to-minutes s2)
5840 (org-hh:mm-string-to-minutes s1)))))
5842 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
5843 txt)
5844 ;; Tags are in the string
5845 (if (or (eq org-agenda-remove-tags t)
5846 (and org-agenda-remove-tags
5847 org-prefix-has-tag))
5848 (setq txt (replace-match "" t t txt))
5849 (setq txt (replace-match
5850 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
5851 (match-string 2 txt))
5852 t t txt))))
5853 (when (derived-mode-p 'org-mode)
5854 (setq effort
5855 (condition-case nil
5856 (org-get-effort
5857 (or (get-text-property 0 'org-hd-marker txt)
5858 (get-text-property 0 'org-marker txt)))
5859 (error nil)))
5860 (when effort
5861 (setq neffort (org-duration-string-to-minutes effort)
5862 effort (setq effort (concat "[" effort "]")))))
5863 ;; prevent erroring out with %e format when there is no effort
5864 (or effort (setq effort ""))
5866 (when remove-re
5867 (while (string-match remove-re txt)
5868 (setq txt (replace-match "" t t txt))))
5870 ;; Set org-heading property on `txt' to mark the start of the
5871 ;; heading.
5872 (add-text-properties 0 (length txt) '(org-heading t) txt)
5874 ;; Prepare the variables needed in the eval of the compiled format
5875 (setq time (cond (s2 (concat
5876 (org-agenda-time-of-day-to-ampm-maybe s1)
5877 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
5878 (if org-agenda-timegrid-use-ampm " ")))
5879 (s1 (concat
5880 (org-agenda-time-of-day-to-ampm-maybe s1)
5881 (if org-agenda-timegrid-use-ampm
5882 "........ "
5883 "......")))
5884 (t ""))
5885 extra (or (and (not habitp) extra) "")
5886 category (if (symbolp category) (symbol-name category) category)
5887 thecategory (copy-sequence category))
5888 (if (string-match org-bracket-link-regexp category)
5889 (progn
5890 (setq l (if (match-end 3)
5891 (- (match-end 3) (match-beginning 3))
5892 (- (match-end 1) (match-beginning 1))))
5893 (when (< l (or org-prefix-category-length 0))
5894 (setq category (copy-sequence category))
5895 (org-add-props category nil
5896 'extra-space (make-string
5897 (- org-prefix-category-length l 1) ?\ ))))
5898 (if (and org-prefix-category-max-length
5899 (>= (length category) org-prefix-category-max-length))
5900 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
5901 ;; Evaluate the compiled format
5902 (setq rtn (concat (eval formatter) txt))
5904 ;; And finally add the text properties
5905 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
5906 (org-add-props rtn nil
5907 'org-category (if thecategory (downcase thecategory) category)
5908 'tags (mapcar 'org-downcase-keep-props tags)
5909 'org-highest-priority org-highest-priority
5910 'org-lowest-priority org-lowest-priority
5911 'time-of-day time-of-day
5912 'duration duration
5913 'effort effort
5914 'effort-minutes neffort
5915 'txt txt
5916 'time time
5917 'extra extra
5918 'format org-prefix-format-compiled
5919 'dotime dotime)))))
5921 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
5922 "Remove tags string from TXT, and add a modified list of tags.
5923 The modified list may contain inherited tags, and tags matched by
5924 `org-agenda-hide-tags-regexp' will be removed."
5925 (when (or add-inherited hide-re)
5926 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
5927 (setq txt (substring txt 0 (match-beginning 0))))
5928 (setq tags
5929 (delq nil
5930 (mapcar (lambda (tg)
5931 (if (or (and hide-re (string-match hide-re tg))
5932 (and (not add-inherited)
5933 (get-text-property 0 'inherited tg)))
5935 tg))
5936 tags)))
5937 (when tags
5938 (let ((have-i (get-text-property 0 'inherited (car tags)))
5940 (setq txt (concat txt " :"
5941 (mapconcat
5942 (lambda (x)
5943 (setq i (get-text-property 0 'inherited x))
5944 (if (and have-i (not i))
5945 (progn
5946 (setq have-i nil)
5947 (concat ":" x))
5949 tags ":")
5950 (if have-i "::" ":"))))))
5951 txt)
5953 (defun org-downcase-keep-props (s)
5954 (let ((props (text-properties-at 0 s)))
5955 (setq s (downcase s))
5956 (add-text-properties 0 (length s) props s)
5959 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
5960 (defvar org-agenda-sorting-strategy-selected nil)
5962 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
5963 (catch 'exit
5964 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
5965 ((and todayp (member 'today (car org-agenda-time-grid))))
5966 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
5967 ((member 'weekly (car org-agenda-time-grid)))
5968 (t (throw 'exit list)))
5969 (let* ((have (delq nil (mapcar
5970 (lambda (x) (get-text-property 1 'time-of-day x))
5971 list)))
5972 (string (nth 1 org-agenda-time-grid))
5973 (gridtimes (nth 2 org-agenda-time-grid))
5974 (req (car org-agenda-time-grid))
5975 (remove (member 'remove-match req))
5976 new time)
5977 (if (and (member 'require-timed req) (not have))
5978 ;; don't show empty grid
5979 (throw 'exit list))
5980 (while (setq time (pop gridtimes))
5981 (unless (and remove (member time have))
5982 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
5983 (push (org-agenda-format-item
5984 nil string "" nil
5985 (concat (substring time 0 -2) ":" (substring time -2)))
5986 new)
5987 (put-text-property
5988 2 (length (car new)) 'face 'org-time-grid (car new))))
5989 (when (and todayp org-agenda-show-current-time-in-grid)
5990 (push (org-agenda-format-item
5992 org-agenda-current-time-string
5993 "" nil
5994 (format-time-string "%H:%M "))
5995 new)
5996 (put-text-property
5997 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
5999 (if (member 'time-up org-agenda-sorting-strategy-selected)
6000 (append new list)
6001 (append list new)))))
6003 (defun org-compile-prefix-format (key)
6004 "Compile the prefix format into a Lisp form that can be evaluated.
6005 The resulting form and associated variable bindings is returned
6006 and stored in the variable `org-prefix-format-compiled'."
6007 (setq org-prefix-has-time nil org-prefix-has-tag nil
6008 org-prefix-category-length nil
6009 org-prefix-has-effort nil)
6010 (let ((s (cond
6011 ((stringp org-agenda-prefix-format)
6012 org-agenda-prefix-format)
6013 ((assq key org-agenda-prefix-format)
6014 (cdr (assq key org-agenda-prefix-format)))
6015 (t " %-12:c%?-12t% s")))
6016 (start 0)
6017 varform vars var e c f opt)
6018 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
6019 s start)
6020 (setq var (or (cdr (assoc (match-string 4 s)
6021 '(("c" . category) ("t" . time) ("s" . extra)
6022 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6023 'eval)
6024 c (or (match-string 3 s) "")
6025 opt (match-beginning 1)
6026 start (1+ (match-beginning 0)))
6027 (if (equal var 'time) (setq org-prefix-has-time t))
6028 (if (equal var 'tag) (setq org-prefix-has-tag t))
6029 (if (equal var 'effort) (setq org-prefix-has-effort t))
6030 (setq f (concat "%" (match-string 2 s) "s"))
6031 (when (equal var 'category)
6032 (setq org-prefix-category-length
6033 (floor (abs (string-to-number (match-string 2 s)))))
6034 (setq org-prefix-category-max-length
6035 (let ((x (match-string 2 s)))
6036 (save-match-data
6037 (if (string-match "\\.[0-9]+" x)
6038 (string-to-number (substring (match-string 0 x) 1)))))))
6039 (if (eq var 'eval)
6040 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6041 (if opt
6042 (setq varform
6043 `(if (equal "" ,var)
6045 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6046 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6047 (setq s (replace-match "%s" t nil s))
6048 (push varform vars))
6049 (setq vars (nreverse vars))
6050 (with-current-buffer org-agenda-buffer
6051 (setq org-prefix-format-compiled
6052 (list
6053 `((org-prefix-has-time ,org-prefix-has-time)
6054 (org-prefix-has-tag ,org-prefix-has-tag)
6055 (org-prefix-category-length ,org-prefix-category-length)
6056 (org-prefix-has-effort ,org-prefix-has-effort))
6057 `(format ,s ,@vars))))))
6059 (defun org-set-sorting-strategy (key)
6060 (if (symbolp (car org-agenda-sorting-strategy))
6061 ;; the old format
6062 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6063 (setq org-agenda-sorting-strategy-selected
6064 (or (cdr (assq key org-agenda-sorting-strategy))
6065 (cdr (assq 'agenda org-agenda-sorting-strategy))
6066 '(time-up category-keep priority-down)))))
6068 (defun org-get-time-of-day (s &optional string mod24)
6069 "Check string S for a time of day.
6070 If found, return it as a military time number between 0 and 2400.
6071 If not found, return nil.
6072 The optional STRING argument forces conversion into a 5 character wide string
6073 HH:MM."
6074 (save-match-data
6075 (when
6076 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6077 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6078 (let* ((h (string-to-number (match-string 1 s)))
6079 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6080 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6081 (am-p (equal ampm "am"))
6082 (h1 (cond ((not ampm) h)
6083 ((= h 12) (if am-p 0 12))
6084 (t (+ h (if am-p 0 12)))))
6085 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6086 (mod h1 24) h1))
6087 (t0 (+ (* 100 h2) m))
6088 (t1 (concat (if (>= h1 24) "+" " ")
6089 (if (and org-agenda-time-leading-zero
6090 (< t0 1000)) "0" "")
6091 (if (< t0 100) "0" "")
6092 (if (< t0 10) "0" "")
6093 (int-to-string t0))))
6094 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6096 (defvar org-agenda-before-sorting-filter-function nil
6097 "Function to be applied to agenda items prior to sorting.
6098 Prior to sorting also means just before they are inserted into the agenda.
6100 To aid sorting, you may revisit the original entries and add more text
6101 properties which will later be used by the sorting functions.
6103 The function should take a string argument, an agenda line.
6104 It has access to the text properties in that line, which contain among
6105 other things, the property `org-hd-marker' that points to the entry
6106 where the line comes from. Note that not all lines going into the agenda
6107 have this property, only most.
6109 The function should return the modified string. It is probably best
6110 to ONLY change text properties.
6112 You can also use this function as a filter, by returning nil for lines
6113 you don't want to have in the agenda at all. For this application, you
6114 could bind the variable in the options section of a custom command.")
6116 (defun org-finalize-agenda-entries (list &optional nosort)
6117 "Sort and concatenate the agenda items."
6118 (setq list (mapcar 'org-agenda-highlight-todo list))
6119 (if nosort
6120 list
6121 (when org-agenda-before-sorting-filter-function
6122 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6123 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6125 (defun org-agenda-highlight-todo (x)
6126 (let ((org-done-keywords org-done-keywords-for-agenda)
6127 (case-fold-search nil)
6129 (if (eq x 'line)
6130 (save-excursion
6131 (beginning-of-line 1)
6132 (setq re (org-get-at-bol 'org-todo-regexp))
6133 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6134 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6135 (add-text-properties (match-beginning 0) (match-end 1)
6136 (list 'face (org-get-todo-face 1)))
6137 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6138 (delete-region (match-beginning 1) (1- (match-end 0)))
6139 (goto-char (match-beginning 1))
6140 (insert (format org-agenda-todo-keyword-format s)))))
6141 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6142 (setq re (get-text-property 0 'org-todo-regexp x))
6143 (when (and re
6144 ;; Test `pl' because if there's no heading content,
6145 ;; there's no point matching to highlight. Note
6146 ;; that if we didn't test `pl' first, and there
6147 ;; happened to be no keyword from `org-todo-regexp'
6148 ;; on this heading line, then the `equal' comparison
6149 ;; afterwards would spuriously succeed in the case
6150 ;; where `pl' is nil -- causing an args-out-of-range
6151 ;; error when we try to add text properties to text
6152 ;; that isn't there.
6154 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6155 x pl) pl))
6156 (add-text-properties
6157 (or (match-end 1) (match-end 0)) (match-end 0)
6158 (list 'face (org-get-todo-face (match-string 2 x)))
6160 (when (match-end 1)
6161 (setq x (concat (substring x 0 (match-end 1))
6162 (format org-agenda-todo-keyword-format
6163 (match-string 2 x))
6164 (org-add-props " " (text-properties-at 0 x))
6165 (substring x (match-end 3)))))))
6166 x)))
6168 (defsubst org-cmp-priority (a b)
6169 "Compare the priorities of string A and B."
6170 (let ((pa (or (get-text-property 1 'priority a) 0))
6171 (pb (or (get-text-property 1 'priority b) 0)))
6172 (cond ((> pa pb) +1)
6173 ((< pa pb) -1)
6174 (t nil))))
6176 (defsubst org-cmp-effort (a b)
6177 "Compare the effort values of string A and B."
6178 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6179 (ea (or (get-text-property 1 'effort-minutes a) def))
6180 (eb (or (get-text-property 1 'effort-minutes b) def)))
6181 (cond ((> ea eb) +1)
6182 ((< ea eb) -1)
6183 (t nil))))
6185 (defsubst org-cmp-category (a b)
6186 "Compare the string values of categories of strings A and B."
6187 (let ((ca (or (get-text-property 1 'org-category a) ""))
6188 (cb (or (get-text-property 1 'org-category b) "")))
6189 (cond ((string-lessp ca cb) -1)
6190 ((string-lessp cb ca) +1)
6191 (t nil))))
6193 (defsubst org-cmp-todo-state (a b)
6194 "Compare the todo states of strings A and B."
6195 (let* ((ma (or (get-text-property 1 'org-marker a)
6196 (get-text-property 1 'org-hd-marker a)))
6197 (mb (or (get-text-property 1 'org-marker b)
6198 (get-text-property 1 'org-hd-marker b)))
6199 (fa (and ma (marker-buffer ma)))
6200 (fb (and mb (marker-buffer mb)))
6201 (todo-kwds
6202 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6203 (and fb (with-current-buffer fb org-todo-keywords-1))))
6204 (ta (or (get-text-property 1 'todo-state a) ""))
6205 (tb (or (get-text-property 1 'todo-state b) ""))
6206 (la (- (length (member ta todo-kwds))))
6207 (lb (- (length (member tb todo-kwds))))
6208 (donepa (member ta org-done-keywords-for-agenda))
6209 (donepb (member tb org-done-keywords-for-agenda)))
6210 (cond ((and donepa (not donepb)) -1)
6211 ((and (not donepa) donepb) +1)
6212 ((< la lb) -1)
6213 ((< lb la) +1)
6214 (t nil))))
6216 (defsubst org-cmp-alpha (a b)
6217 "Compare the headlines, alphabetically."
6218 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6219 (plb (text-property-any 0 (length b) 'org-heading t b))
6220 (ta (and pla (substring a pla)))
6221 (tb (and plb (substring b plb))))
6222 (when pla
6223 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6224 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6225 (setq ta (substring ta (match-end 0))))
6226 (setq ta (downcase ta)))
6227 (when plb
6228 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6229 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6230 (setq tb (substring tb (match-end 0))))
6231 (setq tb (downcase tb)))
6232 (cond ((not ta) +1)
6233 ((not tb) -1)
6234 ((string-lessp ta tb) -1)
6235 ((string-lessp tb ta) +1)
6236 (t nil))))
6238 (defsubst org-cmp-tag (a b)
6239 "Compare the string values of the first tags of A and B."
6240 (let ((ta (car (last (get-text-property 1 'tags a))))
6241 (tb (car (last (get-text-property 1 'tags b)))))
6242 (cond ((not ta) +1)
6243 ((not tb) -1)
6244 ((string-lessp ta tb) -1)
6245 ((string-lessp tb ta) +1)
6246 (t nil))))
6248 (defsubst org-cmp-time (a b)
6249 "Compare the time-of-day values of strings A and B."
6250 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6251 (ta (or (get-text-property 1 'time-of-day a) def))
6252 (tb (or (get-text-property 1 'time-of-day b) def)))
6253 (cond ((< ta tb) -1)
6254 ((< tb ta) +1)
6255 (t nil))))
6257 (defsubst org-cmp-habit-p (a b)
6258 "Compare the todo states of strings A and B."
6259 (let ((ha (get-text-property 1 'org-habit-p a))
6260 (hb (get-text-property 1 'org-habit-p b)))
6261 (cond ((and ha (not hb)) -1)
6262 ((and (not ha) hb) +1)
6263 (t nil))))
6265 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6267 (defun org-entries-lessp (a b)
6268 "Predicate for sorting agenda entries."
6269 ;; The following variables will be used when the form is evaluated.
6270 ;; So even though the compiler complains, keep them.
6271 (let* ((ss org-agenda-sorting-strategy-selected)
6272 (time-up (and (org-em 'time-up 'time-down ss)
6273 (org-cmp-time a b)))
6274 (time-down (if time-up (- time-up) nil))
6275 (priority-up (and (org-em 'priority-up 'priority-down ss)
6276 (org-cmp-priority a b)))
6277 (priority-down (if priority-up (- priority-up) nil))
6278 (effort-up (and (org-em 'effort-up 'effort-down ss)
6279 (org-cmp-effort a b)))
6280 (effort-down (if effort-up (- effort-up) nil))
6281 (category-up (and (or (org-em 'category-up 'category-down ss)
6282 (memq 'category-keep ss))
6283 (org-cmp-category a b)))
6284 (category-down (if category-up (- category-up) nil))
6285 (category-keep (if category-up +1 nil))
6286 (tag-up (and (org-em 'tag-up 'tag-down ss)
6287 (org-cmp-tag a b)))
6288 (tag-down (if tag-up (- tag-up) nil))
6289 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6290 (org-cmp-todo-state a b)))
6291 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6292 (habit-up (and (org-em 'habit-up 'habit-down ss)
6293 (org-cmp-habit-p a b)))
6294 (habit-down (if habit-up (- habit-up) nil))
6295 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6296 (org-cmp-alpha a b)))
6297 (alpha-down (if alpha-up (- alpha-up) nil))
6298 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6299 user-defined-up user-defined-down)
6300 (if (and need-user-cmp org-agenda-cmp-user-defined
6301 (functionp org-agenda-cmp-user-defined))
6302 (setq user-defined-up
6303 (funcall org-agenda-cmp-user-defined a b)
6304 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6305 (cdr (assoc
6306 (eval (cons 'or org-agenda-sorting-strategy-selected))
6307 '((-1 . t) (1 . nil) (nil . nil))))))
6309 ;;; Agenda restriction lock
6311 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6312 "Overlay to mark the headline to which agenda commands are restricted.")
6313 (overlay-put org-agenda-restriction-lock-overlay
6314 'face 'org-agenda-restriction-lock)
6315 (overlay-put org-agenda-restriction-lock-overlay
6316 'help-echo "Agendas are currently limited to this subtree.")
6317 (org-detach-overlay org-agenda-restriction-lock-overlay)
6319 (defun org-agenda-set-restriction-lock (&optional type)
6320 "Set restriction lock for agenda, to current subtree or file.
6321 Restriction will be the file if TYPE is `file', or if type is the
6322 universal prefix '(4), or if the cursor is before the first headline
6323 in the file. Otherwise, restriction will be to the current subtree."
6324 (interactive "P")
6325 (and (equal type '(4)) (setq type 'file))
6326 (setq type (cond
6327 (type type)
6328 ((org-at-heading-p) 'subtree)
6329 ((condition-case nil (org-back-to-heading t) (error nil))
6330 'subtree)
6331 (t 'file)))
6332 (if (eq type 'subtree)
6333 (progn
6334 (setq org-agenda-restrict t)
6335 (setq org-agenda-overriding-restriction 'subtree)
6336 (put 'org-agenda-files 'org-restrict
6337 (list (buffer-file-name (buffer-base-buffer))))
6338 (org-back-to-heading t)
6339 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6340 (move-marker org-agenda-restrict-begin (point))
6341 (move-marker org-agenda-restrict-end
6342 (save-excursion (org-end-of-subtree t)))
6343 (message "Locking agenda restriction to subtree"))
6344 (put 'org-agenda-files 'org-restrict
6345 (list (buffer-file-name (buffer-base-buffer))))
6346 (setq org-agenda-restrict nil)
6347 (setq org-agenda-overriding-restriction 'file)
6348 (move-marker org-agenda-restrict-begin nil)
6349 (move-marker org-agenda-restrict-end nil)
6350 (message "Locking agenda restriction to file"))
6351 (setq current-prefix-arg nil)
6352 (org-agenda-maybe-redo))
6354 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6355 "Remove the agenda restriction lock."
6356 (interactive "P")
6357 (org-detach-overlay org-agenda-restriction-lock-overlay)
6358 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6359 (setq org-agenda-overriding-restriction nil)
6360 (setq org-agenda-restrict nil)
6361 (put 'org-agenda-files 'org-restrict nil)
6362 (move-marker org-agenda-restrict-begin nil)
6363 (move-marker org-agenda-restrict-end nil)
6364 (setq current-prefix-arg nil)
6365 (message "Agenda restriction lock removed")
6366 (or noupdate (org-agenda-maybe-redo)))
6368 (defun org-agenda-maybe-redo ()
6369 "If there is any window showing the agenda view, update it."
6370 (let ((w (get-buffer-window org-agenda-buffer-name t))
6371 (w0 (selected-window)))
6372 (when w
6373 (select-window w)
6374 (org-agenda-redo)
6375 (select-window w0)
6376 (if org-agenda-overriding-restriction
6377 (message "Agenda view shifted to new %s restriction"
6378 org-agenda-overriding-restriction)
6379 (message "Agenda restriction lock removed")))))
6381 ;;; Agenda commands
6383 (defun org-agenda-check-type (error &rest types)
6384 "Check if agenda buffer is of allowed type.
6385 If ERROR is non-nil, throw an error, otherwise just return nil."
6386 (if (not org-agenda-type)
6387 (error "No Org agenda currently displayed")
6388 (if (memq org-agenda-type types)
6390 (if error
6391 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6392 nil))))
6394 (defun org-agenda-Quit (&optional arg)
6395 "Exit agenda by removing the window or the buffer."
6396 (interactive)
6397 (if org-agenda-columns-active
6398 (org-columns-quit)
6399 (let ((buf (current-buffer)))
6400 (if (eq org-agenda-window-setup 'other-frame)
6401 (progn
6402 (org-agenda-reset-markers)
6403 (kill-buffer buf)
6404 (org-columns-remove-overlays)
6405 (setq org-agenda-archives-mode nil)
6406 (delete-frame))
6407 (and (not (eq org-agenda-window-setup 'current-window))
6408 (not (one-window-p))
6409 (delete-window))
6410 (org-agenda-reset-markers)
6411 (kill-buffer buf)
6412 (org-columns-remove-overlays)
6413 (setq org-agenda-archives-mode nil)))
6414 ;; Maybe restore the pre-agenda window configuration.
6415 (and org-agenda-restore-windows-after-quit
6416 (not (eq org-agenda-window-setup 'other-frame))
6417 org-pre-agenda-window-conf
6418 (set-window-configuration org-pre-agenda-window-conf))))
6420 (defun org-agenda-quit ()
6421 "Exit agenda by killing agenda buffer or burying it when
6422 `org-agenda-sticky' is non-NIL"
6423 (interactive)
6424 (if org-agenda-columns-active
6425 (org-columns-quit)
6426 (if org-agenda-sticky
6427 (let ((buf (current-buffer)))
6428 (if (eq org-agenda-window-setup 'other-frame)
6429 (progn
6430 (delete-frame))
6431 (and (not (eq org-agenda-window-setup 'current-window))
6432 (not (one-window-p))
6433 (delete-window)))
6434 (with-current-buffer buf
6435 (bury-buffer)
6436 ;; Maybe restore the pre-agenda window configuration.
6437 (and org-agenda-restore-windows-after-quit
6438 (not (eq org-agenda-window-setup 'other-frame))
6439 org-pre-agenda-window-conf
6440 (set-window-configuration org-pre-agenda-window-conf))))
6441 (org-agenda-Quit))))
6443 (defun org-agenda-exit ()
6444 "Exit agenda by removing the window or the buffer.
6445 Also kill all Org-mode buffers which have been loaded by `org-agenda'.
6446 Org-mode buffers visited directly by the user will not be touched."
6447 (interactive)
6448 (org-release-buffers org-agenda-new-buffers)
6449 (setq org-agenda-new-buffers nil)
6450 (org-agenda-Quit))
6452 (defun org-agenda-kill-all-agenda-buffers ()
6453 "Kill all buffers in `org-agena-mode'.
6454 This is used when toggling sticky agendas. You can also explicitly invoke it
6455 with `C-c a C-k'."
6456 (interactive)
6457 (let (blist)
6458 (dolist (buf (buffer-list))
6459 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6460 (push buf blist)))
6461 (mapc 'kill-buffer blist)))
6463 (defun org-agenda-execute (arg)
6464 "Execute another agenda command, keeping same window.
6465 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6466 in the agenda."
6467 (interactive "P")
6468 (let ((org-agenda-window-setup 'current-window))
6469 (org-agenda arg)))
6471 (defun org-agenda-redo ()
6472 "Rebuild Agenda.
6473 When this is the global TODO list, a prefix argument will be interpreted."
6474 (interactive)
6475 (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
6476 (org-agenda-sticky nil)
6477 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6478 org-agenda-buffer-name))
6479 (org-agenda-keep-modes t)
6480 (tag-filter org-agenda-tag-filter)
6481 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6482 (top-cat-filter org-agenda-top-category-filter)
6483 (cat-filter org-agenda-category-filter)
6484 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6485 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6486 (cols org-agenda-columns-active)
6487 (line (org-current-line))
6488 (window-line (- line (org-current-line (window-start))))
6489 (lprops (get 'org-agenda-redo-command 'org-lprops)))
6490 (put 'org-agenda-tag-filter :preset-filter nil)
6491 (put 'org-agenda-category-filter :preset-filter nil)
6492 (and cols (org-columns-quit))
6493 (message "Rebuilding agenda buffer...")
6494 (org-let lprops '(eval org-agenda-redo-command))
6495 (setq org-agenda-undo-list nil
6496 org-agenda-pending-undo-list nil)
6497 (message "Rebuilding agenda buffer...done")
6498 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6499 (put 'org-agenda-category-filter :preset-filter cat-preset)
6500 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6501 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6502 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6503 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6504 (org-goto-line line)
6505 (recenter window-line)))
6507 (defvar org-global-tags-completion-table nil)
6508 (defvar org-agenda-filter-form nil)
6509 (defvar org-agenda-filtered-by-category nil)
6511 (defun org-agenda-filter-by-category (strip)
6512 "Keep only those lines in the agenda buffer that have a specific category.
6513 The category is that of the current line."
6514 (interactive "P")
6515 (if org-agenda-filtered-by-category
6516 (org-agenda-filter-show-all-cat)
6517 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6518 (if cat (org-agenda-filter-apply
6519 (list (concat (if strip "-" "+") cat)) 'category)
6520 (error "No category at point")))))
6522 (defun org-find-top-category (&optional pos)
6523 (save-excursion
6524 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
6525 (if pos (goto-char pos))
6526 ;; Skip up to the topmost parent
6527 (while (ignore-errors (outline-up-heading 1) t))
6528 (ignore-errors
6529 (nth 4 (org-heading-components))))))
6531 (defvar org-agenda-filtered-by-top-category nil)
6533 (defun org-agenda-filter-by-top-category (strip)
6534 "Keep only those lines in the agenda buffer that have a specific category.
6535 The category is that of the current line."
6536 (interactive "P")
6537 (if org-agenda-filtered-by-top-category
6538 (progn
6539 (setq org-agenda-filtered-by-top-category nil
6540 org-agenda-top-category-filter nil)
6541 (org-agenda-filter-show-all-cat))
6542 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
6543 (if cat (org-agenda-filter-top-category-apply cat strip)
6544 (error "No top-level category at point")))))
6546 (defun org-agenda-filter-by-tag (strip &optional char narrow)
6547 "Keep only those lines in the agenda buffer that have a specific tag.
6548 The tag is selected with its fast selection letter, as configured.
6549 With prefix argument STRIP, remove all lines that do have the tag.
6550 A lisp caller can specify CHAR. NARROW means that the new tag should be
6551 used to narrow the search - the interactive user can also press `-' or `+'
6552 to switch to narrowing."
6553 (interactive "P")
6554 (let* ((alist org-tag-alist-for-agenda)
6555 (tag-chars (mapconcat
6556 (lambda (x) (if (and (not (symbolp (car x)))
6557 (cdr x))
6558 (char-to-string (cdr x))
6559 ""))
6560 alist ""))
6561 (efforts (org-split-string
6562 (or (cdr (assoc (concat org-effort-property "_ALL")
6563 org-global-properties))
6564 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
6565 "")))
6566 (effort-op org-agenda-filter-effort-default-operator)
6567 (effort-prompt "")
6568 (inhibit-read-only t)
6569 (current org-agenda-tag-filter)
6570 maybe-refresh a n tag)
6571 (unless char
6572 (message
6573 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
6574 (if narrow "Narrow" "Filter") tag-chars
6575 (if org-agenda-auto-exclude-function "[RET], " ""))
6576 (setq char (read-char-exclusive)))
6577 (when (member char '(?+ ?-))
6578 ;; Narrowing down
6579 (cond ((equal char ?-) (setq strip t narrow t))
6580 ((equal char ?+) (setq strip nil narrow t)))
6581 (message
6582 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
6583 (setq char (read-char-exclusive)))
6584 (when (member char '(?< ?> ?= ??))
6585 ;; An effort operator
6586 (setq effort-op (char-to-string char))
6587 (setq alist nil) ; to make sure it will be interpreted as effort.
6588 (unless (equal char ??)
6589 (loop for i from 0 to 9 do
6590 (setq effort-prompt
6591 (concat
6592 effort-prompt " ["
6593 (if (= i 9) "0" (int-to-string (1+ i)))
6594 "]" (nth i efforts))))
6595 (message "Effort%s: %s " effort-op effort-prompt)
6596 (setq char (read-char-exclusive))
6597 (when (or (< char ?0) (> char ?9))
6598 (error "Need 1-9,0 to select effort"))))
6599 (when (equal char ?\t)
6600 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
6601 (org-set-local 'org-global-tags-completion-table
6602 (org-global-tags-completion-table)))
6603 (let ((completion-ignore-case t))
6604 (setq tag (org-icompleting-read
6605 "Tag: " org-global-tags-completion-table))))
6606 (cond
6607 ((equal char ?\r)
6608 (org-agenda-filter-show-all-tag)
6609 (when org-agenda-auto-exclude-function
6610 (setq org-agenda-tag-filter '())
6611 (dolist (tag (org-agenda-get-represented-tags))
6612 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
6613 (if modifier
6614 (push modifier org-agenda-tag-filter))))
6615 (if (not (null org-agenda-tag-filter))
6616 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
6617 (setq maybe-refresh t))
6618 ((equal char ?/)
6619 (org-agenda-filter-show-all-tag)
6620 (when (get 'org-agenda-tag-filter :preset-filter)
6621 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
6622 (setq maybe-refresh t))
6623 ((equal char ?. )
6624 (setq org-agenda-tag-filter
6625 (mapcar (lambda(tag) (concat "+" tag))
6626 (org-get-at-bol 'tags)))
6627 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6628 (setq maybe-refresh t))
6629 ((or (equal char ?\ )
6630 (setq a (rassoc char alist))
6631 (and (>= char ?0) (<= char ?9)
6632 (setq n (if (= char ?0) 9 (- char ?0 1))
6633 tag (concat effort-op (nth n efforts))
6634 a (cons tag nil)))
6635 (and (= char ??)
6636 (setq tag "?eff")
6637 a (cons tag nil))
6638 (and tag (setq a (cons tag nil))))
6639 (org-agenda-filter-show-all-tag)
6640 (setq tag (car a))
6641 (setq org-agenda-tag-filter
6642 (cons (concat (if strip "-" "+") tag)
6643 (if narrow current nil)))
6644 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
6645 (setq maybe-refresh t))
6646 (t (error "Invalid tag selection character %c" char)))
6647 (when (and maybe-refresh
6648 (eq org-agenda-clockreport-mode 'with-filter))
6649 (org-agenda-redo))))
6651 (defun org-agenda-get-represented-tags ()
6652 "Get a list of all tags currently represented in the agenda."
6653 (let (p tags)
6654 (save-excursion
6655 (goto-char (point-min))
6656 (while (setq p (next-single-property-change (point) 'tags))
6657 (goto-char p)
6658 (mapc (lambda (x) (add-to-list 'tags x))
6659 (get-text-property (point) 'tags))))
6660 tags))
6662 (defun org-agenda-filter-by-tag-refine (strip &optional char)
6663 "Refine the current filter. See `org-agenda-filter-by-tag'."
6664 (interactive "P")
6665 (org-agenda-filter-by-tag strip char 'refine))
6667 (defun org-agenda-filter-make-matcher ()
6668 "Create the form that tests a line for agenda filter."
6669 (let (f f1)
6670 ;; first compute the tag-filter matcher
6671 (dolist (x (delete-dups
6672 (append (get 'org-agenda-tag-filter
6673 :preset-filter) org-agenda-tag-filter)))
6674 (if (member x '("-" "+"))
6675 (setq f1 (if (equal x "-") 'tags '(not tags)))
6676 (if (string-match "[<=>?]" x)
6677 (setq f1 (org-agenda-filter-effort-form x))
6678 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
6679 (if (equal (string-to-char x) ?-)
6680 (setq f1 (list 'not f1))))
6681 (push f1 f))
6682 ;; then compute the category-filter matcher
6683 (dolist (x (delete-dups
6684 (append (get 'org-agenda-category-filter
6685 :preset-filter) org-agenda-category-filter)))
6686 (if (equal "-" (substring x 0 1))
6687 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
6688 (setq f1 (list 'equal (substring x 1) 'cat)))
6689 (push f1 f))
6690 (cons 'and (nreverse f))))
6692 (defun org-agenda-filter-effort-form (e)
6693 "Return the form to compare the effort of the current line with what E says.
6694 E looks like \"+<2:25\"."
6695 (let (op)
6696 (setq e (substring e 1))
6697 (setq op (string-to-char e) e (substring e 1))
6698 (setq op (cond ((equal op ?<) '<=)
6699 ((equal op ?>) '>=)
6700 ((equal op ??) op)
6701 (t '=)))
6702 (list 'org-agenda-compare-effort (list 'quote op)
6703 (org-duration-string-to-minutes e))))
6705 (defun org-agenda-compare-effort (op value)
6706 "Compare the effort of the current line with VALUE, using OP.
6707 If the line does not have an effort defined, return nil."
6708 (let ((eff (org-get-at-bol 'effort-minutes)))
6709 (if (equal op ??)
6710 (not eff)
6711 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
6712 value))))
6714 (defun org-agenda-filter-apply (filter type)
6715 "Set FILTER as the new agenda filter and apply it."
6716 (let (tags cat)
6717 (if (eq type 'tag)
6718 (setq org-agenda-tag-filter filter)
6719 (setq org-agenda-category-filter filter))
6720 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
6721 (if (and (eq type 'category)
6722 (not (equal (substring (car filter) 0 1) "-")))
6723 ;; Only set `org-agenda-filtered-by-category' to t
6724 ;; when a unique category is used as the filter
6725 (setq org-agenda-filtered-by-category t))
6726 (org-agenda-set-mode-name)
6727 (save-excursion
6728 (goto-char (point-min))
6729 (while (not (eobp))
6730 (if (org-get-at-bol 'org-marker)
6731 (progn
6732 (setq tags (org-get-at-bol 'tags) ; used in eval
6733 cat (get-text-property (point) 'org-category))
6734 (if (not (eval org-agenda-filter-form))
6735 (org-agenda-filter-hide-line type))
6736 (beginning-of-line 2))
6737 (beginning-of-line 2))))
6738 (if (get-char-property (point) 'invisible)
6739 (ignore-errors (org-agenda-previous-line)))))
6741 (defun org-agenda-filter-top-category-apply (category &optional negative)
6742 "Set FILTER as the new agenda filter and apply it."
6743 (org-agenda-set-mode-name)
6744 (save-excursion
6745 (goto-char (point-min))
6746 (while (not (eobp))
6747 (let* ((pos (org-get-at-bol 'org-hd-marker))
6748 (topcat (and pos (org-find-top-category pos))))
6749 (if (and topcat (funcall (if negative 'identity 'not)
6750 (string= category topcat)))
6751 (org-agenda-filter-hide-line 'category)))
6752 (beginning-of-line 2)))
6753 (if (get-char-property (point) 'invisible)
6754 (org-agenda-previous-line))
6755 (setq org-agenda-top-category-filter category
6756 org-agenda-filtered-by-top-category t))
6758 (defun org-agenda-filter-hide-line (type)
6759 (let (ov)
6760 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
6761 (point-at-eol)))
6762 (overlay-put ov 'invisible t)
6763 (overlay-put ov 'type type)
6764 (if (eq type 'tag)
6765 (push ov org-agenda-tag-filter-overlays)
6766 (push ov org-agenda-cat-filter-overlays))))
6768 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
6769 (setq pos (or pos (point)))
6770 (save-excursion
6771 (dolist (ov (overlays-at pos))
6772 (when (and (overlay-get ov 'invisible)
6773 (eq (overlay-get ov 'type) 'tag))
6774 (goto-char pos)
6775 (if (< (overlay-start ov) (point-at-eol))
6776 (move-overlay ov (point-at-eol)
6777 (overlay-end ov)))))))
6779 (defun org-agenda-filter-show-all-tag nil
6780 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
6781 (setq org-agenda-tag-filter-overlays nil
6782 org-agenda-tag-filter nil
6783 org-agenda-filter-form nil)
6784 (org-agenda-set-mode-name))
6786 (defun org-agenda-filter-show-all-cat nil
6787 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
6788 (setq org-agenda-cat-filter-overlays nil
6789 org-agenda-filtered-by-category nil
6790 org-agenda-category-filter nil
6791 org-agenda-filter-form nil)
6792 (org-agenda-set-mode-name))
6794 (defun org-agenda-manipulate-query-add ()
6795 "Manipulate the query by adding a search term with positive selection.
6796 Positive selection means the term must be matched for selection of an entry."
6797 (interactive)
6798 (org-agenda-manipulate-query ?\[))
6799 (defun org-agenda-manipulate-query-subtract ()
6800 "Manipulate the query by adding a search term with negative selection.
6801 Negative selection means term must not be matched for selection of an entry."
6802 (interactive)
6803 (org-agenda-manipulate-query ?\]))
6804 (defun org-agenda-manipulate-query-add-re ()
6805 "Manipulate the query by adding a search regexp with positive selection.
6806 Positive selection means the regexp must match for selection of an entry."
6807 (interactive)
6808 (org-agenda-manipulate-query ?\{))
6809 (defun org-agenda-manipulate-query-subtract-re ()
6810 "Manipulate the query by adding a search regexp with negative selection.
6811 Negative selection means regexp must not match for selection of an entry."
6812 (interactive)
6813 (org-agenda-manipulate-query ?\}))
6814 (defun org-agenda-manipulate-query (char)
6815 (cond
6816 ((memq org-agenda-type '(timeline agenda))
6817 (let ((org-agenda-include-inactive-timestamps t))
6818 (org-agenda-redo))
6819 (message "Display now includes inactive timestamps as well"))
6820 ((eq org-agenda-type 'search)
6821 (org-add-to-string
6822 'org-agenda-query-string
6823 (if org-agenda-last-search-view-search-was-boolean
6824 (cdr (assoc char '((?\[ . " +") (?\] . " -")
6825 (?\{ . " +{}") (?\} . " -{}"))))
6826 " "))
6827 (setq org-agenda-redo-command
6828 (list 'org-search-view
6829 org-todo-only
6830 org-agenda-query-string
6831 (+ (length org-agenda-query-string)
6832 (if (member char '(?\{ ?\})) 0 1))))
6833 (set-register org-agenda-query-register org-agenda-query-string)
6834 (org-agenda-redo))
6835 (t (error "Cannot manipulate query for %s-type agenda buffers"
6836 org-agenda-type))))
6838 (defun org-add-to-string (var string)
6839 (set var (concat (symbol-value var) string)))
6841 (defun org-agenda-goto-date (date)
6842 "Jump to DATE in agenda."
6843 (interactive (list (let ((org-read-date-prefer-future
6844 (eval org-agenda-jump-prefer-future)))
6845 (org-read-date))))
6846 (org-agenda-list nil date))
6848 (defun org-agenda-goto-today ()
6849 "Go to today."
6850 (interactive)
6851 (org-agenda-check-type t 'timeline 'agenda)
6852 (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
6853 (cond
6854 (tdpos (goto-char tdpos))
6855 ((eq org-agenda-type 'agenda)
6856 (let* ((sd (org-agenda-compute-starting-span
6857 (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
6858 (org-agenda-overriding-arguments org-agenda-last-arguments))
6859 (setf (nth 1 org-agenda-overriding-arguments) sd)
6860 (org-agenda-redo)
6861 (org-agenda-find-same-or-today-or-agenda)))
6862 (t (error "Cannot find today")))))
6864 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
6865 (goto-char
6866 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
6867 (text-property-any (point-min) (point-max) 'org-today t)
6868 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
6869 (point-min))))
6871 (defun org-agenda-later (arg)
6872 "Go forward in time by thee current span.
6873 With prefix ARG, go forward that many times the current span."
6874 (interactive "p")
6875 (org-agenda-check-type t 'agenda)
6876 (let* ((span org-agenda-current-span)
6877 (sd org-starting-day)
6878 (greg (calendar-gregorian-from-absolute sd))
6879 (cnt (org-get-at-bol 'org-day-cnt))
6880 greg2)
6881 (cond
6882 ((eq span 'day)
6883 (setq sd (+ arg sd)))
6884 ((eq span 'week)
6885 (setq sd (+ (* 7 arg) sd)))
6886 ((eq span 'month)
6887 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
6888 sd (calendar-absolute-from-gregorian greg2))
6889 (setcar greg2 (1+ (car greg2))))
6890 ((eq span 'year)
6891 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
6892 sd (calendar-absolute-from-gregorian greg2))
6893 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
6895 (setq sd (+ (* span arg) sd))))
6896 (let ((org-agenda-overriding-arguments
6897 (list (car org-agenda-last-arguments) sd span t)))
6898 (org-agenda-redo)
6899 (org-agenda-find-same-or-today-or-agenda cnt))))
6901 (defun org-agenda-earlier (arg)
6902 "Go backward in time by the current span.
6903 With prefix ARG, go backward that many times the current span."
6904 (interactive "p")
6905 (org-agenda-later (- arg)))
6907 (defun org-agenda-view-mode-dispatch ()
6908 "Call one of the view mode commands."
6909 (interactive)
6910 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
6911 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
6912 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
6913 (let ((a (read-char-exclusive)))
6914 (case a
6915 (?\ (call-interactively 'org-agenda-reset-view))
6916 (?d (call-interactively 'org-agenda-day-view))
6917 (?w (call-interactively 'org-agenda-week-view))
6918 (?m (call-interactively 'org-agenda-month-view))
6919 (?y (call-interactively 'org-agenda-year-view))
6920 (?l (call-interactively 'org-agenda-log-mode))
6921 (?L (org-agenda-log-mode '(4)))
6922 (?c (org-agenda-log-mode 'clockcheck))
6923 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
6924 (?a (call-interactively 'org-agenda-archives-mode))
6925 (?A (org-agenda-archives-mode 'files))
6926 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
6927 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
6928 (?G (call-interactively 'org-agenda-toggle-time-grid))
6929 (?D (call-interactively 'org-agenda-toggle-diary))
6930 (?\! (call-interactively 'org-agenda-toggle-deadlines))
6931 (?\[ (let ((org-agenda-include-inactive-timestamps t))
6932 (org-agenda-check-type t 'timeline 'agenda)
6933 (org-agenda-redo))
6934 (message "Display now includes inactive timestamps as well"))
6935 (?q (message "Abort"))
6936 (otherwise (error "Invalid key" )))))
6938 (defun org-agenda-reset-view ()
6939 "Switch to default view for agenda."
6940 (interactive)
6941 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
6942 (defun org-agenda-day-view (&optional day-of-year)
6943 "Switch to daily view for agenda.
6944 With argument DAY-OF-YEAR, switch to that day of the year."
6945 (interactive "P")
6946 (org-agenda-change-time-span 'day day-of-year))
6947 (defun org-agenda-week-view (&optional iso-week)
6948 "Switch to daily view for agenda.
6949 With argument ISO-WEEK, switch to the corresponding ISO week.
6950 If ISO-WEEK has more then 2 digits, only the last two encode the
6951 week. Any digits before this encode a year. So 200712 means
6952 week 12 of year 2007. Years in the range 1938-2037 can also be
6953 written as 2-digit years."
6954 (interactive "P")
6955 (org-agenda-change-time-span 'week iso-week))
6956 (defun org-agenda-month-view (&optional month)
6957 "Switch to monthly view for agenda.
6958 With argument MONTH, switch to that month."
6959 (interactive "P")
6960 (org-agenda-change-time-span 'month month))
6961 (defun org-agenda-year-view (&optional year)
6962 "Switch to yearly view for agenda.
6963 With argument YEAR, switch to that year.
6964 If MONTH has more then 2 digits, only the last two encode the
6965 month. Any digits before this encode a year. So 200712 means
6966 December year 2007. Years in the range 1938-2037 can also be
6967 written as 2-digit years."
6968 (interactive "P")
6969 (when year
6970 (setq year (org-small-year-to-year year)))
6971 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
6972 (org-agenda-change-time-span 'year year)
6973 (error "Abort")))
6975 (defun org-agenda-change-time-span (span &optional n)
6976 "Change the agenda view to SPAN.
6977 SPAN may be `day', `week', `month', `year'."
6978 (org-agenda-check-type t 'agenda)
6979 (if (and (not n) (equal org-agenda-current-span span))
6980 (error "Viewing span is already \"%s\"" span))
6981 (let* ((sd (or (org-get-at-bol 'day)
6982 org-starting-day))
6983 (sd (org-agenda-compute-starting-span sd span n))
6984 (org-agenda-overriding-arguments
6985 (or org-agenda-overriding-arguments
6986 (list (car org-agenda-last-arguments) sd span t))))
6987 (org-agenda-redo)
6988 (org-agenda-find-same-or-today-or-agenda))
6989 (org-agenda-set-mode-name)
6990 (message "Switched to %s view" span))
6992 (defun org-agenda-compute-starting-span (sd span &optional n)
6993 "Compute starting date for agenda.
6994 SPAN may be `day', `week', `month', `year'. The return value
6995 is a cons cell with the starting date and the number of days,
6996 so that the date SD will be in that range."
6997 (let* ((greg (calendar-gregorian-from-absolute sd))
6998 (dg (nth 1 greg))
6999 (mg (car greg))
7000 (yg (nth 2 greg)))
7001 (cond
7002 ((eq span 'day)
7003 (when n
7004 (setq sd (+ (calendar-absolute-from-gregorian
7005 (list mg 1 yg))
7006 n -1))))
7007 ((eq span 'week)
7008 (let* ((nt (calendar-day-of-week
7009 (calendar-gregorian-from-absolute sd)))
7010 (d (if org-agenda-start-on-weekday
7011 (- nt org-agenda-start-on-weekday)
7014 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7015 (when n
7016 (require 'cal-iso)
7017 (when (> n 99)
7018 (setq y1 (org-small-year-to-year (/ n 100))
7019 n (mod n 100)))
7020 (setq sd
7021 (calendar-absolute-from-iso
7022 (list n 1
7023 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7024 ((eq span 'month)
7025 (let (y1)
7026 (when (and n (> n 99))
7027 (setq y1 (org-small-year-to-year (/ n 100))
7028 n (mod n 100)))
7029 (setq sd (calendar-absolute-from-gregorian
7030 (list (or n mg) 1 (or y1 yg))))))
7031 ((eq span 'year)
7032 (setq sd (calendar-absolute-from-gregorian
7033 (list 1 1 (or n yg))))))
7034 sd))
7036 (defun org-agenda-next-date-line (&optional arg)
7037 "Jump to the next line indicating a date in agenda buffer."
7038 (interactive "p")
7039 (org-agenda-check-type t 'agenda 'timeline)
7040 (beginning-of-line 1)
7041 ;; This does not work if user makes date format that starts with a blank
7042 (if (looking-at "^\\S-") (forward-char 1))
7043 (if (not (re-search-forward "^\\S-" nil t arg))
7044 (progn
7045 (backward-char 1)
7046 (error "No next date after this line in this buffer")))
7047 (goto-char (match-beginning 0)))
7049 (defun org-agenda-previous-date-line (&optional arg)
7050 "Jump to the previous line indicating a date in agenda buffer."
7051 (interactive "p")
7052 (org-agenda-check-type t 'agenda 'timeline)
7053 (beginning-of-line 1)
7054 (if (not (re-search-backward "^\\S-" nil t arg))
7055 (error "No previous date before this line in this buffer")))
7057 ;; Initialize the highlight
7058 (defvar org-hl (make-overlay 1 1))
7059 (overlay-put org-hl 'face 'highlight)
7061 (defun org-highlight (begin end &optional buffer)
7062 "Highlight a region with overlay."
7063 (move-overlay org-hl begin end (or buffer (current-buffer))))
7065 (defun org-unhighlight ()
7066 "Detach overlay INDEX."
7067 (org-detach-overlay org-hl))
7069 ;; FIXME this is currently not used.
7070 (defun org-highlight-until-next-command (beg end &optional buffer)
7071 "Move the highlight overlay to BEG/END, remove it before the next command."
7072 (org-highlight beg end buffer)
7073 (add-hook 'pre-command-hook 'org-unhighlight-once))
7074 (defun org-unhighlight-once ()
7075 "Remove the highlight from its position, and this function from the hook."
7076 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7077 (org-unhighlight))
7079 (defun org-agenda-follow-mode ()
7080 "Toggle follow mode in an agenda buffer."
7081 (interactive)
7082 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7083 (org-agenda-set-mode-name)
7084 (org-agenda-do-context-action)
7085 (message "Follow mode is %s"
7086 (if org-agenda-follow-mode "on" "off")))
7088 (defun org-agenda-entry-text-mode (&optional arg)
7089 "Toggle entry text mode in an agenda buffer."
7090 (interactive "P")
7091 (setq org-agenda-entry-text-mode (or (integerp arg)
7092 (not org-agenda-entry-text-mode)))
7093 (org-agenda-entry-text-hide)
7094 (and org-agenda-entry-text-mode
7095 (let ((org-agenda-entry-text-maxlines
7096 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7097 (org-agenda-entry-text-show)))
7098 (org-agenda-set-mode-name)
7099 (message "Entry text mode is %s. Maximum number of lines is %d"
7100 (if org-agenda-entry-text-mode "on" "off")
7101 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7103 (defun org-agenda-clockreport-mode (&optional with-filter)
7104 "Toggle clocktable mode in an agenda buffer.
7105 With prefix arg WITH-FILTER, make the clocktable respect the current
7106 agenda filter."
7107 (interactive "P")
7108 (org-agenda-check-type t 'agenda)
7109 (if with-filter
7110 (setq org-agenda-clockreport-mode 'with-filter)
7111 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7112 (org-agenda-set-mode-name)
7113 (org-agenda-redo)
7114 (message "Clocktable mode is %s"
7115 (if org-agenda-clockreport-mode "on" "off")))
7117 (defun org-agenda-log-mode (&optional special)
7118 "Toggle log mode in an agenda buffer.
7119 With argument SPECIAL, show all possible log items, not only the ones
7120 configured in `org-agenda-log-mode-items'.
7121 With a double `C-u' prefix arg, show *only* log items, nothing else."
7122 (interactive "P")
7123 (org-agenda-check-type t 'agenda 'timeline)
7124 (setq org-agenda-show-log
7125 (cond
7126 ((equal special '(16)) 'only)
7127 ((eq special 'clockcheck)
7128 (if (eq org-agenda-show-log 'clockcheck)
7129 nil 'clockcheck))
7130 (special '(closed clock state))
7131 (t (not org-agenda-show-log))))
7132 (org-agenda-set-mode-name)
7133 (org-agenda-redo)
7134 (message "Log mode is %s"
7135 (if org-agenda-show-log "on" "off")))
7137 (defun org-agenda-archives-mode (&optional with-files)
7138 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7139 When called with a prefix argument, include all archive files as well."
7140 (interactive "P")
7141 (setq org-agenda-archives-mode
7142 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7143 (org-agenda-set-mode-name)
7144 (org-agenda-redo)
7145 (message
7146 "%s"
7147 (cond
7148 ((eq org-agenda-archives-mode nil)
7149 "No archives are included")
7150 ((eq org-agenda-archives-mode 'trees)
7151 (format "Trees with :%s: tag are included" org-archive-tag))
7152 ((eq org-agenda-archives-mode t)
7153 (format "Trees with :%s: tag and all active archive files are included"
7154 org-archive-tag)))))
7156 (defun org-agenda-toggle-diary ()
7157 "Toggle diary inclusion in an agenda buffer."
7158 (interactive)
7159 (org-agenda-check-type t 'agenda)
7160 (setq org-agenda-include-diary (not org-agenda-include-diary))
7161 (org-agenda-redo)
7162 (org-agenda-set-mode-name)
7163 (message "Diary inclusion turned %s"
7164 (if org-agenda-include-diary "on" "off")))
7166 (defun org-agenda-toggle-deadlines ()
7167 "Toggle inclusion of entries with a deadline in an agenda buffer."
7168 (interactive)
7169 (org-agenda-check-type t 'agenda)
7170 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7171 (org-agenda-redo)
7172 (org-agenda-set-mode-name)
7173 (message "Deadlines inclusion turned %s"
7174 (if org-agenda-include-deadlines "on" "off")))
7176 (defun org-agenda-toggle-time-grid ()
7177 "Toggle time grid in an agenda buffer."
7178 (interactive)
7179 (org-agenda-check-type t 'agenda)
7180 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7181 (org-agenda-redo)
7182 (org-agenda-set-mode-name)
7183 (message "Time-grid turned %s"
7184 (if org-agenda-use-time-grid "on" "off")))
7186 (defun org-agenda-set-mode-name ()
7187 "Set the mode name to indicate all the small mode settings."
7188 (setq mode-name
7189 (list "Org-Agenda"
7190 (if (get 'org-agenda-files 'org-restrict) " []" "")
7192 '(:eval (org-agenda-span-name org-agenda-current-span))
7193 (if org-agenda-follow-mode " Follow" "")
7194 (if org-agenda-entry-text-mode " ETxt" "")
7195 (if org-agenda-include-diary " Diary" "")
7196 (if org-agenda-include-deadlines " Ddl" "")
7197 (if org-agenda-use-time-grid " Grid" "")
7198 (if (and (boundp 'org-habit-show-habits)
7199 org-habit-show-habits) " Habit" "")
7200 (cond
7201 ((consp org-agenda-show-log) " LogAll")
7202 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7203 (org-agenda-show-log " Log")
7204 (t ""))
7205 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7206 :preset-filter))
7207 '(:eval (org-propertize
7208 (concat " <"
7209 (mapconcat
7210 'identity
7211 (append
7212 (get 'org-agenda-category-filter :preset-filter)
7213 org-agenda-category-filter)
7215 ">")
7216 'face 'org-agenda-filter-category
7217 'help-echo "Category used in filtering"))
7219 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7220 :preset-filter))
7221 '(:eval (org-propertize
7222 (concat " {"
7223 (mapconcat
7224 'identity
7225 (append
7226 (get 'org-agenda-tag-filter :preset-filter)
7227 org-agenda-tag-filter)
7229 "}")
7230 'face 'org-agenda-filter-tags
7231 'help-echo "Tags used in filtering"))
7233 (if org-agenda-archives-mode
7234 (if (eq org-agenda-archives-mode t)
7235 " Archives"
7236 (format " :%s:" org-archive-tag))
7238 (if org-agenda-clockreport-mode
7239 (if (eq org-agenda-clockreport-mode 'with-filter)
7240 " Clock{}" " Clock")
7241 "")))
7242 (force-mode-line-update))
7244 (defun org-agenda-post-command-hook ()
7245 (setq org-agenda-type
7246 (or (get-text-property (point) 'org-agenda-type)
7247 (get-text-property (max (point-min) (1- (point)))
7248 'org-agenda-type))))
7250 (defun org-agenda-next-line ()
7251 "Move cursor to the next line, and show if follow mode is active."
7252 (interactive)
7253 (call-interactively 'next-line)
7254 (org-agenda-do-context-action))
7256 (defun org-agenda-previous-line ()
7257 "Move cursor to the previous line, and show if follow-mode is active."
7258 (interactive)
7259 (call-interactively 'previous-line)
7260 (org-agenda-do-context-action))
7262 (defun org-agenda-next-item (n)
7263 "Move cursor to next agenda item."
7264 (interactive "p")
7265 (let ((col (current-column)))
7266 (dotimes (c n)
7267 (when (next-single-property-change (point-at-eol) 'org-marker)
7268 (move-end-of-line 1)
7269 (goto-char (next-single-property-change (point) 'org-marker))))
7270 (org-move-to-column col))
7271 (org-agenda-do-context-action))
7273 (defun org-agenda-previous-item (n)
7274 "Move cursor to next agenda item."
7275 (interactive "p")
7276 (dotimes (c n)
7277 (let ((col (current-column))
7278 (goto (save-excursion
7279 (move-end-of-line 0)
7280 (previous-single-property-change (point) 'org-marker))))
7281 (if goto (goto-char goto))
7282 (org-move-to-column col)))
7283 (org-agenda-do-context-action))
7285 (defun org-agenda-do-context-action ()
7286 "Show outline path and, maybe, follow mode window."
7287 (let ((m (org-get-at-bol 'org-marker)))
7288 (when (and (markerp m) (marker-buffer m))
7289 (and org-agenda-follow-mode
7290 (if org-agenda-follow-indirect
7291 (org-agenda-tree-to-indirect-buffer)
7292 (org-agenda-show)))
7293 (and org-agenda-show-outline-path
7294 (org-with-point-at m (org-display-outline-path t))))))
7296 (defun org-agenda-show-priority ()
7297 "Show the priority of the current item.
7298 This priority is composed of the main priority given with the [#A] cookies,
7299 and by additional input from the age of a schedules or deadline entry."
7300 (interactive)
7301 (let* ((pri (org-get-at-bol 'priority)))
7302 (message "Priority is %d" (if pri pri -1000))))
7304 (defun org-agenda-show-tags ()
7305 "Show the tags applicable to the current item."
7306 (interactive)
7307 (let* ((tags (org-get-at-bol 'tags)))
7308 (if tags
7309 (message "Tags are :%s:"
7310 (org-no-properties (mapconcat 'identity tags ":")))
7311 (message "No tags associated with this line"))))
7313 (defun org-agenda-goto (&optional highlight)
7314 "Go to the Org-mode file which contains the item at point."
7315 (interactive)
7316 (let* ((marker (or (org-get-at-bol 'org-marker)
7317 (org-agenda-error)))
7318 (buffer (marker-buffer marker))
7319 (pos (marker-position marker)))
7320 (switch-to-buffer-other-window buffer)
7321 (widen)
7322 (push-mark)
7323 (goto-char pos)
7324 (when (derived-mode-p 'org-mode)
7325 (org-show-context 'agenda)
7326 (save-excursion
7327 (and (outline-next-heading)
7328 (org-flag-heading nil)))) ; show the next heading
7329 (when (outline-invisible-p)
7330 (show-entry)) ; display invisible text
7331 (recenter (/ (window-height) 2))
7332 (run-hooks 'org-agenda-after-show-hook)
7333 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7335 (defvar org-agenda-after-show-hook nil
7336 "Normal hook run after an item has been shown from the agenda.
7337 Point is in the buffer where the item originated.")
7339 (defun org-agenda-kill ()
7340 "Kill the entry or subtree belonging to the current agenda entry."
7341 (interactive)
7342 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7343 (let* ((marker (or (org-get-at-bol 'org-marker)
7344 (org-agenda-error)))
7345 (buffer (marker-buffer marker))
7346 (pos (marker-position marker))
7347 (type (org-get-at-bol 'type))
7348 dbeg dend (n 0) conf)
7349 (org-with-remote-undo buffer
7350 (with-current-buffer buffer
7351 (save-excursion
7352 (goto-char pos)
7353 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7354 (setq dbeg (progn (org-back-to-heading t) (point))
7355 dend (org-end-of-subtree t t))
7356 (setq dbeg (point-at-bol)
7357 dend (min (point-max) (1+ (point-at-eol)))))
7358 (goto-char dbeg)
7359 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7360 (setq conf (or (eq t org-agenda-confirm-kill)
7361 (and (numberp org-agenda-confirm-kill)
7362 (> n org-agenda-confirm-kill))))
7363 (and conf
7364 (not (y-or-n-p
7365 (format "Delete entry with %d lines in buffer \"%s\"? "
7366 n (buffer-name buffer))))
7367 (error "Abort"))
7368 (org-remove-subtree-entries-from-agenda buffer dbeg dend)
7369 (with-current-buffer buffer (delete-region dbeg dend))
7370 (message "Agenda item and source killed"))))
7372 (defvar org-archive-default-command)
7373 (defun org-agenda-archive-default ()
7374 "Archive the entry or subtree belonging to the current agenda entry."
7375 (interactive)
7376 (require 'org-archive)
7377 (org-agenda-archive-with org-archive-default-command))
7379 (defun org-agenda-archive-default-with-confirmation ()
7380 "Archive the entry or subtree belonging to the current agenda entry."
7381 (interactive)
7382 (require 'org-archive)
7383 (org-agenda-archive-with org-archive-default-command 'confirm))
7385 (defun org-agenda-archive ()
7386 "Archive the entry or subtree belonging to the current agenda entry."
7387 (interactive)
7388 (org-agenda-archive-with 'org-archive-subtree))
7390 (defun org-agenda-archive-to-archive-sibling ()
7391 "Move the entry to the archive sibling."
7392 (interactive)
7393 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7395 (defun org-agenda-archive-with (cmd &optional confirm)
7396 "Move the entry to the archive sibling."
7397 (interactive)
7398 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7399 (let* ((marker (or (org-get-at-bol 'org-marker)
7400 (org-agenda-error)))
7401 (buffer (marker-buffer marker))
7402 (pos (marker-position marker)))
7403 (org-with-remote-undo buffer
7404 (with-current-buffer buffer
7405 (if (derived-mode-p 'org-mode)
7406 (if (and confirm
7407 (not (y-or-n-p "Archive this subtree or entry? ")))
7408 (error "Abort")
7409 (save-excursion
7410 (goto-char pos)
7411 (org-remove-subtree-entries-from-agenda)
7412 (org-back-to-heading t)
7413 (funcall cmd)))
7414 (error "Archiving works only in Org-mode files"))))))
7416 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7417 "Remove all lines in the agenda that correspond to a given subtree.
7418 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7419 If this information is not given, the function uses the tree at point."
7420 (let ((buf (or buf (current-buffer))) m p)
7421 (save-excursion
7422 (unless (and beg end)
7423 (org-back-to-heading t)
7424 (setq beg (point))
7425 (org-end-of-subtree t)
7426 (setq end (point)))
7427 (set-buffer (get-buffer org-agenda-buffer-name))
7428 (save-excursion
7429 (goto-char (point-max))
7430 (beginning-of-line 1)
7431 (while (not (bobp))
7432 (when (and (setq m (org-get-at-bol 'org-marker))
7433 (equal buf (marker-buffer m))
7434 (setq p (marker-position m))
7435 (>= p beg)
7436 (< p end))
7437 (let ((inhibit-read-only t))
7438 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7439 (beginning-of-line 0))))))
7441 (defun org-agenda-refile (&optional goto rfloc no-update)
7442 "Refile the item at point."
7443 (interactive "P")
7444 (if (equal goto '(16))
7445 (org-refile-goto-last-stored)
7446 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7447 (org-agenda-error)))
7448 (buffer (marker-buffer marker))
7449 (pos (marker-position marker))
7450 (rfloc (or rfloc
7451 (org-refile-get-location
7452 (if goto "Goto" "Refile to") buffer
7453 org-refile-allow-creating-parent-nodes))))
7454 (with-current-buffer buffer
7455 (save-excursion
7456 (save-restriction
7457 (widen)
7458 (goto-char marker)
7459 (org-remove-subtree-entries-from-agenda)
7460 (org-refile goto buffer rfloc)))))
7461 (unless no-update (org-agenda-redo))))
7463 (defun org-agenda-open-link (&optional arg)
7464 "Follow the link in the current line, if any.
7465 This looks for a link in the displayed line in the agenda. It also looks
7466 at the text of the entry itself."
7467 (interactive "P")
7468 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
7469 (org-get-at-bol 'org-marker)))
7470 (buffer (and marker (marker-buffer marker)))
7471 (prefix (buffer-substring
7472 (point-at-bol) (point-at-eol))))
7473 (cond
7474 (buffer
7475 (with-current-buffer buffer
7476 (save-excursion
7477 (save-restriction
7478 (widen)
7479 (goto-char marker)
7480 (org-offer-links-in-entry arg prefix)))))
7481 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
7482 (save-excursion
7483 (beginning-of-line 1)
7484 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
7485 (org-open-link-from-string (match-string 1)))
7486 (t (error "No link to open here")))))
7488 (defun org-agenda-copy-local-variable (var)
7489 "Get a variable from a referenced buffer and install it here."
7490 (let ((m (org-get-at-bol 'org-marker)))
7491 (when (and m (buffer-live-p (marker-buffer m)))
7492 (org-set-local var (with-current-buffer (marker-buffer m)
7493 (symbol-value var))))))
7495 (defun org-agenda-switch-to (&optional delete-other-windows)
7496 "Go to the Org-mode file which contains the item at point."
7497 (interactive)
7498 (if (and org-return-follows-link
7499 (not (org-get-at-bol 'org-marker))
7500 (org-in-regexp org-bracket-link-regexp))
7501 (org-open-link-from-string (match-string 0))
7502 (let* ((marker (or (org-get-at-bol 'org-marker)
7503 (org-agenda-error)))
7504 (buffer (marker-buffer marker))
7505 (pos (marker-position marker)))
7506 (org-pop-to-buffer-same-window buffer)
7507 (and delete-other-windows (delete-other-windows))
7508 (widen)
7509 (goto-char pos)
7510 (when (derived-mode-p 'org-mode)
7511 (org-show-context 'agenda)
7512 (save-excursion
7513 (and (outline-next-heading)
7514 (org-flag-heading nil))) ; show the next heading
7515 (when (outline-invisible-p)
7516 (show-entry)) ; display invisible text
7517 (run-hooks 'org-agenda-after-show-hook)))))
7519 (defun org-agenda-goto-mouse (ev)
7520 "Go to the Org-mode file which contains the item at the mouse click."
7521 (interactive "e")
7522 (mouse-set-point ev)
7523 (org-agenda-goto))
7525 (defun org-agenda-show (&optional full-entry)
7526 "Display the Org-mode file which contains the item at point.
7527 With prefix argument FULL-ENTRY, make the entire entry visible
7528 if it was hidden in the outline."
7529 (interactive "P")
7530 (let ((win (selected-window)))
7531 (if full-entry
7532 (let ((org-show-entry-below t))
7533 (org-agenda-goto t))
7534 (org-agenda-goto t))
7535 (select-window win)))
7537 (defvar org-agenda-show-window nil)
7538 (defun org-agenda-show-and-scroll-up (&optional arg)
7539 "Display the Org-mode file which contains the item at point.
7540 When called repeatedly, scroll the window that is displaying the buffer.
7541 With a \\[universal-argument] prefix, use `org-show-entry' instead of
7542 `show-subtree' to display the item, so that drawers and logbooks stay
7543 folded."
7544 (interactive "P")
7545 (let ((win (selected-window)))
7546 (if (and (window-live-p org-agenda-show-window)
7547 (eq this-command last-command))
7548 (progn
7549 (select-window org-agenda-show-window)
7550 (ignore-errors (scroll-up)))
7551 (org-agenda-goto t)
7552 (if arg (org-show-entry) (show-subtree))
7553 (setq org-agenda-show-window (selected-window)))
7554 (select-window win)))
7556 (defun org-agenda-show-scroll-down ()
7557 "Scroll down the window showing the agenda."
7558 (interactive)
7559 (let ((win (selected-window)))
7560 (when (window-live-p org-agenda-show-window)
7561 (select-window org-agenda-show-window)
7562 (ignore-errors (scroll-down))
7563 (select-window win))))
7565 (defun org-agenda-show-1 (&optional more)
7566 "Display the Org-mode file which contains the item at point.
7567 The prefix arg selects the amount of information to display:
7569 0 hide the subtree
7570 1 just show the entry according to defaults.
7571 2 show the children view
7572 3 show the subtree view
7573 4 show the entire subtree and any LOGBOOK drawers
7574 5 show the entire subtree and any drawers
7575 With prefix argument FULL-ENTRY, make the entire entry visible
7576 if it was hidden in the outline."
7577 (interactive "p")
7578 (let ((win (selected-window)))
7579 (org-agenda-goto t)
7580 (org-recenter-heading 1)
7581 (cond
7582 ((= more 0)
7583 (hide-subtree)
7584 (save-excursion
7585 (org-back-to-heading)
7586 (run-hook-with-args 'org-cycle-hook 'folded))
7587 (message "Remote: FOLDED"))
7588 ((and (org-called-interactively-p 'any) (= more 1))
7589 (message "Remote: show with default settings"))
7590 ((= more 2)
7591 (show-entry)
7592 (show-children)
7593 (save-excursion
7594 (org-back-to-heading)
7595 (run-hook-with-args 'org-cycle-hook 'children))
7596 (message "Remote: CHILDREN"))
7597 ((= more 3)
7598 (show-subtree)
7599 (save-excursion
7600 (org-back-to-heading)
7601 (run-hook-with-args 'org-cycle-hook 'subtree))
7602 (message "Remote: SUBTREE"))
7603 ((= more 4)
7604 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
7605 (org-drawer-regexp
7606 (concat "^[ \t]*:\\("
7607 (mapconcat 'regexp-quote org-drawers "\\|")
7608 "\\):[ \t]*$")))
7609 (show-subtree)
7610 (save-excursion
7611 (org-back-to-heading)
7612 (org-cycle-hide-drawers 'subtree)))
7613 (message "Remote: SUBTREE AND LOGBOOK"))
7614 ((> more 4)
7615 (show-subtree)
7616 (message "Remote: SUBTREE AND ALL DRAWERS")))
7617 (select-window win)))
7619 (defun org-recenter-heading (n)
7620 (save-excursion
7621 (org-back-to-heading)
7622 (recenter n)))
7624 (defvar org-agenda-cycle-counter nil)
7625 (defun org-agenda-cycle-show (&optional n)
7626 "Show the current entry in another window, with default settings.
7627 Default settings are taken from `org-show-hierarchy-above' and siblings.
7628 When use repeatedly in immediate succession, the remote entry will cycle
7629 through visibility
7631 children -> subtree -> folded
7633 When called with a numeric prefix arg, that arg will be passed through to
7634 `org-agenda-show-1'. For the interpretation of that argument, see the
7635 docstring of `org-agenda-show-1'."
7636 (interactive "P")
7637 (if (integerp n)
7638 (setq org-agenda-cycle-counter n)
7639 (if (not (eq last-command this-command))
7640 (setq org-agenda-cycle-counter 1)
7641 (if (equal org-agenda-cycle-counter 0)
7642 (setq org-agenda-cycle-counter 2)
7643 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
7644 (if (> org-agenda-cycle-counter 3)
7645 (setq org-agenda-cycle-counter 0)))))
7646 (org-agenda-show-1 org-agenda-cycle-counter))
7648 (defun org-agenda-recenter (arg)
7649 "Display the Org-mode file which contains the item at point and recenter."
7650 (interactive "P")
7651 (let ((win (selected-window)))
7652 (org-agenda-goto t)
7653 (recenter arg)
7654 (select-window win)))
7656 (defun org-agenda-show-mouse (ev)
7657 "Display the Org-mode file which contains the item at the mouse click."
7658 (interactive "e")
7659 (mouse-set-point ev)
7660 (org-agenda-show))
7662 (defun org-agenda-check-no-diary ()
7663 "Check if the entry is a diary link and abort if yes."
7664 (if (org-get-at-bol 'org-agenda-diary-link)
7665 (org-agenda-error)))
7667 (defun org-agenda-error ()
7668 (error "Command not allowed in this line"))
7670 (defun org-agenda-tree-to-indirect-buffer ()
7671 "Show the subtree corresponding to the current entry in an indirect buffer.
7672 This calls the command `org-tree-to-indirect-buffer' from the original
7673 Org-mode buffer.
7674 With numerical prefix arg ARG, go up to this level and then take that tree.
7675 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
7676 use the dedicated frame)."
7677 (interactive)
7678 (if (and current-prefix-arg (listp current-prefix-arg))
7679 (org-agenda-do-tree-to-indirect-buffer)
7680 (let ((agenda-window (selected-window))
7681 (indirect-window
7682 (and org-last-indirect-buffer
7683 (get-buffer-window org-last-indirect-buffer))))
7684 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
7685 (unwind-protect
7686 (progn
7687 (unless (and indirect-window (window-live-p indirect-window))
7688 (setq indirect-window (split-window agenda-window)))
7689 (select-window indirect-window)
7690 (switch-to-buffer org-last-indirect-buffer :norecord)
7691 (fit-window-to-buffer indirect-window))
7692 (select-window (get-buffer-window org-agenda-buffer-name))))))
7694 (defun org-agenda-do-tree-to-indirect-buffer ()
7695 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
7696 (org-agenda-check-no-diary)
7697 (let* ((marker (or (org-get-at-bol 'org-marker)
7698 (org-agenda-error)))
7699 (buffer (marker-buffer marker))
7700 (pos (marker-position marker)))
7701 (with-current-buffer buffer
7702 (save-excursion
7703 (goto-char pos)
7704 (call-interactively 'org-tree-to-indirect-buffer)))))
7706 (defvar org-last-heading-marker (make-marker)
7707 "Marker pointing to the headline that last changed its TODO state
7708 by a remote command from the agenda.")
7710 (defun org-agenda-todo-nextset ()
7711 "Switch TODO entry to next sequence."
7712 (interactive)
7713 (org-agenda-todo 'nextset))
7715 (defun org-agenda-todo-previousset ()
7716 "Switch TODO entry to previous sequence."
7717 (interactive)
7718 (org-agenda-todo 'previousset))
7720 (defun org-agenda-todo (&optional arg)
7721 "Cycle TODO state of line at point, also in Org-mode file.
7722 This changes the line at point, all other lines in the agenda referring to
7723 the same tree node, and the headline of the tree node in the Org-mode file."
7724 (interactive "P")
7725 (org-agenda-check-no-diary)
7726 (let* ((col (current-column))
7727 (marker (or (org-get-at-bol 'org-marker)
7728 (org-agenda-error)))
7729 (buffer (marker-buffer marker))
7730 (pos (marker-position marker))
7731 (hdmarker (org-get-at-bol 'org-hd-marker))
7732 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
7733 (inhibit-read-only t)
7734 org-agenda-headline-snapshot-before-repeat newhead just-one)
7735 (org-with-remote-undo buffer
7736 (with-current-buffer buffer
7737 (widen)
7738 (goto-char pos)
7739 (org-show-context 'agenda)
7740 (save-excursion
7741 (and (outline-next-heading)
7742 (org-flag-heading nil))) ; show the next heading
7743 (let ((current-prefix-arg arg))
7744 (call-interactively 'org-todo))
7745 (and (bolp) (forward-char 1))
7746 (setq newhead (org-get-heading))
7747 (when (and (org-bound-and-true-p
7748 org-agenda-headline-snapshot-before-repeat)
7749 (not (equal org-agenda-headline-snapshot-before-repeat
7750 newhead))
7751 todayp)
7752 (setq newhead org-agenda-headline-snapshot-before-repeat
7753 just-one t))
7754 (save-excursion
7755 (org-back-to-heading)
7756 (move-marker org-last-heading-marker (point))))
7757 (beginning-of-line 1)
7758 (save-excursion
7759 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
7760 (org-move-to-column col))))
7762 (defun org-agenda-add-note (&optional arg)
7763 "Add a time-stamped note to the entry at point."
7764 (interactive "P")
7765 (org-agenda-check-no-diary)
7766 (let* ((marker (or (org-get-at-bol 'org-marker)
7767 (org-agenda-error)))
7768 (buffer (marker-buffer marker))
7769 (pos (marker-position marker))
7770 (hdmarker (org-get-at-bol 'org-hd-marker))
7771 (inhibit-read-only t))
7772 (with-current-buffer buffer
7773 (widen)
7774 (goto-char pos)
7775 (org-show-context 'agenda)
7776 (save-excursion
7777 (and (outline-next-heading)
7778 (org-flag-heading nil))) ; show the next heading
7779 (org-add-note))))
7781 (defun org-agenda-change-all-lines (newhead hdmarker
7782 &optional fixface just-this)
7783 "Change all lines in the agenda buffer which match HDMARKER.
7784 The new content of the line will be NEWHEAD (as modified by
7785 `org-agenda-format-item'). HDMARKER is checked with
7786 `equal' against all `org-hd-marker' text properties in the file.
7787 If FIXFACE is non-nil, the face of each item is modified according to
7788 the new TODO state.
7789 If JUST-THIS is non-nil, change just the current line, not all.
7790 If FORCE-TAGS is non nil, the car of it returns the new tags."
7791 (let* ((inhibit-read-only t)
7792 (line (org-current-line))
7793 (org-agenda-buffer (current-buffer))
7794 (thetags (with-current-buffer (marker-buffer hdmarker)
7795 (save-excursion (save-restriction (widen)
7796 (goto-char hdmarker)
7797 (org-get-tags-at)))))
7798 props m pl undone-face done-face finish new dotime cat tags)
7799 (save-excursion
7800 (goto-char (point-max))
7801 (beginning-of-line 1)
7802 (while (not finish)
7803 (setq finish (bobp))
7804 (when (and (setq m (org-get-at-bol 'org-hd-marker))
7805 (or (not just-this) (= (org-current-line) line))
7806 (equal m hdmarker))
7807 (setq props (text-properties-at (point))
7808 dotime (org-get-at-bol 'dotime)
7809 cat (org-get-at-bol 'org-category)
7810 tags thetags
7812 (let ((org-prefix-format-compiled
7813 (or (get-text-property (point) 'format)
7814 org-prefix-format-compiled))
7815 (extra (org-get-at-bol 'extra)))
7816 (with-current-buffer (marker-buffer hdmarker)
7817 (save-excursion
7818 (save-restriction
7819 (widen)
7820 (org-agenda-format-item extra newhead cat tags dotime)))))
7821 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
7822 undone-face (org-get-at-bol 'undone-face)
7823 done-face (org-get-at-bol 'done-face))
7824 (beginning-of-line 1)
7825 (cond
7826 ((equal new "")
7827 (and (looking-at ".*\n?") (replace-match "")))
7828 ((looking-at ".*")
7829 (replace-match new t t)
7830 (beginning-of-line 1)
7831 (add-text-properties (point-at-bol) (point-at-eol) props)
7832 (when fixface
7833 (add-text-properties
7834 (point-at-bol) (point-at-eol)
7835 (list 'face
7836 (if org-last-todo-state-is-todo
7837 undone-face done-face))))
7838 (org-agenda-highlight-todo 'line)
7839 (beginning-of-line 1))
7840 (t (error "Line update did not work"))))
7841 (beginning-of-line 0)))
7842 (org-finalize-agenda)))
7844 (defun org-agenda-align-tags (&optional line)
7845 "Align all tags in agenda items to `org-agenda-tags-column'."
7846 (let ((inhibit-read-only t) l c)
7847 (save-excursion
7848 (goto-char (if line (point-at-bol) (point-min)))
7849 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
7850 (if line (point-at-eol) nil) t)
7851 (add-text-properties
7852 (match-beginning 2) (match-end 2)
7853 (list 'face (delq nil (let ((prop (get-text-property
7854 (match-beginning 2) 'face)))
7855 (or (listp prop) (setq prop (list prop)))
7856 (if (memq 'org-tag prop)
7857 prop
7858 (cons 'org-tag prop))))))
7859 (setq l (- (match-end 2) (match-beginning 2))
7860 c (if (< org-agenda-tags-column 0)
7861 (- (abs org-agenda-tags-column) l)
7862 org-agenda-tags-column))
7863 (delete-region (match-beginning 1) (match-end 1))
7864 (goto-char (match-beginning 1))
7865 (insert (org-add-props
7866 (make-string (max 1 (- c (current-column))) ?\ )
7867 (plist-put (copy-sequence (text-properties-at (point)))
7868 'face nil))))
7869 (goto-char (point-min))
7870 (org-font-lock-add-tag-faces (point-max)))))
7872 (defun org-agenda-priority-up ()
7873 "Increase the priority of line at point, also in Org-mode file."
7874 (interactive)
7875 (org-agenda-priority 'up))
7877 (defun org-agenda-priority-down ()
7878 "Decrease the priority of line at point, also in Org-mode file."
7879 (interactive)
7880 (org-agenda-priority 'down))
7882 (defun org-agenda-priority (&optional force-direction)
7883 "Set the priority of line at point, also in Org-mode file.
7884 This changes the line at point, all other lines in the agenda referring to
7885 the same tree node, and the headline of the tree node in the Org-mode file."
7886 (interactive)
7887 (unless org-enable-priority-commands
7888 (error "Priority commands are disabled"))
7889 (org-agenda-check-no-diary)
7890 (let* ((marker (or (org-get-at-bol 'org-marker)
7891 (org-agenda-error)))
7892 (hdmarker (org-get-at-bol 'org-hd-marker))
7893 (buffer (marker-buffer hdmarker))
7894 (pos (marker-position hdmarker))
7895 (inhibit-read-only t)
7896 newhead)
7897 (org-with-remote-undo buffer
7898 (with-current-buffer buffer
7899 (widen)
7900 (goto-char pos)
7901 (org-show-context 'agenda)
7902 (save-excursion
7903 (and (outline-next-heading)
7904 (org-flag-heading nil))) ; show the next heading
7905 (funcall 'org-priority force-direction)
7906 (end-of-line 1)
7907 (setq newhead (org-get-heading)))
7908 (org-agenda-change-all-lines newhead hdmarker)
7909 (beginning-of-line 1))))
7911 ;; FIXME: should fix the tags property of the agenda line.
7912 (defun org-agenda-set-tags (&optional tag onoff)
7913 "Set tags for the current headline."
7914 (interactive)
7915 (org-agenda-check-no-diary)
7916 (if (and (org-region-active-p) (org-called-interactively-p 'any))
7917 (call-interactively 'org-change-tag-in-region)
7918 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7919 (org-agenda-error)))
7920 (buffer (marker-buffer hdmarker))
7921 (pos (marker-position hdmarker))
7922 (inhibit-read-only t)
7923 newhead)
7924 (org-with-remote-undo buffer
7925 (with-current-buffer buffer
7926 (widen)
7927 (goto-char pos)
7928 (save-excursion
7929 (org-show-context 'agenda))
7930 (save-excursion
7931 (and (outline-next-heading)
7932 (org-flag-heading nil))) ; show the next heading
7933 (goto-char pos)
7934 (if tag
7935 (org-toggle-tag tag onoff)
7936 (call-interactively 'org-set-tags))
7937 (end-of-line 1)
7938 (setq newhead (org-get-heading)))
7939 (org-agenda-change-all-lines newhead hdmarker)
7940 (beginning-of-line 1)))))
7942 (defun org-agenda-set-property ()
7943 "Set a property for the current headline."
7944 (interactive)
7945 (org-agenda-check-no-diary)
7946 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7947 (org-agenda-error)))
7948 (buffer (marker-buffer hdmarker))
7949 (pos (marker-position hdmarker))
7950 (inhibit-read-only t)
7951 newhead)
7952 (org-with-remote-undo buffer
7953 (with-current-buffer buffer
7954 (widen)
7955 (goto-char pos)
7956 (save-excursion
7957 (org-show-context 'agenda))
7958 (save-excursion
7959 (and (outline-next-heading)
7960 (org-flag-heading nil))) ; show the next heading
7961 (goto-char pos)
7962 (call-interactively 'org-set-property)))))
7964 (defun org-agenda-set-effort ()
7965 "Set the effort property for the current headline."
7966 (interactive)
7967 (org-agenda-check-no-diary)
7968 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7969 (org-agenda-error)))
7970 (buffer (marker-buffer hdmarker))
7971 (pos (marker-position hdmarker))
7972 (inhibit-read-only t)
7973 newhead)
7974 (org-with-remote-undo buffer
7975 (with-current-buffer buffer
7976 (widen)
7977 (goto-char pos)
7978 (save-excursion
7979 (org-show-context 'agenda))
7980 (save-excursion
7981 (and (outline-next-heading)
7982 (org-flag-heading nil))) ; show the next heading
7983 (goto-char pos)
7984 (call-interactively 'org-set-effort)
7985 (end-of-line 1)
7986 (setq newhead (org-get-heading)))
7987 (org-agenda-change-all-lines newhead hdmarker))))
7989 (defun org-agenda-toggle-archive-tag ()
7990 "Toggle the archive tag for the current entry."
7991 (interactive)
7992 (org-agenda-check-no-diary)
7993 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
7994 (org-agenda-error)))
7995 (buffer (marker-buffer hdmarker))
7996 (pos (marker-position hdmarker))
7997 (inhibit-read-only t)
7998 newhead)
7999 (org-with-remote-undo buffer
8000 (with-current-buffer buffer
8001 (widen)
8002 (goto-char pos)
8003 (org-show-context 'agenda)
8004 (save-excursion
8005 (and (outline-next-heading)
8006 (org-flag-heading nil))) ; show the next heading
8007 (call-interactively 'org-toggle-archive-tag)
8008 (end-of-line 1)
8009 (setq newhead (org-get-heading)))
8010 (org-agenda-change-all-lines newhead hdmarker)
8011 (beginning-of-line 1))))
8013 (defun org-agenda-do-date-later (arg)
8014 (interactive "P")
8015 (cond
8016 ((or (equal arg '(16))
8017 (memq last-command
8018 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8019 (setq this-command 'org-agenda-date-later-minutes)
8020 (org-agenda-date-later-minutes 1))
8021 ((or (equal arg '(4))
8022 (memq last-command
8023 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8024 (setq this-command 'org-agenda-date-later-hours)
8025 (org-agenda-date-later-hours 1))
8027 (org-agenda-date-later (prefix-numeric-value arg)))))
8029 (defun org-agenda-do-date-earlier (arg)
8030 (interactive "P")
8031 (cond
8032 ((or (equal arg '(16))
8033 (memq last-command
8034 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8035 (setq this-command 'org-agenda-date-earlier-minutes)
8036 (org-agenda-date-earlier-minutes 1))
8037 ((or (equal arg '(4))
8038 (memq last-command
8039 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8040 (setq this-command 'org-agenda-date-earlier-hours)
8041 (org-agenda-date-earlier-hours 1))
8043 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8045 (defun org-agenda-date-later (arg &optional what)
8046 "Change the date of this item to ARG day(s) later."
8047 (interactive "p")
8048 (org-agenda-check-type t 'agenda 'timeline)
8049 (org-agenda-check-no-diary)
8050 (let* ((marker (or (org-get-at-bol 'org-marker)
8051 (org-agenda-error)))
8052 (buffer (marker-buffer marker))
8053 (pos (marker-position marker))
8054 cdate today)
8055 (org-with-remote-undo buffer
8056 (with-current-buffer buffer
8057 (widen)
8058 (goto-char pos)
8059 (if (not (org-at-timestamp-p))
8060 (error "Cannot find time stamp"))
8061 (when (and org-agenda-move-date-from-past-immediately-to-today
8062 (equal arg 1)
8063 (or (not what) (eq what 'day))
8064 (not (save-match-data (org-at-date-range-p))))
8065 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8066 cdate (calendar-absolute-from-gregorian
8067 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8068 today (org-today))
8069 (if (> today cdate)
8070 ;; immediately shift to today
8071 (setq arg (- today cdate))))
8072 (org-timestamp-change arg (or what 'day))
8073 (when (and (org-at-date-range-p)
8074 (re-search-backward org-tr-regexp-both (point-at-bol)))
8075 (let ((end org-last-changed-timestamp))
8076 (org-timestamp-change arg (or what 'day))
8077 (setq org-last-changed-timestamp
8078 (concat org-last-changed-timestamp "--" end)))))
8079 (org-agenda-show-new-time marker org-last-changed-timestamp))
8080 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8082 (defun org-agenda-date-earlier (arg &optional what)
8083 "Change the date of this item to ARG day(s) earlier."
8084 (interactive "p")
8085 (org-agenda-date-later (- arg) what))
8087 (defun org-agenda-date-later-minutes (arg)
8088 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8089 (interactive "p")
8090 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8091 (org-agenda-date-later arg 'minute))
8093 (defun org-agenda-date-earlier-minutes (arg)
8094 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8095 (interactive "p")
8096 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8097 (org-agenda-date-earlier arg 'minute))
8099 (defun org-agenda-date-later-hours (arg)
8100 "Change the time of this item, in hour steps."
8101 (interactive "p")
8102 (org-agenda-date-later arg 'hour))
8104 (defun org-agenda-date-earlier-hours (arg)
8105 "Change the time of this item, in hour steps."
8106 (interactive "p")
8107 (org-agenda-date-earlier arg 'hour))
8109 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8110 "Show new date stamp via text properties."
8111 ;; We use text properties to make this undoable
8112 (let ((inhibit-read-only t)
8113 (buffer-invisibility-spec))
8114 (setq stamp (concat " " prefix " => " stamp))
8115 (save-excursion
8116 (goto-char (point-max))
8117 (while (not (bobp))
8118 (when (equal marker (org-get-at-bol 'org-marker))
8119 (org-move-to-column (- (window-width) (length stamp)) t)
8120 (org-agenda-fix-tags-filter-overlays-at (point))
8121 (if (featurep 'xemacs)
8122 ;; Use `duplicable' property to trigger undo recording
8123 (let ((ex (make-extent nil nil))
8124 (gl (make-glyph stamp)))
8125 (set-glyph-face gl 'secondary-selection)
8126 (set-extent-properties
8127 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8128 (insert-extent ex (1- (point)) (point-at-eol)))
8129 (add-text-properties
8130 (1- (point)) (point-at-eol)
8131 (list 'display (org-add-props stamp nil
8132 'face 'secondary-selection))))
8133 (beginning-of-line 1))
8134 (beginning-of-line 0)))))
8136 (defun org-agenda-date-prompt (arg)
8137 "Change the date of this item. Date is prompted for, with default today.
8138 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8139 be used to request time specification in the time stamp."
8140 (interactive "P")
8141 (org-agenda-check-type t 'agenda 'timeline)
8142 (org-agenda-check-no-diary)
8143 (let* ((marker (or (org-get-at-bol 'org-marker)
8144 (org-agenda-error)))
8145 (buffer (marker-buffer marker))
8146 (pos (marker-position marker)))
8147 (org-with-remote-undo buffer
8148 (with-current-buffer buffer
8149 (widen)
8150 (goto-char pos)
8151 (if (not (org-at-timestamp-p t))
8152 (error "Cannot find time stamp"))
8153 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8154 (org-agenda-show-new-time marker org-last-changed-timestamp))
8155 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8157 (defun org-agenda-schedule (arg &optional time)
8158 "Schedule the item at point.
8159 ARG is passed through to `org-schedule'."
8160 (interactive "P")
8161 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8162 (org-agenda-check-no-diary)
8163 (let* ((marker (or (org-get-at-bol 'org-marker)
8164 (org-agenda-error)))
8165 (type (marker-insertion-type marker))
8166 (buffer (marker-buffer marker))
8167 (pos (marker-position marker))
8168 (org-insert-labeled-timestamps-at-point nil)
8170 (set-marker-insertion-type marker t)
8171 (org-with-remote-undo buffer
8172 (with-current-buffer buffer
8173 (widen)
8174 (goto-char pos)
8175 (setq ts (org-schedule arg time)))
8176 (org-agenda-show-new-time marker ts "S"))
8177 (message "Item scheduled for %s" ts)))
8179 (defun org-agenda-deadline (arg &optional time)
8180 "Schedule the item at point.
8181 ARG is passed through to `org-deadline'."
8182 (interactive "P")
8183 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8184 (org-agenda-check-no-diary)
8185 (let* ((marker (or (org-get-at-bol 'org-marker)
8186 (org-agenda-error)))
8187 (buffer (marker-buffer marker))
8188 (pos (marker-position marker))
8189 (org-insert-labeled-timestamps-at-point nil)
8191 (org-with-remote-undo buffer
8192 (with-current-buffer buffer
8193 (widen)
8194 (goto-char pos)
8195 (setq ts (org-deadline arg time)))
8196 (org-agenda-show-new-time marker ts "D"))
8197 (message "Deadline for this item set to %s" ts)))
8199 (defun org-agenda-action ()
8200 "Select entry for agenda action, or execute an agenda action.
8201 This command prompts for another letter. Valid inputs are:
8203 m Mark the entry at point for an agenda action
8204 s Schedule the marked entry to the date at the cursor
8205 d Set the deadline of the marked entry to the date at the cursor
8206 r Call `org-remember' with cursor date as the default date
8207 c Call `org-capture' with cursor date as the default date
8208 SPC Show marked entry in other window
8209 TAB Visit marked entry in other window
8211 The cursor may be at a date in the calendar, or in the Org agenda."
8212 (interactive)
8213 (let (ans)
8214 (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
8215 (setq ans (read-char-exclusive))
8216 (cond
8217 ((equal ans ?m)
8218 ;; Mark this entry
8219 (if (eq major-mode 'org-agenda-mode)
8220 (let ((m (or (org-get-at-bol 'org-hd-marker)
8221 (org-get-at-bol 'org-marker))))
8222 (if m
8223 (progn
8224 (move-marker org-agenda-action-marker
8225 (marker-position m) (marker-buffer m))
8226 (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
8227 (error "Don't know which entry to mark")))
8228 (error "This command works only in the agenda")))
8229 ((equal ans ?s)
8230 (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
8231 ((equal ans ?d)
8232 (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
8233 ((equal ans ?r)
8234 (org-agenda-do-action '(org-remember) t))
8235 ((equal ans ?c)
8236 (org-agenda-do-action '(org-capture) t))
8237 ((equal ans ?\ )
8238 (let ((cw (selected-window)))
8239 (org-switch-to-buffer-other-window
8240 (marker-buffer org-agenda-action-marker))
8241 (goto-char org-agenda-action-marker)
8242 (org-show-context 'agenda)
8243 (select-window cw)))
8244 ((equal ans ?\C-i)
8245 (org-switch-to-buffer-other-window
8246 (marker-buffer org-agenda-action-marker))
8247 (goto-char org-agenda-action-marker)
8248 (org-show-context 'agenda))
8249 (t (error "Invalid agenda action %c" ans)))))
8251 (defun org-agenda-do-action (form &optional current-buffer)
8252 "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
8253 (let ((org-overriding-default-time (org-get-cursor-date)))
8254 (if current-buffer
8255 (eval form)
8256 (if (not (marker-buffer org-agenda-action-marker))
8257 (error "No entry has been selected for agenda action")
8258 (with-current-buffer (marker-buffer org-agenda-action-marker)
8259 (save-excursion
8260 (save-restriction
8261 (widen)
8262 (goto-char org-agenda-action-marker)
8263 (eval form))))))))
8265 (defun org-agenda-clock-in (&optional arg)
8266 "Start the clock on the currently selected item."
8267 (interactive "P")
8268 (org-agenda-check-no-diary)
8269 (if (equal arg '(4))
8270 (org-clock-in arg)
8271 (let* ((marker (or (org-get-at-bol 'org-marker)
8272 (org-agenda-error)))
8273 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8274 marker))
8275 (pos (marker-position marker))
8276 newhead)
8277 (org-with-remote-undo (marker-buffer marker)
8278 (with-current-buffer (marker-buffer marker)
8279 (widen)
8280 (goto-char pos)
8281 (org-show-context 'agenda)
8282 (org-show-entry)
8283 (org-cycle-hide-drawers 'children)
8284 (org-clock-in arg)
8285 (setq newhead (org-get-heading)))
8286 (org-agenda-change-all-lines newhead hdmarker)))))
8288 (defun org-agenda-clock-out ()
8289 "Stop the currently running clock."
8290 (interactive)
8291 (unless (marker-buffer org-clock-marker)
8292 (error "No running clock"))
8293 (let ((marker (make-marker)) newhead)
8294 (org-with-remote-undo (marker-buffer org-clock-marker)
8295 (with-current-buffer (marker-buffer org-clock-marker)
8296 (save-excursion
8297 (save-restriction
8298 (widen)
8299 (goto-char org-clock-marker)
8300 (org-back-to-heading t)
8301 (move-marker marker (point))
8302 (org-clock-out)
8303 (setq newhead (org-get-heading))))))
8304 (org-agenda-change-all-lines newhead marker)
8305 (move-marker marker nil)))
8307 (defun org-agenda-clock-cancel (&optional arg)
8308 "Cancel the currently running clock."
8309 (interactive "P")
8310 (unless (marker-buffer org-clock-marker)
8311 (error "No running clock"))
8312 (org-with-remote-undo (marker-buffer org-clock-marker)
8313 (org-clock-cancel)))
8315 (defun org-agenda-clock-goto ()
8316 "Jump to the currently clocked in task within the agenda.
8317 If the currently clocked in task is not listed in the agenda
8318 buffer, display it in another window."
8319 (interactive)
8320 (let (pos)
8321 (mapc (lambda (o)
8322 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8323 (setq pos (overlay-start o))))
8324 (overlays-in (point-min) (point-max)))
8325 (cond (pos (goto-char pos))
8326 ;; If the currently clocked entry is not in the agenda
8327 ;; buffer, we visit it in another window:
8328 (org-clock-current-task
8329 (org-switch-to-buffer-other-window (org-clock-goto)))
8330 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8332 (defun org-agenda-diary-entry-in-org-file ()
8333 "Make a diary entry in the file `org-agenda-diary-file'."
8334 (let (d1 d2 char (text "") dp1 dp2)
8335 (if (equal (buffer-name) "*Calendar*")
8336 (setq d1 (calendar-cursor-to-date t)
8337 d2 (car calendar-mark-ring))
8338 (setq dp1 (get-text-property (point-at-bol) 'day))
8339 (unless dp1 (error "No date defined in current line"))
8340 (setq d1 (calendar-gregorian-from-absolute dp1)
8341 d2 (and (ignore-errors (mark))
8342 (save-excursion
8343 (goto-char (mark))
8344 (setq dp2 (get-text-property (point-at-bol) 'day)))
8345 (calendar-gregorian-from-absolute dp2))))
8346 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8347 (setq char (read-char-exclusive))
8348 (cond
8349 ((equal char ?d)
8350 (setq text (read-string "Day entry: "))
8351 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8352 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8353 ((equal char ?a)
8354 (setq d1 (list (car d1) (nth 1 d1)
8355 (read-number (format "Reference year [%d]: " (nth 2 d1))
8356 (nth 2 d1))))
8357 (setq text (read-string "Anniversary (use %d to show years): "))
8358 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8359 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8360 ((equal char ?b)
8361 (setq text (read-string "Block entry: "))
8362 (unless (and d1 d2 (not (equal d1 d2)))
8363 (error "No block of days selected"))
8364 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8365 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8366 ((equal char ?j)
8367 (org-switch-to-buffer-other-window
8368 (find-file-noselect org-agenda-diary-file))
8369 (require 'org-datetree)
8370 (org-datetree-find-date-create d1)
8371 (org-reveal t))
8372 (t (error "Invalid selection character `%c'" char)))))
8374 (defcustom org-agenda-insert-diary-strategy 'date-tree
8375 "Where in `org-agenda-diary-file' should new entries be added?
8376 Valid values:
8378 date-tree in the date tree, as child of the date
8379 top-level as top-level entries at the end of the file."
8380 :group 'org-agenda
8381 :type '(choice
8382 (const :tag "in a date tree" date-tree)
8383 (const :tag "as top level at end of file" top-level)))
8385 (defcustom org-agenda-insert-diary-extract-time nil
8386 "Non-nil means extract any time specification from the diary entry."
8387 :group 'org-agenda
8388 :version "24.1"
8389 :type 'boolean)
8391 (defcustom org-agenda-bulk-mark-char ">"
8392 "A single-character string to be used as the bulk mark."
8393 :group 'org-agenda
8394 :version "24.1"
8395 :type 'string)
8397 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8398 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8399 If TEXT is not empty, it will become the headline of the new entry, and
8400 the resulting entry will not be shown. When TEXT is empty, switch to
8401 `org-agenda-diary-file' and let the user finish the entry there."
8402 (let ((cw (current-window-configuration)))
8403 (org-switch-to-buffer-other-window
8404 (find-file-noselect org-agenda-diary-file))
8405 (widen)
8406 (goto-char (point-min))
8407 (cond
8408 ((eq type 'anniversary)
8409 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8410 (progn
8411 (or (org-at-heading-p t)
8412 (progn
8413 (outline-next-heading)
8414 (insert "* Anniversaries\n\n")
8415 (beginning-of-line -1)))))
8416 (outline-next-heading)
8417 (org-back-over-empty-lines)
8418 (backward-char 1)
8419 (insert "\n")
8420 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8421 (nth 2 d1) (car d1) (nth 1 d1) text)))
8422 ((eq type 'day)
8423 (let ((org-prefix-has-time t)
8424 (org-agenda-time-leading-zero t)
8425 fmt time time2)
8426 (if org-agenda-insert-diary-extract-time
8427 ;; Use org-agenda-format-item to parse text for a time-range and
8428 ;; remove it. FIXME: This is a hack, we should refactor
8429 ;; that function to make time extraction available separately
8430 (setq fmt (org-agenda-format-item nil text nil nil t)
8431 time (get-text-property 0 'time fmt)
8432 time2 (if (> (length time) 0)
8433 ;; split-string removes trailing ...... if
8434 ;; no end time given. First space
8435 ;; separates time from date.
8436 (concat " " (car (split-string time "\\.")))
8437 nil)
8438 text (get-text-property 0 'txt fmt)))
8439 (if (eq org-agenda-insert-diary-strategy 'top-level)
8440 (org-agenda-insert-diary-as-top-level text)
8441 (require 'org-datetree)
8442 (org-datetree-find-date-create d1)
8443 (org-agenda-insert-diary-make-new-entry text))
8444 (org-insert-time-stamp (org-time-from-absolute
8445 (calendar-absolute-from-gregorian d1))
8446 nil nil nil nil time2))
8447 (end-of-line 0))
8448 ((eq type 'block)
8449 (if (> (calendar-absolute-from-gregorian d1)
8450 (calendar-absolute-from-gregorian d2))
8451 (setq d1 (prog1 d2 (setq d2 d1))))
8452 (if (eq org-agenda-insert-diary-strategy 'top-level)
8453 (org-agenda-insert-diary-as-top-level text)
8454 (require 'org-datetree)
8455 (org-datetree-find-date-create d1)
8456 (org-agenda-insert-diary-make-new-entry text))
8457 (org-insert-time-stamp (org-time-from-absolute
8458 (calendar-absolute-from-gregorian d1)))
8459 (insert "--")
8460 (org-insert-time-stamp (org-time-from-absolute
8461 (calendar-absolute-from-gregorian d2)))
8462 (end-of-line 0)))
8463 (if (string-match "\\S-" text)
8464 (progn
8465 (set-window-configuration cw)
8466 (message "%s entry added to %s"
8467 (capitalize (symbol-name type))
8468 (abbreviate-file-name org-agenda-diary-file)))
8469 (org-reveal t)
8470 (message "Please finish entry here"))))
8472 (defun org-agenda-insert-diary-as-top-level (text)
8473 "Make new entry as a top-level entry at the end of the file.
8474 Add TEXT as headline, and position the cursor in the second line so that
8475 a timestamp can be added there."
8476 (widen)
8477 (goto-char (point-max))
8478 (or (bolp) (insert "\n"))
8479 (insert "* " text "\n")
8480 (if org-adapt-indentation (org-indent-to-column 2)))
8482 (defun org-agenda-insert-diary-make-new-entry (text)
8483 "Make new entry as last child of current entry.
8484 Add TEXT as headline, and position the cursor in the second line so that
8485 a timestamp can be added there."
8486 (let ((org-show-following-heading t)
8487 (org-show-siblings t)
8488 (org-show-hierarchy-above t)
8489 (org-show-entry-below t)
8490 col)
8491 (outline-next-heading)
8492 (org-back-over-empty-lines)
8493 (or (looking-at "[ \t]*$")
8494 (progn (insert "\n") (backward-char 1)))
8495 (org-insert-heading nil t)
8496 (org-do-demote)
8497 (setq col (current-column))
8498 (insert text "\n")
8499 (if org-adapt-indentation (org-indent-to-column col))
8500 (let ((org-show-following-heading t)
8501 (org-show-siblings t)
8502 (org-show-hierarchy-above t)
8503 (org-show-entry-below t))
8504 (org-show-context))))
8506 (defun org-agenda-diary-entry ()
8507 "Make a diary entry, like the `i' command from the calendar.
8508 All the standard commands work: block, weekly etc.
8509 When `org-agenda-diary-file' points to a file,
8510 `org-agenda-diary-entry-in-org-file' is called instead to create
8511 entries in that Org-mode file."
8512 (interactive)
8513 (org-agenda-check-type t 'agenda 'timeline)
8514 (if (not (eq org-agenda-diary-file 'diary-file))
8515 (org-agenda-diary-entry-in-org-file)
8516 (require 'diary-lib)
8517 (let* ((char (progn
8518 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
8519 (read-char-exclusive)))
8520 (cmd (cdr (assoc char
8521 '((?d . insert-diary-entry)
8522 (?w . insert-weekly-diary-entry)
8523 (?m . insert-monthly-diary-entry)
8524 (?y . insert-yearly-diary-entry)
8525 (?a . insert-anniversary-diary-entry)
8526 (?b . insert-block-diary-entry)
8527 (?c . insert-cyclic-diary-entry)))))
8528 (oldf (symbol-function 'calendar-cursor-to-date))
8529 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
8530 (point (point))
8531 (mark (or (mark t) (point))))
8532 (unless cmd
8533 (error "No command associated with <%c>" char))
8534 (unless (and (get-text-property point 'day)
8535 (or (not (equal ?b char))
8536 (get-text-property mark 'day)))
8537 (error "Don't know which date to use for diary entry"))
8538 ;; We implement this by hacking the `calendar-cursor-to-date' function
8539 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
8540 (let ((calendar-mark-ring
8541 (list (calendar-gregorian-from-absolute
8542 (or (get-text-property mark 'day)
8543 (get-text-property point 'day))))))
8544 (unwind-protect
8545 (progn
8546 (fset 'calendar-cursor-to-date
8547 (lambda (&optional error dummy)
8548 (calendar-gregorian-from-absolute
8549 (get-text-property point 'day))))
8550 (call-interactively cmd))
8551 (fset 'calendar-cursor-to-date oldf))))))
8553 (defun org-agenda-execute-calendar-command (cmd)
8554 "Execute a calendar command from the agenda, with the date associated to
8555 the cursor position."
8556 (org-agenda-check-type t 'agenda 'timeline)
8557 (require 'diary-lib)
8558 (unless (get-text-property (point) 'day)
8559 (error "Don't know which date to use for calendar command"))
8560 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
8561 (point (point))
8562 (date (calendar-gregorian-from-absolute
8563 (get-text-property point 'day)))
8564 ;; the following 2 vars are needed in the calendar
8565 (displayed-month (car date))
8566 (displayed-year (nth 2 date)))
8567 (unwind-protect
8568 (progn
8569 (fset 'calendar-cursor-to-date
8570 (lambda (&optional error dummy)
8571 (calendar-gregorian-from-absolute
8572 (get-text-property point 'day))))
8573 (call-interactively cmd))
8574 (fset 'calendar-cursor-to-date oldf))))
8576 (defun org-agenda-phases-of-moon ()
8577 "Display the phases of the moon for the 3 months around the cursor date."
8578 (interactive)
8579 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
8581 (defun org-agenda-holidays ()
8582 "Display the holidays for the 3 months around the cursor date."
8583 (interactive)
8584 (org-agenda-execute-calendar-command 'list-calendar-holidays))
8586 (defvar calendar-longitude)
8587 (defvar calendar-latitude)
8588 (defvar calendar-location-name)
8590 (defun org-agenda-sunrise-sunset (arg)
8591 "Display sunrise and sunset for the cursor date.
8592 Latitude and longitude can be specified with the variables
8593 `calendar-latitude' and `calendar-longitude'. When called with prefix
8594 argument, latitude and longitude will be prompted for."
8595 (interactive "P")
8596 (require 'solar)
8597 (let ((calendar-longitude (if arg nil calendar-longitude))
8598 (calendar-latitude (if arg nil calendar-latitude))
8599 (calendar-location-name
8600 (if arg "the given coordinates" calendar-location-name)))
8601 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
8603 (defun org-agenda-goto-calendar ()
8604 "Open the Emacs calendar with the date at the cursor."
8605 (interactive)
8606 (org-agenda-check-type t 'agenda 'timeline)
8607 (let* ((day (or (get-text-property (point) 'day)
8608 (error "Don't know which date to open in calendar")))
8609 (date (calendar-gregorian-from-absolute day))
8610 (calendar-move-hook nil)
8611 (calendar-view-holidays-initially-flag nil)
8612 (calendar-view-diary-initially-flag nil))
8613 (calendar)
8614 (calendar-goto-date date)))
8616 ;;;###autoload
8617 (defun org-calendar-goto-agenda ()
8618 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
8619 This is a command that has to be installed in `calendar-mode-map'."
8620 (interactive)
8621 (org-agenda-list nil (calendar-absolute-from-gregorian
8622 (calendar-cursor-to-date))
8623 nil))
8625 (defun org-agenda-convert-date ()
8626 (interactive)
8627 (org-agenda-check-type t 'agenda 'timeline)
8628 (let ((day (get-text-property (point) 'day))
8629 date s)
8630 (unless day
8631 (error "Don't know which date to convert"))
8632 (setq date (calendar-gregorian-from-absolute day))
8633 (setq s (concat
8634 "Gregorian: " (calendar-date-string date) "\n"
8635 "ISO: " (calendar-iso-date-string date) "\n"
8636 "Day of Yr: " (calendar-day-of-year-string date) "\n"
8637 "Julian: " (calendar-julian-date-string date) "\n"
8638 "Astron. JD: " (calendar-astro-date-string date)
8639 " (Julian date number at noon UTC)\n"
8640 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
8641 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
8642 "French: " (calendar-french-date-string date) "\n"
8643 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
8644 "Mayan: " (calendar-mayan-date-string date) "\n"
8645 "Coptic: " (calendar-coptic-date-string date) "\n"
8646 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
8647 "Persian: " (calendar-persian-date-string date) "\n"
8648 "Chinese: " (calendar-chinese-date-string date) "\n"))
8649 (with-output-to-temp-buffer "*Dates*"
8650 (princ s))
8651 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
8653 ;;; Bulk commands
8655 (defvar org-agenda-bulk-marked-entries nil
8656 "List of markers that refer to marked entries in the agenda.")
8658 (defun org-agenda-bulk-marked-p ()
8659 (eq (get-char-property (point-at-bol) 'type)
8660 'org-marked-entry-overlay))
8662 (defun org-agenda-bulk-mark (&optional arg)
8663 "Mark the entry at point for future bulk action."
8664 (interactive "p")
8665 (dotimes (i (or arg 1))
8666 (unless (org-get-at-bol 'org-agenda-diary-link)
8667 (let* ((m (org-get-at-bol 'org-hd-marker))
8669 (unless (org-agenda-bulk-marked-p)
8670 (unless m (error "Nothing to mark at point"))
8671 (push m org-agenda-bulk-marked-entries)
8672 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
8673 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
8674 (org-get-todo-face "TODO")
8675 'evaporate)
8676 (overlay-put ov 'type 'org-marked-entry-overlay))
8677 (beginning-of-line 2)
8678 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8679 (beginning-of-line 2))
8680 (message "%d entries marked for bulk action"
8681 (length org-agenda-bulk-marked-entries))))))
8683 (defun org-agenda-bulk-mark-all ()
8684 "Mark all entries for future agenda bulk action."
8685 (interactive)
8686 (org-agenda-bulk-mark-regexp "."))
8688 (defun org-agenda-bulk-mark-regexp (regexp)
8689 "Mark entries matching REGEXP for future agenda bulk action."
8690 (interactive "sMark entries matching regexp: ")
8691 (let ((entries-marked 0))
8692 (save-excursion
8693 (goto-char (point-min))
8694 (goto-char (next-single-property-change (point) 'txt))
8695 (while (re-search-forward regexp nil t)
8696 (when (string-match regexp (get-text-property (point) 'txt))
8697 (setq entries-marked (1+ entries-marked))
8698 (call-interactively 'org-agenda-bulk-mark))))
8699 (if (not entries-marked)
8700 (message "No entry matching this regexp."))))
8702 (defun org-agenda-bulk-unmark (&optional arg)
8703 "Unmark the entry at point for future bulk action."
8704 (interactive "P")
8705 (if arg
8706 (org-agenda-bulk-unmark-all)
8707 (cond ((org-agenda-bulk-marked-p)
8708 (org-agenda-bulk-remove-overlays
8709 (point-at-bol) (+ 2 (point-at-bol)))
8710 (setq org-agenda-bulk-marked-entries
8711 (delete (org-get-at-bol 'org-hd-marker)
8712 org-agenda-bulk-marked-entries))
8713 (beginning-of-line 2)
8714 (while (and (get-char-property (point) 'invisible) (not (eobp)))
8715 (beginning-of-line 2))
8716 (message "%d entries left marked for bulk action"
8717 (length org-agenda-bulk-marked-entries)))
8718 (t (message "No entry to unmark here")))))
8720 (defun org-agenda-bulk-toggle ()
8721 "Toggle marking the entry at point for bulk action."
8722 (interactive)
8723 (if (org-agenda-bulk-marked-p)
8724 (org-agenda-bulk-unmark)
8725 (org-agenda-bulk-mark)))
8727 (defun org-agenda-bulk-remove-overlays (&optional beg end)
8728 "Remove the mark overlays between BEG and END in the agenda buffer.
8729 BEG and END default to the buffer limits.
8731 This only removes the overlays, it does not remove the markers
8732 from the list in `org-agenda-bulk-marked-entries'."
8733 (interactive)
8734 (mapc (lambda (ov)
8735 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
8736 (delete-overlay ov)))
8737 (overlays-in (or beg (point-min)) (or end (point-max)))))
8739 (defun org-agenda-bulk-unmark-all ()
8740 "Remove all marks in the agenda buffer.
8741 This will remove the markers and the overlays."
8742 (interactive)
8743 (if (null org-agenda-bulk-marked-entries)
8744 (message "No entry to unmark")
8745 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
8746 (setq org-agenda-bulk-marked-entries nil)
8747 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
8749 (defcustom org-agenda-persistent-marks nil
8750 "Non-nil means marked items will stay marked after a bulk action.
8751 You can interactively and temporarily toggle by typing `p' when you
8752 are prompted for a bulk action."
8753 :group 'org-agenda
8754 :version "24.1"
8755 :type 'boolean)
8757 (defun org-agenda-bulk-action (&optional arg)
8758 "Execute an remote-editing action on all marked entries.
8759 The prefix arg is passed through to the command if possible."
8760 (interactive "P")
8761 ;; Make sure we have markers, and only valid ones
8762 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
8763 (mapc
8764 (lambda (m)
8765 (unless (and (markerp m)
8766 (marker-buffer m)
8767 (buffer-live-p (marker-buffer m))
8768 (marker-position m))
8769 (error "Marker %s for bulk command is invalid" m)))
8770 org-agenda-bulk-marked-entries)
8772 ;; Prompt for the bulk command
8773 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
8774 (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
8775 " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
8776 (when org-agenda-bulk-custom-functions
8777 (concat " Custom: ["
8778 (mapconcat (lambda(f) (char-to-string (car f)))
8779 org-agenda-bulk-custom-functions "")
8780 "]"))))
8781 (catch 'exit
8782 (let* ((action (read-char-exclusive))
8783 (org-log-refile (if org-log-refile 'time nil))
8784 (entries (reverse org-agenda-bulk-marked-entries))
8785 redo-at-end
8786 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
8787 (cond
8788 ((equal action ?p)
8789 (let ((org-agenda-persistent-marks
8790 (not org-agenda-persistent-marks)))
8791 (org-agenda-bulk-action)
8792 (throw 'exit nil)))
8794 ((equal action ?$)
8795 (setq cmd '(org-agenda-archive)))
8797 ((equal action ?A)
8798 (setq cmd '(org-agenda-archive-to-archive-sibling)))
8800 ((member action '(?r ?w))
8801 (setq rfloc (org-refile-get-location
8802 "Refile to"
8803 (marker-buffer (car org-agenda-bulk-marked-entries))
8804 org-refile-allow-creating-parent-nodes))
8805 (if (nth 3 rfloc)
8806 (setcar (nthcdr 3 rfloc)
8807 (move-marker (make-marker) (nth 3 rfloc)
8808 (or (get-file-buffer (nth 1 rfloc))
8809 (find-buffer-visiting (nth 1 rfloc))
8810 (error "This should not happen")))))
8812 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
8813 redo-at-end t))
8815 ((equal action ?t)
8816 (setq state (org-icompleting-read
8817 "Todo state: "
8818 (with-current-buffer (marker-buffer (car entries))
8819 (mapcar 'list org-todo-keywords-1))))
8820 (setq cmd `(let ((org-inhibit-blocking t)
8821 (org-inhibit-logging 'note))
8822 (org-agenda-todo ,state))))
8824 ((memq action '(?- ?+))
8825 (setq tag (org-icompleting-read
8826 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
8827 (with-current-buffer (marker-buffer (car entries))
8828 (delq nil
8829 (mapcar (lambda (x)
8830 (if (stringp (car x)) x)) org-tag-alist)))))
8831 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
8833 ((memq action '(?s ?d))
8834 (let* ((date (unless arg
8835 (org-read-date
8836 nil nil nil
8837 (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
8838 (ans (if arg nil org-read-date-final-answer))
8839 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
8840 (setq cmd `(let* ((bound (fboundp 'read-string))
8841 (old (and bound (symbol-function 'read-string))))
8842 (unwind-protect
8843 (progn
8844 (fset 'read-string (lambda (&rest ignore) ,ans))
8845 (eval '(,c1 arg)))
8846 (if bound
8847 (fset 'read-string old)
8848 (fmakunbound 'read-string)))))))
8850 ((equal action ?S)
8851 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
8852 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
8853 (let ((days (read-number
8854 (format "Scatter tasks across how many %sdays: "
8855 (if arg "week" "")) 7)))
8856 (setq cmd
8857 `(let ((distance (1+ (random ,days))))
8858 (if arg
8859 (let ((dist distance)
8860 (day-of-week
8861 (calendar-day-of-week
8862 (calendar-gregorian-from-absolute (org-today)))))
8863 (dotimes (i (1+ dist))
8864 (while (member day-of-week org-agenda-weekend-days)
8865 (incf distance)
8866 (incf day-of-week)
8867 (if (= day-of-week 7)
8868 (setq day-of-week 0)))
8869 (incf day-of-week)
8870 (if (= day-of-week 7)
8871 (setq day-of-week 0)))))
8872 ;; silently fail when try to replan a sexp entry
8873 (condition-case nil
8874 (let* ((date (calendar-gregorian-from-absolute
8875 (+ (org-today) distance)))
8876 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
8877 (nth 2 date))))
8878 (org-agenda-schedule nil time))
8879 (error nil)))))))
8881 ((assoc action org-agenda-bulk-custom-functions)
8882 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
8883 redo-at-end t))
8885 ((equal action ?f)
8886 (setq cmd (list (intern
8887 (org-icompleting-read "Function: "
8888 obarray 'fboundp t nil nil)))))
8890 (t (error "Invalid bulk action")))
8892 ;; Sort the markers, to make sure that parents are handled before children
8893 (setq entries (sort entries
8894 (lambda (a b)
8895 (cond
8896 ((equal (marker-buffer a) (marker-buffer b))
8897 (< (marker-position a) (marker-position b)))
8899 (string< (buffer-name (marker-buffer a))
8900 (buffer-name (marker-buffer b))))))))
8902 ;; Now loop over all markers and apply cmd
8903 (while (setq e (pop entries))
8904 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
8905 (if (not pos)
8906 (progn (message "Skipping removed entry at %s" e)
8907 (setq cntskip (1+ cntskip)))
8908 (goto-char pos)
8909 (let (org-loop-over-headlines-in-active-region)
8910 (eval cmd))
8911 (when (not org-agenda-persistent-marks)
8912 (setq org-agenda-bulk-marked-entries
8913 (delete e org-agenda-bulk-marked-entries)))
8914 (setq cnt (1+ cnt))))
8915 (when (not org-agenda-persistent-marks)
8916 (org-agenda-bulk-unmark-all))
8917 (when redo-at-end (org-agenda-redo))
8918 (message "Acted on %d entries%s%s"
8920 (if (= cntskip 0)
8922 (format ", skipped %d (disappeared before their turn)"
8923 cntskip))
8924 (if (not org-agenda-persistent-marks)
8925 "" " (kept marked)"))))))
8927 ;;; Flagging notes
8929 (defun org-agenda-show-the-flagging-note ()
8930 "Display the flagging note in the other window.
8931 When called a second time in direct sequence, offer to remove the FLAGGING
8932 tag and (if present) the flagging note."
8933 (interactive)
8934 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
8935 (win (selected-window))
8936 note heading newhead)
8937 (unless hdmarker
8938 (error "No linked entry at point"))
8939 (if (and (eq this-command last-command)
8940 (y-or-n-p "Unflag and remove any flagging note? "))
8941 (progn
8942 (org-agenda-remove-flag hdmarker)
8943 (let ((win (get-buffer-window "*Flagging Note*")))
8944 (and win (delete-window win)))
8945 (message "Entry unflagged"))
8946 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
8947 (unless note
8948 (error "No flagging note"))
8949 (org-kill-new note)
8950 (org-switch-to-buffer-other-window "*Flagging Note*")
8951 (erase-buffer)
8952 (insert note)
8953 (goto-char (point-min))
8954 (while (re-search-forward "\\\\n" nil t)
8955 (replace-match "\n" t t))
8956 (goto-char (point-min))
8957 (select-window win)
8958 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
8960 (defun org-agenda-remove-flag (marker)
8961 "Remove the FLAGGED tag and any flagging note in the entry."
8962 (let (newhead)
8963 (org-with-point-at marker
8964 (org-toggle-tag "FLAGGED" 'off)
8965 (org-entry-delete nil "THEFLAGGINGNOTE")
8966 (setq newhead (org-get-heading)))
8967 (org-agenda-change-all-lines newhead marker)
8968 (message "Entry unflagged")))
8970 (defun org-agenda-get-any-marker (&optional pos)
8971 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
8972 (get-text-property (or pos (point-at-bol)) 'org-marker)))
8974 ;;; Appointment reminders
8976 (defvar appt-time-msg-list)
8978 ;;;###autoload
8979 (defun org-agenda-to-appt (&optional refresh filter &rest args)
8980 "Activate appointments found in `org-agenda-files'.
8981 With a \\[universal-argument] prefix, refresh the list of
8982 appointments.
8984 If FILTER is t, interactively prompt the user for a regular
8985 expression, and filter out entries that don't match it.
8987 If FILTER is a string, use this string as a regular expression
8988 for filtering entries out.
8990 If FILTER is a function, filter out entries against which
8991 calling the function returns nil. This function takes one
8992 argument: an entry from `org-agenda-get-day-entries'.
8994 FILTER can also be an alist with the car of each cell being
8995 either 'headline or 'category. For example:
8997 '((headline \"IMPORTANT\")
8998 (category \"Work\"))
9000 will only add headlines containing IMPORTANT or headlines
9001 belonging to the \"Work\" category.
9003 ARGS are symbols indicating what kind of entries to consider.
9004 By default `org-agenda-to-appt' will use :deadline, :scheduled
9005 and :timestamp entries. See the docstring of `org-diary' for
9006 details and examples.
9008 If an entry as a APPT_WARNTIME property, its value will be used
9009 to override `appt-message-warning-time'."
9010 (interactive "P")
9011 (if refresh (setq appt-time-msg-list nil))
9012 (if (eq filter t)
9013 (setq filter (read-from-minibuffer "Regexp filter: ")))
9014 (let* ((cnt 0) ; count added events
9015 (scope (or args '(:deadline :scheduled :timestamp)))
9016 (org-agenda-new-buffers nil)
9017 (org-deadline-warning-days 0)
9018 ;; Do not use `org-today' here because appt only takes
9019 ;; time and without date as argument, so it may pass wrong
9020 ;; information otherwise
9021 (today (org-date-to-gregorian
9022 (time-to-days (current-time))))
9023 (org-agenda-restrict nil)
9024 (files (org-agenda-files 'unrestricted)) entries file
9025 (org-agenda-buffer nil))
9026 ;; Get all entries which may contain an appt
9027 (org-prepare-agenda-buffers files)
9028 (while (setq file (pop files))
9029 (setq entries
9030 (delq nil
9031 (append entries
9032 (apply 'org-agenda-get-day-entries
9033 file today scope)))))
9034 ;; Map thru entries and find if we should filter them out
9035 (mapc
9036 (lambda(x)
9037 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9038 (cat (get-text-property 1 'org-category x))
9039 (tod (get-text-property 1 'time-of-day x))
9040 (ok (or (null filter)
9041 (and (stringp filter) (string-match filter evt))
9042 (and (functionp filter) (funcall filter x))
9043 (and (listp filter)
9044 (let ((cat-filter (cadr (assoc 'category filter)))
9045 (evt-filter (cadr (assoc 'headline filter))))
9046 (or (and (stringp cat-filter)
9047 (string-match cat-filter cat))
9048 (and (stringp evt-filter)
9049 (string-match evt-filter evt)))))))
9050 (wrn (org-entry-get (point) "APPT_WARNTIME")))
9051 ;; FIXME: Shall we remove text-properties for the appt text?
9052 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9053 (when (and ok tod)
9054 (setq tod (concat "00" (number-to-string tod))
9055 tod (when (string-match
9056 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9057 (concat (match-string 1 tod) ":"
9058 (match-string 2 tod))))
9059 (if (version< emacs-version "23.3")
9060 (appt-add tod evt)
9061 (appt-add tod evt wrn))
9062 (setq cnt (1+ cnt))))) entries)
9063 (org-release-buffers org-agenda-new-buffers)
9064 (if (eq cnt 0)
9065 (message "No event to add")
9066 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9068 (defun org-agenda-todayp (date)
9069 "Does DATE mean today, when considering `org-extend-today-until'?"
9070 (let ((today (org-today))
9071 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9072 date)))
9073 (eq date today)))
9075 (defun org-agenda-todo-yesterday (&optional arg)
9076 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9077 (interactive "P")
9078 (let* ((hour (third (decode-time
9079 (org-current-time))))
9080 (org-extend-today-until (1+ hour)))
9081 (org-agenda-todo arg)))
9083 (provide 'org-agenda)
9085 ;;; org-agenda.el ends here