Merge branch 'maint'
[org-mode.git] / lisp / org-agenda.el
blobed38869130055ca215d406270c3d7b8af772cf7f
1 ;;; org-agenda.el --- Dynamic task and appointment lists for Org
3 ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the code for creating and using the Agenda for Org-mode.
29 ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
30 ;; `org-batch-store-agenda-views' are implemented as macros to provide
31 ;; a convenient way for extracting agenda information from the command
32 ;; line. The Lisp does not evaluate parameters of a macro call; thus
33 ;; it is not necessary to quote the parameters passed to one of those
34 ;; functions. E.g. you can write:
36 ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
38 ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
39 ;; have been implemented as a regular function you'd have to quote the
40 ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
41 ;; value you would have to double quote the symbol.
43 ;; This is a hack, but it works even when running Org byte-compiled.
46 ;;; Code:
48 (require 'org)
49 (require 'org-macs)
50 (eval-when-compile
51 (require 'cl))
53 (declare-function diary-add-to-list "diary-lib"
54 (date string specifier &optional marker globcolor literal))
55 (declare-function calendar-absolute-from-iso "cal-iso" (date))
56 (declare-function calendar-astro-date-string "cal-julian" (&optional date))
57 (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
58 (declare-function calendar-chinese-date-string "cal-china" (&optional date))
59 (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
60 (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
61 (declare-function calendar-french-date-string "cal-french" (&optional date))
62 (declare-function calendar-goto-date "cal-move" (date))
63 (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
64 (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
65 (declare-function calendar-iso-date-string "cal-iso" (&optional date))
66 (declare-function calendar-iso-from-absolute "cal-iso" (date))
67 (declare-function calendar-julian-date-string "cal-julian" (&optional date))
68 (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
69 (declare-function calendar-persian-date-string "cal-persia" (&optional date))
70 (declare-function calendar-check-holidays "holidays" (date))
72 (declare-function org-datetree-find-date-create "org-datetree"
73 (date &optional keep-restriction))
74 (declare-function org-columns-quit "org-colview" ())
75 (declare-function diary-date-display-form "diary-lib" (&optional type))
76 (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
77 (declare-function org-habit-insert-consistency-graphs
78 "org-habit" (&optional line))
79 (declare-function org-is-habit-p "org-habit" (&optional pom))
80 (declare-function org-habit-parse-todo "org-habit" (&optional pom))
81 (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
82 (declare-function org-pop-to-buffer-same-window "org-compat"
83 (&optional buffer-or-name norecord label))
84 (declare-function org-agenda-columns "org-colview" ())
85 (declare-function org-add-archive-files "org-archive" (files))
86 (declare-function org-capture "org-capture" (&optional goto keys))
88 (defvar calendar-mode-map) ; defined in calendar.el
89 (defvar org-clock-current-task nil) ; defined in org-clock.el
90 (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
91 (defvar org-habit-show-habits) ; defined in org-habit.el
92 (defvar org-habit-show-habits-only-for-today)
93 (defvar org-habit-show-all-today)
95 ;; Defined somewhere in this file, but used before definition.
96 (defvar org-agenda-buffer-name "*Org Agenda*")
97 (defvar org-agenda-overriding-header nil)
98 (defvar org-agenda-title-append nil)
99 (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
100 (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
101 (defvar original-date) ; dynamically scoped, calendar.el does scope this
103 (defvar org-agenda-undo-list nil
104 "List of undoable operations in the agenda since last refresh.")
105 (defvar org-agenda-pending-undo-list nil
106 "In a series of undo commands, this is the list of remaining undo items.")
108 (defcustom org-agenda-confirm-kill 1
109 "When set, remote killing from the agenda buffer needs confirmation.
110 When t, a confirmation is always needed. When a number N, confirmation is
111 only needed when the text to be killed contains more than N non-white lines."
112 :group 'org-agenda
113 :type '(choice
114 (const :tag "Never" nil)
115 (const :tag "Always" t)
116 (integer :tag "When more than N lines")))
118 (defcustom org-agenda-compact-blocks nil
119 "Non-nil means make the block agenda more compact.
120 This is done globally by leaving out lines like the agenda span
121 name and week number or the separator lines."
122 :group 'org-agenda
123 :type 'boolean)
125 (defcustom org-agenda-block-separator ?=
126 "The separator between blocks in the agenda.
127 If this is a string, it will be used as the separator, with a newline added.
128 If it is a character, it will be repeated to fill the window width.
129 If nil the separator is disabled. In `org-agenda-custom-commands' this
130 addresses the separator between the current and the previous block."
131 :group 'org-agenda
132 :type '(choice
133 (const :tag "Disabled" nil)
134 (character)
135 (string)))
137 (defgroup org-agenda-export nil
138 "Options concerning exporting agenda views in Org-mode."
139 :tag "Org Agenda Export"
140 :group 'org-agenda)
142 (defcustom org-agenda-with-colors t
143 "Non-nil means use colors in agenda views."
144 :group 'org-agenda-export
145 :type 'boolean)
147 (defcustom org-agenda-exporter-settings nil
148 "Alist of variable/value pairs that should be active during agenda export.
149 This is a good place to set options for ps-print and for htmlize.
150 Note that the way this is implemented, the values will be evaluated
151 before assigned to the variables. So make sure to quote values you do
152 *not* want evaluated, for example
154 (setq org-agenda-exporter-settings
155 '((ps-print-color-p 'black-white)))"
156 :group 'org-agenda-export
157 :type '(repeat
158 (list
159 (variable)
160 (sexp :tag "Value"))))
162 (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
163 "Hook run in a temporary buffer before writing the agenda to an export file.
164 A useful function for this hook is `org-agenda-add-entry-text'."
165 :group 'org-agenda-export
166 :type 'hook
167 :options '(org-agenda-add-entry-text))
169 (defcustom org-agenda-add-entry-text-maxlines 0
170 "Maximum number of entry text lines to be added to agenda.
171 This is only relevant when `org-agenda-add-entry-text' is part of
172 `org-agenda-before-write-hook', which is the default.
173 When this is 0, nothing will happen. When it is greater than 0, it
174 specifies the maximum number of lines that will be added for each entry
175 that is listed in the agenda view.
177 Note that this variable is not used during display, only when exporting
178 the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
179 and `org-agenda-entry-text-maxlines'."
180 :group 'org-agenda
181 :type 'integer)
183 (defcustom org-agenda-add-entry-text-descriptive-links t
184 "Non-nil means export org-links as descriptive links in agenda added text.
185 This variable applies to the text added to the agenda when
186 `org-agenda-add-entry-text-maxlines' is larger than 0.
187 When this variable nil, the URL will (also) be shown."
188 :group 'org-agenda
189 :type 'boolean)
191 (defcustom org-agenda-export-html-style nil
192 "The style specification for exported HTML Agenda files.
193 If this variable contains a string, it will replace the default <style>
194 section as produced by `htmlize'.
195 Since there are different ways of setting style information, this variable
196 needs to contain the full HTML structure to provide a style, including the
197 surrounding HTML tags. The style specifications should include definitions
198 the fonts used by the agenda, here is an example:
200 <style type=\"text/css\">
201 p { font-weight: normal; color: gray; }
202 .org-agenda-structure {
203 font-size: 110%;
204 color: #003399;
205 font-weight: 600;
207 .org-todo {
208 color: #cc6666;
209 font-weight: bold;
211 .org-agenda-done {
212 color: #339933;
214 .org-done {
215 color: #339933;
217 .title { text-align: center; }
218 .todo, .deadline { color: red; }
219 .done { color: green; }
220 </style>
222 or, if you want to keep the style in a file,
224 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
226 As the value of this option simply gets inserted into the HTML <head> header,
227 you can \"misuse\" it to also add other text to the header."
228 :group 'org-agenda-export
229 :group 'org-export-html
230 :type 'string)
232 (defcustom org-agenda-persistent-filter nil
233 "When set, keep filters from one agenda view to the next."
234 :group 'org-agenda
235 :type 'boolean)
237 (defgroup org-agenda-custom-commands nil
238 "Options concerning agenda views in Org-mode."
239 :tag "Org Agenda Custom Commands"
240 :group 'org-agenda)
242 (defconst org-sorting-choice
243 '(choice
244 (const time-up) (const time-down)
245 (const category-keep) (const category-up) (const category-down)
246 (const tag-down) (const tag-up)
247 (const priority-up) (const priority-down)
248 (const todo-state-up) (const todo-state-down)
249 (const effort-up) (const effort-down)
250 (const habit-up) (const habit-down)
251 (const alpha-up) (const alpha-down)
252 (const user-defined-up) (const user-defined-down))
253 "Sorting choices.")
255 ;; Keep custom values for `org-agenda-filter-preset' compatible with
256 ;; the new variable `org-agenda-tag-filter-preset'.
257 (if (fboundp 'defvaralias)
258 (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
259 (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
261 (defconst org-agenda-custom-commands-local-options
262 `(repeat :tag "Local settings for this command. Remember to quote values"
263 (choice :tag "Setting"
264 (list :tag "Heading for this block"
265 (const org-agenda-overriding-header)
266 (string :tag "Headline"))
267 (list :tag "Files to be searched"
268 (const org-agenda-files)
269 (list
270 (const :format "" quote)
271 (repeat (file))))
272 (list :tag "Sorting strategy"
273 (const org-agenda-sorting-strategy)
274 (list
275 (const :format "" quote)
276 (repeat
277 ,org-sorting-choice)))
278 (list :tag "Prefix format"
279 (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
280 (string))
281 (list :tag "Number of days in agenda"
282 (const org-agenda-span)
283 (choice (const :tag "Day" 'day)
284 (const :tag "Week" 'week)
285 (const :tag "Month" 'month)
286 (const :tag "Year" 'year)
287 (integer :tag "Custom")))
288 (list :tag "Fixed starting date"
289 (const org-agenda-start-day)
290 (string :value "2007-11-01"))
291 (list :tag "Start on day of week"
292 (const org-agenda-start-on-weekday)
293 (choice :value 1
294 (const :tag "Today" nil)
295 (integer :tag "Weekday No.")))
296 (list :tag "Include data from diary"
297 (const org-agenda-include-diary)
298 (boolean))
299 (list :tag "Deadline Warning days"
300 (const org-deadline-warning-days)
301 (integer :value 1))
302 (list :tag "Category filter preset"
303 (const org-agenda-category-filter-preset)
304 (list
305 (const :format "" quote)
306 (repeat
307 (string :tag "+category or -category"))))
308 (list :tag "Tags filter preset"
309 (const org-agenda-tag-filter-preset)
310 (list
311 (const :format "" quote)
312 (repeat
313 (string :tag "+tag or -tag"))))
314 (list :tag "Set daily/weekly entry types"
315 (const org-agenda-entry-types)
316 (list
317 (const :format "" quote)
318 (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
319 (const :deadline)
320 (const :scheduled)
321 (const :timestamp)
322 (const :sexp))))
323 (list :tag "Standard skipping condition"
324 :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
325 (const org-agenda-skip-function)
326 (list
327 (const :format "" quote)
328 (list
329 (choice
330 :tag "Skipping range"
331 (const :tag "Skip entry" org-agenda-skip-entry-if)
332 (const :tag "Skip subtree" org-agenda-skip-subtree-if))
333 (repeat :inline t :tag "Conditions for skipping"
334 (choice
335 :tag "Condition type"
336 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
337 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
338 (list :tag "TODO state is" :inline t
339 (const 'todo)
340 (choice
341 (const :tag "any not-done state" 'todo)
342 (const :tag "any done state" 'done)
343 (const :tag "any state" 'any)
344 (list :tag "Keyword list"
345 (const :format "" quote)
346 (repeat (string :tag "Keyword")))))
347 (list :tag "TODO state is not" :inline t
348 (const 'nottodo)
349 (choice
350 (const :tag "any not-done state" 'todo)
351 (const :tag "any done state" 'done)
352 (const :tag "any state" 'any)
353 (list :tag "Keyword list"
354 (const :format "" quote)
355 (repeat (string :tag "Keyword")))))
356 (const :tag "scheduled" 'scheduled)
357 (const :tag "not scheduled" 'notscheduled)
358 (const :tag "deadline" 'deadline)
359 (const :tag "no deadline" 'notdeadline)
360 (const :tag "timestamp" 'timestamp)
361 (const :tag "no timestamp" 'nottimestamp))))))
362 (list :tag "Non-standard skipping condition"
363 :value (org-agenda-skip-function)
364 (const org-agenda-skip-function)
365 (sexp :tag "Function or form (quoted!)"))
366 (list :tag "Any variable"
367 (variable :tag "Variable")
368 (sexp :tag "Value (sexp)"))))
369 "Selection of examples for agenda command settings.
370 This will be spliced into the custom type of
371 `org-agenda-custom-commands'.")
374 (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
375 ((agenda "") (alltodo))))
376 "Custom commands for the agenda.
377 These commands will be offered on the splash screen displayed by the
378 agenda dispatcher \\[org-agenda]. Each entry is a list like this:
380 (key desc type match settings files)
382 key The key (one or more characters as a string) to be associated
383 with the command.
384 desc A description of the command, when omitted or nil, a default
385 description is built using MATCH.
386 type The command type, any of the following symbols:
387 agenda The daily/weekly agenda.
388 todo Entries with a specific TODO keyword, in all agenda files.
389 search Entries containing search words entry or headline.
390 tags Tags/Property/TODO match in all agenda files.
391 tags-todo Tags/P/T match in all agenda files, TODO entries only.
392 todo-tree Sparse tree of specific TODO keyword in *current* file.
393 tags-tree Sparse tree with all tags matches in *current* file.
394 occur-tree Occur sparse tree for *current* file.
395 ... A user-defined function.
396 match What to search for:
397 - a single keyword for TODO keyword searches
398 - a tags match expression for tags searches
399 - a word search expression for text searches.
400 - a regular expression for occur searches
401 For all other commands, this should be the empty string.
402 settings A list of option settings, similar to that in a let form, so like
403 this: ((opt1 val1) (opt2 val2) ...). The values will be
404 evaluated at the moment of execution, so quote them when needed.
405 files A list of files file to write the produced agenda buffer to
406 with the command `org-store-agenda-views'.
407 If a file name ends in \".html\", an HTML version of the buffer
408 is written out. If it ends in \".ps\", a postscript version is
409 produced. Otherwise, only the plain text is written to the file.
411 You can also define a set of commands, to create a composite agenda buffer.
412 In this case, an entry looks like this:
414 (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
416 where
418 desc A description string to be displayed in the dispatcher menu.
419 cmd An agenda command, similar to the above. However, tree commands
420 are not allowed, but instead you can get agenda and global todo list.
421 So valid commands for a set are:
422 (agenda \"\" settings)
423 (alltodo \"\" settings)
424 (stuck \"\" settings)
425 (todo \"match\" settings files)
426 (search \"match\" settings files)
427 (tags \"match\" settings files)
428 (tags-todo \"match\" settings files)
430 Each command can carry a list of options, and another set of options can be
431 given for the whole set of commands. Individual command options take
432 precedence over the general options.
434 When using several characters as key to a command, the first characters
435 are prefix commands. For the dispatcher to display useful information, you
436 should provide a description for the prefix, like
438 (setq org-agenda-custom-commands
439 '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
440 (\"hl\" tags \"+HOME+Lisa\")
441 (\"hp\" tags \"+HOME+Peter\")
442 (\"hk\" tags \"+HOME+Kim\")))"
443 :group 'org-agenda-custom-commands
444 :type `(repeat
445 (choice :value ("x" "Describe command here" tags "" nil)
446 (list :tag "Single command"
447 (string :tag "Access Key(s) ")
448 (option (string :tag "Description"))
449 (choice
450 (const :tag "Agenda" agenda)
451 (const :tag "TODO list" alltodo)
452 (const :tag "Search words" search)
453 (const :tag "Stuck projects" stuck)
454 (const :tag "Tags/Property match (all agenda files)" tags)
455 (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
456 (const :tag "TODO keyword search (all agenda files)" todo)
457 (const :tag "Tags sparse tree (current buffer)" tags-tree)
458 (const :tag "TODO keyword tree (current buffer)" todo-tree)
459 (const :tag "Occur tree (current buffer)" occur-tree)
460 (sexp :tag "Other, user-defined function"))
461 (string :tag "Match (only for some commands)")
462 ,org-agenda-custom-commands-local-options
463 (option (repeat :tag "Export" (file :tag "Export to"))))
464 (list :tag "Command series, all agenda files"
465 (string :tag "Access Key(s)")
466 (string :tag "Description ")
467 (repeat :tag "Component"
468 (choice
469 (list :tag "Agenda"
470 (const :format "" agenda)
471 (const :tag "" :format "" "")
472 ,org-agenda-custom-commands-local-options)
473 (list :tag "TODO list (all keywords)"
474 (const :format "" alltodo)
475 (const :tag "" :format "" "")
476 ,org-agenda-custom-commands-local-options)
477 (list :tag "Search words"
478 (const :format "" search)
479 (string :tag "Match")
480 ,org-agenda-custom-commands-local-options)
481 (list :tag "Stuck projects"
482 (const :format "" stuck)
483 (const :tag "" :format "" "")
484 ,org-agenda-custom-commands-local-options)
485 (list :tag "Tags search"
486 (const :format "" tags)
487 (string :tag "Match")
488 ,org-agenda-custom-commands-local-options)
489 (list :tag "Tags search, TODO entries only"
490 (const :format "" tags-todo)
491 (string :tag "Match")
492 ,org-agenda-custom-commands-local-options)
493 (list :tag "TODO keyword search"
494 (const :format "" todo)
495 (string :tag "Match")
496 ,org-agenda-custom-commands-local-options)
497 (list :tag "Other, user-defined function"
498 (symbol :tag "function")
499 (string :tag "Match")
500 ,org-agenda-custom-commands-local-options)))
502 (repeat :tag "Settings for entire command set"
503 (list (variable :tag "Any variable")
504 (sexp :tag "Value")))
505 (option (repeat :tag "Export" (file :tag "Export to"))))
506 (cons :tag "Prefix key documentation"
507 (string :tag "Access Key(s)")
508 (string :tag "Description ")))))
510 (defcustom org-agenda-query-register ?o
511 "The register holding the current query string.
512 The purpose of this is that if you construct a query string interactively,
513 you can then use it to define a custom command."
514 :group 'org-agenda-custom-commands
515 :type 'character)
517 (defcustom org-stuck-projects
518 '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
519 "How to identify stuck projects.
520 This is a list of four items:
521 1. A tags/todo/property matcher string that is used to identify a project.
522 See the manual for a description of tag and property searches.
523 The entire tree below a headline matched by this is considered one project.
524 2. A list of TODO keywords identifying non-stuck projects.
525 If the project subtree contains any headline with one of these todo
526 keywords, the project is considered to be not stuck. If you specify
527 \"*\" as a keyword, any TODO keyword will mark the project unstuck.
528 3. A list of tags identifying non-stuck projects.
529 If the project subtree contains any headline with one of these tags,
530 the project is considered to be not stuck. If you specify \"*\" as
531 a tag, any tag will mark the project unstuck. Note that this is about
532 the explicit presence of a tag somewhere in the subtree, inherited
533 tags to not count here. If inherited tags make a project not stuck,
534 use \"-TAG\" in the tags part of the matcher under (1.) above.
535 4. An arbitrary regular expression matching non-stuck projects.
537 If the project turns out to be not stuck, search continues also in the
538 subtree to see if any of the subtasks have project status.
540 See also the variable `org-tags-match-list-sublevels' which applies
541 to projects matched by this search as well.
543 After defining this variable, you may use \\[org-agenda-list-stuck-projects]
544 or `C-c a #' to produce the list."
545 :group 'org-agenda-custom-commands
546 :type '(list
547 (string :tag "Tags/TODO match to identify a project")
548 (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
549 (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
550 (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
552 (defcustom org-agenda-filter-effort-default-operator "<"
553 "The default operator for effort estimate filtering.
554 If you select an effort estimate limit without first pressing an operator,
555 this one will be used."
556 :group 'org-agenda-custom-commands
557 :type '(choice (const :tag "less or equal" "<")
558 (const :tag "greater or equal"">")
559 (const :tag "equal" "=")))
561 (defgroup org-agenda-skip nil
562 "Options concerning skipping parts of agenda files."
563 :tag "Org Agenda Skip"
564 :group 'org-agenda)
566 (defcustom org-agenda-skip-function-global nil
567 "Function to be called at each match during agenda construction.
568 If this function returns nil, the current match should not be skipped.
569 If the function decided to skip an agenda match, is must return the
570 buffer position from which the search should be continued.
571 This may also be a Lisp form, which will be evaluated.
573 This variable will be applied to every agenda match, including
574 tags/property searches and TODO lists. So try to make the test function
575 do its checking as efficiently as possible. To implement a skipping
576 condition just for specific agenda commands, use the variable
577 `org-agenda-skip-function' which can be set in the options section
578 of custom agenda commands."
579 :group 'org-agenda-skip
580 :type 'sexp)
582 (defgroup org-agenda-daily/weekly nil
583 "Options concerning the daily/weekly agenda."
584 :tag "Org Agenda Daily/Weekly"
585 :group 'org-agenda)
586 (defgroup org-agenda-todo-list nil
587 "Options concerning the global todo list agenda view."
588 :tag "Org Agenda Todo List"
589 :group 'org-agenda)
590 (defgroup org-agenda-match-view nil
591 "Options concerning the general tags/property/todo match agenda view."
592 :tag "Org Agenda Match View"
593 :group 'org-agenda)
594 (defgroup org-agenda-search-view nil
595 "Options concerning the general tags/property/todo match agenda view."
596 :tag "Org Agenda Match View"
597 :group 'org-agenda)
599 (defvar org-agenda-archives-mode nil
600 "Non-nil means the agenda will include archived items.
601 If this is the symbol `trees', trees in the selected agenda scope
602 that are marked with the ARCHIVE tag will be included anyway. When this is
603 t, also all archive files associated with the current selection of agenda
604 files will be included.")
606 (defcustom org-agenda-skip-comment-trees t
607 "Non-nil means skip trees that start with the COMMENT keyword.
608 When nil, these trees are also scanned by agenda commands."
609 :group 'org-agenda-skip
610 :type 'boolean)
612 (defcustom org-agenda-todo-list-sublevels t
613 "Non-nil means check also the sublevels of a TODO entry for TODO entries.
614 When nil, the sublevels of a TODO entry are not checked, resulting in
615 potentially much shorter TODO lists."
616 :group 'org-agenda-skip
617 :group 'org-agenda-todo-list
618 :type 'boolean)
620 (defcustom org-agenda-todo-ignore-with-date nil
621 "Non-nil means don't show entries with a date in the global todo list.
622 You can use this if you prefer to mark mere appointments with a TODO keyword,
623 but don't want them to show up in the TODO list.
624 When this is set, it also covers deadlines and scheduled items, the settings
625 of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
626 will be ignored.
627 See also the variable `org-agenda-tags-todo-honor-ignore-options'."
628 :group 'org-agenda-skip
629 :group 'org-agenda-todo-list
630 :type 'boolean)
632 (defcustom org-agenda-todo-ignore-timestamp nil
633 "Non-nil means don't show entries with a timestamp.
634 This applies when creating the global todo list.
635 Valid values are:
637 past Don't show entries for today or in the past.
639 future Don't show entries with a timestamp in the future.
640 The idea behind this is that if it has a future
641 timestamp, you don't want to think about it until the
642 date.
644 all Don't show any entries with a timestamp in the global todo list.
645 The idea behind this is that by setting a timestamp, you
646 have already \"taken care\" of this item.
648 This variable can also have an integer as a value. If positive (N),
649 todos with a timestamp N or more days in the future will be ignored. If
650 negative (-N), todos with a timestamp N or more days in the past will be
651 ignored. If 0, todos with a timestamp either today or in the future will
652 be ignored. For example, a value of -1 will exclude todos with a
653 timestamp in the past (yesterday or earlier), while a value of 7 will
654 exclude todos with a timestamp a week or more in the future.
656 See also `org-agenda-todo-ignore-with-date'.
657 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
658 to make his option also apply to the tags-todo list."
659 :group 'org-agenda-skip
660 :group 'org-agenda-todo-list
661 :version "24.1"
662 :type '(choice
663 (const :tag "Ignore future timestamp todos" future)
664 (const :tag "Ignore past or present timestamp todos" past)
665 (const :tag "Ignore all timestamp todos" all)
666 (const :tag "Show timestamp todos" nil)
667 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
669 (defcustom org-agenda-todo-ignore-scheduled nil
670 "Non-nil means, ignore some scheduled TODO items when making TODO list.
671 This applies when creating the global todo list.
672 Valid values are:
674 past Don't show entries scheduled today or in the past.
676 future Don't show entries scheduled in the future.
677 The idea behind this is that by scheduling it, you don't want to
678 think about it until the scheduled date.
680 all Don't show any scheduled entries in the global todo list.
681 The idea behind this is that by scheduling it, you have already
682 \"taken care\" of this item.
684 t Same as `all', for backward compatibility.
686 This variable can also have an integer as a value. See
687 `org-agenda-todo-ignore-timestamp' for more details.
689 See also `org-agenda-todo-ignore-with-date'.
690 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
691 to make his option also apply to the tags-todo list."
692 :group 'org-agenda-skip
693 :group 'org-agenda-todo-list
694 :type '(choice
695 (const :tag "Ignore future-scheduled todos" future)
696 (const :tag "Ignore past- or present-scheduled todos" past)
697 (const :tag "Ignore all scheduled todos" all)
698 (const :tag "Ignore all scheduled todos (compatibility)" t)
699 (const :tag "Show scheduled todos" nil)
700 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
702 (defcustom org-agenda-todo-ignore-deadlines nil
703 "Non-nil means ignore some deadlined TODO items when making TODO list.
704 There are different motivations for using different values, please think
705 carefully when configuring this variable.
707 This applies when creating the global todo list.
708 Valid values are:
710 near Don't show near deadline entries. A deadline is near when it is
711 closer than `org-deadline-warning-days' days. The idea behind this
712 is that such items will appear in the agenda anyway.
714 far Don't show TODO entries where a deadline has been defined, but
715 the deadline is not near. This is useful if you don't want to
716 use the todo list to figure out what to do now.
718 past Don't show entries with a deadline timestamp for today or in the past.
720 future Don't show entries with a deadline timestamp in the future, not even
721 when they become `near' ones. Use it with caution.
723 all Ignore all TODO entries that do have a deadline.
725 t Same as `near', for backward compatibility.
727 This variable can also have an integer as a value. See
728 `org-agenda-todo-ignore-timestamp' for more details.
730 See also `org-agenda-todo-ignore-with-date'.
731 See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
732 to make his option also apply to the tags-todo list."
733 :group 'org-agenda-skip
734 :group 'org-agenda-todo-list
735 :type '(choice
736 (const :tag "Ignore near deadlines" near)
737 (const :tag "Ignore near deadlines (compatibility)" t)
738 (const :tag "Ignore far deadlines" far)
739 (const :tag "Ignore all TODOs with a deadlines" all)
740 (const :tag "Show all TODOs, even if they have a deadline" nil)
741 (integer :tag "Ignore if N or more days in past(-) or future(+).")))
743 (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
744 "Time unit to use when possibly ignoring an agenda item.
746 See the docstring of various `org-agenda-todo-ignore-*' options.
747 The default is to compare time stamps using days. An item is thus
748 considered to be in the future if it is at least one day after today.
749 Non-nil means to compare time stamps using seconds. An item is then
750 considered future if it has a time value later than current time."
751 :group 'org-agenda-skip
752 :group 'org-agenda-todo-list
753 :type '(choice
754 (const :tag "Compare time with days" nil)
755 (const :tag "Compare time with seconds" t)))
757 (defcustom org-agenda-tags-todo-honor-ignore-options nil
758 "Non-nil means honor todo-list ...ignore options also in tags-todo search.
759 The variables
760 `org-agenda-todo-ignore-with-date',
761 `org-agenda-todo-ignore-timestamp',
762 `org-agenda-todo-ignore-scheduled',
763 `org-agenda-todo-ignore-deadlines'
764 make the global TODO list skip entries that have time stamps of certain
765 kinds. If this option is set, the same options will also apply for the
766 tags-todo search, which is the general tags/property matcher
767 restricted to unfinished TODO entries only."
768 :group 'org-agenda-skip
769 :group 'org-agenda-todo-list
770 :group 'org-agenda-match-view
771 :type 'boolean)
773 (defcustom org-agenda-skip-scheduled-if-done nil
774 "Non-nil means don't show scheduled items in agenda when they are done.
775 This is relevant for the daily/weekly agenda, not for the TODO list. And
776 it applies only to the actual date of the scheduling. Warnings about
777 an item with a past scheduling dates are always turned off when the item
778 is DONE."
779 :group 'org-agenda-skip
780 :group 'org-agenda-daily/weekly
781 :type 'boolean)
783 (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
784 "Non-nil means skip scheduling line if same entry shows because of deadline.
785 In the agenda of today, an entry can show up multiple times because
786 it is both scheduled and has a nearby deadline, and maybe a plain time
787 stamp as well.
788 When this variable is t, then only the deadline is shown and the fact that
789 the entry is scheduled today or was scheduled previously is not shown.
790 When this variable is nil, the entry will be shown several times. When
791 the variable is the symbol `not-today', then skip scheduled previously,
792 but not scheduled today."
793 :group 'org-agenda-skip
794 :group 'org-agenda-daily/weekly
795 :type '(choice
796 (const :tag "Never" nil)
797 (const :tag "Always" t)
798 (const :tag "Not when scheduled today" not-today)))
800 (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
801 "Non-nil means skip timestamp line if same entry shows because of deadline.
802 In the agenda of today, an entry can show up multiple times
803 because it has both a plain timestamp and has a nearby deadline.
804 When this variable is t, then only the deadline is shown and the
805 fact that the entry has a timestamp for or including today is not
806 shown. When this variable is nil, the entry will be shown
807 several times."
808 :group 'org-agenda-skip
809 :group 'org-agenda-daily/weekly
810 :version "24.1"
811 :type '(choice
812 (const :tag "Never" nil)
813 (const :tag "Always" t)))
815 (defcustom org-agenda-skip-deadline-if-done nil
816 "Non-nil means don't show deadlines when the corresponding item is done.
817 When nil, the deadline is still shown and should give you a happy feeling.
818 This is relevant for the daily/weekly agenda. And it applied only to the
819 actually date of the deadline. Warnings about approaching and past-due
820 deadlines are always turned off when the item is DONE."
821 :group 'org-agenda-skip
822 :group 'org-agenda-daily/weekly
823 :type 'boolean)
825 (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
826 "Non-nil means skip deadline prewarning when entry is also scheduled.
827 This will apply on all days where a prewarning for the deadline would
828 be shown, but not at the day when the entry is actually due. On that day,
829 the deadline will be shown anyway.
830 This variable may be set to nil, t, the symbol `pre-scheduled',
831 or a number which will then give the number of days before the actual
832 deadline when the prewarnings should resume. The symbol `pre-scheduled'
833 eliminates the deadline prewarning only prior to the scheduled date.
834 This can be used in a workflow where the first showing of the deadline will
835 trigger you to schedule it, and then you don't want to be reminded of it
836 because you will take care of it on the day when scheduled."
837 :group 'org-agenda-skip
838 :group 'org-agenda-daily/weekly
839 :version "24.1"
840 :type '(choice
841 (const :tag "Always show prewarning" nil)
842 (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
843 (const :tag "Remove prewarning if entry is scheduled" t)
844 (integer :tag "Restart prewarning N days before deadline")))
846 (defcustom org-agenda-skip-additional-timestamps-same-entry nil
847 "When nil, multiple same-day timestamps in entry make multiple agenda lines.
848 When non-nil, after the search for timestamps has matched once in an
849 entry, the rest of the entry will not be searched."
850 :group 'org-agenda-skip
851 :type 'boolean)
853 (defcustom org-agenda-skip-timestamp-if-done nil
854 "Non-nil means don't select item by timestamp or -range if it is DONE."
855 :group 'org-agenda-skip
856 :group 'org-agenda-daily/weekly
857 :type 'boolean)
859 (defcustom org-agenda-dim-blocked-tasks nil
860 "Non-nil means dim blocked tasks in the agenda display.
861 This causes some overhead during agenda construction, but if you
862 have turned on `org-enforce-todo-dependencies',
863 `org-enforce-todo-checkbox-dependencies', or any other blocking
864 mechanism, this will create useful feedback in the agenda.
866 Instead of t, this variable can also have the value `invisible'.
867 Then blocked tasks will be invisible and only become visible when
868 they become unblocked. An exemption to this behavior is when a task is
869 blocked because of unchecked checkboxes below it. Since checkboxes do
870 not show up in the agenda views, making this task invisible you remove any
871 trace from agenda views that there is something to do. Therefore, a task
872 that is blocked because of checkboxes will never be made invisible, it
873 will only be dimmed."
874 :group 'org-agenda-daily/weekly
875 :group 'org-agenda-todo-list
876 :version "24.3"
877 :type '(choice
878 (const :tag "Do not dim" nil)
879 (const :tag "Dim to a gray face" t)
880 (const :tag "Make invisible" invisible)))
882 (defcustom org-timeline-show-empty-dates 3
883 "Non-nil means `org-timeline' also shows dates without an entry.
884 When nil, only the days which actually have entries are shown.
885 When t, all days between the first and the last date are shown.
886 When an integer, show also empty dates, but if there is a gap of more than
887 N days, just insert a special line indicating the size of the gap."
888 :group 'org-agenda-skip
889 :type '(choice
890 (const :tag "None" nil)
891 (const :tag "All" t)
892 (integer :tag "at most")))
894 (defgroup org-agenda-startup nil
895 "Options concerning initial settings in the Agenda in Org Mode."
896 :tag "Org Agenda Startup"
897 :group 'org-agenda)
899 (defcustom org-agenda-menu-show-matcher t
900 "Non-nil means show the match string in the agenda dispatcher menu.
901 When nil, the matcher string is not shown, but is put into the help-echo
902 property so than moving the mouse over the command shows it.
903 Setting it to nil is good if matcher strings are very long and/or if
904 you want to use two-columns display (see `org-agenda-menu-two-columns')."
905 :group 'org-agenda
906 :version "24.1"
907 :type 'boolean)
909 (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
911 (defcustom org-agenda-menu-two-columns nil
912 "Non-nil means, use two columns to show custom commands in the dispatcher.
913 If you use this, you probably want to set `org-agenda-menu-show-matcher'
914 to nil."
915 :group 'org-agenda
916 :version "24.1"
917 :type 'boolean)
919 (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
920 (defcustom org-agenda-finalize-hook nil
921 "Hook run just before displaying an agenda buffer.
922 The buffer is still writable when the hook is called.
924 You can modify some of the buffer substrings but you should be
925 extra careful not to modify the text properties of the agenda
926 headlines as the agenda display heavily relies on them."
927 :group 'org-agenda-startup
928 :type 'hook)
930 (defcustom org-agenda-mouse-1-follows-link nil
931 "Non-nil means mouse-1 on a link will follow the link in the agenda.
932 A longer mouse click will still set point. Does not work on XEmacs.
933 Needs to be set before org.el is loaded."
934 :group 'org-agenda-startup
935 :type 'boolean)
937 (defcustom org-agenda-start-with-follow-mode nil
938 "The initial value of follow mode in a newly created agenda window."
939 :group 'org-agenda-startup
940 :type 'boolean)
942 (defcustom org-agenda-follow-indirect nil
943 "Non-nil means `org-agenda-follow-mode' displays only the
944 current item's tree, in an indirect buffer."
945 :group 'org-agenda
946 :version "24.1"
947 :type 'boolean)
949 (defcustom org-agenda-show-outline-path t
950 "Non-nil means show outline path in echo area after line motion."
951 :group 'org-agenda-startup
952 :type 'boolean)
954 (defcustom org-agenda-start-with-entry-text-mode nil
955 "The initial value of entry-text-mode in a newly created agenda window."
956 :group 'org-agenda-startup
957 :type 'boolean)
959 (defcustom org-agenda-entry-text-maxlines 5
960 "Number of text lines to be added when `E' is pressed in the agenda.
962 Note that this variable only used during agenda display. Add add entry text
963 when exporting the agenda, configure the variable
964 `org-agenda-add-entry-ext-maxlines'."
965 :group 'org-agenda
966 :type 'integer)
968 (defcustom org-agenda-entry-text-exclude-regexps nil
969 "List of regular expressions to clean up entry text.
970 The complete matches of all regular expressions in this list will be
971 removed from entry text before it is shown in the agenda."
972 :group 'org-agenda
973 :type '(repeat (regexp)))
975 (defvar org-agenda-entry-text-cleanup-hook nil
976 "Hook that is run after basic cleanup of entry text to be shown in agenda.
977 This cleanup is done in a temporary buffer, so the function may inspect and
978 change the entire buffer.
979 Some default stuff like drawers and scheduling/deadline dates will already
980 have been removed when this is called, as will any matches for regular
981 expressions listed in `org-agenda-entry-text-exclude-regexps'.")
983 (defvar org-agenda-include-inactive-timestamps nil
984 "Non-nil means include inactive time stamps in agenda and timeline.
985 Dynamically scoped.")
987 (defgroup org-agenda-windows nil
988 "Options concerning the windows used by the Agenda in Org Mode."
989 :tag "Org Agenda Windows"
990 :group 'org-agenda)
992 (defcustom org-agenda-window-setup 'reorganize-frame
993 "How the agenda buffer should be displayed.
994 Possible values for this option are:
996 current-window Show agenda in the current window, keeping all other windows.
997 other-window Use `switch-to-buffer-other-window' to display agenda.
998 reorganize-frame Show only two windows on the current frame, the current
999 window and the agenda.
1000 other-frame Use `switch-to-buffer-other-frame' to display agenda.
1001 Also, when exiting the agenda, kill that frame.
1002 See also the variable `org-agenda-restore-windows-after-quit'."
1003 :group 'org-agenda-windows
1004 :type '(choice
1005 (const current-window)
1006 (const other-frame)
1007 (const other-window)
1008 (const reorganize-frame)))
1010 (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
1011 "The min and max height of the agenda window as a fraction of frame height.
1012 The value of the variable is a cons cell with two numbers between 0 and 1.
1013 It only matters if `org-agenda-window-setup' is `reorganize-frame'."
1014 :group 'org-agenda-windows
1015 :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
1017 (defcustom org-agenda-restore-windows-after-quit nil
1018 "Non-nil means restore window configuration upon exiting agenda.
1019 Before the window configuration is changed for displaying the agenda,
1020 the current status is recorded. When the agenda is exited with
1021 `q' or `x' and this option is set, the old state is restored. If
1022 `org-agenda-window-setup' is `other-frame', the value of this
1023 option will be ignored."
1024 :group 'org-agenda-windows
1025 :type 'boolean)
1027 (defcustom org-agenda-ndays nil
1028 "Number of days to include in overview display.
1029 Should be 1 or 7.
1030 Obsolete, see `org-agenda-span'."
1031 :group 'org-agenda-daily/weekly
1032 :type 'integer)
1034 (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
1036 (defcustom org-agenda-span 'week
1037 "Number of days to include in overview display.
1038 Can be day, week, month, year, or any number of days.
1039 Custom commands can set this variable in the options section."
1040 :group 'org-agenda-daily/weekly
1041 :type '(choice (const :tag "Day" day)
1042 (const :tag "Week" week)
1043 (const :tag "Month" month)
1044 (const :tag "Year" year)
1045 (integer :tag "Custom")))
1047 (defcustom org-agenda-start-on-weekday 1
1048 "Non-nil means start the overview always on the specified weekday.
1049 0 denotes Sunday, 1 denotes Monday etc.
1050 When nil, always start on the current day.
1051 Custom commands can set this variable in the options section."
1052 :group 'org-agenda-daily/weekly
1053 :type '(choice (const :tag "Today" nil)
1054 (integer :tag "Weekday No.")))
1056 (defcustom org-agenda-show-all-dates t
1057 "Non-nil means `org-agenda' shows every day in the selected range.
1058 When nil, only the days which actually have entries are shown."
1059 :group 'org-agenda-daily/weekly
1060 :type 'boolean)
1062 (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
1063 "Format string for displaying dates in the agenda.
1064 Used by the daily/weekly agenda and by the timeline. This should be
1065 a format string understood by `format-time-string', or a function returning
1066 the formatted date as a string. The function must take a single argument,
1067 a calendar-style date list like (month day year)."
1068 :group 'org-agenda-daily/weekly
1069 :type '(choice
1070 (string :tag "Format string")
1071 (function :tag "Function")))
1073 (defun org-agenda-format-date-aligned (date)
1074 "Format a date string for display in the daily/weekly agenda, or timeline.
1075 This function makes sure that dates are aligned for easy reading."
1076 (require 'cal-iso)
1077 (let* ((dayname (calendar-day-name date))
1078 (day (cadr date))
1079 (day-of-week (calendar-day-of-week date))
1080 (month (car date))
1081 (monthname (calendar-month-name month))
1082 (year (nth 2 date))
1083 (iso-week (org-days-to-iso-week
1084 (calendar-absolute-from-gregorian date)))
1085 (weekyear (cond ((and (= month 1) (>= iso-week 52))
1086 (1- year))
1087 ((and (= month 12) (<= iso-week 1))
1088 (1+ year))
1089 (t year)))
1090 (weekstring (if (= day-of-week 1)
1091 (format " W%02d" iso-week)
1092 "")))
1093 (format "%-10s %2d %s %4d%s"
1094 dayname day monthname year weekstring)))
1096 (defcustom org-agenda-time-leading-zero nil
1097 "Non-nil means use leading zero for military times in agenda.
1098 For example, 9:30am would become 09:30 rather than 9:30."
1099 :group 'org-agenda-daily/weekly
1100 :version "24.1"
1101 :type 'boolean)
1103 (defcustom org-agenda-timegrid-use-ampm nil
1104 "When set, show AM/PM style timestamps on the timegrid."
1105 :group 'org-agenda
1106 :version "24.1"
1107 :type 'boolean)
1109 (defun org-agenda-time-of-day-to-ampm (time)
1110 "Convert TIME of a string like '13:45' to an AM/PM style time string."
1111 (let* ((hour-number (string-to-number (substring time 0 -3)))
1112 (minute (substring time -2))
1113 (ampm "am"))
1114 (cond
1115 ((equal hour-number 12)
1116 (setq ampm "pm"))
1117 ((> hour-number 12)
1118 (setq ampm "pm")
1119 (setq hour-number (- hour-number 12))))
1120 (concat
1121 (if org-agenda-time-leading-zero
1122 (format "%02d" hour-number)
1123 (format "%02s" (number-to-string hour-number)))
1124 ":" minute ampm)))
1126 (defun org-agenda-time-of-day-to-ampm-maybe (time)
1127 "Conditionally convert TIME to AM/PM format
1128 based on `org-agenda-timegrid-use-ampm'"
1129 (if org-agenda-timegrid-use-ampm
1130 (org-agenda-time-of-day-to-ampm time)
1131 time))
1133 (defcustom org-agenda-weekend-days '(6 0)
1134 "Which days are weekend?
1135 These days get the special face `org-agenda-date-weekend' in the agenda
1136 and timeline buffers."
1137 :group 'org-agenda-daily/weekly
1138 :type '(set :greedy t
1139 (const :tag "Monday" 1)
1140 (const :tag "Tuesday" 2)
1141 (const :tag "Wednesday" 3)
1142 (const :tag "Thursday" 4)
1143 (const :tag "Friday" 5)
1144 (const :tag "Saturday" 6)
1145 (const :tag "Sunday" 0)))
1147 (defcustom org-agenda-move-date-from-past-immediately-to-today t
1148 "Non-nil means jump to today when moving a past date forward in time.
1149 When using S-right in the agenda to move a a date forward, and the date
1150 stamp currently points to the past, the first key press will move it
1151 to today. WHen nil, just move one day forward even if the date stays
1152 in the past."
1153 :group 'org-agenda-daily/weekly
1154 :version "24.1"
1155 :type 'boolean)
1157 (defcustom org-agenda-include-diary nil
1158 "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
1159 Custom commands can set this variable in the options section."
1160 :group 'org-agenda-daily/weekly
1161 :type 'boolean)
1163 (defcustom org-agenda-include-deadlines t
1164 "If non-nil, include entries within their deadline warning period.
1165 Custom commands can set this variable in the options section."
1166 :group 'org-agenda-daily/weekly
1167 :version "24.1"
1168 :type 'boolean)
1170 (defcustom org-agenda-repeating-timestamp-show-all t
1171 "Non-nil means show all occurrences of a repeating stamp in the agenda.
1172 When set to a list of strings, only show occurrences of repeating
1173 stamps for these TODO keywords. When nil, only one occurrence is
1174 shown, either today or the nearest into the future."
1175 :group 'org-agenda-daily/weekly
1176 :type '(choice
1177 (const :tag "Show repeating stamps" t)
1178 (repeat :tag "Show repeating stamps for these TODO keywords"
1179 (string :tag "TODO Keyword"))
1180 (const :tag "Don't show repeating stamps" nil)))
1182 (defcustom org-scheduled-past-days 10000
1183 "No. of days to continue listing scheduled items that are not marked DONE.
1184 When an item is scheduled on a date, it shows up in the agenda on this
1185 day and will be listed until it is marked done for the number of days
1186 given here."
1187 :group 'org-agenda-daily/weekly
1188 :type 'integer)
1190 (defcustom org-agenda-log-mode-items '(closed clock)
1191 "List of items that should be shown in agenda log mode.
1192 This list may contain the following symbols:
1194 closed Show entries that have been closed on that day.
1195 clock Show entries that have received clocked time on that day.
1196 state Show all logged state changes.
1197 Note that instead of changing this variable, you can also press `C-u l' in
1198 the agenda to display all available LOG items temporarily."
1199 :group 'org-agenda-daily/weekly
1200 :type '(set :greedy t (const closed) (const clock) (const state)))
1202 (defcustom org-agenda-clock-consistency-checks
1203 '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
1204 :gap-ok-around ("4:00")
1205 :default-face ((:background "DarkRed") (:foreground "white"))
1206 :overlap-face nil :gap-face nil :no-end-time-face nil
1207 :long-face nil :short-face nil)
1208 "This is a property list, with the following keys:
1210 :max-duration Mark clocking chunks that are longer than this time.
1211 This is a time string like \"HH:MM\", or the number
1212 of minutes as an integer.
1214 :min-duration Mark clocking chunks that are shorter that this.
1215 This is a time string like \"HH:MM\", or the number
1216 of minutes as an integer.
1218 :max-gap Mark gaps between clocking chunks that are longer than
1219 this duration. A number of minutes, or a string
1220 like \"HH:MM\".
1222 :gap-ok-around List of times during the day which are usually not working
1223 times. When a gap is detected, but the gap contains any
1224 of these times, the gap is *not* reported. For example,
1225 if this is (\"4:00\" \"13:00\") then gaps that contain
1226 4:00 in the morning (i.e. the night) and 13:00
1227 (i.e. a typical lunch time) do not cause a warning.
1228 You should have at least one time during the night in this
1229 list, or otherwise the first task each morning will trigger
1230 a warning because it follows a long gap.
1232 Furthermore, the following properties can be used to define faces for
1233 issue display.
1235 :default-face the default face, if the specific face is undefined
1236 :overlap-face face for overlapping clocks
1237 :gap-face face for gaps between clocks
1238 :no-end-time-face face for incomplete clocks
1239 :long-face face for clock intervals that are too long
1240 :short-face face for clock intervals that are too short"
1241 :group 'org-agenda-daily/weekly
1242 :group 'org-clock
1243 :version "24.1"
1244 :type 'plist)
1246 (defcustom org-agenda-log-mode-add-notes t
1247 "Non-nil means add first line of notes to log entries in agenda views.
1248 If a log item like a state change or a clock entry is associated with
1249 notes, the first line of these notes will be added to the entry in the
1250 agenda display."
1251 :group 'org-agenda-daily/weekly
1252 :type 'boolean)
1254 (defcustom org-agenda-start-with-log-mode nil
1255 "The initial value of log-mode in a newly created agenda window.
1256 See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
1257 explanations on the possible values."
1258 :group 'org-agenda-startup
1259 :group 'org-agenda-daily/weekly
1260 :type '(choice (const :tag "Don't show log items" nil)
1261 (const :tag "Show only log items" 'only)
1262 (const :tag "Show all possible log items" 'clockcheck)
1263 (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
1264 (choice (const :tag "Show closed log items" 'closed)
1265 (const :tag "Show clocked log items" 'clock)
1266 (const :tag "Show all logged state changes" 'state)))))
1268 (defcustom org-agenda-start-with-clockreport-mode nil
1269 "The initial value of clockreport-mode in a newly created agenda window."
1270 :group 'org-agenda-startup
1271 :group 'org-agenda-daily/weekly
1272 :type 'boolean)
1274 (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
1275 "Property list with parameters for the clocktable in clockreport mode.
1276 This is the display mode that shows a clock table in the daily/weekly
1277 agenda, the properties for this dynamic block can be set here.
1278 The usual clocktable parameters are allowed here, but you cannot set
1279 the properties :name, :tstart, :tend, :block, and :scope - these will
1280 be overwritten to make sure the content accurately reflects the
1281 current display in the agenda."
1282 :group 'org-agenda-daily/weekly
1283 :type 'plist)
1285 (defcustom org-agenda-search-view-always-boolean nil
1286 "Non-nil means the search string is interpreted as individual parts.
1288 The search string for search view can either be interpreted as a phrase,
1289 or as a list of snippets that define a boolean search for a number of
1290 strings.
1292 When this is non-nil, the string will be split on whitespace, and each
1293 snippet will be searched individually, and all must match in order to
1294 select an entry. A snippet is then a single string of non-white
1295 characters, or a string in double quotes, or a regexp in {} braces.
1296 If a snippet is preceded by \"-\", the snippet must *not* match.
1297 \"+\" is syntactic sugar for positive selection. Each snippet may
1298 be found as a full word or a partial word, but see the variable
1299 `org-agenda-search-view-force-full-words'.
1301 When this is nil, search will look for the entire search phrase as one,
1302 with each space character matching any amount of whitespace, including
1303 line breaks.
1305 Even when this is nil, you can still switch to Boolean search dynamically
1306 by preceding the first snippet with \"+\" or \"-\". If the first snippet
1307 is a regexp marked with braces like \"{abc}\", this will also switch to
1308 boolean search."
1309 :group 'org-agenda-search-view
1310 :version "24.1"
1311 :type 'boolean)
1313 (if (fboundp 'defvaralias)
1314 (defvaralias 'org-agenda-search-view-search-words-only
1315 'org-agenda-search-view-always-boolean))
1317 (defcustom org-agenda-search-view-force-full-words nil
1318 "Non-nil means, search words must be matches as complete words.
1319 When nil, they may also match part of a word."
1320 :group 'org-agenda-search-view
1321 :version "24.1"
1322 :type 'boolean)
1324 (defcustom org-agenda-search-view-max-outline-level nil
1325 "Maximum outline level to display in search view.
1326 E.g. when this is set to 1, the search view will only
1327 show headlines of level 1."
1328 :group 'org-agenda-search-view
1329 :version "24.3"
1330 :type 'integer)
1332 (defgroup org-agenda-time-grid nil
1333 "Options concerning the time grid in the Org-mode Agenda."
1334 :tag "Org Agenda Time Grid"
1335 :group 'org-agenda)
1337 (defcustom org-agenda-search-headline-for-time t
1338 "Non-nil means search headline for a time-of-day.
1339 If the headline contains a time-of-day in one format or another, it will
1340 be used to sort the entry into the time sequence of items for a day.
1341 Some people have time stamps in the headline that refer to the creation
1342 time or so, and then this produces an unwanted side effect. If this is
1343 the case for your, use this variable to turn off searching the headline
1344 for a time."
1345 :group 'org-agenda-time-grid
1346 :type 'boolean)
1348 (defcustom org-agenda-use-time-grid t
1349 "Non-nil means show a time grid in the agenda schedule.
1350 A time grid is a set of lines for specific times (like every two hours between
1351 8:00 and 20:00). The items scheduled for a day at specific times are
1352 sorted in between these lines.
1353 For details about when the grid will be shown, and what it will look like, see
1354 the variable `org-agenda-time-grid'."
1355 :group 'org-agenda-time-grid
1356 :type 'boolean)
1358 (defcustom org-agenda-time-grid
1359 '((daily today require-timed)
1360 "----------------"
1361 (800 1000 1200 1400 1600 1800 2000))
1363 "The settings for time grid for agenda display.
1364 This is a list of three items. The first item is again a list. It contains
1365 symbols specifying conditions when the grid should be displayed:
1367 daily if the agenda shows a single day
1368 weekly if the agenda shows an entire week
1369 today show grid on current date, independent of daily/weekly display
1370 require-timed show grid only if at least one item has a time specification
1372 The second item is a string which will be placed behind the grid time.
1374 The third item is a list of integers, indicating the times that should have
1375 a grid line."
1376 :group 'org-agenda-time-grid
1377 :type
1378 '(list
1379 (set :greedy t :tag "Grid Display Options"
1380 (const :tag "Show grid in single day agenda display" daily)
1381 (const :tag "Show grid in weekly agenda display" weekly)
1382 (const :tag "Always show grid for today" today)
1383 (const :tag "Show grid only if any timed entries are present"
1384 require-timed)
1385 (const :tag "Skip grid times already present in an entry"
1386 remove-match))
1387 (string :tag "Grid String")
1388 (repeat :tag "Grid Times" (integer :tag "Time"))))
1390 (defcustom org-agenda-show-current-time-in-grid t
1391 "Non-nil means show the current time in the time grid."
1392 :group 'org-agenda-time-grid
1393 :version "24.1"
1394 :type 'boolean)
1396 (defcustom org-agenda-current-time-string
1397 "now - - - - - - - - - - - - - - - - - - - - - - - - -"
1398 "The string for the current time marker in the agenda."
1399 :group 'org-agenda-time-grid
1400 :version "24.1"
1401 :type 'string)
1403 (defgroup org-agenda-sorting nil
1404 "Options concerning sorting in the Org-mode Agenda."
1405 :tag "Org Agenda Sorting"
1406 :group 'org-agenda)
1408 (defcustom org-agenda-sorting-strategy
1409 '((agenda habit-down time-up priority-down category-keep)
1410 (todo priority-down category-keep)
1411 (tags priority-down category-keep)
1412 (search category-keep))
1413 "Sorting structure for the agenda items of a single day.
1414 This is a list of symbols which will be used in sequence to determine
1415 if an entry should be listed before another entry. The following
1416 symbols are recognized:
1418 time-up Put entries with time-of-day indications first, early first
1419 time-down Put entries with time-of-day indications first, late first
1420 category-keep Keep the default order of categories, corresponding to the
1421 sequence in `org-agenda-files'.
1422 category-up Sort alphabetically by category, A-Z.
1423 category-down Sort alphabetically by category, Z-A.
1424 tag-up Sort alphabetically by last tag, A-Z.
1425 tag-down Sort alphabetically by last tag, Z-A.
1426 priority-up Sort numerically by priority, high priority last.
1427 priority-down Sort numerically by priority, high priority first.
1428 todo-state-up Sort by todo state, tasks that are done last.
1429 todo-state-down Sort by todo state, tasks that are done first.
1430 effort-up Sort numerically by estimated effort, high effort last.
1431 effort-down Sort numerically by estimated effort, high effort first.
1432 user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
1433 user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
1434 habit-up Put entries that are habits first
1435 habit-down Put entries that are habits last
1436 alpha-up Sort headlines alphabetically
1437 alpha-down Sort headlines alphabetically, reversed
1439 The different possibilities will be tried in sequence, and testing stops
1440 if one comparison returns a \"not-equal\". For example, the default
1441 '(time-up category-keep priority-down)
1442 means: Pull out all entries having a specified time of day and sort them,
1443 in order to make a time schedule for the current day the first thing in the
1444 agenda listing for the day. Of the entries without a time indication, keep
1445 the grouped in categories, don't sort the categories, but keep them in
1446 the sequence given in `org-agenda-files'. Within each category sort by
1447 priority.
1449 Leaving out `category-keep' would mean that items will be sorted across
1450 categories by priority.
1452 Instead of a single list, this can also be a set of list for specific
1453 contents, with a context symbol in the car of the list, any of
1454 `agenda', `todo', `tags', `search' for the corresponding agenda views.
1456 Custom commands can bind this variable in the options section."
1457 :group 'org-agenda-sorting
1458 :type `(choice
1459 (repeat :tag "General" ,org-sorting-choice)
1460 (list :tag "Individually"
1461 (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
1462 (repeat ,org-sorting-choice))
1463 (cons (const :tag "Strategy for TODO lists" todo)
1464 (repeat ,org-sorting-choice))
1465 (cons (const :tag "Strategy for Tags matches" tags)
1466 (repeat ,org-sorting-choice))
1467 (cons (const :tag "Strategy for search matches" search)
1468 (repeat ,org-sorting-choice)))))
1470 (defcustom org-agenda-cmp-user-defined nil
1471 "A function to define the comparison `user-defined'.
1472 This function must receive two arguments, agenda entry a and b.
1473 If a>b, return +1. If a<b, return -1. If they are equal as seen by
1474 the user comparison, return nil.
1475 When this is defined, you can make `user-defined-up' and `user-defined-down'
1476 part of an agenda sorting strategy."
1477 :group 'org-agenda-sorting
1478 :type 'symbol)
1480 (defcustom org-sort-agenda-notime-is-late t
1481 "Non-nil means items without time are considered late.
1482 This is only relevant for sorting. When t, items which have no explicit
1483 time like 15:30 will be considered as 99:01, i.e. later than any items which
1484 do have a time. When nil, the default time is before 0:00. You can use this
1485 option to decide if the schedule for today should come before or after timeless
1486 agenda entries."
1487 :group 'org-agenda-sorting
1488 :type 'boolean)
1490 (defcustom org-sort-agenda-noeffort-is-high t
1491 "Non-nil means items without effort estimate are sorted as high effort.
1492 This also applies when filtering an agenda view with respect to the
1493 < or > effort operator. Then, tasks with no effort defined will be treated
1494 as tasks with high effort.
1495 When nil, such items are sorted as 0 minutes effort."
1496 :group 'org-agenda-sorting
1497 :type 'boolean)
1499 (defgroup org-agenda-line-format nil
1500 "Options concerning the entry prefix in the Org-mode agenda display."
1501 :tag "Org Agenda Line Format"
1502 :group 'org-agenda)
1504 (defcustom org-agenda-prefix-format
1505 '((agenda . " %i %-12:c%?-12t% s")
1506 (timeline . " % s")
1507 (todo . " %i %-12:c")
1508 (tags . " %i %-12:c")
1509 (search . " %i %-12:c"))
1510 "Format specifications for the prefix of items in the agenda views.
1511 An alist with five entries, each for the different agenda types. The
1512 keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
1513 The values are format strings.
1515 This format works similar to a printf format, with the following meaning:
1517 %c the category of the item, \"Diary\" for entries from the diary,
1518 or as given by the CATEGORY keyword or derived from the file name
1519 %e the effort required by the item
1520 %l the level of the item (insert X space(s) if item is of level X)
1521 %i the icon category of the item, see `org-agenda-category-icon-alist'
1522 %T the last tag of the item (ignore inherited tags, which come first)
1523 %t the HH:MM time-of-day specification if one applies to the entry
1524 %s Scheduling/Deadline information, a short string
1525 %(expression) Eval EXPRESSION and replace the control string
1526 by the result
1528 All specifiers work basically like the standard `%s' of printf, but may
1529 contain two additional characters: a question mark just after the `%'
1530 and a whitespace/punctuation character just before the final letter.
1532 If the first character after `%' is a question mark, the entire field
1533 will only be included if the corresponding value applies to the current
1534 entry. This is useful for fields which should have fixed width when
1535 present, but zero width when absent. For example, \"%?-12t\" will
1536 result in a 12 character time field if a time of the day is specified,
1537 but will completely disappear in entries which do not contain a time.
1539 If there is punctuation or whitespace character just before the final
1540 format letter, this character will be appended to the field value if
1541 the value is not empty. For example, the format \"%-12:c\" leads to
1542 \"Diary: \" if the category is \"Diary\". If the category were be
1543 empty, no additional colon would be inserted.
1545 The default value for the agenda sublist is \" %-12:c%?-12t% s\",
1546 which means:
1548 - Indent the line with two space characters
1549 - Give the category a 12 chars wide field, padded with whitespace on
1550 the right (because of `-'). Append a colon if there is a category
1551 (because of `:').
1552 - If there is a time-of-day, put it into a 12 chars wide field. If no
1553 time, don't put in an empty field, just skip it (because of '?').
1554 - Finally, put the scheduling information.
1556 See also the variables `org-agenda-remove-times-when-in-prefix' and
1557 `org-agenda-remove-tags'.
1559 Custom commands can set this variable in the options section."
1560 :type '(choice
1561 (string :tag "General format")
1562 (list :greedy t :tag "View dependent"
1563 (cons (const agenda) (string :tag "Format"))
1564 (cons (const timeline) (string :tag "Format"))
1565 (cons (const todo) (string :tag "Format"))
1566 (cons (const tags) (string :tag "Format"))
1567 (cons (const search) (string :tag "Format"))))
1568 :group 'org-agenda-line-format)
1570 (defvar org-prefix-format-compiled nil
1571 "The compiled prefix format and associated variables.
1572 This is a list where first element is a list of variable bindings, and second
1573 element is the compiled format expression. See the variable
1574 `org-agenda-prefix-format'.")
1576 (defcustom org-agenda-todo-keyword-format "%-1s"
1577 "Format for the TODO keyword in agenda lines.
1578 Set this to something like \"%-12s\" if you want all TODO keywords
1579 to occupy a fixed space in the agenda display."
1580 :group 'org-agenda-line-format
1581 :type 'string)
1583 (defcustom org-agenda-diary-sexp-prefix nil
1584 "A regexp that matches part of a diary sexp entry
1585 which should be treated as scheduling/deadline information in
1586 `org-agenda'.
1588 For example, you can use this to extract the `diary-remind-message' from
1589 `diary-remind' entries."
1590 :group 'org-agenda-line-format
1591 :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
1593 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
1594 "Text preceding timerange entries in the agenda view.
1595 This is a list with two strings. The first applies when the range
1596 is entirely on one day. The second applies if the range spans several days.
1597 The strings may have two \"%d\" format specifiers which will be filled
1598 with the sequence number of the days, and the total number of days in the
1599 range, respectively."
1600 :group 'org-agenda-line-format
1601 :type '(list
1602 (string :tag "Deadline today ")
1603 (choice :tag "Deadline relative"
1604 (string :tag "Format string")
1605 (function))))
1607 (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
1608 "Text preceding scheduled items in the agenda view.
1609 This is a list with two strings. The first applies when the item is
1610 scheduled on the current day. The second applies when it has been scheduled
1611 previously, it may contain a %d indicating that this is the nth time that
1612 this item is scheduled, due to automatic rescheduling of unfinished items
1613 for the following day. So this number is one larger than the number of days
1614 that passed since this item was scheduled first."
1615 :group 'org-agenda-line-format
1616 :type '(list
1617 (string :tag "Scheduled today ")
1618 (string :tag "Scheduled previously")))
1620 (defcustom org-agenda-inactive-leader "["
1621 "Text preceding item pulled into the agenda by inactive time stamps.
1622 These entries are added to the agenda when pressing \"[\"."
1623 :group 'org-agenda-line-format
1624 :version "24.1"
1625 :type '(list
1626 (string :tag "Scheduled today ")
1627 (string :tag "Scheduled previously")))
1629 (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
1630 "Text preceding deadline items in the agenda view.
1631 This is a list with two strings. The first applies when the item has its
1632 deadline on the current day. The second applies when it is in the past or
1633 in the future, it may contain %d to capture how many days away the deadline
1634 is (was)."
1635 :group 'org-agenda-line-format
1636 :type '(list
1637 (string :tag "Deadline today ")
1638 (choice :tag "Deadline relative"
1639 (string :tag "Format string")
1640 (function))))
1642 (defcustom org-agenda-remove-times-when-in-prefix t
1643 "Non-nil means remove duplicate time specifications in agenda items.
1644 When the format `org-agenda-prefix-format' contains a `%t' specifier, a
1645 time-of-day specification in a headline or diary entry is extracted and
1646 placed into the prefix. If this option is non-nil, the original specification
1647 \(a timestamp or -range, or just a plain time(range) specification like
1648 11:30-4pm) will be removed for agenda display. This makes the agenda less
1649 cluttered.
1650 The option can be t or nil. It may also be the symbol `beg', indicating
1651 that the time should only be removed when it is located at the beginning of
1652 the headline/diary entry."
1653 :group 'org-agenda-line-format
1654 :type '(choice
1655 (const :tag "Always" t)
1656 (const :tag "Never" nil)
1657 (const :tag "When at beginning of entry" beg)))
1659 (defcustom org-agenda-remove-timeranges-from-blocks nil
1660 "Non-nil means remove time ranges specifications in agenda
1661 items that span on several days."
1662 :group 'org-agenda-line-format
1663 :version "24.1"
1664 :type 'boolean)
1666 (defcustom org-agenda-default-appointment-duration nil
1667 "Default duration for appointments that only have a starting time.
1668 When nil, no duration is specified in such cases.
1669 When non-nil, this must be the number of minutes, e.g. 60 for one hour."
1670 :group 'org-agenda-line-format
1671 :type '(choice
1672 (integer :tag "Minutes")
1673 (const :tag "No default duration")))
1675 (defcustom org-agenda-show-inherited-tags t
1676 "Non-nil means show inherited tags in each agenda line."
1677 :group 'org-agenda-line-format
1678 :type 'boolean)
1680 (defcustom org-agenda-hide-tags-regexp nil
1681 "Regular expression used to filter away specific tags in agenda views.
1682 This means that these tags will be present, but not be shown in the agenda
1683 line. Secondary filtering will still work on the hidden tags.
1684 Nil means don't hide any tags."
1685 :group 'org-agenda-line-format
1686 :type '(choice
1687 (const :tag "Hide none" nil)
1688 (string :tag "Regexp ")))
1690 (defcustom org-agenda-remove-tags nil
1691 "Non-nil means remove the tags from the headline copy in the agenda.
1692 When this is the symbol `prefix', only remove tags when
1693 `org-agenda-prefix-format' contains a `%T' specifier."
1694 :group 'org-agenda-line-format
1695 :type '(choice
1696 (const :tag "Always" t)
1697 (const :tag "Never" nil)
1698 (const :tag "When prefix format contains %T" prefix)))
1700 (if (fboundp 'defvaralias)
1701 (defvaralias 'org-agenda-remove-tags-when-in-prefix
1702 'org-agenda-remove-tags))
1704 (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
1705 "Shift tags in agenda items to this column.
1706 If this number is positive, it specifies the column. If it is negative,
1707 it means that the tags should be flushright to that column. For example,
1708 -80 works well for a normal 80 character screen."
1709 :group 'org-agenda-line-format
1710 :type 'integer)
1712 (if (fboundp 'defvaralias)
1713 (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
1715 (defcustom org-agenda-fontify-priorities 'cookies
1716 "Non-nil means highlight low and high priorities in agenda.
1717 When t, the highest priority entries are bold, lowest priority italic.
1718 However, settings in `org-priority-faces' will overrule these faces.
1719 When this variable is the symbol `cookies', only fontify the
1720 cookies, not the entire task.
1721 This may also be an association list of priority faces, whose
1722 keys are the character values of `org-highest-priority',
1723 `org-default-priority', and `org-lowest-priority' (the default values
1724 are ?A, ?B, and ?C, respectively). The face may be a named face, a
1725 color as a string, or a list like `(:background \"Red\")'.
1726 If it is a color, the variable `org-faces-easy-properties'
1727 determines if it is a foreground or a background color."
1728 :group 'org-agenda-line-format
1729 :type '(choice
1730 (const :tag "Never" nil)
1731 (const :tag "Defaults" t)
1732 (const :tag "Cookies only" cookies)
1733 (repeat :tag "Specify"
1734 (list (character :tag "Priority" :value ?A)
1735 (choice :tag "Face "
1736 (string :tag "Color")
1737 (sexp :tag "Face"))))))
1739 (defcustom org-agenda-day-face-function nil
1740 "Function called to determine what face should be used to display a day.
1741 The only argument passed to that function is the day. It should
1742 returns a face, or nil if does not want to specify a face and let
1743 the normal rules apply."
1744 :group 'org-agenda-line-format
1745 :version "24.1"
1746 :type 'function)
1748 (defcustom org-agenda-category-icon-alist nil
1749 "Alist of category icon to be displayed in agenda views.
1751 Each entry should have the following format:
1753 (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
1755 Where CATEGORY-REGEXP is a regexp matching the categories where
1756 the icon should be displayed.
1757 FILE-OR-DATA either a file path or a string containing image data.
1759 The other fields can be omitted safely if not needed:
1760 TYPE indicates the image type.
1761 DATA-P is a boolean indicating whether the FILE-OR-DATA string is
1762 image data.
1763 PROPS are additional image attributes to assign to the image,
1764 like, e.g. `:ascent center'.
1766 (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
1768 If you want to set the display properties yourself, just put a
1769 list as second element:
1771 (CATEGORY-REGEXP (MY PROPERTY LIST))
1773 For example, to display a 16px horizontal space for Emacs
1774 category, you can use:
1776 (\"Emacs\" '(space . (:width (16))))"
1777 :group 'org-agenda-line-format
1778 :version "24.1"
1779 :type '(alist :key-type (string :tag "Regexp matching category")
1780 :value-type (choice (list :tag "Icon"
1781 (string :tag "File or data")
1782 (symbol :tag "Type")
1783 (boolean :tag "Data?")
1784 (repeat :tag "Extra image properties" :inline t symbol))
1785 (list :tag "Display properties" sexp))))
1787 (defgroup org-agenda-column-view nil
1788 "Options concerning column view in the agenda."
1789 :tag "Org Agenda Column View"
1790 :group 'org-agenda)
1792 (defcustom org-agenda-columns-show-summaries t
1793 "Non-nil means show summaries for columns displayed in the agenda view."
1794 :group 'org-agenda-column-view
1795 :type 'boolean)
1797 (defcustom org-agenda-columns-compute-summary-properties t
1798 "Non-nil means recompute all summary properties before column view.
1799 When column view in the agenda is listing properties that have a summary
1800 operator, it can go to all relevant buffers and recompute the summaries
1801 there. This can mean overhead for the agenda column view, but is necessary
1802 to have thing up to date.
1803 As a special case, a CLOCKSUM property also makes sure that the clock
1804 computations are current."
1805 :group 'org-agenda-column-view
1806 :type 'boolean)
1808 (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
1809 "Non-nil means the duration of an appointment will add to day effort.
1810 The property to which appointment durations will be added is the one given
1811 in the option `org-effort-property'. If an appointment does not have
1812 an end time, `org-agenda-default-appointment-duration' will be used. If that
1813 is not set, an appointment without end time will not contribute to the time
1814 estimate."
1815 :group 'org-agenda-column-view
1816 :type 'boolean)
1818 (defcustom org-agenda-auto-exclude-function nil
1819 "A function called with a tag to decide if it is filtered on '/ RET'.
1820 The sole argument to the function, which is called once for each
1821 possible tag, is a string giving the name of the tag. The
1822 function should return either nil if the tag should be included
1823 as normal, or \"-<TAG>\" to exclude the tag.
1824 Note that for the purpose of tag filtering, only the lower-case version of
1825 all tags will be considered, so that this function will only ever see
1826 the lower-case version of all tags."
1827 :group 'org-agenda
1828 :type 'function)
1830 (defcustom org-agenda-bulk-custom-functions nil
1831 "Alist of characters and custom functions for bulk actions.
1832 For example, this value makes those two functions available:
1834 '((?R set-category)
1835 (?C bulk-cut))
1837 With selected entries in an agenda buffer, `B R' will call
1838 the custom function `set-category' on the selected entries.
1839 Note that functions in this alist don't need to be quoted."
1840 :type 'alist
1841 :version "24.1"
1842 :group 'org-agenda)
1844 (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
1845 "Execute BODY with point at location given by `org-hd-marker' property.
1846 If STRING is non-nil, the text property will be fetched from position 0
1847 in that string. If STRING is nil, it will be fetched from the beginning
1848 of the current line."
1849 (org-with-gensyms (marker)
1850 `(let ((,marker (get-text-property (if string 0 (point-at-bol))
1851 'org-hd-marker ,string)))
1852 (with-current-buffer (marker-buffer ,marker)
1853 (save-excursion
1854 (goto-char ,marker)
1855 ,@body)))))
1856 (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
1858 (defun org-add-agenda-custom-command (entry)
1859 "Replace or add a command in `org-agenda-custom-commands'.
1860 This is mostly for hacking and trying a new command - once the command
1861 works you probably want to add it to `org-agenda-custom-commands' for good."
1862 (let ((ass (assoc (car entry) org-agenda-custom-commands)))
1863 (if ass
1864 (setcdr ass (cdr entry))
1865 (push entry org-agenda-custom-commands))))
1867 ;;; Define the org-agenda-mode
1869 (defvar org-agenda-mode-map (make-sparse-keymap)
1870 "Keymap for `org-agenda-mode'.")
1871 (if (fboundp 'defvaralias)
1872 (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
1874 (defvar org-agenda-menu) ; defined later in this file.
1875 (defvar org-agenda-restrict nil) ; defined later in this file.
1876 (defvar org-agenda-follow-mode nil)
1877 (defvar org-agenda-entry-text-mode nil)
1878 (defvar org-agenda-clockreport-mode nil)
1879 (defvar org-agenda-show-log nil)
1880 (defvar org-agenda-redo-command nil)
1881 (defvar org-agenda-query-string nil)
1882 (defvar org-agenda-mode-hook nil
1883 "Hook run after `org-agenda-mode' is turned on.
1884 The buffer is still writable when this hook is called.")
1885 (defvar org-agenda-type nil)
1886 (defvar org-agenda-force-single-file nil)
1887 (defvar org-agenda-bulk-marked-entries nil
1888 "List of markers that refer to marked entries in the agenda.")
1890 ;;; Multiple agenda buffers support
1892 (defcustom org-agenda-sticky nil
1893 "Non-nil means agenda q key will bury agenda buffers.
1894 Agenda commands will then show existing buffer instead of generating new ones.
1895 When nil, `q' will kill the single agenda buffer."
1896 :group 'org-agenda
1897 :version "24.3"
1898 :type 'boolean)
1901 ;;;###autoload
1902 (defun org-toggle-sticky-agenda (&optional arg)
1903 "Toggle `org-agenda-sticky'."
1904 (interactive "P")
1905 (let ((new-value (if arg
1906 (> (prefix-numeric-value arg) 0)
1907 (not org-agenda-sticky))))
1908 (if (equal new-value org-agenda-sticky)
1909 (and (org-called-interactively-p 'interactive)
1910 (message "Sticky agenda was already %s"
1911 (if org-agenda-sticky "enabled" "disabled")))
1912 (setq org-agenda-sticky new-value)
1913 (org-agenda-kill-all-agenda-buffers)
1914 (and (org-called-interactively-p 'interactive)
1915 (message "Sticky agenda was %s"
1916 (if org-agenda-sticky "enabled" "disabled"))))))
1918 (autoload 'org-toggle-sticky-agenda "org-agenda" "\
1919 Toggle `org-agenda-sticky'.
1921 \(fn &optional ARG)" t nil)
1923 (defvar org-agenda-buffer nil
1924 "Agenda buffer currently being generated.")
1926 (defvar org-agenda-last-prefix-arg nil)
1927 (defvar org-agenda-this-buffer-name nil)
1928 (defvar org-agenda-doing-sticky-redo nil)
1929 (defvar org-agenda-this-buffer-is-sticky nil)
1931 (defconst org-agenda-local-vars
1932 '(org-agenda-this-buffer-name
1933 org-agenda-undo-list
1934 org-agenda-pending-undo-list
1935 org-agenda-follow-mode
1936 org-agenda-entry-text-mode
1937 org-agenda-clockreport-mode
1938 org-agenda-show-log
1939 org-agenda-redo-command
1940 org-agenda-query-string
1941 org-agenda-type
1942 org-agenda-bulk-marked-entries
1943 org-agenda-undo-has-started-in
1944 org-agenda-info
1945 org-agenda-tag-filter-overlays
1946 org-agenda-cat-filter-overlays
1947 org-agenda-pre-window-conf
1948 org-agenda-columns-active
1949 org-agenda-tag-filter
1950 org-agenda-category-filter
1951 org-agenda-markers
1952 org-agenda-last-search-view-search-was-boolean
1953 org-agenda-filtered-by-category
1954 org-agenda-filter-form
1955 org-agenda-show-window
1956 org-agenda-cycle-counter
1957 org-agenda-last-prefix-arg)
1958 "Variables that must be local in agenda buffers to allow multiple buffers.")
1960 (defun org-agenda-mode ()
1961 "Mode for time-sorted view on action items in Org-mode files.
1963 The following commands are available:
1965 \\{org-agenda-mode-map}"
1966 (interactive)
1967 (cond (org-agenda-doing-sticky-redo
1968 ;; Refreshing sticky agenda-buffer
1970 ;; Preserve the value of `org-agenda-local-vars' variables,
1971 ;; while letting `kill-all-local-variables' kill the rest
1972 (let ((save (buffer-local-variables)))
1973 (kill-all-local-variables)
1974 (mapc 'make-local-variable org-agenda-local-vars)
1975 (dolist (elem save)
1976 (let ((var (car elem))
1977 (val (cdr elem)))
1978 (when (and val
1979 (member var org-agenda-local-vars))
1980 (set var val)))))
1981 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1982 (org-agenda-sticky
1983 ;; Creating a sticky Agenda buffer for the first time
1984 (kill-all-local-variables)
1985 (mapc 'make-local-variable org-agenda-local-vars)
1986 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
1988 ;; Creating a non-sticky agenda buffer
1989 (kill-all-local-variables)
1990 (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
1991 (setq org-agenda-undo-list nil
1992 org-agenda-pending-undo-list nil
1993 org-agenda-bulk-marked-entries nil)
1994 (setq major-mode 'org-agenda-mode)
1995 ;; Keep global-font-lock-mode from turning on font-lock-mode
1996 (org-set-local 'font-lock-global-modes (list 'not major-mode))
1997 (setq mode-name "Org-Agenda")
1998 (use-local-map org-agenda-mode-map)
1999 (easy-menu-add org-agenda-menu)
2000 (if org-startup-truncated (setq truncate-lines t))
2001 (org-set-local 'line-move-visual nil)
2002 (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
2003 (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
2004 ;; Make sure properties are removed when copying text
2005 (make-local-variable 'filter-buffer-substring-functions)
2006 (add-hook 'filter-buffer-substring-functions
2007 (lambda (fun start end delete)
2008 (substring-no-properties (funcall fun start end delete))))
2009 (unless org-agenda-keep-modes
2010 (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
2011 org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
2012 org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
2013 org-agenda-show-log org-agenda-start-with-log-mode))
2015 (easy-menu-change
2016 '("Agenda") "Agenda Files"
2017 (append
2018 (list
2019 (vector
2020 (if (get 'org-agenda-files 'org-restrict)
2021 "Restricted to single file"
2022 "Edit File List")
2023 '(org-edit-agenda-file-list)
2024 (not (get 'org-agenda-files 'org-restrict)))
2025 "--")
2026 (mapcar 'org-file-menu-entry (org-agenda-files))))
2027 (org-agenda-set-mode-name)
2028 (apply
2029 (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
2030 (list 'org-agenda-mode-hook)))
2032 (substitute-key-definition 'undo 'org-agenda-undo
2033 org-agenda-mode-map global-map)
2034 (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
2035 (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
2036 (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
2037 (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
2038 (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
2039 (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
2040 (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
2041 (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
2042 (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
2043 (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
2044 (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
2045 (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
2046 (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
2047 (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
2048 (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
2049 (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
2050 (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
2051 (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
2052 (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
2053 (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
2054 (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
2055 (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
2056 (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
2057 (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
2058 (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
2059 (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
2060 (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
2061 (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
2062 (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
2063 (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
2064 (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
2065 (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
2066 (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
2067 (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
2068 (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
2069 (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
2070 (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
2071 (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
2072 (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
2073 (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
2074 (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
2075 (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
2076 (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
2077 (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
2078 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
2079 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
2081 (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
2082 (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
2083 (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
2084 (let ((l '(1 2 3 4 5 6 7 8 9 0)))
2085 (while l (org-defkey org-agenda-mode-map
2086 (int-to-string (pop l)) 'digit-argument)))
2088 (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
2089 (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
2090 (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
2091 (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
2092 (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
2093 (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
2094 (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
2095 (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
2096 (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
2097 (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
2098 (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
2099 (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
2100 (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
2101 'org-clock-modify-effort-estimate)
2102 (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
2103 (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
2104 (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
2105 (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
2106 (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
2107 (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
2108 (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
2109 (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
2110 (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
2111 (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
2112 (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
2113 (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
2114 (substitute-key-definition 'next-line 'org-agenda-next-line
2115 org-agenda-mode-map global-map)
2116 (substitute-key-definition 'previous-line 'org-agenda-previous-line
2117 org-agenda-mode-map global-map)
2118 (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
2119 (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
2120 (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
2121 (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
2122 (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
2123 (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
2124 (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
2125 (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
2126 (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
2127 (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
2128 (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
2129 (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
2130 (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
2131 (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
2132 (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
2133 (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
2134 (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
2135 (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
2136 (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
2137 (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
2138 (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
2139 (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
2140 (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
2141 (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
2142 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
2143 (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
2144 (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
2145 (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
2146 (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
2147 (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
2149 (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
2150 (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
2151 (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
2152 (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
2153 (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
2154 (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
2155 (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
2156 (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
2157 (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
2158 (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
2159 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
2160 (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
2162 (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
2163 (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
2164 (when org-agenda-mouse-1-follows-link
2165 (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
2166 (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
2167 '("Agenda"
2168 ("Agenda Files")
2169 "--"
2170 ("Agenda Dates"
2171 ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
2172 ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
2173 ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
2174 ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
2175 "--"
2176 ("View"
2177 ["Day View" org-agenda-day-view
2178 :active (org-agenda-check-type nil 'agenda)
2179 :style radio :selected (eq org-agenda-current-span 'day)
2180 :keys "v d (or just d)"]
2181 ["Week View" org-agenda-week-view
2182 :active (org-agenda-check-type nil 'agenda)
2183 :style radio :selected (eq org-agenda-current-span 'week)
2184 :keys "v w (or just w)"]
2185 ["Month View" org-agenda-month-view
2186 :active (org-agenda-check-type nil 'agenda)
2187 :style radio :selected (eq org-agenda-current-span 'month)
2188 :keys "v m"]
2189 ["Year View" org-agenda-year-view
2190 :active (org-agenda-check-type nil 'agenda)
2191 :style radio :selected (eq org-agenda-current-span 'year)
2192 :keys "v y"]
2193 "--"
2194 ["Include Diary" org-agenda-toggle-diary
2195 :style toggle :selected org-agenda-include-diary
2196 :active (org-agenda-check-type nil 'agenda)]
2197 ["Include Deadlines" org-agenda-toggle-deadlines
2198 :style toggle :selected org-agenda-include-deadlines
2199 :active (org-agenda-check-type nil 'agenda)]
2200 ["Use Time Grid" org-agenda-toggle-time-grid
2201 :style toggle :selected org-agenda-use-time-grid
2202 :active (org-agenda-check-type nil 'agenda)]
2203 "--"
2204 ["Show clock report" org-agenda-clockreport-mode
2205 :style toggle :selected org-agenda-clockreport-mode
2206 :active (org-agenda-check-type nil 'agenda)]
2207 ["Show some entry text" org-agenda-entry-text-mode
2208 :style toggle :selected org-agenda-entry-text-mode
2209 :active t]
2210 "--"
2211 ["Show Logbook entries" org-agenda-log-mode
2212 :style toggle :selected org-agenda-show-log
2213 :active (org-agenda-check-type nil 'agenda 'timeline)
2214 :keys "v l (or just l)"]
2215 ["Include archived trees" org-agenda-archives-mode
2216 :style toggle :selected org-agenda-archives-mode :active t
2217 :keys "v a"]
2218 ["Include archive files" (org-agenda-archives-mode t)
2219 :style toggle :selected (eq org-agenda-archives-mode t) :active t
2220 :keys "v A"]
2221 "--"
2222 ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
2223 ["Write view to file" org-agenda-write t]
2224 ["Rebuild buffer" org-agenda-redo t]
2225 ["Save all Org-mode Buffers" org-save-all-org-buffers t]
2226 "--"
2227 ["Show original entry" org-agenda-show t]
2228 ["Go To (other window)" org-agenda-goto t]
2229 ["Go To (this window)" org-agenda-switch-to t]
2230 ["Capture with cursor date" org-agenda-capture t]
2231 ["Follow Mode" org-agenda-follow-mode
2232 :style toggle :selected org-agenda-follow-mode :active t]
2233 ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
2234 "--"
2235 ("TODO"
2236 ["Cycle TODO" org-agenda-todo t]
2237 ["Next TODO set" org-agenda-todo-nextset t]
2238 ["Previous TODO set" org-agenda-todo-previousset t]
2239 ["Add note" org-agenda-add-note t])
2240 ("Archive/Refile/Delete"
2241 ["Archive default" org-agenda-archive-default t]
2242 ["Archive default" org-agenda-archive-default-with-confirmation t]
2243 ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
2244 ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
2245 ["Archive subtree" org-agenda-archive t]
2246 "--"
2247 ["Refile" org-agenda-refile t]
2248 "--"
2249 ["Delete subtree" org-agenda-kill t])
2250 ("Bulk action"
2251 ["Mark entry" org-agenda-bulk-mark t]
2252 ["Mark all" org-agenda-bulk-mark-all t]
2253 ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
2254 ["Unmark entry" org-agenda-bulk-unmark t]
2255 ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
2256 ["Act on all marked" org-agenda-bulk-action t]
2257 "--"
2258 ("Tags and Properties"
2259 ["Show all Tags" org-agenda-show-tags t]
2260 ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
2261 ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
2262 "--"
2263 ["Column View" org-columns t])
2264 ("Deadline/Schedule"
2265 ["Schedule" org-agenda-schedule t]
2266 ["Set Deadline" org-agenda-deadline t]
2267 "--"
2268 ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
2269 ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
2270 ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
2271 ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
2272 ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
2273 ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
2274 ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
2275 ("Clock and Effort"
2276 ["Clock in" org-agenda-clock-in t]
2277 ["Clock out" org-agenda-clock-out t]
2278 ["Clock cancel" org-agenda-clock-cancel t]
2279 ["Goto running clock" org-clock-goto t]
2280 "--"
2281 ["Set Effort" org-agenda-set-effort t]
2282 ["Change clocked effort" org-clock-modify-effort-estimate
2283 (org-clock-is-active)])
2284 ("Priority"
2285 ["Set Priority" org-agenda-priority t]
2286 ["Increase Priority" org-agenda-priority-up t]
2287 ["Decrease Priority" org-agenda-priority-down t]
2288 ["Show Priority" org-show-priority t])
2289 ("Calendar/Diary"
2290 ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
2291 ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
2292 ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
2293 ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
2294 ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
2295 ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
2296 "--"
2297 ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
2298 "--"
2299 ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
2300 "--"
2301 ("MobileOrg"
2302 ["Push Files and Views" org-mobile-push t]
2303 ["Get Captured and Flagged" org-mobile-pull t]
2304 ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
2305 ["Show note / unflag" org-agenda-show-the-flagging-note t]
2306 "--"
2307 ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
2308 "--"
2309 ["Quit" org-agenda-quit t]
2310 ["Exit and Release Buffers" org-agenda-exit t]
2313 ;;; Agenda undo
2315 (defvar org-agenda-allow-remote-undo t
2316 "Non-nil means allow remote undo from the agenda buffer.")
2317 (defvar org-agenda-undo-has-started-in nil
2318 "Buffers that have already seen `undo-start' in the current undo sequence.")
2320 (defun org-agenda-undo ()
2321 "Undo a remote editing step in the agenda.
2322 This undoes changes both in the agenda buffer and in the remote buffer
2323 that have been changed along."
2324 (interactive)
2325 (or org-agenda-allow-remote-undo
2326 (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
2327 (if (not (eq this-command last-command))
2328 (setq org-agenda-undo-has-started-in nil
2329 org-agenda-pending-undo-list org-agenda-undo-list))
2330 (if (not org-agenda-pending-undo-list)
2331 (error "No further undo information"))
2332 (let* ((entry (pop org-agenda-pending-undo-list))
2333 buf line cmd rembuf)
2334 (setq cmd (pop entry) line (pop entry))
2335 (setq rembuf (nth 2 entry))
2336 (org-with-remote-undo rembuf
2337 (while (bufferp (setq buf (pop entry)))
2338 (if (pop entry)
2339 (with-current-buffer buf
2340 (let ((last-undo-buffer buf)
2341 (inhibit-read-only t))
2342 (unless (memq buf org-agenda-undo-has-started-in)
2343 (push buf org-agenda-undo-has-started-in)
2344 (make-local-variable 'pending-undo-list)
2345 (undo-start))
2346 (while (and pending-undo-list
2347 (listp pending-undo-list)
2348 (not (car pending-undo-list)))
2349 (pop pending-undo-list))
2350 (undo-more 1))))))
2351 (org-goto-line line)
2352 (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
2354 (defun org-verify-change-for-undo (l1 l2)
2355 "Verify that a real change occurred between the undo lists L1 and L2."
2356 (while (and l1 (listp l1) (null (car l1))) (pop l1))
2357 (while (and l2 (listp l2) (null (car l2))) (pop l2))
2358 (not (eq l1 l2)))
2360 ;;; Agenda dispatch
2362 (defvar org-agenda-restrict-begin (make-marker))
2363 (defvar org-agenda-restrict-end (make-marker))
2364 (defvar org-agenda-last-dispatch-buffer nil)
2365 (defvar org-agenda-overriding-restriction nil)
2367 (defcustom org-agenda-custom-commands-contexts nil
2368 "Alist of custom agenda keys and contextual rules.
2370 For example, if you have a custom agenda command \"p\" and you
2371 want this command to be accessible only from plain text files,
2372 use this:
2374 '((\"p\" (in-file . \"\\.txt\")))
2376 Here are the available contexts definitions:
2378 in-file: command displayed only in matching files
2379 in-mode: command displayed only in matching modes
2380 not-in-file: command not displayed in matching files
2381 not-in-mode: command not displayed in matching modes
2382 [function]: a custom function taking no argument
2384 If you define several checks, the agenda command will be
2385 accessible if there is at least one valid check.
2387 You can also bind a key to another agenda custom command
2388 depending on contextual rules.
2390 '((\"p\" \"q\" (in-file . \"\\.txt\")))
2392 Here it means: in .txt files, use \"p\" as the key for the
2393 agenda command otherwise associated with \"q\". (The command
2394 originally associated with \"q\" is not displayed to avoid
2395 duplicates.)"
2396 :version "24.3"
2397 :group 'org-agenda-custom-commands
2398 :type '(repeat (list :tag "Rule"
2399 (string :tag " Agenda key")
2400 (string :tag "Replace by command")
2401 (repeat :tag "Available when"
2402 (choice
2403 (cons :tag "Condition"
2404 (choice
2405 (const :tag "In file" in-file)
2406 (const :tag "Not in file" not-in-file)
2407 (const :tag "In mode" in-mode)
2408 (const :tag "Not in mode" not-in-mode))
2409 (regexp))
2410 (function :tag "Custom function"))))))
2412 (defvar org-keys nil)
2413 (defvar org-match nil)
2414 ;;;###autoload
2415 (defun org-agenda (&optional arg org-keys restriction)
2416 "Dispatch agenda commands to collect entries to the agenda buffer.
2417 Prompts for a command to execute. Any prefix arg will be passed
2418 on to the selected command. The default selections are:
2420 a Call `org-agenda-list' to display the agenda for current day or week.
2421 t Call `org-todo-list' to display the global todo list.
2422 T Call `org-todo-list' to display the global todo list, select only
2423 entries with a specific TODO keyword (the user gets a prompt).
2424 m Call `org-tags-view' to display headlines with tags matching
2425 a condition (the user is prompted for the condition).
2426 M Like `m', but select only TODO entries, no ordinary headlines.
2427 L Create a timeline for the current buffer.
2428 e Export views to associated files.
2429 s Search entries for keywords.
2430 S Search entries for keywords, only with TODO keywords.
2431 / Multi occur across all agenda files and also files listed
2432 in `org-agenda-text-search-extra-files'.
2433 < Restrict agenda commands to buffer, subtree, or region.
2434 Press several times to get the desired effect.
2435 > Remove a previous restriction.
2436 # List \"stuck\" projects.
2437 ! Configure what \"stuck\" means.
2438 C Configure custom agenda commands.
2440 More commands can be added by configuring the variable
2441 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2442 searches can be pre-defined in this way.
2444 If the current buffer is in Org-mode and visiting a file, you can also
2445 first press `<' once to indicate that the agenda should be temporarily
2446 \(until the next use of \\[org-agenda]) restricted to the current file.
2447 Pressing `<' twice means to restrict to the current subtree or region
2448 \(if active)."
2449 (interactive "P")
2450 (catch 'exit
2451 (let* ((prefix-descriptions nil)
2452 (org-agenda-buffer-name org-agenda-buffer-name)
2453 (org-agenda-window-setup (if (equal (buffer-name)
2454 org-agenda-buffer-name)
2455 'current-window
2456 org-agenda-window-setup))
2457 (org-agenda-custom-commands-orig org-agenda-custom-commands)
2458 (org-agenda-custom-commands
2459 ;; normalize different versions
2460 (delq nil
2461 (mapcar
2462 (lambda (x)
2463 (cond ((stringp (cdr x))
2464 (push x prefix-descriptions)
2465 nil)
2466 ((stringp (nth 1 x)) x)
2467 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2468 (t (cons (car x) (cons "" (cdr x))))))
2469 org-agenda-custom-commands)))
2470 (org-agenda-custom-commands
2471 (org-contextualize-keys
2472 org-agenda-custom-commands org-agenda-custom-commands-contexts))
2473 (buf (current-buffer))
2474 (bfn (buffer-file-name (buffer-base-buffer)))
2475 entry key type org-match lprops ans)
2476 ;; Turn off restriction unless there is an overriding one,
2477 (unless org-agenda-overriding-restriction
2478 (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
2479 ;; There is a request to keep the file list in place
2480 (put 'org-agenda-files 'org-restrict nil))
2481 (setq org-agenda-restrict nil)
2482 (move-marker org-agenda-restrict-begin nil)
2483 (move-marker org-agenda-restrict-end nil))
2484 ;; Delete old local properties
2485 (put 'org-agenda-redo-command 'org-lprops nil)
2486 ;; Delete previously set last-arguments
2487 (put 'org-agenda-redo-command 'last-args nil)
2488 ;; Remember where this call originated
2489 (setq org-agenda-last-dispatch-buffer (current-buffer))
2490 (unless org-keys
2491 (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
2492 org-keys (car ans)
2493 restriction (cdr ans)))
2494 ;; If we have sticky agenda buffers, set a name for the buffer,
2495 ;; depending on the invoking keys. The user may still set this
2496 ;; as a command option, which will overwrite what we do here.
2497 (if org-agenda-sticky
2498 (setq org-agenda-buffer-name
2499 (format "*Org Agenda(%s)*" org-keys)))
2500 ;; Establish the restriction, if any
2501 (when (and (not org-agenda-overriding-restriction) restriction)
2502 (put 'org-agenda-files 'org-restrict (list bfn))
2503 (cond
2504 ((eq restriction 'region)
2505 (setq org-agenda-restrict t)
2506 (move-marker org-agenda-restrict-begin (region-beginning))
2507 (move-marker org-agenda-restrict-end (region-end)))
2508 ((eq restriction 'subtree)
2509 (save-excursion
2510 (setq org-agenda-restrict t)
2511 (org-back-to-heading t)
2512 (move-marker org-agenda-restrict-begin (point))
2513 (move-marker org-agenda-restrict-end
2514 (progn (org-end-of-subtree t)))))))
2516 ;; For example the todo list should not need it (but does...)
2517 (cond
2518 ((setq entry (assoc org-keys org-agenda-custom-commands))
2519 (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
2520 (progn
2521 (setq type (nth 2 entry) org-match (eval (nth 3 entry))
2522 lprops (nth 4 entry))
2523 (if org-agenda-sticky
2524 (setq org-agenda-buffer-name
2525 (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
2526 (format "*Org Agenda(%s)*" org-keys))))
2527 (put 'org-agenda-redo-command 'org-lprops lprops)
2528 (cond
2529 ((eq type 'agenda)
2530 (org-let lprops '(org-agenda-list current-prefix-arg)))
2531 ((eq type 'alltodo)
2532 (org-let lprops '(org-todo-list current-prefix-arg)))
2533 ((eq type 'search)
2534 (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
2535 ((eq type 'stuck)
2536 (org-let lprops '(org-agenda-list-stuck-projects
2537 current-prefix-arg)))
2538 ((eq type 'tags)
2539 (org-let lprops '(org-tags-view current-prefix-arg org-match)))
2540 ((eq type 'tags-todo)
2541 (org-let lprops '(org-tags-view '(4) org-match)))
2542 ((eq type 'todo)
2543 (org-let lprops '(org-todo-list org-match)))
2544 ((eq type 'tags-tree)
2545 (org-check-for-org-mode)
2546 (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
2547 ((eq type 'todo-tree)
2548 (org-check-for-org-mode)
2549 (org-let lprops
2550 '(org-occur (concat "^" org-outline-regexp "[ \t]*"
2551 (regexp-quote org-match) "\\>"))))
2552 ((eq type 'occur-tree)
2553 (org-check-for-org-mode)
2554 (org-let lprops '(org-occur org-match)))
2555 ((functionp type)
2556 (org-let lprops '(funcall type org-match)))
2557 ((fboundp type)
2558 (org-let lprops '(funcall type org-match)))
2559 (t (error "Invalid custom agenda command type %s" type))))
2560 (org-agenda-run-series (nth 1 entry) (cddr entry))))
2561 ((equal org-keys "C")
2562 (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
2563 (customize-variable 'org-agenda-custom-commands))
2564 ((equal org-keys "a") (call-interactively 'org-agenda-list))
2565 ((equal org-keys "s") (call-interactively 'org-search-view))
2566 ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
2567 ((equal org-keys "t") (call-interactively 'org-todo-list))
2568 ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
2569 ((equal org-keys "m") (call-interactively 'org-tags-view))
2570 ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
2571 ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
2572 ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
2573 (org-add-hook
2574 'post-command-hook
2575 (lambda ()
2576 (unless (current-message)
2577 (let* ((m (org-agenda-get-any-marker))
2578 (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
2579 (when note
2580 (message (concat
2581 "FLAGGING-NOTE ([?] for more info): "
2582 (org-add-props
2583 (replace-regexp-in-string
2584 "\\\\n" "//"
2585 (copy-sequence note))
2586 nil 'face 'org-warning)))))))
2587 t t))
2588 ((equal org-keys "L")
2589 (unless (derived-mode-p 'org-mode)
2590 (error "This is not an Org-mode file"))
2591 (unless restriction
2592 (put 'org-agenda-files 'org-restrict (list bfn))
2593 (org-call-with-arg 'org-timeline arg)))
2594 ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
2595 ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
2596 ((equal org-keys "!") (customize-variable 'org-stuck-projects))
2597 (t (error "Invalid agenda key"))))))
2599 (autoload 'org-agenda "org-agenda" "\
2600 Dispatch agenda commands to collect entries to the agenda buffer.
2601 Prompts for a command to execute. Any prefix arg will be passed
2602 on to the selected command. The default selections are:
2604 a Call `org-agenda-list' to display the agenda for current day or week.
2605 t Call `org-todo-list' to display the global todo list.
2606 T Call `org-todo-list' to display the global todo list, select only
2607 entries with a specific TODO keyword (the user gets a prompt).
2608 m Call `org-tags-view' to display headlines with tags matching
2609 a condition (the user is prompted for the condition).
2610 M Like `m', but select only TODO entries, no ordinary headlines.
2611 L Create a timeline for the current buffer.
2612 e Export views to associated files.
2613 s Search entries for keywords.
2614 S Search entries for keywords, only with TODO keywords.
2615 / Multi occur across all agenda files and also files listed
2616 in `org-agenda-text-search-extra-files'.
2617 < Restrict agenda commands to buffer, subtree, or region.
2618 Press several times to get the desired effect.
2619 > Remove a previous restriction.
2620 # List \"stuck\" projects.
2621 ! Configure what \"stuck\" means.
2622 C Configure custom agenda commands.
2624 More commands can be added by configuring the variable
2625 `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
2626 searches can be pre-defined in this way.
2628 If the current buffer is in Org-mode and visiting a file, you can also
2629 first press `<' once to indicate that the agenda should be temporarily
2630 \(until the next use of \\[org-agenda]) restricted to the current file.
2631 Pressing `<' twice means to restrict to the current subtree or region
2632 \(if active).
2634 \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
2636 (defun org-agenda-append-agenda ()
2637 "Append another agenda view to the current one.
2638 This function allows interactive building of block agendas.
2639 Agenda views are separated by `org-agenda-block-separator'."
2640 (interactive)
2641 (unless (derived-mode-p 'org-agenda-mode)
2642 (error "Can only append from within agenda buffer"))
2643 (let ((org-agenda-multi t))
2644 (org-agenda)
2645 (widen)
2646 (org-agenda-finalize)
2647 (org-agenda-fit-window-to-buffer)))
2649 (defun org-agenda-normalize-custom-commands (cmds)
2650 (delq nil
2651 (mapcar
2652 (lambda (x)
2653 (cond ((stringp (cdr x)) nil)
2654 ((stringp (nth 1 x)) x)
2655 ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
2656 (t (cons (car x) (cons "" (cdr x))))))
2657 cmds)))
2659 (defun org-agenda-get-restriction-and-command (prefix-descriptions)
2660 "The user interface for selecting an agenda command."
2661 (catch 'exit
2662 (let* ((bfn (buffer-file-name (buffer-base-buffer)))
2663 (restrict-ok (and bfn (derived-mode-p 'org-mode)))
2664 (region-p (org-region-active-p))
2665 (custom org-agenda-custom-commands)
2666 (selstring "")
2667 restriction second-time
2668 c entry key type match prefixes rmheader header-end custom1 desc
2669 line lines left right n n1)
2670 (save-window-excursion
2671 (delete-other-windows)
2672 (org-switch-to-buffer-other-window " *Agenda Commands*")
2673 (erase-buffer)
2674 (insert (eval-when-compile
2675 (let ((header
2676 "Press key for an agenda command: < Buffer, subtree/region restriction
2677 -------------------------------- > Remove restriction
2678 a Agenda for current week or day e Export agenda views
2679 t List of all TODO entries T Entries with special TODO kwd
2680 m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
2681 s Search for keywords S Like s, but only TODO entries
2682 L Timeline for current buffer # List stuck projects (!=configure)
2683 / Multi-occur C Configure custom agenda commands
2684 ? Find :FLAGGED: entries * Toggle sticky agenda views
2686 (start 0))
2687 (while (string-match
2688 "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
2689 header start)
2690 (setq start (match-end 0))
2691 (add-text-properties (match-beginning 2) (match-end 2)
2692 '(face bold) header))
2693 header)))
2694 (setq header-end (point-marker))
2695 (while t
2696 (setq custom1 custom)
2697 (when (eq rmheader t)
2698 (org-goto-line 1)
2699 (re-search-forward ":" nil t)
2700 (delete-region (match-end 0) (point-at-eol))
2701 (forward-char 1)
2702 (looking-at "-+")
2703 (delete-region (match-end 0) (point-at-eol))
2704 (move-marker header-end (match-end 0)))
2705 (goto-char header-end)
2706 (delete-region (point) (point-max))
2708 ;; Produce all the lines that describe custom commands and prefixes
2709 (setq lines nil)
2710 (while (setq entry (pop custom1))
2711 (setq key (car entry) desc (nth 1 entry)
2712 type (nth 2 entry)
2713 match (nth 3 entry))
2714 (if (> (length key) 1)
2715 (add-to-list 'prefixes (string-to-char key))
2716 (setq line
2717 (format
2718 "%-4s%-14s"
2719 (org-add-props (copy-sequence key)
2720 '(face bold))
2721 (cond
2722 ((string-match "\\S-" desc) desc)
2723 ((eq type 'agenda) "Agenda for current week or day")
2724 ((eq type 'alltodo) "List of all TODO entries")
2725 ((eq type 'search) "Word search")
2726 ((eq type 'stuck) "List of stuck projects")
2727 ((eq type 'todo) "TODO keyword")
2728 ((eq type 'tags) "Tags query")
2729 ((eq type 'tags-todo) "Tags (TODO)")
2730 ((eq type 'tags-tree) "Tags tree")
2731 ((eq type 'todo-tree) "TODO kwd tree")
2732 ((eq type 'occur-tree) "Occur tree")
2733 ((functionp type) (if (symbolp type)
2734 (symbol-name type)
2735 "Lambda expression"))
2736 (t "???"))))
2737 (if org-agenda-menu-show-matcher
2738 (setq line
2739 (concat line ": "
2740 (cond
2741 ((stringp match)
2742 (setq match (copy-sequence match))
2743 (org-add-props match nil 'face 'org-warning))
2744 ((listp type)
2745 (format "set of %d commands" (length type))))))
2746 (if (org-string-nw-p match)
2747 (add-text-properties
2748 0 (length line) (list 'help-echo
2749 (concat "Matcher: " match)) line)))
2750 (push line lines)))
2751 (setq lines (nreverse lines))
2752 (when prefixes
2753 (mapc (lambda (x)
2754 (push
2755 (format "%s %s"
2756 (org-add-props (char-to-string x)
2757 nil 'face 'bold)
2758 (or (cdr (assoc (concat selstring
2759 (char-to-string x))
2760 prefix-descriptions))
2761 "Prefix key"))
2762 lines))
2763 prefixes))
2765 ;; Check if we should display in two columns
2766 (if org-agenda-menu-two-columns
2767 (progn
2768 (setq n (length lines)
2769 n1 (+ (/ n 2) (mod n 2))
2770 right (nthcdr n1 lines)
2771 left (copy-sequence lines))
2772 (setcdr (nthcdr (1- n1) left) nil))
2773 (setq left lines right nil))
2774 (while left
2775 (insert "\n" (pop left))
2776 (when right
2777 (if (< (current-column) 40)
2778 (move-to-column 40 t)
2779 (insert " "))
2780 (insert (pop right))))
2782 ;; Make the window the right size
2783 (goto-char (point-min))
2784 (if second-time
2785 (if (not (pos-visible-in-window-p (point-max)))
2786 (org-fit-window-to-buffer))
2787 (setq second-time t)
2788 (org-fit-window-to-buffer))
2790 ;; Ask for selection
2791 (message "Press key for agenda command%s:"
2792 (if (or restrict-ok org-agenda-overriding-restriction)
2793 (if org-agenda-overriding-restriction
2794 " (restriction lock active)"
2795 (if restriction
2796 (format " (restricted to %s)" restriction)
2797 " (unrestricted)"))
2798 ""))
2799 (setq c (read-char-exclusive))
2800 (message "")
2801 (cond
2802 ((assoc (char-to-string c) custom)
2803 (setq selstring (concat selstring (char-to-string c)))
2804 (throw 'exit (cons selstring restriction)))
2805 ((memq c prefixes)
2806 (setq selstring (concat selstring (char-to-string c))
2807 prefixes nil
2808 rmheader (or rmheader t)
2809 custom (delq nil (mapcar
2810 (lambda (x)
2811 (if (or (= (length (car x)) 1)
2812 (/= (string-to-char (car x)) c))
2814 (cons (substring (car x) 1) (cdr x))))
2815 custom))))
2816 ((eq c ?*)
2817 (call-interactively 'org-toggle-sticky-agenda)
2818 (sit-for 2))
2819 ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
2820 (message "Restriction is only possible in Org-mode buffers")
2821 (ding) (sit-for 1))
2822 ((eq c ?1)
2823 (org-agenda-remove-restriction-lock 'noupdate)
2824 (setq restriction 'buffer))
2825 ((eq c ?0)
2826 (org-agenda-remove-restriction-lock 'noupdate)
2827 (setq restriction (if region-p 'region 'subtree)))
2828 ((eq c ?<)
2829 (org-agenda-remove-restriction-lock 'noupdate)
2830 (setq restriction
2831 (cond
2832 ((eq restriction 'buffer)
2833 (if region-p 'region 'subtree))
2834 ((memq restriction '(subtree region))
2835 nil)
2836 (t 'buffer))))
2837 ((eq c ?>)
2838 (org-agenda-remove-restriction-lock 'noupdate)
2839 (setq restriction nil))
2840 ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
2841 (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
2842 ((and (> (length selstring) 0) (eq c ?\d))
2843 (delete-window)
2844 (org-agenda-get-restriction-and-command prefix-descriptions))
2846 ((equal c ?q) (error "Abort"))
2847 (t (error "Invalid key %c" c))))))))
2849 (defun org-agenda-fit-window-to-buffer ()
2850 "Fit the window to the buffer size."
2851 (and (memq org-agenda-window-setup '(reorganize-frame))
2852 (fboundp 'fit-window-to-buffer)
2853 (org-fit-window-to-buffer
2855 (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
2856 (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
2858 (defvar org-cmd nil)
2859 (defvar org-agenda-overriding-cmd nil)
2860 (defvar org-agenda-overriding-arguments nil)
2861 (defvar org-agenda-overriding-cmd-arguments nil)
2862 (defun org-agenda-run-series (name series)
2863 (org-let (nth 1 series) '(org-agenda-prepare name))
2864 ;; We need to reset agenda markers here, because when constructing a
2865 ;; block agenda, the individual blocks do not do that.
2866 (org-agenda-reset-markers)
2867 (let* ((org-agenda-multi t)
2868 (redo (list 'org-agenda-run-series name (list 'quote series)))
2869 (cmds (car series))
2870 (gprops (nth 1 series))
2871 match ;; The byte compiler incorrectly complains about this. Keep it!
2872 org-cmd type lprops)
2873 (while (setq org-cmd (pop cmds))
2874 (setq type (car org-cmd)
2875 match (eval (nth 1 org-cmd))
2876 lprops (nth 2 org-cmd))
2877 (let ((org-agenda-overriding-arguments
2878 (if (eq org-agenda-overriding-cmd org-cmd)
2879 (or org-agenda-overriding-arguments
2880 org-agenda-overriding-cmd-arguments))))
2881 (cond
2882 ((eq type 'agenda)
2883 (org-let2 gprops lprops
2884 '(call-interactively 'org-agenda-list)))
2885 ((eq type 'alltodo)
2886 (org-let2 gprops lprops
2887 '(call-interactively 'org-todo-list)))
2888 ((eq type 'search)
2889 (org-let2 gprops lprops
2890 '(org-search-view current-prefix-arg match nil)))
2891 ((eq type 'stuck)
2892 (org-let2 gprops lprops
2893 '(call-interactively 'org-agenda-list-stuck-projects)))
2894 ((eq type 'tags)
2895 (org-let2 gprops lprops
2896 '(org-tags-view current-prefix-arg match)))
2897 ((eq type 'tags-todo)
2898 (org-let2 gprops lprops
2899 '(org-tags-view '(4) match)))
2900 ((eq type 'todo)
2901 (org-let2 gprops lprops
2902 '(org-todo-list match)))
2903 ((fboundp type)
2904 (org-let2 gprops lprops
2905 '(funcall type match)))
2906 (t (error "Invalid type in command series")))))
2907 (widen)
2908 (let ((inhibit-read-only t))
2909 (add-text-properties (point-min) (point-max)
2910 `(org-series t org-series-redo-cmd ,redo)))
2911 (setq org-agenda-redo-command redo)
2912 (goto-char (point-min)))
2913 (org-agenda-fit-window-to-buffer)
2914 (org-let (nth 1 series) '(org-agenda-finalize)))
2916 ;;;###autoload
2917 (defmacro org-batch-agenda (cmd-key &rest parameters)
2918 "Run an agenda command in batch mode and send the result to STDOUT.
2919 If CMD-KEY is a string of length 1, it is used as a key in
2920 `org-agenda-custom-commands' and triggers this command. If it is a
2921 longer string it is used as a tags/todo match string.
2922 Parameters are alternating variable names and values that will be bound
2923 before running the agenda command."
2924 (org-eval-in-environment (org-make-parameter-alist parameters)
2925 (if (> (length cmd-key) 2)
2926 (org-tags-view nil cmd-key)
2927 (org-agenda nil cmd-key)))
2928 (set-buffer org-agenda-buffer-name)
2929 (princ (buffer-string)))
2931 (autoload 'org-batch-agenda "org-agenda" "\
2932 Run an agenda command in batch mode and send the result to STDOUT.
2933 If CMD-KEY is a string of length 1, it is used as a key in
2934 `org-agenda-custom-commands' and triggers this command. If it is a
2935 longer string it is used as a tags/todo match string.
2936 Parameters are alternating variable names and values that will be bound
2937 before running the agenda command.
2939 \(fn CMD-KEY &rest PARAMETERS)" nil t)
2940 (def-edebug-spec org-batch-agenda (form &rest sexp))
2942 (defvar org-agenda-info nil)
2944 ;;;###autoload
2945 (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
2946 "Run an agenda command in batch mode and send the result to STDOUT.
2947 If CMD-KEY is a string of length 1, it is used as a key in
2948 `org-agenda-custom-commands' and triggers this command. If it is a
2949 longer string it is used as a tags/todo match string.
2950 Parameters are alternating variable names and values that will be bound
2951 before running the agenda command.
2953 The output gives a line for each selected agenda item. Each
2954 item is a list of comma-separated values, like this:
2956 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
2958 category The category of the item
2959 head The headline, without TODO kwd, TAGS and PRIORITY
2960 type The type of the agenda entry, can be
2961 todo selected in TODO match
2962 tagsmatch selected in tags match
2963 diary imported from diary
2964 deadline a deadline on given date
2965 scheduled scheduled on given date
2966 timestamp entry has timestamp on given date
2967 closed entry was closed on given date
2968 upcoming-deadline warning about deadline
2969 past-scheduled forwarded scheduled item
2970 block entry has date block including g. date
2971 todo The todo keyword, if any
2972 tags All tags including inherited ones, separated by colons
2973 date The relevant date, like 2007-2-14
2974 time The time, like 15:00-16:50
2975 extra Sting with extra planning info
2976 priority-l The priority letter if any was given
2977 priority-n The computed numerical priority
2978 agenda-day The day in the agenda where this is listed"
2979 (org-eval-in-environment (append '((org-agenda-remove-tags t))
2980 (org-make-parameter-alist parameters))
2981 (if (> (length cmd-key) 2)
2982 (org-tags-view nil cmd-key)
2983 (org-agenda nil cmd-key)))
2984 (set-buffer org-agenda-buffer-name)
2985 (let* ((lines (org-split-string (buffer-string) "\n"))
2986 line)
2987 (while (setq line (pop lines))
2988 (catch 'next
2989 (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
2990 (setq org-agenda-info
2991 (org-fix-agenda-info (text-properties-at 0 line)))
2992 (princ
2993 (mapconcat 'org-agenda-export-csv-mapper
2994 '(org-category txt type todo tags date time extra
2995 priority-letter priority agenda-day)
2996 ","))
2997 (princ "\n")))))
2999 (autoload 'org-batch-agenda-csv "org-agenda" "\
3000 Run an agenda command in batch mode and send the result to STDOUT.
3001 If CMD-KEY is a string of length 1, it is used as a key in
3002 `org-agenda-custom-commands' and triggers this command. If it is a
3003 longer string it is used as a tags/todo match string.
3004 Parameters are alternating variable names and values that will be bound
3005 before running the agenda command.
3007 The output gives a line for each selected agenda item. Each
3008 item is a list of comma-separated values, like this:
3010 category,head,type,todo,tags,date,time,extra,priority-l,priority-n
3012 category The category of the item
3013 head The headline, without TODO kwd, TAGS and PRIORITY
3014 type The type of the agenda entry, can be
3015 todo selected in TODO match
3016 tagsmatch selected in tags match
3017 diary imported from diary
3018 deadline a deadline on given date
3019 scheduled scheduled on given date
3020 timestamp entry has timestamp on given date
3021 closed entry was closed on given date
3022 upcoming-deadline warning about deadline
3023 past-scheduled forwarded scheduled item
3024 block entry has date block including g. date
3025 todo The todo keyword, if any
3026 tags All tags including inherited ones, separated by colons
3027 date The relevant date, like 2007-2-14
3028 time The time, like 15:00-16:50
3029 extra Sting with extra planning info
3030 priority-l The priority letter if any was given
3031 priority-n The computed numerical priority
3032 agenda-day The day in the agenda where this is listed
3034 \(fn CMD-KEY &rest PARAMETERS)" nil t)
3035 (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
3037 (defun org-fix-agenda-info (props)
3038 "Make sure all properties on an agenda item have a canonical form.
3039 This ensures the export commands can easily use it."
3040 (let (tmp re)
3041 (when (setq tmp (plist-get props 'tags))
3042 (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
3043 (when (setq tmp (plist-get props 'date))
3044 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3045 (let ((calendar-date-display-form '(year "-" month "-" day)))
3046 '((format "%4d, %9s %2s, %4s" dayname monthname day year))
3048 (setq tmp (calendar-date-string tmp)))
3049 (setq props (plist-put props 'date tmp)))
3050 (when (setq tmp (plist-get props 'day))
3051 (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
3052 (let ((calendar-date-display-form '(year "-" month "-" day)))
3053 (setq tmp (calendar-date-string tmp)))
3054 (setq props (plist-put props 'day tmp))
3055 (setq props (plist-put props 'agenda-day tmp)))
3056 (when (setq tmp (plist-get props 'txt))
3057 (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
3058 (plist-put props 'priority-letter (match-string 1 tmp))
3059 (setq tmp (replace-match "" t t tmp)))
3060 (when (and (setq re (plist-get props 'org-todo-regexp))
3061 (setq re (concat "\\`\\.*" re " ?"))
3062 (string-match re tmp))
3063 (plist-put props 'todo (match-string 1 tmp))
3064 (setq tmp (replace-match "" t t tmp)))
3065 (plist-put props 'txt tmp)))
3066 props)
3068 (defun org-agenda-export-csv-mapper (prop)
3069 (let ((res (plist-get org-agenda-info prop)))
3070 (setq res
3071 (cond
3072 ((not res) "")
3073 ((stringp res) res)
3074 (t (prin1-to-string res))))
3075 (while (string-match "," res)
3076 (setq res (replace-match ";" t t res)))
3077 (org-trim res)))
3079 ;;;###autoload
3080 (defun org-store-agenda-views (&rest parameters)
3081 (interactive)
3082 (eval (list 'org-batch-store-agenda-views)))
3084 (autoload 'org-store-agenda-views "org-agenda" "\
3087 \(fn &rest PARAMETERS)" t nil)
3089 ;;;###autoload
3090 (defmacro org-batch-store-agenda-views (&rest parameters)
3091 "Run all custom agenda commands that have a file argument."
3092 (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
3093 (pop-up-frames nil)
3094 (dir default-directory)
3095 (pars (org-make-parameter-alist parameters))
3096 cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
3097 (save-window-excursion
3098 (while cmds
3099 (setq cmd (pop cmds)
3100 thiscmdkey (car cmd)
3101 thiscmdcmd (cdr cmd)
3102 match (nth 2 thiscmdcmd)
3103 bufname (if org-agenda-sticky
3104 (or (and (stringp match)
3105 (format "*Org Agenda(%s:%s)*" thiscmdkey match))
3106 (format "*Org Agenda(%s)*" thiscmdkey))
3107 org-agenda-buffer-name)
3108 cmd-or-set (nth 2 cmd)
3109 opts (nth (if (listp cmd-or-set) 3 4) cmd)
3110 files (nth (if (listp cmd-or-set) 4 5) cmd))
3111 (if (stringp files) (setq files (list files)))
3112 (when files
3113 (org-eval-in-environment (append org-agenda-exporter-settings
3114 opts pars)
3115 (org-agenda nil thiscmdkey))
3116 (set-buffer bufname)
3117 (while files
3118 (org-eval-in-environment (append org-agenda-exporter-settings
3119 opts pars)
3120 (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
3121 (and (get-buffer bufname)
3122 (kill-buffer bufname)))))))
3124 (autoload 'org-batch-store-agenda-views "org-agenda" "\
3125 Run all custom agenda commands that have a file argument.
3127 \(fn &rest PARAMETERS)" nil t)
3128 (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
3130 (defvar org-agenda-current-span nil
3131 "The current span used in the agenda view.") ; local variable in the agenda buffer
3132 (defun org-agenda-mark-header-line (pos)
3133 "Mark the line at POS as an agenda structure header."
3134 (save-excursion
3135 (goto-char pos)
3136 (put-text-property (point-at-bol) (point-at-eol)
3137 'org-agenda-structural-header t)
3138 (when org-agenda-title-append
3139 (put-text-property (point-at-bol) (point-at-eol)
3140 'org-agenda-title-append org-agenda-title-append))))
3142 (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
3143 (defvar org-agenda-write-buffer-name "Agenda View")
3144 (defun org-agenda-write (file &optional open nosettings agenda-bufname)
3145 "Write the current buffer (an agenda view) as a file.
3146 Depending on the extension of the file name, plain text (.txt),
3147 HTML (.html or .htm) or Postscript (.ps) is produced.
3148 If the extension is .ics, run icalendar export over all files used
3149 to construct the agenda and limit the export to entries listed in the
3150 agenda now.
3151 With prefix argument OPEN, open the new file immediately.
3152 If NOSETTINGS is given, do not scope the settings of
3153 `org-agenda-exporter-settings' into the export commands. This is used when
3154 the settings have already been scoped and we do not wish to overrule other,
3155 higher priority settings.
3156 If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
3157 (interactive "FWrite agenda to file: \nP")
3158 (if (not (file-writable-p file))
3159 (error "Cannot write agenda to file %s" file))
3160 (org-let (if nosettings nil org-agenda-exporter-settings)
3161 '(save-excursion
3162 (save-window-excursion
3163 (org-agenda-mark-filtered-text)
3164 (let ((bs (copy-sequence (buffer-string))) beg)
3165 (org-agenda-unmark-filtered-text)
3166 (with-temp-buffer
3167 (rename-buffer org-agenda-write-buffer-name t)
3168 (set-buffer-modified-p nil)
3169 (insert bs)
3170 (org-agenda-remove-marked-text 'org-filtered)
3171 (while (setq beg (text-property-any (point-min) (point-max)
3172 'org-filtered t))
3173 (delete-region
3174 beg (or (next-single-property-change beg 'org-filtered)
3175 (point-max))))
3176 (run-hooks 'org-agenda-before-write-hook)
3177 (cond
3178 ((org-bound-and-true-p org-mobile-creating-agendas)
3179 (org-mobile-write-agenda-for-mobile file))
3180 ((string-match "\\.html?\\'" file)
3181 (require 'htmlize)
3182 (set-buffer (htmlize-buffer (current-buffer)))
3183 (when org-agenda-export-html-style
3184 ;; replace <style> section with org-agenda-export-html-style
3185 (goto-char (point-min))
3186 (kill-region (- (search-forward "<style") 6)
3187 (search-forward "</style>"))
3188 (insert org-agenda-export-html-style))
3189 (write-file file)
3190 (kill-buffer (current-buffer))
3191 (message "HTML written to %s" file))
3192 ((string-match "\\.ps\\'" file)
3193 (require 'ps-print)
3194 (ps-print-buffer-with-faces file)
3195 (message "Postscript written to %s" file))
3196 ((string-match "\\.pdf\\'" file)
3197 (require 'ps-print)
3198 (ps-print-buffer-with-faces
3199 (concat (file-name-sans-extension file) ".ps"))
3200 (call-process "ps2pdf" nil nil nil
3201 (expand-file-name
3202 (concat (file-name-sans-extension file) ".ps"))
3203 (expand-file-name file))
3204 (delete-file (concat (file-name-sans-extension file) ".ps"))
3205 (message "PDF written to %s" file))
3206 ((string-match "\\.ics\\'" file)
3207 (require 'org-icalendar)
3208 (let ((org-agenda-marker-table
3209 (org-create-marker-find-array
3210 (org-agenda-collect-markers)))
3211 (org-icalendar-verify-function 'org-check-agenda-marker-table)
3212 (org-combined-agenda-icalendar-file file))
3213 (apply 'org-export-icalendar 'combine
3214 (org-agenda-files nil 'ifmode))))
3216 (let ((bs (buffer-string)))
3217 (find-file file)
3218 (erase-buffer)
3219 (insert bs)
3220 (save-buffer 0)
3221 (kill-buffer (current-buffer))
3222 (message "Plain text written to %s" file))))))))
3223 (set-buffer (or agenda-bufname
3224 (and (org-called-interactively-p 'any) (buffer-name))
3225 org-agenda-buffer-name)))
3226 (when open (org-open-file file)))
3228 (defvar org-agenda-tag-filter-overlays nil)
3229 (defvar org-agenda-cat-filter-overlays nil)
3231 (defun org-agenda-mark-filtered-text ()
3232 "Mark all text hidden by filtering with a text property."
3233 (let ((inhibit-read-only t))
3234 (mapc
3235 (lambda (o)
3236 (when (equal (overlay-buffer o) (current-buffer))
3237 (put-text-property
3238 (overlay-start o) (overlay-end o)
3239 'org-filtered t)))
3240 (append org-agenda-tag-filter-overlays
3241 org-agenda-cat-filter-overlays))))
3243 (defun org-agenda-unmark-filtered-text ()
3244 "Remove the filtering text property."
3245 (let ((inhibit-read-only t))
3246 (remove-text-properties (point-min) (point-max) '(org-filtered t))))
3248 (defun org-agenda-remove-marked-text (property &optional value)
3249 "Delete all text marked with VALUE of PROPERTY.
3250 VALUE defaults to t."
3251 (let (beg)
3252 (setq value (or value t))
3253 (while (setq beg (text-property-any (point-min) (point-max)
3254 property value))
3255 (delete-region
3256 beg (or (next-single-property-change beg 'org-filtered)
3257 (point-max))))))
3259 (defun org-agenda-add-entry-text ()
3260 "Add entry text to agenda lines.
3261 This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
3262 entry text following headings shown in the agenda.
3263 Drawers will be excluded, also the line with scheduling/deadline info."
3264 (when (and (> org-agenda-add-entry-text-maxlines 0)
3265 (not (org-bound-and-true-p org-mobile-creating-agendas)))
3266 (let (m txt)
3267 (goto-char (point-min))
3268 (while (not (eobp))
3269 (if (not (setq m (org-get-at-bol 'org-hd-marker)))
3270 (beginning-of-line 2)
3271 (setq txt (org-agenda-get-some-entry-text
3272 m org-agenda-add-entry-text-maxlines " > "))
3273 (end-of-line 1)
3274 (if (string-match "\\S-" txt)
3275 (insert "\n" txt)
3276 (or (eobp) (forward-char 1))))))))
3278 (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
3279 &rest keep)
3280 "Extract entry text from MARKER, at most N-LINES lines.
3281 This will ignore drawers etc, just get the text.
3282 If INDENT is given, prefix every line with this string. If KEEP is
3283 given, it is a list of symbols, defining stuff that should not be
3284 removed from the entry content. Currently only `planning' is allowed here."
3285 (let (txt drawer-re kwd-time-re ind)
3286 (save-excursion
3287 (with-current-buffer (marker-buffer marker)
3288 (if (not (derived-mode-p 'org-mode))
3289 (setq txt "")
3290 (save-excursion
3291 (save-restriction
3292 (widen)
3293 (goto-char marker)
3294 (end-of-line 1)
3295 (setq txt (buffer-substring
3296 (min (1+ (point)) (point-max))
3297 (progn (outline-next-heading) (point)))
3298 drawer-re org-drawer-regexp
3299 kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
3300 ".*\n?"))
3301 (with-temp-buffer
3302 (insert txt)
3303 (when org-agenda-add-entry-text-descriptive-links
3304 (goto-char (point-min))
3305 (while (org-activate-bracket-links (point-max))
3306 (add-text-properties (match-beginning 0) (match-end 0)
3307 '(face org-link))))
3308 (goto-char (point-min))
3309 (while (re-search-forward org-bracket-link-regexp (point-max) t)
3310 (set-text-properties (match-beginning 0) (match-end 0)
3311 nil))
3312 (goto-char (point-min))
3313 (while (re-search-forward drawer-re nil t)
3314 (delete-region
3315 (match-beginning 0)
3316 (progn (re-search-forward
3317 "^[ \t]*:END:.*\n?" nil 'move)
3318 (point))))
3319 (unless (member 'planning keep)
3320 (goto-char (point-min))
3321 (while (re-search-forward kwd-time-re nil t)
3322 (replace-match "")))
3323 (goto-char (point-min))
3324 (when org-agenda-entry-text-exclude-regexps
3325 (let ((re-list org-agenda-entry-text-exclude-regexps) re)
3326 (while (setq re (pop re-list))
3327 (goto-char (point-min))
3328 (while (re-search-forward re nil t)
3329 (replace-match "")))))
3330 (goto-char (point-max))
3331 (skip-chars-backward " \t\n")
3332 (if (looking-at "[ \t\n]+\\'") (replace-match ""))
3334 ;; find and remove min common indentation
3335 (goto-char (point-min))
3336 (untabify (point-min) (point-max))
3337 (setq ind (org-get-indentation))
3338 (while (not (eobp))
3339 (unless (looking-at "[ \t]*$")
3340 (setq ind (min ind (org-get-indentation))))
3341 (beginning-of-line 2))
3342 (goto-char (point-min))
3343 (while (not (eobp))
3344 (unless (looking-at "[ \t]*$")
3345 (move-to-column ind)
3346 (delete-region (point-at-bol) (point)))
3347 (beginning-of-line 2))
3349 (run-hooks 'org-agenda-entry-text-cleanup-hook)
3351 (goto-char (point-min))
3352 (when indent
3353 (while (and (not (eobp)) (re-search-forward "^" nil t))
3354 (replace-match indent t t)))
3355 (goto-char (point-min))
3356 (while (looking-at "[ \t]*\n") (replace-match ""))
3357 (goto-char (point-max))
3358 (when (> (org-current-line)
3359 n-lines)
3360 (org-goto-line (1+ n-lines))
3361 (backward-char 1))
3362 (setq txt (buffer-substring (point-min) (point)))))))))
3363 txt))
3365 (defun org-agenda-collect-markers ()
3366 "Collect the markers pointing to entries in the agenda buffer."
3367 (let (m markers)
3368 (save-excursion
3369 (goto-char (point-min))
3370 (while (not (eobp))
3371 (when (setq m (or (org-get-at-bol 'org-hd-marker)
3372 (org-get-at-bol 'org-marker)))
3373 (push m markers))
3374 (beginning-of-line 2)))
3375 (nreverse markers)))
3377 (defun org-create-marker-find-array (marker-list)
3378 "Create a alist of files names with all marker positions in that file."
3379 (let (f tbl m a p)
3380 (while (setq m (pop marker-list))
3381 (setq p (marker-position m)
3382 f (buffer-file-name (or (buffer-base-buffer
3383 (marker-buffer m))
3384 (marker-buffer m))))
3385 (if (setq a (assoc f tbl))
3386 (push (marker-position m) (cdr a))
3387 (push (list f p) tbl)))
3388 (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
3389 tbl)))
3391 (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
3392 (defun org-check-agenda-marker-table ()
3393 "Check of the current entry is on the marker list."
3394 (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
3396 (and (setq a (assoc file org-agenda-marker-table))
3397 (save-match-data
3398 (save-excursion
3399 (org-back-to-heading t)
3400 (member (point) (cdr a)))))))
3402 (defun org-check-for-org-mode ()
3403 "Make sure current buffer is in org-mode. Error if not."
3404 (or (derived-mode-p 'org-mode)
3405 (error "Cannot execute org-mode agenda command on buffer in %s"
3406 major-mode)))
3408 ;;; Agenda prepare and finalize
3410 (defvar org-agenda-multi nil) ; dynamically scoped
3411 (defvar org-agenda-pre-window-conf nil)
3412 (defvar org-agenda-columns-active nil)
3413 (defvar org-agenda-name nil)
3414 (defvar org-agenda-tag-filter nil)
3415 (defvar org-agenda-category-filter nil)
3416 (defvar org-agenda-top-category-filter nil)
3417 (defvar org-agenda-tag-filter-while-redo nil)
3418 (defvar org-agenda-tag-filter-preset nil
3419 "A preset of the tags filter used for secondary agenda filtering.
3420 This must be a list of strings, each string must be a single tag preceded
3421 by \"+\" or \"-\".
3422 This variable should not be set directly, but agenda custom commands can
3423 bind it in the options section. The preset filter is a global property of
3424 the entire agenda view. In a block agenda, it will not work reliably to
3425 define a filter for one of the individual blocks. You need to set it in
3426 the global options and expect it to be applied to the entire view.")
3428 (defvar org-agenda-category-filter-preset nil
3429 "A preset of the category filter used for secondary agenda filtering.
3430 This must be a list of strings, each string must be a single category
3431 preceded by \"+\" or \"-\".
3432 This variable should not be set directly, but agenda custom commands can
3433 bind it in the options section. The preset filter is a global property of
3434 the entire agenda view. In a block agenda, it will not work reliably to
3435 define a filter for one of the individual blocks. You need to set it in
3436 the global options and expect it to be applied to the entire view.")
3439 (defun org-agenda-use-sticky-p ()
3440 "Return non-nil if an agenda buffer named
3441 `org-agenda-buffer-name' exists and should be shown instead of
3442 generating a new one."
3443 (and
3444 ;; turned off by user
3445 org-agenda-sticky
3446 ;; For multi-agenda buffer already exists
3447 (not org-agenda-multi)
3448 ;; buffer found
3449 (get-buffer org-agenda-buffer-name)
3450 ;; C-u parameter is same as last call
3451 (with-current-buffer (get-buffer org-agenda-buffer-name)
3452 (and
3453 (equal current-prefix-arg
3454 org-agenda-last-prefix-arg)
3455 ;; In case user turned stickiness on, while having existing
3456 ;; Agenda buffer active, don't reuse that buffer, because it
3457 ;; does not have org variables local
3458 org-agenda-this-buffer-is-sticky))))
3460 (defun org-agenda-prepare-window (abuf)
3461 "Setup agenda buffer in the window."
3462 (let* ((awin (get-buffer-window abuf))
3463 wconf)
3464 (cond
3465 ((equal (current-buffer) abuf) nil)
3466 (awin (select-window awin))
3467 ((not (setq wconf (current-window-configuration))))
3468 ((equal org-agenda-window-setup 'current-window)
3469 (org-pop-to-buffer-same-window abuf))
3470 ((equal org-agenda-window-setup 'other-window)
3471 (org-switch-to-buffer-other-window abuf))
3472 ((equal org-agenda-window-setup 'other-frame)
3473 (switch-to-buffer-other-frame abuf))
3474 ((equal org-agenda-window-setup 'reorganize-frame)
3475 (delete-other-windows)
3476 (org-switch-to-buffer-other-window abuf)))
3477 ;; additional test in case agenda is invoked from within agenda
3478 ;; buffer via elisp link
3479 (unless (equal (current-buffer) abuf)
3480 (org-pop-to-buffer-same-window abuf))
3481 (setq org-agenda-pre-window-conf
3482 (or org-agenda-pre-window-conf wconf))))
3484 (defun org-agenda-prepare (&optional name)
3485 (if (org-agenda-use-sticky-p)
3486 (progn
3487 ;; Popup existing buffer
3488 (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
3489 (message "Sticky Agenda buffer, use `r' to refresh")
3490 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
3491 (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
3492 (setq org-todo-keywords-for-agenda nil)
3493 (setq org-drawers-for-agenda nil)
3494 (unless org-agenda-persistent-filter
3495 (setq org-agenda-tag-filter nil
3496 org-agenda-category-filter nil))
3497 (put 'org-agenda-tag-filter :preset-filter
3498 org-agenda-tag-filter-preset)
3499 (put 'org-agenda-category-filter :preset-filter
3500 org-agenda-category-filter-preset)
3501 (if org-agenda-multi
3502 (progn
3503 (setq buffer-read-only nil)
3504 (goto-char (point-max))
3505 (unless (or (bobp) org-agenda-compact-blocks
3506 (not org-agenda-block-separator))
3507 (insert "\n"
3508 (if (stringp org-agenda-block-separator)
3509 org-agenda-block-separator
3510 (make-string (window-width) org-agenda-block-separator))
3511 "\n"))
3512 (narrow-to-region (point) (point-max)))
3513 (setq org-done-keywords-for-agenda nil)
3515 ;; Setting any org variables that are in org-agenda-local-vars
3516 ;; list need to be done after the prepare call
3517 (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
3518 (setq buffer-read-only nil)
3519 (org-agenda-reset-markers)
3520 (let ((inhibit-read-only t)) (erase-buffer))
3521 (org-agenda-mode)
3522 (setq org-agenda-buffer (current-buffer))
3523 (setq org-agenda-contributing-files nil)
3524 (setq org-agenda-columns-active nil)
3525 (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
3526 (setq org-todo-keywords-for-agenda
3527 (org-uniquify org-todo-keywords-for-agenda))
3528 (setq org-done-keywords-for-agenda
3529 (org-uniquify org-done-keywords-for-agenda))
3530 (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
3531 (setq org-agenda-last-prefix-arg current-prefix-arg)
3532 (setq org-agenda-this-buffer-name org-agenda-buffer-name)
3533 (and name (not org-agenda-name)
3534 (org-set-local 'org-agenda-name name)))
3535 (setq buffer-read-only nil)))
3537 (defvar org-agenda-overriding-columns-format) ; From org-colview.el
3538 (defun org-agenda-finalize ()
3539 "Finishing touch for the agenda buffer, called just before displaying it."
3540 (unless org-agenda-multi
3541 (save-excursion
3542 (let ((inhibit-read-only t))
3543 (goto-char (point-min))
3544 (save-excursion
3545 (while (org-activate-bracket-links (point-max))
3546 (add-text-properties (match-beginning 0) (match-end 0)
3547 '(face org-link))))
3548 (save-excursion
3549 (while (org-activate-plain-links (point-max))
3550 (add-text-properties (match-beginning 0) (match-end 0)
3551 '(face org-link))))
3552 (when (cadr (assoc 'org-prefix-has-tag
3553 (car org-prefix-format-compiled)))
3554 (org-agenda-align-tags))
3555 (unless org-agenda-with-colors
3556 (remove-text-properties (point-min) (point-max) '(face nil))))
3557 (if (and (boundp 'org-agenda-overriding-columns-format)
3558 org-agenda-overriding-columns-format)
3559 (org-set-local 'org-agenda-overriding-columns-format
3560 org-agenda-overriding-columns-format))
3561 (if (and (boundp 'org-agenda-view-columns-initially)
3562 org-agenda-view-columns-initially)
3563 (org-agenda-columns))
3564 (when org-agenda-fontify-priorities
3565 (org-agenda-fontify-priorities))
3566 (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
3567 (org-agenda-dim-blocked-tasks))
3568 ;; We need to widen when `org-agenda-finalize' is called from
3569 ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
3570 (when org-clock-current-task
3571 (save-restriction
3572 (widen)
3573 (org-agenda-mark-clocking-task)))
3574 (when org-agenda-entry-text-mode
3575 (org-agenda-entry-text-hide)
3576 (org-agenda-entry-text-show))
3577 (if (and (functionp 'org-habit-insert-consistency-graphs)
3578 (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
3579 (org-habit-insert-consistency-graphs))
3580 (let ((inhibit-read-only t))
3581 (run-hooks 'org-agenda-finalize-hook))
3582 (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
3583 (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
3584 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
3585 (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
3586 (org-agenda-filter-apply org-agenda-category-filter 'category))
3587 (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
3589 (defun org-agenda-mark-clocking-task ()
3590 "Mark the current clock entry in the agenda if it is present."
3591 (mapc (lambda (o)
3592 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
3593 (delete-overlay o)))
3594 (overlays-in (point-min) (point-max)))
3595 (when (marker-buffer org-clock-hd-marker)
3596 (save-excursion
3597 (goto-char (point-min))
3598 (let (s ov)
3599 (while (setq s (next-single-property-change (point) 'org-hd-marker))
3600 (goto-char s)
3601 (when (equal (org-get-at-bol 'org-hd-marker)
3602 org-clock-hd-marker)
3603 (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
3604 (overlay-put ov 'type 'org-agenda-clocking)
3605 (overlay-put ov 'face 'org-agenda-clocking)
3606 (overlay-put ov 'help-echo
3607 "The clock is running in this item")))))))
3609 (defun org-agenda-fontify-priorities ()
3610 "Make highest priority lines bold, and lowest italic."
3611 (interactive)
3612 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
3613 (delete-overlay o)))
3614 (overlays-in (point-min) (point-max)))
3615 (save-excursion
3616 (let ((inhibit-read-only t)
3617 b e p ov h l)
3618 (goto-char (point-min))
3619 (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
3620 (setq h (or (get-char-property (point) 'org-highest-priority)
3621 org-highest-priority)
3622 l (or (get-char-property (point) 'org-lowest-priority)
3623 org-lowest-priority)
3624 p (string-to-char (match-string 1))
3625 b (match-beginning 0)
3626 e (if (eq org-agenda-fontify-priorities 'cookies)
3627 (match-end 0)
3628 (point-at-eol))
3629 ov (make-overlay b e))
3630 (overlay-put
3631 ov 'face
3632 (cond ((org-face-from-face-or-color
3633 'priority nil
3634 (cdr (assoc p org-priority-faces))))
3635 ((and (listp org-agenda-fontify-priorities)
3636 (org-face-from-face-or-color
3637 'priority nil
3638 (cdr (assoc p org-agenda-fontify-priorities)))))
3639 ((equal p l) 'italic)
3640 ((equal p h) 'bold)))
3641 (overlay-put ov 'org-type 'org-priority)))))
3643 (defun org-agenda-dim-blocked-tasks (&optional invisible)
3644 (interactive "P")
3645 "Dim currently blocked TODO's in the agenda display."
3646 (message "Dim or hide blocked tasks...")
3647 (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
3648 (delete-overlay o)))
3649 (overlays-in (point-min) (point-max)))
3650 (save-excursion
3651 (let ((inhibit-read-only t)
3652 (org-depend-tag-blocked nil)
3653 (invis (or (not (null invisible))
3654 (eq org-agenda-dim-blocked-tasks 'invisible)))
3655 org-blocked-by-checkboxes
3656 invis1 b e p ov h l)
3657 (goto-char (point-min))
3658 (while (let ((pos (next-single-property-change (point) 'todo-state)))
3659 (and pos (goto-char (1+ pos))))
3660 (setq org-blocked-by-checkboxes nil invis1 invis)
3661 (let ((marker (org-get-at-bol 'org-hd-marker)))
3662 (when (and marker
3663 (with-current-buffer (marker-buffer marker)
3664 (save-excursion (goto-char marker)
3665 (org-entry-blocked-p))))
3666 (if org-blocked-by-checkboxes (setq invis1 nil))
3667 (setq b (if invis1
3668 (max (point-min) (1- (point-at-bol)))
3669 (point-at-bol))
3670 e (point-at-eol)
3671 ov (make-overlay b e))
3672 (if invis1
3673 (overlay-put ov 'invisible t)
3674 (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
3675 (overlay-put ov 'org-type 'org-blocked-todo))))))
3676 (message "Dim or hide blocked tasks...done"))
3678 (defvar org-agenda-skip-function nil
3679 "Function to be called at each match during agenda construction.
3680 If this function returns nil, the current match should not be skipped.
3681 Otherwise, the function must return a position from where the search
3682 should be continued.
3683 This may also be a Lisp form, it will be evaluated.
3684 Never set this variable using `setq' or so, because then it will apply
3685 to all future agenda commands. If you do want a global skipping condition,
3686 use the option `org-agenda-skip-function-global' instead.
3687 The correct usage for `org-agenda-skip-function' is to bind it with
3688 `let' to scope it dynamically into the agenda-constructing command.
3689 A good way to set it is through options in `org-agenda-custom-commands'.")
3691 (defun org-agenda-skip ()
3692 "Throw to `:skip' in places that should be skipped.
3693 Also moves point to the end of the skipped region, so that search can
3694 continue from there."
3695 (let ((p (point-at-bol)) to)
3696 (when (org-in-src-block-p t) (throw :skip t))
3697 (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
3698 (get-text-property p :org-archived)
3699 (org-end-of-subtree t)
3700 (throw :skip t))
3701 (and org-agenda-skip-comment-trees
3702 (get-text-property p :org-comment)
3703 (org-end-of-subtree t)
3704 (throw :skip t))
3705 (if (equal (char-after p) ?#) (throw :skip t))
3706 (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
3707 (org-agenda-skip-eval org-agenda-skip-function)))
3708 (goto-char to)
3709 (throw :skip t))))
3711 (defun org-agenda-skip-eval (form)
3712 "If FORM is a function or a list, call (or eval) is and return result.
3713 `save-excursion' and `save-match-data' are wrapped around the call, so point
3714 and match data are returned to the previous state no matter what these
3715 functions do."
3716 (let (fp)
3717 (and form
3718 (or (setq fp (functionp form))
3719 (consp form))
3720 (save-excursion
3721 (save-match-data
3722 (if fp
3723 (funcall form)
3724 (eval form)))))))
3726 (defvar org-agenda-markers nil
3727 "List of all currently active markers created by `org-agenda'.")
3728 (defvar org-agenda-last-marker-time (org-float-time)
3729 "Creation time of the last agenda marker.")
3731 (defun org-agenda-new-marker (&optional pos)
3732 "Return a new agenda marker.
3733 Org-mode keeps a list of these markers and resets them when they are
3734 no longer in use."
3735 (let ((m (copy-marker (or pos (point)))))
3736 (setq org-agenda-last-marker-time (org-float-time))
3737 (if org-agenda-buffer
3738 (with-current-buffer org-agenda-buffer
3739 (push m org-agenda-markers))
3740 (push m org-agenda-markers))
3743 (defun org-agenda-reset-markers ()
3744 "Reset markers created by `org-agenda'."
3745 (while org-agenda-markers
3746 (move-marker (pop org-agenda-markers) nil)))
3748 (defun org-agenda-save-markers-for-cut-and-paste (beg end)
3749 "Save relative positions of markers in region.
3750 This check for agenda markers in all agenda buffers currently active."
3751 (dolist (buf (buffer-list))
3752 (with-current-buffer buf
3753 (when (eq major-mode 'org-agenda-mode)
3754 (mapc (lambda (m) (org-check-and-save-marker m beg end))
3755 org-agenda-markers)))))
3757 ;;; Entry text mode
3759 (defun org-agenda-entry-text-show-here ()
3760 "Add some text from the entry as context to the current line."
3761 (let (m txt o)
3762 (setq m (org-get-at-bol 'org-hd-marker))
3763 (unless (marker-buffer m)
3764 (error "No marker points to an entry here"))
3765 (setq txt (concat "\n" (org-no-properties
3766 (org-agenda-get-some-entry-text
3767 m org-agenda-entry-text-maxlines " > "))))
3768 (when (string-match "\\S-" txt)
3769 (setq o (make-overlay (point-at-bol) (point-at-eol)))
3770 (overlay-put o 'evaporate t)
3771 (overlay-put o 'org-overlay-type 'agenda-entry-content)
3772 (overlay-put o 'after-string txt))))
3774 (defun org-agenda-entry-text-show ()
3775 "Add entry context for all agenda lines."
3776 (interactive)
3777 (save-excursion
3778 (goto-char (point-max))
3779 (beginning-of-line 1)
3780 (while (not (bobp))
3781 (when (org-get-at-bol 'org-hd-marker)
3782 (org-agenda-entry-text-show-here))
3783 (beginning-of-line 0))))
3785 (defun org-agenda-entry-text-hide ()
3786 "Remove any shown entry context."
3787 (delq nil
3788 (mapcar (lambda (o)
3789 (if (eq (overlay-get o 'org-overlay-type)
3790 'agenda-entry-content)
3791 (progn (delete-overlay o) t)))
3792 (overlays-in (point-min) (point-max)))))
3794 (defun org-agenda-get-day-face (date)
3795 "Return the face DATE should be displayed with."
3796 (or (and (functionp org-agenda-day-face-function)
3797 (funcall org-agenda-day-face-function date))
3798 (cond ((org-agenda-todayp date)
3799 'org-agenda-date-today)
3800 ((member (calendar-day-of-week date) org-agenda-weekend-days)
3801 'org-agenda-date-weekend)
3802 (t 'org-agenda-date))))
3804 ;;; Agenda timeline
3806 (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
3808 (defun org-timeline (&optional dotodo)
3809 "Show a time-sorted view of the entries in the current org file.
3810 Only entries with a time stamp of today or later will be listed. With
3811 \\[universal-argument] prefix, all unfinished TODO items will also be shown,
3812 under the current date.
3813 If the buffer contains an active region, only check the region for
3814 dates."
3815 (interactive "P")
3816 (let* ((dopast t)
3817 (org-agenda-show-log-scoped org-agenda-show-log)
3818 (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
3819 (current-buffer))))
3820 (date (calendar-current-date))
3821 (beg (if (org-region-active-p) (region-beginning) (point-min)))
3822 (end (if (org-region-active-p) (region-end) (point-max)))
3823 (day-numbers (org-get-all-dates
3824 beg end 'no-ranges
3825 t org-agenda-show-log-scoped ; always include today
3826 org-timeline-show-empty-dates))
3827 (org-deadline-warning-days 0)
3828 (org-agenda-only-exact-dates t)
3829 (today (org-today))
3830 (past t)
3831 args
3832 s e rtn d emptyp)
3833 (setq org-agenda-redo-command
3834 (list 'progn
3835 (list 'org-switch-to-buffer-other-window (current-buffer))
3836 (list 'org-timeline (list 'quote dotodo))))
3837 (if (not dopast)
3838 ;; Remove past dates from the list of dates.
3839 (setq day-numbers (delq nil (mapcar (lambda(x)
3840 (if (>= x today) x nil))
3841 day-numbers))))
3842 (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
3843 (org-compile-prefix-format 'timeline)
3844 (org-set-sorting-strategy 'timeline)
3845 (if org-agenda-show-log-scoped (push :closed args))
3846 (push :timestamp args)
3847 (push :deadline args)
3848 (push :scheduled args)
3849 (push :sexp args)
3850 (if dotodo (push :todo args))
3851 (insert "Timeline of file " entry "\n")
3852 (add-text-properties (point-min) (point)
3853 (list 'face 'org-agenda-structure))
3854 (org-agenda-mark-header-line (point-min))
3855 (while (setq d (pop day-numbers))
3856 (if (and (listp d) (eq (car d) :omitted))
3857 (progn
3858 (setq s (point))
3859 (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
3860 (put-text-property s (1- (point)) 'face 'org-agenda-structure))
3861 (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
3862 (if (and (>= d today)
3863 dopast
3864 past)
3865 (progn
3866 (setq past nil)
3867 (insert (make-string 79 ?-) "\n")))
3868 (setq date (calendar-gregorian-from-absolute d))
3869 (setq s (point))
3870 (setq rtn (and (not emptyp)
3871 (apply 'org-agenda-get-day-entries entry
3872 date args)))
3873 (if (or rtn (equal d today) org-timeline-show-empty-dates)
3874 (progn
3875 (insert
3876 (if (stringp org-agenda-format-date)
3877 (format-time-string org-agenda-format-date
3878 (org-time-from-absolute date))
3879 (funcall org-agenda-format-date date))
3880 "\n")
3881 (put-text-property s (1- (point)) 'face
3882 (org-agenda-get-day-face date))
3883 (put-text-property s (1- (point)) 'org-date-line t)
3884 (put-text-property s (1- (point)) 'org-agenda-date-header t)
3885 (if (equal d today)
3886 (put-text-property s (1- (point)) 'org-today t))
3887 (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
3888 (put-text-property s (1- (point)) 'day d)))))
3889 (goto-char (point-min))
3890 (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
3891 (point-min)))
3892 (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
3893 (org-agenda-finalize)
3894 (setq buffer-read-only t)))
3896 (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
3897 "Return a list of all relevant day numbers from BEG to END buffer positions.
3898 If NO-RANGES is non-nil, include only the start and end dates of a range,
3899 not every single day in the range. If FORCE-TODAY is non-nil, make
3900 sure that TODAY is included in the list. If INACTIVE is non-nil, also
3901 inactive time stamps (those in square brackets) are included.
3902 When EMPTY is non-nil, also include days without any entries."
3903 (let ((re (concat
3904 (if pre-re pre-re "")
3905 (if inactive org-ts-regexp-both org-ts-regexp)))
3906 dates dates1 date day day1 day2 ts1 ts2 pos)
3907 (if force-today
3908 (setq dates (list (org-today))))
3909 (save-excursion
3910 (goto-char beg)
3911 (while (re-search-forward re end t)
3912 (setq day (time-to-days (org-time-string-to-time
3913 (substring (match-string 1) 0 10)
3914 (current-buffer) (match-beginning 0))))
3915 (or (memq day dates) (push day dates)))
3916 (unless no-ranges
3917 (goto-char beg)
3918 (while (re-search-forward org-tr-regexp end t)
3919 (setq pos (match-beginning 0))
3920 (setq ts1 (substring (match-string 1) 0 10)
3921 ts2 (substring (match-string 2) 0 10)
3922 day1 (time-to-days (org-time-string-to-time
3923 ts1 (current-buffer) pos))
3924 day2 (time-to-days (org-time-string-to-time
3925 ts2 (current-buffer) pos)))
3926 (while (< (setq day1 (1+ day1)) day2)
3927 (or (memq day1 dates) (push day1 dates)))))
3928 (setq dates (sort dates '<))
3929 (when empty
3930 (while (setq day (pop dates))
3931 (setq day2 (car dates))
3932 (push day dates1)
3933 (when (and day2 empty)
3934 (if (or (eq empty t)
3935 (and (numberp empty) (<= (- day2 day) empty)))
3936 (while (< (setq day (1+ day)) day2)
3937 (push (list day) dates1))
3938 (push (cons :omitted (- day2 day)) dates1))))
3939 (setq dates (nreverse dates1)))
3940 dates)))
3942 ;;; Agenda Daily/Weekly
3944 (defvar org-agenda-start-day nil ; dynamically scoped parameter
3945 "Start day for the agenda view.
3946 Custom commands can set this variable in the options section.")
3947 (defvar org-starting-day nil) ; local variable in the agenda buffer
3948 (defvar org-arg-loc nil) ; local variable
3950 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
3951 "List of types searched for when creating the daily/weekly agenda.
3952 This variable is a list of symbols that controls the types of
3953 items that appear in the daily/weekly agenda. Allowed symbols in this
3954 list are are
3956 :timestamp List items containing a date stamp or date range matching
3957 the selected date. This includes sexp entries in
3958 angular brackets.
3960 :sexp List entries resulting from plain diary-like sexps.
3962 :deadline List deadline due on that date. When the date is today,
3963 also list any deadlines past due, or due within
3964 `org-deadline-warning-days'. `:deadline' must appear before
3965 `:scheduled' if the setting of
3966 `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
3967 any effect.
3969 :scheduled List all items which are scheduled for the given date.
3970 The diary for *today* also contains items which were
3971 scheduled earlier and are not yet marked DONE.
3973 By default, all four types are turned on.
3975 Never set this variable globally using `setq', because then it
3976 will apply to all future agenda commands. Instead, bind it with
3977 `let' to scope it dynamically into the agenda-constructing
3978 command. A good way to set it is through options in
3979 `org-agenda-custom-commands'. For a more flexible (though
3980 somewhat less efficient) way of determining what is included in
3981 the daily/weekly agenda, see `org-agenda-skip-function'.")
3983 (defvar org-agenda-buffer-tmp-name nil)
3984 ;;;###autoload
3985 (defun org-agenda-list (&optional arg start-day span)
3986 "Produce a daily/weekly view from all files in variable `org-agenda-files'.
3987 The view will be for the current day or week, but from the overview buffer
3988 you will be able to go to other days/weeks.
3990 With a numeric prefix argument in an interactive call, the agenda will
3991 span ARG days. Lisp programs should instead specify SPAN to change
3992 the number of days. SPAN defaults to `org-agenda-span'.
3994 START-DAY defaults to TODAY, or to the most recent match for the weekday
3995 given in `org-agenda-start-on-weekday'."
3996 (interactive "P")
3997 (if org-agenda-overriding-arguments
3998 (setq arg (car org-agenda-overriding-arguments)
3999 start-day (nth 1 org-agenda-overriding-arguments)
4000 span (nth 2 org-agenda-overriding-arguments)))
4001 (if (and (integerp arg) (> arg 0))
4002 (setq span arg arg nil))
4003 (catch 'exit
4004 (setq org-agenda-buffer-name
4005 (or org-agenda-buffer-tmp-name
4006 (if org-agenda-sticky
4007 (cond ((and org-keys (stringp org-match))
4008 (format "*Org Agenda(%s:%s)*" org-keys org-match))
4009 (org-keys
4010 (format "*Org Agenda(%s)*" org-keys))
4011 (t "*Org Agenda(a)*")))
4012 org-agenda-buffer-name))
4013 (org-agenda-prepare "Day/Week")
4014 (setq start-day (or start-day org-agenda-start-day))
4015 (if (stringp start-day)
4016 ;; Convert to an absolute day number
4017 (setq start-day (time-to-days (org-read-date nil t start-day))))
4018 (org-compile-prefix-format 'agenda)
4019 (org-set-sorting-strategy 'agenda)
4020 (let* ((span (org-agenda-ndays-to-span
4021 (or span org-agenda-ndays org-agenda-span)))
4022 (today (org-today))
4023 (sd (or start-day today))
4024 (ndays (org-agenda-span-to-ndays span sd))
4025 (org-agenda-start-on-weekday
4026 (if (eq ndays 7)
4027 org-agenda-start-on-weekday))
4028 (thefiles (org-agenda-files nil 'ifmode))
4029 (files thefiles)
4030 (start (if (or (null org-agenda-start-on-weekday)
4031 (< ndays 7))
4033 (let* ((nt (calendar-day-of-week
4034 (calendar-gregorian-from-absolute sd)))
4035 (n1 org-agenda-start-on-weekday)
4036 (d (- nt n1)))
4037 (- sd (+ (if (< d 0) 7 0) d)))))
4038 (day-numbers (list start))
4039 (day-cnt 0)
4040 (inhibit-redisplay (not debug-on-error))
4041 (org-agenda-show-log-scoped org-agenda-show-log)
4042 s e rtn rtnall file date d start-pos end-pos todayp
4043 clocktable-start clocktable-end filter)
4044 (setq org-agenda-redo-command
4045 (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
4046 (dotimes (n (1- ndays))
4047 (push (1+ (car day-numbers)) day-numbers))
4048 (setq day-numbers (nreverse day-numbers))
4049 (setq clocktable-start (car day-numbers)
4050 clocktable-end (1+ (or (org-last day-numbers) 0)))
4051 (org-set-local 'org-starting-day (car day-numbers))
4052 (org-set-local 'org-arg-loc arg)
4053 (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
4054 (unless org-agenda-compact-blocks
4055 (let* ((d1 (car day-numbers))
4056 (d2 (org-last day-numbers))
4057 (w1 (org-days-to-iso-week d1))
4058 (w2 (org-days-to-iso-week d2)))
4059 (setq s (point))
4060 (if org-agenda-overriding-header
4061 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4062 nil 'face 'org-agenda-structure) "\n")
4063 (insert (org-agenda-span-name span)
4064 "-agenda"
4065 (if (< (- d2 d1) 350)
4066 (if (= w1 w2)
4067 (format " (W%02d)" w1)
4068 (format " (W%02d-W%02d)" w1 w2))
4070 ":\n")))
4071 (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
4072 'org-date-line t))
4073 (org-agenda-mark-header-line s))
4074 (while (setq d (pop day-numbers))
4075 (setq date (calendar-gregorian-from-absolute d)
4076 s (point))
4077 (if (or (setq todayp (= d today))
4078 (and (not start-pos) (= d sd)))
4079 (setq start-pos (point))
4080 (if (and start-pos (not end-pos))
4081 (setq end-pos (point))))
4082 (setq files thefiles
4083 rtnall nil)
4084 (while (setq file (pop files))
4085 (catch 'nextfile
4086 (org-check-agenda-file file)
4087 (let ((org-agenda-entry-types org-agenda-entry-types))
4088 (unless org-agenda-include-deadlines
4089 (setq org-agenda-entry-types
4090 (delq :deadline org-agenda-entry-types)))
4091 (cond
4092 ((memq org-agenda-show-log-scoped '(only clockcheck))
4093 (setq rtn (org-agenda-get-day-entries
4094 file date :closed)))
4095 (org-agenda-show-log-scoped
4096 (setq rtn (apply 'org-agenda-get-day-entries
4097 file date
4098 (append '(:closed) org-agenda-entry-types))))
4100 (setq rtn (apply 'org-agenda-get-day-entries
4101 file date
4102 org-agenda-entry-types)))))
4103 (setq rtnall (append rtnall rtn)))) ;; all entries
4104 (if org-agenda-include-diary
4105 (let ((org-agenda-search-headline-for-time t))
4106 (require 'diary-lib)
4107 (setq rtn (org-get-entries-from-diary date))
4108 (setq rtnall (append rtnall rtn))))
4109 (if (or rtnall org-agenda-show-all-dates)
4110 (progn
4111 (setq day-cnt (1+ day-cnt))
4112 (insert
4113 (if (stringp org-agenda-format-date)
4114 (format-time-string org-agenda-format-date
4115 (org-time-from-absolute date))
4116 (funcall org-agenda-format-date date))
4117 "\n")
4118 (put-text-property s (1- (point)) 'face
4119 (org-agenda-get-day-face date))
4120 (put-text-property s (1- (point)) 'org-date-line t)
4121 (put-text-property s (1- (point)) 'org-agenda-date-header t)
4122 (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
4123 (when todayp
4124 (put-text-property s (1- (point)) 'org-today t))
4125 (setq rtnall
4126 (org-agenda-add-time-grid-maybe rtnall ndays todayp))
4127 (if rtnall (insert ;; all entries
4128 (org-agenda-finalize-entries rtnall)
4129 "\n"))
4130 (put-text-property s (1- (point)) 'day d)
4131 (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
4132 (when (and org-agenda-clockreport-mode clocktable-start)
4133 (let ((org-agenda-files (org-agenda-files nil 'ifmode))
4134 ;; the above line is to ensure the restricted range!
4135 (p (copy-sequence org-agenda-clockreport-parameter-plist))
4136 tbl)
4137 (setq p (org-plist-delete p :block))
4138 (setq p (plist-put p :tstart clocktable-start))
4139 (setq p (plist-put p :tend clocktable-end))
4140 (setq p (plist-put p :scope 'agenda))
4141 (when (and (eq org-agenda-clockreport-mode 'with-filter)
4142 (setq filter (or org-agenda-tag-filter-while-redo
4143 (get 'org-agenda-tag-filter :preset-filter))))
4144 (setq p (plist-put p :tags (mapconcat (lambda (x)
4145 (if (string-match "[<>=]" x)
4148 filter ""))))
4149 (setq tbl (apply 'org-clock-get-clocktable p))
4150 (insert tbl)))
4151 (goto-char (point-min))
4152 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4153 (unless (and (pos-visible-in-window-p (point-min))
4154 (pos-visible-in-window-p (point-max)))
4155 (goto-char (1- (point-max)))
4156 (recenter -1)
4157 (if (not (pos-visible-in-window-p (or start-pos 1)))
4158 (progn
4159 (goto-char (or start-pos 1))
4160 (recenter 1))))
4161 (goto-char (or start-pos 1))
4162 (add-text-properties (point-min) (point-max)
4163 `(org-agenda-type agenda
4164 org-last-args (,arg ,start-day ,span)
4165 org-redo-cmd ,org-agenda-redo-command
4166 org-series-cmd ,org-cmd))
4167 (if (eq org-agenda-show-log-scoped 'clockcheck)
4168 (org-agenda-show-clocking-issues))
4169 (org-agenda-finalize)
4170 (setq buffer-read-only t)
4171 (message ""))))
4173 (autoload 'org-agenda-list "org-agenda" "\
4174 Produce a daily/weekly view from all files in variable `org-agenda-files'.
4175 The view will be for the current day or week, but from the overview buffer
4176 you will be able to go to other days/weeks.
4178 With a numeric prefix argument in an interactive call, the agenda will
4179 span ARG days. Lisp programs should instead specify SPAN to change
4180 the number of days. SPAN defaults to `org-agenda-span'.
4182 START-DAY defaults to TODAY, or to the most recent match for the weekday
4183 given in `org-agenda-start-on-weekday'.
4185 \(fn &optional ARG START-DAY SPAN)" t nil)
4187 (defun org-agenda-ndays-to-span (n)
4188 "Return a span symbol for a span of N days, or N if none matches."
4189 (cond ((symbolp n) n)
4190 ((= n 1) 'day)
4191 ((= n 7) 'week)
4192 (t n)))
4194 (defun org-agenda-span-to-ndays (span &optional start-day)
4195 "Return ndays from SPAN, possibly starting at START-DAY."
4196 (cond ((numberp span) span)
4197 ((eq span 'day) 1)
4198 ((eq span 'week) 7)
4199 ((eq span 'month)
4200 (let ((date (calendar-gregorian-from-absolute start-day)))
4201 (calendar-last-day-of-month (car date) (caddr date))))
4202 ((eq span 'year)
4203 (let ((date (calendar-gregorian-from-absolute start-day)))
4204 (if (calendar-leap-year-p (caddr date)) 366 365)))))
4206 (defun org-agenda-span-name (span)
4207 "Return a SPAN name."
4208 (if (null span)
4210 (if (symbolp span)
4211 (capitalize (symbol-name span))
4212 (format "%d days" span))))
4214 ;;; Agenda word search
4216 (defvar org-agenda-search-history nil)
4218 (defvar org-search-syntax-table nil
4219 "Special syntax table for org-mode search.
4220 In this table, we have single quotes not as word constituents, to
4221 that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
4223 (defvar org-mode-syntax-table) ; From org.el
4224 (defun org-search-syntax-table ()
4225 (unless org-search-syntax-table
4226 (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
4227 (modify-syntax-entry ?' "." org-search-syntax-table)
4228 (modify-syntax-entry ?` "." org-search-syntax-table))
4229 org-search-syntax-table)
4231 (defvar org-agenda-last-search-view-search-was-boolean nil)
4233 ;;;###autoload
4234 (defun org-search-view (&optional todo-only string edit-at)
4235 "Show all entries that contain a phrase or words or regular expressions.
4237 With optional prefix argument TODO-ONLY, only consider entries that are
4238 TODO entries. The argument STRING can be used to pass a default search
4239 string into this function. If EDIT-AT is non-nil, it means that the
4240 user should get a chance to edit this string, with cursor at position
4241 EDIT-AT.
4243 The search string can be viewed either as a phrase that should be found as
4244 is, or it can be broken into a number of snippets, each of which must match
4245 in a Boolean way to select an entry. The default depends on the variable
4246 `org-agenda-search-view-always-boolean'.
4247 Even if this is turned off (the default) you can always switch to
4248 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4250 The default is a direct search of the whole phrase, where each space in
4251 the search string can expand to an arbitrary amount of whitespace,
4252 including newlines.
4254 If using a Boolean search, the search string is split on whitespace and
4255 each snippet is searched separately, with logical AND to select an entry.
4256 Words prefixed with a minus must *not* occur in the entry. Words without
4257 a prefix or prefixed with a plus must occur in the entry. Matching is
4258 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4259 match whole words, not parts of a word) if
4260 `org-agenda-search-view-force-full-words' is set (default is nil).
4262 Boolean search snippets enclosed by curly braces are interpreted as
4263 regular expressions that must or (when preceded with \"-\") must not
4264 match in the entry. Snippets enclosed into double quotes will be taken
4265 as a whole, to include whitespace.
4267 - If the search string starts with an asterisk, search only in headlines.
4268 - If (possibly after the leading star) the search string starts with an
4269 exclamation mark, this also means to look at TODO entries only, an effect
4270 that can also be achieved with a prefix argument.
4271 - If (possibly after star and exclamation mark) the search string starts
4272 with a colon, this will mean that the (non-regexp) snippets of the
4273 Boolean search must match as full words.
4275 This command searches the agenda files, and in addition the files listed
4276 in `org-agenda-text-search-extra-files'."
4277 (interactive "P")
4278 (if org-agenda-overriding-arguments
4279 (setq todo-only (car org-agenda-overriding-arguments)
4280 string (nth 1 org-agenda-overriding-arguments)
4281 edit-at (nth 2 org-agenda-overriding-arguments)))
4282 (let* ((props (list 'face nil
4283 'done-face 'org-agenda-done
4284 'org-not-done-regexp org-not-done-regexp
4285 'org-todo-regexp org-todo-regexp
4286 'org-complex-heading-regexp org-complex-heading-regexp
4287 'mouse-face 'highlight
4288 'help-echo (format "mouse-2 or RET jump to location")))
4289 (full-words org-agenda-search-view-force-full-words)
4290 (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
4291 regexp rtn rtnall files file pos
4292 marker category category-pos level tags c neg re boolean
4293 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
4294 (unless (and (not edit-at)
4295 (stringp string)
4296 (string-match "\\S-" string))
4297 (setq string (read-string
4298 (if org-agenda-search-view-always-boolean
4299 "[+-]Word/{Regexp} ...: "
4300 "Phrase or [+-]Word/{Regexp} ...: ")
4301 (cond
4302 ((integerp edit-at) (cons string edit-at))
4303 (edit-at string))
4304 'org-agenda-search-history)))
4305 (catch 'exit
4306 (if org-agenda-sticky
4307 (setq org-agenda-buffer-name
4308 (if (stringp string)
4309 (format "*Org Agenda(%s:%s)*"
4310 (or org-keys (or (and todo-only "S") "s")) string)
4311 (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
4312 (org-agenda-prepare "SEARCH")
4313 (org-compile-prefix-format 'search)
4314 (org-set-sorting-strategy 'search)
4315 (setq org-agenda-redo-command
4316 (list 'org-search-view (if todo-only t nil)
4317 (list 'if 'current-prefix-arg nil string)))
4318 (setq org-agenda-query-string string)
4319 (if (equal (string-to-char string) ?*)
4320 (setq hdl-only t
4321 words (substring string 1))
4322 (setq words string))
4323 (when (equal (string-to-char words) ?!)
4324 (setq todo-only t
4325 words (substring words 1)))
4326 (when (equal (string-to-char words) ?:)
4327 (setq full-words t
4328 words (substring words 1)))
4329 (if (or org-agenda-search-view-always-boolean
4330 (member (string-to-char words) '(?- ?+ ?\{)))
4331 (setq boolean t))
4332 (setq words (org-split-string words))
4333 (let (www w)
4334 (while (setq w (pop words))
4335 (while (and (string-match "\\\\\\'" w) words)
4336 (setq w (concat (substring w 0 -1) " " (pop words))))
4337 (push w www))
4338 (setq words (nreverse www) www nil)
4339 (while (setq w (pop words))
4340 (when (and (string-match "\\`[-+]?{" w)
4341 (not (string-match "}\\'" w)))
4342 (while (and words (not (string-match "}\\'" (car words))))
4343 (setq w (concat w " " (pop words))))
4344 (setq w (concat w " " (pop words))))
4345 (push w www))
4346 (setq words (nreverse www)))
4347 (setq org-agenda-last-search-view-search-was-boolean boolean)
4348 (when boolean
4349 (let (wds w)
4350 (while (setq w (pop words))
4351 (if (or (equal (substring w 0 1) "\"")
4352 (and (> (length w) 1)
4353 (member (substring w 0 1) '("+" "-"))
4354 (equal (substring w 1 2) "\"")))
4355 (while (and words (not (equal (substring w -1) "\"")))
4356 (setq w (concat w " " (pop words)))))
4357 (and (string-match "\\`\\([-+]?\\)\"" w)
4358 (setq w (replace-match "\\1" nil nil w)))
4359 (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
4360 (push w wds))
4361 (setq words (nreverse wds))))
4362 (if boolean
4363 (mapc (lambda (w)
4364 (setq c (string-to-char w))
4365 (if (equal c ?-)
4366 (setq neg t w (substring w 1))
4367 (if (equal c ?+)
4368 (setq neg nil w (substring w 1))
4369 (setq neg nil)))
4370 (if (string-match "\\`{.*}\\'" w)
4371 (setq re (substring w 1 -1))
4372 (if full-words
4373 (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
4374 (setq re (regexp-quote (downcase w)))))
4375 (if neg (push re regexps-) (push re regexps+)))
4376 words)
4377 (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
4378 regexps+))
4379 (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
4380 (if (not regexps+)
4381 (setq regexp org-outline-regexp-bol)
4382 (setq regexp (pop regexps+))
4383 (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
4384 regexp))))
4385 (setq files (org-agenda-files nil 'ifmode))
4386 (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
4387 (pop org-agenda-text-search-extra-files)
4388 (setq files (org-add-archive-files files)))
4389 (setq files (append files org-agenda-text-search-extra-files)
4390 rtnall nil)
4391 (while (setq file (pop files))
4392 (setq ee nil)
4393 (catch 'nextfile
4394 (org-check-agenda-file file)
4395 (setq buffer (if (file-exists-p file)
4396 (org-get-agenda-file-buffer file)
4397 (error "No such file %s" file)))
4398 (if (not buffer)
4399 ;; If file does not exist, make sure an error message is sent
4400 (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
4401 file))))
4402 (with-current-buffer buffer
4403 (with-syntax-table (org-search-syntax-table)
4404 (unless (derived-mode-p 'org-mode)
4405 (error "Agenda file %s is not in `org-mode'" file))
4406 (let ((case-fold-search t))
4407 (save-excursion
4408 (save-restriction
4409 (if org-agenda-restrict
4410 (narrow-to-region org-agenda-restrict-begin
4411 org-agenda-restrict-end)
4412 (widen))
4413 (goto-char (point-min))
4414 (unless (or (org-at-heading-p)
4415 (outline-next-heading))
4416 (throw 'nextfile t))
4417 (goto-char (max (point-min) (1- (point))))
4418 (while (re-search-forward regexp nil t)
4419 (org-back-to-heading t)
4420 (while (and org-agenda-search-view-max-outline-level
4421 (> (org-reduced-level (org-outline-level))
4422 org-agenda-search-view-max-outline-level)
4423 (forward-line -1)
4424 (outline-back-to-heading t)))
4425 (skip-chars-forward "* ")
4426 (setq beg (point-at-bol)
4427 beg1 (point)
4428 end (progn
4429 (outline-next-heading)
4430 (while (and org-agenda-search-view-max-outline-level
4431 (> (org-reduced-level (org-outline-level))
4432 org-agenda-search-view-max-outline-level)
4433 (forward-line 1)
4434 (outline-next-heading)))
4435 (point)))
4437 (catch :skip
4438 (goto-char beg)
4439 (org-agenda-skip)
4440 (setq str (buffer-substring-no-properties
4441 (point-at-bol)
4442 (if hdl-only (point-at-eol) end)))
4443 (mapc (lambda (wr) (when (string-match wr str)
4444 (goto-char (1- end))
4445 (throw :skip t)))
4446 regexps-)
4447 (mapc (lambda (wr) (unless (string-match wr str)
4448 (goto-char (1- end))
4449 (throw :skip t)))
4450 (if todo-only
4451 (cons (concat "^\*+[ \t]+" org-not-done-regexp)
4452 regexps+)
4453 regexps+))
4454 (goto-char beg)
4455 (setq marker (org-agenda-new-marker (point))
4456 category (org-get-category)
4457 level (make-string (org-reduced-level (org-outline-level)) ? )
4458 category-pos (get-text-property (point) 'org-category-position)
4459 tags (org-get-tags-at (point))
4460 txt (org-agenda-format-item
4462 (buffer-substring-no-properties
4463 beg1 (point-at-eol))
4464 level category tags t))
4465 (org-add-props txt props
4466 'org-marker marker 'org-hd-marker marker
4467 'org-todo-regexp org-todo-regexp
4468 'level level
4469 'org-complex-heading-regexp org-complex-heading-regexp
4470 'priority 1000 'org-category category
4471 'org-category-position category-pos
4472 'type "search")
4473 (push txt ee)
4474 (goto-char (1- end))))))))))
4475 (setq rtn (nreverse ee))
4476 (setq rtnall (append rtnall rtn)))
4477 (if org-agenda-overriding-header
4478 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4479 nil 'face 'org-agenda-structure) "\n")
4480 (insert "Search words: ")
4481 (add-text-properties (point-min) (1- (point))
4482 (list 'face 'org-agenda-structure))
4483 (setq pos (point))
4484 (insert string "\n")
4485 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4486 (setq pos (point))
4487 (unless org-agenda-multi
4488 (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
4489 (add-text-properties pos (1- (point))
4490 (list 'face 'org-agenda-structure))))
4491 (org-agenda-mark-header-line (point-min))
4492 (when rtnall
4493 (insert (org-agenda-finalize-entries rtnall) "\n"))
4494 (goto-char (point-min))
4495 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4496 (add-text-properties (point-min) (point-max)
4497 `(org-agenda-type search
4498 org-last-args (,todo-only ,string ,edit-at)
4499 org-redo-cmd ,org-agenda-redo-command
4500 org-series-cmd ,org-cmd))
4501 (org-agenda-finalize)
4502 (setq buffer-read-only t))))
4504 (autoload 'org-search-view "org-agenda" "\
4505 Show all entries that contain a phrase or words or regular expressions.
4507 With optional prefix argument TODO-ONLY, only consider entries that are
4508 TODO entries. The argument STRING can be used to pass a default search
4509 string into this function. If EDIT-AT is non-nil, it means that the
4510 user should get a chance to edit this string, with cursor at position
4511 EDIT-AT.
4513 The search string can be viewed either as a phrase that should be found as
4514 is, or it can be broken into a number of snippets, each of which must match
4515 in a Boolean way to select an entry. The default depends on the variable
4516 `org-agenda-search-view-always-boolean'.
4517 Even if this is turned off (the default) you can always switch to
4518 Boolean search dynamically by preceding the first word with \"+\" or \"-\".
4520 The default is a direct search of the whole phrase, where each space in
4521 the search string can expand to an arbitrary amount of whitespace,
4522 including newlines.
4524 If using a Boolean search, the search string is split on whitespace and
4525 each snippet is searched separately, with logical AND to select an entry.
4526 Words prefixed with a minus must *not* occur in the entry. Words without
4527 a prefix or prefixed with a plus must occur in the entry. Matching is
4528 case-insensitive. Words are enclosed by word delimiters (i.e. they must
4529 match whole words, not parts of a word) if
4530 `org-agenda-search-view-force-full-words' is set (default is nil).
4532 Boolean search snippets enclosed by curly braces are interpreted as
4533 regular expressions that must or (when preceded with \"-\") must not
4534 match in the entry. Snippets enclosed into double quotes will be taken
4535 as a whole, to include whitespace.
4537 - If the search string starts with an asterisk, search only in headlines.
4538 - If (possibly after the leading star) the search string starts with an
4539 exclamation mark, this also means to look at TODO entries only, an effect
4540 that can also be achieved with a prefix argument.
4541 - If (possibly after star and exclamation mark) the search string starts
4542 with a colon, this will mean that the (non-regexp) snippets of the
4543 Boolean search must match as full words.
4545 This command searches the agenda files, and in addition the files listed
4546 in `org-agenda-text-search-extra-files'.
4548 \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
4550 ;;; Agenda TODO list
4552 (defun org-agenda-propertize-selected-todo-keywords (keywords)
4553 "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
4554 (concat
4555 (if (or (equal keywords "ALL") (not keywords))
4556 (propertize "ALL" 'face 'warning)
4557 (mapconcat
4558 (lambda (kw)
4559 (propertize kw 'face (org-get-todo-face kw)))
4560 (org-split-string keywords "|")
4561 "|"))
4562 "\n"))
4564 (defvar org-select-this-todo-keyword nil)
4565 (defvar org-last-arg nil)
4567 ;;;###autoload
4568 (defun org-todo-list (&optional arg)
4569 "Show all (not done) TODO entries from all agenda file in a single list.
4570 The prefix arg can be used to select a specific TODO keyword and limit
4571 the list to these. When using \\[universal-argument], you will be prompted
4572 for a keyword. A numeric prefix directly selects the Nth keyword in
4573 `org-todo-keywords-1'."
4574 (interactive "P")
4575 (if org-agenda-overriding-arguments
4576 (setq arg org-agenda-overriding-arguments))
4577 (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
4578 (let* ((today (org-today))
4579 (date (calendar-gregorian-from-absolute today))
4580 (kwds org-todo-keywords-for-agenda)
4581 (completion-ignore-case t)
4582 (org-select-this-todo-keyword
4583 (if (stringp arg) arg
4584 (and arg (integerp arg) (> arg 0)
4585 (nth (1- arg) kwds))))
4586 rtn rtnall files file pos)
4587 (when (equal arg '(4))
4588 (setq org-select-this-todo-keyword
4589 (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
4590 (mapcar 'list kwds) nil nil)))
4591 (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
4592 (catch 'exit
4593 (if org-agenda-sticky
4594 (setq org-agenda-buffer-name
4595 (if (stringp org-select-this-todo-keyword)
4596 (format "*Org Agenda(%s:%s)*" (or org-keys "t")
4597 org-select-this-todo-keyword)
4598 (format "*Org Agenda(%s)*" (or org-keys "t")))))
4599 (org-agenda-prepare "TODO")
4600 (org-compile-prefix-format 'todo)
4601 (org-set-sorting-strategy 'todo)
4602 (setq org-agenda-redo-command
4603 `(org-todo-list (or (and (numberp current-prefix-arg)
4604 current-prefix-arg)
4605 ,org-select-this-todo-keyword
4606 current-prefix-arg ,arg)))
4607 (setq files (org-agenda-files nil 'ifmode)
4608 rtnall nil)
4609 (while (setq file (pop files))
4610 (catch 'nextfile
4611 (org-check-agenda-file file)
4612 (setq rtn (org-agenda-get-day-entries file date :todo))
4613 (setq rtnall (append rtnall rtn))))
4614 (if org-agenda-overriding-header
4615 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4616 nil 'face 'org-agenda-structure) "\n")
4617 (insert "Global list of TODO items of type: ")
4618 (add-text-properties (point-min) (1- (point))
4619 (list 'face 'org-agenda-structure
4620 'short-heading
4621 (concat "ToDo: "
4622 (or org-select-this-todo-keyword "ALL"))))
4623 (org-agenda-mark-header-line (point-min))
4624 (insert (org-agenda-propertize-selected-todo-keywords
4625 org-select-this-todo-keyword))
4626 (setq pos (point))
4627 (unless org-agenda-multi
4628 (insert "Available with `N r': (0)[ALL]")
4629 (let ((n 0) s)
4630 (mapc (lambda (x)
4631 (setq s (format "(%d)%s" (setq n (1+ n)) x))
4632 (if (> (+ (current-column) (string-width s) 1) (frame-width))
4633 (insert "\n "))
4634 (insert " " s))
4635 kwds))
4636 (insert "\n"))
4637 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4638 (org-agenda-mark-header-line (point-min))
4639 (when rtnall
4640 (insert (org-agenda-finalize-entries rtnall) "\n"))
4641 (goto-char (point-min))
4642 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4643 (add-text-properties (point-min) (point-max)
4644 `(org-agenda-type todo
4645 org-last-args ,arg
4646 org-redo-cmd ,org-agenda-redo-command
4647 org-series-cmd ,org-cmd))
4648 (org-agenda-finalize)
4649 (setq buffer-read-only t))))
4651 (autoload 'org-todo-list "org-agenda" "\
4652 Show all (not done) TODO entries from all agenda file in a single list.
4653 The prefix arg can be used to select a specific TODO keyword and limit
4654 the list to these. When using \\[universal-argument], you will be prompted
4655 for a keyword. A numeric prefix directly selects the Nth keyword in
4656 `org-todo-keywords-1'.
4658 \(fn &optional ARG)" t nil)
4660 ;;; Agenda tags match
4662 ;;;###autoload
4663 (defun org-tags-view (&optional todo-only match)
4664 "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4665 The prefix arg TODO-ONLY limits the search to TODO entries."
4666 (interactive "P")
4667 (if org-agenda-overriding-arguments
4668 (setq todo-only (car org-agenda-overriding-arguments)
4669 match (nth 1 org-agenda-overriding-arguments)))
4670 (let* ((org-tags-match-list-sublevels
4671 org-tags-match-list-sublevels)
4672 (completion-ignore-case t)
4673 rtn rtnall files file pos matcher
4674 buffer)
4675 (when (and (stringp match) (not (string-match "\\S-" match)))
4676 (setq match nil))
4677 (setq matcher (org-make-tags-matcher match)
4678 match (car matcher) matcher (cdr matcher))
4679 (catch 'exit
4680 (if org-agenda-sticky
4681 (setq org-agenda-buffer-name
4682 (if (stringp match)
4683 (format "*Org Agenda(%s:%s)*"
4684 (or org-keys (or (and todo-only "M") "m")) match)
4685 (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
4686 (org-agenda-prepare (concat "TAGS " match))
4687 (org-compile-prefix-format 'tags)
4688 (org-set-sorting-strategy 'tags)
4689 (setq org-agenda-query-string match)
4690 (setq org-agenda-redo-command
4691 (list 'org-tags-view `(quote ,todo-only)
4692 (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
4693 (setq files (org-agenda-files nil 'ifmode)
4694 rtnall nil)
4695 (while (setq file (pop files))
4696 (catch 'nextfile
4697 (org-check-agenda-file file)
4698 (setq buffer (if (file-exists-p file)
4699 (org-get-agenda-file-buffer file)
4700 (error "No such file %s" file)))
4701 (if (not buffer)
4702 ;; If file does not exist, error message to agenda
4703 (setq rtn (list
4704 (format "ORG-AGENDA-ERROR: No such org-file %s" file))
4705 rtnall (append rtnall rtn))
4706 (with-current-buffer buffer
4707 (unless (derived-mode-p 'org-mode)
4708 (error "Agenda file %s is not in `org-mode'" file))
4709 (save-excursion
4710 (save-restriction
4711 (if org-agenda-restrict
4712 (narrow-to-region org-agenda-restrict-begin
4713 org-agenda-restrict-end)
4714 (widen))
4715 (setq rtn (org-scan-tags 'agenda matcher todo-only))
4716 (setq rtnall (append rtnall rtn))))))))
4717 (if org-agenda-overriding-header
4718 (insert (org-add-props (copy-sequence org-agenda-overriding-header)
4719 nil 'face 'org-agenda-structure) "\n")
4720 (insert "Headlines with TAGS match: ")
4721 (add-text-properties (point-min) (1- (point))
4722 (list 'face 'org-agenda-structure
4723 'short-heading
4724 (concat "Match: " match)))
4725 (setq pos (point))
4726 (insert match "\n")
4727 (add-text-properties pos (1- (point)) (list 'face 'org-warning))
4728 (setq pos (point))
4729 (unless org-agenda-multi
4730 (insert "Press `C-u r' to search again with new search string\n"))
4731 (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
4732 (org-agenda-mark-header-line (point-min))
4733 (when rtnall
4734 (insert (org-agenda-finalize-entries rtnall) "\n"))
4735 (goto-char (point-min))
4736 (or org-agenda-multi (org-agenda-fit-window-to-buffer))
4737 (add-text-properties (point-min) (point-max)
4738 `(org-agenda-type tags
4739 org-last-args (,todo-only ,match)
4740 org-redo-cmd ,org-agenda-redo-command
4741 org-series-cmd ,org-cmd))
4742 (org-agenda-finalize)
4743 (setq buffer-read-only t))))
4745 (autoload 'org-tags-view "org-agenda" "\
4746 Show all headlines for all `org-agenda-files' matching a TAGS criterion.
4747 The prefix arg TODO-ONLY limits the search to TODO entries.
4749 \(fn &optional TODO-ONLY MATCH)" t nil)
4751 ;;; Agenda Finding stuck projects
4753 (defvar org-agenda-skip-regexp nil
4754 "Regular expression used in skipping subtrees for the agenda.
4755 This is basically a temporary global variable that can be set and then
4756 used by user-defined selections using `org-agenda-skip-function'.")
4758 (defvar org-agenda-overriding-header nil
4759 "When set during agenda, todo and tags searches it replaces the header.
4760 This variable should not be set directly, but custom commands can bind it
4761 in the options section.")
4763 (defun org-agenda-skip-entry-when-regexp-matches ()
4764 "Check if the current entry contains match for `org-agenda-skip-regexp'.
4765 If yes, it returns the end position of this entry, causing agenda commands
4766 to skip the entry but continuing the search in the subtree. This is a
4767 function that can be put into `org-agenda-skip-function' for the duration
4768 of a command."
4769 (let ((end (save-excursion (org-end-of-subtree t)))
4770 skip)
4771 (save-excursion
4772 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4773 (and skip end)))
4775 (defun org-agenda-skip-subtree-when-regexp-matches ()
4776 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4777 If yes, it returns the end position of this tree, causing agenda commands
4778 to skip this subtree. This is a function that can be put into
4779 `org-agenda-skip-function' for the duration of a command."
4780 (let ((end (save-excursion (org-end-of-subtree t)))
4781 skip)
4782 (save-excursion
4783 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4784 (and skip end)))
4786 (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
4787 "Check if the current subtree contains match for `org-agenda-skip-regexp'.
4788 If yes, it returns the end position of the current entry (NOT the tree),
4789 causing agenda commands to skip the entry but continuing the search in
4790 the subtree. This is a function that can be put into
4791 `org-agenda-skip-function' for the duration of a command. An important
4792 use of this function is for the stuck project list."
4793 (let ((end (save-excursion (org-end-of-subtree t)))
4794 (entry-end (save-excursion (outline-next-heading) (1- (point))))
4795 skip)
4796 (save-excursion
4797 (setq skip (re-search-forward org-agenda-skip-regexp end t)))
4798 (and skip entry-end)))
4800 (defun org-agenda-skip-entry-if (&rest conditions)
4801 "Skip entry if any of CONDITIONS is true.
4802 See `org-agenda-skip-if' for details."
4803 (org-agenda-skip-if nil conditions))
4805 (defun org-agenda-skip-subtree-if (&rest conditions)
4806 "Skip entry if any of CONDITIONS is true.
4807 See `org-agenda-skip-if' for details."
4808 (org-agenda-skip-if t conditions))
4810 (defun org-agenda-skip-if (subtree conditions)
4811 "Checks current entity for CONDITIONS.
4812 If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
4813 the entry (i.e. the text before the next heading) is checked.
4815 CONDITIONS is a list of symbols, boolean OR is used to combine the results
4816 from different tests. Valid conditions are:
4818 scheduled Check if there is a scheduled cookie
4819 notscheduled Check if there is no scheduled cookie
4820 deadline Check if there is a deadline
4821 notdeadline Check if there is no deadline
4822 timestamp Check if there is a timestamp (also deadline or scheduled)
4823 nottimestamp Check if there is no timestamp (also deadline or scheduled)
4824 regexp Check if regexp matches
4825 notregexp Check if regexp does not match.
4826 todo Check if TODO keyword matches
4827 nottodo Check if TODO keyword does not match
4829 The regexp is taken from the conditions list, it must come right after
4830 the `regexp' or `notregexp' element.
4832 `todo' and `nottodo' accept as an argument a list of todo
4833 keywords, which may include \"*\" to match any todo keyword.
4835 (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
4837 would skip all entries with \"TODO\" or \"WAITING\" keywords.
4839 Instead of a list, a keyword class may be given. For example:
4841 (org-agenda-skip-entry-if 'nottodo 'done)
4843 would skip entries that haven't been marked with any of \"DONE\"
4844 keywords. Possible classes are: `todo', `done', `any'.
4846 If any of these conditions is met, this function returns the end point of
4847 the entity, causing the search to continue from there. This is a function
4848 that can be put into `org-agenda-skip-function' for the duration of a command."
4849 (let (beg end m)
4850 (org-back-to-heading t)
4851 (setq beg (point)
4852 end (if subtree
4853 (progn (org-end-of-subtree t) (point))
4854 (progn (outline-next-heading) (1- (point)))))
4855 (goto-char beg)
4856 (and
4858 (and (memq 'scheduled conditions)
4859 (re-search-forward org-scheduled-time-regexp end t))
4860 (and (memq 'notscheduled conditions)
4861 (not (re-search-forward org-scheduled-time-regexp end t)))
4862 (and (memq 'deadline conditions)
4863 (re-search-forward org-deadline-time-regexp end t))
4864 (and (memq 'notdeadline conditions)
4865 (not (re-search-forward org-deadline-time-regexp end t)))
4866 (and (memq 'timestamp conditions)
4867 (re-search-forward org-ts-regexp end t))
4868 (and (memq 'nottimestamp conditions)
4869 (not (re-search-forward org-ts-regexp end t)))
4870 (and (setq m (memq 'regexp conditions))
4871 (stringp (nth 1 m))
4872 (re-search-forward (nth 1 m) end t))
4873 (and (setq m (memq 'notregexp conditions))
4874 (stringp (nth 1 m))
4875 (not (re-search-forward (nth 1 m) end t)))
4876 (and (or
4877 (setq m (memq 'nottodo conditions))
4878 (setq m (memq 'todo-unblocked conditions))
4879 (setq m (memq 'nottodo-unblocked conditions))
4880 (setq m (memq 'todo conditions)))
4881 (org-agenda-skip-if-todo m end)))
4882 end)))
4884 (defun org-agenda-skip-if-todo (args end)
4885 "Helper function for `org-agenda-skip-if', do not use it directly.
4886 ARGS is a list with first element either `todo', `nottodo',
4887 `todo-unblocked' or `nottodo-unblocked'. The remainder is either
4888 a list of TODO keywords, or a state symbol `todo' or `done' or
4889 `any'."
4890 (let ((kw (car args))
4891 (arg (cadr args))
4892 todo-wds todo-re)
4893 (setq todo-wds
4894 (org-uniquify
4895 (cond
4896 ((listp arg) ;; list of keywords
4897 (if (member "*" arg)
4898 (mapcar 'substring-no-properties org-todo-keywords-1)
4899 arg))
4900 ((symbolp arg) ;; keyword class name
4901 (cond
4902 ((eq arg 'todo)
4903 (org-delete-all org-done-keywords
4904 (mapcar 'substring-no-properties
4905 org-todo-keywords-1)))
4906 ((eq arg 'done) org-done-keywords)
4907 ((eq arg 'any)
4908 (mapcar 'substring-no-properties org-todo-keywords-1)))))))
4909 (setq todo-re
4910 (concat "^\\*+[ \t]+\\<\\("
4911 (mapconcat 'identity todo-wds "\\|")
4912 "\\)\\>"))
4913 (cond
4914 ((eq kw 'todo) (re-search-forward todo-re end t))
4915 ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
4916 ((eq kw 'todo-unblocked)
4917 (catch 'unblocked
4918 (while (re-search-forward todo-re end t)
4919 (or (org-entry-blocked-p) (throw 'unblocked t)))
4920 nil))
4921 ((eq kw 'nottodo-unblocked)
4922 (catch 'unblocked
4923 (while (re-search-forward todo-re end t)
4924 (or (org-entry-blocked-p) (throw 'unblocked nil)))
4928 ;;;###autoload
4929 (defun org-agenda-list-stuck-projects (&rest ignore)
4930 "Create agenda view for projects that are stuck.
4931 Stuck projects are project that have no next actions. For the definitions
4932 of what a project is and how to check if it stuck, customize the variable
4933 `org-stuck-projects'."
4934 (interactive)
4935 (let* ((org-agenda-skip-function
4936 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
4937 ;; We could have used org-agenda-skip-if here.
4938 (org-agenda-overriding-header
4939 (or org-agenda-overriding-header "List of stuck projects: "))
4940 (matcher (nth 0 org-stuck-projects))
4941 (todo (nth 1 org-stuck-projects))
4942 (todo-wds (if (member "*" todo)
4943 (progn
4944 (org-agenda-prepare-buffers (org-agenda-files
4945 nil 'ifmode))
4946 (org-delete-all
4947 org-done-keywords-for-agenda
4948 (copy-sequence org-todo-keywords-for-agenda)))
4949 todo))
4950 (todo-re (concat "^\\*+[ \t]+\\("
4951 (mapconcat 'identity todo-wds "\\|")
4952 "\\)\\>"))
4953 (tags (nth 2 org-stuck-projects))
4954 (tags-re (if (member "*" tags)
4955 (concat org-outline-regexp-bol
4956 (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
4957 (if tags
4958 (concat org-outline-regexp-bol
4959 ".*:\\("
4960 (mapconcat 'identity tags "\\|")
4961 (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
4962 (gen-re (nth 3 org-stuck-projects))
4963 (re-list
4964 (delq nil
4965 (list
4966 (if todo todo-re)
4967 (if tags tags-re)
4968 (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
4969 gen-re)))))
4970 (setq org-agenda-skip-regexp
4971 (if re-list
4972 (mapconcat 'identity re-list "\\|")
4973 (error "No information how to identify unstuck projects")))
4974 (org-tags-view nil matcher)
4975 (with-current-buffer org-agenda-buffer-name
4976 (setq org-agenda-redo-command
4977 `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
4979 (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
4980 Create agenda view for projects that are stuck.
4981 Stuck projects are project that have no next actions. For the definitions
4982 of what a project is and how to check if it stuck, customize the variable
4983 `org-stuck-projects'.
4985 \(fn &rest IGNORE)" t nil)
4987 ;;; Diary integration
4989 (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
4990 (defvar diary-list-entries-hook)
4991 (defvar diary-time-regexp)
4992 (defun org-get-entries-from-diary (date)
4993 "Get the (Emacs Calendar) diary entries for DATE."
4994 (require 'diary-lib)
4995 (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
4996 (diary-display-hook '(fancy-diary-display))
4997 (diary-display-function 'fancy-diary-display)
4998 (pop-up-frames nil)
4999 (diary-list-entries-hook
5000 (cons 'org-diary-default-entry diary-list-entries-hook))
5001 (diary-file-name-prefix-function nil) ; turn this feature off
5002 (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
5003 entries
5004 (org-disable-agenda-to-diary t))
5005 (save-excursion
5006 (save-window-excursion
5007 (funcall (if (fboundp 'diary-list-entries)
5008 'diary-list-entries 'list-diary-entries)
5009 date 1)))
5010 (if (not (get-buffer diary-fancy-buffer))
5011 (setq entries nil)
5012 (with-current-buffer diary-fancy-buffer
5013 (setq buffer-read-only nil)
5014 (if (zerop (buffer-size))
5015 ;; No entries
5016 (setq entries nil)
5017 ;; Omit the date and other unnecessary stuff
5018 (org-agenda-cleanup-fancy-diary)
5019 ;; Add prefix to each line and extend the text properties
5020 (if (zerop (buffer-size))
5021 (setq entries nil)
5022 (setq entries (buffer-substring (point-min) (- (point-max) 1)))
5023 (setq entries
5024 (with-temp-buffer
5025 (insert entries) (goto-char (point-min))
5026 (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
5027 (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
5028 (replace-match (concat "; " (match-string 1)))))
5029 (buffer-string)))))
5030 (set-buffer-modified-p nil)
5031 (kill-buffer diary-fancy-buffer)))
5032 (when entries
5033 (setq entries (org-split-string entries "\n"))
5034 (setq entries
5035 (mapcar
5036 (lambda (x)
5037 (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
5038 ;; Extend the text properties to the beginning of the line
5039 (org-add-props x (text-properties-at (1- (length x)) x)
5040 'type "diary" 'date date 'face 'org-agenda-diary))
5041 entries)))))
5043 (defvar org-agenda-cleanup-fancy-diary-hook nil
5044 "Hook run when the fancy diary buffer is cleaned up.")
5046 (defun org-agenda-cleanup-fancy-diary ()
5047 "Remove unwanted stuff in buffer created by `fancy-diary-display'.
5048 This gets rid of the date, the underline under the date, and
5049 the dummy entry installed by `org-mode' to ensure non-empty diary for each
5050 date. It also removes lines that contain only whitespace."
5051 (goto-char (point-min))
5052 (if (looking-at ".*?:[ \t]*")
5053 (progn
5054 (replace-match "")
5055 (re-search-forward "\n=+$" nil t)
5056 (replace-match "")
5057 (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
5058 (re-search-forward "\n=+$" nil t)
5059 (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
5060 (goto-char (point-min))
5061 (while (re-search-forward "^ +\n" nil t)
5062 (replace-match ""))
5063 (goto-char (point-min))
5064 (if (re-search-forward "^Org-mode dummy\n?" nil t)
5065 (replace-match ""))
5066 (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
5068 ;; Make sure entries from the diary have the right text properties.
5069 (eval-after-load "diary-lib"
5070 '(if (boundp 'diary-modify-entry-list-string-function)
5071 ;; We can rely on the hook, nothing to do
5073 ;; Hook not available, must use advice to make this work
5074 (defadvice add-to-diary-list (before org-mark-diary-entry activate)
5075 "Make the position visible."
5076 (if (and org-disable-agenda-to-diary ;; called from org-agenda
5077 (stringp string)
5078 buffer-file-name)
5079 (setq string (org-modify-diary-entry-string string))))))
5081 (defun org-modify-diary-entry-string (string)
5082 "Add text properties to string, allowing org-mode to act on it."
5083 (org-add-props string nil
5084 'mouse-face 'highlight
5085 'help-echo (if buffer-file-name
5086 (format "mouse-2 or RET jump to diary file %s"
5087 (abbreviate-file-name buffer-file-name))
5089 'org-agenda-diary-link t
5090 'org-marker (org-agenda-new-marker (point-at-bol))))
5092 (defun org-diary-default-entry ()
5093 "Add a dummy entry to the diary.
5094 Needed to avoid empty dates which mess up holiday display."
5095 ;; Catch the error if dealing with the new add-to-diary-alist
5096 (when org-disable-agenda-to-diary
5097 (condition-case nil
5098 (org-add-to-diary-list original-date "Org-mode dummy" "")
5099 (error
5100 (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
5102 (defun org-add-to-diary-list (&rest args)
5103 (if (fboundp 'diary-add-to-list)
5104 (apply 'diary-add-to-list args)
5105 (apply 'add-to-diary-list args)))
5107 (defvar org-diary-last-run-time nil)
5109 ;;;###autoload
5110 (defun org-diary (&rest args)
5111 "Return diary information from org files.
5112 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5113 It accesses org files and extracts information from those files to be
5114 listed in the diary. The function accepts arguments specifying what
5115 items should be listed. For a list of arguments allowed here, see the
5116 variable `org-agenda-entry-types'.
5118 The call in the diary file should look like this:
5120 &%%(org-diary) ~/path/to/some/orgfile.org
5122 Use a separate line for each org file to check. Or, if you omit the file name,
5123 all files listed in `org-agenda-files' will be checked automatically:
5125 &%%(org-diary)
5127 If you don't give any arguments (as in the example above), the default
5128 arguments (:deadline :scheduled :timestamp :sexp) are used.
5129 So the example above may also be written as
5131 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5133 The function expects the lisp variables `entry' and `date' to be provided
5134 by the caller, because this is how the calendar works. Don't use this
5135 function from a program - use `org-agenda-get-day-entries' instead."
5136 (when (> (- (org-float-time)
5137 org-agenda-last-marker-time)
5139 ;; I am not sure if this works with sticky agendas, because the marker
5140 ;; list is then no longer a global variable.
5141 (org-agenda-reset-markers))
5142 (org-compile-prefix-format 'agenda)
5143 (org-set-sorting-strategy 'agenda)
5144 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5145 (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
5146 (list entry)
5147 (org-agenda-files t)))
5148 (time (org-float-time))
5149 file rtn results)
5150 (when (or (not org-diary-last-run-time)
5151 (> (- time
5152 org-diary-last-run-time)
5154 (org-agenda-prepare-buffers files))
5155 (setq org-diary-last-run-time time)
5156 ;; If this is called during org-agenda, don't return any entries to
5157 ;; the calendar. Org Agenda will list these entries itself.
5158 (if org-disable-agenda-to-diary (setq files nil))
5159 (while (setq file (pop files))
5160 (setq rtn (apply 'org-agenda-get-day-entries file date args))
5161 (setq results (append results rtn)))
5162 (if results
5163 (concat (org-agenda-finalize-entries results) "\n"))))
5165 (autoload 'org-diary "org-agenda" "\
5166 Return diary information from org files.
5167 This function can be used in a \"sexp\" diary entry in the Emacs calendar.
5168 It accesses org files and extracts information from those files to be
5169 listed in the diary. The function accepts arguments specifying what
5170 items should be listed. For a list of arguments allowed here, see the
5171 variable `org-agenda-entry-types'.
5173 The call in the diary file should look like this:
5175 &%%(org-diary) ~/path/to/some/orgfile.org
5177 Use a separate line for each org file to check. Or, if you omit the file name,
5178 all files listed in `org-agenda-files' will be checked automatically:
5180 &%%(org-diary)
5182 If you don't give any arguments (as in the example above), the default
5183 arguments (:deadline :scheduled :timestamp :sexp) are used.
5184 So the example above may also be written as
5186 &%%(org-diary :deadline :timestamp :sexp :scheduled)
5188 The function expects the lisp variables `entry' and `date' to be provided
5189 by the caller, because this is how the calendar works. Don't use this
5190 function from a program - use `org-agenda-get-day-entries' instead.
5192 \(fn &rest ARGS)" nil nil)
5194 ;;; Agenda entry finders
5196 (defun org-agenda-get-day-entries (file date &rest args)
5197 "Does the work for `org-diary' and `org-agenda'.
5198 FILE is the path to a file to be checked for entries. DATE is date like
5199 the one returned by `calendar-current-date'. ARGS are symbols indicating
5200 which kind of entries should be extracted. For details about these, see
5201 the documentation of `org-diary'."
5202 (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
5203 (let* ((org-startup-folded nil)
5204 (org-startup-align-all-tables nil)
5205 (buffer (if (file-exists-p file)
5206 (org-get-agenda-file-buffer file)
5207 (error "No such file %s" file)))
5208 arg results rtn deadline-results)
5209 (if (not buffer)
5210 ;; If file does not exist, make sure an error message ends up in diary
5211 (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
5212 (with-current-buffer buffer
5213 (unless (derived-mode-p 'org-mode)
5214 (error "Agenda file %s is not in `org-mode'" file))
5215 (setq org-agenda-buffer (or org-agenda-buffer buffer))
5216 (let ((case-fold-search nil))
5217 (save-excursion
5218 (save-restriction
5219 (if org-agenda-restrict
5220 (narrow-to-region org-agenda-restrict-begin
5221 org-agenda-restrict-end)
5222 (widen))
5223 ;; The way we repeatedly append to `results' makes it O(n^2) :-(
5224 (while (setq arg (pop args))
5225 (cond
5226 ((and (eq arg :todo)
5227 (equal date (calendar-gregorian-from-absolute
5228 (org-today))))
5229 (setq rtn (org-agenda-get-todos))
5230 (setq results (append results rtn)))
5231 ((eq arg :timestamp)
5232 (setq rtn (org-agenda-get-blocks))
5233 (setq results (append results rtn))
5234 (setq rtn (org-agenda-get-timestamps deadline-results))
5235 (setq results (append results rtn)))
5236 ((eq arg :sexp)
5237 (setq rtn (org-agenda-get-sexps))
5238 (setq results (append results rtn)))
5239 ((eq arg :scheduled)
5240 (setq rtn (org-agenda-get-scheduled deadline-results))
5241 (setq results (append results rtn)))
5242 ((eq arg :closed)
5243 (setq rtn (org-agenda-get-progress))
5244 (setq results (append results rtn)))
5245 ((eq arg :deadline)
5246 (setq rtn (org-agenda-get-deadlines))
5247 (setq deadline-results (copy-sequence rtn))
5248 (setq results (append results rtn))))))))
5249 results))))
5251 (defvar org-heading-keyword-regexp-format) ; defined in org.el
5252 (defun org-agenda-get-todos ()
5253 "Return the TODO information for agenda display."
5254 (let* ((props (list 'face nil
5255 'done-face 'org-agenda-done
5256 'org-not-done-regexp org-not-done-regexp
5257 'org-todo-regexp org-todo-regexp
5258 'org-complex-heading-regexp org-complex-heading-regexp
5259 'mouse-face 'highlight
5260 'help-echo
5261 (format "mouse-2 or RET jump to org file %s"
5262 (abbreviate-file-name buffer-file-name))))
5263 (regexp (format org-heading-keyword-regexp-format
5264 (cond
5265 ((and org-select-this-todo-keyword
5266 (equal org-select-this-todo-keyword "*"))
5267 org-todo-regexp)
5268 (org-select-this-todo-keyword
5269 (concat "\\("
5270 (mapconcat 'identity
5271 (org-split-string
5272 org-select-this-todo-keyword
5273 "|")
5274 "\\|") "\\)"))
5275 (t org-not-done-regexp))))
5276 marker priority category category-pos level tags todo-state
5277 ee txt beg end)
5278 (goto-char (point-min))
5279 (while (re-search-forward regexp nil t)
5280 (catch :skip
5281 (save-match-data
5282 (beginning-of-line)
5283 (org-agenda-skip)
5284 (setq beg (point) end (save-excursion (outline-next-heading) (point)))
5285 (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
5286 (goto-char (1+ beg))
5287 (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
5288 (throw :skip nil)))
5289 (goto-char (match-beginning 2))
5290 (setq marker (org-agenda-new-marker (match-beginning 0))
5291 category (org-get-category)
5292 category-pos (get-text-property (point) 'org-category-position)
5293 txt (org-trim
5294 (buffer-substring (match-beginning 2) (match-end 0)))
5295 tags (org-get-tags-at (point))
5296 level (make-string (org-reduced-level (org-outline-level)) ? )
5297 txt (org-agenda-format-item "" txt level category tags t)
5298 priority (1+ (org-get-priority txt))
5299 todo-state (org-get-todo-state))
5300 (org-add-props txt props
5301 'org-marker marker 'org-hd-marker marker
5302 'priority priority 'org-category category
5303 'level level
5304 'org-category-position category-pos
5305 'type "todo" 'todo-state todo-state)
5306 (push txt ee)
5307 (if org-agenda-todo-list-sublevels
5308 (goto-char (match-end 2))
5309 (org-end-of-subtree 'invisible))))
5310 (nreverse ee)))
5312 (defun org-agenda-todo-custom-ignore-p (time n)
5313 "Check whether timestamp is farther away than n number of days.
5314 This function is invoked if `org-agenda-todo-ignore-deadlines',
5315 `org-agenda-todo-ignore-scheduled' or
5316 `org-agenda-todo-ignore-timestamp' is set to an integer."
5317 (let ((days (org-time-stamp-to-now
5318 time org-agenda-todo-ignore-time-comparison-use-seconds)))
5319 (if (>= n 0)
5320 (>= days n)
5321 (<= days n))))
5323 (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
5324 (&optional end)
5325 "Do we have a reason to ignore this TODO entry because it has a time stamp?"
5326 (when (or org-agenda-todo-ignore-with-date
5327 org-agenda-todo-ignore-scheduled
5328 org-agenda-todo-ignore-deadlines
5329 org-agenda-todo-ignore-timestamp)
5330 (setq end (or end (save-excursion (outline-next-heading) (point))))
5331 (save-excursion
5332 (or (and org-agenda-todo-ignore-with-date
5333 (re-search-forward org-ts-regexp end t))
5334 (and org-agenda-todo-ignore-scheduled
5335 (re-search-forward org-scheduled-time-regexp end t)
5336 (cond
5337 ((eq org-agenda-todo-ignore-scheduled 'future)
5338 (> (org-time-stamp-to-now
5339 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5340 ((eq org-agenda-todo-ignore-scheduled 'past)
5341 (<= (org-time-stamp-to-now
5342 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5343 ((numberp org-agenda-todo-ignore-scheduled)
5344 (org-agenda-todo-custom-ignore-p
5345 (match-string 1) org-agenda-todo-ignore-scheduled))
5346 (t)))
5347 (and org-agenda-todo-ignore-deadlines
5348 (re-search-forward org-deadline-time-regexp end t)
5349 (cond
5350 ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
5351 ((eq org-agenda-todo-ignore-deadlines 'far)
5352 (not (org-deadline-close (match-string 1))))
5353 ((eq org-agenda-todo-ignore-deadlines 'future)
5354 (> (org-time-stamp-to-now
5355 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5356 ((eq org-agenda-todo-ignore-deadlines 'past)
5357 (<= (org-time-stamp-to-now
5358 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5359 ((numberp org-agenda-todo-ignore-deadlines)
5360 (org-agenda-todo-custom-ignore-p
5361 (match-string 1) org-agenda-todo-ignore-deadlines))
5362 (t (org-deadline-close (match-string 1)))))
5363 (and org-agenda-todo-ignore-timestamp
5364 (let ((buffer (current-buffer))
5365 (regexp
5366 (concat
5367 org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
5368 (start (point)))
5369 ;; Copy current buffer into a temporary one
5370 (with-temp-buffer
5371 (insert-buffer-substring buffer start end)
5372 (goto-char (point-min))
5373 ;; Delete SCHEDULED and DEADLINE items
5374 (while (re-search-forward regexp end t)
5375 (delete-region (match-beginning 0) (match-end 0)))
5376 (goto-char (point-min))
5377 ;; No search for timestamp left
5378 (when (re-search-forward org-ts-regexp nil t)
5379 (cond
5380 ((eq org-agenda-todo-ignore-timestamp 'future)
5381 (> (org-time-stamp-to-now
5382 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5383 ((eq org-agenda-todo-ignore-timestamp 'past)
5384 (<= (org-time-stamp-to-now
5385 (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
5386 ((numberp org-agenda-todo-ignore-timestamp)
5387 (org-agenda-todo-custom-ignore-p
5388 (match-string 1) org-agenda-todo-ignore-timestamp))
5389 (t))))))))))
5391 (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
5392 Do we have a reason to ignore this TODO entry because it has a time stamp?
5394 \(fn &optional END)" nil nil)
5396 (defconst org-agenda-no-heading-message
5397 "No heading for this item in buffer or region.")
5399 (defun org-agenda-get-timestamps (&optional deadline-results)
5400 "Return the date stamp information for agenda display."
5401 (let* ((props (list 'face 'org-agenda-calendar-event
5402 'org-not-done-regexp org-not-done-regexp
5403 'org-todo-regexp org-todo-regexp
5404 'org-complex-heading-regexp org-complex-heading-regexp
5405 'mouse-face 'highlight
5406 'help-echo
5407 (format "mouse-2 or RET jump to org file %s"
5408 (abbreviate-file-name buffer-file-name))))
5409 (d1 (calendar-absolute-from-gregorian date))
5411 (deadline-position-alist
5412 (mapcar (lambda (a) (and (setq mm (get-text-property
5413 0 'org-hd-marker a))
5414 (cons (marker-position mm) a)))
5415 deadline-results))
5416 (remove-re org-ts-regexp)
5417 (regexp
5418 (concat
5419 (if org-agenda-include-inactive-timestamps "[[<]" "<")
5420 (regexp-quote
5421 (substring
5422 (format-time-string
5423 (car org-time-stamp-formats)
5424 (apply 'encode-time ; DATE bound by calendar
5425 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5426 1 11))
5427 "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
5428 "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
5429 marker hdmarker deadlinep scheduledp clockp closedp inactivep
5430 donep tmp priority category category-pos level ee txt timestr tags
5431 b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
5432 (goto-char (point-min))
5433 (while (setq end-of-match (re-search-forward regexp nil t))
5434 (setq b0 (match-beginning 0)
5435 b3 (match-beginning 3) e3 (match-end 3)
5436 todo-state (save-match-data (ignore-errors (org-get-todo-state)))
5437 habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
5438 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5439 (member todo-state
5440 org-agenda-repeating-timestamp-show-all)))
5441 (catch :skip
5442 (and (org-at-date-range-p) (throw :skip nil))
5443 (org-agenda-skip)
5444 (if (and (match-end 1)
5445 (not (= d1 (org-time-string-to-absolute
5446 (match-string 1) d1 nil show-all
5447 (current-buffer) b0))))
5448 (throw :skip nil))
5449 (if (and e3
5450 (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
5451 (throw :skip nil))
5452 (setq tmp (buffer-substring (max (point-min)
5453 (- b0 org-ds-keyword-length))
5455 timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
5456 inactivep (= (char-after b0) ?\[)
5457 deadlinep (string-match org-deadline-regexp tmp)
5458 scheduledp (string-match org-scheduled-regexp tmp)
5459 closedp (and org-agenda-include-inactive-timestamps
5460 (string-match org-closed-string tmp))
5461 clockp (and org-agenda-include-inactive-timestamps
5462 (or (string-match org-clock-string tmp)
5463 (string-match "]-+\\'" tmp)))
5464 warntime (org-entry-get (point) "APPT_WARNTIME")
5465 donep (member todo-state org-done-keywords))
5466 (if (or scheduledp deadlinep closedp clockp
5467 (and donep org-agenda-skip-timestamp-if-done))
5468 (throw :skip t))
5469 (if (string-match ">" timestr)
5470 ;; substring should only run to end of time stamp
5471 (setq timestr (substring timestr 0 (match-end 0))))
5472 (setq marker (org-agenda-new-marker b0)
5473 category (org-get-category b0)
5474 category-pos (get-text-property b0 'org-category-position))
5475 (save-excursion
5476 (if (not (re-search-backward org-outline-regexp-bol nil t))
5477 (setq txt org-agenda-no-heading-message)
5478 (goto-char (match-beginning 0))
5479 (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
5480 (assoc (point) deadline-position-alist))
5481 (throw :skip nil))
5482 (setq hdmarker (org-agenda-new-marker)
5483 tags (org-get-tags-at)
5484 level (make-string (org-reduced-level (org-outline-level)) ? ))
5485 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5486 (setq head (or (match-string 1) ""))
5487 (setq txt (org-agenda-format-item
5488 (if inactivep org-agenda-inactive-leader nil)
5489 head level category tags timestr
5490 remove-re habitp)))
5491 (setq priority (org-get-priority txt))
5492 (org-add-props txt props 'priority priority
5493 'org-marker marker 'org-hd-marker hdmarker
5494 'org-category category 'date date
5495 'level level
5496 'org-category-position category-pos
5497 'todo-state todo-state
5498 'warntime warntime
5499 'type "timestamp")
5500 (push txt ee))
5501 (if org-agenda-skip-additional-timestamps-same-entry
5502 (outline-next-heading)
5503 (goto-char end-of-match))))
5504 (nreverse ee)))
5506 (defun org-agenda-get-sexps ()
5507 "Return the sexp information for agenda display."
5508 (require 'diary-lib)
5509 (let* ((props (list 'face 'org-agenda-calendar-sexp
5510 'mouse-face 'highlight
5511 'help-echo
5512 (format "mouse-2 or RET jump to org file %s"
5513 (abbreviate-file-name buffer-file-name))))
5514 (regexp "^&?%%(")
5515 marker category extra category-pos level ee txt tags entry
5516 result beg b sexp sexp-entry todo-state warntime)
5517 (goto-char (point-min))
5518 (while (re-search-forward regexp nil t)
5519 (catch :skip
5520 (org-agenda-skip)
5521 (setq beg (match-beginning 0))
5522 (goto-char (1- (match-end 0)))
5523 (setq b (point))
5524 (forward-sexp 1)
5525 (setq sexp (buffer-substring b (point)))
5526 (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
5527 (org-trim (match-string 1))
5528 ""))
5529 (setq result (org-diary-sexp-entry sexp sexp-entry date))
5530 (when result
5531 (setq marker (org-agenda-new-marker beg)
5532 level (make-string (org-reduced-level (org-outline-level)) ? )
5533 category (org-get-category beg)
5534 category-pos (get-text-property beg 'org-category-position)
5535 tags (save-excursion (org-backward-heading-same-level 0)
5536 (org-get-tags-at))
5537 todo-state (org-get-todo-state)
5538 warntime (org-entry-get (point) "APPT_WARNTIME")
5539 extra nil)
5541 (dolist (r (if (stringp result)
5542 (list result)
5543 result)) ;; we expect a list here
5544 (when (and org-agenda-diary-sexp-prefix
5545 (string-match org-agenda-diary-sexp-prefix r))
5546 (setq extra (match-string 0 r)
5547 r (replace-match "" nil nil r)))
5548 (if (string-match "\\S-" r)
5549 (setq txt r)
5550 (setq txt "SEXP entry returned empty string"))
5551 (setq txt (org-agenda-format-item extra txt level category tags 'time))
5552 (org-add-props txt props 'org-marker marker
5553 'org-category category 'date date 'todo-state todo-state
5554 'org-category-position category-pos 'tags tags
5555 'level level
5556 'type "sexp" 'warntime warntime)
5557 (push txt ee)))))
5558 (nreverse ee)))
5560 ;; Calendar sanity: define some functions that are independent of
5561 ;; `calendar-date-style'.
5562 ;; Normally I would like to use ISO format when calling the diary functions,
5563 ;; but to make sure we still have Emacs 22 compatibility we bind
5564 ;; also `european-calendar-style' and use european format
5565 (defun org-anniversary (year month day &optional mark)
5566 "Like `diary-anniversary', but with fixed (ISO) order of arguments."
5567 (org-no-warnings
5568 (let ((calendar-date-style 'european) (european-calendar-style t))
5569 (diary-anniversary day month year mark))))
5570 (defun org-cyclic (N year month day &optional mark)
5571 "Like `diary-cyclic', but with fixed (ISO) order of arguments."
5572 (org-no-warnings
5573 (let ((calendar-date-style 'european) (european-calendar-style t))
5574 (diary-cyclic N day month year mark))))
5575 (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
5576 "Like `diary-block', but with fixed (ISO) order of arguments."
5577 (org-no-warnings
5578 (let ((calendar-date-style 'european) (european-calendar-style t))
5579 (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
5580 (defun org-date (year month day &optional mark)
5581 "Like `diary-date', but with fixed (ISO) order of arguments."
5582 (org-no-warnings
5583 (let ((calendar-date-style 'european) (european-calendar-style t))
5584 (diary-date day month year mark))))
5585 (defalias 'org-float 'diary-float)
5587 ;; Define the` org-class' function
5588 (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
5589 "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
5590 DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
5591 SKIP-WEEKS is any number of ISO weeks in the block period for which the
5592 item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
5593 `holidays', then any date that is known by the Emacs calendar to be a
5594 holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
5595 then those holidays will be skipped."
5596 (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
5597 (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
5598 (d (calendar-absolute-from-gregorian date))
5599 (h (when skip-weeks (calendar-check-holidays date))))
5600 (and
5601 (<= date1 d)
5602 (<= d date2)
5603 (= (calendar-day-of-week date) dayname)
5604 (or (not skip-weeks)
5605 (progn
5606 (require 'cal-iso)
5607 (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
5608 (not (or (and h (memq 'holidays skip-weeks))
5609 (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
5610 entry)))
5612 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
5613 "Like `org-class', but honor `calendar-date-style'.
5614 The order of the first 2 times 3 arguments depends on the variable
5615 `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
5616 So for American calendars, give this as MONTH DAY YEAR, for European as
5617 DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
5618 DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
5619 is any number of ISO weeks in the block period for which the item should
5620 be skipped.
5622 This function is here only for backward compatibility and it is deprecated,
5623 please use `org-class' instead."
5624 (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
5625 (date2 (org-order-calendar-date-args m2 d2 y2)))
5626 (org-class
5627 (nth 2 date1) (car date1) (nth 1 date1)
5628 (nth 2 date2) (car date2) (nth 1 date2)
5629 dayname skip-weeks)))
5630 (make-obsolete 'org-diary-class 'org-class "")
5632 (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
5633 (defalias 'org-get-closed 'org-agenda-get-progress)
5634 (defun org-agenda-get-progress ()
5635 "Return the logged TODO entries for agenda display."
5636 (let* ((props (list 'mouse-face 'highlight
5637 'org-not-done-regexp org-not-done-regexp
5638 'org-todo-regexp org-todo-regexp
5639 'org-complex-heading-regexp org-complex-heading-regexp
5640 'help-echo
5641 (format "mouse-2 or RET jump to org file %s"
5642 (abbreviate-file-name buffer-file-name))))
5643 (items (if (consp org-agenda-show-log-scoped)
5644 org-agenda-show-log-scoped
5645 (if (eq org-agenda-show-log-scoped 'clockcheck)
5646 '(clock)
5647 org-agenda-log-mode-items)))
5648 (parts
5649 (delq nil
5650 (list
5651 (if (memq 'closed items) (concat "\\<" org-closed-string))
5652 (if (memq 'clock items) (concat "\\<" org-clock-string))
5653 (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
5654 (parts-re (if parts (mapconcat 'identity parts "\\|")
5655 (error "`org-agenda-log-mode-items' is empty")))
5656 (regexp (concat
5657 "\\(" parts-re "\\)"
5658 " *\\["
5659 (regexp-quote
5660 (substring
5661 (format-time-string
5662 (car org-time-stamp-formats)
5663 (apply 'encode-time ; DATE bound by calendar
5664 (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
5665 1 11))))
5666 (org-agenda-search-headline-for-time nil)
5667 marker hdmarker priority category category-pos level tags closedp
5668 statep clockp state ee txt extra timestr rest clocked)
5669 (goto-char (point-min))
5670 (while (re-search-forward regexp nil t)
5671 (catch :skip
5672 (org-agenda-skip)
5673 (setq marker (org-agenda-new-marker (match-beginning 0))
5674 closedp (equal (match-string 1) org-closed-string)
5675 statep (equal (string-to-char (match-string 1)) ?-)
5676 clockp (not (or closedp statep))
5677 state (and statep (match-string 2))
5678 category (org-get-category (match-beginning 0))
5679 category-pos (get-text-property (match-beginning 0) 'org-category-position)
5680 timestr (buffer-substring (match-beginning 0) (point-at-eol)))
5681 (when (string-match "\\]" timestr)
5682 ;; substring should only run to end of time stamp
5683 (setq rest (substring timestr (match-end 0))
5684 timestr (substring timestr 0 (match-end 0)))
5685 (if (and (not closedp) (not statep)
5686 (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
5687 rest))
5688 (progn (setq timestr (concat (substring timestr 0 -1)
5689 "-" (match-string 1 rest) "]"))
5690 (setq clocked (match-string 2 rest)))
5691 (setq clocked "-")))
5692 (save-excursion
5693 (setq extra
5694 (cond
5695 ((not org-agenda-log-mode-add-notes) nil)
5696 (statep
5697 (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
5698 (match-string 1)))
5699 (clockp
5700 (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
5701 (match-string 1)))))
5702 (if (not (re-search-backward org-outline-regexp-bol nil t))
5703 (setq txt org-agenda-no-heading-message)
5704 (goto-char (match-beginning 0))
5705 (setq hdmarker (org-agenda-new-marker)
5706 tags (org-get-tags-at)
5707 level (make-string (org-reduced-level (org-outline-level)) ? ))
5708 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
5709 (setq txt (match-string 1))
5710 (when extra
5711 (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
5712 (setq txt (concat (substring txt 0 (match-beginning 1))
5713 " - " extra " " (match-string 2 txt)))
5714 (setq txt (concat txt " - " extra))))
5715 (setq txt (org-agenda-format-item
5716 (cond
5717 (closedp "Closed: ")
5718 (statep (concat "State: (" state ")"))
5719 (t (concat "Clocked: (" clocked ")")))
5720 txt level category tags timestr)))
5721 (setq priority 100000)
5722 (org-add-props txt props
5723 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
5724 'priority priority 'org-category category
5725 'org-category-position category-pos
5726 'level level
5727 'type "closed" 'date date
5728 'undone-face 'org-warning 'done-face 'org-agenda-done)
5729 (push txt ee))
5730 (goto-char (point-at-eol))))
5731 (nreverse ee)))
5733 (defun org-agenda-show-clocking-issues ()
5734 "Add overlays, showing issues with clocking.
5735 See also the user option `org-agenda-clock-consistency-checks'."
5736 (interactive)
5737 (let* ((pl org-agenda-clock-consistency-checks)
5738 (re (concat "^[ \t]*"
5739 org-clock-string
5740 "[ \t]+"
5741 "\\(\\[.*?\\]\\)" ; group 1 is first stamp
5742 "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
5743 (tlstart 0.)
5744 (tlend 0.)
5745 (maxtime (org-hh:mm-string-to-minutes
5746 (or (plist-get pl :max-duration) "24:00")))
5747 (mintime (org-hh:mm-string-to-minutes
5748 (or (plist-get pl :min-duration) 0)))
5749 (maxgap (org-hh:mm-string-to-minutes
5750 ;; default 30:00 means never complain
5751 (or (plist-get pl :max-gap) "30:00")))
5752 (gapok (mapcar 'org-hh:mm-string-to-minutes
5753 (plist-get pl :gap-ok-around)))
5754 (def-face (or (plist-get pl :default-face)
5755 '((:background "DarkRed") (:foreground "white"))))
5756 issue face m te ts dt ov)
5757 (goto-char (point-min))
5758 (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
5759 (setq issue nil face def-face)
5760 (catch 'next
5761 (setq m (org-get-at-bol 'org-marker)
5762 te nil ts nil)
5763 (unless (and m (markerp m))
5764 (setq issue "No valid clock line") (throw 'next t))
5765 (org-with-point-at m
5766 (save-excursion
5767 (goto-char (point-at-bol))
5768 (unless (looking-at re)
5769 (error "No valid Clock line")
5770 (throw 'next t))
5771 (unless (match-end 3)
5772 (setq issue "No end time"
5773 face (or (plist-get pl :no-end-time-face) face))
5774 (throw 'next t))
5775 (setq ts (match-string 1)
5776 te (match-string 3)
5777 ts (org-float-time
5778 (apply 'encode-time (org-parse-time-string ts)))
5779 te (org-float-time
5780 (apply 'encode-time (org-parse-time-string te)))
5781 dt (- te ts))))
5782 (cond
5783 ((> dt (* 60 maxtime))
5784 ;; a very long clocking chunk
5785 (setq issue (format "Clocking interval is very long: %s"
5786 (org-minutes-to-clocksum-string
5787 (floor (/ (float dt) 60.))))
5788 face (or (plist-get pl :long-face) face)))
5789 ((< dt (* 60 mintime))
5790 ;; a very short clocking chunk
5791 (setq issue (format "Clocking interval is very short: %s"
5792 (org-minutes-to-clocksum-string
5793 (floor (/ (float dt) 60.))))
5794 face (or (plist-get pl :short-face) face)))
5795 ((and (> tlend 0) (< ts tlend))
5796 ;; Two clock entries are overlapping
5797 (setq issue (format "Clocking overlap: %d minutes"
5798 (/ (- tlend ts) 60))
5799 face (or (plist-get pl :overlap-face) face)))
5800 ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
5801 ;; There is a gap, lets see if we need to report it
5802 (unless (org-agenda-check-clock-gap tlend ts gapok)
5803 (setq issue (format "Clocking gap: %d minutes"
5804 (/ (- ts tlend) 60))
5805 face (or (plist-get pl :gap-face) face))))
5806 (t nil)))
5807 (setq tlend (or te tlend) tlstart (or ts tlstart))
5808 (when issue
5809 ;; OK, there was some issue, add an overlay to show the issue
5810 (setq ov (make-overlay (point-at-bol) (point-at-eol)))
5811 (overlay-put ov 'before-string
5812 (concat
5813 (org-add-props
5814 (format "%-43s" (concat " " issue))
5816 'face face)
5817 "\n"))
5818 (overlay-put ov 'evaporate t)))))
5820 (defun org-agenda-check-clock-gap (t1 t2 ok-list)
5821 "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
5822 (catch 'exit
5823 (unless ok-list
5824 ;; there are no OK times for gaps...
5825 (throw 'exit nil))
5826 (if (> (- (/ t2 36000) (/ t1 36000)) 24)
5827 ;; This is more than 24 hours, so it is OK.
5828 ;; because we have at least one OK time, that must be in the
5829 ;; 24 hour interval.
5830 (throw 'exit t))
5831 ;; We have a shorter gap.
5832 ;; Now we have to get the minute of the day when these times are
5833 (let* ((t1dec (decode-time (seconds-to-time t1)))
5834 (t2dec (decode-time (seconds-to-time t2)))
5835 ;; compute the minute on the day
5836 (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
5837 (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
5838 (when (< min2 min1)
5839 ;; if min2 is smaller than min1, this means it is on the next day.
5840 ;; Wrap it to after midnight.
5841 (setq min2 (+ min2 1440)))
5842 ;; Now check if any of the OK times is in the gap
5843 (mapc (lambda (x)
5844 ;; Wrap the time to after midnight if necessary
5845 (if (< x min1) (setq x (+ x 1440)))
5846 ;; Check if in interval
5847 (and (<= min1 x) (>= min2 x) (throw 'exit t)))
5848 ok-list)
5849 ;; Nope, this gap is not OK
5850 nil)))
5852 (defun org-agenda-get-deadlines ()
5853 "Return the deadline information for agenda display."
5854 (let* ((props (list 'mouse-face 'highlight
5855 'org-not-done-regexp org-not-done-regexp
5856 'org-todo-regexp org-todo-regexp
5857 'org-complex-heading-regexp org-complex-heading-regexp
5858 'help-echo
5859 (format "mouse-2 or RET jump to org file %s"
5860 (abbreviate-file-name buffer-file-name))))
5861 (regexp org-deadline-time-regexp)
5862 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5863 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5864 d2 diff dfrac wdays pos pos1 category category-pos level
5865 tags suppress-prewarning ee txt head face s todo-state
5866 show-all upcomingp donep timestr warntime)
5867 (goto-char (point-min))
5868 (while (re-search-forward regexp nil t)
5869 (catch :skip
5870 (org-agenda-skip)
5871 (setq s (match-string 1)
5872 txt nil
5873 pos (1- (match-beginning 1))
5874 todo-state (save-match-data (org-get-todo-state))
5875 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
5876 (member todo-state
5877 org-agenda-repeating-timestamp-show-all))
5878 d2 (org-time-string-to-absolute
5879 (match-string 1) d1 'past show-all
5880 (current-buffer) pos)
5881 diff (- d2 d1))
5882 (setq suppress-prewarning
5883 (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
5884 (let ((item (buffer-substring (point-at-bol)
5885 (point-at-eol))))
5886 (save-match-data
5887 (and (string-match
5888 org-scheduled-time-regexp item)
5889 (match-string 1 item)))))))
5890 (cond
5891 ((not ds) nil)
5892 ;; The current item has a scheduled date (in ds), so
5893 ;; evaluate its prewarning lead time.
5894 ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
5895 ;; Use global prewarning-restart lead time.
5896 org-agenda-skip-deadline-prewarning-if-scheduled)
5897 ((eq org-agenda-skip-deadline-prewarning-if-scheduled
5898 'pre-scheduled)
5899 ;; Set prewarning to no earlier than scheduled.
5900 (min (- d2 (org-time-string-to-absolute
5901 ds d1 'past show-all (current-buffer) pos))
5902 org-deadline-warning-days))
5903 ;; Set prewarning to deadline.
5904 (t 0))))
5905 (setq wdays (if suppress-prewarning
5906 (let ((org-deadline-warning-days suppress-prewarning))
5907 (org-get-wdays s))
5908 (org-get-wdays s))
5909 dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
5910 upcomingp (and todayp (> diff 0)))
5911 ;; When to show a deadline in the calendar:
5912 ;; If the expiration is within wdays warning time.
5913 ;; Past-due deadlines are only shown on the current date
5914 (if (and (or (and (<= diff wdays)
5915 (and todayp (not org-agenda-only-exact-dates)))
5916 (= diff 0)))
5917 (save-excursion
5918 ;; (setq todo-state (org-get-todo-state))
5919 (setq donep (member todo-state org-done-keywords))
5920 (if (and donep
5921 (or org-agenda-skip-deadline-if-done
5922 (not (= diff 0))))
5923 (setq txt nil)
5924 (setq category (org-get-category)
5925 warntime (org-entry-get (point) "APPT_WARNTIME")
5926 category-pos (get-text-property (point) 'org-category-position))
5927 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
5928 (setq txt org-agenda-no-heading-message)
5929 (goto-char (match-end 0))
5930 (setq pos1 (match-beginning 0))
5931 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
5932 (setq tags (org-get-tags-at pos1))
5933 (setq head (buffer-substring-no-properties
5934 (point)
5935 (progn (skip-chars-forward "^\r\n")
5936 (point))))
5937 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
5938 (setq timestr
5939 (concat (substring s (match-beginning 1)) " "))
5940 (setq timestr 'time))
5941 (setq txt (org-agenda-format-item
5942 (if (= diff 0)
5943 (car org-agenda-deadline-leaders)
5944 (if (functionp
5945 (nth 1 org-agenda-deadline-leaders))
5946 (funcall
5947 (nth 1 org-agenda-deadline-leaders)
5948 diff date)
5949 (format (nth 1 org-agenda-deadline-leaders)
5950 diff)))
5951 head level category tags
5952 (if (not (= diff 0)) nil timestr)))))
5953 (when txt
5954 (setq face (org-agenda-deadline-face dfrac))
5955 (org-add-props txt props
5956 'org-marker (org-agenda-new-marker pos)
5957 'warntime warntime
5958 'level level
5959 'org-hd-marker (org-agenda-new-marker pos1)
5960 'priority (+ (- diff)
5961 (org-get-priority txt))
5962 'org-category category
5963 'org-category-position category-pos
5964 'todo-state todo-state
5965 'type (if upcomingp "upcoming-deadline" "deadline")
5966 'date (if upcomingp date d2)
5967 'face (if donep 'org-agenda-done face)
5968 'undone-face face 'done-face 'org-agenda-done)
5969 (push txt ee))))))
5970 (nreverse ee)))
5972 (defun org-agenda-deadline-face (fraction)
5973 "Return the face to displaying a deadline item.
5974 FRACTION is what fraction of the head-warning time has passed."
5975 (let ((faces org-agenda-deadline-faces) f)
5976 (catch 'exit
5977 (while (setq f (pop faces))
5978 (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
5980 (defun org-agenda-get-scheduled (&optional deadline-results)
5981 "Return the scheduled information for agenda display."
5982 (let* ((props (list 'org-not-done-regexp org-not-done-regexp
5983 'org-todo-regexp org-todo-regexp
5984 'org-complex-heading-regexp org-complex-heading-regexp
5985 'done-face 'org-agenda-done
5986 'mouse-face 'highlight
5987 'help-echo
5988 (format "mouse-2 or RET jump to org file %s"
5989 (abbreviate-file-name buffer-file-name))))
5990 (regexp org-scheduled-time-regexp)
5991 (todayp (org-agenda-todayp date)) ; DATE bound by calendar
5992 (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
5994 (deadline-position-alist
5995 (mapcar (lambda (a) (and (setq mm (get-text-property
5996 0 'org-hd-marker a))
5997 (cons (marker-position mm) a)))
5998 deadline-results))
5999 d2 diff pos pos1 category category-pos level tags donep
6000 ee txt head pastschedp todo-state face timestr s habitp show-all
6001 did-habit-check-p warntime)
6002 (goto-char (point-min))
6003 (while (re-search-forward regexp nil t)
6004 (catch :skip
6005 (org-agenda-skip)
6006 (setq s (match-string 1)
6007 txt nil
6008 pos (1- (match-beginning 1))
6009 todo-state (save-match-data (org-get-todo-state))
6010 show-all (or (eq org-agenda-repeating-timestamp-show-all t)
6011 (member todo-state
6012 org-agenda-repeating-timestamp-show-all))
6013 d2 (org-time-string-to-absolute
6014 (match-string 1) d1 'past show-all
6015 (current-buffer) pos)
6016 diff (- d2 d1)
6017 warntime (org-entry-get (point) "APPT_WARNTIME"))
6018 (setq pastschedp (and todayp (< diff 0)))
6019 (setq did-habit-check-p nil)
6020 ;; When to show a scheduled item in the calendar:
6021 ;; If it is on or past the date.
6022 (when (or (and (< diff 0)
6023 (< (abs diff) org-scheduled-past-days)
6024 (and todayp (not org-agenda-only-exact-dates)))
6025 (= diff 0)
6026 ;; org-is-habit-p uses org-entry-get, which is expansive
6027 ;; so we go extra mile to only call it once
6028 (and todayp
6029 (boundp 'org-habit-show-all-today)
6030 org-habit-show-all-today
6031 (setq did-habit-check-p t)
6032 (setq habitp (and (functionp 'org-is-habit-p)
6033 (org-is-habit-p)))))
6034 (save-excursion
6035 (setq donep (member todo-state org-done-keywords))
6036 (if (and donep
6037 (or org-agenda-skip-scheduled-if-done
6038 (not (= diff 0))
6039 (and (functionp 'org-is-habit-p)
6040 (org-is-habit-p))))
6041 (setq txt nil)
6042 (setq habitp (if did-habit-check-p habitp
6043 (and (functionp 'org-is-habit-p)
6044 (org-is-habit-p))))
6045 (setq category (org-get-category)
6046 category-pos (get-text-property (point) 'org-category-position))
6047 (if (not (re-search-backward "^\\*+[ \t]+" nil t))
6048 (setq txt org-agenda-no-heading-message)
6049 (goto-char (match-end 0))
6050 (setq pos1 (match-beginning 0))
6051 (if habitp
6052 (if (or (not org-habit-show-habits)
6053 (and (not todayp)
6054 (boundp 'org-habit-show-habits-only-for-today)
6055 org-habit-show-habits-only-for-today))
6056 (throw :skip nil))
6057 (if (and
6058 (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
6059 (and org-agenda-skip-scheduled-if-deadline-is-shown
6060 pastschedp))
6061 (setq mm (assoc pos1 deadline-position-alist)))
6062 (throw :skip nil)))
6063 (setq tags (org-get-tags-at))
6064 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6065 (setq head (buffer-substring-no-properties
6066 (point)
6067 (progn (skip-chars-forward "^\r\n") (point))))
6068 (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
6069 (setq timestr
6070 (concat (substring s (match-beginning 1)) " "))
6071 (setq timestr 'time))
6072 (setq txt (org-agenda-format-item
6073 (if (= diff 0)
6074 (car org-agenda-scheduled-leaders)
6075 (format (nth 1 org-agenda-scheduled-leaders)
6076 (- 1 diff)))
6077 head level category tags
6078 (if (not (= diff 0)) nil timestr)
6079 nil habitp))))
6080 (when txt
6081 (setq face
6082 (cond
6083 ((and (not habitp) pastschedp)
6084 'org-scheduled-previously)
6085 (todayp 'org-scheduled-today)
6086 (t 'org-scheduled))
6087 habitp (and habitp (org-habit-parse-todo)))
6088 (org-add-props txt props
6089 'undone-face face
6090 'face (if donep 'org-agenda-done face)
6091 'org-marker (org-agenda-new-marker pos)
6092 'org-hd-marker (org-agenda-new-marker pos1)
6093 'type (if pastschedp "past-scheduled" "scheduled")
6094 'date (if pastschedp d2 date)
6095 'warntime warntime
6096 'level level
6097 'priority (if habitp
6098 (org-habit-get-priority habitp)
6099 (+ 94 (- 5 diff) (org-get-priority txt)))
6100 'org-category category
6101 'category-position category-pos
6102 'org-habit-p habitp
6103 'todo-state todo-state)
6104 (push txt ee))))))
6105 (nreverse ee)))
6107 (defun org-agenda-get-blocks ()
6108 "Return the date-range information for agenda display."
6109 (let* ((props (list 'face nil
6110 'org-not-done-regexp org-not-done-regexp
6111 'org-todo-regexp org-todo-regexp
6112 'org-complex-heading-regexp org-complex-heading-regexp
6113 'mouse-face 'highlight
6114 'help-echo
6115 (format "mouse-2 or RET jump to org file %s"
6116 (abbreviate-file-name buffer-file-name))))
6117 (regexp org-tr-regexp)
6118 (d0 (calendar-absolute-from-gregorian date))
6119 marker hdmarker ee txt d1 d2 s1 s2 category category-pos
6120 level todo-state tags pos head donep)
6121 (goto-char (point-min))
6122 (while (re-search-forward regexp nil t)
6123 (catch :skip
6124 (org-agenda-skip)
6125 (setq pos (point))
6126 (let ((start-time (match-string 1))
6127 (end-time (match-string 2)))
6128 (setq s1 (match-string 1)
6129 s2 (match-string 2)
6130 d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
6131 d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
6132 (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
6133 ;; Only allow days between the limits, because the normal
6134 ;; date stamps will catch the limits.
6135 (save-excursion
6136 (setq todo-state (org-get-todo-state))
6137 (setq donep (member todo-state org-done-keywords))
6138 (if (and donep org-agenda-skip-timestamp-if-done)
6139 (throw :skip t))
6140 (setq marker (org-agenda-new-marker (point)))
6141 (setq category (org-get-category)
6142 category-pos (get-text-property (point) 'org-category-position))
6143 (if (not (re-search-backward org-outline-regexp-bol nil t))
6144 (setq txt org-agenda-no-heading-message)
6145 (goto-char (match-beginning 0))
6146 (setq hdmarker (org-agenda-new-marker (point)))
6147 (setq tags (org-get-tags-at))
6148 (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
6149 (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
6150 (setq head (match-string 1))
6151 (let ((remove-re
6152 (if org-agenda-remove-timeranges-from-blocks
6153 (concat
6154 "<" (regexp-quote s1) ".*?>"
6155 "--"
6156 "<" (regexp-quote s2) ".*?>")
6157 nil)))
6158 (setq txt (org-agenda-format-item
6159 (format
6160 (nth (if (= d1 d2) 0 1)
6161 org-agenda-timerange-leaders)
6162 (1+ (- d0 d1)) (1+ (- d2 d1)))
6163 head level category tags
6164 (cond ((and (= d1 d0) (= d2 d0))
6165 (concat "<" start-time ">--<" end-time ">"))
6166 ((= d1 d0)
6167 (concat "<" start-time ">"))
6168 ((= d2 d0)
6169 (concat "<" end-time ">")))
6170 remove-re))))
6171 (org-add-props txt props
6172 'org-marker marker 'org-hd-marker hdmarker
6173 'type "block" 'date date
6174 'level level
6175 'todo-state todo-state
6176 'priority (org-get-priority txt) 'org-category category
6177 'org-category-position category-pos)
6178 (push txt ee))))
6179 (goto-char pos)))
6180 ;; Sort the entries by expiration date.
6181 (nreverse ee)))
6183 ;;; Agenda presentation and sorting
6185 (defvar org-prefix-has-time nil
6186 "A flag, set by `org-compile-prefix-format'.
6187 The flag is set if the currently compiled format contains a `%t'.")
6188 (defvar org-prefix-has-tag nil
6189 "A flag, set by `org-compile-prefix-format'.
6190 The flag is set if the currently compiled format contains a `%T'.")
6191 (defvar org-prefix-has-effort nil
6192 "A flag, set by `org-compile-prefix-format'.
6193 The flag is set if the currently compiled format contains a `%e'.")
6194 (defvar org-prefix-category-length nil
6195 "Used by `org-compile-prefix-format' to remember the category field width.")
6196 (defvar org-prefix-category-max-length nil
6197 "Used by `org-compile-prefix-format' to remember the category field width.")
6199 (defun org-agenda-get-category-icon (category)
6200 "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
6201 (dolist (entry org-agenda-category-icon-alist)
6202 (when (org-string-match-p (car entry) category)
6203 (if (listp (cadr entry))
6204 (return (cadr entry))
6205 (return (apply 'create-image (cdr entry)))))))
6207 (defun org-agenda-format-item (extra txt &optional level category tags dotime
6208 remove-re habitp)
6209 "Format TXT to be inserted into the agenda buffer.
6210 In particular, add the prefix and corresponding text properties.
6212 EXTRA must be a string to replace the `%s' specifier in the prefix format.
6213 LEVEL may be a string to replace the `%l' specifier.
6214 CATEGORY (a string, a symbol or nil) may be used to overrule the default
6215 category taken from local variable or file name. It will replace the `%c'
6216 specifier in the format.
6217 DOTIME, when non-nil, indicates that a time-of-day should be extracted from
6218 TXT for sorting of this entry, and for the `%t' specifier in the format.
6219 When DOTIME is a string, this string is searched for a time before TXT is.
6220 TAGS can be the tags of the headline.
6221 Any match of REMOVE-RE will be removed from TXT."
6222 ;; We keep the org-prefix-* variable values along with a compiled
6223 ;; formatter, so that multiple agendas existing at the same time do
6224 ;; not step on each other toes.
6226 ;; It was inconvenient to make these variables buffer local in
6227 ;; Agenda buffers, because this function expects to be called with
6228 ;; the buffer where item comes from being current, and not agenda
6229 ;; buffer
6230 (let* ((bindings (car org-prefix-format-compiled))
6231 (formatter (cadr org-prefix-format-compiled)))
6232 (loop for (var value) in bindings
6233 do (set var value))
6234 (save-match-data
6235 ;; Diary entries sometimes have extra whitespace at the beginning
6236 (setq txt (org-trim txt))
6238 ;; Fix the tags part in txt
6239 (setq txt (org-agenda-fix-displayed-tags
6240 txt tags
6241 org-agenda-show-inherited-tags
6242 org-agenda-hide-tags-regexp))
6244 (let* ((category (or category
6245 (if (stringp org-category)
6246 org-category
6247 (and org-category (symbol-name org-category)))
6248 (if buffer-file-name
6249 (file-name-sans-extension
6250 (file-name-nondirectory buffer-file-name))
6251 "")))
6252 (category-icon (org-agenda-get-category-icon category))
6253 (category-icon (if category-icon
6254 (propertize " " 'display category-icon)
6255 ""))
6256 ;; time, tag, effort are needed for the eval of the prefix format
6257 (tag (if tags (nth (1- (length tags)) tags) ""))
6258 time effort neffort
6259 (ts (if dotime (concat
6260 (if (stringp dotime) dotime "")
6261 (and org-agenda-search-headline-for-time txt))))
6262 (time-of-day (and dotime (org-get-time-of-day ts)))
6263 stamp plain s0 s1 s2 rtn srp l
6264 duration thecategory)
6265 (and (derived-mode-p 'org-mode) buffer-file-name
6266 (add-to-list 'org-agenda-contributing-files buffer-file-name))
6267 (when (and dotime time-of-day)
6268 ;; Extract starting and ending time and move them to prefix
6269 (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
6270 (setq plain (string-match org-plain-time-of-day-regexp ts)))
6271 (setq s0 (match-string 0 ts)
6272 srp (and stamp (match-end 3))
6273 s1 (match-string (if plain 1 2) ts)
6274 s2 (match-string (if plain 8 (if srp 4 6)) ts))
6276 ;; If the times are in TXT (not in DOTIMES), and the prefix will list
6277 ;; them, we might want to remove them there to avoid duplication.
6278 ;; The user can turn this off with a variable.
6279 (if (and org-prefix-has-time
6280 org-agenda-remove-times-when-in-prefix (or stamp plain)
6281 (string-match (concat (regexp-quote s0) " *") txt)
6282 (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
6283 (if (eq org-agenda-remove-times-when-in-prefix 'beg)
6284 (= (match-beginning 0) 0)
6286 (setq txt (replace-match "" nil nil txt))))
6287 ;; Normalize the time(s) to 24 hour
6288 (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
6289 (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
6291 ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
6292 (when (and s1 (not s2) org-agenda-default-appointment-duration)
6293 (setq s2
6294 (org-minutes-to-clocksum-string
6295 (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
6297 ;; Compute the duration
6298 (when s2
6299 (setq duration (- (org-hh:mm-string-to-minutes s2)
6300 (org-hh:mm-string-to-minutes s1)))))
6302 (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
6303 txt)
6304 ;; Tags are in the string
6305 (if (or (eq org-agenda-remove-tags t)
6306 (and org-agenda-remove-tags
6307 org-prefix-has-tag))
6308 (setq txt (replace-match "" t t txt))
6309 (setq txt (replace-match
6310 (concat (make-string (max (- 50 (length txt)) 1) ?\ )
6311 (match-string 2 txt))
6312 t t txt))))
6313 (when (derived-mode-p 'org-mode)
6314 (setq effort
6315 (condition-case nil
6316 (org-get-effort
6317 (or (get-text-property 0 'org-hd-marker txt)
6318 (get-text-property 0 'org-marker txt)))
6319 (error nil)))
6320 (when effort
6321 (setq neffort (org-duration-string-to-minutes effort)
6322 effort (setq effort (concat "[" effort "]")))))
6323 ;; prevent erroring out with %e format when there is no effort
6324 (or effort (setq effort ""))
6326 (when remove-re
6327 (while (string-match remove-re txt)
6328 (setq txt (replace-match "" t t txt))))
6330 ;; Set org-heading property on `txt' to mark the start of the
6331 ;; heading.
6332 (add-text-properties 0 (length txt) '(org-heading t) txt)
6334 ;; Prepare the variables needed in the eval of the compiled format
6335 (setq time (cond (s2 (concat
6336 (org-agenda-time-of-day-to-ampm-maybe s1)
6337 "-" (org-agenda-time-of-day-to-ampm-maybe s2)
6338 (if org-agenda-timegrid-use-ampm " ")))
6339 (s1 (concat
6340 (org-agenda-time-of-day-to-ampm-maybe s1)
6341 (if org-agenda-timegrid-use-ampm
6342 "........ "
6343 "......")))
6344 (t ""))
6345 extra (or (and (not habitp) extra) "")
6346 category (if (symbolp category) (symbol-name category) category)
6347 thecategory (copy-sequence category)
6348 level (or level ""))
6349 (if (string-match org-bracket-link-regexp category)
6350 (progn
6351 (setq l (if (match-end 3)
6352 (- (match-end 3) (match-beginning 3))
6353 (- (match-end 1) (match-beginning 1))))
6354 (when (< l (or org-prefix-category-length 0))
6355 (setq category (copy-sequence category))
6356 (org-add-props category nil
6357 'extra-space (make-string
6358 (- org-prefix-category-length l 1) ?\ ))))
6359 (if (and org-prefix-category-max-length
6360 (>= (length category) org-prefix-category-max-length))
6361 (setq category (substring category 0 (1- org-prefix-category-max-length)))))
6362 ;; Evaluate the compiled format
6363 (setq rtn (concat (eval formatter) txt))
6365 ;; And finally add the text properties
6366 (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
6367 (org-add-props rtn nil
6368 'org-category (if thecategory (downcase thecategory) category)
6369 'tags (mapcar 'org-downcase-keep-props tags)
6370 'org-highest-priority org-highest-priority
6371 'org-lowest-priority org-lowest-priority
6372 'time-of-day time-of-day
6373 'duration duration
6374 'effort effort
6375 'effort-minutes neffort
6376 'txt txt
6377 'level level
6378 'time time
6379 'extra extra
6380 'format org-prefix-format-compiled
6381 'dotime dotime)))))
6383 (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
6384 "Remove tags string from TXT, and add a modified list of tags.
6385 The modified list may contain inherited tags, and tags matched by
6386 `org-agenda-hide-tags-regexp' will be removed."
6387 (when (or add-inherited hide-re)
6388 (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
6389 (setq txt (substring txt 0 (match-beginning 0))))
6390 (setq tags
6391 (delq nil
6392 (mapcar (lambda (tg)
6393 (if (or (and hide-re (string-match hide-re tg))
6394 (and (not add-inherited)
6395 (get-text-property 0 'inherited tg)))
6397 tg))
6398 tags)))
6399 (when tags
6400 (let ((have-i (get-text-property 0 'inherited (car tags)))
6402 (setq txt (concat txt " :"
6403 (mapconcat
6404 (lambda (x)
6405 (setq i (get-text-property 0 'inherited x))
6406 (if (and have-i (not i))
6407 (progn
6408 (setq have-i nil)
6409 (concat ":" x))
6411 tags ":")
6412 (if have-i "::" ":"))))))
6413 txt)
6415 (defun org-downcase-keep-props (s)
6416 (let ((props (text-properties-at 0 s)))
6417 (setq s (downcase s))
6418 (add-text-properties 0 (length s) props s)
6421 (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
6422 (defvar org-agenda-sorting-strategy-selected nil)
6424 (defun org-agenda-add-time-grid-maybe (list ndays todayp)
6425 "Add a time-grid for agenda items which need it.
6427 LIST is the list of agenda items formatted by `org-agenda-list'.
6428 NDAYS is the span of the current agenda view.
6429 TODAYP is `t' when the current agenda view is on today."
6430 (catch 'exit
6431 (cond ((not org-agenda-use-time-grid) (throw 'exit list))
6432 ((and todayp (member 'today (car org-agenda-time-grid))))
6433 ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
6434 ((member 'weekly (car org-agenda-time-grid)))
6435 (t (throw 'exit list)))
6436 (let* ((have (delq nil (mapcar
6437 (lambda (x) (get-text-property 1 'time-of-day x))
6438 list)))
6439 (string (nth 1 org-agenda-time-grid))
6440 (gridtimes (nth 2 org-agenda-time-grid))
6441 (req (car org-agenda-time-grid))
6442 (remove (member 'remove-match req))
6443 new time)
6444 (if (and (member 'require-timed req) (not have))
6445 ;; don't show empty grid
6446 (throw 'exit list))
6447 (while (setq time (pop gridtimes))
6448 (unless (and remove (member time have))
6449 (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
6450 (push (org-agenda-format-item
6451 nil string nil "" nil
6452 (concat (substring time 0 -2) ":" (substring time -2)))
6453 new)
6454 (put-text-property
6455 2 (length (car new)) 'face 'org-time-grid (car new))))
6456 (when (and todayp org-agenda-show-current-time-in-grid)
6457 (push (org-agenda-format-item
6458 nil org-agenda-current-time-string nil "" nil
6459 (format-time-string "%H:%M "))
6460 new)
6461 (put-text-property
6462 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
6464 (if (member 'time-up org-agenda-sorting-strategy-selected)
6465 (append new list)
6466 (append list new)))))
6468 (defun org-compile-prefix-format (key)
6469 "Compile the prefix format into a Lisp form that can be evaluated.
6470 The resulting form and associated variable bindings is returned
6471 and stored in the variable `org-prefix-format-compiled'."
6472 (setq org-prefix-has-time nil
6473 org-prefix-has-tag nil
6474 org-prefix-category-length nil
6475 org-prefix-has-effort nil)
6476 (let ((s (cond
6477 ((stringp org-agenda-prefix-format)
6478 org-agenda-prefix-format)
6479 ((assq key org-agenda-prefix-format)
6480 (cdr (assq key org-agenda-prefix-format)))
6481 (t " %-12:c%?-12t% s")))
6482 (start 0)
6483 varform vars var e c f opt)
6484 (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
6485 s start)
6486 (setq var (or (cdr (assoc (match-string 4 s)
6487 '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
6488 ("i" . category-icon) ("T" . tag) ("e" . effort))))
6489 'eval)
6490 c (or (match-string 3 s) "")
6491 opt (match-beginning 1)
6492 start (1+ (match-beginning 0)))
6493 (if (equal var 'time) (setq org-prefix-has-time t))
6494 (if (equal var 'tag) (setq org-prefix-has-tag t))
6495 (if (equal var 'effort) (setq org-prefix-has-effort t))
6496 (setq f (concat "%" (match-string 2 s) "s"))
6497 (when (equal var 'category)
6498 (setq org-prefix-category-length
6499 (floor (abs (string-to-number (match-string 2 s)))))
6500 (setq org-prefix-category-max-length
6501 (let ((x (match-string 2 s)))
6502 (save-match-data
6503 (if (string-match "\\.[0-9]+" x)
6504 (string-to-number (substring (match-string 0 x) 1)))))))
6505 (if (eq var 'eval)
6506 (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
6507 (if opt
6508 (setq varform
6509 `(if (equal "" ,var)
6511 (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
6512 (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
6513 (setq s (replace-match "%s" t nil s))
6514 (push varform vars))
6515 (setq vars (nreverse vars))
6516 (with-current-buffer (or org-agenda-buffer (current-buffer))
6517 (setq org-prefix-format-compiled
6518 (list
6519 `((org-prefix-has-time ,org-prefix-has-time)
6520 (org-prefix-has-tag ,org-prefix-has-tag)
6521 (org-prefix-category-length ,org-prefix-category-length)
6522 (org-prefix-has-effort ,org-prefix-has-effort))
6523 `(format ,s ,@vars))))))
6525 (defun org-set-sorting-strategy (key)
6526 (if (symbolp (car org-agenda-sorting-strategy))
6527 ;; the old format
6528 (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
6529 (setq org-agenda-sorting-strategy-selected
6530 (or (cdr (assq key org-agenda-sorting-strategy))
6531 (cdr (assq 'agenda org-agenda-sorting-strategy))
6532 '(time-up category-keep priority-down)))))
6534 (defun org-get-time-of-day (s &optional string mod24)
6535 "Check string S for a time of day.
6536 If found, return it as a military time number between 0 and 2400.
6537 If not found, return nil.
6538 The optional STRING argument forces conversion into a 5 character wide string
6539 HH:MM."
6540 (save-match-data
6541 (when
6542 (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
6543 (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
6544 (let* ((h (string-to-number (match-string 1 s)))
6545 (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
6546 (ampm (if (match-end 4) (downcase (match-string 4 s))))
6547 (am-p (equal ampm "am"))
6548 (h1 (cond ((not ampm) h)
6549 ((= h 12) (if am-p 0 12))
6550 (t (+ h (if am-p 0 12)))))
6551 (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
6552 (mod h1 24) h1))
6553 (t0 (+ (* 100 h2) m))
6554 (t1 (concat (if (>= h1 24) "+" " ")
6555 (if (and org-agenda-time-leading-zero
6556 (< t0 1000)) "0" "")
6557 (if (< t0 100) "0" "")
6558 (if (< t0 10) "0" "")
6559 (int-to-string t0))))
6560 (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
6562 (defvar org-agenda-before-sorting-filter-function nil
6563 "Function to be applied to agenda items prior to sorting.
6564 Prior to sorting also means just before they are inserted into the agenda.
6566 To aid sorting, you may revisit the original entries and add more text
6567 properties which will later be used by the sorting functions.
6569 The function should take a string argument, an agenda line.
6570 It has access to the text properties in that line, which contain among
6571 other things, the property `org-hd-marker' that points to the entry
6572 where the line comes from. Note that not all lines going into the agenda
6573 have this property, only most.
6575 The function should return the modified string. It is probably best
6576 to ONLY change text properties.
6578 You can also use this function as a filter, by returning nil for lines
6579 you don't want to have in the agenda at all. For this application, you
6580 could bind the variable in the options section of a custom command.")
6582 (defun org-agenda-finalize-entries (list &optional nosort)
6583 "Sort and concatenate the agenda items."
6584 (setq list (mapcar 'org-agenda-highlight-todo list))
6585 (if nosort
6586 list
6587 (when org-agenda-before-sorting-filter-function
6588 (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
6589 (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
6591 (defun org-agenda-highlight-todo (x)
6592 (let ((org-done-keywords org-done-keywords-for-agenda)
6593 (case-fold-search nil)
6595 (if (eq x 'line)
6596 (save-excursion
6597 (beginning-of-line 1)
6598 (setq re (org-get-at-bol 'org-todo-regexp))
6599 (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
6600 (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
6601 (add-text-properties (match-beginning 0) (match-end 1)
6602 (list 'face (org-get-todo-face 1)))
6603 (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
6604 (delete-region (match-beginning 1) (1- (match-end 0)))
6605 (goto-char (match-beginning 1))
6606 (insert (format org-agenda-todo-keyword-format s)))))
6607 (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
6608 (setq re (get-text-property 0 'org-todo-regexp x))
6609 (when (and re
6610 ;; Test `pl' because if there's no heading content,
6611 ;; there's no point matching to highlight. Note
6612 ;; that if we didn't test `pl' first, and there
6613 ;; happened to be no keyword from `org-todo-regexp'
6614 ;; on this heading line, then the `equal' comparison
6615 ;; afterwards would spuriously succeed in the case
6616 ;; where `pl' is nil -- causing an args-out-of-range
6617 ;; error when we try to add text properties to text
6618 ;; that isn't there.
6620 (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
6621 x pl) pl))
6622 (add-text-properties
6623 (or (match-end 1) (match-end 0)) (match-end 0)
6624 (list 'face (org-get-todo-face (match-string 2 x)))
6626 (when (match-end 1)
6627 (setq x (concat (substring x 0 (match-end 1))
6628 (format org-agenda-todo-keyword-format
6629 (match-string 2 x))
6630 (org-add-props " " (text-properties-at 0 x))
6631 (substring x (match-end 3)))))))
6632 x)))
6634 (defsubst org-cmp-priority (a b)
6635 "Compare the priorities of string A and B."
6636 (let ((pa (or (get-text-property 1 'priority a) 0))
6637 (pb (or (get-text-property 1 'priority b) 0)))
6638 (cond ((> pa pb) +1)
6639 ((< pa pb) -1))))
6641 (defsubst org-cmp-effort (a b)
6642 "Compare the effort values of string A and B."
6643 (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
6644 (ea (or (get-text-property 1 'effort-minutes a) def))
6645 (eb (or (get-text-property 1 'effort-minutes b) def)))
6646 (cond ((> ea eb) +1)
6647 ((< ea eb) -1))))
6649 (defsubst org-cmp-category (a b)
6650 "Compare the string values of categories of strings A and B."
6651 (let ((ca (or (get-text-property 1 'org-category a) ""))
6652 (cb (or (get-text-property 1 'org-category b) "")))
6653 (cond ((string-lessp ca cb) -1)
6654 ((string-lessp cb ca) +1))))
6656 (defsubst org-cmp-todo-state (a b)
6657 "Compare the todo states of strings A and B."
6658 (let* ((ma (or (get-text-property 1 'org-marker a)
6659 (get-text-property 1 'org-hd-marker a)))
6660 (mb (or (get-text-property 1 'org-marker b)
6661 (get-text-property 1 'org-hd-marker b)))
6662 (fa (and ma (marker-buffer ma)))
6663 (fb (and mb (marker-buffer mb)))
6664 (todo-kwds
6665 (or (and fa (with-current-buffer fa org-todo-keywords-1))
6666 (and fb (with-current-buffer fb org-todo-keywords-1))))
6667 (ta (or (get-text-property 1 'todo-state a) ""))
6668 (tb (or (get-text-property 1 'todo-state b) ""))
6669 (la (- (length (member ta todo-kwds))))
6670 (lb (- (length (member tb todo-kwds))))
6671 (donepa (member ta org-done-keywords-for-agenda))
6672 (donepb (member tb org-done-keywords-for-agenda)))
6673 (cond ((and donepa (not donepb)) -1)
6674 ((and (not donepa) donepb) +1)
6675 ((< la lb) -1)
6676 ((< lb la) +1))))
6678 (defsubst org-cmp-alpha (a b)
6679 "Compare the headlines, alphabetically."
6680 (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
6681 (plb (text-property-any 0 (length b) 'org-heading t b))
6682 (ta (and pla (substring a pla)))
6683 (tb (and plb (substring b plb))))
6684 (when pla
6685 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
6686 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
6687 (setq ta (substring ta (match-end 0))))
6688 (setq ta (downcase ta)))
6689 (when plb
6690 (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
6691 "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
6692 (setq tb (substring tb (match-end 0))))
6693 (setq tb (downcase tb)))
6694 (cond ((not ta) +1)
6695 ((not tb) -1)
6696 ((string-lessp ta tb) -1)
6697 ((string-lessp tb ta) +1))))
6699 (defsubst org-cmp-tag (a b)
6700 "Compare the string values of the first tags of A and B."
6701 (let ((ta (car (last (get-text-property 1 'tags a))))
6702 (tb (car (last (get-text-property 1 'tags b)))))
6703 (cond ((not ta) +1)
6704 ((not tb) -1)
6705 ((string-lessp ta tb) -1)
6706 ((string-lessp tb ta) +1))))
6708 (defsubst org-cmp-time (a b)
6709 "Compare the time-of-day values of strings A and B."
6710 (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
6711 (ta (or (get-text-property 1 'time-of-day a) def))
6712 (tb (or (get-text-property 1 'time-of-day b) def)))
6713 (cond ((< ta tb) -1)
6714 ((< tb ta) +1))))
6716 (defsubst org-cmp-habit-p (a b)
6717 "Compare the todo states of strings A and B."
6718 (let ((ha (get-text-property 1 'org-habit-p a))
6719 (hb (get-text-property 1 'org-habit-p b)))
6720 (cond ((and ha (not hb)) -1)
6721 ((and (not ha) hb) +1))))
6723 (defsubst org-em (x y list) (or (memq x list) (memq y list)))
6725 (defun org-entries-lessp (a b)
6726 "Predicate for sorting agenda entries."
6727 ;; The following variables will be used when the form is evaluated.
6728 ;; So even though the compiler complains, keep them.
6729 (let* ((ss org-agenda-sorting-strategy-selected)
6730 (time-up (and (org-em 'time-up 'time-down ss)
6731 (org-cmp-time a b)))
6732 (time-down (if time-up (- time-up) nil))
6733 (priority-up (and (org-em 'priority-up 'priority-down ss)
6734 (org-cmp-priority a b)))
6735 (priority-down (if priority-up (- priority-up) nil))
6736 (effort-up (and (org-em 'effort-up 'effort-down ss)
6737 (org-cmp-effort a b)))
6738 (effort-down (if effort-up (- effort-up) nil))
6739 (category-up (and (or (org-em 'category-up 'category-down ss)
6740 (memq 'category-keep ss))
6741 (org-cmp-category a b)))
6742 (category-down (if category-up (- category-up) nil))
6743 (category-keep (if category-up +1 nil))
6744 (tag-up (and (org-em 'tag-up 'tag-down ss)
6745 (org-cmp-tag a b)))
6746 (tag-down (if tag-up (- tag-up) nil))
6747 (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
6748 (org-cmp-todo-state a b)))
6749 (todo-state-down (if todo-state-up (- todo-state-up) nil))
6750 (habit-up (and (org-em 'habit-up 'habit-down ss)
6751 (org-cmp-habit-p a b)))
6752 (habit-down (if habit-up (- habit-up) nil))
6753 (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
6754 (org-cmp-alpha a b)))
6755 (alpha-down (if alpha-up (- alpha-up) nil))
6756 (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
6757 user-defined-up user-defined-down)
6758 (if (and need-user-cmp org-agenda-cmp-user-defined
6759 (functionp org-agenda-cmp-user-defined))
6760 (setq user-defined-up
6761 (funcall org-agenda-cmp-user-defined a b)
6762 user-defined-down (if user-defined-up (- user-defined-up) nil)))
6763 (cdr (assoc
6764 (eval (cons 'or org-agenda-sorting-strategy-selected))
6765 '((-1 . t) (1 . nil) (nil . nil))))))
6767 ;;; Agenda restriction lock
6769 (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
6770 "Overlay to mark the headline to which agenda commands are restricted.")
6771 (overlay-put org-agenda-restriction-lock-overlay
6772 'face 'org-agenda-restriction-lock)
6773 (overlay-put org-agenda-restriction-lock-overlay
6774 'help-echo "Agendas are currently limited to this subtree.")
6775 (org-detach-overlay org-agenda-restriction-lock-overlay)
6777 (defun org-agenda-set-restriction-lock (&optional type)
6778 "Set restriction lock for agenda, to current subtree or file.
6779 Restriction will be the file if TYPE is `file', or if type is the
6780 universal prefix '(4), or if the cursor is before the first headline
6781 in the file. Otherwise, restriction will be to the current subtree."
6782 (interactive "P")
6783 (and (equal type '(4)) (setq type 'file))
6784 (setq type (cond
6785 (type type)
6786 ((org-at-heading-p) 'subtree)
6787 ((condition-case nil (org-back-to-heading t) (error nil))
6788 'subtree)
6789 (t 'file)))
6790 (if (eq type 'subtree)
6791 (progn
6792 (setq org-agenda-restrict t)
6793 (setq org-agenda-overriding-restriction 'subtree)
6794 (put 'org-agenda-files 'org-restrict
6795 (list (buffer-file-name (buffer-base-buffer))))
6796 (org-back-to-heading t)
6797 (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
6798 (move-marker org-agenda-restrict-begin (point))
6799 (move-marker org-agenda-restrict-end
6800 (save-excursion (org-end-of-subtree t)))
6801 (message "Locking agenda restriction to subtree"))
6802 (put 'org-agenda-files 'org-restrict
6803 (list (buffer-file-name (buffer-base-buffer))))
6804 (setq org-agenda-restrict nil)
6805 (setq org-agenda-overriding-restriction 'file)
6806 (move-marker org-agenda-restrict-begin nil)
6807 (move-marker org-agenda-restrict-end nil)
6808 (message "Locking agenda restriction to file"))
6809 (setq current-prefix-arg nil)
6810 (org-agenda-maybe-redo))
6812 (defun org-agenda-remove-restriction-lock (&optional noupdate)
6813 "Remove the agenda restriction lock."
6814 (interactive "P")
6815 (org-detach-overlay org-agenda-restriction-lock-overlay)
6816 (org-detach-overlay org-speedbar-restriction-lock-overlay)
6817 (setq org-agenda-overriding-restriction nil)
6818 (setq org-agenda-restrict nil)
6819 (put 'org-agenda-files 'org-restrict nil)
6820 (move-marker org-agenda-restrict-begin nil)
6821 (move-marker org-agenda-restrict-end nil)
6822 (setq current-prefix-arg nil)
6823 (message "Agenda restriction lock removed")
6824 (or noupdate (org-agenda-maybe-redo)))
6826 (defun org-agenda-maybe-redo ()
6827 "If there is any window showing the agenda view, update it."
6828 (let ((w (get-buffer-window org-agenda-buffer-name t))
6829 (w0 (selected-window)))
6830 (when w
6831 (select-window w)
6832 (org-agenda-redo)
6833 (select-window w0)
6834 (if org-agenda-overriding-restriction
6835 (message "Agenda view shifted to new %s restriction"
6836 org-agenda-overriding-restriction)
6837 (message "Agenda restriction lock removed")))))
6839 ;;; Agenda commands
6841 (defun org-agenda-check-type (error &rest types)
6842 "Check if agenda buffer is of allowed type.
6843 If ERROR is non-nil, throw an error, otherwise just return nil."
6844 (if (not org-agenda-type)
6845 (error "No Org agenda currently displayed")
6846 (if (memq org-agenda-type types)
6848 (if error
6849 (error "Not allowed in %s-type agenda buffers" org-agenda-type)
6850 nil))))
6852 (defun org-agenda-Quit ()
6853 "Exit the agenda and kill buffers loaded by `org-agenda'.
6854 Also restore the window configuration."
6855 (interactive)
6856 (if org-agenda-columns-active
6857 (org-columns-quit)
6858 (let ((buf (current-buffer)))
6859 (if (eq org-agenda-window-setup 'other-frame)
6860 (progn
6861 (org-agenda-reset-markers)
6862 (kill-buffer buf)
6863 (org-columns-remove-overlays)
6864 (setq org-agenda-archives-mode nil)
6865 (delete-frame))
6866 (and (not (eq org-agenda-window-setup 'current-window))
6867 (not (one-window-p))
6868 (delete-window))
6869 (org-agenda-reset-markers)
6870 (kill-buffer buf)
6871 (org-columns-remove-overlays)
6872 (setq org-agenda-archives-mode nil)))
6873 ;; Maybe restore the pre-agenda window configuration.
6874 (and org-agenda-restore-windows-after-quit
6875 (not (eq org-agenda-window-setup 'other-frame))
6876 org-agenda-pre-window-conf
6877 (set-window-configuration org-agenda-pre-window-conf)
6878 (setq org-agenda-pre-window-conf nil))))
6880 (defun org-agenda-quit ()
6881 "Exit the agenda and restore the window configuration.
6882 When `org-agenda-sticky' is non-nil, only bury the agenda."
6883 (interactive)
6884 (if (and (eq org-indirect-buffer-display 'other-window)
6885 org-last-indirect-buffer)
6886 (delete-window (get-buffer-window org-last-indirect-buffer)))
6887 (if org-agenda-columns-active
6888 (org-columns-quit)
6889 (if org-agenda-sticky
6890 (let ((buf (current-buffer)))
6891 (if (eq org-agenda-window-setup 'other-frame)
6892 (progn
6893 (delete-frame))
6894 (and (not (eq org-agenda-window-setup 'current-window))
6895 (not (one-window-p))
6896 (delete-window)))
6897 (with-current-buffer buf
6898 (bury-buffer)
6899 ;; Maybe restore the pre-agenda window configuration.
6900 (and org-agenda-restore-windows-after-quit
6901 (not (eq org-agenda-window-setup 'other-frame))
6902 org-agenda-pre-window-conf
6903 (set-window-configuration org-agenda-pre-window-conf)
6904 (setq org-agenda-pre-window-conf nil))))
6905 (org-agenda-Quit))))
6907 (defun org-agenda-exit ()
6908 "Exit the agenda and restore the window configuration.
6909 Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
6910 buffers visited directly by the user will not be touched."
6911 (interactive)
6912 (org-release-buffers org-agenda-new-buffers)
6913 (setq org-agenda-new-buffers nil)
6914 (org-agenda-Quit))
6916 (defun org-agenda-kill-all-agenda-buffers ()
6917 "Kill all buffers in `org-agenda-mode'.
6918 This is used when toggling sticky agendas.
6919 You can also explicitly invoke it with `C-c a C-k'."
6920 (interactive)
6921 (let (blist)
6922 (dolist (buf (buffer-list))
6923 (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
6924 (push buf blist)))
6925 (mapc 'kill-buffer blist)))
6927 (defun org-agenda-execute (arg)
6928 "Execute another agenda command, keeping same window.
6929 So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
6930 in the agenda."
6931 (interactive "P")
6932 (let ((org-agenda-window-setup 'current-window))
6933 (org-agenda arg)))
6935 (defun org-agenda-redo (&optional all)
6936 "Rebuild possibly ALL agenda view(s) in the current buffer."
6937 (interactive "P")
6938 (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
6939 (cpa (unless (eq all t) current-prefix-arg))
6940 (org-agenda-doing-sticky-redo org-agenda-sticky)
6941 (org-agenda-sticky nil)
6942 (org-agenda-buffer-name (or org-agenda-this-buffer-name
6943 org-agenda-buffer-name))
6944 (org-agenda-keep-modes t)
6945 (tag-filter org-agenda-tag-filter)
6946 (tag-preset (get 'org-agenda-tag-filter :preset-filter))
6947 (top-cat-filter org-agenda-top-category-filter)
6948 (cat-filter org-agenda-category-filter)
6949 (cat-preset (get 'org-agenda-category-filter :preset-filter))
6950 (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
6951 (cols org-agenda-columns-active)
6952 (line (org-current-line))
6953 (window-line (- line (org-current-line (window-start))))
6954 (lprops (get 'org-agenda-redo-command 'org-lprops))
6955 (redo-cmd (get-text-property p 'org-redo-cmd))
6956 (last-args (get-text-property p 'org-last-args))
6957 (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
6958 (org-agenda-overriding-cmd-arguments
6959 (unless (eq all t)
6960 (cond ((listp last-args)
6961 (cons (or cpa (car last-args)) (cdr last-args)))
6962 ((stringp last-args)
6963 last-args))))
6964 (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
6965 (put 'org-agenda-tag-filter :preset-filter nil)
6966 (put 'org-agenda-category-filter :preset-filter nil)
6967 (and cols (org-columns-quit))
6968 (message "Rebuilding agenda buffer...")
6969 (if series-redo-cmd
6970 (eval series-redo-cmd)
6971 (org-let lprops '(eval redo-cmd)))
6972 (setq org-agenda-undo-list nil
6973 org-agenda-pending-undo-list nil)
6974 (message "Rebuilding agenda buffer...done")
6975 (put 'org-agenda-tag-filter :preset-filter tag-preset)
6976 (put 'org-agenda-category-filter :preset-filter cat-preset)
6977 (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
6978 (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
6979 (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
6980 (and cols (org-called-interactively-p 'any) (org-agenda-columns))
6981 (org-goto-line line)
6982 (recenter window-line)))
6984 (defvar org-global-tags-completion-table nil)
6985 (defvar org-agenda-filter-form nil)
6986 (defvar org-agenda-filtered-by-category nil)
6988 (defun org-agenda-filter-by-category (strip)
6989 "Keep only those lines in the agenda buffer that have a specific category.
6990 The category is that of the current line."
6991 (interactive "P")
6992 (if (and org-agenda-filtered-by-category
6993 org-agenda-category-filter)
6994 (org-agenda-filter-show-all-cat)
6995 (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
6996 (if cat (org-agenda-filter-apply
6997 (list (concat (if strip "-" "+") cat)) 'category)
6998 (error "No category at point")))))
7000 (defun org-find-top-category (&optional pos)
7001 (save-excursion
7002 (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
7003 (if pos (goto-char pos))
7004 ;; Skip up to the topmost parent
7005 (while (ignore-errors (outline-up-heading 1) t))
7006 (ignore-errors
7007 (nth 4 (org-heading-components))))))
7009 (defvar org-agenda-filtered-by-top-category nil)
7011 (defun org-agenda-filter-by-top-category (strip)
7012 "Keep only those lines in the agenda buffer that have a specific category.
7013 The category is that of the current line."
7014 (interactive "P")
7015 (if org-agenda-filtered-by-top-category
7016 (progn
7017 (setq org-agenda-filtered-by-top-category nil
7018 org-agenda-top-category-filter nil)
7019 (org-agenda-filter-show-all-cat))
7020 (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
7021 (if cat (org-agenda-filter-top-category-apply cat strip)
7022 (error "No top-level category at point")))))
7024 (defun org-agenda-filter-by-tag (strip &optional char narrow)
7025 "Keep only those lines in the agenda buffer that have a specific tag.
7026 The tag is selected with its fast selection letter, as configured.
7027 With prefix argument STRIP, remove all lines that do have the tag.
7028 A lisp caller can specify CHAR. NARROW means that the new tag should be
7029 used to narrow the search - the interactive user can also press `-' or `+'
7030 to switch to narrowing."
7031 (interactive "P")
7032 (let* ((alist org-tag-alist-for-agenda)
7033 (tag-chars (mapconcat
7034 (lambda (x) (if (and (not (symbolp (car x)))
7035 (cdr x))
7036 (char-to-string (cdr x))
7037 ""))
7038 alist ""))
7039 (efforts (org-split-string
7040 (or (cdr (assoc (concat org-effort-property "_ALL")
7041 org-global-properties))
7042 "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
7043 "")))
7044 (effort-op org-agenda-filter-effort-default-operator)
7045 (effort-prompt "")
7046 (inhibit-read-only t)
7047 (current org-agenda-tag-filter)
7048 maybe-refresh a n tag)
7049 (unless char
7050 (message
7051 "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
7052 (if narrow "Narrow" "Filter") tag-chars
7053 (if org-agenda-auto-exclude-function "[RET], " ""))
7054 (setq char (read-char-exclusive)))
7055 (when (member char '(?+ ?-))
7056 ;; Narrowing down
7057 (cond ((equal char ?-) (setq strip t narrow t))
7058 ((equal char ?+) (setq strip nil narrow t)))
7059 (message
7060 "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
7061 (setq char (read-char-exclusive)))
7062 (when (member char '(?< ?> ?= ??))
7063 ;; An effort operator
7064 (setq effort-op (char-to-string char))
7065 (setq alist nil) ; to make sure it will be interpreted as effort.
7066 (unless (equal char ??)
7067 (loop for i from 0 to 9 do
7068 (setq effort-prompt
7069 (concat
7070 effort-prompt " ["
7071 (if (= i 9) "0" (int-to-string (1+ i)))
7072 "]" (nth i efforts))))
7073 (message "Effort%s: %s " effort-op effort-prompt)
7074 (setq char (read-char-exclusive))
7075 (when (or (< char ?0) (> char ?9))
7076 (error "Need 1-9,0 to select effort"))))
7077 (when (equal char ?\t)
7078 (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
7079 (org-set-local 'org-global-tags-completion-table
7080 (org-global-tags-completion-table)))
7081 (let ((completion-ignore-case t))
7082 (setq tag (org-icompleting-read
7083 "Tag: " org-global-tags-completion-table))))
7084 (cond
7085 ((equal char ?\r)
7086 (org-agenda-filter-show-all-tag)
7087 (when org-agenda-auto-exclude-function
7088 (setq org-agenda-tag-filter '())
7089 (dolist (tag (org-agenda-get-represented-tags))
7090 (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
7091 (if modifier
7092 (push modifier org-agenda-tag-filter))))
7093 (if (not (null org-agenda-tag-filter))
7094 (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
7095 (setq maybe-refresh t))
7096 ((equal char ?/)
7097 (org-agenda-filter-show-all-tag)
7098 (when (get 'org-agenda-tag-filter :preset-filter)
7099 (org-agenda-filter-apply org-agenda-tag-filter 'tag))
7100 (setq maybe-refresh t))
7101 ((equal char ?. )
7102 (setq org-agenda-tag-filter
7103 (mapcar (lambda(tag) (concat "+" tag))
7104 (org-get-at-bol 'tags)))
7105 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7106 (setq maybe-refresh t))
7107 ((or (equal char ?\ )
7108 (setq a (rassoc char alist))
7109 (and (>= char ?0) (<= char ?9)
7110 (setq n (if (= char ?0) 9 (- char ?0 1))
7111 tag (concat effort-op (nth n efforts))
7112 a (cons tag nil)))
7113 (and (= char ??)
7114 (setq tag "?eff")
7115 a (cons tag nil))
7116 (and tag (setq a (cons tag nil))))
7117 (org-agenda-filter-show-all-tag)
7118 (setq tag (car a))
7119 (setq org-agenda-tag-filter
7120 (cons (concat (if strip "-" "+") tag)
7121 (if narrow current nil)))
7122 (org-agenda-filter-apply org-agenda-tag-filter 'tag)
7123 (setq maybe-refresh t))
7124 (t (error "Invalid tag selection character %c" char)))
7125 (when (and maybe-refresh
7126 (eq org-agenda-clockreport-mode 'with-filter))
7127 (org-agenda-redo))))
7129 (defun org-agenda-get-represented-tags ()
7130 "Get a list of all tags currently represented in the agenda."
7131 (let (p tags)
7132 (save-excursion
7133 (goto-char (point-min))
7134 (while (setq p (next-single-property-change (point) 'tags))
7135 (goto-char p)
7136 (mapc (lambda (x) (add-to-list 'tags x))
7137 (get-text-property (point) 'tags))))
7138 tags))
7140 (defun org-agenda-filter-by-tag-refine (strip &optional char)
7141 "Refine the current filter. See `org-agenda-filter-by-tag'."
7142 (interactive "P")
7143 (org-agenda-filter-by-tag strip char 'refine))
7145 (defun org-agenda-filter-make-matcher ()
7146 "Create the form that tests a line for agenda filter."
7147 (let (f f1)
7148 ;; first compute the tag-filter matcher
7149 (dolist (x (delete-dups
7150 (append (get 'org-agenda-tag-filter
7151 :preset-filter) org-agenda-tag-filter)))
7152 (if (member x '("-" "+"))
7153 (setq f1 (if (equal x "-") 'tags '(not tags)))
7154 (if (string-match "[<=>?]" x)
7155 (setq f1 (org-agenda-filter-effort-form x))
7156 (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
7157 (if (equal (string-to-char x) ?-)
7158 (setq f1 (list 'not f1))))
7159 (push f1 f))
7160 ;; then compute the category-filter matcher
7161 (dolist (x (delete-dups
7162 (append (get 'org-agenda-category-filter
7163 :preset-filter) org-agenda-category-filter)))
7164 (if (equal "-" (substring x 0 1))
7165 (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
7166 (setq f1 (list 'equal (substring x 1) 'cat)))
7167 (push f1 f))
7168 (cons 'and (nreverse f))))
7170 (defun org-agenda-filter-effort-form (e)
7171 "Return the form to compare the effort of the current line with what E says.
7172 E looks like \"+<2:25\"."
7173 (let (op)
7174 (setq e (substring e 1))
7175 (setq op (string-to-char e) e (substring e 1))
7176 (setq op (cond ((equal op ?<) '<=)
7177 ((equal op ?>) '>=)
7178 ((equal op ??) op)
7179 (t '=)))
7180 (list 'org-agenda-compare-effort (list 'quote op)
7181 (org-duration-string-to-minutes e))))
7183 (defun org-agenda-compare-effort (op value)
7184 "Compare the effort of the current line with VALUE, using OP.
7185 If the line does not have an effort defined, return nil."
7186 (let ((eff (org-get-at-bol 'effort-minutes)))
7187 (if (equal op ??)
7188 (not eff)
7189 (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
7190 value))))
7192 (defun org-agenda-filter-apply (filter type)
7193 "Set FILTER as the new agenda filter and apply it."
7194 (let (tags cat)
7195 (if (eq type 'tag)
7196 (setq org-agenda-tag-filter filter)
7197 (setq org-agenda-category-filter filter))
7198 (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
7199 (if (and (eq type 'category)
7200 (not (equal (substring (car filter) 0 1) "-")))
7201 ;; Only set `org-agenda-filtered-by-category' to t
7202 ;; when a unique category is used as the filter
7203 (setq org-agenda-filtered-by-category t))
7204 (org-agenda-set-mode-name)
7205 (save-excursion
7206 (goto-char (point-min))
7207 (while (not (eobp))
7208 (if (org-get-at-bol 'org-marker)
7209 (progn
7210 (setq tags (org-get-at-bol 'tags) ; used in eval
7211 cat (get-text-property (point) 'org-category))
7212 (if (not (eval org-agenda-filter-form))
7213 (org-agenda-filter-hide-line type))
7214 (beginning-of-line 2))
7215 (beginning-of-line 2))))
7216 (if (get-char-property (point) 'invisible)
7217 (ignore-errors (org-agenda-previous-line)))))
7219 (defun org-agenda-filter-top-category-apply (category &optional negative)
7220 "Set FILTER as the new agenda filter and apply it."
7221 (org-agenda-set-mode-name)
7222 (save-excursion
7223 (goto-char (point-min))
7224 (while (not (eobp))
7225 (let* ((pos (org-get-at-bol 'org-hd-marker))
7226 (topcat (and pos (org-find-top-category pos))))
7227 (if (and topcat (funcall (if negative 'identity 'not)
7228 (string= category topcat)))
7229 (org-agenda-filter-hide-line 'category)))
7230 (beginning-of-line 2)))
7231 (if (get-char-property (point) 'invisible)
7232 (org-agenda-previous-line))
7233 (setq org-agenda-top-category-filter category
7234 org-agenda-filtered-by-top-category t))
7236 (defun org-agenda-filter-hide-line (type)
7237 (let (ov)
7238 (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
7239 (point-at-eol)))
7240 (overlay-put ov 'invisible t)
7241 (overlay-put ov 'type type)
7242 (if (eq type 'tag)
7243 (push ov org-agenda-tag-filter-overlays)
7244 (push ov org-agenda-cat-filter-overlays))))
7246 (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
7247 (setq pos (or pos (point)))
7248 (save-excursion
7249 (dolist (ov (overlays-at pos))
7250 (when (and (overlay-get ov 'invisible)
7251 (eq (overlay-get ov 'type) 'tag))
7252 (goto-char pos)
7253 (if (< (overlay-start ov) (point-at-eol))
7254 (move-overlay ov (point-at-eol)
7255 (overlay-end ov)))))))
7257 (defun org-agenda-filter-show-all-tag nil
7258 (mapc 'delete-overlay org-agenda-tag-filter-overlays)
7259 (setq org-agenda-tag-filter-overlays nil
7260 org-agenda-tag-filter nil
7261 org-agenda-filter-form nil)
7262 (org-agenda-set-mode-name))
7264 (defun org-agenda-filter-show-all-cat nil
7265 (mapc 'delete-overlay org-agenda-cat-filter-overlays)
7266 (setq org-agenda-cat-filter-overlays nil
7267 org-agenda-filtered-by-category nil
7268 org-agenda-category-filter nil
7269 org-agenda-filter-form nil)
7270 (org-agenda-set-mode-name))
7272 (defun org-agenda-manipulate-query-add ()
7273 "Manipulate the query by adding a search term with positive selection.
7274 Positive selection means the term must be matched for selection of an entry."
7275 (interactive)
7276 (org-agenda-manipulate-query ?\[))
7277 (defun org-agenda-manipulate-query-subtract ()
7278 "Manipulate the query by adding a search term with negative selection.
7279 Negative selection means term must not be matched for selection of an entry."
7280 (interactive)
7281 (org-agenda-manipulate-query ?\]))
7282 (defun org-agenda-manipulate-query-add-re ()
7283 "Manipulate the query by adding a search regexp with positive selection.
7284 Positive selection means the regexp must match for selection of an entry."
7285 (interactive)
7286 (org-agenda-manipulate-query ?\{))
7287 (defun org-agenda-manipulate-query-subtract-re ()
7288 "Manipulate the query by adding a search regexp with negative selection.
7289 Negative selection means regexp must not match for selection of an entry."
7290 (interactive)
7291 (org-agenda-manipulate-query ?\}))
7292 (defun org-agenda-manipulate-query (char)
7293 (cond
7294 ((memq org-agenda-type '(timeline agenda))
7295 (let ((org-agenda-include-inactive-timestamps t))
7296 (org-agenda-redo))
7297 (message "Display now includes inactive timestamps as well"))
7298 ((eq org-agenda-type 'search)
7299 (org-add-to-string
7300 'org-agenda-query-string
7301 (if org-agenda-last-search-view-search-was-boolean
7302 (cdr (assoc char '((?\[ . " +") (?\] . " -")
7303 (?\{ . " +{}") (?\} . " -{}"))))
7304 " "))
7305 (setq org-agenda-redo-command
7306 (list 'org-search-view
7307 (car (get-text-property (min (1- (point-max)) (point))
7308 'org-last-args))
7309 org-agenda-query-string
7310 (+ (length org-agenda-query-string)
7311 (if (member char '(?\{ ?\})) 0 1))))
7312 (set-register org-agenda-query-register org-agenda-query-string)
7313 (let ((org-agenda-overriding-arguments
7314 (cdr org-agenda-redo-command)))
7315 (org-agenda-redo)))
7316 (t (error "Cannot manipulate query for %s-type agenda buffers"
7317 org-agenda-type))))
7319 (defun org-add-to-string (var string)
7320 (set var (concat (symbol-value var) string)))
7322 (defun org-agenda-goto-date (span)
7323 "Jump to DATE in agenda."
7324 (interactive "P")
7325 (let* ((org-read-date-prefer-future
7326 (eval org-agenda-jump-prefer-future))
7327 (date (org-read-date))
7328 (org-agenda-sticky-orig org-agenda-sticky)
7329 (org-agenda-buffer-tmp-name (buffer-name))
7330 (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7331 (0-arg (or current-prefix-arg (car args)))
7332 (2-arg (nth 2 args))
7333 (newcmd (list 'org-agenda-list 0-arg date
7334 (org-agenda-span-to-ndays 2-arg)))
7335 (newargs (cdr newcmd))
7336 (inhibit-read-only t)
7337 org-agenda-sticky)
7338 (if (not (org-agenda-check-type t 'agenda))
7339 (error "Not available in non-agenda blocks")
7340 (add-text-properties (point-min) (point-max)
7341 `(org-redo-cmd ,newcmd org-last-args ,newargs))
7342 (org-agenda-redo)
7343 (setq org-agenda-sticky org-agenda-sticky-orig
7344 org-agenda-this-buffer-is-sticky org-agenda-sticky))))
7346 (defun org-agenda-goto-today ()
7347 "Go to today."
7348 (interactive)
7349 (org-agenda-check-type t 'timeline 'agenda)
7350 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7351 (curspan (nth 2 args))
7352 (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
7353 (cond
7354 (tdpos (goto-char tdpos))
7355 ((eq org-agenda-type 'agenda)
7356 (let* ((sd (org-agenda-compute-starting-span
7357 (org-today) (or curspan org-agenda-ndays org-agenda-span)))
7358 (org-agenda-overriding-arguments args))
7359 (setf (nth 1 org-agenda-overriding-arguments) sd)
7360 (org-agenda-redo)
7361 (org-agenda-find-same-or-today-or-agenda)))
7362 (t (error "Cannot find today")))))
7364 (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
7365 (goto-char
7366 (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
7367 (text-property-any (point-min) (point-max) 'org-today t)
7368 (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
7369 (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
7370 (org-agenda-goto-block-beginning))
7371 (point-min))))
7373 (defun org-agenda-goto-block-beginning ()
7374 "Go the agenda block beginning."
7375 (interactive)
7376 (if (not (derived-mode-p 'org-agenda-mode))
7377 (error "Cannot execute this command outside of org-agenda-mode buffers")
7378 (let (dest)
7379 (save-excursion
7380 (unless (looking-at "\\'")
7381 (forward-char))
7382 (let* ((prop 'org-agenda-structural-header)
7383 (p (previous-single-property-change (point) prop))
7384 (n (next-single-property-change (or (and (looking-at "\\`") 1)
7385 (1- (point))) prop)))
7386 (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
7387 (if (not dest)
7388 (error "Cannot find the beginning of the blog")
7389 (goto-char dest)
7390 (move-beginning-of-line 1)))))
7392 (defun org-agenda-later (arg)
7393 "Go forward in time by the current span.
7394 With prefix ARG, go forward that many times the current span."
7395 (interactive "p")
7396 (org-agenda-check-type t 'agenda)
7397 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7398 (span (or (nth 2 args) org-agenda-current-span))
7399 (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
7400 (greg (calendar-gregorian-from-absolute sd))
7401 (cnt (org-get-at-bol 'org-day-cnt))
7402 greg2)
7403 (cond
7404 ((numberp span)
7405 (setq sd (+ (* span arg) sd)))
7406 ((eq span 'day)
7407 (setq sd (+ arg sd)))
7408 ((eq span 'week)
7409 (setq sd (+ (* 7 arg) sd)))
7410 ((eq span 'month)
7411 (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
7412 sd (calendar-absolute-from-gregorian greg2))
7413 (setcar greg2 (1+ (car greg2))))
7414 ((eq span 'year)
7415 (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
7416 sd (calendar-absolute-from-gregorian greg2))
7417 (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
7419 (setq sd (+ (* span arg) sd))))
7420 (let ((org-agenda-overriding-cmd
7421 ;; `cmd' may have been set by `org-agenda-run-series' which
7422 ;; uses `org-agenda-overriding-cmd' to decide whether
7423 ;; overriding is allowed for `cmd'
7424 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7425 (org-agenda-overriding-arguments
7426 (list (car args) sd span)))
7427 (org-agenda-redo)
7428 (org-agenda-find-same-or-today-or-agenda cnt))))
7430 (defun org-agenda-earlier (arg)
7431 "Go backward in time by the current span.
7432 With prefix ARG, go backward that many times the current span."
7433 (interactive "p")
7434 (org-agenda-later (- arg)))
7436 (defun org-agenda-view-mode-dispatch ()
7437 "Call one of the view mode commands."
7438 (interactive)
7439 (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
7440 time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
7441 [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
7442 (let ((a (read-char-exclusive)))
7443 (case a
7444 (?\ (call-interactively 'org-agenda-reset-view))
7445 (?d (call-interactively 'org-agenda-day-view))
7446 (?w (call-interactively 'org-agenda-week-view))
7447 (?m (call-interactively 'org-agenda-month-view))
7448 (?y (call-interactively 'org-agenda-year-view))
7449 (?l (call-interactively 'org-agenda-log-mode))
7450 (?L (org-agenda-log-mode '(4)))
7451 (?c (org-agenda-log-mode 'clockcheck))
7452 ((?F ?f) (call-interactively 'org-agenda-follow-mode))
7453 (?a (call-interactively 'org-agenda-archives-mode))
7454 (?A (org-agenda-archives-mode 'files))
7455 ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
7456 ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
7457 (?G (call-interactively 'org-agenda-toggle-time-grid))
7458 (?D (call-interactively 'org-agenda-toggle-diary))
7459 (?\! (call-interactively 'org-agenda-toggle-deadlines))
7460 (?\[ (let ((org-agenda-include-inactive-timestamps t))
7461 (org-agenda-check-type t 'timeline 'agenda)
7462 (org-agenda-redo))
7463 (message "Display now includes inactive timestamps as well"))
7464 (?q (message "Abort"))
7465 (otherwise (error "Invalid key" )))))
7467 (defun org-agenda-reset-view ()
7468 "Switch to default view for agenda."
7469 (interactive)
7470 (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
7471 (defun org-agenda-day-view (&optional day-of-year)
7472 "Switch to daily view for agenda.
7473 With argument DAY-OF-YEAR, switch to that day of the year."
7474 (interactive "P")
7475 (org-agenda-change-time-span 'day day-of-year))
7476 (defun org-agenda-week-view (&optional iso-week)
7477 "Switch to daily view for agenda.
7478 With argument ISO-WEEK, switch to the corresponding ISO week.
7479 If ISO-WEEK has more then 2 digits, only the last two encode the
7480 week. Any digits before this encode a year. So 200712 means
7481 week 12 of year 2007. Years in the range 1938-2037 can also be
7482 written as 2-digit years."
7483 (interactive "P")
7484 (org-agenda-change-time-span 'week iso-week))
7485 (defun org-agenda-month-view (&optional month)
7486 "Switch to monthly view for agenda.
7487 With argument MONTH, switch to that month."
7488 (interactive "P")
7489 (org-agenda-change-time-span 'month month))
7490 (defun org-agenda-year-view (&optional year)
7491 "Switch to yearly view for agenda.
7492 With argument YEAR, switch to that year.
7493 If MONTH has more then 2 digits, only the last two encode the
7494 month. Any digits before this encode a year. So 200712 means
7495 December year 2007. Years in the range 1938-2037 can also be
7496 written as 2-digit years."
7497 (interactive "P")
7498 (when year
7499 (setq year (org-small-year-to-year year)))
7500 (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
7501 (org-agenda-change-time-span 'year year)
7502 (error "Abort")))
7504 (defun org-agenda-change-time-span (span &optional n)
7505 "Change the agenda view to SPAN.
7506 SPAN may be `day', `week', `month', `year'."
7507 (org-agenda-check-type t 'agenda)
7508 (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
7509 (curspan (nth 2 args)))
7510 (if (and (not n) (equal curspan span))
7511 (error "Viewing span is already \"%s\"" span))
7512 (let* ((sd (or (org-get-at-bol 'day)
7513 (nth 1 args)
7514 org-starting-day))
7515 (sd (org-agenda-compute-starting-span sd span n))
7516 (org-agenda-overriding-cmd
7517 (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
7518 (org-agenda-overriding-arguments
7519 (list (car args) sd span)))
7520 (org-agenda-redo)
7521 (org-agenda-find-same-or-today-or-agenda))
7522 (org-agenda-set-mode-name)
7523 (message "Switched to %s view" span)))
7525 (defun org-agenda-compute-starting-span (sd span &optional n)
7526 "Compute starting date for agenda.
7527 SPAN may be `day', `week', `month', `year'. The return value
7528 is a cons cell with the starting date and the number of days,
7529 so that the date SD will be in that range."
7530 (let* ((greg (calendar-gregorian-from-absolute sd))
7531 (dg (nth 1 greg))
7532 (mg (car greg))
7533 (yg (nth 2 greg)))
7534 (cond
7535 ((eq span 'day)
7536 (when n
7537 (setq sd (+ (calendar-absolute-from-gregorian
7538 (list mg 1 yg))
7539 n -1))))
7540 ((eq span 'week)
7541 (let* ((nt (calendar-day-of-week
7542 (calendar-gregorian-from-absolute sd)))
7543 (d (if org-agenda-start-on-weekday
7544 (- nt org-agenda-start-on-weekday)
7547 (setq sd (- sd (+ (if (< d 0) 7 0) d)))
7548 (when n
7549 (require 'cal-iso)
7550 (when (> n 99)
7551 (setq y1 (org-small-year-to-year (/ n 100))
7552 n (mod n 100)))
7553 (setq sd
7554 (calendar-absolute-from-iso
7555 (list n 1
7556 (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
7557 ((eq span 'month)
7558 (let (y1)
7559 (when (and n (> n 99))
7560 (setq y1 (org-small-year-to-year (/ n 100))
7561 n (mod n 100)))
7562 (setq sd (calendar-absolute-from-gregorian
7563 (list (or n mg) 1 (or y1 yg))))))
7564 ((eq span 'year)
7565 (setq sd (calendar-absolute-from-gregorian
7566 (list 1 1 (or n yg))))))
7567 sd))
7569 (defun org-agenda-next-date-line (&optional arg)
7570 "Jump to the next line indicating a date in agenda buffer."
7571 (interactive "p")
7572 (org-agenda-check-type t 'agenda 'timeline)
7573 (beginning-of-line 1)
7574 ;; This does not work if user makes date format that starts with a blank
7575 (if (looking-at "^\\S-") (forward-char 1))
7576 (if (not (re-search-forward "^\\S-" nil t arg))
7577 (progn
7578 (backward-char 1)
7579 (error "No next date after this line in this buffer")))
7580 (goto-char (match-beginning 0)))
7582 (defun org-agenda-previous-date-line (&optional arg)
7583 "Jump to the previous line indicating a date in agenda buffer."
7584 (interactive "p")
7585 (org-agenda-check-type t 'agenda 'timeline)
7586 (beginning-of-line 1)
7587 (if (not (re-search-backward "^\\S-" nil t arg))
7588 (error "No previous date before this line in this buffer")))
7590 ;; Initialize the highlight
7591 (defvar org-hl (make-overlay 1 1))
7592 (overlay-put org-hl 'face 'highlight)
7594 (defun org-highlight (begin end &optional buffer)
7595 "Highlight a region with overlay."
7596 (move-overlay org-hl begin end (or buffer (current-buffer))))
7598 (defun org-unhighlight ()
7599 "Detach overlay INDEX."
7600 (org-detach-overlay org-hl))
7602 (defun org-unhighlight-once ()
7603 "Remove the highlight from its position, and this function from the hook."
7604 (remove-hook 'pre-command-hook 'org-unhighlight-once)
7605 (org-unhighlight))
7607 (defvar org-agenda-pre-follow-window-conf nil)
7608 (defun org-agenda-follow-mode ()
7609 "Toggle follow mode in an agenda buffer."
7610 (interactive)
7611 (unless org-agenda-follow-mode
7612 (setq org-agenda-pre-follow-window-conf
7613 (current-window-configuration)))
7614 (setq org-agenda-follow-mode (not org-agenda-follow-mode))
7615 (unless org-agenda-follow-mode
7616 (set-window-configuration org-agenda-pre-follow-window-conf))
7617 (org-agenda-set-mode-name)
7618 (org-agenda-do-context-action)
7619 (message "Follow mode is %s"
7620 (if org-agenda-follow-mode "on" "off")))
7622 (defun org-agenda-entry-text-mode (&optional arg)
7623 "Toggle entry text mode in an agenda buffer."
7624 (interactive "P")
7625 (setq org-agenda-entry-text-mode (or (integerp arg)
7626 (not org-agenda-entry-text-mode)))
7627 (org-agenda-entry-text-hide)
7628 (and org-agenda-entry-text-mode
7629 (let ((org-agenda-entry-text-maxlines
7630 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7631 (org-agenda-entry-text-show)))
7632 (org-agenda-set-mode-name)
7633 (message "Entry text mode is %s. Maximum number of lines is %d"
7634 (if org-agenda-entry-text-mode "on" "off")
7635 (if (integerp arg) arg org-agenda-entry-text-maxlines)))
7637 (defun org-agenda-clockreport-mode (&optional with-filter)
7638 "Toggle clocktable mode in an agenda buffer.
7639 With prefix arg WITH-FILTER, make the clocktable respect the current
7640 agenda filter."
7641 (interactive "P")
7642 (org-agenda-check-type t 'agenda)
7643 (if with-filter
7644 (setq org-agenda-clockreport-mode 'with-filter)
7645 (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
7646 (org-agenda-set-mode-name)
7647 (org-agenda-redo)
7648 (message "Clocktable mode is %s"
7649 (if org-agenda-clockreport-mode "on" "off")))
7651 (defun org-agenda-log-mode (&optional special)
7652 "Toggle log mode in an agenda buffer.
7653 With argument SPECIAL, show all possible log items, not only the ones
7654 configured in `org-agenda-log-mode-items'.
7655 With a double `C-u' prefix arg, show *only* log items, nothing else."
7656 (interactive "P")
7657 (org-agenda-check-type t 'agenda 'timeline)
7658 (setq org-agenda-show-log
7659 (cond
7660 ((equal special '(16)) 'only)
7661 ((eq special 'clockcheck)
7662 (if (eq org-agenda-show-log 'clockcheck)
7663 nil 'clockcheck))
7664 (special '(closed clock state))
7665 (t (not org-agenda-show-log))))
7666 (org-agenda-set-mode-name)
7667 (org-agenda-redo)
7668 (message "Log mode is %s"
7669 (if org-agenda-show-log "on" "off")))
7671 (defun org-agenda-archives-mode (&optional with-files)
7672 "Toggle inclusion of items in trees marked with :ARCHIVE:.
7673 When called with a prefix argument, include all archive files as well."
7674 (interactive "P")
7675 (setq org-agenda-archives-mode
7676 (if with-files t (if org-agenda-archives-mode nil 'trees)))
7677 (org-agenda-set-mode-name)
7678 (org-agenda-redo)
7679 (message
7680 "%s"
7681 (cond
7682 ((eq org-agenda-archives-mode nil)
7683 "No archives are included")
7684 ((eq org-agenda-archives-mode 'trees)
7685 (format "Trees with :%s: tag are included" org-archive-tag))
7686 ((eq org-agenda-archives-mode t)
7687 (format "Trees with :%s: tag and all active archive files are included"
7688 org-archive-tag)))))
7690 (defun org-agenda-toggle-diary ()
7691 "Toggle diary inclusion in an agenda buffer."
7692 (interactive)
7693 (org-agenda-check-type t 'agenda)
7694 (setq org-agenda-include-diary (not org-agenda-include-diary))
7695 (org-agenda-redo)
7696 (org-agenda-set-mode-name)
7697 (message "Diary inclusion turned %s"
7698 (if org-agenda-include-diary "on" "off")))
7700 (defun org-agenda-toggle-deadlines ()
7701 "Toggle inclusion of entries with a deadline in an agenda buffer."
7702 (interactive)
7703 (org-agenda-check-type t 'agenda)
7704 (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
7705 (org-agenda-redo)
7706 (org-agenda-set-mode-name)
7707 (message "Deadlines inclusion turned %s"
7708 (if org-agenda-include-deadlines "on" "off")))
7710 (defun org-agenda-toggle-time-grid ()
7711 "Toggle time grid in an agenda buffer."
7712 (interactive)
7713 (org-agenda-check-type t 'agenda)
7714 (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
7715 (org-agenda-redo)
7716 (org-agenda-set-mode-name)
7717 (message "Time-grid turned %s"
7718 (if org-agenda-use-time-grid "on" "off")))
7720 (defun org-agenda-set-mode-name ()
7721 "Set the mode name to indicate all the small mode settings."
7722 (setq mode-name
7723 (list "Org-Agenda"
7724 (if (get 'org-agenda-files 'org-restrict) " []" "")
7726 '(:eval (org-agenda-span-name org-agenda-current-span))
7727 (if org-agenda-follow-mode " Follow" "")
7728 (if org-agenda-entry-text-mode " ETxt" "")
7729 (if org-agenda-include-diary " Diary" "")
7730 (if org-agenda-include-deadlines " Ddl" "")
7731 (if org-agenda-use-time-grid " Grid" "")
7732 (if (and (boundp 'org-habit-show-habits)
7733 org-habit-show-habits) " Habit" "")
7734 (cond
7735 ((consp org-agenda-show-log) " LogAll")
7736 ((eq org-agenda-show-log 'clockcheck) " ClkCk")
7737 (org-agenda-show-log " Log")
7738 (t ""))
7739 (if (or org-agenda-category-filter (get 'org-agenda-category-filter
7740 :preset-filter))
7741 '(:eval (org-propertize
7742 (concat " <"
7743 (mapconcat
7744 'identity
7745 (append
7746 (get 'org-agenda-category-filter :preset-filter)
7747 org-agenda-category-filter)
7749 ">")
7750 'face 'org-agenda-filter-category
7751 'help-echo "Category used in filtering"))
7753 (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
7754 :preset-filter))
7755 '(:eval (org-propertize
7756 (concat " {"
7757 (mapconcat
7758 'identity
7759 (append
7760 (get 'org-agenda-tag-filter :preset-filter)
7761 org-agenda-tag-filter)
7763 "}")
7764 'face 'org-agenda-filter-tags
7765 'help-echo "Tags used in filtering"))
7767 (if org-agenda-archives-mode
7768 (if (eq org-agenda-archives-mode t)
7769 " Archives"
7770 (format " :%s:" org-archive-tag))
7772 (if org-agenda-clockreport-mode
7773 (if (eq org-agenda-clockreport-mode 'with-filter)
7774 " Clock{}" " Clock")
7775 "")))
7776 (force-mode-line-update))
7778 (define-obsolete-function-alias
7779 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
7781 (defun org-agenda-update-agenda-type ()
7782 "Update the agenda type after each command."
7783 (setq org-agenda-type
7784 (or (get-text-property (point) 'org-agenda-type)
7785 (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
7787 (defun org-agenda-next-line ()
7788 "Move cursor to the next line, and show if follow mode is active."
7789 (interactive)
7790 (call-interactively 'next-line)
7791 (org-agenda-do-context-action))
7793 (defun org-agenda-previous-line ()
7794 "Move cursor to the previous line, and show if follow-mode is active."
7795 (interactive)
7796 (call-interactively 'previous-line)
7797 (org-agenda-do-context-action))
7799 (defun org-agenda-next-item (n)
7800 "Move cursor to next agenda item."
7801 (interactive "p")
7802 (let ((col (current-column)))
7803 (dotimes (c n)
7804 (when (next-single-property-change (point-at-eol) 'org-marker)
7805 (move-end-of-line 1)
7806 (goto-char (next-single-property-change (point) 'org-marker))))
7807 (org-move-to-column col))
7808 (org-agenda-do-context-action))
7810 (defun org-agenda-previous-item (n)
7811 "Move cursor to next agenda item."
7812 (interactive "p")
7813 (dotimes (c n)
7814 (let ((col (current-column))
7815 (goto (save-excursion
7816 (move-end-of-line 0)
7817 (previous-single-property-change (point) 'org-marker))))
7818 (if goto (goto-char goto))
7819 (org-move-to-column col)))
7820 (org-agenda-do-context-action))
7822 (defun org-agenda-do-context-action ()
7823 "Show outline path and, maybe, follow mode window."
7824 (let ((m (org-get-at-bol 'org-marker)))
7825 (when (and (markerp m) (marker-buffer m))
7826 (and org-agenda-follow-mode
7827 (if org-agenda-follow-indirect
7828 (org-agenda-tree-to-indirect-buffer nil)
7829 (org-agenda-show)))
7830 (and org-agenda-show-outline-path
7831 (org-with-point-at m (org-display-outline-path t))))))
7833 (defun org-agenda-show-tags ()
7834 "Show the tags applicable to the current item."
7835 (interactive)
7836 (let* ((tags (org-get-at-bol 'tags)))
7837 (if tags
7838 (message "Tags are :%s:"
7839 (org-no-properties (mapconcat 'identity tags ":")))
7840 (message "No tags associated with this line"))))
7842 (defun org-agenda-goto (&optional highlight)
7843 "Go to the Org-mode file which contains the item at point."
7844 (interactive)
7845 (let* ((marker (or (org-get-at-bol 'org-marker)
7846 (org-agenda-error)))
7847 (buffer (marker-buffer marker))
7848 (pos (marker-position marker)))
7849 (switch-to-buffer-other-window buffer)
7850 (widen)
7851 (push-mark)
7852 (goto-char pos)
7853 (when (derived-mode-p 'org-mode)
7854 (org-show-context 'agenda)
7855 (save-excursion
7856 (and (outline-next-heading)
7857 (org-flag-heading nil)))) ; show the next heading
7858 (when (outline-invisible-p)
7859 (show-entry)) ; display invisible text
7860 (recenter (/ (window-height) 2))
7861 (run-hooks 'org-agenda-after-show-hook)
7862 (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
7864 (defvar org-agenda-after-show-hook nil
7865 "Normal hook run after an item has been shown from the agenda.
7866 Point is in the buffer where the item originated.")
7868 (defun org-agenda-kill ()
7869 "Kill the entry or subtree belonging to the current agenda entry."
7870 (interactive)
7871 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7872 (let* ((bufname-orig (buffer-name))
7873 (marker (or (org-get-at-bol 'org-marker)
7874 (org-agenda-error)))
7875 (buffer (marker-buffer marker))
7876 (pos (marker-position marker))
7877 (type (org-get-at-bol 'type))
7878 dbeg dend (n 0) conf)
7879 (org-with-remote-undo buffer
7880 (with-current-buffer buffer
7881 (save-excursion
7882 (goto-char pos)
7883 (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
7884 (setq dbeg (progn (org-back-to-heading t) (point))
7885 dend (org-end-of-subtree t t))
7886 (setq dbeg (point-at-bol)
7887 dend (min (point-max) (1+ (point-at-eol)))))
7888 (goto-char dbeg)
7889 (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
7890 (setq conf (or (eq t org-agenda-confirm-kill)
7891 (and (numberp org-agenda-confirm-kill)
7892 (> n org-agenda-confirm-kill))))
7893 (and conf
7894 (not (y-or-n-p
7895 (format "Delete entry with %d lines in buffer \"%s\"? "
7896 n (buffer-name buffer))))
7897 (error "Abort"))
7898 (let ((org-agenda-buffer-name bufname-orig))
7899 (org-remove-subtree-entries-from-agenda buffer dbeg dend))
7900 (with-current-buffer buffer (delete-region dbeg dend))
7901 (message "Agenda item and source killed"))))
7903 (defvar org-archive-default-command) ; defined in org-archive.el
7904 (defun org-agenda-archive-default ()
7905 "Archive the entry or subtree belonging to the current agenda entry."
7906 (interactive)
7907 (require 'org-archive)
7908 (org-agenda-archive-with org-archive-default-command))
7910 (defun org-agenda-archive-default-with-confirmation ()
7911 "Archive the entry or subtree belonging to the current agenda entry."
7912 (interactive)
7913 (require 'org-archive)
7914 (org-agenda-archive-with org-archive-default-command 'confirm))
7916 (defun org-agenda-archive ()
7917 "Archive the entry or subtree belonging to the current agenda entry."
7918 (interactive)
7919 (org-agenda-archive-with 'org-archive-subtree))
7921 (defun org-agenda-archive-to-archive-sibling ()
7922 "Move the entry to the archive sibling."
7923 (interactive)
7924 (org-agenda-archive-with 'org-archive-to-archive-sibling))
7926 (defun org-agenda-archive-with (cmd &optional confirm)
7927 "Move the entry to the archive sibling."
7928 (interactive)
7929 (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
7930 (let* ((bufname-orig (buffer-name))
7931 (marker (or (org-get-at-bol 'org-marker)
7932 (org-agenda-error)))
7933 (buffer (marker-buffer marker))
7934 (pos (marker-position marker)))
7935 (org-with-remote-undo buffer
7936 (with-current-buffer buffer
7937 (if (derived-mode-p 'org-mode)
7938 (if (and confirm
7939 (not (y-or-n-p "Archive this subtree or entry? ")))
7940 (error "Abort")
7941 (save-excursion
7942 (goto-char pos)
7943 (let ((org-agenda-buffer-name bufname-orig))
7944 (org-remove-subtree-entries-from-agenda))
7945 (org-back-to-heading t)
7946 (funcall cmd)))
7947 (error "Archiving works only in Org-mode files"))))))
7949 (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
7950 "Remove all lines in the agenda that correspond to a given subtree.
7951 The subtree is the one in buffer BUF, starting at BEG and ending at END.
7952 If this information is not given, the function uses the tree at point."
7953 (let ((buf (or buf (current-buffer))) m p)
7954 (save-excursion
7955 (unless (and beg end)
7956 (org-back-to-heading t)
7957 (setq beg (point))
7958 (org-end-of-subtree t)
7959 (setq end (point)))
7960 (set-buffer (get-buffer org-agenda-buffer-name))
7961 (save-excursion
7962 (goto-char (point-max))
7963 (beginning-of-line 1)
7964 (while (not (bobp))
7965 (when (and (setq m (org-get-at-bol 'org-marker))
7966 (equal buf (marker-buffer m))
7967 (setq p (marker-position m))
7968 (>= p beg)
7969 (< p end))
7970 (let ((inhibit-read-only t))
7971 (delete-region (point-at-bol) (1+ (point-at-eol)))))
7972 (beginning-of-line 0))))))
7974 (defun org-agenda-refile (&optional goto rfloc no-update)
7975 "Refile the item at point."
7976 (interactive "P")
7977 (if (equal goto '(16))
7978 (org-refile-goto-last-stored)
7979 (let* ((buffer-orig (buffer-name))
7980 (marker (or (org-get-at-bol 'org-hd-marker)
7981 (org-agenda-error)))
7982 (buffer (marker-buffer marker))
7983 (pos (marker-position marker))
7984 (rfloc (or rfloc
7985 (org-refile-get-location
7986 (if goto "Goto" "Refile to") buffer
7987 org-refile-allow-creating-parent-nodes))))
7988 (with-current-buffer buffer
7989 (save-excursion
7990 (save-restriction
7991 (widen)
7992 (goto-char marker)
7993 (let ((org-agenda-buffer-name buffer-orig))
7994 (org-remove-subtree-entries-from-agenda))
7995 (org-refile goto buffer rfloc)))))
7996 (unless no-update (org-agenda-redo))))
7998 (defun org-agenda-open-link (&optional arg)
7999 "Open the link(s) in the current entry, if any.
8000 This looks for a link in the displayed line in the agenda.
8001 It also looks at the text of the entry itself."
8002 (interactive "P")
8003 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
8004 (org-get-at-bol 'org-marker)))
8005 (buffer (and marker (marker-buffer marker)))
8006 (prefix (buffer-substring
8007 (point-at-bol) (point-at-eol)))
8008 (lkall (org-offer-links-in-entry buffer marker arg prefix))
8009 (lk (car lkall))
8010 (lkend (cdr lkall))
8011 trg)
8012 (cond
8013 ((and buffer (stringp lk))
8014 (with-current-buffer buffer
8015 (setq trg (and (string-match org-bracket-link-regexp lk)
8016 (match-string 1 lk)))
8017 (if (or (not trg) (string-match org-any-link-re trg))
8018 (save-excursion
8019 (save-restriction
8020 (widen)
8021 (goto-char marker)
8022 (when (search-forward lk nil lkend)
8023 (goto-char (match-beginning 0))
8024 (org-open-at-point))))
8025 ;; This is an internal link, widen the buffer
8026 (switch-to-buffer-other-window buffer)
8027 (widen)
8028 (goto-char marker)
8029 (when (search-forward lk nil lkend)
8030 (goto-char (match-beginning 0))
8031 (org-open-at-point)))))
8032 ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
8033 (save-excursion
8034 (beginning-of-line 1)
8035 (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
8036 (org-open-link-from-string (match-string 1)))
8037 (t (message "No link to open here")))))
8039 (defun org-agenda-copy-local-variable (var)
8040 "Get a variable from a referenced buffer and install it here."
8041 (let ((m (org-get-at-bol 'org-marker)))
8042 (when (and m (buffer-live-p (marker-buffer m)))
8043 (org-set-local var (with-current-buffer (marker-buffer m)
8044 (symbol-value var))))))
8046 (defun org-agenda-switch-to (&optional delete-other-windows)
8047 "Go to the Org-mode file which contains the item at point."
8048 (interactive)
8049 (if (and org-return-follows-link
8050 (not (org-get-at-bol 'org-marker))
8051 (org-in-regexp org-bracket-link-regexp))
8052 (org-open-link-from-string (match-string 0))
8053 (let* ((marker (or (org-get-at-bol 'org-marker)
8054 (org-agenda-error)))
8055 (buffer (marker-buffer marker))
8056 (pos (marker-position marker)))
8057 (org-pop-to-buffer-same-window buffer)
8058 (and delete-other-windows (delete-other-windows))
8059 (widen)
8060 (goto-char pos)
8061 (when (derived-mode-p 'org-mode)
8062 (org-show-context 'agenda)
8063 (save-excursion
8064 (and (outline-next-heading)
8065 (org-flag-heading nil))) ; show the next heading
8066 (when (outline-invisible-p)
8067 (show-entry)) ; display invisible text
8068 (run-hooks 'org-agenda-after-show-hook)))))
8070 (defun org-agenda-goto-mouse (ev)
8071 "Go to the Org-mode file which contains the item at the mouse click."
8072 (interactive "e")
8073 (mouse-set-point ev)
8074 (org-agenda-goto))
8076 (defun org-agenda-show (&optional full-entry)
8077 "Display the Org-mode file which contains the item at point.
8078 With prefix argument FULL-ENTRY, make the entire entry visible
8079 if it was hidden in the outline."
8080 (interactive "P")
8081 (let ((win (selected-window)))
8082 (if full-entry
8083 (let ((org-show-entry-below t))
8084 (org-agenda-goto t))
8085 (org-agenda-goto t))
8086 (select-window win)))
8088 (defvar org-agenda-show-window nil)
8089 (defun org-agenda-show-and-scroll-up (&optional arg)
8090 "Display the Org-mode file which contains the item at point.
8091 When called repeatedly, scroll the window that is displaying the buffer.
8092 With a \\[universal-argument] prefix, use `org-show-entry' instead of
8093 `show-subtree' to display the item, so that drawers and logbooks stay
8094 folded."
8095 (interactive "P")
8096 (let ((win (selected-window)))
8097 (if (and (window-live-p org-agenda-show-window)
8098 (eq this-command last-command))
8099 (progn
8100 (select-window org-agenda-show-window)
8101 (ignore-errors (scroll-up)))
8102 (org-agenda-goto t)
8103 (if arg (org-show-entry) (show-subtree))
8104 (setq org-agenda-show-window (selected-window)))
8105 (select-window win)))
8107 (defun org-agenda-show-scroll-down ()
8108 "Scroll down the window showing the agenda."
8109 (interactive)
8110 (let ((win (selected-window)))
8111 (when (window-live-p org-agenda-show-window)
8112 (select-window org-agenda-show-window)
8113 (ignore-errors (scroll-down))
8114 (select-window win))))
8116 (defun org-agenda-show-1 (&optional more)
8117 "Display the Org-mode file which contains the item at point.
8118 The prefix arg selects the amount of information to display:
8120 0 hide the subtree
8121 1 just show the entry according to defaults.
8122 2 show the children view
8123 3 show the subtree view
8124 4 show the entire subtree and any LOGBOOK drawers
8125 5 show the entire subtree and any drawers
8126 With prefix argument FULL-ENTRY, make the entire entry visible
8127 if it was hidden in the outline."
8128 (interactive "p")
8129 (let ((win (selected-window)))
8130 (org-agenda-goto t)
8131 (org-recenter-heading 1)
8132 (cond
8133 ((= more 0)
8134 (hide-subtree)
8135 (save-excursion
8136 (org-back-to-heading)
8137 (run-hook-with-args 'org-cycle-hook 'folded))
8138 (message "Remote: FOLDED"))
8139 ((and (org-called-interactively-p 'any) (= more 1))
8140 (message "Remote: show with default settings"))
8141 ((= more 2)
8142 (show-entry)
8143 (show-children)
8144 (save-excursion
8145 (org-back-to-heading)
8146 (run-hook-with-args 'org-cycle-hook 'children))
8147 (message "Remote: CHILDREN"))
8148 ((= more 3)
8149 (show-subtree)
8150 (save-excursion
8151 (org-back-to-heading)
8152 (run-hook-with-args 'org-cycle-hook 'subtree))
8153 (message "Remote: SUBTREE"))
8154 ((= more 4)
8155 (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
8156 (org-drawer-regexp
8157 (concat "^[ \t]*:\\("
8158 (mapconcat 'regexp-quote org-drawers "\\|")
8159 "\\):[ \t]*$")))
8160 (show-subtree)
8161 (save-excursion
8162 (org-back-to-heading)
8163 (org-cycle-hide-drawers 'subtree)))
8164 (message "Remote: SUBTREE AND LOGBOOK"))
8165 ((> more 4)
8166 (show-subtree)
8167 (message "Remote: SUBTREE AND ALL DRAWERS")))
8168 (select-window win)))
8170 (defun org-recenter-heading (n)
8171 (save-excursion
8172 (org-back-to-heading)
8173 (recenter n)))
8175 (defvar org-agenda-cycle-counter nil)
8176 (defun org-agenda-cycle-show (&optional n)
8177 "Show the current entry in another window, with default settings.
8178 Default settings are taken from `org-show-hierarchy-above' and siblings.
8179 When use repeatedly in immediate succession, the remote entry will cycle
8180 through visibility
8182 children -> subtree -> folded
8184 When called with a numeric prefix arg, that arg will be passed through to
8185 `org-agenda-show-1'. For the interpretation of that argument, see the
8186 docstring of `org-agenda-show-1'."
8187 (interactive "P")
8188 (if (integerp n)
8189 (setq org-agenda-cycle-counter n)
8190 (if (not (eq last-command this-command))
8191 (setq org-agenda-cycle-counter 1)
8192 (if (equal org-agenda-cycle-counter 0)
8193 (setq org-agenda-cycle-counter 2)
8194 (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
8195 (if (> org-agenda-cycle-counter 3)
8196 (setq org-agenda-cycle-counter 0)))))
8197 (org-agenda-show-1 org-agenda-cycle-counter))
8199 (defun org-agenda-recenter (arg)
8200 "Display the Org-mode file which contains the item at point and recenter."
8201 (interactive "P")
8202 (let ((win (selected-window)))
8203 (org-agenda-goto t)
8204 (recenter arg)
8205 (select-window win)))
8207 (defun org-agenda-show-mouse (ev)
8208 "Display the Org-mode file which contains the item at the mouse click."
8209 (interactive "e")
8210 (mouse-set-point ev)
8211 (org-agenda-show))
8213 (defun org-agenda-check-no-diary ()
8214 "Check if the entry is a diary link and abort if yes."
8215 (if (org-get-at-bol 'org-agenda-diary-link)
8216 (org-agenda-error)))
8218 (defun org-agenda-error ()
8219 (error "Command not allowed in this line"))
8221 (defun org-agenda-tree-to-indirect-buffer (arg)
8222 "Show the subtree corresponding to the current entry in an indirect buffer.
8223 This calls the command `org-tree-to-indirect-buffer' from the original buffer.
8225 With a numerical prefix ARG, go up to this level and then take that tree.
8226 With a negative numeric ARG, go up by this number of levels.
8227 With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
8228 use the dedicated frame)."
8229 (interactive "P")
8230 (if current-prefix-arg
8231 (org-agenda-do-tree-to-indirect-buffer arg)
8232 (let ((agenda-buffer (buffer-name))
8233 (agenda-window (selected-window))
8234 (indirect-window
8235 (and org-last-indirect-buffer
8236 (get-buffer-window org-last-indirect-buffer))))
8237 (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
8238 (unless (or (eq org-indirect-buffer-display 'new-frame)
8239 (eq org-indirect-buffer-display 'dedicated-frame))
8240 (unwind-protect
8241 (unless (and indirect-window (window-live-p indirect-window))
8242 (setq indirect-window (split-window agenda-window)))
8243 (and indirect-window (select-window indirect-window))
8244 (switch-to-buffer org-last-indirect-buffer :norecord)
8245 (fit-window-to-buffer indirect-window)))
8246 (select-window (get-buffer-window agenda-buffer)))))
8248 (defun org-agenda-do-tree-to-indirect-buffer (arg)
8249 "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
8250 (org-agenda-check-no-diary)
8251 (let* ((marker (or (org-get-at-bol 'org-marker)
8252 (org-agenda-error)))
8253 (buffer (marker-buffer marker))
8254 (pos (marker-position marker)))
8255 (with-current-buffer buffer
8256 (save-excursion
8257 (goto-char pos)
8258 (funcall 'org-tree-to-indirect-buffer arg)))))
8260 (defvar org-last-heading-marker (make-marker)
8261 "Marker pointing to the headline that last changed its TODO state
8262 by a remote command from the agenda.")
8264 (defun org-agenda-todo-nextset ()
8265 "Switch TODO entry to next sequence."
8266 (interactive)
8267 (org-agenda-todo 'nextset))
8269 (defun org-agenda-todo-previousset ()
8270 "Switch TODO entry to previous sequence."
8271 (interactive)
8272 (org-agenda-todo 'previousset))
8274 (defun org-agenda-todo (&optional arg)
8275 "Cycle TODO state of line at point, also in Org-mode file.
8276 This changes the line at point, all other lines in the agenda referring to
8277 the same tree node, and the headline of the tree node in the Org-mode file."
8278 (interactive "P")
8279 (org-agenda-check-no-diary)
8280 (let* ((col (current-column))
8281 (marker (or (org-get-at-bol 'org-marker)
8282 (org-agenda-error)))
8283 (buffer (marker-buffer marker))
8284 (pos (marker-position marker))
8285 (hdmarker (org-get-at-bol 'org-hd-marker))
8286 (todayp (org-agenda-todayp (org-get-at-bol 'day)))
8287 (inhibit-read-only t)
8288 org-agenda-headline-snapshot-before-repeat newhead just-one)
8289 (org-with-remote-undo buffer
8290 (with-current-buffer buffer
8291 (widen)
8292 (goto-char pos)
8293 (org-show-context 'agenda)
8294 (save-excursion
8295 (and (outline-next-heading)
8296 (org-flag-heading nil))) ; show the next heading
8297 (let ((current-prefix-arg arg))
8298 (call-interactively 'org-todo))
8299 (and (bolp) (forward-char 1))
8300 (setq newhead (org-get-heading))
8301 (when (and (org-bound-and-true-p
8302 org-agenda-headline-snapshot-before-repeat)
8303 (not (equal org-agenda-headline-snapshot-before-repeat
8304 newhead))
8305 todayp)
8306 (setq newhead org-agenda-headline-snapshot-before-repeat
8307 just-one t))
8308 (save-excursion
8309 (org-back-to-heading)
8310 (move-marker org-last-heading-marker (point))))
8311 (beginning-of-line 1)
8312 (save-excursion
8313 (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
8314 (org-move-to-column col))))
8316 (defun org-agenda-add-note (&optional arg)
8317 "Add a time-stamped note to the entry at point."
8318 (interactive "P")
8319 (org-agenda-check-no-diary)
8320 (let* ((marker (or (org-get-at-bol 'org-marker)
8321 (org-agenda-error)))
8322 (buffer (marker-buffer marker))
8323 (pos (marker-position marker))
8324 (hdmarker (org-get-at-bol 'org-hd-marker))
8325 (inhibit-read-only t))
8326 (with-current-buffer buffer
8327 (widen)
8328 (goto-char pos)
8329 (org-show-context 'agenda)
8330 (save-excursion
8331 (and (outline-next-heading)
8332 (org-flag-heading nil))) ; show the next heading
8333 (org-add-note))))
8335 (defun org-agenda-change-all-lines (newhead hdmarker
8336 &optional fixface just-this)
8337 "Change all lines in the agenda buffer which match HDMARKER.
8338 The new content of the line will be NEWHEAD (as modified by
8339 `org-agenda-format-item'). HDMARKER is checked with
8340 `equal' against all `org-hd-marker' text properties in the file.
8341 If FIXFACE is non-nil, the face of each item is modified according to
8342 the new TODO state.
8343 If JUST-THIS is non-nil, change just the current line, not all.
8344 If FORCE-TAGS is non nil, the car of it returns the new tags."
8345 (let* ((inhibit-read-only t)
8346 (line (org-current-line))
8347 (org-agenda-buffer (current-buffer))
8348 (thetags (with-current-buffer (marker-buffer hdmarker)
8349 (save-excursion (save-restriction (widen)
8350 (goto-char hdmarker)
8351 (org-get-tags-at)))))
8352 props m pl undone-face done-face finish new dotime level cat tags)
8353 (save-excursion
8354 (goto-char (point-max))
8355 (beginning-of-line 1)
8356 (while (not finish)
8357 (setq finish (bobp))
8358 (when (and (setq m (org-get-at-bol 'org-hd-marker))
8359 (or (not just-this) (= (org-current-line) line))
8360 (equal m hdmarker))
8361 (setq props (text-properties-at (point))
8362 dotime (org-get-at-bol 'dotime)
8363 cat (org-get-at-bol 'org-category)
8364 level (org-get-at-bol 'level)
8365 tags thetags
8367 (let ((org-prefix-format-compiled
8368 (or (get-text-property (min (1- (point-max)) (point)) 'format)
8369 org-prefix-format-compiled))
8370 (extra (org-get-at-bol 'extra)))
8371 (with-current-buffer (marker-buffer hdmarker)
8372 (save-excursion
8373 (save-restriction
8374 (widen)
8375 (org-agenda-format-item extra newhead level cat tags dotime)))))
8376 pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
8377 undone-face (org-get-at-bol 'undone-face)
8378 done-face (org-get-at-bol 'done-face))
8379 (beginning-of-line 1)
8380 (cond
8381 ((equal new "")
8382 (and (looking-at ".*\n?") (replace-match "")))
8383 ((looking-at ".*")
8384 (replace-match new t t)
8385 (beginning-of-line 1)
8386 (add-text-properties (point-at-bol) (point-at-eol) props)
8387 (when fixface
8388 (add-text-properties
8389 (point-at-bol) (point-at-eol)
8390 (list 'face
8391 (if org-last-todo-state-is-todo
8392 undone-face done-face))))
8393 (org-agenda-highlight-todo 'line)
8394 (beginning-of-line 1))
8395 (t (error "Line update did not work")))
8396 (save-restriction
8397 (narrow-to-region (point-at-bol) (point-at-eol))
8398 (org-agenda-finalize)))
8399 (beginning-of-line 0)))))
8401 (defun org-agenda-align-tags (&optional line)
8402 "Align all tags in agenda items to `org-agenda-tags-column'."
8403 (let ((inhibit-read-only t) l c)
8404 (save-excursion
8405 (goto-char (if line (point-at-bol) (point-min)))
8406 (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
8407 (if line (point-at-eol) nil) t)
8408 (add-text-properties
8409 (match-beginning 2) (match-end 2)
8410 (list 'face (delq nil (let ((prop (get-text-property
8411 (match-beginning 2) 'face)))
8412 (or (listp prop) (setq prop (list prop)))
8413 (if (memq 'org-tag prop)
8414 prop
8415 (cons 'org-tag prop))))))
8416 (setq l (- (match-end 2) (match-beginning 2))
8417 c (if (< org-agenda-tags-column 0)
8418 (- (abs org-agenda-tags-column) l)
8419 org-agenda-tags-column))
8420 (delete-region (match-beginning 1) (match-end 1))
8421 (goto-char (match-beginning 1))
8422 (insert (org-add-props
8423 (make-string (max 1 (- c (current-column))) ?\ )
8424 (plist-put (copy-sequence (text-properties-at (point)))
8425 'face nil))))
8426 (goto-char (point-min))
8427 (org-font-lock-add-tag-faces (point-max)))))
8429 (defun org-agenda-priority-up ()
8430 "Increase the priority of line at point, also in Org-mode file."
8431 (interactive)
8432 (org-agenda-priority 'up))
8434 (defun org-agenda-priority-down ()
8435 "Decrease the priority of line at point, also in Org-mode file."
8436 (interactive)
8437 (org-agenda-priority 'down))
8439 (defun org-agenda-priority (&optional force-direction)
8440 "Set the priority of line at point, also in Org-mode file.
8441 This changes the line at point, all other lines in the agenda referring to
8442 the same tree node, and the headline of the tree node in the Org-mode file.
8443 Called with a universal prefix arg, show the priority instead of setting it."
8444 (interactive "P")
8445 (if (equal force-direction '(4))
8446 (org-show-priority)
8447 (unless org-enable-priority-commands
8448 (error "Priority commands are disabled"))
8449 (org-agenda-check-no-diary)
8450 (let* ((marker (or (org-get-at-bol 'org-marker)
8451 (org-agenda-error)))
8452 (hdmarker (org-get-at-bol 'org-hd-marker))
8453 (buffer (marker-buffer hdmarker))
8454 (pos (marker-position hdmarker))
8455 (inhibit-read-only t)
8456 newhead)
8457 (org-with-remote-undo buffer
8458 (with-current-buffer buffer
8459 (widen)
8460 (goto-char pos)
8461 (org-show-context 'agenda)
8462 (save-excursion
8463 (and (outline-next-heading)
8464 (org-flag-heading nil))) ; show the next heading
8465 (funcall 'org-priority force-direction)
8466 (end-of-line 1)
8467 (setq newhead (org-get-heading)))
8468 (org-agenda-change-all-lines newhead hdmarker)
8469 (beginning-of-line 1)))))
8471 ;; FIXME: should fix the tags property of the agenda line.
8472 (defun org-agenda-set-tags (&optional tag onoff)
8473 "Set tags for the current headline."
8474 (interactive)
8475 (org-agenda-check-no-diary)
8476 (if (and (org-region-active-p) (org-called-interactively-p 'any))
8477 (call-interactively 'org-change-tag-in-region)
8478 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8479 (org-agenda-error)))
8480 (buffer (marker-buffer hdmarker))
8481 (pos (marker-position hdmarker))
8482 (inhibit-read-only t)
8483 newhead)
8484 (org-with-remote-undo buffer
8485 (with-current-buffer buffer
8486 (widen)
8487 (goto-char pos)
8488 (save-excursion
8489 (org-show-context 'agenda))
8490 (save-excursion
8491 (and (outline-next-heading)
8492 (org-flag-heading nil))) ; show the next heading
8493 (goto-char pos)
8494 (if tag
8495 (org-toggle-tag tag onoff)
8496 (call-interactively 'org-set-tags))
8497 (end-of-line 1)
8498 (setq newhead (org-get-heading)))
8499 (org-agenda-change-all-lines newhead hdmarker)
8500 (beginning-of-line 1)))))
8502 (defun org-agenda-set-property ()
8503 "Set a property for the current headline."
8504 (interactive)
8505 (org-agenda-check-no-diary)
8506 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8507 (org-agenda-error)))
8508 (buffer (marker-buffer hdmarker))
8509 (pos (marker-position hdmarker))
8510 (inhibit-read-only t)
8511 newhead)
8512 (org-with-remote-undo buffer
8513 (with-current-buffer buffer
8514 (widen)
8515 (goto-char pos)
8516 (save-excursion
8517 (org-show-context 'agenda))
8518 (save-excursion
8519 (and (outline-next-heading)
8520 (org-flag-heading nil))) ; show the next heading
8521 (goto-char pos)
8522 (call-interactively 'org-set-property)))))
8524 (defun org-agenda-set-effort ()
8525 "Set the effort property for the current headline."
8526 (interactive)
8527 (org-agenda-check-no-diary)
8528 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8529 (org-agenda-error)))
8530 (buffer (marker-buffer hdmarker))
8531 (pos (marker-position hdmarker))
8532 (inhibit-read-only t)
8533 newhead)
8534 (org-with-remote-undo buffer
8535 (with-current-buffer buffer
8536 (widen)
8537 (goto-char pos)
8538 (save-excursion
8539 (org-show-context 'agenda))
8540 (save-excursion
8541 (and (outline-next-heading)
8542 (org-flag-heading nil))) ; show the next heading
8543 (goto-char pos)
8544 (call-interactively 'org-set-effort)
8545 (end-of-line 1)
8546 (setq newhead (org-get-heading)))
8547 (org-agenda-change-all-lines newhead hdmarker))))
8549 (defun org-agenda-toggle-archive-tag ()
8550 "Toggle the archive tag for the current entry."
8551 (interactive)
8552 (org-agenda-check-no-diary)
8553 (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
8554 (org-agenda-error)))
8555 (buffer (marker-buffer hdmarker))
8556 (pos (marker-position hdmarker))
8557 (inhibit-read-only t)
8558 newhead)
8559 (org-with-remote-undo buffer
8560 (with-current-buffer buffer
8561 (widen)
8562 (goto-char pos)
8563 (org-show-context 'agenda)
8564 (save-excursion
8565 (and (outline-next-heading)
8566 (org-flag-heading nil))) ; show the next heading
8567 (call-interactively 'org-toggle-archive-tag)
8568 (end-of-line 1)
8569 (setq newhead (org-get-heading)))
8570 (org-agenda-change-all-lines newhead hdmarker)
8571 (beginning-of-line 1))))
8573 (defun org-agenda-do-date-later (arg)
8574 (interactive "P")
8575 (cond
8576 ((or (equal arg '(16))
8577 (memq last-command
8578 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8579 (setq this-command 'org-agenda-date-later-minutes)
8580 (org-agenda-date-later-minutes 1))
8581 ((or (equal arg '(4))
8582 (memq last-command
8583 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8584 (setq this-command 'org-agenda-date-later-hours)
8585 (org-agenda-date-later-hours 1))
8587 (org-agenda-date-later (prefix-numeric-value arg)))))
8589 (defun org-agenda-do-date-earlier (arg)
8590 (interactive "P")
8591 (cond
8592 ((or (equal arg '(16))
8593 (memq last-command
8594 '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
8595 (setq this-command 'org-agenda-date-earlier-minutes)
8596 (org-agenda-date-earlier-minutes 1))
8597 ((or (equal arg '(4))
8598 (memq last-command
8599 '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
8600 (setq this-command 'org-agenda-date-earlier-hours)
8601 (org-agenda-date-earlier-hours 1))
8603 (org-agenda-date-earlier (prefix-numeric-value arg)))))
8605 (defun org-agenda-date-later (arg &optional what)
8606 "Change the date of this item to ARG day(s) later."
8607 (interactive "p")
8608 (org-agenda-check-type t 'agenda 'timeline)
8609 (org-agenda-check-no-diary)
8610 (let* ((marker (or (org-get-at-bol 'org-marker)
8611 (org-agenda-error)))
8612 (buffer (marker-buffer marker))
8613 (pos (marker-position marker))
8614 cdate today)
8615 (org-with-remote-undo buffer
8616 (with-current-buffer buffer
8617 (widen)
8618 (goto-char pos)
8619 (if (not (org-at-timestamp-p))
8620 (error "Cannot find time stamp"))
8621 (when (and org-agenda-move-date-from-past-immediately-to-today
8622 (equal arg 1)
8623 (or (not what) (eq what 'day))
8624 (not (save-match-data (org-at-date-range-p))))
8625 (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
8626 cdate (calendar-absolute-from-gregorian
8627 (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
8628 today (org-today))
8629 (if (> today cdate)
8630 ;; immediately shift to today
8631 (setq arg (- today cdate))))
8632 (org-timestamp-change arg (or what 'day))
8633 (when (and (org-at-date-range-p)
8634 (re-search-backward org-tr-regexp-both (point-at-bol)))
8635 (let ((end org-last-changed-timestamp))
8636 (org-timestamp-change arg (or what 'day))
8637 (setq org-last-changed-timestamp
8638 (concat org-last-changed-timestamp "--" end)))))
8639 (org-agenda-show-new-time marker org-last-changed-timestamp))
8640 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8642 (defun org-agenda-date-earlier (arg &optional what)
8643 "Change the date of this item to ARG day(s) earlier."
8644 (interactive "p")
8645 (org-agenda-date-later (- arg) what))
8647 (defun org-agenda-date-later-minutes (arg)
8648 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8649 (interactive "p")
8650 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8651 (org-agenda-date-later arg 'minute))
8653 (defun org-agenda-date-earlier-minutes (arg)
8654 "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
8655 (interactive "p")
8656 (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
8657 (org-agenda-date-earlier arg 'minute))
8659 (defun org-agenda-date-later-hours (arg)
8660 "Change the time of this item, in hour steps."
8661 (interactive "p")
8662 (org-agenda-date-later arg 'hour))
8664 (defun org-agenda-date-earlier-hours (arg)
8665 "Change the time of this item, in hour steps."
8666 (interactive "p")
8667 (org-agenda-date-earlier arg 'hour))
8669 (defun org-agenda-show-new-time (marker stamp &optional prefix)
8670 "Show new date stamp via text properties."
8671 ;; We use text properties to make this undoable
8672 (let ((inhibit-read-only t)
8673 (buffer-invisibility-spec))
8674 (setq stamp (concat " " prefix " => " stamp))
8675 (save-excursion
8676 (goto-char (point-max))
8677 (while (not (bobp))
8678 (when (equal marker (org-get-at-bol 'org-marker))
8679 (org-move-to-column (- (window-width) (length stamp)) t)
8680 (org-agenda-fix-tags-filter-overlays-at (point))
8681 (if (featurep 'xemacs)
8682 ;; Use `duplicable' property to trigger undo recording
8683 (let ((ex (make-extent nil nil))
8684 (gl (make-glyph stamp)))
8685 (set-glyph-face gl 'secondary-selection)
8686 (set-extent-properties
8687 ex (list 'invisible t 'end-glyph gl 'duplicable t))
8688 (insert-extent ex (1- (point)) (point-at-eol)))
8689 (add-text-properties
8690 (1- (point)) (point-at-eol)
8691 (list 'display (org-add-props stamp nil
8692 'face 'secondary-selection))))
8693 (beginning-of-line 1))
8694 (beginning-of-line 0)))))
8696 (defun org-agenda-date-prompt (arg)
8697 "Change the date of this item. Date is prompted for, with default today.
8698 The prefix ARG is passed to the `org-time-stamp' command and can therefore
8699 be used to request time specification in the time stamp."
8700 (interactive "P")
8701 (org-agenda-check-type t 'agenda 'timeline)
8702 (org-agenda-check-no-diary)
8703 (let* ((marker (or (org-get-at-bol 'org-marker)
8704 (org-agenda-error)))
8705 (buffer (marker-buffer marker))
8706 (pos (marker-position marker)))
8707 (org-with-remote-undo buffer
8708 (with-current-buffer buffer
8709 (widen)
8710 (goto-char pos)
8711 (if (not (org-at-timestamp-p t))
8712 (error "Cannot find time stamp"))
8713 (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
8714 (org-agenda-show-new-time marker org-last-changed-timestamp))
8715 (message "Time stamp changed to %s" org-last-changed-timestamp)))
8717 (defun org-agenda-schedule (arg &optional time)
8718 "Schedule the item at point.
8719 ARG is passed through to `org-schedule'."
8720 (interactive "P")
8721 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8722 (org-agenda-check-no-diary)
8723 (let* ((marker (or (org-get-at-bol 'org-marker)
8724 (org-agenda-error)))
8725 (type (marker-insertion-type marker))
8726 (buffer (marker-buffer marker))
8727 (pos (marker-position marker))
8728 (org-insert-labeled-timestamps-at-point nil)
8730 (set-marker-insertion-type marker t)
8731 (org-with-remote-undo buffer
8732 (with-current-buffer buffer
8733 (widen)
8734 (goto-char pos)
8735 (setq ts (org-schedule arg time)))
8736 (org-agenda-show-new-time marker ts "S"))
8737 (message "%s" ts)))
8739 (defun org-agenda-deadline (arg &optional time)
8740 "Schedule the item at point.
8741 ARG is passed through to `org-deadline'."
8742 (interactive "P")
8743 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
8744 (org-agenda-check-no-diary)
8745 (let* ((marker (or (org-get-at-bol 'org-marker)
8746 (org-agenda-error)))
8747 (buffer (marker-buffer marker))
8748 (pos (marker-position marker))
8749 (org-insert-labeled-timestamps-at-point nil)
8751 (org-with-remote-undo buffer
8752 (with-current-buffer buffer
8753 (widen)
8754 (goto-char pos)
8755 (setq ts (org-deadline arg time)))
8756 (org-agenda-show-new-time marker ts "D"))
8757 (message "%s" ts)))
8759 (defun org-agenda-clock-in (&optional arg)
8760 "Start the clock on the currently selected item."
8761 (interactive "P")
8762 (org-agenda-check-no-diary)
8763 (if (equal arg '(4))
8764 (org-clock-in arg)
8765 (let* ((marker (or (org-get-at-bol 'org-marker)
8766 (org-agenda-error)))
8767 (hdmarker (or (org-get-at-bol 'org-hd-marker)
8768 marker))
8769 (pos (marker-position marker))
8770 newhead)
8771 (org-with-remote-undo (marker-buffer marker)
8772 (with-current-buffer (marker-buffer marker)
8773 (widen)
8774 (goto-char pos)
8775 (org-show-context 'agenda)
8776 (org-show-entry)
8777 (org-cycle-hide-drawers 'children)
8778 (org-clock-in arg)
8779 (setq newhead (org-get-heading)))
8780 (org-agenda-change-all-lines newhead hdmarker)))))
8782 (defun org-agenda-clock-out ()
8783 "Stop the currently running clock."
8784 (interactive)
8785 (unless (marker-buffer org-clock-marker)
8786 (error "No running clock"))
8787 (let ((marker (make-marker)) newhead)
8788 (org-with-remote-undo (marker-buffer org-clock-marker)
8789 (with-current-buffer (marker-buffer org-clock-marker)
8790 (save-excursion
8791 (save-restriction
8792 (widen)
8793 (goto-char org-clock-marker)
8794 (org-back-to-heading t)
8795 (move-marker marker (point))
8796 (org-clock-out)
8797 (setq newhead (org-get-heading))))))
8798 (org-agenda-change-all-lines newhead marker)
8799 (move-marker marker nil)))
8801 (defun org-agenda-clock-cancel (&optional arg)
8802 "Cancel the currently running clock."
8803 (interactive "P")
8804 (unless (marker-buffer org-clock-marker)
8805 (error "No running clock"))
8806 (org-with-remote-undo (marker-buffer org-clock-marker)
8807 (org-clock-cancel)))
8809 (defun org-agenda-clock-goto ()
8810 "Jump to the currently clocked in task within the agenda.
8811 If the currently clocked in task is not listed in the agenda
8812 buffer, display it in another window."
8813 (interactive)
8814 (let (pos)
8815 (mapc (lambda (o)
8816 (if (eq (overlay-get o 'type) 'org-agenda-clocking)
8817 (setq pos (overlay-start o))))
8818 (overlays-in (point-min) (point-max)))
8819 (cond (pos (goto-char pos))
8820 ;; If the currently clocked entry is not in the agenda
8821 ;; buffer, we visit it in another window:
8822 (org-clock-current-task
8823 (org-switch-to-buffer-other-window (org-clock-goto)))
8824 (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
8826 (defun org-agenda-diary-entry-in-org-file ()
8827 "Make a diary entry in the file `org-agenda-diary-file'."
8828 (let (d1 d2 char (text "") dp1 dp2)
8829 (if (equal (buffer-name) "*Calendar*")
8830 (setq d1 (calendar-cursor-to-date t)
8831 d2 (car calendar-mark-ring))
8832 (setq dp1 (get-text-property (point-at-bol) 'day))
8833 (unless dp1 (error "No date defined in current line"))
8834 (setq d1 (calendar-gregorian-from-absolute dp1)
8835 d2 (and (ignore-errors (mark))
8836 (save-excursion
8837 (goto-char (mark))
8838 (setq dp2 (get-text-property (point-at-bol) 'day)))
8839 (calendar-gregorian-from-absolute dp2))))
8840 (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
8841 (setq char (read-char-exclusive))
8842 (cond
8843 ((equal char ?d)
8844 (setq text (read-string "Day entry: "))
8845 (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
8846 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8847 ((equal char ?a)
8848 (setq d1 (list (car d1) (nth 1 d1)
8849 (read-number (format "Reference year [%d]: " (nth 2 d1))
8850 (nth 2 d1))))
8851 (setq text (read-string "Anniversary (use %d to show years): "))
8852 (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
8853 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8854 ((equal char ?b)
8855 (setq text (read-string "Block entry: "))
8856 (unless (and d1 d2 (not (equal d1 d2)))
8857 (error "No block of days selected"))
8858 (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
8859 (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
8860 ((equal char ?j)
8861 (org-switch-to-buffer-other-window
8862 (find-file-noselect org-agenda-diary-file))
8863 (require 'org-datetree)
8864 (org-datetree-find-date-create d1)
8865 (org-reveal t))
8866 (t (error "Invalid selection character `%c'" char)))))
8868 (defcustom org-agenda-insert-diary-strategy 'date-tree
8869 "Where in `org-agenda-diary-file' should new entries be added?
8870 Valid values:
8872 date-tree in the date tree, as child of the date
8873 top-level as top-level entries at the end of the file."
8874 :group 'org-agenda
8875 :type '(choice
8876 (const :tag "in a date tree" date-tree)
8877 (const :tag "as top level at end of file" top-level)))
8879 (defcustom org-agenda-insert-diary-extract-time nil
8880 "Non-nil means extract any time specification from the diary entry."
8881 :group 'org-agenda
8882 :version "24.1"
8883 :type 'boolean)
8885 (defcustom org-agenda-bulk-mark-char ">"
8886 "A single-character string to be used as the bulk mark."
8887 :group 'org-agenda
8888 :version "24.1"
8889 :type 'string)
8891 (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
8892 "Add a diary entry with TYPE to `org-agenda-diary-file'.
8893 If TEXT is not empty, it will become the headline of the new entry, and
8894 the resulting entry will not be shown. When TEXT is empty, switch to
8895 `org-agenda-diary-file' and let the user finish the entry there."
8896 (let ((cw (current-window-configuration)))
8897 (org-switch-to-buffer-other-window
8898 (find-file-noselect org-agenda-diary-file))
8899 (widen)
8900 (goto-char (point-min))
8901 (cond
8902 ((eq type 'anniversary)
8903 (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
8904 (progn
8905 (or (org-at-heading-p t)
8906 (progn
8907 (outline-next-heading)
8908 (insert "* Anniversaries\n\n")
8909 (beginning-of-line -1)))))
8910 (outline-next-heading)
8911 (org-back-over-empty-lines)
8912 (backward-char 1)
8913 (insert "\n")
8914 (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
8915 (nth 2 d1) (car d1) (nth 1 d1) text)))
8916 ((eq type 'day)
8917 (let ((org-prefix-has-time t)
8918 (org-agenda-time-leading-zero t)
8919 fmt time time2)
8920 (if org-agenda-insert-diary-extract-time
8921 ;; Use org-agenda-format-item to parse text for a time-range and
8922 ;; remove it. FIXME: This is a hack, we should refactor
8923 ;; that function to make time extraction available separately
8924 (setq fmt (org-agenda-format-item nil text nil nil nil t)
8925 time (get-text-property 0 'time fmt)
8926 time2 (if (> (length time) 0)
8927 ;; split-string removes trailing ...... if
8928 ;; no end time given. First space
8929 ;; separates time from date.
8930 (concat " " (car (split-string time "\\.")))
8931 nil)
8932 text (get-text-property 0 'txt fmt)))
8933 (if (eq org-agenda-insert-diary-strategy 'top-level)
8934 (org-agenda-insert-diary-as-top-level text)
8935 (require 'org-datetree)
8936 (org-datetree-find-date-create d1)
8937 (org-agenda-insert-diary-make-new-entry text))
8938 (org-insert-time-stamp (org-time-from-absolute
8939 (calendar-absolute-from-gregorian d1))
8940 nil nil nil nil time2))
8941 (end-of-line 0))
8942 ((eq type 'block)
8943 (if (> (calendar-absolute-from-gregorian d1)
8944 (calendar-absolute-from-gregorian d2))
8945 (setq d1 (prog1 d2 (setq d2 d1))))
8946 (if (eq org-agenda-insert-diary-strategy 'top-level)
8947 (org-agenda-insert-diary-as-top-level text)
8948 (require 'org-datetree)
8949 (org-datetree-find-date-create d1)
8950 (org-agenda-insert-diary-make-new-entry text))
8951 (org-insert-time-stamp (org-time-from-absolute
8952 (calendar-absolute-from-gregorian d1)))
8953 (insert "--")
8954 (org-insert-time-stamp (org-time-from-absolute
8955 (calendar-absolute-from-gregorian d2)))
8956 (end-of-line 0)))
8957 (if (string-match "\\S-" text)
8958 (progn
8959 (set-window-configuration cw)
8960 (message "%s entry added to %s"
8961 (capitalize (symbol-name type))
8962 (abbreviate-file-name org-agenda-diary-file)))
8963 (org-reveal t)
8964 (message "Please finish entry here"))))
8966 (defun org-agenda-insert-diary-as-top-level (text)
8967 "Make new entry as a top-level entry at the end of the file.
8968 Add TEXT as headline, and position the cursor in the second line so that
8969 a timestamp can be added there."
8970 (widen)
8971 (goto-char (point-max))
8972 (or (bolp) (insert "\n"))
8973 (insert "* " text "\n")
8974 (if org-adapt-indentation (org-indent-to-column 2)))
8976 (defun org-agenda-insert-diary-make-new-entry (text)
8977 "Make new entry as last child of current entry.
8978 Add TEXT as headline, and position the cursor in the second line so that
8979 a timestamp can be added there."
8980 (let ((org-show-following-heading t)
8981 (org-show-siblings t)
8982 (org-show-hierarchy-above t)
8983 (org-show-entry-below t)
8984 col)
8985 (outline-next-heading)
8986 (org-back-over-empty-lines)
8987 (or (looking-at "[ \t]*$")
8988 (progn (insert "\n") (backward-char 1)))
8989 (org-insert-heading nil t)
8990 (org-do-demote)
8991 (setq col (current-column))
8992 (insert text "\n")
8993 (if org-adapt-indentation (org-indent-to-column col))
8994 (let ((org-show-following-heading t)
8995 (org-show-siblings t)
8996 (org-show-hierarchy-above t)
8997 (org-show-entry-below t))
8998 (org-show-context))))
9000 (defun org-agenda-diary-entry ()
9001 "Make a diary entry, like the `i' command from the calendar.
9002 All the standard commands work: block, weekly etc.
9003 When `org-agenda-diary-file' points to a file,
9004 `org-agenda-diary-entry-in-org-file' is called instead to create
9005 entries in that Org-mode file."
9006 (interactive)
9007 (if (not (eq org-agenda-diary-file 'diary-file))
9008 (org-agenda-diary-entry-in-org-file)
9009 (require 'diary-lib)
9010 (let* ((char (progn
9011 (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
9012 (read-char-exclusive)))
9013 (cmd (cdr (assoc char
9014 '((?d . insert-diary-entry)
9015 (?w . insert-weekly-diary-entry)
9016 (?m . insert-monthly-diary-entry)
9017 (?y . insert-yearly-diary-entry)
9018 (?a . insert-anniversary-diary-entry)
9019 (?b . insert-block-diary-entry)
9020 (?c . insert-cyclic-diary-entry)))))
9021 (oldf (symbol-function 'calendar-cursor-to-date))
9022 ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
9023 (point (point))
9024 (mark (or (mark t) (point))))
9025 (unless cmd
9026 (error "No command associated with <%c>" char))
9027 (unless (and (get-text-property point 'day)
9028 (or (not (equal ?b char))
9029 (get-text-property mark 'day)))
9030 (error "Don't know which date to use for diary entry"))
9031 ;; We implement this by hacking the `calendar-cursor-to-date' function
9032 ;; and the `calendar-mark-ring' variable. Saves a lot of code.
9033 (let ((calendar-mark-ring
9034 (list (calendar-gregorian-from-absolute
9035 (or (get-text-property mark 'day)
9036 (get-text-property point 'day))))))
9037 (unwind-protect
9038 (progn
9039 (fset 'calendar-cursor-to-date
9040 (lambda (&optional error dummy)
9041 (calendar-gregorian-from-absolute
9042 (get-text-property point 'day))))
9043 (call-interactively cmd))
9044 (fset 'calendar-cursor-to-date oldf))))))
9046 (defun org-agenda-execute-calendar-command (cmd)
9047 "Execute a calendar command from the agenda with date from cursor."
9048 (org-agenda-check-type t 'agenda 'timeline)
9049 (require 'diary-lib)
9050 (unless (get-text-property (min (1- (point-max)) (point)) 'day)
9051 (error "Don't know which date to use for the calendar command"))
9052 (let* ((oldf (symbol-function 'calendar-cursor-to-date))
9053 (point (point))
9054 (date (calendar-gregorian-from-absolute
9055 (get-text-property point 'day)))
9056 ;; the following 2 vars are needed in the calendar
9057 (displayed-month (car date))
9058 (displayed-year (nth 2 date)))
9059 (unwind-protect
9060 (progn
9061 (fset 'calendar-cursor-to-date
9062 (lambda (&optional error dummy)
9063 (calendar-gregorian-from-absolute
9064 (get-text-property point 'day))))
9065 (call-interactively cmd))
9066 (fset 'calendar-cursor-to-date oldf))))
9068 (defun org-agenda-phases-of-moon ()
9069 "Display the phases of the moon for the 3 months around the cursor date."
9070 (interactive)
9071 (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
9073 (defun org-agenda-holidays ()
9074 "Display the holidays for the 3 months around the cursor date."
9075 (interactive)
9076 (org-agenda-execute-calendar-command 'list-calendar-holidays))
9078 (defvar calendar-longitude) ; defined in calendar.el
9079 (defvar calendar-latitude) ; defined in calendar.el
9080 (defvar calendar-location-name) ; defined in calendar.el
9082 (defun org-agenda-sunrise-sunset (arg)
9083 "Display sunrise and sunset for the cursor date.
9084 Latitude and longitude can be specified with the variables
9085 `calendar-latitude' and `calendar-longitude'. When called with prefix
9086 argument, latitude and longitude will be prompted for."
9087 (interactive "P")
9088 (require 'solar)
9089 (let ((calendar-longitude (if arg nil calendar-longitude))
9090 (calendar-latitude (if arg nil calendar-latitude))
9091 (calendar-location-name
9092 (if arg "the given coordinates" calendar-location-name)))
9093 (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
9095 (defun org-agenda-goto-calendar ()
9096 "Open the Emacs calendar with the date at the cursor."
9097 (interactive)
9098 (org-agenda-check-type t 'agenda 'timeline)
9099 (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
9100 (error "Don't know which date to open in calendar")))
9101 (date (calendar-gregorian-from-absolute day))
9102 (calendar-move-hook nil)
9103 (calendar-view-holidays-initially-flag nil)
9104 (calendar-view-diary-initially-flag nil))
9105 (calendar)
9106 (calendar-goto-date date)))
9108 ;;;###autoload
9109 (defun org-calendar-goto-agenda ()
9110 "Compute the Org-mode agenda for the calendar date displayed at the cursor.
9111 This is a command that has to be installed in `calendar-mode-map'."
9112 (interactive)
9113 (org-agenda-list nil (calendar-absolute-from-gregorian
9114 (calendar-cursor-to-date))
9115 nil))
9117 (autoload 'org-calendar-goto-agenda "org-agenda" "\
9118 Compute the Org-mode agenda for the calendar date displayed at the cursor.
9119 This is a command that has to be installed in `calendar-mode-map'.
9121 \(fn)" t nil)
9123 (defun org-agenda-convert-date ()
9124 (interactive)
9125 (org-agenda-check-type t 'agenda 'timeline)
9126 (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
9127 date s)
9128 (unless day
9129 (error "Don't know which date to convert"))
9130 (setq date (calendar-gregorian-from-absolute day))
9131 (setq s (concat
9132 "Gregorian: " (calendar-date-string date) "\n"
9133 "ISO: " (calendar-iso-date-string date) "\n"
9134 "Day of Yr: " (calendar-day-of-year-string date) "\n"
9135 "Julian: " (calendar-julian-date-string date) "\n"
9136 "Astron. JD: " (calendar-astro-date-string date)
9137 " (Julian date number at noon UTC)\n"
9138 "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
9139 "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
9140 "French: " (calendar-french-date-string date) "\n"
9141 "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
9142 "Mayan: " (calendar-mayan-date-string date) "\n"
9143 "Coptic: " (calendar-coptic-date-string date) "\n"
9144 "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
9145 "Persian: " (calendar-persian-date-string date) "\n"
9146 "Chinese: " (calendar-chinese-date-string date) "\n"))
9147 (with-output-to-temp-buffer "*Dates*"
9148 (princ s))
9149 (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
9151 ;;; Bulk commands
9153 (defun org-agenda-bulk-marked-p ()
9154 (eq (get-char-property (point-at-bol) 'type)
9155 'org-marked-entry-overlay))
9157 (defun org-agenda-bulk-mark (&optional arg)
9158 "Mark the entry at point for future bulk action."
9159 (interactive "p")
9160 (dotimes (i (or arg 1))
9161 (unless (org-get-at-bol 'org-agenda-diary-link)
9162 (let* ((m (org-get-at-bol 'org-hd-marker))
9164 (unless (org-agenda-bulk-marked-p)
9165 (unless m (error "Nothing to mark at point"))
9166 (push m org-agenda-bulk-marked-entries)
9167 (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
9168 (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
9169 (org-get-todo-face "TODO")
9170 'evaporate)
9171 (overlay-put ov 'type 'org-marked-entry-overlay))
9172 (beginning-of-line 2)
9173 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9174 (beginning-of-line 2))
9175 (message "%d entries marked for bulk action"
9176 (length org-agenda-bulk-marked-entries))))))
9178 (defun org-agenda-bulk-mark-all ()
9179 "Mark all entries for future agenda bulk action."
9180 (interactive)
9181 (org-agenda-bulk-mark-regexp "."))
9183 (defun org-agenda-bulk-mark-regexp (regexp)
9184 "Mark entries matching REGEXP for future agenda bulk action."
9185 (interactive "sMark entries matching regexp: ")
9186 (let ((entries-marked 0))
9187 (save-excursion
9188 (goto-char (point-min))
9189 (goto-char (next-single-property-change (point) 'txt))
9190 (while (re-search-forward regexp nil t)
9191 (when (string-match regexp (get-text-property (point) 'txt))
9192 (setq entries-marked (1+ entries-marked))
9193 (call-interactively 'org-agenda-bulk-mark))))
9194 (if (not entries-marked)
9195 (message "No entry matching this regexp."))))
9197 (defun org-agenda-bulk-unmark (&optional arg)
9198 "Unmark the entry at point for future bulk action."
9199 (interactive "P")
9200 (if arg
9201 (org-agenda-bulk-unmark-all)
9202 (cond ((org-agenda-bulk-marked-p)
9203 (org-agenda-bulk-remove-overlays
9204 (point-at-bol) (+ 2 (point-at-bol)))
9205 (setq org-agenda-bulk-marked-entries
9206 (delete (org-get-at-bol 'org-hd-marker)
9207 org-agenda-bulk-marked-entries))
9208 (beginning-of-line 2)
9209 (while (and (get-char-property (point) 'invisible) (not (eobp)))
9210 (beginning-of-line 2))
9211 (message "%d entries left marked for bulk action"
9212 (length org-agenda-bulk-marked-entries)))
9213 (t (message "No entry to unmark here")))))
9215 (defun org-agenda-bulk-toggle ()
9216 "Toggle marking the entry at point for bulk action."
9217 (interactive)
9218 (if (org-agenda-bulk-marked-p)
9219 (org-agenda-bulk-unmark)
9220 (org-agenda-bulk-mark)))
9222 (defun org-agenda-bulk-remove-overlays (&optional beg end)
9223 "Remove the mark overlays between BEG and END in the agenda buffer.
9224 BEG and END default to the buffer limits.
9226 This only removes the overlays, it does not remove the markers
9227 from the list in `org-agenda-bulk-marked-entries'."
9228 (interactive)
9229 (mapc (lambda (ov)
9230 (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
9231 (delete-overlay ov)))
9232 (overlays-in (or beg (point-min)) (or end (point-max)))))
9234 (defun org-agenda-bulk-unmark-all ()
9235 "Remove all marks in the agenda buffer.
9236 This will remove the markers and the overlays."
9237 (interactive)
9238 (if (null org-agenda-bulk-marked-entries)
9239 (message "No entry to unmark")
9240 (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
9241 (setq org-agenda-bulk-marked-entries nil)
9242 (org-agenda-bulk-remove-overlays (point-min) (point-max))))
9244 (defcustom org-agenda-persistent-marks nil
9245 "Non-nil means marked items will stay marked after a bulk action.
9246 You can toggle this interactively by typing `p' when prompted for a
9247 bulk action."
9248 :group 'org-agenda
9249 :version "24.1"
9250 :type 'boolean)
9252 (defun org-agenda-bulk-action (&optional arg)
9253 "Execute an remote-editing action on all marked entries.
9254 The prefix arg is passed through to the command if possible."
9255 (interactive "P")
9256 ;; Make sure we have markers, and only valid ones
9257 (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
9258 (mapc
9259 (lambda (m)
9260 (unless (and (markerp m)
9261 (marker-buffer m)
9262 (buffer-live-p (marker-buffer m))
9263 (marker-position m))
9264 (error "Marker %s for bulk command is invalid" m)))
9265 org-agenda-bulk-marked-entries)
9267 ;; Prompt for the bulk command
9268 (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
9269 (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
9270 "[S]catter [f]unction "
9271 (when org-agenda-bulk-custom-functions
9272 (concat " Custom: ["
9273 (mapconcat (lambda(f) (char-to-string (car f)))
9274 org-agenda-bulk-custom-functions "")
9275 "]"))))
9276 (catch 'exit
9277 (let* ((action (read-char-exclusive))
9278 (org-log-refile (if org-log-refile 'time nil))
9279 (entries (reverse org-agenda-bulk-marked-entries))
9280 (org-overriding-default-time
9281 (if (get-text-property (point) 'org-agenda-date-header)
9282 (org-get-cursor-date)))
9283 redo-at-end
9284 cmd rfloc state e tag pos (cnt 0) (cntskip 0))
9285 (cond
9286 ((equal action ?p)
9287 (let ((org-agenda-persistent-marks
9288 (not org-agenda-persistent-marks)))
9289 (org-agenda-bulk-action)
9290 (throw 'exit nil)))
9292 ((equal action ?$)
9293 (setq cmd '(org-agenda-archive)))
9295 ((equal action ?A)
9296 (setq cmd '(org-agenda-archive-to-archive-sibling)))
9298 ((member action '(?r ?w))
9299 (setq rfloc (org-refile-get-location
9300 "Refile to"
9301 (marker-buffer (car entries))
9302 org-refile-allow-creating-parent-nodes))
9303 (if (nth 3 rfloc)
9304 (setcar (nthcdr 3 rfloc)
9305 (move-marker (make-marker) (nth 3 rfloc)
9306 (or (get-file-buffer (nth 1 rfloc))
9307 (find-buffer-visiting (nth 1 rfloc))
9308 (error "This should not happen")))))
9310 (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
9311 redo-at-end t))
9313 ((equal action ?t)
9314 (setq state (org-icompleting-read
9315 "Todo state: "
9316 (with-current-buffer (marker-buffer (car entries))
9317 (mapcar 'list org-todo-keywords-1))))
9318 (setq cmd `(let ((org-inhibit-blocking t)
9319 (org-inhibit-logging 'note))
9320 (org-agenda-todo ,state))))
9322 ((memq action '(?- ?+))
9323 (setq tag (org-icompleting-read
9324 (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
9325 (with-current-buffer (marker-buffer (car entries))
9326 (delq nil
9327 (mapcar (lambda (x)
9328 (if (stringp (car x)) x)) org-tag-alist)))))
9329 (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
9331 ((memq action '(?s ?d))
9332 (let* ((time
9333 (unless arg
9334 (org-read-date
9335 nil nil nil
9336 (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
9337 org-overriding-default-time)))
9338 (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
9339 (setq cmd `(eval '(,c1 arg ,time)))))
9341 ((equal action ?S)
9342 (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
9343 (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
9344 (let ((days (read-number
9345 (format "Scatter tasks across how many %sdays: "
9346 (if arg "week" "")) 7)))
9347 (setq cmd
9348 `(let ((distance (1+ (random ,days))))
9349 (if arg
9350 (let ((dist distance)
9351 (day-of-week
9352 (calendar-day-of-week
9353 (calendar-gregorian-from-absolute (org-today)))))
9354 (dotimes (i (1+ dist))
9355 (while (member day-of-week org-agenda-weekend-days)
9356 (incf distance)
9357 (incf day-of-week)
9358 (if (= day-of-week 7)
9359 (setq day-of-week 0)))
9360 (incf day-of-week)
9361 (if (= day-of-week 7)
9362 (setq day-of-week 0)))))
9363 ;; silently fail when try to replan a sexp entry
9364 (condition-case nil
9365 (let* ((date (calendar-gregorian-from-absolute
9366 (+ (org-today) distance)))
9367 (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
9368 (nth 2 date))))
9369 (org-agenda-schedule nil time))
9370 (error nil)))))))
9372 ((assoc action org-agenda-bulk-custom-functions)
9373 (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
9374 redo-at-end t))
9376 ((equal action ?f)
9377 (setq cmd (list (intern
9378 (org-icompleting-read "Function: "
9379 obarray 'fboundp t nil nil)))))
9381 (t (error "Invalid bulk action")))
9383 ;; Sort the markers, to make sure that parents are handled before children
9384 (setq entries (sort entries
9385 (lambda (a b)
9386 (cond
9387 ((equal (marker-buffer a) (marker-buffer b))
9388 (< (marker-position a) (marker-position b)))
9390 (string< (buffer-name (marker-buffer a))
9391 (buffer-name (marker-buffer b))))))))
9393 ;; Now loop over all markers and apply cmd
9394 (while (setq e (pop entries))
9395 (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
9396 (if (not pos)
9397 (progn (message "Skipping removed entry at %s" e)
9398 (setq cntskip (1+ cntskip)))
9399 (goto-char pos)
9400 (let (org-loop-over-headlines-in-active-region)
9401 (eval cmd))
9402 (setq cnt (1+ cnt))))
9403 (when redo-at-end (org-agenda-redo))
9404 (unless org-agenda-persistent-marks
9405 (org-agenda-bulk-unmark-all))
9406 (message "Acted on %d entries%s%s"
9408 (if (= cntskip 0)
9410 (format ", skipped %d (disappeared before their turn)"
9411 cntskip))
9412 (if (not org-agenda-persistent-marks)
9413 "" " (kept marked)"))))))
9415 (defun org-agenda-capture (&optional with-time)
9416 "Call `org-capture' with the date at point.
9417 With a `C-1' prefix, use the HH:MM value at point (if any) or the
9418 current HH:MM time."
9419 (interactive "P")
9420 (if (not (eq major-mode 'org-agenda-mode))
9421 (user-error "You cannot do this outside of agenda buffers")
9422 (let ((org-overriding-default-time
9423 (org-get-cursor-date (equal with-time 1))))
9424 (call-interactively 'org-capture))))
9426 ;;; Flagging notes
9428 (defun org-agenda-show-the-flagging-note ()
9429 "Display the flagging note in the other window.
9430 When called a second time in direct sequence, offer to remove the FLAGGING
9431 tag and (if present) the flagging note."
9432 (interactive)
9433 (let ((hdmarker (org-get-at-bol 'org-hd-marker))
9434 (win (selected-window))
9435 note heading newhead)
9436 (unless hdmarker
9437 (error "No linked entry at point"))
9438 (if (and (eq this-command last-command)
9439 (y-or-n-p "Unflag and remove any flagging note? "))
9440 (progn
9441 (org-agenda-remove-flag hdmarker)
9442 (let ((win (get-buffer-window "*Flagging Note*")))
9443 (and win (delete-window win)))
9444 (message "Entry unflagged"))
9445 (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
9446 (unless note
9447 (error "No flagging note"))
9448 (org-kill-new note)
9449 (org-switch-to-buffer-other-window "*Flagging Note*")
9450 (erase-buffer)
9451 (insert note)
9452 (goto-char (point-min))
9453 (while (re-search-forward "\\\\n" nil t)
9454 (replace-match "\n" t t))
9455 (goto-char (point-min))
9456 (select-window win)
9457 (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
9459 (defun org-agenda-remove-flag (marker)
9460 "Remove the FLAGGED tag and any flagging note in the entry."
9461 (let (newhead)
9462 (org-with-point-at marker
9463 (org-toggle-tag "FLAGGED" 'off)
9464 (org-entry-delete nil "THEFLAGGINGNOTE")
9465 (setq newhead (org-get-heading)))
9466 (org-agenda-change-all-lines newhead marker)
9467 (message "Entry unflagged")))
9469 (defun org-agenda-get-any-marker (&optional pos)
9470 (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
9471 (get-text-property (or pos (point-at-bol)) 'org-marker)))
9473 ;;; Appointment reminders
9475 (defvar appt-time-msg-list) ; defined in appt.el
9477 ;;;###autoload
9478 (defun org-agenda-to-appt (&optional refresh filter &rest args)
9479 "Activate appointments found in `org-agenda-files'.
9480 With a \\[universal-argument] prefix, refresh the list of
9481 appointments.
9483 If FILTER is t, interactively prompt the user for a regular
9484 expression, and filter out entries that don't match it.
9486 If FILTER is a string, use this string as a regular expression
9487 for filtering entries out.
9489 If FILTER is a function, filter out entries against which
9490 calling the function returns nil. This function takes one
9491 argument: an entry from `org-agenda-get-day-entries'.
9493 FILTER can also be an alist with the car of each cell being
9494 either 'headline or 'category. For example:
9496 '((headline \"IMPORTANT\")
9497 (category \"Work\"))
9499 will only add headlines containing IMPORTANT or headlines
9500 belonging to the \"Work\" category.
9502 ARGS are symbols indicating what kind of entries to consider.
9503 By default `org-agenda-to-appt' will use :deadline, :scheduled
9504 and :timestamp entries. See the docstring of `org-diary' for
9505 details and examples.
9507 If an entry as a APPT_WARNTIME property, its value will be used
9508 to override `appt-message-warning-time'."
9509 (interactive "P")
9510 (if refresh (setq appt-time-msg-list nil))
9511 (if (eq filter t)
9512 (setq filter (read-from-minibuffer "Regexp filter: ")))
9513 (let* ((cnt 0) ; count added events
9514 (scope (or args '(:deadline :scheduled :timestamp)))
9515 (org-agenda-new-buffers nil)
9516 (org-deadline-warning-days 0)
9517 ;; Do not use `org-today' here because appt only takes
9518 ;; time and without date as argument, so it may pass wrong
9519 ;; information otherwise
9520 (today (org-date-to-gregorian
9521 (time-to-days (current-time))))
9522 (org-agenda-restrict nil)
9523 (files (org-agenda-files 'unrestricted)) entries file
9524 (org-agenda-buffer nil))
9525 ;; Get all entries which may contain an appt
9526 (org-agenda-prepare-buffers files)
9527 (while (setq file (pop files))
9528 (setq entries
9529 (delq nil
9530 (append entries
9531 (apply 'org-agenda-get-day-entries
9532 file today scope)))))
9533 ;; Map thru entries and find if we should filter them out
9534 (mapc
9535 (lambda(x)
9536 (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
9537 (cat (get-text-property 1 'org-category x))
9538 (tod (get-text-property 1 'time-of-day x))
9539 (ok (or (null filter)
9540 (and (stringp filter) (string-match filter evt))
9541 (and (functionp filter) (funcall filter x))
9542 (and (listp filter)
9543 (let ((cat-filter (cadr (assoc 'category filter)))
9544 (evt-filter (cadr (assoc 'headline filter))))
9545 (or (and (stringp cat-filter)
9546 (string-match cat-filter cat))
9547 (and (stringp evt-filter)
9548 (string-match evt-filter evt)))))))
9549 (wrn (get-text-property 1 'warntime x)))
9550 ;; FIXME: Shall we remove text-properties for the appt text?
9551 ;; (setq evt (set-text-properties 0 (length evt) nil evt))
9552 (when (and ok tod)
9553 (setq tod (concat "00" (number-to-string tod))
9554 tod (when (string-match
9555 "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
9556 (concat (match-string 1 tod) ":"
9557 (match-string 2 tod))))
9558 (if (version< emacs-version "23.3")
9559 (appt-add tod evt)
9560 (appt-add tod evt wrn))
9561 (setq cnt (1+ cnt))))) entries)
9562 (org-release-buffers org-agenda-new-buffers)
9563 (if (eq cnt 0)
9564 (message "No event to add")
9565 (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
9567 (autoload 'org-agenda-to-appt "org-agenda" "\
9568 Activate appointments found in `org-agenda-files'.
9569 With a \\[universal-argument] prefix, refresh the list of
9570 appointments.
9572 If FILTER is t, interactively prompt the user for a regular
9573 expression, and filter out entries that don't match it.
9575 If FILTER is a string, use this string as a regular expression
9576 for filtering entries out.
9578 If FILTER is a function, filter out entries against which
9579 calling the function returns nil. This function takes one
9580 argument: an entry from `org-agenda-get-day-entries'.
9582 FILTER can also be an alist with the car of each cell being
9583 either 'headline or 'category. For example:
9585 '((headline \"IMPORTANT\")
9586 (category \"Work\"))
9588 will only add headlines containing IMPORTANT or headlines
9589 belonging to the \"Work\" category.
9591 ARGS are symbols indicating what kind of entries to consider.
9592 By default `org-agenda-to-appt' will use :deadline, :scheduled
9593 and :timestamp entries. See the docstring of `org-diary' for
9594 details and examples.
9596 If an entry as a APPT_WARNTIME property, its value will be used
9597 to override `appt-message-warning-time'.
9599 \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
9601 (defun org-agenda-todayp (date)
9602 "Does DATE mean today, when considering `org-extend-today-until'?"
9603 (let ((today (org-today))
9604 (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
9605 date)))
9606 (eq date today)))
9608 (defun org-agenda-todo-yesterday (&optional arg)
9609 "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
9610 (interactive "P")
9611 (let* ((hour (third (decode-time
9612 (org-current-time))))
9613 (org-extend-today-until (1+ hour)))
9614 (org-agenda-todo arg)))
9616 (provide 'org-agenda)
9618 ;;; org-agenda.el ends here